Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
tool_change_thesaurus_term.inc
1 <?php
17 require_once SQ_SYSTEM_ROOT.'/core/assets/system/tool/tool.inc';
18 
32 {
33 
34 
41  function Tool_Change_Thesaurus_Term($assetid=0)
42  {
43  $this->Tool($assetid);
44 
45  }//end constructor
46 
47 
58  public static function paintTool(&$o, $type_code)
59  {
60  $o->openSection(translate('tool_rename_thesaurus_term'));
61  $o->openField(translate('tool_thesaurus_term'));
62  asset_finder('thesaurus_term', 0, Array('thesaurus_term'=>'I'));
63  $err_msg = str_replace("'", "\'", translate('tool_thesaurus_term_empty'));
64  $o->addOnSubmit("if (document.getElementById('thesaurus_term[assetid]').value == 0) {
65  alert('$err_msg');
66  return false;
67  }");
68  $o->closeField();
69  $o->openField(translate('tool_thesaurus_term_old'));
70  text_box('thesaurus_term_old');
71  $err_msg = str_replace("'", "\'", translate('tool_thesaurus_term_old_empty'));
72  $o->addOnSubmit("if (document.getElementById('thesaurus_term_old').value == '') {
73  alert('$err_msg');
74  return false;
75  }");
76  $o->closeField();
77  // No need for asking for the thesaurus, they pick the term, we know the thesaurus it comes from
78  $o->openField(translate('tool_thesaurus_term_root_node'));
79  asset_finder('root_node', 0);
80  echo '<br />';
81  check_box('cascade', '1', FALSE);
82  label(translate('tool_thesaurus_term_cascade'), 'cascade');
83  $o->closeField();
84  $o->sectionNote(translate('tool_rename_thesaurus_term_note'));
85  $o->closeSection();
86 
87  }//end paintTool()
88 
89 
100  public static function processTool(&$o, $type_code)
101  {
102  $current_term = array_get_index($_REQUEST['thesaurus_term'], 'assetid', 0);
103  $old_value = array_get_index($_REQUEST, 'thesaurus_term_old', '');
104  $root_node = array_get_index($_REQUEST['root_node'], 'assetid', 0);
105  $cascade = array_get_index($_REQUEST, 'cascade', 0);
106 
107  if (empty($current_term) || empty($old_value)) {
108  return FALSE;
109  }//end if
110 
111  $term = $GLOBALS['SQ_SYSTEM']->am->getAsset($current_term, '', TRUE);
112  if (is_null($term)) {
113  return FALSE;
114  }//end if
115 
116  // Locate the thesaurus
117  $parts = explode(':', $term->id);
118  $thesaurus_id = array_get_index($parts, 0, 0);
119  if (empty($thesaurus_id)) {
120  return FALSE;
121  }//end if
122 
123  // Set the running vars for the HIPO job
124  $new_value = $term->attr('name');
125  $running_vars = Array(
126  'thesaurusid' => $thesaurus_id,
127  'terms' => Array($old_value => $new_value),
128  );
129 
130  // If a root node is set, add it in
131  if (!empty($root_node)) {
132  $root = $GLOBALS['SQ_SYSTEM']->am->getAsset($root_node, '', TRUE);
133  if (!is_null($root)) {
134  $running_vars['assetids'] = Array($root->id);
135  if (!empty($cascade)) {
136  $running_vars['cascade'] = TRUE;
137  }//end if
138  }//end if
139  }//end if
140 
141  // Run the hipo job
142  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
143  $hh->queueHipo('hipo_job_rename_thesaurus_term', $running_vars);
144  $url = $hh->runQueuedJobs();
145  if (!empty($url)) $o->setRedirect($url);
146 
147  return TRUE;
148 
149  }//end processTool()
150 
151 
152 }//end class
153 ?>