Ejemplo n.º 1
0
 public function save(PropelPDO $con = null)
 {
     if ($this->isNew()) {
         $numOfCatsForPartner = categoryPeer::doCount(new Criteria());
         if ($numOfCatsForPartner >= Partner::MAX_NUMBER_OF_CATEGORIES) {
             throw new kCoreException("Max number of categories was reached", kCoreException::MAX_NUMBER_OF_CATEGORIES_REACHED);
         }
     }
     // set the depth of the parent category + 1
     if ($this->isNew() || $this->isColumnModified(categoryPeer::PARENT_ID)) {
         $parentCat = $this->getParentCategory();
         if ($this->getParentId() !== 0) {
             $this->setDepth($parentCat->getDepth() + 1);
         } else {
             $this->setDepth(0);
         }
         $this->setChildsDepth();
     }
     if ($this->getDepth() >= self::MAX_CATEGORY_DEPTH) {
         throw new kCoreException("Max depth was reached", kCoreException::MAX_CATEGORY_DEPTH_REACHED);
     }
     if ($this->isColumnModified(categoryPeer::NAME) || $this->isColumnModified(categoryPeer::PARENT_ID)) {
         $this->updateFullName();
         $this->renameOnEntries();
     }
     // happens in 3 cases:
     // 1. name of the current category was updated
     // 2. full name of the parent category was updated and it was set here as child
     // 3. parent id was changed
     if ($this->isColumnModified(categoryPeer::FULL_NAME)) {
         $this->setChildsFullNames();
     }
     // save the childs
     foreach ($this->childs_for_save as $child) {
         $child->save();
     }
     $this->childs_for_save = array();
     if ($this->isColumnModified(categoryPeer::DELETED_AT) && $this->getDeletedAt() !== null) {
         $this->moveEntriesToParent();
     }
     if ($this->isColumnModified(categoryPeer::PARENT_ID) && !$this->isNew()) {
         // decrease for the old parent category
         if ($this->old_parent_id) {
             $oldParentCat = categoryPeer::retrieveByPK($this->old_parent_id);
         }
         if ($oldParentCat) {
             $oldParentCat->decrementEntriesCount($this->entries_count);
         }
         // increase for the new parent category
         $newParentCat = categoryPeer::retrieveByPK($this->parent_id);
         if ($newParentCat) {
             $newParentCat->incrementEntriesCount($this->entries_count);
         }
         $this->old_parent_id = null;
     }
     parent::save($con);
 }
Ejemplo n.º 2
0
 public function postInsert(PropelPDO $con = null)
 {
     parent::postInsert($con);
     if ($this->getFullIds() == null) {
         $this->reSetFullIds();
         parent::save();
     }
     if (!$this->alreadyInSave) {
         kEventsManager::raiseEvent(new kObjectAddedEvent($this));
     }
     kEventsManager::flushEvents();
     if ($this->getParentCategory()) {
         $parentCategory = $this->getParentCategory();
         if ($parentCategory) {
             $parentCategory->reSetDirectSubCategoriesCount();
             $parentCategory->save();
         }
     }
 }