/** * _storeInternalFields(): Manipulate _primaryTableRow to preserve the * nested set property. * * @return int The primary id of the created row. */ public function _storeInternalFields() { if (is_null($this->getRoleId())) { throw new Exception("RoleId must be set when storing Collection!"); } if ($this->isNewRecord()) { $nested_sets = $this->_primaryTableRow->getTable(); // Insert new node into the tree. The position is specified by // PositionKey = { root, First-/LastChild, Next-/PrevSibling } // PositionId = { roleId, ParentId, SiblingId } $position_key = $this->getPositionKey(); $position_id = $this->getPositionId(); if (false === isset($position_key)) { throw new Exception('PositionKey must be set!'); } $data = null; switch ($position_key) { case 'FirstChild': $data = $nested_sets->insertFirstChild($position_id); break; case 'LastChild': $data = $nested_sets->insertLastChild($position_id); break; case 'NextSibling': $data = $nested_sets->insertNextSibling($position_id); break; case 'PrevSibling': $data = $nested_sets->insertPrevSibling($position_id); break; case 'Root': $data = $nested_sets->createRoot(); break; default: throw new Exception("PositionKey({$position_key}) invalid."); } // var_dump($data); // Dirty fix: After storing the nested set information, the row // has still the old information. But we need the role_id in // many other places! // $this->setRoleId( $data['role_id'] ); // Store nested set information in current table row. $this->_primaryTableRow->setFromArray($data); } // var_dump( $this->_primaryTableRow ); return parent::_storeInternalFields(); }