Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_set_status.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 require_once SQ_CORE_PACKAGE_PATH.'/system/triggers/trigger_action/trigger_action.inc';
19 
33 {
34 
35 
58  public static function execute($settings, &$state)
59  {
60  // check required settings
61  if (empty($settings['status'])) return FALSE;
62 
63  if (empty($state['asset'])) {
64  // grab the asset if assetid is given, but not the asset.
65  if (empty($state['assetid'])) {
66  return FALSE;
67  } else {
68  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
69  }
70  }
71 
72  // assume dependant_parents is turned off, unless told otherwise
73  if (!isset($settings['dependant_parents'])) {
74  $settings['dependant_parents'] = FALSE;
75  }
76 
77  // if dependant_parents is turned on, look for all our dependant parents
78  // and change their statuses, instead of our own
79  $target_assets = Array();
80  if ($settings['dependant_parents']) {
81  // get only the top level
82  $target_assets = $GLOBALS['SQ_SYSTEM']->am->getDependantParents($state['asset']->id, '', TRUE, FALSE);
83  if (!empty($target_assets)) {
84  // returns Array(0 => Assetid), so flip the array
85  $target_assets = array_flip($target_assets);
86  foreach ($target_assets as $assetid => $null) {
87  $target_assets[$assetid] = $GLOBALS['SQ_SYSTEM']->am->getAsset($assetid);
88  }
89  }
90  }
91 
92  if (empty($target_assets) || !$settings['dependant_parents']) {
93  $target_assets[$state['asset']->id] =& $state['asset'];
94  }
95 
96 
97  foreach ($target_assets as $target_assetid => $target_asset) {
98 
99  // couldn't load asset, fail
100  if (is_null($target_asset)) return FALSE;
101 
102  $old_status = $target_asset->status;
103  if ($old_status != $settings['status']) {
104  $available_statuses = $target_asset->getAvailableStatii();
105 
106  if (!isset($available_statuses[$settings['status']])) {
107  return FALSE;
108  }
109 
110  // need to use a hipo job to set status (handles dependant children)
111  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
112  $vars = Array(
113  'assetid' => $target_assetid,
114  'new_status' => $settings['status'],
115  );
116  $status_errors = $hh->freestyleHipo('hipo_job_edit_status', $vars);
117 
118  if (!empty($status_errors)) return FALSE;
119  }
120 
121  }//end foreach ($target_assets)
122 
123 
124  return Array(
125  'assetid' => $state['asset']->id,
126  'affected_assetids' => $target_assets,
127  'old_status' => $old_status,
128  'new_status' => $state['asset']->status,
129  );
130 
131  }//end execute()
132 
133 
144  public static function getInterface($settings, $prefix, $write_access=FALSE)
145  {
146  if (empty($settings['status'])) {
147  // set to default
148  $selected_status = SQ_STATUS_UNDER_CONSTRUCTION;
149  } else {
150  $selected_status = $settings['status'];
151  }
152 
154 
155  if (!$write_access) {
156  $form_element_extras = 'disabled="disabled"';
157  } else {
158  $form_element_extras = '';
159  }
160 
161  ob_start();
162  combo_box($prefix.'[status]', $status_list, FALSE, $selected_status, NULL, $form_element_extras);
163  $basic_part_1 = ob_get_contents();
164  ob_end_clean();
165 
166  ob_start();
167  $dependant_parents = array_get_index($settings, 'dependant_parents', FALSE);
168  if ($write_access) {
169  check_box($prefix.'[dependant_parents]', 1, $dependant_parents);
170  } else {
171  echo '<img src="'.sq_web_path('lib').'/web/images/'.($dependant_parents ? 'tick' : 'cross').'.gif" alt="'.($dependant_parents ? translate('yes') : translate('no')).'" /> ';
172  }
173  $basic_part_2 = ob_get_contents();
174  ob_end_clean();
175 
176 
177  return translate('trigger_set_status', $basic_part_1, $basic_part_2);
178 
179  }//end getInterface()
180 
181 
193  public static function processInterface(&$settings, $request_data)
194  {
195  // dependant_parents
196  $settings['dependant_parents'] = array_get_index($request_data, 'dependant_parents', FALSE);
197 
198  // status
199  $status = array_get_index($request_data, 'status', NULL);
200  if (is_null($status)) {
201  return 'Status has not been specified';
202  }
203 
205 
206  // check if the status is valid
207  if (!isset($status_list[$status])) {
208  return 'Specified status is invalid';
209  }
210  $settings['status'] = $status;
211 
212  return FALSE;
213 
214  }//end processInterface()
215 
216 
223  public static function _getStatusList()
224  {
225  $status = Array();
226  foreach (get_constant_values('SQ_STATUS_') as $status_value) {
227  $status[$status_value] = get_status_description($status_value);
228  }
229  return $status;
230 
231  }//end _getStatusList()
232 
233 
234 }//end class
235 
236 ?>