コード例 #1
0
 /**
  * @param ItemModel $item
  *
  * @return $this
  *
  * @todo события
  */
 public function removeItem(ItemModel $item)
 {
     foreach ($this->getAttributes() as $attribute) {
         if ($attribute->isType('image') and $item->hasAttribute($attribute->getName())) {
             // @todo сделать кеширование при первом же вытаскивании данных о записи. тоже самое в saveItem(), а еще лучше выделить этот код в отельный защищенный метод.
             $tableItems = $this->em->getClassMetadata($this->configuration->getItemClass())->getTableName();
             $sql = "SELECT * FROM {$tableItems} WHERE id = '{$item->getId()}'";
             $res = $this->em->getConnection()->query($sql)->fetch();
             $fileId = null;
             if (!empty($res)) {
                 $previousAttributes = unserialize($res['attributes']);
                 $fileId = $previousAttributes[$attribute->getName()];
             }
             $this->mc->remove($fileId);
         }
     }
     $this->em->remove($item);
     $this->em->flush();
     // Надо делать полный flush т.к. каскадом удаляются связи с категориями.
     return $this;
 }
コード例 #2
0
 /**
  * @return int
  */
 public function getId()
 {
     return $this->item->getId();
 }