Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
report_total_internal_messages.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_Internal_Messages::loadReport($type_code);
61 
62  if (empty($report)) {
64  return TRUE;
65  }
66 
67  $generated = $report['generated'];
68  $report = $report['report_data'];
69  $total_system_messages_by_type = $report['total_system_messages_by_type'];
70  $total_user_messages_by_type = $report['total_user_messages_by_type'];
71  $total_messages_by_status = $report['total_messages_by_status'];
72 
73  $row_format = '<tr>
74  <td class="sq-backend-table-cell">
75  %s
76  </td>
77  <td class="sq-backend-table-cell" align="right">
78  %s
79  </td>
80  </tr>';
81 
82  $table_format = ' <br><b>%s</b><br><br>
83  <table class="sq-backend-table">
84  <tr>
85  <th class="sq-backend-table-header">Message Type</th>
86  <th class="sq-backend-table-header" width="70" align="right">Total</th>
87  </tr>
88  %s
89  </table>
90  ';
91 
92  $rows_string = '';
93  foreach ($total_system_messages_by_type as $report) {
94  $rows_string .= sprintf($row_format, $report['type'], $report['total']);
95  }
96 
97  $table = sprintf($table_format, 'System Messages', $rows_string);
98 
99  Report_Total_Internal_Messages::paintLastGeneratedDate($type_code, date('d M Y, H:i:s', $generated));
100  echo '<br>'.$table;
101 
102  $rows_string = '';
103  foreach ($total_user_messages_by_type as $report) {
104  $rows_string .= sprintf($row_format, $report['type'], $report['total']);
105  }
106 
107  $table = sprintf($table_format, 'User Messages', $rows_string);
108 
109  echo '<br>'.$table;
110 
111  $rows_string = '';
112 
113  $row_format = '<tr>
114  <td class="sq-backend-table-cell" style="width: 10px">
115  %s
116  </td>
117  <td class="sq-backend-table-cell">
118  %s
119  </td>
120  <td class="sq-backend-table-cell" align="right">
121  %s
122  </td>
123  </tr>';
124 
125  foreach ($total_messages_by_status as $report) {
126  $status = $report['status'];
127  $unknown_status = FALSE;
128 
129  switch ($status) {
130  case 'U': $status = 'Unread';
131  break;
132 
133  case 'R': $status = 'Read';
134  break;
135 
136  case 'D': $status = 'Deleted';
137  break;
138 
139  default: $unknown_status = TRUE;
140  break;
141  }
142 
143  $icon = '';
144  if (!$unknown_status) {
145  if ($status == 'Deleted') {
146  $icon = '<img src="'.sq_web_path('lib').'/web/images/icons/internal_message/trash.png">';
147  } else {
148  $icon = '<img src="'.sq_web_path('lib').'/web/images/icons/internal_message/message_'.strtolower($status).'.png">';
149  }
150  }
151 
152  $rows_string .= sprintf($row_format, $icon, $status, $report['total']);
153  }
154 
155 
156  $table_format = ' <br>
157  <table class="sq-backend-table">
158  <tr>
159  <th class="sq-backend-table-header" colspan="2">Message Status</th>
160  <th class="sq-backend-table-header" width="70" align="right">Total</th>
161  </tr>
162  %s
163  </table>
164  ';
165 
166  $table = sprintf($table_format, $rows_string);
167  echo $table;
168 
169  }//end paintReport()
170 
171 
182  public static function processReport(Backend_Outputter &$o, $type_code)
183  {
184  $today = time();
185 
186  $messages_report = Array(
187  'total_system_messages_by_type' => Report_Total_Internal_Messages::_getTotalInternalMessagesByType('system'),
188  'total_user_messages_by_type' => Report_Total_Internal_Messages::_getTotalInternalMessagesByType('user'),
189  'total_messages_by_status' => Report_Total_Internal_Messages::_getTotalInternalMessagesByStatus(),
190  );
191 
192  $report = Array(
193  'generated' => $today,
194  'report_data' => $messages_report,
195  );
196 
197  Report_Total_Internal_Messages::saveReport($type_code, $report);
198 
199  return TRUE;
200 
201  }//end processReport()
202 
203 
213  private static function _getTotalInternalMessagesByType($message_type='all')
214  {
215  $db = MatrixDAL::getDb();
216 
217  $where_clause = '';
218  if ($message_type == 'system') {
219  $where_clause = 'WHERE type LIKE '.MatrixDAL::quote('system.%');
220  } else if ($message_type == 'user') {
221  $where_clause = 'WHERE type NOT LIKE '.MatrixDAL::quote('system.%');
222  }
223 
224  $sql = 'SELECT type, COUNT(*) AS total '.
225  'FROM sq_internal_msg '.$where_clause.
226  'GROUP BY type ORDER BY total DESC, type';
227 
228  $rows = MatrixDAL::executeSqlAssoc($sql);
229 
230  return $rows;
231 
232  }//end _getTotalInternalMessagesByType()
233 
234 
242  private function _getTotalInternalMessagesByStatus()
243  {
244  $db = MatrixDAL::getDb();
245  $sql = 'SELECT status, COUNT(*) AS total '.
246  'FROM sq_internal_msg '.
247  'GROUP BY status ORDER BY status DESC';
248 
249  $rows = MatrixDAL::executeSqlAssoc($sql);
250 
251  return $rows;
252 
253  }//end _getTotalInternalMessagesByStatus()
254 
255 
256 }//end class
257 
258 ?>