Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_status.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/general_occasional.inc';
18 
32 {
33 
34 
51  public static function evaluate($settings, &$state)
52  {
53  // grab the data we need to check the condition, if it's not already cached
54  // note that new state is modified and new data is available to other conditions
55  if (empty($state['asset'])) {
56  // grab the asset if assetid is given, but not the asset
57  if (empty($state['assetid'])) {
58  return FALSE;
59  } else {
60  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
61  }
62  }
63 
64  if (empty($settings['status'])) {
65  // if no settings, fail
66  return FALSE;
67  }
68 
69  // check the condition
70  if ($state['asset']->status == $settings['status']) {
71  return TRUE;
72  } else {
73  return FALSE;
74  }
75 
76  }//end evaluate()
77 
78 
89  public static function getInterface($settings, $prefix, $write_access=FALSE)
90  {
91  if (empty($settings['status'])) {
92  // set to default
93  $selected_status = SQ_STATUS_UNDER_CONSTRUCTION;
94  } else {
95  $selected_status = $settings['status'];
96  }
97 
98  $status_list = trigger_condition_status::_getStatusList();
99 
100  if (!$write_access) {
101  $form_element_extras = 'disabled="disabled"';
102  } else {
103  $form_element_extras = '';
104  }
105 
106  // begin buffering basic options
107  ob_start();
108  if ($write_access) {
109  combo_box($prefix.'[status]', $status_list, FALSE, $selected_status, NULL, $form_element_extras);
110  } else {
111  echo get_asset_status_icon($selected_status).'<strong>'. get_status_description($selected_status).'</strong>';
112  }
113  $basic_part_1 = ob_get_contents();
114  ob_end_clean();
115 
116  return translate('trigger_has_status_basic', $basic_part_1);
117 
118  }//end getInterface()
119 
120 
130  public static function processInterface(&$settings, $request_data)
131  {
132  $status = array_get_index($request_data, 'status', FALSE);
133  if (!$status) return 'No status selected';
134 
135  $status_list = trigger_condition_status::_getStatusList();
136 
137  // check if the status is valid
138  if (isset($status_list[$status])) {
139  $settings['status'] = $status;
140  return FALSE;
141  } else {
142  return translate('trigger_selected_status_invalid');
143  }
144 
145  }//end processInterface()
146 
147 
154  protected static function _getStatusList()
155  {
156  $status = Array();
157  foreach (get_constant_values('SQ_STATUS_') as $status_value) {
158  $status[$status_value] = get_status_description($status_value);
159  }
160  return $status;
161 
162  }//end _getStatusList()
163 
164 
165 }//end class
166 
167 ?>