FOF30\Model\TreeModel::onAfterDelete PHP Méthode

onAfterDelete() protected méthode

protected onAfterDelete ( $oid )
    protected function onAfterDelete($oid)
    {
        $db = $this->getDbo();
        $myLeft = $this->lft;
        $myRight = $this->rgt;
        $fldLft = $db->qn($this->getFieldAlias('lft'));
        $fldRgt = $db->qn($this->getFieldAlias('rgt'));
        // Move all siblings to the left
        $width = $this->rgt - $this->lft + 1;
        // Wrap everything in a transaction
        $db->transactionStart();
        try {
            // Shrink lft values
            $query = $db->getQuery(true)->update($db->qn($this->getTableName()))->set($fldLft . ' = ' . $fldLft . ' - ' . $width)->where($fldLft . ' > ' . $db->q($myLeft));
            $db->setQuery($query)->execute();
            // Shrink rgt values
            $query = $db->getQuery(true)->update($db->qn($this->getTableName()))->set($fldRgt . ' = ' . $fldRgt . ' - ' . $width)->where($fldRgt . ' > ' . $db->q($myRight));
            $db->setQuery($query)->execute();
            // Commit the transaction
            $db->transactionCommit();
        } catch (\Exception $e) {
            // Roll back the transaction on error
            $db->transactionRollback();
            throw $e;
        }
        return $this;
    }

Usage Example

Exemple #1
0
 public function onAfterDelete($oid)
 {
     if (isset($this->methods['onAfterDelete'])) {
         $func = $this->methods['onAfterDelete'];
         return call_user_func_array($func, array($this, $oid));
     }
     return parent::onAfterDelete($oid);
 }