Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
search_manager_edit_fns.inc
1 <?php
17 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
18 
32 {
33 
34 
40  function __construct()
41  {
42  parent::__construct();
43  unset($this->static_screens['settings']);
44  unset($this->static_screens['preview']);
45  unset($this->static_screens['lookupValues']);
46  unset($this->static_screens['metadata']);
47  unset($this->static_screens['metadataSchemas']);
48  unset($this->static_screens['workflow']);
49  unset($this->static_screens['tagging']);
50  unset($this->static_screens['dependants']);
51  unset($this->static_screens['linking']);
52  unset($this->static_screens['roles']);
53  unset($this->static_screens['permissions']);
54  unset($this->static_screens['layouts']);
55 
56  }//end constructor
57 
58 
69  function paintAssetWeights(&$asset, &$o, $prefix)
70  {
71  $customised = array_keys($asset->getAssetWeightings());
72  return $this->_paintWeightInterface($asset, $o, $prefix, 'asset', $customised);
73 
74  }//end paintAssetWeights()
75 
76 
87  function processAssetWeights(&$asset, &$o, $prefix)
88  {
89  return $this->_processWeights($asset, $o, $prefix, 'asset');
90 
91  }//end processAssetWeights()
92 
93 
104  function paintAssetTreeWeights(&$asset, &$o, $prefix)
105  {
106  $write_access = $asset->writeAccess('attributes');
107  $assetid = $this->_getCurrentCustomisation($prefix, 'asset_tree');
108 
109  $global_customised = $asset->getAssetTreeWeightings();
110  // remove the root folder from the weightings as these are the global weightings
111  $root_folder_assetid = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('root_folder');
112  if (isset($global_customised[$root_folder_assetid])) {
113  unset($global_customised[$root_folder_assetid]);
114  }
115 
116  $this->_paintCurrentCustomisations($asset, $o, $prefix, array_keys($global_customised), 'asset');
117  $this->_paintWeightingSourceInterface($asset, $o, $prefix, 'asset');
118 
119  if (!empty($assetid)) {
120  return $this->_paintTreeWeightInterface($asset, $o, $prefix, $assetid);
121  }
122 
123  return $write_access;
124 
125  }//end paintAssetTreeWeights()
126 
127 
138  function processAssetTreeWeights(&$asset, &$o, $prefix)
139  {
140  if ($this->_usingGoButton($prefix)) return FALSE;
141  return $this->_processWeights($asset, $o, $prefix, 'asset_tree');
142 
143  }//end processAssetTreeWeights()
144 
145 
156  function paintMetadataWeights(&$asset, &$o, $prefix)
157  {
158  $weights = $asset->getMetadataWeightings();
159  return $this->_paintMetadataWeightInterface($asset, $o, $prefix, $weights);
160 
161  }//end paintMetadataWeights()
162 
163 
174  function processMetadataWeights(&$asset, &$o, $prefix)
175  {
176  $weights = $asset->getMetadataWeightings();
177  $this->_processMetadataWeights($prefix, $weights);
178  $asset->saveMetadataWeightings($weights);
179 
180  return FALSE;
181 
182  }//end processMetadataWeights()
183 
184 
195  function paintGlobalWeights(&$asset, &$o, $prefix)
196  {
197  // for global weightings we store them as tree weightings under the root folder assetid
198  $root_folder_assetid = $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('root_folder');
199  $global_customised = $asset->getAssetTreeWeightings($root_folder_assetid);
200  $customised = (isset($global_customised['type_weights'])) ? array_keys($global_customised['type_weights']) : Array();
201  $this->_paintCurrentCustomisations($asset, $o, $prefix, $customised, 'asset_type');
202  return $this->_paintTreeWeightInterface($asset, $o, $prefix, $root_folder_assetid, FALSE);
203 
204  }//end paintGlobalWeights()
205 
206 
217  function processGlobalWeights(&$asset, &$o, $prefix)
218  {
219  if ($this->_usingGoButton($prefix)) return FALSE;
220  return $this->_processWeights($asset, $o, $prefix, 'asset_tree');
221 
222  }//end processGlobalWeights()
223 
224 
237  function _paintTreeWeightInterface(&$asset, &$o, $prefix, $assetid, $paint_customised=TRUE)
238  {
239  $write_access = $asset->writeAccess('attributes');
240  $tree_type = array_get_index($_POST, $prefix.'_selected_tree_type', '');
241 
242  if ($this->_customisationsRemoved($prefix, 'asset_tree')) {
243  return $write_access;
244  }
245  $o->addHiddenField($prefix.'_current_assetid', $assetid);
246  // check to see if this tree has been customised before - if so
247  // we can bring up the details for this tree
248  $weights = $asset->getAssetTreeWeightings($assetid);
249  $tree_type = array_get_index($_POST, $prefix.'_selected_tree_type', '');
250 
251  // section opened by xml
252  $o->openField(translate('sch_customise').'?');
253  $types = Array(
254  'asset_type' => translate('asset_types'),
255  'metadata' => translate('metadata'),
256  );
257  combo_box($prefix.'_selected_tree_type', $types, FALSE, $tree_type);
258  echo '&nbsp;';
259  submit_button($prefix.'_selected_tree_type_go', translate('go'), 'main_form.submit()');
260  $o->closeField();
261 
262  // check to see if they have chosen to customise a different tree asset than the current
263  // one, if so we want to clear the current interface from here down
264  $key = array_get_index($_POST, $prefix.'_current_assetid', '');
265  if (!empty($key) && $this->_getCurrentCustomisation($prefix, 'asset') != $key) {
266  return $write_access;
267  }
268 
269  if (!empty($tree_type)) {
270  if ($tree_type == 'asset_type') {
271  $type_code = $this->_getCurrentCustomisation($prefix, 'asset_type');
272  if ($paint_customised) {
273  $customised = isset($weights['type_weights']) ? array_keys($weights['type_weights']) : Array();
274  } else {
275  $customised = Array();
276  }
277  $weights = isset($weights['type_weights'][$type_code]) ? $weights['type_weights'][$type_code] : Array();
278  return $this->_paintWeightInterface($asset, $o, $prefix, $tree_type, $customised, $weights);
279  } else {
280  $metadata_weights = array_get_index($weights, 'metadata_weights', Array());
281  return $this->_paintMetadataWeightInterface($asset, $o, $prefix, $metadata_weights);
282  }
283  }
284  return $write_access;
285 
286  }//end _paintTreeWeightInterface()
287 
288 
300  function _paintAssetWeightInterface(&$asset, &$o, $prefix, $weights)
301  {
302  $write_access = $asset->writeAccess('attributes');
303  $o->openSection(translate('sch_asset_weightings'));
304  $o->openField('');
305  ?>
306  <table class="sq-backend-table" style="width:50%">
307  <tr>
308  <td width="250" class="sq-backend-table-header"><?php echo translate('sch_weighting_component'); ?></td>
309  <td class="sq-backend-table-header"><?php echo translate('sch_weighting'); ?></td>
310  <td class="sq-backend-table-header"><?php echo translate('sch_indexed'); ?>?</td>
311  </tr>
312  <?php
313 
314  $components = $asset->getIndexableAssetComponents();
315 
316  foreach ($components as $comp => $name) {
317  $weight = (isset($weights[$comp]['weight'])) ? $weights[$comp]['weight'] : 1;
318  $indexed = (isset($weights[$comp]['indexed'])) ? $weights[$comp]['indexed'] : 1;
319  ?>
320  <tr>
321  <td class="sq-backend-table-cell">
322  <?php echo $name; ?>
323  </td>
324  <td class="sq-backend-table-cell">
325  <?php
326  if ($write_access) {
327  text_box($prefix.'_asset_weights['.$comp.'][weight]', $weight, 5);
328  } else {
329  echo $weight;
330  }
331  ?>
332  </td>
333  <td class="sq-backend-table-cell">
334  <?php
335  if ($write_access) {
336  check_box($prefix.'_asset_weights['.$comp.'][indexed]', 1, $indexed);
337  } else {
338  echo ($indexed) ? translate('yes') : translate('no');
339  }
340  ?>
341  </td>
342  </tr>
343  <?php
344  }
345  ?>
346  </table>
347  <?php
348  $o->closeField();
349  $o->closeSection();
350 
351  return $write_access;
352 
353  }//end _paintAssetWeightInterface()
354 
355 
368  function _paintAttributeWeightInterface(&$asset, &$o, $prefix, $weights, $type_code)
369  {
370  $write_access = $asset->writeAccess('attributes');
371  $attrs = $asset->getIndexableAttributes($type_code);
372 
373  if (!empty($attrs)) {
374  $o->openSection(translate('sch_attribute_weightings'));
375  $o->openField('');
376  ?>
377  <table class="sq-backend-table" style="width:50%">
378  <tr>
379  <td width="250" class="sq-backend-table-header"><?php echo translate('sch_weighting_attribute'); ?></td>
380  <td class="sq-backend-table-header"><?php echo translate('sch_weighting'); ?></td>
381  <td class="sq-backend-table-header"><?php echo translate('sch_indexed'); ?>?</td>
382  </tr>
383  <?php
384 
385  foreach ($attrs as $name => $info) {
386 
387  // don't accept weightings for names and shortnames as we have these
388  // as asset components
389  if ($name == 'name' || $name == 'short_name') {
390  continue;
391  }
392 
393  $type = $info['type'];
394  $weight = (isset($weights[$name]['weight'])) ? $weights[$name]['weight'] : 1;
395  $indexed = (isset($weights[$name]['indexed'])) ? $weights[$name]['indexed'] : 1;
396  ?>
397  <tr>
398  <td class="sq-backend-table-cell">
399  <?php echo ucwords(str_replace('_', ' ', $name)); ?>
400  </td>
401  <td class="sq-backend-table-cell">
402  <?php
403  if ($write_access) {
404  text_box($prefix.'_attr_weights['.$name.'][weight]', $weight, 5);
405  } else {
406  echo $weight;
407  }
408  ?>
409  </td>
410  <td class="sq-backend-table-cell">
411  <?php
412  if ($write_access) {
413  check_box($prefix.'_attr_weights['.$name.'][indexed]', 1, $indexed);
414  } else {
415  echo ($indexed) ? translate('yes') : translate('no');
416  }
417  ?>
418  </td>
419  </tr>
420  <?php
421  }//end foreach attr
422  ?>
423  </table>
424  <?php
425  $o->closeField();
426  $o->closeSection();
427  }//end if !empty(attrs)
428 
429  return $write_access;
430 
431  }//end _paintAttributeWeightInterface()
432 
433 
445  function _paintMetadataWeightInterface(&$asset, &$o, $prefix, $weights)
446  {
447  $write_access = $asset->writeAccess('attributes');
448  $valid_types = Array(
449  'metadata_schema' => 'I',
450  'metadata_section' => 'I',
451  'metadata_field' => 'D',
452  );
453  if ($write_access) {
454  $o->openSection(translate('sch_metadata_weightings'));
455  $o->openField('');
456  ?>
457  <table class="sq-backend-table" style="width:60%">
458  <tr>
459  <td class="sq-backend-table-header"><?php echo translate('sch_metadata_asset'); ?></td>
460  <td class="sq-backend-table-cell">
461  <?php asset_finder($prefix.'_metadata_asset', 0, $valid_types); ?>
462  </td>
463  </tr>
464  <tr>
465  <td class="sq-backend-table-header"><?php echo translate('sch_weighting'); ?></td>
466  <td class="sq-backend-table-cell">
467  <?php text_box($prefix.'_metadata_weight', 1, 5); ?>
468  </td>
469  </tr>
470  </table>
471  <?php
472  $o->closeField();
473  $o->closeSection();
474  }
475 
476  $o->openSection(translate('sch_metadata_asset_weightings'));
477  $o->openField('');
478  if (!empty($weights)) {
479  ?>
480  <table class="sq-backend-table" style="width:60%">
481  <tr>
482  <td class="sq-backend-table-header"><?php echo translate('assetid'); ?></td>
483  <td class="sq-backend-table-header"><?php echo translate('sch_metadata_asset_name'); ?></td>
484  <td class="sq-backend-table-header"><?php echo translate('asset_type'); ?></td>
485  <td class="sq-backend-table-header"><?php echo translate('sch_weighting'); ?></td>
486  <td class="sq-backend-table-header"><?php echo translate('sch_indexed'); ?>?</td>
487  <?php
488  if ($write_access) {
489  echo '<td class="sq-backend-table-header">'.translate('sch_remove').'?</td>';
490  }
491  ?>
492  </tr>
493  <?php
494 
495  foreach ($weights as $assetid => $info) {
496 
497  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($info['type_code'], 'name');
498  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($assetid), Array(), TRUE, 'name');
499  $indexed = (isset($weights[$assetid]['indexed'])) ? $weights[$assetid]['indexed'] : 1;
500  $asset_name = !empty($asset_info[$assetid]) ? $asset_info[$assetid] : "<span style='color:red'>(".translate('asset_not_found_no_id').")</span>";
501  ?>
502  <tr>
503  <td class="sq-backend-table-cell">
504  <?php echo $assetid; ?>
505  </td>
506  <td class="sq-backend-table-cell">
507  <?php echo $asset_name; ?>
508  </td>
509  <td class="sq-backend-table-cell" border="0">
510  <?php echo $type_name; ?>
511  </td>
512  <td class="sq-backend-table-cell">
513  <?php
514  if ($write_access) {
515  text_box($prefix.'_metadata_assets['.$assetid.'][weight]', $info['weight'], 5);
516  } else {
517  echo $info['weight'];
518  }
519  ?>
520  </td>
521  <td class="sq-backend-table-cell">
522  <?php
523  if ($write_access) {
524  echo check_box($prefix.'_metadata_assets['.$assetid.'][indexed]', 1, $indexed);
525  } else {
526  echo ($indexed) ? translate('yes') : translate('no');
527  }
528  ?>
529  </td>
530  <?php
531  if ($write_access) {
532  echo '<td class="sq-backend-table-cell">';
533  echo check_box($prefix.'_metadata_assets['.$assetid.'][remove]', 1, FALSE);
534  echo '</td>';
535  }
536  ?>
537  </tr>
538  <?php
539  }//end foreach weights
540  ?>
541  </table>
542  <?php
543  } else {
544  echo translate('sch_no_metadata_customised');
545  }
546  $o->closeField();
547  $o->closeSection();
548 
549  return $write_access;
550 
551  }//end _paintMetadataWeightInterface()
552 
553 
565  function _paintAssetTypeChooser($field_name, $selected_type_code)
566  {
567  $asset_types = $GLOBALS['SQ_SYSTEM']->am->getAssetTypes(TRUE);
568 
569  $all_types = Array();
570  foreach ($asset_types as $type_code => $info) {
571  $all_types[$type_code] = $info['name'];
572  $type_anc = $GLOBALS['SQ_SYSTEM']->am->getTypeAncestors($type_code);
573 
574  foreach ($type_anc as $anc_type_code) {
575  if ($anc_type_code == 'asset') continue;
576  // save on db calls if we have this ancestor already
577  if (!in_array($anc_type_code, array_keys($all_types))) {
578  $all_types[$anc_type_code] = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($anc_type_code, 'name');
579  }
580  }
581  }
582  $all_types = array_unique($all_types);
583  arsort($all_types);
584  $all_types['asset'] = '-- '.translate('sch_all_asset_types').' --';
585  $all_types[''] = '';
586  $all_types = array_reverse($all_types);
587 
588  combo_box($field_name, $all_types, FALSE, $selected_type_code);
589  echo '&nbsp;';
590  submit_button($field_name.'_go', translate('go'), 'main_form.submit()');
591 
592  }//end _paintAssetTypeChooser()
593 
594 
607  function _paintWeightingSourceInterface(&$asset, &$o, $prefix, $screen, $field_suffix='')
608  {
609  $write_access = $asset->writeAccess('attributes');
610  if ($screen == 'asset_type') {
611  $o->openField(translate('sch_choose_type_code'));
612  $current_customisation = $this->_getCurrentCustomisation($prefix, 'asset_type');
613  if ($write_access) {
614  $this->_paintAssetTypeChooser($prefix.'_selected_type_code'.$field_suffix, $current_customisation);
615  } else {
616  if (!empty($current_customisation)) {
617  if ($current_customisation == 'asset') {
618  echo translate('sch_all_asset_types');
619  } else {
620  echo $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($current_customisation, 'name');
621  }
622  }
623  }
624  $o->closeField();
625  } else if ($screen == 'asset') {
626  if ($write_access) {
627  $o->openField(translate('sch_choose_assetid'));
628  $current_customisation = $this->_getCurrentCustomisation($prefix, 'asset');
629  asset_finder($prefix.'_selected_assetid'.$field_suffix, $current_customisation, Array());
630  $o->closeField();
631  }
632  }
633 
634  }//end _paintWeightingSourceInterface()
635 
636 
649  function _paintCurrentCustomisations(&$asset, &$o, $prefix, $weights, $screen)
650  {
651  $post_field = $this->_getPostField($screen);
652  $current_key = $this->_getCurrentCustomisation($prefix, $screen);
653 
654  if (empty($weights)) return;
655  $write_access = $asset->writeAccess('attributes');
656  $o->openField('');
657  $o->openSection('Current customisations');
658  $o->openField('');
659  ?>
660  <table class="sq-backend-table" style="width:60%">
661  <tr>
662  <?php
663  // only print this header if we are printing non asset_type screens
664  if ($screen != 'asset_type') {
665  ?><td class="sq-backend-table-header"><?php echo translate('assetid'); ?></td><?php
666  }
667  $type_col_name = ($screen == 'asset') ? 'asset_name' : 'asset_type';
668  ?>
669  <td class="sq-backend-table-header"><?php echo translate($type_col_name); ?></td>
670  <?php
671  if ($write_access) {
672  echo '<td class="sq-backend-table-header">'.translate('sch_remove').'?</td>';
673  }
674  ?>
675  </tr>
676  <?php
677  foreach ($weights as $key) {
678  // highlight the current table row begin customised
679  $css_class = 'sq-backend-table-cell';
680  if ($key == $current_key) $css_class .= '-alt';
681 
682  // when we click on a customisation, set a hidden field to the
683  // key that we are customising and submit the screen to save any options
684  // that have been changed
685  $field = $prefix.'_customise_'.$post_field;
686  $o->addHiddenField($field, '');
687  $src = 'Javascript: document.getElementById(\''.$field.'\').value = \''.$key.'\';';
688  $src .= 'main_form.submit()';
689  ?>
690  <tr>
691  <?php
692  if ($screen != 'asset_type') $key_name = $key; // assetid
693  $type_name = $this->_getDisplayName($key, $screen);
694 
695  // we only paint the section for the assetid if we are
696  // printing non-asset_type screens
697  if ($screen != 'asset_type') {
698  ?>
699  <td class="<?php echo $css_class; ?>">
700  <?php echo $key_name; ?>
701  </td>
702  <?php
703  }
704  ?>
705  <td class="<?php echo $css_class; ?>">
706  <a href="<?php echo $src?>"><?php echo $type_name; ?></a>
707  </td>
708  <?php
709  if ($write_access) {
710  ?>
711  <td class="<?php echo $css_class; ?>">
712  <?php echo check_box($field.'_remove['.$key.']', 1, FALSE); ?>
713  </td>
714  <?php
715  }
716  ?>
717  </tr>
718  <?php
719  }//end foreach
720  ?>
721  </table>
722  <?php
723  $o->closeField();
724  $o->closeSection();
725  $o->closeField();
726 
727  }//end _paintCurrentCustomisations()
728 
729 
739  function _getDisplayName($key, $screen)
740  {
741  if (empty($key)) return '';
742 
743  if ($screen != 'asset_type') {
744  $info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($key), Array(), TRUE);
745  $type_name = $info[$key]['name'];
746  } else {
747  // if the key is 'asset' then we are processing all asset types
748  if ($key != 'asset') {
749  $type_name = $GLOBALS['SQ_SYSTEM']->am->getTypeInfo($key, 'name');
750  } else {
751  $type_name = translate('sch_all_asset_types');
752  }
753  }
754  return $type_name;
755 
756  }//end _getDisplayName()
757 
758 
768  function _getCurrentCustomisation($prefix, $screen)
769  {
770  $post_field = $this->_getPostField($screen);
771  $key = array_get_index($_POST, $prefix.'_selected_'.$post_field, '');
772 
773  // if the screen requires an asset finder, extract the
774  // assetid into $key from the info posted from the asset finder
775  if ($post_field == 'assetid') {
776  $key = isset($key['assetid']) ? $key['assetid'] : '';
777  }
778  // if there was nothing selected to customise, check for a current customisation in process
779  if (empty($key)) {
780  $key = array_get_index($_POST, $prefix.'_current_'.$post_field, '');
781  }
782 
783  // check to see if a current customisation was selected
784  if (isset($_POST[$prefix.'_customise_'.$post_field]) && !empty($_POST[$prefix.'_customise_'.$post_field])) {
785  $key = $_POST[$prefix.'_customise_'.$post_field];
786  }
787  return $key;
788 
789  }//end _getCurrentCustomisation()
790 
791 
800  function _getPostField($screen)
801  {
802  $post_fields = Array(
803  'asset_tree' => 'assetid',
804  'asset' => 'assetid',
805  'asset_type' => 'type_code',
806  'metadata' => 'assetid',
807  );
808  return $post_fields[$screen];
809 
810  }//end _getPostField()
811 
812 
827  function _paintWeightInterface(&$asset, &$o, $prefix, $screen, $customised=Array(), $weights=NULL)
828  {
829  $write_access = $asset->writeAccess('attributes');
830  $post_field = $this->_getPostField($screen);
831  $key = $this->_getCurrentCustomisation($prefix, $screen);
832 
833  // section opened by xml
834  $this->_paintCurrentCustomisations($asset, $o, $prefix, $customised, $screen);
835  $this->_paintWeightingSourceInterface($asset, $o, $prefix, $screen);
836  $o->closeSection();
837 
838  // if any customisations have been removed, dont show the weighting interface
839  // as the previous interface shown may have been for a removed customisation
840  if ($this->_customisationsRemoved($prefix, $screen)) {
841  return $write_access;
842  }
843 
844  $o->openSection(translate('sch_'.$screen.'_management'));
845  $o->openField('');
846  if (!empty($key)) {
847  // obtain the current weightings for this screen
848  $fn = 'get'.str_replace('_', '', $screen).'weightings';
849  if (is_null($weights)) $weights = $asset->$fn($key);
850 
851  if ($post_field == 'type_code') {
852  $type_code = $key;
853  } else {
854  $asset_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($key), Array(), TRUE);
855  $type_code = $asset_info[$key]['type_code'];
856  }
857 
858  $o->openField(translate('sch_indexing_enabled'));
859 
860  if (isset($weights['indexed'])) {
861  $indexed = $weights['indexed'];
862  } else {
863  $indexed = 1;
864  }
865  $options = Array(
866  1 => translate('yes'),
867  0 => translate('no'),
868  );
869  if ($write_access) {
870  combo_box($prefix.'_indexed', $options, FALSE, $indexed);
871  } else {
872  echo $options[$indexed];
873  }
874  $o->closeField();
875 
876  $asset_weights = array_get_index($weights, 'asset_weights', Array());
877  $attr_weights = array_get_index($weights, 'attr_weights', Array());
878  $metadata_weights = array_get_index($weights, 'metadata_weights', Array());
879 
880  $this->_paintAssetWeightInterface($asset, $o, $prefix, $asset_weights);
881  $this->_paintAttributeWeightInterface($asset, $o, $prefix, $attr_weights, $type_code);
882  $this->_paintMetadataWeightInterface($asset, $o, $prefix, $metadata_weights);
883 
884  if (!$this->_customisationsRemoved($prefix, $screen)) {
885  $o->addHiddenField($prefix.'_current_'.$post_field, $key);
886  }
887  }//end if !empty(assetid)
888  $o->closeField();
889  // section closed by xml
890 
891  return $write_access;
892 
893  }//end _paintWeightInterface()
894 
895 
907  function _processWeights(&$asset, &$o, $prefix, $screen)
908  {
909  if (!$asset->writeAccess('attributes')) return FALSE;
910  $post_field = $this->_getPostField($screen);
911 
912  // if they have clicked on a current customisation, dont process
913  if (!empty($_POST[$prefix.'_customise_type_code']) || !empty($_POST[$prefix.'_customise_assetid'])) {
914  return FALSE;
915  }
916 
917  $function_suffix = str_replace('_', '', $screen).'Weightings';
918  $get_function = 'get'.$function_suffix;
919  $save_function = 'save'.$function_suffix;
920 
921  $key = array_get_index($_POST, $prefix.'_current_'.$post_field, '');
922  $weights = $asset->$get_function();
923 
924  if (!empty($key)) {
925  // the asset tree screen is a bit special - we need to dig down the
926  // array depending on what we are customising
927  if ($screen == 'asset_tree') {
928 
929  if (!isset($weights[$key])) $weights[$key] = Array();
930  $tree_assetid = $key;
931  $tree_weights = $weights;
932  $weights = $weights[$key];
933 
934  $tree_type = array_get_index($_POST, $prefix.'_selected_tree_type', '');
935 
936  if (empty($tree_type)) return;
937 
938  if ($tree_type == 'asset_type') {
939  $type_code = array_get_index($_POST, $prefix.'_current_type_code', '');
940  if (!empty($type_code)) {
941  // the key will be the type code within the asset tree array
942  // that we are currently customising
943  $key = $type_code;
944  if (!isset($weights['type_weights'])) {
945  $weights['type_weights'] = Array();
946  }
947  $weights = $weights['type_weights'];
948  } else {
949  // remove any asset type customisatons or tree customisations that have
950  // be flagged for removal
951  $this->_removeUnwantedCustomisations($prefix, 'asset_type', $weights['type_weights']);
952  $tree_weights[$key] = $weights;
953  $this->_removeUnwantedCustomisations($prefix, $screen, $tree_weights);
954  $asset->$save_function($tree_weights);
955  return FALSE;
956  }
957  } else {
958  // we are setting metadata weights for assets underneath 'key', which
959  // is stored in the global section for the asset tree that we are customising
960  if (!isset($weights['metadata_weights'])) {
961  $weights['metadata_weights'] = Array();
962  }
963  $this->_processMetadataWeights($prefix, $weights['metadata_weights']);
964  $tree_weights[$tree_assetid] = $weights;
965  $asset->$save_function($tree_weights);
966 
967  // no more work to do so just return
968  return FALSE;
969  }
970  }//end if asset_tree
971 
972  if (!isset($weights[$key])) $weights[$key] = Array();
973 
974  foreach (Array('asset_weights', 'attr_weights', 'metadata_weights') as $index) {
975  if (!isset($weights[$key][$index])) {
976  $weights[$key][$index] = Array();
977  }
978  }
979 
980  // set the 1 if there is no 'indexed' value set
981  $indexed = array_get_index($_POST, $prefix.'_indexed', 1);
982  $weights[$key]['indexed'] = $indexed;
983 
984  $this->_processAssetWeights($prefix, $weights[$key]['asset_weights']);
985  $this->_processAttributeWeights($prefix, $weights[$key]['attr_weights']);
986  $this->_processMetadataWeights($prefix, $weights[$key]['metadata_weights']);
987 
988  if ($screen == 'asset_tree') {
989  // remove any asset type customisations that have been flagged for removal
990  $this->_removeUnwantedCustomisations($prefix, 'asset_type', $weights);
991  // we only get into here if tree_type == asset_type
992  $tree_weights[$tree_assetid]['type_weights'] = $weights;
993  $weights = $tree_weights;
994  }
995  }//end if
996 
997  if (!empty($weights)) {
998  // remove any unwanted customisations
999  $this->_removeUnwantedCustomisations($prefix, $screen, $weights);
1000  $asset->$save_function($weights);
1001  }
1002 
1003  // we never save attributes
1004  return FALSE;
1005 
1006  }//end _processWeights()
1007 
1008 
1018  function _processAssetWeights($prefix, &$weights)
1019  {
1020  $asset_weights = array_get_index($_POST, $prefix.'_asset_weights', Array());
1021 
1022  foreach ($asset_weights as $comp => $info) {
1023  // verify that all weights are positive
1024  if ($info['weight'] <= 0) {
1025  if (!isset($weights[$comp]['weight'])) {
1026  $asset_weights[$comp]['weight'] = 1;
1027  } else {
1028  $asset_weights[$comp]['weight'] = (int) $weights[$comp]['weight'];
1029  }
1030  }
1031  if (!isset($info['indexed'])) {
1032  $asset_weights[$comp]['indexed'] = 0;
1033  }
1034  }
1035  $weights = $asset_weights;
1036 
1037  }//end _processAssetWeights()
1038 
1039 
1049  function _processAttributeWeights($prefix, &$weights)
1050  {
1051  $attr_weights = array_get_index($_POST, $prefix.'_attr_weights', Array());
1052  foreach ($attr_weights as $name => $info) {
1053  // verify that all weights are positive
1054  if ($info['weight'] <= 0) {
1055  if (!isset($weights[$name]['weight'])) {
1056  $attr_weights[$name]['weight'] = 1;
1057  } else {
1058  $attr_weights[$name]['weight'] = (int) $weights[$name]['weight'];
1059  }
1060  }
1061  if (!isset($info['indexed'])) {
1062  $attr_weights[$name]['indexed'] = 0;
1063  }
1064  }
1065  $weights = $attr_weights;
1066 
1067  }//end _processAttributeWeights()
1068 
1069 
1079  function _processMetadataWeights($prefix, &$weights)
1080  {
1081  // information about already added metadata assets
1082  $metadata_assets = array_get_index($_POST, $prefix.'_metadata_assets', Array());
1083 
1084  // process any assets that have been previously added
1085  foreach ($metadata_assets as $assetid => $info) {
1086  if (isset($info['remove']) && $info['remove']) {
1087  unset($weights[$assetid]);
1088  } else {
1089  $weight = ((int) $info['weight'] > 0) ? $info['weight'] : NULL;
1090  if (!is_null($weight)) {
1091  $weights[$assetid]['weight'] = (int) $weight;
1092  }
1093  $weights[$assetid]['indexed'] = array_get_index($info, 'indexed', FALSE);
1094  }
1095  }
1096 
1097  // the information posted by the asset finder
1098  $metadata_asset = array_get_index($_POST, $prefix.'_metadata_asset', NULL);
1099 
1100  if (!is_null($metadata_asset) && $metadata_asset['assetid'] != 0) {
1101  $weight = array_get_index($_POST, $prefix.'_metadata_weight', 1);
1102  if ($weight < 0) $weight = 1;
1103 
1104  $assetid = $metadata_asset['assetid'];
1105  $type_info = $GLOBALS['SQ_SYSTEM']->am->getAssetInfo(Array($assetid), Array(), TRUE, 'type_code');
1106  $type_code = $type_info[$assetid];
1107 
1108  // save any values from a metadata asset that was selected using the asset finder
1109  $weights[$assetid] = Array(
1110  'weight' => (int) $weight,
1111  'type_code' => $type_code,
1112  'indexed' => 1,
1113  );
1114  }
1115 
1116  }//end _processMetadataWeights()
1117 
1118 
1129  function _removeUnwantedCustomisations($prefix, $screen, &$weights)
1130  {
1131  $post_field = $this->_getPostField($screen);
1132  // remove any customisations that have been checked for removal
1133  $remove_array = array_get_index($_POST, $prefix.'_customise_'.$post_field.'_remove', Array());
1134  foreach ($remove_array as $key => $info) {
1135  unset($weights[$key]);
1136  }
1137 
1138  }//end _removeUnwantedCustomisations()
1139 
1140 
1150  function _customisationsRemoved($prefix, $screen)
1151  {
1152  $post_field = $this->_getPostField($screen);
1153  $removed = array_get_index($_POST, $prefix.'_customise_'.$post_field.'_remove', Array());
1154 
1155  return (!empty($removed));
1156 
1157  }//end _customisationsRemoved()
1158 
1159 
1170  function paintReindexing(&$asset, &$o, $prefix)
1171  {
1172  if ($asset->writeAccess('attributes')) {
1173  asset_finder($prefix.'_reindexing_root_assetid', '');
1174  echo '&nbsp;&nbsp;&nbsp;<b>'.strtoupper(translate('or')).'</b>';
1175  $o->closeField();
1176  $o->openField(translate('sch_system_wide'));
1177  check_box($prefix.'_reindexing_root_folder');
1178  echo translate('sch_reindex_all_assets');
1179  return TRUE;
1180  }
1181  return FALSE;
1182 
1183  }//end paintReindexing()
1184 
1185 
1196  function processReindexing(&$asset, &$o, $prefix)
1197  {
1198  if (isset($_POST[$prefix.'_reindexing_root_assetid']['assetid'])) {
1199  $root_assetid = $_POST[$prefix.'_reindexing_root_assetid']['assetid'];
1200  if ($root_assetid > 0) {
1201  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
1202  $running_vars = Array(
1203  'root_assetid' => $root_assetid,
1204  'contextid' => $GLOBALS['SQ_SYSTEM']->getContextId(),
1205  );
1206  $hh->queueHipo('hipo_job_reindex', $running_vars, '', SQ_PACKAGES_PATH.'/search/hipo_jobs');
1207  return TRUE;
1208  }
1209  }
1210 
1211  if (isset($_POST[$prefix.'_reindexing_root_folder'])) {
1212  // System-wide reindex.
1213  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
1214  $running_vars = Array(
1215  'root_assetid' => $GLOBALS['SQ_SYSTEM']->am->getSystemAssetid('root_folder'),
1216  'contextid' => $GLOBALS['SQ_SYSTEM']->getContextId(),
1217  );
1218  $hh->queueHipo('hipo_job_reindex', $running_vars, '', SQ_PACKAGES_PATH.'/search/hipo_jobs');
1219  return TRUE;
1220  }
1221  return FALSE;
1222 
1223  }//end processReindexing()
1224 
1225 
1236  function paintNoiseWords(&$asset, &$o, $prefix)
1237  {
1238  $write_access = $asset->writeAccess('attributes');
1239 
1240  $noise_words = $asset->attr('noise_word_list');
1241  $noise_words = (is_array($noise_words)) ? implode(' ', $noise_words) : '';
1242 
1243  if ($write_access) {
1244  text_area($prefix.'_noise_words', $noise_words, 60, 5);
1245  } else {
1246  echo $noise_words;
1247  }
1248  return $write_access;
1249 
1250  }//end paintNoiseWords()
1251 
1252 
1263  function processNoiseWords(&$asset, &$o, $prefix)
1264  {
1265 
1266  $words = array_get_index($_POST, $prefix.'_noise_words', FALSE);
1267 
1268  $matches = Array();
1269  $new_words = Array();
1270 
1271  if (preg_match_all('/\w+/i', $words, $matches, PREG_SET_ORDER)) {
1272  foreach ($matches as $match) {
1273  $word = array_pop($match);
1274  $new_words[$word] = $word;
1275  }
1276  }
1277 
1278  $asset->setAttrValue('noise_word_list', $new_words);
1279 
1280  return TRUE;
1281 
1282  }//end processNoiseWords()
1283 
1284 
1295  function paintWhiteWords(&$asset, &$o, $prefix)
1296  {
1297  $write_access = $asset->writeAccess('attributes');
1298 
1299  $words = $asset->attr('white_word_list');
1300  $words = (is_array($words)) ? implode(' ', $words) : '';
1301 
1302  if ($write_access) {
1303  text_area($prefix.'_white_words', $words, 60, 5);
1304  } else {
1305  echo $words;
1306  }
1307  return $write_access;
1308 
1309  }//end paintWhiteWords()
1310 
1311 
1322  function processWhiteWords(&$asset, &$o, $prefix)
1323  {
1324  $words = array_get_index($_POST, $prefix.'_white_words', FALSE);
1325 
1326  $matches = Array();
1327  $new_words = Array();
1328 
1329  if (preg_match_all('/\w+/i', $words, $matches, PREG_SET_ORDER)) {
1330  foreach ($matches as $match) {
1331  $word = array_pop($match);
1332  $new_words[$word] = $word;
1333  }
1334  }
1335 
1336  $asset->setAttrValue('white_word_list', $new_words);
1337 
1338  return TRUE;
1339 
1340  }//end processWhiteWords()
1341 
1342 
1352  function indexingOn(&$owner, $prefix)
1353  {
1354  return $owner->attr('indexing');
1355 
1356  }//end indexingOn()
1357 
1358 
1364  private function _usingGoButton($prefix)
1365  {
1366  $tree_type_go = array_get_index($_POST, $prefix.'_selected_tree_type_go', FALSE);
1367  $type_code_go = array_get_index($_POST, $prefix.'_selected_type_code_go', FALSE);
1368 
1369  return ($tree_type_go !== FALSE || $type_code_go !== FALSE);
1370 
1371  }// end _usingGoButton()
1372 
1373 
1374 }//end class
1375 ?>