Inheritance: extends Pimcore\Model\AbstractModel
Example #1
0
File: Dao.php Project: sfie/pimcore
 /**
  * Loads a list of tags for the specifies parameters, returns an array of Element\Tag elements
  *
  * @return array
  */
 public function load()
 {
     $tagsData = $this->db->fetchCol("SELECT id FROM tags" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     $tags = array();
     foreach ($tagsData as $tagData) {
         if ($tag = Model\Element\Tag::getById($tagData)) {
             $tags[] = $tag;
         }
     }
     $this->model->setTags($tags);
     return $tags;
 }
Example #2
0
 public function updateAction()
 {
     $tag = Pimcore\Model\Element\Tag::getById($this->getParam("id"));
     if ($tag) {
         $parentId = $this->getParam("parentId");
         if ($parentId || $parentId === "0") {
             $tag->setParentId(intval($parentId));
         }
         if ($this->getParam("text")) {
             $tag->setName(strip_tags($this->getParam("text")));
         }
         $tag->save();
         $this->_helper->json(['success' => true]);
     } else {
         throw new \Exception("Tag with ID " . $this->getParam("id") . " not found.");
     }
 }
Example #3
0
 public function doBatchAssignmentAction()
 {
     $cType = strip_tags($this->getParam("elementType"));
     $assignedTags = json_decode($this->getParam("assignedTags"));
     $elementIds = json_decode($this->getParam("childrenIds"));
     $doCleanupTags = $this->getParam("removeAndApply") == "true";
     Tag::batchAssignTagsToElement($cType, $elementIds, $assignedTags, $doCleanupTags);
     $this->_helper->json(['success' => true]);
 }
Example #4
0
 /**
  * @return Tag
  */
 public function getParent()
 {
     if ($this->parent == null) {
         $this->parent = Tag::getById($this->getParentId());
     }
     return $this->parent;
 }
Example #5
0
\Pimcore::getEventManager()->attach(["admin.object.get.preSendData", "admin.asset.get.preSendData", "admin.document.get.preSendData"], ["\\Pimcore\\WorkflowManagement\\EventHandler", "adminElementGetPreSendData"]);
// backed search
foreach (["asset", "object", "document"] as $type) {
    \Pimcore::getEventManager()->attach($type . ".postAdd", ["Pimcore\\Search\\EventHandler", "postAddElement"]);
    \Pimcore::getEventManager()->attach($type . ".postUpdate", ["Pimcore\\Search\\EventHandler", "postUpdateElement"]);
    \Pimcore::getEventManager()->attach($type . ".preDelete", ["Pimcore\\Search\\EventHandler", "preDeleteElement"]);
}
// UUID
$conf = \Pimcore\Config::getSystemConfig();
if ($conf->general->instanceIdentifier) {
    foreach (["asset", "object", "document", "object.class"] as $type) {
        \Pimcore::getEventManager()->attach($type . ".postAdd", function ($e) {
            \Pimcore\Model\Tool\UUID::create($e->getTarget());
        });
        \Pimcore::getEventManager()->attach($type . ".postDelete", function ($e) {
            $uuidObject = \Pimcore\Model\Tool\UUID::getByItem($e->getTarget());
            if ($uuidObject instanceof \Pimcore\Model\Tool\UUID) {
                $uuidObject->delete();
            }
        });
    }
}
//assign tags after copying an element
Pimcore::getEventManager()->attach(["document.postCopy", "asset.postCopy", "object.postCopy"], function (\Zend_EventManager_Event $e) {
    $elementType = strtok($e->getName(), '.');
    /** @var \Pimcore\Model\Element\AbstractElement $copiedElement */
    $copiedElement = $e->getTarget();
    /** @var \Pimcore\Model\Element\AbstractElement $baseElement */
    $baseElement = $e->getParam('base_element');
    \Pimcore\Model\Element\Tag::setTagsForElement($elementType, $copiedElement->getId(), \Pimcore\Model\Element\Tag::getTagsForElement($elementType, $baseElement->getId()));
});
Example #6
0
 /**
  * @param $cType
  * @param $cId
  * @return Model\Element\Tag[]
  */
 public function getTagsForElement($cType, $cId)
 {
     $tags = [];
     $tagIds = $this->db->fetchCol("SELECT tagid FROM tags_assignment WHERE cid = ? AND ctype = ?", [$cId, $cType]);
     foreach ($tagIds as $tagId) {
         $tags[] = Model\Element\Tag::getById($tagId);
     }
     array_filter($tags);
     @usort($tags, function ($left, $right) {
         return strcmp($left->getNamePath(), $right->getNamePath());
     });
     return $tags;
 }
Example #7
0
<?php

/**
 * Pimcore
 *
 * This source file is subject to the GNU General Public License version 3 (GPLv3)
 * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
 * files that are distributed with this source code.
 *
 * @copyright  Copyright (c) 2009-2015 pimcore GmbH (http://www.pimcore.org)
 * @license    http://www.pimcore.org/license     GNU General Public License version 3 (GPLv3)
 */
/**
 * this file is included at end of startup and attaches event listeners for pimcore internal events
 */
// attach global shutdown event
Pimcore::getEventManager()->attach("system.shutdown", array("Pimcore", "shutdown"), 9999);
// remove assets on element delete
Pimcore::getEventManager()->attach("asset.postDelete", function (\Zend_EventManager_Event $e) {
    $asset = $e->getTarget();
    \Pimcore\Model\Element\Tag::setTagsForElement("asset", $asset->getId(), []);
}, 9999);
Example #8
0
 /**
  * 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;
 }