Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
report_trash_age.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/assets/system/simple_report/simple_report.inc';
18 
32 {
33 
34 
41  function __construct($assetid=0)
42  {
43  parent::__construct($assetid);
44 
45  }//end constructor
46 
47 
58  public static function paintReport(Backend_Outputter &$o, $type_code)
59  {
60  $report = Report_Trash_Age::loadReport($type_code);
61 
62  if (empty($report)) {
64  return TRUE;
65  }
66 
67  $generated = $report['generated'];
68  $report = $report['report_data'];
69 
70  $am = $GLOBALS['SQ_SYSTEM']->am;
71 
72  $row_format = '<tr>
73  <td class="sq-backend-table-cell" style="width: 10px">
74  <img src="%s">
75  </td>
76  <td class="sq-backend-table-cell">
77  %s (Id: %s)
78  </td>
79  <td class="sq-backend-table-cell" align="right">
80  %s
81  </td>
82  </tr>';
83 
84  $rows_string = '';
85  foreach ($report as $asset_info) {
86  $rows_string .= sprintf($row_format, $am->getAssetIconURL($asset_info['type_code']), $asset_info['name'], $asset_info['assetid'], date('d M Y, H:i:s', strtotime($asset_info['updated'])));
87  }
88 
89  $table_format = '<table class="sq-backend-table">
90  <tr>
91  <th class="sq-backend-table-header" colspan="2">Name</th>
92  <th class="sq-backend-table-header" align="right">Last Updated</th>
93  </tr>
94  %s
95  </table>';
96 
97  $table = sprintf($table_format, $rows_string);
98 
99  Report_Trash_Age::paintLastGeneratedDate($type_code, date('d M Y, H:i:s', $generated));
100  echo '<br>';
101  if (empty($rows_string)) {
102  $table = '<table class="sq-backend-table">
103  <tr>
104  <td class="sq-backend-table-cell">There are currently no assets in the trash</td>
105  </tr>
106  </table>';
107  }
108 
109  echo $table;
110 
111  }//end paintReport()
112 
113 
124  public static function processReport(Backend_Outputter &$o, $type_code)
125  {
126  $today = time();
127 
128  $asset_report = Report_Trash_Age::_getOldestAssetsInTrash();
129 
130  $report = Array(
131  'generated' => $today,
132  'report_data' => $asset_report,
133  );
134 
135  Report_Trash_Age::saveReport($type_code, $report);
136 
137  return TRUE;
138 
139  }//end processReport()
140 
141 
149  private static function _getOldestAssetsInTrash()
150  {
151  $am = $GLOBALS['SQ_SYSTEM']->am;
152  $asset_info = Array();
153 
154  $db = MatrixDAL::getDb();
155  $sql = 'SELECT a.assetid, a.type_code, a.name, a.updated '.
156  'FROM sq_ast_lnk l, sq_ast_lnk_tree t, sq_ast a, sq_ast_typ p '.
157  'WHERE a.type_code = p.type_code AND p.allowed_access != '.MatrixDAL::quote('system').' AND p.instantiable = '.MatrixDAL::quote('1').' '.
158  'AND t.treeid LIKE '.
159  '(SELECT t.treeid FROM sq_ast_lnk_tree t, sq_ast_lnk l, sq_ast a '.
160  'WHERE l.minorid = a.assetid AND t.linkid = l.linkid AND a.type_code = '.MatrixDAL::quote('trash_folder').')||'.MatrixDAL::quote('%').' '.
161  'AND l.linkid = t.linkid AND a.assetid = l.minorid AND a.type_code != '.MatrixDAL::quote('trash_folder').' '.
162  'ORDER BY updated';
163  $sql = db_extras_modify_limit_clause($sql, MatrixDAL::getDbType(), 20);
164 
165  $rows = MatrixDAL::executeSqlAssoc($sql);
166 
167  return $rows;
168 
169  }//end _getOldestAssetsInTrash()
170 
171 
172 }//end class
173 ?>