protected function convertTagToArray(Tag $tag, $showSelection, $assignedTagIds, $loadChildren = false) { $tagArray = ["id" => $tag->getId(), "text" => $tag->getName(), "path" => $tag->getNamePath(), "expandable" => $tag->hasChildren(), "iconCls" => "pimcore_icon_element_tags", "qtipCfg" => ["title" => "ID: " . $tag->getId()]]; if ($showSelection) { $tagArray["checked"] = isset($assignedTagIds[$tag->getId()]); } if ($loadChildren) { $children = $tag->getChildren(); foreach ($children as $child) { $tagArray['children'][] = $this->convertTagToArray($child, $showSelection, $assignedTagIds); } } return $tagArray; }
public function addAction() { $tag = new Pimcore\Model\Element\Tag(); $tag->setName(strip_tags($this->getParam('text'))); $tag->setParentId(intval($this->getParam('parentId'))); $tag->save(); $this->_helper->json(['success' => true, 'id' => $tag->getId()]); }
/** * Retrieves all elements that have a specific tag or one of its child tags assigned * * @param Tag $tag The tag to search for * @param string $type The type of elements to search for: 'document', 'asset' or 'object' * @param array $subtypes Filter by subtypes, eg. page, object, email, folder etc. * @param array $classNames For objects only: filter by classnames * @param bool $considerChildTags Look for elements having one of $tag's children assigned * * @return array */ public function getElementsForTag(Tag $tag, $type, array $subtypes = [], array $classNames = [], $considerChildTags = false) { $elements = []; $map = ['document' => ['documents', 'id', 'type', '\\Pimcore\\Model\\Document'], 'asset' => ['assets', 'id', 'type', '\\Pimcore\\Model\\Asset'], 'object' => ['objects', 'o_id', 'o_type', '\\Pimcore\\Model\\Object\\AbstractObject']]; $select = $this->db->select()->from('tags_assignment', [])->where('tags_assignment.ctype = ?', $type); if (true === $considerChildTags) { $select->joinInner('tags', 'tags.id = tags_assignment.tagid', ['tags_id' => 'id']); $select->where('(' . $this->db->quoteInto('tags_assignment.tagid = ?', $tag->getId()) . ' OR ' . $this->db->quoteInto('tags.idPath LIKE ?', $tag->getFullIdPath() . "%") . ')'); } else { $select->where('tags_assignment.tagid = ?', $tag->getId()); } $select->joinInner(['el' => $map[$type][0]], 'tags_assignment.cId = el.' . $map[$type][1], ['el_id' => $map[$type][1]]); if (!empty($subtypes)) { $select->where($map[$type][2] . ' IN (?)', $subtypes); } if ('object' === $type && !empty($classNames)) { $select->where('o_className IN (?)', $classNames); } $res = $this->db->query($select); while ($row = $res->fetch()) { $el = $map[$type][3]::getById($row['el_id']); if ($el) { $elements[] = $el; } } return $elements; }