18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
47 if (empty($asset_id)) {
51 if (strpos($asset_id,
':') === FALSE)
return;
53 list($thesaurus_id, $termid) = explode(
':', $asset_id);
55 $this->_thesaurus = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($thesaurus_id);
57 $term = $this->_thesaurus->getTermById($termid);
58 if (is_null($term))
return;
60 $this->
id = $asset_id;
61 $this->_termid = $termid;
64 $this->name = $term[
'term'];
65 $this->short_name = $this->name;
66 $this->status = $this->_thesaurus->status;
92 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
93 $this->name = $this->
attr(
'name');
94 if (empty($this->name))
return FALSE;
98 if ($link[
'asset'] instanceof
Thesaurus) {
99 $this->_thesaurus =& $link[
'asset'];
101 $this->_thesaurus =& $link[
'asset']->_thesaurus;
102 $majorid = $link[
'asset']->_termid;
104 $type = method_exists($link[
'asset'],
'type') ? $link[
'asset']->type() :
'';
105 trigger_localised_error(
'CORE0236', E_USER_WARNING, $type);
110 $term = $this->
attr(
'name');
111 $relation = isset($this->_tmp[
'relation']) ? $this->_tmp[
'relation'] : $link[
'value'];
113 $relation = trim($relation);
117 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
118 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
121 $termid = $this->_thesaurus->getTermIdByName($term);
122 if (is_null($termid)) {
123 $termid = $this->_thesaurus->_addTerm($term);
124 if (is_null($termid)) {
125 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
126 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
127 trigger_error(
'Unknown error. Cannot add.');
133 $this->
id = $this->_thesaurus->id.
':'.$termid;
134 $this->_termid = $termid;
137 if (is_null($majorid)) {
138 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
140 $em->broadcastEvent($this,
'AssetCreate', Array(
'name',
'assetid'));
142 $em->broadcastEvent($this->_thesaurus,
'CreateLink', Array());
143 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
144 return $this->_thesaurus->id.
':atoz:'.$termid;
147 $existing_link = $this->_thesaurus->getTermLinkByTermids($termid, $majorid, $relation);
148 if (!empty($existing_link)) {
149 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
150 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
151 return $this->_thesaurus->id.
':'.$existing_link[
'linkid'];
154 $linkid = $this->_thesaurus->linkTerms($termid, $majorid, $relation);
155 if (is_null($linkid)) {
156 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
157 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
158 trigger_localised_error(
'CORE0237', E_USER_WARNING);
162 $this->_thesaurus->markContentsChanged();
163 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
164 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
167 $em->broadcastEvent($this,
'AssetCreate', Array(
'name',
'assetid'));
170 return $this->_thesaurus->id.
':'.$linkid;
185 if (isset($this->_termid)) {
186 $links = $this->_thesaurus->_getShadowAssetMapLinks($this->_termid);
210 SQ_LINK_TYPE_1 => Array(
211 'thesaurus_term' => Array(
213 'exclusive' => FALSE,
216 SQ_LINK_TYPE_2 => Array(
217 'thesaurus_term' => Array(
219 'exclusive' => FALSE,
222 SQ_LINK_TYPE_3 => Array(),
236 if (empty($this->_thesaurus))
return TRUE;
238 $name = $this->
attr(
'name');
242 if ($this->name != $this->
attr(
'name')) {
246 $success = $this->_thesaurus->updateTerm($this->_termid, $name);
249 $this->_thesaurus->saveAttributes();
251 if (!empty($this->_tmp[
'vars_set'])) {
253 foreach ($this->_tmp[
'vars_set'] as $attr => $details) {
254 $changed_vars[$attr] = Array(
255 'type' => $this->vars[$attr][
'type'],
256 'old_value' => $details[
'old_value'],
257 'new_value' => $this->
attr($attr),
260 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_attributes_changed', $this, $changed_vars);
263 unset($this->_tmp[
'vars_set']);
264 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
265 $em->broadcastEvent($this,
'AssetUpdate', Array(
'name'));
266 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_attributes_saved', $this);
326 $create_link = FALSE;
329 $create_link = (($link_type == SQ_LINK_TYPE_1) || ($link_type == SQ_LINK_TYPE_2));
348 $this->_thesaurus->addTermNote($this->_termid, $name, $note);
361 $this->_thesaurus->deleteTermNotes($this->_termid);
374 return $this->_thesaurus->getTermNotes($this->_termid);