Proyectos de Subversion Moodle

Rev

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

Rev 1267 Rev 1441
Línea 36... Línea 36...
36
define('ASSIGN_FILTER_NONE', 'none');
36
define('ASSIGN_FILTER_NONE', 'none');
37
define('ASSIGN_FILTER_SUBMITTED', 'submitted');
37
define('ASSIGN_FILTER_SUBMITTED', 'submitted');
38
define('ASSIGN_FILTER_NOT_SUBMITTED', 'notsubmitted');
38
define('ASSIGN_FILTER_NOT_SUBMITTED', 'notsubmitted');
39
define('ASSIGN_FILTER_SINGLE_USER', 'singleuser');
39
define('ASSIGN_FILTER_SINGLE_USER', 'singleuser');
40
define('ASSIGN_FILTER_REQUIRE_GRADING', 'requiregrading');
40
define('ASSIGN_FILTER_REQUIRE_GRADING', 'requiregrading');
-
 
41
define('ASSIGN_FILTER_GRADED', 'graded');
41
define('ASSIGN_FILTER_GRANTED_EXTENSION', 'grantedextension');
42
define('ASSIGN_FILTER_GRANTED_EXTENSION', 'grantedextension');
42
define('ASSIGN_FILTER_DRAFT', 'draft');
43
define('ASSIGN_FILTER_DRAFT', 'draft');
Línea 43... Línea 44...
43
 
44
 
44
// Marker filter for grading page.
45
// Marker filter for grading page.
Línea 45... Línea 46...
45
define('ASSIGN_MARKER_FILTER_NO_MARKER', -1);
46
define('ASSIGN_MARKER_FILTER_NO_MARKER', -1);
-
 
47
 
-
 
48
// Reopen attempt methods.
-
 
49
/**
-
 
50
 * ASSIGN_ATTEMPT_REOPEN_METHOD_NONE - Reopening attempts is not allowed.
-
 
51
 *
-
 
52
 * @deprecated since Moodle 4.4
46
 
53
 * @todo MDL-81977 This will be deleted in Moodle 4.8.
47
// Reopen attempt methods.
54
 */
-
 
55
define('ASSIGN_ATTEMPT_REOPEN_METHOD_NONE', 'none');
48
define('ASSIGN_ATTEMPT_REOPEN_METHOD_NONE', 'none');
56
define('ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL', 'manual');
Línea 49... Línea 57...
49
define('ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL', 'manual');
57
define('ASSIGN_ATTEMPT_REOPEN_METHOD_AUTOMATIC', 'automatic');
50
define('ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS', 'untilpass');
58
define('ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS', 'untilpass');
Línea 79... Línea 87...
79
// Event types.
87
// Event types.
80
define('ASSIGN_EVENT_TYPE_DUE', 'due');
88
define('ASSIGN_EVENT_TYPE_DUE', 'due');
81
define('ASSIGN_EVENT_TYPE_GRADINGDUE', 'gradingdue');
89
define('ASSIGN_EVENT_TYPE_GRADINGDUE', 'gradingdue');
82
define('ASSIGN_EVENT_TYPE_OPEN', 'open');
90
define('ASSIGN_EVENT_TYPE_OPEN', 'open');
83
define('ASSIGN_EVENT_TYPE_CLOSE', 'close');
91
define('ASSIGN_EVENT_TYPE_CLOSE', 'close');
-
 
92
define('ASSIGN_EVENT_TYPE_EXTENSION', 'extension');
Línea 84... Línea 93...
84
 
93
 
85
require_once($CFG->libdir . '/accesslib.php');
94
require_once($CFG->libdir . '/accesslib.php');
86
require_once($CFG->libdir . '/formslib.php');
95
require_once($CFG->libdir . '/formslib.php');
87
require_once($CFG->dirroot . '/repository/lib.php');
96
require_once($CFG->dirroot . '/repository/lib.php');
Línea 107... Línea 116...
107
 *
116
 *
108
 * @package   mod_assign
117
 * @package   mod_assign
109
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
118
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
110
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
119
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
111
 */
120
 */
112
class assign
121
class assign {
113
{
-
 
Línea 114... Línea 122...
114
 
122
 
115
    /** @var stdClass the assignment record that contains the global settings for this assign instance */
123
    /** @var stdClass the assignment record that contains the global settings for this assign instance */
Línea 116... Línea 124...
116
    private $instance;
124
    private $instance;
Línea 141... Línea 149...
141
    /** @var array cache for things like the coursemodule name or the scale menu -
149
    /** @var array cache for things like the coursemodule name or the scale menu -
142
     *             only lives for a single request.
150
     *             only lives for a single request.
143
     */
151
     */
144
    private $cache;
152
    private $cache;
Línea 145... Línea 153...
145
 
153
 
146
    /** @var array list of the installed submission plugins */
154
    /** @var assign_submission_plugin[] list of the installed submission plugins */
Línea 147... Línea 155...
147
    private $submissionplugins;
155
    private $submissionplugins;
148
 
156
 
Línea 149... Línea 157...
149
    /** @var array list of the installed feedback plugins */
157
    /** @var assign_feedback_plugin[] list of the installed feedback plugins */
150
    private $feedbackplugins;
158
    private $feedbackplugins;
151
 
159
 
Línea 200... Línea 208...
200
    private $overridedata;
208
    private $overridedata;
Línea 201... Línea 209...
201
 
209
 
202
    /** @var float grade value. */
210
    /** @var float grade value. */
Línea -... Línea 211...
-
 
211
    public $grade;
-
 
212
 
-
 
213
    /** @var array $usersearch The content that the current user is looking for. */
203
    public $grade;
214
    protected array $usersearch = [];
204
 
215
 
205
    /**
216
    /**
206
     * Constructor for the base assign class.
217
     * Constructor for the base assign class.
207
     *
218
     *
Línea 214... Línea 225...
214
     * @param mixed $coursemodule the current course module if it was already loaded,
225
     * @param mixed $coursemodule the current course module if it was already loaded,
215
     *                            otherwise this class will load one from the context as required.
226
     *                            otherwise this class will load one from the context as required.
216
     * @param mixed $course the current course  if it was already loaded,
227
     * @param mixed $course the current course  if it was already loaded,
217
     *                      otherwise this class will load one from the context as required.
228
     *                      otherwise this class will load one from the context as required.
218
     */
229
     */
219
    public function __construct($coursemodulecontext, $coursemodule, $course)
230
    public function __construct($coursemodulecontext, $coursemodule, $course) {
220
    {
-
 
221
        $this->context = $coursemodulecontext;
231
        $this->context = $coursemodulecontext;
222
        $this->course = $course;
232
        $this->course = $course;
Línea 223... Línea 233...
223
 
233
 
224
        // Ensure that $this->coursemodule is a cm_info object (or null).
234
        // Ensure that $this->coursemodule is a cm_info object (or null).
Línea 240... Línea 250...
240
     * @param string $action The action for the current page
250
     * @param string $action The action for the current page
241
     * @param array $params An array of name value pairs which form the parameters
251
     * @param array $params An array of name value pairs which form the parameters
242
     *                      to return to the current page.
252
     *                      to return to the current page.
243
     * @return void
253
     * @return void
244
     */
254
     */
245
    public function register_return_link($action, $params)
255
    public function register_return_link($action, $params) {
246
    {
-
 
247
        global $PAGE;
256
        global $PAGE;
248
        $params['action'] = $action;
257
        $params['action'] = $action;
249
        $cm = $this->get_course_module();
258
        $cm = $this->get_course_module();
250
        if ($cm) {
259
        if ($cm) {
251
            $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $cm->id));
260
            $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $cm->id));
Línea 260... Línea 269...
260
    /**
269
    /**
261
     * Return an action that can be used to get back to the current page.
270
     * Return an action that can be used to get back to the current page.
262
     *
271
     *
263
     * @return string action
272
     * @return string action
264
     */
273
     */
265
    public function get_return_action()
274
    public function get_return_action() {
266
    {
-
 
267
        global $PAGE;
275
        global $PAGE;
Línea 268... Línea 276...
268
 
276
 
269
        // Web services don't set a URL, we should avoid debugging when ussing the url object.
277
        // Web services don't set a URL, we should avoid debugging when ussing the url object.
270
        if (!WS_SERVER) {
278
        if (!WS_SERVER) {
Línea 280... Línea 288...
280
    /**
288
    /**
281
     * Based on the current assignment settings should we display the intro.
289
     * Based on the current assignment settings should we display the intro.
282
     *
290
     *
283
     * @return bool showintro
291
     * @return bool showintro
284
     */
292
     */
285
    public function show_intro()
293
    public function show_intro() {
286
    {
-
 
287
        if (
-
 
288
            $this->get_instance()->alwaysshowdescription ||
294
        if ($this->get_instance()->alwaysshowdescription ||
289
            time() > $this->get_instance()->allowsubmissionsfromdate
295
                time() > $this->get_instance()->allowsubmissionsfromdate) {
290
        ) {
-
 
291
            return true;
296
            return true;
292
        }
297
        }
293
        return false;
298
        return false;
294
    }
299
    }
Línea 295... Línea 300...
295
 
300
 
296
    /**
301
    /**
297
     * Return a list of parameters that can be used to get back to the current page.
302
     * Return a list of parameters that can be used to get back to the current page.
298
     *
303
     *
299
     * @return array params
304
     * @return array params
300
     */
305
     */
301
    public function get_return_params()
-
 
302
    {
306
    public function get_return_params() {
Línea 303... Línea 307...
303
        global $PAGE;
307
        global $PAGE;
304
 
308
 
305
        $params = array();
309
        $params = array();
Línea 314... Línea 318...
314
    /**
318
    /**
315
     * Set the submitted form data.
319
     * Set the submitted form data.
316
     *
320
     *
317
     * @param stdClass $data The form data (instance)
321
     * @param stdClass $data The form data (instance)
318
     */
322
     */
319
    public function set_instance(stdClass $data)
323
    public function set_instance(stdClass $data) {
320
    {
-
 
321
        $this->instance = $data;
324
        $this->instance = $data;
322
    }
325
    }
Línea 323... Línea 326...
323
 
326
 
324
    /**
327
    /**
325
     * Set the context.
328
     * Set the context.
326
     *
329
     *
327
     * @param context $context The new context
330
     * @param context $context The new context
328
     */
331
     */
329
    public function set_context(context $context)
-
 
330
    {
332
    public function set_context(context $context) {
331
        $this->context = $context;
333
        $this->context = $context;
Línea 332... Línea 334...
332
    }
334
    }
333
 
335
 
334
    /**
336
    /**
335
     * Set the course data.
337
     * Set the course data.
336
     *
338
     *
337
     * @param stdClass $course The course data
339
     * @param stdClass $course The course data
338
     */
-
 
339
    public function set_course(stdClass $course)
340
     */
340
    {
341
    public function set_course(stdClass $course) {
Línea 341... Línea 342...
341
        $this->course = $course;
342
        $this->course = $course;
-
 
343
    }
-
 
344
 
-
 
345
    /**
-
 
346
     * Set usersearch to limit results when getting list of participants.
-
 
347
     *
-
 
348
     * @param int|null $userid User id to search for.
-
 
349
     * @param int|null $groupid Group id to limit resuts to specific group.
-
 
350
     * @param string $usersearch Search string to limit results.
-
 
351
     */
-
 
352
    public function set_usersearch(?int $userid, ?int $groupid, string $usersearch = ''): void {
-
 
353
        $usersearcharray = [];
-
 
354
        $usersearcharray['userid'] = $userid;
-
 
355
        $usersearcharray['groupid'] = $groupid;
-
 
356
        $usersearcharray['usersearch'] = $usersearch;
-
 
357
        $this->usersearch = $usersearcharray;
342
    }
358
    }
343
 
359
 
344
    /**
360
    /**
345
     * Set error message.
361
     * Set error message.
346
     *
362
     *
347
     * @param string $message The error message
-
 
348
     */
363
     * @param string $message The error message
349
    protected function set_error_message(string $message)
364
     */
Línea 350... Línea 365...
350
    {
365
    protected function set_error_message(string $message) {
351
        $this->errors[] = $message;
366
        $this->errors[] = $message;
352
    }
367
    }
353
 
368
 
354
    /**
369
    /**
355
     * Get error messages.
370
     * Get error messages.
356
     *
-
 
357
     * @return array The array of error messages
371
     *
358
     */
372
     * @return array The array of error messages
Línea 359... Línea 373...
359
    protected function get_error_messages(): array
373
     */
360
    {
374
    public function get_error_messages(): array {
361
        return $this->errors;
375
        return $this->errors;
362
    }
376
    }
363
 
377
 
364
    /**
378
    /**
365
     * Get list of feedback plugins installed.
-
 
366
     *
379
     * Get list of feedback plugins installed.
367
     * @return array
380
     *
Línea 368... Línea 381...
368
     */
381
     * @return array
369
    public function get_feedback_plugins()
382
     */
370
    {
383
    public function get_feedback_plugins() {
371
        return $this->feedbackplugins;
384
        return $this->feedbackplugins;
372
    }
385
    }
373
 
386
 
374
    /**
-
 
375
     * Get list of submission plugins installed.
387
    /**
376
     *
388
     * Get list of submission plugins installed.
Línea 377... Línea 389...
377
     * @return array
389
     *
378
     */
390
     * @return array
379
    public function get_submission_plugins()
391
     */
380
    {
392
    public function get_submission_plugins() {
381
        return $this->submissionplugins;
393
        return $this->submissionplugins;
382
    }
394
    }
383
 
-
 
384
    /**
395
 
385
     * Is blind marking enabled and reveal identities not set yet?
396
    /**
Línea 386... Línea 397...
386
     *
397
     * Is blind marking enabled and reveal identities not set yet?
387
     * @return bool
398
     *
Línea 397... Línea 408...
397
     * This just checks the assignment settings. Remember to check
408
     * This just checks the assignment settings. Remember to check
398
     * the user has the 'showhiddengrader' capability too
409
     * the user has the 'showhiddengrader' capability too
399
     *
410
     *
400
     * @return bool
411
     * @return bool
401
     */
412
     */
402
    public function is_hidden_grader()
413
    public function is_hidden_grader() {
403
    {
-
 
404
        return $this->get_instance()->hidegrader;
414
        return $this->get_instance()->hidegrader;
405
    }
415
    }
Línea 406... Línea 416...
406
 
416
 
407
    /**
417
    /**
408
     * Does an assignment have submission(s) or grade(s) already?
418
     * Does an assignment have submission(s) or grade(s) already?
409
     *
419
     *
410
     * @return bool
420
     * @return bool
411
     */
421
     */
412
    public function has_submissions_or_grades()
-
 
413
    {
422
    public function has_submissions_or_grades() {
414
        $allgrades = $this->count_grades();
423
        $allgrades = $this->count_grades();
415
        $allsubmissions = $this->count_submissions();
424
        $allsubmissions = $this->count_submissions();
416
        if (($allgrades == 0) && ($allsubmissions == 0)) {
425
        if (($allgrades == 0) && ($allsubmissions == 0)) {
417
            return false;
426
            return false;
Línea 424... Línea 433...
424
     *
433
     *
425
     * @param string $subtype assignsubmission | assignfeedback
434
     * @param string $subtype assignsubmission | assignfeedback
426
     * @param string $type
435
     * @param string $type
427
     * @return mixed assign_plugin|null
436
     * @return mixed assign_plugin|null
428
     */
437
     */
429
    public function get_plugin_by_type($subtype, $type)
438
    public function get_plugin_by_type($subtype, $type) {
430
    {
-
 
431
        $shortsubtype = substr($subtype, strlen('assign'));
439
        $shortsubtype = substr($subtype, strlen('assign'));
432
        $name = $shortsubtype . 'plugins';
440
        $name = $shortsubtype . 'plugins';
433
        if ($name != 'feedbackplugins' && $name != 'submissionplugins') {
441
        if ($name != 'feedbackplugins' && $name != 'submissionplugins') {
434
            return null;
442
            return null;
435
        }
443
        }
Línea 446... Línea 454...
446
     * Get a feedback plugin by type.
454
     * Get a feedback plugin by type.
447
     *
455
     *
448
     * @param string $type - The type of plugin e.g comments
456
     * @param string $type - The type of plugin e.g comments
449
     * @return mixed assign_feedback_plugin|null
457
     * @return mixed assign_feedback_plugin|null
450
     */
458
     */
451
    public function get_feedback_plugin_by_type($type)
459
    public function get_feedback_plugin_by_type($type) {
452
    {
-
 
453
        return $this->get_plugin_by_type('assignfeedback', $type);
460
        return $this->get_plugin_by_type('assignfeedback', $type);
454
    }
461
    }
Línea 455... Línea 462...
455
 
462
 
456
    /**
463
    /**
457
     * Get a submission plugin by type.
464
     * Get a submission plugin by type.
458
     *
465
     *
459
     * @param string $type - The type of plugin e.g comments
466
     * @param string $type - The type of plugin e.g comments
460
     * @return mixed assign_submission_plugin|null
467
     * @return mixed assign_submission_plugin|null
461
     */
468
     */
462
    public function get_submission_plugin_by_type($type)
-
 
463
    {
469
    public function get_submission_plugin_by_type($type) {
464
        return $this->get_plugin_by_type('assignsubmission', $type);
470
        return $this->get_plugin_by_type('assignsubmission', $type);
Línea 465... Línea 471...
465
    }
471
    }
466
 
472
 
467
    /**
473
    /**
468
     * Load the plugins from the sub folders under subtype.
474
     * Load the plugins from the sub folders under subtype.
469
     *
475
     *
470
     * @param string $subtype - either submission or feedback
476
     * @param string $subtype - either submission or feedback
471
     * @return array - The sorted list of plugins
477
     * @return array - The sorted list of plugins
472
     */
-
 
473
    public function load_plugins($subtype)
478
     */
474
    {
479
    public function load_plugins($subtype) {
Línea 475... Línea 480...
475
        global $CFG;
480
        global $CFG;
Línea 487... Línea 492...
487
                $plugin = new $pluginclass($this, $name);
492
                $plugin = new $pluginclass($this, $name);
Línea 488... Línea 493...
488
 
493
 
489
                if ($plugin instanceof assign_plugin) {
494
                if ($plugin instanceof assign_plugin) {
490
                    $idx = $plugin->get_sort_order();
495
                    $idx = $plugin->get_sort_order();
491
                    while (array_key_exists($idx, $result)) {
496
                    while (array_key_exists($idx, $result)) {
492
                        $idx += 1;
497
                        $idx +=1;
493
                    }
498
                    }
494
                    $result[$idx] = $plugin;
499
                    $result[$idx] = $plugin;
495
                }
500
                }
496
            }
501
            }
Línea 507... Línea 512...
507
     *
512
     *
508
     * @param string $action The current action if any.
513
     * @param string $action The current action if any.
509
     * @param array $args Optional arguments to pass to the view (instead of getting them from GET and POST).
514
     * @param array $args Optional arguments to pass to the view (instead of getting them from GET and POST).
510
     * @return string - The page output.
515
     * @return string - The page output.
511
     */
516
     */
512
    public function view($action = '', $args = array())
517
    public function view($action='', $args = array()) {
513
    {
-
 
514
        global $PAGE;
518
        global $PAGE;
Línea 515... Línea 519...
515
 
519
 
516
        $o = '';
520
        $o = '';
517
        $mform = null;
521
        $mform = null;
Línea 520... Línea 524...
520
 
524
 
521
        if (!empty($this->get_course_module()->id)) {
525
        if (!empty($this->get_course_module()->id)) {
522
            $nextpageparams['id'] = $this->get_course_module()->id;
526
            $nextpageparams['id'] = $this->get_course_module()->id;
Línea 523... Línea -...
523
        }
-
 
524
 
-
 
525
        if (empty($action)) {
-
 
526
            $PAGE->add_body_class('limitedwidth');
-
 
527
        }
527
        }
528
 
528
 
529
        // Handle form submissions first.
529
        // Handle form submissions first.
530
        if ($action == 'savesubmission') {
530
        if ($action == 'savesubmission') {
531
            $action = 'editsubmission';
531
            $action = 'editsubmission';
Línea 589... Línea 589...
589
                $nextpageparams['action'] = 'grading';
589
                $nextpageparams['action'] = 'grading';
590
            } else {
590
            } else {
591
                $action = 'viewsubmitforgradingerror';
591
                $action = 'viewsubmitforgradingerror';
592
            }
592
            }
593
        } else if ($action == 'gradingbatchoperation') {
593
        } else if ($action == 'gradingbatchoperation') {
594
            $action = $this->process_grading_batch_operation($mform);
594
            $action = $this->process_grading_batch_operation();
595
            if ($action == 'grading') {
595
            if ($action == 'grading') {
596
                $action = 'redirect';
596
                $action = 'redirect';
597
                $nextpageparams['action'] = 'grading';
597
                $nextpageparams['action'] = 'grading';
598
            }
598
            }
599
        } else if ($action == 'submitgrade') {
599
        } else if ($action == 'submitgrade') {
Línea 629... Línea 629...
629
                $nextpageparams['action'] = 'grading';
629
                $nextpageparams['action'] = 'grading';
630
            }
630
            }
631
        } else if ($action == 'quickgrade') {
631
        } else if ($action == 'quickgrade') {
632
            $message = $this->process_save_quick_grades();
632
            $message = $this->process_save_quick_grades();
633
            $action = 'quickgradingresult';
633
            $action = 'quickgradingresult';
634
        } else if ($action == 'saveoptions') {
-
 
635
            $this->process_save_grading_options();
-
 
636
            $action = 'redirect';
-
 
637
            $nextpageparams['action'] = 'grading';
-
 
638
        } else if ($action == 'saveextension') {
634
        } else if ($action == 'saveextension') {
639
            $action = 'grantextension';
635
            $action = 'grantextension';
640
            if ($this->process_save_extension($mform)) {
636
            if ($this->process_save_extension($mform)) {
641
                $action = 'redirect';
637
                $action = 'redirect';
642
                $nextpageparams['action'] = 'grading';
638
                $nextpageparams['action'] = 'grading';
Línea 645... Línea 641...
645
            $this->process_reveal_identities();
641
            $this->process_reveal_identities();
646
            $action = 'redirect';
642
            $action = 'redirect';
647
            $nextpageparams['action'] = 'grading';
643
            $nextpageparams['action'] = 'grading';
648
        }
644
        }
Línea 649... Línea -...
649
 
-
 
650
        $returnparams = array(
645
 
651
            'rownum' => optional_param('rownum', 0, PARAM_INT),
646
        $returnparams = array('rownum'=>optional_param('rownum', 0, PARAM_INT),
652
            'useridlistid' => optional_param('useridlistid', $this->get_useridlist_key_id(), PARAM_ALPHANUM)
-
 
653
        );
647
                              'useridlistid' => optional_param('useridlistid', $this->get_useridlist_key_id(), PARAM_ALPHANUM));
Línea 654... Línea 648...
654
        $this->register_return_link($action, $returnparams);
648
        $this->register_return_link($action, $returnparams);
655
 
649
 
656
        // Include any page action as part of the body tag CSS id.
650
        // Include any page action as part of the body tag CSS id.
Línea 696... Línea 690...
696
            $PAGE->add_body_class('limitedwidth');
690
            $PAGE->add_body_class('limitedwidth');
697
            $o .= $this->check_submit_for_grading($mform);
691
            $o .= $this->check_submit_for_grading($mform);
698
        } else if ($action == 'grantextension') {
692
        } else if ($action == 'grantextension') {
699
            $o .= $this->view_grant_extension($mform);
693
            $o .= $this->view_grant_extension($mform);
700
        } else if ($action == 'revealidentities') {
694
        } else if ($action == 'revealidentities') {
701
            $o .= $this->view_reveal_identities_confirm($mform);
695
            $o .= $this->view_reveal_identities_confirm();
702
        } else if ($action == 'removesubmissionconfirm') {
696
        } else if ($action == 'removesubmissionconfirm') {
703
            $PAGE->add_body_class('limitedwidth');
697
            $PAGE->add_body_class('limitedwidth');
704
            $o .= $this->view_remove_submission_confirm();
698
            $o .= $this->view_remove_submission_confirm();
705
        } else if ($action == 'plugingradingbatchoperation') {
699
        } else if ($action == 'plugingradingbatchoperation') {
706
            $o .= $this->view_plugin_grading_batch_operation($mform);
700
            $o .= $this->view_plugin_grading_batch_operation();
707
        } else if ($action == 'viewpluginpage') {
701
        } else if ($action == 'viewpluginpage') {
708
            $o .= $this->view_plugin_page();
702
             $o .= $this->view_plugin_page();
709
        } else if ($action == 'viewcourseindex') {
-
 
710
            $o .= $this->view_course_index();
-
 
711
        } else if ($action == 'viewbatchsetmarkingworkflowstate') {
703
        } else if ($action == 'viewbatchsetmarkingworkflowstate') {
712
            $o .= $this->view_batch_set_workflow_state($mform);
704
             $o .= $this->view_batch_set_workflow_state();
713
        } else if ($action == 'viewbatchmarkingallocation') {
705
        } else if ($action == 'viewbatchmarkingallocation') {
714
            $o .= $this->view_batch_markingallocation($mform);
706
            $o .= $this->view_batch_markingallocation();
715
        } else if ($action == 'viewsubmitforgradingerror') {
707
        } else if ($action == 'viewsubmitforgradingerror') {
716
            $o .= $this->view_error_page(get_string('submitforgrading', 'assign'), $notices);
708
            $o .= $this->view_error_page(get_string('submitforgrading', 'assign'), $notices);
717
        } else if ($action == 'fixrescalednullgrades') {
709
        } else if ($action == 'fixrescalednullgrades') {
718
            $o .= $this->view_fix_rescaled_null_grades();
710
            $o .= $this->view_fix_rescaled_null_grades();
719
        } else {
711
        } else {
Línea 730... Línea 722...
730
     * @param stdClass $formdata The data submitted from the form
722
     * @param stdClass $formdata The data submitted from the form
731
     * @param bool $callplugins This is used to skip the plugin code
723
     * @param bool $callplugins This is used to skip the plugin code
732
     *             when upgrading an old assignment to a new one (the plugins get called manually)
724
     *             when upgrading an old assignment to a new one (the plugins get called manually)
733
     * @return mixed false if an error occurs or the int id of the new instance
725
     * @return mixed false if an error occurs or the int id of the new instance
734
     */
726
     */
735
    public function add_instance(stdClass $formdata, $callplugins)
727
    public function add_instance(stdClass $formdata, $callplugins) {
736
    {
-
 
737
        global $DB;
728
        global $DB;
738
        $adminconfig = $this->get_admin_config();
729
        $adminconfig = $this->get_admin_config();
Línea 739... Línea 730...
739
 
730
 
Línea 780... Línea 771...
780
        }
771
        }
781
        $update->blindmarking = $formdata->blindmarking;
772
        $update->blindmarking = $formdata->blindmarking;
782
        if (isset($formdata->hidegrader)) {
773
        if (isset($formdata->hidegrader)) {
783
            $update->hidegrader = $formdata->hidegrader;
774
            $update->hidegrader = $formdata->hidegrader;
784
        }
775
        }
785
        $update->attemptreopenmethod = ASSIGN_ATTEMPT_REOPEN_METHOD_NONE;
-
 
786
        if (!empty($formdata->attemptreopenmethod)) {
776
        $update->maxattempts = $formdata->maxattempts ?? 1;
787
            $update->attemptreopenmethod = $formdata->attemptreopenmethod;
777
        $update->attemptreopenmethod = $formdata->attemptreopenmethod ?? ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS;
788
        }
-
 
789
        if (!empty($formdata->maxattempts)) {
-
 
790
            $update->maxattempts = $formdata->maxattempts;
-
 
791
        }
-
 
792
        if (isset($formdata->preventsubmissionnotingroup)) {
778
        if (isset($formdata->preventsubmissionnotingroup)) {
793
            $update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
779
            $update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
794
        }
780
        }
795
        $update->markingworkflow = $formdata->markingworkflow;
781
        $update->markingworkflow = $formdata->markingworkflow;
796
        $update->markingallocation = $formdata->markingallocation;
782
        $update->markingallocation = $formdata->markingallocation;
Línea 803... Línea 789...
803
                $update->markinganonymous = 0;
789
                $update->markinganonymous = 0;
804
            } else {
790
            } else {
805
                $update->markinganonymous = $formdata->markinganonymous;
791
                $update->markinganonymous = $formdata->markinganonymous;
806
            }
792
            }
807
        }
793
        }
-
 
794
 
-
 
795
        // Grade penalties.
-
 
796
        $update->gradepenalty = $formdata->gradepenalty ?? 0;
-
 
797
 
808
        $returnid = $DB->insert_record('assign', $update);
798
        $returnid = $DB->insert_record('assign', $update);
809
        $this->instance = $DB->get_record('assign', array('id' => $returnid), '*', MUST_EXIST);
799
        $this->instance = $DB->get_record('assign', array('id'=>$returnid), '*', MUST_EXIST);
810
        // Cache the course record.
800
        // Cache the course record.
811
        $this->course = $DB->get_record('course', array('id' => $formdata->course), '*', MUST_EXIST);
801
        $this->course = $DB->get_record('course', array('id'=>$formdata->course), '*', MUST_EXIST);
Línea 812... Línea 802...
812
 
802
 
813
        $this->save_intro_draft_files($formdata);
803
        $this->save_intro_draft_files($formdata);
Línea 814... Línea 804...
814
        $this->save_editor_draft_files($formdata);
804
        $this->save_editor_draft_files($formdata);
Línea 830... Línea 820...
830
 
820
 
831
            // In the case of upgrades the coursemodule has not been set,
821
            // In the case of upgrades the coursemodule has not been set,
832
            // so we need to wait before calling these two.
822
            // so we need to wait before calling these two.
833
            $this->update_calendar($formdata->coursemodule);
823
            $this->update_calendar($formdata->coursemodule);
834
            if (!empty($formdata->completionexpected)) {
824
            if (!empty($formdata->completionexpected)) {
835
                \core_completion\api::update_completion_date_event(
-
 
836
                    $formdata->coursemodule,
-
 
837
                    'assign',
-
 
838
                    $this->instance,
825
                \core_completion\api::update_completion_date_event($formdata->coursemodule, 'assign', $this->instance,
839
                    $formdata->completionexpected
-
 
840
                );
826
                        $formdata->completionexpected);
841
            }
827
            }
-
 
828
            $this->update_gradebook(false, $formdata->coursemodule);
842
            $this->update_gradebook(false, $formdata->coursemodule);
829
 
Línea 843... Línea 830...
843
        }
830
        }
844
 
831
 
845
        $update = new stdClass();
832
        $update = new stdClass();
846
        $update->id = $this->get_instance()->id;
833
        $update->id = $this->get_instance()->id;
Línea 847... Línea 834...
847
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1 : 0;
834
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1: 0;
848
        $DB->update_record('assign', $update);
835
        $DB->update_record('assign', $update);
Línea 849... Línea 836...
849
 
836
 
850
        return $returnid;
837
        return $returnid;
851
    }
838
    }
852
 
839
 
853
    /**
840
    /**
854
     * Delete all grades from the gradebook for this assignment.
841
     * Delete all grades from the gradebook for this assignment.
855
     *
-
 
856
     * @return bool
842
     *
Línea 857... Línea 843...
857
     */
843
     * @return bool
858
    protected function delete_grades()
-
 
859
    {
844
     */
860
        global $CFG;
845
    protected function delete_grades() {
861
 
846
        global $CFG;
862
        $result = grade_update(
847
 
863
            'mod/assign',
848
        $result = grade_update('mod/assign',
864
            $this->get_course()->id,
849
                               $this->get_course()->id,
865
            'mod',
850
                               'mod',
866
            'assign',
-
 
867
            $this->get_instance()->id,
851
                               'assign',
868
            0,
852
                               $this->get_instance()->id,
Línea 869... Línea 853...
869
            null,
853
                               0,
870
            array('deleted' => 1)
854
                               null,
871
        );
855
                               array('deleted'=>1));
872
        return $result == GRADE_UPDATE_OK;
856
        return $result == GRADE_UPDATE_OK;
873
    }
857
    }
874
 
858
 
875
    /**
-
 
876
     * Delete this instance from the database.
859
    /**
877
     *
860
     * Delete this instance from the database.
Línea 878... Línea 861...
878
     * @return bool false if an error occurs
861
     *
879
     */
862
     * @return bool false if an error occurs
Línea 895... Línea 878...
895
            }
878
            }
896
        }
879
        }
Línea 897... Línea 880...
897
 
880
 
898
        // Delete files associated with this assignment.
881
        // Delete files associated with this assignment.
899
        $fs = get_file_storage();
882
        $fs = get_file_storage();
900
        if (! $fs->delete_area_files($this->context->id)) {
883
        if (! $fs->delete_area_files($this->context->id) ) {
901
            $result = false;
884
            $result = false;
Línea 902... Línea 885...
902
        }
885
        }
Línea 915... Línea 898...
915
            $result = false;
898
            $result = false;
916
        }
899
        }
Línea 917... Línea 900...
917
 
900
 
918
        // Delete the instance.
901
        // Delete the instance.
919
        // We must delete the module record after we delete the grade item.
902
        // We must delete the module record after we delete the grade item.
Línea 920... Línea 903...
920
        $DB->delete_records('assign', array('id' => $this->get_instance()->id));
903
        $DB->delete_records('assign', array('id'=>$this->get_instance()->id));
921
 
904
 
Línea 922... Línea 905...
922
        return $result;
905
        return $result;
923
    }
906
    }
924
 
907
 
925
    /**
908
    /**
926
     * Deletes a assign override from the database and clears any corresponding calendar events
909
     * Deletes a assign override from the database and clears any corresponding calendar events
927
     *
910
     *
928
     * @param int $overrideid The id of the override being deleted
911
     * @param int $overrideid The id of the override being deleted
929
     * @return bool true on success
-
 
930
     */
912
     * @return bool true on success
Línea 931... Línea 913...
931
    public function delete_override($overrideid)
913
     */
Línea 932... Línea 914...
932
    {
914
    public function delete_override($overrideid) {
Línea 985... Línea 967...
985
    }
967
    }
Línea 986... Línea 968...
986
 
968
 
987
    /**
969
    /**
988
     * Deletes all assign overrides from the database and clears any corresponding calendar events
970
     * Deletes all assign overrides from the database and clears any corresponding calendar events
989
     */
971
     */
990
    public function delete_all_overrides()
-
 
991
    {
972
    public function delete_all_overrides() {
Línea 992... Línea 973...
992
        global $DB;
973
        global $DB;
993
 
974
 
994
        $overrides = $DB->get_records('assign_overrides', array('assignid' => $this->get_instance()->id), 'id');
975
        $overrides = $DB->get_records('assign_overrides', array('assignid' => $this->get_instance()->id), 'id');
Línea 1004... Línea 985...
1004
     *   then use that otherwise, if there are group-specific overrides, return the most
985
     *   then use that otherwise, if there are group-specific overrides, return the most
1005
     *   lenient combination of them.  If neither applies, leave the assign setting unchanged.
986
     *   lenient combination of them.  If neither applies, leave the assign setting unchanged.
1006
     *
987
     *
1007
     * @param int $userid The userid.
988
     * @param int $userid The userid.
1008
     */
989
     */
1009
    public function update_effective_access($userid)
990
    public function update_effective_access($userid) {
1010
    {
-
 
Línea 1011... Línea 991...
1011
 
991
 
Línea 1012... Línea 992...
1012
        $override = $this->override_exists($userid);
992
        $override = $this->override_exists($userid);
1013
 
993
 
1014
        // Merge with assign defaults.
994
        // Merge with assign defaults.
1015
        $keys = array('duedate', 'cutoffdate', 'allowsubmissionsfromdate', 'timelimit');
995
        $keys = array('duedate', 'cutoffdate', 'allowsubmissionsfromdate', 'timelimit');
1016
        foreach ($keys as $key) {
996
        foreach ($keys as $key) {
1017
            if (isset($override->{$key})) {
997
            if (isset($override->{$key})) {
1018
                $this->get_instance($userid)->{$key} = $override->{$key};
998
                $this->get_instance($userid)->{$key} = $override->{$key};
-
 
999
            }
1019
            }
1000
        }
Línea 1020... Línea 1001...
1020
        }
1001
 
1021
    }
1002
    }
1022
 
1003
 
1023
    /**
1004
    /**
1024
     * Returns whether an assign has any overrides.
1005
     * Returns whether an assign has any overrides.
1025
     *
1006
     *
1026
     * @return true if any, false if not
-
 
1027
     */
1007
     * @return true if any, false if not
Línea 1028... Línea 1008...
1028
    public function has_overrides()
1008
     */
Línea 1029... Línea 1009...
1029
    {
1009
    public function has_overrides() {
Línea 1046... Línea 1026...
1046
     *   lowest sort order. If neither applies, leave the assign setting unchanged.
1026
     *   lowest sort order. If neither applies, leave the assign setting unchanged.
1047
     *
1027
     *
1048
     * @param int $userid The userid.
1028
     * @param int $userid The userid.
1049
     * @return stdClass The override
1029
     * @return stdClass The override
1050
     */
1030
     */
1051
    public function override_exists($userid)
1031
    public function override_exists($userid) {
1052
    {
-
 
1053
        global $DB;
1032
        global $DB;
Línea 1054... Línea 1033...
1054
 
1033
 
1055
        // Gets an assoc array containing the keys for defined user overrides only.
1034
        // Gets an assoc array containing the keys for defined user overrides only.
1056
        $getuseroverride = function ($userid) use ($DB) {
1035
        $getuseroverride = function($userid) use ($DB) {
1057
            $useroverride = $DB->get_record('assign_overrides', ['assignid' => $this->get_instance()->id, 'userid' => $userid]);
1036
            $useroverride = $DB->get_record('assign_overrides', ['assignid' => $this->get_instance()->id, 'userid' => $userid]);
1058
            return $useroverride ? get_object_vars($useroverride) : [];
1037
            return $useroverride ? get_object_vars($useroverride) : [];
Línea 1059... Línea 1038...
1059
        };
1038
        };
1060
 
1039
 
1061
        // Gets an assoc array containing the keys for defined group overrides only.
1040
        // Gets an assoc array containing the keys for defined group overrides only.
Línea 1062... Línea 1041...
1062
        $getgroupoverride = function ($userid) use ($DB) {
1041
        $getgroupoverride = function($userid) use ($DB) {
1063
            $groupings = groups_get_user_groups($this->get_instance()->course, $userid);
1042
            $groupings = groups_get_user_groups($this->get_instance()->course, $userid);
1064
 
1043
 
Línea 1090... Línea 1069...
1090
     * Check if the given calendar_event is either a user or group override
1069
     * Check if the given calendar_event is either a user or group override
1091
     * event.
1070
     * event.
1092
     *
1071
     *
1093
     * @return bool
1072
     * @return bool
1094
     */
1073
     */
1095
    public function is_override_calendar_event(\calendar_event $event)
1074
    public function is_override_calendar_event(\calendar_event $event) {
1096
    {
-
 
1097
        global $DB;
1075
        global $DB;
Línea 1098... Línea 1076...
1098
 
1076
 
1099
        if (!isset($event->modulename)) {
1077
        if (!isset($event->modulename)) {
1100
            return false;
1078
            return false;
Línea 1150... Línea 1128...
1150
     * be returned.
1128
     * be returned.
1151
     *
1129
     *
1152
     * @param calendar_event $event The calendar event to get the time range for
1130
     * @param calendar_event $event The calendar event to get the time range for
1153
     * @return array
1131
     * @return array
1154
     */
1132
     */
1155
    function get_valid_calendar_event_timestart_range(\calendar_event $event)
1133
    function get_valid_calendar_event_timestart_range(\calendar_event $event) {
1156
    {
-
 
1157
        $instance = $this->get_instance();
1134
        $instance = $this->get_instance();
1158
        $submissionsfromdate = $instance->allowsubmissionsfromdate;
1135
        $submissionsfromdate = $instance->allowsubmissionsfromdate;
1159
        $cutoffdate = $instance->cutoffdate;
1136
        $cutoffdate = $instance->cutoffdate;
1160
        $duedate = $instance->duedate;
1137
        $duedate = $instance->duedate;
1161
        $gradingduedate = $instance->gradingduedate;
1138
        $gradingduedate = $instance->gradingduedate;
Línea 1219... Línea 1196...
1219
     * assignment submissions for course $data->courseid.
1196
     * assignment submissions for course $data->courseid.
1220
     *
1197
     *
1221
     * @param stdClass $data the data submitted from the reset course.
1198
     * @param stdClass $data the data submitted from the reset course.
1222
     * @return array status array
1199
     * @return array status array
1223
     */
1200
     */
1224
    public function reset_userdata($data)
1201
    public function reset_userdata($data) {
1225
    {
-
 
1226
        global $CFG, $DB;
1202
        global $CFG, $DB;
Línea 1227... Línea 1203...
1227
 
1203
 
1228
        $componentstr = get_string('modulenameplural', 'assign');
1204
        $componentstr = get_string('modulenameplural', 'assign');
Línea 1229... Línea 1205...
1229
        $status = array();
1205
        $status = [];
1230
 
1206
 
1231
        $fs = get_file_storage();
1207
        $fs = get_file_storage();
1232
        if (!empty($data->reset_assign_submissions)) {
1208
        if (!empty($data->reset_assign_submissions)) {
1233
            // Delete files associated with this assignment.
1209
            // Delete files associated with this assignment.
1234
            foreach ($this->submissionplugins as $plugin) {
1210
            foreach ($this->submissionplugins as $plugin) {
1235
                $fileareas = array();
1211
                $fileareas = [];
1236
                $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
1212
                $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
1237
                $fileareas = $plugin->get_file_areas();
1213
                $fileareas = $plugin->get_file_areas();
1238
                foreach ($fileareas as $filearea => $notused) {
1214
                foreach ($fileareas as $filearea => $notused) {
Línea 1239... Línea 1215...
1239
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1215
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1240
                }
1216
                }
1241
 
1217
 
1242
                if (!$plugin->delete_instance()) {
1218
                if (!$plugin->delete_instance()) {
1243
                    $status[] = array(
1219
                    $status[] = [
1244
                        'component' => $componentstr,
1220
                        'component' => $componentstr,
1245
                        'item' => get_string('deleteallsubmissions', 'assign'),
1221
                        'item' => get_string('deleteallsubmissions', 'assign'),
1246
                        'error' => $plugin->get_error()
1222
                        'error' => $plugin->get_error(),
Línea 1247... Línea 1223...
1247
                    );
1223
                    ];
1248
                }
1224
                }
Línea 1255... Línea 1231...
1255
                foreach ($fileareas as $filearea => $notused) {
1231
                foreach ($fileareas as $filearea => $notused) {
1256
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1232
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1257
                }
1233
                }
Línea 1258... Línea 1234...
1258
 
1234
 
1259
                if (!$plugin->delete_instance()) {
1235
                if (!$plugin->delete_instance()) {
1260
                    $status[] = array(
1236
                    $status[] = [
1261
                        'component' => $componentstr,
1237
                        'component' => $componentstr,
1262
                        'item' => get_string('deleteallsubmissions', 'assign'),
1238
                        'item ' => get_string('deleteallsubmissions', 'assign'),
1263
                        'error' => $plugin->get_error()
1239
                        'error' => $plugin->get_error(),
1264
                    );
1240
                    ];
1265
                }
1241
                }
Línea 1266... Línea 1242...
1266
            }
1242
            }
1267
 
1243
 
Línea 1268... Línea 1244...
1268
            $assignids = $DB->get_records('assign', array('course' => $data->courseid), '', 'id');
1244
            $assignids = $DB->get_records('assign', ['course' => $data->courseid], '', 'id');
1269
            list($sql, $params) = $DB->get_in_or_equal(array_keys($assignids));
1245
            list($sql, $params) = $DB->get_in_or_equal(array_keys($assignids));
Línea 1270... Línea 1246...
1270
 
1246
 
1271
            $DB->delete_records_select('assign_submission', "assignment $sql", $params);
1247
            $DB->delete_records_select('assign_submission', "assignment $sql", $params);
1272
            $DB->delete_records_select('assign_user_flags', "assignment $sql", $params);
1248
            $DB->delete_records_select('assign_user_flags', "assignment $sql", $params);
1273
 
1249
 
1274
            $status[] = array(
1250
            $status[] = [
Línea 1275... Línea 1251...
1275
                'component' => $componentstr,
1251
                'component' => $componentstr,
1276
                'item' => get_string('deleteallsubmissions', 'assign'),
1252
                'item' => get_string('deleteallsubmissions', 'assign'),
1277
                'error' => false
1253
                'error' => false,
1278
            );
1254
            ];
1279
 
1255
 
1280
            if (!empty($data->reset_gradebook_grades)) {
1256
            if (!empty($data->reset_gradebook_grades)) {
Línea 1281... Línea 1257...
1281
                $DB->delete_records_select('assign_grades', "assignment $sql", $params);
1257
                $DB->delete_records_select('assign_grades', "assignment $sql", $params);
1282
                // Remove all grades from gradebook.
1258
                // Remove all grades from gradebook.
1283
                require_once($CFG->dirroot . '/mod/assign/lib.php');
1259
                require_once($CFG->dirroot . '/mod/assign/lib.php');
1284
                assign_reset_gradebook($data->courseid);
1260
                assign_reset_gradebook($data->courseid);
1285
            }
1261
            }
Línea 1286... Línea 1262...
1286
 
1262
 
Línea 1287... Línea 1263...
1287
            // Reset revealidentities for assign if blindmarking is enabled.
1263
            // Reset revealidentities for assign if blindmarking is enabled.
1288
            if ($this->get_instance()->blindmarking) {
1264
            if ($this->get_instance()->blindmarking) {
1289
                $DB->set_field('assign', 'revealidentities', 0, array('id' => $this->get_instance()->id));
1265
                $DB->set_field('assign', 'revealidentities', 0, ['id' => $this->get_instance()->id]);
1290
            }
-
 
1291
        }
1266
            }
1292
 
-
 
1293
        $purgeoverrides = false;
-
 
1294
 
1267
        }
1295
        // Remove user overrides.
1268
 
1296
        if (!empty($data->reset_assign_user_overrides)) {
1269
        $purgeoverrides = false;
1297
            $DB->delete_records_select(
1270
 
1298
                'assign_overrides',
1271
        // Remove user overrides.
1299
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND userid IS NOT NULL',
1272
        if (!empty($data->reset_assign_user_overrides)) {
1300
                array($data->courseid)
1273
            $DB->delete_records_select('assign_overrides',
1301
            );
1274
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND userid IS NOT NULL', [$data->courseid]);
1302
            $status[] = array(
1275
            $status[] = [
1303
                'component' => $componentstr,
1276
                'component' => $componentstr,
1304
                'item' => get_string('useroverridesdeleted', 'assign'),
-
 
1305
                'error' => false
1277
                'item' => get_string('useroverrides', 'assign'),
1306
            );
-
 
1307
            $purgeoverrides = true;
-
 
1308
        }
1278
                'error' => false,
1309
        // Remove group overrides.
1279
            ];
1310
        if (!empty($data->reset_assign_group_overrides)) {
1280
            $purgeoverrides = true;
1311
            $DB->delete_records_select(
1281
        }
1312
                'assign_overrides',
1282
        // Remove group overrides.
1313
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND groupid IS NOT NULL',
1283
        if (!empty($data->reset_assign_group_overrides)) {
1314
                array($data->courseid)
1284
            $DB->delete_records_select('assign_overrides',
Línea 1315... Línea 1285...
1315
            );
1285
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND groupid IS NOT NULL', [$data->courseid]);
1316
            $status[] = array(
1286
            $status[] = [
-
 
1287
                'component' => $componentstr,
-
 
1288
                'item' => get_string('groupoverrides', 'assign'),
-
 
1289
                'error' => false,
1317
                'component' => $componentstr,
1290
            ];
1318
                'item' => get_string('groupoverridesdeleted', 'assign'),
1291
            $purgeoverrides = true;
1319
                'error' => false
-
 
1320
            );
-
 
1321
            $purgeoverrides = true;
1292
        }
1322
        }
1293
 
-
 
1294
        // Updating dates - shift may be negative too.
-
 
1295
        if ($data->timeshift) {
-
 
1296
            $sql = "UPDATE {assign_overrides}
1323
 
1297
                       SET allowsubmissionsfromdate = allowsubmissionsfromdate + ?
1324
        // Updating dates - shift may be negative too.
1298
                     WHERE assignid = ? AND allowsubmissionsfromdate <> 0";
1325
        if ($data->timeshift) {
-
 
1326
            $DB->execute(
-
 
1327
                "UPDATE {assign_overrides}
1299
            $DB->execute(
1328
                         SET allowsubmissionsfromdate = allowsubmissionsfromdate + ?
1300
                $sql,
-
 
1301
                [$data->timeshift, $this->get_instance()->id],
-
 
1302
            );
-
 
1303
            $sql = "UPDATE {assign_overrides}
1329
                       WHERE assignid = ? AND allowsubmissionsfromdate <> 0",
1304
                       SET duedate = duedate + ?
1330
                array($data->timeshift, $this->get_instance()->id)
1305
                     WHERE assignid = ? AND duedate <> 0";
1331
            );
-
 
1332
            $DB->execute(
-
 
1333
                "UPDATE {assign_overrides}
1306
            $DB->execute(
1334
                         SET duedate = duedate + ?
1307
                $sql,
Línea 1335... Línea 1308...
1335
                       WHERE assignid = ? AND duedate <> 0",
1308
                [$data->timeshift, $this->get_instance()->id],
Línea 1336... Línea 1309...
1336
                array($data->timeshift, $this->get_instance()->id)
1309
            );
1337
            );
1310
            $sql = "UPDATE {assign_overrides}
1338
            $DB->execute(
1311
                       SET cutoffdate = cutoffdate + ?
1339
                "UPDATE {assign_overrides}
1312
                     WHERE assignid =? AND cutoffdate <> 0";
1340
                         SET cutoffdate = cutoffdate + ?
1313
            $DB->execute(
1341
                       WHERE assignid =? AND cutoffdate <> 0",
1314
                $sql,
1342
                array($data->timeshift, $this->get_instance()->id)
1315
                [$data->timeshift, $this->get_instance()->id],
1343
            );
1316
            );
1344
 
1317
 
1345
            $purgeoverrides = true;
1318
            $purgeoverrides = true;
1346
 
1319
 
1347
            // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
1320
            // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
1348
            // See MDL-9367.
1321
            // See MDL-9367.
1349
            shift_course_mod_dates(
1322
            shift_course_mod_dates('assign', [
1350
                'assign',
1323
                'allowsubmissionsfromdate',
Línea 1351... Línea 1324...
1351
                array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'),
1324
                'duedate',
1352
                $data->timeshift,
1325
                'cutoffdate',
1353
                $data->courseid,
1326
                'gradingduedate',
Línea 1372... Línea 1345...
1372
     *
1345
     *
1373
     * @param assign_plugin $plugin The plugin to update
1346
     * @param assign_plugin $plugin The plugin to update
1374
     * @param stdClass $formdata The form data
1347
     * @param stdClass $formdata The form data
1375
     * @return bool false if an error occurs
1348
     * @return bool false if an error occurs
1376
     */
1349
     */
1377
    protected function update_plugin_instance(assign_plugin $plugin, stdClass $formdata)
1350
    protected function update_plugin_instance(assign_plugin $plugin, stdClass $formdata) {
1378
    {
-
 
1379
        if ($plugin->is_visible()) {
1351
        if ($plugin->is_visible()) {
1380
            $enabledname = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1352
            $enabledname = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1381
            if (!empty($formdata->$enabledname)) {
1353
            if (!empty($formdata->$enabledname)) {
1382
                $plugin->enable();
1354
                $plugin->enable();
1383
                if (!$plugin->save_settings($formdata)) {
1355
                if (!$plugin->save_settings($formdata)) {
Línea 1396... Línea 1368...
1396
     *
1368
     *
1397
     * @param bool $reset If true, will reset all grades in the gradbook for this assignment
1369
     * @param bool $reset If true, will reset all grades in the gradbook for this assignment
1398
     * @param int $coursemoduleid This is required because it might not exist in the database yet
1370
     * @param int $coursemoduleid This is required because it might not exist in the database yet
1399
     * @return bool
1371
     * @return bool
1400
     */
1372
     */
1401
    public function update_gradebook($reset, $coursemoduleid)
1373
    public function update_gradebook($reset, $coursemoduleid) {
1402
    {
-
 
1403
        global $CFG;
1374
        global $CFG;
Línea 1404... Línea 1375...
1404
 
1375
 
1405
        require_once($CFG->dirroot . '/mod/assign/lib.php');
1376
        require_once($CFG->dirroot.'/mod/assign/lib.php');
1406
        $assign = clone $this->get_instance();
1377
        $assign = clone $this->get_instance();
Línea 1407... Línea 1378...
1407
        $assign->cmidnumber = $coursemoduleid;
1378
        $assign->cmidnumber = $coursemoduleid;
1408
 
1379
 
Línea 1420... Línea 1391...
1420
    /**
1391
    /**
1421
     * Get the marking table page size
1392
     * Get the marking table page size
1422
     *
1393
     *
1423
     * @return integer
1394
     * @return integer
1424
     */
1395
     */
1425
    public function get_assign_perpage()
1396
    public function get_assign_perpage() {
1426
    {
-
 
1427
        $perpage = (int) get_user_preferences('assign_perpage', 10);
1397
        $perpage = (int) get_user_preferences('assign_perpage', 10);
1428
        $adminconfig = $this->get_admin_config();
1398
        $adminconfig = $this->get_admin_config();
1429
        $maxperpage = -1;
1399
        $maxperpage = -1;
1430
        if (isset($adminconfig->maxperpage)) {
1400
        if (isset($adminconfig->maxperpage)) {
1431
            $maxperpage = $adminconfig->maxperpage;
1401
            $maxperpage = $adminconfig->maxperpage;
1432
        }
1402
        }
1433
        if (
-
 
1434
            isset($maxperpage) &&
1403
        if (isset($maxperpage) &&
1435
            $maxperpage != -1 &&
1404
            $maxperpage != -1 &&
1436
            ($perpage == -1 || $perpage > $maxperpage)
1405
            ($perpage == -1 || $perpage > $maxperpage)) {
1437
        ) {
-
 
1438
            $perpage = $maxperpage;
1406
            $perpage = $maxperpage;
1439
        }
1407
        }
1440
        return $perpage;
1408
        return $perpage;
1441
    }
1409
    }
Línea 1442... Línea 1410...
1442
 
1410
 
1443
    /**
1411
    /**
1444
     * Load and cache the admin config for this module.
1412
     * Load and cache the admin config for this module.
1445
     *
1413
     *
1446
     * @return stdClass the plugin config
1414
     * @return stdClass the plugin config
1447
     */
1415
     */
1448
    public function get_admin_config()
-
 
1449
    {
1416
    public function get_admin_config() {
1450
        if ($this->adminconfig) {
1417
        if ($this->adminconfig) {
1451
            return $this->adminconfig;
1418
            return $this->adminconfig;
1452
        }
1419
        }
1453
        $this->adminconfig = get_config('assign');
1420
        $this->adminconfig = get_config('assign');
Línea 1459... Línea 1426...
1459
     *
1426
     *
1460
     * @param int $coursemoduleid - Required to pass this in because it might
1427
     * @param int $coursemoduleid - Required to pass this in because it might
1461
     *                              not exist in the database yet.
1428
     *                              not exist in the database yet.
1462
     * @return bool
1429
     * @return bool
1463
     */
1430
     */
1464
    public function update_calendar($coursemoduleid)
1431
    public function update_calendar($coursemoduleid) {
1465
    {
-
 
1466
        global $DB, $CFG;
1432
        global $DB, $CFG;
1467
        require_once($CFG->dirroot . '/calendar/lib.php');
1433
        require_once($CFG->dirroot.'/calendar/lib.php');
Línea 1468... Línea 1434...
1468
 
1434
 
1469
        // Special case for add_instance as the coursemodule has not been set yet.
1435
        // Special case for add_instance as the coursemodule has not been set yet.
Línea 1470... Línea 1436...
1470
        $instance = $this->get_instance();
1436
        $instance = $this->get_instance();
Línea 1520... Línea 1486...
1520
                $calendarevent->update($event, false);
1486
                $calendarevent->update($event, false);
1521
            } else {
1487
            } else {
1522
                calendar_event::create($event, false);
1488
                calendar_event::create($event, false);
1523
            }
1489
            }
1524
        } else {
1490
        } else {
1525
            $DB->delete_records('event', array(
1491
            $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
1526
                'modulename' => 'assign',
-
 
1527
                'instance' => $instance->id,
-
 
1528
                'eventtype' => $eventtype
1492
                'eventtype' => $eventtype));
1529
            ));
-
 
1530
        }
1493
        }
Línea 1531... Línea 1494...
1531
 
1494
 
1532
        $eventtype = ASSIGN_EVENT_TYPE_GRADINGDUE;
1495
        $eventtype = ASSIGN_EVENT_TYPE_GRADINGDUE;
1533
        if ($instance->gradingduedate) {
1496
        if ($instance->gradingduedate) {
1534
            $event->name = get_string('calendargradingdue', 'assign', $instance->name);
1497
            $event->name = get_string('calendargradingdue', 'assign', $instance->name);
1535
            $event->eventtype = $eventtype;
1498
            $event->eventtype = $eventtype;
1536
            $event->timestart = $instance->gradingduedate;
1499
            $event->timestart = $instance->gradingduedate;
1537
            $event->timesort = $instance->gradingduedate;
1500
            $event->timesort = $instance->gradingduedate;
1538
            $event->id = $DB->get_field('event', 'id', array(
-
 
1539
                'modulename' => 'assign',
-
 
1540
                'instance' => $instance->id,
1501
            $event->id = $DB->get_field('event', 'id', array('modulename' => 'assign',
1541
                'eventtype' => $event->eventtype
-
 
Línea 1542... Línea 1502...
1542
            ));
1502
                'instance' => $instance->id, 'eventtype' => $event->eventtype));
1543
 
1503
 
1544
            // Now process the event.
1504
            // Now process the event.
1545
            if ($event->id) {
1505
            if ($event->id) {
1546
                $calendarevent = calendar_event::load($event->id);
1506
                $calendarevent = calendar_event::load($event->id);
1547
                $calendarevent->update($event, false);
1507
                $calendarevent->update($event, false);
1548
            } else {
1508
            } else {
1549
                calendar_event::create($event, false);
1509
                calendar_event::create($event, false);
1550
            }
1510
            }
1551
        } else {
-
 
1552
            $DB->delete_records('event', array(
-
 
1553
                'modulename' => 'assign',
1511
        } else {
1554
                'instance' => $instance->id,
-
 
1555
                'eventtype' => $eventtype
1512
            $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
Línea 1556... Línea 1513...
1556
            ));
1513
                'eventtype' => $eventtype));
1557
        }
1514
        }
Línea 1563... Línea 1520...
1563
     * Update this instance in the database.
1520
     * Update this instance in the database.
1564
     *
1521
     *
1565
     * @param stdClass $formdata - the data submitted from the form
1522
     * @param stdClass $formdata - the data submitted from the form
1566
     * @return bool false if an error occurs
1523
     * @return bool false if an error occurs
1567
     */
1524
     */
1568
    public function update_instance($formdata)
1525
    public function update_instance($formdata) {
1569
    {
-
 
1570
        global $DB;
1526
        global $DB;
1571
        $adminconfig = $this->get_admin_config();
1527
        $adminconfig = $this->get_admin_config();
Línea 1572... Línea 1528...
1572
 
1528
 
1573
        $update = new stdClass();
1529
        $update = new stdClass();
Línea 1611... Línea 1567...
1611
        }
1567
        }
1612
        if (isset($formdata->hidegrader)) {
1568
        if (isset($formdata->hidegrader)) {
1613
            $update->hidegrader = $formdata->hidegrader;
1569
            $update->hidegrader = $formdata->hidegrader;
1614
        }
1570
        }
1615
        $update->blindmarking = $formdata->blindmarking;
1571
        $update->blindmarking = $formdata->blindmarking;
1616
        $update->attemptreopenmethod = ASSIGN_ATTEMPT_REOPEN_METHOD_NONE;
-
 
1617
        if (!empty($formdata->attemptreopenmethod)) {
1572
        $update->maxattempts = $formdata->maxattempts ?? 1;
1618
            $update->attemptreopenmethod = $formdata->attemptreopenmethod;
1573
        $update->attemptreopenmethod = $formdata->attemptreopenmethod ?? ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS;
1619
        }
-
 
1620
        if (!empty($formdata->maxattempts)) {
-
 
1621
            $update->maxattempts = $formdata->maxattempts;
-
 
1622
        }
-
 
1623
        if (isset($formdata->preventsubmissionnotingroup)) {
1574
        if (isset($formdata->preventsubmissionnotingroup)) {
1624
            $update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
1575
            $update->preventsubmissionnotingroup = $formdata->preventsubmissionnotingroup;
1625
        }
1576
        }
1626
        $update->markingworkflow = $formdata->markingworkflow;
1577
        $update->markingworkflow = $formdata->markingworkflow;
1627
        $update->markingallocation = $formdata->markingallocation;
1578
        $update->markingallocation = $formdata->markingallocation;
Línea 1632... Línea 1583...
1632
        // If marking workflow is disabled, or blindmarking is disabled then make sure marking anonymous is disabled.
1583
        // If marking workflow is disabled, or blindmarking is disabled then make sure marking anonymous is disabled.
1633
        if (empty($update->markingworkflow) || empty($update->blindmarking)) {
1584
        if (empty($update->markingworkflow) || empty($update->blindmarking)) {
1634
            $update->markinganonymous = 0;
1585
            $update->markinganonymous = 0;
1635
        }
1586
        }
Línea -... Línea 1587...
-
 
1587
 
-
 
1588
        // Grade penalties.
-
 
1589
        $update->gradepenalty = $formdata->gradepenalty ?? 0;
1636
 
1590
 
1637
        $result = $DB->update_record('assign', $update);
1591
        $result = $DB->update_record('assign', $update);
Línea 1638... Línea 1592...
1638
        $this->instance = $DB->get_record('assign', array('id' => $update->id), '*', MUST_EXIST);
1592
        $this->instance = $DB->get_record('assign', array('id'=>$update->id), '*', MUST_EXIST);
Línea 1639... Línea 1593...
1639
 
1593
 
Línea 1655... Línea 1609...
1655
            }
1609
            }
1656
        }
1610
        }
Línea 1657... Línea 1611...
1657
 
1611
 
1658
        $this->update_calendar($this->get_course_module()->id);
1612
        $this->update_calendar($this->get_course_module()->id);
1659
        $completionexpected = (!empty($formdata->completionexpected)) ? $formdata->completionexpected : null;
1613
        $completionexpected = (!empty($formdata->completionexpected)) ? $formdata->completionexpected : null;
1660
        \core_completion\api::update_completion_date_event(
-
 
1661
            $this->get_course_module()->id,
-
 
1662
            'assign',
-
 
1663
            $this->instance,
1614
        \core_completion\api::update_completion_date_event($this->get_course_module()->id, 'assign', $this->instance,
1664
            $completionexpected
-
 
1665
        );
1615
                $completionexpected);
Línea 1666... Línea 1616...
1666
        $this->update_gradebook(false, $this->get_course_module()->id);
1616
        $this->update_gradebook(false, $this->get_course_module()->id);
1667
 
1617
 
1668
        $update = new stdClass();
1618
        $update = new stdClass();
1669
        $update->id = $this->get_instance()->id;
1619
        $update->id = $this->get_instance()->id;
Línea -... Línea 1620...
-
 
1620
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1: 0;
-
 
1621
        $DB->update_record('assign', $update);
-
 
1622
 
-
 
1623
        // Check if we need to recalculate penalty for existing grades.
-
 
1624
        if (!empty($formdata->recalculatepenalty) && $formdata->recalculatepenalty === 'yes') {
-
 
1625
            $assign = clone $this->get_instance();
-
 
1626
            $assign->cmidnumber = $this->get_course_module()->idnumber;
1670
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1 : 0;
1627
            assign_update_grades($assign);
1671
        $DB->update_record('assign', $update);
1628
        }
Línea 1672... Línea 1629...
1672
 
1629
 
1673
        return $result;
1630
        return $result;
1674
    }
1631
    }
1675
 
1632
 
1676
    /**
1633
    /**
1677
     * Save the attachments in the intro description.
1634
     * Save the attachments in the intro description.
1678
     *
-
 
1679
     * @param stdClass $formdata
1635
     *
1680
     */
-
 
1681
    protected function save_intro_draft_files($formdata)
1636
     * @param stdClass $formdata
1682
    {
-
 
1683
        if (isset($formdata->introattachments)) {
-
 
1684
            file_save_draft_area_files(
1637
     */
1685
                $formdata->introattachments,
-
 
1686
                $this->get_context()->id,
-
 
1687
                'mod_assign',
1638
    protected function save_intro_draft_files($formdata) {
1688
                ASSIGN_INTROATTACHMENT_FILEAREA,
1639
        if (isset($formdata->introattachments)) {
Línea 1689... Línea 1640...
1689
                0
1640
            file_save_draft_area_files($formdata->introattachments, $this->get_context()->id,
1690
            );
1641
                                       'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
1691
        }
1642
        }
1692
    }
1643
    }
1693
 
1644
 
1694
    /**
1645
    /**
1695
     * Save the attachments in the editor description.
-
 
1696
     *
1646
     * Save the attachments in the editor description.
1697
     * @param stdClass $formdata
1647
     *
1698
     */
1648
     * @param stdClass $formdata
1699
    protected function save_editor_draft_files($formdata): string
1649
     */
1700
    {
-
 
1701
        $text = '';
1650
    protected function save_editor_draft_files($formdata): string {
1702
        if (isset($formdata->activityeditor)) {
-
 
1703
            $text = $formdata->activityeditor['text'];
-
 
1704
            if (isset($formdata->activityeditor['itemid'])) {
1651
        $text = '';
1705
                $text = file_save_draft_area_files(
-
 
1706
                    $formdata->activityeditor['itemid'],
-
 
1707
                    $this->get_context()->id,
1652
        if (isset($formdata->activityeditor)) {
1708
                    'mod_assign',
-
 
1709
                    ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
1653
            $text = $formdata->activityeditor['text'];
1710
                    0,
1654
            if (isset($formdata->activityeditor['itemid'])) {
1711
                    array('subdirs' => true),
1655
                $text = file_save_draft_area_files($formdata->activityeditor['itemid'], $this->get_context()->id,
1712
                    $formdata->activityeditor['text']
1656
                    'mod_assign', ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
Línea 1724... Línea 1668...
1724
     * @param MoodleQuickForm $mform
1668
     * @param MoodleQuickForm $mform
1725
     * @param stdClass $data
1669
     * @param stdClass $data
1726
     * @param int $userid - The userid we are grading
1670
     * @param int $userid - The userid we are grading
1727
     * @return void
1671
     * @return void
1728
     */
1672
     */
1729
    protected function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid)
1673
    protected function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
1730
    {
-
 
1731
        foreach ($this->feedbackplugins as $plugin) {
1674
        foreach ($this->feedbackplugins as $plugin) {
1732
            if ($plugin->is_enabled() && $plugin->is_visible()) {
1675
            if ($plugin->is_enabled() && $plugin->is_visible()) {
1733
                $plugin->get_form_elements_for_user($grade, $mform, $data, $userid);
1676
                $plugin->get_form_elements_for_user($grade, $mform, $data, $userid);
1734
            }
1677
            }
1735
        }
1678
        }
Línea 1745... Línea 1688...
1745
     *                               This form is modified directly (not returned).
1688
     *                               This form is modified directly (not returned).
1746
     * @param array $pluginsenabled A list of form elements to be added to a group.
1689
     * @param array $pluginsenabled A list of form elements to be added to a group.
1747
     *                              The new element is added to this array by this function.
1690
     *                              The new element is added to this array by this function.
1748
     * @return void
1691
     * @return void
1749
     */
1692
     */
1750
    protected function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, &$pluginsenabled)
1693
    protected function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, & $pluginsenabled) {
1751
    {
-
 
1752
        global $CFG;
1694
        global $CFG;
1753
        if ($plugin->is_visible() && !$plugin->is_configurable() && $plugin->is_enabled()) {
1695
        if ($plugin->is_visible() && !$plugin->is_configurable() && $plugin->is_enabled()) {
1754
            $name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1696
            $name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1755
            $pluginsenabled[] = $mform->createElement('hidden', $name, 1);
1697
            $pluginsenabled[] = $mform->createElement('hidden', $name, 1);
1756
            $mform->setType($name, PARAM_BOOL);
1698
            $mform->setType($name, PARAM_BOOL);
Línea 1767... Línea 1709...
1767
                $default = $plugin->is_enabled();
1709
                $default = $plugin->is_enabled();
1768
            }
1710
            }
1769
            $mform->setDefault($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', $default);
1711
            $mform->setDefault($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', $default);
Línea 1770... Línea 1712...
1770
 
1712
 
-
 
1713
            $plugin->get_settings($mform);
1771
            $plugin->get_settings($mform);
1714
 
1772
        }
1715
        }
Línea 1773... Línea 1716...
1773
    }
1716
    }
1774
 
1717
 
1775
    /**
1718
    /**
1776
     * Add settings to edit plugin form.
1719
     * Add settings to edit plugin form.
1777
     *
1720
     *
1778
     * @param MoodleQuickForm $mform The form to add the configuration settings to.
1721
     * @param MoodleQuickForm $mform The form to add the configuration settings to.
1779
     *                               This form is modified directly (not returned).
1722
     *                               This form is modified directly (not returned).
1780
     * @return void
1723
     * @return void
1781
     */
-
 
1782
    public function add_all_plugin_settings(MoodleQuickForm $mform)
1724
     */
Línea 1783... Línea 1725...
1783
    {
1725
    public function add_all_plugin_settings(MoodleQuickForm $mform) {
1784
        $mform->addElement('header', 'submissiontypes', get_string('submissiontypes', 'assign'));
1726
        $mform->addElement('header', 'submissiontypes', get_string('submissiontypes', 'assign'));
1785
 
1727
 
Línea 1805... Línea 1747...
1805
     * passed in to the settings form (needed to set up draft areas for
1747
     * passed in to the settings form (needed to set up draft areas for
1806
     * editor and filemanager elements)
1748
     * editor and filemanager elements)
1807
     *
1749
     *
1808
     * @param array $defaultvalues
1750
     * @param array $defaultvalues
1809
     */
1751
     */
1810
    public function plugin_data_preprocessing(&$defaultvalues)
1752
    public function plugin_data_preprocessing(&$defaultvalues) {
1811
    {
-
 
1812
        foreach ($this->submissionplugins as $plugin) {
1753
        foreach ($this->submissionplugins as $plugin) {
1813
            if ($plugin->is_visible()) {
1754
            if ($plugin->is_visible()) {
1814
                $plugin->data_preprocessing($defaultvalues);
1755
                $plugin->data_preprocessing($defaultvalues);
1815
            }
1756
            }
1816
        }
1757
        }
Línea 1820... Línea 1761...
1820
            }
1761
            }
1821
        }
1762
        }
1822
    }
1763
    }
Línea 1823... Línea 1764...
1823
 
1764
 
-
 
1765
    /**
-
 
1766
     * Allow each plugin to validiate the data from the assignments settings form.
-
 
1767
     *
-
 
1768
     * @param array $data as passed to mod_assign_mod_form::validation().
-
 
1769
     * @param array $files as passed to mod_assign_mod_form::validation().
-
 
1770
     * @return array and validation errors that should be displayed.
-
 
1771
     */
-
 
1772
    public function plugin_settings_validation(array $data, array $files): array {
-
 
1773
        $errors = [];
-
 
1774
 
-
 
1775
        foreach ($this->submissionplugins as $plugin) {
-
 
1776
            if ($plugin->is_visible()) {
-
 
1777
                $errors = array_merge($errors, $plugin->settings_validation($data, $files));
-
 
1778
            }
-
 
1779
        }
-
 
1780
 
-
 
1781
        foreach ($this->feedbackplugins as $plugin) {
-
 
1782
            if ($plugin->is_visible()) {
-
 
1783
                $errors = array_merge($errors, $plugin->settings_validation($data, $files));
-
 
1784
            }
-
 
1785
        }
-
 
1786
 
-
 
1787
        return $errors;
-
 
1788
    }
-
 
1789
 
1824
    /**
1790
    /**
1825
     * Get the name of the current module.
1791
     * Get the name of the current module.
1826
     *
1792
     *
1827
     * @return string the module name (Assignment)
1793
     * @return string the module name (Assignment)
1828
     */
1794
     */
1829
    protected function get_module_name()
-
 
1830
    {
1795
    protected function get_module_name() {
1831
        if (isset(self::$modulename)) {
1796
        if (isset(self::$modulename)) {
1832
            return self::$modulename;
1797
            return self::$modulename;
1833
        }
1798
        }
1834
        self::$modulename = get_string('modulename', 'assign');
1799
        self::$modulename = get_string('modulename', 'assign');
Línea 1838... Línea 1803...
1838
    /**
1803
    /**
1839
     * Get the plural name of the current module.
1804
     * Get the plural name of the current module.
1840
     *
1805
     *
1841
     * @return string the module name plural (Assignments)
1806
     * @return string the module name plural (Assignments)
1842
     */
1807
     */
1843
    protected function get_module_name_plural()
1808
    protected function get_module_name_plural() {
1844
    {
-
 
1845
        if (isset(self::$modulenameplural)) {
1809
        if (isset(self::$modulenameplural)) {
1846
            return self::$modulenameplural;
1810
            return self::$modulenameplural;
1847
        }
1811
        }
1848
        self::$modulenameplural = get_string('modulenameplural', 'assign');
1812
        self::$modulenameplural = get_string('modulenameplural', 'assign');
1849
        return self::$modulenameplural;
1813
        return self::$modulenameplural;
Línea 1852... Línea 1816...
1852
    /**
1816
    /**
1853
     * Has this assignment been constructed from an instance?
1817
     * Has this assignment been constructed from an instance?
1854
     *
1818
     *
1855
     * @return bool
1819
     * @return bool
1856
     */
1820
     */
1857
    public function has_instance()
1821
    public function has_instance() {
1858
    {
-
 
1859
        return $this->instance || $this->get_course_module();
1822
        return $this->instance || $this->get_course_module();
1860
    }
1823
    }
Línea 1861... Línea 1824...
1861
 
1824
 
1862
    /**
1825
    /**
1863
     * Get the settings for the current instance of this assignment.
1826
     * Get the settings for the current instance of this assignment.
1864
     *
1827
     *
1865
     * @return stdClass The settings
1828
     * @return stdClass The settings
1866
     * @throws dml_exception
1829
     * @throws dml_exception
1867
     */
1830
     */
1868
    public function get_default_instance()
-
 
1869
    {
1831
    public function get_default_instance() {
1870
        global $DB;
1832
        global $DB;
1871
        if (!$this->instance && $this->get_course_module()) {
1833
        if (!$this->instance && $this->get_course_module()) {
1872
            $params = array('id' => $this->get_course_module()->instance);
1834
            $params = array('id' => $this->get_course_module()->instance);
Línea 1880... Línea 1842...
1880
    /**
1842
    /**
1881
     * Get the settings for the current instance of this assignment
1843
     * Get the settings for the current instance of this assignment
1882
     * @param int|null $userid the id of the user to load the assign instance for.
1844
     * @param int|null $userid the id of the user to load the assign instance for.
1883
     * @return stdClass The settings
1845
     * @return stdClass The settings
1884
     */
1846
     */
1885
    public function get_instance(int $userid = null): stdClass
1847
    public function get_instance(?int $userid = null): stdClass {
1886
    {
-
 
1887
        global $USER;
1848
        global $USER;
1888
        $userid = $userid ?? $USER->id;
1849
        $userid = $userid ?? $USER->id;
Línea 1889... Línea 1850...
1889
 
1850
 
Línea 1904... Línea 1865...
1904
     *
1865
     *
1905
     * @param stdClass $record the raw assign record.
1866
     * @param stdClass $record the raw assign record.
1906
     * @param int $userid the id of the user to calculate the properties for.
1867
     * @param int $userid the id of the user to calculate the properties for.
1907
     * @return stdClass a new record having calculated properties.
1868
     * @return stdClass a new record having calculated properties.
1908
     */
1869
     */
1909
    private function calculate_properties(\stdClass $record, int $userid): \stdClass
1870
    private function calculate_properties(\stdClass $record, int $userid): \stdClass {
1910
    {
-
 
1911
        $record = clone ($record);
1871
        $record = clone ($record);
Línea 1912... Línea 1872...
1912
 
1872
 
1913
        // Relative dates.
1873
        // Relative dates.
1914
        if (!empty($record->duedate)) {
1874
        if (!empty($record->duedate)) {
Línea 1925... Línea 1885...
1925
    /**
1885
    /**
1926
     * Get the primary grade item for this assign instance.
1886
     * Get the primary grade item for this assign instance.
1927
     *
1887
     *
1928
     * @return grade_item The grade_item record
1888
     * @return grade_item The grade_item record
1929
     */
1889
     */
1930
    public function get_grade_item()
1890
    public function get_grade_item() {
1931
    {
-
 
1932
        if ($this->gradeitem) {
1891
        if ($this->gradeitem) {
1933
            return $this->gradeitem;
1892
            return $this->gradeitem;
1934
        }
1893
        }
1935
        $instance = $this->get_instance();
1894
        $instance = $this->get_instance();
1936
        $params = array(
-
 
1937
            'itemtype' => 'mod',
1895
        $params = array('itemtype' => 'mod',
1938
            'itemmodule' => 'assign',
1896
                        'itemmodule' => 'assign',
1939
            'iteminstance' => $instance->id,
1897
                        'iteminstance' => $instance->id,
1940
            'courseid' => $instance->course,
1898
                        'courseid' => $instance->course,
1941
            'itemnumber' => 0
1899
                        'itemnumber' => 0);
1942
        );
-
 
1943
        $this->gradeitem = grade_item::fetch($params);
1900
        $this->gradeitem = grade_item::fetch($params);
1944
        if (!$this->gradeitem) {
1901
        if (!$this->gradeitem) {
1945
            throw new coding_exception('Improper use of the assignment class. ' .
1902
            throw new coding_exception('Improper use of the assignment class. ' .
1946
                'Cannot load the grade item.');
1903
                                       'Cannot load the grade item.');
1947
        }
1904
        }
1948
        return $this->gradeitem;
1905
        return $this->gradeitem;
1949
    }
1906
    }
Línea 1950... Línea 1907...
1950
 
1907
 
1951
    /**
1908
    /**
1952
     * Get the context of the current course.
1909
     * Get the context of the current course.
1953
     *
1910
     *
1954
     * @return mixed context|null The course context
1911
     * @return mixed context|null The course context
1955
     */
1912
     */
1956
    public function get_course_context()
-
 
1957
    {
1913
    public function get_course_context() {
1958
        if (!$this->context && !$this->course) {
1914
        if (!$this->context && !$this->course) {
1959
            throw new coding_exception('Improper use of the assignment class. ' .
1915
            throw new coding_exception('Improper use of the assignment class. ' .
1960
                'Cannot load the course context.');
1916
                                       'Cannot load the course context.');
1961
        }
1917
        }
1962
        if ($this->context) {
1918
        if ($this->context) {
1963
            return $this->context->get_course_context();
1919
            return $this->context->get_course_context();
1964
        } else {
1920
        } else {
Línea 1970... Línea 1926...
1970
    /**
1926
    /**
1971
     * Get the current course module.
1927
     * Get the current course module.
1972
     *
1928
     *
1973
     * @return cm_info|null The course module or null if not known
1929
     * @return cm_info|null The course module or null if not known
1974
     */
1930
     */
1975
    public function get_course_module()
1931
    public function get_course_module() {
1976
    {
-
 
1977
        if ($this->coursemodule) {
1932
        if ($this->coursemodule) {
1978
            return $this->coursemodule;
1933
            return $this->coursemodule;
1979
        }
1934
        }
1980
        if (!$this->context) {
1935
        if (!$this->context) {
1981
            return null;
1936
            return null;
Línea 1992... Línea 1947...
1992
    /**
1947
    /**
1993
     * Get context module.
1948
     * Get context module.
1994
     *
1949
     *
1995
     * @return context
1950
     * @return context
1996
     */
1951
     */
1997
    public function get_context()
1952
    public function get_context() {
1998
    {
-
 
1999
        return $this->context;
1953
        return $this->context;
2000
    }
1954
    }
Línea 2001... Línea 1955...
2001
 
1955
 
2002
    /**
1956
    /**
2003
     * Get the current course.
1957
     * Get the current course.
2004
     *
1958
     *
2005
     * @return mixed stdClass|null The course
1959
     * @return mixed stdClass|null The course
2006
     */
1960
     */
2007
    public function get_course()
-
 
2008
    {
1961
    public function get_course() {
Línea 2009... Línea 1962...
2009
        global $DB;
1962
        global $DB;
2010
 
1963
 
2011
        if ($this->course && is_object($this->course)) {
1964
        if ($this->course && is_object($this->course)) {
Línea 2024... Línea 1977...
2024
    /**
1977
    /**
2025
     * Count the number of intro attachments.
1978
     * Count the number of intro attachments.
2026
     *
1979
     *
2027
     * @return int
1980
     * @return int
2028
     */
1981
     */
2029
    protected function count_attachments()
1982
    protected function count_attachments() {
2030
    {
-
 
Línea 2031... Línea 1983...
2031
 
1983
 
2032
        $fs = get_file_storage();
-
 
2033
        $files = $fs->get_area_files(
-
 
2034
            $this->get_context()->id,
-
 
2035
            'mod_assign',
1984
        $fs = get_file_storage();
2036
            ASSIGN_INTROATTACHMENT_FILEAREA,
-
 
2037
            0,
-
 
2038
            'id',
1985
        $files = $fs->get_area_files($this->get_context()->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA,
2039
            false
-
 
Línea 2040... Línea 1986...
2040
        );
1986
                        0, 'id', false);
2041
 
1987
 
Línea 2042... Línea 1988...
2042
        return count($files);
1988
        return count($files);
2043
    }
1989
    }
2044
 
1990
 
2045
    /**
1991
    /**
2046
     * Are there any intro attachments to display?
1992
     * Are there any intro attachments to display?
2047
     *
1993
     *
2048
     * @return boolean
-
 
2049
     */
1994
     * @return boolean
2050
    protected function has_visible_attachments()
1995
     */
Línea 2051... Línea 1996...
2051
    {
1996
    protected function has_visible_attachments() {
2052
        return ($this->count_attachments() > 0);
1997
        return ($this->count_attachments() > 0);
2053
    }
1998
    }
2054
 
1999
 
2055
    /**
2000
    /**
2056
     * Check if the intro attachments should be provided to the user.
2001
     * Check if the intro attachments should be provided to the user.
2057
     *
2002
     *
2058
     * @param int $userid User id.
-
 
2059
     * @return bool
2003
     * @param int $userid User id.
Línea 2060... Línea 2004...
2060
     */
2004
     * @return bool
2061
    public function should_provide_intro_attachments(int $userid): bool
2005
     */
2062
    {
2006
    public function should_provide_intro_attachments(int $userid): bool {
Línea 2085... Línea 2029...
2085
     *
2029
     *
2086
     * @param mixed $grade int|null
2030
     * @param mixed $grade int|null
2087
     * @param boolean $editing Are we allowing changes to this grade?
2031
     * @param boolean $editing Are we allowing changes to this grade?
2088
     * @param int $userid The user id the grade belongs to
2032
     * @param int $userid The user id the grade belongs to
2089
     * @param int $modified Timestamp from when the grade was last modified
2033
     * @param int $modified Timestamp from when the grade was last modified
-
 
2034
     * @param float $deductedmark The deducted mark if penalty is applied
2090
     * @return string User-friendly representation of grade
2035
     * @return string User-friendly representation of grade
2091
     */
2036
     */
2092
    public function display_grade($grade, $editing, $userid = 0, $modified = 0)
2037
    public function display_grade($grade, $editing, $userid = 0, $modified = 0, float $deductedmark = 0) {
2093
    {
-
 
2094
        global $DB;
2038
        global $DB, $PAGE;
Línea 2095... Línea 2039...
2095
 
2039
 
Línea 2096... Línea 2040...
2096
        static $scalegrades = array();
2040
        static $scalegrades = array();
Línea 2104... Línea 2048...
2104
                    $displaygrade = '';
2048
                    $displaygrade = '';
2105
                } else {
2049
                } else {
2106
                    $displaygrade = format_float($grade, $this->get_grade_item()->get_decimals());
2050
                    $displaygrade = format_float($grade, $this->get_grade_item()->get_decimals());
2107
                }
2051
                }
2108
                $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' .
2052
                $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' .
2109
                    get_string('usergrade', 'assign') .
2053
                       get_string('usergrade', 'assign') .
2110
                    '</label>';
2054
                       '</label>';
2111
                $o .= '<input type="text"
2055
                $o .= '<input type="text"
2112
                              id="quickgrade_' . $userid . '"
2056
                              id="quickgrade_' . $userid . '"
2113
                              name="quickgrade_' . $userid . '"
2057
                              name="quickgrade_' . $userid . '"
2114
                              value="' .  $displaygrade . '"
2058
                              value="' .  $displaygrade . '"
2115
                              size="6"
2059
                              size="6"
2116
                              maxlength="10"
2060
                              maxlength="10"
2117
                              class="quickgrade"/>';
2061
                              class="quickgrade"/>';
2118
                $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $this->get_grade_item()->get_decimals());
2062
                $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $this->get_grade_item()->get_decimals());
2119
                return $o;
-
 
2120
            } else {
2063
            } else {
2121
                if ($grade == -1 || $grade === null) {
2064
                if ($grade == -1 || $grade === null) {
2122
                    $o .= '-';
2065
                    $o .= '-';
2123
                } else {
2066
                } else {
2124
                    $item = $this->get_grade_item();
2067
                    $item = $this->get_grade_item();
Línea 2126... Línea 2069...
2126
                    if ($item->get_displaytype() == GRADE_DISPLAY_TYPE_REAL) {
2069
                    if ($item->get_displaytype() == GRADE_DISPLAY_TYPE_REAL) {
2127
                        // If displaying the raw grade, also display the total value.
2070
                        // If displaying the raw grade, also display the total value.
2128
                        $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $item->get_decimals());
2071
                        $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $item->get_decimals());
2129
                    }
2072
                    }
2130
                }
2073
                }
2131
                return $o;
-
 
2132
            }
2074
            }
-
 
2075
 
-
 
2076
            // Add penalty indicator, icon only.
-
 
2077
            $penaltyindicator = '';
-
 
2078
            if ($deductedmark > 0) {
-
 
2079
                $gradegrade = new \grade_grade();
-
 
2080
                $gradegrade->deductedmark = $deductedmark;
-
 
2081
                $gradegrade->overridden = $userid > 0 ? $this->get_grade_item()->get_grade($userid)->overridden : 0;
-
 
2082
                $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator($gradegrade);
-
 
2083
            }
-
 
2084
 
-
 
2085
            return $penaltyindicator . $o;
2133
        } else {
2086
        } else {
2134
            // Scale.
2087
            // Scale.
2135
            if (empty($this->cache['scale'])) {
2088
            if (empty($this->cache['scale'])) {
2136
                if ($scale = $DB->get_record('scale', array('id' => - ($this->get_instance()->grade)))) {
2089
                if ($scale = $DB->get_record('scale', array('id'=>-($this->get_instance()->grade)))) {
2137
                    $this->cache['scale'] = make_menu_from_list($scale->scale);
2090
                    $this->cache['scale'] = make_menu_from_list($scale->scale);
2138
                } else {
2091
                } else {
2139
                    $o .= '-';
2092
                    $o .= '-';
2140
                    return $o;
2093
                    return $o;
2141
                }
2094
                }
2142
            }
2095
            }
2143
            if ($editing) {
2096
            if ($editing) {
2144
                $o .= '<label class="accesshide"
2097
                $o .= '<label class="accesshide"
2145
                              for="quickgrade_' . $userid . '">' .
2098
                              for="quickgrade_' . $userid . '">' .
2146
                    get_string('usergrade', 'assign') .
2099
                      get_string('usergrade', 'assign') .
2147
                    '</label>';
2100
                      '</label>';
2148
                $o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
2101
                $o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
2149
                $o .= '<option value="-1">' . get_string('nograde') . '</option>';
2102
                $o .= '<option value="-1">' . get_string('nograde') . '</option>';
2150
                foreach ($this->cache['scale'] as $optionid => $option) {
2103
                foreach ($this->cache['scale'] as $optionid => $option) {
2151
                    $selected = '';
2104
                    $selected = '';
2152
                    if ($grade == $optionid) {
2105
                    if ($grade == $optionid) {
Línea 2178... Línea 2131...
2178
     * @param array $participants an associative array where the key is the participant id and
2131
     * @param array $participants an associative array where the key is the participant id and
2179
     *                            the value is the participant record.
2132
     *                            the value is the participant record.
2180
     * @return array an associative array where the key is the participant id and the value is
2133
     * @return array an associative array where the key is the participant id and the value is
2181
     *               the participant record.
2134
     *               the participant record.
2182
     */
2135
     */
2183
    private function get_submission_info_for_participants($participants)
2136
    private function get_submission_info_for_participants($participants) {
2184
    {
-
 
2185
        global $DB;
2137
        global $DB;
Línea 2186... Línea 2138...
2186
 
2138
 
2187
        if (empty($participants)) {
2139
        if (empty($participants)) {
2188
            return $participants;
2140
            return $participants;
Línea 2223... Línea 2175...
2223
 
2175
 
Línea 2224... Línea 2176...
2224
        $records = $DB->get_records_sql($sql, $params);
2176
        $records = $DB->get_records_sql($sql, $params);
2225
 
2177
 
2226
        if ($this->get_instance()->teamsubmission) {
2178
        if ($this->get_instance()->teamsubmission) {
2227
            // Get all groups.
-
 
2228
            $allgroups = groups_get_all_groups(
2179
            // Get all groups.
2229
                $this->get_course()->id,
2180
            $allgroups = groups_get_all_groups($this->get_course()->id,
2230
                array_keys($participants),
2181
                                               array_keys($participants),
2231
                $this->get_instance()->teamsubmissiongroupingid,
2182
                                               $this->get_instance()->teamsubmissiongroupingid,
2232
                'DISTINCT g.id, g.name'
2183
                                               'DISTINCT g.id, g.name');
2233
            );
2184
 
2234
        }
2185
        }
2235
        foreach ($participants as $userid => $participant) {
2186
        foreach ($participants as $userid => $participant) {
2236
            $participants[$userid]->fullname = $this->fullname($participant);
2187
            $participants[$userid]->fullname = $this->fullname($participant);
Línea 2250... Línea 2201...
2250
            if (!empty($submissioninfo->stime) && $submissioninfo->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
2201
            if (!empty($submissioninfo->stime) && $submissioninfo->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
2251
                $submitted = true;
2202
                $submitted = true;
2252
            }
2203
            }
Línea 2253... Línea 2204...
2253
 
2204
 
2254
            if ($submitted && ($submissioninfo->stime >= $submissioninfo->gtime ||
2205
            if ($submitted && ($submissioninfo->stime >= $submissioninfo->gtime ||
2255
                empty($submissioninfo->gtime) ||
2206
                    empty($submissioninfo->gtime) ||
2256
                $submissioninfo->grade === null)) {
2207
                    $submissioninfo->grade === null)) {
2257
                $requiregrading = true;
2208
                $requiregrading = true;
Línea 2258... Línea 2209...
2258
            }
2209
            }
2259
 
2210
 
Línea 2284... Línea 2235...
2284
     * @param int $currentgroup
2235
     * @param int $currentgroup
2285
     * @param boolean $tablesort Apply current user table sorting preferences.
2236
     * @param boolean $tablesort Apply current user table sorting preferences.
2286
     * @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'grantedextension',
2237
     * @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'grantedextension',
2287
     *               'groupid', 'groupname'
2238
     *               'groupid', 'groupname'
2288
     */
2239
     */
2289
    public function list_participants_with_filter_status_and_group($currentgroup, $tablesort = false)
2240
    public function list_participants_with_filter_status_and_group($currentgroup, $tablesort = false) {
2290
    {
-
 
2291
        $participants = $this->list_participants($currentgroup, false, $tablesort);
2241
        $participants = $this->list_participants($currentgroup, false, $tablesort);
Línea 2292... Línea 2242...
2292
 
2242
 
2293
        if (empty($participants)) {
2243
        if (empty($participants)) {
2294
            return $participants;
2244
            return $participants;
Línea 2303... Línea 2253...
2303
     * we are only concerned with a list of users so we can't search on anything
2253
     * we are only concerned with a list of users so we can't search on anything
2304
     * that is not part of the user information (like grading statud or last modified stuff).
2254
     * that is not part of the user information (like grading statud or last modified stuff).
2305
     *
2255
     *
2306
     * @return string Order by clause for list_participants
2256
     * @return string Order by clause for list_participants
2307
     */
2257
     */
2308
    private function get_grading_sort_sql()
2258
    private function get_grading_sort_sql() {
2309
    {
-
 
2310
        $usersort = flexible_table::get_sort_for_table('mod_assign_grading');
2259
        $usersort = flexible_table::get_sort_for_table('mod_assign_grading');
2311
        // TODO Does not support custom user profile fields (MDL-70456).
2260
        // TODO Does not support custom user profile fields (MDL-70456).
2312
        $userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
2261
        $userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
2313
        $userfields = $userfieldsapi->get_required_fields();
2262
        $userfields = $userfieldsapi->get_required_fields();
2314
        $orderfields = explode(',', $usersort);
2263
        $orderfields = explode(',', $usersort);
Línea 2338... Línea 2287...
2338
     * Returns array with sql code and parameters returning all ids of users who have submitted an assignment.
2287
     * Returns array with sql code and parameters returning all ids of users who have submitted an assignment.
2339
     *
2288
     *
2340
     * @param int $group The group that the query is for.
2289
     * @param int $group The group that the query is for.
2341
     * @return array list($sql, $params)
2290
     * @return array list($sql, $params)
2342
     */
2291
     */
2343
    protected function get_submitted_sql($group = 0)
2292
    protected function get_submitted_sql($group = 0) {
2344
    {
-
 
2345
        // We need to guarentee unique table names.
2293
        // We need to guarentee unique table names.
2346
        static $i = 0;
2294
        static $i = 0;
2347
        $i++;
2295
        $i++;
2348
        $prefix = 'sa' . $i . '_';
2296
        $prefix = 'sa' . $i . '_';
2349
        $params = [
2297
        $params = [
Línea 2370... Línea 2318...
2370
     * @param int $currentgroup
2318
     * @param int $currentgroup
2371
     * @param bool $idsonly
2319
     * @param bool $idsonly
2372
     * @param bool $tablesort
2320
     * @param bool $tablesort
2373
     * @return array List of user records
2321
     * @return array List of user records
2374
     */
2322
     */
2375
    public function list_participants($currentgroup, $idsonly, $tablesort = false)
2323
    public function list_participants($currentgroup, $idsonly, $tablesort = false) {
2376
    {
-
 
2377
        global $DB, $USER;
2324
        global $DB, $USER;
Línea 2378... Línea 2325...
2378
 
2325
 
Línea 2379... Línea 2326...
2379
        // Get the last known sort order for the grading table.
2326
        // Get the last known sort order for the grading table.
2380
 
2327
 
2381
        if (empty($currentgroup)) {
2328
        if (empty($currentgroup)) {
Línea 2382... Línea 2329...
2382
            $currentgroup = 0;
2329
            $currentgroup = 0;
2383
        }
2330
        }
2384
 
2331
 
2385
        $key = $this->context->id . '-' . $currentgroup . '-' . $this->show_only_active_users();
-
 
2386
        if (!isset($this->participants[$key])) {
-
 
2387
            list($esql, $params) = get_enrolled_sql(
-
 
2388
                $this->context,
2332
        $key = $this->context->id . '-' . $currentgroup . '-' . $this->show_only_active_users();
2389
                'mod/assign:submit',
-
 
2390
                $currentgroup,
2333
        if (!isset($this->participants[$key])) {
2391
                $this->show_only_active_users()
2334
            list($esql, $params) = get_enrolled_sql($this->context, 'mod/assign:submit', $currentgroup,
Línea 2392... Línea 2335...
2392
            );
2335
                    $this->show_only_active_users());
2393
            list($ssql, $sparams) = $this->get_submitted_sql($currentgroup);
2336
            list($ssql, $sparams) = $this->get_submitted_sql($currentgroup);
Línea 2419... Línea 2362...
2419
                if (empty($tablesort)) {
2362
                if (empty($tablesort)) {
2420
                    $orderby = "COALESCE(s.timecreated, " . time() . ") ASC, COALESCE(s.id, " . PHP_INT_MAX . ") ASC, um.id ASC";
2363
                    $orderby = "COALESCE(s.timecreated, " . time() . ") ASC, COALESCE(s.id, " . PHP_INT_MAX . ") ASC, um.id ASC";
2421
                }
2364
                }
2422
            }
2365
            }
Línea 2423... Línea -...
2423
 
-
 
2424
            if (
2366
 
2425
                $instance->markingworkflow &&
2367
            if ($instance->markingworkflow &&
2426
                $instance->markingallocation &&
2368
                    $instance->markingallocation &&
2427
                !has_capability('mod/assign:manageallocations', $this->get_context()) &&
2369
                    !has_capability('mod/assign:manageallocations', $this->get_context()) &&
2428
                has_capability('mod/assign:grade', $this->get_context())
-
 
Línea 2429... Línea 2370...
2429
            ) {
2370
                    has_capability('mod/assign:grade', $this->get_context())) {
2430
 
2371
 
2431
                $additionaljoins .= ' LEFT JOIN {assign_user_flags} uf
2372
                $additionaljoins .= ' LEFT JOIN {assign_user_flags} uf
Línea 2436... Línea 2377...
2436
 
2377
 
2437
                $additionalfilters .= ' AND uf.allocatedmarker = :markerid';
2378
                $additionalfilters .= ' AND uf.allocatedmarker = :markerid';
2438
                $params['markerid'] = $USER->id;
2379
                $params['markerid'] = $USER->id;
Línea -... Línea 2380...
-
 
2380
            }
-
 
2381
 
-
 
2382
            // A user wants to view a particular user rather than a set of users.
-
 
2383
            if ($this->usersearch) {
-
 
2384
                if (isset($this->usersearch['userid'])) {
-
 
2385
                    $additionalfilters .= " AND u.id = :uid";
-
 
2386
                    $params['uid'] = $this->usersearch['userid'];
-
 
2387
                } else if ($this->usersearch['usersearch'] !== '') { // A user wants to view a subset of learners that match the search criteria.
-
 
2388
                    [
-
 
2389
                        'where' => $keywordswhere,
-
 
2390
                        'params' => $keywordsparams,
-
 
2391
                    ] = \core_user::get_users_search_sql($this->context, $this->usersearch['usersearch']);
-
 
2392
                    $additionalfilters .= " AND $keywordswhere";
-
 
2393
                    $params = array_merge($params, $keywordsparams);
-
 
2394
                }
-
 
2395
            }
-
 
2396
 
-
 
2397
            // Exclude suspended users from the list of participants.
2439
            }
2398
            $additionalfilters .= " AND u.suspended = 0 AND u.auth <> 'nologin'";
2440
 
2399
 
2441
            $sql = "SELECT $fields
2400
            $sql = "SELECT $fields
2442
                      FROM {user} u
2401
                      FROM {user} u
2443
                      JOIN ($esql UNION $ssql) je ON je.id = u.id
2402
                      JOIN ($esql UNION $ssql) je ON je.id = u.id
Línea 2484... Línea 2443...
2484
     * status for this assignment.
2443
     * status for this assignment.
2485
     *
2444
     *
2486
     * @param int $userid
2445
     * @param int $userid
2487
     * @return null|stdClass user record
2446
     * @return null|stdClass user record
2488
     */
2447
     */
2489
    public function get_participant($userid)
2448
    public function get_participant($userid) {
2490
    {
-
 
2491
        global $DB, $USER;
2449
        global $DB, $USER;
Línea 2492... Línea 2450...
2492
 
2450
 
2493
        if ($userid == $USER->id) {
2451
        if ($userid == $USER->id) {
2494
            $participant = clone ($USER);
2452
            $participant = clone ($USER);
Línea 2517... Línea 2475...
2517
     * Load a count of valid teams for this assignment.
2475
     * Load a count of valid teams for this assignment.
2518
     *
2476
     *
2519
     * @param int $activitygroup Activity active group
2477
     * @param int $activitygroup Activity active group
2520
     * @return int number of valid teams
2478
     * @return int number of valid teams
2521
     */
2479
     */
2522
    public function count_teams($activitygroup = 0)
2480
    public function count_teams($activitygroup = 0) {
2523
    {
-
 
Línea 2524... Línea 2481...
2524
 
2481
 
Línea 2525... Línea 2482...
2525
        $count = 0;
2482
        $count = 0;
Línea 2530... Línea 2487...
2530
        // are the submission teams, but if no team submission grouping was specified
2487
        // are the submission teams, but if no team submission grouping was specified
2531
        // $groups will contain all participants groups.
2488
        // $groups will contain all participants groups.
2532
        if ($this->get_instance()->teamsubmissiongroupingid) {
2489
        if ($this->get_instance()->teamsubmissiongroupingid) {
Línea 2533... Línea 2490...
2533
 
2490
 
2534
            // We restrict the users to the selected group ones.
2491
            // We restrict the users to the selected group ones.
2535
            $groups = groups_get_all_groups(
-
 
2536
                $this->get_course()->id,
2492
            $groups = groups_get_all_groups($this->get_course()->id,
2537
                array_keys($participants),
2493
                                            array_keys($participants),
2538
                $this->get_instance()->teamsubmissiongroupingid,
2494
                                            $this->get_instance()->teamsubmissiongroupingid,
2539
                'DISTINCT g.id, g.name'
-
 
Línea 2540... Línea 2495...
2540
            );
2495
                                            'DISTINCT g.id, g.name');
Línea 2541... Línea 2496...
2541
 
2496
 
2542
            $count = count($groups);
2497
            $count = count($groups);
Línea 2577... Línea 2532...
2577
     * 0 for no group.
2532
     * 0 for no group.
2578
     *
2533
     *
2579
     * @param int $currentgroup
2534
     * @param int $currentgroup
2580
     * @return int number of matching users
2535
     * @return int number of matching users
2581
     */
2536
     */
2582
    public function count_participants($currentgroup)
2537
    public function count_participants($currentgroup) {
2583
    {
-
 
2584
        return count($this->list_participants($currentgroup, true));
2538
        return count($this->list_participants($currentgroup, true));
2585
    }
2539
    }
Línea 2586... Línea 2540...
2586
 
2540
 
2587
    /**
2541
    /**
Línea 2590... Línea 2544...
2590
     * grading modification time and the status is SUBMITTED.
2544
     * grading modification time and the status is SUBMITTED.
2591
     *
2545
     *
2592
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2546
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2593
     * @return int number of matching submissions
2547
     * @return int number of matching submissions
2594
     */
2548
     */
2595
    public function count_submissions_need_grading($currentgroup = null)
2549
    public function count_submissions_need_grading($currentgroup = null) {
2596
    {
-
 
2597
        global $DB;
2550
        global $DB;
Línea 2598... Línea 2551...
2598
 
2551
 
2599
        if ($this->get_instance()->teamsubmission) {
2552
        if ($this->get_instance()->teamsubmission) {
2600
            // This does not make sense for group assignment because the submission is shared.
2553
            // This does not make sense for group assignment because the submission is shared.
Línea 2621... Línea 2574...
2621
                        s.latest = 1 AND
2574
                        s.latest = 1 AND
2622
                        s.assignment = :assignid AND
2575
                        s.assignment = :assignid AND
2623
                        s.timemodified IS NOT NULL AND
2576
                        s.timemodified IS NOT NULL AND
2624
                        s.status = :submitted AND
2577
                        s.status = :submitted AND
2625
                        (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL '
2578
                        (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL '
2626
            . $sqlscalegrade . ')';
2579
                            . $sqlscalegrade . ')';
Línea 2627... Línea 2580...
2627
 
2580
 
2628
        return $DB->count_records_sql($sql, $params);
2581
        return $DB->count_records_sql($sql, $params);
Línea 2629... Línea 2582...
2629
    }
2582
    }
2630
 
2583
 
2631
    /**
2584
    /**
2632
     * Load a count of grades.
2585
     * Load a count of grades.
2633
     *
2586
     *
2634
     * @return int number of grades
2587
     * @return int number of grades
2635
     */
-
 
2636
    public function count_grades()
2588
     */
Línea 2637... Línea 2589...
2637
    {
2589
    public function count_grades() {
2638
        global $DB;
2590
        global $DB;
2639
 
2591
 
Línea 2658... Línea 2610...
2658
     * Load a count of submissions.
2610
     * Load a count of submissions.
2659
     *
2611
     *
2660
     * @param bool $includenew When true, also counts the submissions with status 'new'.
2612
     * @param bool $includenew When true, also counts the submissions with status 'new'.
2661
     * @return int number of submissions
2613
     * @return int number of submissions
2662
     */
2614
     */
2663
    public function count_submissions($includenew = false)
2615
    public function count_submissions($includenew = false) {
2664
    {
-
 
2665
        global $DB;
2616
        global $DB;
Línea 2666... Línea 2617...
2666
 
2617
 
2667
        if (!$this->has_instance()) {
2618
        if (!$this->has_instance()) {
2668
            return 0;
2619
            return 0;
Línea 2682... Línea 2633...
2682
                        FROM {assign_submission} s
2633
                        FROM {assign_submission} s
2683
                        WHERE
2634
                        WHERE
2684
                            s.assignment = :assignid AND
2635
                            s.assignment = :assignid AND
2685
                            s.timemodified IS NOT NULL AND
2636
                            s.timemodified IS NOT NULL AND
2686
                            s.userid = :groupuserid' .
2637
                            s.userid = :groupuserid' .
2687
                $sqlnew;
2638
                            $sqlnew;
Línea 2688... Línea 2639...
2688
 
2639
 
2689
            $params['assignid'] = $this->get_instance()->id;
2640
            $params['assignid'] = $this->get_instance()->id;
2690
            $params['groupuserid'] = 0;
2641
            $params['groupuserid'] = 0;
2691
        } else {
2642
        } else {
Línea 2699... Línea 2650...
2699
                       FROM {assign_submission} s
2650
                       FROM {assign_submission} s
2700
                       JOIN(' . $esql . ') e ON e.id = s.userid
2651
                       JOIN(' . $esql . ') e ON e.id = s.userid
2701
                       WHERE
2652
                       WHERE
2702
                            s.assignment = :assignid AND
2653
                            s.assignment = :assignid AND
2703
                            s.timemodified IS NOT NULL ' .
2654
                            s.timemodified IS NOT NULL ' .
2704
                $sqlnew;
2655
                            $sqlnew;
-
 
2656
 
2705
        }
2657
        }
Línea 2706... Línea 2658...
2706
 
2658
 
2707
        return $DB->count_records_sql($sql, $params);
2659
        return $DB->count_records_sql($sql, $params);
Línea 2712... Línea 2664...
2712
     *
2664
     *
2713
     * @param string $status The submission status - should match one of the constants
2665
     * @param string $status The submission status - should match one of the constants
2714
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2666
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2715
     * @return int number of matching submissions
2667
     * @return int number of matching submissions
2716
     */
2668
     */
2717
    public function count_submissions_with_status($status, $currentgroup = null)
2669
    public function count_submissions_with_status($status, $currentgroup = null) {
2718
    {
-
 
2719
        global $DB;
2670
        global $DB;
Línea 2720... Línea 2671...
2720
 
2671
 
2721
        if ($currentgroup === null) {
2672
        if ($currentgroup === null) {
2722
            $currentgroup = groups_get_activity_group($this->get_course_module(), true);
2673
            $currentgroup = groups_get_activity_group($this->get_course_module(), true);
Línea 2731... Línea 2682...
2731
 
2682
 
2732
            $groupsstr = '';
2683
            $groupsstr = '';
2733
            if ($currentgroup != 0) {
2684
            if ($currentgroup != 0) {
2734
                // If there is an active group we should only display the current group users groups.
2685
                // If there is an active group we should only display the current group users groups.
2735
                $participants = $this->list_participants($currentgroup, true);
2686
                $participants = $this->list_participants($currentgroup, true);
2736
                $groups = groups_get_all_groups(
-
 
2737
                    $this->get_course()->id,
2687
                $groups = groups_get_all_groups($this->get_course()->id,
2738
                    array_keys($participants),
2688
                                                array_keys($participants),
2739
                    $this->get_instance()->teamsubmissiongroupingid,
2689
                                                $this->get_instance()->teamsubmissiongroupingid,
2740
                    'DISTINCT g.id, g.name'
-
 
2741
                );
2690
                                                'DISTINCT g.id, g.name');
2742
                if (empty($groups)) {
2691
                if (empty($groups)) {
2743
                    // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
2692
                    // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
2744
                    // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
2693
                    // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
2745
                    // count towards groupid = 0. Setting to true as only '0' key matters.
2694
                    // count towards groupid = 0. Setting to true as only '0' key matters.
Línea 2754... Línea 2703...
2754
                        WHERE
2703
                        WHERE
2755
                            s.latest = 1 AND
2704
                            s.latest = 1 AND
2756
                            s.assignment = :assignid AND
2705
                            s.assignment = :assignid AND
2757
                            s.timemodified IS NOT NULL AND
2706
                            s.timemodified IS NOT NULL AND
2758
                            s.userid = :groupuserid AND '
2707
                            s.userid = :groupuserid AND '
2759
                . $groupsstr . '
2708
                            . $groupsstr . '
2760
                            s.status = :submissionstatus';
2709
                            s.status = :submissionstatus';
2761
            $params['groupuserid'] = 0;
2710
            $params['groupuserid'] = 0;
2762
        } else {
2711
        } else {
2763
            $sql = 'SELECT COUNT(s.userid)
2712
            $sql = 'SELECT COUNT(s.userid)
2764
                        FROM {assign_submission} s
2713
                        FROM {assign_submission} s
Línea 2766... Línea 2715...
2766
                        WHERE
2715
                        WHERE
2767
                            s.latest = 1 AND
2716
                            s.latest = 1 AND
2768
                            s.assignment = :assignid AND
2717
                            s.assignment = :assignid AND
2769
                            s.timemodified IS NOT NULL AND
2718
                            s.timemodified IS NOT NULL AND
2770
                            s.status = :submissionstatus';
2719
                            s.status = :submissionstatus';
-
 
2720
 
2771
        }
2721
        }
Línea 2772... Línea 2722...
2772
 
2722
 
2773
        return $DB->count_records_sql($sql, $params);
2723
        return $DB->count_records_sql($sql, $params);
Línea 2779... Línea 2729...
2779
     *
2729
     *
2780
     * @param boolean $cached If true, the cached list from the session could be returned.
2730
     * @param boolean $cached If true, the cached list from the session could be returned.
2781
     * @param string $useridlistid String value used for caching the participant list.
2731
     * @param string $useridlistid String value used for caching the participant list.
2782
     * @return array An array of userids
2732
     * @return array An array of userids
2783
     */
2733
     */
2784
    protected function get_grading_userid_list($cached = false, $useridlistid = '')
2734
    protected function get_grading_userid_list($cached = false, $useridlistid = '') {
2785
    {
-
 
2786
        global $SESSION;
2735
        global $SESSION;
Línea 2787... Línea 2736...
2787
 
2736
 
2788
        if ($cached) {
2737
        if ($cached) {
2789
            if (empty($useridlistid)) {
2738
            if (empty($useridlistid)) {
Línea 2807... Línea 2756...
2807
     * Is user id filtered by user filters and table preferences.
2756
     * Is user id filtered by user filters and table preferences.
2808
     *
2757
     *
2809
     * @param int $userid User id that needs to be checked.
2758
     * @param int $userid User id that needs to be checked.
2810
     * @return bool
2759
     * @return bool
2811
     */
2760
     */
2812
    public function is_userid_filtered($userid)
2761
    public function is_userid_filtered($userid) {
2813
    {
-
 
2814
        $users = $this->get_grading_userid_list();
2762
        $users = $this->get_grading_userid_list();
2815
        return in_array($userid, $users);
2763
        return in_array($userid, $users);
2816
    }
2764
    }
Línea 2817... Línea 2765...
2817
 
2765
 
Línea 2820... Línea 2768...
2820
     *
2768
     *
2821
     * Cron function to be run periodically according to the moodle cron.
2769
     * Cron function to be run periodically according to the moodle cron.
2822
     *
2770
     *
2823
     * @return bool
2771
     * @return bool
2824
     */
2772
     */
2825
    public static function cron()
2773
    public static function cron() {
2826
    {
-
 
2827
        global $DB;
2774
        global $DB;
Línea 2828... Línea 2775...
2828
 
2775
 
2829
        // Only ever send a max of one days worth of updates.
2776
        // Only ever send a max of one days worth of updates.
2830
        $yesterday = time() - (24 * 3600);
2777
        $yesterday = time() - (24 * 3600);
Línea 2873... Línea 2820...
2873
            // Filter out duplicates.
2820
            // Filter out duplicates.
2874
            $courseids = array_unique($courseids);
2821
            $courseids = array_unique($courseids);
2875
            $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
2822
            $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
2876
            list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
2823
            list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
2877
            $sql = 'SELECT c.*, ' . $ctxselect .
2824
            $sql = 'SELECT c.*, ' . $ctxselect .
2878
                ' FROM {course} c
2825
                      ' FROM {course} c
2879
                 LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel
2826
                 LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel
2880
                     WHERE c.id ' . $courseidsql;
2827
                     WHERE c.id ' . $courseidsql;
Línea 2881... Línea 2828...
2881
 
2828
 
2882
            $params['contextlevel'] = CONTEXT_COURSE;
2829
            $params['contextlevel'] = CONTEXT_COURSE;
Línea 2892... Línea 2839...
2892
            foreach ($submissions as $submission) {
2839
            foreach ($submissions as $submission) {
Línea 2893... Línea 2840...
2893
 
2840
 
Línea 2894... Línea 2841...
2894
                mtrace("Processing assignment submission $submission->id ...");
2841
                mtrace("Processing assignment submission $submission->id ...");
2895
 
2842
 
2896
                // Do not cache user lookups - could be too many.
2843
                // Do not cache user lookups - could be too many.
2897
                if (!$user = $DB->get_record('user', array('id' => $submission->userid))) {
2844
                if (!$user = $DB->get_record('user', array('id'=>$submission->userid))) {
2898
                    mtrace('Could not find user ' . $submission->userid);
2845
                    mtrace('Could not find user ' . $submission->userid);
Línea 2899... Línea 2846...
2899
                    continue;
2846
                    continue;
Línea 2915... Línea 2862...
2915
                \core\cron::setup_user($user, $course);
2862
                \core\cron::setup_user($user, $course);
Línea 2916... Línea 2863...
2916
 
2863
 
2917
                // Context lookups are already cached.
2864
                // Context lookups are already cached.
2918
                $coursecontext = context_course::instance($course->id);
2865
                $coursecontext = context_course::instance($course->id);
2919
                if (!is_enrolled($coursecontext, $user->id)) {
2866
                if (!is_enrolled($coursecontext, $user->id)) {
2920
                    $courseshortname = format_string(
2867
                    $courseshortname = format_string($course->shortname,
2921
                        $course->shortname,
-
 
2922
                        true,
2868
                                                     true,
2923
                        array('context' => $coursecontext)
-
 
2924
                    );
2869
                                                     array('context' => $coursecontext));
2925
                    mtrace(fullname($user) . ' not an active participant in ' . $courseshortname);
2870
                    mtrace(fullname($user) . ' not an active participant in ' . $courseshortname);
2926
                    continue;
2871
                    continue;
Línea 2927... Línea 2872...
2927
                }
2872
                }
2928
 
2873
 
2929
                if (!$grader = $DB->get_record('user', array('id' => $submission->grader))) {
2874
                if (!$grader = $DB->get_record('user', array('id'=>$submission->grader))) {
2930
                    mtrace('Could not find grader ' . $submission->grader);
2875
                    mtrace('Could not find grader ' . $submission->grader);
Línea 2931... Línea 2876...
2931
                    continue;
2876
                    continue;
Línea 2963... Línea 2908...
2963
                    } else {
2908
                    } else {
2964
                        $uniqueid = $submission->recordid;
2909
                        $uniqueid = $submission->recordid;
2965
                    }
2910
                    }
2966
                }
2911
                }
2967
                $showusers = $submission->blindmarking && !$submission->revealidentities;
2912
                $showusers = $submission->blindmarking && !$submission->revealidentities;
2968
                self::send_assignment_notification(
2913
                self::send_assignment_notification($grader,
2969
                    $grader,
-
 
2970
                    $user,
2914
                                                   $user,
2971
                    $messagetype,
2915
                                                   $messagetype,
2972
                    $eventtype,
2916
                                                   $eventtype,
2973
                    $updatetime,
2917
                                                   $updatetime,
2974
                    $cm,
2918
                                                   $cm,
2975
                    $contextmodule,
2919
                                                   $contextmodule,
2976
                    $course,
2920
                                                   $course,
2977
                    $modulename,
2921
                                                   $modulename,
2978
                    $submission->name,
2922
                                                   $submission->name,
2979
                    $showusers,
2923
                                                   $showusers,
2980
                    $uniqueid
2924
                                                   $uniqueid);
2981
                );
-
 
Línea 2982... Línea 2925...
2982
 
2925
 
2983
                $flags = $DB->get_record('assign_user_flags', array('userid' => $user->id, 'assignment' => $submission->assignment));
2926
                $flags = $DB->get_record('assign_user_flags', array('userid'=>$user->id, 'assignment'=>$submission->assignment));
2984
                if ($flags) {
2927
                if ($flags) {
2985
                    $flags->mailed = 1;
2928
                    $flags->mailed = 1;
2986
                    $DB->update_record('assign_user_flags', $flags);
2929
                    $DB->update_record('assign_user_flags', $flags);
2987
                } else {
2930
                } else {
Línea 3027... Línea 2970...
3027
     *
2970
     *
3028
     * @param stdClass $grade a grade record keyed on id
2971
     * @param stdClass $grade a grade record keyed on id
3029
     * @param bool $mailedoverride when true, flag notification to be sent again.
2972
     * @param bool $mailedoverride when true, flag notification to be sent again.
3030
     * @return bool true for success
2973
     * @return bool true for success
3031
     */
2974
     */
3032
    public function notify_grade_modified($grade, $mailedoverride = false)
2975
    public function notify_grade_modified($grade, $mailedoverride = false) {
3033
    {
-
 
3034
        global $DB;
2976
        global $DB;
Línea 3035... Línea 2977...
3035
 
2977
 
3036
        $flags = $this->get_user_flags($grade->userid, true);
2978
        $flags = $this->get_user_flags($grade->userid, true);
3037
        if ($flags->mailed != 1 || $mailedoverride) {
2979
        if ($flags->mailed != 1 || $mailedoverride) {
Línea 3045... Línea 2987...
3045
     * Update user flags for this user in this assignment.
2987
     * Update user flags for this user in this assignment.
3046
     *
2988
     *
3047
     * @param stdClass $flags a flags record keyed on id
2989
     * @param stdClass $flags a flags record keyed on id
3048
     * @return bool true for success
2990
     * @return bool true for success
3049
     */
2991
     */
3050
    public function update_user_flags($flags)
2992
    public function update_user_flags($flags) {
3051
    {
-
 
3052
        global $DB;
2993
        global $DB;
3053
        if ($flags->userid <= 0 || $flags->assignment <= 0 || $flags->id <= 0) {
2994
        if ($flags->userid <= 0 || $flags->assignment <= 0 || $flags->id <= 0) {
3054
            return false;
2995
            return false;
3055
        }
2996
        }
Línea 3063... Línea 3004...
3063
     *
3004
     *
3064
     * @param stdClass $grade a grade record keyed on id
3005
     * @param stdClass $grade a grade record keyed on id
3065
     * @param bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this assignment.
3006
     * @param bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this assignment.
3066
     * @return bool true for success
3007
     * @return bool true for success
3067
     */
3008
     */
3068
    public function update_grade($grade, $reopenattempt = false)
3009
    public function update_grade($grade, $reopenattempt = false) {
3069
    {
-
 
3070
        global $DB;
3010
        global $DB;
Línea 3071... Línea 3011...
3071
 
3011
 
Línea 3072... Línea 3012...
3072
        $grade->timemodified = time();
3012
        $grade->timemodified = time();
Línea 3087... Línea 3027...
3087
                } else if ($grade->grade < 0) {
3027
                } else if ($grade->grade < 0) {
3088
                    return false;
3028
                    return false;
3089
                }
3029
                }
3090
            } else {
3030
            } else {
3091
                // This is a scale.
3031
                // This is a scale.
3092
                if ($scale = $DB->get_record('scale', array('id' => - ($this->get_instance()->grade)))) {
3032
                if ($scale = $DB->get_record('scale', array('id' => -($this->get_instance()->grade)))) {
3093
                    $scaleoptions = make_menu_from_list($scale->scale);
3033
                    $scaleoptions = make_menu_from_list($scale->scale);
3094
                    if (!array_key_exists((int) $grade->grade, $scaleoptions)) {
3034
                    if (!array_key_exists((int) $grade->grade, $scaleoptions)) {
3095
                        return false;
3035
                        return false;
3096
                    }
3036
                    }
3097
                }
3037
                }
Línea 3124... Línea 3064...
3124
            \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
3064
            \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
3125
        }
3065
        }
Línea 3126... Línea 3066...
3126
 
3066
 
3127
        // If the conditions are met, allow another attempt.
3067
        // If the conditions are met, allow another attempt.
3128
        if ($submission) {
3068
        if ($submission) {
3129
            $isreopened = $this->reopen_submission_if_required(
-
 
3130
                $grade->userid,
3069
            $isreopened = $this->reopen_submission_if_required($grade->userid,
3131
                $submission,
3070
                    $submission,
3132
                $reopenattempt
-
 
3133
            );
3071
                    $reopenattempt);
3134
            if ($isreopened) {
3072
            if ($isreopened) {
3135
                $completion = new completion_info($this->get_course());
-
 
3136
                if (
3073
                $completion = new completion_info($this->get_course());
3137
                    $completion->is_enabled($this->get_course_module()) &&
3074
                if ($completion->is_enabled($this->get_course_module()) &&
3138
                    $this->get_instance()->completionsubmit
-
 
3139
                ) {
3075
                    $this->get_instance()->completionsubmit) {
3140
                    $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $grade->userid);
3076
                    $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $grade->userid);
3141
                }
3077
                }
3142
            }
3078
            }
Línea 3152... Línea 3088...
3152
     * or from parameter 'selectedusers'
3088
     * or from parameter 'selectedusers'
3153
     *
3089
     *
3154
     * @param moodleform $mform - Used for validation of the submitted data
3090
     * @param moodleform $mform - Used for validation of the submitted data
3155
     * @return string
3091
     * @return string
3156
     */
3092
     */
3157
    protected function view_grant_extension($mform)
3093
    protected function view_grant_extension($mform) {
3158
    {
-
 
3159
        global $CFG;
3094
        global $CFG;
3160
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
3095
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
Línea 3161... Línea 3096...
3161
 
3096
 
Línea 3203... Línea 3138...
3203
 
3138
 
3204
        if (empty($mform)) {
3139
        if (empty($mform)) {
3205
            $mform = new mod_assign_extension_form(null, $formparams);
3140
            $mform = new mod_assign_extension_form(null, $formparams);
3206
        }
3141
        }
3207
        $mform->set_data($data);
3142
        $mform->set_data($data);
3208
        $header = new assign_header(
-
 
3209
            $this->get_instance(),
3143
        $header = new assign_header($this->get_instance(),
3210
            $this->get_context(),
3144
                                    $this->get_context(),
3211
            $this->show_intro(),
3145
                                    $this->show_intro(),
3212
            $this->get_course_module()->id,
3146
                                    $this->get_course_module()->id,
3213
            get_string('grantextension', 'assign')
-
 
3214
        );
3147
                                    get_string('grantextension', 'assign'));
3215
        $o .= $this->get_renderer()->render($header);
3148
        $o .= $this->get_renderer()->render($header);
3216
        $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform));
3149
        $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform));
3217
        $o .= $this->view_footer();
3150
        $o .= $this->view_footer();
3218
        return $o;
3151
        return $o;
Línea 3224... Línea 3157...
3224
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3157
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3225
     * @param bool $onlyids Whether to retrieve only the user id's
3158
     * @param bool $onlyids Whether to retrieve only the user id's
3226
     * @param bool $excludesuspended Whether to exclude suspended users
3159
     * @param bool $excludesuspended Whether to exclude suspended users
3227
     * @return array The users (possibly id's only)
3160
     * @return array The users (possibly id's only)
3228
     */
3161
     */
3229
    public function get_submission_group_members($groupid, $onlyids, $excludesuspended = false)
3162
    public function get_submission_group_members($groupid, $onlyids, $excludesuspended = false) {
3230
    {
-
 
3231
        $members = array();
3163
        $members = array();
3232
        if ($groupid != 0) {
3164
        if ($groupid != 0) {
3233
            $allusers = $this->list_participants($groupid, $onlyids);
3165
            $allusers = $this->list_participants($groupid, $onlyids);
3234
            foreach ($allusers as $user) {
3166
            foreach ($allusers as $user) {
3235
                if ($this->get_submission_group($user->id)) {
3167
                if ($this->get_submission_group($user->id)) {
Línea 3261... Línea 3193...
3261
     *
3193
     *
3262
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3194
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3263
     * @param bool $onlyids Whether to retrieve only the user id's
3195
     * @param bool $onlyids Whether to retrieve only the user id's
3264
     * @return array The users (possibly id's only)
3196
     * @return array The users (possibly id's only)
3265
     */
3197
     */
3266
    public function get_submission_group_members_who_have_not_submitted($groupid, $onlyids)
3198
    public function get_submission_group_members_who_have_not_submitted($groupid, $onlyids) {
3267
    {
-
 
3268
        $instance = $this->get_instance();
3199
        $instance = $this->get_instance();
3269
        if (!$instance->teamsubmission || !$instance->requireallteammemberssubmit) {
3200
        if (!$instance->teamsubmission || !$instance->requireallteammemberssubmit) {
3270
            return array();
3201
            return array();
3271
        }
3202
        }
3272
        $members = $this->get_submission_group_members($groupid, $onlyids);
3203
        $members = $this->get_submission_group_members($groupid, $onlyids);
Línea 3276... Línea 3207...
3276
            if ($submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
3207
            if ($submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
3277
                unset($members[$id]);
3208
                unset($members[$id]);
3278
            } else {
3209
            } else {
3279
                if ($this->is_blind_marking()) {
3210
                if ($this->is_blind_marking()) {
3280
                    $members[$id]->alias = get_string('hiddenuser', 'assign') .
3211
                    $members[$id]->alias = get_string('hiddenuser', 'assign') .
3281
                        $this->get_uniqueid_for_user($id);
3212
                                           $this->get_uniqueid_for_user($id);
3282
                }
3213
                }
3283
            }
3214
            }
3284
        }
3215
        }
3285
        return $members;
3216
        return $members;
3286
    }
3217
    }
Línea 3294... Línea 3225...
3294
     * @param bool $create If set to true a new submission object will be created in the database
3225
     * @param bool $create If set to true a new submission object will be created in the database
3295
     *                     with the status set to "new".
3226
     *                     with the status set to "new".
3296
     * @param int $attemptnumber - -1 means the latest attempt
3227
     * @param int $attemptnumber - -1 means the latest attempt
3297
     * @return stdClass|false The submission
3228
     * @return stdClass|false The submission
3298
     */
3229
     */
3299
    public function get_group_submission($userid, $groupid, $create, $attemptnumber = -1)
3230
    public function get_group_submission($userid, $groupid, $create, $attemptnumber=-1) {
3300
    {
-
 
3301
        global $DB;
3231
        global $DB;
Línea 3302... Línea 3232...
3302
 
3232
 
3303
        if ($groupid == 0) {
3233
        if ($groupid == 0) {
3304
            $group = $this->get_submission_group($userid);
3234
            $group = $this->get_submission_group($userid);
3305
            if ($group) {
3235
            if ($group) {
3306
                $groupid = $group->id;
3236
                $groupid = $group->id;
3307
            }
3237
            }
Línea 3308... Línea 3238...
3308
        }
3238
        }
3309
 
3239
 
3310
        // Now get the group submission.
3240
        // Now get the group submission.
3311
        $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
3241
        $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
3312
        if ($attemptnumber >= 0) {
3242
        if ($attemptnumber >= 0) {
Línea 3313... Línea 3243...
3313
            $params['attemptnumber'] = $attemptnumber;
3243
            $params['attemptnumber'] = $attemptnumber;
Línea 3344... Línea 3274...
3344
            } else {
3274
            } else {
3345
                $submission->attemptnumber = 0;
3275
                $submission->attemptnumber = 0;
3346
            }
3276
            }
3347
            // Work out if this is the latest submission.
3277
            // Work out if this is the latest submission.
3348
            $submission->latest = 0;
3278
            $submission->latest = 0;
3349
            $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
3279
            $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
3350
            if ($attemptnumber == -1) {
3280
            if ($attemptnumber == -1) {
3351
                // This is a new submission so it must be the latest.
3281
                // This is a new submission so it must be the latest.
3352
                $submission->latest = 1;
3282
                $submission->latest = 1;
3353
            } else {
3283
            } else {
3354
                // We need to work this out.
3284
                // We need to work this out.
Línea 3372... Línea 3302...
3372
        }
3302
        }
3373
        return false;
3303
        return false;
3374
    }
3304
    }
Línea 3375... Línea 3305...
3375
 
3305
 
3376
    /**
-
 
3377
     * View a summary listing of all assignments in the current course.
-
 
3378
     *
-
 
3379
     * @return string
-
 
3380
     */
-
 
3381
    private function view_course_index()
-
 
3382
    {
-
 
3383
        global $USER;
-
 
3384
 
-
 
3385
        $o = '';
-
 
3386
 
-
 
3387
        $course = $this->get_course();
-
 
3388
        $strplural = get_string('modulenameplural', 'assign');
-
 
3389
 
-
 
3390
        if (!$cms = get_coursemodules_in_course('assign', $course->id, 'm.duedate')) {
-
 
3391
            $o .= $this->get_renderer()->notification(get_string('thereareno', 'moodle', $strplural));
-
 
3392
            $o .= $this->get_renderer()->continue_button(new moodle_url('/course/view.php', array('id' => $course->id)));
-
 
3393
            return $o;
-
 
3394
        }
-
 
3395
 
-
 
3396
        $strsectionname = '';
-
 
3397
        $usesections = course_format_uses_sections($course->format);
-
 
3398
        $modinfo = get_fast_modinfo($course);
-
 
3399
 
-
 
3400
        if ($usesections) {
-
 
3401
            $strsectionname = get_string('sectionname', 'format_' . $course->format);
-
 
3402
            $sections = $modinfo->get_section_info_all();
-
 
3403
        }
-
 
3404
        $courseindexsummary = new assign_course_index_summary($usesections, $strsectionname);
-
 
3405
 
-
 
3406
        $timenow = time();
-
 
3407
 
-
 
3408
        $currentsection = '';
-
 
3409
        foreach ($modinfo->instances['assign'] as $cm) {
-
 
3410
            if (!$cm->uservisible) {
-
 
3411
                continue;
-
 
3412
            }
-
 
3413
 
-
 
3414
            $timedue = $cms[$cm->id]->duedate;
-
 
3415
 
-
 
3416
            $sectionname = '';
-
 
3417
            if ($usesections && $cm->sectionnum) {
-
 
3418
                $sectionname = get_section_name($course, $sections[$cm->sectionnum]);
-
 
3419
            }
-
 
3420
 
-
 
3421
            $submitted = '';
-
 
3422
            $context = context_module::instance($cm->id);
-
 
3423
 
-
 
3424
            $assignment = new assign($context, $cm, $course);
-
 
3425
 
-
 
3426
            // Apply overrides.
-
 
3427
            $assignment->update_effective_access($USER->id);
-
 
3428
            $timedue = $assignment->get_instance()->duedate;
-
 
3429
 
-
 
3430
            if (
-
 
3431
                has_capability('mod/assign:submit', $context) &&
-
 
3432
                !has_capability('moodle/site:config', $context)
-
 
3433
            ) {
-
 
3434
                $cangrade = false;
-
 
3435
                if ($assignment->get_instance()->teamsubmission) {
-
 
3436
                    $usersubmission = $assignment->get_group_submission($USER->id, 0, false);
-
 
3437
                } else {
-
 
3438
                    $usersubmission = $assignment->get_user_submission($USER->id, false);
-
 
3439
                }
-
 
3440
 
-
 
3441
                if (!empty($usersubmission->status)) {
-
 
3442
                    $submitted = get_string('submissionstatus_' . $usersubmission->status, 'assign');
-
 
3443
                } else {
-
 
3444
                    $submitted = get_string('submissionstatus_', 'assign');
-
 
3445
                }
-
 
3446
 
-
 
3447
                $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id);
-
 
3448
                if (
-
 
3449
                    isset($gradinginfo->items[0]->grades[$USER->id]) &&
-
 
3450
                    !$gradinginfo->items[0]->grades[$USER->id]->hidden
-
 
3451
                ) {
-
 
3452
                    $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade;
-
 
3453
                } else {
-
 
3454
                    $grade = '-';
-
 
3455
                }
-
 
3456
            } else if (has_capability('mod/assign:grade', $context)) {
-
 
3457
                $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
-
 
3458
                $grade = $assignment->count_submissions_need_grading();
-
 
3459
                $cangrade = true;
-
 
3460
            }
-
 
3461
 
-
 
3462
            $courseindexsummary->add_assign_info(
-
 
3463
                $cm->id,
-
 
3464
                $cm->get_formatted_name(),
-
 
3465
                $sectionname,
-
 
3466
                $timedue,
-
 
3467
                $submitted,
-
 
3468
                $grade,
-
 
3469
                $cangrade
-
 
3470
            );
-
 
3471
        }
-
 
3472
 
-
 
3473
        $o .= $this->get_renderer()->render($courseindexsummary);
-
 
3474
        $o .= $this->view_footer();
-
 
3475
 
-
 
3476
        return $o;
-
 
3477
    }
-
 
3478
 
-
 
3479
    /**
3306
    /**
3480
     * View a page rendered by a plugin.
3307
     * View a page rendered by a plugin.
3481
     *
3308
     *
3482
     * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'.
3309
     * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'.
3483
     *
3310
     *
3484
     * @return string
3311
     * @return string
3485
     */
3312
     */
3486
    protected function view_plugin_page()
-
 
3487
    {
3313
    protected function view_plugin_page() {
Línea 3488... Línea 3314...
3488
        global $USER;
3314
        global $USER;
Línea 3489... Línea 3315...
3489
 
3315
 
Línea 3510... Línea 3336...
3510
     * If the user is a member of multiple or no groups this will return false
3336
     * If the user is a member of multiple or no groups this will return false
3511
     *
3337
     *
3512
     * @param int $userid The id of the user whose submission we want
3338
     * @param int $userid The id of the user whose submission we want
3513
     * @return mixed The group or false
3339
     * @return mixed The group or false
3514
     */
3340
     */
3515
    public function get_submission_group($userid)
3341
    public function get_submission_group($userid) {
3516
    {
-
 
Línea 3517... Línea 3342...
3517
 
3342
 
3518
        if (isset($this->usersubmissiongroups[$userid])) {
3343
        if (isset($this->usersubmissiongroups[$userid])) {
3519
            return $this->usersubmissiongroups[$userid];
3344
            return $this->usersubmissiongroups[$userid];
Línea 3536... Línea 3361...
3536
     * Gets all groups the user is a member of.
3361
     * Gets all groups the user is a member of.
3537
     *
3362
     *
3538
     * @param int $userid Teh id of the user who's groups we are checking
3363
     * @param int $userid Teh id of the user who's groups we are checking
3539
     * @return array The group objects
3364
     * @return array The group objects
3540
     */
3365
     */
3541
    public function get_all_groups($userid)
3366
    public function get_all_groups($userid) {
3542
    {
-
 
3543
        if (isset($this->usergroups[$userid])) {
3367
        if (isset($this->usergroups[$userid])) {
3544
            return $this->usergroups[$userid];
3368
            return $this->usergroups[$userid];
3545
        }
3369
        }
Línea 3546... Línea 3370...
3546
 
3370
 
Línea 3559... Línea 3383...
3559
     * Uses url parameters 'sid', 'gid' and 'plugin'.
3383
     * Uses url parameters 'sid', 'gid' and 'plugin'.
3560
     *
3384
     *
3561
     * @param string $pluginsubtype
3385
     * @param string $pluginsubtype
3562
     * @return string
3386
     * @return string
3563
     */
3387
     */
3564
    protected function view_plugin_content($pluginsubtype)
3388
    protected function view_plugin_content($pluginsubtype) {
3565
    {
-
 
3566
        $o = '';
3389
        $o = '';
Línea 3567... Línea 3390...
3567
 
3390
 
3568
        $submissionid = optional_param('sid', 0, PARAM_INT);
3391
        $submissionid = optional_param('sid', 0, PARAM_INT);
3569
        $gradeid = optional_param('gid', 0, PARAM_INT);
3392
        $gradeid = optional_param('gid', 0, PARAM_INT);
Línea 3581... Línea 3404...
3581
                // Group submission.
3404
                // Group submission.
3582
                $this->require_view_group_submission($item->groupid);
3405
                $this->require_view_group_submission($item->groupid);
3583
            } else {
3406
            } else {
3584
                $this->require_view_submission($item->userid);
3407
                $this->require_view_submission($item->userid);
3585
            }
3408
            }
3586
            $o .= $this->get_renderer()->render(new assign_header(
3409
            $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3587
                $this->get_instance(),
-
 
3588
                $this->get_context(),
3410
                                                              $this->get_context(),
3589
                $this->show_intro(),
3411
                                                              $this->show_intro(),
3590
                $this->get_course_module()->id,
3412
                                                              $this->get_course_module()->id,
3591
                $plugin->get_name()
3413
                                                              $plugin->get_name()));
3592
            ));
-
 
3593
            $o .= $this->get_renderer()->render(new assign_submission_plugin_submission(
3414
            $o .= $this->get_renderer()->render(new assign_submission_plugin_submission($plugin,
3594
                $plugin,
-
 
3595
                $item,
3415
                                                              $item,
3596
                assign_submission_plugin_submission::FULL,
3416
                                                              assign_submission_plugin_submission::FULL,
3597
                $this->get_course_module()->id,
3417
                                                              $this->get_course_module()->id,
3598
                $this->get_return_action(),
3418
                                                              $this->get_return_action(),
3599
                $this->get_return_params()
3419
                                                              $this->get_return_params()));
3600
            ));
-
 
Línea 3601... Línea 3420...
3601
 
3420
 
3602
            // Trigger event for viewing a submission.
3421
            // Trigger event for viewing a submission.
-
 
3422
            \mod_assign\event\submission_viewed::create_from_submission($this, $item)->trigger();
3603
            \mod_assign\event\submission_viewed::create_from_submission($this, $item)->trigger();
3423
 
3604
        } else {
3424
        } else {
3605
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
3425
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
3606
            if ($gradeid <= 0) {
3426
            if ($gradeid <= 0) {
3607
                throw new coding_exception('Grade id should not be 0');
3427
                throw new coding_exception('Grade id should not be 0');
3608
            }
3428
            }
3609
            $item = $this->get_grade($gradeid);
3429
            $item = $this->get_grade($gradeid);
3610
            // Check permissions.
3430
            // Check permissions.
3611
            $this->require_view_submission($item->userid);
3431
            $this->require_view_submission($item->userid);
3612
            $o .= $this->get_renderer()->render(new assign_header(
-
 
3613
                $this->get_instance(),
3432
            $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3614
                $this->get_context(),
3433
                                                              $this->get_context(),
3615
                $this->show_intro(),
3434
                                                              $this->show_intro(),
3616
                $this->get_course_module()->id,
3435
                                                              $this->get_course_module()->id,
3617
                $plugin->get_name()
-
 
3618
            ));
3436
                                                              $plugin->get_name()));
3619
            $o .= $this->get_renderer()->render(new assign_feedback_plugin_feedback(
-
 
3620
                $plugin,
3437
            $o .= $this->get_renderer()->render(new assign_feedback_plugin_feedback($plugin,
3621
                $item,
3438
                                                              $item,
3622
                assign_feedback_plugin_feedback::FULL,
3439
                                                              assign_feedback_plugin_feedback::FULL,
3623
                $this->get_course_module()->id,
3440
                                                              $this->get_course_module()->id,
3624
                $this->get_return_action(),
3441
                                                              $this->get_return_action(),
3625
                $this->get_return_params()
-
 
Línea 3626... Línea 3442...
3626
            ));
3442
                                                              $this->get_return_params()));
3627
 
3443
 
3628
            // Trigger event for viewing feedback.
3444
            // Trigger event for viewing feedback.
Línea 3641... Línea 3457...
3641
     *
3457
     *
3642
     * @param string $text - The replacement text
3458
     * @param string $text - The replacement text
3643
     * @param stdClass $user - The user record
3459
     * @param stdClass $user - The user record
3644
     * @param assign_plugin $plugin - The assignment plugin
3460
     * @param assign_plugin $plugin - The assignment plugin
3645
     */
3461
     */
3646
    public function download_rewrite_pluginfile_urls($text, $user, $plugin)
3462
    public function download_rewrite_pluginfile_urls($text, $user, $plugin) {
3647
    {
-
 
3648
        // The groupname prefix for the urls doesn't depend on the group mode of the assignment instance.
3463
        // The groupname prefix for the urls doesn't depend on the group mode of the assignment instance.
3649
        // Rather, it should be determined by checking the group submission settings of the instance,
3464
        // Rather, it should be determined by checking the group submission settings of the instance,
3650
        // which is what download_submission() does when generating the file name prefixes.
3465
        // which is what download_submission() does when generating the file name prefixes.
3651
        $groupname = '';
3466
        $groupname = '';
3652
        if ($this->get_instance()->teamsubmission) {
3467
        if ($this->get_instance()->teamsubmission) {
Línea 3690... Línea 3505...
3690
     * @param string $editor
3505
     * @param string $editor
3691
     * @param string $component
3506
     * @param string $component
3692
     * @param bool $shortentext Whether to shorten the text content.
3507
     * @param bool $shortentext Whether to shorten the text content.
3693
     * @return string
3508
     * @return string
3694
     */
3509
     */
3695
    public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false)
3510
    public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false) {
3696
    {
-
 
3697
        global $CFG;
3511
        global $CFG;
Línea 3698... Línea 3512...
3698
 
3512
 
Línea 3699... Línea 3513...
3699
        $result = '';
3513
        $result = '';
Línea 3704... Línea 3518...
3704
        if ($shortentext) {
3518
        if ($shortentext) {
3705
            $text = shorten_text($text, 140);
3519
            $text = shorten_text($text, 140);
3706
        }
3520
        }
3707
        $format = $plugin->get_editor_format($editor, $submissionid);
3521
        $format = $plugin->get_editor_format($editor, $submissionid);
Línea 3708... Línea 3522...
3708
 
3522
 
3709
        $finaltext = file_rewrite_pluginfile_urls(
-
 
3710
            $text,
3523
        $finaltext = file_rewrite_pluginfile_urls($text,
3711
            'pluginfile.php',
3524
                                                  'pluginfile.php',
3712
            $this->get_context()->id,
3525
                                                  $this->get_context()->id,
3713
            $component,
3526
                                                  $component,
3714
            $filearea,
3527
                                                  $filearea,
3715
            $submissionid
-
 
3716
        );
3528
                                                  $submissionid);
3717
        $params = array('overflowdiv' => true, 'context' => $this->get_context());
3529
        $params = array('overflowdiv' => true, 'context' => $this->get_context());
Línea 3718... Línea 3530...
3718
        $result .= format_text($finaltext, $format, $params);
3530
        $result .= format_text($finaltext, $format, $params);
3719
 
3531
 
Línea 3720... Línea 3532...
3720
        if ($CFG->enableportfolios && has_capability('mod/assign:exportownsubmission', $this->context)) {
3532
        if ($CFG->enableportfolios && has_capability('mod/assign:exportownsubmission', $this->context)) {
3721
            require_once($CFG->libdir . '/portfoliolib.php');
-
 
3722
 
3533
            require_once($CFG->libdir . '/portfoliolib.php');
3723
            $button = new portfolio_add_button();
3534
 
3724
            $portfolioparams = array(
3535
            $button = new portfolio_add_button();
3725
                'cmid' => $this->get_course_module()->id,
3536
            $portfolioparams = array('cmid' => $this->get_course_module()->id,
3726
                'sid' => $submissionid,
3537
                                     'sid' => $submissionid,
3727
                'plugin' => $plugintype,
-
 
3728
                'editor' => $editor,
3538
                                     'plugin' => $plugintype,
3729
                'area' => $filearea
3539
                                     'editor' => $editor,
Línea 3730... Línea 3540...
3730
            );
3540
                                     'area'=>$filearea);
3731
            $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign');
-
 
3732
            $fs = get_file_storage();
3541
            $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign');
3733
 
3542
            $fs = get_file_storage();
3734
            if ($files = $fs->get_area_files(
3543
 
3735
                $this->context->id,
3544
            if ($files = $fs->get_area_files($this->context->id,
3736
                $component,
3545
                                             $component,
3737
                $filearea,
-
 
3738
                $submissionid,
3546
                                             $filearea,
3739
                'timemodified',
3547
                                             $submissionid,
3740
                false
3548
                                             'timemodified',
3741
            )) {
3549
                                             false)) {
3742
                $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
3550
                $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
Línea 3752... Línea 3560...
3752
     * Display a continue page after grading.
3560
     * Display a continue page after grading.
3753
     *
3561
     *
3754
     * @param string $message - The message to display.
3562
     * @param string $message - The message to display.
3755
     * @return string
3563
     * @return string
3756
     */
3564
     */
3757
    protected function view_savegrading_result($message)
3565
    protected function view_savegrading_result($message) {
3758
    {
-
 
3759
        $o = '';
3566
        $o = '';
3760
        $o .= $this->get_renderer()->render(new assign_header(
3567
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3761
            $this->get_instance(),
-
 
3762
            $this->get_context(),
3568
                                                      $this->get_context(),
3763
            $this->show_intro(),
3569
                                                      $this->show_intro(),
3764
            $this->get_course_module()->id,
3570
                                                      $this->get_course_module()->id,
3765
            get_string('savegradingresult', 'assign')
3571
                                                      get_string('savegradingresult', 'assign')));
3766
        ));
-
 
3767
        $gradingresult = new assign_gradingmessage(
3572
        $gradingresult = new assign_gradingmessage(get_string('savegradingresult', 'assign'),
3768
            get_string('savegradingresult', 'assign'),
3573
                                                   $message,
3769
            $message,
-
 
3770
            $this->get_course_module()->id
3574
                                                   $this->get_course_module()->id);
3771
        );
-
 
3772
        $o .= $this->get_renderer()->render($gradingresult);
3575
        $o .= $this->get_renderer()->render($gradingresult);
3773
        $o .= $this->view_footer();
3576
        $o .= $this->view_footer();
3774
        return $o;
3577
        return $o;
3775
    }
3578
    }
3776
    /**
3579
    /**
3777
     * Display a continue page after quickgrading.
3580
     * Display a continue page after quickgrading.
3778
     *
3581
     *
3779
     * @param string $message - The message to display.
3582
     * @param string $message - The message to display.
3780
     * @return string
3583
     * @return string
3781
     */
3584
     */
3782
    protected function view_quickgrading_result($message)
3585
    protected function view_quickgrading_result($message) {
3783
    {
-
 
3784
        $o = '';
3586
        $o = '';
3785
        $o .= $this->get_renderer()->render(new assign_header(
3587
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3786
            $this->get_instance(),
-
 
3787
            $this->get_context(),
3588
                                                      $this->get_context(),
3788
            $this->show_intro(),
3589
                                                      $this->show_intro(),
3789
            $this->get_course_module()->id,
3590
                                                      $this->get_course_module()->id,
3790
            get_string('quickgradingresult', 'assign')
3591
                                                      get_string('quickgradingresult', 'assign')));
3791
        ));
-
 
3792
        $gradingerror = in_array($message, $this->get_error_messages());
3592
        $gradingerror = in_array($message, $this->get_error_messages());
3793
        $lastpage = optional_param('lastpage', null, PARAM_INT);
3593
        $lastpage = optional_param('lastpage', null, PARAM_INT);
3794
        $gradingresult = new assign_gradingmessage(
3594
        $gradingresult = new assign_gradingmessage(get_string('quickgradingresult', 'assign'),
3795
            get_string('quickgradingresult', 'assign'),
3595
                                                   $message,
3796
            $message,
-
 
3797
            $this->get_course_module()->id,
3596
                                                   $this->get_course_module()->id,
3798
            $gradingerror,
3597
                                                   $gradingerror,
3799
            $lastpage
3598
                                                   $lastpage);
3800
        );
-
 
3801
        $o .= $this->get_renderer()->render($gradingresult);
3599
        $o .= $this->get_renderer()->render($gradingresult);
3802
        $o .= $this->view_footer();
3600
        $o .= $this->view_footer();
3803
        return $o;
3601
        return $o;
3804
    }
3602
    }
Línea 3805... Línea 3603...
3805
 
3603
 
3806
    /**
3604
    /**
3807
     * Display the page footer.
3605
     * Display the page footer.
3808
     *
3606
     *
3809
     * @return string
3607
     * @return string
3810
     */
3608
     */
3811
    protected function view_footer()
-
 
3812
    {
3609
    protected function view_footer() {
3813
        // When viewing the footer during PHPUNIT tests a set_state error is thrown.
3610
        // When viewing the footer during PHPUNIT tests a set_state error is thrown.
3814
        if (!PHPUNIT_TEST) {
3611
        if (!PHPUNIT_TEST) {
3815
            return $this->get_renderer()->render_footer();
3612
            return $this->get_renderer()->render_footer();
Línea 3822... Línea 3619...
3822
     * Throw an error if the permissions to view this users' group submission are missing.
3619
     * Throw an error if the permissions to view this users' group submission are missing.
3823
     *
3620
     *
3824
     * @param int $groupid Group id.
3621
     * @param int $groupid Group id.
3825
     * @throws required_capability_exception
3622
     * @throws required_capability_exception
3826
     */
3623
     */
3827
    public function require_view_group_submission($groupid)
3624
    public function require_view_group_submission($groupid) {
3828
    {
-
 
3829
        if (!$this->can_view_group_submission($groupid)) {
3625
        if (!$this->can_view_group_submission($groupid)) {
3830
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3626
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3831
        }
3627
        }
3832
    }
3628
    }
Línea 3835... Línea 3631...
3835
     * Throw an error if the permissions to view this users submission are missing.
3631
     * Throw an error if the permissions to view this users submission are missing.
3836
     *
3632
     *
3837
     * @throws required_capability_exception
3633
     * @throws required_capability_exception
3838
     * @return none
3634
     * @return none
3839
     */
3635
     */
3840
    public function require_view_submission($userid)
3636
    public function require_view_submission($userid) {
3841
    {
-
 
3842
        if (!$this->can_view_submission($userid)) {
3637
        if (!$this->can_view_submission($userid)) {
3843
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3638
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3844
        }
3639
        }
3845
    }
3640
    }
Línea 3848... Línea 3643...
3848
     * Throw an error if the permissions to view grades in this assignment are missing.
3643
     * Throw an error if the permissions to view grades in this assignment are missing.
3849
     *
3644
     *
3850
     * @throws required_capability_exception
3645
     * @throws required_capability_exception
3851
     * @return none
3646
     * @return none
3852
     */
3647
     */
3853
    public function require_view_grades()
3648
    public function require_view_grades() {
3854
    {
-
 
3855
        if (!$this->can_view_grades()) {
3649
        if (!$this->can_view_grades()) {
3856
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3650
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3857
        }
3651
        }
3858
    }
3652
    }
Línea 3861... Línea 3655...
3861
     * Does this user have view grade or grade permission for this assignment?
3655
     * Does this user have view grade or grade permission for this assignment?
3862
     *
3656
     *
3863
     * @param mixed $groupid int|null when is set to a value, use this group instead calculating it
3657
     * @param mixed $groupid int|null when is set to a value, use this group instead calculating it
3864
     * @return bool
3658
     * @return bool
3865
     */
3659
     */
3866
    public function can_view_grades($groupid = null)
3660
    public function can_view_grades($groupid = null) {
3867
    {
-
 
3868
        // Permissions check.
3661
        // Permissions check.
3869
        if (!has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) {
3662
        if (!has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) {
3870
            return false;
3663
            return false;
3871
        }
3664
        }
3872
        // Checks for the edge case when user belongs to no groups and groupmode is sep.
3665
        // Checks for the edge case when user belongs to no groups and groupmode is sep.
Línea 3885... Línea 3678...
3885
     * Does this user have grade permission for this assignment?
3678
     * Does this user have grade permission for this assignment?
3886
     *
3679
     *
3887
     * @param int|stdClass $user The object or id of the user who will do the editing (default to current user).
3680
     * @param int|stdClass $user The object or id of the user who will do the editing (default to current user).
3888
     * @return bool
3681
     * @return bool
3889
     */
3682
     */
3890
    public function can_grade($user = null)
3683
    public function can_grade($user = null) {
3891
    {
-
 
3892
        // Permissions check.
3684
        // Permissions check.
3893
        if (!has_capability('mod/assign:grade', $this->context, $user)) {
3685
        if (!has_capability('mod/assign:grade', $this->context, $user)) {
3894
            return false;
3686
            return false;
3895
        }
3687
        }
Línea 3898... Línea 3690...
3898
    }
3690
    }
Línea 3899... Línea 3691...
3899
 
3691
 
3900
    /**
3692
    /**
3901
     * Download a zip file of all assignment submissions.
3693
     * Download a zip file of all assignment submissions.
3902
     *
3694
     *
3903
     * @param array|null $userids Array of user ids to download assignment submissions in a zip file
3695
     * @param int[]|null $userids Array of user ids to download assignment submissions in a zip file
3904
     * @return string - If an error occurs, this will contain the error page.
3696
     * @return string - If an error occurs, this will contain the error page.
3905
     */
3697
     */
3906
    protected function download_submissions($userids = null)
-
 
3907
    {
3698
    protected function download_submissions($userids = null) {
3908
        $downloader = new downloader($this, $userids ?: null);
3699
        $downloader = new downloader($this, $userids ?: null);
3909
        if ($downloader->load_filelist()) {
3700
        if ($downloader->load_filelist()) {
3910
            $downloader->download_zip();
3701
            $downloader->download_zip();
3911
        }
3702
        }
Línea 3926... Línea 3717...
3926
        $result .= $this->view_footer();
3717
        $result .= $this->view_footer();
3927
        return $result;
3718
        return $result;
3928
    }
3719
    }
Línea 3929... Línea 3720...
3929
 
3720
 
3930
    /**
-
 
3931
     * @deprecated since 2.7 - Use new events system instead.
-
 
3932
     */
-
 
3933
    public function add_to_log()
-
 
3934
    {
-
 
3935
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
-
 
3936
    }
-
 
3937
 
-
 
3938
    /**
3721
    /**
3939
     * Lazy load the page renderer and expose the renderer to plugins.
3722
     * Lazy load the page renderer and expose the renderer to plugins.
3940
     *
3723
     *
3941
     * @return assign_renderer
3724
     * @return assign_renderer
3942
     */
3725
     */
3943
    public function get_renderer()
-
 
3944
    {
3726
    public function get_renderer() {
3945
        global $PAGE;
3727
        global $PAGE;
3946
        if ($this->output) {
3728
        if ($this->output) {
3947
            return $this->output;
3729
            return $this->output;
3948
        }
3730
        }
Línea 3960... Línea 3742...
3960
     * @param int $userid The id of the user whose submission we want or 0 in which case USER->id is used
3742
     * @param int $userid The id of the user whose submission we want or 0 in which case USER->id is used
3961
     * @param bool $create If set to true a new submission object will be created in the database with the status set to "new".
3743
     * @param bool $create If set to true a new submission object will be created in the database with the status set to "new".
3962
     * @param int $attemptnumber - -1 means the latest attempt
3744
     * @param int $attemptnumber - -1 means the latest attempt
3963
     * @return stdClass|false The submission
3745
     * @return stdClass|false The submission
3964
     */
3746
     */
3965
    public function get_user_submission($userid, $create, $attemptnumber = -1)
3747
    public function get_user_submission($userid, $create, $attemptnumber=-1) {
3966
    {
-
 
3967
        global $DB, $USER;
3748
        global $DB, $USER;
Línea 3968... Línea 3749...
3968
 
3749
 
3969
        if (!$userid) {
3750
        if (!$userid) {
3970
            $userid = $USER->id;
3751
            $userid = $USER->id;
3971
        }
3752
        }
3972
        // If the userid is not null then use userid.
3753
        // If the userid is not null then use userid.
3973
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid, 'groupid' => 0);
3754
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid, 'groupid'=>0);
3974
        if ($attemptnumber >= 0) {
3755
        if ($attemptnumber >= 0) {
3975
            $params['attemptnumber'] = $attemptnumber;
3756
            $params['attemptnumber'] = $attemptnumber;
Línea 3976... Línea 3757...
3976
        }
3757
        }
Línea 4006... Línea 3787...
4006
            } else {
3787
            } else {
4007
                $submission->attemptnumber = 0;
3788
                $submission->attemptnumber = 0;
4008
            }
3789
            }
4009
            // Work out if this is the latest submission.
3790
            // Work out if this is the latest submission.
4010
            $submission->latest = 0;
3791
            $submission->latest = 0;
4011
            $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid, 'groupid' => 0);
3792
            $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid, 'groupid'=>0);
4012
            if ($attemptnumber == -1) {
3793
            if ($attemptnumber == -1) {
4013
                // This is a new submission so it must be the latest.
3794
                // This is a new submission so it must be the latest.
4014
                $submission->latest = 1;
3795
                $submission->latest = 1;
4015
            } else {
3796
            } else {
4016
                // We need to work this out.
3797
                // We need to work this out.
Línea 4039... Línea 3820...
4039
     * Load the submission object from it's id.
3820
     * Load the submission object from it's id.
4040
     *
3821
     *
4041
     * @param int $submissionid The id of the submission we want
3822
     * @param int $submissionid The id of the submission we want
4042
     * @return stdClass The submission
3823
     * @return stdClass The submission
4043
     */
3824
     */
4044
    protected function get_submission($submissionid)
3825
    protected function get_submission($submissionid) {
4045
    {
-
 
4046
        global $DB;
3826
        global $DB;
Línea 4047... Línea 3827...
4047
 
3827
 
4048
        $params = array('assignment' => $this->get_instance()->id, 'id' => $submissionid);
3828
        $params = array('assignment'=>$this->get_instance()->id, 'id'=>$submissionid);
4049
        return $DB->get_record('assign_submission', $params, '*', MUST_EXIST);
3829
        return $DB->get_record('assign_submission', $params, '*', MUST_EXIST);
Línea 4050... Línea 3830...
4050
    }
3830
    }
4051
 
3831
 
Línea 4055... Línea 3835...
4055
     *
3835
     *
4056
     * @param int $userid The user we are getting the flags for.
3836
     * @param int $userid The user we are getting the flags for.
4057
     * @param bool $create If true the flags record will be created if it does not exist
3837
     * @param bool $create If true the flags record will be created if it does not exist
4058
     * @return stdClass The flags record
3838
     * @return stdClass The flags record
4059
     */
3839
     */
4060
    public function get_user_flags($userid, $create)
3840
    public function get_user_flags($userid, $create) {
4061
    {
-
 
4062
        global $DB, $USER;
3841
        global $DB, $USER;
Línea 4063... Línea 3842...
4063
 
3842
 
4064
        // If the userid is not null then use userid.
3843
        // If the userid is not null then use userid.
4065
        if (!$userid) {
3844
        if (!$userid) {
4066
            $userid = $USER->id;
3845
            $userid = $USER->id;
Línea 4067... Línea 3846...
4067
        }
3846
        }
Línea 4068... Línea 3847...
4068
 
3847
 
Línea 4069... Línea 3848...
4069
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
3848
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
4070
 
3849
 
Línea 4099... Línea 3878...
4099
     * @param int $userid The user we are grading
3878
     * @param int $userid The user we are grading
4100
     * @param bool $create If true the grade will be created if it does not exist
3879
     * @param bool $create If true the grade will be created if it does not exist
4101
     * @param int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.
3880
     * @param int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.
4102
     * @return stdClass The grade record
3881
     * @return stdClass The grade record
4103
     */
3882
     */
4104
    public function get_user_grade($userid, $create, $attemptnumber = -1)
3883
    public function get_user_grade($userid, $create, $attemptnumber=-1) {
4105
    {
-
 
4106
        global $DB, $USER;
3884
        global $DB, $USER;
Línea 4107... Línea 3885...
4107
 
3885
 
4108
        // If the userid is not null then use userid.
3886
        // If the userid is not null then use userid.
4109
        if (!$userid) {
3887
        if (!$userid) {
4110
            $userid = $USER->id;
3888
            $userid = $USER->id;
4111
        }
3889
        }
Línea 4112... Línea 3890...
4112
        $submission = null;
3890
        $submission = null;
4113
 
3891
 
4114
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
3892
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
4115
        if ($attemptnumber < 0 || $create) {
3893
        if ($attemptnumber < 0 || $create) {
4116
            // Make sure this grade matches the latest submission attempt.
3894
            // Make sure this grade matches the latest submission attempt.
4117
            if ($this->get_instance()->teamsubmission) {
3895
            if ($this->get_instance()->teamsubmission) {
Línea 4150... Línea 3928...
4150
            // Do not set the grader id here as it would be the admin users which is incorrect.
3928
            // Do not set the grader id here as it would be the admin users which is incorrect.
4151
            $grade->grader = -1;
3929
            $grade->grader = -1;
4152
            if ($attemptnumber >= 0) {
3930
            if ($attemptnumber >= 0) {
4153
                $grade->attemptnumber = $attemptnumber;
3931
                $grade->attemptnumber = $attemptnumber;
4154
            }
3932
            }
-
 
3933
            $grade->penalty = 0.0;
Línea 4155... Línea 3934...
4155
 
3934
 
4156
            $gid = $DB->insert_record('assign_grades', $grade);
3935
            $gid = $DB->insert_record('assign_grades', $grade);
4157
            $grade->id = $gid;
3936
            $grade->id = $gid;
4158
            return $grade;
3937
            return $grade;
Línea 4164... Línea 3943...
4164
     * This will retrieve a grade object from the db.
3943
     * This will retrieve a grade object from the db.
4165
     *
3944
     *
4166
     * @param int $gradeid The id of the grade
3945
     * @param int $gradeid The id of the grade
4167
     * @return stdClass The grade record
3946
     * @return stdClass The grade record
4168
     */
3947
     */
4169
    protected function get_grade($gradeid)
3948
    protected function get_grade($gradeid) {
4170
    {
-
 
4171
        global $DB;
3949
        global $DB;
Línea 4172... Línea 3950...
4172
 
3950
 
4173
        $params = array('assignment' => $this->get_instance()->id, 'id' => $gradeid);
3951
        $params = array('assignment'=>$this->get_instance()->id, 'id'=>$gradeid);
4174
        return $DB->get_record('assign_grades', $params, '*', MUST_EXIST);
3952
        return $DB->get_record('assign_grades', $params, '*', MUST_EXIST);
Línea 4175... Línea 3953...
4175
    }
3953
    }
4176
 
3954
 
4177
    /**
3955
    /**
4178
     * Print the grading page for a single user submission.
3956
     * Print the grading page for a single user submission.
4179
     *
3957
     *
4180
     * @param array $args Optional args array (better than pulling args from _GET and _POST)
3958
     * @param array $args Optional args array (better than pulling args from _GET and _POST)
4181
     * @return string
3959
     * @return string
4182
     */
-
 
4183
    protected function view_single_grading_panel($args)
3960
     */
Línea 4184... Línea 3961...
4184
    {
3961
    protected function view_single_grading_panel($args) {
Línea 4185... Línea 3962...
4185
        global $DB, $CFG;
3962
        global $DB, $CFG;
Línea 4219... Línea 3996...
4219
            $groupid = 0;
3996
            $groupid = 0;
4220
            if ($submissiongroup) {
3997
            if ($submissiongroup) {
4221
                $groupid = $submissiongroup->id;
3998
                $groupid = $submissiongroup->id;
4222
            }
3999
            }
4223
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4000
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
-
 
4001
 
4224
        }
4002
        }
Línea 4225... Línea 4003...
4225
 
4003
 
4226
        // Get the requested grade.
4004
        // Get the requested grade.
4227
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
4005
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
Línea 4234... Línea 4012...
4234
            }
4012
            }
4235
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4013
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4236
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4014
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4237
            $usergroups = $this->get_all_groups($user->id);
4015
            $usergroups = $this->get_all_groups($user->id);
Línea 4238... Línea 4016...
4238
 
4016
 
4239
            $submissionstatus = new assign_submission_status_compact(
-
 
4240
                $instance->allowsubmissionsfromdate,
4017
            $submissionstatus = new assign_submission_status_compact($instance->allowsubmissionsfromdate,
4241
                $instance->alwaysshowdescription,
4018
                                                                     $instance->alwaysshowdescription,
4242
                $submission,
4019
                                                                     $submission,
4243
                $instance->teamsubmission,
4020
                                                                     $instance->teamsubmission,
4244
                $teamsubmission,
4021
                                                                     $teamsubmission,
4245
                $submissiongroup,
4022
                                                                     $submissiongroup,
4246
                $notsubmitted,
4023
                                                                     $notsubmitted,
4247
                $this->is_any_submission_plugin_enabled(),
4024
                                                                     $this->is_any_submission_plugin_enabled(),
4248
                $submissionlocked,
4025
                                                                     $submissionlocked,
4249
                $this->is_graded($userid),
4026
                                                                     $this->is_graded($userid),
4250
                $instance->duedate,
4027
                                                                     $instance->duedate,
4251
                $instance->cutoffdate,
4028
                                                                     $instance->cutoffdate,
4252
                $this->get_submission_plugins(),
4029
                                                                     $this->get_submission_plugins(),
4253
                $this->get_return_action(),
4030
                                                                     $this->get_return_action(),
4254
                $this->get_return_params(),
4031
                                                                     $this->get_return_params(),
4255
                $this->get_course_module()->id,
4032
                                                                     $this->get_course_module()->id,
4256
                $this->get_course()->id,
4033
                                                                     $this->get_course()->id,
4257
                assign_submission_status::GRADER_VIEW,
4034
                                                                     assign_submission_status::GRADER_VIEW,
4258
                $showedit,
4035
                                                                     $showedit,
4259
                false,
4036
                                                                     false,
4260
                $viewfullnames,
4037
                                                                     $viewfullnames,
4261
                $extensionduedate,
4038
                                                                     $extensionduedate,
4262
                $this->get_context(),
4039
                                                                     $this->get_context(),
4263
                $this->is_blind_marking(),
4040
                                                                     $this->is_blind_marking(),
4264
                '',
4041
                                                                     '',
4265
                $instance->attemptreopenmethod,
4042
                                                                     $instance->attemptreopenmethod,
4266
                $instance->maxattempts,
4043
                                                                     $instance->maxattempts,
4267
                $this->get_grading_status($userid),
4044
                                                                     $this->get_grading_status($userid),
4268
                $instance->preventsubmissionnotingroup,
4045
                                                                     $instance->preventsubmissionnotingroup,
4269
                $usergroups,
4046
                                                                     $usergroups,
4270
                $instance->timelimit
-
 
4271
            );
4047
                                                                     $instance->timelimit);
4272
            $o .= $this->get_renderer()->render($submissionstatus);
4048
            $o .= $this->get_renderer()->render($submissionstatus);
Línea 4273... Línea 4049...
4273
        }
4049
        }
4274
 
4050
 
Línea 4291... Línea 4067...
4291
 
4067
 
4292
        // Warning if required.
4068
        // Warning if required.
Línea 4293... Línea 4069...
4293
        $allsubmissions = $this->get_all_submissions($userid);
4069
        $allsubmissions = $this->get_all_submissions($userid);
4294
 
-
 
4295
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4070
 
4296
            $params = array(
4071
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4297
                'attemptnumber' => $attemptnumber + 1,
-
 
4298
                'totalattempts' => count($allsubmissions)
4072
            $params = array('attemptnumber' => $attemptnumber + 1,
4299
            );
4073
                            'totalattempts' => count($allsubmissions));
4300
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
4074
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
Línea 4301... Línea -...
4301
            $o .= $this->get_renderer()->notification($message);
-
 
4302
        }
4075
            $o .= $this->get_renderer()->notification($message);
4303
 
4076
        }
4304
        $pagination = array(
4077
 
4305
            'rownum' => $rownum,
4078
        $pagination = array('rownum' => $rownum,
4306
            'useridlistid' => 0,
4079
                            'useridlistid' => 0,
4307
            'last' => $last,
4080
                            'last' => $last,
4308
            'userid' => $userid,
-
 
Línea 4309... Línea 4081...
4309
            'attemptnumber' => $attemptnumber,
4081
                            'userid' => $userid,
4310
            'gradingpanel' => true
4082
                            'attemptnumber' => $attemptnumber,
4311
        );
4083
                            'gradingpanel' => true);
4312
 
4084
 
4313
        if (!empty($args['formdata'])) {
4085
        if (!empty($args['formdata'])) {
4314
            $data = (array) $data;
4086
            $data = (array) $data;
4315
            $data = (object) array_merge($data, $args['formdata']);
-
 
4316
        }
4087
            $data = (object) array_merge($data, $args['formdata']);
4317
        $formparams = array($this, $data, $pagination);
4088
        }
4318
        $mform = new mod_assign_grade_form(
4089
        $formparams = array($this, $data, $pagination);
4319
            null,
4090
        $mform = new mod_assign_grade_form(null,
4320
            $formparams,
-
 
Línea 4321... Línea 4091...
4321
            'post',
4091
                                           $formparams,
4322
            '',
4092
                                           'post',
4323
            array('class' => 'gradeform')
4093
                                           '',
4324
        );
4094
                                           array('class' => 'gradeform'));
Línea 4331... Línea 4101...
4331
 
4101
 
Línea 4332... Línea 4102...
4332
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4102
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4333
 
4103
 
4334
        if (count($allsubmissions) > 1) {
4104
        if (count($allsubmissions) > 1) {
4335
            $allgrades = $this->get_all_grades($userid);
-
 
4336
            $history = new assign_attempt_history_chooser(
4105
            $allgrades = $this->get_all_grades($userid);
4337
                $allsubmissions,
4106
            $history = new assign_attempt_history_chooser($allsubmissions,
4338
                $allgrades,
4107
                                                          $allgrades,
4339
                $this->get_course_module()->id,
-
 
Línea 4340... Línea 4108...
4340
                $userid
4108
                                                          $this->get_course_module()->id,
4341
            );
4109
                                                          $userid);
Línea 4342... Línea 4110...
4342
 
4110
 
Línea 4352... Línea 4120...
4352
     * Print the grading page for a single user submission.
4120
     * Print the grading page for a single user submission.
4353
     *
4121
     *
4354
     * @param moodleform $mform
4122
     * @param moodleform $mform
4355
     * @return string
4123
     * @return string
4356
     */
4124
     */
4357
    protected function view_single_grade_page($mform)
4125
    protected function view_single_grade_page($mform) {
4358
    {
-
 
4359
        global $DB, $CFG, $SESSION;
4126
        global $DB, $CFG, $SESSION;
Línea 4360... Línea 4127...
4360
 
4127
 
4361
        $o = '';
4128
        $o = '';
Línea 4362... Línea 4129...
4362
        $instance = $this->get_instance();
4129
        $instance = $this->get_instance();
Línea 4363... Línea 4130...
4363
 
4130
 
4364
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
4131
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
Línea 4365... Línea 4132...
4365
 
4132
 
4366
        // Need submit permission to submit an assignment.
-
 
4367
        require_capability('mod/assign:grade', $this->context);
4133
        // Need submit permission to submit an assignment.
4368
 
4134
        require_capability('mod/assign:grade', $this->context);
4369
        $header = new assign_header(
4135
 
4370
            $instance,
4136
        $header = new assign_header($instance,
4371
            $this->get_context(),
-
 
4372
            false,
4137
                                    $this->get_context(),
Línea 4373... Línea 4138...
4373
            $this->get_course_module()->id,
4138
                                    false,
4374
            get_string('grading', 'assign')
4139
                                    $this->get_course_module()->id,
4375
        );
4140
                                    get_string('grading', 'assign'));
Línea 4405... Línea 4170...
4405
 
4170
 
4406
        $user = $DB->get_record('user', array('id' => $userid));
4171
        $user = $DB->get_record('user', array('id' => $userid));
4407
        if ($user) {
4172
        if ($user) {
4408
            $this->update_effective_access($userid);
4173
            $this->update_effective_access($userid);
4409
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4174
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4410
            $usersummary = new assign_user_summary(
-
 
4411
                $user,
4175
            $usersummary = new assign_user_summary($user,
4412
                $this->get_course()->id,
4176
                                                   $this->get_course()->id,
4413
                $viewfullnames,
4177
                                                   $viewfullnames,
4414
                $this->is_blind_marking(),
4178
                                                   $this->is_blind_marking(),
4415
                $this->get_uniqueid_for_user($user->id),
4179
                                                   $this->get_uniqueid_for_user($user->id),
4416
                // TODO Does not support custom user profile fields (MDL-70456).
4180
                                                   // TODO Does not support custom user profile fields (MDL-70456).
4417
                \core_user\fields::get_identity_fields($this->get_context(), false),
4181
                                                   \core_user\fields::get_identity_fields($this->get_context(), false),
4418
                !$this->is_active_user($userid)
-
 
4419
            );
4182
                                                   !$this->is_active_user($userid));
4420
            $o .= $this->get_renderer()->render($usersummary);
4183
            $o .= $this->get_renderer()->render($usersummary);
4421
        }
4184
        }
4422
        $submission = $this->get_user_submission($userid, false, $attemptnumber);
4185
        $submission = $this->get_user_submission($userid, false, $attemptnumber);
4423
        $submissiongroup = null;
4186
        $submissiongroup = null;
Línea 4429... Línea 4192...
4429
            $groupid = 0;
4192
            $groupid = 0;
4430
            if ($submissiongroup) {
4193
            if ($submissiongroup) {
4431
                $groupid = $submissiongroup->id;
4194
                $groupid = $submissiongroup->id;
4432
            }
4195
            }
4433
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4196
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
-
 
4197
 
4434
        }
4198
        }
Línea 4435... Línea 4199...
4435
 
4199
 
4436
        // Get the requested grade.
4200
        // Get the requested grade.
4437
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
4201
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
Línea 4443... Línea 4207...
4443
                $extensionduedate = $flags->extensionduedate;
4207
                $extensionduedate = $flags->extensionduedate;
4444
            }
4208
            }
4445
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4209
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4446
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4210
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4447
            $usergroups = $this->get_all_groups($user->id);
4211
            $usergroups = $this->get_all_groups($user->id);
4448
            $submissionstatus = new assign_submission_status(
4212
            $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
4449
                $instance->allowsubmissionsfromdate,
-
 
4450
                $instance->alwaysshowdescription,
4213
                                                             $instance->alwaysshowdescription,
4451
                $submission,
4214
                                                             $submission,
4452
                $instance->teamsubmission,
4215
                                                             $instance->teamsubmission,
4453
                $teamsubmission,
4216
                                                             $teamsubmission,
4454
                $submissiongroup,
4217
                                                             $submissiongroup,
4455
                $notsubmitted,
4218
                                                             $notsubmitted,
4456
                $this->is_any_submission_plugin_enabled(),
4219
                                                             $this->is_any_submission_plugin_enabled(),
4457
                $submissionlocked,
4220
                                                             $submissionlocked,
4458
                $this->is_graded($userid),
4221
                                                             $this->is_graded($userid),
4459
                $instance->duedate,
4222
                                                             $instance->duedate,
4460
                $instance->cutoffdate,
4223
                                                             $instance->cutoffdate,
4461
                $this->get_submission_plugins(),
4224
                                                             $this->get_submission_plugins(),
4462
                $this->get_return_action(),
4225
                                                             $this->get_return_action(),
4463
                $this->get_return_params(),
4226
                                                             $this->get_return_params(),
4464
                $this->get_course_module()->id,
4227
                                                             $this->get_course_module()->id,
4465
                $this->get_course()->id,
4228
                                                             $this->get_course()->id,
4466
                assign_submission_status::GRADER_VIEW,
4229
                                                             assign_submission_status::GRADER_VIEW,
4467
                $showedit,
4230
                                                             $showedit,
4468
                false,
4231
                                                             false,
4469
                $viewfullnames,
4232
                                                             $viewfullnames,
4470
                $extensionduedate,
4233
                                                             $extensionduedate,
4471
                $this->get_context(),
4234
                                                             $this->get_context(),
4472
                $this->is_blind_marking(),
4235
                                                             $this->is_blind_marking(),
4473
                '',
4236
                                                             '',
4474
                $instance->attemptreopenmethod,
4237
                                                             $instance->attemptreopenmethod,
4475
                $instance->maxattempts,
4238
                                                             $instance->maxattempts,
4476
                $this->get_grading_status($userid),
4239
                                                             $this->get_grading_status($userid),
4477
                $instance->preventsubmissionnotingroup,
4240
                                                             $instance->preventsubmissionnotingroup,
4478
                $usergroups,
4241
                                                             $usergroups,
4479
                $instance->timelimit
4242
                                                             $instance->timelimit);
4480
            );
-
 
4481
            $o .= $this->get_renderer()->render($submissionstatus);
4243
            $o .= $this->get_renderer()->render($submissionstatus);
4482
        }
4244
        }
Línea 4483... Línea 4245...
4483
 
4245
 
4484
        if ($grade) {
4246
        if ($grade) {
Línea 4500... Línea 4262...
4500
 
4262
 
4501
        // Warning if required.
4263
        // Warning if required.
Línea 4502... Línea 4264...
4502
        $allsubmissions = $this->get_all_submissions($userid);
4264
        $allsubmissions = $this->get_all_submissions($userid);
4503
 
-
 
4504
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4265
 
4505
            $params = array(
4266
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4506
                'attemptnumber' => $attemptnumber + 1,
-
 
4507
                'totalattempts' => count($allsubmissions)
4267
            $params = array('attemptnumber'=>$attemptnumber + 1,
4508
            );
4268
                            'totalattempts'=>count($allsubmissions));
4509
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
4269
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
Línea 4510... Línea 4270...
4510
            $o .= $this->get_renderer()->notification($message);
4270
            $o .= $this->get_renderer()->notification($message);
4511
        }
4271
        }
4512
 
-
 
4513
        // Now show the grading form.
4272
 
4514
        if (!$mform) {
4273
        // Now show the grading form.
4515
            $pagination = array(
4274
        if (!$mform) {
4516
                'rownum' => $rownum,
4275
            $pagination = array('rownum' => $rownum,
4517
                'useridlistid' => $useridlistid,
4276
                                'useridlistid' => $useridlistid,
4518
                'last' => $last,
-
 
4519
                'userid' => $userid,
4277
                                'last' => $last,
4520
                'attemptnumber' => $attemptnumber
4278
                                'userid' => $userid,
4521
            );
-
 
4522
            $formparams = array($this, $data, $pagination);
4279
                                'attemptnumber' => $attemptnumber);
4523
            $mform = new mod_assign_grade_form(
4280
            $formparams = array($this, $data, $pagination);
4524
                null,
4281
            $mform = new mod_assign_grade_form(null,
4525
                $formparams,
4282
                                               $formparams,
4526
                'post',
-
 
4527
                '',
4283
                                               'post',
Línea 4528... Línea 4284...
4528
                array('class' => 'gradeform')
4284
                                               '',
Línea 4529... Línea 4285...
4529
            );
4285
                                               array('class'=>'gradeform'));
4530
        }
4286
        }
4531
 
4287
 
4532
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
-
 
4533
 
4288
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4534
        if (count($allsubmissions) > 1 && $attemptnumber == -1) {
4289
 
4535
            $allgrades = $this->get_all_grades($userid);
4290
        if (count($allsubmissions) > 1 && $attemptnumber == -1) {
4536
            $history = new assign_attempt_history(
4291
            $allgrades = $this->get_all_grades($userid);
4537
                $allsubmissions,
4292
            $history = new assign_attempt_history($allsubmissions,
4538
                $allgrades,
4293
                                                  $allgrades,
4539
                $this->get_submission_plugins(),
4294
                                                  $this->get_submission_plugins(),
4540
                $this->get_feedback_plugins(),
4295
                                                  $this->get_feedback_plugins(),
4541
                $this->get_course_module()->id,
4296
                                                  $this->get_course_module()->id,
4542
                $this->get_return_action(),
-
 
Línea 4543... Línea 4297...
4543
                $this->get_return_params(),
4297
                                                  $this->get_return_action(),
4544
                true,
4298
                                                  $this->get_return_params(),
Línea 4545... Línea 4299...
4545
                $useridlistid,
4299
                                                  true,
Línea 4558... Línea 4312...
4558
    /**
4312
    /**
4559
     * Show a confirmation page to make sure they want to remove submission data.
4313
     * Show a confirmation page to make sure they want to remove submission data.
4560
     *
4314
     *
4561
     * @return string
4315
     * @return string
4562
     */
4316
     */
4563
    protected function view_remove_submission_confirm()
4317
    protected function view_remove_submission_confirm() {
4564
    {
-
 
4565
        global $USER;
4318
        global $USER;
Línea 4566... Línea 4319...
4566
 
4319
 
Línea 4567... Línea 4320...
4567
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4320
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4568
 
4321
 
4569
        if (!$this->can_edit_submission($userid, $USER->id)) {
4322
        if (!$this->can_edit_submission($userid, $USER->id)) {
4570
            throw new \moodle_exception('nopermission');
4323
            throw new \moodle_exception('nopermission');
Línea 4571... Línea 4324...
4571
        }
4324
        }
4572
        $user = core_user::get_user($userid, '*', MUST_EXIST);
4325
        $user = core_user::get_user($userid, '*', MUST_EXIST);
4573
 
-
 
4574
        $o = '';
4326
 
4575
        $header = new assign_header(
4327
        $o = '';
4576
            $this->get_instance(),
4328
        $header = new assign_header($this->get_instance(),
4577
            $this->get_context(),
-
 
4578
            false,
4329
                                    $this->get_context(),
Línea 4579... Línea -...
4579
            $this->get_course_module()->id
-
 
4580
        );
4330
                                    false,
4581
        $o .= $this->get_renderer()->render($header);
4331
                                    $this->get_course_module()->id);
4582
 
4332
        $o .= $this->get_renderer()->render($header);
4583
        $urlparams = array(
4333
 
4584
            'id' => $this->get_course_module()->id,
-
 
4585
            'action' => 'removesubmission',
4334
        $urlparams = array('id' => $this->get_course_module()->id,
Línea 4586... Línea -...
4586
            'userid' => $userid,
-
 
4587
            'sesskey' => sesskey()
4335
                           'action' => 'removesubmission',
4588
        );
4336
                           'userid' => $userid,
4589
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
-
 
4590
 
4337
                           'sesskey' => sesskey());
Línea 4591... Línea 4338...
4591
        $urlparams = array(
4338
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4592
            'id' => $this->get_course_module()->id,
4339
 
4593
            'action' => 'view'
4340
        $urlparams = array('id' => $this->get_course_module()->id,
Línea 4605... Línea 4352...
4605
                $confirmstr = get_string('removesubmissionconfirmforstudentwithtimelimit', 'assign', $this->fullname($user));
4352
                $confirmstr = get_string('removesubmissionconfirmforstudentwithtimelimit', 'assign', $this->fullname($user));
4606
            } else {
4353
            } else {
4607
                $confirmstr = get_string('removesubmissionconfirmforstudent', 'assign', $this->fullname($user));
4354
                $confirmstr = get_string('removesubmissionconfirmforstudent', 'assign', $this->fullname($user));
4608
            }
4355
            }
4609
        }
4356
        }
4610
        $o .= $this->get_renderer()->confirm(
4357
        $o .= $this->get_renderer()->confirm($confirmstr,
4611
            $confirmstr,
-
 
4612
            $confirmurl,
4358
                                             $confirmurl,
4613
            $cancelurl
4359
                                             $cancelurl);
4614
        );
-
 
4615
        $o .= $this->view_footer();
4360
        $o .= $this->view_footer();
Línea 4616... Línea 4361...
4616
 
4361
 
Línea 4617... Línea 4362...
4617
        \mod_assign\event\remove_submission_form_viewed::create_from_user($this, $user)->trigger();
4362
        \mod_assign\event\remove_submission_form_viewed::create_from_user($this, $user)->trigger();
Línea 4623... Línea 4368...
4623
    /**
4368
    /**
4624
     * Show a confirmation page to make sure they want to release student identities.
4369
     * Show a confirmation page to make sure they want to release student identities.
4625
     *
4370
     *
4626
     * @return string
4371
     * @return string
4627
     */
4372
     */
4628
    protected function view_reveal_identities_confirm()
4373
    protected function view_reveal_identities_confirm() {
4629
    {
-
 
4630
        require_capability('mod/assign:revealidentities', $this->get_context());
4374
        require_capability('mod/assign:revealidentities', $this->get_context());
Línea 4631... Línea 4375...
4631
 
4375
 
4632
        $o = '';
4376
        $o = '';
4633
        $header = new assign_header(
-
 
4634
            $this->get_instance(),
4377
        $header = new assign_header($this->get_instance(),
4635
            $this->get_context(),
4378
                                    $this->get_context(),
4636
            false,
4379
                                    false,
4637
            $this->get_course_module()->id
-
 
4638
        );
4380
                                    $this->get_course_module()->id);
Línea 4639... Línea -...
4639
        $o .= $this->get_renderer()->render($header);
-
 
4640
 
4381
        $o .= $this->get_renderer()->render($header);
4641
        $urlparams = array(
4382
 
4642
            'id' => $this->get_course_module()->id,
4383
        $urlparams = array('id'=>$this->get_course_module()->id,
4643
            'action' => 'revealidentitiesconfirm',
-
 
4644
            'sesskey' => sesskey()
4384
                           'action'=>'revealidentitiesconfirm',
Línea 4645... Línea -...
4645
        );
-
 
4646
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4385
                           'sesskey'=>sesskey());
4647
 
4386
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4648
        $urlparams = array(
-
 
4649
            'id' => $this->get_course_module()->id,
4387
 
Línea 4650... Línea -...
4650
            'action' => 'grading'
-
 
4651
        );
4388
        $urlparams = array('id'=>$this->get_course_module()->id,
4652
        $cancelurl = new moodle_url('/mod/assign/view.php', $urlparams);
4389
                           'action'=>'grading');
4653
 
4390
        $cancelurl = new moodle_url('/mod/assign/view.php', $urlparams);
4654
        $o .= $this->get_renderer()->confirm(
-
 
4655
            get_string('revealidentitiesconfirm', 'assign'),
4391
 
Línea 4656... Línea 4392...
4656
            $confirmurl,
4392
        $o .= $this->get_renderer()->confirm(get_string('revealidentitiesconfirm', 'assign'),
Línea 4657... Línea 4393...
4657
            $cancelurl
4393
                                             $confirmurl,
Línea 4666... Línea 4402...
4666
    /**
4402
    /**
4667
     * View a link to go back to the previous page. Uses url parameters returnaction and returnparams.
4403
     * View a link to go back to the previous page. Uses url parameters returnaction and returnparams.
4668
     *
4404
     *
4669
     * @return string
4405
     * @return string
4670
     */
4406
     */
4671
    protected function view_return_links()
4407
    protected function view_return_links() {
4672
    {
-
 
4673
        $returnaction = optional_param('returnaction', '', PARAM_ALPHA);
4408
        $returnaction = optional_param('returnaction', '', PARAM_ALPHA);
4674
        $returnparams = optional_param('returnparams', '', PARAM_TEXT);
4409
        $returnparams = optional_param('returnparams', '', PARAM_TEXT);
Línea 4675... Línea 4410...
4675
 
4410
 
4676
        $params = array();
4411
        $params = array();
Línea 4686... Línea 4421...
4686
    /**
4421
    /**
4687
     * View the grading table of all submissions for this assignment.
4422
     * View the grading table of all submissions for this assignment.
4688
     *
4423
     *
4689
     * @return string
4424
     * @return string
4690
     */
4425
     */
4691
    protected function view_grading_table()
4426
    protected function view_grading_table() {
4692
    {
-
 
4693
        global $USER, $CFG, $SESSION, $PAGE;
4427
        global $USER, $CFG, $SESSION, $PAGE, $OUTPUT;
Línea 4694... Línea -...
4694
 
-
 
4695
        // Include grading options form.
-
 
4696
        require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
4428
 
4697
        require_once($CFG->dirroot . '/mod/assign/quickgradingform.php');
-
 
4698
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
-
 
4699
        $o = '';
-
 
Línea 4700... Línea -...
4700
        $cmid = $this->get_course_module()->id;
-
 
4701
 
-
 
4702
        $links = array();
-
 
4703
        if (
-
 
4704
            has_capability('gradereport/grader:view', $this->get_course_context()) &&
-
 
4705
            has_capability('moodle/grade:viewall', $this->get_course_context())
-
 
4706
        ) {
4429
        require_once($CFG->dirroot . '/mod/assign/quickgradingform.php');
4707
            $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
-
 
4708
            $links[$gradebookurl] = get_string('viewgradebook', 'assign');
-
 
4709
        }
4430
 
4710
        if (
4431
        $submittedfilter = optional_param('status', null, PARAM_ALPHA);
4711
            $this->is_blind_marking() &&
-
 
4712
            has_capability('mod/assign:revealidentities', $this->get_context())
4432
        if (isset($submittedfilter)) {
4713
        ) {
-
 
4714
            $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities';
-
 
4715
            $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
-
 
4716
        }
4433
            $validfilters = array_column($this->get_filters(), 'key');
4717
        foreach ($this->get_feedback_plugins() as $plugin) {
-
 
4718
            if ($plugin->is_enabled() && $plugin->is_visible()) {
-
 
4719
                foreach ($plugin->get_grading_actions() as $action => $description) {
-
 
4720
                    $url = '/mod/assign/view.php' .
-
 
4721
                        '?id=' .  $cmid .
4434
            $validfilters = array_diff($validfilters, [ASSIGN_FILTER_NONE]); // The 'none' filter is not a real filter.
4722
                        '&plugin=' . $plugin->get_type() .
-
 
4723
                        '&pluginsubtype=assignfeedback' .
-
 
4724
                        '&action=viewpluginpage&pluginaction=' . $action;
-
 
4725
                    $links[$url] = $description;
4435
            if ($submittedfilter === '' || in_array($submittedfilter, $validfilters)) {
4726
                }
4436
                set_user_preference('assign_filter', $submittedfilter);
Línea 4727... Línea 4437...
4727
            }
4437
            }
4728
        }
4438
        }
-
 
4439
 
-
 
4440
        $submittedquickgrading = optional_param('quickgrading', null, PARAM_BOOL);
-
 
4441
        if (isset($submittedquickgrading)) {
-
 
4442
            set_user_preference('assign_quickgrading', $submittedquickgrading);
-
 
4443
        }
-
 
4444
 
-
 
4445
        $submitteddownloadasfolders = optional_param('downloadasfolders', null, PARAM_BOOL);
Línea -... Línea 4446...
-
 
4446
        if (isset($submitteddownloadasfolders)) {
4729
 
4447
            set_user_preference('assign_downloadasfolders', $submitteddownloadasfolders);
4730
        // Sort links alphabetically based on the link description.
4448
        }
-
 
4449
 
-
 
4450
        $submittedperpage = optional_param('perpage', null, PARAM_INT);
-
 
4451
        if (isset($submittedperpage)) {
4731
        core_collator::asort($links);
4452
            set_user_preference('assign_perpage', $submittedperpage);
Línea 4732... Línea 4453...
4732
 
4453
        }
Línea 4733... Línea 4454...
4733
        $gradingactions = new url_select($links);
4454
 
4734
        $gradingactions->set_label(get_string('choosegradingaction', 'assign'));
4455
        $o = '';
-
 
4456
        $cmid = $this->get_course_module()->id;
-
 
4457
 
-
 
4458
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
-
 
4459
 
-
 
4460
        $perpage = $this->get_assign_perpage();
-
 
4461
        $filter = get_user_preferences('assign_filter', '');
4735
        $gradingactions->class .= ' mb-1';
4462
 
-
 
4463
        // Retrieve the 'workflowfilter' parameter, or set it to null if not provided.
-
 
4464
        $workflowfilter = optional_param('workflowfilter', null, PARAM_ALPHA);
-
 
4465
        // Check if the parameter is not null and if it exists in the list of valid workflow filters.
-
 
4466
        if ($workflowfilter !== null && array_key_exists($workflowfilter, $this->get_marking_workflow_filters())) {
-
 
4467
            // Save the valid 'workflowfilter' value as a user preference.
-
 
4468
            set_user_preference('assign_workflowfilter', $workflowfilter);
-
 
4469
        }
-
 
4470
 
4736
 
4471
        // Retrieve the 'markingallocationfilter' parameter, or set it to null if not provided.
-
 
4472
        $markingallocationfilter = optional_param('markingallocationfilter', null, PARAM_ALPHANUMEXT);
-
 
4473
        // Check if the parameter is not null and if it exists in the list of valid marking allocation filters.
-
 
4474
        if ($markingallocationfilter !== null &&
-
 
4475
                array_key_exists($markingallocationfilter, $this->get_marking_allocation_filters())) {
-
 
4476
            // Save the valid 'markingallocationfilter' value as a user preference.
-
 
4477
            set_user_preference('assign_markerfilter', $markingallocationfilter);
-
 
4478
        }
-
 
4479
 
-
 
4480
        // Retrieve the 'suspendedparticipantsfilter' parameter, or set it to null if not provided.
-
 
4481
        $suspendedparticipantsfilter = optional_param('suspendedparticipantsfilter', null, PARAM_BOOL);
4737
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
4482
        if ($suspendedparticipantsfilter !== null &&
4738
 
4483
                has_capability('moodle/course:viewsuspendedusers', $this->get_context())) {
4739
        $perpage = $this->get_assign_perpage();
4484
            // Save the 'suspendedparticipantsfilter' value as a user preference.
4740
        $filter = get_user_preferences('assign_filter', '');
-
 
4741
        $markerfilter = get_user_preferences('assign_markerfilter', '');
-
 
Línea 4742... Línea 4485...
4742
        $workflowfilter = get_user_preferences('assign_workflowfilter', '');
4485
            set_user_preference('grade_report_showonlyactiveenrol', !$suspendedparticipantsfilter);
4743
        $controller = $gradingmanager->get_active_controller();
4486
        }
4744
        $showquickgrading = empty($controller) && $this->can_grade();
4487
 
4745
        $quickgrading = get_user_preferences('assign_quickgrading', false);
-
 
4746
        $showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
-
 
4747
        $downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
-
 
4748
 
-
 
4749
        $markingallocation = $this->get_instance()->markingworkflow &&
-
 
4750
            $this->get_instance()->markingallocation &&
-
 
4751
            has_capability('mod/assign:manageallocations', $this->context);
-
 
4752
        // Get markers to use in drop lists.
-
 
4753
        $markingallocationoptions = array();
-
 
4754
        if ($markingallocation) {
-
 
4755
            list($sort, $params) = users_order_by_sql('u');
-
 
4756
            // Only enrolled users could be assigned as potential markers.
-
 
4757
            $markers = get_enrolled_users($this->context, 'mod/assign:grade', 0, 'u.*', $sort);
-
 
Línea 4758... Línea 4488...
4758
            $markingallocationoptions[''] = get_string('filternone', 'assign');
4488
        $controller = $gradingmanager->get_active_controller();
4759
            $markingallocationoptions[ASSIGN_MARKER_FILTER_NO_MARKER] = get_string('markerfilternomarker', 'assign');
-
 
4760
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->context);
-
 
4761
            foreach ($markers as $marker) {
-
 
4762
                $markingallocationoptions[$marker->id] = fullname($marker, $viewfullnames);
-
 
4763
            }
-
 
4764
        }
-
 
4765
 
-
 
4766
        $markingworkflow = $this->get_instance()->markingworkflow;
-
 
4767
        // Get marking states to show in form.
-
 
4768
        $markingworkflowoptions = $this->get_marking_workflow_filters();
-
 
4769
 
-
 
4770
        // Print options for changing the filter and changing the number of results per page.
-
 
4771
        $gradingoptionsformparams = array(
-
 
4772
            'cm' => $cmid,
-
 
4773
            'contextid' => $this->context->id,
-
 
4774
            'userid' => $USER->id,
-
 
4775
            'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
-
 
4776
            'showquickgrading' => $showquickgrading,
-
 
4777
            'quickgrading' => $quickgrading,
-
 
4778
            'markingworkflowopt' => $markingworkflowoptions,
-
 
4779
            'markingallocationopt' => $markingallocationoptions,
-
 
4780
            'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
-
 
4781
            'showonlyactiveenrol' => $this->show_only_active_users(),
-
 
4782
            'downloadasfolders' => $downloadasfolders
-
 
4783
        );
-
 
4784
 
-
 
4785
        $classoptions = array('class' => 'gradingoptionsform');
-
 
4786
        $gradingoptionsform = new mod_assign_grading_options_form(
-
 
4787
            null,
-
 
4788
            $gradingoptionsformparams,
-
 
4789
            'post',
-
 
4790
            '',
-
 
4791
            $classoptions
-
 
4792
        );
-
 
4793
 
-
 
4794
        $batchformparams = array(
-
 
4795
            'cm' => $cmid,
-
 
4796
            'submissiondrafts' => $this->get_instance()->submissiondrafts,
-
 
4797
            'duedate' => $this->get_instance()->duedate,
-
 
4798
            'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod,
-
 
4799
            'feedbackplugins' => $this->get_feedback_plugins(),
-
 
4800
            'context' => $this->get_context(),
-
 
4801
            'markingworkflow' => $markingworkflow,
-
 
4802
            'markingallocation' => $markingallocation
-
 
4803
        );
-
 
4804
        $classoptions = [
-
 
4805
            'class' => 'gradingbatchoperationsform',
-
 
4806
            'data-double-submit-protection' => 'off',
-
 
4807
        ];
-
 
4808
 
-
 
4809
        $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(
-
 
4810
            null,
-
 
4811
            $batchformparams,
-
 
4812
            'post',
-
 
4813
            '',
-
 
4814
            $classoptions
-
 
Línea -... Línea 4489...
-
 
4489
        $showquickgrading = empty($controller) && $this->can_grade();
-
 
4490
        $quickgrading = get_user_preferences('assign_quickgrading', false);
-
 
4491
 
-
 
4492
        $markingallocation = $this->get_instance()->markingworkflow &&
-
 
4493
            $this->get_instance()->markingallocation &&
-
 
4494
            has_capability('mod/assign:manageallocations', $this->context);
-
 
4495
 
4815
        );
4496
        $markingworkflow = $this->get_instance()->markingworkflow;
4816
 
4497
 
4817
        $gradingoptionsdata = new stdClass();
4498
        // Load the table of submissions, to be printed further down.
4818
        $gradingoptionsdata->perpage = $perpage;
4499
        $usequickgrading = $showquickgrading && $quickgrading;
-
 
4500
        $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, $usequickgrading);
-
 
4501
        $gradingtable->responsive = false;
-
 
4502
        $table = $this->get_renderer()->render($gradingtable);
4819
        $gradingoptionsdata->filter = $filter;
4503
        // This initialises the selected first/last initials for the action menu.
4820
        $gradingoptionsdata->markerfilter = $markerfilter;
4504
        $gradingtable->initialbars(true);
-
 
4505
        $buttons = new \mod_assign\output\grading_actionmenu(
4821
        $gradingoptionsdata->workflowfilter = $workflowfilter;
4506
            cmid: $this->get_course_module()->id,
Línea 4822... Línea 4507...
4822
        $gradingoptionsform->set_data($gradingoptionsdata);
4507
            assign: $this,
Línea 4823... Línea 4508...
4823
 
4508
            userinitials: [
-
 
4509
                'firstname' => $gradingtable->get_initial_first(),
-
 
4510
                'lastname' => $gradingtable->get_initial_last(),
-
 
4511
            ]
-
 
4512
        );
4824
        $buttons = new \mod_assign\output\grading_actionmenu(
4513
        $actionformtext = $this->get_renderer()->render($buttons);
4825
            $this->get_course_module()->id,
4514
        $currenturl = new moodle_url('/mod/assign/view.php', ['id' => $this->get_course_module()->id, 'action' => 'grading']);
4826
            $this->is_any_submission_plugin_enabled(),
4515
        $PAGE->activityheader->set_attrs(['hidecompletion' => true]);
4827
            $this->count_submissions()
4516
 
4828
        );
4517
        $PAGE->requires->js_call_amd('mod_assign/user', 'init', [$currenturl->out(false)]);
4829
        $actionformtext = $this->get_renderer()->render($buttons);
4518
 
4830
        $PAGE->activityheader->set_attrs(['hidecompletion' => true]);
4519
        // Conditionally add the group JS if we have groups enabled.
4831
 
4520
        if (groups_get_activity_groupmode($this->get_course_module(), $this->get_course())) {
4832
        $currenturl = new moodle_url('/mod/assign/view.php', ['id' => $this->get_course_module()->id, 'action' => 'grading']);
-
 
4833
 
4521
            $PAGE->requires->js_call_amd('core_course/actionbar/group', 'init', [$currenturl->out(false), $cmid]);
Línea 4834... Línea 4522...
4834
        $header = new assign_header(
4522
        }
Línea 4835... Línea -...
4835
            $this->get_instance(),
-
 
4836
            $this->get_context(),
-
 
4837
            false,
-
 
4838
            $this->get_course_module()->id,
-
 
4839
            get_string('grading', 'assign'),
-
 
4840
            '',
-
 
4841
            '',
-
 
4842
            $currenturl
-
 
4843
        );
-
 
4844
        $o .= $this->get_renderer()->render($header);
-
 
4845
 
-
 
4846
        $o .= $actionformtext;
4523
 
-
 
4524
        $header = new assign_header($this->get_instance(),
4847
 
4525
                                    $this->get_context(),
-
 
4526
                                    false,
-
 
4527
                                    $this->get_course_module()->id,
-
 
4528
                                    get_string('gradeitem:submissions', 'assign'),
4848
        $o .= $this->get_renderer()->heading(get_string('gradeitem:submissions', 'mod_assign'), 2);
4529
                                    '',
Línea 4849... Línea 4530...
4849
        $o .= $this->get_renderer()->render($gradingactions);
4530
                                    '',
4850
 
4531
                                    $currenturl);
4851
        $o .= groups_print_activity_menu($this->get_course_module(), $currenturl, true);
4532
        $o .= $this->get_renderer()->render($header);
4852
 
4533
 
4853
        // Plagiarism update status apearring in the grading book.
4534
        $o .= $actionformtext;
-
 
4535
 
4854
        if (!empty($CFG->enableplagiarism)) {
4536
        if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) {
4855
            require_once($CFG->libdir . '/plagiarismlib.php');
-
 
4856
            $o .= plagiarism_update_status($this->get_course(), $this->get_course_module());
-
 
4857
        }
-
 
4858
 
-
 
4859
        if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) {
-
 
4860
            $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
4537
            if ($this->is_marking_anonymous()) {
4861
        }
-
 
4862
 
4538
                $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
4863
        // Load and print the table of submissions.
4539
            } else {
4864
        $assignform = new assign_form(
4540
                $o .= $this->get_renderer()->notification(get_string('blindmarkingnogradewarning', 'assign'), 'notifymessage');
4865
            'gradingoptionsform',
-
 
4866
            $gradingoptionsform,
4541
            }
4867
            'M.mod_assign.init_grading_options'
-
 
4868
        );
4542
        }
4869
        $o .= $this->get_renderer()->render($assignform);
4543
 
4870
        $currentgroup = groups_get_activity_group($this->get_course_module(), true);
4544
        // Print the table of submissions.
4871
        $users = array_keys($this->list_participants($currentgroup, true));
-
 
4872
        if (count($users) != 0 && $this->can_grade()) {
4545
        $footerdata = [
-
 
4546
            'perpage' => $gradingtable->get_paging_selector(),
4873
            // If no enrolled user in a course then don't display the batch operations feature.
4547
            'pagingbar' => $gradingtable->get_paging_bar(),
-
 
4548
            'hassubmit' => $usequickgrading,
Línea 4874... Línea 4549...
4874
            $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform);
4549
            'sendstudentnotifications' => $this->get_instance()->sendstudentnotifications,
4875
            $o .= $this->get_renderer()->render($assignform);
4550
        ];
4876
        }
4551
        $footer = new core\output\sticky_footer($OUTPUT->render_from_template('mod_assign/grading_sticky_footer', $footerdata));
4877
        if ($showquickgrading && $quickgrading) {
4552
 
4878
            $page = optional_param('page', null, PARAM_INT);
4553
        if ($usequickgrading) {
Línea 4879... Línea 4554...
4879
            $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
4554
            $page = optional_param('page', null, PARAM_INT);
4880
            $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
4555
            $PAGE->requires->js_call_amd('mod_assign/quick_grading', 'init', []);
4881
            $table = $this->get_renderer()->render($gradingtable);
4556
            $quickformparams = [
-
 
4557
                'cm' => $this->get_course_module()->id,
4882
            $quickformparams = array(
4558
                'gradingtable' => $table,
4883
                'cm' => $this->get_course_module()->id,
4559
                'page' => $page,
4884
                'gradingtable' => $table,
4560
                'footer' => $this->get_renderer()->render($footer),
-
 
4561
            ];
-
 
4562
            $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
-
 
4563
 
-
 
4564
            $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
-
 
4565
        } else {
-
 
4566
            $o .= $table;
-
 
4567
            $o .= $this->get_renderer()->render($footer);
-
 
4568
        }
-
 
4569
 
-
 
4570
        if ($this->can_grade()) {
-
 
4571
            // We need to store the order of uses in the table as the person may wish to grade them.
-
 
4572
            // This is done based on the row number of the user.
-
 
4573
            // Pagination has be added before this because calling get_column_data will reset the pagination.
-
 
4574
            $useridlist = $gradingtable->get_column_data('userid');
-
 
4575
            $SESSION->mod_assign_useridlist[$this->get_useridlist_key()] = $useridlist;
-
 
4576
        }
-
 
4577
 
-
 
4578
        $currentgroup = groups_get_activity_group($this->get_course_module(), true);
-
 
4579
        $users = array_keys($this->list_participants($currentgroup, true));
-
 
4580
        if (count($users) != 0 && $this->can_grade()) {
-
 
4581
            $jsparams = [];
-
 
4582
            $jsparams['message'] = !empty($CFG->messaging)
-
 
4583
                && has_all_capabilities(['moodle/site:sendmessage', 'moodle/course:bulkmessaging'], $this->context);
-
 
4584
            $jsparams['submissiondrafts'] = !empty($this->get_instance()->submissiondrafts);
-
 
4585
            $jsparams['removesubmission'] = has_capability('mod/assign:editothersubmission', $this->context);
-
 
4586
            $jsparams['extend'] = $this->get_instance()->duedate && has_capability('mod/assign:grantextension', $this->context);
-
 
4587
 
-
 
4588
            $multipleattemptsallowed = $this->get_instance()->maxattempts > 1
-
 
4589
                || $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
-
 
4590
            $jsparams['grantattempt'] =
-
 
4591
                $multipleattemptsallowed && $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
-
 
4592
 
-
 
4593
            $jsparams['pluginoperations'] = [];
-
 
4594
            foreach ($this->get_feedback_plugins() as $plugin) {
-
 
4595
                if ($plugin->is_visible() && $plugin->is_enabled()) {
-
 
4596
                    foreach ($plugin->get_grading_batch_operation_details() as $operation) {
-
 
4597
                        $jsparams['pluginoperations'][] = [
-
 
4598
                            'key' => 'plugingradingbatchoperation_' . $plugin->get_type() . '_' . $operation->key,
-
 
4599
                            'label' => $operation->label,
4885
                'sendstudentnotifications' => $this->get_instance()->sendstudentnotifications,
4600
                            'icon' => $operation->icon,
4886
                'page' => $page
4601
                            'confirmationtitle' => $operation->confirmationtitle,
Línea 4887... Línea 4602...
4887
            );
4602
                            'confirmationquestion' => $operation->confirmationquestion,
4888
 
4603
                        ];
4889
            $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
4604
                    }
4890
        } else {
4605
                }
4891
            $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false);
4606
            }
4892
            $o .= $this->get_renderer()->render($gradingtable);
4607
 
4893
        }
-
 
4894
 
4608
            $jsparams['workflowstate'] = !empty($this->get_instance()->markingworkflow);
Línea 4895... Línea 4609...
4895
        if ($this->can_grade()) {
4609
            $jsparams['markingallocation'] = !empty($this->get_instance()->markingallocation);
4896
            // We need to store the order of uses in the table as the person may wish to grade them.
4610
            $jsparams['cmid'] = $this->get_course_module()->id;
4897
            // This is done based on the row number of the user.
4611
            $jsparams['sesskey'] = sesskey();
Línea 4956... Línea 4670...
4956
    /**
4670
    /**
4957
     * View entire grading page.
4671
     * View entire grading page.
4958
     *
4672
     *
4959
     * @return string
4673
     * @return string
4960
     */
4674
     */
4961
    protected function view_grading_page()
4675
    protected function view_grading_page() {
4962
    {
-
 
4963
        global $CFG;
4676
        global $CFG, $PAGE;
-
 
4677
 
-
 
4678
        // Ensure that the 'Submissions' navigation node is highlighted as 'active' in the secondary navigation.
-
 
4679
        $PAGE->set_secondary_active_tab('mod_assign_submissions');
Línea 4964... Línea 4680...
4964
 
4680
 
4965
        $o = '';
4681
        $o = '';
4966
        // Need submit permission to submit an assignment.
4682
        // Need submit permission to submit an assignment.
4967
        $this->require_view_grades();
4683
        $this->require_view_grades();
Línea 4982... Línea 4698...
4982
    /**
4698
    /**
4983
     * Capture the output of the plagiarism plugins disclosures and return it as a string.
4699
     * Capture the output of the plagiarism plugins disclosures and return it as a string.
4984
     *
4700
     *
4985
     * @return string
4701
     * @return string
4986
     */
4702
     */
4987
    protected function plagiarism_print_disclosure()
4703
    protected function plagiarism_print_disclosure() {
4988
    {
-
 
4989
        global $CFG;
4704
        global $CFG;
4990
        $o = '';
4705
        $o = '';
Línea 4991... Línea 4706...
4991
 
4706
 
4992
        if (!empty($CFG->enableplagiarism)) {
4707
        if (!empty($CFG->enableplagiarism)) {
Línea 5003... Línea 4718...
5003
     *
4718
     *
5004
     * @param string $title The page title
4719
     * @param string $title The page title
5005
     * @param array $notices The array of notices to show.
4720
     * @param array $notices The array of notices to show.
5006
     * @return string
4721
     * @return string
5007
     */
4722
     */
5008
    protected function view_notices($title, $notices)
4723
    protected function view_notices($title, $notices) {
5009
    {
-
 
5010
        global $CFG;
4724
        global $CFG;
Línea 5011... Línea 4725...
5011
 
4725
 
Línea 5012... Línea 4726...
5012
        $o = '';
4726
        $o = '';
5013
 
-
 
5014
        $header = new assign_header(
4727
 
5015
            $this->get_instance(),
4728
        $header = new assign_header($this->get_instance(),
5016
            $this->get_context(),
4729
                                    $this->get_context(),
5017
            $this->show_intro(),
4730
                                    $this->show_intro(),
5018
            $this->get_course_module()->id,
-
 
5019
            $title
4731
                                    $this->get_course_module()->id,
Línea 5020... Línea 4732...
5020
        );
4732
                                    $title);
5021
        $o .= $this->get_renderer()->render($header);
4733
        $o .= $this->get_renderer()->render($header);
5022
 
4734
 
Línea 5023... Línea 4735...
5023
        foreach ($notices as $notice) {
4735
        foreach ($notices as $notice) {
5024
            $o .= $this->get_renderer()->notification($notice);
4736
            $o .= $this->get_renderer()->notification($notice);
Línea 5025... Línea 4737...
5025
        }
4737
        }
Línea 5026... Línea 4738...
5026
 
4738
 
Línea 5036... Línea 4748...
5036
     * Get the name for a user - hiding their real name if blind marking is on.
4748
     * Get the name for a user - hiding their real name if blind marking is on.
5037
     *
4749
     *
5038
     * @param stdClass $user The user record as required by fullname()
4750
     * @param stdClass $user The user record as required by fullname()
5039
     * @return string The name.
4751
     * @return string The name.
5040
     */
4752
     */
5041
    public function fullname($user)
4753
    public function fullname($user) {
5042
    {
-
 
5043
        if ($this->is_blind_marking()) {
4754
        if ($this->is_blind_marking()) {
5044
            $hasviewblind = has_capability('mod/assign:viewblinddetails', $this->get_context());
4755
            $hasviewblind = has_capability('mod/assign:viewblinddetails', $this->get_context());
5045
            if (empty($user->recordid)) {
4756
            if (empty($user->recordid)) {
5046
                $uniqueid = $this->get_uniqueid_for_user($user->id);
4757
                $uniqueid = $this->get_uniqueid_for_user($user->id);
5047
            } else {
4758
            } else {
5048
                $uniqueid = $user->recordid;
4759
                $uniqueid = $user->recordid;
5049
            }
4760
            }
5050
            if ($hasviewblind) {
4761
            if ($hasviewblind) {
5051
                return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' .
4762
                return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' .
5052
                    fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())) . ')';
4763
                        fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())) . ')';
5053
            } else {
4764
            } else {
5054
                return get_string('participant', 'assign') . ' ' . $uniqueid;
4765
                return get_string('participant', 'assign') . ' ' . $uniqueid;
5055
            }
4766
            }
5056
        } else {
4767
        } else {
5057
            return fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
4768
            return fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
Línea 5064... Línea 4775...
5064
     * @param moodleform $mform
4775
     * @param moodleform $mform
5065
     * @param array $notices A list of notices to display at the top of the
4776
     * @param array $notices A list of notices to display at the top of the
5066
     *                       edit submission form (e.g. from plugins).
4777
     *                       edit submission form (e.g. from plugins).
5067
     * @return string The page output.
4778
     * @return string The page output.
5068
     */
4779
     */
5069
    protected function view_edit_submission_page($mform, $notices)
4780
    protected function view_edit_submission_page($mform, $notices) {
5070
    {
-
 
5071
        global $CFG, $USER, $DB, $PAGE;
4781
        global $CFG, $USER, $DB, $PAGE;
Línea 5072... Línea 4782...
5072
 
4782
 
5073
        $o = '';
4783
        $o = '';
5074
        require_once($CFG->dirroot . '/mod/assign/submission_form.php');
4784
        require_once($CFG->dirroot . '/mod/assign/submission_form.php');
5075
        // Need submit permission to submit an assignment.
4785
        // Need submit permission to submit an assignment.
5076
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4786
        $userid = optional_param('userid', $USER->id, PARAM_INT);
5077
        $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
4787
        $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
Línea 5078... Línea 4788...
5078
        $timelimitenabled = get_config('assign', 'enabletimelimit');
4788
        $timelimitenabled = get_config('assign', 'enabletimelimit');
5079
 
4789
 
5080
        // This variation on the url will link direct to this student.
4790
        // This variation on the url will link direct to this student.
Línea 5132... Línea 4842...
5132
            $bc->content = $navbc;
4842
            $bc->content = $navbc;
5133
            $PAGE->blocks->add_fake_block($bc, reset($regions));
4843
            $PAGE->blocks->add_fake_block($bc, reset($regions));
5134
        }
4844
        }
Línea 5135... Línea 4845...
5135
 
4845
 
5136
        $o .= $this->get_renderer()->render(
-
 
5137
            new assign_header(
4846
        $o .= $this->get_renderer()->render(
5138
                $this->get_instance(),
4847
            new assign_header($this->get_instance(),
5139
                $this->get_context(),
4848
                              $this->get_context(),
5140
                $this->show_intro(),
4849
                              $this->show_intro(),
5141
                $this->get_course_module()->id,
4850
                              $this->get_course_module()->id,
5142
                $title,
4851
                              $title,
5143
                '',
4852
                              '',
5144
                $postfix,
4853
                              $postfix,
5145
                null,
4854
                              null,
5146
                true
4855
                              true
5147
            )
4856
            )
Línea 5148... Línea 4857...
5148
        );
4857
        );
5149
 
4858
 
Línea 5166... Línea 4875...
5166
     * Get the time limit panel object for this submission attempt.
4875
     * Get the time limit panel object for this submission attempt.
5167
     *
4876
     *
5168
     * @param stdClass $submission assign submission.
4877
     * @param stdClass $submission assign submission.
5169
     * @return string the panel output.
4878
     * @return string the panel output.
5170
     */
4879
     */
5171
    public function get_timelimit_panel(stdClass $submission): string
4880
    public function get_timelimit_panel(stdClass $submission): string {
5172
    {
-
 
5173
        global $USER;
4881
        global $USER;
Línea 5174... Línea 4882...
5174
 
4882
 
5175
        // Apply overrides.
4883
        // Apply overrides.
5176
        $this->update_effective_access($USER->id);
4884
        $this->update_effective_access($USER->id);
Línea 5182... Línea 4890...
5182
     * See if this assignment has a grade yet.
4890
     * See if this assignment has a grade yet.
5183
     *
4891
     *
5184
     * @param int $userid
4892
     * @param int $userid
5185
     * @return bool
4893
     * @return bool
5186
     */
4894
     */
5187
    protected function is_graded($userid)
4895
    protected function is_graded($userid) {
5188
    {
-
 
5189
        $grade = $this->get_user_grade($userid, false);
4896
        $grade = $this->get_user_grade($userid, false);
5190
        if ($grade) {
4897
        if ($grade) {
5191
            return ($grade->grade !== null && $grade->grade >= 0);
4898
            return ($grade->grade !== null && $grade->grade >= 0);
5192
        }
4899
        }
5193
        return false;
4900
        return false;
Línea 5197... Línea 4904...
5197
     * Perform an access check to see if the current $USER can edit this group submission.
4904
     * Perform an access check to see if the current $USER can edit this group submission.
5198
     *
4905
     *
5199
     * @param int $groupid
4906
     * @param int $groupid
5200
     * @return bool
4907
     * @return bool
5201
     */
4908
     */
5202
    public function can_edit_group_submission($groupid)
4909
    public function can_edit_group_submission($groupid) {
5203
    {
-
 
5204
        global $USER;
4910
        global $USER;
Línea 5205... Línea 4911...
5205
 
4911
 
5206
        $members = $this->get_submission_group_members($groupid, true);
4912
        $members = $this->get_submission_group_members($groupid, true);
5207
        foreach ($members as $member) {
4913
        foreach ($members as $member) {
Línea 5217... Línea 4923...
5217
     * Perform an access check to see if the current $USER can view this group submission.
4923
     * Perform an access check to see if the current $USER can view this group submission.
5218
     *
4924
     *
5219
     * @param int $groupid
4925
     * @param int $groupid
5220
     * @return bool
4926
     * @return bool
5221
     */
4927
     */
5222
    public function can_view_group_submission($groupid)
4928
    public function can_view_group_submission($groupid) {
5223
    {
-
 
5224
        global $USER;
4929
        global $USER;
Línea 5225... Línea 4930...
5225
 
4930
 
5226
        $members = $this->get_submission_group_members($groupid, true);
4931
        $members = $this->get_submission_group_members($groupid, true);
5227
        foreach ($members as $member) {
4932
        foreach ($members as $member) {
Línea 5237... Línea 4942...
5237
     * Perform an access check to see if the current $USER can view this users submission.
4942
     * Perform an access check to see if the current $USER can view this users submission.
5238
     *
4943
     *
5239
     * @param int $userid
4944
     * @param int $userid
5240
     * @return bool
4945
     * @return bool
5241
     */
4946
     */
5242
    public function can_view_submission($userid)
4947
    public function can_view_submission($userid) {
5243
    {
-
 
5244
        global $USER;
4948
        global $USER;
Línea 5245... Línea 4949...
5245
 
4949
 
5246
        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
4950
        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
5247
            return false;
4951
            return false;
Línea 5258... Línea 4962...
5258
        return false;
4962
        return false;
5259
    }
4963
    }
Línea 5260... Línea 4964...
5260
 
4964
 
5261
    /**
4965
    /**
-
 
4966
     * Allows the plugin to show a batch grading operation page.
5262
     * Allows the plugin to show a batch grading operation page.
4967
     * You should confirm sesskey before calling this function.
5263
     *
-
 
5264
     * @param moodleform $mform
4968
     *
5265
     * @return none
4969
     * @return none
5266
     */
4970
     */
5267
    protected function view_plugin_grading_batch_operation($mform)
-
 
5268
    {
4971
    protected function view_plugin_grading_batch_operation() {
5269
        require_capability('mod/assign:grade', $this->context);
4972
        require_capability('mod/assign:grade', $this->context);
Línea 5270... Línea -...
5270
        $prefix = 'plugingradingbatchoperation_';
-
 
5271
 
4973
        $prefix = 'plugingradingbatchoperation_';
5272
        if ($data = $mform->get_data()) {
-
 
Línea -... Línea 4974...
-
 
4974
 
-
 
4975
        $operation = required_param('operation', PARAM_ALPHAEXT);
-
 
4976
 
5273
            $tail = substr($data->operation, strlen($prefix));
4977
        $tail = substr($operation, strlen($prefix));
5274
            list($plugintype, $action) = explode('_', $tail, 2);
4978
        list($plugintype, $action) = explode('_', $tail, 2);
5275
 
4979
 
5276
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
4980
        $plugin = $this->get_feedback_plugin_by_type($plugintype);
5277
            if ($plugin) {
4981
        if ($plugin) {
5278
                $users = $data->selectedusers;
4982
            $users = required_param('selectedusers', PARAM_SEQUENCE);
5279
                $userlist = explode(',', $users);
-
 
5280
                echo $plugin->grading_batch_operation($action, $userlist);
4983
            $userlist = explode(',', $users);
-
 
4984
            echo $plugin->grading_batch_operation($action, $userlist);
5281
                return;
4985
            return;
5282
            }
4986
        }
Línea 5283... Línea 4987...
5283
        }
4987
 
5284
        throw new \moodle_exception('invalidformdata', '');
4988
        throw new \moodle_exception('invalidformdata', '');
5285
    }
4989
    }
5286
 
-
 
5287
    /**
4990
 
5288
     * Ask the user to confirm they want to perform this batch operation
4991
    /**
5289
     *
4992
     * Ask the user to confirm they want to perform this batch operation
5290
     * @param moodleform $mform Set to a grading batch operations form
-
 
5291
     * @return string - the page to view after processing these actions
-
 
5292
     */
-
 
5293
    protected function process_grading_batch_operation(&$mform)
4993
     *
Línea 5294... Línea -...
5294
    {
-
 
5295
        global $CFG;
-
 
5296
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
4994
     * @return string - the page to view after processing these actions
5297
        require_sesskey();
-
 
5298
 
-
 
5299
        $markingallocation = $this->get_instance()->markingworkflow &&
-
 
5300
            $this->get_instance()->markingallocation &&
-
 
5301
            has_capability('mod/assign:manageallocations', $this->context);
-
 
5302
 
-
 
5303
        $batchformparams = array(
4995
     */
5304
            'cm' => $this->get_course_module()->id,
-
 
5305
            'submissiondrafts' => $this->get_instance()->submissiondrafts,
-
 
5306
            'duedate' => $this->get_instance()->duedate,
-
 
5307
            'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod,
-
 
5308
            'feedbackplugins' => $this->get_feedback_plugins(),
-
 
5309
            'context' => $this->get_context(),
-
 
5310
            'markingworkflow' => $this->get_instance()->markingworkflow,
-
 
5311
            'markingallocation' => $markingallocation
-
 
Línea 5312... Línea -...
5312
        );
-
 
5313
        $formclasses = [
-
 
5314
            'class' => 'gradingbatchoperationsform',
4996
    protected function process_grading_batch_operation() {
5315
            'data-double-submit-protection' => 'off'
-
 
5316
        ];
-
 
5317
 
4997
        require_sesskey();
5318
        $mform = new mod_assign_grading_batch_operations_form(
-
 
Línea 5319... Línea -...
5319
            null,
-
 
5320
            $batchformparams,
-
 
5321
            'post',
-
 
5322
            '',
4998
 
Línea -... Línea 4999...
-
 
4999
        $operation = required_param('operation', PARAM_ALPHAEXT);
-
 
5000
        $selectedusers = required_param('selectedusers', PARAM_SEQUENCE);
-
 
5001
 
-
 
5002
        // Get the list of users.
-
 
5003
        $userlist = explode(',', $selectedusers);
5323
            $formclasses
5004
 
-
 
5005
        $prefix = 'plugingradingbatchoperation_';
-
 
5006
 
-
 
5007
        if ($operation == 'grantextension') {
Línea 5324... Línea -...
5324
        );
-
 
5325
 
-
 
5326
        if ($data = $mform->get_data()) {
-
 
5327
            // Get the list of users.
-
 
5328
            $users = $data->selectedusers;
-
 
5329
            $userlist = explode(',', $users);
-
 
5330
 
-
 
5331
            $prefix = 'plugingradingbatchoperation_';
-
 
5332
 
-
 
5333
            if ($data->operation == 'grantextension') {
-
 
5334
                // Reset the form so the grant extension page will create the extension form.
-
 
5335
                $mform = null;
-
 
5336
                return 'grantextension';
5008
            return 'grantextension';
5337
            } else if ($data->operation == 'setmarkingworkflowstate') {
5009
        } else if ($operation == 'setmarkingworkflowstate') {
5338
                return 'viewbatchsetmarkingworkflowstate';
5010
            return 'viewbatchsetmarkingworkflowstate';
5339
            } else if ($data->operation == 'setmarkingallocation') {
-
 
5340
                return 'viewbatchmarkingallocation';
5011
        } else if ($operation == 'setmarkingallocation') {
-
 
5012
            return 'viewbatchmarkingallocation';
Línea 5341... Línea 5013...
5341
            } else if (strpos($data->operation, $prefix) === 0) {
5013
        } else if (strpos($operation, $prefix) === 0) {
5342
                $tail = substr($data->operation, strlen($prefix));
5014
            $tail = substr($operation, strlen($prefix));
5343
                list($plugintype, $action) = explode('_', $tail, 2);
5015
            list($plugintype, $action) = explode('_', $tail, 2);
5344
 
5016
 
5345
                $plugin = $this->get_feedback_plugin_by_type($plugintype);
5017
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
5346
                if ($plugin) {
5018
            if ($plugin) {
5347
                    return 'plugingradingbatchoperation';
5019
                return 'plugingradingbatchoperation';
5348
                }
5020
            }
5349
            }
5021
        }
5350
 
5022
 
5351
            if ($data->operation == 'downloadselected') {
5023
        if ($operation == 'downloadselected') {
5352
                $this->download_submissions($userlist);
5024
            $this->download_submissions($userlist);
5353
            } else {
5025
        } else {
5354
                foreach ($userlist as $userid) {
5026
            foreach ($userlist as $userid) {
5355
                    if ($data->operation == 'lock') {
5027
                if ($operation == 'lock') {
5356
                        $this->process_lock_submission($userid);
-
 
5357
                    } else if ($data->operation == 'unlock') {
5028
                    $this->process_lock_submission($userid);
5358
                        $this->process_unlock_submission($userid);
5029
                } else if ($operation == 'unlock') {
5359
                    } else if ($data->operation == 'reverttodraft') {
5030
                    $this->process_unlock_submission($userid);
-
 
5031
                } else if ($operation == 'reverttodraft') {
5360
                        $this->process_revert_to_draft($userid);
5032
                    $this->process_revert_to_draft($userid);
5361
                    } else if ($data->operation == 'removesubmission') {
5033
                } else if ($operation == 'removesubmission') {
5362
                        $this->process_remove_submission($userid);
5034
                    $this->process_remove_submission($userid);
5363
                    } else if ($data->operation == 'addattempt') {
-
 
5364
                        if (!$this->get_instance()->teamsubmission) {
5035
                } else if ($operation == 'addattempt') {
Línea 5365... Línea 5036...
5365
                            $this->process_add_attempt($userid);
5036
                    if (!$this->get_instance()->teamsubmission) {
5366
                        }
5037
                        $this->process_add_attempt($userid);
Línea 5367... Línea 5038...
5367
                    }
5038
                    }
5368
                }
5039
                }
-
 
5040
            }
5369
            }
5041
        }
5370
            if ($this->get_instance()->teamsubmission && $data->operation == 'addattempt') {
-
 
5371
                // This needs to be handled separately so that each team submission is only re-opened one time.
5042
        if ($this->get_instance()->teamsubmission && $operation == 'addattempt') {
5372
                $this->process_add_attempt_group($userlist);
5043
            // This needs to be handled separately so that each team submission is only re-opened one time.
5373
            }
5044
            $this->process_add_attempt_group($userlist);
5374
        }
-
 
5375
 
5045
        }
Línea 5376... Línea 5046...
5376
        return 'grading';
5046
 
Línea 5377... Línea 5047...
5377
    }
5047
        return 'grading';
Línea 5378... Línea -...
5378
 
-
 
5379
    /**
5048
    }
5380
     * Shows a form that allows the workflow state for selected submissions to be changed.
5049
 
Línea 5381... Línea -...
5381
     *
-
 
5382
     * @param moodleform $mform Set to a grading batch operations form
5050
    /**
5383
     * @return string - the page to view after processing these actions
5051
     * Shows a form that allows the workflow state for selected submissions to be changed.
5384
     */
-
 
Línea 5385... Línea 5052...
5385
    protected function view_batch_set_workflow_state($mform)
5052
     * You should confirm sesskey before calling this function.
Línea 5386... Línea 5053...
5386
    {
5053
     *
5387
        global $CFG, $DB;
5054
     * @return string - the page to view after processing these actions
Línea 5408... Línea 5075...
5408
        foreach ($userlist as $userid) {
5075
        foreach ($userlist as $userid) {
5409
            if ($usercount >= 5) {
5076
            if ($usercount >= 5) {
5410
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5077
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5411
                break;
5078
                break;
5412
            }
5079
            }
5413
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
5080
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
Línea 5414... Línea 5081...
5414
 
5081
 
5415
            $usershtml .= $this->get_renderer()->render(new assign_user_summary(
-
 
5416
                $user,
5082
            $usershtml .= $this->get_renderer()->render(new assign_user_summary($user,
5417
                $this->get_course()->id,
5083
                                                                $this->get_course()->id,
5418
                $viewfullnames,
5084
                                                                $viewfullnames,
5419
                $this->is_blind_marking(),
5085
                                                                $this->is_blind_marking(),
5420
                $this->get_uniqueid_for_user($user->id),
5086
                                                                $this->get_uniqueid_for_user($user->id),
5421
                $extrauserfields,
5087
                                                                $extrauserfields,
5422
                !$this->is_active_user($userid)
-
 
5423
            ));
5088
                                                                !$this->is_active_user($userid)));
5424
            $usercount += 1;
5089
            $usercount += 1;
Línea 5425... Línea 5090...
5425
        }
5090
        }
5426
 
5091
 
Línea 5430... Línea 5095...
5430
            'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
5095
            'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
5431
        );
5096
        );
Línea 5432... Línea 5097...
5432
 
5097
 
5433
        $mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);
5098
        $mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);
5434
        $mform->set_data($formdata);    // Initialises the hidden elements.
5099
        $mform->set_data($formdata);    // Initialises the hidden elements.
5435
        $header = new assign_header(
-
 
5436
            $this->get_instance(),
5100
        $header = new assign_header($this->get_instance(),
5437
            $this->get_context(),
5101
            $this->get_context(),
5438
            $this->show_intro(),
5102
            $this->show_intro(),
5439
            $this->get_course_module()->id,
5103
            $this->get_course_module()->id,
5440
            get_string('setmarkingworkflowstate', 'assign')
-
 
5441
        );
5104
            get_string('setmarkingworkflowstate', 'assign'));
5442
        $o .= $this->get_renderer()->render($header);
5105
        $o .= $this->get_renderer()->render($header);
5443
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
5106
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
Línea 5444... Línea 5107...
5444
        $o .= $this->view_footer();
5107
        $o .= $this->view_footer();
Línea 5448... Línea 5111...
5448
        return $o;
5111
        return $o;
5449
    }
5112
    }
Línea 5450... Línea 5113...
5450
 
5113
 
5451
    /**
5114
    /**
-
 
5115
     * Shows a form that allows the allocated marker for selected submissions to be changed.
5452
     * Shows a form that allows the allocated marker for selected submissions to be changed.
5116
     * You should confirm sesskey before calling this function.
5453
     *
-
 
5454
     * @param moodleform $mform Set to a grading batch operations form
5117
     *
5455
     * @return string - the page to view after processing these actions
5118
     * @return string - the page to view after processing these actions
5456
     */
5119
     */
5457
    public function view_batch_markingallocation($mform)
-
 
5458
    {
5120
    public function view_batch_markingallocation() {
Línea 5459... Línea 5121...
5459
        global $CFG, $DB;
5121
        global $CFG, $DB;
Línea 5460... Línea 5122...
5460
 
5122
 
Línea 5461... Línea -...
5461
        require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
-
 
5462
 
5123
        require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
5463
        $o = '';
5124
 
Línea 5464... Línea -...
5464
 
-
 
5465
        $submitteddata = $mform->get_data();
5125
        $o = '';
5466
        $users = $submitteddata->selectedusers;
5126
 
5467
        $userlist = explode(',', $users);
-
 
Línea 5468... Línea 5127...
5468
 
5127
        $users = required_param('selectedusers', PARAM_SEQUENCE);
Línea 5469... Línea 5128...
5469
        $formdata = array(
5128
        $userlist = explode(',', $users);
5470
            'id' => $this->get_course_module()->id,
5129
 
Línea 5480... Línea 5139...
5480
        foreach ($userlist as $userid) {
5139
        foreach ($userlist as $userid) {
5481
            if ($usercount >= 5) {
5140
            if ($usercount >= 5) {
5482
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5141
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5483
                break;
5142
                break;
5484
            }
5143
            }
5485
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
5144
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
Línea 5486... Línea 5145...
5486
 
5145
 
5487
            $usershtml .= $this->get_renderer()->render(new assign_user_summary(
-
 
5488
                $user,
5146
            $usershtml .= $this->get_renderer()->render(new assign_user_summary($user,
5489
                $this->get_course()->id,
5147
                $this->get_course()->id,
5490
                $viewfullnames,
5148
                $viewfullnames,
5491
                $this->is_blind_marking(),
5149
                $this->is_blind_marking(),
5492
                $this->get_uniqueid_for_user($user->id),
5150
                $this->get_uniqueid_for_user($user->id),
5493
                $extrauserfields,
5151
                $extrauserfields,
5494
                !$this->is_active_user($userid)
-
 
5495
            ));
5152
                !$this->is_active_user($userid)));
5496
            $usercount += 1;
5153
            $usercount += 1;
Línea 5497... Línea 5154...
5497
        }
5154
        }
5498
 
5155
 
Línea 5511... Línea 5168...
5511
 
5168
 
Línea 5512... Línea 5169...
5512
        $formparams['markers'] = $markerlist;
5169
        $formparams['markers'] = $markerlist;
5513
 
5170
 
5514
        $mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);
5171
        $mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);
5515
        $mform->set_data($formdata);    // Initialises the hidden elements.
-
 
5516
        $header = new assign_header(
5172
        $mform->set_data($formdata);    // Initialises the hidden elements.
5517
            $this->get_instance(),
5173
        $header = new assign_header($this->get_instance(),
5518
            $this->get_context(),
5174
            $this->get_context(),
5519
            $this->show_intro(),
5175
            $this->show_intro(),
5520
            $this->get_course_module()->id,
-
 
5521
            get_string('setmarkingallocation', 'assign')
5176
            $this->get_course_module()->id,
5522
        );
5177
            get_string('setmarkingallocation', 'assign'));
5523
        $o .= $this->get_renderer()->render($header);
5178
        $o .= $this->get_renderer()->render($header);
Línea 5524... Línea 5179...
5524
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
5179
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
Línea 5533... Línea 5188...
5533
     * Ask the user to confirm they want to submit their work for grading.
5188
     * Ask the user to confirm they want to submit their work for grading.
5534
     *
5189
     *
5535
     * @param moodleform $mform - null unless form validation has failed
5190
     * @param moodleform $mform - null unless form validation has failed
5536
     * @return string
5191
     * @return string
5537
     */
5192
     */
5538
    protected function check_submit_for_grading($mform)
5193
    protected function check_submit_for_grading($mform) {
5539
    {
-
 
5540
        global $USER, $CFG;
5194
        global $USER, $CFG;
Línea 5541... Línea 5195...
5541
 
5195
 
Línea 5542... Línea 5196...
5542
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
5196
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
Línea 5583... Línea 5237...
5583
        if (empty($submissionstatement)) {
5237
        if (empty($submissionstatement)) {
5584
            $requiresubmissionstatement = false;
5238
            $requiresubmissionstatement = false;
5585
        }
5239
        }
Línea 5586... Línea 5240...
5586
 
5240
 
5587
        if ($mform == null) {
5241
        if ($mform == null) {
5588
            $mform = new mod_assign_confirm_submission_form(null, array(
5242
            $mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
5589
                $requiresubmissionstatement,
-
 
5590
                $submissionstatement,
5243
                                                                        $submissionstatement,
5591
                $this->get_course_module()->id,
5244
                                                                        $this->get_course_module()->id,
5592
                $data
-
 
5593
            ));
5245
                                                                        $data));
5594
        }
5246
        }
5595
        $o = '';
5247
        $o = '';
5596
        $o .= $this->get_renderer()->render(new assign_header(
-
 
5597
            $this->get_instance(),
5248
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
5598
            $this->get_context(),
5249
                                                              $this->get_context(),
5599
            $this->show_intro(),
5250
                                                              $this->show_intro(),
5600
            $this->get_course_module()->id,
5251
                                                              $this->get_course_module()->id,
5601
            get_string('confirmsubmissionheading', 'assign')
-
 
5602
        ));
5252
                                                              get_string('confirmsubmissionheading', 'assign')));
5603
        $submitforgradingpage = new assign_submit_for_grading_page(
-
 
5604
            $notifications,
5253
        $submitforgradingpage = new assign_submit_for_grading_page($notifications,
5605
            $this->get_course_module()->id,
5254
                                                                   $this->get_course_module()->id,
5606
            $mform
-
 
5607
        );
5255
                                                                   $mform);
5608
        $o .= $this->get_renderer()->render($submitforgradingpage);
5256
        $o .= $this->get_renderer()->render($submitforgradingpage);
Línea 5609... Línea 5257...
5609
        $o .= $this->view_footer();
5257
        $o .= $this->view_footer();
Línea 5618... Línea 5266...
5618
     *
5266
     *
5619
     * @param stdClass $user the user to get the report for
5267
     * @param stdClass $user the user to get the report for
5620
     * @param bool $showlinks return plain text or links to the profile
5268
     * @param bool $showlinks return plain text or links to the profile
5621
     * @return assign_submission_status renderable object
5269
     * @return assign_submission_status renderable object
5622
     */
5270
     */
5623
    public function get_assign_submission_status_renderable($user, $showlinks)
5271
    public function get_assign_submission_status_renderable($user, $showlinks) {
5624
    {
-
 
5625
        global $PAGE;
5272
        global $PAGE;
Línea 5626... Línea 5273...
5626
 
5273
 
5627
        $instance = $this->get_instance();
5274
        $instance = $this->get_instance();
5628
        $flags = $this->get_user_flags($user->id, false);
5275
        $flags = $this->get_user_flags($user->id, false);
Línea 5640... Línea 5287...
5640
            }
5287
            }
5641
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
5288
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
5642
        }
5289
        }
Línea 5643... Línea 5290...
5643
 
5290
 
5644
        $showedit = $showlinks &&
5291
        $showedit = $showlinks &&
5645
            ($this->is_any_submission_plugin_enabled()) &&
5292
                    ($this->is_any_submission_plugin_enabled()) &&
Línea 5646... Línea 5293...
5646
            $this->can_edit_submission($user->id);
5293
                    $this->can_edit_submission($user->id);
Línea 5647... Línea 5294...
5647
 
5294
 
5648
        $submissionlocked = ($flags && $flags->locked);
5295
        $submissionlocked = ($flags && $flags->locked);
Línea 5666... Línea 5313...
5666
        }
5313
        }
5667
        $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
5314
        $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
Línea 5668... Línea 5315...
5668
 
5315
 
5669
        $gradingstatus = $this->get_grading_status($user->id);
5316
        $gradingstatus = $this->get_grading_status($user->id);
5670
        $usergroups = $this->get_all_groups($user->id);
5317
        $usergroups = $this->get_all_groups($user->id);
5671
        $submissionstatus = new assign_submission_status(
-
 
5672
            $instance->allowsubmissionsfromdate,
5318
        $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
5673
            $instance->alwaysshowdescription,
5319
                                                          $instance->alwaysshowdescription,
5674
            $submission,
5320
                                                          $submission,
5675
            $instance->teamsubmission,
5321
                                                          $instance->teamsubmission,
5676
            $teamsubmission,
5322
                                                          $teamsubmission,
5677
            $submissiongroup,
5323
                                                          $submissiongroup,
5678
            $notsubmitted,
5324
                                                          $notsubmitted,
5679
            $this->is_any_submission_plugin_enabled(),
5325
                                                          $this->is_any_submission_plugin_enabled(),
5680
            $submissionlocked,
5326
                                                          $submissionlocked,
5681
            $this->is_graded($user->id),
5327
                                                          $this->is_graded($user->id),
5682
            $instance->duedate,
5328
                                                          $instance->duedate,
5683
            $instance->cutoffdate,
5329
                                                          $instance->cutoffdate,
5684
            $this->get_submission_plugins(),
5330
                                                          $this->get_submission_plugins(),
5685
            $this->get_return_action(),
5331
                                                          $this->get_return_action(),
5686
            $this->get_return_params(),
5332
                                                          $this->get_return_params(),
5687
            $this->get_course_module()->id,
5333
                                                          $this->get_course_module()->id,
5688
            $this->get_course()->id,
5334
                                                          $this->get_course()->id,
5689
            assign_submission_status::STUDENT_VIEW,
5335
                                                          assign_submission_status::STUDENT_VIEW,
5690
            $showedit,
5336
                                                          $showedit,
5691
            $showsubmit,
5337
                                                          $showsubmit,
5692
            $viewfullnames,
5338
                                                          $viewfullnames,
5693
            $extensionduedate,
5339
                                                          $extensionduedate,
5694
            $this->get_context(),
5340
                                                          $this->get_context(),
5695
            $this->is_blind_marking(),
5341
                                                          $this->is_blind_marking(),
5696
            $gradingcontrollerpreview,
5342
                                                          $gradingcontrollerpreview,
5697
            $instance->attemptreopenmethod,
5343
                                                          $instance->attemptreopenmethod,
5698
            $instance->maxattempts,
5344
                                                          $instance->maxattempts,
5699
            $gradingstatus,
5345
                                                          $gradingstatus,
5700
            $instance->preventsubmissionnotingroup,
5346
                                                          $instance->preventsubmissionnotingroup,
5701
            $usergroups,
5347
                                                          $usergroups,
5702
            $instance->timelimit
-
 
5703
        );
5348
                                                          $instance->timelimit);
5704
        return $submissionstatus;
5349
        return $submissionstatus;
Línea 5705... Línea 5350...
5705
    }
5350
    }
5706
 
5351
 
5707
 
5352
 
5708
    /**
5353
    /**
5709
     * Creates an assign_feedback_status renderable.
5354
     * Creates an assign_feedback_status renderable.
5710
     *
5355
     *
5711
     * @param stdClass $user the user to get the report for
5356
     * @param stdClass $user the user to get the report for
5712
     * @return assign_feedback_status renderable object
-
 
5713
     */
5357
     * @return assign_feedback_status renderable object
Línea 5714... Línea 5358...
5714
    public function get_assign_feedback_status_renderable($user)
5358
     */
5715
    {
5359
    public function get_assign_feedback_status_renderable($user) {
Línea 5716... Línea 5360...
5716
        global $CFG, $DB, $PAGE;
5360
        global $CFG, $DB, $PAGE;
5717
 
5361
 
5718
        require_once($CFG->libdir . '/gradelib.php');
5362
        require_once($CFG->libdir.'/gradelib.php');
Línea 5719... Línea 5363...
5719
        require_once($CFG->dirroot . '/grade/grading/lib.php');
5363
        require_once($CFG->dirroot.'/grade/grading/lib.php');
5720
 
5364
 
5721
        $instance = $this->get_instance();
-
 
5722
        $grade = $this->get_user_grade($user->id, false);
5365
        $instance = $this->get_instance();
5723
        $gradingstatus = $this->get_grading_status($user->id);
5366
        $grade = $this->get_user_grade($user->id, false);
5724
 
5367
        $gradingstatus = $this->get_grading_status($user->id);
5725
        $gradinginfo = grade_get_grades(
-
 
Línea 5726... Línea 5368...
5726
            $this->get_course()->id,
5368
 
5727
            'mod',
5369
        $gradinginfo = grade_get_grades($this->get_course()->id,
5728
            'assign',
5370
                                    'mod',
5729
            $instance->id,
5371
                                    'assign',
Línea 5753... Línea 5395...
5753
            $emptyplugins = true; // Don't show feedback plugins until released either.
5395
            $emptyplugins = true; // Don't show feedback plugins until released either.
5754
        }
5396
        }
Línea 5755... Línea 5397...
5755
 
5397
 
5756
        $cangrade = has_capability('mod/assign:grade', $this->get_context());
5398
        $cangrade = has_capability('mod/assign:grade', $this->get_context());
5757
        $hasgrade = $this->get_instance()->grade != GRADE_TYPE_NONE &&
5399
        $hasgrade = $this->get_instance()->grade != GRADE_TYPE_NONE &&
5758
            !is_null($gradebookgrade) && !is_null($gradebookgrade->grade);
5400
                        !is_null($gradebookgrade) && !is_null($gradebookgrade->grade);
5759
        $gradevisible = $cangrade || $this->get_instance()->grade == GRADE_TYPE_NONE ||
5401
        $gradevisible = $cangrade || $this->get_instance()->grade == GRADE_TYPE_NONE ||
5760
            (!is_null($gradebookgrade) && !$gradebookgrade->hidden);
5402
                        (!is_null($gradebookgrade) && !$gradebookgrade->hidden);
5761
        // If there is a visible grade, show the summary.
5403
        // If there is a visible grade, show the summary.
Línea 5762... Línea 5404...
5762
        if (($hasgrade || !$emptyplugins) && $gradevisible) {
5404
        if (($hasgrade || !$emptyplugins) && $gradevisible) {
5763
 
5405
 
Línea 5776... Línea 5418...
5776
                        $grade->id,
5418
                        $grade->id,
5777
                        $gradingitem,
5419
                        $gradingitem,
5778
                        '',
5420
                        '',
5779
                        $cangrade
5421
                        $cangrade
5780
                    );
5422
                    );
-
 
5423
                    // Display the penalty indicator next to the penalized grade, if applicable.
-
 
5424
                    $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator(
-
 
5425
                        new \grade_grade([
-
 
5426
                            'deductedmark' => $gradebookgrade->deductedmark ?? 0,
-
 
5427
                            'overridden' => $gradebookgrade->overridden ?? 0,
-
 
5428
                        ], false)
-
 
5429
                    );
-
 
5430
 
5781
                    $gradefordisplay = $gradebookgrade->str_long_grade;
5431
                    $gradefordisplay = $penaltyindicator . $gradebookgrade->str_long_grade;
5782
                } else {
5432
                } else {
-
 
5433
                    // This grade info is the grade from gradebook.
-
 
5434
                    // We need user id to determine if the grade is overridden or not.
5783
                    $gradefordisplay = $this->display_grade($gradebookgrade->grade, false);
5435
                    $gradefordisplay = $this->display_grade(
-
 
5436
                        $gradebookgrade->grade,
-
 
5437
                        false,
-
 
5438
                        $user->id,
-
 
5439
                        0,
-
 
5440
                        $gradebookgrade->deductedmark
-
 
5441
                    );
5784
                }
5442
                }
5785
                $gradeddate = $gradebookgrade->dategraded;
5443
                $gradeddate = $gradebookgrade->dategraded;
Línea 5786... Línea 5444...
5786
 
5444
 
5787
                // Show the grader's identity if 'Hide Grader' is disabled or has the 'Show Hidden Grader' capability.
5445
                // Show the grader's identity if 'Hide Grader' is disabled or has the 'Show Hidden Grader' capability.
5788
                if (has_capability('mod/assign:showhiddengrader', $this->context) || !$this->is_hidden_grader()) {
5446
                if (has_capability('mod/assign:showhiddengrader', $this->context) || !$this->is_hidden_grader()) {
5789
                    // Only display the grader if it is in the right state.
5447
                    // Only display the grader if it is in the right state.
5790
                    if (in_array($gradingstatus, [ASSIGN_GRADING_STATUS_GRADED, ASSIGN_MARKING_WORKFLOW_STATE_RELEASED])) {
5448
                    if (in_array($gradingstatus, [ASSIGN_GRADING_STATUS_GRADED, ASSIGN_MARKING_WORKFLOW_STATE_RELEASED])) {
5791
                        if (isset($grade->grader) && $grade->grader > 0) {
5449
                        if (isset($grade->grader) && $grade->grader > 0) {
5792
                            $grader = $DB->get_record('user', array('id' => $grade->grader));
-
 
5793
                        } else if (
5450
                            $grader = $DB->get_record('user', array('id' => $grade->grader));
5794
                            isset($gradebookgrade->usermodified)
5451
                        } else if (isset($gradebookgrade->usermodified)
5795
                            && $gradebookgrade->usermodified > 0
5452
                            && $gradebookgrade->usermodified > 0
5796
                            && has_capability('mod/assign:grade', $this->get_context(), $gradebookgrade->usermodified)
-
 
5797
                        ) {
5453
                            && has_capability('mod/assign:grade', $this->get_context(), $gradebookgrade->usermodified)) {
5798
                            // Grader not provided. Check that usermodified is a user who can grade.
5454
                            // Grader not provided. Check that usermodified is a user who can grade.
5799
                            // Case 1: When an assignment is reopened an empty assign_grade is created so the feedback
5455
                            // Case 1: When an assignment is reopened an empty assign_grade is created so the feedback
5800
                            // plugin can know which attempt it's referring to. In this case, usermodifed is a student.
5456
                            // plugin can know which attempt it's referring to. In this case, usermodifed is a student.
5801
                            // Case 2: When an assignment's grade is overrided via the gradebook, usermodified is a grader.
5457
                            // Case 2: When an assignment's grade is overrided via the gradebook, usermodified is a grader.
Línea 5832... Línea 5488...
5832
     * Creates an assign_attempt_history renderable.
5488
     * Creates an assign_attempt_history renderable.
5833
     *
5489
     *
5834
     * @param stdClass $user the user to get the report for
5490
     * @param stdClass $user the user to get the report for
5835
     * @return assign_attempt_history renderable object
5491
     * @return assign_attempt_history renderable object
5836
     */
5492
     */
5837
    public function get_assign_attempt_history_renderable($user)
5493
    public function get_assign_attempt_history_renderable($user) {
5838
    {
-
 
Línea 5839... Línea 5494...
5839
 
5494
 
5840
        $allsubmissions = $this->get_all_submissions($user->id);
5495
        $allsubmissions = $this->get_all_submissions($user->id);
Línea 5841... Línea 5496...
5841
        $allgrades = $this->get_all_grades($user->id);
5496
        $allgrades = $this->get_all_grades($user->id);
5842
 
-
 
5843
        $history = new assign_attempt_history(
5497
 
5844
            $allsubmissions,
5498
        $history = new assign_attempt_history($allsubmissions,
5845
            $allgrades,
5499
                                              $allgrades,
5846
            $this->get_submission_plugins(),
5500
                                              $this->get_submission_plugins(),
5847
            $this->get_feedback_plugins(),
5501
                                              $this->get_feedback_plugins(),
5848
            $this->get_course_module()->id,
5502
                                              $this->get_course_module()->id,
5849
            $this->get_return_action(),
5503
                                              $this->get_return_action(),
5850
            $this->get_return_params(),
5504
                                              $this->get_return_params(),
5851
            false,
5505
                                              false,
5852
            0,
-
 
5853
            0
5506
                                              0,
5854
        );
5507
                                              0);
Línea 5855... Línea 5508...
5855
        return $history;
5508
        return $history;
5856
    }
5509
    }
Línea 5861... Línea 5514...
5861
     *
5514
     *
5862
     * @param stdClass $user the user to print the report for
5515
     * @param stdClass $user the user to print the report for
5863
     * @param bool $showlinks - Return plain text or links to the profile
5516
     * @param bool $showlinks - Return plain text or links to the profile
5864
     * @return string - the html summary
5517
     * @return string - the html summary
5865
     */
5518
     */
5866
    public function view_student_summary($user, $showlinks)
5519
    public function view_student_summary($user, $showlinks) {
5867
    {
-
 
Línea 5868... Línea 5520...
5868
 
5520
 
Línea 5869... Línea 5521...
5869
        $o = '';
5521
        $o = '';
5870
 
5522
 
Línea 5896... Línea 5548...
5896
     * @param stdClass $submission The users own submission record.
5548
     * @param stdClass $submission The users own submission record.
5897
     * @param stdClass $teamsubmission The users team submission record if there is one
5549
     * @param stdClass $teamsubmission The users team submission record if there is one
5898
     * @param int $userid The user
5550
     * @param int $userid The user
5899
     * @return bool
5551
     * @return bool
5900
     */
5552
     */
5901
    protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null)
5553
    protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null) {
5902
    {
-
 
5903
        if (!has_capability('mod/assign:submit', $this->get_context(), $userid, false)) {
5554
        if (!has_capability('mod/assign:submit', $this->get_context(), $userid, false)) {
5904
            // The user does not have the capability to submit.
5555
            // The user does not have the capability to submit.
5905
            return false;
5556
            return false;
5906
        }
5557
        }
5907
        if ($teamsubmission) {
5558
        if ($teamsubmission) {
Línea 5942... Línea 5593...
5942
     * and gradefordisplay is added (rendered from grading manager).
5593
     * and gradefordisplay is added (rendered from grading manager).
5943
     *
5594
     *
5944
     * @param int $userid If not set, $USER->id will be used.
5595
     * @param int $userid If not set, $USER->id will be used.
5945
     * @return array $grades All grade records for this user.
5596
     * @return array $grades All grade records for this user.
5946
     */
5597
     */
5947
    protected function get_all_grades($userid)
5598
    protected function get_all_grades($userid) {
5948
    {
-
 
5949
        global $DB, $USER, $PAGE;
5599
        global $DB, $USER, $PAGE;
Línea 5950... Línea 5600...
5950
 
5600
 
5951
        // If the userid is not null then use userid.
5601
        // If the userid is not null then use userid.
5952
        if (!$userid) {
5602
        if (!$userid) {
5953
            $userid = $USER->id;
5603
            $userid = $USER->id;
Línea 5954... Línea 5604...
5954
        }
5604
        }
Línea 5955... Línea 5605...
5955
 
5605
 
Línea 5956... Línea 5606...
5956
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
5606
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
5957
 
5607
 
Línea 5968... Línea 5618...
5968
 
5618
 
5969
        // Need gradingitem and gradingmanager.
5619
        // Need gradingitem and gradingmanager.
5970
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
5620
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
Línea 5971... Línea 5621...
5971
        $controller = $gradingmanager->get_active_controller();
5621
        $controller = $gradingmanager->get_active_controller();
5972
 
5622
 
5973
        $gradinginfo = grade_get_grades(
-
 
5974
            $this->get_course()->id,
5623
        $gradinginfo = grade_get_grades($this->get_course()->id,
5975
            'mod',
5624
                                        'mod',
5976
            'assign',
5625
                                        'assign',
5977
            $this->get_instance()->id,
-
 
Línea 5978... Línea 5626...
5978
            $userid
5626
                                        $this->get_instance()->id,
5979
        );
5627
                                        $userid);
5980
 
5628
 
5981
        $gradingitem = null;
5629
        $gradingitem = null;
Línea 5989... Línea 5637...
5989
                $grade->grader = null;
5637
                $grade->grader = null;
5990
            } else if (isset($gradercache[$grade->grader])) {
5638
            } else if (isset($gradercache[$grade->grader])) {
5991
                $grade->grader = $gradercache[$grade->grader];
5639
                $grade->grader = $gradercache[$grade->grader];
5992
            } else if ($grade->grader > 0) {
5640
            } else if ($grade->grader > 0) {
5993
                // Not in cache - need to load the grader record.
5641
                // Not in cache - need to load the grader record.
5994
                $grade->grader = $DB->get_record('user', array('id' => $grade->grader));
5642
                $grade->grader = $DB->get_record('user', array('id'=>$grade->grader));
5995
                if ($grade->grader) {
5643
                if ($grade->grader) {
5996
                    $gradercache[$grade->grader->id] = $grade->grader;
5644
                    $gradercache[$grade->grader->id] = $grade->grader;
5997
                }
5645
                }
5998
            }
5646
            }
Línea -... Línea 5647...
-
 
5647
 
-
 
5648
            // The assign grade for each attempt is not stored in the gradebook.
-
 
5649
            // We need to calculate them from assign_grade records.
-
 
5650
            [$penalisedgrade, $deductedmark] = $this->calculate_penalised_grade($grade);
5999
 
5651
 
6000
            // Now get the gradefordisplay.
5652
            // Now get the gradefordisplay.
6001
            if ($controller) {
5653
            if ($controller) {
6002
                $controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
5654
                $controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
6003
                $grade->gradefordisplay = $controller->render_grade(
5655
                // Display the penalty indicator next to the penalized grade, if applicable.
6004
                    $PAGE,
5656
                $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator(
6005
                    $grade->id,
5657
                    new \grade_grade([
6006
                    $gradingitem,
5658
                        'deductedmark' => $deductedmark,
6007
                    $grade->grade,
5659
                        'overridden' => $userid > 0 ? $this->get_grade_item()->get_grade($userid)->overridden : 0,
6008
                    $cangrade
5660
                    ], false)
-
 
5661
                );
-
 
5662
                $gradeoutput = $penaltyindicator . format_float($penalisedgrade, $this->get_grade_item()->get_decimals());
-
 
5663
 
6009
                );
5664
                $grade->gradefordisplay = $controller->render_grade($PAGE, $grade->id, $gradingitem, $gradeoutput, $cangrade);
-
 
5665
            } else {
6010
            } else {
5666
                // We do not need user id here as the overriden grade should not affect the previous attempts.
6011
                $grade->gradefordisplay = $this->display_grade($grade->grade, false);
5667
                $grade->gradefordisplay = $this->display_grade($penalisedgrade, false, 0, 0, $deductedmark);
-
 
5668
            }
6012
            }
5669
 
Línea 6013... Línea 5670...
6013
        }
5670
        }
6014
 
5671
 
Línea 6015... Línea 5672...
6015
        return $grades;
5672
        return $grades;
-
 
5673
    }
-
 
5674
 
-
 
5675
    /**
-
 
5676
     * Calculate penalised grade and deducted mark.
-
 
5677
     *
-
 
5678
     * @param stdClass $grade The grade object
-
 
5679
     * @return array [$penalisedgrade, $deductedmark] the penalised grade and the deducted mark
-
 
5680
     */
-
 
5681
    public function calculate_penalised_grade(stdClass $grade): array {
-
 
5682
        $penalisedgrade = $grade->grade;
-
 
5683
        $deductedmark = 0;
-
 
5684
 
-
 
5685
        // No calculation needed if the grade is null or negative.
-
 
5686
        if (is_null($penalisedgrade) || $penalisedgrade < 0) {
-
 
5687
            return [$penalisedgrade, $deductedmark];
-
 
5688
        }
-
 
5689
 
-
 
5690
        if ($grade->penalty > 0) {
-
 
5691
            $deductedmark = $grade->grade * $grade->penalty / 100;
-
 
5692
            $penalisedgrade = $grade->grade - $deductedmark;
-
 
5693
        }
-
 
5694
        return [$penalisedgrade, $deductedmark];
6016
    }
5695
    }
6017
 
5696
 
6018
    /**
5697
    /**
6019
     * Get the submissions for all previous attempts.
5698
     * Get the submissions for all previous attempts.
6020
     *
5699
     *
6021
     * @param int $userid If not set, $USER->id will be used.
5700
     * @param int $userid If not set, $USER->id will be used.
6022
     * @return array $submissions All submission records for this user (or group).
-
 
6023
     */
5701
     * @return array $submissions All submission records for this user (or group).
Línea 6024... Línea 5702...
6024
    public function get_all_submissions($userid)
5702
     */
6025
    {
5703
    public function get_all_submissions($userid) {
6026
        global $DB, $USER;
5704
        global $DB, $USER;
Línea 6038... Línea 5716...
6038
            if ($group) {
5716
            if ($group) {
6039
                $groupid = $group->id;
5717
                $groupid = $group->id;
6040
            }
5718
            }
Línea 6041... Línea 5719...
6041
 
5719
 
6042
            // Params to get the group submissions.
5720
            // Params to get the group submissions.
6043
            $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
5721
            $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
6044
        } else {
5722
        } else {
6045
            // Params to get the user submissions.
5723
            // Params to get the user submissions.
6046
            $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
5724
            $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
Línea 6047... Línea 5725...
6047
        }
5725
        }
6048
 
5726
 
Línea 6056... Línea 5734...
6056
     * Creates an assign_grading_summary renderable.
5734
     * Creates an assign_grading_summary renderable.
6057
     *
5735
     *
6058
     * @param mixed $activitygroup int|null the group for calculating the grading summary (if null the function will determine it)
5736
     * @param mixed $activitygroup int|null the group for calculating the grading summary (if null the function will determine it)
6059
     * @return assign_grading_summary renderable object
5737
     * @return assign_grading_summary renderable object
6060
     */
5738
     */
6061
    public function get_assign_grading_summary_renderable($activitygroup = null)
5739
    public function get_assign_grading_summary_renderable($activitygroup = null) {
6062
    {
-
 
Línea 6063... Línea 5740...
6063
 
5740
 
6064
        $instance = $this->get_default_instance(); // Grading summary requires the raw dates, regardless of relativedates mode.
5741
        $instance = $this->get_default_instance(); // Grading summary requires the raw dates, regardless of relativedates mode.
6065
        $cm = $this->get_course_module();
5742
        $cm = $this->get_course_module();
Línea 6134... Línea 5811...
6134
     * Helper function to allow up to fetch the group overrides via one query as opposed to many calls.
5811
     * Helper function to allow up to fetch the group overrides via one query as opposed to many calls.
6135
     *
5812
     *
6136
     * @param int $activitygroup The group we want to check the overrides of
5813
     * @param int $activitygroup The group we want to check the overrides of
6137
     * @return mixed Can return either a fetched DB object, local object or false
5814
     * @return mixed Can return either a fetched DB object, local object or false
6138
     */
5815
     */
6139
    private function get_override_data(int $activitygroup)
5816
    private function get_override_data(int $activitygroup) {
6140
    {
-
 
6141
        global $DB;
5817
        global $DB;
Línea 6142... Línea 5818...
6142
 
5818
 
6143
        $instanceid = $this->get_instance()->id;
5819
        $instanceid = $this->get_instance()->id;
6144
        $cachekey = "$instanceid-$activitygroup";
5820
        $cachekey = "$instanceid-$activitygroup";
Línea 6155... Línea 5831...
6155
     * Return group override duedate.
5831
     * Return group override duedate.
6156
     *
5832
     *
6157
     * @param int $activitygroup Activity active group
5833
     * @param int $activitygroup Activity active group
6158
     * @return int $duedate
5834
     * @return int $duedate
6159
     */
5835
     */
6160
    private function get_duedate($activitygroup = null)
5836
    private function get_duedate($activitygroup = null) {
6161
    {
-
 
6162
        if ($activitygroup === null) {
5837
        if ($activitygroup === null) {
6163
            $activitygroup = groups_get_activity_group($this->get_course_module());
5838
            $activitygroup = groups_get_activity_group($this->get_course_module());
6164
        }
5839
        }
6165
        if ($this->can_view_grades() && !empty($activitygroup)) {
5840
        if ($this->can_view_grades() && !empty($activitygroup)) {
6166
            $groupoverride = $this->get_override_data($activitygroup);
5841
            $groupoverride = $this->get_override_data($activitygroup);
Línea 6175... Línea 5850...
6175
     * Return group override timelimit.
5850
     * Return group override timelimit.
6176
     *
5851
     *
6177
     * @param null|int $activitygroup Activity active group
5852
     * @param null|int $activitygroup Activity active group
6178
     * @return int $timelimit
5853
     * @return int $timelimit
6179
     */
5854
     */
6180
    private function get_timelimit(?int $activitygroup = null): int
5855
    private function get_timelimit(?int $activitygroup = null): int {
6181
    {
-
 
6182
        if ($activitygroup === null) {
5856
        if ($activitygroup === null) {
6183
            $activitygroup = groups_get_activity_group($this->get_course_module());
5857
            $activitygroup = groups_get_activity_group($this->get_course_module());
6184
        }
5858
        }
6185
        if ($this->can_view_grades() && !empty($activitygroup)) {
5859
        if ($this->can_view_grades() && !empty($activitygroup)) {
6186
            $groupoverride = $this->get_override_data($activitygroup);
5860
            $groupoverride = $this->get_override_data($activitygroup);
Línea 6195... Línea 5869...
6195
     * Return group override cutoffdate.
5869
     * Return group override cutoffdate.
6196
     *
5870
     *
6197
     * @param null|int $activitygroup Activity active group
5871
     * @param null|int $activitygroup Activity active group
6198
     * @return int $cutoffdate
5872
     * @return int $cutoffdate
6199
     */
5873
     */
6200
    private function get_cutoffdate(?int $activitygroup = null): int
5874
    private function get_cutoffdate(?int $activitygroup = null): int {
6201
    {
-
 
6202
        if ($activitygroup === null) {
5875
        if ($activitygroup === null) {
6203
            $activitygroup = groups_get_activity_group($this->get_course_module());
5876
            $activitygroup = groups_get_activity_group($this->get_course_module());
6204
        }
5877
        }
6205
        if ($this->can_view_grades() && !empty($activitygroup)) {
5878
        if ($this->can_view_grades() && !empty($activitygroup)) {
6206
            $groupoverride = $this->get_override_data($activitygroup);
5879
            $groupoverride = $this->get_override_data($activitygroup);
Línea 6214... Línea 5887...
6214
    /**
5887
    /**
6215
     * View submissions page (contains details of current submission).
5888
     * View submissions page (contains details of current submission).
6216
     *
5889
     *
6217
     * @return string
5890
     * @return string
6218
     */
5891
     */
6219
    protected function view_submission_page()
5892
    protected function view_submission_page() {
6220
    {
-
 
6221
        global $CFG, $DB, $USER, $PAGE;
5893
        global $CFG, $DB, $USER, $PAGE;
Línea 6222... Línea 5894...
6222
 
5894
 
Línea 6223... Línea 5895...
6223
        $instance = $this->get_instance();
5895
        $instance = $this->get_instance();
Línea 6229... Línea 5901...
6229
        $postfix = '';
5901
        $postfix = '';
6230
        if ($this->has_visible_attachments() && (!$this->get_instance($USER->id)->submissionattachments)) {
5902
        if ($this->has_visible_attachments() && (!$this->get_instance($USER->id)->submissionattachments)) {
6231
            $postfix = $this->render_area_files('mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
5903
            $postfix = $this->render_area_files('mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
6232
        }
5904
        }
Línea 6233... Línea 5905...
6233
 
5905
 
6234
        $o .= $this->get_renderer()->render(new assign_header(
-
 
6235
            $instance,
5906
        $o .= $this->get_renderer()->render(new assign_header($instance,
6236
            $this->get_context(),
5907
                                                      $this->get_context(),
6237
            $this->show_intro(),
5908
                                                      $this->show_intro(),
6238
            $this->get_course_module()->id,
-
 
6239
            '',
-
 
6240
            '',
5909
                                                      $this->get_course_module()->id,
6241
            $postfix
-
 
Línea 6242... Línea 5910...
6242
        ));
5910
                                                      '', '', $postfix));
6243
 
5911
 
6244
        // Display plugin specific headers.
5912
        // Display plugin specific headers.
6245
        $plugins = array_merge($this->get_submission_plugins(), $this->get_feedback_plugins());
5913
        $plugins = array_merge($this->get_submission_plugins(), $this->get_feedback_plugins());
Línea 6274... Línea 5942...
6274
     *
5942
     *
6275
     * @param stdClass $instance The settings for the current instance of this assignment
5943
     * @param stdClass $instance The settings for the current instance of this assignment
6276
     * @param stdClass $user The user to print the action bar for
5944
     * @param stdClass $user The user to print the action bar for
6277
     * @return string
5945
     * @return string
6278
     */
5946
     */
6279
    public function view_submission_action_bar(stdClass $instance, stdClass $user): string
5947
    public function view_submission_action_bar(stdClass $instance, stdClass $user): string {
6280
    {
-
 
6281
        $submission = $this->get_user_submission($user->id, false);
5948
        $submission = $this->get_user_submission($user->id, false);
6282
        // Figure out if we are team or solitary submission.
5949
        // Figure out if we are team or solitary submission.
6283
        $teamsubmission = null;
5950
        $teamsubmission = null;
6284
        if ($instance->teamsubmission) {
5951
        if ($instance->teamsubmission) {
6285
            $teamsubmission = $this->get_group_submission($user->id, 0, false);
5952
            $teamsubmission = $this->get_group_submission($user->id, 0, false);
Línea 6313... Línea 5980...
6313
     * Convert the final raw grade(s) in the grading table for the gradebook.
5980
     * Convert the final raw grade(s) in the grading table for the gradebook.
6314
     *
5981
     *
6315
     * @param stdClass $grade
5982
     * @param stdClass $grade
6316
     * @return array
5983
     * @return array
6317
     */
5984
     */
6318
    protected function convert_grade_for_gradebook(stdClass $grade)
5985
    protected function convert_grade_for_gradebook(stdClass $grade) {
6319
    {
-
 
6320
        $gradebookgrade = array();
5986
        $gradebookgrade = array();
6321
        if ($grade->grade >= 0) {
5987
        if ($grade->grade >= 0) {
6322
            $gradebookgrade['rawgrade'] = $grade->grade;
5988
            $gradebookgrade['rawgrade'] = $grade->grade;
6323
        }
5989
        }
6324
        // Allow "no grade" to be chosen.
5990
        // Allow "no grade" to be chosen.
Línea 6346... Línea 6012...
6346
     * Convert submission details for the gradebook.
6012
     * Convert submission details for the gradebook.
6347
     *
6013
     *
6348
     * @param stdClass $submission
6014
     * @param stdClass $submission
6349
     * @return array
6015
     * @return array
6350
     */
6016
     */
6351
    protected function convert_submission_for_gradebook(stdClass $submission)
6017
    protected function convert_submission_for_gradebook(stdClass $submission) {
6352
    {
-
 
6353
        $gradebookgrade = array();
6018
        $gradebookgrade = array();
Línea 6354... Línea 6019...
6354
 
6019
 
6355
        $gradebookgrade['userid'] = $submission->userid;
6020
        $gradebookgrade['userid'] = $submission->userid;
6356
        $gradebookgrade['usermodified'] = $submission->userid;
6021
        $gradebookgrade['usermodified'] = $submission->userid;
Línea 6364... Línea 6029...
6364
     *
6029
     *
6365
     * @param mixed $submission stdClass|null
6030
     * @param mixed $submission stdClass|null
6366
     * @param mixed $grade stdClass|null
6031
     * @param mixed $grade stdClass|null
6367
     * @return bool
6032
     * @return bool
6368
     */
6033
     */
6369
    protected function gradebook_item_update($submission = null, $grade = null)
6034
    protected function gradebook_item_update($submission=null, $grade=null) {
6370
    {
-
 
6371
        global $CFG;
6035
        global $CFG;
Línea 6372... Línea 6036...
6372
 
6036
 
6373
        require_once($CFG->dirroot . '/mod/assign/lib.php');
6037
        require_once($CFG->dirroot.'/mod/assign/lib.php');
6374
        // Do not push grade to gradebook if blind marking is active as
6038
        // Do not push grade to gradebook if blind marking is active as
6375
        // the gradebook would reveal the students.
6039
        // the gradebook would reveal the students.
6376
        if ($this->is_blind_marking()) {
6040
        if ($this->is_blind_marking() && !$this->is_marking_anonymous()) {
6377
            return false;
6041
            return false;
Línea 6378... Línea 6042...
6378
        }
6042
        }
6379
 
-
 
6380
        // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook.
6043
 
6381
        if (
6044
        // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook.
6382
            $this->get_instance()->markingworkflow && !empty($grade) &&
-
 
6383
            $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
6045
        if ($this->get_instance()->markingworkflow && !empty($grade) &&
6384
        ) {
6046
                $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
6385
            // Remove the grade (if it exists) from the gradebook as it is not 'final'.
6047
            // Remove the grade (if it exists) from the gradebook as it is not 'final'.
6386
            $grade->grade = -1;
6048
            $grade->grade = -1;
6387
            $grade->feedbacktext = '';
6049
            $grade->feedbacktext = '';
Línea 6401... Línea 6063...
6401
                }
6063
                }
6402
                return;
6064
                return;
6403
            }
6065
            }
Línea 6404... Línea 6066...
6404
 
6066
 
-
 
6067
            $gradebookgrade = $this->convert_submission_for_gradebook($submission);
6405
            $gradebookgrade = $this->convert_submission_for_gradebook($submission);
6068
 
6406
        } else {
6069
        } else {
6407
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
6070
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
6408
        }
6071
        }
6409
        // Grading is disabled, return.
6072
        // Grading is disabled, return.
Línea 6423... Línea 6086...
6423
     * @param stdClass $submission
6086
     * @param stdClass $submission
6424
     * @param int $userid
6087
     * @param int $userid
6425
     * @param bool $updatetime
6088
     * @param bool $updatetime
6426
     * @return bool
6089
     * @return bool
6427
     */
6090
     */
6428
    protected function update_team_submission(stdClass $submission, $userid, $updatetime)
6091
    protected function update_team_submission(stdClass $submission, $userid, $updatetime) {
6429
    {
-
 
6430
        global $DB;
6092
        global $DB;
Línea 6431... Línea 6093...
6431
 
6093
 
6432
        if ($updatetime) {
6094
        if ($updatetime) {
6433
            $submission->timemodified = time();
6095
            $submission->timemodified = time();
Línea 6448... Línea 6110...
6448
        if (!in_array($submission->status, [ASSIGN_SUBMISSION_STATUS_NEW, ASSIGN_SUBMISSION_STATUS_REOPENED])) {
6110
        if (!in_array($submission->status, [ASSIGN_SUBMISSION_STATUS_NEW, ASSIGN_SUBMISSION_STATUS_REOPENED])) {
6449
            foreach ($team as $member) {
6111
            foreach ($team as $member) {
6450
                $membersubmission = $this->get_user_submission($member->id, false, $submission->attemptnumber);
6112
                $membersubmission = $this->get_user_submission($member->id, false, $submission->attemptnumber);
Línea 6451... Línea 6113...
6451
 
6113
 
6452
                // If no submission found for team member and member is active then everyone has not submitted.
-
 
6453
                if (
6114
                // If no submission found for team member and member is active then everyone has not submitted.
6454
                    !$membersubmission || $membersubmission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED
6115
                if (!$membersubmission || $membersubmission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED
6455
                    && ($this->is_active_user($member->id))
-
 
6456
                ) {
6116
                        && ($this->is_active_user($member->id))) {
6457
                    $allsubmitted = false;
6117
                    $allsubmitted = false;
6458
                    if ($anysubmitted) {
6118
                    if ($anysubmitted) {
6459
                        break;
6119
                        break;
6460
                    }
6120
                    }
Línea 6498... Línea 6158...
6498
     * @param int $userid
6158
     * @param int $userid
6499
     * @param bool $updatetime
6159
     * @param bool $updatetime
6500
     * @param bool $teamsubmission
6160
     * @param bool $teamsubmission
6501
     * @return bool
6161
     * @return bool
6502
     */
6162
     */
6503
    protected function update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission)
6163
    protected function update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission) {
6504
    {
-
 
6505
        global $DB;
6164
        global $DB;
Línea 6506... Línea 6165...
6506
 
6165
 
6507
        if ($teamsubmission) {
6166
        if ($teamsubmission) {
6508
            return $this->update_team_submission($submission, $userid, $updatetime);
6167
            return $this->update_team_submission($submission, $userid, $updatetime);
Línea 6509... Línea 6168...
6509
        }
6168
        }
6510
 
6169
 
6511
        if ($updatetime) {
6170
        if ($updatetime) {
6512
            $submission->timemodified = time();
6171
            $submission->timemodified = time();
6513
        }
6172
        }
6514
        $result = $DB->update_record('assign_submission', $submission);
6173
        $result= $DB->update_record('assign_submission', $submission);
6515
        if ($result) {
6174
        if ($result) {
6516
            $this->gradebook_item_update($submission);
6175
            $this->gradebook_item_update($submission);
6517
        }
6176
        }
Línea 6531... Línea 6190...
6531
     * @param stdClass $submission - Pre-fetched submission record (or false to fetch it)
6190
     * @param stdClass $submission - Pre-fetched submission record (or false to fetch it)
6532
     * @param stdClass $flags - Pre-fetched user flags record (or false to fetch it)
6191
     * @param stdClass $flags - Pre-fetched user flags record (or false to fetch it)
6533
     * @param stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)
6192
     * @param stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)
6534
     * @return bool
6193
     * @return bool
6535
     */
6194
     */
6536
    public function submissions_open(
6195
    public function submissions_open($userid = 0,
6537
        $userid = 0,
-
 
6538
        $skipenrolled = false,
6196
                                     $skipenrolled = false,
6539
        $submission = false,
6197
                                     $submission = false,
6540
        $flags = false,
6198
                                     $flags = false,
6541
        $gradinginfo = false
6199
                                     $gradinginfo = false) {
6542
    ) {
-
 
6543
        global $USER;
6200
        global $USER;
Línea 6544... Línea 6201...
6544
 
6201
 
6545
        if (!$userid) {
6202
        if (!$userid) {
6546
            $userid = $USER->id;
6203
            $userid = $USER->id;
Línea 6600... Línea 6257...
6600
            }
6257
            }
6601
        }
6258
        }
Línea 6602... Línea 6259...
6602
 
6259
 
6603
        // See if this user grade is locked in the gradebook.
6260
        // See if this user grade is locked in the gradebook.
6604
        if ($gradinginfo === false) {
6261
        if ($gradinginfo === false) {
6605
            $gradinginfo = grade_get_grades(
6262
            $gradinginfo = grade_get_grades($this->get_course()->id,
6606
                $this->get_course()->id,
-
 
6607
                'mod',
6263
                                            'mod',
6608
                'assign',
6264
                                            'assign',
6609
                $this->get_instance()->id,
6265
                                            $this->get_instance()->id,
6610
                array($userid)
-
 
6611
            );
6266
                                            array($userid));
6612
        }
-
 
6613
        if (
6267
        }
6614
            $gradinginfo &&
6268
        if ($gradinginfo &&
6615
            isset($gradinginfo->items[0]->grades[$userid]) &&
6269
                isset($gradinginfo->items[0]->grades[$userid]) &&
6616
            $gradinginfo->items[0]->grades[$userid]->locked
-
 
6617
        ) {
6270
                $gradinginfo->items[0]->grades[$userid]->locked) {
6618
            return false;
6271
            return false;
Línea 6619... Línea 6272...
6619
        }
6272
        }
6620
 
6273
 
Línea 6627... Línea 6280...
6627
     * @param string $component
6280
     * @param string $component
6628
     * @param string $area
6281
     * @param string $area
6629
     * @param int $submissionid
6282
     * @param int $submissionid
6630
     * @return string
6283
     * @return string
6631
     */
6284
     */
6632
    public function render_area_files($component, $area, $submissionid)
6285
    public function render_area_files($component, $area, $submissionid) {
6633
    {
-
 
6634
        global $USER;
6286
        global $USER;
Línea 6635... Línea 6287...
6635
 
6287
 
6636
        return $this->get_renderer()->assign_files(
-
 
6637
            $this->context,
-
 
6638
            $submissionid,
-
 
6639
            $area,
-
 
6640
            $component,
-
 
6641
            $this->course,
6288
        return $this->get_renderer()->assign_files($this->context, $submissionid, $area, $component,
6642
            $this->coursemodule
6289
                                                   $this->course, $this->coursemodule);
6643
        );
6290
 
Línea 6644... Línea 6291...
6644
    }
6291
    }
6645
 
6292
 
6646
    /**
6293
    /**
6647
     * Capability check to make sure this grader can edit this submission.
6294
     * Capability check to make sure this grader can edit this submission.
6648
     *
6295
     *
6649
     * @param int $userid - The user whose submission is to be edited
6296
     * @param int $userid - The user whose submission is to be edited
6650
     * @param int $graderid (optional) - The user who will do the editing (default to $USER->id).
6297
     * @param int $graderid (optional) - The user who will do the editing (default to $USER->id).
6651
     * @return bool
6298
     * @return bool
6652
     */
-
 
6653
    public function can_edit_submission($userid, $graderid = 0)
6299
     */
Línea 6654... Línea 6300...
6654
    {
6300
    public function can_edit_submission($userid, $graderid = 0) {
6655
        global $USER;
6301
        global $USER;
6656
 
6302
 
Línea 6657... Línea 6303...
6657
        if (empty($graderid)) {
6303
        if (empty($graderid)) {
6658
            $graderid = $USER->id;
-
 
6659
        }
6304
            $graderid = $USER->id;
6660
 
6305
        }
6661
        $instance = $this->get_instance();
6306
 
6662
        if (
6307
        $instance = $this->get_instance();
6663
            $userid == $graderid &&
-
 
6664
            $instance->teamsubmission &&
6308
        if ($userid == $graderid &&
6665
            $instance->preventsubmissionnotingroup &&
6309
            $instance->teamsubmission &&
Línea 6666... Línea 6310...
6666
            $this->get_submission_group($userid) == false
6310
            $instance->preventsubmissionnotingroup &&
6667
        ) {
-
 
6668
            return false;
6311
            $this->get_submission_group($userid) == false) {
6669
        }
6312
            return false;
6670
 
-
 
6671
        if ($userid == $graderid) {
6313
        }
6672
            if (
6314
 
6673
                $this->submissions_open($userid) &&
6315
        if ($userid == $graderid) {
6674
                has_capability('mod/assign:submit', $this->context, $graderid)
6316
            if ($this->submissions_open($userid) &&
6675
            ) {
6317
                    has_capability('mod/assign:submit', $this->context, $graderid)) {
Línea 6684... Línea 6326...
6684
        if (!has_capability('mod/assign:editothersubmission', $this->context, $graderid)) {
6326
        if (!has_capability('mod/assign:editothersubmission', $this->context, $graderid)) {
6685
            return false;
6327
            return false;
6686
        }
6328
        }
Línea 6687... Línea 6329...
6687
 
6329
 
6688
        $cm = $this->get_course_module();
6330
        $cm = $this->get_course_module();
-
 
6331
        if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS &&
6689
        if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) {
6332
                !has_capability('moodle/site:accessallgroups', $this->context, $graderid)) {
6690
            $sharedgroupmembers = $this->get_shared_group_members($cm, $graderid);
6333
            $sharedgroupmembers = $this->get_shared_group_members($cm, $graderid);
6691
            return in_array($userid, $sharedgroupmembers);
6334
            return in_array($userid, $sharedgroupmembers);
6692
        }
6335
        }
6693
        return true;
6336
        return true;
Línea 6698... Línea 6341...
6698
     *
6341
     *
6699
     * @param stdClass|cm_info $cm Course-module
6342
     * @param stdClass|cm_info $cm Course-module
6700
     * @param int $userid User ID
6343
     * @param int $userid User ID
6701
     * @return array An array of ID of users.
6344
     * @return array An array of ID of users.
6702
     */
6345
     */
6703
    public function get_shared_group_members($cm, $userid)
6346
    public function get_shared_group_members($cm, $userid) {
6704
    {
-
 
6705
        if (!isset($this->sharedgroupmembers[$userid])) {
6347
        if (!isset($this->sharedgroupmembers[$userid])) {
6706
            $this->sharedgroupmembers[$userid] = array();
6348
            $this->sharedgroupmembers[$userid] = array();
6707
            if ($members = groups_get_activity_shared_group_members($cm, $userid)) {
6349
            if ($members = groups_get_activity_shared_group_members($cm, $userid)) {
6708
                $this->sharedgroupmembers[$userid] = array_keys($members);
6350
                $this->sharedgroupmembers[$userid] = array_keys($members);
6709
            }
6351
            }
Línea 6716... Línea 6358...
6716
     * Returns a list of teachers that should be grading given submission.
6358
     * Returns a list of teachers that should be grading given submission.
6717
     *
6359
     *
6718
     * @param int $userid The submission to grade
6360
     * @param int $userid The submission to grade
6719
     * @return array
6361
     * @return array
6720
     */
6362
     */
6721
    protected function get_graders($userid)
6363
    protected function get_graders($userid) {
6722
    {
-
 
6723
        // Potential graders should be active users only.
6364
        // Potential graders should be active users only.
6724
        $potentialgraders = get_enrolled_users($this->context, "mod/assign:grade", null, 'u.*', null, null, null, true);
6365
        $potentialgraders = get_enrolled_users($this->context, "mod/assign:grade", null, 'u.*', null, null, null, true);
Línea 6725... Línea 6366...
6725
 
6366
 
6726
        $graders = array();
6367
        $graders = array();
Línea 6768... Línea 6409...
6768
     * Returns a list of users that should receive notification about given submission.
6409
     * Returns a list of users that should receive notification about given submission.
6769
     *
6410
     *
6770
     * @param int $userid The submission to grade
6411
     * @param int $userid The submission to grade
6771
     * @return array
6412
     * @return array
6772
     */
6413
     */
6773
    protected function get_notifiable_users($userid)
6414
    protected function get_notifiable_users($userid) {
6774
    {
-
 
6775
        // Potential users should be active users only.
6415
        // Potential users should be active users only.
6776
        $potentialusers = get_enrolled_users(
6416
        $potentialusers = get_enrolled_users($this->context, "mod/assign:receivegradernotifications",
6777
            $this->context,
-
 
6778
            "mod/assign:receivegradernotifications",
6417
                                             null, 'u.*', null, null, null, true);
6779
            null,
-
 
6780
            'u.*',
-
 
6781
            null,
-
 
6782
            null,
-
 
6783
            null,
-
 
6784
            true
-
 
6785
        );
-
 
Línea 6786... Línea 6418...
6786
 
6418
 
6787
        $notifiableusers = array();
6419
        $notifiableusers = array();
6788
        if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) {
6420
        if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) {
6789
            if ($groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_course_module()->groupingid)) {
6421
            if ($groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_course_module()->groupingid)) {
Línea 6824... Línea 6456...
6824
        }
6456
        }
6825
        return $notifiableusers;
6457
        return $notifiableusers;
6826
    }
6458
    }
Línea 6827... Línea 6459...
6827
 
6459
 
6828
    /**
-
 
6829
     * Format a notification for plain text.
-
 
6830
     *
-
 
6831
     * @param string $messagetype
-
 
6832
     * @param stdClass $info
-
 
6833
     * @param stdClass $course
-
 
6834
     * @param stdClass $context
-
 
6835
     * @param string $modulename
-
 
6836
     * @param string $assignmentname
-
 
6837
     */
-
 
6838
    protected static function format_notification_message_text(
-
 
6839
        $messagetype,
-
 
6840
        $info,
-
 
6841
        $course,
-
 
6842
        $context,
-
 
6843
        $modulename,
-
 
6844
        $assignmentname
-
 
6845
    ) {
-
 
6846
        $formatparams = array('context' => $context->get_course_context());
-
 
6847
        $posttext  = format_string($course->shortname, true, $formatparams) .
-
 
6848
            ' -> ' .
-
 
6849
            $modulename .
-
 
6850
            ' -> ' .
-
 
6851
            format_string($assignmentname, true, $formatparams) . "\n";
-
 
6852
        $posttext .= '---------------------------------------------------------------------' . "\n";
-
 
6853
        $posttext .= get_string($messagetype . 'text', 'assign', $info) . "\n";
-
 
6854
        $posttext .= "\n---------------------------------------------------------------------\n";
-
 
6855
        return $posttext;
-
 
6856
    }
-
 
6857
 
-
 
6858
    /**
-
 
6859
     * Format a notification for HTML.
-
 
6860
     *
-
 
6861
     * @param string $messagetype
-
 
6862
     * @param stdClass $info
-
 
6863
     * @param stdClass $course
-
 
6864
     * @param stdClass $context
-
 
6865
     * @param string $modulename
-
 
6866
     * @param stdClass $coursemodule
-
 
6867
     * @param string $assignmentname
-
 
6868
     */
-
 
6869
    protected static function format_notification_message_html(
-
 
6870
        $messagetype,
-
 
6871
        $info,
-
 
6872
        $course,
-
 
6873
        $context,
-
 
6874
        $modulename,
-
 
6875
        $coursemodule,
-
 
6876
        $assignmentname
-
 
6877
    ) {
-
 
6878
        global $CFG;
-
 
6879
        $formatparams = array('context' => $context->get_course_context());
-
 
6880
        $posthtml  = '<p><font face="sans-serif">' .
-
 
6881
            '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' .
-
 
6882
            format_string($course->shortname, true, $formatparams) .
-
 
6883
            '</a> ->' .
-
 
6884
            '<a href="' . $CFG->wwwroot . '/mod/assign/index.php?id=' . $course->id . '">' .
-
 
6885
            $modulename .
-
 
6886
            '</a> ->' .
-
 
6887
            '<a href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id . '">' .
-
 
6888
            format_string($assignmentname, true, $formatparams) .
-
 
6889
            '</a></font></p>';
-
 
6890
        $posthtml .= '<hr /><font face="sans-serif">';
-
 
6891
        $posthtml .= '<p>' . get_string($messagetype . 'html', 'assign', $info) . '</p>';
-
 
6892
        $posthtml .= '</font><hr />';
-
 
6893
        return $posthtml;
-
 
6894
    }
-
 
6895
 
-
 
6896
    /**
6460
    /**
6897
     * Message someone about something (static so it can be called from cron).
6461
     * Message someone about something (static so it can be called from cron).
6898
     *
6462
     *
6899
     * @param stdClass $userfrom
6463
     * @param stdClass $userfrom
6900
     * @param stdClass $userto
6464
     * @param stdClass $userto
6901
     * @param string $messagetype
6465
     * @param string $messagetype
6902
     * @param string $eventtype
6466
     * @param string $eventtype
6903
     * @param int $updatetime
6467
     * @param int $updatetime
6904
     * @param stdClass $coursemodule
6468
     * @param stdClass $coursemodule
6905
     * @param stdClass $context
6469
     * @param context $context
6906
     * @param stdClass $course
6470
     * @param stdClass $course
6907
     * @param string $modulename
6471
     * @param string $modulename - no longer used.
6908
     * @param string $assignmentname
6472
     * @param string $assignmentname
6909
     * @param bool $blindmarking
6473
     * @param bool $blindmarking
-
 
6474
     * @param int $uniqueidforuser
6910
     * @param int $uniqueidforuser
6475
     * @param array $extrainfo extra values to pass to any language strings or templates used in preparing the message.
6911
     * @return void
6476
     * @return void
6912
     */
6477
     */
6913
    public static function send_assignment_notification(
-
 
6914
        $userfrom,
6478
    public static function send_assignment_notification($userfrom,
6915
        $userto,
6479
                                                        $userto,
6916
        $messagetype,
6480
                                                        $messagetype,
6917
        $eventtype,
6481
                                                        $eventtype,
6918
        $updatetime,
6482
                                                        $updatetime,
6919
        $coursemodule,
6483
                                                        $coursemodule,
6920
        $context,
6484
                                                        $context,
6921
        $course,
6485
                                                        $course,
6922
        $modulename,
6486
                                                        $modulename,
6923
        $assignmentname,
6487
                                                        $assignmentname,
6924
        $blindmarking,
6488
                                                        $blindmarking,
6925
        $uniqueidforuser
6489
                                                        $uniqueidforuser,
6926
    ) {
6490
                                                        $extrainfo = []) {
Línea -... Línea 6491...
-
 
6491
        global $CFG, $PAGE;
-
 
6492
 
-
 
6493
        // We put more data into info that is used by the default language strings,
-
 
6494
        // so that there is more flexibility for organisations that want to use
-
 
6495
        // Language Customisation to customise the messages.
6927
        global $CFG, $PAGE;
6496
 
6928
 
6497
        // Information about the sender - normally the user who performed the action.
6929
        $info = new stdClass();
6498
        $info = new stdClass();
6930
        if ($blindmarking) {
6499
        if ($blindmarking) {
6931
            $userfrom = clone ($userfrom);
6500
            $userfrom = clone($userfrom);
6932
            $info->username = get_string('participant', 'assign') . ' ' . $uniqueidforuser;
6501
            $info->username = get_string('participant', 'assign') . ' ' . $uniqueidforuser;
6933
            $userfrom->firstname = get_string('participant', 'assign');
6502
            $userfrom->firstname = get_string('participant', 'assign');
6934
            $userfrom->lastname = $uniqueidforuser;
6503
            $userfrom->lastname = $uniqueidforuser;
6935
            $userfrom->email = $CFG->noreplyaddress;
6504
            $userfrom->email = $CFG->noreplyaddress;
6936
        } else {
6505
        } else {
-
 
6506
            $info->username = core_user::get_fullname($userfrom, $context, ['override' => true]);
-
 
6507
        }
-
 
6508
 
-
 
6509
        // Information about the recipient (for greeting, etc.).
-
 
6510
        $info->recipentname = core_user::get_fullname($userto, $context, ['override' => true]);
6937
            $info->username = fullname($userfrom, true);
6511
 
6938
        }
6512
        // Information about the assignment.
-
 
6513
        $info->assignment = format_string($assignmentname, true, ['context' => $context]);
-
 
6514
        $info->url = $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id;
-
 
6515
        // Note: URLs here avoid the & character to avoid escaping issues between text and HTML messages.
-
 
6516
        $info->assignmentlink  = '<a href="' . $info->url . '">' . s($info->assignment) . ' report</a>';
-
 
6517
        $info->assigncmid = $coursemodule->id;
-
 
6518
 
-
 
6519
        // Information about the course.
-
 
6520
        $info->courseshortname = format_string($course->shortname, true, ['context' => $context]);
-
 
6521
        $info->coursefullname = format_string($course->fullname, true, ['context' => $context]);
-
 
6522
        // Note: URLs here avoid the & character to avoid escaping issues between text and HTML messages.
-
 
6523
        $info->courseurl = $CFG->wwwroot . '/course/view.php?id=' . $course->id;
-
 
6524
        $info->courseassignsurl = $CFG->wwwroot . '/mod/assign/index.php?id=' . $course->id;
6939
        $info->assignment = format_string($assignmentname, true, array('context' => $context));
6525
 
-
 
6526
        // Time of the action.
-
 
6527
        $info->timeupdated = userdate($updatetime);
-
 
6528
 
-
 
6529
        // Other data passed in.
-
 
6530
        $info = (object) array_merge((array) $info, $extrainfo);
-
 
6531
 
-
 
6532
        // Since format_string returns text with HTML characters escaped,
-
 
6533
        // we need to un-escape before including in the plain text email and subject line.
-
 
6534
        // (Test with a course or assignment called "Escaping & unescaping" to understand).
-
 
6535
        $plaintextinfo = clone $info;
-
 
6536
        $plaintextinfo->assignment = html_entity_decode($info->assignment);
-
 
6537
        $plaintextinfo->courseshortname = html_entity_decode($info->courseshortname);
-
 
6538
        $plaintextinfo->coursefullname = html_entity_decode($info->coursefullname);
-
 
6539
 
-
 
6540
        // Prepare the message subject and bodies.
-
 
6541
        $postsubject = get_string($messagetype . 'small', 'assign', $plaintextinfo);
-
 
6542
        $smsmessage = get_string($messagetype . 'sms', 'assign', $plaintextinfo);
-
 
6543
 
-
 
6544
        $renderer = $PAGE->get_renderer('mod_assign');
-
 
6545
        $context = clone $plaintextinfo;
-
 
6546
        $context->messagetext = get_string($messagetype . 'text', 'assign', $plaintextinfo);
-
 
6547
        // Mustache strips off all training whitespace, but we want a newline at the end.
Línea 6940... Línea -...
6940
        $info->url = $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id;
-
 
6941
        $info->timeupdated = userdate($updatetime, get_string('strftimerecentfull'));
-
 
6942
 
-
 
6943
        $postsubject = get_string($messagetype . 'small', 'assign', $info);
-
 
6944
        $posttext = self::format_notification_message_text(
-
 
6945
            $messagetype,
-
 
6946
            $info,
-
 
6947
            $course,
-
 
6948
            $context,
-
 
6949
            $modulename,
6548
        $posttext = $renderer->render_from_template(
6950
            $assignmentname
6549
            'mod_assign/messages/notification_text', $context) . "\n";
6951
        );
-
 
6952
        $posthtml = '';
-
 
6953
        if ($userto->mailformat == 1) {
6550
 
6954
            $posthtml = self::format_notification_message_html(
-
 
6955
                $messagetype,
-
 
6956
                $info,
6551
        $posthtml = '';
6957
                $course,
6552
        if ($userto->mailformat == 1) {
6958
                $context,
6553
            $context = clone $info;
6959
                $modulename,
-
 
6960
                $coursemodule,
6554
            $context->messagehtml = get_string($messagetype . 'html', 'assign', $info);
Línea -... Línea 6555...
-
 
6555
            $posthtml = $renderer->render_from_template(
6961
                $assignmentname
6556
                'mod_assign/messages/notification_html', $context);
6962
            );
6557
        }
6963
        }
6558
 
6964
 
6559
        // Build the message object.
6965
        $eventdata = new \core\message\message();
6560
        $eventdata = new \core\message\message();
6966
        $eventdata->courseid         = $course->id;
6561
        $eventdata->courseid         = $course->id;
6967
        $eventdata->modulename       = 'assign';
6562
        $eventdata->modulename       = 'assign';
6968
        $eventdata->userfrom         = $userfrom;
6563
        $eventdata->userfrom         = $userfrom;
6969
        $eventdata->userto           = $userto;
6564
        $eventdata->userto           = $userto;
-
 
6565
        $eventdata->subject          = $postsubject;
6970
        $eventdata->subject          = $postsubject;
6566
        $eventdata->fullmessage      = $posttext;
Línea 6971... Línea 6567...
6971
        $eventdata->fullmessage      = $posttext;
6567
        $eventdata->fullmessageformat = FORMAT_PLAIN;
6972
        $eventdata->fullmessageformat = FORMAT_PLAIN;
6568
        $eventdata->fullmessagehtml  = $posthtml;
6973
        $eventdata->fullmessagehtml  = $posthtml;
6569
        $eventdata->fullmessagesms   = $smsmessage;
Línea 7003... Línea 6599...
7003
     * @param stdClass $userfrom
6599
     * @param stdClass $userfrom
7004
     * @param stdClass $userto
6600
     * @param stdClass $userto
7005
     * @param string $messagetype
6601
     * @param string $messagetype
7006
     * @param string $eventtype
6602
     * @param string $eventtype
7007
     * @param int $updatetime
6603
     * @param int $updatetime
-
 
6604
     * @param array $extrainfo extra values to pass to any language strings or templates used in preparing the message.
7008
     * @return void
6605
     * @return void
7009
     */
6606
     */
7010
    public function send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime)
6607
    public function send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime, $extrainfo = []) {
7011
    {
-
 
7012
        global $USER;
6608
        global $USER;
7013
        $userid = core_user::is_real_user($userfrom->id) ? $userfrom->id : $USER->id;
6609
        $userid = core_user::is_real_user($userfrom->id) ? $userfrom->id : $USER->id;
7014
        $uniqueid = $this->get_uniqueid_for_user($userid);
6610
        $uniqueid = $this->get_uniqueid_for_user($userid);
7015
        self::send_assignment_notification(
6611
        $oldforcelang = force_current_language($userto->lang);
7016
            $userfrom,
6612
        self::send_assignment_notification($userfrom,
7017
            $userto,
6613
                                           $userto,
7018
            $messagetype,
6614
                                           $messagetype,
7019
            $eventtype,
6615
                                           $eventtype,
7020
            $updatetime,
6616
                                           $updatetime,
7021
            $this->get_course_module(),
6617
                                           $this->get_course_module(),
7022
            $this->get_context(),
6618
                                           $this->get_context(),
7023
            $this->get_course(),
6619
                                           $this->get_course(),
7024
            $this->get_module_name(),
6620
                                           $this->get_module_name(),
7025
            $this->get_instance()->name,
6621
                                           $this->get_instance()->name,
7026
            $this->is_blind_marking(),
6622
                                           $this->is_blind_marking(),
7027
            $uniqueid
6623
                                           $uniqueid,
-
 
6624
                                           $extrainfo);
7028
        );
6625
        force_current_language($oldforcelang);
7029
    }
6626
    }
Línea 7030... Línea 6627...
7030
 
6627
 
7031
    /**
6628
    /**
7032
     * Notify student upon successful submission copy.
6629
     * Notify student upon successful submission copy.
7033
     *
6630
     *
7034
     * @param stdClass $submission
6631
     * @param stdClass $submission
7035
     * @return void
6632
     * @return void
7036
     */
6633
     */
7037
    protected function notify_student_submission_copied(stdClass $submission)
-
 
7038
    {
6634
    protected function notify_student_submission_copied(stdClass $submission) {
Línea 7039... Línea 6635...
7039
        global $DB, $USER;
6635
        global $DB, $USER;
7040
 
6636
 
7041
        $adminconfig = $this->get_admin_config();
6637
        $adminconfig = $this->get_admin_config();
7042
        // Use the same setting for this - no need for another one.
6638
        // Use the same setting for this - no need for another one.
7043
        if (empty($adminconfig->submissionreceipts)) {
6639
        if (empty($adminconfig->submissionreceipts)) {
7044
            // No need to do anything.
6640
            // No need to do anything.
7045
            return;
6641
            return;
7046
        }
6642
        }
7047
        if ($submission->userid) {
6643
        if ($submission->userid) {
7048
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6644
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
7049
        } else {
6645
        } else {
7050
            $user = $USER;
6646
            $user = $USER;
7051
        }
-
 
7052
        $this->send_notification(
6647
        }
7053
            $user,
6648
        $this->send_notification($user,
7054
            $user,
6649
                                 $user,
7055
            'submissioncopied',
6650
                                 'submissioncopied',
7056
            'assign_notification',
-
 
7057
            $submission->timemodified
6651
                                 'assign_notification',
7058
        );
6652
                                 $submission->timemodified);
7059
    }
6653
    }
7060
    /**
6654
    /**
7061
     * Notify student upon successful submission.
6655
     * Notify student upon successful submission.
7062
     *
6656
     *
7063
     * @param stdClass $submission
6657
     * @param stdClass $submission
7064
     * @return void
6658
     * @return void
7065
     */
-
 
7066
    protected function notify_student_submission_receipt(stdClass $submission)
6659
     */
Línea 7067... Línea 6660...
7067
    {
6660
    protected function notify_student_submission_receipt(stdClass $submission) {
7068
        global $DB, $USER;
6661
        global $DB, $USER;
7069
 
6662
 
7070
        $adminconfig = $this->get_admin_config();
6663
        $adminconfig = $this->get_admin_config();
7071
        if (empty($adminconfig->submissionreceipts)) {
6664
        if (empty($adminconfig->submissionreceipts)) {
7072
            // No need to do anything.
6665
            // No need to do anything.
7073
            return;
6666
            return;
7074
        }
6667
        }
7075
        if ($submission->userid) {
6668
        if ($submission->userid) {
7076
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6669
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
-
 
6670
        } else {
-
 
6671
            $user = $USER;
-
 
6672
        }
-
 
6673
        // Prepare extra data for submission receipt notification.
7077
        } else {
6674
        $oldforcelang = force_current_language($user->lang);
7078
            $user = $USER;
-
 
7079
        }
6675
        $extrainfo = $this->get_submission_summaries_for_messages($submission);
7080
        if ($submission->userid == $USER->id) {
6676
        force_current_language($oldforcelang);
7081
            $this->send_notification(
6677
        if ($submission->userid == $USER->id) {
7082
                core_user::get_noreply_user(),
6678
            $this->send_notification(core_user::get_noreply_user(),
7083
                $user,
6679
                                     $user,
7084
                'submissionreceipt',
6680
                                     'submissionreceipt',
7085
                'assign_notification',
6681
                                     'assign_notification',
7086
                $submission->timemodified
6682
                                     $submission->timemodified,
7087
            );
-
 
7088
        } else {
6683
                                     $extrainfo);
7089
            $this->send_notification(
6684
        } else {
7090
                $USER,
6685
            $this->send_notification($USER,
7091
                $user,
6686
                                     $user,
7092
                'submissionreceiptother',
6687
                                     'submissionreceiptother',
7093
                'assign_notification',
6688
                                     'assign_notification',
7094
                $submission->timemodified
6689
                                     $submission->timemodified,
Línea 7095... Línea 6690...
7095
            );
6690
                                     $extrainfo);
-
 
6691
        }
-
 
6692
    }
-
 
6693
 
-
 
6694
    /**
-
 
6695
     * Produce a summary of a submission that can be used in messages.
-
 
6696
     *
-
 
6697
     * This function iterates through all enabled submission plugins and calls their
-
 
6698
     * `get_submission_summary` method (if implemented). It aggregates the results
-
 
6699
     * into a formatted summary string.
-
 
6700
     *
-
 
6701
     * @param stdClass $submission the submission the message is about. Row from assign_submission table.
-
 
6702
     * @return string[] with two elements:
-
 
6703
     *      'submissionsummarytext' => a plain text summary,
-
 
6704
     *      'submissionsummaryhtml' => an HTML summary.
-
 
6705
     */
-
 
6706
    protected function get_submission_summaries_for_messages(stdClass $submission): array {
-
 
6707
        $textsummaries = [];
-
 
6708
        $htmlsummaries = [];
-
 
6709
        foreach ($this->submissionplugins as $plugin) {
-
 
6710
            if ($plugin->is_enabled() && $plugin->is_visible()) {
-
 
6711
                [$textsummary, $htmlsummary] = $plugin->submission_summary_for_messages($submission);
-
 
6712
                if ($textsummary) {
-
 
6713
                    $textsummaries[] = $textsummary;
-
 
6714
                }
-
 
6715
                if ($htmlsummary) {
-
 
6716
                    $htmlsummaries[] = $htmlsummary;
-
 
6717
                }
-
 
6718
            }
-
 
6719
        }
-
 
6720
 
-
 
6721
        $textsummary = '';
-
 
6722
        if ($textsummaries) {
-
 
6723
            $textsummary = get_string('submissioncontains', 'assign') . "\n\n" .
-
 
6724
                implode("\n", $textsummaries);
-
 
6725
        }
-
 
6726
 
-
 
6727
        $htmlsummary = '';
-
 
6728
        if ($htmlsummaries) {
-
 
6729
            $htmlsummary = html_writer::tag('h2', get_string('submissioncontains', 'assign')) .
-
 
6730
                implode('', $htmlsummaries);
-
 
6731
        }
-
 
6732
 
-
 
6733
        return [
-
 
6734
            'submissionsummarytext' => $textsummary,
-
 
6735
            'submissionsummaryhtml' => $htmlsummary,
7096
        }
6736
        ];
7097
    }
6737
    }
7098
 
6738
 
7099
    /**
6739
    /**
7100
     * Send notifications to graders upon student submissions.
6740
     * Send notifications to graders upon student submissions.
7101
     *
6741
     *
7102
     * @param stdClass $submission
-
 
7103
     * @return void
6742
     * @param stdClass $submission
Línea 7104... Línea 6743...
7104
     */
6743
     * @return void
Línea 7105... Línea 6744...
7105
    protected function notify_graders(stdClass $submission)
6744
     */
Línea 7114... Línea 6753...
7114
            // No need to do anything.
6753
            // No need to do anything.
7115
            return;
6754
            return;
7116
        }
6755
        }
Línea 7117... Línea 6756...
7117
 
6756
 
7118
        if ($submission->userid) {
6757
        if ($submission->userid) {
7119
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6758
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
7120
        } else {
6759
        } else {
7121
            $user = $USER;
6760
            $user = $USER;
Línea 7122... Línea 6761...
7122
        }
6761
        }
7123
 
6762
 
7124
        if ($notifyusers = $this->get_notifiable_users($user->id)) {
6763
        if ($notifyusers = $this->get_notifiable_users($user->id)) {
7125
            foreach ($notifyusers as $notifyuser) {
-
 
7126
                $this->send_notification(
6764
            foreach ($notifyusers as $notifyuser) {
7127
                    $user,
6765
                $this->send_notification($user,
7128
                    $notifyuser,
6766
                                         $notifyuser,
7129
                    'gradersubmissionupdated',
6767
                                         'gradersubmissionupdated',
7130
                    'assign_notification',
-
 
7131
                    $submission->timemodified
6768
                                         'assign_notification',
7132
                );
6769
                                         $submission->timemodified);
7133
            }
6770
            }
Línea 7134... Línea 6771...
7134
        }
6771
        }
Línea 7139... Línea 6776...
7139
     *
6776
     *
7140
     * @param stdClass $data - The form data
6777
     * @param stdClass $data - The form data
7141
     * @param array $notices - List of error messages to display on an error condition.
6778
     * @param array $notices - List of error messages to display on an error condition.
7142
     * @return bool Return false if the submission was not submitted.
6779
     * @return bool Return false if the submission was not submitted.
7143
     */
6780
     */
7144
    public function submit_for_grading($data, $notices)
6781
    public function submit_for_grading($data, $notices) {
7145
    {
-
 
7146
        global $USER;
6782
        global $USER;
Línea 7147... Línea 6783...
7147
 
6783
 
7148
        $userid = $USER->id;
6784
        $userid = $USER->id;
7149
        if (!empty($data->userid)) {
6785
        if (!empty($data->userid)) {
Línea 7176... Línea 6812...
7176
        $submissionstatement = '';
6812
        $submissionstatement = '';
7177
        if ($instance->requiresubmissionstatement) {
6813
        if ($instance->requiresubmissionstatement) {
7178
            $submissionstatement = $this->get_submissionstatement($adminconfig, $instance, $this->context);
6814
            $submissionstatement = $this->get_submissionstatement($adminconfig, $instance, $this->context);
7179
        }
6815
        }
Línea 7180... Línea -...
7180
 
-
 
7181
        if (
6816
 
7182
            !empty($submissionstatement) && $instance->requiresubmissionstatement
6817
        if (!empty($submissionstatement) && $instance->requiresubmissionstatement
7183
            && empty($data->submissionstatement) && $USER->id == $userid
-
 
7184
        ) {
6818
                && empty($data->submissionstatement) && $USER->id == $userid) {
7185
            return false;
6819
            return false;
Línea 7186... Línea 6820...
7186
        }
6820
        }
7187
 
6821
 
Línea 7196... Línea 6830...
7196
 
6830
 
7197
            $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
6831
            $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
7198
            $this->update_submission($submission, $userid, true, $instance->teamsubmission);
6832
            $this->update_submission($submission, $userid, true, $instance->teamsubmission);
7199
            $completion = new completion_info($this->get_course());
6833
            $completion = new completion_info($this->get_course());
7200
            if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
6834
            if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7201
                $this->update_activity_completion_records(
-
 
7202
                    $instance->teamsubmission,
6835
                $this->update_activity_completion_records($instance->teamsubmission,
7203
                    $instance->requireallteammemberssubmit,
6836
                                                          $instance->requireallteammemberssubmit,
7204
                    $submission,
6837
                                                          $submission,
7205
                    $userid,
6838
                                                          $userid,
7206
                    COMPLETION_COMPLETE,
6839
                                                          COMPLETION_COMPLETE,
7207
                    $completion
-
 
7208
                );
6840
                                                          $completion);
Línea 7209... Línea 6841...
7209
            }
6841
            }
7210
 
6842
 
7211
            if (!empty($data->submissionstatement) && $USER->id == $userid) {
6843
            if (!empty($data->submissionstatement) && $USER->id == $userid) {
Línea 7225... Línea 6857...
7225
    /**
6857
    /**
7226
     * A students submission is submitted for grading by a teacher.
6858
     * A students submission is submitted for grading by a teacher.
7227
     *
6859
     *
7228
     * @return bool
6860
     * @return bool
7229
     */
6861
     */
7230
    protected function process_submit_other_for_grading($mform, $notices)
6862
    protected function process_submit_other_for_grading($mform, $notices) {
7231
    {
-
 
7232
        global $USER, $CFG;
6863
        global $USER, $CFG;
Línea 7233... Línea 6864...
7233
 
6864
 
Línea 7234... Línea 6865...
7234
        require_sesskey();
6865
        require_sesskey();
Línea 7249... Línea 6880...
7249
     *
6880
     *
7250
     * @param moodleform|null $mform If validation failed when submitting this form - this is the moodleform.
6881
     * @param moodleform|null $mform If validation failed when submitting this form - this is the moodleform.
7251
     *               It can be null.
6882
     *               It can be null.
7252
     * @return bool Return false if the validation fails. This affects which page is displayed next.
6883
     * @return bool Return false if the validation fails. This affects which page is displayed next.
7253
     */
6884
     */
7254
    protected function process_submit_for_grading($mform, $notices)
6885
    protected function process_submit_for_grading($mform, $notices) {
7255
    {
-
 
7256
        global $CFG;
6886
        global $CFG;
Línea 7257... Línea 6887...
7257
 
6887
 
7258
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
6888
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
Línea 7277... Línea 6907...
7277
        if (empty($submissionstatement)) {
6907
        if (empty($submissionstatement)) {
7278
            $requiresubmissionstatement = false;
6908
            $requiresubmissionstatement = false;
7279
        }
6909
        }
Línea 7280... Línea 6910...
7280
 
6910
 
7281
        if ($mform == null) {
6911
        if ($mform == null) {
7282
            $mform = new mod_assign_confirm_submission_form(null, array(
6912
            $mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
7283
                $requiresubmissionstatement,
-
 
7284
                $submissionstatement,
6913
                                                                    $submissionstatement,
7285
                $this->get_course_module()->id,
6914
                                                                    $this->get_course_module()->id,
7286
                $data
-
 
7287
            ));
6915
                                                                    $data));
Línea 7288... Línea 6916...
7288
        }
6916
        }
7289
 
6917
 
7290
        $data = $mform->get_data();
6918
        $data = $mform->get_data();
Línea 7302... Línea 6930...
7302
     *
6930
     *
7303
     * @param int $userid The user id
6931
     * @param int $userid The user id
7304
     * @param mixed $extensionduedate Either an integer date or null
6932
     * @param mixed $extensionduedate Either an integer date or null
7305
     * @return boolean
6933
     * @return boolean
7306
     */
6934
     */
7307
    public function save_user_extension($userid, $extensionduedate)
6935
    public function save_user_extension($userid, $extensionduedate) {
7308
    {
-
 
7309
        global $DB;
6936
        global $DB, $CFG;
-
 
6937
        require_once($CFG->dirroot.'/calendar/lib.php');
Línea 7310... Línea 6938...
7310
 
6938
 
7311
        // Need submit permission to submit an assignment.
6939
        // Need submit permission to submit an assignment.
Línea 7312... Línea 6940...
7312
        require_capability('mod/assign:grantextension', $this->context);
6940
        require_capability('mod/assign:grantextension', $this->context);
Línea 7334... Línea 6962...
7334
 
6962
 
Línea 7335... Línea 6963...
7335
        $result = $this->update_user_flags($flags);
6963
        $result = $this->update_user_flags($flags);
7336
 
6964
 
-
 
6965
        if ($result) {
-
 
6966
            \mod_assign\event\extension_granted::create_from_assign($this, $userid)->trigger();
-
 
6967
 
-
 
6968
            $cm = $this->get_course_module();
-
 
6969
            $instance = $this->get_instance();
-
 
6970
 
-
 
6971
            if ($extensionduedate) {
-
 
6972
                $event = $DB->get_record('event', [
-
 
6973
                    'userid' => $userid,
-
 
6974
                    'eventtype' => ASSIGN_EVENT_TYPE_EXTENSION,
-
 
6975
                    'modulename' => 'assign',
-
 
6976
                    'instance' => $instance->id,
-
 
6977
                ]);
-
 
6978
 
-
 
6979
                if ($event) {
-
 
6980
                    $event->timestart = $extensionduedate;
-
 
6981
                    $DB->update_record('event', $event);
-
 
6982
                } else {
-
 
6983
                    $event = new stdClass();
-
 
6984
                    $event->type          = CALENDAR_EVENT_TYPE_ACTION;
-
 
6985
                    $event->name          = get_string('calendarextension', 'assign', $instance->name);
-
 
6986
                    $event->description   = format_module_intro('assign', $instance, $cm->id);
-
 
6987
                    $event->format        = FORMAT_HTML;
-
 
6988
                    $event->courseid      = 0;
-
 
6989
                    $event->groupid       = 0;
-
 
6990
                    $event->userid        = $userid;
-
 
6991
                    $event->modulename    = 'assign';
-
 
6992
                    $event->instance      = $instance->id;
-
 
6993
                    $event->timestart     = $extensionduedate;
-
 
6994
                    $event->timeduration  = 0;
-
 
6995
                    $event->visible       = instance_is_visible('assign', $instance);
-
 
6996
                    $event->eventtype     = ASSIGN_EVENT_TYPE_EXTENSION;
-
 
6997
                    $event->priority      = null;
-
 
6998
 
-
 
6999
                    calendar_event::create($event, false);
-
 
7000
                }
-
 
7001
            } else {
-
 
7002
                $DB->delete_records('event', [
-
 
7003
                  'userid' => $userid,
-
 
7004
                  'eventtype' => ASSIGN_EVENT_TYPE_EXTENSION,
-
 
7005
                  'modulename' => 'assign',
-
 
7006
                  'instance' => $instance->id,
7337
        if ($result) {
7007
                ]);
7338
            \mod_assign\event\extension_granted::create_from_assign($this, $userid)->trigger();
7008
            }
7339
        }
7009
        }
Línea 7340... Línea 7010...
7340
        return $result;
7010
        return $result;
7341
    }
7011
    }
7342
 
7012
 
7343
    /**
7013
    /**
7344
     * Save extension date.
7014
     * Save extension date.
7345
     *
7015
     *
7346
     * @param moodleform $mform The submitted form
7016
     * @param moodleform $mform The submitted form
7347
     * @return boolean
-
 
7348
     */
7017
     * @return boolean
Línea 7349... Línea 7018...
7349
    protected function process_save_extension(&$mform)
7018
     */
7350
    {
7019
    protected function process_save_extension(& $mform) {
7351
        global $DB, $CFG;
7020
        global $DB, $CFG;
Línea 7415... Línea 7084...
7415
    /**
7084
    /**
7416
     * Save quick grades.
7085
     * Save quick grades.
7417
     *
7086
     *
7418
     * @return string The result of the save operation
7087
     * @return string The result of the save operation
7419
     */
7088
     */
7420
    protected function process_save_quick_grades()
7089
    protected function process_save_quick_grades() {
7421
    {
-
 
7422
        global $USER, $DB, $CFG;
7090
        global $USER, $DB, $CFG;
Línea 7423... Línea 7091...
7423
 
7091
 
7424
        // Need grade permission.
7092
        // Need grade permission.
7425
        require_capability('mod/assign:grade', $this->context);
7093
        require_capability('mod/assign:grade', $this->context);
Línea 7446... Línea 7114...
7446
            // Gather the userid, updated grade and last modified value.
7114
            // Gather the userid, updated grade and last modified value.
7447
            $record = new stdClass();
7115
            $record = new stdClass();
7448
            $record->userid = $userid;
7116
            $record->userid = $userid;
7449
            if ($modified >= 0) {
7117
            if ($modified >= 0) {
7450
                $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT));
7118
                $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT));
7451
                $record->workflowstate = optional_param('quickgrade_' . $record->userid . '_workflowstate', false, PARAM_ALPHA);
7119
                $record->workflowstate = optional_param('quickgrade_' . $record->userid.'_workflowstate', false, PARAM_ALPHA);
7452
                $record->allocatedmarker = optional_param('quickgrade_' . $record->userid . '_allocatedmarker', false, PARAM_INT);
7120
                $record->allocatedmarker = optional_param('quickgrade_' . $record->userid.'_allocatedmarker', false, PARAM_INT);
7453
            } else {
7121
            } else {
7454
                // This user was not in the grading table.
7122
                // This user was not in the grading table.
7455
                continue;
7123
                continue;
7456
            }
7124
            }
7457
            $record->attemptnumber = $attemptnumber;
7125
            $record->attemptnumber = $attemptnumber;
7458
            $record->lastmodified = $modified;
7126
            $record->lastmodified = $modified;
7459
            $record->gradinginfo = grade_get_grades(
7127
            $record->gradinginfo = grade_get_grades($this->get_course()->id,
7460
                $this->get_course()->id,
7128
                                                    'mod',
7461
                'mod',
-
 
7462
                'assign',
7129
                                                    'assign',
7463
                $this->get_instance()->id,
7130
                                                    $this->get_instance()->id,
7464
                array($userid)
7131
                                                    array($userid));
7465
            );
-
 
7466
            $users[$userid] = $record;
7132
            $users[$userid] = $record;
7467
        }
7133
        }
Línea 7468... Línea 7134...
7468
 
7134
 
7469
        if (empty($users)) {
7135
        if (empty($users)) {
Línea 7533... Línea 7199...
7533
                    }
7199
                    }
7534
                }
7200
                }
7535
            }
7201
            }
Línea 7536... Línea 7202...
7536
 
7202
 
7537
            if (($current->grade < 0 || $current->grade === null) &&
7203
            if (($current->grade < 0 || $current->grade === null) &&
7538
                ($modified->grade < 0 || $modified->grade === null)
-
 
7539
            ) {
7204
                ($modified->grade < 0 || $modified->grade === null)) {
7540
                // Different ways to indicate no grade.
7205
                // Different ways to indicate no grade.
7541
                $modified->grade = $current->grade; // Keep existing grade.
7206
                $modified->grade = $current->grade; // Keep existing grade.
7542
            }
7207
            }
7543
            // Treat 0 and null as different values.
7208
            // Treat 0 and null as different values.
7544
            if ($current->grade !== null) {
7209
            if ($current->grade !== null) {
7545
                $current->grade = floatval($current->grade);
7210
                $current->grade = floatval($current->grade);
7546
            }
7211
            }
7547
            $gradechanged = $gradecolpresent && grade_floats_different($current->grade, $modified->grade);
7212
            $gradechanged = $gradecolpresent && grade_floats_different($current->grade, $modified->grade);
7548
            $markingallocationchanged = $this->get_instance()->markingworkflow &&
7213
            $markingallocationchanged = $this->get_instance()->markingworkflow &&
7549
                $this->get_instance()->markingallocation &&
7214
                                        $this->get_instance()->markingallocation &&
7550
                ($modified->allocatedmarker !== false) &&
7215
                                            ($modified->allocatedmarker !== false) &&
7551
                ($current->allocatedmarker != $modified->allocatedmarker);
7216
                                            ($current->allocatedmarker != $modified->allocatedmarker);
7552
            $workflowstatechanged = $this->get_instance()->markingworkflow &&
7217
            $workflowstatechanged = $this->get_instance()->markingworkflow &&
7553
                ($modified->workflowstate !== false) &&
7218
                                            ($modified->workflowstate !== false) &&
7554
                ($current->workflowstate != $modified->workflowstate);
7219
                                            ($current->workflowstate != $modified->workflowstate);
7555
            if ($gradechanged || $markingallocationchanged || $workflowstatechanged) {
7220
            if ($gradechanged || $markingallocationchanged || $workflowstatechanged) {
7556
                // Grade changed.
7221
                // Grade changed.
7557
                if ($this->grading_disabled($modified->userid)) {
7222
                if ($this->grading_disabled($modified->userid)) {
7558
                    continue;
7223
                    continue;
Línea 7566... Línea 7231...
7566
                    return $message;
7231
                    return $message;
7567
                } else {
7232
                } else {
7568
                    $modifiedusers[$modified->userid] = $modified;
7233
                    $modifiedusers[$modified->userid] = $modified;
7569
                }
7234
                }
7570
            }
7235
            }
-
 
7236
 
7571
        }
7237
        }
7572
        $currentgrades->close();
7238
        $currentgrades->close();
Línea 7573... Línea 7239...
7573
 
7239
 
7574
        $adminconfig = $this->get_admin_config();
7240
        $adminconfig = $this->get_admin_config();
Línea 7575... Línea 7241...
7575
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7241
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7576
 
7242
 
7577
        // Ok - ready to process the updates.
7243
        // Ok - ready to process the updates.
7578
        foreach ($modifiedusers as $userid => $modified) {
7244
        foreach ($modifiedusers as $userid => $modified) {
7579
            $grade = $this->get_user_grade($userid, true);
7245
            $grade = $this->get_user_grade($userid, true);
7580
            $flags = $this->get_user_flags($userid, true);
7246
            $flags = $this->get_user_flags($userid, true);
7581
            $grade->grade = grade_floatval(unformat_float($modified->grade));
7247
            $grade->grade= grade_floatval(unformat_float($modified->grade));
Línea 7582... Línea 7248...
7582
            $grade->grader = $USER->id;
7248
            $grade->grader= $USER->id;
7583
            $gradecolpresent = optional_param('quickgrade_' . $userid, false, PARAM_INT) !== false;
7249
            $gradecolpresent = optional_param('quickgrade_' . $userid, false, PARAM_INT) !== false;
7584
 
7250
 
Línea 7596... Línea 7262...
7596
            }
7262
            }
Línea 7597... Línea 7263...
7597
 
7263
 
7598
            // These will be set to false if they are not present in the quickgrading
7264
            // These will be set to false if they are not present in the quickgrading
7599
            // form (e.g. column hidden).
7265
            // form (e.g. column hidden).
7600
            $workflowstatemodified = ($modified->workflowstate !== false) &&
7266
            $workflowstatemodified = ($modified->workflowstate !== false) &&
Línea 7601... Línea 7267...
7601
                ($flags->workflowstate != $modified->workflowstate);
7267
                                        ($flags->workflowstate != $modified->workflowstate);
7602
 
7268
 
Línea 7603... Línea 7269...
7603
            $allocatedmarkermodified = ($modified->allocatedmarker !== false) &&
7269
            $allocatedmarkermodified = ($modified->allocatedmarker !== false) &&
7604
                ($flags->allocatedmarker != $modified->allocatedmarker);
7270
                                        ($flags->allocatedmarker != $modified->allocatedmarker);
7605
 
7271
 
7606
            if ($workflowstatemodified) {
7272
            if ($workflowstatemodified) {
Línea 7634... Línea 7300...
7634
                    if ($newoutcome !== false && ($oldoutcome != $newoutcome)) {
7300
                    if ($newoutcome !== false && ($oldoutcome != $newoutcome)) {
7635
                        $data[$outcomeid] = $newoutcome;
7301
                        $data[$outcomeid] = $newoutcome;
7636
                    }
7302
                    }
7637
                }
7303
                }
7638
                if (count($data) > 0) {
7304
                if (count($data) > 0) {
7639
                    grade_update_outcomes(
7305
                    grade_update_outcomes('mod/assign',
7640
                        'mod/assign',
-
 
7641
                        $this->course->id,
7306
                                          $this->course->id,
7642
                        'mod',
7307
                                          'mod',
7643
                        'assign',
7308
                                          'assign',
7644
                        $this->get_instance()->id,
7309
                                          $this->get_instance()->id,
7645
                        $userid,
7310
                                          $userid,
7646
                        $data
7311
                                          $data);
7647
                    );
-
 
7648
                }
7312
                }
7649
            }
7313
            }
7650
        }
7314
        }
Línea 7651... Línea 7315...
7651
 
7315
 
Línea 7655... Línea 7319...
7655
    /**
7319
    /**
7656
     * Reveal student identities to markers (and the gradebook).
7320
     * Reveal student identities to markers (and the gradebook).
7657
     *
7321
     *
7658
     * @return void
7322
     * @return void
7659
     */
7323
     */
7660
    public function reveal_identities()
7324
    public function reveal_identities() {
7661
    {
-
 
7662
        global $DB;
7325
        global $DB;
Línea 7663... Línea 7326...
7663
 
7326
 
Línea 7664... Línea 7327...
7664
        require_capability('mod/assign:revealidentities', $this->context);
7327
        require_capability('mod/assign:revealidentities', $this->context);
Línea 7683... Línea 7346...
7683
        // Now release all grades.
7346
        // Now release all grades.
Línea 7684... Línea 7347...
7684
 
7347
 
7685
        $adminconfig = $this->get_admin_config();
7348
        $adminconfig = $this->get_admin_config();
7686
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7349
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7687
        $gradebookplugin = str_replace('assignfeedback_', '', $gradebookplugin);
7350
        $gradebookplugin = str_replace('assignfeedback_', '', $gradebookplugin);
Línea 7688... Línea 7351...
7688
        $grades = $DB->get_records('assign_grades', array('assignment' => $this->get_instance()->id));
7351
        $grades = $DB->get_records('assign_grades', array('assignment'=>$this->get_instance()->id));
Línea 7689... Línea 7352...
7689
 
7352
 
7690
        $plugin = $this->get_feedback_plugin_by_type($gradebookplugin);
7353
        $plugin = $this->get_feedback_plugin_by_type($gradebookplugin);
Línea 7705... Línea 7368...
7705
    /**
7368
    /**
7706
     * Reveal student identities to markers (and the gradebook).
7369
     * Reveal student identities to markers (and the gradebook).
7707
     *
7370
     *
7708
     * @return void
7371
     * @return void
7709
     */
7372
     */
7710
    protected function process_reveal_identities()
7373
    protected function process_reveal_identities() {
7711
    {
-
 
Línea 7712... Línea 7374...
7712
 
7374
 
7713
        if (!confirm_sesskey()) {
7375
        if (!confirm_sesskey()) {
7714
            return false;
7376
            return false;
Línea 7719... Línea 7381...
7719
 
7381
 
7720
 
7382
 
7721
    /**
7383
    /**
-
 
7384
     * Save grading options.
-
 
7385
     *
7722
     * Save grading options.
7386
     * @deprecated since Moodle 4.5
7723
     *
7387
     * @todo Final deprecation in Moodle 6.0. See MDL-82876.
7724
     * @return void
-
 
7725
     */
-
 
7726
    protected function process_save_grading_options()
-
 
7727
    {
-
 
7728
        global $USER, $CFG;
-
 
7729
 
-
 
7730
        // Include grading options form.
-
 
7731
        require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
-
 
7732
 
7388
     * @return void
7733
        // Need submit permission to submit an assignment.
-
 
7734
        $this->require_view_grades();
-
 
7735
        require_sesskey();
-
 
7736
 
-
 
7737
        // Is advanced grading enabled?
-
 
7738
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
-
 
7739
        $controller = $gradingmanager->get_active_controller();
-
 
7740
        $showquickgrading = empty($controller);
-
 
7741
        if (!is_null($this->context)) {
7389
     */
7742
            $showonlyactiveenrolopt = has_capability('moodle/course:viewsuspendedusers', $this->context);
-
 
7743
        } else {
-
 
7744
            $showonlyactiveenrolopt = false;
-
 
7745
        }
-
 
7746
 
-
 
7747
        $markingallocation = $this->get_instance()->markingworkflow &&
-
 
7748
            $this->get_instance()->markingallocation &&
-
 
7749
            has_capability('mod/assign:manageallocations', $this->context);
-
 
7750
        // Get markers to use in drop lists.
-
 
7751
        $markingallocationoptions = array();
-
 
7752
        if ($markingallocation) {
-
 
7753
            $markingallocationoptions[''] = get_string('filternone', 'assign');
-
 
7754
            $markingallocationoptions[ASSIGN_MARKER_FILTER_NO_MARKER] = get_string('markerfilternomarker', 'assign');
-
 
7755
            list($sort, $params) = users_order_by_sql('u');
-
 
7756
            // Only enrolled users could be assigned as potential markers.
-
 
7757
            $markers = get_enrolled_users($this->context, 'mod/assign:grade', 0, 'u.*', $sort);
-
 
7758
            foreach ($markers as $marker) {
7390
    #[\core\attribute\deprecated(
7759
                $markingallocationoptions[$marker->id] = fullname($marker);
-
 
7760
            }
-
 
7761
        }
7391
        'null',
7762
 
-
 
7763
        // Get marking states to show in form.
-
 
7764
        $markingworkflowoptions = $this->get_marking_workflow_filters();
-
 
7765
 
-
 
7766
        $gradingoptionsparams = array(
-
 
7767
            'cm' => $this->get_course_module()->id,
-
 
7768
            'contextid' => $this->context->id,
-
 
7769
            'userid' => $USER->id,
-
 
7770
            'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
-
 
7771
            'showquickgrading' => $showquickgrading,
-
 
7772
            'quickgrading' => false,
-
 
7773
            'markingworkflowopt' => $markingworkflowoptions,
-
 
7774
            'markingallocationopt' => $markingallocationoptions,
-
 
7775
            'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
-
 
7776
            'showonlyactiveenrol' => $this->show_only_active_users(),
-
 
7777
            'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1)
-
 
7778
        );
-
 
7779
        $mform = new mod_assign_grading_options_form(null, $gradingoptionsparams);
-
 
7780
        if ($formdata = $mform->get_data()) {
-
 
7781
            set_user_preference('assign_perpage', $formdata->perpage);
-
 
7782
            if (isset($formdata->filter)) {
-
 
7783
                set_user_preference('assign_filter', $formdata->filter);
-
 
7784
            }
-
 
7785
            if (isset($formdata->markerfilter)) {
-
 
7786
                set_user_preference('assign_markerfilter', $formdata->markerfilter);
-
 
7787
            }
-
 
7788
            if (isset($formdata->workflowfilter)) {
-
 
7789
                set_user_preference('assign_workflowfilter', $formdata->workflowfilter);
-
 
7790
            }
-
 
7791
            if ($showquickgrading) {
-
 
7792
                set_user_preference('assign_quickgrading', isset($formdata->quickgrading));
-
 
7793
            }
-
 
7794
            if (isset($formdata->downloadasfolders)) {
7392
        since: '4.5',
7795
                set_user_preference('assign_downloadasfolders', 1); // Enabled.
-
 
7796
            } else {
-
 
7797
                set_user_preference('assign_downloadasfolders', 0); // Disabled.
-
 
7798
            }
-
 
7799
            if (!empty($showonlyactiveenrolopt)) {
-
 
7800
                $showonlyactiveenrol = isset($formdata->showonlyactiveenrol);
-
 
7801
                set_user_preference('grade_report_showonlyactiveenrol', $showonlyactiveenrol);
-
 
7802
                $this->showonlyactiveenrol = $showonlyactiveenrol;
-
 
7803
            }
7393
        reason: 'It is no longer used.',
7804
        }
-
 
7805
    }
-
 
7806
 
-
 
7807
    /**
-
 
7808
     * @deprecated since 2.7
7394
        mdl: 'MDL-82681',
7809
     */
-
 
7810
    public function format_grade_for_log()
-
 
7811
    {
-
 
7812
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
-
 
7813
    }
-
 
7814
 
-
 
7815
    /**
-
 
7816
     * @deprecated since 2.7
-
 
7817
     */
-
 
7818
    public function format_submission_for_log()
7395
    )]
7819
    {
7396
    protected function process_save_grading_options() {
Línea 7820... Línea 7397...
7820
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
7397
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
7821
    }
7398
    }
7822
 
7399
 
7823
    /**
7400
    /**
7824
     * Require a valid sess key and then call copy_previous_attempt.
7401
     * Require a valid sess key and then call copy_previous_attempt.
7825
     *
7402
     *
7826
     * @param  array $notices Any error messages that should be shown
7403
     * @param  array $notices Any error messages that should be shown
7827
     *                        to the user at the top of the edit submission form.
7404
     *                        to the user at the top of the edit submission form.
7828
     * @return bool
-
 
7829
     */
7405
     * @return bool
Línea 7830... Línea 7406...
7830
    protected function process_copy_previous_attempt(&$notices)
7406
     */
7831
    {
7407
    protected function process_copy_previous_attempt(&$notices) {
Línea 7839... Línea 7415...
7839
     *
7415
     *
7840
     * @param  array $notices Any error messages that should be shown
7416
     * @param  array $notices Any error messages that should be shown
7841
     *                        to the user at the top of the edit submission form.
7417
     *                        to the user at the top of the edit submission form.
7842
     * @return bool
7418
     * @return bool
7843
     */
7419
     */
7844
    public function copy_previous_attempt(&$notices)
7420
    public function copy_previous_attempt(&$notices) {
7845
    {
-
 
7846
        global $USER, $CFG;
7421
        global $USER, $CFG;
Línea 7847... Línea 7422...
7847
 
7422
 
Línea 7848... Línea 7423...
7848
        require_capability('mod/assign:submit', $this->context);
7423
        require_capability('mod/assign:submit', $this->context);
Línea 7902... Línea 7477...
7902
        if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
7477
        if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
7903
            $complete = COMPLETION_COMPLETE;
7478
            $complete = COMPLETION_COMPLETE;
7904
        }
7479
        }
7905
        $completion = new completion_info($this->get_course());
7480
        $completion = new completion_info($this->get_course());
7906
        if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7481
        if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7907
            $this->update_activity_completion_records(
7482
            $this->update_activity_completion_records($instance->teamsubmission,
7908
                $instance->teamsubmission,
-
 
7909
                $instance->requireallteammemberssubmit,
7483
                                                      $instance->requireallteammemberssubmit,
7910
                $submission,
7484
                                                      $submission,
7911
                $USER->id,
7485
                                                      $USER->id,
7912
                $complete,
7486
                                                      $complete,
7913
                $completion
7487
                                                      $completion);
7914
            );
-
 
7915
        }
7488
        }
Línea 7916... Línea 7489...
7916
 
7489
 
7917
        if (!$instance->submissiondrafts) {
7490
        if (!$instance->submissiondrafts) {
7918
            // There is a case for not notifying the student about the submission copy,
7491
            // There is a case for not notifying the student about the submission copy,
Línea 7933... Línea 7506...
7933
     * Determine if the current submission is empty or not.
7506
     * Determine if the current submission is empty or not.
7934
     *
7507
     *
7935
     * @param submission $submission the students submission record to check.
7508
     * @param submission $submission the students submission record to check.
7936
     * @return bool
7509
     * @return bool
7937
     */
7510
     */
7938
    public function submission_empty($submission)
7511
    public function submission_empty($submission) {
7939
    {
-
 
7940
        $allempty = true;
7512
        $allempty = true;
Línea 7941... Línea 7513...
7941
 
7513
 
7942
        foreach ($this->submissionplugins as $plugin) {
7514
        foreach ($this->submissionplugins as $plugin) {
7943
            if ($plugin->is_enabled() && $plugin->is_visible()) {
7515
            if ($plugin->is_enabled() && $plugin->is_visible()) {
Línea 7953... Línea 7525...
7953
     * Determine if a new submission is empty or not
7525
     * Determine if a new submission is empty or not
7954
     *
7526
     *
7955
     * @param stdClass $data Submission data
7527
     * @param stdClass $data Submission data
7956
     * @return bool
7528
     * @return bool
7957
     */
7529
     */
7958
    public function new_submission_empty($data)
7530
    public function new_submission_empty($data) {
7959
    {
-
 
7960
        foreach ($this->submissionplugins as $plugin) {
7531
        foreach ($this->submissionplugins as $plugin) {
7961
            if (
-
 
7962
                $plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions() &&
7532
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions() &&
7963
                !$plugin->submission_is_empty($data)
7533
                    !$plugin->submission_is_empty($data)) {
7964
            ) {
-
 
7965
                return false;
7534
                return false;
7966
            }
7535
            }
7967
        }
7536
        }
7968
        return true;
7537
        return true;
7969
    }
7538
    }
Línea 7974... Línea 7543...
7974
     * @param  stdClass $data
7543
     * @param  stdClass $data
7975
     * @param  array $notices Any error messages that should be shown
7544
     * @param  array $notices Any error messages that should be shown
7976
     *                        to the user.
7545
     *                        to the user.
7977
     * @return bool
7546
     * @return bool
7978
     */
7547
     */
7979
    public function save_submission(stdClass $data, &$notices)
7548
    public function save_submission(stdClass $data, & $notices) {
7980
    {
-
 
7981
        global $CFG, $USER, $DB;
7549
        global $CFG, $USER, $DB;
Línea 7982... Línea 7550...
7982
 
7550
 
7983
        $userid = $USER->id;
7551
        $userid = $USER->id;
7984
        if (!empty($data->userid)) {
7552
        if (!empty($data->userid)) {
7985
            $userid = $data->userid;
7553
            $userid = $data->userid;
Línea 7986... Línea 7554...
7986
        }
7554
        }
7987
 
7555
 
7988
        $user = clone ($USER);
7556
        $user = clone($USER);
7989
        if ($userid == $USER->id) {
7557
        if ($userid == $USER->id) {
7990
            require_capability('mod/assign:submit', $this->context);
7558
            require_capability('mod/assign:submit', $this->context);
7991
        } else {
7559
        } else {
7992
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
7560
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
7993
            if (!$this->can_edit_submission($userid, $USER->id)) {
7561
            if (!$this->can_edit_submission($userid, $USER->id)) {
7994
                throw new \moodle_exception('nopermission');
7562
                throw new \moodle_exception('nopermission');
7995
            }
7563
            }
Línea 8010... Línea 7578...
8010
        // Check that no one has modified the submission since we started looking at it.
7578
        // Check that no one has modified the submission since we started looking at it.
8011
        if (isset($data->lastmodified) && ($submission->timemodified > $data->lastmodified)) {
7579
        if (isset($data->lastmodified) && ($submission->timemodified > $data->lastmodified)) {
8012
            // Another user has submitted something. Notify the current user.
7580
            // Another user has submitted something. Notify the current user.
8013
            if ($submission->status !== ASSIGN_SUBMISSION_STATUS_NEW) {
7581
            if ($submission->status !== ASSIGN_SUBMISSION_STATUS_NEW) {
8014
                $notices[] = $instance->teamsubmission ? get_string('submissionmodifiedgroup', 'mod_assign')
7582
                $notices[] = $instance->teamsubmission ? get_string('submissionmodifiedgroup', 'mod_assign')
8015
                    : get_string('submissionmodified', 'mod_assign');
7583
                                                       : get_string('submissionmodified', 'mod_assign');
8016
                return false;
7584
                return false;
8017
            }
7585
            }
8018
        }
7586
        }
Línea 8019... Línea 7587...
8019
 
7587
 
Línea 8055... Línea 7623...
8055
        if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
7623
        if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
8056
            $team = $this->get_submission_group_members($submission->groupid, true);
7624
            $team = $this->get_submission_group_members($submission->groupid, true);
Línea 8057... Línea 7625...
8057
 
7625
 
8058
            foreach ($team as $member) {
7626
            foreach ($team as $member) {
8059
                if ($member->id != $userid) {
7627
                if ($member->id != $userid) {
8060
                    $membersubmission = clone ($submission);
7628
                    $membersubmission = clone($submission);
8061
                    $this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
7629
                    $this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
8062
                    $users[] = $member->id;
7630
                    $users[] = $member->id;
8063
                }
7631
                }
8064
            }
7632
            }
Línea 8095... Línea 7663...
8095
     * @param  moodleform $mform
7663
     * @param  moodleform $mform
8096
     * @param  array $notices Any error messages that should be shown
7664
     * @param  array $notices Any error messages that should be shown
8097
     *                        to the user at the top of the edit submission form.
7665
     *                        to the user at the top of the edit submission form.
8098
     * @return bool
7666
     * @return bool
8099
     */
7667
     */
8100
    protected function process_save_submission(&$mform, &$notices)
7668
    protected function process_save_submission(&$mform, &$notices) {
8101
    {
-
 
8102
        global $CFG, $USER;
7669
        global $CFG, $USER;
Línea 8103... Línea 7670...
8103
 
7670
 
8104
        // Include submission form.
7671
        // Include submission form.
Línea 8132... Línea 7699...
8132
     * @param int $userid - The student userid
7699
     * @param int $userid - The student userid
8133
     * @param bool $checkworkflow - whether to include a check for the workflow state.
7700
     * @param bool $checkworkflow - whether to include a check for the workflow state.
8134
     * @param stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.
7701
     * @param stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.
8135
     * @return bool $gradingdisabled
7702
     * @return bool $gradingdisabled
8136
     */
7703
     */
8137
    public function grading_disabled($userid, $checkworkflow = true, $gradinginfo = null)
7704
    public function grading_disabled($userid, $checkworkflow = true, $gradinginfo = null) {
8138
    {
-
 
8139
        if ($checkworkflow && $this->get_instance()->markingworkflow) {
7705
        if ($checkworkflow && $this->get_instance()->markingworkflow) {
8140
            $grade = $this->get_user_grade($userid, false);
7706
            $grade = $this->get_user_grade($userid, false);
8141
            $validstates = $this->get_marking_workflow_states_for_current_user();
7707
            $validstates = $this->get_marking_workflow_states_for_current_user();
8142
            if (!empty($grade) && !empty($grade->workflowstate) && !array_key_exists($grade->workflowstate, $validstates)) {
7708
            if (!empty($grade) && !empty($grade->workflowstate) && !array_key_exists($grade->workflowstate, $validstates)) {
8143
                return true;
7709
                return true;
8144
            }
7710
            }
8145
        }
7711
        }
Línea 8146... Línea 7712...
8146
 
7712
 
8147
        if (is_null($gradinginfo)) {
7713
        if (is_null($gradinginfo)) {
8148
            $gradinginfo = grade_get_grades(
-
 
8149
                $this->get_course()->id,
7714
            $gradinginfo = grade_get_grades($this->get_course()->id,
8150
                'mod',
7715
                'mod',
8151
                'assign',
7716
                'assign',
8152
                $this->get_instance()->id,
7717
                $this->get_instance()->id,
8153
                array($userid)
-
 
8154
            );
7718
                array($userid));
Línea 8155... Línea 7719...
8155
        }
7719
        }
8156
 
7720
 
8157
        if (!$gradinginfo) {
7721
        if (!$gradinginfo) {
Línea 8158... Línea 7722...
8158
            return false;
7722
            return false;
8159
        }
7723
        }
8160
 
7724
 
8161
        if (!isset($gradinginfo->items[0]->grades[$userid])) {
7725
        if (!isset($gradinginfo->items[0]->grades[$userid])) {
8162
            return false;
7726
            return false;
8163
        }
7727
        }
8164
        $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked ||
7728
        $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked ||
Línea 8165... Línea 7729...
8165
            $gradinginfo->items[0]->grades[$userid]->overridden;
7729
                           $gradinginfo->items[0]->grades[$userid]->overridden;
Línea 8174... Línea 7738...
8174
     * @param int $userid - The student userid
7738
     * @param int $userid - The student userid
8175
     * @param stdClass|false $grade - The grade record
7739
     * @param stdClass|false $grade - The grade record
8176
     * @param bool $gradingdisabled
7740
     * @param bool $gradingdisabled
8177
     * @return mixed gradingform_instance|null $gradinginstance
7741
     * @return mixed gradingform_instance|null $gradinginstance
8178
     */
7742
     */
8179
    protected function get_grading_instance($userid, $grade, $gradingdisabled)
7743
    protected function get_grading_instance($userid, $grade, $gradingdisabled) {
8180
    {
-
 
8181
        global $CFG, $USER;
7744
        global $CFG, $USER;
Línea 8182... Línea 7745...
8182
 
7745
 
8183
        $grademenu = make_grades_menu($this->get_instance()->grade);
7746
        $grademenu = make_grades_menu($this->get_instance()->grade);
Línea 8195... Línea 7758...
8195
                }
7758
                }
8196
                if ($gradingdisabled && $itemid) {
7759
                if ($gradingdisabled && $itemid) {
8197
                    $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
7760
                    $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
8198
                } else if (!$gradingdisabled) {
7761
                } else if (!$gradingdisabled) {
8199
                    $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
7762
                    $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
8200
                    $gradinginstance = $controller->get_or_create_instance(
7763
                    $gradinginstance = $controller->get_or_create_instance($instanceid,
8201
                        $instanceid,
-
 
8202
                        $USER->id,
7764
                                                                           $USER->id,
8203
                        $itemid
7765
                                                                           $itemid);
8204
                    );
-
 
8205
                }
7766
                }
8206
            } else {
7767
            } else {
8207
                $advancedgradingwarning = $controller->form_unavailable_notification();
7768
                $advancedgradingwarning = $controller->form_unavailable_notification();
8208
            }
7769
            }
8209
        }
7770
        }
Línea 8219... Línea 7780...
8219
     * @param MoodleQuickForm $mform
7780
     * @param MoodleQuickForm $mform
8220
     * @param stdClass $data
7781
     * @param stdClass $data
8221
     * @param array $params
7782
     * @param array $params
8222
     * @return void
7783
     * @return void
8223
     */
7784
     */
8224
    public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params)
7785
    public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params) {
8225
    {
-
 
8226
        global $USER, $CFG, $SESSION;
7786
        global $USER, $CFG, $SESSION, $PAGE;
8227
        $settings = $this->get_instance();
7787
        $settings = $this->get_instance();
Línea 8228... Línea 7788...
8228
 
7788
 
8229
        $rownum = isset($params['rownum']) ? $params['rownum'] : 0;
7789
        $rownum = isset($params['rownum']) ? $params['rownum'] : 0;
8230
        $last = isset($params['last']) ? $params['last'] : true;
7790
        $last = isset($params['last']) ? $params['last'] : true;
Línea 8258... Línea 7818...
8258
        $gradingdisabled = $this->grading_disabled($userid);
7818
        $gradingdisabled = $this->grading_disabled($userid);
8259
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
7819
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
Línea 8260... Línea 7820...
8260
 
7820
 
8261
        $mform->addElement('header', 'gradeheader', get_string('gradenoun'));
7821
        $mform->addElement('header', 'gradeheader', get_string('gradenoun'));
8262
        if ($gradinginstance) {
7822
        if ($gradinginstance) {
8263
            $gradingelement = $mform->addElement(
-
 
8264
                'grading',
7823
            $gradingelement = $mform->addElement('grading',
8265
                'advancedgrading',
7824
                                                 'advancedgrading',
8266
                get_string('gradenoun') . ':',
7825
                                                 get_string('gradenoun') . ':',
8267
                array('gradinginstance' => $gradinginstance)
-
 
8268
            );
7826
                                                 array('gradinginstance' => $gradinginstance));
8269
            if ($gradingdisabled) {
7827
            if ($gradingdisabled) {
8270
                $gradingelement->freeze();
7828
                $gradingelement->freeze();
8271
            } else {
7829
            } else {
8272
                $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
7830
                $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
Línea 8300... Línea 7858...
8300
                    }
7858
                    }
8301
                }
7859
                }
8302
            }
7860
            }
8303
        }
7861
        }
Línea 8304... Línea 7862...
8304
 
7862
 
8305
        $gradinginfo = grade_get_grades(
7863
        $gradinginfo = grade_get_grades($this->get_course()->id,
8306
            $this->get_course()->id,
-
 
8307
            'mod',
7864
                                        'mod',
8308
            'assign',
7865
                                        'assign',
8309
            $this->get_instance()->id,
7866
                                        $this->get_instance()->id,
8310
            $userid
-
 
8311
        );
7867
                                        $userid);
8312
        if (!empty($CFG->enableoutcomes)) {
7868
        if (!empty($CFG->enableoutcomes)) {
8313
            foreach ($gradinginfo->outcomes as $index => $outcome) {
7869
            foreach ($gradinginfo->outcomes as $index => $outcome) {
8314
                $options = make_grades_menu(-$outcome->scaleid);
7870
                $options = make_grades_menu(-$outcome->scaleid);
8315
                $options[0] = get_string('nooutcome', 'grades');
7871
                $options[0] = get_string('nooutcome', 'grades');
8316
                if ($outcome->grades[$userid]->locked) {
7872
                if ($outcome->grades[$userid]->locked) {
8317
                    $mform->addElement(
-
 
8318
                        'static',
7873
                    $mform->addElement('static',
8319
                        'outcome_' . $index . '[' . $userid . ']',
7874
                                       'outcome_' . $index . '[' . $userid . ']',
8320
                        $outcome->name . ':',
7875
                                       $outcome->name . ':',
8321
                        $options[$outcome->grades[$userid]->grade]
-
 
8322
                    );
7876
                                       $options[$outcome->grades[$userid]->grade]);
8323
                } else {
7877
                } else {
8324
                    $attributes = array('id' => 'menuoutcome_' . $index);
7878
                    $attributes = array('id' => 'menuoutcome_' . $index );
8325
                    $mform->addElement(
-
 
8326
                        'select',
7879
                    $mform->addElement('select',
8327
                        'outcome_' . $index . '[' . $userid . ']',
7880
                                       'outcome_' . $index . '[' . $userid . ']',
8328
                        $outcome->name . ':',
7881
                                       $outcome->name.':',
8329
                        $options,
7882
                                       $options,
8330
                        $attributes
-
 
8331
                    );
7883
                                       $attributes);
8332
                    $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
-
 
8333
                    $mform->setDefault(
7884
                    $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
8334
                        'outcome_' . $index . '[' . $userid . ']',
7885
                    $mform->setDefault('outcome_' . $index . '[' . $userid . ']',
8335
                        $outcome->grades[$userid]->grade
-
 
8336
                    );
7886
                                       $outcome->grades[$userid]->grade);
8337
                }
7887
                }
8338
            }
7888
            }
Línea 8339... Línea 7889...
8339
        }
7889
        }
8340
 
7890
 
8341
        $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
7891
        $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
8342
        $usergrade = get_string('notgraded', 'assign');
7892
        $usergrade = get_string('notgraded', 'assign');
8343
        if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
7893
        if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
8344
            $urlparams = array('id' => $this->get_course()->id);
7894
            $urlparams = array('id'=>$this->get_course()->id);
8345
            $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
7895
            $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
8346
            if (isset($gradinginfo->items[0]->grades[$userid]->grade)) {
7896
            if (isset($gradinginfo->items[0]->grades[$userid]->grade)) {
8347
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
7897
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
8348
            }
7898
            }
8349
            $gradestring = $this->get_renderer()->action_link($url, $usergrade);
-
 
8350
        } else {
7899
            $gradestring = $this->get_renderer()->action_link($url, $usergrade);
8351
            if (
7900
        } else {
8352
                isset($gradinginfo->items[0]->grades[$userid]) &&
-
 
8353
                !$gradinginfo->items[0]->grades[$userid]->hidden
7901
            if (isset($gradinginfo->items[0]->grades[$userid]) &&
8354
            ) {
7902
                    !$gradinginfo->items[0]->grades[$userid]->hidden) {
8355
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
7903
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
8356
            }
7904
            }
Línea -... Línea 7905...
-
 
7905
            $gradestring = $usergrade;
-
 
7906
        }
-
 
7907
 
-
 
7908
        // Penalty indicator.
-
 
7909
        $userassigngrade = $gradinginfo->items[0]->grades[$userid];
-
 
7910
        if (isset($userassigngrade->grade)) {
-
 
7911
            $gradegrade = new \grade_grade();
-
 
7912
            $gradegrade->deductedmark = $userassigngrade->deductedmark;
-
 
7913
            $gradegrade->overridden = $userassigngrade->overridden;
-
 
7914
            $penaltyindicator = \core_grades\penalty_manager::show_penalty_indicator($gradegrade);
8357
            $gradestring = $usergrade;
7915
            $gradestring = $penaltyindicator . $gradestring;
8358
        }
7916
        }
8359
 
7917
 
8360
        if ($this->get_instance()->markingworkflow) {
7918
        if ($this->get_instance()->markingworkflow) {
8361
            $states = $this->get_marking_workflow_states_for_current_user();
7919
            $states = $this->get_marking_workflow_states_for_current_user();
Línea 8382... Línea 7940...
8382
                    $mform->addElement('static', 'currentassigngrade', $label, $assigngradestring);
7940
                    $mform->addElement('static', 'currentassigngrade', $label, $assigngradestring);
8383
                }
7941
                }
8384
            }
7942
            }
8385
        }
7943
        }
Línea 8386... Línea -...
8386
 
-
 
8387
        if (
7944
 
8388
            $this->get_instance()->markingworkflow &&
7945
        if ($this->get_instance()->markingworkflow &&
8389
            $this->get_instance()->markingallocation &&
7946
            $this->get_instance()->markingallocation &&
8390
            has_capability('mod/assign:manageallocations', $this->context)
-
 
Línea 8391... Línea 7947...
8391
        ) {
7947
            has_capability('mod/assign:manageallocations', $this->context)) {
8392
 
7948
 
8393
            list($sort, $params) = users_order_by_sql('u');
7949
            list($sort, $params) = users_order_by_sql('u');
8394
            // Only enrolled users could be assigned as potential markers.
7950
            // Only enrolled users could be assigned as potential markers.
Línea 8408... Línea 7964...
8408
 
7964
 
8409
        $gradestring = '<span class="currentgrade">' . $gradestring . '</span>';
7965
        $gradestring = '<span class="currentgrade">' . $gradestring . '</span>';
Línea 8410... Línea 7966...
8410
        $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
7966
        $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
8411
 
7967
 
8412
        if (count($useridlist) > 1) {
7968
        if (count($useridlist) > 1) {
8413
            $strparams = array('current' => $rownum + 1, 'total' => count($useridlist));
7969
            $strparams = array('current'=>$rownum+1, 'total'=>count($useridlist));
8414
            $name = get_string('outof', 'assign', $strparams);
7970
            $name = get_string('outof', 'assign', $strparams);
Línea 8415... Línea 7971...
8415
            $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
7971
            $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
Línea 8438... Línea 7994...
8438
            $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign'));
7994
            $mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign'));
8439
            $mform->setDefault('applytoall', 1);
7995
            $mform->setDefault('applytoall', 1);
8440
        }
7996
        }
Línea 8441... Línea 7997...
8441
 
7997
 
8442
        // Do not show if we are editing a previous attempt.
-
 
8443
        if (($attemptnumber == -1 ||
7998
        // Do not show if we are editing a previous attempt.
8444
                ($attemptnumber + 1) == count($this->get_all_submissions($userid))) &&
7999
        if (($attemptnumber == -1 || ($attemptnumber + 1) == count($this->get_all_submissions($userid))) &&
8445
            $this->get_instance()->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE
-
 
8446
        ) {
8000
                ($this->get_instance()->maxattempts > 1 || $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS)) {
8447
            $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign'));
8001
            $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign'));
8448
            $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign');
8002
            $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign');
Línea 8449... Línea 8003...
8449
            $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod);
8003
            $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod);
Línea 8460... Línea 8014...
8460
            $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1);
8014
            $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1);
Línea 8461... Línea 8015...
8461
 
8015
 
8462
            $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
8016
            $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
8463
            $issubmission = !empty($submission);
8017
            $issubmission = !empty($submission);
8464
            $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
8018
            $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
Línea 8465... Línea 8019...
8465
            $islessthanmaxattempts = $issubmission && ($submission->attemptnumber < ($this->get_instance()->maxattempts - 1));
8019
            $islessthanmaxattempts = $issubmission && ($submission->attemptnumber < ($this->get_instance()->maxattempts-1));
8466
 
8020
 
8467
            if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) {
8021
            if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) {
8468
                $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign'));
8022
                $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign'));
Línea 8534... Línea 8088...
8534
     * @param MoodleQuickForm $mform
8088
     * @param MoodleQuickForm $mform
8535
     * @param stdClass $data
8089
     * @param stdClass $data
8536
     * @param int $userid The current userid (same as $USER->id)
8090
     * @param int $userid The current userid (same as $USER->id)
8537
     * @return void
8091
     * @return void
8538
     */
8092
     */
8539
    protected function add_plugin_submission_elements(
8093
    protected function add_plugin_submission_elements($submission,
8540
        $submission,
-
 
8541
        MoodleQuickForm $mform,
8094
                                                    MoodleQuickForm $mform,
8542
        stdClass $data,
8095
                                                    stdClass $data,
8543
        $userid
8096
                                                    $userid) {
8544
    ) {
-
 
8545
        foreach ($this->submissionplugins as $plugin) {
8097
        foreach ($this->submissionplugins as $plugin) {
8546
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
8098
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
8547
                $plugin->get_form_elements_for_user($submission, $mform, $data, $userid);
8099
                $plugin->get_form_elements_for_user($submission, $mform, $data, $userid);
8548
            }
8100
            }
8549
        }
8101
        }
Línea 8552... Línea 8104...
8552
    /**
8104
    /**
8553
     * Check if feedback plugins installed are enabled.
8105
     * Check if feedback plugins installed are enabled.
8554
     *
8106
     *
8555
     * @return bool
8107
     * @return bool
8556
     */
8108
     */
8557
    public function is_any_feedback_plugin_enabled()
8109
    public function is_any_feedback_plugin_enabled() {
8558
    {
-
 
8559
        if (!isset($this->cache['any_feedback_plugin_enabled'])) {
8110
        if (!isset($this->cache['any_feedback_plugin_enabled'])) {
8560
            $this->cache['any_feedback_plugin_enabled'] = false;
8111
            $this->cache['any_feedback_plugin_enabled'] = false;
8561
            foreach ($this->feedbackplugins as $plugin) {
8112
            foreach ($this->feedbackplugins as $plugin) {
8562
                if ($plugin->is_enabled() && $plugin->is_visible()) {
8113
                if ($plugin->is_enabled() && $plugin->is_visible()) {
8563
                    $this->cache['any_feedback_plugin_enabled'] = true;
8114
                    $this->cache['any_feedback_plugin_enabled'] = true;
Línea 8565... Línea 8116...
8565
                }
8116
                }
8566
            }
8117
            }
8567
        }
8118
        }
Línea 8568... Línea 8119...
8568
 
8119
 
-
 
8120
        return $this->cache['any_feedback_plugin_enabled'];
8569
        return $this->cache['any_feedback_plugin_enabled'];
8121
 
Línea 8570... Línea 8122...
8570
    }
8122
    }
8571
 
8123
 
8572
    /**
8124
    /**
8573
     * Check if submission plugins installed are enabled.
8125
     * Check if submission plugins installed are enabled.
8574
     *
8126
     *
8575
     * @return bool
8127
     * @return bool
8576
     */
-
 
8577
    public function is_any_submission_plugin_enabled()
8128
     */
8578
    {
8129
    public function is_any_submission_plugin_enabled() {
8579
        if (!isset($this->cache['any_submission_plugin_enabled'])) {
8130
        if (!isset($this->cache['any_submission_plugin_enabled'])) {
8580
            $this->cache['any_submission_plugin_enabled'] = false;
8131
            $this->cache['any_submission_plugin_enabled'] = false;
8581
            foreach ($this->submissionplugins as $plugin) {
8132
            foreach ($this->submissionplugins as $plugin) {
Línea 8585... Línea 8136...
8585
                }
8136
                }
8586
            }
8137
            }
8587
        }
8138
        }
Línea 8588... Línea 8139...
8588
 
8139
 
-
 
8140
        return $this->cache['any_submission_plugin_enabled'];
8589
        return $this->cache['any_submission_plugin_enabled'];
8141
 
Línea 8590... Línea 8142...
8590
    }
8142
    }
8591
 
8143
 
8592
    /**
8144
    /**
8593
     * Add elements to submission form.
8145
     * Add elements to submission form.
8594
     * @param MoodleQuickForm $mform
8146
     * @param MoodleQuickForm $mform
8595
     * @param stdClass $data
8147
     * @param stdClass $data
8596
     * @return void
8148
     * @return void
8597
     */
-
 
8598
    public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data)
8149
     */
Línea 8599... Línea 8150...
8599
    {
8150
    public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data) {
8600
        global $USER;
8151
        global $USER;
8601
 
8152
 
Línea 8627... Línea 8178...
8627
        $mform->addElement('header', 'submission header', get_string('addsubmission', 'mod_assign'));
8178
        $mform->addElement('header', 'submission header', get_string('addsubmission', 'mod_assign'));
Línea 8628... Línea 8179...
8628
 
8179
 
8629
        // Only show submission statement if we are editing our own submission.
8180
        // Only show submission statement if we are editing our own submission.
8630
        if ($requiresubmissionstatement && !$draftsenabled && $userid == $USER->id) {
8181
        if ($requiresubmissionstatement && !$draftsenabled && $userid == $USER->id) {
8631
            $mform->addElement('checkbox', 'submissionstatement', '', $submissionstatement);
-
 
8632
            $mform->addRule(
-
 
8633
                'submissionstatement',
8182
            $mform->addElement('checkbox', 'submissionstatement', '', $submissionstatement);
8634
                get_string('submissionstatementrequired', 'mod_assign'),
8183
            $mform->addRule('submissionstatement', get_string('submissionstatementrequired', 'mod_assign'),
8635
                'required',
-
 
8636
                null,
-
 
8637
                'client'
-
 
8638
            );
8184
                'required', null, 'client');
Línea 8639... Línea 8185...
8639
        }
8185
        }
Línea 8640... Línea 8186...
8640
 
8186
 
Línea 8656... Línea 8202...
8656
     *
8202
     *
8657
     * @param int $userid
8203
     * @param int $userid
8658
     * @return boolean
8204
     * @return boolean
8659
     * @throws coding_exception
8205
     * @throws coding_exception
8660
     */
8206
     */
8661
    public function remove_submission($userid)
8207
    public function remove_submission($userid) {
8662
    {
-
 
8663
        global $USER;
8208
        global $USER;
Línea 8664... Línea 8209...
8664
 
8209
 
8665
        if (!$this->can_edit_submission($userid, $USER->id)) {
8210
        if (!$this->can_edit_submission($userid, $USER->id)) {
8666
            $user = core_user::get_user($userid);
8211
            $user = core_user::get_user($userid);
Línea 8688... Línea 8233...
8688
                $plugin->remove($submission);
8233
                $plugin->remove($submission);
8689
            }
8234
            }
8690
        }
8235
        }
Línea 8691... Línea 8236...
8691
 
8236
 
8692
        $completion = new completion_info($this->get_course());
-
 
8693
        if (
8237
        $completion = new completion_info($this->get_course());
8694
            $completion->is_enabled($this->get_course_module()) &&
8238
        if ($completion->is_enabled($this->get_course_module()) &&
8695
            $this->get_instance()->completionsubmit
-
 
8696
        ) {
8239
                $this->get_instance()->completionsubmit) {
8697
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8240
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
Línea 8698... Línea 8241...
8698
        }
8241
        }
8699
 
8242
 
Línea 8706... Línea 8249...
8706
     * Revert to draft.
8249
     * Revert to draft.
8707
     *
8250
     *
8708
     * @param int $userid
8251
     * @param int $userid
8709
     * @return boolean
8252
     * @return boolean
8710
     */
8253
     */
8711
    public function revert_to_draft($userid)
8254
    public function revert_to_draft($userid) {
8712
    {
-
 
8713
        global $DB, $USER;
8255
        global $DB, $USER;
Línea 8714... Línea 8256...
8714
 
8256
 
8715
        // Need grade permission.
8257
        // Need grade permission.
Línea 8738... Línea 8280...
8738
        $grade = $this->get_user_grade($userid, true);
8280
        $grade = $this->get_user_grade($userid, true);
8739
        $grade->grader = $USER->id;
8281
        $grade->grader = $USER->id;
8740
        $this->update_grade($grade);
8282
        $this->update_grade($grade);
Línea 8741... Línea 8283...
8741
 
8283
 
8742
        $completion = new completion_info($this->get_course());
-
 
8743
        if (
8284
        $completion = new completion_info($this->get_course());
8744
            $completion->is_enabled($this->get_course_module()) &&
8285
        if ($completion->is_enabled($this->get_course_module()) &&
8745
            $this->get_instance()->completionsubmit
-
 
8746
        ) {
8286
                $this->get_instance()->completionsubmit) {
8747
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8287
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8748
        }
8288
        }
8749
        \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
8289
        \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
8750
        return true;
8290
        return true;
Línea 8754... Línea 8294...
8754
     * Remove the current submission.
8294
     * Remove the current submission.
8755
     *
8295
     *
8756
     * @param int $userid
8296
     * @param int $userid
8757
     * @return boolean
8297
     * @return boolean
8758
     */
8298
     */
8759
    protected function process_remove_submission($userid = 0)
8299
    protected function process_remove_submission($userid = 0) {
8760
    {
-
 
8761
        require_sesskey();
8300
        require_sesskey();
Línea 8762... Línea 8301...
8762
 
8301
 
8763
        if (!$userid) {
8302
        if (!$userid) {
8764
            $userid = required_param('userid', PARAM_INT);
8303
            $userid = required_param('userid', PARAM_INT);
Línea 8772... Línea 8311...
8772
     * Uses url parameter userid if userid not supplied as a parameter.
8311
     * Uses url parameter userid if userid not supplied as a parameter.
8773
     *
8312
     *
8774
     * @param int $userid
8313
     * @param int $userid
8775
     * @return boolean
8314
     * @return boolean
8776
     */
8315
     */
8777
    protected function process_revert_to_draft($userid = 0)
8316
    protected function process_revert_to_draft($userid = 0) {
8778
    {
-
 
8779
        require_sesskey();
8317
        require_sesskey();
Línea 8780... Línea 8318...
8780
 
8318
 
8781
        if (!$userid) {
8319
        if (!$userid) {
8782
            $userid = required_param('userid', PARAM_INT);
8320
            $userid = required_param('userid', PARAM_INT);
Línea 8789... Línea 8327...
8789
     * Prevent student updates to this submission
8327
     * Prevent student updates to this submission
8790
     *
8328
     *
8791
     * @param int $userid
8329
     * @param int $userid
8792
     * @return bool
8330
     * @return bool
8793
     */
8331
     */
8794
    public function lock_submission($userid)
8332
    public function lock_submission($userid) {
8795
    {
-
 
8796
        global $USER, $DB;
8333
        global $USER, $DB;
8797
        // Need grade permission.
8334
        // Need grade permission.
8798
        require_capability('mod/assign:grade', $this->context);
8335
        require_capability('mod/assign:grade', $this->context);
Línea 8799... Línea 8336...
8799
 
8336
 
Línea 8820... Línea 8357...
8820
    /**
8357
    /**
8821
     * Set the workflow state for multiple users
8358
     * Set the workflow state for multiple users
8822
     *
8359
     *
8823
     * @return void
8360
     * @return void
8824
     */
8361
     */
8825
    protected function process_set_batch_marking_workflow_state()
8362
    protected function process_set_batch_marking_workflow_state() {
8826
    {
-
 
8827
        global $CFG, $DB;
8363
        global $CFG, $DB;
Línea 8828... Línea 8364...
8828
 
8364
 
8829
        // Include batch marking workflow form.
8365
        // Include batch marking workflow form.
Línea 8853... Línea 8389...
8853
                // Clear the mailed flag if notification is requested, the student hasn't been
8389
                // Clear the mailed flag if notification is requested, the student hasn't been
8854
                // notified previously, the student can access the assignment, and the state
8390
                // notified previously, the student can access the assignment, and the state
8855
                // is "Released".
8391
                // is "Released".
8856
                $modinfo = get_fast_modinfo($this->course, $userid);
8392
                $modinfo = get_fast_modinfo($this->course, $userid);
8857
                $cm = $modinfo->get_cm($this->get_course_module()->id);
8393
                $cm = $modinfo->get_cm($this->get_course_module()->id);
8858
                if (
-
 
8859
                    $formdata->sendstudentnotifications && $cm->uservisible &&
8394
                if ($formdata->sendstudentnotifications && $cm->uservisible &&
8860
                    $state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
8395
                        $state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
8861
                ) {
-
 
8862
                    $flags->mailed = 0;
8396
                    $flags->mailed = 0;
8863
                }
8397
                }
Línea 8864... Línea 8398...
8864
 
8398
 
Línea 8876... Línea 8410...
8876
                        $grade->feedbacktext = $plugin->text_for_gradebook($grade);
8410
                        $grade->feedbacktext = $plugin->text_for_gradebook($grade);
8877
                        $grade->feedbackformat = $plugin->format_for_gradebook($grade);
8411
                        $grade->feedbackformat = $plugin->format_for_gradebook($grade);
8878
                        $grade->feedbackfiles = $plugin->files_for_gradebook($grade);
8412
                        $grade->feedbackfiles = $plugin->files_for_gradebook($grade);
8879
                    }
8413
                    }
8880
                    $this->update_grade($grade);
8414
                    $this->update_grade($grade);
8881
                    $assign = clone $this->get_instance();
-
 
8882
                    $assign->cmidnumber = $this->get_course_module()->idnumber;
-
 
8883
                    // Set assign gradebook feedback plugin status.
-
 
8884
                    $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled();
-
 
8885
 
-
 
8886
                    // If markinganonymous is enabled then allow to release grades anonymously.
-
 
8887
                    if (isset($assign->markinganonymous) && $assign->markinganonymous == 1) {
-
 
8888
                        assign_update_grades($assign, $userid);
-
 
8889
                    }
-
 
8890
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
8415
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
8891
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
8416
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $state)->trigger();
8892
                }
8417
                }
8893
            }
8418
            }
8894
        }
8419
        }
Línea 8897... Línea 8422...
8897
    /**
8422
    /**
8898
     * Set the marking allocation for multiple users
8423
     * Set the marking allocation for multiple users
8899
     *
8424
     *
8900
     * @return void
8425
     * @return void
8901
     */
8426
     */
8902
    protected function process_set_batch_marking_allocation()
8427
    protected function process_set_batch_marking_allocation() {
8903
    {
-
 
8904
        global $CFG, $DB;
8428
        global $CFG, $DB;
Línea 8905... Línea 8429...
8905
 
8429
 
8906
        // Include batch marking allocation form.
8430
        // Include batch marking allocation form.
Línea 8931... Línea 8455...
8931
            $useridlist = explode(',', $formdata->selectedusers);
8455
            $useridlist = explode(',', $formdata->selectedusers);
8932
            $marker = $DB->get_record('user', array('id' => $formdata->allocatedmarker), '*', MUST_EXIST);
8456
            $marker = $DB->get_record('user', array('id' => $formdata->allocatedmarker), '*', MUST_EXIST);
Línea 8933... Línea 8457...
8933
 
8457
 
8934
            foreach ($useridlist as $userid) {
8458
            foreach ($useridlist as $userid) {
8935
                $flags = $this->get_user_flags($userid, true);
-
 
8936
                if (
8459
                $flags = $this->get_user_flags($userid, true);
8937
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
8460
                if ($flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
8938
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
8461
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
8939
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
8462
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
8940
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
-
 
Línea 8941... Línea 8463...
8941
                ) {
8463
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
8942
 
8464
 
Línea 8943... Línea 8465...
8943
                    continue; // Allocated marker can only be changed in certain workflow states.
8465
                    continue; // Allocated marker can only be changed in certain workflow states.
Línea 8959... Línea 8481...
8959
     * Uses url parameter userid.
8481
     * Uses url parameter userid.
8960
     *
8482
     *
8961
     * @param int $userid
8483
     * @param int $userid
8962
     * @return void
8484
     * @return void
8963
     */
8485
     */
8964
    protected function process_lock_submission($userid = 0)
8486
    protected function process_lock_submission($userid = 0) {
8965
    {
-
 
Línea 8966... Línea 8487...
8966
 
8487
 
Línea 8967... Línea 8488...
8967
        require_sesskey();
8488
        require_sesskey();
8968
 
8489
 
Línea 8977... Línea 8498...
8977
     * Unlock the student submission.
8498
     * Unlock the student submission.
8978
     *
8499
     *
8979
     * @param int $userid
8500
     * @param int $userid
8980
     * @return bool
8501
     * @return bool
8981
     */
8502
     */
8982
    public function unlock_submission($userid)
8503
    public function unlock_submission($userid) {
8983
    {
-
 
8984
        global $USER, $DB;
8504
        global $USER, $DB;
Línea 8985... Línea 8505...
8985
 
8505
 
8986
        // Need grade permission.
8506
        // Need grade permission.
Línea 9010... Línea 8530...
9010
     * Uses url parameter userid.
8530
     * Uses url parameter userid.
9011
     *
8531
     *
9012
     * @param int $userid
8532
     * @param int $userid
9013
     * @return bool
8533
     * @return bool
9014
     */
8534
     */
9015
    protected function process_unlock_submission($userid = 0)
8535
    protected function process_unlock_submission($userid = 0) {
9016
    {
-
 
Línea 9017... Línea 8536...
9017
 
8536
 
Línea 9018... Línea 8537...
9018
        require_sesskey();
8537
        require_sesskey();
9019
 
8538
 
Línea 9030... Línea 8549...
9030
     * @param stdClass $formdata - the data from the form
8549
     * @param stdClass $formdata - the data from the form
9031
     * @param int $userid - the user to apply the grade to
8550
     * @param int $userid - the user to apply the grade to
9032
     * @param int $attemptnumber - The attempt number to apply the grade to.
8551
     * @param int $attemptnumber - The attempt number to apply the grade to.
9033
     * @return void
8552
     * @return void
9034
     */
8553
     */
9035
    protected function apply_grade_to_user($formdata, $userid, $attemptnumber)
8554
    protected function apply_grade_to_user($formdata, $userid, $attemptnumber) {
9036
    {
-
 
9037
        global $USER, $CFG, $DB;
8555
        global $USER, $CFG, $DB;
Línea 9038... Línea 8556...
9038
 
8556
 
9039
        $grade = $this->get_user_grade($userid, true, $attemptnumber);
8557
        $grade = $this->get_user_grade($userid, true, $attemptnumber);
9040
        $originalgrade = $grade->grade;
8558
        $originalgrade = $grade->grade;
9041
        $gradingdisabled = $this->grading_disabled($userid);
8559
        $gradingdisabled = $this->grading_disabled($userid);
9042
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
8560
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
9043
        if (!$gradingdisabled) {
8561
        if (!$gradingdisabled) {
9044
            if ($gradinginstance) {
8562
            if ($gradinginstance) {
9045
                $grade->grade = $gradinginstance->submit_and_get_grade(
8563
                $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading,
9046
                    $formdata->advancedgrading,
-
 
9047
                    $grade->id
-
 
9048
                );
8564
                                                                       $grade->id);
9049
            } else {
8565
            } else {
9050
                // Handle the case when grade is set to No Grade.
8566
                // Handle the case when grade is set to No Grade.
9051
                if (isset($formdata->grade)) {
8567
                if (isset($formdata->grade)) {
9052
                    $grade->grade = grade_floatval(unformat_float($formdata->grade));
8568
                    $grade->grade = grade_floatval(unformat_float($formdata->grade));
Línea 9055... Línea 8571...
9055
            if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
8571
            if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
9056
                $flags = $this->get_user_flags($userid, true);
8572
                $flags = $this->get_user_flags($userid, true);
9057
                $oldworkflowstate = $flags->workflowstate;
8573
                $oldworkflowstate = $flags->workflowstate;
9058
                $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
8574
                $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
9059
                $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
8575
                $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
9060
                if (
-
 
9061
                    $this->update_user_flags($flags) &&
8576
                if ($this->update_user_flags($flags) &&
9062
                    isset($formdata->workflowstate) &&
8577
                        isset($formdata->workflowstate) &&
9063
                    $formdata->workflowstate !== $oldworkflowstate
8578
                        $formdata->workflowstate !== $oldworkflowstate) {
9064
                ) {
-
 
9065
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
8579
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
9066
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $formdata->workflowstate)->trigger();
8580
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $formdata->workflowstate)->trigger();
9067
                }
8581
                }
9068
            }
8582
            }
9069
        }
8583
        }
9070
        $grade->grader = $USER->id;
8584
        $grade->grader= $USER->id;
Línea 9071... Línea 8585...
9071
 
8585
 
9072
        $adminconfig = $this->get_admin_config();
8586
        $adminconfig = $this->get_admin_config();
Línea 9073... Línea 8587...
9073
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
8587
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
Línea 9094... Línea 8608...
9094
                }
8608
                }
9095
            }
8609
            }
9096
        }
8610
        }
Línea 9097... Línea 8611...
9097
 
8611
 
9098
        // We do not want to update the timemodified if no grade was added.
-
 
9099
        if (
8612
        // We do not want to update the timemodified if no grade was added.
9100
            !empty($formdata->addattempt) ||
8613
        if (!empty($formdata->addattempt) ||
9101
            ($originalgrade !== null && $originalgrade != -1) ||
8614
                ($originalgrade !== null && $originalgrade != -1) ||
9102
            ($grade->grade !== null && $grade->grade != -1) ||
8615
                ($grade->grade !== null && $grade->grade != -1) ||
9103
            $feedbackmodified
-
 
9104
        ) {
8616
                $feedbackmodified) {
9105
            $this->update_grade($grade, !empty($formdata->addattempt));
8617
            $this->update_grade($grade, !empty($formdata->addattempt));
Línea 9106... Línea 8618...
9106
        }
8618
        }
9107
 
-
 
9108
        // We never send notifications if we have marking workflow and the grade is not released.
8619
 
9109
        if (
8620
        // We never send notifications if we have marking workflow and the grade is not released.
9110
            $this->get_instance()->markingworkflow &&
8621
        if ($this->get_instance()->markingworkflow &&
9111
            isset($formdata->workflowstate) &&
-
 
9112
            $formdata->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
8622
                isset($formdata->workflowstate) &&
9113
        ) {
8623
                $formdata->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
Línea 9114... Línea 8624...
9114
            $formdata->sendstudentnotifications = false;
8624
            $formdata->sendstudentnotifications = false;
9115
        }
8625
        }
Línea 9128... Línea 8638...
9128
     * @param int $userid
8638
     * @param int $userid
9129
     * @param stdClass $formdata
8639
     * @param stdClass $formdata
9130
     * @param int $sourceuserid The user ID under which the outcome data is accessible. This is relevant
8640
     * @param int $sourceuserid The user ID under which the outcome data is accessible. This is relevant
9131
     *                          for an outcome set to a user but applied to an entire group.
8641
     *                          for an outcome set to a user but applied to an entire group.
9132
     */
8642
     */
9133
    protected function process_outcomes($userid, $formdata, $sourceuserid = null)
8643
    protected function process_outcomes($userid, $formdata, $sourceuserid = null) {
9134
    {
-
 
9135
        global $CFG, $USER;
8644
        global $CFG, $USER;
Línea 9136... Línea 8645...
9136
 
8645
 
9137
        if (empty($CFG->enableoutcomes)) {
8646
        if (empty($CFG->enableoutcomes)) {
9138
            return;
8647
            return;
9139
        }
8648
        }
9140
        if ($this->grading_disabled($userid)) {
8649
        if ($this->grading_disabled($userid)) {
9141
            return;
8650
            return;
Línea 9142... Línea 8651...
9142
        }
8651
        }
Línea 9143... Línea 8652...
9143
 
8652
 
9144
        require_once($CFG->libdir . '/gradelib.php');
8653
        require_once($CFG->libdir.'/gradelib.php');
9145
 
8654
 
9146
        $data = array();
-
 
9147
        $gradinginfo = grade_get_grades(
8655
        $data = array();
9148
            $this->get_course()->id,
8656
        $gradinginfo = grade_get_grades($this->get_course()->id,
9149
            'mod',
8657
                                        'mod',
9150
            'assign',
-
 
Línea 9151... Línea 8658...
9151
            $this->get_instance()->id,
8658
                                        'assign',
9152
            $userid
8659
                                        $this->get_instance()->id,
9153
        );
8660
                                        $userid);
9154
 
8661
 
9155
        if (!empty($gradinginfo->outcomes)) {
-
 
9156
            foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
8662
        if (!empty($gradinginfo->outcomes)) {
9157
                $name = 'outcome_' . $index;
8663
            foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
9158
                $sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
-
 
9159
                if (
8664
                $name = 'outcome_'.$index;
9160
                    isset($formdata->{$name}[$sourceuserid]) &&
8665
                $sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
9161
                    $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]
8666
                if (isset($formdata->{$name}[$sourceuserid]) &&
9162
                ) {
8667
                        $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]) {
9163
                    $data[$index] = $formdata->{$name}[$sourceuserid];
8668
                    $data[$index] = $formdata->{$name}[$sourceuserid];
9164
                }
8669
                }
9165
            }
-
 
9166
        }
8670
            }
9167
        if (count($data) > 0) {
8671
        }
9168
            grade_update_outcomes(
8672
        if (count($data) > 0) {
9169
                'mod/assign',
8673
            grade_update_outcomes('mod/assign',
9170
                $this->course->id,
8674
                                  $this->course->id,
9171
                'mod',
8675
                                  'mod',
9172
                'assign',
-
 
9173
                $this->get_instance()->id,
8676
                                  'assign',
9174
                $userid,
8677
                                  $this->get_instance()->id,
Línea 9175... Línea 8678...
9175
                $data
8678
                                  $userid,
9176
            );
8679
                                  $data);
Línea 9184... Línea 8687...
9184
     * @param int $userid The userid.
8687
     * @param int $userid The userid.
9185
     * @param stdClass $submission The submission (may be a group submission).
8688
     * @param stdClass $submission The submission (may be a group submission).
9186
     * @param bool $addattempt - True if the "allow another attempt" checkbox was checked.
8689
     * @param bool $addattempt - True if the "allow another attempt" checkbox was checked.
9187
     * @return bool - true if another attempt was added.
8690
     * @return bool - true if another attempt was added.
9188
     */
8691
     */
9189
    protected function reopen_submission_if_required($userid, $submission, $addattempt)
8692
    protected function reopen_submission_if_required($userid, $submission, $addattempt) {
9190
    {
-
 
9191
        $instance = $this->get_instance();
8693
        $instance = $this->get_instance();
9192
        $maxattemptsreached = !empty($submission) &&
8694
        $maxattemptsreached = !empty($submission) &&
9193
            $submission->attemptnumber >= ($instance->maxattempts - 1) &&
8695
                              $submission->attemptnumber >= ($instance->maxattempts - 1) &&
9194
            $instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
8696
                              $instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
9195
        $shouldreopen = false;
8697
        $shouldreopen = false;
-
 
8698
        switch ($instance->attemptreopenmethod) {
-
 
8699
            case ASSIGN_ATTEMPT_REOPEN_METHOD_AUTOMATIC:
-
 
8700
                $shouldreopen = true;
-
 
8701
                break;
9196
        if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
8702
            case ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS:
9197
            // Check the gradetopass from the gradebook.
8703
                // Check the gradetopass from the gradebook.
9198
            $gradeitem = $this->get_grade_item();
8704
                $gradeitem = $this->get_grade_item();
9199
            if ($gradeitem) {
8705
                if ($gradeitem) {
9200
                $gradegrade = grade_grade::fetch(array('userid' => $userid, 'itemid' => $gradeitem->id));
8706
                    $gradegrade = grade_grade::fetch(['userid' => $userid, 'itemid' => $gradeitem->id]);
9201
 
8707
 
9202
                // Do not reopen if is_passed returns null, e.g. if there is no pass criterion set.
8708
                    // Do not reopen if is_passed returns null, e.g. if there is no pass criterion set.
9203
                if ($gradegrade && ($gradegrade->is_passed() === false)) {
8709
                    if ($gradegrade && ($gradegrade->is_passed() === false)) {
-
 
8710
                        $shouldreopen = true;
-
 
8711
                    }
-
 
8712
                }
-
 
8713
                break;
-
 
8714
            case ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL:
-
 
8715
                if (!empty($addattempt)) {
9204
                    $shouldreopen = true;
8716
                    $shouldreopen = true;
9205
                }
8717
                }
9206
            }
8718
                break;
9207
        }
-
 
9208
        if (
-
 
9209
            $instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL &&
-
 
9210
            !empty($addattempt)
-
 
9211
        ) {
-
 
9212
            $shouldreopen = true;
-
 
9213
        }
8719
        }
9214
        if ($shouldreopen && !$maxattemptsreached) {
8720
        if ($shouldreopen && !$maxattemptsreached) {
9215
            $this->add_attempt($userid);
8721
            $this->add_attempt($userid);
9216
            return true;
8722
            return true;
9217
        }
8723
        }
Línea 9223... Línea 8729...
9223
     *
8729
     *
9224
     * @param int $userid
8730
     * @param int $userid
9225
     * @param  stdClass $data
8731
     * @param  stdClass $data
9226
     * @return bool - was the grade saved
8732
     * @return bool - was the grade saved
9227
     */
8733
     */
9228
    public function save_grade($userid, $data)
8734
    public function save_grade($userid, $data) {
9229
    {
-
 
Línea 9230... Línea 8735...
9230
 
8735
 
9231
        // Need grade permission.
8736
        // Need grade permission.
Línea 9232... Línea 8737...
9232
        require_capability('mod/assign:grade', $this->context);
8737
        require_capability('mod/assign:grade', $this->context);
Línea 9273... Línea 8778...
9273
     * Save grade.
8778
     * Save grade.
9274
     *
8779
     *
9275
     * @param  moodleform $mform
8780
     * @param  moodleform $mform
9276
     * @return bool - was the grade saved
8781
     * @return bool - was the grade saved
9277
     */
8782
     */
9278
    protected function process_save_grade(&$mform)
8783
    protected function process_save_grade(&$mform) {
9279
    {
-
 
9280
        global $CFG, $SESSION;
8784
        global $CFG, $SESSION;
9281
        // Include grade form.
8785
        // Include grade form.
9282
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
8786
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
Línea 9283... Línea 8787...
9283
 
8787
 
Línea 9307... Línea 8811...
9307
            $last = true;
8811
            $last = true;
9308
        }
8812
        }
Línea 9309... Línea 8813...
9309
 
8813
 
Línea 9310... Línea 8814...
9310
        $data = new stdClass();
8814
        $data = new stdClass();
9311
 
-
 
9312
        $gradeformparams = array(
8815
 
9313
            'rownum' => $rownum,
8816
        $gradeformparams = array('rownum' => $rownum,
9314
            'useridlistid' => $useridlistid,
8817
                                 'useridlistid' => $useridlistid,
9315
            'last' => $last,
8818
                                 'last' => $last,
9316
            'attemptnumber' => $attemptnumber,
-
 
9317
            'userid' => $userid
8819
                                 'attemptnumber' => $attemptnumber,
9318
        );
-
 
9319
        $mform = new mod_assign_grade_form(
8820
                                 'userid' => $userid);
9320
            null,
8821
        $mform = new mod_assign_grade_form(null,
9321
            array($this, $data, $gradeformparams),
8822
                                           array($this, $data, $gradeformparams),
9322
            'post',
8823
                                           'post',
9323
            '',
-
 
Línea 9324... Línea 8824...
9324
            array('class' => 'gradeform')
8824
                                           '',
9325
        );
8825
                                           array('class'=>'gradeform'));
9326
 
8826
 
9327
        if ($formdata = $mform->get_data()) {
8827
        if ($formdata = $mform->get_data()) {
Línea 9336... Línea 8836...
9336
     *
8836
     *
9337
     * @param string $type The plugin type
8837
     * @param string $type The plugin type
9338
     * @param int $version The plugin version
8838
     * @param int $version The plugin version
9339
     * @return bool
8839
     * @return bool
9340
     */
8840
     */
9341
    public static function can_upgrade_assignment($type, $version)
8841
    public static function can_upgrade_assignment($type, $version) {
9342
    {
-
 
9343
        $assignment = new assign(null, null, null);
8842
        $assignment = new assign(null, null, null);
9344
        return $assignment->can_upgrade($type, $version);
8843
        return $assignment->can_upgrade($type, $version);
9345
    }
8844
    }
Línea 9346... Línea 8845...
9346
 
8845
 
Línea 9349... Línea 8848...
9349
     *
8848
     *
9350
     * @param string $type The plugin type
8849
     * @param string $type The plugin type
9351
     * @param int $version The plugin version
8850
     * @param int $version The plugin version
9352
     * @return bool
8851
     * @return bool
9353
     */
8852
     */
9354
    public function can_upgrade($type, $version)
8853
    public function can_upgrade($type, $version) {
9355
    {
-
 
9356
        if ($type == 'offline' && $version >= 2011112900) {
8854
        if ($type == 'offline' && $version >= 2011112900) {
9357
            return true;
8855
            return true;
9358
        }
8856
        }
9359
        foreach ($this->submissionplugins as $plugin) {
8857
        foreach ($this->submissionplugins as $plugin) {
9360
            if ($plugin->can_upgrade($type, $version)) {
8858
            if ($plugin->can_upgrade($type, $version)) {
Línea 9381... Línea 8879...
9381
     * @param int $newcomponent The new assignment component ('assignment')
8879
     * @param int $newcomponent The new assignment component ('assignment')
9382
     * @param int $newfilearea The new assignment filearea ('submissions')
8880
     * @param int $newfilearea The new assignment filearea ('submissions')
9383
     * @param int $newitemid The new submissionid (can be null e.g. intro)
8881
     * @param int $newitemid The new submissionid (can be null e.g. intro)
9384
     * @return int The number of files copied
8882
     * @return int The number of files copied
9385
     */
8883
     */
9386
    public function copy_area_files_for_upgrade(
8884
    public function copy_area_files_for_upgrade($oldcontextid,
9387
        $oldcontextid,
-
 
9388
        $oldcomponent,
8885
                                                $oldcomponent,
9389
        $oldfilearea,
8886
                                                $oldfilearea,
9390
        $olditemid,
8887
                                                $olditemid,
9391
        $newcontextid,
8888
                                                $newcontextid,
9392
        $newcomponent,
8889
                                                $newcomponent,
9393
        $newfilearea,
8890
                                                $newfilearea,
9394
        $newitemid
8891
                                                $newitemid) {
9395
    ) {
-
 
9396
        // Note, this code is based on some code in filestorage - but that code
8892
        // Note, this code is based on some code in filestorage - but that code
9397
        // deleted the old files (which we don't want).
8893
        // deleted the old files (which we don't want).
9398
        $count = 0;
8894
        $count = 0;
Línea 9399... Línea 8895...
9399
 
8895
 
Línea 9400... Línea 8896...
9400
        $fs = get_file_storage();
8896
        $fs = get_file_storage();
9401
 
-
 
9402
        $oldfiles = $fs->get_area_files(
8897
 
9403
            $oldcontextid,
8898
        $oldfiles = $fs->get_area_files($oldcontextid,
9404
            $oldcomponent,
8899
                                        $oldcomponent,
9405
            $oldfilearea,
8900
                                        $oldfilearea,
9406
            $olditemid,
8901
                                        $olditemid,
9407
            'id',
-
 
9408
            false
8902
                                        'id',
9409
        );
8903
                                        false);
9410
        foreach ($oldfiles as $oldfile) {
8904
        foreach ($oldfiles as $oldfile) {
9411
            $filerecord = new stdClass();
8905
            $filerecord = new stdClass();
9412
            $filerecord->contextid = $newcontextid;
8906
            $filerecord->contextid = $newcontextid;
Línea 9425... Línea 8919...
9425
     * at most 1 time.
8919
     * at most 1 time.
9426
     *
8920
     *
9427
     * @param array $useridlist Array of userids to reopen.
8921
     * @param array $useridlist Array of userids to reopen.
9428
     * @return bool
8922
     * @return bool
9429
     */
8923
     */
9430
    protected function process_add_attempt_group($useridlist)
8924
    protected function process_add_attempt_group($useridlist) {
9431
    {
-
 
9432
        $groupsprocessed = array();
8925
        $groupsprocessed = array();
9433
        $result = true;
8926
        $result = true;
Línea 9434... Línea 8927...
9434
 
8927
 
9435
        foreach ($useridlist as $userid) {
8928
        foreach ($useridlist as $userid) {
Línea 9456... Línea 8949...
9456
     * Check for a sess key and then call add_attempt.
8949
     * Check for a sess key and then call add_attempt.
9457
     *
8950
     *
9458
     * @param int $userid int The user to add the attempt for
8951
     * @param int $userid int The user to add the attempt for
9459
     * @return bool - true if successful.
8952
     * @return bool - true if successful.
9460
     */
8953
     */
9461
    protected function process_add_attempt($userid)
8954
    protected function process_add_attempt($userid) {
9462
    {
-
 
9463
        require_sesskey();
8955
        require_sesskey();
Línea 9464... Línea 8956...
9464
 
8956
 
9465
        return $this->add_attempt($userid);
8957
        return $this->add_attempt($userid);
Línea 9469... Línea 8961...
9469
     * Add a new attempt for a user.
8961
     * Add a new attempt for a user.
9470
     *
8962
     *
9471
     * @param int $userid int The user to add the attempt for
8963
     * @param int $userid int The user to add the attempt for
9472
     * @return bool - true if successful.
8964
     * @return bool - true if successful.
9473
     */
8965
     */
9474
    protected function add_attempt($userid)
8966
    protected function add_attempt($userid) {
9475
    {
-
 
9476
        require_capability('mod/assign:grade', $this->context);
8967
        require_capability('mod/assign:grade', $this->context);
Línea -... Línea 8968...
-
 
8968
 
9477
 
8969
        // If additional attempts are disallowed.
9478
        if ($this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
8970
        if ($this->get_instance()->maxattempts == 1) {
9479
            return false;
8971
            return false;
Línea 9480... Línea 8972...
9480
        }
8972
        }
9481
 
8973
 
Línea 9488... Línea 8980...
9488
        if (!$oldsubmission) {
8980
        if (!$oldsubmission) {
9489
            return false;
8981
            return false;
9490
        }
8982
        }
Línea 9491... Línea 8983...
9491
 
8983
 
9492
        // No more than max attempts allowed.
-
 
9493
        if (
8984
        // No more than max attempts allowed.
9494
            $this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
8985
        if ($this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
9495
            $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)
-
 
9496
        ) {
8986
            $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)) {
9497
            return false;
8987
            return false;
Línea 9498... Línea 8988...
9498
        }
8988
        }
9499
 
8989
 
Línea 9545... Línea 9035...
9545
     *                                                   feedbackformat,
9035
     *                                                   feedbackformat,
9546
     *                                                   usermodified,
9036
     *                                                   usermodified,
9547
     *                                                   dategraded,
9037
     *                                                   dategraded,
9548
     *                                                   datesubmitted
9038
     *                                                   datesubmitted
9549
     */
9039
     */
9550
    public function get_user_grades_for_gradebook($userid)
9040
    public function get_user_grades_for_gradebook($userid) {
9551
    {
-
 
9552
        global $DB, $CFG;
9041
        global $DB, $CFG;
9553
        $grades = array();
9042
        $grades = array();
9554
        $assignmentid = $this->get_instance()->id;
9043
        $assignmentid = $this->get_instance()->id;
Línea 9555... Línea 9044...
9555
 
9044
 
Línea 9570... Línea 9059...
9570
        } else {
9059
        } else {
9571
            $where = ' WHERE u.id != :userid ';
9060
            $where = ' WHERE u.id != :userid ';
9572
        }
9061
        }
Línea 9573... Línea 9062...
9573
 
9062
 
9574
        // When the gradebook asks us for grades - only return the last attempt for each user.
-
 
9575
        $params = array(
9063
        // When the gradebook asks us for grades - only return the last attempt for each user.
9576
            'assignid1' => $assignmentid,
9064
        $params = array('assignid1'=>$assignmentid,
9577
            'assignid2' => $assignmentid,
9065
                        'assignid2'=>$assignmentid,
9578
            'userid' => $userid
-
 
9579
        );
9066
                        'userid'=>$userid);
9580
        $graderesults = $DB->get_recordset_sql('SELECT
9067
        $graderesults = $DB->get_recordset_sql('SELECT
9581
                                                    u.id as userid,
9068
                                                    u.id as userid,
9582
                                                    s.timemodified as datesubmitted,
9069
                                                    s.timemodified as datesubmitted,
9583
                                                    g.grade as rawgrade,
9070
                                                    g.grade as rawgrade,
Línea 9588... Línea 9075...
9588
                                                    ON u.id = s.userid and s.assignment = :assignid1 AND
9075
                                                    ON u.id = s.userid and s.assignment = :assignid1 AND
9589
                                                    s.latest = 1
9076
                                                    s.latest = 1
9590
                                                JOIN {assign_grades} g
9077
                                                JOIN {assign_grades} g
9591
                                                    ON u.id = g.userid and g.assignment = :assignid2 AND
9078
                                                    ON u.id = g.userid and g.assignment = :assignid2 AND
9592
                                                    g.attemptnumber = s.attemptnumber' .
9079
                                                    g.attemptnumber = s.attemptnumber' .
9593
            $where, $params);
9080
                                                $where, $params);
Línea 9594... Línea 9081...
9594
 
9081
 
9595
        foreach ($graderesults as $result) {
9082
        foreach ($graderesults as $result) {
9596
            $gradingstatus = $this->get_grading_status($result->userid);
9083
            $gradingstatus = $this->get_grading_status($result->userid);
9597
            if (!$this->get_instance()->markingworkflow || $gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
9084
            if (!$this->get_instance()->markingworkflow || $gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
Línea 9620... Línea 9107...
9620
     * Call the static version of this function
9107
     * Call the static version of this function
9621
     *
9108
     *
9622
     * @param int $userid The userid to lookup
9109
     * @param int $userid The userid to lookup
9623
     * @return int The unique id
9110
     * @return int The unique id
9624
     */
9111
     */
9625
    public function get_uniqueid_for_user($userid)
9112
    public function get_uniqueid_for_user($userid) {
9626
    {
-
 
9627
        return self::get_uniqueid_for_user_static($this->get_instance()->id, $userid);
9113
        return self::get_uniqueid_for_user_static($this->get_instance()->id, $userid);
9628
    }
9114
    }
Línea 9629... Línea 9115...
9629
 
9115
 
9630
    /**
9116
    /**
9631
     * Foreach participant in the course - assign them a random id.
9117
     * Foreach participant in the course - assign them a random id.
9632
     *
9118
     *
9633
     * @param int $assignid The assignid to lookup
9119
     * @param int $assignid The assignid to lookup
9634
     */
9120
     */
9635
    public static function allocate_unique_ids($assignid)
-
 
9636
    {
9121
    public static function allocate_unique_ids($assignid) {
Línea 9637... Línea 9122...
9637
        global $DB;
9122
        global $DB;
9638
 
9123
 
Línea 9644... Línea 9129...
9644
 
9129
 
9645
        // Shuffle the users.
9130
        // Shuffle the users.
Línea 9646... Línea 9131...
9646
        shuffle($users);
9131
        shuffle($users);
9647
 
9132
 
9648
        foreach ($users as $user) {
-
 
9649
            $record = $DB->get_record(
9133
        foreach ($users as $user) {
9650
                'assign_user_mapping',
9134
            $record = $DB->get_record('assign_user_mapping',
9651
                array('assignment' => $assignid, 'userid' => $user->id),
-
 
9652
                'id'
9135
                                      array('assignment'=>$assignid, 'userid'=>$user->id),
9653
            );
9136
                                     'id');
9654
            if (!$record) {
9137
            if (!$record) {
9655
                $record = new stdClass();
9138
                $record = new stdClass();
9656
                $record->assignment = $assignid;
9139
                $record->assignment = $assignid;
Línea 9665... Línea 9148...
9665
     *
9148
     *
9666
     * @param int $assignid The assignment id
9149
     * @param int $assignid The assignment id
9667
     * @param int $userid The userid to lookup
9150
     * @param int $userid The userid to lookup
9668
     * @return int The unique id
9151
     * @return int The unique id
9669
     */
9152
     */
9670
    public static function get_uniqueid_for_user_static($assignid, $userid)
9153
    public static function get_uniqueid_for_user_static($assignid, $userid) {
9671
    {
-
 
9672
        global $DB;
9154
        global $DB;
Línea 9673... Línea 9155...
9673
 
9155
 
9674
        // Search for a record.
9156
        // Search for a record.
9675
        $params = array('assignment' => $assignid, 'userid' => $userid);
9157
        $params = array('assignment'=>$assignid, 'userid'=>$userid);
9676
        if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) {
9158
        if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) {
9677
            return $record->id;
9159
            return $record->id;
Línea 9678... Línea 9160...
9678
        }
9160
        }
Línea 9699... Línea 9181...
9699
     * Call the static version of this function.
9181
     * Call the static version of this function.
9700
     *
9182
     *
9701
     * @param int $uniqueid The uniqueid to lookup
9183
     * @param int $uniqueid The uniqueid to lookup
9702
     * @return int The user id or false if they don't exist
9184
     * @return int The user id or false if they don't exist
9703
     */
9185
     */
9704
    public function get_user_id_for_uniqueid($uniqueid)
9186
    public function get_user_id_for_uniqueid($uniqueid) {
9705
    {
-
 
9706
        return self::get_user_id_for_uniqueid_static($this->get_instance()->id, $uniqueid);
9187
        return self::get_user_id_for_uniqueid_static($this->get_instance()->id, $uniqueid);
9707
    }
9188
    }
Línea 9708... Línea 9189...
9708
 
9189
 
9709
    /**
9190
    /**
9710
     * Lookup this unique id and return the user id for this assignment.
9191
     * Lookup this unique id and return the user id for this assignment.
9711
     *
9192
     *
9712
     * @param int $assignid The id of the assignment this user mapping is in
9193
     * @param int $assignid The id of the assignment this user mapping is in
9713
     * @param int $uniqueid The uniqueid to lookup
9194
     * @param int $uniqueid The uniqueid to lookup
9714
     * @return int The user id or false if they don't exist
9195
     * @return int The user id or false if they don't exist
9715
     */
9196
     */
9716
    public static function get_user_id_for_uniqueid_static($assignid, $uniqueid)
-
 
9717
    {
9197
    public static function get_user_id_for_uniqueid_static($assignid, $uniqueid) {
Línea 9718... Línea 9198...
9718
        global $DB;
9198
        global $DB;
9719
 
9199
 
9720
        // Search for a record.
-
 
9721
        if ($record = $DB->get_record(
9200
        // Search for a record.
9722
            'assign_user_mapping',
9201
        if ($record = $DB->get_record('assign_user_mapping',
9723
            array('assignment' => $assignid, 'id' => $uniqueid),
9202
                                      array('assignment'=>$assignid, 'id'=>$uniqueid),
9724
            'userid',
-
 
9725
            IGNORE_MISSING
9203
                                      'userid',
9726
        )) {
9204
                                      IGNORE_MISSING)) {
Línea 9727... Línea 9205...
9727
            return $record->userid;
9205
            return $record->userid;
9728
        }
9206
        }
Línea 9733... Línea 9211...
9733
    /**
9211
    /**
9734
     * Get the list of marking_workflow states the current user has permission to transition a grade to.
9212
     * Get the list of marking_workflow states the current user has permission to transition a grade to.
9735
     *
9213
     *
9736
     * @return array of state => description
9214
     * @return array of state => description
9737
     */
9215
     */
9738
    public function get_marking_workflow_states_for_current_user()
9216
    public function get_marking_workflow_states_for_current_user() {
9739
    {
-
 
9740
        if (!empty($this->markingworkflowstates)) {
9217
        if (!empty($this->markingworkflowstates)) {
9741
            return $this->markingworkflowstates;
9218
            return $this->markingworkflowstates;
9742
        }
9219
        }
9743
        $states = array();
9220
        $states = array();
9744
        if (has_capability('mod/assign:grade', $this->context)) {
9221
        if (has_capability('mod/assign:grade', $this->context)) {
9745
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INMARKING] = get_string('markingworkflowstateinmarking', 'assign');
9222
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INMARKING] = get_string('markingworkflowstateinmarking', 'assign');
9746
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW] = get_string('markingworkflowstatereadyforreview', 'assign');
9223
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW] = get_string('markingworkflowstatereadyforreview', 'assign');
9747
        }
9224
        }
9748
        if (has_any_capability(array(
9225
        if (has_any_capability(array('mod/assign:reviewgrades',
9749
            'mod/assign:reviewgrades',
-
 
9750
            'mod/assign:managegrades'
9226
                                     'mod/assign:managegrades'), $this->context)) {
9751
        ), $this->context)) {
-
 
9752
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW] = get_string('markingworkflowstateinreview', 'assign');
9227
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW] = get_string('markingworkflowstateinreview', 'assign');
9753
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE] = get_string('markingworkflowstatereadyforrelease', 'assign');
9228
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE] = get_string('markingworkflowstatereadyforrelease', 'assign');
9754
        }
9229
        }
9755
        if (has_any_capability(array(
9230
        if (has_any_capability(array('mod/assign:releasegrades',
9756
            'mod/assign:releasegrades',
-
 
9757
            'mod/assign:managegrades'
9231
                                     'mod/assign:managegrades'), $this->context)) {
9758
        ), $this->context)) {
-
 
9759
            $states[ASSIGN_MARKING_WORKFLOW_STATE_RELEASED] = get_string('markingworkflowstatereleased', 'assign');
9232
            $states[ASSIGN_MARKING_WORKFLOW_STATE_RELEASED] = get_string('markingworkflowstatereleased', 'assign');
9760
        }
9233
        }
9761
        $this->markingworkflowstates = $states;
9234
        $this->markingworkflowstates = $states;
9762
        return $this->markingworkflowstates;
9235
        return $this->markingworkflowstates;
9763
    }
9236
    }
Línea 9765... Línea 9238...
9765
    /**
9238
    /**
9766
     * Get the list of marking_workflow states.
9239
     * Get the list of marking_workflow states.
9767
     *
9240
     *
9768
     * @return array Array of multiple state => description.
9241
     * @return array Array of multiple state => description.
9769
     */
9242
     */
9770
    public function get_all_marking_workflow_states(): array
9243
    public function get_all_marking_workflow_states(): array {
9771
    {
-
 
9772
        if (!empty($this->allmarkingworkflowstates)) {
9244
        if (!empty($this->allmarkingworkflowstates)) {
9773
            return $this->allmarkingworkflowstates;
9245
            return $this->allmarkingworkflowstates;
9774
        }
9246
        }
Línea 9775... Línea 9247...
9775
 
9247
 
Línea 9788... Línea 9260...
9788
    /**
9260
    /**
9789
     * Check is only active users in course should be shown.
9261
     * Check is only active users in course should be shown.
9790
     *
9262
     *
9791
     * @return bool true if only active users should be shown.
9263
     * @return bool true if only active users should be shown.
9792
     */
9264
     */
9793
    public function show_only_active_users()
9265
    public function show_only_active_users() {
9794
    {
-
 
9795
        global $CFG;
9266
        global $CFG;
Línea 9796... Línea 9267...
9796
 
9267
 
9797
        if (is_null($this->showonlyactiveenrol)) {
9268
        if (is_null($this->showonlyactiveenrol)) {
9798
            $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
9269
            $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
Línea 9799... Línea 9270...
9799
            $this->showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
9270
            $this->showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
9800
 
9271
 
9801
            if (!is_null($this->context)) {
9272
            if (!is_null($this->context)) {
9802
                $this->showonlyactiveenrol = $this->showonlyactiveenrol ||
9273
                $this->showonlyactiveenrol = $this->showonlyactiveenrol ||
9803
                    !has_capability('moodle/course:viewsuspendedusers', $this->context);
9274
                            !has_capability('moodle/course:viewsuspendedusers', $this->context);
9804
            }
9275
            }
9805
        }
9276
        }
Línea 9810... Línea 9281...
9810
     * Return true is user is active user in course else false
9281
     * Return true is user is active user in course else false
9811
     *
9282
     *
9812
     * @param int $userid
9283
     * @param int $userid
9813
     * @return bool true is user is active in course.
9284
     * @return bool true is user is active in course.
9814
     */
9285
     */
9815
    public function is_active_user($userid)
9286
    public function is_active_user($userid) {
9816
    {
-
 
9817
        return !in_array($userid, get_suspended_userids($this->context, true));
9287
        return !in_array($userid, get_suspended_userids($this->context, true));
9818
    }
9288
    }
Línea 9819... Línea 9289...
9819
 
9289
 
9820
    /**
9290
    /**
9821
     * Returns true if gradebook feedback plugin is enabled
9291
     * Returns true if gradebook feedback plugin is enabled
9822
     *
9292
     *
9823
     * @return bool true if gradebook feedback plugin is enabled and visible else false.
9293
     * @return bool true if gradebook feedback plugin is enabled and visible else false.
9824
     */
9294
     */
9825
    public function is_gradebook_feedback_enabled()
-
 
9826
    {
9295
    public function is_gradebook_feedback_enabled() {
9827
        // Get default grade book feedback plugin.
9296
        // Get default grade book feedback plugin.
9828
        $adminconfig = $this->get_admin_config();
9297
        $adminconfig = $this->get_admin_config();
9829
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
9298
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
Línea 9848... Línea 9317...
9848
     * Returns the grading status.
9317
     * Returns the grading status.
9849
     *
9318
     *
9850
     * @param int $userid the user id
9319
     * @param int $userid the user id
9851
     * @return string returns the grading status
9320
     * @return string returns the grading status
9852
     */
9321
     */
9853
    public function get_grading_status($userid)
9322
    public function get_grading_status($userid) {
9854
    {
-
 
9855
        if ($this->get_instance()->markingworkflow) {
9323
        if ($this->get_instance()->markingworkflow) {
9856
            $flags = $this->get_user_flags($userid, false);
9324
            $flags = $this->get_user_flags($userid, false);
9857
            if (!empty($flags->workflowstate)) {
9325
            if (!empty($flags->workflowstate)) {
9858
                return $flags->workflowstate;
9326
                return $flags->workflowstate;
9859
            }
9327
            }
Línea 9873... Línea 9341...
9873
    /**
9341
    /**
9874
     * The id used to uniquily identify the cache for this instance of the assign object.
9342
     * The id used to uniquily identify the cache for this instance of the assign object.
9875
     *
9343
     *
9876
     * @return string
9344
     * @return string
9877
     */
9345
     */
9878
    public function get_useridlist_key_id()
9346
    public function get_useridlist_key_id() {
9879
    {
-
 
9880
        return $this->useridlistid;
9347
        return $this->useridlistid;
9881
    }
9348
    }
Línea 9882... Línea 9349...
9882
 
9349
 
9883
    /**
9350
    /**
9884
     * Generates the key that should be used for an entry in the useridlist cache.
9351
     * Generates the key that should be used for an entry in the useridlist cache.
9885
     *
9352
     *
9886
     * @param string $id Generate a key for this instance (optional)
9353
     * @param string $id Generate a key for this instance (optional)
9887
     * @return string The key for the id, or new entry if no $id is passed.
9354
     * @return string The key for the id, or new entry if no $id is passed.
9888
     */
9355
     */
9889
    public function get_useridlist_key($id = null)
-
 
9890
    {
9356
    public function get_useridlist_key($id = null) {
Línea 9891... Línea 9357...
9891
        global $SESSION;
9357
        global $SESSION;
9892
 
9358
 
9893
        // Ensure the user id list cache is initialised.
9359
        // Ensure the user id list cache is initialised.
Línea 9911... Línea 9377...
9911
     * @param int $complete
9377
     * @param int $complete
9912
     * @param obj $completion
9378
     * @param obj $completion
9913
     *
9379
     *
9914
     * @return null
9380
     * @return null
9915
     */
9381
     */
9916
    protected function update_activity_completion_records(
9382
    protected function update_activity_completion_records($teamsubmission,
9917
        $teamsubmission,
-
 
9918
        $requireallteammemberssubmit,
9383
                                                          $requireallteammemberssubmit,
9919
        $submission,
9384
                                                          $submission,
9920
        $userid,
9385
                                                          $userid,
9921
        $complete,
9386
                                                          $complete,
9922
        $completion
9387
                                                          $completion) {
9923
    ) {
-
 
Línea 9924... Línea 9388...
9924
 
9388
 
9925
        if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
9389
        if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
9926
            ($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
9390
            ($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
9927
                $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)
-
 
Línea 9928... Línea 9391...
9928
        ) {
9391
             $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {
Línea 9929... Línea 9392...
9929
 
9392
 
9930
            $members = groups_get_members($submission->groupid);
9393
            $members = groups_get_members($submission->groupid);
Línea 9942... Línea 9405...
9942
    /**
9405
    /**
9943
     * Update the module completion status (set it viewed) and trigger module viewed event.
9406
     * Update the module completion status (set it viewed) and trigger module viewed event.
9944
     *
9407
     *
9945
     * @since Moodle 3.2
9408
     * @since Moodle 3.2
9946
     */
9409
     */
9947
    public function set_module_viewed()
9410
    public function set_module_viewed() {
9948
    {
-
 
9949
        $completion = new completion_info($this->get_course());
9411
        $completion = new completion_info($this->get_course());
9950
        $completion->set_module_viewed($this->get_course_module());
9412
        $completion->set_module_viewed($this->get_course_module());
Línea 9951... Línea 9413...
9951
 
9413
 
9952
        // Trigger the course module viewed event.
9414
        // Trigger the course module viewed event.
Línea 9968... Línea 9430...
9968
    /**
9430
    /**
9969
     * Checks for any grade notices, and adds notifications. Will display on assignment main page and grading table.
9431
     * Checks for any grade notices, and adds notifications. Will display on assignment main page and grading table.
9970
     *
9432
     *
9971
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9433
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9972
     */
9434
     */
9973
    protected function add_grade_notices()
9435
    protected function add_grade_notices() {
9974
    {
-
 
9975
        if (has_capability('mod/assign:grade', $this->get_context()) && get_config('assign', 'has_rescaled_null_grades_' . $this->get_instance()->id)) {
9436
        if (has_capability('mod/assign:grade', $this->get_context()) && get_config('assign', 'has_rescaled_null_grades_' . $this->get_instance()->id)) {
9976
            $link = new \moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id, 'action' => 'fixrescalednullgrades'));
9437
            $link = new \moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id, 'action' => 'fixrescalednullgrades'));
9977
            \core\notification::warning(get_string('fixrescalednullgrades', 'mod_assign', ['link' => $link->out()]));
9438
            \core\notification::warning(get_string('fixrescalednullgrades', 'mod_assign', ['link' => $link->out()]));
9978
        }
9439
        }
9979
    }
9440
    }
Línea 9981... Línea 9442...
9981
    /**
9442
    /**
9982
     * View fix rescaled null grades.
9443
     * View fix rescaled null grades.
9983
     *
9444
     *
9984
     * @return bool True if null all grades are now fixed.
9445
     * @return bool True if null all grades are now fixed.
9985
     */
9446
     */
9986
    protected function fix_null_grades()
9447
    protected function fix_null_grades() {
9987
    {
-
 
9988
        global $DB;
9448
        global $DB;
9989
        $result = $DB->set_field_select(
9449
        $result = $DB->set_field_select(
9990
            'assign_grades',
9450
            'assign_grades',
9991
            'grade',
9451
            'grade',
9992
            ASSIGN_GRADE_NOT_SET,
9452
            ASSIGN_GRADE_NOT_SET,
Línea 10002... Línea 9462...
10002
    /**
9462
    /**
10003
     * View fix rescaled null grades.
9463
     * View fix rescaled null grades.
10004
     *
9464
     *
10005
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9465
     * @return void The notifications API will render the notifications at the appropriate part of the page.
10006
     */
9466
     */
10007
    protected function view_fix_rescaled_null_grades()
9467
    protected function view_fix_rescaled_null_grades() {
10008
    {
-
 
10009
        global $OUTPUT;
9468
        global $OUTPUT;
Línea 10010... Línea 9469...
10010
 
9469
 
Línea 10011... Línea 9470...
10011
        $o = '';
9470
        $o = '';
Línea 10062... Línea 9521...
10062
     * attempt on a group assignment, and whether the gradebook should be updated.
9521
     * attempt on a group assignment, and whether the gradebook should be updated.
10063
     *
9522
     *
10064
     * @since Moodle 3.4
9523
     * @since Moodle 3.4
10065
     * @param stdClass $submission The most recent submission of the group.
9524
     * @param stdClass $submission The most recent submission of the group.
10066
     */
9525
     */
10067
    public function set_most_recent_team_submission($submission)
9526
    public function set_most_recent_team_submission($submission) {
10068
    {
-
 
10069
        $this->mostrecentteamsubmission = $submission;
9527
        $this->mostrecentteamsubmission = $submission;
10070
    }
9528
    }
Línea 10071... Línea 9529...
10071
 
9529
 
10072
    /**
9530
    /**
10073
     * Return array of valid grading allocation filters for the grading interface.
9531
     * Return array of valid grading allocation filters for the grading interface.
10074
     *
9532
     *
10075
     * @param boolean $export Export the list of filters for a template.
9533
     * @param boolean $export Export the list of filters for a template.
10076
     * @return array
9534
     * @return array
10077
     */
9535
     */
10078
    public function get_marking_allocation_filters($export = false)
-
 
10079
    {
9536
    public function get_marking_allocation_filters($export = false) {
10080
        $markingallocation = $this->get_instance()->markingworkflow &&
9537
        $markingallocation = $this->get_instance()->markingworkflow &&
10081
            $this->get_instance()->markingallocation &&
9538
            $this->get_instance()->markingallocation &&
10082
            has_capability('mod/assign:manageallocations', $this->context);
9539
            has_capability('mod/assign:manageallocations', $this->context);
10083
        // Get markers to use in drop lists.
9540
        // Get markers to use in drop lists.
Línea 10103... Línea 9560...
10103
                    'active' => ($allocationfilter == $option),
9560
                    'active' => ($allocationfilter == $option),
10104
                ]);
9561
                ]);
10105
            }
9562
            }
10106
            return $result;
9563
            return $result;
10107
        }
9564
        }
10108
        return $markingworkflowoptions;
9565
        return $markingallocationoptions;
10109
    }
9566
    }
Línea 10110... Línea 9567...
10110
 
9567
 
10111
    /**
9568
    /**
10112
     * Return array of valid grading workflow filters for the grading interface.
9569
     * Return array of valid grading workflow filters for the grading interface.
10113
     *
9570
     *
10114
     * @param boolean $export Export the list of filters for a template.
9571
     * @param boolean $export Export the list of filters for a template.
10115
     * @return array
9572
     * @return array
10116
     */
9573
     */
10117
    public function get_marking_workflow_filters($export = false)
-
 
10118
    {
9574
    public function get_marking_workflow_filters($export = false) {
10119
        $markingworkflow = $this->get_instance()->markingworkflow;
9575
        $markingworkflow = $this->get_instance()->markingworkflow;
10120
        // Get marking states to show in form.
9576
        // Get marking states to show in form.
10121
        $markingworkflowoptions = array();
9577
        $markingworkflowoptions = array();
10122
        if ($markingworkflow) {
9578
        if ($markingworkflow) {
Línea 10141... Línea 9597...
10141
    }
9597
    }
Línea 10142... Línea 9598...
10142
 
9598
 
10143
    /**
9599
    /**
10144
     * Return array of valid search filters for the grading interface.
9600
     * Return array of valid search filters for the grading interface.
-
 
9601
     *
10145
     *
9602
     * @param bool $grouped Whether to return the filters grouped or not.
10146
     * @return array
9603
     * @return array
10147
     */
9604
     */
10148
    public function get_filters()
-
 
10149
    {
9605
    public function get_filters(bool $grouped = false): array {
-
 
9606
        $groupedfilterkeys = [
10150
        $filterkeys = [
9607
            [
10151
            ASSIGN_FILTER_NOT_SUBMITTED,
9608
                ASSIGN_FILTER_NOT_SUBMITTED,
10152
            ASSIGN_FILTER_DRAFT,
9609
                ASSIGN_FILTER_DRAFT,
10153
            ASSIGN_FILTER_SUBMITTED,
9610
                ASSIGN_FILTER_SUBMITTED,
-
 
9611
                ASSIGN_FILTER_REQUIRE_GRADING,
-
 
9612
                ASSIGN_FILTER_GRADED,
-
 
9613
            ],
10154
            ASSIGN_FILTER_REQUIRE_GRADING,
9614
            [
-
 
9615
                ASSIGN_FILTER_GRANTED_EXTENSION,
10155
            ASSIGN_FILTER_GRANTED_EXTENSION
9616
            ],
Línea 10156... Línea 9617...
10156
        ];
9617
        ];
Línea 10157... Línea 9618...
10157
 
9618
 
10158
        $current = get_user_preferences('assign_filter', '');
9619
        $current = get_user_preferences('assign_filter', '');
10159
 
9620
 
-
 
9621
        $filters = [];
10160
        $filters = [];
9622
        // First is always "no filter" option.
10161
        // First is always "no filter" option.
9623
        $filters[0] = [
10162
        array_push($filters, [
9624
            [
-
 
9625
                'key' => ASSIGN_FILTER_NONE,
10163
            'key' => 'none',
9626
                'name' => get_string('filterall', 'assign'),
10164
            'name' => get_string('filternone', 'assign'),
9627
                'active' => ($current == ''),
-
 
9628
            ],
10165
            'active' => ($current == '')
9629
        ];
-
 
9630
 
10166
        ]);
9631
        foreach ($groupedfilterkeys as $group => $filterkeys) {
10167
 
9632
            foreach ($filterkeys as $key) {
10168
        foreach ($filterkeys as $key) {
9633
                $filters[$group] = $filters[$group] ?? [];
10169
            array_push($filters, [
9634
                $filters[$group][] = [
-
 
9635
                    'key' => $key,
10170
                'key' => $key,
9636
                    'name' => get_string('filter' . $key, 'assign'),
10171
                'name' => get_string('filter' . $key, 'assign'),
9637
                    'active' => ($current == $key),
-
 
9638
                ];
10172
                'active' => ($current == $key)
9639
            }
10173
            ]);
9640
        }
Línea 10174... Línea 9641...
10174
        }
9641
 
10175
        return $filters;
9642
        return $grouped ? $filters : array_merge(...$filters);
10176
    }
9643
    }
Línea 10183... Línea 9650...
10183
     * @param stdClass $instance
9650
     * @param stdClass $instance
10184
     * @param context $context
9651
     * @param context $context
10185
     *
9652
     *
10186
     * @return string
9653
     * @return string
10187
     */
9654
     */
10188
    protected function get_submissionstatement($adminconfig, $instance, $context)
9655
    protected function get_submissionstatement($adminconfig, $instance, $context) {
10189
    {
-
 
10190
        $submissionstatement = '';
9656
        $submissionstatement = '';
Línea 10191... Línea 9657...
10191
 
9657
 
10192
        if (!($context instanceof context)) {
9658
        if (!($context instanceof context)) {
10193
            return $submissionstatement;
9659
            return $submissionstatement;
Línea 10212... Línea 9678...
10212
                // a form element.
9678
                // a form element.
10213
                $options = array(
9679
                $options = array(
10214
                    'context' => $context,
9680
                    'context' => $context,
10215
                    'para'    => false
9681
                    'para'    => false
10216
                );
9682
                );
10217
                $submissionstatement = format_text(
-
 
10218
                    $adminconfig->submissionstatementteamsubmission,
9683
                $submissionstatement = format_text($adminconfig->submissionstatementteamsubmission,
10219
                    FORMAT_MOODLE,
9684
                    FORMAT_MOODLE, $options);
10220
                    $options
-
 
10221
                );
-
 
10222
            } else if (
-
 
10223
                !empty($adminconfig->submissionstatementteamsubmissionallsubmit) &&
9685
            } else if (!empty($adminconfig->submissionstatementteamsubmissionallsubmit) &&
10224
                $instance->requireallteammemberssubmit
9686
                $instance->requireallteammemberssubmit) {
10225
            ) {
-
 
10226
                // All team members must submit.
9687
                // All team members must submit.
10227
                // Format the submission statement before its sent. We turn off para because this is going within
9688
                // Format the submission statement before its sent. We turn off para because this is going within
10228
                // a form element.
9689
                // a form element.
10229
                $options = array(
9690
                $options = array(
10230
                    'context' => $context,
9691
                    'context' => $context,
10231
                    'para'    => false
9692
                    'para'    => false
10232
                );
9693
                );
10233
                $submissionstatement = format_text(
-
 
10234
                    $adminconfig->submissionstatementteamsubmissionallsubmit,
9694
                $submissionstatement = format_text($adminconfig->submissionstatementteamsubmissionallsubmit,
10235
                    FORMAT_MOODLE,
9695
                    FORMAT_MOODLE, $options);
10236
                    $options
-
 
10237
                );
-
 
10238
            }
9696
            }
10239
        }
9697
        }
Línea 10240... Línea 9698...
10240
 
9698
 
10241
        return $submissionstatement;
9699
        return $submissionstatement;
Línea 10245... Línea 9703...
10245
     * Check if time limit for assignment enabled and set up.
9703
     * Check if time limit for assignment enabled and set up.
10246
     *
9704
     *
10247
     * @param int|null $userid User ID. If null, use global user.
9705
     * @param int|null $userid User ID. If null, use global user.
10248
     * @return bool
9706
     * @return bool
10249
     */
9707
     */
10250
    public function is_time_limit_enabled(?int $userid = null): bool
9708
    public function is_time_limit_enabled(?int $userid = null): bool {
10251
    {
-
 
10252
        $instance = $this->get_instance($userid);
9709
        $instance = $this->get_instance($userid);
10253
        return get_config('assign', 'enabletimelimit') && !empty($instance->timelimit);
9710
        return get_config('assign', 'enabletimelimit') && !empty($instance->timelimit);
10254
    }
9711
    }
Línea 10255... Línea 9712...
10255
 
9712
 
Línea 10259... Línea 9716...
10259
     * @param int|null $userid User ID. If null, use global user.
9716
     * @param int|null $userid User ID. If null, use global user.
10260
     * @param int $groupid Group ID. If 0, use user id to determine group.
9717
     * @param int $groupid Group ID. If 0, use user id to determine group.
10261
     * @param int $attemptnumber Attempt number. If -1, check latest submission.
9718
     * @param int $attemptnumber Attempt number. If -1, check latest submission.
10262
     * @return bool
9719
     * @return bool
10263
     */
9720
     */
10264
    public function is_attempt_in_progress(?int $userid = null, int $groupid = 0, int $attemptnumber = -1): bool
9721
    public function is_attempt_in_progress(?int $userid = null, int $groupid = 0, int $attemptnumber = -1): bool {
10265
    {
-
 
10266
        if ($this->get_instance($userid)->teamsubmission) {
9722
        if ($this->get_instance($userid)->teamsubmission) {
10267
            $submission = $this->get_group_submission($userid, $groupid, false, $attemptnumber);
9723
            $submission = $this->get_group_submission($userid, $groupid, false, $attemptnumber);
10268
        } else {
9724
        } else {
10269
            $submission = $this->get_user_submission($userid, false, $attemptnumber);
9725
            $submission = $this->get_user_submission($userid, false, $attemptnumber);
10270
        }
9726
        }
Línea 10275... Línea 9731...
10275
            $timedattemptstarted = !empty($submission) && !empty($submission->timestarted);
9731
            $timedattemptstarted = !empty($submission) && !empty($submission->timestarted);
10276
        }
9732
        }
Línea 10277... Línea 9733...
10277
 
9733
 
10278
        return !empty($submission) && $submission->status !== ASSIGN_SUBMISSION_STATUS_SUBMITTED && $timedattemptstarted;
9734
        return !empty($submission) && $submission->status !== ASSIGN_SUBMISSION_STATUS_SUBMITTED && $timedattemptstarted;
-
 
9735
    }
-
 
9736
 
-
 
9737
    /**
-
 
9738
     * Is "Allow partial release of grades while marking anonymously" enabled?
-
 
9739
     *
-
 
9740
     * @return bool
-
 
9741
     */
-
 
9742
    public function is_marking_anonymous(): bool {
-
 
9743
        return isset($this->get_instance()->markinganonymous) && $this->get_instance()->markinganonymous;
10279
    }
9744
    }
Línea 10280... Línea 9745...
10280
}
9745
}
10281
 
9746
 
10282
/**
9747
/**
10283
 * Portfolio caller class for mod_assign.
9748
 * Portfolio caller class for mod_assign.
10284
 *
9749
 *
10285
 * @package   mod_assign
9750
 * @package   mod_assign
10286
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
9751
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
10287
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
9752
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
10288
 */
-
 
Línea 10289... Línea 9753...
10289
class assign_portfolio_caller extends portfolio_module_caller_base
9753
 */
10290
{
9754
class assign_portfolio_caller extends portfolio_module_caller_base {
Línea 10291... Línea 9755...
10291
 
9755
 
Línea 10311... Línea 9775...
10311
    protected $editor;
9775
    protected $editor;
Línea 10312... Línea 9776...
10312
 
9776
 
10313
    /**
9777
    /**
10314
     * Callback arg for a single file export.
9778
     * Callback arg for a single file export.
10315
     */
9779
     */
10316
    public static function expected_callbackargs()
-
 
10317
    {
9780
    public static function expected_callbackargs() {
10318
        return array(
9781
        return array(
10319
            'cmid' => true,
9782
            'cmid' => true,
10320
            'sid' => false,
9783
            'sid' => false,
10321
            'area' => false,
9784
            'area' => false,
Línea 10329... Línea 9792...
10329
    /**
9792
    /**
10330
     * The constructor.
9793
     * The constructor.
10331
     *
9794
     *
10332
     * @param array $callbackargs
9795
     * @param array $callbackargs
10333
     */
9796
     */
10334
    public function __construct($callbackargs)
9797
    public function __construct($callbackargs) {
10335
    {
-
 
10336
        parent::__construct($callbackargs);
9798
        parent::__construct($callbackargs);
10337
        $this->cm = get_coursemodule_from_id('assign', $this->cmid, 0, false, MUST_EXIST);
9799
        $this->cm = get_coursemodule_from_id('assign', $this->cmid, 0, false, MUST_EXIST);
10338
    }
9800
    }
Línea 10339... Línea 9801...
10339
 
9801
 
Línea 10345... Línea 9807...
10345
     * submissionid and filearea (to export all data attached to the given submission file area)
9807
     * submissionid and filearea (to export all data attached to the given submission file area)
10346
     * via callback arguments.
9808
     * via callback arguments.
10347
     *
9809
     *
10348
     * @throws     portfolio_caller_exception
9810
     * @throws     portfolio_caller_exception
10349
     */
9811
     */
10350
    public function load_data()
9812
    public function load_data() {
10351
    {
-
 
10352
        global $DB;
9813
        global $DB;
Línea 10353... Línea 9814...
10353
 
9814
 
Línea 10354... Línea 9815...
10354
        $context = context_module::instance($this->cmid);
9815
        $context = context_module::instance($this->cmid);
Línea 10378... Línea 9839...
10378
        }
9839
        }
Línea 10379... Línea 9840...
10379
 
9840
 
10380
        // Export either an area of files or a single file (see function for more detail).
9841
        // Export either an area of files or a single file (see function for more detail).
10381
        // The first arg is an id or null. If it is an id, the rest of the args are ignored.
9842
        // The first arg is an id or null. If it is an id, the rest of the args are ignored.
10382
        // If it is null, the rest of the args are used to load a list of files from get_areafiles.
9843
        // If it is null, the rest of the args are used to load a list of files from get_areafiles.
10383
        $this->set_file_and_format_data(
-
 
10384
            $this->fileid,
9844
        $this->set_file_and_format_data($this->fileid,
10385
            $context->id,
9845
                                        $context->id,
10386
            $this->component,
9846
                                        $this->component,
10387
            $this->area,
9847
                                        $this->area,
10388
            $this->sid,
9848
                                        $this->sid,
10389
            'timemodified',
9849
                                        'timemodified',
10390
            false
9850
                                        false);
10391
        );
9851
 
Línea 10392... Línea 9852...
10392
    }
9852
    }
10393
 
9853
 
10394
    /**
9854
    /**
10395
     * Prepares the package up before control is passed to the portfolio plugin.
9855
     * Prepares the package up before control is passed to the portfolio plugin.
10396
     *
9856
     *
10397
     * @throws portfolio_caller_exception
9857
     * @throws portfolio_caller_exception
10398
     * @return mixed
9858
     * @return mixed
10399
     */
-
 
Línea 10400... Línea 9859...
10400
    public function prepare_package()
9859
     */
10401
    {
9860
    public function prepare_package() {
10402
 
9861
 
10403
        if ($this->plugin && $this->editor) {
9862
        if ($this->plugin && $this->editor) {
Línea 10409... Línea 9868...
10409
 
9868
 
10410
            $text = $plugin->get_editor_text($this->editor, $this->sid);
9869
            $text = $plugin->get_editor_text($this->editor, $this->sid);
Línea 10411... Línea 9870...
10411
            $format = $plugin->get_editor_format($this->editor, $this->sid);
9870
            $format = $plugin->get_editor_format($this->editor, $this->sid);
10412
 
9871
 
10413
            $html = format_text($text, $format, $options);
-
 
10414
            $html = portfolio_rewrite_pluginfile_urls(
9872
            $html = format_text($text, $format, $options);
10415
                $html,
9873
            $html = portfolio_rewrite_pluginfile_urls($html,
10416
                $context->id,
9874
                                                      $context->id,
10417
                'mod_assign',
9875
                                                      'mod_assign',
10418
                $this->area,
9876
                                                      $this->area,
10419
                $this->sid,
-
 
Línea 10420... Línea 9877...
10420
                $this->exporter->get('format')
9877
                                                      $this->sid,
10421
            );
9878
                                                      $this->exporter->get('format'));
10422
 
9879
 
10423
            $exporterclass = $this->exporter->get('formatclass');
9880
            $exporterclass = $this->exporter->get('formatclass');
Línea 10428... Línea 9885...
10428
                    }
9885
                    }
10429
                }
9886
                }
10430
                return $this->exporter->write_new_file($html, 'assignment.html', !empty($files));
9887
                return $this->exporter->write_new_file($html, 'assignment.html', !empty($files));
10431
            } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
9888
            } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
10432
                $leapwriter = $this->exporter->get('format')->leap2a_writer();
9889
                $leapwriter = $this->exporter->get('format')->leap2a_writer();
10433
                $entry = new portfolio_format_leap2a_entry(
9890
                $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid,
10434
                    $this->area . $this->cmid,
-
 
10435
                    $context->get_context_name(),
9891
                                                           $context->get_context_name(),
10436
                    'resource',
9892
                                                           'resource',
10437
                    $html
9893
                                                           $html);
10438
                );
-
 
Línea 10439... Línea 9894...
10439
 
9894
 
10440
                $entry->add_category('web', 'resource_type');
9895
                $entry->add_category('web', 'resource_type');
10441
                $entry->author = $this->user;
9896
                $entry->author = $this->user;
10442
                $leapwriter->add_entry($entry);
9897
                $leapwriter->add_entry($entry);
10443
                if ($files = $this->exporter->get('caller')->get('multifiles')) {
9898
                if ($files = $this->exporter->get('caller')->get('multifiles')) {
10444
                    $leapwriter->link_files($entry, $files, $this->area . $this->cmid . 'file');
9899
                    $leapwriter->link_files($entry, $files, $this->area . $this->cmid . 'file');
10445
                    foreach ($files as $file) {
9900
                    foreach ($files as $file) {
10446
                        $this->exporter->copy_existing_file($file);
9901
                        $this->exporter->copy_existing_file($file);
10447
                    }
9902
                    }
10448
                }
9903
                }
10449
                return $this->exporter->write_new_file(
-
 
10450
                    $leapwriter->to_xml(),
9904
                return $this->exporter->write_new_file($leapwriter->to_xml(),
10451
                    $this->exporter->get('format')->manifest_name(),
9905
                                                       $this->exporter->get('format')->manifest_name(),
10452
                    true
-
 
10453
                );
9906
                                                       true);
10454
            } else {
9907
            } else {
10455
                debugging('invalid format class: ' . $this->exporter->get('formatclass'));
9908
                debugging('invalid format class: ' . $this->exporter->get('formatclass'));
-
 
9909
            }
10456
            }
9910
 
Línea 10457... Línea 9911...
10457
        }
9911
        }
10458
 
9912
 
10459
        if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
9913
        if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
10460
            $leapwriter = $this->exporter->get('format')->leap2a_writer();
9914
            $leapwriter = $this->exporter->get('format')->leap2a_writer();
10461
            $files = array();
9915
            $files = array();
10462
            if ($this->singlefile) {
9916
            if ($this->singlefile) {
10463
                $files[] = $this->singlefile;
9917
                $files[] = $this->singlefile;
10464
            } else if ($this->multifiles) {
9918
            } else if ($this->multifiles) {
10465
                $files = $this->multifiles;
9919
                $files = $this->multifiles;
10466
            } else {
-
 
10467
                throw new portfolio_caller_exception(
9920
            } else {
10468
                    'invalidpreparepackagefile',
9921
                throw new portfolio_caller_exception('invalidpreparepackagefile',
10469
                    'portfolio',
-
 
10470
                    $this->get_return_url()
9922
                                                     'portfolio',
Línea 10471... Línea 9923...
10471
                );
9923
                                                     $this->get_return_url());
10472
            }
9924
            }
10473
 
9925
 
Línea 10482... Línea 9934...
10482
            if (count($files) > 1) {
9934
            if (count($files) > 1) {
10483
                $baseid = 'assign' . $this->cmid . $this->area;
9935
                $baseid = 'assign' . $this->cmid . $this->area;
10484
                $context = context_module::instance($this->cmid);
9936
                $context = context_module::instance($this->cmid);
Línea 10485... Línea 9937...
10485
 
9937
 
10486
                // If we have multiple files, they should be grouped together into a folder.
9938
                // If we have multiple files, they should be grouped together into a folder.
10487
                $entry = new portfolio_format_leap2a_entry(
-
 
10488
                    $baseid . 'group',
9939
                $entry = new portfolio_format_leap2a_entry($baseid . 'group',
10489
                    $context->get_context_name(),
9940
                                                           $context->get_context_name(),
10490
                    'selection'
-
 
10491
                );
9941
                                                           'selection');
10492
                $leapwriter->add_entry($entry);
9942
                $leapwriter->add_entry($entry);
10493
                $leapwriter->make_selection($entry, $entryids, 'Folder');
9943
                $leapwriter->make_selection($entry, $entryids, 'Folder');
10494
            }
9944
            }
10495
            return $this->exporter->write_new_file(
-
 
10496
                $leapwriter->to_xml(),
9945
            return $this->exporter->write_new_file($leapwriter->to_xml(),
10497
                $this->exporter->get('format')->manifest_name(),
9946
                                                   $this->exporter->get('format')->manifest_name(),
10498
                true
-
 
10499
            );
9947
                                                   true);
10500
        }
9948
        }
10501
        return $this->prepare_package_file();
9949
        return $this->prepare_package_file();
Línea 10502... Línea 9950...
10502
    }
9950
    }
10503
 
9951
 
10504
    /**
9952
    /**
10505
     * Fetch the plugin by its type.
9953
     * Fetch the plugin by its type.
10506
     *
9954
     *
10507
     * @return assign_submission_plugin
9955
     * @return assign_submission_plugin
10508
     */
-
 
10509
    protected function get_submission_plugin()
9956
     */
10510
    {
9957
    protected function get_submission_plugin() {
10511
        global $CFG;
9958
        global $CFG;
10512
        if (!$this->plugin || !$this->cmid) {
9959
        if (!$this->plugin || !$this->cmid) {
Línea 10525... Línea 9972...
10525
     * Calculate a sha1 has of either a single file or a list
9972
     * Calculate a sha1 has of either a single file or a list
10526
     * of files based on the data set by load_data.
9973
     * of files based on the data set by load_data.
10527
     *
9974
     *
10528
     * @return string
9975
     * @return string
10529
     */
9976
     */
10530
    public function get_sha1()
9977
    public function get_sha1() {
10531
    {
-
 
Línea 10532... Línea 9978...
10532
 
9978
 
10533
        if ($this->plugin && $this->editor) {
9979
        if ($this->plugin && $this->editor) {
10534
            $plugin = $this->get_submission_plugin();
9980
            $plugin = $this->get_submission_plugin();
10535
            $options = portfolio_format_text_options();
9981
            $options = portfolio_format_text_options();
Línea 10536... Línea -...
10536
            $options->context = context_module::instance($this->cmid);
-
 
10537
 
9982
            $options->context = context_module::instance($this->cmid);
10538
            $text = format_text(
9983
 
10539
                $plugin->get_editor_text($this->editor, $this->sid),
9984
            $text = format_text($plugin->get_editor_text($this->editor, $this->sid),
10540
                $plugin->get_editor_format($this->editor, $this->sid),
-
 
10541
                $options
9985
                                $plugin->get_editor_format($this->editor, $this->sid),
10542
            );
9986
                                $options);
10543
            $textsha1 = sha1($text);
9987
            $textsha1 = sha1($text);
10544
            $filesha1 = '';
9988
            $filesha1 = '';
10545
            try {
9989
            try {
Línea 10556... Línea 10000...
10556
     * Calculate the time to transfer either a single file or a list
10000
     * Calculate the time to transfer either a single file or a list
10557
     * of files based on the data set by load_data.
10001
     * of files based on the data set by load_data.
10558
     *
10002
     *
10559
     * @return int
10003
     * @return int
10560
     */
10004
     */
10561
    public function expected_time()
10005
    public function expected_time() {
10562
    {
-
 
10563
        return $this->expected_time_file();
10006
        return $this->expected_time_file();
10564
    }
10007
    }
Línea 10565... Línea 10008...
10565
 
10008
 
10566
    /**
10009
    /**
10567
     * Checking the permissions.
10010
     * Checking the permissions.
10568
     *
10011
     *
10569
     * @return bool
10012
     * @return bool
10570
     */
10013
     */
10571
    public function check_permissions()
-
 
10572
    {
10014
    public function check_permissions() {
10573
        $context = context_module::instance($this->cmid);
10015
        $context = context_module::instance($this->cmid);
10574
        return has_capability('mod/assign:exportownsubmission', $context);
10016
        return has_capability('mod/assign:exportownsubmission', $context);
Línea 10575... Línea 10017...
10575
    }
10017
    }
10576
 
10018
 
10577
    /**
10019
    /**
10578
     * Display a module name.
10020
     * Display a module name.
10579
     *
10021
     *
10580
     * @return string
10022
     * @return string
10581
     */
-
 
10582
    public static function display_name()
10023
     */
10583
    {
10024
    public static function display_name() {
Línea 10584... Línea 10025...
10584
        return get_string('modulename', 'assign');
10025
        return get_string('modulename', 'assign');
10585
    }
10026
    }
10586
 
10027
 
10587
    /**
10028
    /**
10588
     * Return array of formats supported by this portfolio call back.
10029
     * Return array of formats supported by this portfolio call back.
10589
     *
10030
     *
10590
     * @return array
-
 
10591
     */
10031
     * @return array
10592
    public static function base_supported_formats()
10032
     */
10593
    {
10033
    public static function base_supported_formats() {
Línea 10594... Línea 10034...
10594
        return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
10034
        return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
Línea 10600... Línea 10040...
10600
 *
10040
 *
10601
 * @param int $courseid The course ID.
10041
 * @param int $courseid The course ID.
10602
 * @param int $groupid The group id if it is known
10042
 * @param int $groupid The group id if it is known
10603
 * @return void
10043
 * @return void
10604
 */
10044
 */
10605
function assign_process_group_deleted_in_course($courseid, $groupid = null)
10045
function assign_process_group_deleted_in_course($courseid, $groupid = null) {
10606
{
-
 
10607
    global $DB;
10046
    global $DB;
Línea 10608... Línea 10047...
10608
 
10047
 
10609
    $params = array('courseid' => $courseid);
10048
    $params = array('courseid' => $courseid);
10610
    if ($groupid) {
10049
    if ($groupid) {
Línea 10642... Línea 10081...
10642
 * @param int $id of the override
10081
 * @param int $id of the override
10643
 * @param string $move direction of move
10082
 * @param string $move direction of move
10644
 * @param int $assignid of the assignment
10083
 * @param int $assignid of the assignment
10645
 * @return bool success of operation
10084
 * @return bool success of operation
10646
 */
10085
 */
10647
function move_group_override($id, $move, $assignid)
10086
function move_group_override($id, $move, $assignid) {
10648
{
-
 
10649
    global $DB;
10087
    global $DB;
Línea 10650... Línea 10088...
10650
 
10088
 
10651
    // Get the override object.
10089
    // Get the override object.
10652
    if (!$override = $DB->get_record('assign_overrides', ['id' => $id, 'assignid' => $assignid], 'id, sortorder, groupid')) {
10090
    if (!$override = $DB->get_record('assign_overrides', ['id' => $id, 'assignid' => $assignid], 'id, sortorder, groupid')) {
10653
        return false;
10091
        return false;
10654
    }
10092
    }
10655
    // Count the number of group overrides.
10093
    // Count the number of group overrides.
Línea 10656... Línea 10094...
10656
    $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assignid));
10094
    $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assignid));
10657
 
10095
 
10658
    // Calculate the new sortorder.
10096
    // Calculate the new sortorder.
10659
    if (($move == 'up') and ($override->sortorder > 1)) {
10097
    if ( ($move == 'up') and ($override->sortorder > 1)) {
10660
        $neworder = $override->sortorder - 1;
10098
        $neworder = $override->sortorder - 1;
10661
    } else if (($move == 'down') and ($override->sortorder < $overridecountgroup)) {
10099
    } else if (($move == 'down') and ($override->sortorder < $overridecountgroup)) {
10662
        $neworder = $override->sortorder + 1;
10100
        $neworder = $override->sortorder + 1;
Línea 10689... Línea 10127...
10689
/**
10127
/**
10690
 * Reorder the overrides starting at the override at the given startorder.
10128
 * Reorder the overrides starting at the override at the given startorder.
10691
 *
10129
 *
10692
 * @param int $assignid of the assigment
10130
 * @param int $assignid of the assigment
10693
 */
10131
 */
10694
function reorder_group_overrides($assignid)
10132
function reorder_group_overrides($assignid) {
10695
{
-
 
10696
    global $DB;
10133
    global $DB;
Línea 10697... Línea 10134...
10697
 
10134
 
10698
    $i = 1;
10135
    $i = 1;
10699
    if ($overrides = $DB->get_records('assign_overrides', array('userid' => null, 'assignid' => $assignid), 'sortorder ASC')) {
10136
    if ($overrides = $DB->get_records('assign_overrides', array('userid' => null, 'assignid' => $assignid), 'sortorder ASC')) {
Línea 10718... Línea 10155...
10718
 
10155
 
10719
/**
10156
/**
10720
 * Get the information about the standard assign JavaScript module.
10157
 * Get the information about the standard assign JavaScript module.
10721
 * @return array a standard jsmodule structure.
10158
 * @return array a standard jsmodule structure.
10722
 */
10159
 */
10723
function assign_get_js_module()
-
 
10724
{
10160
function assign_get_js_module() {
10725
    return array(
10161
    return array(
10726
        'name' => 'mod_assign',
10162
        'name' => 'mod_assign',
10727
        'fullpath' => '/mod/assign/module.js',
10163
        'fullpath' => '/mod/assign/module.js',
10728
    );
10164
    );