Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_condition_asset_type.inc
1 <?php
31 {
32 
33 
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 (!isset($state['asset_type'])) {
56  if (isset($state['asset'])) {
57  $state['asset_type'] = $state['asset']->type();
58  } else {
59  return FALSE;
60  }
61  }
62 
63 
64  if (empty($settings['asset_type'])) return FALSE;
65 
66 
67  $selected_types = array_get_index($settings, 'asset_type', Array('page'));
68  // backwards compatibility. previously you could only specify one type
69  if (!is_array($selected_types)) {
70  $selected_types = Array($selected_types);
71  }
72 
73  $descendant_flags = array_get_index($settings, 'descendants', Array(FALSE));
74  if (!is_array($descendant_flags)) {
75  $descendant_flags = Array($descendant_flags);
76  }
77 
78  foreach ($selected_types as $key => $type) {
79  if ($descendant_flags[$key]) {
80  $type_desc = $GLOBALS['SQ_SYSTEM']->am->getTypeDescendants($type, TRUE);
81  if (in_array($state['asset_type'], $type_desc)) {
82  return TRUE;
83  }
84  } else {
85  if ($type == $state['asset_type']) return TRUE;
86  }
87  }
88 
89 
90  return FALSE;
91 
92 
93  }//end evaluate()
94 
95 
106  public static function getInterface($settings, $prefix, $write_access=FALSE)
107  {
108  $selected_types = array_get_index($settings, 'asset_type', Array('page'));
109 
110  // backwards compatibility. previously you could only specify one type
111  if (!is_array($selected_types)) {
112  $selected_types = Array($selected_types);
113  }
114 
115  $descendant_flags = array_get_index($settings, 'descendants', Array(FALSE));
116  if (!is_array($descendant_flags)) {
117  $descendant_flags = Array($descendant_flags);
118  }
119 
120  ob_start();
121  if ($write_access) {
122  asset_type_chooser($prefix, TRUE, Array('type_code' => $selected_types, 'inherit' => $descendant_flags), NULL, FALSE, TRUE);
123  } else {
124  foreach ($selected_types as $key => $type) {
125  echo '<b>';
126  echo $type;
127  if ($descendant_flags[$key]) {
128  echo '&nbsp;('.translate('or_decendant_types').')';
129  }
130  echo '</b><br />';
131  }
132  }
133 
134  $interface = ob_get_contents();
135  ob_end_clean();
136 
137  return translate('trigger_asset_type', $interface);
138 
139  }//end getInterface()
140 
141 
152  public static function processInterface(&$settings, $request_data)
153  {
154  if (empty($request_data)) {
155  return translate('trigger_input_data_error');
156  }
157 
158  $asset_type = array_get_index($request_data, 'type_code', FALSE);
159  if (!$asset_type) {
160  return translate('trigger_type_code_not_supplied');
161  }
162 
163  // descendants is set to either '1' or not at all
164  $descendants = array_get_index($request_data, 'inherit', FALSE);
165 
166  $settings['asset_type'] = $asset_type;
167  $settings['descendants'] = $descendants;
168 
169  return FALSE;
170 
171  }//end processInterface()
172 
173 
184  public static function setHash(&$settings, &$hash)
185  {
186  if (isset($settings['asset_type']) && isset($settings['descendants'])) {
187  foreach ($settings['asset_type'] as $key => $type) {
188  if (empty($type)) continue;
189  $hash->setAssetType($type, ($settings['descendants'][$key] == '1' ? TRUE : FALSE));
190  }
191  }
192 
193  return FALSE;
194 
195  }//end setHash()
196 
197 
198 }//end class
199 
200 ?>