public function doSave($con = null) { parent::doSave($con); if (!$this->getValue('parent')) { $treeObject = Doctrine_Core::getTable('Category')->getTree(); $roots = $treeObject->fetchRoots(); //If root was deleted, recreate if (count($roots) == 0) { $rootCategory = new Category(); $rootCategory->setName("Categories"); $rootCategory->setActive(true); $rootCategory->save(); $treeObject->createRoot($rootCategory); $parent = $rootCategory; } else { $parent = Doctrine::getTable('Category')->findOneById($roots[0]['id']); } if ($this->isNew()) { $this->getObject()->getNode()->insertAsFirstChildOf($parent); } else { $this->getObject()->getNode()->moveAsFirstChildOf($parent); } } elseif ($this->getValue('parent')) { $parent = Doctrine::getTable('Category')->findOneById($this->getValue('parent')); if ($this->isNew()) { $this->getObject()->getNode()->insertAsLastChildOf($parent); } else { $this->getObject()->getNode()->moveAsLastChildOf($parent); } } }
/** * Updates and saves the current object. Overrides the parent_id method * by treating the record as a node in the nested set and updating * the tree accordingly. * * @param Doctrine_Connection $con An optional connection parameter */ public function doSave($con = null) { // save the record itself parent::doSave($con); // if a parent_id has been specified, add/move this node to be the child of that node if ($this->getValue('parent_id')) { $parent_id = Doctrine::getTable('Category')->findOneById($this->getValue('parent_id')); if ($this->isNew()) { $this->getObject()->getNode()->insertAsLastChildOf($parent_id); } else { $this->getObject()->getNode()->moveAsLastChildOf($parent_id); } } else { $categoryTree = Doctrine::getTable('Category')->getTree(); if ($this->isNew()) { $categoryTree->createRoot($this->getObject()); } else { $this->getObject()->getNode()->makeRoot($this->getObject()->getId()); } } }
public function configure() { parent::configure(); }