Get the extra attributes.

@param  array[] $insertedPKs
@param  Model   $currentParent
@return array
184732
protected function getExtraAttributes(array $insertedPKs, Model $currentParent)
    {
        if (!$this->guessedFormatters) {
            return [];
        }

        $extra = array_merge($this->guessedFormatters, $this->customAttributes);

        return $this->evaluateClosureFormatters($extra, $insertedPKs, $currentParent);
    }
442735
private function parseRelationshipLinks(
        SchemaInterface $parentSchema,
        $parentData,
        string $name,
        array $description
    ): array {
        $addSelfLink    = $description[SchemaInterface::RELATIONSHIP_LINKS_SELF] ??
            $parentSchema->isAddSelfLinkInRelationshipByDefault($name);
        $addRelatedLink = $description[SchemaInterface::RELATIONSHIP_LINKS_RELATED] ??
            $parentSchema->isAddRelatedLinkInRelationshipByDefault($name);
        \assert(\is_bool($addSelfLink) === true || $addSelfLink instanceof LinkInterface);
        \assert(\is_bool($addRelatedLink) === true || $addRelatedLink instanceof LinkInterface);

        $schemaLinks = $description[SchemaInterface::RELATIONSHIP_LINKS] ?? [];
        \assert(\is_array($schemaLinks));

        // if `self` or `related` link was given as LinkInterface merge it with the other links
        $extraSchemaLinks = null;
        if (\is_bool($addSelfLink) === false) {
            $extraSchemaLinks[LinkInterface::SELF] = $addSelfLink;
            $addSelfLink                           = false;
        }
        if (\is_bool($addRelatedLink) === false) {
            $extraSchemaLinks[LinkInterface::RELATED] = $addRelatedLink;
            $addRelatedLink                           = false;
        }
        if (empty($extraSchemaLinks) === false) {
            // IDE do not understand it's defined without he line below
            \assert(isset($extraSchemaLinks));
            $schemaLinks = \array_merge($extraSchemaLinks, $schemaLinks);
            unset($extraSchemaLinks);
        }
        \assert(\is_bool($addSelfLink) === true && \is_bool($addRelatedLink) === true);

        $hasLinks = $addSelfLink === true || $addRelatedLink === true || empty($schemaLinks) === false;
        $links    = $hasLinks === true ?
            $this->parseLinks($parentSchema, $parentData, $name, $schemaLinks, $addSelfLink, $addRelatedLink) : null;

        return [$hasLinks, $links];
    }
1125781
private function getParentsIdRec($id, $className, $primaryKey, $parentIdField)
    {
        $parentId = (int)$className::find()->select($parentIdField)->where([ $primaryKey => $id ])->scalar();
        if ( $parentId ) {
            return array_merge(self::getParentsIdRec($parentId, $className, $primaryKey, $parentIdField), [$id]);
        } else {
            return [$id];
        }
    }
1083759
private function addChildData(&$parentData, $childAttributes)
    {
        $authorizedChildAttributes = $parentData['children_attributes'];
        $addedChildAttributesData  = array_filter(
            $childAttributes,
            function ($attributeCode) use ($authorizedChildAttributes) {
                return in_array($attributeCode, $authorizedChildAttributes);
            },
            ARRAY_FILTER_USE_KEY
        );

        foreach ($addedChildAttributesData as $attributeCode => $value) {
            if (!isset($parentData[$attributeCode])) {
                $parentData[$attributeCode] = [];
            }

            $parentData[$attributeCode] = array_values(array_unique(array_merge($parentData[$attributeCode], $value)));
        }
    }
1009329
public function execute(Model $currentParent, array $insertedPKs)
    {
        if (!isset($insertedPKs[$this->relatedClass])) {
            return;
        }

        $this->updateParentKey($currentParent);

        $this->relation->attach(
            collect($this->pickRelatedIds($insertedPKs))
                ->mapWithKeys(function ($relatedId) use ($insertedPKs, $currentParent) {
                    return [$relatedId => $this->getExtraAttributes($insertedPKs, $currentParent)];
                })
                ->all()
        );
    }
922256
protected function getSuitableParentTags(array $additionalTags = [])
    {
        return array_merge([
            WsdlDocument::TAG_ELEMENT,
            WsdlDocument::TAG_ATTRIBUTE,
            WsdlDocument::TAG_SIMPLE_TYPE,
            WsdlDocument::TAG_COMPLEX_TYPE,
        ], $additionalTags);
    }
328995
private function getForeignLink($parentLinkName, $parentLinkParams, $currentEntityDefs)
    {
        if (isset($parentLinkParams['foreign']) && isset($currentEntityDefs['links'][$parentLinkParams['foreign']])) {
            return array(
                'name' => $parentLinkParams['foreign'],
                'params' => $currentEntityDefs['links'][$parentLinkParams['foreign']],
            );
        }

        return false;
    }
1173419
public function getAttributes( $includeParents = true )
    {
        if( !$this->columns ) {
            $this->columns = $this->catalog->pgAttributes->findByAttrelid( $this->oid )->sortByAttnum();
        }

        $output = $this->columns->copy();

        // include parents
        if( !$includeParents ) {
            $output->filter(
                function($attribute){
                    return !$attribute->isInherited();
                }
            );
        }

        return $output;
    }
872688
public function getGridParentOptions(): array
    {
        $columns[] = 'tl_form_field.type = ?';
        $columns[] = 'tl_form_field.pid = ?';

        $values[] = 'bs_gridStart';
        $values[] = CURRENT_ID;

        $collection = FormFieldModel::findBy($columns, $values);
        $options    = [];

        if ($collection) {
            foreach ($collection as $model) {
                $options[$model->id] = sprintf(
                    '%s [%s]',
                    $model->bs_grid_name,
                    $model->getRelated('bs_grid')->title
                );
            }
        }

        return $options;
    }
574774
private function getChildren($parentID)
    {
        $tmp = [];
        $count = 0;
        foreach($this->existingMenuLinks as $key => $menuLink){
            if ($menuLink['parent'] == $parentID) {
                $tmp[$count] = $menuLink;
                $count++;
            }
        }
        return $tmp;
    }
556595
protected function evaluateClosureFormatters(array $extra, array $insertedPKs, Model $currentParent)
    {
        return array_map(function ($formatter) use ($insertedPKs, $currentParent) {
            return is_callable($formatter) ? $formatter($currentParent, $insertedPKs) : $formatter;
        }, $extra);
    }
74660
public function addParentRoles($role, array $parents)
    {
        $role = $this->checkRole($role);
        $roleId = $role->getRoleId();
        if ($this->hasRole($roleId)) {
            foreach ($parents as $parent) {
                $parent = $this->checkRole($parent);
                $parentId = $parent->getRoleId();
                if ($this->hasRole($parentId)) {
                    array_push($this->roles[$roleId][self::NODE_PARENTS_ROLE], $parentId);
                } else {
                    throw new RoleNotExistException(
                        sprintf(
                            'Role parent %s not stored',
                            $roleId
                        )
                    );
                }
            }
            return true;
        } else {
            throw new RoleNotExistException(
                sprintf(
                    'Role %s not stored',
                    $roleId
                )
            );
        }
    }
217767
public function getOtherFks()
    {
        $fks = [];
        foreach ($this->parentTable->getForeignKeys() as $fk) {
            if ($fk !== $this) {
                $fks[]= $fk;
            }
        }

        return $fks;
    }
965892
public function getCurrentPageAttributes()
    {
        // Create Attributes Array:
        
        $attributes = [];
        
        // Define Attributes Array:
        
        if ($id = $this->getCurrentPageClassID()) {
            $attributes['id'] = $id;
        }
        
        if ($class = $this->getCurrentPageAncestry()) {
            $attributes['class'] = $class;
        }
        
        // Extend Attributes Array:
        
        $this->extend('updateCurrentPageAttributes', $attributes);
        
        // Answer Attributes Array:
        
        return $attributes;
    }
1170065
public function getRoles($verbose = false) {
        if (Zend_Registry::isRegistered('Zend_Acl')) {
            $acl = Zend_Registry::get('Zend_Acl');
            $roles = $acl->getRoles();

            // collect parents
            if ($verbose) {
                $roles = array_fill_keys($roles, array());
                foreach (array_keys($roles) as $role) {
                    $roles[$role]['parents'] = $this->getRoleParents($role);
                    $roles[$role]['children'] = $this->getRoleChildren($role);
                }
            }
            return $roles;
        }
        return array();
    }
1180371
private function _insert($attrs, $calling, $pk, $pk_value)
    {
        $escape        = Driver::$escape_char;
        $vals          = array();
        $create_column = self::hasColumn("created_at");
        $update_column = self::hasColumn("updated_at");

        $sql = "insert into $escape".$calling::getTableName()."$escape (";

        // remove the current value when need to insert a NULL value to create 
        // the autoincrement value
        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_DELETE && !$pk_value) {
            unset($attrs[$pk]);
        }

        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_SEQUENCE && empty($pk_value)) {
            $seq_name   = self::resolveSequenceName();

            // check if the sequence exists
            self::_checkSequence();
            if (!self::_sequenceExists()) {
                $this->_addError($pk, "Sequence $seq_name could not be created");
                return false;
            }

            // get the sequence next value
            $attrs[$pk] = self::sequenceNextVal($seq_name);
        } 

        // use sequence, but there is already a value on the primary key.
        // remember that it will allow this only if is really a record that
        // wasn't found when checking for the primary key, specifying that its 
        // a new record!
        if (Driver::$primary_key_behaviour == Driver::PRIMARY_KEY_SEQUENCE && !empty($pk_value)) {
            $attrs[$pk] = $pk_value;
        }

        if ($create_column && array_key_exists($create_column, $attrs)) {
            unset($attrs[$create_column]);
        }

        if ($update_column && array_key_exists($update_column, $attrs)) {
            unset($attrs[$update_column]);
        }

        // marks to insert values on prepared statement
        $marks = array();

        foreach ($attrs as $attr => $value) {
            $sql .= "$escape".self::$_mapping[$calling][$attr]."$escape,";
            array_push($marks, "?");
        }

        // if is there a 'created_at' column ...
        if ($create_column) {
            $sql .= "$escape".self::$_mapping[$calling][$create_column]."$escape,";
            array_push($marks, Driver::$current_timestamp);
        }

        // if is there an 'updated_at' column ...
        if ($update_column) {
            $sql .= "$escape".self::$_mapping[$calling][$update_column]."$escape,";
            array_push($marks, Driver::$current_timestamp);
        }

        $marks = join(",", $marks);
        $sql   = substr($sql, 0, strlen($sql)-1);
        $sql  .= ") values ($marks)";

        // now fill the $vals array with all values to be inserted on the 
        // prepared statement
        foreach ($attrs as $attr => $value) {
            array_push($vals, $value);
        }
        $rtn = self::executePrepared($sql, $vals)->rowCount()==1;

        // if inserted
        if ($rtn) {
            // check for last inserted value
            $lid = null;
            if (Driver::$last_id_supported) {
                $lid = self::resolveConnection()->lastInsertId();
                if (empty($this->_data[$pk]) && !empty($lid)) {
                    $this->_data[$pk] = $lid;
                }
            }

            // or, like Oracle, if the database does not support last inserted id
            if (empty($this->_data[$pk]) && empty($lid) && !empty($attrs[$pk])) {
                $this->_data[$pk] = $attrs[$pk];
            }

            // check for database filled columns
            if ($this->_data[$pk]) {
                $found = self::find($this->_data[$pk]);
                if ($found) {
                    if ($create_column) {
                        $this->_data[$create_column] = $found->get($create_column);
                    }
                }
            }

            // push later objects
            foreach ($this->_push_later as $obj) {
                $this->push($obj);
            }
            $this->_push_later = array();
        }
        return $rtn;
    }
1082572
public function getIndexes( $includeParents = true )
    {

        // lazy load indexes
        if( !isset( $this->indexes ) ) {

            $this->indexes = $this->catalog->pgIndexes->findByIndrelid( $this->oid );

            // are we inheriting off another table
            if( $parent = $this->getParent() ) {

                foreach( $parent->getIndexes() as $parentIndex ) {

                    $data = $parentIndex->all();
                    $data['inherited'] = true;
                    $data['columns'] = [];

                    foreach( $parentIndex->indkey as $indkey ) {
                        $columns[] = sprintf( "%s.%s", $this->oid, $indkey );
                    }

                    $this->indexes->add(
                        new PgIndex( $this->catalog, $data )
                    );

                }

            }

        }

        // include parent indexes
        if( $includeParents ) {
            return $this->indexes->copy();
        } else {
            return $this->indexes->copy()->removeByInherited( true );
        }

    }