Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 17... Línea 17...
17
namespace mod_feedback\output;
17
namespace mod_feedback\output;
Línea 18... Línea 18...
18
 
18
 
19
use confirm_action;
19
use confirm_action;
20
use context_system;
20
use context_system;
-
 
21
use moodle_url;
-
 
22
use pix_icon;
21
use moodle_url;
23
use core\output\action_menu;
-
 
24
use core\output\action_link;
-
 
25
use core\output\action_menu\link as action_menu_link;
Línea 22... Línea 26...
22
use action_link;
26
use mod_feedback\manager;
23
 
27
 
24
/**
28
/**
25
 * Class actionbar - Display the action bar
29
 * Class actionbar - Display the action bar
Línea 29... Línea 33...
29
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
34
 */
31
class edit_template_action_bar extends base_action_bar {
35
class edit_template_action_bar extends base_action_bar {
32
    /** @var int $templateid The template that is being edited/used */
36
    /** @var int $templateid The template that is being edited/used */
33
    private $templateid;
37
    private $templateid;
34
    /** @var string $mode The type of view we are dealing with  */
-
 
35
    private $mode;
-
 
Línea 36... Línea 38...
36
 
38
 
37
    /**
39
    /**
38
     * edit_template_action_bar constructor.
40
     * edit_template_action_bar constructor.
39
     * @param int $cmid
41
     * @param int $cmid
40
     * @param int $templateid
42
     * @param int $templateid
41
     * @param string $mode
43
     * @param string|null $mode This parameter has been deprecated since 4.5 and should not be used anymore.
42
     */
44
     */
-
 
45
    public function __construct(int $cmid, int $templateid, ?string $mode = null) {
-
 
46
        if ($mode !== null) {
-
 
47
            debugging(
-
 
48
                'The age argument has been deprecated. Please remove it from your method calls.',
-
 
49
                DEBUG_DEVELOPER,
-
 
50
            );
43
    public function __construct(int $cmid, int $templateid, string $mode) {
51
        }
44
        parent::__construct($cmid);
52
        parent::__construct($cmid);
45
        $this->templateid = $templateid;
-
 
46
        $this->mode = $mode;
53
        $this->templateid = $templateid;
Línea 47... Línea 54...
47
    }
54
    }
48
 
55
 
49
    /**
56
    /**
50
     * Return the items to be used in the tertiary nav
57
     * Return the items to be used in the tertiary nav
51
     *
58
     *
52
     * @return array
59
     * @return array
53
     */
60
     */
-
 
61
    public function get_items(): array {
54
    public function get_items(): array {
62
        global $PAGE;
55
        global $DB;
63
 
-
 
64
        $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
-
 
65
        $template = manager::get_template_record($this->templateid);
56
        $additionalparams = ($this->mode ? ['mode' => $this->mode] : []);
66
 
Línea -... Línea 67...
-
 
67
        // Back button.
57
        $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams + $additionalparams);
68
        $items['left'][]['actionlink'] = new action_link($templateurl, get_string('back'), null, ['class' => 'btn btn-secondary']);
-
 
69
 
-
 
70
        // Actions.
-
 
71
        if (has_capability('mod/feedback:edititems', $this->context)) {
-
 
72
            $actionsselect = new action_menu();
-
 
73
            $actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-outline-primary');
58
        $items['left'][]['actionlink'] = new action_link($templateurl, get_string('back'), null, ['class' => 'btn btn-secondary']);
74
            $PAGE->requires->js_call_amd('mod_feedback/usetemplate', 'init');
-
 
75
 
-
 
76
            // Use template.
59
 
77
            $actionsselect->add(new action_menu_link(
-
 
78
                new moodle_url('#'),
-
 
79
                new pix_icon('i/files', get_string('preview')),
60
        if (has_capability('mod/feedback:edititems', $this->context)) {
80
                get_string('use_this_template', 'mod_feedback'),
61
            $items['usetemplate'] = $this->urlparams + [
81
                false,
Línea 62... Línea -...
62
                'templateid' => $this->templateid
-
 
63
            ];
82
                ['data-action' => 'usetemplate', 'data-dataid' => $this->cmid, 'data-templateid' => $this->templateid],
64
        }
83
            ));
65
 
84
        }
66
        $template = $DB->get_record('feedback_template', array('id' => $this->templateid), '*', MUST_EXIST);
85
 
67
        $systemcontext = context_system::instance();
86
        // Delete.
-
 
87
        $showdelete = has_capability('mod/feedback:deletetemplate', $this->context);
-
 
88
        if ($template->ispublic) {
68
        $showdelete = has_capability('mod/feedback:deletetemplate', $this->context);
89
            $showdelete = has_all_capabilities(
69
        if ($template->ispublic) {
-
 
70
            $showdelete = has_capability('mod/feedback:createpublictemplate', $systemcontext) &&
90
                ['mod/feedback:createpublictemplate', 'mod/feedback:deletetemplate'],
71
                has_capability('mod/feedback:deletetemplate', $systemcontext);
91
                context_system::instance()
72
        }
92
            );
73
 
93
        }
74
        if ($showdelete) {
94
        if ($showdelete) {
75
            $params = $this->urlparams + $additionalparams + [
95
            $params = $this->urlparams + [
-
 
96
                'deletetemplate' => $this->templateid,
-
 
97
                'sesskey' => sesskey()
-
 
98
            ];
76
                'deletetemplate' => $this->templateid,
99
            $deleteurl = new moodle_url('/mod/feedback/manage_templates.php', $params);
-
 
100
            $deleteaction = new action_link(
77
                'sesskey' => sesskey()
101
                $deleteurl,
-
 
102
                get_string('delete'),
-
 
103
                new confirm_action(get_string('confirmdeletetemplate', 'feedback')),
78
            ];
104
                ['class' => 'text-danger'],
Línea -... Línea 105...
-
 
105
                new pix_icon('t/delete', get_string('delete_template', 'feedback')),
-
 
106
            );
79
            $deleteurl = new moodle_url('/mod/feedback/manage_templates.php', $params);
107
            $actionsselect->add_secondary_action($deleteaction);
80
            $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback'));
108
        }
81
            $items['export'] = new action_link($deleteurl, get_string('delete'), $deleteaction, ['class' => 'btn btn-secondary']);
109