18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
39 $this->_ser_attrs = TRUE;
40 $this->
Asset($assetid);
58 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
59 if (!system_asset_fns_create_pre_check($this)) {
63 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
64 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
66 if ($linkid = parent::create($link)) {
67 if (!system_asset_fns_create_cleanup($this)) {
73 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
75 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
78 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
95 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
125 $tag_links = Array();
126 $notice_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($assetid, SQ_LINK_NOTICE);
127 foreach ($notice_links as $notice_link) {
128 $id_parts = explode(
':', $notice_link[
'minorid']);
129 if (!empty($id_parts[1])) {
130 $thes_id = $id_parts[0];
131 if (empty($thesaurus_filter_ids) || in_array($thes_id, $thesaurus_filter_ids)) {
132 $thes = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($thes_id,
'thesaurus', TRUE);
133 if (!is_null($thes)) {
134 $tag_term_exists = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($notice_link[
'minorid'],
'thesaurus_term', FALSE);
135 if (!is_null($tag_term_exists)) {
136 $tag_links[] = $notice_link;
160 if (!is_array($tagids)) $tagids = Array($tagids);
164 return !empty($tag_link);
166 $array_keys = array_keys($tag_link);
167 $result = array_diff($tagids, $array_keys);
168 return empty($result);
185 $tag_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($assetid, $tagids, SQ_LINK_NOTICE);
186 if (isset($tag_links[
'minorid'])) {
187 $tag_links = Array($tag_links);
192 foreach ($tag_links as $link) {
193 $links[$link[
'minorid']] = $link;
213 if (!is_array($tagid)) {
214 $tagids = Array($tagid);
220 $asset_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($tagids, SQ_LINK_NOTICE, NULL, FALSE,
'minor');
242 if (!is_array($relator_id)) {
243 $relator_ids = Array($relator_id);
245 $relator_ids = $relator_id;
249 $relator_weightings = Array();
250 foreach ($relator_ids as $relator_id) {
251 $tag_links = $this->
getTagLinks($relator_id, $thesaurus_filter_ids);
252 foreach ($tag_links as $tag_link) {
253 $tag_id = $tag_link[
'minorid'];
254 $current_value = array_get_index($relator_weightings, $tag_id, 0);
255 $relator_weightings[$tag_id] = $current_value + $tag_link[
'value'];
261 $all_related_asset_links = $this->
getAssetLinksByTag(array_keys($relator_weightings));
264 $related_ids = Array();
266 foreach ($all_related_asset_links as $tag_id => $related_asset_links) {
267 $multiplier = array_get_index($relator_weightings, $tag_id);
269 if (is_null($multiplier))
continue;
271 foreach ($related_asset_links as $one_related_link) {
272 $related_assetid = $one_related_link[
'majorid'];
273 $current_value = array_get_index($related_ids, $related_assetid, 0);
274 $related_ids[$related_assetid] = $current_value + $multiplier * $one_related_link[
'value'];
278 arsort($related_ids);
296 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
int) $assetid);
297 if (is_null($asset))
return TRUE;
298 $edit_fns = $asset->getEditFns();
299 return isset($edit_fns->static_screens[
'tagging']);
314 function setTag($assetid, $tagids, $weight)
320 if (!is_array($tagids)) $tagids = Array($tagids);
322 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
323 if (is_null($asset))
return 0;
326 foreach ($tagids as $tagid) {
329 trigger_localised_error(
'CORE0274', E_USER_WARNING);
334 $new_tag_object = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($tagid);
335 if (is_null($new_tag_object)) {
336 trigger_localised_error(
'SYS0087', E_USER_WARNING, $tagid);
343 $already_tagged = FALSE;
344 foreach ($tag_links as $link) {
345 if ($tagid == $link[
'minorid']) {
346 $already_tagged = TRUE;
347 if ($weight == $link[
'value']) {
352 trigger_localised_error(
'CORE0275', E_USER_WARNING, $assetid, $weight);
359 if (!$already_tagged) {
360 if (!$GLOBALS[
'SQ_SYSTEM']->am->createAssetLink($asset, $new_tag_object, SQ_LINK_NOTICE, $weight)) {
369 return ($has_error) ? 0 : 1;
389 if (!is_array($tagids)) $tagids = Array($tagids);
391 foreach ($tagids as $tag) {
393 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($assetid, $tag, SQ_LINK_NOTICE);
395 trigger_localised_error(
'CORE0277', E_USER_WARNING, $tag, $assetid);
399 if (!$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($link[
'linkid'])) {
400 trigger_localised_error(
'CORE0278', E_USER_WARNING, $tag, $assetid, $link[
'linkid']);
406 return ($has_error) ? 0 : 1;
426 $tagid = $thes->getTermIdByName($tag);
427 return $this->
setTag($assetid, $tagid, $weight);
441 if ($this->
attr(
'thesaurus')) {
442 $thes = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->
attr(
'thesaurus'));
460 $success = $GLOBALS[
'SQ_SYSTEM']->am->updateLink($linkid, SQ_LINK_NOTICE, $weight);
479 $id_parts = explode(
':', $tagid);
480 if ($this->
attr(
'thesaurus') != $id_parts[0]) {
499 return $this->
attr(
'restrict_tag_source');