Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core_badges\output;
18
 
19
use renderable;
20
use renderer_base;
21
use moodle_page;
22
use navigation_node;
23
use templatable;
24
 
25
/**
26
 * Abstract class for the badges tertiary navigation. The class initialises the page and type class variables.
27
 *
28
 * @package   core_badges
29
 * @copyright 2021 Peter Dias
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
abstract class base_action_bar implements renderable, templatable {
33
    /** @var moodle_page $page The context we are operating within. */
34
    protected $page;
35
    /** @var int $type The badge type. */
36
    protected $type;
37
 
38
    /**
39
     * standard_action_bar constructor.
40
     *
41
     * @param moodle_page $page
42
     * @param int $type
43
     */
44
    public function __construct(moodle_page $page, int $type) {
45
        $this->type = $type;
46
        $this->page = $page;
47
    }
48
 
49
    /**
50
     * The template that this tertiary nav should use.
51
     *
52
     * @return string
53
     */
54
    abstract public function get_template(): string;
55
 
56
    /**
57
     * Gets additional third party navigation nodes for display.
58
     *
59
     * @param renderer_base $output  The output
60
     * @return array All that sweet third party navigation action.
61
     */
62
    public function get_third_party_nav_action(renderer_base $output): array {
63
        $badgenode = $this->page->settingsnav->find('coursebadges', navigation_node::TYPE_CONTAINER);
64
        if (!$badgenode) {
65
            return [];
66
        }
67
        $leftovernodes = [];
68
        foreach ($badgenode->children as $key => $value) {
69
            if (array_search($value->key, $this->expected_items()) === false) {
70
                $leftovernodes[] = $value;
71
            }
72
        }
73
        $result = \core\navigation\views\secondary::create_menu_element($leftovernodes);
74
 
75
        if ($result == false) {
76
            return [];
77
        } else {
78
            $data ['thirdpartybutton'] = true;
79
            if (count($result) == 1) {
80
                // Return a button.
81
                $link = key($result);
82
                $text = current($result);
83
                $data['thirdpartynodes'] = ['link' => $link, 'text' => $text];
84
            } else {
85
                // Return a url_select.
86
                $selectobject = new \url_select($result, $this->page->url, get_string('othernavigation', 'badges'));
87
                $data['thirdpartynodes'] = $selectobject->export_for_template($output);
88
                $data['thirdpartybutton'] = false;
89
            }
90
        }
91
 
92
        return $data;
93
    }
94
 
95
    /**
96
     * Expected navigation node keys for badges.
97
     *
98
     * @return array default badge navigation node keys.
99
     */
100
    protected function expected_items(): array {
101
        return ['coursebadges', 'newbadge'];
102
    }
103
}