Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 22... Línea 22...
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
Línea -... Línea 25...
-
 
25
defined('MOODLE_INTERNAL') || die();
-
 
26
 
-
 
27
use core\output\notification;
-
 
28
use core\output\action_menu;
-
 
29
use core\output\action_link;
-
 
30
use core\output\action_menu\link_secondary;
25
defined('MOODLE_INTERNAL') || die();
31
use core\output\actions\confirm_action;
26
 
32
 
Línea 27... Línea 33...
27
global $CFG;
33
global $CFG;
28
require_once($CFG->libdir . '/tablelib.php');
34
require_once($CFG->libdir . '/tablelib.php');
29
 
35
 
30
/**
36
/**
31
 * Class mod_feedback_templates_table
37
 * Class mod_feedback_templates_table
32
 *
38
 *
33
 * @package   mod_feedback
39
 * @package   mod_feedback
34
 * @copyright 2016 Marina Glancy
40
 * @copyright 2016 Marina Glancy
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
42
 */
Línea 37... Línea 43...
37
class mod_feedback_templates_table extends flexible_table {
43
class mod_feedback_templates_table extends core_table\flexible_table {
38
    /** @var string|null Indicate whether we are managing template or not. */
44
    /** @var int|null The module id. */
39
    private $mode;
45
    private $cmid;
40
 
46
 
41
    /**
47
    /**
42
     * Constructor
48
     * Constructor
43
     * @param int $uniqueid all tables have to have a unique id, this is used
49
     * @param int $uniqueid all tables have to have a unique id, this is used
44
     *      as a key when storing table properties like sort order in the session.
50
     *      as a key when storing table properties like sort order in the session.
45
     * @param moodle_url $baseurl
51
     * @param moodle_url $baseurl
46
     * @param string $mode Indicate whether we are managing templates
52
     * @param string|null $mode This parameter has been deprecated since 4.5 and should not be used anymore.
47
     */
53
     */
48
    public function __construct($uniqueid, $baseurl, ?string $mode = null) {
54
    public function __construct($uniqueid, $baseurl, ?string $mode = null) {
49
        parent::__construct($uniqueid);
55
        if ($mode !== null) {
50
        $this->mode = $mode;
56
            debugging(
51
        $tablecolumns = array('template');
-
 
-
 
57
                'The age argument has been deprecated. Please remove it from your method calls.',
-
 
58
                DEBUG_DEVELOPER,
-
 
59
            );
52
        if ($this->mode) {
60
        }
-
 
61
        parent::__construct($uniqueid);
-
 
62
        $this->cmid = $baseurl->param('id');
Línea 53... Línea 63...
53
            $tablecolumns[] = 'actions';
63
        $tablecolumns = [
Línea 54... Línea 64...
54
        }
64
            'template' => get_string('template', 'feedback'),
55
 
65
            'actions' => html_writer::span(get_string('actions'), 'visually-hidden'),
56
        $tableheaders = array(get_string('template', 'feedback'), '');
66
        ];
57
 
67
 
58
        $this->set_attribute('class', 'templateslist');
-
 
59
 
68
        $this->set_attribute('class', 'templateslist');
60
        $this->define_columns($tablecolumns);
69
 
Línea 61... Línea 70...
61
        $this->define_headers($tableheaders);
70
        $this->define_columns(array_keys($tablecolumns));
62
        $this->define_baseurl($baseurl);
71
        $this->define_headers(array_values($tablecolumns));
63
        $this->column_class('template', 'template');
72
        $this->define_baseurl($baseurl);
64
        $this->column_class('actions', 'text-right');
73
        $this->column_class('template', 'template');
65
        $this->sortable(false);
74
        $this->sortable(false);
66
    }
75
    }
67
 
76
 
-
 
77
    /**
68
    /**
78
     * Displays the table with the given set of templates
69
     * Displays the table with the given set of templates
79
     * @param array $templates
-
 
80
     */
-
 
81
    public function display($templates) {
70
     * @param array $templates
82
        global $OUTPUT;
71
     */
83
        if (empty($templates)) {
Línea 72... Línea 84...
72
    public function display($templates) {
84
            echo $OUTPUT->notification(
73
        global $OUTPUT;
-
 
Línea 74... Línea 85...
74
        if (empty($templates)) {
85
                get_string('no_templates_available_yet', 'feedback'),
75
            echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
-
 
76
                             'generalbox boxaligncenter');
-
 
77
            return;
-
 
78
        }
-
 
79
 
86
                notification::NOTIFY_INFO,
80
        $this->setup();
-
 
81
        $strdeletefeedback = get_string('delete_template', 'feedback');
87
                false,
82
 
-
 
83
        foreach ($templates as $template) {
-
 
84
            $data = [];
-
 
85
            $url = new moodle_url($this->baseurl, array('templateid' => $template->id, 'sesskey' => sesskey()));
88
            );
86
            $data[] = $OUTPUT->action_link($url, format_string($template->name));
-
 
87
 
-
 
88
            // Only show the actions if we are managing templates.
-
 
89
            if ($this->mode && has_capability('mod/feedback:deletetemplate', $this->get_context())) {
-
 
90
                $deleteurl = new moodle_url('/mod/feedback/manage_templates.php',
89
            return;
91
                    $url->params() + ['deletetemplate' => $template->id]);
90
        }
92
                $deleteaction = new confirm_action(get_string('confirmdeletetemplate', 'feedback'));
91
 
-
 
92
        $this->setup();
93
                $deleteicon = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', $strdeletefeedback), $deleteaction);
93
 
Línea 94... Línea 94...
94
                if ($template->ispublic) {
94
        foreach ($templates as $template) {
95
                    $systemcontext = context_system::instance();
95
            $showactions = has_any_capability(
96
                    if (!(has_capability('mod/feedback:createpublictemplate', $systemcontext) &&
96
                ['mod/feedback:deletetemplate', 'mod/feedback:edititems', 'mod/feedback:createpublictemplate'],
97
                        has_capability('mod/feedback:deletetemplate', $systemcontext))) {
97
                $this->get_context()
-
 
98
            );
-
 
99
            $data = [
-
 
100
                format_string($template->name),
-
 
101
                $showactions ? $OUTPUT->render($this->get_row_actions($template)) : '',
-
 
102
            ];
-
 
103
 
-
 
104
            $this->add_data($data);
-
 
105
        }
-
 
106
        $this->finish_output();
-
 
107
    }
-
 
108
 
-
 
109
    /**
-
 
110
     * Get the row actions for the given template
-
 
111
     *
-
 
112
     * @param stdClass $template
-
 
113
     * @return action_menu
-
 
114
     */
-
 
115
    private function get_row_actions(stdClass $template): action_menu {
-
 
116
        global $PAGE, $OUTPUT;
-
 
117
 
-
 
118
        $url = new moodle_url($this->baseurl, ['templateid' => $template->id, 'sesskey' => sesskey()]);
-
 
119
        $strdeletefeedback = get_string('delete_template', 'feedback');
-
 
120
        $actions = new action_menu();
-
 
121
        $actions->set_menu_trigger($OUTPUT->pix_icon('a/setting', get_string('actions')));
-
 
122
 
-
 
123
        // Preview.
-
 
124
        $actions->add(new link_secondary(
-
 
125
            new moodle_url($this->baseurl, ['templateid' => $template->id, 'sesskey' => sesskey()]),
-
 
126
            new pix_icon('t/preview', get_string('preview')),
-
 
127
            get_string('preview'),
-
 
128
        ));
-
 
129
 
-
 
130
        // Use template.
-
 
131
        if (has_capability('mod/feedback:edititems', context_module::instance($this->cmid))) {
-
 
132
            $PAGE->requires->js_call_amd('mod_feedback/usetemplate', 'init');
-
 
133
            $actions->add(new link_secondary(
-
 
134
                new moodle_url('#'),
-
 
135
                new pix_icon('i/files', get_string('preview')),
-
 
136
                get_string('use_this_template', 'mod_feedback'),
-
 
137
                ['data-action' => 'usetemplate', 'data-dataid' => $this->cmid, 'data-templateid' => $template->id],
-
 
138
            ));
-
 
139
        }
-
 
140
 
-
 
141
        // Delete.
-
 
142
        $showdelete = has_capability('mod/feedback:deletetemplate', context_module::instance($this->cmid));
-
 
143
        if ($template->ispublic) {
-
 
144
            $showdelete = has_all_capabilities(
-
 
145
                ['mod/feedback:createpublictemplate', 'mod/feedback:deletetemplate'],
-
 
146
                context_system::instance()
-
 
147
            );
-
 
148
        }
-
 
149
        if ($showdelete) {
-
 
150
            $exporturl = new moodle_url(
-
 
151
                '/mod/feedback/manage_templates.php',
-
 
152
                $url->params() + ['deletetemplate' => $template->id]
-
 
153
            );
-
 
154
            $deleteaction = new action_link(
-
 
155
                $exporturl,
98
                        $deleteicon = false;
156
                get_string('delete'),