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
namespace mod_assign\output;
-
 
26
 
-
 
27
use assign;
-
 
28
use context_module;
25
namespace mod_assign\output;
29
use core_course\output\actionbar\group_selector;
26
 
30
use core_course\output\actionbar\user_selector;
27
use templatable;
31
use templatable;
-
 
32
use renderable;
Línea 28... Línea 33...
28
use renderable;
33
use moodle_url;
29
use moodle_url;
34
use core\output\local\dropdown\dialog;
30
 
35
 
31
/**
36
/**
Línea 36... Línea 41...
36
 * @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
37
 */
42
 */
38
class grading_actionmenu implements templatable, renderable {
43
class grading_actionmenu implements templatable, renderable {
Línea 39... Línea 44...
39
 
44
 
40
    /** @var int Course module ID. */
45
    /** @var int Course module ID. */
41
    protected $cmid;
46
    protected int $cmid;
42
    /** @var bool If any submission plugins are enabled. */
47
    /** @var bool If any submission plugins are enabled. */
43
    protected $submissionpluginenabled;
48
    protected bool $submissionpluginenabled;
44
    /** @var int The number of submissions made. */
49
    /** @var int The number of submissions made. */
-
 
50
    protected int $submissioncount;
-
 
51
    /** @var assign The assign instance. */
Línea -... Línea 52...
-
 
52
    protected assign $assign;
-
 
53
 
-
 
54
    /** @var bool If there are submissions to download. */
-
 
55
    protected bool $showdownload;
-
 
56
 
-
 
57
    /** @var array Applied user initials filters, containing 'firstname' and 'lastname'. **/
-
 
58
    protected array $userinitials;
-
 
59
 
Línea 45... Línea 60...
45
    protected $submissioncount;
60
    /** @var bool true if the user has this capability. Otherwise false. */
46
 
61
    private bool $hasviewblind;
47
 
62
 
48
    /**
63
    /**
49
     * Constructor for this object.
64
     * Constructor for this object.
-
 
65
     *
-
 
66
     * @param int $cmid Course module ID.
50
     *
67
     * @param null|bool $submissionpluginenabled This parameter has been deprecated since 4.5 and should not be used anymore.
51
     * @param int $cmid Course module ID.
68
     * @param null|int $submissioncount This parameter has been deprecated since 4.5 and should not be used anymore.
-
 
69
     * @param assign|null $assign The assign instance. If not provided, it will be loaded based on the cmid.
-
 
70
     * @param array $userinitials The user initials to filter the table by.
52
     * @param bool $submissionpluginenabled If any submission plugins are enabled.
71
     */
-
 
72
    public function __construct(
-
 
73
        int $cmid,
-
 
74
        ?bool $submissionpluginenabled = null,
-
 
75
        ?int $submissioncount = null,
53
     * @param int $submissioncount The number of submissions made.
76
        ?assign $assign = null,
-
 
77
        array $userinitials = []
-
 
78
    ) {
-
 
79
        $this->cmid = $cmid;
-
 
80
        if (!$assign) {
54
     */
81
            $context = context_module::instance($cmid);
-
 
82
            $assign = new assign($context, null, null);
55
    public function __construct(int $cmid, bool $submissionpluginenabled = false, int $submissioncount = 0) {
83
        }
Línea -... Línea 84...
-
 
84
        $this->assign = $assign;
-
 
85
        $this->showdownload = $this->assign->is_any_submission_plugin_enabled() && $this->assign->count_submissions();
56
        $this->cmid = $cmid;
86
        $this->userinitials = $userinitials;
Línea 57... Línea 87...
57
        $this->submissionpluginenabled = $submissionpluginenabled;
87
 
58
        $this->submissioncount = $submissioncount;
88
        // Check if we have the elevated view capablities to see the blind details.
59
 
89
        $this->hasviewblind = has_capability('mod/assign:viewblinddetails', $this->assign->get_context());
60
    }
90
    }
61
 
91
 
62
    /**
92
    /**
63
     * Data to render in a template.
93
     * Data to render in a template.
-
 
94
     *
-
 
95
     * @param \renderer_base $output renderer base output.
-
 
96
     * @return array Data to render.
-
 
97
     */
64
     *
98
    public function export_for_template(\renderer_base $output): array {
-
 
99
        global $PAGE;
-
 
100
 
-
 
101
        $course = $this->assign->get_course();
-
 
102
        $cm = get_coursemodule_from_id('assign', $this->cmid);
-
 
103
        $data = [];
-
 
104
 
65
     * @param \renderer_base $output renderer base output.
105
        $userid = optional_param('userid', null, PARAM_INT);
-
 
106
        // If the user ID is set, it indicates that a user has been selected. In this case, override the user search
-
 
107
        // string with the full name of the selected user.
-
 
108
        $usersearch = $userid ? fullname(\core_user::get_user($userid)) : optional_param('search', '', PARAM_NOTAGS);
-
 
109
 
66
     * @return array Data to render.
110
        $isblind = $this->assign->is_blind_marking() && !$this->hasviewblind;
-
 
111
        if ($isblind) {
-
 
112
            $usersearch = $userid ? get_string('hiddenuser', 'assign') . $this->assign->get_uniqueid_for_user($userid) : $usersearch;
-
 
113
        }
-
 
114
 
-
 
115
        $resetlink = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'grading']);
-
 
116
        $groupid = groups_get_course_group($course, true);
-
 
117
        $userselector = new user_selector(
-
 
118
            course: $course,
-
 
119
            resetlink: $resetlink,
-
 
120
            userid: !$isblind ? $userid : null,
-
 
121
            groupid: $groupid,
-
 
122
            usersearch: $usersearch,
-
 
123
            instanceid: $this->assign->get_instance()->id
-
 
124
        );
-
 
125
        $data['userselector'] = $userselector->export_for_template($output);
-
 
126
 
-
 
127
        $hasinitials = !empty($this->userinitials['firstname']) || !empty($this->userinitials['lastname']);
-
 
128
        $additionalparams = ['action' => 'grading', 'id' => $this->cmid];
-
 
129
 
-
 
130
        if (!empty($userid)) {
-
 
131
            $additionalparams['userid'] = $userid;
-
 
132
        } else if (!empty($usersearch)) {
-
 
133
            $additionalparams['search'] = $usersearch;
-
 
134
        }
-
 
135
 
-
 
136
        $initialselector = new \core_course\output\actionbar\initials_selector(
-
 
137
            course: $course,
-
 
138
            targeturl: 'mod/assign/view.php',
-
 
139
            firstinitial: $this->userinitials['firstname'] ?? '',
-
 
140
            lastinitial: $this->userinitials['lastname'] ?? '',
-
 
141
            firstinitialparam: 'tifirst',
-
 
142
            lastinitialparam: 'tilast',
-
 
143
            additionalparams: $additionalparams
-
 
144
        );
-
 
145
 
-
 
146
        $data['initialselector'] = $initialselector->export_for_template($output);
-
 
147
 
-
 
148
        if (groups_get_activity_groupmode($cm, $course)) {
-
 
149
            $gs = new group_selector($PAGE->context);
-
 
150
            $data['groupselector'] = $gs->export_for_template($output);
-
 
151
        }
-
 
152
 
-
 
153
        if ($extrafiltersdropdown = $this->get_extra_filters_dropdown()) {
-
 
154
            $PAGE->requires->js_call_amd('mod_assign/actionbar/grading/extra_filters_dropdown', 'init', []);
-
 
155
            $data['extrafiltersdropdown'] = $extrafiltersdropdown->export_for_template($output);
-
 
156
        }
-
 
157
 
-
 
158
        $activitygroup = groups_get_activity_group($cm);
-
 
159
        $hasuserfilter = get_user_preferences('assign_filter');
-
 
160
        $hasextrafilters = $this->get_applied_extra_filters_count() > 0;
-
 
161
        if ($activitygroup || $hasuserfilter || $hasextrafilters || $hasinitials) {
-
 
162
            $url = new moodle_url('/mod/assign/view.php', [
-
 
163
                'id' => $this->cmid,
-
 
164
                'action' => 'grading',
-
 
165
                'group' => 0,
-
 
166
                'status' => '',
-
 
167
                'workflowfilter' => '',
-
 
168
                'markingallocationfilter' => '',
-
 
169
                'suspendedparticipantsfilter' => 0,
-
 
170
                'tifirst' => '',
-
 
171
                'tilast' => '',
-
 
172
            ]);
-
 
173
            $data['pagereset'] = $url->out(false);
-
 
174
        }
-
 
175
 
-
 
176
        if ($this->assign->is_any_submission_plugin_enabled()) {
-
 
177
            ['statusmenu' => $statusmenu, 'currentvalue' => $currentvalue] = $this->get_status_menu();
-
 
178
            $statusselect = new \core\output\select_menu('status', $statusmenu, $currentvalue);
-
 
179
            $statusselect->set_label(get_string('status', 'mod_assign'), [], true);
-
 
180
            $data['statusselector'] = $statusselect->export_for_template($output);
-
 
181
        }
-
 
182
 
-
 
183
        if ($this->assign->can_grade()) {
-
 
184
            $url = new moodle_url('/mod/assign/view.php', [
-
 
185
                'id' => $this->assign->get_course_module()->id,
-
 
186
                'action' => 'grader',
-
 
187
            ]);
-
 
188
            $data['graderurl'] = $url->out(false);
-
 
189
        }
-
 
190
 
-
 
191
        $gradingmanager = get_grading_manager($this->assign->get_context(), 'mod_assign', 'submissions');
-
 
192
        $controller = $gradingmanager->get_active_controller();
-
 
193
        $showquickgrading = empty($controller) && $this->assign->can_grade();
-
 
194
        if ($showquickgrading) {
-
 
195
            $quickgradingbaseurl = new moodle_url('/mod/assign/view.php', [
-
 
196
                'id' => $this->assign->get_course_module()->id,
-
 
197
                'action' => 'grading',
-
 
198
            ]);
-
 
199
            if ($userid) {
-
 
200
                $quickgradingbaseurl->param('userid', $userid);
-
 
201
            } else if ($usersearch) {
-
 
202
                $quickgradingbaseurl->param('search', $usersearch);
-
 
203
            }
-
 
204
 
-
 
205
            $data['quickgrading'] = [
-
 
206
                'baseurl' => $quickgradingbaseurl->out(false),
-
 
207
                'enabled' => get_user_preferences('assign_quickgrading', false),
-
 
208
            ];
-
 
209
        }
-
 
210
 
-
 
211
        if ($this->showdownload) {
-
 
212
            $downloadasfoldersbaseurl = new moodle_url('/mod/assign/view.php', [
-
 
213
                'id' => $this->assign->get_course_module()->id,
-
 
214
                'action' => 'grading',
-
 
215
            ]);
-
 
216
            if ($userid) {
-
 
217
                $downloadasfoldersbaseurl->param('userid', $userid);
-
 
218
            } else if ($usersearch) {
-
 
219
                $downloadasfoldersbaseurl->param('search', $usersearch);
-
 
220
            }
-
 
221
            $downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
-
 
222
            $data['downloadasfolders'] = [
-
 
223
                'baseurl' => $downloadasfoldersbaseurl->out(false),
-
 
224
                'enabled' => $downloadasfolders,
-
 
225
            ];
-
 
226
        }
-
 
227
 
-
 
228
        $actions = $this->get_actions();
-
 
229
        if ($actions) {
-
 
230
            $menu = new \action_menu();
-
 
231
            $menu->set_menu_trigger(get_string('actions'), 'btn btn-outline-primary');
-
 
232
            foreach ($actions as $groupkey => $actiongroup) {
-
 
233
                foreach ($actiongroup as $label => $url) {
-
 
234
                    $menu->add(new \action_menu_link_secondary(new \moodle_url($url), null, $label));
-
 
235
                }
-
 
236
                if ($groupkey !== array_key_last($actions)) {
-
 
237
                    $divider = new \action_menu_filler();
-
 
238
                    $divider->primary = false;
-
 
239
                    $menu->add($divider);
-
 
240
                }
-
 
241
            }
-
 
242
 
-
 
243
            $renderer = $PAGE->get_renderer('core');
-
 
244
            $data['actions'] = $renderer->render($menu);
-
 
245
        }
-
 
246
 
-
 
247
        return $data;
-
 
248
    }
-
 
249
 
-
 
250
    /**
-
 
251
     * Get the actions for the grading action menu.
-
 
252
     *
-
 
253
     * @return array A 2D array of actions grouped by a key in the form of key => label => URL.
-
 
254
     */
-
 
255
    private function get_actions() {
-
 
256
        $actions = [];
-
 
257
        if (
-
 
258
            has_capability('gradereport/grader:view', $this->assign->get_course_context())
-
 
259
            && has_capability('moodle/grade:viewall', $this->assign->get_course_context())
-
 
260
        ) {
-
 
261
            $url = new moodle_url('/grade/report/grader/index.php', ['id' => $this->assign->get_course()->id]);
-
 
262
            $actions['gradebook'][get_string('viewgradebook', 'assign')] = $url->out(false);
-
 
263
        }
-
 
264
        if ($this->assign->is_blind_marking() && has_capability('mod/assign:revealidentities', $this->assign->get_context())) {
-
 
265
            $url = new moodle_url('/mod/assign/view.php', [
-
 
266
                'id' => $this->assign->get_course_module()->id,
-
 
267
                'action' => 'revealidentities',
-
 
268
            ]);
-
 
269
            $actions['blindmarking'][get_string('revealidentities', 'assign')] = $url->out(false);
-
 
270
        }
-
 
271
        foreach ($this->assign->get_feedback_plugins() as $plugin) {
-
 
272
            if ($plugin->is_enabled() && $plugin->is_visible()) {
-
 
273
                foreach ($plugin->get_grading_actions() as $action => $description) {
-
 
274
                    $url = new moodle_url('/mod/assign/view.php', [
-
 
275
                        'id' => $this->assign->get_course_module()->id,
-
 
276
                        'plugin' => $plugin->get_type(),
-
 
277
                        'pluginsubtype' => 'assignfeedback',
-
 
278
                        'action' => 'viewpluginpage',
-
 
279
                        'pluginaction' => $action,
-
 
280
                    ]);
-
 
281
                    $actions['assignfeedback_' . $plugin->get_type()][$description] = $url->out(false);
-
 
282
                }
-
 
283
            }
-
 
284
        }
-
 
285
        if ($this->showdownload) {
67
     */
286
            $url = new moodle_url('/mod/assign/view.php', [
-
 
287
                'id' => $this->assign->get_course_module()->id,
-
 
288
                'action' => 'downloadall',
-
 
289
            ]);
-
 
290
            $actions['downloadall'][get_string('downloadall', 'mod_assign')] = $url->out(false);
-
 
291
        }
-
 
292
 
-
 
293
        return $actions;
-
 
294
    }
-
 
295
 
-
 
296
    /**
-
 
297
     * Get the status menu for the grading action menu.
-
 
298
     *
-
 
299
     * @return array An array containing the status menu and the current value.
-
 
300
     */
-
 
301
    private function get_status_menu(): array {
-
 
302
        $statusmenu = [];
-
 
303
        $currentvalue = '';
-
 
304
 
-
 
305
        $groupedfilters = $this->assign->get_filters(true);
-
 
306
        foreach ($groupedfilters as $group => $filters) {
-
 
307
            foreach ($filters as $filter) {
-
 
308
                if ($filter['key'] === ASSIGN_FILTER_NONE) {
-
 
309
                    // The 'none' filter is not a real filter.
-
 
310
                    $filter['key'] = '';
-
 
311
                }
-
 
312
                $url = new moodle_url('/mod/assign/view.php', [
-
 
313
                    'id' => $this->assign->get_course_module()->id,
-
 
314
                    'action' => 'grading',
-
 
315
                    'status' => $filter['key'],
-
 
316
                ]);
-
 
317
                $statusmenu[$url->out(false)] = $filter['name'];
-
 
318
 
-
 
319
                if ($filter['active']) {
-
 
320
                    $currentvalue = $url->out(false);
-
 
321
                }
-
 
322
            }
68
    public function export_for_template(\renderer_base $output): array {
323
            if ($group !== array_key_last($groupedfilters)) {
-
 
324
                $statusmenu[] = '';
69
        $downloadall = '';
325
            }
70
        if ($this->submissionpluginenabled && $this->submissioncount) {
326
        }
71
            $downloadall = (new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'downloadall']))->out(false);
327
 
-
 
328
        return [
-
 
329
            'statusmenu' => $statusmenu,
-
 
330
            'currentvalue' => $currentvalue,
-
 
331
        ];
-
 
332
    }
-
 
333
 
-
 
334
    /**
-
 
335
     * The renderable for the extra filters dropdown, if available.
-
 
336
     *
-
 
337
     * @return dialog|null The renderable for the extra filters dropdown, if available.
-
 
338
     */
-
 
339
    private function get_extra_filters_dropdown(): ?dialog {
-
 
340
        global $OUTPUT;
-
 
341
 
-
 
342
        $dropdowncontentdata = [
-
 
343
            'actionurl' => (new moodle_url('/mod/assign/view.php'))->out(false),
-
 
344
            'id' => $this->assign->get_course_module()->id,
-
 
345
            'action' => 'grading',
-
 
346
            'filters' => [],
-
 
347
        ];
-
 
348
 
-
 
349
        // If marking workflow is enabled.
-
 
350
        if ($this->assign->get_instance()->markingworkflow) {
-
 
351
            $dropdowncontentdata['filters']['markingworkflow'] = [
-
 
352
                'workflowfilteroptions' => $this->assign->get_marking_workflow_filters(true),
-
 
353
            ];
-
 
354
 
-
 
355
            // If marking allocation is enabled and the user has the capability to manage marker allocations.
-
 
356
            if ($this->assign->get_instance()->markingallocation &&
-
 
357
                    has_capability('mod/assign:manageallocations', $this->assign->get_context())) {
-
 
358
                $dropdowncontentdata['filters']['markingallocation'] = [
-
 
359
                    'markingallocationoptions' => $this->assign->get_marking_allocation_filters(true),
-
 
360
                ];
-
 
361
            }
-
 
362
        }
-
 
363
 
-
 
364
        if (has_capability('moodle/course:viewsuspendedusers', $this->assign->get_context())) {
-
 
365
            $dropdowncontentdata['filters']['suspendedparticipants'] = [
-
 
366
                'active' => !$this->assign->show_only_active_users(),
-
 
367
            ];
-
 
368
        }
-
 
369
 
-
 
370
        // If there are no available filters, return null.
-
 
371
        if (empty($dropdowncontentdata['filters'])) {
-
 
372
            return null;
-
 
373
        }
-
 
374
 
-
 
375
        // Define the content output for the extra filters dropdown menu.
-
 
376
        $dropdowncontent = $OUTPUT->render_from_template(
-
 
377
            'mod_assign/actionbar/grading/extra_filters_dropdown_body',
-
 
378
            $dropdowncontentdata
-
 
379
        );
-
 
380
 
-
 
381
        // Define the output for the extra filters dropdown trigger.
-
 
382
        $buttoncontent = $OUTPUT->render_from_template(
-
 
383
            'mod_assign/actionbar/grading/extra_filters_dropdown_trigger',
-
 
384
            ['appliedfilterscount' => $this->get_applied_extra_filters_count()]
-
 
385
        );
-
 
386
 
-
 
387
        return new dialog(
-
 
388
            $buttoncontent,
-
 
389
            $dropdowncontent,
-
 
390
            [
-
 
391
                'classes' => 'extrafilters d-flex',
-
 
392
                'buttonclasses' => 'btn d-flex border-none align-items-center dropdown-toggle p-0',
-
 
393
                'autoclose' => 'outside',
-
 
394
            ]
-
 
395
        );
-
 
396
    }
-
 
397
 
-
 
398
    /**
-
 
399
     * Returns the number of applied extra filters.
-
 
400
     *
-
 
401
     * @return int The number of applied extra filters.
-
 
402
     */
-
 
403
    private function get_applied_extra_filters_count(): int {
-
 
404
        $appliedextrafilterscount = 0;
-
 
405
 
-
 
406
        // If marking workflow is enabled.
-
 
407
        if ($this->assign->get_instance()->markingworkflow) {
-
 
408
            if (get_user_preferences('assign_workflowfilter')) {
-
 
409
                $appliedextrafilterscount++;
-
 
410
            }
-
 
411
 
-
 
412
            $canallocatemarker = $this->assign->get_instance()->markingallocation &&
-
 
413
                has_capability('mod/assign:manageallocations', $this->assign->get_context());
-
 
414
 
-
 
415
            if ($canallocatemarker && get_user_preferences('assign_markerfilter')) {
-
 
416
                $appliedextrafilterscount++;
-
 
417
            }
-
 
418
        }
-
 
419
 
-
 
420
        // If suspended participants are included.
-
 
421
        if (!$this->assign->show_only_active_users()) {
72
        }
422
            $appliedextrafilterscount++;