getById() public static méthode

public static getById ( $id ) : Pimcore\Model\Element\Tag
$id
Résultat Pimcore\Model\Element\Tag
Exemple #1
0
 /**
  * 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;
 }
Exemple #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.");
     }
 }
Exemple #3
0
 public function removeTagFromElementAction()
 {
     $assginmentCId = intval($this->getParam("assignmentElementId"));
     $assginmentCType = strip_tags($this->getParam("assignmentElementType"));
     $tagId = intval($this->getParam("tagId"));
     $tag = Tag::getById($tagId);
     if ($tag) {
         Tag::removeTagFromElement($assginmentCType, $assginmentCId, $tag);
         $this->_helper->json(['success' => true, 'id' => $tag->getId()]);
     } else {
         $this->_helper->json(['success' => false]);
     }
 }
Exemple #4
0
 /**
  * @return Tag
  */
 public function getParent()
 {
     if ($this->parent == null) {
         $this->parent = Tag::getById($this->getParentId());
     }
     return $this->parent;
 }
Exemple #5
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;
 }