@param \NilPortugues\Api\Mapping\Mapping[] $mappings
@param array                               $array
@param array                               $parent

@return array
355871
public static function setResponseDataRelationship(array &$mappings, array &$array, array $parent)
    {
        $data = [JsonApiTransformer::RELATIONSHIPS_KEY => []];

        foreach ($array as $propertyName => $value) {
            if (\is_array($value)) {
                self::addRelationshipData($mappings, $parent, $value, $propertyName, $data);
                if (\array_key_exists(Serializer::MAP_TYPE, $value)) {
                    $newData = [];

                    foreach ($value[Serializer::SCALAR_VALUE] as $d) {
                        self::addRelationshipData($mappings, $parent, $d, $propertyName, $newData);

                        if (!empty($d[Serializer::CLASS_IDENTIFIER_KEY])) {
                            $type = $d[Serializer::CLASS_IDENTIFIER_KEY];

                            if (!in_array($propertyName, RecursiveFormatterHelper::getIdProperties($mappings, $type), true)) {
                                $parentType = $d[Serializer::CLASS_IDENTIFIER_KEY];

                                list($idValues, $idProperties) = RecursiveFormatterHelper::getIdPropertyAndValues(
                                    $mappings,
                                    $d,
                                    $parentType
                                );

                                if (!empty($mappings[$parentType]) && !empty($selfLink = $mappings[$parentType]->getRelationshipSelfUrl($propertyName))) {
                                    $href = \str_replace($idProperties, $idValues, $selfLink);
                                    if ($selfLink != $href) {
                                        $propertyNameKey = DataAttributesHelper::transformToValidMemberName($propertyName);
                                        $propertyNameKey = self::camelCaseToUnderscore($propertyNameKey);

                                        $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyNameKey][JsonApiTransformer::LINKS_KEY][JsonApiTransformer::SELF_LINK][JsonApiTransformer::LINKS_HREF] = $href;
                                    }
                                }
                            }
                        }

                        if (!empty($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName])) {
                            $propertyNameKey = DataAttributesHelper::transformToValidMemberName($propertyName);
                            $propertyNameKey = self::camelCaseToUnderscore($propertyNameKey);

                            if (!empty($d[Serializer::CLASS_IDENTIFIER_KEY])) {
                                $type = $d[Serializer::CLASS_IDENTIFIER_KEY];
                                $parentType = $parent[Serializer::CLASS_IDENTIFIER_KEY];

                                //Removes relationships related to the current resource if filtering include resources has been set.
                                if (!empty($mappings[$parentType]) && !empty($mappings[$parentType]->isFilteringIncludedResources())) {
                                    foreach ($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName] as $position => $includedResource) {
                                        if (count($mappings[$parentType]->getIncludedResources()) > 0 &&
                                            false === in_array($type, $mappings[$parentType]->getIncludedResources(), true)
                                        ) {
                                            unset($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName][$position]);
                                        }
                                    }
                                }

                                $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName] = array_filter($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName]);
                                if (!empty($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName][JsonApiTransformer::DATA_KEY])) {
                                    $data[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyNameKey][JsonApiTransformer::DATA_KEY][] = $newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName][JsonApiTransformer::DATA_KEY];
                                }
                            }
                        }
                    }
                }
            }
        }

        return (array) \array_filter($data);
    }
15943
public static function createFromArray(array $tree, EntityInterface $parent = null)
    {
        $childrenRelationIndex = with(new static)->getChildrenRelationIndex();
        $entities = [];

        foreach ($tree as $item) {
            $children = array_pull($item, $childrenRelationIndex);

            /**
             * @var Entity $entity
             */
            $entity = new static($item);
            $entity->parent_id = $parent ? $parent->getKey() : null;
            $entity->save();

            if (!is_null($children)) {
                $children = static::createFromArray($children, $entity);
                $entity->setRelation($childrenRelationIndex, $children);
                $entity->addChildren($children->all());
            }

            $entities[] = $entity;
        }

        return new Collection($entities);
    }
206308
protected function normalizeScopeArray(array $scopes, $parentKey = 'list.scopes')
    {
        $scopes = $this->normalizeStandardArrayProperty(
            $scopes,
            'strategy',
            ModelScopeData::class,
            $parentKey
        );

        // Make sure that each scope entry has at least a method or a strategy
        foreach ($scopes as $key => &$value) {
            if ( ! $value['method'] && ! $value['strategy']) {
                $value['method'] = $key;
            }
        }

        unset($value);

        return $scopes;
    }
538417
private function _getParentArray($parent, $array)
    {
        foreach ($array as $section => $arraySection) {

            $sectionName = explode(':', $section);

            if (trim($sectionName[0]) == $parent) return $arraySection;
        }

        throw new NoSectionMatchesException('No section matches with ' . $parent);
    }
918991
public function mapAll($elements, $mappingName, $context = [], $disassociate = false)
    {
        if (!is_array($elements)) {
            throw new \RuntimeException('MapAll expected an array');
        }

        if (empty($elements)) {
            return $elements;
        }

        $res = [];
        foreach ($elements as $key => $element) {
            $element = ($disassociate) ? ['key' => $key, 'value' => $element] : $element;
            $res[$key] = $this->map($element, $mappingName, $context);
        }

        return $res;
    }
148589
private static function returnKey($key, $mappingArray)
    {
        if (!is_array($mappingArray)) {
            return $key;
        }

        foreach ($mappingArray as $mappingKey => $mappingData) {
            if (is_array($mappingData)) {
                if (isset($mappingData[$key])) {
                    return $mappingData[$key];
                }
            }
            else {
                if ($mappingKey == $key) {
                    return $mappingData;
                }
            }
        }
        return $key;
    }
62320
protected function copyVatInfoToParent(array $parent, array $children)
    {
        $parent[Meta::VatAmount] = 0;
        // Copy vat rate info from a child when the parent has no vat rate info.
        if (empty($parent[Tag::VatRate]) || Number::isZero($parent[Tag::VatRate])) {
            $parent[Tag::VatRate] = CompletorInvoiceLines::getMaxAppearingVatRate($children, $index);
            $parent[Meta::VatRateSource] = Completor::VatRateSource_Copied_From_Children;
            if (isset($children[$index][Meta::VatRateMin])) {
                $parent[Meta::VatRateMin] = $children[$index][Meta::VatRateMin];
            } else {
                unset($parent[Meta::VatRateMin]);
            }
            if (isset($children[$index][Meta::VatRateMax])) {
                $parent[Meta::VatRateMax] = $children[$index][Meta::VatRateMax];
            } else {
                unset($parent[Meta::VatRateMax]);
            }
        }
        $parent[Meta::LineVatAmount] = 0;
        unset($parent[Meta::LineDiscountVatAmount]);

        return $parent;
    }
891934
public function formatInherited(array $parents)
    {
        $privileges = array_keys($this->getInheritedPrivileges($parents));
        return $this->formatPrivileges($privileges);
    }
172075
public static function map($array, $mapping) {
        $result = array();
        foreach($mapping as $src=>$dest) {
            if(array_key_exists($src, $array)) {
                $result[$dest] = $array[$src];
            }
        }
        return $result;
    }
528103
public static function flatten(array $array, $parent_prefix = '')
    {
        $flattened = [];

        foreach ($array as $key => $value) {
            $key = $parent_prefix . $key;
            if (is_array($value) && self::isAssoc($value)) {
                $flattened = array_merge(self::flatten($value, $key . '.'), $flattened);
            } else {
                $flattened[$key] = $value;
            }
        }

        return $flattened;
    }
1092157
public function toArray($collection = false, $parent = false, $parents = array(), $depth = 0, SerializeHelper $serializeHelper = null, $parentName = false)
    {
        if($serializeHelper===null){
            $serializeHelper = new SerializeHelper();
        }

        $serializeHelper->logClass(get_class($this));

        $queryArray = array();
        if ($parent !== false) {
            $parents['list'][] = get_class($this);


            if (!isset($parents['ids'][get_class($this)][$this->getId()])) {
                $parents['ids'][get_class($this)][$this->getId()] = $this->getId();
            } else {
                $array['id'] = $this->getId();
                return $array;
            }

        } else {
            $parents['list']['Root'] = get_class($this);
            $parents['ids'][get_class($this)][$this->getId()] = $this->getId();
            if($serializeHelper->queryMode()){
                $queryArray[] = $this->getQuery($parent, $parentName);
            }
        }

        $depth++;

        $array = array();
        $i = 0;

        if (strstr(get_class($this), '\\__CG__\\')) {
            $class = strstr(get_class($this), '\\__CG__\\');
            $newClass = str_replace('\\__CG__\\', "", $class);
            $parents['list'][] = $newClass;

            if(!isset($parents['ids'][$newClass][$this->getId()])) {
                $parents['ids'][$newClass][$this->getId()] = $this->getId();
            }else{

                $array['id'] = $this->getId();
                return $array;
            }
        }

        foreach (get_object_vars($this) as $key => $var) {

            if (empty($certainObjects)) {
                $certainObjects[$key] = array();
            }

            $skip = false;
            if (!empty($parents)) {

                foreach ($parents as $key2 => $var2) {

                    if ($this->isParent($var, $var2)) {
                        $array['id'] = $this->getId();
                        if($serializeHelper->queryMode()){
                            //    $array['id']  = $this->getQuery($parent);
                        }
                        return $array;
                    }
                }
            }
            //@todo make this optional according to config for issue-36
            if ($depth > 7) {
                if($serializeHelper->queryMode()){
                    $array['query'] = $this->getQuery($parent, $parentName, true);
                }else{
                    $array['id'] = $this->getId();
                }
                return $array;
                $skip = true;
            }

            if ( isset($many[$key])
                || $this->isParent($parent, $var)
                || $skip === true
                || is_resource($var)
                /*            ||(!empty($certainObjects)&& !isset($certainObjects[$key]))*/
            ) {
                continue;
            }
            if (in_array($key, array("__initializer__", "__isInitialized__", "__cloner__"))) {
                continue;
            }
            $this->$key = $var;

            if (!($var instanceof \Doctrine\ORM\PersistentCollection)) {

                if($serializeHelper->queryMode()){
                    $array["query"] =  $this->getQuery($parent, $parentName);
                }
                if(!$serializeHelper->queryMode()){
                    $array[lcfirst($key)] = $var;
                }
            }

            if (is_array($var)) {
                foreach ($var as $key2 => $var2) {
                    if ($var2 instanceof ArraySerialize && !(in_array(get_class($var2), $parents['list']))) {
                        $return = $var2->toArray(true, $this, $parents, $depth, $serializeHelper, $key);
                        //@todo search mode
                        // break;

                        if($serializeHelper->queryMode()){
                            $array =  $return;
                        }else{
                            $array[lcfirst($key)][$key2] = $return;
                        }
                    }
                }
                //@todo make this optional according to config for issue-36
            } else if ($var instanceof ArraySerialize && !(in_array(get_class($var), $parents['list']))) {

                try {
                    $array[$key] = $var->toArray(false, $this, $parents, $depth, $serializeHelper, $key);
                } catch (EntityNotFoundException $e) {
                    //Many to one on opposite side with stuff missing
                    $yes = strstr(get_class($array[$key]), '\\__CG__\\');
                    $newClass = str_replace('\\__CG__\\', "", $yes);

                    $array[$key] = new $newClass;
                    $array[$key] = $var->toArray(false, $this, $parents, $depth, $serializeHelper, $key);
                }

            } else if ($var instanceof \Doctrine\ORM\PersistentCollection) {

                $iterator = $var->getIterator();

                $i = 0;
                $parents['variableList'][] = lcfirst($key);
                foreach ($iterator as $key3 => $var3) {


                    if ($this->isParent($parent, $var3)) {
                        //        continue;
                    }
                    if (!($var3 instanceof LookUpArray)) {
                        //@todo make this optional according to config for issue-36
                        if (!(in_array(get_class($var3), $parents['list']))) {
                            $return = $var3->toArray(true, $this, $parents, $depth, $serializeHelper, $key);
                            //@todo search mode
                            //break;

                            if($serializeHelper->queryMode()) {
                                $array[lcfirst($key)] = $return;
                                break;
                            }else{
                                $array[lcfirst($key)][$i] = $return;
                            }
                        }
                    } else {
                        $array[lcfirst($key)][$i] = $var3->getLookupId();
                    }
                    $i++;
                }

            } else if ($var instanceof \DateTime) {
                if($serializeHelper->queryMode()){
                    $array[lcfirst($key)] =  $this->getQuery($parent, $parentName);
                }else {
                    $array[lcfirst($key)] = $var->format('Y-m-d H:i:s');
                }
            }
        }

        gc_collect_cycles();

        return $array;

    }
1334303
public function mapTree(array $nodes, array $mappedNodes = []) {
        if (!$mappedNodes) {
            return $nodes;
        }

        $tree = [];
        $pk = $this->getRepository()->getPrimaryKey();

        foreach ($nodes as $node) {
            $id = $node[$pk];

            if (isset($mappedNodes[$id])) {
                $node[$this->getConfig('treeField') ?: 'Nodes'] = $this->mapTree($mappedNodes[$id], $mappedNodes);
            }

            $tree[] = $node;
        }

        return $tree;
    }
149807
public function find($name, $array, $throw = false, $parent = null)
    {
        list($key, $child) = array_pad(explode('.', $name, 2), 2, null);

        if (!isset($array[$key]) && !$throw) {
            return null;
        }

        isset($array[$key]) || $this->throwKeyDoesNotExist($name);

        return $child ? $this->find($child, $array[$key], $name) : $array[$key];
    }
161945
public function findHierarchiesByParents(User $user, array $parents)
    {
        if (count($parents) === 0) {
            throw new \InvalidArgumentException('Array argument cannot be empty');
        }

        $index = 0;
        $eol = PHP_EOL;
        $parentsTest = '(';

        foreach ($parents as $parent) {
            $parentsTest .= $index > 0 ? '    OR ' : '    ';
            $parentsTest .= "p.id = {$parent}{$eol}";
            $index++;
        }
        $parentsTest .= "){$eol}";

        $dql = "
            SELECT h
            FROM Claroline\CoreBundle\Entity\Workspace\WorkspaceTagHierarchy h
            JOIN h.parent p
            WHERE h.user = :user
            AND {$parentsTest}
        ";
        $query = $this->_em->createQuery($dql);
        $query->setParameter('user', $user);

        return $query->getResult();
    }
239635
protected function normalizeMappingSources(array $mappingSources): array
    {
        return \array_map(
            function ($mappingSource): array {
                if (!\is_array($mappingSource)) {
                    $mappingSource = [
                        'type' => DriverFactoryInterface::DRIVER_ANNOTATION,
                        'path' => $mappingSource,
                    ];
                }

                return $mappingSource;
            },
            $mappingSources
        );
    }
1366572
public function parentRelations(array $relations): ModelList
    {
        $this->main['parents'] = [];

        foreach ($relations as $key => $value) {

            if (is_string($key)) {
                $parent = [
                    'relation' => $key,
                    'field'    => $value,
                ];
            } else {
                $parent = [
                    'relation' => $value,
                    'field'    => $value,
                ];
            }

            $this->main['parents'][] = $parent;
        }

        return $this;
    }
903964
public function setPreferredMappings(array $mappings): void
    {
        foreach ($mappings as $language => $map) {
            $this->preferred[$language] = (array) $map;
        }
    }