Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_delete_future_status.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 
32 {
33 
34 
52  public static function execute($settings, &$state)
53  {
54  // check settings, status
55  if (empty($settings['status'])) {
56  // if no settings, fail
57  return FALSE;
58  }
59 
60  if (empty($state['asset'])) {
61  // grab the asset if assetid is given, but not the asset.
62  if (empty($state['assetid'])) {
63  return FALSE;
64  } else {
65  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
66  }
67  }
68  $assetid = $state['asset']->id;
69 
70  $cron_mgr = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
71  if (is_null($cron_mgr)) return FALSE;
72 
73  // nothing to process
74  $GLOBALS['SQ_SYSTEM']->am->includeAsset('cron_job_future_status');
75  $future_status_jobs = Cron_Job_Future_Status::getActiveJobs($state['asset']);
76  if (empty($future_status_jobs)) return TRUE;
77 
79  $jobids = Array();
80 
81  foreach ($future_status_jobs as $job) {
82  // Does it meet the conditions?
83  $status_desc = $job->statusName();
84  if ($status_desc != $status_list[$settings['status']]) {
85  continue;
86  }
87 
88  // Okidoki, let's delete them
89  if (!$cron_mgr->removeJob($job)) {
90  trigger_localised_error('CORE0261', E_USER_WARNING, $job->id);
91  } else {
92  $jobids[] = $job->id;
93  }
94  }
95 
96  return Array(
97  'jobids' => $jobids,
98  );
99 
100  }//end execute()
101 
102 
113  public static function getInterface($settings, $prefix, $write_access=FALSE)
114  {
115  if (empty($settings['status'])) {
116  // set to default
117  $selected_status = SQ_STATUS_UNDER_CONSTRUCTION;
118  } else {
119  $selected_status = $settings['status'];
120  }
121 
123 
124  if (!$write_access) {
125  $form_element_extras = 'disabled="disabled"';
126  } else {
127  $form_element_extras = '';
128  }
129 
130  ob_start();
131  echo translate('trigger_delete_future_status');
132  combo_box($prefix.'[status]', $status_list, FALSE, $selected_status, NULL, $form_element_extras);
133  $html = ob_get_contents();
134  ob_end_clean();
135 
136  return $html;
137 
138  }//end getInterface()
139 
140 
152  public static function processInterface(&$settings, $request_data)
153  {
154  // status
155  $status = array_get_index($request_data, 'status', NULL);
156  if (is_null($status)) {
157  return 'Status has not been specified';
158  }
159 
161 
162  // check if the status is valid
163  if (!isset($status_list[$status])) {
164  return 'Specified status is invalid';
165  }
166  $settings['status'] = $status;
167 
168  return FALSE;
169 
170  }//end processInterface()
171 
172 
181  protected static function _getStatusList()
182  {
183  $status = Array();
184  foreach (get_constant_values('SQ_STATUS_') as $status_value) {
185  $status[$status_value] = get_status_description($status_value);
186  }
187  return $status;
188 
189  }//end _getStatusList()
190 
191 
192 }//end class
193 
194 ?>