Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
report_triggers.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/assets/system/simple_report/simple_report.inc';
18 
33 {
34 
35 
42  function __construct($assetid=0)
43  {
44  parent::__construct($assetid);
45 
46  }//end constructor
47 
48 
59  public static function paintReport(Backend_Outputter &$o, $type_code)
60  {
61  $report = Report_Triggers::loadReport($type_code);
62 
63  if (empty($report)) {
65  return TRUE;
66  }
67 
68  $generated = $report['generated'];
69  $report = $report['report_data'];
70 
71  $row_format = '<tr>
72  <td class="sq-backend-table-cell">
73  <img src="%s">
74  </td>
75  <td class="sq-backend-table-cell">
76  %s
77  </td>
78  <td class="sq-backend-table-cell" align="right">
79  %s
80  </td>
81  <td class="sq-backend-table-cell" align="right">
82  %s
83  </td>
84  <td class="sq-backend-table-cell" align="right">
85  %s
86  </td>
87  </tr>';
88 
89  $rows_string = '';
90 
91  $trigger_manager = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('trigger_manager');
92 
93  foreach ($report as $key => $trigger_info) {
94  if (($key == 'num_triggers') || ($key == 'num_active_triggers')) continue;
95 
96  foreach ($trigger_info as $trigger_weighted_info) {
97  $icon = 'exit_limbo';
98  if ($trigger_weighted_info['active'] == 1) {
99  $icon = 'preview';
100  }
101 
102  $rows_string .= sprintf($row_format, sq_web_path('lib').'/web/images/icons/header/'.$icon.'.png', $trigger_weighted_info['name'].' (Id: '.$trigger_manager->id.':'.$trigger_weighted_info['id'].')', $trigger_weighted_info['events'], $trigger_weighted_info['conditions'], $trigger_weighted_info['actions']);
103  }
104  }
105 
106  $table_format = '<table class="sq-backend-table">
107  <tr>
108  <th class="sq-backend-table-header">State</th>
109  <th class="sq-backend-table-header">Trigger</th>
110  <th class="sq-backend-table-header" align="right">Events</th>
111  <th class="sq-backend-table-header" align="right">Conditions</th>
112  <th class="sq-backend-table-header" align="right">Actions</th>
113  </tr>
114  %s
115  </table>';
116 
117  $table = sprintf($table_format, $rows_string);
118 
119  Report_Triggers::paintLastGeneratedDate($type_code, date('d M Y, H:i:s', $generated));
120 
121  ?>
122 <br>
123 <table class="sq-backend-table">
124  <?php
125  if ($report['num_triggers'] > 0) {
126  ?>
127 <tr>
128  <th class=sq-backend-table-header">Total Active Triggers</th>
129  <td class="sq-backend-table-cell" align="right"><?php echo $report['num_active_triggers']; ?></td>
130 </tr>
131 <tr>
132  <th class=sq-backend-table-header">Total Triggers</th>
133  <td class="sq-backend-table-cell" align="right"><?php echo $report['num_triggers']; ?></td>
134 </tr>
135  <?php
136  } else {
137  ?>
138 <tr>
139  <td class="sq-backend-table-cell">There are no Triggers in the system</td>
140 </tr>
141  <?php
142  }
143  ?>
144 </table>
145 <br>
146  <?php
147 
148  if (!empty($rows_string)) echo $table;
149 
150  }//end paintReport()
151 
152 
163  public static function processReport(Backend_Outputter &$o, $type_code)
164  {
165  $today = time();
166  $trigger_report = Report_Triggers::_getTriggerInfo();
167 
168  $report = Array(
169  'generated' => $today,
170  'report_data' => $trigger_report,
171  );
172 
173  Report_Triggers::saveReport($type_code, $report);
174 
175  return TRUE;
176 
177  }//end processReport()
178 
186  private static function _getTriggerInfo()
187  {
188  $trigger_info = MatrixDAL::executeAll('core', 'getTriggerList');
189  $trigger_info_sorted = Array();
190 
191  $num_triggers = count($trigger_info);
192  $num_active_triggers = 0;
193 
194  foreach ($trigger_info as $trigger) {
195  $trigger_data = unserialize($trigger['data']);
196 
197  $num_events = count($trigger_data['events']);
198  $num_conditions = count($trigger_data['conditions']);
199  $num_actions = count($trigger_data['actions']);
200 
201  $weighting = ($num_events * 20) + ($num_conditions * 10) + $num_actions;
202 
203  $trigger_info_sorted[$weighting][] = Array(
204  'id' => $trigger['id'],
205  'name' => $trigger['name'],
206  'events' => $num_events,
207  'conditions' => $num_conditions,
208  'actions' => $num_actions,
209  'active' => $trigger['active'],
210  );
211 
212  if ($trigger['active']) $num_active_triggers++;
213  }
214 
215  ksort($trigger_info_sorted);
216 
217  $trigger_info_sorted['num_active_triggers'] = $num_active_triggers;
218  $trigger_info_sorted['num_triggers'] = $num_triggers;
219 
220  return $trigger_info_sorted;
221 
222  }//end _getTriggerInfo()
223 
224 
225 }//end class
226 ?>