Skip to content
Snippets Groups Projects
Select Git revision
  • 86041ef424bc00ef6f83b85936e3c4b66cf8e88d
  • master default protected
  • v1.5
  • v1.4.7
  • v1.4.6
  • v1.4.5
  • v1.4.4
  • v1.4.3
  • v1.4.2
  • v1.4.1
  • v1.4
  • v1.3
  • v1.2.1
  • v1.2
  • v1.1.2
  • v1.1.1
  • v1.0
17 results

MatrixPlugin.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    CourseNavigation.php 3.45 KiB
    <?php
    # Lifter010: TODO
    /*
     * CourseNavigation.php - navigation for course / institute area
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License as
     * published by the Free Software Foundation; either version 2 of
     * the License, or (at your option) any later version.
     *
     * @author      Elmar Ludwig
     * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
     * @category    Stud.IP
     */
    
    class CourseNavigation extends Navigation
    {
        private $range;
    
        /**
         * Initialize a new Navigation instance.
         */
        public function __construct(Range $range)
        {
            if (!($range instanceof Course) && !($range instanceof Institute)) {
                throw new InvalidArgumentException('Invalid range type "' . get_class($range) . '" for course navigation');
            }
    
            $this->range = $range;
    
            // check if logged in
            if (User::findCurrent()) {
                $coursetext = _('Veranstaltungen');
                $courseinfo = _('Meine Veranstaltungen & Einrichtungen');
                $courselink = 'dispatch.php/my_courses';
            } else {
                $coursetext = _('Freie Veranstaltungen');
                $courseinfo = _('Freie Veranstaltungen');
                $courselink = 'dispatch.php/public_courses';
            }
    
            parent::__construct($coursetext, $courselink);
    
            if (User::findCurrent()) {
                $this->setImage(Icon::create('seminar', Icon::ROLE_NAVIGATION, ['title' => $courseinfo]));
            }
        }
    
        /**
         * Initialize the subnavigation of this item. This method
         * is called once before the first item is added or removed.
         */
        public function initSubNavigation()
        {
            parent::initSubNavigation();
    
            $admin_plugin_ids = [];
    
            $core_admin = PluginManager::getInstance()->getPlugin(CoreAdmin::class);
            if ($core_admin) {
                $admin_plugin_ids[] = $core_admin->getPluginId();
            }
    
            $core_studygroup_admin = PluginManager::getInstance()->getPlugin(CoreStudygroupAdmin::class);
            if ($core_studygroup_admin) {
                $admin_plugin_ids[] = $core_studygroup_admin->getPluginId();
            }
    
            $tools = $this->range->tools->getArrayCopy();
            usort($tools, function ($a, $b) use ($admin_plugin_ids) {
                if (in_array($a['plugin_id'], $admin_plugin_ids)) {
                    return -1;
                }
                if (in_array($b['plugin_id'], $admin_plugin_ids)) {
                    return 1;
                }
                return $a['position'] - $b['position'];
            });
    
            foreach ($tools as $tool) {
                if (
                    !($this->range instanceof Institute)
                    && !Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $this->range->id)
                ) {
                    continue;
                }
    
                $studip_module = $tool->getStudipModule();
                if (!($studip_module instanceof StudipModule)) {
                    continue;
                }
    
                $tool_nav = $studip_module->getTabNavigation($this->range->id) ?: [];
    
                foreach ($tool_nav as $nav_name => $navigation) {
                    if (!$nav_name || !$navigation instanceof Navigation) {
                        continue;
                    }
    
                    if ($tool->metadata['displayname']) {
                        $navigation->setTitle($tool->getDisplayname());
                    }
                    $this->addSubNavigation($nav_name, $navigation);
                }
            }
        }
    }