Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
thesaurus_term_edit_fns.inc
1 <?php
18 require_once SQ_INCLUDE_PATH.'/asset_edit/asset_edit_fns.inc';
19 
32 {
33 
34 
40  {
41  $this->Asset_Edit_Fns();
42 
43  // disable all static screens
44  $this->static_screens = Array();
45 
46  // enable just the details
47  $this->static_screens['details']['name'] = translate('details');
48  $this->static_screens['details']['force_unlock'] = FALSE;
49 
50  }//end constructor
51 
52 
63  function paintName(&$asset, &$o, $prefix)
64  {
65  $write = $asset->writeAccess('attributes');
66 
67  // Paint the name
68  if ($write) {
69  check_box($prefix.'_rename', '1');
70  label(translate('rename_thesaurus_term_sys_wide'), $prefix.'_rename');
71  echo '<input type="hidden" name="'.$prefix.'_old_name" value="'.$asset->attr('name').'" />';
72  }
73 
74  return TRUE;
75 
76  }//end paintName()
77 
78 
89  function processName(&$asset, &$o, $prefix)
90  {
91  $old_name = array_get_index($_POST, $prefix.'_old_name', '');
92  $name = $asset->attr('name');
93  $rename = array_get_index($_POST, $prefix.'_rename', 0);
94 
95  // Save the name
96  if (!empty($name)) {
97  $asset->setAttrValue('name', $name);
98  if (!$asset->saveAttributes()) {
99  $asset->setAttrValue('name', $old_name);
100  return FALSE;
101  } else {
102  // Attributes saved, if the user wants to rename metadata... do it!
103  if (!empty($rename) && !empty($asset->_thesaurus->id)) {
104  $hh = $GLOBALS['SQ_SYSTEM']->getHipoHerder();
105  $vars = Array('thesaurusid' => $asset->_thesaurus->id, 'terms' => Array($old_name => $name));
106  $hh->queueHipo('hipo_job_rename_thesaurus_term', $vars);
107  }//end if
108  }//end if
109  }//end if
110 
111  return TRUE;
112 
113  }//end processName()
114 
115 
126  function paintRelations(&$asset, &$o, $prefix)
127  {
128 
129  // Special case for when the asset is being created
130  $o->openRaw();
131  if ($asset->id == 0) {
132  $parent_assetid = array_get_index($_REQUEST, 'parent_assetid');
133  $parent_asset = $GLOBALS['SQ_SYSTEM']->am->getAsset($parent_assetid);
134  if ($parent_asset->type() == 'thesaurus') {
135  echo translate('thesaurus_creating_top_level_term');
136  } else {
137  $relations = (property_exists($parent_asset, '_thesaurus')) ? $parent_asset->_thesaurus->getActiveRelations() : NULL;
138  ?>
139  <table class="sq-backend-table">
140  <tr>
141  <th class="sq-backend-table-header"><strong><?php echo translate('parent'); ?></strong></th>
142  <th class="sq-backend-table-header"><strong><?php echo translate('relation'); ?></strong></th>
143  </tr>
144  <tr>
145  <td><?php echo get_asset_tag_line($parent_assetid); ?></td>
146  <td><?php
147  if (empty($relations)) {
148  echo 'Because the thesaurus has no relations, this term will not be linked to the parent';
149  } else {
150  combo_box($prefix.'_new_relation[existing]', $relations, FALSE, $parent_asset->_thesaurus->attr('default_rel'));
151  }
152  ?></td>
153  </tr>
154  </table>
155  <?php
156  }
157  } else {
158  $thesaurus = $asset->_thesaurus;
159  $relations = $thesaurus->getActiveRelations();
160 
161  $parents = $asset->_thesaurus->getParentTerms($asset->_termid);
162 
163  $writeable = $asset->writeAccess('all');
164 
165  ?>
166  <table class="sq-backend-table">
167  <tr>
168  <th class="sq-backend-table-header"><strong><?php echo translate('parent'); ?></strong></th>
169  <th class="sq-backend-table-header"><strong><?php echo translate('relation'); ?></strong></th>
170  </tr>
171  <?php
172  if (empty($relations)) {
173  echo '<tr><td colspan="2">There are no relations defined in this thesaurus, you cannot set or view the relations to parent terms.</td></tr>';
174  } else {
175 
176  foreach ($parents as $parent) {
177  $parent_rel = array_get_index($parent, 'relid');
178 
179  if (is_null($parent['termid'])) continue;
180  echo '<tr>';
181  echo '<td>';
182  echo get_asset_tag_line($thesaurus->id.':'.$parent['termid']);
183  echo '</td>';
184  echo '<td>';
185  if ($writeable) {
186  combo_box($prefix.'_relations['.$parent['linkid'].']', $relations, FALSE, $parent_rel);
187  } else {
188  echo array_get_index($relations, $parent_rel);
189  }
190  echo '</td>';
191  echo '</tr>';
192  }
193  }
194 
195  echo '</table>';
196 
197  }//end else
198 
199  $o->closeRaw();
200  return TRUE;
201 
202  }//end paintRelations()
203 
204 
215  function processRelations(&$asset, &$o, $prefix)
216  {
217  if ($asset->id == 0) {
218  $new_rel = array_get_index($_REQUEST, $prefix.'_new_relation');
219  if (isset($new_rel['new'])) {
220  $relation = trim($new_rel['new']);
221  }
222 
223  if (empty($relation)) {
224  $relation = array_get_index($new_rel, 'existing');
225  }
226 
227  $asset->_tmp['relation'] = $relation;
228  } else {
229  $thesaurus =& $asset->_thesaurus;
230  $relations = array_get_index($_REQUEST, $prefix.'_relations', Array());
231  foreach ($relations as $link_id => $relid) {
232  $thesaurus->updateLinkRelation($link_id, $relid);
233  }
234  }
235 
236  return TRUE;
237 
238  }//end processRelations()
239 
240 
251  function paintTermInfo(&$asset, &$o, $prefix)
252  {
253  // cannot display anything while creating a new asset
254  if ($asset->id == 0) {
255  return;
256  }
257 
258  $o->openRaw();
259 
260  echo '<table>';
261  $notes = $asset->getTermNotes();
262  foreach ($notes as $note_name => $note_array) {
263  echo '<tr><td valign="top" align="right">'.$note_name.':</td><td valign="top">';
264  foreach ($note_array as $note) {
265  echo nl2br($note).'<br />';
266  }
267  echo '</td></tr>';
268  }
269 
270  $bridge_id = $asset->_thesaurus->id;
271  $child_rel = $asset->_thesaurus->getChildRelationsForTerm($asset->_termid);
272  foreach ($child_rel as $relid => $relname) {
273  echo '<tr><td valign="top" align="right">'.$relname.':</td><td valign="top">';
274  $rel_terms = $asset->_thesaurus->getChildTerms($asset->_termid, $relid);
275  foreach ($rel_terms as $term) {
276  $term_assetid = $bridge_id.':'.$term['termid'];
277  $href_array = $GLOBALS['SQ_SYSTEM']->am->getAssetBackendHref(Array($term_assetid => 'details'));
278  $term_backendhref = $href_array[$term_assetid];
279  echo '<a href="'.$term_backendhref.'">'.$term['term'].'</a>';
280  echo '<br />';
281  }
282  echo '</td></tr>';
283  }
284 
285  echo '</table>';
286 
287  $o->closeRaw();
288  return TRUE;
289 
290  }//end paintTermInfo()
291 
292 
293 }//end class
294 ?>