Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_attribute_changed.inc
1 <?php
17 require_once dirname(dirname(__FILE__)).'/trigger_condition_asset_type/trigger_condition_asset_type.inc';
18 
32 {
33 
34 
63  public static function evaluate($settings, &$state)
64  {
65  if (empty($settings['asset_type'])) return FALSE;
66  if (empty($settings['attribute'])) return FALSE;
67 
68  if ((!$settings['inherit']) && (array_get_index($state, 'asset_type') != $settings['asset_type'])) {
69  // definitely not the right type
70  return FALSE;
71  }
72 
73  if (empty($state['asset'])) {
74  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
75  }
76 
77  if (!isset($state['asset_type'])) {
78  $state['asset_type'] = $state['asset']->type();
79  }
80 
81  $changed_attr = $state['event']['data'];
82 
83  if ($settings['inherit']) {
84  if ($state['asset'] instanceof $settings['asset_type']) {
85  return isset($changed_attr[$settings['attribute']]);
86  }
87  } else {
88  if ($state['asset_type'] == $settings['asset_type']) {
89  return isset($changed_attr[$settings['attribute']]);
90  }
91  }
92  return FALSE;
93 
94  }//end evaluate()
95 
96 
107  public static function getInterface($settings, $prefix, $write_access=FALSE)
108  {
109  $selected_type = array_get_index($settings, 'asset_type', 'page');
110  $am =& $GLOBALS['SQ_SYSTEM']->am;
111 
112  // asset type selector
113  ob_start();
114  if ($write_access) {
115  asset_type_chooser($prefix.'[type_code]', FALSE, Array('type_code' => $selected_type), NULL, TRUE, FALSE);
116  echo ' ( ';
117  check_box($prefix.'[inherit]', 1, array_get_index($settings, 'inherit'), '', 'id="'.$prefix.'_inherit" style="margin: 0px"');
118  echo ' ';
119  label(translate('or_inherited_types'), $prefix.'_inherit');
120  echo ') ';
121  } else {
122  echo '<b>'.$selected_type.'</b>';
123  if (array_get_index($settings, 'inherit')) {
124  echo ' '.translate('or_inherited_types').' ';
125  }
126  }
127  $asset_type_component = ob_get_contents();
128  ob_end_clean();
129 
130  // attribute selector
131  ob_start();
132  $attribute = array_get_index($settings, 'attribute', '');
133  if ($selected_type == '') {
134  echo '<b>['.translate('asset_type_not_selected').']</b>';
135  } else {
136  $attrs = $GLOBALS['SQ_SYSTEM']->am->getAssetTypeAttributes($selected_type, Array('name'));
137  if (empty($attrs)) {
138  echo '<b>['.translate('asset_type_no_attributes_found').']</b>';
139  } else {
140  if ($write_access) {
141  $attr_options = Array('' => '');
142  foreach ($attrs as $attr_name) {
143  $attr_options[$attr_name] = $attr_name;
144  }
145  combo_box($prefix.'[attribute]', $attr_options, FALSE, $attribute);
146  } else {
147  echo '<b>'.$attribute.'</b>';
148  }
149  }
150  }
151  $attribute_component = ob_get_contents();
152  ob_end_clean();
153 
154  return translate('trigger_attribute_changed', $asset_type_component, $attribute_component);
155 
156  }//end getInterface()
157 
158 
169  public static function processInterface(&$settings, $request_data)
170  {
171  if (empty($request_data)) {
172  return translate('trigger_input_data_error');
173  }
174 
175  $asset_type = array_get_index($request_data, 'type_code', FALSE);
176  if (!$asset_type) {
177  return translate('trigger_type_code_not_supplied');
178  }
179 
180  $settings['asset_type'] = $asset_type;
181  $settings['inherit'] = !empty($request_data['inherit']);
182  $settings['attribute'] = array_get_index($request_data, 'attribute', FALSE);
183 
184  return FALSE;
185 
186  }//end processInterface()
187 
188 
189 }//end class
190 
191 ?>