Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
report_most_used_asset_types.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_Most_Used_Asset_Types::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  // Lovingly borrowed from the Asset Counter Report
73  $row_format = '<tr>
74  <td class="sq-backend-table-cell" style="width: 10px">
75  <img src="%s">
76  </td>
77  <td class="sq-backend-table-cell">
78  %s
79  </td>
80  <td class="sq-backend-table-cell" align="right">
81  %s
82  </td>
83  </tr>';
84 
85  $rows_string = '';
86 
87  foreach ($report['user_assets'] as $asset_type_code => $user_asset_stats) {
88  $rows_string .= sprintf($row_format, $am->getAssetIconURL($asset_type_code), $user_asset_stats['asset_type_name'], $user_asset_stats['total']);
89  }
90 
91  $table_format = ' <b>%s</b><br><br>
92  <table class="sq-backend-table">
93  <tr>
94  <th class="sq-backend-table-header" colspan="2">Asset Type</th>
95  <th class="sq-backend-table-header" width="70" align="right">Total</th>
96  </tr>
97  %s
98  </table>
99  <br>';
100 
101  $user_assets_table = sprintf($table_format, 'User Asset Types', $rows_string);
102 
103  $rows_string = '';
104 
105  foreach ($report['system_assets'] as $asset_type_code => $system_asset_stats) {
106  $rows_string .= sprintf($row_format, $am->getAssetIconURL($asset_type_code), $system_asset_stats['asset_type_name'], $system_asset_stats['total']);
107  }
108 
109  $system_assets_table = sprintf($table_format, 'System Asset Types', $rows_string);
110 
111  Report_Most_Used_Asset_Types::paintLastGeneratedDate($type_code, date('d M Y, H:i:s', $generated));
112  echo '<br><br>';
113  echo $user_assets_table;
114  echo '<br>'.$system_assets_table;
115 
116  }//end paintReport()
117 
118 
129  public static function processReport(Backend_Outputter &$o, $type_code)
130  {
131  $today = time();
132 
133  $report = Array(
134  'generated' => $today,
135  'report_data' => Array(
136  'user_assets' => Report_Most_Used_Asset_Types::_getTopAssetTypes('user'),
137  'system_assets' => Report_Most_Used_Asset_Types::_getTopAssetTypes('system'),
138  ),
139  );
140 
141  Report_Most_Used_Asset_Types::saveReport($type_code, $report);
142 
143  return TRUE;
144 
145  }//end processReport()
146 
147 
157  private static function _getTopAssetTypes($asset_access_type='all')
158  {
159  $access_type_query = '';
160 
161  $am = $GLOBALS['SQ_SYSTEM']->am;
162 
163  $db = MatrixDAL::getDb();
164  $sql = 'SELECT type_code, count(*) AS total '.
165  'FROM sq_ast '.
166  'GROUP BY type_code '.
167  'ORDER BY total DESC';
168 
169  // Now for our "Top Ten"
170  $sql = db_extras_modify_limit_clause($sql, MatrixDAL::getDbType(), 10);
171 
172  if (($asset_access_type == 'system') || ($asset_access_type == 'user')) {
173  if ($asset_access_type == 'system') {
174  $access_type_query = 't.allowed_access = '.MatrixDAL::quote('system').' ';
175  } else if ($asset_access_type == 'user') {
176  $access_type_query = 't.allowed_access != '.MatrixDAL::quote('system').' ';
177  }
178 
179  $sql = 'SELECT a.type_code, count(*) AS total '.
180  'FROM sq_ast a, sq_ast_typ t '.
181  'WHERE a.type_code = t.type_code AND t.instantiable = '.MatrixDAL::quote('1').' AND '.$access_type_query.
182  'GROUP BY a.type_code '.
183  'ORDER BY total DESC';
184  $sql = db_extras_modify_limit_clause($sql, MatrixDAL::getDbType(), 10);
185  }
186 
187  $rows = MatrixDAL::executeSqlAssoc($sql);
188  $asset_types = Array();
189 
190  foreach ($rows as $row) {
191  $asset_type_name = $am->getTypeInfo($row['type_code'], 'name');
192 
193  $asset_types[$row['type_code']] = Array(
194  'asset_type_name' => $asset_type_name,
195  'total' => $row['total'],
196  );
197  }
198 
199  return $asset_types;
200 
201  }//end _getTopAssetTypes()
202 
203 
204 }//end class
205 
206 ?>