Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
trigger_action_clear_cache.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 
32 {
33 
34 
55  public static function execute($settings, &$state)
56  {
57  if (empty($state['asset'])) {
58  // grab the asset if assetid is given, but not the asset.
59  if (empty($state['assetid'])) {
60  return FALSE;
61  } else {
62  $state['asset'] = $GLOBALS['SQ_SYSTEM']->am->getAsset($state['assetid']);
63  }
64  }
65 
66  if (is_null($state['asset'])) return FALSE;
67 
68  // adds current asset to the todo list
69  $assetid = $state['asset']->id;
70  $todo_assetids = $settings['selected_assets'];
71  if ($settings['use_current_asset']) {
72  $todo_assetids[] = $assetid;
73  }
74  // tricky: empty string means include all asset types
75  $type_code = empty($settings['asset_types']) ? '' : $settings['asset_types'];
76 
77  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
78 
79  $vars = Array(
80  'assetid' => $todo_assetids,
81  'level' => $settings['level'],
82  'type_codes' => $type_code,
83  'delete_all' => 'no',
84  );
85  $status_errors = $hh->freestyleHipo('hipo_job_clear_cache', $vars);
86 
87 
88  return Array(
89  'assetid' => $assetid,
90  );
91 
92  }//end execute()
93 
94 
105  public static function getInterface($settings, $prefix, $write_access=FALSE)
106  {
107  // munge the prefix so that we can use the Cache Manager interfaces to paint/process
108  $new_prefix = str_replace('[', '_', $prefix);
109  $new_prefix = str_replace(']', '', $new_prefix);
110 
111  // level options
112  $level_options = Array(
113  'single' => translate('selected_asset'),
114  'dependants' => translate('selected_asset_and_dependants'),
115  'children' => translate('selected_asset_and_children'),
116  );
117 
118  // asset types options
119  $asset_types = $GLOBALS['SQ_SYSTEM']->am->getTypeList();
120  foreach ($asset_types as $type_code) {
121  $info = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code);
122  if ($info['allowed_access'] != 'system' && $info['instantiable']) {
123  $asset_types_options[$type_code] = $info['name'];
124  }
125  }
126  asort($asset_types_options);
127  $asset_types_options = array_reverse($asset_types_options, TRUE);
128  $asset_types_options[''] = '-- '.translate('all_asset_types').' --';
129  $asset_types_options = array_reverse($asset_types_options, TRUE);
130 
131  // initialise settings var
132  $settings['use_current_asset'] = isset($settings['use_current_asset']) ? $settings['use_current_asset'] : FALSE;
133  $settings['selected_assets'] = isset($settings['selected_assets']) ? $settings['selected_assets'] : Array();
134  $settings['level'] = isset($settings['level']) ? $settings['level'] : 'single';
135  $settings['asset_types'] = isset($settings['asset_types']) ? $settings['asset_types'] : Array();
136  if (empty($settings['asset_types'])) {
137  $settings['asset_types'] = Array(0 => '');
138  }
139 
140  // paint the edit interface
141  ob_start();
142  ?>
143  <table border="0">
144  <tr>
145  <td valign="top"><b><?php echo translate('trigger_clear_cache_current_asset'); ?></b></td>
146  <td valign="top" style="padding-bottom: 10px;"><?php
147  // current asset
148  if ($write_access) {
149  echo check_box($prefix.'[use_current_asset]', 1, $settings['use_current_asset']);
150  echo translate('trigger_clear_cache_include_current_asset');
151  } else {
152  echo '&nbsp; &nbsp;';
153  echo ($settings['use_current_asset']) ? translate('yes') : translate('no');
154  }
155  ?>
156  </td>
157  </tr>
158  <tr><?php
159  // selected assets/choose assets
160  if ($write_access) {
161  ?>
162  <td valign="top"><b><?php echo translate('trigger_clear_cache_choose_asset'); ?></b></td>
163  <td valign="top" style="padding-bottom: 10px;"><?php
164  echo multiple_asset_finder($new_prefix.'_select_assets', $settings['selected_assets']);
165  } else {
166  ?>
167  <td valign="top"><b><?php echo translate('trigger_clear_cache_choose_asset_selected'); ?></b></td>
168  <td valign="top" style="padding-bottom: 10px;"><?php
169  if (empty($settings['selected_assets'])) {
170  echo '&nbsp; &nbsp;'.translate('no_asset_selected');
171  } else {
172  ?><ul><?php
173  foreach ($settings['selected_assets'] as $selected_asset) {
174  ?><li><?php
175  echo get_asset_tag_line($selected_asset);
176  ?></li><?php
177  }
178  ?></ul><?php
179  }
180  }
181  ?>
182  </td>
183  </tr>
184  <tr>
185  <td valign="top"><b><?php echo translate('level'); ?></b></td>
186  <td valign="top" style="padding-bottom: 10px;"><?php
187  // level
188  if ($write_access) {
189  echo combo_box($new_prefix.'_level', $level_options, FALSE, $settings['level'], 0);
190  } else {
191  echo '&nbsp; &nbsp;'.$level_options[$settings['level']];
192  }
193  ?>
194  </td>
195  </tr>
196  <tr><?php
197  // selected asset types/asset types
198  if ($write_access) {
199  ?>
200  <td valign="top"><b><?php echo translate('asset_types'); ?></b></td>
201  <td valign="top" style="padding-bottom: 10px;"><?php echo combo_box($new_prefix.'_asset_types', $asset_types_options, TRUE, $settings['asset_types'], 8); ?></td>
202  <?php
203  } else {
204  ?>
205  <td valign="top"><b><?php echo translate('trigger_clear_cache_asset_types_selected'); ?></b></td>
206  <td valign="top" style="padding-bottom: 10px;"><?php
207  if (!empty($settings['asset_types'][0])) {
208  ?><ul><?php
209  foreach ($settings['asset_types'] as $type_code) {
210  ?><li><?php
211  echo get_asset_type_icon($type_code);
212  echo $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($type_code, 'name');
213  ?></li><?php
214  }
215  ?></ul><?php
216  } else {
217  echo '&nbsp; &nbsp;'.translate('all_asset_types');
218  }
219  ?>
220  </td><?php
221  }
222  ?>
223  </tr>
224  </table>
225  <?php
226  hidden_field($prefix.'[prefix]', $new_prefix);
227 
228  return ob_get_clean();
229 
230  }//end getInterface()
231 
232 
244  public static function processInterface(&$settings, $request_data)
245  {
246  $new_prefix = $request_data['prefix'];
247  $settings['prefix'] = $new_prefix;
248 
249  // we will combine current asset and selected assets into one todo list
250  $settings['use_current_asset'] = array_get_index($request_data, 'use_current_asset', FALSE);
251  $settings['selected_assets'] = Array();
252  if (isset($_POST[$new_prefix.'_select_assets']) && !empty($_POST[$new_prefix.'_asset_types'])) {
253  foreach ($_POST[$new_prefix.'_select_assets'] as $key => $array) {
254  // check for fields with no value
255  if ($array['assetid'] != 0) {
256  $settings['selected_assets'][] = $array['assetid'];
257  }
258  }
259  }
260 
261  // level
262  $settings['level'] = 'single';
263  if (isset($_POST[$new_prefix.'_level'])) {
264  $settings['level'] = $_POST[$new_prefix.'_level'];
265  }
266 
267  // selected asset types
268  if (isset($_POST[$new_prefix.'_asset_types']) && !empty($_POST[$new_prefix.'_asset_types'][0])) {
269  $settings['asset_types'] = $_POST[$new_prefix.'_asset_types'];
270  } else {
271  $settings['asset_types'] = Array();
272  }
273 
274  return FALSE;
275 
276  }//end processInterface()
277 
278 
288  public static function getLocks($settings, &$state)
289  {
290  return Array($state['assetid'] => Array('lookups'));
291 
292  }//end getLocks()
293 
294 
295 }//end class
296 
297 ?>