<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <https://www.gnu.org/licenses/>.

/**
 * Plugin administration pages are defined here.
 *
 * @package     local_hshexport
 * @copyright   2024 Elke Kreim elke.kreim@hs-hannover.de
 * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

define('LOCALHSHEXPORT_NAV_COURSE', 'navcourse');
define('LOCALHSHEXPORT_NAV_PARTICIPANTS', 'navpart');


function local_hshexport_extend_navigation_course($navigation, $course, $context) {
    if (has_capability('local/hshexport:canexport', $context)) {
        // Create the navigation node.
        $url = new moodle_url('/local/hshexport/export.php', ['id' => $course->id]);
        $hshexportnode = navigation_node::create(get_string('pluginname', 'local_hshexport'), $url,
            navigation_node::TYPE_SETTING, null, 'local_hshexport', new pix_icon('i/users', ''));

        // Get the navigation node placement setting.
        $navigationplacement = get_config('local_hshexport', 'navigation');

        // If the admin wanted to add the navigation node to the participants page jump menu.
        if ($navigationplacement == LOCALBULKENROL_NAV_PARTICIPANTS) {
            $usersnode = $navigation->get('users');
            if (isset($hshexportnode) && !empty($usersnode)) {
                $usersnode->add_node($hshexportnode);
            }
        }

        // If the admin wanted to add the navigation node to the course navigation.
        if ($navigationplacement == LOCALBULKENROL_NAV_COURSE) {
            if (isset($hshexportnode)) {
                $navigation->add_node($hshexportnode);
            }
        }
    }
}