All pastes #924776 Raw Edit

StR

public php v1 · immutable
·published 2008-03-01 18:21 UTC
rendered paste body
    /**     * Inserts a new leaf, it is inserted at the end, as an append     *     * @param array             $data   Data to insert     * @param Biznet_Model_Tree $parent Parent to this leaf     *     * @return int     */    public function insert($data, Biznet_Model_Tree $parent=NULL)    {        $this->_db->beginTransaction();        $sql = "LOCK TABLE {$this->_name} WRITE";        $this->_db->query($sql);        if ($parent) {            $sql = "UPDATE {$this->_name} set rgt=rgt+2 where rgt >= ?";            $this->_db->query($sql, $parent->getRight());            $sql = "UPDATE {$this->_name} set lft=lft+2 where lft > ?";            $this->_db->query($sql, $parent->getRight());                        $brothers = $parent->getChildren();            // Checks if parent is empty            if (!count($brothers)) {                $data['lft'] = $parent->getLeft() +1;                $data['rgt'] = $parent->getLeft() +2;            } else {                $lastBroter  = $brothers[count($brothers)];                $data['lft'] = $lastBrother->getRight() +1;                $data['rgt'] = $lastBrother->getRight() +2;            }        } else {          // @todo: por aquí voy....          }        $id =  parent::insert($data);                $sql = "LOCK TABLE {$this->_name} WRITE";        $this->_db->query($sql);        $this->_db->commit();            return $id;    }