1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Utilities\ArrayHelper;
13
14 15 16 17 18 19
20 class JHelperTags extends JHelper
21 {
22 23 24 25 26 27
28 protected $tagsChanged = false;
29
30 31 32 33 34 35
36 protected $replaceTags = false;
37
38 39 40 41 42 43
44 public $typeAlias = null;
45
46 47 48 49 50 51 52 53 54 55 56
57 public function addTagMapping($ucmId, JTableInterface $table, $tags = array())
58 {
59 $db = $table->getDbo();
60 $key = $table->getKeyName();
61 $item = $table->$key;
62 $typeId = $this->getTypeId($this->typeAlias);
63
64
65 if (strpos('#', implode(',', $tags)) === false)
66 {
67 $tags = self::createTagsFromField($tags);
68 }
69
70
71 $tags = array_unique($tags);
72
73 $query = $db->getQuery(true);
74 $query->insert('#__contentitem_tag_map');
75 $query->columns(
76 array(
77 $db->quoteName('type_alias'),
78 $db->quoteName('core_content_id'),
79 $db->quoteName('content_item_id'),
80 $db->quoteName('tag_id'),
81 $db->quoteName('tag_date'),
82 $db->quoteName('type_id'),
83 )
84 );
85
86 foreach ($tags as $tag)
87 {
88 $query->values(
89 $db->quote($this->typeAlias)
90 . ', ' . (int) $ucmId
91 . ', ' . (int) $item
92 . ', ' . $db->quote($tag)
93 . ', ' . $query->currentTimestamp()
94 . ', ' . (int) $typeId
95 );
96 }
97
98 $db->setQuery($query);
99
100 return (boolean) $db->execute();
101 }
102
103 104 105 106 107 108 109 110 111
112 public static function convertPathsToNames($tags)
113 {
114
115 if ($tags)
116 {
117
118 $aliases = array();
119
120 foreach ($tags as $tag)
121 {
122 if (!empty($tag->path))
123 {
124 if ($pathParts = explode('/', $tag->path))
125 {
126 $aliases = array_merge($aliases, $pathParts);
127 }
128 }
129 }
130
131
132 if ($aliases)
133 {
134
135 $aliases = array_unique($aliases);
136
137 $db = JFactory::getDbo();
138
139 $query = $db->getQuery(true)
140 ->select('alias, title')
141 ->from('#__tags')
142 ->where('alias IN (' . implode(',', array_map(array($db, 'quote'), $aliases)) . ')');
143 $db->setQuery($query);
144
145 try
146 {
147 $aliasesMapper = $db->loadAssocList('alias');
148 }
149 catch (RuntimeException $e)
150 {
151 return false;
152 }
153
154
155 if ($aliasesMapper)
156 {
157 foreach ($tags as $tag)
158 {
159 $namesPath = array();
160
161 if (!empty($tag->path))
162 {
163 if ($pathParts = explode('/', $tag->path))
164 {
165 foreach ($pathParts as $alias)
166 {
167 if (isset($aliasesMapper[$alias]))
168 {
169 $namesPath[] = $aliasesMapper[$alias]['title'];
170 }
171 else
172 {
173 $namesPath[] = $alias;
174 }
175 }
176
177 $tag->text = implode('/', $namesPath);
178 }
179 }
180 }
181 }
182 }
183 }
184
185 return $tags;
186 }
187
188 189 190 191 192 193 194 195 196
197 public function createTagsFromField($tags)
198 {
199 if (empty($tags) || $tags[0] == '')
200 {
201 return;
202 }
203 else
204 {
205
206 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
207 $tagTable = JTable::getInstance('Tag', 'TagsTable');
208 $newTags = array();
209 $canCreate = JFactory::getUser()->authorise('core.create', 'com_tags');
210
211 foreach ($tags as $key => $tag)
212 {
213
214 if (!$canCreate && strpos($tag, '#new#') !== false)
215 {
216 continue;
217 }
218
219
220 $tagText = str_replace('#new#', '', $tag);
221
222 if ($tagText === $tag)
223 {
224 $newTags[] = (int) $tag;
225 }
226 else
227 {
228
229 $tagTable->reset();
230
231
232 if ($tagTable->load(array('title' => $tagText)))
233 {
234 $newTags[] = (int) $tagTable->id;
235 }
236 else
237 {
238
239 $tagTable->id = 0;
240 $tagTable->title = $tagText;
241 $tagTable->published = 1;
242
243
244 $tagTable->language = '*';
245 $tagTable->access = 1;
246
247
248 $tagTable->setLocation($tagTable->getRootId(), 'last-child');
249
250
251 if ($tagTable->check())
252 {
253
254 $tagTable->path = $tagTable->alias;
255
256 if ($tagTable->store())
257 {
258 $newTags[] = (int) $tagTable->id;
259 }
260 }
261 }
262 }
263 }
264
265
266 $this->tags = $newTags;
267 $result = $newTags;
268 }
269
270 return $result;
271 }
272
273 274 275 276 277 278 279 280 281 282
283 public function createTagsFromMetadata($metadata)
284 {
285 $metaObject = json_decode($metadata);
286
287 if (empty($metaObject->tags))
288 {
289 return $metadata;
290 }
291
292 $tags = $metaObject->tags;
293
294 if (empty($tags) || !is_array($tags))
295 {
296 $result = $metadata;
297 }
298 else
299 {
300
301 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
302 $tagTable = JTable::getInstance('Tag', 'TagsTable');
303 $newTags = array();
304
305 foreach ($tags as $tag)
306 {
307
308 $tagText = str_replace('#new#', '', $tag);
309
310 if ($tagText === $tag)
311 {
312 $newTags[] = (int) $tag;
313 }
314 else
315 {
316
317 $tagTable->reset();
318
319
320 if ($tagTable->load(array('title' => $tagText)))
321 {
322 $newTags[] = (int) $tagTable->id;
323 }
324 else
325 {
326
327 $tagTable->id = 0;
328 $tagTable->title = $tagText;
329 $tagTable->published = 1;
330
331
332 $tagTable->language = '*';
333 $tagTable->access = 1;
334
335
336 $tagTable->setLocation($tagTable->getRootId(), 'last-child');
337
338
339 if ($tagTable->check())
340 {
341
342 $tagTable->path = $tagTable->alias;
343
344 if ($tagTable->store())
345 {
346 $newTags[] = (int) $tagTable->id;
347 }
348 }
349 }
350 }
351 }
352
353
354 $metaObject->tags = $newTags;
355 $result = json_encode($metaObject);
356 }
357
358 return $result;
359 }
360
361 362 363 364 365 366 367 368 369 370 371 372 373
374 public function deleteTagData(JTableInterface $table, $contentItemId)
375 {
376 $key = $table->getKeyName();
377
378 if (!is_array($contentItemId))
379 {
380 $contentItemId = array($key => $contentItemId);
381 }
382
383
384
385 if (count($contentItemId) != 1)
386 {
387 throw new InvalidArgumentException('Multiple primary keys are not supported as a content item id');
388 }
389
390 $result = $this->unTagItem($contentItemId[$key], $table);
391
392
393 $ucmContentTable = JTable::getInstance('Corecontent');
394
395 return $result && $ucmContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias);
396 }
397
398 399 400 401 402 403 404 405 406 407 408
409 public function getItemTags($contentType, $id, $getTagData = true)
410 {
411
412 $db = JFactory::getDbo();
413 $query = $db->getQuery(true)
414 ->select($db->quoteName('m.tag_id'))
415 ->from($db->quoteName('#__contentitem_tag_map') . ' AS m ')
416 ->where(
417 array(
418 $db->quoteName('m.type_alias') . ' = ' . $db->quote($contentType),
419 $db->quoteName('m.content_item_id') . ' = ' . (int) $id,
420 $db->quoteName('t.published') . ' = 1',
421 )
422 );
423
424 $user = JFactory::getUser();
425 $groups = implode(',', $user->getAuthorisedViewLevels());
426
427 $query->where('t.access IN (' . $groups . ')');
428
429
430 $language = JComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
431
432 if ($language !== 'all')
433 {
434 if ($language === 'current_language')
435 {
436 $language = $this->getCurrentLanguage();
437 }
438
439 $query->where($db->quoteName('language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
440 }
441
442 if ($getTagData)
443 {
444 $query->select($db->quoteName('t') . '.*');
445 }
446
447 $query->join('INNER', $db->quoteName('#__tags') . ' AS t ' . ' ON ' . $db->quoteName('m.tag_id') . ' = ' . $db->quoteName('t.id'));
448
449 $db->setQuery($query);
450 $this->itemTags = $db->loadObjectList();
451
452 return $this->itemTags;
453 }
454
455 456 457 458 459 460 461 462 463 464 465
466 public function getTagIds($ids, $prefix)
467 {
468 if (empty($ids))
469 {
470 return;
471 }
472
473 474 475 476 477 478 479 480
481 $ids = (array) $ids;
482 $ids = implode(',', $ids);
483 $ids = explode(',', $ids);
484 $ids = ArrayHelper::toInteger($ids);
485
486 $db = JFactory::getDbo();
487
488
489 $query = $db->getQuery(true)
490 ->select($db->quoteName('t.id'))
491 ->from($db->quoteName('#__tags') . ' AS t ')
492 ->join(
493 'INNER', $db->quoteName('#__contentitem_tag_map') . ' AS m'
494 . ' ON ' . $db->quoteName('m.tag_id') . ' = ' . $db->quoteName('t.id')
495 . ' AND ' . $db->quoteName('m.type_alias') . ' = ' . $db->quote($prefix)
496 . ' AND ' . $db->quoteName('m.content_item_id') . ' IN ( ' . implode(',', $ids) . ')'
497 );
498
499 $db->setQuery($query);
500
501
502 $tagsList = $db->loadColumn();
503 $this->tags = implode(',', $tagsList);
504
505 return $this->tags;
506 }
507
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
525 public function getTagItemsQuery($tagId, $typesr = null, $includeChildren = false, $orderByOption = 'c.core_title', $orderDir = 'ASC',
526 $anyOrAll = true, $languageFilter = 'all', $stateFilter = '0,1')
527 {
528
529 $db = JFactory::getDbo();
530 $query = $db->getQuery(true);
531 $user = JFactory::getUser();
532 $nullDate = $db->quote($db->getNullDate());
533 $nowDate = $db->quote(JFactory::getDate()->toSql());
534
535
536 $tagIds = (array) $tagId;
537 $tagIds = implode(',', $tagIds);
538 $tagIds = explode(',', $tagIds);
539 $tagIds = ArrayHelper::toInteger($tagIds);
540
541 $ntagsr = count($tagIds);
542
543
544
545 if ($includeChildren)
546 {
547 $tagTreeArray = array();
548
549 foreach ($tagIds as $tag)
550 {
551 $this->getTagTreeArray($tag, $tagTreeArray);
552 }
553
554 $tagIds = array_unique(array_merge($tagIds, $tagTreeArray));
555 }
556
557
558 $stateFilters = explode(',', $stateFilter);
559 $stateFilters = ArrayHelper::toInteger($stateFilters);
560
561
562 $query
563 ->select(
564 'm.type_alias'
565 . ', ' . 'm.content_item_id'
566 . ', ' . 'm.core_content_id'
567 . ', ' . 'count(m.tag_id) AS match_count'
568 . ', ' . 'MAX(m.tag_date) as tag_date'
569 . ', ' . 'MAX(c.core_title) AS core_title'
570 . ', ' . 'MAX(c.core_params) AS core_params'
571 )
572 ->select('MAX(c.core_alias) AS core_alias, MAX(c.core_body) AS core_body, MAX(c.core_state) AS core_state, MAX(c.core_access) AS core_access')
573 ->select(
574 'MAX(c.core_metadata) AS core_metadata'
575 . ', ' . 'MAX(c.core_created_user_id) AS core_created_user_id'
576 . ', ' . 'MAX(c.core_created_by_alias) AS core_created_by_alias'
577 )
578 ->select('MAX(c.core_created_time) as core_created_time, MAX(c.core_images) as core_images')
579 ->select('CASE WHEN c.core_modified_time = ' . $nullDate . ' THEN c.core_created_time ELSE c.core_modified_time END as core_modified_time')
580 ->select('MAX(c.core_language) AS core_language, MAX(c.core_catid) AS core_catid')
581 ->select('MAX(c.core_publish_up) AS core_publish_up, MAX(c.core_publish_down) as core_publish_down')
582 ->select('MAX(ct.type_title) AS content_type_title, MAX(ct.router) AS router')
583
584 ->from('#__contentitem_tag_map AS m')
585 ->join(
586 'INNER',
587 '#__ucm_content AS c ON m.type_alias = c.core_type_alias AND m.core_content_id = c.core_content_id AND c.core_state IN ('
588 . implode(',', $stateFilters) . ')'
589 . (in_array('0', $stateFilters) ? '' : ' AND (c.core_publish_up = ' . $nullDate
590 . ' OR c.core_publish_up <= ' . $nowDate . ') '
591 . ' AND (c.core_publish_down = ' . $nullDate . ' OR c.core_publish_down >= ' . $nowDate . ')')
592 )
593 ->join('INNER', '#__content_types AS ct ON ct.type_alias = m.type_alias')
594
595
596 ->join('LEFT', '#__categories AS tc ON tc.id = c.core_catid')
597
598
599 ->select("CASE WHEN c.core_created_by_alias > ' ' THEN c.core_created_by_alias ELSE ua.name END AS author")
600 ->select('ua.email AS author_email')
601
602 ->join('LEFT', '#__users AS ua ON ua.id = c.core_created_user_id')
603
604 ->where('m.tag_id IN (' . implode(',', $tagIds) . ')')
605 ->where('(c.core_catid = 0 OR tc.published = 1)');
606
607
608 if (empty($language))
609 {
610 $language = $languageFilter;
611 }
612
613 if ($language !== 'all')
614 {
615 if ($language === 'current_language')
616 {
617 $language = $this->getCurrentLanguage();
618 }
619
620 $query->where($db->quoteName('c.core_language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
621 }
622
623
624 $typesarray = self::getTypes('assocList', $typesr, false);
625
626 $typeAliases = array();
627
628 foreach ($typesarray as $type)
629 {
630 $typeAliases[] = $db->quote($type['type_alias']);
631 }
632
633 $query->where('m.type_alias IN (' . implode(',', $typeAliases) . ')');
634
635 $groups = '0,' . implode(',', array_unique($user->getAuthorisedViewLevels()));
636 $query->where('c.core_access IN (' . $groups . ')')
637 ->group('m.type_alias, m.content_item_id, m.core_content_id, core_modified_time, core_created_time, core_created_by_alias, name, author_email');
638
639
640 if ($ntagsr > 1 && $anyOrAll != 1 && $includeChildren != 1)
641 {
642
643 $query->having("COUNT('m.tag_id') = " . (int) $ntagsr);
644 }
645
646
647 if ($orderByOption === 'match_count')
648 {
649 $orderBy = 'COUNT(m.tag_id)';
650 }
651 else
652 {
653 $orderBy = 'MAX(' . $db->quoteName($orderByOption) . ')';
654 }
655
656 $query->order($orderBy . ' ' . $orderDir);
657
658 return $query;
659 }
660
661 662 663 664 665 666 667 668 669
670 public function getTagNames($tagIds)
671 {
672 $tagNames = array();
673
674 if (is_array($tagIds) && count($tagIds) > 0)
675 {
676 $tagIds = ArrayHelper::toInteger($tagIds);
677
678 $db = JFactory::getDbo();
679 $query = $db->getQuery(true)
680 ->select($db->quoteName('title'))
681 ->from($db->quoteName('#__tags'))
682 ->where($db->quoteName('id') . ' IN (' . implode(',', $tagIds) . ')');
683 $query->order($db->quoteName('title'));
684
685 $db->setQuery($query);
686 $tagNames = $db->loadColumn();
687 }
688
689 return $tagNames;
690 }
691
692 693 694 695 696 697 698 699 700 701
702 public function getTagTreeArray($id, &$tagTreeArray = array())
703 {
704
705 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
706 $table = JTable::getInstance('Tag', 'TagsTable');
707
708 if ($table->isLeaf($id))
709 {
710 $tagTreeArray[] = $id;
711
712 return $tagTreeArray;
713 }
714
715 $tagTree = $table->getTree($id);
716
717
718 if ($tagTree)
719 {
720 foreach ($tagTree as $tag)
721 {
722 $tagTreeArray[] = $tag->id;
723 }
724
725 return $tagTreeArray;
726 }
727 }
728
729 730 731 732 733 734 735 736 737 738
739 public function getTypeId($typeAlias)
740 {
741 $contentType = new JUcmType;
742
743 return $contentType->getTypeId($typeAlias);
744 }
745
746 747 748 749 750 751 752 753 754 755 756 757
758 public static function getTypes($arrayType = 'objectList', $selectTypes = null, $useAlias = true)
759 {
760
761 $db = JFactory::getDbo();
762 $query = $db->getQuery(true)
763 ->select('*');
764
765 if (!empty($selectTypes))
766 {
767 $selectTypes = (array) $selectTypes;
768
769 if ($useAlias)
770 {
771 $selectTypes = array_map(array($db, 'quote'), $selectTypes);
772
773 $query->where($db->quoteName('type_alias') . ' IN (' . implode(',', $selectTypes) . ')');
774 }
775 else
776 {
777 $selectTypes = ArrayHelper::toInteger($selectTypes);
778
779 $query->where($db->quoteName('type_id') . ' IN (' . implode(',', $selectTypes) . ')');
780 }
781 }
782
783 $query->from($db->quoteName('#__content_types'));
784
785 $db->setQuery($query);
786
787 switch ($arrayType)
788 {
789 case 'assocList':
790 $types = $db->loadAssocList();
791 break;
792
793 case 'rowList':
794 $types = $db->loadRowList();
795 break;
796
797 case 'objectList':
798 default:
799 $types = $db->loadObjectList();
800 break;
801 }
802
803 return $types;
804 }
805
806 807 808 809 810 811 812 813 814 815 816
817 public function postStoreProcess(JTableInterface $table, $newTags = array(), $replace = true)
818 {
819 if (!empty($table->newTags) && empty($newTags))
820 {
821 $newTags = $table->newTags;
822 }
823
824
825 $newTable = clone $table;
826 $newTable->reset();
827
828 $result = true;
829
830
831 if ($this->tagsChanged || (!empty($newTags) && $newTags[0] != ''))
832 {
833 if (!$newTags && $replace == true)
834 {
835
836 $key = $table->getKeyName();
837 $result = $this->deleteTagData($table, $table->$key);
838 }
839 else
840 {
841
842 $data = $this->getRowData($table);
843 $ucmContentTable = JTable::getInstance('Corecontent');
844
845 $ucm = new JUcmContent($table, $this->typeAlias);
846 $ucmData = $data ? $ucm->mapData($data) : $ucm->ucmData;
847
848 $primaryId = $ucm->getPrimaryKey($ucmData['common']['core_type_id'], $ucmData['common']['core_content_item_id']);
849 $result = $ucmContentTable->load($primaryId);
850 $result = $result && $ucmContentTable->bind($ucmData['common']);
851 $result = $result && $ucmContentTable->check();
852 $result = $result && $ucmContentTable->store();
853 $ucmId = $ucmContentTable->core_content_id;
854
855
856 $result = $result && $this->tagItem($ucmId, $table, $newTags, $replace);
857 }
858 }
859
860 return $result;
861 }
862
863 864 865 866 867 868 869 870 871 872
873 public function preStoreProcess(JTableInterface $table, $newTags = array())
874 {
875 if ($newTags != array())
876 {
877 $this->newTags = $newTags;
878 }
879
880
881 $oldTable = clone $table;
882 $oldTable->reset();
883 $key = $oldTable->getKeyName();
884 $typeAlias = $this->typeAlias;
885
886 if ($oldTable->$key && $oldTable->load())
887 {
888 $this->oldTags = $this->getTagIds($oldTable->$key, $typeAlias);
889 }
890
891
892 if ((!empty($newTags) && is_string($newTags) || (isset($newTags[0]) && $newTags[0] != '')) || isset($this->oldTags))
893 {
894 if (is_array($newTags))
895 {
896 $newTags = implode(',', $newTags);
897 }
898
899 $this->tagsChanged = (empty($this->oldTags) && !empty($newTags)) ||(!empty($this->oldTags) && $this->oldTags != $newTags) || !$table->$key;
900 }
901 }
902
903 904 905 906 907 908 909 910 911
912 public static function searchTags($filters = array())
913 {
914 $db = JFactory::getDbo();
915 $query = $db->getQuery(true)
916 ->select('a.id AS value')
917 ->select('a.path AS text')
918 ->select('a.path')
919 ->from('#__tags AS a')
920 ->join('LEFT', $db->quoteName('#__tags', 'b') . ' ON a.lft > b.lft AND a.rgt < b.rgt');
921
922
923 if (!empty($filters['flanguage']))
924 {
925 $query->where('a.language IN (' . $db->quote($filters['flanguage']) . ',' . $db->quote('*') . ') ');
926 }
927
928
929 $query->where($db->quoteName('a.alias') . ' <> ' . $db->quote('root'));
930
931
932 if (!empty($filters['like']))
933 {
934 $query->where(
935 '(' . $db->quoteName('a.title') . ' LIKE ' . $db->quote('%' . $filters['like'] . '%')
936 . ' OR ' . $db->quoteName('a.path') . ' LIKE ' . $db->quote('%' . $filters['like'] . '%') . ')'
937 );
938 }
939
940
941 if (!empty($filters['title']))
942 {
943 $query->where($db->quoteName('a.title') . ' = ' . $db->quote($filters['title']));
944 }
945
946
947 if (isset($filters['published']) && is_numeric($filters['published']))
948 {
949 $query->where('a.published = ' . (int) $filters['published']);
950 }
951
952
953 if (isset($filters['parent_id']) && is_numeric($filters['parent_id']))
954 {
955 JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
956 $tagTable = JTable::getInstance('Tag', 'TagsTable');
957
958 if ($children = $tagTable->getTree($filters['parent_id']))
959 {
960 foreach ($children as $child)
961 {
962 $childrenIds[] = $child->id;
963 }
964
965 $query->where('a.id IN (' . implode(',', $childrenIds) . ')');
966 }
967 }
968
969 $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.parent_id, a.published, a.path')
970 ->order('a.lft ASC');
971
972
973 $db->setQuery($query);
974
975 try
976 {
977 $results = $db->loadObjectList();
978 }
979 catch (RuntimeException $e)
980 {
981 return array();
982 }
983
984
985 return self::convertPathsToNames($results);
986 }
987
988 989 990 991 992 993 994 995 996
997 public function tagDeleteInstances($tag_id)
998 {
999
1000 $db = JFactory::getDbo();
1001 $query = $db->getQuery(true)
1002 ->delete($db->quoteName('#__contentitem_tag_map'))
1003 ->where($db->quoteName('tag_id') . ' = ' . (int) $tag_id);
1004 $db->setQuery($query);
1005 $db->execute();
1006 }
1007
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
1020 public function tagItem($ucmId, JTableInterface $table, $tags = array(), $replace = true)
1021 {
1022 $key = $table->get('_tbl_key');
1023 $oldTags = $this->getTagIds((int) $table->$key, $this->typeAlias);
1024 $oldTags = explode(',', $oldTags);
1025 $result = $this->unTagItem($ucmId, $table);
1026
1027 if ($replace)
1028 {
1029 $newTags = $tags;
1030 }
1031 else
1032 {
1033 if ($tags == array())
1034 {
1035 $newTags = $table->newTags;
1036 }
1037 else
1038 {
1039 $newTags = $tags;
1040 }
1041
1042 if ($oldTags[0] != '')
1043 {
1044 $newTags = array_unique(array_merge($newTags, $oldTags));
1045 }
1046 }
1047
1048 if (is_array($newTags) && count($newTags) > 0 && $newTags[0] != '')
1049 {
1050 $result = $result && $this->addTagMapping($ucmId, $table, $newTags);
1051 }
1052
1053 return $result;
1054 }
1055
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
1067 public function unTagItem($contentId, JTableInterface $table, $tags = array())
1068 {
1069 $key = $table->getKeyName();
1070 $id = $table->$key;
1071 $db = JFactory::getDbo();
1072 $query = $db->getQuery(true)
1073 ->delete('#__contentitem_tag_map')
1074 ->where($db->quoteName('type_alias') . ' = ' . $db->quote($this->typeAlias))
1075 ->where($db->quoteName('content_item_id') . ' = ' . (int) $id);
1076
1077 if (is_array($tags) && count($tags) > 0)
1078 {
1079 $tags = ArrayHelper::toInteger($tags);
1080
1081 $query->where($db->quoteName('tag_id') . ' IN (' . implode(',', $tags) . ')');
1082 }
1083
1084 $db->setQuery($query);
1085
1086 return (boolean) $db->execute();
1087 }
1088 }
1089