Jarves\Storage\Propel::getParents PHP Method

getParents() public method

public getParents ( $pk, $options = null )
    public function getParents($pk, $options = null)
    {
        $query = $this->getQueryClass();
        $item = $query->findPK($this->getPropelPk($pk));
        if (!$item) {
            throw new \Exception('Can not found entry. ' . var_export($pk, true));
        }
        if (!$item->getRgt()) {
            throw new \Exception('Entry it not in a tree. ' . var_export($pk, true));
        }
        list($fields, $relations, $relationFields) = $this->getFields(@$options['fields']);
        $selects = array_keys($fields);
        $selects[] = 'Lft';
        $selects[] = 'Rgt';
        //        $selects[] = 'Title';
        $query->select($selects);
        $this->mapOptions($query, $options);
        $this->mapToOneRelationFields($query, $relations, $relationFields);
        $query->ancestorsOf($item);
        $query->orderByLevel();
        $stmt = $this->getStm($query);
        $clazz = $this->getPhpName();
        $result = array();
        if ($this->definition['nestedRootAsObject']) {
            //fetch root object entry
            $scopeField = 'get' . ucfirst($this->definition['nestedRootObjectField']);
            $scopeId = $item->{$scopeField}();
            $root = $this->objects->get($this->definition['nestedRootObject'], $scopeId);
            $root['_object'] = $this->definition['nestedRootObject'];
            $result[] = $root;
        }
        $item = false;
        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
            //propels nested set requires a own root item, we do not return this
            if (false === $item) {
                $item = true;
                continue;
            }
            $item = $this->populateRow($clazz, $row, $selects, $relations, $relationFields, $options['permissionCheck']);
            $result[] = $item;
        }
        return $result;
    }