예제 #1
0
 /**
  * Process post data before save
  *
  * @param Varien_Object $object
  * @return EM_Blog_Model_Resource_Post
  */
 protected function _beforeSave(Varien_Object $object)
 {
     /**
      * Check if declared category ids in object data.
      */
     if ($object->hasCategoryIds()) {
         $categoryIds = Mage::getResourceSingleton('blog/category')->verifyIds($object->getCategoryIds());
         $object->setCategoryIds($categoryIds);
     }
     if ($object->getId()) {
         $oldImage = $object->getImage();
         // Remove Old Image
         if (is_array($oldImage)) {
             if (isset($oldImage['delete'])) {
                 $path = Mage::getBaseDir('media') . DS . 'emblog' . DS . 'post' . DS;
                 $nameImage = $oldImage['value'];
                 /* Remove primary image */
                 if (is_file($path . $nameImage)) {
                     unlink($path . $nameImage);
                 }
                 /* Remove thumbnail image */
                 $thumbnailWidth = Mage::getStoreConfig('blog/info/thumbnail_width');
                 $thumbnailHeight = Mage::getStoreConfig('blog/info/thumbnail_height');
                 if (is_file($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage)) {
                     unlink($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage);
                 }
                 /* Remove thumbnail image at recent post blog */
                 $thumbnailWidth = Mage::getStoreConfig('blog/info/recent_thumbnail_width');
                 $thumbnailHeight = Mage::getStoreConfig('blog/info/recent_thumbnail_height');
                 if (is_file($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage)) {
                     unlink($path . 'thumbnail' . DS . "{$thumbnailWidth}x{$thumbnailHeight}" . DS . $nameImage);
                 }
             }
         }
     }
     return parent::_beforeSave($object);
 }
예제 #2
0
 /**
  * Process category data before saving
  * prepare path and increment children count for parent categories
  *
  * @param Varien_Object $object
  * @return EM_Blog_Model_Resource_Category
  */
 protected function _beforeSave(Varien_Object $object)
 {
     parent::_beforeSave($object);
     if (!$object->getChildrenCount()) {
         $object->setChildrenCount(0);
     }
     if ($object->getLevel() === null) {
         $object->setLevel(1);
     }
     if (!$object->getId()) {
         $object->setPosition($this->_getMaxPosition($object->getPath()) + 1);
         $path = explode('/', $object->getPath());
         $level = count($path);
         $object->setLevel($level);
         if ($level) {
             $object->setParentId($path[$level - 1]);
         }
         $object->setPath($object->getPath() . '/');
         $toUpdateChild = explode('/', $object->getPath());
         $this->_getWriteAdapter()->update($this->getEntityTable(), array('children_count' => new Zend_Db_Expr('children_count+1')), array('entity_id IN(?)' => $toUpdateChild));
     } else {
         $oldImage = $object->getImage();
         if (is_array($oldImage)) {
             if (isset($oldImage['delete'])) {
                 $path = Mage::getBaseDir('media') . DS . 'emblog' . DS . 'category' . DS;
                 $nameImage = $oldImage['value'];
                 /* Remove primary image */
                 if (is_file($path . $nameImage)) {
                     unlink($path . $nameImage);
                 }
             }
         }
     }
     return $this;
 }