Generates recursively views depending on the appConfig file

@param string $key Child name view
@param string $fullKey Path in the appConfig file

@return \Zend\View\Model\ViewModel
549271
public function generateRec($key, $fullKey, $recDatas = [])
    {

        $isXmlHttpRequest = false;
        if ($this->getRequest()->isXmlHttpRequest()) {
            $isXmlHttpRequest = true;
        }

        $melisAppConfig = $this->getServiceLocator()->get('MelisCoreConfig');

        /**
         * Get the corresponding appConfig part
         */
        $itemConfig = $melisAppConfig->getItem($fullKey);

        if (!empty($itemConfig['datas'])) {
            $recDatas = array_merge_recursive($recDatas, $itemConfig['datas']);
        }

        /**
         * If we find a conf/type in the app.config, then we'll match it with
         * the correct plugin conf.
         */
        if (!empty($itemConfig['conf']) && !empty($itemConfig['conf']['type'])) {
            $fullKey = $itemConfig['conf']['type'];
            $itemConfigOld = $itemConfig;
            $itemConfig = $melisAppConfig->getItem($itemConfig['conf']['type']);
            if (!empty($itemConfig['datas'])) {
                $recDatas = array_merge_recursive($recDatas, $itemConfig['datas']);
            }

            if ($itemConfig) {
                $itemConfig['conf'] = array_merge($itemConfig['conf'], $itemConfigOld['conf']);
            }

        }


        /**
         * Second check if rendering is allowed for the user
         * according to his rights
         */
        $melisCoreAuth = $this->getServiceLocator()->get('MelisCoreAuth');
        $melisCoreRights = $this->getServiceLocator()->get('MelisCoreRights');
        $xmlRights = $melisCoreAuth->getAuthRights();
        $isAccessible = $melisCoreRights->isAccessible($xmlRights, MelisCoreRightsService::MELISCORE_PREFIX_INTERFACE, $fullKey);
        $isDisabled = $melisAppConfig->isInterfaceDisabled($key);


        if (!$isAccessible || $isDisabled) {
            $view = new ViewModel();
            $view->setTemplate('melis-core/plugin-view/disabled');
            $view->setVariable('norights', true);

            return $view;
        }

        /**
         * Reorder children interface depending on MelisModuleConfig
         * to fit the user's preference
         */
        if (!empty($itemConfig['interface'])) {
            $itemConfig['interface'] = $this->orderInterfaceChildren($key, $itemConfig['interface']);
        }

        /**
         *  Creates the view based on the config
         *  If forward key is found, forward will dispatch to the appropriate module/controller action and view
         *  Datas will also be included in the forward if provided inside appConfig
         *  If forward is not present, the default plugin-view template will be used to echo the key and then will
         *  logicaly continue inside children in the interface section.
         */
        $view = new ViewModel();
        $melisKeyFollow = isset($itemConfig['conf']['follow_regular_rendering']) ? $itemConfig['conf']['follow_regular_rendering'] : true;

        if($melisKeyFollow || $isXmlHttpRequest)
        {
            /**
             * Dashboard plugin interface
             */
            if (!empty($itemConfig['forward']) && !empty($itemConfig['forward']['plugin'])) {
                // Setting the controller calling the dashboard plugins after forward
                $itemConfig['forward']['module'] = 'MelisCore';
                $itemConfig['forward']['controller'] = 'DashboardPlugins';
                $itemConfig['forward']['action'] = 'generateDahsboardPlugin';
                
                // Adding dashboard plugin controller to generate plugin interface
                $recDatas['plugin'] = $itemConfig['forward']['plugin'];
                $recDatas['function'] = $itemConfig['forward']['function'];
            }
            
            if (!empty($itemConfig['forward']) && !empty($itemConfig['forward']['controller'])
                && !empty($itemConfig['forward']['action'])) {
                // Preparing dispatch
                $ctrlPath = $itemConfig['forward']['controller'];
                if (!empty($itemConfig['forward']['module'])) {
                    $ctrlPath = $itemConfig['forward']['module'] . '\\Controller\\' . $ctrlPath;
                }

                // Add the action for dispatch
                $datas = array_merge_recursive($recDatas, ['action' => $itemConfig['forward']['action']]);
                // Add the fullKey for data-id rendering

                if (!empty($itemConfig['conf']) && !empty($itemConfig['conf']['melisKey'])) {
                    $datas['melisKey'] = $itemConfig['conf']['melisKey'];
                } else {
                    $datas['melisKey'] = $fullKey;
                }

                $datas['zoneconfig'] = $itemConfig;

                // Get the view
                try {
                    // maxNestedForwards for generation of interface
                    $config = $this->getServiceLocator()->get('config');
                    $specialConfigZf2 = $config['plugins']['meliscore']['datas']['zf2'];

                    $view = $this->forward()->setMaxNestedForwards($specialConfigZf2['maxNestedForwards'])->dispatch($ctrlPath, $datas);

                    $melisCoreGeneralSrv = $this->getServiceLocator()->get('MelisCoreGeneralService');
                    $eventRes = $melisCoreGeneralSrv->sendEvent('meliscore_generate_interface_'.$datas['melisKey'], array('view' => $view));
                    $view = $eventRes['view'];

                } catch (\Exception $e) {
                    $view = new ViewModel();
                    $view->setTemplate('melis-core/plugin-view/generate');
                    $ctrlPath = $itemConfig['forward']['controller'];
                    if (!empty($itemConfig['forward']['module'])) {
                        $ctrlPath = $itemConfig['forward']['module'] . '/' . $ctrlPath;
                    };
                    $ctrlPath = $ctrlPath . '/' . $itemConfig['forward']['action'];
                    $view->setVariable('meliscore_error_dispatch',
                        'Error: ' . $ctrlPath . '<br />' . $e->getMessage());
                }
            } else {
                // Use the default template because no forward item was found in appConfig
                $view->setTemplate('melis-core/plugin-view/generate');
            }
            // Adds the appConfig section to the view for further disposal in the view
            $view->setVariable('zoneconfig', $itemConfig);
            $view->setVariables($recDatas);

            /**
             * Going recursive in interface section of appConfig to generate any
             * subplugin.
             */
            if (!empty($itemConfig['interface'])) {

                /**
                 * Looping and getting the children in interface section to generate the children views.
                 * Key defined in the appConfig will be used as child view keys
                 */
                foreach ($itemConfig['interface'] as $keyInterface => $valueInterface) {
                    $subKey = $fullKey . '/interface/' . $keyInterface;
                    $subView = $this->generateRec($keyInterface, $subKey, $recDatas);

                    if (!empty($subView)) {
                        $norights = $subView->getVariable('norights');
                        if ($norights) {
                            $zoneconfig = $view->getVariable('zoneconfig');
                            unset($zoneconfig['interface'][$keyInterface]);
                            $view->setVariable('zoneconfig', $zoneconfig);
                        }
                        $view->addChild($subView, $keyInterface);
                        $view->setVariable('keyInterface', $keyInterface);
                    }

                }
            }
            
            if (isset($itemConfig['conf']['dashboard']) && $itemConfig['conf']['dashboard'])
            {
                $melisDashboardSrv = $this->getServiceLocator()->get('MelisCoreDashboardService');
                list($jsCallBacks, $datasCallback) = $melisDashboardSrv->getDashboardPluginsJsCallbackJsDatas($itemConfig['conf']['id']);
                
                $view->setVariable('jsCallBacks', $jsCallBacks);
                $view->setVariable('datasCallback', $datasCallback);


            }

            $view->setVariable('keyInterface', $key);

            return $view;
        } else {
            return null;
        }

	}
138987
public function findOrFail($fullslug)
    {
        if (!$tree = $this->find($fullslug)) {
            throw (new ModelNotFoundException)->setModel(Tree::class);
        }

        return $tree;
    }
403803
public function generateKey($key, $fileName = null)
    {
        if ($key) {
            $key = $this->chiper->encrypt($key);
        }

        return parent::generateKey($key, $fileName);
    }
1332362
protected ConfigProperties getChild(String key, boolean create) {

    if ((key == null) || (key.isEmpty())) {
      return this;
    }
    if (key.indexOf(KEY_SEPARATOR) > 0) {
      String[] segments = key.split("\\.");
      return getChild(create, segments);
    }
    SimpleConfigProperties result = this.childMap.get(key);
    if (result == null) {
      result = createChild(key, create);
      if (result == null) {
        return EMPTY;
      } else {
        this.childMap.put(key, result);
        this.nodeModifications++;
      }
    }
    return result;
  }
841027
protected function findParentBlock($fullBlockName, $viewFileName)
    {
        $parentViewFile = $this->findParentViewFile($viewFileName);
        $viewFilesChain = $this->getViewFilesChain($parentViewFile);
        $savedContent = '';
        foreach ($viewFilesChain as $viewFile) {
            if ($this->viewBlocks($viewFile)->exists($fullBlockName)) {
                $savedContent = $this->viewBlocks($viewFile)->get($fullBlockName);
                break;
            }
        }
        return $savedContent;
    }
794714
public function get($key, $default = false)
    {
        $value = $this->translate($this->fullkey($key), $default);

        if (is_string($value)) {
            $value = $this->resolve($value);
        } elseif (is_array($value)) {
            foreach ($value as &$subValue) {
                $subValue = $this->resolve($subValue);
            }
        }

        return $value;
    }
1188552
public function addSelector(
        $key,
        FullMethodIdentifier $fullMethodId
    ) {
        if ($this->noIdentifierFor($key)) {
            $this->fullMethodIdentifierByKey[$key] = [];
        }
        
        $this->fullMethodIdentifierByKey[$key][] = $fullMethodId;
    }
906137
public function loadFromConfig($key)
    {
        $items = new IlluminateCollection(config()->get($key, []));

        if ($items->isEmpty()) return $this;

        $allHasConfig = $items->every(function ($item) {
            return config()->has($item);
        });

        if ($allHasConfig) {
            $items->each(function ($item) {
                $this->loadFromConfig($item);
            });

            return $this;
        }

        return $this->add($items->toArray());
    }
1336777
public static function getData($key = null) {
        if (!isset($key)) {
            return self::$viewContext->viewData;
        }
        else {
            return isset(self::$viewContext->viewData[$key]) ? self::$viewContext->viewData[$key] : null;
        }
    }
1277330
public function getChildKeyList($key = null)
    {
        $child = $this->get($key);
        $list  = [];
        $n     = 0;
        foreach ($child as $k => $v) {
            $list[$n++] = $k;
        }
        return $list;
    }
897158
public function loadByKey($key)
    {
        $configuration = new Configuration();
        require $key;
        $vars = get_defined_vars();
        unset($vars['configuration']);
        unset($vars['key']);
        foreach ($vars as $name => $value) {
            $configuration->{$name} = $value;
        }

        return $configuration;
    }
734790
public function fullUrlFor($name, $data = [], $queryParams = [], $appName = 'default')
    {
        $path = $this->pathFor($name, $data, $queryParams, $appName);

        /** @var Uri $uri */
        if (is_string($this->uri)) {
            $uri = Uri::createFromString($this->uri);
        } else {
            $uri = $this->uri;
        }

        $scheme = $uri->getScheme();
        $authority = $uri->getAuthority();

        $host = ($scheme ? $scheme . ':' : '')
            . ($authority ? '//' . $authority : '');

        return $host.$path;
    }
1278057
protected function fileUrlAndKey($key)
    {

        if (isset($this->keyUrlCache[$key])) {
            return $this->keyUrlCache[$key];
        }

        $parts = explode('.', $key);
        $url = $this->urlOrFail();
        $partCount = count($parts);

        if ($partCount <= $this->nestingLevel) {
            $minLength = $this->nestingLevel+1;
            $msg = "The key segments has to have a minimum count of $minLength (nesting level: $this->nestingLevel)";
            throw (new KeyLengthException($msg))->setMinSegments($minLength);
        }

        $subKey = [];

        for ($i=0; $i<$partCount; $i++) {


            if ($i < $this->nestingLevel) {
                $url = $url->append($parts[$i]);
                continue;
            }


            if ($i == $this->nestingLevel) {
                $url = $url->append($this->fileName($parts[$i]));
                continue;
            }

            $subKey[] = $parts[$i];
        }

        $this->keyUrlCache[$key] = [$url, implode('.', $subKey)];

        return $this->keyUrlCache[$key];

    }
1213674
public function view($name)
    {
        $fullPath = $name . ".phtml";
        $directory = dirname($fullPath);

        $globalDirPath = $this->appPath . "/Views/" . $directory;
        $fileName = $globalDirPath . "/" . basename($fullPath);

        if (!is_dir($globalDirPath)) {
            // Dir doesn't exist, make it
            mkdir($globalDirPath, 0777, true);
        }

        if (file_put_contents($fileName, "<!-- Created by CLI -->")) {
            echo Utils::colorize('Create ' . $fileName, 'SUCCESS');

            return true;
        } else {
            echo Utils::colorize('Can\'t create ' . $fileName, 'FAILURE');

            return false;
        }
    }
649804
public static function createModel($name, $key = 'default')
    {
        if (!isset(static::$models[$name])) {
            $modelName = 'Model\\'.ucfirst($name).'Model';
            static::$models[$name] = new $modelName(database($key));
        }

        return static::$models[$name];
    }
610308
public static function getFile($fullPath)
    {
        $fileKey = new FileKey($fullPath);

        return new File(
            $fileKey,
            static::getDirectory($fileKey->getDir())
        );
    }
797147
protected function getPageByRequestKey($key)
	{
		$page = $this->searchPageByRequestKey($key);

		if (is_null($page)) {
			$localization = $this->searchLocalizationByRequestKey($key);

			if ( ! is_null($localization)) {
				$page = $localization->getMaster();
			}
		}

		return $page;
	}