Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
report_total_assets.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_Total_Assets::loadReport($type_code);
61 
62  if (empty($report)) {
64  return TRUE;
65  }
66 
67  $generated = $report['generated'];
68  $report = $report['report_data'];
69 
70  $row_format = '<tr>
71  <td class="sq-backend-table-cell">
72  %s
73  </td>
74  <td class="sq-backend-table-cell" align="right">
75  %s
76  </td>
77  </tr>';
78 
79  $current_day_assets_table = '<table class="sq-backend-table">
80  <tr>
81  <th class="sq-backend-table-header" width="30%%">Assets currently in the system</th>
82  <td align="right">'.$report['num_assets_today'].'</td>
83  </tr>
84  </table>';
85 
86  $row_string = '';
87  $report = $report['date_report'];
88  foreach ($report as $date_description => $date_data) {
89  $row_string .= sprintf($row_format, $date_description, $date_data['num_assets']);
90  }
91 
92  $table_format = '<table class="sq-backend-table">
93  <tr>
94  <th class="sq-backend-table-header">Period</th>
95  <th class="sq-backend-table-header" width="35%%" align="right">Assets in the system</th>
96  </tr>
97  %s
98  </table>';
99 
100  $table = sprintf($table_format, $row_string);
101  Report_Total_Assets::paintLastGeneratedDate($type_code, date('d M Y, H:i:s', $generated));
102  echo '<br>';
103  Report_Total_Assets::_paintSystemInstallDate();
104  echo $current_day_assets_table;
105  echo $table;
106 
107  }//end paintReport()
108 
109 
120  public static function processReport(Backend_Outputter &$o, $type_code)
121  {
122  $today = time();
123 
124  $year = date('Y', $today);
125  $month = date('m', $today);
126  $date = date('d', $today);
127 
128  $last_month = str_pad(date('m', $today) - 1, 2, '0', STR_PAD_LEFT);
129 
130  $date_yesterday = date('Y-m-d', $today - (24*3600));
131  $last_week_date = date('Y-m-d', $today - (24*3600*7));
132  $last_month_date = date('Y-m-d', $today - (30*24*3600));
133  $last_quarter_date = date('Y-m-d', $today - (90*24*3600));
134  $last_semester_date = date('Y-m-d', $today - (180*24*3600));
135  $last_year_date = date('Y-m-d', $today - (365*24*3600));
136 
137  $date_report = Array(
138  'Yesterday' => Array(
139  'date' => $date_yesterday,
140  'num_assets' => 0,
141  ),
142  'Last week' => Array(
143  'date' => $last_week_date,
144  'num_assets' => 0,
145  ),
146  'Last month' => Array(
147  'date' => $last_month_date,
148  'num_assets' => 0,
149  ),
150  'Last three months' => Array(
151  'date' => $last_quarter_date,
152  'num_assets' => 0,
153  ),
154  'Last six months' => Array(
155  'date' => $last_semester_date,
156  'num_assets' => 0,
157  ),
158  'Last year' => Array(
159  'date' => $last_year_date,
160  'num_assets' => 0,
161  ),
162  );
163 
164  $num_assets_today = Report_Total_Assets::_getTotalAssets();
165  $last_period = FALSE;
166  $remove_date_items = Array();
167 
168  foreach ($date_report as $date_description => $date_data) {
169  if ($last_period) {
170  $remove_date_items[] = $date_description;
171  continue;
172  }
173 
174  $num_assets = Report_Total_Assets::_getTotalAssets($date_data['date']);
175  $date_report[$date_description]['num_assets'] = $num_assets_today - $num_assets;
176 
177  if ($date_report[$date_description]['num_assets'] === 0) {
178  $last_period = TRUE;
179  }
180  }
181 
182  foreach ($remove_date_items as $date_description) {
183  unset($date_report[$date_description]);
184  }
185 
186  $report = Array(
187  'generated' => $today,
188  'report_data' => Array(
189  'num_assets_today' => $num_assets_today,
190  'date_report' => $date_report,
191  ),
192  );
193 
194  Report_Total_Assets::saveReport($type_code, $report);
195 
196  return TRUE;
197 
198  }//end processReport()
199 
200 
210  private static function _getTotalAssets($after_date='')
211  {
212  $after_date_query = '';
213  if ($after_date != '') {
214  $after_date_query = ' WHERE created >= '.MatrixDAL::quote($after_date);
215  }
216 
217  $db = MatrixDAL::getDb();
218  $sql = 'SELECT count(*) AS total '.
219  'FROM sq_ast'.$after_date_query;
220 
221  $num_assets = MatrixDAL::executeSqlOne($sql);
222 
223  return $num_assets;
224 
225  }//end _getTotalAssets()
226 
227 
235  private static function _paintSystemInstallDate()
236  {
237  $table_format = '<table class="sq-backend-table">
238  <tr>
239  <th class="sq-backend-table-header" width="30%%">System Install Date</th>
240  <td class="sq-backend-table-cell" align="right">%s</td>
241  </tr>
242  </table>';
243 
244  $time = strtotime(Report_Total_Assets::_getSystemInstallDate());
245  $date = date('d M Y, H:i:s', $time);
246 
247  $table = sprintf($table_format, $date);
248  echo $table;
249 
250  }//end _paintSystemInstallDate()
251 
252 
260  private static function _getSystemInstallDate()
261  {
262  $db = MatrixDAL::getDb();
263  $sql = 'SELECT MIN(created)FROM sq_ast';
264 
265  $first_asset_date = MatrixDAL::executeSqlOne($sql);
266 
267  return $first_asset_date;
268 
269  }//end _getSystemInstallDate()
270 
271 
272 }//end class
273 ?>