Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
hipo_job_trigger_batch_events.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/hipo/hipo_job.inc';
18 
38 {
39 
40 
46  function HIPO_Job_Trigger_Batch_Events($code_name='')
47  {
48  $this->HIPO_Job($code_name);
49 
50  }//end constructor
51 
52 
62  public static function paintConfig(&$o, $class, $write_access)
63  {
64  // threshhold HIPO config entry
65  $o->openField(translate('trigger_execution_threshold'));
66 
67  if ($write_access) {
68  text_box($class.'[SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD]', SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD, 0);
69  } else {
70  echo SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD;
71  }
72 
73  $o->closeField();
74 
75  }//end paintConfig()
76 
77 
84  public static function getConfigVars()
85  {
86  return Array(
87  'SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD' => Array('editable' => 1, 'default' => 0),
88  );
89 
90  }//end getConfigVars()
91 
92 
103  function getCodeName()
104  {
105  return parent::getCodeName().'-u'.$GLOBALS['SQ_SYSTEM']->currentUserId().'-a'.$this->_running_vars['codename_target'].'-'.$this->_running_vars['codename_propagate'];
106 
107  }//end getCodeName()
108 
109 
116  function getHipoName()
117  {
118  return translate('hipo_name_trigger_batch_events');
119 
120  }//end getHipoName()
121 
122 
131  {
132  return Array(
133  Array(
134  'name' => translate('hipo_processing_assets'),
135  'function_call' => Array(
136  'process_function' => 'processAssets',
137  ),
138  'running_mode' => 'server',
139  'auto_step' => true,
140  'allow_cancel' => true,
141  'percent_done' => 0,
142  'complete' => false,
143  'message' => '',
144  ),
145  );
146 
147  }//end getInitialStepData()
148 
149 
160  {
161  if (SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD == 0) {
162  return 0;
163  }
164 
165  if (empty($this->_running_vars['assets'])) return 0;
166 
167  return (($this->_running_vars['total_steps'] / SQ_HIPO_TRIGGER_BATCH_EVENTS_THRESHOLD) * 100);
168 
169  }//end getThresholdPercentageRequired()
170 
171 
178  function freestyle()
179  {
180  while (!empty($this->_running_vars['assets'])) {
181  if (!$this->processAssets($this->_steps[0], get_class($this))) {
182  return false;
183  }
184  }
185  return true;
186 
187  }//end freestyle()
188 
189 
196  function prepare()
197  {
198  // to start the batch events, we need to have asset ids and the events to fire on each
199  if (empty($this->_running_vars['assets']) || empty($this->_running_vars['events'])) {
200  trigger_localised_error('HIPO0002', E_USER_WARNING);
201  return false;
202  }
203 
204  // total steps is the number of assets * the number of events to broadcast for each.
205  $this->_running_vars['total_steps'] = count($this->_running_vars['assets']) * count($this->_running_vars['events']);
206  $this->_running_vars['step_value'] = (int) (100 / $this->_running_vars['total_steps']);
207 
208  if (empty($this->_running_vars['event_parameters'])) $this->_running_vars['event_parameters'] = NULL;
209 
210  return parent::prepare();
211 
212  }//end prepare()
213 
214 
224  function processAssets(&$step_data, $prefix)
225  {
226  if (empty($this->_running_vars['current_events'])) {
227  if (empty($this->_running_vars['assets'])) {
228  // update percentages, set completed
229  $step_data['complete'] = true;
230  $step_data['percent_done'] = 100;
231  return true;
232  }
233  $this->_running_vars['current_events'] = $this->_running_vars['events'];
234  $this->_running_vars['current_assetid'] = array_pop($this->_running_vars['assets']);
235  }
236 
237  $current_event = array_pop($this->_running_vars['current_events']);
238  $asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($this->_running_vars['current_assetid']);
239  $GLOBALS['SQ_SYSTEM']->broadcastTriggerEvent($current_event, $asset, $this->_running_vars['event_parameters']);
240 
241  $step_data['message'] = translate('hipo_broadcast_event', $current_event, $this->_running_vars['current_assetid']);
242  $step_data['percent_done'] += $this->_running_vars['step_value'];
243  $step_data['complete'] = false;
244 
245  return true;
246 
247  }//end processAssets()
248 
249 
250 }//end class
251 
252 ?>