Create relation index between modules.

@param mixed[] $modules modules.
@return mixed[]
492835
protected function createRelationIndex(array $modules) : array
    {
        $index = [];

        foreach ($modules as $moduleName => $module) {
            if (! isset($module['relations'])) {
                $index[$moduleName] = [];
                continue;
            }

            if (! is_array($module['relations'])) {
                $index[$moduleName] = [];
                continue;
            }

            foreach ($module['relations'] as $relatedModule) {
                if (!empty($index[$relatedModule][$moduleName])) {
                    continue;
                }
                $index[$relatedModule][] = $moduleName;
            }
        }

        return $index;
    }
615615
public function parseModuleChains($modules)
    {
        $moduleArray = [];

        if (is_array($modules)) {
            foreach ($modules as $class => $moduleChain) {
                if (strstr($moduleChain, '&')) {
                    $moduleChain = explode('&', $moduleChain);
                } else {
                    $moduleChain = [$moduleChain];
                }
                $moduleArray[$class] = $moduleChain;
            }
        }

        return $moduleArray;
    }
428363
public static function forModules(ModuleList $modules)
    {
        $graph = new static($modules->getModuleNames());

        foreach ($modules as $module) {
            if (null === $module->getModuleFile()) {
                continue;
            }

            foreach ($module->getModuleFile()->getDependencies() as $dependency) {
                if ($graph->hasModuleName($dependency)) {
                    $graph->addDependency($module->getName(), $dependency);
                }
            }
        }

        // Do we have a root module?
        if (null === $modules->getRootModule()) {
            return $graph;
        }

        // Make sure we have numeric, ascending keys here
        $moduleOrder = array_values($modules->getRootModule()->getModuleFile()->getModuleOrder());

        // Each module overrides the previous one in the list
        for ($i = 1, $l = count($moduleOrder); $i < $l; ++$i) {
            $dependency = $moduleOrder[$i - 1];
            $moduleName = $moduleOrder[$i];

            if ($graph->hasModuleName($dependency)) {
                $graph->addDependency($moduleName, $dependency);
            }
        }

        return $graph;
    }
1055882
function loadModules(array $modules)
    {
        $modules = array_diff($modules, array_keys($this->_c__loadedModules));
        if ( empty($modules) )
            // Modules are loaded
            return $this;


        // Load Enabled Modules:
        foreach($modules as $im => $vm) {
            /* @see loadModule */
            if (is_string($im) && $vm)
                # ['moduleName' => 'ModuleManager_Options_In_Any_Value_Form']
                $module = array($im => $vm);
            else
                # ['module', ..]
                $module = $vm;

            $this->loadModule($module);
        }


        ## Trigger Post Load Modules Event
        #
        $collectorPass = new DataCollectorModuleManager;
        $collectorPass->setModuleManager($this);
        $this->event()->trigger(EventHeapOfModuleManager::EVENT_MODULES_POSTLOAD, $collectorPass);

        return $this;
    }
45314
protected function sortModules()
    {
        $this->modules = $this->modules->sortBy(function (ModuleInterface $module) {
            return $module->getName();
        });

        return $this;
    }
1129766
function setModules($modules)
    {
        if (! is_array($modules) )
            throw new \InvalidArgumentException(sprintf(
                'Modules Must be Array list of module names; given (%s).'
                , $modules
            ));
        
        $this->modules = $modules;
    }
1184551
public function getModulesIndex()
    {
        if ($this->modulesIndex) {
            return $this->modulesIndex;
        }

        $modules = $this->getModuleManager()->getModules();

        $modulesIndex = [];

        foreach ($modules as $moduleName) {
            $prepareModuleName = rtrim($moduleName, '\\') . '\\';
            $modulesIndex[$prepareModuleName] = strlen($prepareModuleName);
        }

        arsort($modulesIndex, SORT_NUMERIC);
        $this->modulesIndex = $modulesIndex;

        return $this->modulesIndex;
    }
1216929
public function relations($embedded = false)
    {
        $result = [];
        foreach ($this->_relations as $field => $config) {
            if (!$config['embedded'] || $embedded) {
                $result[] = $field;
            }
        }
        return $result;
    }
1226590
protected function getModuleCsvData(array $modules) : array
    {
        $csvFiles = [];

        foreach ($modules as $module) {
            $mc = new ModuleConfig(ConfigType::MIGRATION(), $module);

            $config = json_encode($mc->parse());
            if (false === $config) {
                continue;
            }

            $config = json_decode($config, true);
            if (empty($config)) {
                continue;
            }

            if (! isset($csvFiles[$module])) {
                $csvFiles[$module] = [];
            }

            $csvFiles[$module] = $config;
        }

        return $csvFiles;
    }
126953
public function addRelations($relations)
	{
		if(is_numeric($relations))
		{
			
			$relations = intval($relations);
			$this->relations = $relations;
		}
		else
		{
			$relations = ( is_array($relations) ) ? $relations : explode(',', strval($relations));
			foreach ($relations as $prop)
			{
				if( ! in_array($prop, $this->relations) )
				{
					$this->relations[] = trim($prop);
				}
			}
		}

		if($this instanceof Collection)
		{
			foreach ($this->data as $model)
			{
				$model->addRelations($this->relations);
			}
		}
	}
268419
protected function createTableRelations(array $tables)
    {
        /** @var TableMigration $tableObject */
        foreach ($tables as $tableObject) {
            $tableObject->relateToOtherTables($tables);
        } // foreach

        return $this->sortTablesWithFKsToEnd($tables);
    }
1236048
private function getModuleDependencies(DependsOnModule $module)
    {
        $depends = $module->_depends();

        if (!$depends) {
            return [];
        }

        if (!is_array($depends)) {
            $message = sprintf("Method _depends of module '%s' must return an array", get_class($module));
            throw new ModuleException($module, $message);
        }

        return $depends;
    }
1270875
protected function sortModules(Collection $modules)
    {
        $index = 0;

        // Make a mapping to easily look up configured order with
        // Account for possibility of either 'module key' => [] or 'module key' format in config
        $orderMap = array_map(
            function ($key) {

                if (is_string($key)) return $key;

                if ( ! is_string($this->configModules[$key])) {
                    throw new UnexpectedValueException(
                        "cms-modules.menu.modules entry '{$key}' must be string or have a non-numeric key"
                    );
                }

                return $this->configModules[$key];
            },
            array_keys($this->configModules)
        );
        $orderMap = array_flip($orderMap);


        return $modules->sortBy(function (ModuleInterface $module) use (&$index, $orderMap) {

            // Order by configured order first, natural modules order second.
            if (count($orderMap)) {
                $primaryOrder = (int) array_get($orderMap, $module->getKey(), -2) + 1;
            } else {
                $primaryOrder = -1;
            }

            return $primaryOrder < 0 ? ++$index : (1 - 1 / $primaryOrder);
        });
    }
946957
public function getList(array $module)
    {
        $list = array();

        foreach ($this->getScanFolders() as $folder) {
            $files = gplcart_file_scan_recursive("{$module['directory']}/$folder");
            sort($files);
            $list[$folder] = $files;
        }

        $this->hook->attach('module.editor.list', $list);
        return $list;
    }
160978
public function relations(array $relations)
    {
        foreach ($relations as $column1 => $column2) {
            $this->relation($column1, $column2);
        }

        return $this;
    }
804679
private function getParentJoins(): array
    {
        if (empty($this->getParentModules())) {
            return [];
        }

        $result = [];
        foreach ($this->table->associations() as $association) {
            if (! $this->isSupportedJoinAssociation($association)) {
                continue;
            }

            if (! $this->isParentModuleAssociation($association)) {
                continue;
            }

            $conditions = $this->getParentJoin($association);
            if (empty($conditions)) {
                continue;
            }

            $result[$association->getName()] = $conditions;
        }

        return $result;
    }
1070173
private function getIndexesByModule($module)
    {
        // Indexes to be removed
        $indexes = array();

        foreach ($this->data as $index => $row) {
            if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
                array_push($indexes, $index);
            }
        }

        return $indexes;
    }