FOF30\Model\TreeModel::getParent PHP Метод

getParent() публичный Метод

Returns the immediate parent of the current node
public getParent ( ) : static
Результат static
    public function getParent()
    {
        // Sanity checks on current node position
        if ($this->lft >= $this->rgt) {
            throw new TreeInvalidLftRgtCurrent();
        }
        if ($this->isRoot()) {
            return $this;
        }
        if (empty($this->treeParent) || !is_object($this->treeParent) || !$this->treeParent instanceof TreeModel) {
            $db = $this->getDbo();
            $fldLft = $db->qn($this->getFieldAlias('lft'));
            $fldRgt = $db->qn($this->getFieldAlias('rgt'));
            $query = $db->getQuery(true)->select($db->qn('parent') . '.' . $fldLft)->from($db->qn($this->tableName) . ' AS ' . $db->qn('node'))->join('CROSS', $db->qn($this->tableName) . ' AS ' . $db->qn('parent'))->where($db->qn('node') . '.' . $fldLft . ' >= ' . $db->qn('parent') . '.' . $fldLft)->where($db->qn('node') . '.' . $fldLft . ' <= ' . $db->qn('parent') . '.' . $fldRgt)->where($db->qn('node') . '.' . $fldLft . ' = ' . $db->q($this->lft))->order($db->qn('parent') . '.' . $fldLft . ' DESC');
            $targetLft = $db->setQuery($query, 1, 1)->loadResult();
            $this->treeParent = $this->getClone()->reset()->whereRaw($fldLft . ' = ' . $db->q($targetLft))->firstOrFail();
        }
        return $this->treeParent;
    }