FOF30\Toolbar\Toolbar::getMyViews PHP Méthode

getMyViews() protected méthode

Automatically detects all views of the component
protected getMyViews ( ) : array
Résultat array A list of all views, in the order to be displayed in the toolbar submenu
    protected function getMyViews()
    {
        $t_views = array();
        $using_meta = false;
        $componentPaths = $this->container->platform->getComponentBaseDirs($this->container->componentName);
        $searchPath = $componentPaths['main'] . '/View';
        $filesystem = $this->container->filesystem;
        $allFolders = $filesystem->folderFolders($searchPath);
        if (!empty($allFolders)) {
            foreach ($allFolders as $folder) {
                $view = $folder;
                // View already added
                if (in_array($this->container->inflector->pluralize($view), $t_views)) {
                    continue;
                }
                // Do we have a 'skip.xml' file in there?
                $files = $filesystem->folderFiles($searchPath . '/' . $view, '^skip\\.xml$');
                if (!empty($files)) {
                    continue;
                }
                // Do we have extra information about this view? (ie. ordering)
                $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\\.xml$');
                // Not found, do we have it inside the plural one?
                if (!$meta) {
                    $plural = $this->container->inflector->pluralize($view);
                    if (in_array($plural, $allFolders)) {
                        $view = $plural;
                        $meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\\.xml$');
                    }
                }
                if (!empty($meta)) {
                    $using_meta = true;
                    $xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]);
                    $order = (int) $xml->foflib->ordering;
                } else {
                    // Next place. It's ok since the index are 0-based and count is 1-based
                    if (!isset($to_order)) {
                        $to_order = array();
                    }
                    $order = count($to_order);
                }
                $view = $this->container->inflector->pluralize($view);
                $t_view = new \stdClass();
                $t_view->ordering = $order;
                $t_view->view = $view;
                $to_order[] = $t_view;
                $t_views[] = $view;
            }
        }
        $views = array();
        if (!empty($to_order)) {
            \JArrayHelper::sortObjects($to_order, 'ordering');
            $views = \JArrayHelper::getColumn($to_order, 'view');
        }
        // If not using the metadata file, let's put the cpanel view on top
        if (!$using_meta) {
            $cpanel = array_search('cpanels', $views);
            if ($cpanel !== false) {
                unset($views[$cpanel]);
                array_unshift($views, 'cpanels');
            }
        }
        return $views;
    }