Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_status_change_to.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['statii'])) {
65  // if no settings, fail
66  return FALSE;
67  }
68 
69  // check the condition
70  if (in_array($state['event']['data']['new_status'], $settings['statii'])) return TRUE;
71 
72  return FALSE;
73 
74  }//end evaluate()
75 
76 
87  public static function getInterface($settings, $prefix, $write_access=FALSE)
88  {
89  if (empty($settings['statii'])) {
90  // set to default
91  $selected_status = Array();
92  } else {
93  $selected_status = $settings['statii'];
94  }
95 
96  $status_list = self::_getStatusList();
97 
98  if (!$write_access) {
99  $form_element_extras = 'disabled="disabled"';
100  } else {
101  $form_element_extras = '';
102  }
103 
104  // begin buffering basic options
105  ob_start();
106  if ($write_access) {
107  combo_box($prefix.'[statii]', $status_list, TRUE, $selected_status, NULL, $form_element_extras);
108  } else {
109  echo '<table>';
110  foreach($selected_status as $print_status) {
111  echo '<tr><td>'.get_asset_status_icon($print_status).'<strong>'. get_status_description($print_status).'</strong></td></tr>';
112  }
113  echo '</table>';
114  }
115  $basic_part_1 = ob_get_contents();
116  ob_end_clean();
117 
118  return translate('trigger_status_change_to_basic', $basic_part_1);
119 
120  }//end getInterface()
121 
122 
132  public static function processInterface(&$settings, $request_data)
133  {
134  $statii = array_get_index($request_data, 'statii', Array());
135  if (!$statii) return 'No status selected';
136 
137  $status_list = self::_getStatusList();
138 
139  // check if the status is valid
140  foreach($statii as $status) {
141  if (isset($status_list[$status])) {
142  $settings['statii'][] = $status;
143  } else {
144  return translate('trigger_selected_status_invalid');
145  }
146  }
147 
148  return FALSE;
149 
150  }//end processInterface()
151 
152 
159  protected static function _getStatusList()
160  {
161  $status = Array();
162  foreach (get_constant_values('SQ_STATUS_') as $status_value) {
163  $status[$status_value] = get_status_description($status_value);
164  }
165  return $status;
166 
167  }//end _getStatusList()
168 
169 
170 }//end class
171 
172 ?>