18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
19 require_once SQ_FUDGE_PATH.
'/general/text.inc';
20 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
21 require_once SQ_CORE_PACKAGE_PATH.
'/interfaces/bridge/bridge.inc';
47 $this->_ser_attrs = TRUE;
48 $this->
Asset($assetid);
61 function delete($release_lock)
63 if (parent::delete($release_lock)) {
85 if (!parent::_createAdditional($link))
return FALSE;
86 return create_directory($this->data_path);
106 $abbreviation_attr = $this->
getAttribute(
'abbreviation_rel');
107 $abbreviation_rel = $abbreviation_attr->value;
108 if (empty($abbreviation_rel)) {
109 $abbreviation_rel = NULL;
114 if (is_null($abbr_rows))
return Array();
117 foreach ($abbr_rows as $abbr) {
118 $result[$abbr[
'major']] = $abbr[
'minor'];
138 if (empty($termid))
return Array();
141 $synonym_rel = $synonym_attr->value;
142 if (empty($synonym_rel)) $synonym_rel = NULL;
147 if (!empty($synonyms)) {
148 foreach ($synonyms as $synonym) {
149 $result[$synonym[
'term']] = $synonym[
'term'];
175 $limit_relation = TRUE;
176 if (is_null($relid)) $limit_relation = FALSE;
182 linkid, term, termid, relid
185 INNER JOIN sq_thes_lnk link ON term.termid = link.minor
187 term.thesid = :assetid_1
189 link.thesid = :assetid_2
194 if ($limit_relation) {
210 if ($limit_relation) {
216 }
catch (Exception $e) {
217 throw new Exception(
'Unable to get thesaurus child terms due to database error: '. $e->getMessage());
241 'assetid' => $this->
id,
247 }
catch (Exception $e) {
248 throw new Exception(
'Unable to count thesaurus child terms due to database error: '. $e->getMessage());
267 $bind_vars[
'assetid'] = $this->id;
271 }
catch (Exception $e) {
272 throw new Exception(
'Unable to count thesaurus term links due to database error: '. $e->getMessage());
291 $bind_vars[
'assetid'] = $this->id;
295 }
catch (Exception $e) {
296 throw new Exception(
'Unable to count thesaurus terms due to database error: '. $e->getMessage());
321 'assetid' => $this->
id,
327 }
catch (Exception $e) {
328 throw new Exception(
'Unable to count thesaurus parent terms due to database error: '. $e->getMessage());
353 'assetid' => $this->
id,
359 }
catch (Exception $e) {
360 throw new Exception(
'Unable to get child relations for term due to database error: '. $e->getMessage());
362 if (!empty($results)) {
364 foreach ($results as $result) {
365 $new_res[$result[
'relid']] = $result[
'relation'];
388 if (!isset($termid))
return NULL;
393 'assetid' => $this->
id,
399 }
catch (Exception $e) {
400 throw new Exception(
'Unable to get parent relations for term due to database error: '. $e->getMessage());
416 $bind_vars = Array();
417 $bind_vars[
'assetid'] = $this->id;
421 }
catch (Exception $e) {
422 throw new Exception(
'Unable to get a list of all thesaurus terms due to database error: '. $e->getMessage());
444 $limit_relation = TRUE;
445 if (is_null($relid)) $limit_relation = FALSE;
451 linkid, term, termid, relid
454 INNER JOIN sq_thes_lnk link ON term.termid = link.major
456 term.thesid = :thesid_1
458 link.thesid = :thesid_2
463 if ($limit_relation) {
480 if ($limit_relation) {
486 }
catch (Exception $e) {
487 throw new Exception(
'Unable to get thesaurus parent terms due to database error: '. $e->getMessage());
505 if (empty($relation_id))
return NULL;
512 major.termid as majorid,
514 minor.termid as minorid
517 INNER JOIN sq_thes_lnk link ON major.termid = link.major
518 INNER JOIN sq_thes_term minor ON minor.termid = link.minor
522 major.thesid = :major_thesid
524 minor.thesid = :minor_thesid
526 link.thesid = :link_thesid
553 if (!isset($term) || $term ==
'') {
560 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
564 'thesid' => $this->
id,
571 }
catch (Exception $e) {
572 throw new Exception(
'Unable to insert a thesaurus term due to database error: '. $e->getMessage());
575 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
576 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
596 if (!is_null($termid))
return $termid;
618 $sql =
'SELECT a.termid, a.name, a.value, a.thesid, b.term
619 FROM sq_thes_term_note a, sq_thes_term b
620 WHERE a.termid = '.MatrixDAL::quote($termid).
' AND
624 b.thesid = a.thesid AND b.termid = a.termid
630 }
catch (Exception $e) {
631 throw new Exception($e->getMessage());
634 if (!empty($result)) {
636 trigger_localised_error(
'CORE0282', E_USER_WARNING, $note_name.
":".$note_value, $result[0][
'term']);
640 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
644 'thesid' => $this->
id,
646 'name' => $note_name,
647 'value' => $note_value,
652 }
catch (Exception $e) {
653 throw new Exception(
'Unable to insert a thesaurus term note due to database error: '. $e->getMessage());
656 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
657 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
678 'assetid' => $this->
id,
684 }
catch (Exception $e) {
685 throw new Exception(
'Unable to get thesaurus term note due to database error: '. $e->getMessage());
703 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
707 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
710 'thesid' => $this->
id,
716 }
catch (Exception $e) {
717 throw new Exception(
'Unable to delete a thesaurus term note due to database error: '. $e->getMessage());
721 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
722 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
743 $term_linkid = $this->
_linkTerms($minorid, $majorid, $relid);
745 if (is_null($term_linkid)) {
746 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
750 if ($this->
attr(
'enforce_reflection')) {
753 $this->
_linkTerms($majorid, $minorid, $ref_relid);
777 if (is_null($minorid) || is_null($majorid)) {
781 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
785 'thesid' => $this->
id,
788 'relation' => $relation_id,
793 }
catch (Exception $e) {
794 throw new Exception(
'Unable to get thesaurus linkid due to database error: '. $e->getMessage());
799 if (!empty($result))
return $result;
801 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
806 $bind_vars[
'linkid'] = $linkid;
808 }
catch (Exception $e) {
809 throw new Exception(
'Unable to link a thesaurus term due to database error: '. $e->getMessage());
813 $em = $GLOBALS[
'SQ_SYSTEM']->getEventManager();
815 $em->broadcastEvent($major,
'CreateLink', Array());
817 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
818 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
844 if ($term[
'term'] == $name)
return TRUE;
846 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
853 if ($this->
isTerm($name, $termid)) {
854 trigger_localised_error(
'CORE0239', E_USER_WARNING);
860 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
864 'assetid' => $this->
id,
871 }
catch (Exception $e) {
872 throw new Exception(
'Unable to update a thesaurus term due to database error: '. $e->getMessage());
876 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
877 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
896 if ($new_name ==
'') $new_name = NULL;
900 if (!is_null($relid))
return NULL;
904 $this->_tmp[
'error'][] = translate(
'thesaurus_new_relation_in_use');
908 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
910 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
915 'assetid' => $this->
id,
916 'relid' => $relation_id,
917 'relation' => $new_name,
922 }
catch (Exception $e) {
923 throw new Exception(
'Unable to update a thesaurus relation name due to database error: '. $e->getMessage());
926 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
927 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
950 'assetid' => $this->
id,
956 if (!empty($result) && isset($result[0])) {
957 $result = $result[0];
959 }
catch (Exception $e) {
960 throw new Exception(
'Unable to get a thesaurus term by id due to database error: '. $e->getMessage());
983 'assetid' => $this->
id,
989 if (!empty($result) && isset($result[0])) {
990 $result = $result[0];
992 }
catch (Exception $e) {
993 throw new Exception(
'Unable to get a thesaurus term link by id due to database error: '. $e->getMessage());
1019 relation '.(is_null($name)?
'IS NULL':
'= :name').
'
1024 if (!is_null($name)) {
1031 }
catch (Exception $e) {
1032 throw new Exception(
'Unable to get thesaurus relation Id by name due to database error: '. $e->getMessage());
1035 if (empty($result)) $result = NULL;
1052 if ($name ==
'') $name = NULL;
1056 if (!is_null($relid))
return $relid;
1058 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1061 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1064 $bind_vars = Array (
1065 'thesid' => $this->
id,
1066 'relation' => $name,
1072 }
catch (Exception $e) {
1073 throw new Exception(
'Unable to add a thesaurus relation due to database error: '. $e->getMessage());
1076 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1077 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1096 if (!isset($linkid) || !isset($relid)) {
1101 $major = $link_info[
'major'];
1102 $minor = $link_info[
'minor'];
1103 $old_relid = $link_info[
'relid'];
1106 $this->
linkTerms($minor, $major, $relid);
1128 $bind_vars = Array (
1129 'thesid' => $this->
id,
1131 'parentid' => $parentid,
1132 'termid' => $termid,
1137 if (!empty($result) && isset($result[0])) {
1138 $result = $result[0];
1140 }
catch (Exception $e) {
1141 throw new Exception(
'Unable to get a thesaurus term link by id due to database error: '. $e->getMessage());
1161 $name = strtolower($name);
1179 }
catch (Exception $e) {
1180 throw new Exception(
'Unable to get thesaurus term id by name due to database error: '. $e->getMessage());
1183 if (empty($result)) $result = NULL;
1207 if (empty($names))
return Array();
1211 $formatted_names = Array();
1212 foreach ($names as $name) {
1213 $formatted_names[] = strtolower($name);
1216 $bind_vars = Array (
1217 'names' => $formatted_names,
1218 'theid' => $this->
id,
1223 }
catch (Exception $e) {
1224 throw new Exception(
'Unable to get thesaurus term ids by names due to database error: '. $e->getMessage());
1243 if (is_null($term))
return FALSE;
1245 $db = MAtrixDAL::getDb();
1258 $sql .=
' AND termid <> :termid';
1261 $bind_vars = Array (
1262 'term' => strtolower($term),
1263 'thesid' => $this->
id,
1267 $bind_vars[
'termid'] = $termid;
1278 }
catch (Exception $e) {
1279 throw new Exception(
'Unable to get thesaurus term id due to database error: '.$e->getMessage());
1282 return !empty($result);
1297 $bind_vars = Array (
1298 'assetid' => $this->
id,
1303 }
catch (Exception $e) {
1304 throw new Exception(
'Unable to get thesaurus active relations due to database error: '. $e->getMessage());
1307 if(!empty($results)) {
1309 foreach ($results as $result) {
1310 $new_res[$result[
'relid']] = $result[
'relation'];
1312 $results = $new_res;
1350 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1351 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1355 $bind_vars = Array (
1356 'assetid' => $this->
id,
1361 }
catch (Exception $e) {
1362 throw new Exception(
'Unable to delete all thesaurus terms due to database error: '. $e->getMessage());
1367 }
catch (Exception $e) {
1368 throw new Exception(
'Unable to delete all thesaurus links due to database error: '. $e->getMessage());
1373 }
catch (Exception $e) {
1374 throw new Exception(
'Unable to delete all thesaurus relations due to database error: '. $e->getMessage());
1377 $bind_vars[
'assetid'] = $this->
id.
':%';
1381 }
catch (Exception $e) {
1382 throw new Exception(
'Unable to delete all shadow thesaurus links due to database error: '. $e->getMessage());
1385 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1386 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1401 return $this->data_path.
'/content.xml';
1419 if ($contextid === NULL) {
1420 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
1424 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
1425 if (empty($values) === TRUE) {
1426 return parent::_getName($short_name, $contextid);
1428 return $values[$this->id];
1447 if (!isset($relation_id))
return Array();
1492 }
catch (Exception $e) {
1493 throw new Exception(
'Unable to get absolute parent om relation due to database error: '. $e->getMessage());
1538 function getAsset($shadowid, $type_code=
'', $mute_errors=FALSE)
1542 $id_parts = explode(
':', $shadowid);
1543 if (!empty($id_parts[1])) {
1547 if (!empty($term)) {
1548 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'thesaurus_term');
1581 $bridge_id = $this->id;
1583 $majorid = $bridge_id;
1584 if (!is_null($parent_term_id)) {
1585 $majorid .=
':'.$parent_term_id;
1594 foreach ($linked_terms as $term_link) {
1600 $link[
'num_kids'] = -1;
1601 $link[
'accessible'] = 1;
1603 $link[
'majorid'] = $majorid;
1604 $link[
'minorid'] = $bridge_id.
':'.$term_link[
'termid'];
1605 $link[
'assetid'] = $link[
'minorid'];
1606 $link[
'type_code'] =
'thesaurus_term';
1607 $link[
'minor_type_code'] = $link[
'type_code'];
1609 $link[
'linkid'] = $bridge_id.
':'.$term_link[
'linkid'];
1611 $rel_name = array_get_index($active_relations, $term_link[
'relid']);
1612 $name_prefix = (empty($rel_name) ?
'' :
'('.$rel_name.
') ');
1613 $link[
'name'] = $name_prefix.$term_link[
'term'];
1614 $link[
'short_name'] = $link[
'name'];
1616 $link[
'status'] = $this->status;
1617 $link[
'link_type'] = SQ_LINK_TYPE_1;
1618 $link[
'sort_order'] = 1;
1619 $link[
'is_dependant'] = 0;
1639 $linkid_prefix =
'';
1640 if ($this->
attr(
'hierarchy_mode')) {
1641 $linkid_prefix =
':hierarchy';
1644 $linkid_prefix =
':atoz';
1648 $bridge_id = $this->id;
1653 foreach ($terms as $one_term) {
1659 $link[
'num_kids'] = -1;
1660 $link[
'accessible'] = 1;
1662 $link[
'majorid'] = $bridge_id;
1663 $link[
'minorid'] = $bridge_id.
':'.$one_term[
'termid'];
1664 $link[
'assetid'] = $link[
'minorid'];
1665 $link[
'type_code'] =
'thesaurus_term';
1666 $link[
'minor_type_code'] = $link[
'type_code'];
1668 $link[
'linkid'] = $bridge_id.$linkid_prefix.
':'.$one_term[
'termid'];
1671 $link[
'name'] = $one_term[
'term'];
1672 $link[
'short_name'] = $link[
'name'];
1674 $link[
'status'] = $this->status;
1675 $link[
'link_type'] = SQ_LINK_TYPE_2;
1676 $link[
'sort_order'] = 1;
1677 $link[
'is_dependant'] = 0;
1702 function getAssetInfo($assetids, $type_code=Array(), $strict_type_code=TRUE, $field=
'')
1704 $info_array = Array();
1706 foreach ($assetids as $id) {
1707 $id_parts = explode(
':', $id);
1708 if (empty($id_parts[1]))
continue;
1711 if (empty($term))
continue;
1713 $info_array[$id][
'assetid'] = $id;
1714 $info_array[$id][
'name'] = $term[
'term'];
1715 $info_array[$id][
'short_name'] = $term[
'term'];
1716 $info_array[$id][
'version'] = $this->version;
1717 $info_array[$id][
'status'] = $this->status;
1718 $info_array[$id][
'type_code'] =
'thesaurus_term';
1719 $info_array[$id][
'num_kids'] = $this->
countChildTerms($term[
'termid']);
1720 $info_array[$id][
'accessible'] = 1;
1721 $info_array[$id][
'url'] =
'';
1722 $info_array[$id][
'web_path'] =
'';
1724 if (!empty($field)) {
1725 $info_array[$id] = array_get_index($info_array[$id], $field);
1745 $asset_info = Array();
1746 $asset_info[
'assetid'] = $assetid;
1748 $id_parts = explode(
':', $assetid);
1749 if (empty($id_parts[1]))
return $asset_info;
1752 if (empty($term))
return $asset_info;
1754 $asset_info[
'name'] = $term[
'term'];
1755 $asset_info[
'short_name'] = $term[
'term'];
1756 $asset_info[
'version'] = $this->version;
1757 $asset_info[
'status'] = $this->status;
1758 $asset_info[
'type_code'] =
'thesaurus_term';
1760 $asset_info[
'accessible'] = 1;
1761 $asset_info[
'url'] =
'';
1762 $asset_info[
'web_path'] =
'';
1789 function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL)
1817 function getLink($assetid, $link_type=NULL, $type_code=
'', $strict_type_code=TRUE, $value=NULL, $side_of_link=
'major', $exclusive=NULL)
1844 function getLinkByAsset($assetid, $other_assetid, $link_types=NULL, $value=NULL, $side_of_link=
'major', $force_array=FALSE, $dependant=NULL, $exclusive=NULL)
1846 assert_valid_assetid($assetid);
1847 assert_valid_assetid($other_assetid);
1848 assert_false($side_of_link !=
'major' && $side_of_link !=
'minor',
'Unknown Side of Link "'.$side_of_link.
'"');
1850 if ($side_of_link ==
'major') {
1851 $major_assetid = $assetid;
1852 $minor_assetid = $other_assetid;
1854 $major_assetid = $other_assetid;
1855 $minor_assetid = $assetid;
1858 $major_parts = explode(
':', $major_assetid);
1859 $majorid = array_get_index($major_parts, 1, NULL);
1861 $minor_parts = explode(
':', $minor_assetid);
1862 $minorid = array_get_index($minor_parts, 1, NULL);
1863 if (empty($minorid))
return Array();
1867 if (empty($link_info))
return Array();
1871 'majorid' => $major_assetid,
1872 'minorid' => $minor_assetid,
1873 'link_type' => SQ_LINK_TYPE_2,
1874 'major_type_code' =>
'',
1875 'minor_type_code' =>
'thesaurus_term',
1877 'linkid' => $this->
id.
':'.$link_info[
'linkid'],
1878 'is_dependant' => 0,
1879 'is_exclusive' => 0,
1901 $link_parts = explode(
':', $linkid);
1903 $majorid = $this->id;
1905 if (isset($link_parts[2])) {
1907 $term_id = array_get_index($link_parts, 2);
1908 $minorid = $term_id;
1910 $major_type_code =
'thesaurus';
1913 $term_linkid = array_get_index($link_parts, 1);
1914 if (is_null($term_linkid)) {
1915 trigger_error(
'Invalid Link ID', E_USER_ERROR);
1918 $minorid = array_get_index($link_info,
'minorid');
1919 $majorid .=
':'.array_get_index($link_info,
'major');
1920 $value = array_get_index($link_info,
'relation');
1921 $major_type_code =
'thesaurus_term';
1926 'majorid' => $majorid,
1927 'minorid' => $this->
id.
':'.$minorid,
1928 'link_type' => SQ_LINK_TYPE_2,
1929 'major_type_code' => $major_type_code,
1930 'minor_type_code' =>
'thesaurus_term',
1932 'linkid' => $linkid,
1933 'is_dependant' => 0,
1934 'is_exclusive' => 0,
1935 'sort_order' => NULL,
1960 SQ_LINK_TYPE_1 => Array(
1961 'thesaurus_term' => Array(
1963 'exclusive' => FALSE,
1966 SQ_LINK_TYPE_2 => Array(
1967 'thesaurus_term' => Array(
1969 'exclusive' => FALSE,
1972 SQ_LINK_TYPE_3 => Array(),
2000 function getChildren($assetid, $type_code=
'thesaurus_term', $strict_type_code=TRUE, $dependant=TRUE, $sort_by=NULL)
2003 $id_parts = explode(
':', $assetid);
2004 if ($type_code ==
'thesaurus_term' || (is_array($type_code) && in_array(
'thesaurus_term', $type_code))) {
2007 if (isset($id_parts[1]) && $id_parts[0] == $this->
id) {
2014 foreach ($terms as $term_info) {
2015 $result[$this->
id.
':'.$term_info[
'termid']] = Array(Array(
'type_code' =>
'thesaurus_term'));
2038 function getParents($assetid, $type_code=
'', $strict_type_code=TRUE)
2040 if (strpos($assetid,
':') !== FALSE) {
2041 list($realid, $shadowid) = explode(
':', $assetid);
2042 $parents = Array($realid => $this->
type());
2043 $parents += $GLOBALS[
'SQ_SYSTEM']->am->getParents($realid, $type_code, $strict_type_code);
2070 function createAssetLink(&$major, &$minor, $link_type, $value=
'', $sort_order=NULL, $dependant=
'0', $exclusive=
'0', $moving=FALSE)
2072 if ($major->id == $this->id) {
2076 trigger_error(
'Cannot link term to thesaurus. Term already exists in thesaurus. Its appearance as a top-level term is governed by the HIERARCHY options of the thesaurus and cannot be forced.', E_USER_ERROR);
2080 $major_parts = explode(
':',$major->id);
2081 $majorid = array_get_index($major_parts, 1);
2083 $minor_parts = explode(
':',$minor->id);
2084 $minorid = array_get_index($minor_parts, 1);
2085 if (empty($minorid))
return NULL;
2087 $relid = empty($value) ? NULL : $value;
2092 if (($minor_parts[0] != $this->
id) || ($major_parts[0] != $this->
id)) {
2096 $minor_term = $minor->name;
2098 if (isset($major_parts[1])) {
2099 $major_term = $major->name;
2104 if (!is_null($link_info)) {
2105 trigger_localised_error(
'CORE0240');
2110 $relid = $this->
attr(
'default_rel');
2113 $term_linkid = $this->
linkTerms($minorid, $majorid, $relid);
2115 if (is_null($term_linkid))
return FALSE;
2117 return $this->
id.
':'.$term_linkid;
2142 function getPermission($assetid, $permission, $granted=NULL, $and_greater=TRUE, $expand_groups=FALSE, $all_info=FALSE)
2145 return $GLOBALS[
'SQ_SYSTEM']->am->getPermission($this->
id, $permission, $granted, $and_greater, $expand_groups, $all_info);
2161 if ($this->
attr(
'contents_changed'))
return;
2163 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
2166 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
2194 function countLinks($assetid, $side_of_link=
'major', $link_types=0, $type_code=
'', $strict_type_code=TRUE, $ignore_linkid=0)
2197 $id_parts = explode(
':', $assetid);
2199 $termid = array_get_index($id_parts, 1);
2200 if (is_null($termid))
return -1;
2202 $relations = Array();
2204 if ($side_of_link ==
'major') {
2207 $keyword =
'Parent';
2209 $get_term_function =
'count'.$keyword.
'Terms';
2210 return $this->$get_term_function($termid);
2226 $link_parts = explode(
':', $linkid);
2228 if (isset($link_parts[1])) {
2229 if (isset($link_parts[2])) {
2230 if ($link_parts[1] ==
'atoz') {
2253 if (empty($linkid))
return FALSE;
2257 $major = $link_info[
'major'];
2258 $minor = $link_info[
'minor'];
2259 $relid = $link_info[
'relid'];
2263 if ($this->
attr(
'enforce_reflection')) {
2265 if (!is_null($ref_relid)) {
2267 if (!empty($reflect_link)) {
2287 if (empty($linkid))
return FALSE;
2289 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2290 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2293 $bind_vars = Array (
2294 'linkid' => $linkid,
2295 'assetid' => $this->
id,
2298 }
catch (Exception $e) {
2299 throw new Exception(
'Unable to delete thesaurus term link due to the following database error:'.$e->getMessage());
2302 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2303 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2320 if (empty($termid))
return FALSE;
2322 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2323 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2327 $bind_vars = Array (
2328 'assetid' => $this->
id,
2329 'termid' => $termid,
2332 }
catch (Exception $e) {
2333 throw new Exception(
'Unable to delete thesaurus term due to the following database error:'.$e->getMessage());
2337 $bind_vars = Array (
2338 'termid' => $termid,
2339 'assetid' => $this->
id,
2342 }
catch (Exception $e) {
2343 throw new Exception(
'Unable to delete thesaurus links containing term due to the following database error:'.$e->getMessage());
2347 $bind_vars = Array (
2348 'assetid' => $this->
id.
':'.$termid,
2351 }
catch (Exception $e) {
2352 throw new Exception(
'Unable to delete shadow links due to the following database error:'.$e->getMessage());
2355 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2356 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2373 if (empty($relid))
return FALSE;
2375 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
2376 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
2380 $bind_vars = Array (
2381 'relation' => $relid,
2382 'assetid' => $this->
id,
2385 }
catch (Exception $e) {
2386 throw new Exception(
'Unable to delete thesaurus terms relation due to the following database error:'.$e->getMessage());
2390 $bind_vars = Array (
2391 'relation' => $relid,
2392 'assetid' => $this->
id,
2395 }
catch (Exception $e) {
2396 throw new Exception(
'Unable to delete links containing relation due to the following database error:'.$e->getMessage());
2404 $synonym_rel = $this->
attr(
'synonym_rel');
2405 if ($synonym_rel == $relid) {
2409 $abbreviation_rel = $this->
attr(
'abbreviation_rel');
2410 if ($abbreviation_rel == $relid) {
2414 $default_rel = $this->
attr(
'default_rel');
2415 if ($default_rel == $relid) {
2420 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
2421 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
2440 function moveLink($linkid, $to_parentid, $link_type, $to_parent_pos)
2460 function updateLink($linkid, $link_type=NULL, $value=NULL, $new_sort_order=NULL)
2462 $linkid_parts = explode(
':', $linkid);
2463 if (!isset($linkid_parts[1]) || ($linkid_parts[0] != $this->
id)) {
2485 $shadow_asset_ids = Array();
2488 $count = count($assetids);
2490 $is_array = is_array($assetids);
2491 $is_empty = empty($assetids);
2494 if ($is_array && !$is_empty) {
2495 foreach ($assetids as $key => $value) {
2496 assert_valid_assetid($value);
2498 }
else if (!$is_empty) {
2499 assert_valid_assetid($assetids);
2503 $sql =
'SELECT termid, thesid
2504 FROM '.SQ_TABLE_RUNNING_PREFIX.
'thes_term ';
2508 if ($is_empty)
return FALSE;
2509 $id_parts = explode(
':', $assetids);
2511 $where =
'termid = :termid AND thesid = :thesid';
2512 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
2519 return ($db_assetids == $assetids);
2523 $existing_asset_ids = Array();
2525 $in =
'termid IN (';
2526 $thesid_array = Array();
2527 for ($i=0; $i<count($assetids); $i++) {
2528 $id_parts = explode(
':', $assetids[$i]);
2530 $thesid_array[$id_parts[1]] = $id_parts[0];
2531 $in .=
MatrixDAL::quote($id_parts[1]).(($i == count($assetids) - 1) ?
')' :
',');
2534 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($in);
2537 foreach ($db_assetids as $db_id) {
2538 if ($db_id[
'thesid'] == $thesid_array[$db_id[
'termid']]) {
2539 $existing_asset_ids[] = $db_id[
'thesid'].
':'.$db_id[
'termid'];
2544 return $existing_asset_ids;
2557 return $this->
attr(
'reflections');
2573 return array_get_index($reflections, $start);
2591 if (isset($relfections[$start]) || isset($reflections[$end])) {
2595 $reflections[$start] = $end;
2596 $reflections[$end] = $start;
2615 $end = array_get_index($reflections, $start);
2616 if (is_null($end))
return FALSE;
2618 unset($reflections[$start]);
2619 unset($reflections[$end]);