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 moodle_page;
|
|
|
20 |
use moodle_url;
|
|
|
21 |
use renderer_base;
|
|
|
22 |
use single_button;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Class standard_action_bar - Display the action bar
|
|
|
26 |
*
|
|
|
27 |
* @package core_badges
|
|
|
28 |
* @copyright 2021 Peter Dias
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class standard_action_bar extends base_action_bar {
|
|
|
32 |
/**
|
1441 |
ariadna |
33 |
* The constructor.
|
1 |
efrain |
34 |
*
|
|
|
35 |
*/
|
1441 |
ariadna |
36 |
public function __construct(
|
|
|
37 |
moodle_page $page,
|
|
|
38 |
int $type,
|
|
|
39 |
/** @var null|bool $showmanage This parameter has been deprecated since 4.5 and should not be used anymore. */
|
|
|
40 |
?bool $showmanage = null,
|
|
|
41 |
/** @var bool $showaddbadge Whether or not to show the add badges button. */
|
|
|
42 |
protected bool $showaddbadge = true,
|
|
|
43 |
/** @var moodle_url $backurl BackURL to be used when the back button is required. */
|
|
|
44 |
protected ?moodle_url $backurl = null,
|
|
|
45 |
) {
|
1 |
efrain |
46 |
parent::__construct($page, $type);
|
|
|
47 |
|
1441 |
ariadna |
48 |
if ($showmanage !== null) {
|
|
|
49 |
debugging(
|
|
|
50 |
'The showmanage argument has been deprecated. Please remove it from your method calls.',
|
|
|
51 |
DEBUG_DEVELOPER,
|
|
|
52 |
);
|
|
|
53 |
}
|
|
|
54 |
|
1 |
efrain |
55 |
$this->showaddbadge = $showaddbadge;
|
|
|
56 |
$this->backurl = $backurl;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* The template that this tertiary nav should use.
|
|
|
61 |
*
|
|
|
62 |
* @return string
|
|
|
63 |
*/
|
|
|
64 |
public function get_template(): string {
|
|
|
65 |
return 'core_badges/manage_badges';
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Export the action bar
|
|
|
70 |
*
|
|
|
71 |
* @param renderer_base $output
|
|
|
72 |
* @return array The buttons to be rendered
|
|
|
73 |
*/
|
|
|
74 |
public function export_for_template(renderer_base $output): array {
|
|
|
75 |
$buttons = [];
|
|
|
76 |
if ($this->backurl) {
|
|
|
77 |
$buttons[] = new single_button($this->backurl, get_string('back'), 'get');
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
$params = ['type' => $this->type];
|
|
|
81 |
if ($this->page->context->contextlevel == CONTEXT_COURSE) {
|
|
|
82 |
$params['id'] = $this->page->context->instanceid;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
if ($this->showaddbadge && has_capability('moodle/badges:createbadge', $this->page->context)) {
|
1441 |
ariadna |
86 |
$editparams = ['action' => 'new'];
|
|
|
87 |
if (array_key_exists('id', $params)) {
|
|
|
88 |
$editparams['courseid'] = $params['id'];
|
|
|
89 |
}
|
|
|
90 |
$buttons[] = new single_button(
|
|
|
91 |
new moodle_url(
|
|
|
92 |
'/badges/edit.php',
|
|
|
93 |
$editparams,
|
|
|
94 |
),
|
|
|
95 |
get_string('newbadge', 'core_badges'),
|
|
|
96 |
'post',
|
|
|
97 |
single_button::BUTTON_PRIMARY,
|
|
|
98 |
);
|
1 |
efrain |
99 |
}
|
|
|
100 |
|
|
|
101 |
foreach ($buttons as $key => $button) {
|
|
|
102 |
$buttons[$key] = $button->export_for_template($output);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
$data = ['buttons' => $buttons];
|
|
|
106 |
$additional = $this->get_third_party_nav_action($output);
|
|
|
107 |
$data += $additional ?: [];
|
|
|
108 |
|
|
|
109 |
return $data;
|
|
|
110 |
}
|
|
|
111 |
}
|