Proyectos de Subversion Moodle

Rev

Rev 1 | Rev 1255 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1254
Línea 107... Línea 107...
107
 *
107
 *
108
 * @package   mod_assign
108
 * @package   mod_assign
109
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
109
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
110
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
110
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
111
 */
111
 */
112
class assign {
112
class assign
-
 
113
{
Línea 113... Línea 114...
113
 
114
 
114
    /** @var stdClass the assignment record that contains the global settings for this assign instance */
115
    /** @var stdClass the assignment record that contains the global settings for this assign instance */
Línea 115... Línea 116...
115
    private $instance;
116
    private $instance;
Línea 213... Línea 214...
213
     * @param mixed $coursemodule the current course module if it was already loaded,
214
     * @param mixed $coursemodule the current course module if it was already loaded,
214
     *                            otherwise this class will load one from the context as required.
215
     *                            otherwise this class will load one from the context as required.
215
     * @param mixed $course the current course  if it was already loaded,
216
     * @param mixed $course the current course  if it was already loaded,
216
     *                      otherwise this class will load one from the context as required.
217
     *                      otherwise this class will load one from the context as required.
217
     */
218
     */
218
    public function __construct($coursemodulecontext, $coursemodule, $course) {
219
    public function __construct($coursemodulecontext, $coursemodule, $course)
-
 
220
    {
219
        $this->context = $coursemodulecontext;
221
        $this->context = $coursemodulecontext;
220
        $this->course = $course;
222
        $this->course = $course;
Línea 221... Línea 223...
221
 
223
 
222
        // Ensure that $this->coursemodule is a cm_info object (or null).
224
        // Ensure that $this->coursemodule is a cm_info object (or null).
Línea 238... Línea 240...
238
     * @param string $action The action for the current page
240
     * @param string $action The action for the current page
239
     * @param array $params An array of name value pairs which form the parameters
241
     * @param array $params An array of name value pairs which form the parameters
240
     *                      to return to the current page.
242
     *                      to return to the current page.
241
     * @return void
243
     * @return void
242
     */
244
     */
243
    public function register_return_link($action, $params) {
245
    public function register_return_link($action, $params)
-
 
246
    {
244
        global $PAGE;
247
        global $PAGE;
245
        $params['action'] = $action;
248
        $params['action'] = $action;
246
        $cm = $this->get_course_module();
249
        $cm = $this->get_course_module();
247
        if ($cm) {
250
        if ($cm) {
248
            $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $cm->id));
251
            $currenturl = new moodle_url('/mod/assign/view.php', array('id' => $cm->id));
Línea 257... Línea 260...
257
    /**
260
    /**
258
     * Return an action that can be used to get back to the current page.
261
     * Return an action that can be used to get back to the current page.
259
     *
262
     *
260
     * @return string action
263
     * @return string action
261
     */
264
     */
262
    public function get_return_action() {
265
    public function get_return_action()
-
 
266
    {
263
        global $PAGE;
267
        global $PAGE;
Línea 264... Línea 268...
264
 
268
 
265
        // Web services don't set a URL, we should avoid debugging when ussing the url object.
269
        // Web services don't set a URL, we should avoid debugging when ussing the url object.
266
        if (!WS_SERVER) {
270
        if (!WS_SERVER) {
Línea 276... Línea 280...
276
    /**
280
    /**
277
     * Based on the current assignment settings should we display the intro.
281
     * Based on the current assignment settings should we display the intro.
278
     *
282
     *
279
     * @return bool showintro
283
     * @return bool showintro
280
     */
284
     */
281
    public function show_intro() {
285
    public function show_intro()
-
 
286
    {
-
 
287
        if (
282
        if ($this->get_instance()->alwaysshowdescription ||
288
            $this->get_instance()->alwaysshowdescription ||
283
                time() > $this->get_instance()->allowsubmissionsfromdate) {
289
            time() > $this->get_instance()->allowsubmissionsfromdate
-
 
290
        ) {
284
            return true;
291
            return true;
285
        }
292
        }
286
        return false;
293
        return false;
287
    }
294
    }
Línea 288... Línea 295...
288
 
295
 
289
    /**
296
    /**
290
     * Return a list of parameters that can be used to get back to the current page.
297
     * Return a list of parameters that can be used to get back to the current page.
291
     *
298
     *
292
     * @return array params
299
     * @return array params
293
     */
300
     */
-
 
301
    public function get_return_params()
294
    public function get_return_params() {
302
    {
Línea 295... Línea 303...
295
        global $PAGE;
303
        global $PAGE;
296
 
304
 
297
        $params = array();
305
        $params = array();
Línea 306... Línea 314...
306
    /**
314
    /**
307
     * Set the submitted form data.
315
     * Set the submitted form data.
308
     *
316
     *
309
     * @param stdClass $data The form data (instance)
317
     * @param stdClass $data The form data (instance)
310
     */
318
     */
311
    public function set_instance(stdClass $data) {
319
    public function set_instance(stdClass $data)
-
 
320
    {
312
        $this->instance = $data;
321
        $this->instance = $data;
313
    }
322
    }
Línea 314... Línea 323...
314
 
323
 
315
    /**
324
    /**
316
     * Set the context.
325
     * Set the context.
317
     *
326
     *
318
     * @param context $context The new context
327
     * @param context $context The new context
319
     */
328
     */
-
 
329
    public function set_context(context $context)
320
    public function set_context(context $context) {
330
    {
321
        $this->context = $context;
331
        $this->context = $context;
Línea 322... Línea 332...
322
    }
332
    }
323
 
333
 
324
    /**
334
    /**
325
     * Set the course data.
335
     * Set the course data.
326
     *
336
     *
327
     * @param stdClass $course The course data
337
     * @param stdClass $course The course data
-
 
338
     */
328
     */
339
    public function set_course(stdClass $course)
329
    public function set_course(stdClass $course) {
340
    {
Línea 330... Línea 341...
330
        $this->course = $course;
341
        $this->course = $course;
331
    }
342
    }
332
 
343
 
333
    /**
344
    /**
334
     * Set error message.
345
     * Set error message.
335
     *
346
     *
-
 
347
     * @param string $message The error message
336
     * @param string $message The error message
348
     */
337
     */
349
    protected function set_error_message(string $message)
Línea 338... Línea 350...
338
    protected function set_error_message(string $message) {
350
    {
339
        $this->errors[] = $message;
351
        $this->errors[] = $message;
340
    }
352
    }
341
 
353
 
342
    /**
354
    /**
343
     * Get error messages.
355
     * Get error messages.
-
 
356
     *
344
     *
357
     * @return array The array of error messages
345
     * @return array The array of error messages
358
     */
Línea 346... Línea 359...
346
     */
359
    protected function get_error_messages(): array
347
    protected function get_error_messages(): array {
360
    {
348
        return $this->errors;
361
        return $this->errors;
349
    }
362
    }
350
 
363
 
351
    /**
364
    /**
-
 
365
     * Get list of feedback plugins installed.
352
     * Get list of feedback plugins installed.
366
     *
353
     *
367
     * @return array
Línea 354... Línea 368...
354
     * @return array
368
     */
355
     */
369
    public function get_feedback_plugins()
356
    public function get_feedback_plugins() {
370
    {
357
        return $this->feedbackplugins;
371
        return $this->feedbackplugins;
358
    }
372
    }
359
 
373
 
-
 
374
    /**
360
    /**
375
     * Get list of submission plugins installed.
361
     * Get list of submission plugins installed.
376
     *
Línea 362... Línea 377...
362
     *
377
     * @return array
363
     * @return array
378
     */
364
     */
379
    public function get_submission_plugins()
365
    public function get_submission_plugins() {
380
    {
366
        return $this->submissionplugins;
381
        return $this->submissionplugins;
367
    }
382
    }
-
 
383
 
368
 
384
    /**
369
    /**
385
     * Is blind marking enabled and reveal identities not set yet?
Línea 370... Línea 386...
370
     * Is blind marking enabled and reveal identities not set yet?
386
     *
371
     *
387
     * @return bool
Línea 381... Línea 397...
381
     * This just checks the assignment settings. Remember to check
397
     * This just checks the assignment settings. Remember to check
382
     * the user has the 'showhiddengrader' capability too
398
     * the user has the 'showhiddengrader' capability too
383
     *
399
     *
384
     * @return bool
400
     * @return bool
385
     */
401
     */
386
    public function is_hidden_grader() {
402
    public function is_hidden_grader()
-
 
403
    {
387
        return $this->get_instance()->hidegrader;
404
        return $this->get_instance()->hidegrader;
388
    }
405
    }
Línea 389... Línea 406...
389
 
406
 
390
    /**
407
    /**
391
     * Does an assignment have submission(s) or grade(s) already?
408
     * Does an assignment have submission(s) or grade(s) already?
392
     *
409
     *
393
     * @return bool
410
     * @return bool
394
     */
411
     */
-
 
412
    public function has_submissions_or_grades()
395
    public function has_submissions_or_grades() {
413
    {
396
        $allgrades = $this->count_grades();
414
        $allgrades = $this->count_grades();
397
        $allsubmissions = $this->count_submissions();
415
        $allsubmissions = $this->count_submissions();
398
        if (($allgrades == 0) && ($allsubmissions == 0)) {
416
        if (($allgrades == 0) && ($allsubmissions == 0)) {
399
            return false;
417
            return false;
Línea 406... Línea 424...
406
     *
424
     *
407
     * @param string $subtype assignsubmission | assignfeedback
425
     * @param string $subtype assignsubmission | assignfeedback
408
     * @param string $type
426
     * @param string $type
409
     * @return mixed assign_plugin|null
427
     * @return mixed assign_plugin|null
410
     */
428
     */
411
    public function get_plugin_by_type($subtype, $type) {
429
    public function get_plugin_by_type($subtype, $type)
-
 
430
    {
412
        $shortsubtype = substr($subtype, strlen('assign'));
431
        $shortsubtype = substr($subtype, strlen('assign'));
413
        $name = $shortsubtype . 'plugins';
432
        $name = $shortsubtype . 'plugins';
414
        if ($name != 'feedbackplugins' && $name != 'submissionplugins') {
433
        if ($name != 'feedbackplugins' && $name != 'submissionplugins') {
415
            return null;
434
            return null;
416
        }
435
        }
Línea 427... Línea 446...
427
     * Get a feedback plugin by type.
446
     * Get a feedback plugin by type.
428
     *
447
     *
429
     * @param string $type - The type of plugin e.g comments
448
     * @param string $type - The type of plugin e.g comments
430
     * @return mixed assign_feedback_plugin|null
449
     * @return mixed assign_feedback_plugin|null
431
     */
450
     */
432
    public function get_feedback_plugin_by_type($type) {
451
    public function get_feedback_plugin_by_type($type)
-
 
452
    {
433
        return $this->get_plugin_by_type('assignfeedback', $type);
453
        return $this->get_plugin_by_type('assignfeedback', $type);
434
    }
454
    }
Línea 435... Línea 455...
435
 
455
 
436
    /**
456
    /**
437
     * Get a submission plugin by type.
457
     * Get a submission plugin by type.
438
     *
458
     *
439
     * @param string $type - The type of plugin e.g comments
459
     * @param string $type - The type of plugin e.g comments
440
     * @return mixed assign_submission_plugin|null
460
     * @return mixed assign_submission_plugin|null
441
     */
461
     */
-
 
462
    public function get_submission_plugin_by_type($type)
442
    public function get_submission_plugin_by_type($type) {
463
    {
443
        return $this->get_plugin_by_type('assignsubmission', $type);
464
        return $this->get_plugin_by_type('assignsubmission', $type);
Línea 444... Línea 465...
444
    }
465
    }
445
 
466
 
446
    /**
467
    /**
447
     * Load the plugins from the sub folders under subtype.
468
     * Load the plugins from the sub folders under subtype.
448
     *
469
     *
449
     * @param string $subtype - either submission or feedback
470
     * @param string $subtype - either submission or feedback
450
     * @return array - The sorted list of plugins
471
     * @return array - The sorted list of plugins
-
 
472
     */
451
     */
473
    public function load_plugins($subtype)
452
    public function load_plugins($subtype) {
474
    {
Línea 453... Línea 475...
453
        global $CFG;
475
        global $CFG;
Línea 465... Línea 487...
465
                $plugin = new $pluginclass($this, $name);
487
                $plugin = new $pluginclass($this, $name);
Línea 466... Línea 488...
466
 
488
 
467
                if ($plugin instanceof assign_plugin) {
489
                if ($plugin instanceof assign_plugin) {
468
                    $idx = $plugin->get_sort_order();
490
                    $idx = $plugin->get_sort_order();
469
                    while (array_key_exists($idx, $result)) {
491
                    while (array_key_exists($idx, $result)) {
470
                        $idx +=1;
492
                        $idx += 1;
471
                    }
493
                    }
472
                    $result[$idx] = $plugin;
494
                    $result[$idx] = $plugin;
473
                }
495
                }
474
            }
496
            }
Línea 485... Línea 507...
485
     *
507
     *
486
     * @param string $action The current action if any.
508
     * @param string $action The current action if any.
487
     * @param array $args Optional arguments to pass to the view (instead of getting them from GET and POST).
509
     * @param array $args Optional arguments to pass to the view (instead of getting them from GET and POST).
488
     * @return string - The page output.
510
     * @return string - The page output.
489
     */
511
     */
490
    public function view($action='', $args = array()) {
512
    public function view($action = '', $args = array())
-
 
513
    {
491
        global $PAGE;
514
        global $PAGE;
Línea 492... Línea 515...
492
 
515
 
493
        $o = '';
516
        $o = '';
494
        $mform = null;
517
        $mform = null;
Línea 622... Línea 645...
622
            $this->process_reveal_identities();
645
            $this->process_reveal_identities();
623
            $action = 'redirect';
646
            $action = 'redirect';
624
            $nextpageparams['action'] = 'grading';
647
            $nextpageparams['action'] = 'grading';
625
        }
648
        }
Línea -... Línea 649...
-
 
649
 
626
 
650
        $returnparams = array(
627
        $returnparams = array('rownum'=>optional_param('rownum', 0, PARAM_INT),
651
            'rownum' => optional_param('rownum', 0, PARAM_INT),
-
 
652
            'useridlistid' => optional_param('useridlistid', $this->get_useridlist_key_id(), PARAM_ALPHANUM)
628
                              'useridlistid' => optional_param('useridlistid', $this->get_useridlist_key_id(), PARAM_ALPHANUM));
653
        );
Línea 629... Línea 654...
629
        $this->register_return_link($action, $returnparams);
654
        $this->register_return_link($action, $returnparams);
630
 
655
 
631
        // Include any page action as part of the body tag CSS id.
656
        // Include any page action as part of the body tag CSS id.
Línea 678... Línea 703...
678
            $PAGE->add_body_class('limitedwidth');
703
            $PAGE->add_body_class('limitedwidth');
679
            $o .= $this->view_remove_submission_confirm();
704
            $o .= $this->view_remove_submission_confirm();
680
        } else if ($action == 'plugingradingbatchoperation') {
705
        } else if ($action == 'plugingradingbatchoperation') {
681
            $o .= $this->view_plugin_grading_batch_operation($mform);
706
            $o .= $this->view_plugin_grading_batch_operation($mform);
682
        } else if ($action == 'viewpluginpage') {
707
        } else if ($action == 'viewpluginpage') {
683
             $o .= $this->view_plugin_page();
708
            $o .= $this->view_plugin_page();
684
        } else if ($action == 'viewcourseindex') {
709
        } else if ($action == 'viewcourseindex') {
685
             $o .= $this->view_course_index();
710
            $o .= $this->view_course_index();
686
        } else if ($action == 'viewbatchsetmarkingworkflowstate') {
711
        } else if ($action == 'viewbatchsetmarkingworkflowstate') {
687
             $o .= $this->view_batch_set_workflow_state($mform);
712
            $o .= $this->view_batch_set_workflow_state($mform);
688
        } else if ($action == 'viewbatchmarkingallocation') {
713
        } else if ($action == 'viewbatchmarkingallocation') {
689
            $o .= $this->view_batch_markingallocation($mform);
714
            $o .= $this->view_batch_markingallocation($mform);
690
        } else if ($action == 'viewsubmitforgradingerror') {
715
        } else if ($action == 'viewsubmitforgradingerror') {
691
            $o .= $this->view_error_page(get_string('submitforgrading', 'assign'), $notices);
716
            $o .= $this->view_error_page(get_string('submitforgrading', 'assign'), $notices);
692
        } else if ($action == 'fixrescalednullgrades') {
717
        } else if ($action == 'fixrescalednullgrades') {
Línea 705... Línea 730...
705
     * @param stdClass $formdata The data submitted from the form
730
     * @param stdClass $formdata The data submitted from the form
706
     * @param bool $callplugins This is used to skip the plugin code
731
     * @param bool $callplugins This is used to skip the plugin code
707
     *             when upgrading an old assignment to a new one (the plugins get called manually)
732
     *             when upgrading an old assignment to a new one (the plugins get called manually)
708
     * @return mixed false if an error occurs or the int id of the new instance
733
     * @return mixed false if an error occurs or the int id of the new instance
709
     */
734
     */
710
    public function add_instance(stdClass $formdata, $callplugins) {
735
    public function add_instance(stdClass $formdata, $callplugins)
-
 
736
    {
711
        global $DB;
737
        global $DB;
712
        $adminconfig = $this->get_admin_config();
738
        $adminconfig = $this->get_admin_config();
Línea 713... Línea 739...
713
 
739
 
Línea 778... Línea 804...
778
            } else {
804
            } else {
779
                $update->markinganonymous = $formdata->markinganonymous;
805
                $update->markinganonymous = $formdata->markinganonymous;
780
            }
806
            }
781
        }
807
        }
782
        $returnid = $DB->insert_record('assign', $update);
808
        $returnid = $DB->insert_record('assign', $update);
783
        $this->instance = $DB->get_record('assign', array('id'=>$returnid), '*', MUST_EXIST);
809
        $this->instance = $DB->get_record('assign', array('id' => $returnid), '*', MUST_EXIST);
784
        // Cache the course record.
810
        // Cache the course record.
785
        $this->course = $DB->get_record('course', array('id'=>$formdata->course), '*', MUST_EXIST);
811
        $this->course = $DB->get_record('course', array('id' => $formdata->course), '*', MUST_EXIST);
Línea 786... Línea 812...
786
 
812
 
787
        $this->save_intro_draft_files($formdata);
813
        $this->save_intro_draft_files($formdata);
Línea 788... Línea 814...
788
        $this->save_editor_draft_files($formdata);
814
        $this->save_editor_draft_files($formdata);
Línea 804... Línea 830...
804
 
830
 
805
            // In the case of upgrades the coursemodule has not been set,
831
            // In the case of upgrades the coursemodule has not been set,
806
            // so we need to wait before calling these two.
832
            // so we need to wait before calling these two.
807
            $this->update_calendar($formdata->coursemodule);
833
            $this->update_calendar($formdata->coursemodule);
808
            if (!empty($formdata->completionexpected)) {
834
            if (!empty($formdata->completionexpected)) {
-
 
835
                \core_completion\api::update_completion_date_event(
-
 
836
                    $formdata->coursemodule,
-
 
837
                    'assign',
809
                \core_completion\api::update_completion_date_event($formdata->coursemodule, 'assign', $this->instance,
838
                    $this->instance,
-
 
839
                    $formdata->completionexpected
810
                        $formdata->completionexpected);
840
                );
811
            }
841
            }
812
            $this->update_gradebook(false, $formdata->coursemodule);
-
 
813
 
842
            $this->update_gradebook(false, $formdata->coursemodule);
Línea 814... Línea 843...
814
        }
843
        }
815
 
844
 
816
        $update = new stdClass();
845
        $update = new stdClass();
817
        $update->id = $this->get_instance()->id;
846
        $update->id = $this->get_instance()->id;
Línea 818... Línea 847...
818
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1: 0;
847
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1 : 0;
819
        $DB->update_record('assign', $update);
848
        $DB->update_record('assign', $update);
Línea 820... Línea 849...
820
 
849
 
821
        return $returnid;
850
        return $returnid;
822
    }
851
    }
823
 
852
 
824
    /**
853
    /**
825
     * Delete all grades from the gradebook for this assignment.
854
     * Delete all grades from the gradebook for this assignment.
-
 
855
     *
826
     *
856
     * @return bool
Línea 827... Línea 857...
827
     * @return bool
857
     */
-
 
858
    protected function delete_grades()
828
     */
859
    {
829
    protected function delete_grades() {
860
        global $CFG;
830
        global $CFG;
861
 
831
 
862
        $result = grade_update(
832
        $result = grade_update('mod/assign',
863
            'mod/assign',
833
                               $this->get_course()->id,
864
            $this->get_course()->id,
834
                               'mod',
865
            'mod',
-
 
866
            'assign',
835
                               'assign',
867
            $this->get_instance()->id,
836
                               $this->get_instance()->id,
868
            0,
Línea 837... Línea 869...
837
                               0,
869
            null,
838
                               null,
870
            array('deleted' => 1)
839
                               array('deleted'=>1));
871
        );
840
        return $result == GRADE_UPDATE_OK;
872
        return $result == GRADE_UPDATE_OK;
841
    }
873
    }
842
 
874
 
-
 
875
    /**
843
    /**
876
     * Delete this instance from the database.
844
     * Delete this instance from the database.
877
     *
Línea 845... Línea 878...
845
     *
878
     * @return bool false if an error occurs
846
     * @return bool false if an error occurs
879
     */
Línea 862... Línea 895...
862
            }
895
            }
863
        }
896
        }
Línea 864... Línea 897...
864
 
897
 
865
        // Delete files associated with this assignment.
898
        // Delete files associated with this assignment.
866
        $fs = get_file_storage();
899
        $fs = get_file_storage();
867
        if (! $fs->delete_area_files($this->context->id) ) {
900
        if (! $fs->delete_area_files($this->context->id)) {
868
            $result = false;
901
            $result = false;
Línea 869... Línea 902...
869
        }
902
        }
Línea 882... Línea 915...
882
            $result = false;
915
            $result = false;
883
        }
916
        }
Línea 884... Línea 917...
884
 
917
 
885
        // Delete the instance.
918
        // Delete the instance.
886
        // We must delete the module record after we delete the grade item.
919
        // We must delete the module record after we delete the grade item.
Línea 887... Línea 920...
887
        $DB->delete_records('assign', array('id'=>$this->get_instance()->id));
920
        $DB->delete_records('assign', array('id' => $this->get_instance()->id));
888
 
921
 
Línea 889... Línea 922...
889
        return $result;
922
        return $result;
890
    }
923
    }
891
 
924
 
892
    /**
925
    /**
893
     * Deletes a assign override from the database and clears any corresponding calendar events
926
     * Deletes a assign override from the database and clears any corresponding calendar events
894
     *
927
     *
895
     * @param int $overrideid The id of the override being deleted
928
     * @param int $overrideid The id of the override being deleted
-
 
929
     * @return bool true on success
896
     * @return bool true on success
930
     */
Línea 897... Línea 931...
897
     */
931
    public function delete_override($overrideid)
Línea 898... Línea 932...
898
    public function delete_override($overrideid) {
932
    {
Línea 951... Línea 985...
951
    }
985
    }
Línea 952... Línea 986...
952
 
986
 
953
    /**
987
    /**
954
     * Deletes all assign overrides from the database and clears any corresponding calendar events
988
     * Deletes all assign overrides from the database and clears any corresponding calendar events
955
     */
989
     */
-
 
990
    public function delete_all_overrides()
956
    public function delete_all_overrides() {
991
    {
Línea 957... Línea 992...
957
        global $DB;
992
        global $DB;
958
 
993
 
959
        $overrides = $DB->get_records('assign_overrides', array('assignid' => $this->get_instance()->id), 'id');
994
        $overrides = $DB->get_records('assign_overrides', array('assignid' => $this->get_instance()->id), 'id');
Línea 969... Línea 1004...
969
     *   then use that otherwise, if there are group-specific overrides, return the most
1004
     *   then use that otherwise, if there are group-specific overrides, return the most
970
     *   lenient combination of them.  If neither applies, leave the assign setting unchanged.
1005
     *   lenient combination of them.  If neither applies, leave the assign setting unchanged.
971
     *
1006
     *
972
     * @param int $userid The userid.
1007
     * @param int $userid The userid.
973
     */
1008
     */
974
    public function update_effective_access($userid) {
1009
    public function update_effective_access($userid)
-
 
1010
    {
Línea 975... Línea 1011...
975
 
1011
 
Línea 976... Línea 1012...
976
        $override = $this->override_exists($userid);
1012
        $override = $this->override_exists($userid);
977
 
1013
 
978
        // Merge with assign defaults.
1014
        // Merge with assign defaults.
979
        $keys = array('duedate', 'cutoffdate', 'allowsubmissionsfromdate', 'timelimit');
1015
        $keys = array('duedate', 'cutoffdate', 'allowsubmissionsfromdate', 'timelimit');
980
        foreach ($keys as $key) {
1016
        foreach ($keys as $key) {
981
            if (isset($override->{$key})) {
1017
            if (isset($override->{$key})) {
982
                $this->get_instance($userid)->{$key} = $override->{$key};
1018
                $this->get_instance($userid)->{$key} = $override->{$key};
983
            }
-
 
984
        }
1019
            }
Línea 985... Línea 1020...
985
 
1020
        }
986
    }
1021
    }
987
 
1022
 
988
    /**
1023
    /**
989
     * Returns whether an assign has any overrides.
1024
     * Returns whether an assign has any overrides.
990
     *
1025
     *
-
 
1026
     * @return true if any, false if not
991
     * @return true if any, false if not
1027
     */
Línea 992... Línea 1028...
992
     */
1028
    public function has_overrides()
Línea 993... Línea 1029...
993
    public function has_overrides() {
1029
    {
Línea 1010... Línea 1046...
1010
     *   lowest sort order. If neither applies, leave the assign setting unchanged.
1046
     *   lowest sort order. If neither applies, leave the assign setting unchanged.
1011
     *
1047
     *
1012
     * @param int $userid The userid.
1048
     * @param int $userid The userid.
1013
     * @return stdClass The override
1049
     * @return stdClass The override
1014
     */
1050
     */
1015
    public function override_exists($userid) {
1051
    public function override_exists($userid)
-
 
1052
    {
1016
        global $DB;
1053
        global $DB;
Línea 1017... Línea 1054...
1017
 
1054
 
1018
        // Gets an assoc array containing the keys for defined user overrides only.
1055
        // Gets an assoc array containing the keys for defined user overrides only.
1019
        $getuseroverride = function($userid) use ($DB) {
1056
        $getuseroverride = function ($userid) use ($DB) {
1020
            $useroverride = $DB->get_record('assign_overrides', ['assignid' => $this->get_instance()->id, 'userid' => $userid]);
1057
            $useroverride = $DB->get_record('assign_overrides', ['assignid' => $this->get_instance()->id, 'userid' => $userid]);
1021
            return $useroverride ? get_object_vars($useroverride) : [];
1058
            return $useroverride ? get_object_vars($useroverride) : [];
Línea 1022... Línea 1059...
1022
        };
1059
        };
1023
 
1060
 
1024
        // Gets an assoc array containing the keys for defined group overrides only.
1061
        // Gets an assoc array containing the keys for defined group overrides only.
Línea 1025... Línea 1062...
1025
        $getgroupoverride = function($userid) use ($DB) {
1062
        $getgroupoverride = function ($userid) use ($DB) {
1026
            $groupings = groups_get_user_groups($this->get_instance()->course, $userid);
1063
            $groupings = groups_get_user_groups($this->get_instance()->course, $userid);
1027
 
1064
 
Línea 1053... Línea 1090...
1053
     * Check if the given calendar_event is either a user or group override
1090
     * Check if the given calendar_event is either a user or group override
1054
     * event.
1091
     * event.
1055
     *
1092
     *
1056
     * @return bool
1093
     * @return bool
1057
     */
1094
     */
1058
    public function is_override_calendar_event(\calendar_event $event) {
1095
    public function is_override_calendar_event(\calendar_event $event)
-
 
1096
    {
1059
        global $DB;
1097
        global $DB;
Línea 1060... Línea 1098...
1060
 
1098
 
1061
        if (!isset($event->modulename)) {
1099
        if (!isset($event->modulename)) {
1062
            return false;
1100
            return false;
Línea 1112... Línea 1150...
1112
     * be returned.
1150
     * be returned.
1113
     *
1151
     *
1114
     * @param calendar_event $event The calendar event to get the time range for
1152
     * @param calendar_event $event The calendar event to get the time range for
1115
     * @return array
1153
     * @return array
1116
     */
1154
     */
1117
    function get_valid_calendar_event_timestart_range(\calendar_event $event) {
1155
    function get_valid_calendar_event_timestart_range(\calendar_event $event)
-
 
1156
    {
1118
        $instance = $this->get_instance();
1157
        $instance = $this->get_instance();
1119
        $submissionsfromdate = $instance->allowsubmissionsfromdate;
1158
        $submissionsfromdate = $instance->allowsubmissionsfromdate;
1120
        $cutoffdate = $instance->cutoffdate;
1159
        $cutoffdate = $instance->cutoffdate;
1121
        $duedate = $instance->duedate;
1160
        $duedate = $instance->duedate;
1122
        $gradingduedate = $instance->gradingduedate;
1161
        $gradingduedate = $instance->gradingduedate;
Línea 1180... Línea 1219...
1180
     * assignment submissions for course $data->courseid.
1219
     * assignment submissions for course $data->courseid.
1181
     *
1220
     *
1182
     * @param stdClass $data the data submitted from the reset course.
1221
     * @param stdClass $data the data submitted from the reset course.
1183
     * @return array status array
1222
     * @return array status array
1184
     */
1223
     */
1185
    public function reset_userdata($data) {
1224
    public function reset_userdata($data)
-
 
1225
    {
1186
        global $CFG, $DB;
1226
        global $CFG, $DB;
Línea 1187... Línea 1227...
1187
 
1227
 
1188
        $componentstr = get_string('modulenameplural', 'assign');
1228
        $componentstr = get_string('modulenameplural', 'assign');
Línea 1198... Línea 1238...
1198
                foreach ($fileareas as $filearea => $notused) {
1238
                foreach ($fileareas as $filearea => $notused) {
1199
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1239
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1200
                }
1240
                }
Línea 1201... Línea 1241...
1201
 
1241
 
-
 
1242
                if (!$plugin->delete_instance()) {
1202
                if (!$plugin->delete_instance()) {
1243
                    $status[] = array(
1203
                    $status[] = array('component'=>$componentstr,
1244
                        'component' => $componentstr,
1204
                                      'item'=>get_string('deleteallsubmissions', 'assign'),
1245
                        'item' => get_string('deleteallsubmissions', 'assign'),
-
 
1246
                        'error' => $plugin->get_error()
1205
                                      'error'=>$plugin->get_error());
1247
                    );
1206
                }
1248
                }
Línea 1207... Línea 1249...
1207
            }
1249
            }
1208
 
1250
 
Línea 1213... Línea 1255...
1213
                foreach ($fileareas as $filearea => $notused) {
1255
                foreach ($fileareas as $filearea => $notused) {
1214
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1256
                    $fs->delete_area_files($this->context->id, $plugincomponent, $filearea);
1215
                }
1257
                }
Línea 1216... Línea 1258...
1216
 
1258
 
-
 
1259
                if (!$plugin->delete_instance()) {
1217
                if (!$plugin->delete_instance()) {
1260
                    $status[] = array(
1218
                    $status[] = array('component'=>$componentstr,
1261
                        'component' => $componentstr,
1219
                                      'item'=>get_string('deleteallsubmissions', 'assign'),
1262
                        'item' => get_string('deleteallsubmissions', 'assign'),
-
 
1263
                        'error' => $plugin->get_error()
1220
                                      'error'=>$plugin->get_error());
1264
                    );
1221
                }
1265
                }
Línea 1222... Línea 1266...
1222
            }
1266
            }
1223
 
1267
 
Línea 1224... Línea 1268...
1224
            $assignids = $DB->get_records('assign', array('course' => $data->courseid), '', 'id');
1268
            $assignids = $DB->get_records('assign', array('course' => $data->courseid), '', 'id');
1225
            list($sql, $params) = $DB->get_in_or_equal(array_keys($assignids));
1269
            list($sql, $params) = $DB->get_in_or_equal(array_keys($assignids));
Línea -... Línea 1270...
-
 
1270
 
1226
 
1271
            $DB->delete_records_select('assign_submission', "assignment $sql", $params);
1227
            $DB->delete_records_select('assign_submission', "assignment $sql", $params);
1272
            $DB->delete_records_select('assign_user_flags', "assignment $sql", $params);
1228
            $DB->delete_records_select('assign_user_flags', "assignment $sql", $params);
1273
 
-
 
1274
            $status[] = array(
Línea 1229... Línea 1275...
1229
 
1275
                'component' => $componentstr,
1230
            $status[] = array('component'=>$componentstr,
1276
                'item' => get_string('deleteallsubmissions', 'assign'),
1231
                              'item'=>get_string('deleteallsubmissions', 'assign'),
1277
                'error' => false
1232
                              'error'=>false);
1278
            );
1233
 
1279
 
1234
            if (!empty($data->reset_gradebook_grades)) {
1280
            if (!empty($data->reset_gradebook_grades)) {
Línea 1235... Línea 1281...
1235
                $DB->delete_records_select('assign_grades', "assignment $sql", $params);
1281
                $DB->delete_records_select('assign_grades', "assignment $sql", $params);
1236
                // Remove all grades from gradebook.
1282
                // Remove all grades from gradebook.
Línea 1246... Línea 1292...
1246
 
1292
 
Línea 1247... Línea 1293...
1247
        $purgeoverrides = false;
1293
        $purgeoverrides = false;
1248
 
1294
 
1249
        // Remove user overrides.
1295
        // Remove user overrides.
-
 
1296
        if (!empty($data->reset_assign_user_overrides)) {
1250
        if (!empty($data->reset_assign_user_overrides)) {
1297
            $DB->delete_records_select(
-
 
1298
                'assign_overrides',
-
 
1299
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND userid IS NOT NULL',
1251
            $DB->delete_records_select('assign_overrides',
1300
                array($data->courseid)
1252
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND userid IS NOT NULL', array($data->courseid));
1301
            );
1253
            $status[] = array(
1302
            $status[] = array(
1254
                'component' => $componentstr,
1303
                'component' => $componentstr,
-
 
1304
                'item' => get_string('useroverridesdeleted', 'assign'),
1255
                'item' => get_string('useroverridesdeleted', 'assign'),
1305
                'error' => false
1256
                'error' => false);
1306
            );
1257
            $purgeoverrides = true;
1307
            $purgeoverrides = true;
1258
        }
1308
        }
1259
        // Remove group overrides.
1309
        // Remove group overrides.
-
 
1310
        if (!empty($data->reset_assign_group_overrides)) {
1260
        if (!empty($data->reset_assign_group_overrides)) {
1311
            $DB->delete_records_select(
-
 
1312
                'assign_overrides',
-
 
1313
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND groupid IS NOT NULL',
1261
            $DB->delete_records_select('assign_overrides',
1314
                array($data->courseid)
1262
                'assignid IN (SELECT id FROM {assign} WHERE course = ?) AND groupid IS NOT NULL', array($data->courseid));
1315
            );
1263
            $status[] = array(
1316
            $status[] = array(
1264
                'component' => $componentstr,
1317
                'component' => $componentstr,
-
 
1318
                'item' => get_string('groupoverridesdeleted', 'assign'),
1265
                'item' => get_string('groupoverridesdeleted', 'assign'),
1319
                'error' => false
1266
                'error' => false);
1320
            );
Línea 1267... Línea 1321...
1267
            $purgeoverrides = true;
1321
            $purgeoverrides = true;
1268
        }
1322
        }
-
 
1323
 
1269
 
1324
        // Updating dates - shift may be negative too.
1270
        // Updating dates - shift may be negative too.
1325
        if ($data->timeshift) {
1271
        if ($data->timeshift) {
1326
            $DB->execute(
1272
            $DB->execute("UPDATE {assign_overrides}
1327
                "UPDATE {assign_overrides}
-
 
1328
                         SET allowsubmissionsfromdate = allowsubmissionsfromdate + ?
-
 
1329
                       WHERE assignid = ? AND allowsubmissionsfromdate <> 0",
1273
                         SET allowsubmissionsfromdate = allowsubmissionsfromdate + ?
1330
                array($data->timeshift, $this->get_instance()->id)
1274
                       WHERE assignid = ? AND allowsubmissionsfromdate <> 0",
1331
            );
1275
                array($data->timeshift, $this->get_instance()->id));
1332
            $DB->execute(
1276
            $DB->execute("UPDATE {assign_overrides}
1333
                "UPDATE {assign_overrides}
-
 
1334
                         SET duedate = duedate + ?
-
 
1335
                       WHERE assignid = ? AND duedate <> 0",
1277
                         SET duedate = duedate + ?
1336
                array($data->timeshift, $this->get_instance()->id)
1278
                       WHERE assignid = ? AND duedate <> 0",
1337
            );
1279
                array($data->timeshift, $this->get_instance()->id));
1338
            $DB->execute(
1280
            $DB->execute("UPDATE {assign_overrides}
1339
                "UPDATE {assign_overrides}
-
 
1340
                         SET cutoffdate = cutoffdate + ?
Línea 1281... Línea 1341...
1281
                         SET cutoffdate = cutoffdate + ?
1341
                       WHERE assignid =? AND cutoffdate <> 0",
Línea 1282... Línea 1342...
1282
                       WHERE assignid =? AND cutoffdate <> 0",
1342
                array($data->timeshift, $this->get_instance()->id)
1283
                array($data->timeshift, $this->get_instance()->id));
1343
            );
1284
 
1344
 
-
 
1345
            $purgeoverrides = true;
1285
            $purgeoverrides = true;
1346
 
1286
 
1347
            // 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.
1287
            // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
1349
            shift_course_mod_dates(
-
 
1350
                'assign',
-
 
1351
                array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'),
1288
            // See MDL-9367.
1352
                $data->timeshift,
1289
            shift_course_mod_dates('assign',
1353
                $data->courseid,
1290
                                    array('duedate', 'allowsubmissionsfromdate', 'cutoffdate'),
1354
                $this->get_instance()->id
-
 
1355
            );
1291
                                    $data->timeshift,
1356
            $status[] = array(
Línea 1292... Línea 1357...
1292
                                    $data->courseid, $this->get_instance()->id);
1357
                'component' => $componentstr,
1293
            $status[] = array('component'=>$componentstr,
1358
                'item' => get_string('datechanged'),
1294
                              'item'=>get_string('datechanged'),
1359
                'error' => false
Línea 1307... Línea 1372...
1307
     *
1372
     *
1308
     * @param assign_plugin $plugin The plugin to update
1373
     * @param assign_plugin $plugin The plugin to update
1309
     * @param stdClass $formdata The form data
1374
     * @param stdClass $formdata The form data
1310
     * @return bool false if an error occurs
1375
     * @return bool false if an error occurs
1311
     */
1376
     */
1312
    protected function update_plugin_instance(assign_plugin $plugin, stdClass $formdata) {
1377
    protected function update_plugin_instance(assign_plugin $plugin, stdClass $formdata)
-
 
1378
    {
1313
        if ($plugin->is_visible()) {
1379
        if ($plugin->is_visible()) {
1314
            $enabledname = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1380
            $enabledname = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1315
            if (!empty($formdata->$enabledname)) {
1381
            if (!empty($formdata->$enabledname)) {
1316
                $plugin->enable();
1382
                $plugin->enable();
1317
                if (!$plugin->save_settings($formdata)) {
1383
                if (!$plugin->save_settings($formdata)) {
Línea 1330... Línea 1396...
1330
     *
1396
     *
1331
     * @param bool $reset If true, will reset all grades in the gradbook for this assignment
1397
     * @param bool $reset If true, will reset all grades in the gradbook for this assignment
1332
     * @param int $coursemoduleid This is required because it might not exist in the database yet
1398
     * @param int $coursemoduleid This is required because it might not exist in the database yet
1333
     * @return bool
1399
     * @return bool
1334
     */
1400
     */
1335
    public function update_gradebook($reset, $coursemoduleid) {
1401
    public function update_gradebook($reset, $coursemoduleid)
-
 
1402
    {
1336
        global $CFG;
1403
        global $CFG;
Línea 1337... Línea 1404...
1337
 
1404
 
1338
        require_once($CFG->dirroot.'/mod/assign/lib.php');
1405
        require_once($CFG->dirroot . '/mod/assign/lib.php');
1339
        $assign = clone $this->get_instance();
1406
        $assign = clone $this->get_instance();
Línea 1340... Línea 1407...
1340
        $assign->cmidnumber = $coursemoduleid;
1407
        $assign->cmidnumber = $coursemoduleid;
1341
 
1408
 
Línea 1353... Línea 1420...
1353
    /**
1420
    /**
1354
     * Get the marking table page size
1421
     * Get the marking table page size
1355
     *
1422
     *
1356
     * @return integer
1423
     * @return integer
1357
     */
1424
     */
1358
    public function get_assign_perpage() {
1425
    public function get_assign_perpage()
-
 
1426
    {
1359
        $perpage = (int) get_user_preferences('assign_perpage', 10);
1427
        $perpage = (int) get_user_preferences('assign_perpage', 10);
1360
        $adminconfig = $this->get_admin_config();
1428
        $adminconfig = $this->get_admin_config();
1361
        $maxperpage = -1;
1429
        $maxperpage = -1;
1362
        if (isset($adminconfig->maxperpage)) {
1430
        if (isset($adminconfig->maxperpage)) {
1363
            $maxperpage = $adminconfig->maxperpage;
1431
            $maxperpage = $adminconfig->maxperpage;
1364
        }
1432
        }
-
 
1433
        if (
1365
        if (isset($maxperpage) &&
1434
            isset($maxperpage) &&
1366
            $maxperpage != -1 &&
1435
            $maxperpage != -1 &&
1367
            ($perpage == -1 || $perpage > $maxperpage)) {
1436
            ($perpage == -1 || $perpage > $maxperpage)
-
 
1437
        ) {
1368
            $perpage = $maxperpage;
1438
            $perpage = $maxperpage;
1369
        }
1439
        }
1370
        return $perpage;
1440
        return $perpage;
1371
    }
1441
    }
Línea 1372... Línea 1442...
1372
 
1442
 
1373
    /**
1443
    /**
1374
     * Load and cache the admin config for this module.
1444
     * Load and cache the admin config for this module.
1375
     *
1445
     *
1376
     * @return stdClass the plugin config
1446
     * @return stdClass the plugin config
1377
     */
1447
     */
-
 
1448
    public function get_admin_config()
1378
    public function get_admin_config() {
1449
    {
1379
        if ($this->adminconfig) {
1450
        if ($this->adminconfig) {
1380
            return $this->adminconfig;
1451
            return $this->adminconfig;
1381
        }
1452
        }
1382
        $this->adminconfig = get_config('assign');
1453
        $this->adminconfig = get_config('assign');
Línea 1388... Línea 1459...
1388
     *
1459
     *
1389
     * @param int $coursemoduleid - Required to pass this in because it might
1460
     * @param int $coursemoduleid - Required to pass this in because it might
1390
     *                              not exist in the database yet.
1461
     *                              not exist in the database yet.
1391
     * @return bool
1462
     * @return bool
1392
     */
1463
     */
1393
    public function update_calendar($coursemoduleid) {
1464
    public function update_calendar($coursemoduleid)
-
 
1465
    {
1394
        global $DB, $CFG;
1466
        global $DB, $CFG;
1395
        require_once($CFG->dirroot.'/calendar/lib.php');
1467
        require_once($CFG->dirroot . '/calendar/lib.php');
Línea 1396... Línea 1468...
1396
 
1468
 
1397
        // Special case for add_instance as the coursemodule has not been set yet.
1469
        // Special case for add_instance as the coursemodule has not been set yet.
Línea 1398... Línea 1470...
1398
        $instance = $this->get_instance();
1470
        $instance = $this->get_instance();
Línea 1448... Línea 1520...
1448
                $calendarevent->update($event, false);
1520
                $calendarevent->update($event, false);
1449
            } else {
1521
            } else {
1450
                calendar_event::create($event, false);
1522
                calendar_event::create($event, false);
1451
            }
1523
            }
1452
        } else {
1524
        } else {
1453
            $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
1525
            $DB->delete_records('event', array(
-
 
1526
                'modulename' => 'assign',
-
 
1527
                'instance' => $instance->id,
1454
                'eventtype' => $eventtype));
1528
                'eventtype' => $eventtype
-
 
1529
            ));
1455
        }
1530
        }
Línea 1456... Línea 1531...
1456
 
1531
 
1457
        $eventtype = ASSIGN_EVENT_TYPE_GRADINGDUE;
1532
        $eventtype = ASSIGN_EVENT_TYPE_GRADINGDUE;
1458
        if ($instance->gradingduedate) {
1533
        if ($instance->gradingduedate) {
1459
            $event->name = get_string('calendargradingdue', 'assign', $instance->name);
1534
            $event->name = get_string('calendargradingdue', 'assign', $instance->name);
1460
            $event->eventtype = $eventtype;
1535
            $event->eventtype = $eventtype;
1461
            $event->timestart = $instance->gradingduedate;
1536
            $event->timestart = $instance->gradingduedate;
1462
            $event->timesort = $instance->gradingduedate;
1537
            $event->timesort = $instance->gradingduedate;
-
 
1538
            $event->id = $DB->get_field('event', 'id', array(
-
 
1539
                'modulename' => 'assign',
1463
            $event->id = $DB->get_field('event', 'id', array('modulename' => 'assign',
1540
                'instance' => $instance->id,
-
 
1541
                'eventtype' => $event->eventtype
Línea 1464... Línea 1542...
1464
                'instance' => $instance->id, 'eventtype' => $event->eventtype));
1542
            ));
1465
 
1543
 
1466
            // Now process the event.
1544
            // Now process the event.
1467
            if ($event->id) {
1545
            if ($event->id) {
1468
                $calendarevent = calendar_event::load($event->id);
1546
                $calendarevent = calendar_event::load($event->id);
1469
                $calendarevent->update($event, false);
1547
                $calendarevent->update($event, false);
1470
            } else {
1548
            } else {
1471
                calendar_event::create($event, false);
1549
                calendar_event::create($event, false);
1472
            }
1550
            }
-
 
1551
        } else {
-
 
1552
            $DB->delete_records('event', array(
1473
        } else {
1553
                'modulename' => 'assign',
-
 
1554
                'instance' => $instance->id,
1474
            $DB->delete_records('event', array('modulename' => 'assign', 'instance' => $instance->id,
1555
                'eventtype' => $eventtype
Línea 1475... Línea 1556...
1475
                'eventtype' => $eventtype));
1556
            ));
1476
        }
1557
        }
Línea 1482... Línea 1563...
1482
     * Update this instance in the database.
1563
     * Update this instance in the database.
1483
     *
1564
     *
1484
     * @param stdClass $formdata - the data submitted from the form
1565
     * @param stdClass $formdata - the data submitted from the form
1485
     * @return bool false if an error occurs
1566
     * @return bool false if an error occurs
1486
     */
1567
     */
1487
    public function update_instance($formdata) {
1568
    public function update_instance($formdata)
-
 
1569
    {
1488
        global $DB;
1570
        global $DB;
1489
        $adminconfig = $this->get_admin_config();
1571
        $adminconfig = $this->get_admin_config();
Línea 1490... Línea 1572...
1490
 
1572
 
1491
        $update = new stdClass();
1573
        $update = new stdClass();
Línea 1551... Línea 1633...
1551
        if (empty($update->markingworkflow) || empty($update->blindmarking)) {
1633
        if (empty($update->markingworkflow) || empty($update->blindmarking)) {
1552
            $update->markinganonymous = 0;
1634
            $update->markinganonymous = 0;
1553
        }
1635
        }
Línea 1554... Línea 1636...
1554
 
1636
 
1555
        $result = $DB->update_record('assign', $update);
1637
        $result = $DB->update_record('assign', $update);
Línea 1556... Línea 1638...
1556
        $this->instance = $DB->get_record('assign', array('id'=>$update->id), '*', MUST_EXIST);
1638
        $this->instance = $DB->get_record('assign', array('id' => $update->id), '*', MUST_EXIST);
Línea 1557... Línea 1639...
1557
 
1639
 
Línea 1573... Línea 1655...
1573
            }
1655
            }
1574
        }
1656
        }
Línea 1575... Línea 1657...
1575
 
1657
 
1576
        $this->update_calendar($this->get_course_module()->id);
1658
        $this->update_calendar($this->get_course_module()->id);
1577
        $completionexpected = (!empty($formdata->completionexpected)) ? $formdata->completionexpected : null;
1659
        $completionexpected = (!empty($formdata->completionexpected)) ? $formdata->completionexpected : null;
-
 
1660
        \core_completion\api::update_completion_date_event(
-
 
1661
            $this->get_course_module()->id,
-
 
1662
            'assign',
1578
        \core_completion\api::update_completion_date_event($this->get_course_module()->id, 'assign', $this->instance,
1663
            $this->instance,
-
 
1664
            $completionexpected
1579
                $completionexpected);
1665
        );
Línea 1580... Línea 1666...
1580
        $this->update_gradebook(false, $this->get_course_module()->id);
1666
        $this->update_gradebook(false, $this->get_course_module()->id);
1581
 
1667
 
1582
        $update = new stdClass();
1668
        $update = new stdClass();
1583
        $update->id = $this->get_instance()->id;
1669
        $update->id = $this->get_instance()->id;
Línea 1584... Línea 1670...
1584
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1: 0;
1670
        $update->nosubmissions = (!$this->is_any_submission_plugin_enabled()) ? 1 : 0;
1585
        $DB->update_record('assign', $update);
1671
        $DB->update_record('assign', $update);
Línea 1586... Línea 1672...
1586
 
1672
 
1587
        return $result;
1673
        return $result;
1588
    }
1674
    }
1589
 
1675
 
1590
    /**
1676
    /**
1591
     * Save the attachments in the intro description.
1677
     * Save the attachments in the intro description.
-
 
1678
     *
1592
     *
1679
     * @param stdClass $formdata
-
 
1680
     */
1593
     * @param stdClass $formdata
1681
    protected function save_intro_draft_files($formdata)
-
 
1682
    {
-
 
1683
        if (isset($formdata->introattachments)) {
1594
     */
1684
            file_save_draft_area_files(
-
 
1685
                $formdata->introattachments,
-
 
1686
                $this->get_context()->id,
1595
    protected function save_intro_draft_files($formdata) {
1687
                'mod_assign',
1596
        if (isset($formdata->introattachments)) {
1688
                ASSIGN_INTROATTACHMENT_FILEAREA,
Línea 1597... Línea 1689...
1597
            file_save_draft_area_files($formdata->introattachments, $this->get_context()->id,
1689
                0
1598
                                       'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
1690
            );
1599
        }
1691
        }
1600
    }
1692
    }
1601
 
1693
 
1602
    /**
1694
    /**
-
 
1695
     * Save the attachments in the editor description.
1603
     * Save the attachments in the editor description.
1696
     *
1604
     *
1697
     * @param stdClass $formdata
1605
     * @param stdClass $formdata
1698
     */
1606
     */
1699
    protected function save_editor_draft_files($formdata): string
-
 
1700
    {
1607
    protected function save_editor_draft_files($formdata): string {
1701
        $text = '';
-
 
1702
        if (isset($formdata->activityeditor)) {
-
 
1703
            $text = $formdata->activityeditor['text'];
1608
        $text = '';
1704
            if (isset($formdata->activityeditor['itemid'])) {
-
 
1705
                $text = file_save_draft_area_files(
-
 
1706
                    $formdata->activityeditor['itemid'],
1609
        if (isset($formdata->activityeditor)) {
1707
                    $this->get_context()->id,
-
 
1708
                    'mod_assign',
1610
            $text = $formdata->activityeditor['text'];
1709
                    ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
1611
            if (isset($formdata->activityeditor['itemid'])) {
1710
                    0,
1612
                $text = file_save_draft_area_files($formdata->activityeditor['itemid'], $this->get_context()->id,
1711
                    array('subdirs' => true),
1613
                    'mod_assign', ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
1712
                    $formdata->activityeditor['text']
Línea 1625... Línea 1724...
1625
     * @param MoodleQuickForm $mform
1724
     * @param MoodleQuickForm $mform
1626
     * @param stdClass $data
1725
     * @param stdClass $data
1627
     * @param int $userid - The userid we are grading
1726
     * @param int $userid - The userid we are grading
1628
     * @return void
1727
     * @return void
1629
     */
1728
     */
1630
    protected function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
1729
    protected function add_plugin_grade_elements($grade, MoodleQuickForm $mform, stdClass $data, $userid)
-
 
1730
    {
1631
        foreach ($this->feedbackplugins as $plugin) {
1731
        foreach ($this->feedbackplugins as $plugin) {
1632
            if ($plugin->is_enabled() && $plugin->is_visible()) {
1732
            if ($plugin->is_enabled() && $plugin->is_visible()) {
1633
                $plugin->get_form_elements_for_user($grade, $mform, $data, $userid);
1733
                $plugin->get_form_elements_for_user($grade, $mform, $data, $userid);
1634
            }
1734
            }
1635
        }
1735
        }
Línea 1645... Línea 1745...
1645
     *                               This form is modified directly (not returned).
1745
     *                               This form is modified directly (not returned).
1646
     * @param array $pluginsenabled A list of form elements to be added to a group.
1746
     * @param array $pluginsenabled A list of form elements to be added to a group.
1647
     *                              The new element is added to this array by this function.
1747
     *                              The new element is added to this array by this function.
1648
     * @return void
1748
     * @return void
1649
     */
1749
     */
1650
    protected function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, & $pluginsenabled) {
1750
    protected function add_plugin_settings(assign_plugin $plugin, MoodleQuickForm $mform, &$pluginsenabled)
-
 
1751
    {
1651
        global $CFG;
1752
        global $CFG;
1652
        if ($plugin->is_visible() && !$plugin->is_configurable() && $plugin->is_enabled()) {
1753
        if ($plugin->is_visible() && !$plugin->is_configurable() && $plugin->is_enabled()) {
1653
            $name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1754
            $name = $plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled';
1654
            $pluginsenabled[] = $mform->createElement('hidden', $name, 1);
1755
            $pluginsenabled[] = $mform->createElement('hidden', $name, 1);
1655
            $mform->setType($name, PARAM_BOOL);
1756
            $mform->setType($name, PARAM_BOOL);
Línea 1666... Línea 1767...
1666
                $default = $plugin->is_enabled();
1767
                $default = $plugin->is_enabled();
1667
            }
1768
            }
1668
            $mform->setDefault($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', $default);
1769
            $mform->setDefault($plugin->get_subtype() . '_' . $plugin->get_type() . '_enabled', $default);
Línea 1669... Línea 1770...
1669
 
1770
 
1670
            $plugin->get_settings($mform);
-
 
1671
 
1771
            $plugin->get_settings($mform);
1672
        }
1772
        }
Línea 1673... Línea 1773...
1673
    }
1773
    }
1674
 
1774
 
1675
    /**
1775
    /**
1676
     * Add settings to edit plugin form.
1776
     * Add settings to edit plugin form.
1677
     *
1777
     *
1678
     * @param MoodleQuickForm $mform The form to add the configuration settings to.
1778
     * @param MoodleQuickForm $mform The form to add the configuration settings to.
1679
     *                               This form is modified directly (not returned).
1779
     *                               This form is modified directly (not returned).
1680
     * @return void
1780
     * @return void
-
 
1781
     */
1681
     */
1782
    public function add_all_plugin_settings(MoodleQuickForm $mform)
Línea 1682... Línea 1783...
1682
    public function add_all_plugin_settings(MoodleQuickForm $mform) {
1783
    {
1683
        $mform->addElement('header', 'submissiontypes', get_string('submissiontypes', 'assign'));
1784
        $mform->addElement('header', 'submissiontypes', get_string('submissiontypes', 'assign'));
1684
 
1785
 
Línea 1704... Línea 1805...
1704
     * passed in to the settings form (needed to set up draft areas for
1805
     * passed in to the settings form (needed to set up draft areas for
1705
     * editor and filemanager elements)
1806
     * editor and filemanager elements)
1706
     *
1807
     *
1707
     * @param array $defaultvalues
1808
     * @param array $defaultvalues
1708
     */
1809
     */
1709
    public function plugin_data_preprocessing(&$defaultvalues) {
1810
    public function plugin_data_preprocessing(&$defaultvalues)
-
 
1811
    {
1710
        foreach ($this->submissionplugins as $plugin) {
1812
        foreach ($this->submissionplugins as $plugin) {
1711
            if ($plugin->is_visible()) {
1813
            if ($plugin->is_visible()) {
1712
                $plugin->data_preprocessing($defaultvalues);
1814
                $plugin->data_preprocessing($defaultvalues);
1713
            }
1815
            }
1714
        }
1816
        }
Línea 1722... Línea 1824...
1722
    /**
1824
    /**
1723
     * Get the name of the current module.
1825
     * Get the name of the current module.
1724
     *
1826
     *
1725
     * @return string the module name (Assignment)
1827
     * @return string the module name (Assignment)
1726
     */
1828
     */
1727
    protected function get_module_name() {
1829
    protected function get_module_name()
-
 
1830
    {
1728
        if (isset(self::$modulename)) {
1831
        if (isset(self::$modulename)) {
1729
            return self::$modulename;
1832
            return self::$modulename;
1730
        }
1833
        }
1731
        self::$modulename = get_string('modulename', 'assign');
1834
        self::$modulename = get_string('modulename', 'assign');
1732
        return self::$modulename;
1835
        return self::$modulename;
Línea 1735... Línea 1838...
1735
    /**
1838
    /**
1736
     * Get the plural name of the current module.
1839
     * Get the plural name of the current module.
1737
     *
1840
     *
1738
     * @return string the module name plural (Assignments)
1841
     * @return string the module name plural (Assignments)
1739
     */
1842
     */
1740
    protected function get_module_name_plural() {
1843
    protected function get_module_name_plural()
-
 
1844
    {
1741
        if (isset(self::$modulenameplural)) {
1845
        if (isset(self::$modulenameplural)) {
1742
            return self::$modulenameplural;
1846
            return self::$modulenameplural;
1743
        }
1847
        }
1744
        self::$modulenameplural = get_string('modulenameplural', 'assign');
1848
        self::$modulenameplural = get_string('modulenameplural', 'assign');
1745
        return self::$modulenameplural;
1849
        return self::$modulenameplural;
Línea 1748... Línea 1852...
1748
    /**
1852
    /**
1749
     * Has this assignment been constructed from an instance?
1853
     * Has this assignment been constructed from an instance?
1750
     *
1854
     *
1751
     * @return bool
1855
     * @return bool
1752
     */
1856
     */
1753
    public function has_instance() {
1857
    public function has_instance()
-
 
1858
    {
1754
        return $this->instance || $this->get_course_module();
1859
        return $this->instance || $this->get_course_module();
1755
    }
1860
    }
Línea 1756... Línea 1861...
1756
 
1861
 
1757
    /**
1862
    /**
1758
     * Get the settings for the current instance of this assignment.
1863
     * Get the settings for the current instance of this assignment.
1759
     *
1864
     *
1760
     * @return stdClass The settings
1865
     * @return stdClass The settings
1761
     * @throws dml_exception
1866
     * @throws dml_exception
1762
     */
1867
     */
-
 
1868
    public function get_default_instance()
1763
    public function get_default_instance() {
1869
    {
1764
        global $DB;
1870
        global $DB;
1765
        if (!$this->instance && $this->get_course_module()) {
1871
        if (!$this->instance && $this->get_course_module()) {
1766
            $params = array('id' => $this->get_course_module()->instance);
1872
            $params = array('id' => $this->get_course_module()->instance);
Línea 1774... Línea 1880...
1774
    /**
1880
    /**
1775
     * Get the settings for the current instance of this assignment
1881
     * Get the settings for the current instance of this assignment
1776
     * @param int|null $userid the id of the user to load the assign instance for.
1882
     * @param int|null $userid the id of the user to load the assign instance for.
1777
     * @return stdClass The settings
1883
     * @return stdClass The settings
1778
     */
1884
     */
1779
    public function get_instance(int $userid = null): stdClass {
1885
    public function get_instance(int $userid = null): stdClass
-
 
1886
    {
1780
        global $USER;
1887
        global $USER;
1781
        $userid = $userid ?? $USER->id;
1888
        $userid = $userid ?? $USER->id;
Línea 1782... Línea 1889...
1782
 
1889
 
Línea 1797... Línea 1904...
1797
     *
1904
     *
1798
     * @param stdClass $record the raw assign record.
1905
     * @param stdClass $record the raw assign record.
1799
     * @param int $userid the id of the user to calculate the properties for.
1906
     * @param int $userid the id of the user to calculate the properties for.
1800
     * @return stdClass a new record having calculated properties.
1907
     * @return stdClass a new record having calculated properties.
1801
     */
1908
     */
1802
    private function calculate_properties(\stdClass $record, int $userid): \stdClass {
1909
    private function calculate_properties(\stdClass $record, int $userid): \stdClass
-
 
1910
    {
1803
        $record = clone ($record);
1911
        $record = clone ($record);
Línea 1804... Línea 1912...
1804
 
1912
 
1805
        // Relative dates.
1913
        // Relative dates.
1806
        if (!empty($record->duedate)) {
1914
        if (!empty($record->duedate)) {
Línea 1817... Línea 1925...
1817
    /**
1925
    /**
1818
     * Get the primary grade item for this assign instance.
1926
     * Get the primary grade item for this assign instance.
1819
     *
1927
     *
1820
     * @return grade_item The grade_item record
1928
     * @return grade_item The grade_item record
1821
     */
1929
     */
1822
    public function get_grade_item() {
1930
    public function get_grade_item()
-
 
1931
    {
1823
        if ($this->gradeitem) {
1932
        if ($this->gradeitem) {
1824
            return $this->gradeitem;
1933
            return $this->gradeitem;
1825
        }
1934
        }
1826
        $instance = $this->get_instance();
1935
        $instance = $this->get_instance();
-
 
1936
        $params = array(
1827
        $params = array('itemtype' => 'mod',
1937
            'itemtype' => 'mod',
1828
                        'itemmodule' => 'assign',
1938
            'itemmodule' => 'assign',
1829
                        'iteminstance' => $instance->id,
1939
            'iteminstance' => $instance->id,
1830
                        'courseid' => $instance->course,
1940
            'courseid' => $instance->course,
1831
                        'itemnumber' => 0);
1941
            'itemnumber' => 0
-
 
1942
        );
1832
        $this->gradeitem = grade_item::fetch($params);
1943
        $this->gradeitem = grade_item::fetch($params);
1833
        if (!$this->gradeitem) {
1944
        if (!$this->gradeitem) {
1834
            throw new coding_exception('Improper use of the assignment class. ' .
1945
            throw new coding_exception('Improper use of the assignment class. ' .
1835
                                       'Cannot load the grade item.');
1946
                'Cannot load the grade item.');
1836
        }
1947
        }
1837
        return $this->gradeitem;
1948
        return $this->gradeitem;
1838
    }
1949
    }
Línea 1839... Línea 1950...
1839
 
1950
 
1840
    /**
1951
    /**
1841
     * Get the context of the current course.
1952
     * Get the context of the current course.
1842
     *
1953
     *
1843
     * @return mixed context|null The course context
1954
     * @return mixed context|null The course context
1844
     */
1955
     */
-
 
1956
    public function get_course_context()
1845
    public function get_course_context() {
1957
    {
1846
        if (!$this->context && !$this->course) {
1958
        if (!$this->context && !$this->course) {
1847
            throw new coding_exception('Improper use of the assignment class. ' .
1959
            throw new coding_exception('Improper use of the assignment class. ' .
1848
                                       'Cannot load the course context.');
1960
                'Cannot load the course context.');
1849
        }
1961
        }
1850
        if ($this->context) {
1962
        if ($this->context) {
1851
            return $this->context->get_course_context();
1963
            return $this->context->get_course_context();
1852
        } else {
1964
        } else {
Línea 1858... Línea 1970...
1858
    /**
1970
    /**
1859
     * Get the current course module.
1971
     * Get the current course module.
1860
     *
1972
     *
1861
     * @return cm_info|null The course module or null if not known
1973
     * @return cm_info|null The course module or null if not known
1862
     */
1974
     */
1863
    public function get_course_module() {
1975
    public function get_course_module()
-
 
1976
    {
1864
        if ($this->coursemodule) {
1977
        if ($this->coursemodule) {
1865
            return $this->coursemodule;
1978
            return $this->coursemodule;
1866
        }
1979
        }
1867
        if (!$this->context) {
1980
        if (!$this->context) {
1868
            return null;
1981
            return null;
Línea 1879... Línea 1992...
1879
    /**
1992
    /**
1880
     * Get context module.
1993
     * Get context module.
1881
     *
1994
     *
1882
     * @return context
1995
     * @return context
1883
     */
1996
     */
1884
    public function get_context() {
1997
    public function get_context()
-
 
1998
    {
1885
        return $this->context;
1999
        return $this->context;
1886
    }
2000
    }
Línea 1887... Línea 2001...
1887
 
2001
 
1888
    /**
2002
    /**
1889
     * Get the current course.
2003
     * Get the current course.
1890
     *
2004
     *
1891
     * @return mixed stdClass|null The course
2005
     * @return mixed stdClass|null The course
1892
     */
2006
     */
-
 
2007
    public function get_course()
1893
    public function get_course() {
2008
    {
Línea 1894... Línea 2009...
1894
        global $DB;
2009
        global $DB;
1895
 
2010
 
1896
        if ($this->course && is_object($this->course)) {
2011
        if ($this->course && is_object($this->course)) {
Línea 1909... Línea 2024...
1909
    /**
2024
    /**
1910
     * Count the number of intro attachments.
2025
     * Count the number of intro attachments.
1911
     *
2026
     *
1912
     * @return int
2027
     * @return int
1913
     */
2028
     */
1914
    protected function count_attachments() {
2029
    protected function count_attachments()
-
 
2030
    {
Línea 1915... Línea 2031...
1915
 
2031
 
-
 
2032
        $fs = get_file_storage();
-
 
2033
        $files = $fs->get_area_files(
-
 
2034
            $this->get_context()->id,
1916
        $fs = get_file_storage();
2035
            'mod_assign',
-
 
2036
            ASSIGN_INTROATTACHMENT_FILEAREA,
-
 
2037
            0,
1917
        $files = $fs->get_area_files($this->get_context()->id, 'mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA,
2038
            'id',
-
 
2039
            false
Línea 1918... Línea 2040...
1918
                        0, 'id', false);
2040
        );
1919
 
2041
 
Línea 1920... Línea 2042...
1920
        return count($files);
2042
        return count($files);
1921
    }
2043
    }
1922
 
2044
 
1923
    /**
2045
    /**
1924
     * Are there any intro attachments to display?
2046
     * Are there any intro attachments to display?
1925
     *
2047
     *
-
 
2048
     * @return boolean
1926
     * @return boolean
2049
     */
1927
     */
2050
    protected function has_visible_attachments()
Línea 1928... Línea 2051...
1928
    protected function has_visible_attachments() {
2051
    {
1929
        return ($this->count_attachments() > 0);
2052
        return ($this->count_attachments() > 0);
1930
    }
2053
    }
1931
 
2054
 
1932
    /**
2055
    /**
1933
     * Check if the intro attachments should be provided to the user.
2056
     * Check if the intro attachments should be provided to the user.
1934
     *
2057
     *
-
 
2058
     * @param int $userid User id.
1935
     * @param int $userid User id.
2059
     * @return bool
Línea 1936... Línea 2060...
1936
     * @return bool
2060
     */
1937
     */
2061
    public function should_provide_intro_attachments(int $userid): bool
1938
    public function should_provide_intro_attachments(int $userid): bool {
2062
    {
Línea 1963... Línea 2087...
1963
     * @param boolean $editing Are we allowing changes to this grade?
2087
     * @param boolean $editing Are we allowing changes to this grade?
1964
     * @param int $userid The user id the grade belongs to
2088
     * @param int $userid The user id the grade belongs to
1965
     * @param int $modified Timestamp from when the grade was last modified
2089
     * @param int $modified Timestamp from when the grade was last modified
1966
     * @return string User-friendly representation of grade
2090
     * @return string User-friendly representation of grade
1967
     */
2091
     */
1968
    public function display_grade($grade, $editing, $userid=0, $modified=0) {
2092
    public function display_grade($grade, $editing, $userid = 0, $modified = 0)
-
 
2093
    {
1969
        global $DB;
2094
        global $DB;
Línea 1970... Línea 2095...
1970
 
2095
 
Línea 1971... Línea 2096...
1971
        static $scalegrades = array();
2096
        static $scalegrades = array();
Línea 1979... Línea 2104...
1979
                    $displaygrade = '';
2104
                    $displaygrade = '';
1980
                } else {
2105
                } else {
1981
                    $displaygrade = format_float($grade, $this->get_grade_item()->get_decimals());
2106
                    $displaygrade = format_float($grade, $this->get_grade_item()->get_decimals());
1982
                }
2107
                }
1983
                $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' .
2108
                $o .= '<label class="accesshide" for="quickgrade_' . $userid . '">' .
1984
                       get_string('usergrade', 'assign') .
2109
                    get_string('usergrade', 'assign') .
1985
                       '</label>';
2110
                    '</label>';
1986
                $o .= '<input type="text"
2111
                $o .= '<input type="text"
1987
                              id="quickgrade_' . $userid . '"
2112
                              id="quickgrade_' . $userid . '"
1988
                              name="quickgrade_' . $userid . '"
2113
                              name="quickgrade_' . $userid . '"
1989
                              value="' .  $displaygrade . '"
2114
                              value="' .  $displaygrade . '"
1990
                              size="6"
2115
                              size="6"
Línea 2003... Línea 2128...
2003
                        $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $item->get_decimals());
2128
                        $o .= '&nbsp;/&nbsp;' . format_float($this->get_instance()->grade, $item->get_decimals());
2004
                    }
2129
                    }
2005
                }
2130
                }
2006
                return $o;
2131
                return $o;
2007
            }
2132
            }
2008
 
-
 
2009
        } else {
2133
        } else {
2010
            // Scale.
2134
            // Scale.
2011
            if (empty($this->cache['scale'])) {
2135
            if (empty($this->cache['scale'])) {
2012
                if ($scale = $DB->get_record('scale', array('id'=>-($this->get_instance()->grade)))) {
2136
                if ($scale = $DB->get_record('scale', array('id' => - ($this->get_instance()->grade)))) {
2013
                    $this->cache['scale'] = make_menu_from_list($scale->scale);
2137
                    $this->cache['scale'] = make_menu_from_list($scale->scale);
2014
                } else {
2138
                } else {
2015
                    $o .= '-';
2139
                    $o .= '-';
2016
                    return $o;
2140
                    return $o;
2017
                }
2141
                }
2018
            }
2142
            }
2019
            if ($editing) {
2143
            if ($editing) {
2020
                $o .= '<label class="accesshide"
2144
                $o .= '<label class="accesshide"
2021
                              for="quickgrade_' . $userid . '">' .
2145
                              for="quickgrade_' . $userid . '">' .
2022
                      get_string('usergrade', 'assign') .
2146
                    get_string('usergrade', 'assign') .
2023
                      '</label>';
2147
                    '</label>';
2024
                $o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
2148
                $o .= '<select name="quickgrade_' . $userid . '" class="quickgrade">';
2025
                $o .= '<option value="-1">' . get_string('nograde') . '</option>';
2149
                $o .= '<option value="-1">' . get_string('nograde') . '</option>';
2026
                foreach ($this->cache['scale'] as $optionid => $option) {
2150
                foreach ($this->cache['scale'] as $optionid => $option) {
2027
                    $selected = '';
2151
                    $selected = '';
2028
                    if ($grade == $optionid) {
2152
                    if ($grade == $optionid) {
Línea 2054... Línea 2178...
2054
     * @param array $participants an associative array where the key is the participant id and
2178
     * @param array $participants an associative array where the key is the participant id and
2055
     *                            the value is the participant record.
2179
     *                            the value is the participant record.
2056
     * @return array an associative array where the key is the participant id and the value is
2180
     * @return array an associative array where the key is the participant id and the value is
2057
     *               the participant record.
2181
     *               the participant record.
2058
     */
2182
     */
2059
    private function get_submission_info_for_participants($participants) {
2183
    private function get_submission_info_for_participants($participants)
-
 
2184
    {
2060
        global $DB;
2185
        global $DB;
Línea 2061... Línea 2186...
2061
 
2186
 
2062
        if (empty($participants)) {
2187
        if (empty($participants)) {
2063
            return $participants;
2188
            return $participants;
Línea 2098... Línea 2223...
2098
 
2223
 
Línea 2099... Línea 2224...
2099
        $records = $DB->get_records_sql($sql, $params);
2224
        $records = $DB->get_records_sql($sql, $params);
2100
 
2225
 
2101
        if ($this->get_instance()->teamsubmission) {
2226
        if ($this->get_instance()->teamsubmission) {
-
 
2227
            // Get all groups.
2102
            // Get all groups.
2228
            $allgroups = groups_get_all_groups(
2103
            $allgroups = groups_get_all_groups($this->get_course()->id,
2229
                $this->get_course()->id,
2104
                                               array_keys($participants),
2230
                array_keys($participants),
2105
                                               $this->get_instance()->teamsubmissiongroupingid,
2231
                $this->get_instance()->teamsubmissiongroupingid,
2106
                                               'DISTINCT g.id, g.name');
2232
                'DISTINCT g.id, g.name'
2107
 
2233
            );
2108
        }
2234
        }
2109
        foreach ($participants as $userid => $participant) {
2235
        foreach ($participants as $userid => $participant) {
2110
            $participants[$userid]->fullname = $this->fullname($participant);
2236
            $participants[$userid]->fullname = $this->fullname($participant);
Línea 2124... Línea 2250...
2124
            if (!empty($submissioninfo->stime) && $submissioninfo->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
2250
            if (!empty($submissioninfo->stime) && $submissioninfo->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
2125
                $submitted = true;
2251
                $submitted = true;
2126
            }
2252
            }
Línea 2127... Línea 2253...
2127
 
2253
 
2128
            if ($submitted && ($submissioninfo->stime >= $submissioninfo->gtime ||
2254
            if ($submitted && ($submissioninfo->stime >= $submissioninfo->gtime ||
2129
                    empty($submissioninfo->gtime) ||
2255
                empty($submissioninfo->gtime) ||
2130
                    $submissioninfo->grade === null)) {
2256
                $submissioninfo->grade === null)) {
2131
                $requiregrading = true;
2257
                $requiregrading = true;
Línea 2132... Línea 2258...
2132
            }
2258
            }
2133
 
2259
 
Línea 2158... Línea 2284...
2158
     * @param int $currentgroup
2284
     * @param int $currentgroup
2159
     * @param boolean $tablesort Apply current user table sorting preferences.
2285
     * @param boolean $tablesort Apply current user table sorting preferences.
2160
     * @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'grantedextension',
2286
     * @return array List of user records with extra fields 'submitted', 'notsubmitted', 'requiregrading', 'grantedextension',
2161
     *               'groupid', 'groupname'
2287
     *               'groupid', 'groupname'
2162
     */
2288
     */
2163
    public function list_participants_with_filter_status_and_group($currentgroup, $tablesort = false) {
2289
    public function list_participants_with_filter_status_and_group($currentgroup, $tablesort = false)
-
 
2290
    {
2164
        $participants = $this->list_participants($currentgroup, false, $tablesort);
2291
        $participants = $this->list_participants($currentgroup, false, $tablesort);
Línea 2165... Línea 2292...
2165
 
2292
 
2166
        if (empty($participants)) {
2293
        if (empty($participants)) {
2167
            return $participants;
2294
            return $participants;
Línea 2176... Línea 2303...
2176
     * we are only concerned with a list of users so we can't search on anything
2303
     * we are only concerned with a list of users so we can't search on anything
2177
     * that is not part of the user information (like grading statud or last modified stuff).
2304
     * that is not part of the user information (like grading statud or last modified stuff).
2178
     *
2305
     *
2179
     * @return string Order by clause for list_participants
2306
     * @return string Order by clause for list_participants
2180
     */
2307
     */
2181
    private function get_grading_sort_sql() {
2308
    private function get_grading_sort_sql()
-
 
2309
    {
2182
        $usersort = flexible_table::get_sort_for_table('mod_assign_grading');
2310
        $usersort = flexible_table::get_sort_for_table('mod_assign_grading');
2183
        // TODO Does not support custom user profile fields (MDL-70456).
2311
        // TODO Does not support custom user profile fields (MDL-70456).
2184
        $userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
2312
        $userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_userpic();
2185
        $userfields = $userfieldsapi->get_required_fields();
2313
        $userfields = $userfieldsapi->get_required_fields();
2186
        $orderfields = explode(',', $usersort);
2314
        $orderfields = explode(',', $usersort);
Línea 2210... Línea 2338...
2210
     * Returns array with sql code and parameters returning all ids of users who have submitted an assignment.
2338
     * Returns array with sql code and parameters returning all ids of users who have submitted an assignment.
2211
     *
2339
     *
2212
     * @param int $group The group that the query is for.
2340
     * @param int $group The group that the query is for.
2213
     * @return array list($sql, $params)
2341
     * @return array list($sql, $params)
2214
     */
2342
     */
2215
    protected function get_submitted_sql($group = 0) {
2343
    protected function get_submitted_sql($group = 0)
-
 
2344
    {
2216
        // We need to guarentee unique table names.
2345
        // We need to guarentee unique table names.
2217
        static $i = 0;
2346
        static $i = 0;
2218
        $i++;
2347
        $i++;
2219
        $prefix = 'sa' . $i . '_';
2348
        $prefix = 'sa' . $i . '_';
2220
        $params = [
2349
        $params = [
Línea 2241... Línea 2370...
2241
     * @param int $currentgroup
2370
     * @param int $currentgroup
2242
     * @param bool $idsonly
2371
     * @param bool $idsonly
2243
     * @param bool $tablesort
2372
     * @param bool $tablesort
2244
     * @return array List of user records
2373
     * @return array List of user records
2245
     */
2374
     */
2246
    public function list_participants($currentgroup, $idsonly, $tablesort = false) {
2375
    public function list_participants($currentgroup, $idsonly, $tablesort = false)
-
 
2376
    {
2247
        global $DB, $USER;
2377
        global $DB, $USER;
Línea 2248... Línea 2378...
2248
 
2378
 
Línea 2249... Línea 2379...
2249
        // Get the last known sort order for the grading table.
2379
        // Get the last known sort order for the grading table.
2250
 
2380
 
2251
        if (empty($currentgroup)) {
2381
        if (empty($currentgroup)) {
Línea 2252... Línea 2382...
2252
            $currentgroup = 0;
2382
            $currentgroup = 0;
2253
        }
2383
        }
2254
 
2384
 
-
 
2385
        $key = $this->context->id . '-' . $currentgroup . '-' . $this->show_only_active_users();
-
 
2386
        if (!isset($this->participants[$key])) {
-
 
2387
            list($esql, $params) = get_enrolled_sql(
2255
        $key = $this->context->id . '-' . $currentgroup . '-' . $this->show_only_active_users();
2388
                $this->context,
-
 
2389
                'mod/assign:submit',
2256
        if (!isset($this->participants[$key])) {
2390
                $currentgroup,
2257
            list($esql, $params) = get_enrolled_sql($this->context, 'mod/assign:submit', $currentgroup,
2391
                $this->show_only_active_users()
Línea 2258... Línea 2392...
2258
                    $this->show_only_active_users());
2392
            );
2259
            list($ssql, $sparams) = $this->get_submitted_sql($currentgroup);
2393
            list($ssql, $sparams) = $this->get_submitted_sql($currentgroup);
Línea 2285... Línea 2419...
2285
                if (empty($tablesort)) {
2419
                if (empty($tablesort)) {
2286
                    $orderby = "COALESCE(s.timecreated, " . time() . ") ASC, COALESCE(s.id, " . PHP_INT_MAX . ") ASC, um.id ASC";
2420
                    $orderby = "COALESCE(s.timecreated, " . time() . ") ASC, COALESCE(s.id, " . PHP_INT_MAX . ") ASC, um.id ASC";
2287
                }
2421
                }
2288
            }
2422
            }
Línea -... Línea 2423...
-
 
2423
 
2289
 
2424
            if (
2290
            if ($instance->markingworkflow &&
2425
                $instance->markingworkflow &&
2291
                    $instance->markingallocation &&
2426
                $instance->markingallocation &&
2292
                    !has_capability('mod/assign:manageallocations', $this->get_context()) &&
2427
                !has_capability('mod/assign:manageallocations', $this->get_context()) &&
-
 
2428
                has_capability('mod/assign:grade', $this->get_context())
Línea 2293... Línea 2429...
2293
                    has_capability('mod/assign:grade', $this->get_context())) {
2429
            ) {
2294
 
2430
 
2295
                $additionaljoins .= ' LEFT JOIN {assign_user_flags} uf
2431
                $additionaljoins .= ' LEFT JOIN {assign_user_flags} uf
Línea 2348... Línea 2484...
2348
     * status for this assignment.
2484
     * status for this assignment.
2349
     *
2485
     *
2350
     * @param int $userid
2486
     * @param int $userid
2351
     * @return null|stdClass user record
2487
     * @return null|stdClass user record
2352
     */
2488
     */
2353
    public function get_participant($userid) {
2489
    public function get_participant($userid)
-
 
2490
    {
2354
        global $DB, $USER;
2491
        global $DB, $USER;
Línea 2355... Línea 2492...
2355
 
2492
 
2356
        if ($userid == $USER->id) {
2493
        if ($userid == $USER->id) {
2357
            $participant = clone ($USER);
2494
            $participant = clone ($USER);
Línea 2380... Línea 2517...
2380
     * Load a count of valid teams for this assignment.
2517
     * Load a count of valid teams for this assignment.
2381
     *
2518
     *
2382
     * @param int $activitygroup Activity active group
2519
     * @param int $activitygroup Activity active group
2383
     * @return int number of valid teams
2520
     * @return int number of valid teams
2384
     */
2521
     */
2385
    public function count_teams($activitygroup = 0) {
2522
    public function count_teams($activitygroup = 0)
-
 
2523
    {
Línea 2386... Línea 2524...
2386
 
2524
 
Línea 2387... Línea 2525...
2387
        $count = 0;
2525
        $count = 0;
Línea 2392... Línea 2530...
2392
        // are the submission teams, but if no team submission grouping was specified
2530
        // are the submission teams, but if no team submission grouping was specified
2393
        // $groups will contain all participants groups.
2531
        // $groups will contain all participants groups.
2394
        if ($this->get_instance()->teamsubmissiongroupingid) {
2532
        if ($this->get_instance()->teamsubmissiongroupingid) {
Línea 2395... Línea 2533...
2395
 
2533
 
2396
            // We restrict the users to the selected group ones.
2534
            // We restrict the users to the selected group ones.
-
 
2535
            $groups = groups_get_all_groups(
2397
            $groups = groups_get_all_groups($this->get_course()->id,
2536
                $this->get_course()->id,
2398
                                            array_keys($participants),
2537
                array_keys($participants),
2399
                                            $this->get_instance()->teamsubmissiongroupingid,
2538
                $this->get_instance()->teamsubmissiongroupingid,
-
 
2539
                'DISTINCT g.id, g.name'
Línea 2400... Línea 2540...
2400
                                            'DISTINCT g.id, g.name');
2540
            );
Línea 2401... Línea 2541...
2401
 
2541
 
2402
            $count = count($groups);
2542
            $count = count($groups);
Línea 2437... Línea 2577...
2437
     * 0 for no group.
2577
     * 0 for no group.
2438
     *
2578
     *
2439
     * @param int $currentgroup
2579
     * @param int $currentgroup
2440
     * @return int number of matching users
2580
     * @return int number of matching users
2441
     */
2581
     */
2442
    public function count_participants($currentgroup) {
2582
    public function count_participants($currentgroup)
-
 
2583
    {
2443
        return count($this->list_participants($currentgroup, true));
2584
        return count($this->list_participants($currentgroup, true));
2444
    }
2585
    }
Línea 2445... Línea 2586...
2445
 
2586
 
2446
    /**
2587
    /**
Línea 2449... Línea 2590...
2449
     * grading modification time and the status is SUBMITTED.
2590
     * grading modification time and the status is SUBMITTED.
2450
     *
2591
     *
2451
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2592
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2452
     * @return int number of matching submissions
2593
     * @return int number of matching submissions
2453
     */
2594
     */
2454
    public function count_submissions_need_grading($currentgroup = null) {
2595
    public function count_submissions_need_grading($currentgroup = null)
-
 
2596
    {
2455
        global $DB;
2597
        global $DB;
Línea 2456... Línea 2598...
2456
 
2598
 
2457
        if ($this->get_instance()->teamsubmission) {
2599
        if ($this->get_instance()->teamsubmission) {
2458
            // This does not make sense for group assignment because the submission is shared.
2600
            // This does not make sense for group assignment because the submission is shared.
Línea 2479... Línea 2621...
2479
                        s.latest = 1 AND
2621
                        s.latest = 1 AND
2480
                        s.assignment = :assignid AND
2622
                        s.assignment = :assignid AND
2481
                        s.timemodified IS NOT NULL AND
2623
                        s.timemodified IS NOT NULL AND
2482
                        s.status = :submitted AND
2624
                        s.status = :submitted AND
2483
                        (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL '
2625
                        (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL '
2484
                            . $sqlscalegrade . ')';
2626
            . $sqlscalegrade . ')';
Línea 2485... Línea 2627...
2485
 
2627
 
2486
        return $DB->count_records_sql($sql, $params);
2628
        return $DB->count_records_sql($sql, $params);
Línea 2487... Línea 2629...
2487
    }
2629
    }
2488
 
2630
 
2489
    /**
2631
    /**
2490
     * Load a count of grades.
2632
     * Load a count of grades.
2491
     *
2633
     *
2492
     * @return int number of grades
2634
     * @return int number of grades
-
 
2635
     */
2493
     */
2636
    public function count_grades()
Línea 2494... Línea 2637...
2494
    public function count_grades() {
2637
    {
2495
        global $DB;
2638
        global $DB;
2496
 
2639
 
Línea 2515... Línea 2658...
2515
     * Load a count of submissions.
2658
     * Load a count of submissions.
2516
     *
2659
     *
2517
     * @param bool $includenew When true, also counts the submissions with status 'new'.
2660
     * @param bool $includenew When true, also counts the submissions with status 'new'.
2518
     * @return int number of submissions
2661
     * @return int number of submissions
2519
     */
2662
     */
2520
    public function count_submissions($includenew = false) {
2663
    public function count_submissions($includenew = false)
-
 
2664
    {
2521
        global $DB;
2665
        global $DB;
Línea 2522... Línea 2666...
2522
 
2666
 
2523
        if (!$this->has_instance()) {
2667
        if (!$this->has_instance()) {
2524
            return 0;
2668
            return 0;
Línea 2538... Línea 2682...
2538
                        FROM {assign_submission} s
2682
                        FROM {assign_submission} s
2539
                        WHERE
2683
                        WHERE
2540
                            s.assignment = :assignid AND
2684
                            s.assignment = :assignid AND
2541
                            s.timemodified IS NOT NULL AND
2685
                            s.timemodified IS NOT NULL AND
2542
                            s.userid = :groupuserid' .
2686
                            s.userid = :groupuserid' .
2543
                            $sqlnew;
2687
                $sqlnew;
Línea 2544... Línea 2688...
2544
 
2688
 
2545
            $params['assignid'] = $this->get_instance()->id;
2689
            $params['assignid'] = $this->get_instance()->id;
2546
            $params['groupuserid'] = 0;
2690
            $params['groupuserid'] = 0;
2547
        } else {
2691
        } else {
Línea 2555... Línea 2699...
2555
                       FROM {assign_submission} s
2699
                       FROM {assign_submission} s
2556
                       JOIN(' . $esql . ') e ON e.id = s.userid
2700
                       JOIN(' . $esql . ') e ON e.id = s.userid
2557
                       WHERE
2701
                       WHERE
2558
                            s.assignment = :assignid AND
2702
                            s.assignment = :assignid AND
2559
                            s.timemodified IS NOT NULL ' .
2703
                            s.timemodified IS NOT NULL ' .
2560
                            $sqlnew;
2704
                $sqlnew;
2561
 
-
 
2562
        }
2705
        }
Línea 2563... Línea 2706...
2563
 
2706
 
2564
        return $DB->count_records_sql($sql, $params);
2707
        return $DB->count_records_sql($sql, $params);
Línea 2569... Línea 2712...
2569
     *
2712
     *
2570
     * @param string $status The submission status - should match one of the constants
2713
     * @param string $status The submission status - should match one of the constants
2571
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2714
     * @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
2572
     * @return int number of matching submissions
2715
     * @return int number of matching submissions
2573
     */
2716
     */
2574
    public function count_submissions_with_status($status, $currentgroup = null) {
2717
    public function count_submissions_with_status($status, $currentgroup = null)
-
 
2718
    {
2575
        global $DB;
2719
        global $DB;
Línea 2576... Línea 2720...
2576
 
2720
 
2577
        if ($currentgroup === null) {
2721
        if ($currentgroup === null) {
2578
            $currentgroup = groups_get_activity_group($this->get_course_module(), true);
2722
            $currentgroup = groups_get_activity_group($this->get_course_module(), true);
Línea 2587... Línea 2731...
2587
 
2731
 
2588
            $groupsstr = '';
2732
            $groupsstr = '';
2589
            if ($currentgroup != 0) {
2733
            if ($currentgroup != 0) {
2590
                // If there is an active group we should only display the current group users groups.
2734
                // If there is an active group we should only display the current group users groups.
2591
                $participants = $this->list_participants($currentgroup, true);
2735
                $participants = $this->list_participants($currentgroup, true);
-
 
2736
                $groups = groups_get_all_groups(
2592
                $groups = groups_get_all_groups($this->get_course()->id,
2737
                    $this->get_course()->id,
2593
                                                array_keys($participants),
2738
                    array_keys($participants),
2594
                                                $this->get_instance()->teamsubmissiongroupingid,
2739
                    $this->get_instance()->teamsubmissiongroupingid,
-
 
2740
                    'DISTINCT g.id, g.name'
2595
                                                'DISTINCT g.id, g.name');
2741
                );
2596
                if (empty($groups)) {
2742
                if (empty($groups)) {
2597
                    // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
2743
                    // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
2598
                    // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
2744
                    // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
2599
                    // count towards groupid = 0. Setting to true as only '0' key matters.
2745
                    // count towards groupid = 0. Setting to true as only '0' key matters.
Línea 2608... Línea 2754...
2608
                        WHERE
2754
                        WHERE
2609
                            s.latest = 1 AND
2755
                            s.latest = 1 AND
2610
                            s.assignment = :assignid AND
2756
                            s.assignment = :assignid AND
2611
                            s.timemodified IS NOT NULL AND
2757
                            s.timemodified IS NOT NULL AND
2612
                            s.userid = :groupuserid AND '
2758
                            s.userid = :groupuserid AND '
2613
                            . $groupsstr . '
2759
                . $groupsstr . '
2614
                            s.status = :submissionstatus';
2760
                            s.status = :submissionstatus';
2615
            $params['groupuserid'] = 0;
2761
            $params['groupuserid'] = 0;
2616
        } else {
2762
        } else {
2617
            $sql = 'SELECT COUNT(s.userid)
2763
            $sql = 'SELECT COUNT(s.userid)
2618
                        FROM {assign_submission} s
2764
                        FROM {assign_submission} s
Línea 2620... Línea 2766...
2620
                        WHERE
2766
                        WHERE
2621
                            s.latest = 1 AND
2767
                            s.latest = 1 AND
2622
                            s.assignment = :assignid AND
2768
                            s.assignment = :assignid AND
2623
                            s.timemodified IS NOT NULL AND
2769
                            s.timemodified IS NOT NULL AND
2624
                            s.status = :submissionstatus';
2770
                            s.status = :submissionstatus';
2625
 
-
 
2626
        }
2771
        }
Línea 2627... Línea 2772...
2627
 
2772
 
2628
        return $DB->count_records_sql($sql, $params);
2773
        return $DB->count_records_sql($sql, $params);
Línea 2634... Línea 2779...
2634
     *
2779
     *
2635
     * @param boolean $cached If true, the cached list from the session could be returned.
2780
     * @param boolean $cached If true, the cached list from the session could be returned.
2636
     * @param string $useridlistid String value used for caching the participant list.
2781
     * @param string $useridlistid String value used for caching the participant list.
2637
     * @return array An array of userids
2782
     * @return array An array of userids
2638
     */
2783
     */
2639
    protected function get_grading_userid_list($cached = false, $useridlistid = '') {
2784
    protected function get_grading_userid_list($cached = false, $useridlistid = '')
-
 
2785
    {
2640
        global $SESSION;
2786
        global $SESSION;
Línea 2641... Línea 2787...
2641
 
2787
 
2642
        if ($cached) {
2788
        if ($cached) {
2643
            if (empty($useridlistid)) {
2789
            if (empty($useridlistid)) {
Línea 2661... Línea 2807...
2661
     * Is user id filtered by user filters and table preferences.
2807
     * Is user id filtered by user filters and table preferences.
2662
     *
2808
     *
2663
     * @param int $userid User id that needs to be checked.
2809
     * @param int $userid User id that needs to be checked.
2664
     * @return bool
2810
     * @return bool
2665
     */
2811
     */
2666
    public function is_userid_filtered($userid) {
2812
    public function is_userid_filtered($userid)
-
 
2813
    {
2667
        $users = $this->get_grading_userid_list();
2814
        $users = $this->get_grading_userid_list();
2668
        return in_array($userid, $users);
2815
        return in_array($userid, $users);
2669
    }
2816
    }
Línea 2670... Línea 2817...
2670
 
2817
 
Línea 2673... Línea 2820...
2673
     *
2820
     *
2674
     * Cron function to be run periodically according to the moodle cron.
2821
     * Cron function to be run periodically according to the moodle cron.
2675
     *
2822
     *
2676
     * @return bool
2823
     * @return bool
2677
     */
2824
     */
2678
    public static function cron() {
2825
    public static function cron()
-
 
2826
    {
2679
        global $DB;
2827
        global $DB;
Línea 2680... Línea 2828...
2680
 
2828
 
2681
        // Only ever send a max of one days worth of updates.
2829
        // Only ever send a max of one days worth of updates.
2682
        $yesterday = time() - (24 * 3600);
2830
        $yesterday = time() - (24 * 3600);
Línea 2725... Línea 2873...
2725
            // Filter out duplicates.
2873
            // Filter out duplicates.
2726
            $courseids = array_unique($courseids);
2874
            $courseids = array_unique($courseids);
2727
            $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
2875
            $ctxselect = context_helper::get_preload_record_columns_sql('ctx');
2728
            list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
2876
            list($courseidsql, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
2729
            $sql = 'SELECT c.*, ' . $ctxselect .
2877
            $sql = 'SELECT c.*, ' . $ctxselect .
2730
                      ' FROM {course} c
2878
                ' FROM {course} c
2731
                 LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel
2879
                 LEFT JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel
2732
                     WHERE c.id ' . $courseidsql;
2880
                     WHERE c.id ' . $courseidsql;
Línea 2733... Línea 2881...
2733
 
2881
 
2734
            $params['contextlevel'] = CONTEXT_COURSE;
2882
            $params['contextlevel'] = CONTEXT_COURSE;
Línea 2744... Línea 2892...
2744
            foreach ($submissions as $submission) {
2892
            foreach ($submissions as $submission) {
Línea 2745... Línea 2893...
2745
 
2893
 
Línea 2746... Línea 2894...
2746
                mtrace("Processing assignment submission $submission->id ...");
2894
                mtrace("Processing assignment submission $submission->id ...");
2747
 
2895
 
2748
                // Do not cache user lookups - could be too many.
2896
                // Do not cache user lookups - could be too many.
2749
                if (!$user = $DB->get_record('user', array('id'=>$submission->userid))) {
2897
                if (!$user = $DB->get_record('user', array('id' => $submission->userid))) {
2750
                    mtrace('Could not find user ' . $submission->userid);
2898
                    mtrace('Could not find user ' . $submission->userid);
Línea 2751... Línea 2899...
2751
                    continue;
2899
                    continue;
Línea 2767... Línea 2915...
2767
                \core\cron::setup_user($user, $course);
2915
                \core\cron::setup_user($user, $course);
Línea 2768... Línea 2916...
2768
 
2916
 
2769
                // Context lookups are already cached.
2917
                // Context lookups are already cached.
2770
                $coursecontext = context_course::instance($course->id);
2918
                $coursecontext = context_course::instance($course->id);
2771
                if (!is_enrolled($coursecontext, $user->id)) {
2919
                if (!is_enrolled($coursecontext, $user->id)) {
2772
                    $courseshortname = format_string($course->shortname,
2920
                    $courseshortname = format_string(
-
 
2921
                        $course->shortname,
2773
                                                     true,
2922
                        true,
-
 
2923
                        array('context' => $coursecontext)
2774
                                                     array('context' => $coursecontext));
2924
                    );
2775
                    mtrace(fullname($user) . ' not an active participant in ' . $courseshortname);
2925
                    mtrace(fullname($user) . ' not an active participant in ' . $courseshortname);
2776
                    continue;
2926
                    continue;
Línea 2777... Línea 2927...
2777
                }
2927
                }
2778
 
2928
 
2779
                if (!$grader = $DB->get_record('user', array('id'=>$submission->grader))) {
2929
                if (!$grader = $DB->get_record('user', array('id' => $submission->grader))) {
2780
                    mtrace('Could not find grader ' . $submission->grader);
2930
                    mtrace('Could not find grader ' . $submission->grader);
Línea 2781... Línea 2931...
2781
                    continue;
2931
                    continue;
Línea 2813... Línea 2963...
2813
                    } else {
2963
                    } else {
2814
                        $uniqueid = $submission->recordid;
2964
                        $uniqueid = $submission->recordid;
2815
                    }
2965
                    }
2816
                }
2966
                }
2817
                $showusers = $submission->blindmarking && !$submission->revealidentities;
2967
                $showusers = $submission->blindmarking && !$submission->revealidentities;
2818
                self::send_assignment_notification($grader,
2968
                self::send_assignment_notification(
-
 
2969
                    $grader,
2819
                                                   $user,
2970
                    $user,
2820
                                                   $messagetype,
2971
                    $messagetype,
2821
                                                   $eventtype,
2972
                    $eventtype,
2822
                                                   $updatetime,
2973
                    $updatetime,
2823
                                                   $cm,
2974
                    $cm,
2824
                                                   $contextmodule,
2975
                    $contextmodule,
2825
                                                   $course,
2976
                    $course,
2826
                                                   $modulename,
2977
                    $modulename,
2827
                                                   $submission->name,
2978
                    $submission->name,
2828
                                                   $showusers,
2979
                    $showusers,
2829
                                                   $uniqueid);
2980
                    $uniqueid
-
 
2981
                );
Línea 2830... Línea 2982...
2830
 
2982
 
2831
                $flags = $DB->get_record('assign_user_flags', array('userid'=>$user->id, 'assignment'=>$submission->assignment));
2983
                $flags = $DB->get_record('assign_user_flags', array('userid' => $user->id, 'assignment' => $submission->assignment));
2832
                if ($flags) {
2984
                if ($flags) {
2833
                    $flags->mailed = 1;
2985
                    $flags->mailed = 1;
2834
                    $DB->update_record('assign_user_flags', $flags);
2986
                    $DB->update_record('assign_user_flags', $flags);
2835
                } else {
2987
                } else {
Línea 2875... Línea 3027...
2875
     *
3027
     *
2876
     * @param stdClass $grade a grade record keyed on id
3028
     * @param stdClass $grade a grade record keyed on id
2877
     * @param bool $mailedoverride when true, flag notification to be sent again.
3029
     * @param bool $mailedoverride when true, flag notification to be sent again.
2878
     * @return bool true for success
3030
     * @return bool true for success
2879
     */
3031
     */
2880
    public function notify_grade_modified($grade, $mailedoverride = false) {
3032
    public function notify_grade_modified($grade, $mailedoverride = false)
-
 
3033
    {
2881
        global $DB;
3034
        global $DB;
Línea 2882... Línea 3035...
2882
 
3035
 
2883
        $flags = $this->get_user_flags($grade->userid, true);
3036
        $flags = $this->get_user_flags($grade->userid, true);
2884
        if ($flags->mailed != 1 || $mailedoverride) {
3037
        if ($flags->mailed != 1 || $mailedoverride) {
Línea 2892... Línea 3045...
2892
     * Update user flags for this user in this assignment.
3045
     * Update user flags for this user in this assignment.
2893
     *
3046
     *
2894
     * @param stdClass $flags a flags record keyed on id
3047
     * @param stdClass $flags a flags record keyed on id
2895
     * @return bool true for success
3048
     * @return bool true for success
2896
     */
3049
     */
2897
    public function update_user_flags($flags) {
3050
    public function update_user_flags($flags)
-
 
3051
    {
2898
        global $DB;
3052
        global $DB;
2899
        if ($flags->userid <= 0 || $flags->assignment <= 0 || $flags->id <= 0) {
3053
        if ($flags->userid <= 0 || $flags->assignment <= 0 || $flags->id <= 0) {
2900
            return false;
3054
            return false;
2901
        }
3055
        }
Línea 2909... Línea 3063...
2909
     *
3063
     *
2910
     * @param stdClass $grade a grade record keyed on id
3064
     * @param stdClass $grade a grade record keyed on id
2911
     * @param bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this assignment.
3065
     * @param bool $reopenattempt If the attempt reopen method is manual, allow another attempt at this assignment.
2912
     * @return bool true for success
3066
     * @return bool true for success
2913
     */
3067
     */
2914
    public function update_grade($grade, $reopenattempt = false) {
3068
    public function update_grade($grade, $reopenattempt = false)
-
 
3069
    {
2915
        global $DB;
3070
        global $DB;
Línea 2916... Línea 3071...
2916
 
3071
 
Línea 2917... Línea 3072...
2917
        $grade->timemodified = time();
3072
        $grade->timemodified = time();
Línea 2932... Línea 3087...
2932
                } else if ($grade->grade < 0) {
3087
                } else if ($grade->grade < 0) {
2933
                    return false;
3088
                    return false;
2934
                }
3089
                }
2935
            } else {
3090
            } else {
2936
                // This is a scale.
3091
                // This is a scale.
2937
                if ($scale = $DB->get_record('scale', array('id' => -($this->get_instance()->grade)))) {
3092
                if ($scale = $DB->get_record('scale', array('id' => - ($this->get_instance()->grade)))) {
2938
                    $scaleoptions = make_menu_from_list($scale->scale);
3093
                    $scaleoptions = make_menu_from_list($scale->scale);
2939
                    if (!array_key_exists((int) $grade->grade, $scaleoptions)) {
3094
                    if (!array_key_exists((int) $grade->grade, $scaleoptions)) {
2940
                        return false;
3095
                        return false;
2941
                    }
3096
                    }
2942
                }
3097
                }
Línea 2969... Línea 3124...
2969
            \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
3124
            \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger();
2970
        }
3125
        }
Línea 2971... Línea 3126...
2971
 
3126
 
2972
        // If the conditions are met, allow another attempt.
3127
        // If the conditions are met, allow another attempt.
2973
        if ($submission) {
3128
        if ($submission) {
-
 
3129
            $isreopened = $this->reopen_submission_if_required(
2974
            $isreopened = $this->reopen_submission_if_required($grade->userid,
3130
                $grade->userid,
2975
                    $submission,
3131
                $submission,
-
 
3132
                $reopenattempt
2976
                    $reopenattempt);
3133
            );
2977
            if ($isreopened) {
3134
            if ($isreopened) {
-
 
3135
                $completion = new completion_info($this->get_course());
2978
                $completion = new completion_info($this->get_course());
3136
                if (
2979
                if ($completion->is_enabled($this->get_course_module()) &&
3137
                    $completion->is_enabled($this->get_course_module()) &&
-
 
3138
                    $this->get_instance()->completionsubmit
2980
                    $this->get_instance()->completionsubmit) {
3139
                ) {
2981
                    $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $grade->userid);
3140
                    $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $grade->userid);
2982
                }
3141
                }
2983
            }
3142
            }
Línea 2993... Línea 3152...
2993
     * or from parameter 'selectedusers'
3152
     * or from parameter 'selectedusers'
2994
     *
3153
     *
2995
     * @param moodleform $mform - Used for validation of the submitted data
3154
     * @param moodleform $mform - Used for validation of the submitted data
2996
     * @return string
3155
     * @return string
2997
     */
3156
     */
2998
    protected function view_grant_extension($mform) {
3157
    protected function view_grant_extension($mform)
-
 
3158
    {
2999
        global $CFG;
3159
        global $CFG;
3000
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
3160
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
Línea 3001... Línea 3161...
3001
 
3161
 
Línea 3043... Línea 3203...
3043
 
3203
 
3044
        if (empty($mform)) {
3204
        if (empty($mform)) {
3045
            $mform = new mod_assign_extension_form(null, $formparams);
3205
            $mform = new mod_assign_extension_form(null, $formparams);
3046
        }
3206
        }
3047
        $mform->set_data($data);
3207
        $mform->set_data($data);
-
 
3208
        $header = new assign_header(
3048
        $header = new assign_header($this->get_instance(),
3209
            $this->get_instance(),
3049
                                    $this->get_context(),
3210
            $this->get_context(),
3050
                                    $this->show_intro(),
3211
            $this->show_intro(),
3051
                                    $this->get_course_module()->id,
3212
            $this->get_course_module()->id,
-
 
3213
            get_string('grantextension', 'assign')
3052
                                    get_string('grantextension', 'assign'));
3214
        );
3053
        $o .= $this->get_renderer()->render($header);
3215
        $o .= $this->get_renderer()->render($header);
3054
        $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform));
3216
        $o .= $this->get_renderer()->render(new assign_form('extensionform', $mform));
3055
        $o .= $this->view_footer();
3217
        $o .= $this->view_footer();
3056
        return $o;
3218
        return $o;
Línea 3062... Línea 3224...
3062
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3224
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3063
     * @param bool $onlyids Whether to retrieve only the user id's
3225
     * @param bool $onlyids Whether to retrieve only the user id's
3064
     * @param bool $excludesuspended Whether to exclude suspended users
3226
     * @param bool $excludesuspended Whether to exclude suspended users
3065
     * @return array The users (possibly id's only)
3227
     * @return array The users (possibly id's only)
3066
     */
3228
     */
3067
    public function get_submission_group_members($groupid, $onlyids, $excludesuspended = false) {
3229
    public function get_submission_group_members($groupid, $onlyids, $excludesuspended = false)
-
 
3230
    {
3068
        $members = array();
3231
        $members = array();
3069
        if ($groupid != 0) {
3232
        if ($groupid != 0) {
3070
            $allusers = $this->list_participants($groupid, $onlyids);
3233
            $allusers = $this->list_participants($groupid, $onlyids);
3071
            foreach ($allusers as $user) {
3234
            foreach ($allusers as $user) {
3072
                if ($this->get_submission_group($user->id)) {
3235
                if ($this->get_submission_group($user->id)) {
Línea 3098... Línea 3261...
3098
     *
3261
     *
3099
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3262
     * @param int $groupid The id of the group whose members we want or 0 for the default group
3100
     * @param bool $onlyids Whether to retrieve only the user id's
3263
     * @param bool $onlyids Whether to retrieve only the user id's
3101
     * @return array The users (possibly id's only)
3264
     * @return array The users (possibly id's only)
3102
     */
3265
     */
3103
    public function get_submission_group_members_who_have_not_submitted($groupid, $onlyids) {
3266
    public function get_submission_group_members_who_have_not_submitted($groupid, $onlyids)
-
 
3267
    {
3104
        $instance = $this->get_instance();
3268
        $instance = $this->get_instance();
3105
        if (!$instance->teamsubmission || !$instance->requireallteammemberssubmit) {
3269
        if (!$instance->teamsubmission || !$instance->requireallteammemberssubmit) {
3106
            return array();
3270
            return array();
3107
        }
3271
        }
3108
        $members = $this->get_submission_group_members($groupid, $onlyids);
3272
        $members = $this->get_submission_group_members($groupid, $onlyids);
Línea 3112... Línea 3276...
3112
            if ($submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
3276
            if ($submission && $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
3113
                unset($members[$id]);
3277
                unset($members[$id]);
3114
            } else {
3278
            } else {
3115
                if ($this->is_blind_marking()) {
3279
                if ($this->is_blind_marking()) {
3116
                    $members[$id]->alias = get_string('hiddenuser', 'assign') .
3280
                    $members[$id]->alias = get_string('hiddenuser', 'assign') .
3117
                                           $this->get_uniqueid_for_user($id);
3281
                        $this->get_uniqueid_for_user($id);
3118
                }
3282
                }
3119
            }
3283
            }
3120
        }
3284
        }
3121
        return $members;
3285
        return $members;
3122
    }
3286
    }
Línea 3130... Línea 3294...
3130
     * @param bool $create If set to true a new submission object will be created in the database
3294
     * @param bool $create If set to true a new submission object will be created in the database
3131
     *                     with the status set to "new".
3295
     *                     with the status set to "new".
3132
     * @param int $attemptnumber - -1 means the latest attempt
3296
     * @param int $attemptnumber - -1 means the latest attempt
3133
     * @return stdClass|false The submission
3297
     * @return stdClass|false The submission
3134
     */
3298
     */
3135
    public function get_group_submission($userid, $groupid, $create, $attemptnumber=-1) {
3299
    public function get_group_submission($userid, $groupid, $create, $attemptnumber = -1)
-
 
3300
    {
3136
        global $DB;
3301
        global $DB;
Línea 3137... Línea 3302...
3137
 
3302
 
3138
        if ($groupid == 0) {
3303
        if ($groupid == 0) {
3139
            $group = $this->get_submission_group($userid);
3304
            $group = $this->get_submission_group($userid);
3140
            if ($group) {
3305
            if ($group) {
3141
                $groupid = $group->id;
3306
                $groupid = $group->id;
3142
            }
3307
            }
Línea 3143... Línea 3308...
3143
        }
3308
        }
3144
 
3309
 
3145
        // Now get the group submission.
3310
        // Now get the group submission.
3146
        $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
3311
        $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
3147
        if ($attemptnumber >= 0) {
3312
        if ($attemptnumber >= 0) {
Línea 3148... Línea 3313...
3148
            $params['attemptnumber'] = $attemptnumber;
3313
            $params['attemptnumber'] = $attemptnumber;
Línea 3179... Línea 3344...
3179
            } else {
3344
            } else {
3180
                $submission->attemptnumber = 0;
3345
                $submission->attemptnumber = 0;
3181
            }
3346
            }
3182
            // Work out if this is the latest submission.
3347
            // Work out if this is the latest submission.
3183
            $submission->latest = 0;
3348
            $submission->latest = 0;
3184
            $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
3349
            $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
3185
            if ($attemptnumber == -1) {
3350
            if ($attemptnumber == -1) {
3186
                // This is a new submission so it must be the latest.
3351
                // This is a new submission so it must be the latest.
3187
                $submission->latest = 1;
3352
                $submission->latest = 1;
3188
            } else {
3353
            } else {
3189
                // We need to work this out.
3354
                // We need to work this out.
Línea 3211... Línea 3376...
3211
    /**
3376
    /**
3212
     * View a summary listing of all assignments in the current course.
3377
     * View a summary listing of all assignments in the current course.
3213
     *
3378
     *
3214
     * @return string
3379
     * @return string
3215
     */
3380
     */
3216
    private function view_course_index() {
3381
    private function view_course_index()
-
 
3382
    {
3217
        global $USER;
3383
        global $USER;
Línea 3218... Línea 3384...
3218
 
3384
 
Línea 3219... Línea 3385...
3219
        $o = '';
3385
        $o = '';
Línea 3230... Línea 3396...
3230
        $strsectionname = '';
3396
        $strsectionname = '';
3231
        $usesections = course_format_uses_sections($course->format);
3397
        $usesections = course_format_uses_sections($course->format);
3232
        $modinfo = get_fast_modinfo($course);
3398
        $modinfo = get_fast_modinfo($course);
Línea 3233... Línea 3399...
3233
 
3399
 
3234
        if ($usesections) {
3400
        if ($usesections) {
3235
            $strsectionname = get_string('sectionname', 'format_'.$course->format);
3401
            $strsectionname = get_string('sectionname', 'format_' . $course->format);
3236
            $sections = $modinfo->get_section_info_all();
3402
            $sections = $modinfo->get_section_info_all();
3237
        }
3403
        }
Línea 3238... Línea 3404...
3238
        $courseindexsummary = new assign_course_index_summary($usesections, $strsectionname);
3404
        $courseindexsummary = new assign_course_index_summary($usesections, $strsectionname);
Línea 3259... Línea 3425...
3259
 
3425
 
3260
            // Apply overrides.
3426
            // Apply overrides.
3261
            $assignment->update_effective_access($USER->id);
3427
            $assignment->update_effective_access($USER->id);
Línea -... Línea 3428...
-
 
3428
            $timedue = $assignment->get_instance()->duedate;
3262
            $timedue = $assignment->get_instance()->duedate;
3429
 
3263
 
3430
            if (
-
 
3431
                has_capability('mod/assign:submit', $context) &&
3264
            if (has_capability('mod/assign:submit', $context) &&
3432
                !has_capability('moodle/site:config', $context)
3265
                !has_capability('moodle/site:config', $context)) {
3433
            ) {
3266
                $cangrade = false;
3434
                $cangrade = false;
3267
                if ($assignment->get_instance()->teamsubmission) {
3435
                if ($assignment->get_instance()->teamsubmission) {
3268
                    $usersubmission = $assignment->get_group_submission($USER->id, 0, false);
3436
                    $usersubmission = $assignment->get_group_submission($USER->id, 0, false);
Línea 3275... Línea 3443...
3275
                } else {
3443
                } else {
3276
                    $submitted = get_string('submissionstatus_', 'assign');
3444
                    $submitted = get_string('submissionstatus_', 'assign');
3277
                }
3445
                }
Línea 3278... Línea 3446...
3278
 
3446
 
-
 
3447
                $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id);
3279
                $gradinginfo = grade_get_grades($course->id, 'mod', 'assign', $cm->instance, $USER->id);
3448
                if (
3280
                if (isset($gradinginfo->items[0]->grades[$USER->id]) &&
3449
                    isset($gradinginfo->items[0]->grades[$USER->id]) &&
-
 
3450
                    !$gradinginfo->items[0]->grades[$USER->id]->hidden
3281
                        !$gradinginfo->items[0]->grades[$USER->id]->hidden ) {
3451
                ) {
3282
                    $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade;
3452
                    $grade = $gradinginfo->items[0]->grades[$USER->id]->str_grade;
3283
                } else {
3453
                } else {
3284
                    $grade = '-';
3454
                    $grade = '-';
3285
                }
3455
                }
3286
            } else if (has_capability('mod/assign:grade', $context)) {
3456
            } else if (has_capability('mod/assign:grade', $context)) {
3287
                $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
3457
                $submitted = $assignment->count_submissions_with_status(ASSIGN_SUBMISSION_STATUS_SUBMITTED);
3288
                $grade = $assignment->count_submissions_need_grading();
3458
                $grade = $assignment->count_submissions_need_grading();
3289
                $cangrade = true;
3459
                $cangrade = true;
Línea 3290... Línea 3460...
3290
            }
3460
            }
-
 
3461
 
3291
 
3462
            $courseindexsummary->add_assign_info(
-
 
3463
                $cm->id,
-
 
3464
                $cm->get_formatted_name(),
-
 
3465
                $sectionname,
-
 
3466
                $timedue,
-
 
3467
                $submitted,
-
 
3468
                $grade,
3292
            $courseindexsummary->add_assign_info($cm->id, $cm->get_formatted_name(),
3469
                $cangrade
Línea 3293... Línea 3470...
3293
                $sectionname, $timedue, $submitted, $grade, $cangrade);
3470
            );
3294
        }
3471
        }
Línea 3304... Línea 3481...
3304
     *
3481
     *
3305
     * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'.
3482
     * Uses url parameters 'pluginaction', 'pluginsubtype', 'plugin', and 'id'.
3306
     *
3483
     *
3307
     * @return string
3484
     * @return string
3308
     */
3485
     */
3309
    protected function view_plugin_page() {
3486
    protected function view_plugin_page()
-
 
3487
    {
3310
        global $USER;
3488
        global $USER;
Línea 3311... Línea 3489...
3311
 
3489
 
Línea 3312... Línea 3490...
3312
        $o = '';
3490
        $o = '';
Línea 3332... Línea 3510...
3332
     * If the user is a member of multiple or no groups this will return false
3510
     * If the user is a member of multiple or no groups this will return false
3333
     *
3511
     *
3334
     * @param int $userid The id of the user whose submission we want
3512
     * @param int $userid The id of the user whose submission we want
3335
     * @return mixed The group or false
3513
     * @return mixed The group or false
3336
     */
3514
     */
3337
    public function get_submission_group($userid) {
3515
    public function get_submission_group($userid)
-
 
3516
    {
Línea 3338... Línea 3517...
3338
 
3517
 
3339
        if (isset($this->usersubmissiongroups[$userid])) {
3518
        if (isset($this->usersubmissiongroups[$userid])) {
3340
            return $this->usersubmissiongroups[$userid];
3519
            return $this->usersubmissiongroups[$userid];
Línea 3357... Línea 3536...
3357
     * Gets all groups the user is a member of.
3536
     * Gets all groups the user is a member of.
3358
     *
3537
     *
3359
     * @param int $userid Teh id of the user who's groups we are checking
3538
     * @param int $userid Teh id of the user who's groups we are checking
3360
     * @return array The group objects
3539
     * @return array The group objects
3361
     */
3540
     */
3362
    public function get_all_groups($userid) {
3541
    public function get_all_groups($userid)
-
 
3542
    {
3363
        if (isset($this->usergroups[$userid])) {
3543
        if (isset($this->usergroups[$userid])) {
3364
            return $this->usergroups[$userid];
3544
            return $this->usergroups[$userid];
3365
        }
3545
        }
Línea 3366... Línea 3546...
3366
 
3546
 
Línea 3379... Línea 3559...
3379
     * Uses url parameters 'sid', 'gid' and 'plugin'.
3559
     * Uses url parameters 'sid', 'gid' and 'plugin'.
3380
     *
3560
     *
3381
     * @param string $pluginsubtype
3561
     * @param string $pluginsubtype
3382
     * @return string
3562
     * @return string
3383
     */
3563
     */
3384
    protected function view_plugin_content($pluginsubtype) {
3564
    protected function view_plugin_content($pluginsubtype)
-
 
3565
    {
3385
        $o = '';
3566
        $o = '';
Línea 3386... Línea 3567...
3386
 
3567
 
3387
        $submissionid = optional_param('sid', 0, PARAM_INT);
3568
        $submissionid = optional_param('sid', 0, PARAM_INT);
3388
        $gradeid = optional_param('gid', 0, PARAM_INT);
3569
        $gradeid = optional_param('gid', 0, PARAM_INT);
Línea 3400... Línea 3581...
3400
                // Group submission.
3581
                // Group submission.
3401
                $this->require_view_group_submission($item->groupid);
3582
                $this->require_view_group_submission($item->groupid);
3402
            } else {
3583
            } else {
3403
                $this->require_view_submission($item->userid);
3584
                $this->require_view_submission($item->userid);
3404
            }
3585
            }
3405
            $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3586
            $o .= $this->get_renderer()->render(new assign_header(
-
 
3587
                $this->get_instance(),
3406
                                                              $this->get_context(),
3588
                $this->get_context(),
3407
                                                              $this->show_intro(),
3589
                $this->show_intro(),
3408
                                                              $this->get_course_module()->id,
3590
                $this->get_course_module()->id,
3409
                                                              $plugin->get_name()));
3591
                $plugin->get_name()
-
 
3592
            ));
3410
            $o .= $this->get_renderer()->render(new assign_submission_plugin_submission($plugin,
3593
            $o .= $this->get_renderer()->render(new assign_submission_plugin_submission(
-
 
3594
                $plugin,
3411
                                                              $item,
3595
                $item,
3412
                                                              assign_submission_plugin_submission::FULL,
3596
                assign_submission_plugin_submission::FULL,
3413
                                                              $this->get_course_module()->id,
3597
                $this->get_course_module()->id,
3414
                                                              $this->get_return_action(),
3598
                $this->get_return_action(),
3415
                                                              $this->get_return_params()));
3599
                $this->get_return_params()
-
 
3600
            ));
Línea 3416... Línea 3601...
3416
 
3601
 
3417
            // Trigger event for viewing a submission.
3602
            // Trigger event for viewing a submission.
3418
            \mod_assign\event\submission_viewed::create_from_submission($this, $item)->trigger();
-
 
3419
 
3603
            \mod_assign\event\submission_viewed::create_from_submission($this, $item)->trigger();
3420
        } else {
3604
        } else {
3421
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
3605
            $plugin = $this->get_feedback_plugin_by_type($plugintype);
3422
            if ($gradeid <= 0) {
3606
            if ($gradeid <= 0) {
3423
                throw new coding_exception('Grade id should not be 0');
3607
                throw new coding_exception('Grade id should not be 0');
3424
            }
3608
            }
3425
            $item = $this->get_grade($gradeid);
3609
            $item = $this->get_grade($gradeid);
3426
            // Check permissions.
3610
            // Check permissions.
3427
            $this->require_view_submission($item->userid);
3611
            $this->require_view_submission($item->userid);
-
 
3612
            $o .= $this->get_renderer()->render(new assign_header(
3428
            $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3613
                $this->get_instance(),
3429
                                                              $this->get_context(),
3614
                $this->get_context(),
3430
                                                              $this->show_intro(),
3615
                $this->show_intro(),
3431
                                                              $this->get_course_module()->id,
3616
                $this->get_course_module()->id,
-
 
3617
                $plugin->get_name()
3432
                                                              $plugin->get_name()));
3618
            ));
-
 
3619
            $o .= $this->get_renderer()->render(new assign_feedback_plugin_feedback(
3433
            $o .= $this->get_renderer()->render(new assign_feedback_plugin_feedback($plugin,
3620
                $plugin,
3434
                                                              $item,
3621
                $item,
3435
                                                              assign_feedback_plugin_feedback::FULL,
3622
                assign_feedback_plugin_feedback::FULL,
3436
                                                              $this->get_course_module()->id,
3623
                $this->get_course_module()->id,
3437
                                                              $this->get_return_action(),
3624
                $this->get_return_action(),
-
 
3625
                $this->get_return_params()
Línea 3438... Línea 3626...
3438
                                                              $this->get_return_params()));
3626
            ));
3439
 
3627
 
3440
            // Trigger event for viewing feedback.
3628
            // Trigger event for viewing feedback.
Línea 3453... Línea 3641...
3453
     *
3641
     *
3454
     * @param string $text - The replacement text
3642
     * @param string $text - The replacement text
3455
     * @param stdClass $user - The user record
3643
     * @param stdClass $user - The user record
3456
     * @param assign_plugin $plugin - The assignment plugin
3644
     * @param assign_plugin $plugin - The assignment plugin
3457
     */
3645
     */
3458
    public function download_rewrite_pluginfile_urls($text, $user, $plugin) {
3646
    public function download_rewrite_pluginfile_urls($text, $user, $plugin)
-
 
3647
    {
3459
        // The groupname prefix for the urls doesn't depend on the group mode of the assignment instance.
3648
        // The groupname prefix for the urls doesn't depend on the group mode of the assignment instance.
3460
        // Rather, it should be determined by checking the group submission settings of the instance,
3649
        // Rather, it should be determined by checking the group submission settings of the instance,
3461
        // which is what download_submission() does when generating the file name prefixes.
3650
        // which is what download_submission() does when generating the file name prefixes.
3462
        $groupname = '';
3651
        $groupname = '';
3463
        if ($this->get_instance()->teamsubmission) {
3652
        if ($this->get_instance()->teamsubmission) {
Línea 3501... Línea 3690...
3501
     * @param string $editor
3690
     * @param string $editor
3502
     * @param string $component
3691
     * @param string $component
3503
     * @param bool $shortentext Whether to shorten the text content.
3692
     * @param bool $shortentext Whether to shorten the text content.
3504
     * @return string
3693
     * @return string
3505
     */
3694
     */
3506
    public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false) {
3695
    public function render_editor_content($filearea, $submissionid, $plugintype, $editor, $component, $shortentext = false)
-
 
3696
    {
3507
        global $CFG;
3697
        global $CFG;
Línea 3508... Línea 3698...
3508
 
3698
 
Línea 3509... Línea 3699...
3509
        $result = '';
3699
        $result = '';
Línea 3514... Línea 3704...
3514
        if ($shortentext) {
3704
        if ($shortentext) {
3515
            $text = shorten_text($text, 140);
3705
            $text = shorten_text($text, 140);
3516
        }
3706
        }
3517
        $format = $plugin->get_editor_format($editor, $submissionid);
3707
        $format = $plugin->get_editor_format($editor, $submissionid);
Línea 3518... Línea 3708...
3518
 
3708
 
-
 
3709
        $finaltext = file_rewrite_pluginfile_urls(
3519
        $finaltext = file_rewrite_pluginfile_urls($text,
3710
            $text,
3520
                                                  'pluginfile.php',
3711
            'pluginfile.php',
3521
                                                  $this->get_context()->id,
3712
            $this->get_context()->id,
3522
                                                  $component,
3713
            $component,
3523
                                                  $filearea,
3714
            $filearea,
-
 
3715
            $submissionid
3524
                                                  $submissionid);
3716
        );
3525
        $params = array('overflowdiv' => true, 'context' => $this->get_context());
3717
        $params = array('overflowdiv' => true, 'context' => $this->get_context());
Línea 3526... Línea 3718...
3526
        $result .= format_text($finaltext, $format, $params);
3718
        $result .= format_text($finaltext, $format, $params);
3527
 
3719
 
Línea 3528... Línea 3720...
3528
        if ($CFG->enableportfolios && has_capability('mod/assign:exportownsubmission', $this->context)) {
3720
        if ($CFG->enableportfolios && has_capability('mod/assign:exportownsubmission', $this->context)) {
-
 
3721
            require_once($CFG->libdir . '/portfoliolib.php');
3529
            require_once($CFG->libdir . '/portfoliolib.php');
3722
 
3530
 
3723
            $button = new portfolio_add_button();
3531
            $button = new portfolio_add_button();
3724
            $portfolioparams = array(
3532
            $portfolioparams = array('cmid' => $this->get_course_module()->id,
3725
                'cmid' => $this->get_course_module()->id,
3533
                                     'sid' => $submissionid,
3726
                'sid' => $submissionid,
-
 
3727
                'plugin' => $plugintype,
3534
                                     'plugin' => $plugintype,
3728
                'editor' => $editor,
3535
                                     'editor' => $editor,
3729
                'area' => $filearea
Línea 3536... Línea 3730...
3536
                                     'area'=>$filearea);
3730
            );
-
 
3731
            $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign');
3537
            $button->set_callback_options('assign_portfolio_caller', $portfolioparams, 'mod_assign');
3732
            $fs = get_file_storage();
3538
            $fs = get_file_storage();
3733
 
3539
 
3734
            if ($files = $fs->get_area_files(
3540
            if ($files = $fs->get_area_files($this->context->id,
3735
                $this->context->id,
3541
                                             $component,
3736
                $component,
-
 
3737
                $filearea,
3542
                                             $filearea,
3738
                $submissionid,
3543
                                             $submissionid,
3739
                'timemodified',
3544
                                             'timemodified',
3740
                false
3545
                                             false)) {
3741
            )) {
3546
                $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
3742
                $button->set_formats(PORTFOLIO_FORMAT_RICHHTML);
Línea 3556... Línea 3752...
3556
     * Display a continue page after grading.
3752
     * Display a continue page after grading.
3557
     *
3753
     *
3558
     * @param string $message - The message to display.
3754
     * @param string $message - The message to display.
3559
     * @return string
3755
     * @return string
3560
     */
3756
     */
3561
    protected function view_savegrading_result($message) {
3757
    protected function view_savegrading_result($message)
-
 
3758
    {
3562
        $o = '';
3759
        $o = '';
3563
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3760
        $o .= $this->get_renderer()->render(new assign_header(
-
 
3761
            $this->get_instance(),
3564
                                                      $this->get_context(),
3762
            $this->get_context(),
3565
                                                      $this->show_intro(),
3763
            $this->show_intro(),
3566
                                                      $this->get_course_module()->id,
3764
            $this->get_course_module()->id,
3567
                                                      get_string('savegradingresult', 'assign')));
3765
            get_string('savegradingresult', 'assign')
-
 
3766
        ));
3568
        $gradingresult = new assign_gradingmessage(get_string('savegradingresult', 'assign'),
3767
        $gradingresult = new assign_gradingmessage(
3569
                                                   $message,
3768
            get_string('savegradingresult', 'assign'),
-
 
3769
            $message,
3570
                                                   $this->get_course_module()->id);
3770
            $this->get_course_module()->id
-
 
3771
        );
3571
        $o .= $this->get_renderer()->render($gradingresult);
3772
        $o .= $this->get_renderer()->render($gradingresult);
3572
        $o .= $this->view_footer();
3773
        $o .= $this->view_footer();
3573
        return $o;
3774
        return $o;
3574
    }
3775
    }
3575
    /**
3776
    /**
3576
     * Display a continue page after quickgrading.
3777
     * Display a continue page after quickgrading.
3577
     *
3778
     *
3578
     * @param string $message - The message to display.
3779
     * @param string $message - The message to display.
3579
     * @return string
3780
     * @return string
3580
     */
3781
     */
3581
    protected function view_quickgrading_result($message) {
3782
    protected function view_quickgrading_result($message)
-
 
3783
    {
3582
        $o = '';
3784
        $o = '';
3583
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
3785
        $o .= $this->get_renderer()->render(new assign_header(
-
 
3786
            $this->get_instance(),
3584
                                                      $this->get_context(),
3787
            $this->get_context(),
3585
                                                      $this->show_intro(),
3788
            $this->show_intro(),
3586
                                                      $this->get_course_module()->id,
3789
            $this->get_course_module()->id,
3587
                                                      get_string('quickgradingresult', 'assign')));
3790
            get_string('quickgradingresult', 'assign')
-
 
3791
        ));
3588
        $gradingerror = in_array($message, $this->get_error_messages());
3792
        $gradingerror = in_array($message, $this->get_error_messages());
3589
        $lastpage = optional_param('lastpage', null, PARAM_INT);
3793
        $lastpage = optional_param('lastpage', null, PARAM_INT);
3590
        $gradingresult = new assign_gradingmessage(get_string('quickgradingresult', 'assign'),
3794
        $gradingresult = new assign_gradingmessage(
3591
                                                   $message,
3795
            get_string('quickgradingresult', 'assign'),
-
 
3796
            $message,
3592
                                                   $this->get_course_module()->id,
3797
            $this->get_course_module()->id,
3593
                                                   $gradingerror,
3798
            $gradingerror,
3594
                                                   $lastpage);
3799
            $lastpage
-
 
3800
        );
3595
        $o .= $this->get_renderer()->render($gradingresult);
3801
        $o .= $this->get_renderer()->render($gradingresult);
3596
        $o .= $this->view_footer();
3802
        $o .= $this->view_footer();
3597
        return $o;
3803
        return $o;
3598
    }
3804
    }
Línea 3599... Línea 3805...
3599
 
3805
 
3600
    /**
3806
    /**
3601
     * Display the page footer.
3807
     * Display the page footer.
3602
     *
3808
     *
3603
     * @return string
3809
     * @return string
3604
     */
3810
     */
-
 
3811
    protected function view_footer()
3605
    protected function view_footer() {
3812
    {
3606
        // When viewing the footer during PHPUNIT tests a set_state error is thrown.
3813
        // When viewing the footer during PHPUNIT tests a set_state error is thrown.
3607
        if (!PHPUNIT_TEST) {
3814
        if (!PHPUNIT_TEST) {
3608
            return $this->get_renderer()->render_footer();
3815
            return $this->get_renderer()->render_footer();
Línea 3615... Línea 3822...
3615
     * Throw an error if the permissions to view this users' group submission are missing.
3822
     * Throw an error if the permissions to view this users' group submission are missing.
3616
     *
3823
     *
3617
     * @param int $groupid Group id.
3824
     * @param int $groupid Group id.
3618
     * @throws required_capability_exception
3825
     * @throws required_capability_exception
3619
     */
3826
     */
3620
    public function require_view_group_submission($groupid) {
3827
    public function require_view_group_submission($groupid)
-
 
3828
    {
3621
        if (!$this->can_view_group_submission($groupid)) {
3829
        if (!$this->can_view_group_submission($groupid)) {
3622
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3830
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3623
        }
3831
        }
3624
    }
3832
    }
Línea 3627... Línea 3835...
3627
     * Throw an error if the permissions to view this users submission are missing.
3835
     * Throw an error if the permissions to view this users submission are missing.
3628
     *
3836
     *
3629
     * @throws required_capability_exception
3837
     * @throws required_capability_exception
3630
     * @return none
3838
     * @return none
3631
     */
3839
     */
3632
    public function require_view_submission($userid) {
3840
    public function require_view_submission($userid)
-
 
3841
    {
3633
        if (!$this->can_view_submission($userid)) {
3842
        if (!$this->can_view_submission($userid)) {
3634
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3843
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3635
        }
3844
        }
3636
    }
3845
    }
Línea 3639... Línea 3848...
3639
     * Throw an error if the permissions to view grades in this assignment are missing.
3848
     * Throw an error if the permissions to view grades in this assignment are missing.
3640
     *
3849
     *
3641
     * @throws required_capability_exception
3850
     * @throws required_capability_exception
3642
     * @return none
3851
     * @return none
3643
     */
3852
     */
3644
    public function require_view_grades() {
3853
    public function require_view_grades()
-
 
3854
    {
3645
        if (!$this->can_view_grades()) {
3855
        if (!$this->can_view_grades()) {
3646
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3856
            throw new required_capability_exception($this->context, 'mod/assign:viewgrades', 'nopermission', '');
3647
        }
3857
        }
3648
    }
3858
    }
Línea 3651... Línea 3861...
3651
     * Does this user have view grade or grade permission for this assignment?
3861
     * Does this user have view grade or grade permission for this assignment?
3652
     *
3862
     *
3653
     * @param mixed $groupid int|null when is set to a value, use this group instead calculating it
3863
     * @param mixed $groupid int|null when is set to a value, use this group instead calculating it
3654
     * @return bool
3864
     * @return bool
3655
     */
3865
     */
3656
    public function can_view_grades($groupid = null) {
3866
    public function can_view_grades($groupid = null)
-
 
3867
    {
3657
        // Permissions check.
3868
        // Permissions check.
3658
        if (!has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) {
3869
        if (!has_any_capability(array('mod/assign:viewgrades', 'mod/assign:grade'), $this->context)) {
3659
            return false;
3870
            return false;
3660
        }
3871
        }
3661
        // Checks for the edge case when user belongs to no groups and groupmode is sep.
3872
        // Checks for the edge case when user belongs to no groups and groupmode is sep.
Línea 3674... Línea 3885...
3674
     * Does this user have grade permission for this assignment?
3885
     * Does this user have grade permission for this assignment?
3675
     *
3886
     *
3676
     * @param int|stdClass $user The object or id of the user who will do the editing (default to current user).
3887
     * @param int|stdClass $user The object or id of the user who will do the editing (default to current user).
3677
     * @return bool
3888
     * @return bool
3678
     */
3889
     */
3679
    public function can_grade($user = null) {
3890
    public function can_grade($user = null)
-
 
3891
    {
3680
        // Permissions check.
3892
        // Permissions check.
3681
        if (!has_capability('mod/assign:grade', $this->context, $user)) {
3893
        if (!has_capability('mod/assign:grade', $this->context, $user)) {
3682
            return false;
3894
            return false;
3683
        }
3895
        }
Línea 3689... Línea 3901...
3689
     * Download a zip file of all assignment submissions.
3901
     * Download a zip file of all assignment submissions.
3690
     *
3902
     *
3691
     * @param array|null $userids Array of user ids to download assignment submissions in a zip file
3903
     * @param array|null $userids Array of user ids to download assignment submissions in a zip file
3692
     * @return string - If an error occurs, this will contain the error page.
3904
     * @return string - If an error occurs, this will contain the error page.
3693
     */
3905
     */
3694
    protected function download_submissions($userids = null) {
3906
    protected function download_submissions($userids = null)
-
 
3907
    {
3695
        $downloader = new downloader($this, $userids ?: null);
3908
        $downloader = new downloader($this, $userids ?: null);
3696
        if ($downloader->load_filelist()) {
3909
        if ($downloader->load_filelist()) {
3697
            $downloader->download_zip();
3910
            $downloader->download_zip();
3698
        }
3911
        }
3699
        // Show some notification if we have nothing to download.
3912
        // Show some notification if we have nothing to download.
Línea 3715... Línea 3928...
3715
    }
3928
    }
Línea 3716... Línea 3929...
3716
 
3929
 
3717
    /**
3930
    /**
3718
     * @deprecated since 2.7 - Use new events system instead.
3931
     * @deprecated since 2.7 - Use new events system instead.
3719
     */
3932
     */
-
 
3933
    public function add_to_log()
3720
    public function add_to_log() {
3934
    {
3721
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
3935
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
Línea 3722... Línea 3936...
3722
    }
3936
    }
3723
 
3937
 
3724
    /**
3938
    /**
3725
     * Lazy load the page renderer and expose the renderer to plugins.
3939
     * Lazy load the page renderer and expose the renderer to plugins.
3726
     *
3940
     *
3727
     * @return assign_renderer
3941
     * @return assign_renderer
-
 
3942
     */
3728
     */
3943
    public function get_renderer()
3729
    public function get_renderer() {
3944
    {
3730
        global $PAGE;
3945
        global $PAGE;
3731
        if ($this->output) {
3946
        if ($this->output) {
3732
            return $this->output;
3947
            return $this->output;
Línea 3745... Línea 3960...
3745
     * @param int $userid The id of the user whose submission we want or 0 in which case USER->id is used
3960
     * @param int $userid The id of the user whose submission we want or 0 in which case USER->id is used
3746
     * @param bool $create If set to true a new submission object will be created in the database with the status set to "new".
3961
     * @param bool $create If set to true a new submission object will be created in the database with the status set to "new".
3747
     * @param int $attemptnumber - -1 means the latest attempt
3962
     * @param int $attemptnumber - -1 means the latest attempt
3748
     * @return stdClass|false The submission
3963
     * @return stdClass|false The submission
3749
     */
3964
     */
3750
    public function get_user_submission($userid, $create, $attemptnumber=-1) {
3965
    public function get_user_submission($userid, $create, $attemptnumber = -1)
-
 
3966
    {
3751
        global $DB, $USER;
3967
        global $DB, $USER;
Línea 3752... Línea 3968...
3752
 
3968
 
3753
        if (!$userid) {
3969
        if (!$userid) {
3754
            $userid = $USER->id;
3970
            $userid = $USER->id;
3755
        }
3971
        }
3756
        // If the userid is not null then use userid.
3972
        // If the userid is not null then use userid.
3757
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid, 'groupid'=>0);
3973
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid, 'groupid' => 0);
3758
        if ($attemptnumber >= 0) {
3974
        if ($attemptnumber >= 0) {
3759
            $params['attemptnumber'] = $attemptnumber;
3975
            $params['attemptnumber'] = $attemptnumber;
Línea 3760... Línea 3976...
3760
        }
3976
        }
Línea 3790... Línea 4006...
3790
            } else {
4006
            } else {
3791
                $submission->attemptnumber = 0;
4007
                $submission->attemptnumber = 0;
3792
            }
4008
            }
3793
            // Work out if this is the latest submission.
4009
            // Work out if this is the latest submission.
3794
            $submission->latest = 0;
4010
            $submission->latest = 0;
3795
            $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid, 'groupid'=>0);
4011
            $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid, 'groupid' => 0);
3796
            if ($attemptnumber == -1) {
4012
            if ($attemptnumber == -1) {
3797
                // This is a new submission so it must be the latest.
4013
                // This is a new submission so it must be the latest.
3798
                $submission->latest = 1;
4014
                $submission->latest = 1;
3799
            } else {
4015
            } else {
3800
                // We need to work this out.
4016
                // We need to work this out.
Línea 3823... Línea 4039...
3823
     * Load the submission object from it's id.
4039
     * Load the submission object from it's id.
3824
     *
4040
     *
3825
     * @param int $submissionid The id of the submission we want
4041
     * @param int $submissionid The id of the submission we want
3826
     * @return stdClass The submission
4042
     * @return stdClass The submission
3827
     */
4043
     */
3828
    protected function get_submission($submissionid) {
4044
    protected function get_submission($submissionid)
-
 
4045
    {
3829
        global $DB;
4046
        global $DB;
Línea 3830... Línea 4047...
3830
 
4047
 
3831
        $params = array('assignment'=>$this->get_instance()->id, 'id'=>$submissionid);
4048
        $params = array('assignment' => $this->get_instance()->id, 'id' => $submissionid);
3832
        return $DB->get_record('assign_submission', $params, '*', MUST_EXIST);
4049
        return $DB->get_record('assign_submission', $params, '*', MUST_EXIST);
Línea 3833... Línea 4050...
3833
    }
4050
    }
3834
 
4051
 
Línea 3838... Línea 4055...
3838
     *
4055
     *
3839
     * @param int $userid The user we are getting the flags for.
4056
     * @param int $userid The user we are getting the flags for.
3840
     * @param bool $create If true the flags record will be created if it does not exist
4057
     * @param bool $create If true the flags record will be created if it does not exist
3841
     * @return stdClass The flags record
4058
     * @return stdClass The flags record
3842
     */
4059
     */
3843
    public function get_user_flags($userid, $create) {
4060
    public function get_user_flags($userid, $create)
-
 
4061
    {
3844
        global $DB, $USER;
4062
        global $DB, $USER;
Línea 3845... Línea 4063...
3845
 
4063
 
3846
        // If the userid is not null then use userid.
4064
        // If the userid is not null then use userid.
3847
        if (!$userid) {
4065
        if (!$userid) {
3848
            $userid = $USER->id;
4066
            $userid = $USER->id;
Línea 3849... Línea 4067...
3849
        }
4067
        }
Línea 3850... Línea 4068...
3850
 
4068
 
Línea 3851... Línea 4069...
3851
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
4069
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
3852
 
4070
 
Línea 3881... Línea 4099...
3881
     * @param int $userid The user we are grading
4099
     * @param int $userid The user we are grading
3882
     * @param bool $create If true the grade will be created if it does not exist
4100
     * @param bool $create If true the grade will be created if it does not exist
3883
     * @param int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.
4101
     * @param int $attemptnumber The attempt number to retrieve the grade for. -1 means the latest submission.
3884
     * @return stdClass The grade record
4102
     * @return stdClass The grade record
3885
     */
4103
     */
3886
    public function get_user_grade($userid, $create, $attemptnumber=-1) {
4104
    public function get_user_grade($userid, $create, $attemptnumber = -1)
-
 
4105
    {
3887
        global $DB, $USER;
4106
        global $DB, $USER;
Línea 3888... Línea 4107...
3888
 
4107
 
3889
        // If the userid is not null then use userid.
4108
        // If the userid is not null then use userid.
3890
        if (!$userid) {
4109
        if (!$userid) {
3891
            $userid = $USER->id;
4110
            $userid = $USER->id;
3892
        }
4111
        }
Línea 3893... Línea 4112...
3893
        $submission = null;
4112
        $submission = null;
3894
 
4113
 
3895
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
4114
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
3896
        if ($attemptnumber < 0 || $create) {
4115
        if ($attemptnumber < 0 || $create) {
3897
            // Make sure this grade matches the latest submission attempt.
4116
            // Make sure this grade matches the latest submission attempt.
3898
            if ($this->get_instance()->teamsubmission) {
4117
            if ($this->get_instance()->teamsubmission) {
Línea 3945... Línea 4164...
3945
     * This will retrieve a grade object from the db.
4164
     * This will retrieve a grade object from the db.
3946
     *
4165
     *
3947
     * @param int $gradeid The id of the grade
4166
     * @param int $gradeid The id of the grade
3948
     * @return stdClass The grade record
4167
     * @return stdClass The grade record
3949
     */
4168
     */
3950
    protected function get_grade($gradeid) {
4169
    protected function get_grade($gradeid)
-
 
4170
    {
3951
        global $DB;
4171
        global $DB;
Línea 3952... Línea 4172...
3952
 
4172
 
3953
        $params = array('assignment'=>$this->get_instance()->id, 'id'=>$gradeid);
4173
        $params = array('assignment' => $this->get_instance()->id, 'id' => $gradeid);
3954
        return $DB->get_record('assign_grades', $params, '*', MUST_EXIST);
4174
        return $DB->get_record('assign_grades', $params, '*', MUST_EXIST);
Línea 3955... Línea 4175...
3955
    }
4175
    }
3956
 
4176
 
3957
    /**
4177
    /**
3958
     * Print the grading page for a single user submission.
4178
     * Print the grading page for a single user submission.
3959
     *
4179
     *
3960
     * @param array $args Optional args array (better than pulling args from _GET and _POST)
4180
     * @param array $args Optional args array (better than pulling args from _GET and _POST)
3961
     * @return string
4181
     * @return string
-
 
4182
     */
3962
     */
4183
    protected function view_single_grading_panel($args)
Línea 3963... Línea 4184...
3963
    protected function view_single_grading_panel($args) {
4184
    {
Línea 3964... Línea 4185...
3964
        global $DB, $CFG;
4185
        global $DB, $CFG;
Línea 3998... Línea 4219...
3998
            $groupid = 0;
4219
            $groupid = 0;
3999
            if ($submissiongroup) {
4220
            if ($submissiongroup) {
4000
                $groupid = $submissiongroup->id;
4221
                $groupid = $submissiongroup->id;
4001
            }
4222
            }
4002
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4223
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4003
 
-
 
4004
        }
4224
        }
Línea 4005... Línea 4225...
4005
 
4225
 
4006
        // Get the requested grade.
4226
        // Get the requested grade.
4007
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
4227
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
Línea 4014... Línea 4234...
4014
            }
4234
            }
4015
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4235
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4016
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4236
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4017
            $usergroups = $this->get_all_groups($user->id);
4237
            $usergroups = $this->get_all_groups($user->id);
Línea 4018... Línea 4238...
4018
 
4238
 
-
 
4239
            $submissionstatus = new assign_submission_status_compact(
4019
            $submissionstatus = new assign_submission_status_compact($instance->allowsubmissionsfromdate,
4240
                $instance->allowsubmissionsfromdate,
4020
                                                                     $instance->alwaysshowdescription,
4241
                $instance->alwaysshowdescription,
4021
                                                                     $submission,
4242
                $submission,
4022
                                                                     $instance->teamsubmission,
4243
                $instance->teamsubmission,
4023
                                                                     $teamsubmission,
4244
                $teamsubmission,
4024
                                                                     $submissiongroup,
4245
                $submissiongroup,
4025
                                                                     $notsubmitted,
4246
                $notsubmitted,
4026
                                                                     $this->is_any_submission_plugin_enabled(),
4247
                $this->is_any_submission_plugin_enabled(),
4027
                                                                     $submissionlocked,
4248
                $submissionlocked,
4028
                                                                     $this->is_graded($userid),
4249
                $this->is_graded($userid),
4029
                                                                     $instance->duedate,
4250
                $instance->duedate,
4030
                                                                     $instance->cutoffdate,
4251
                $instance->cutoffdate,
4031
                                                                     $this->get_submission_plugins(),
4252
                $this->get_submission_plugins(),
4032
                                                                     $this->get_return_action(),
4253
                $this->get_return_action(),
4033
                                                                     $this->get_return_params(),
4254
                $this->get_return_params(),
4034
                                                                     $this->get_course_module()->id,
4255
                $this->get_course_module()->id,
4035
                                                                     $this->get_course()->id,
4256
                $this->get_course()->id,
4036
                                                                     assign_submission_status::GRADER_VIEW,
4257
                assign_submission_status::GRADER_VIEW,
4037
                                                                     $showedit,
4258
                $showedit,
4038
                                                                     false,
4259
                false,
4039
                                                                     $viewfullnames,
4260
                $viewfullnames,
4040
                                                                     $extensionduedate,
4261
                $extensionduedate,
4041
                                                                     $this->get_context(),
4262
                $this->get_context(),
4042
                                                                     $this->is_blind_marking(),
4263
                $this->is_blind_marking(),
4043
                                                                     '',
4264
                '',
4044
                                                                     $instance->attemptreopenmethod,
4265
                $instance->attemptreopenmethod,
4045
                                                                     $instance->maxattempts,
4266
                $instance->maxattempts,
4046
                                                                     $this->get_grading_status($userid),
4267
                $this->get_grading_status($userid),
4047
                                                                     $instance->preventsubmissionnotingroup,
4268
                $instance->preventsubmissionnotingroup,
4048
                                                                     $usergroups,
4269
                $usergroups,
-
 
4270
                $instance->timelimit
4049
                                                                     $instance->timelimit);
4271
            );
4050
            $o .= $this->get_renderer()->render($submissionstatus);
4272
            $o .= $this->get_renderer()->render($submissionstatus);
Línea 4051... Línea 4273...
4051
        }
4273
        }
4052
 
4274
 
Línea 4069... Línea 4291...
4069
 
4291
 
4070
        // Warning if required.
4292
        // Warning if required.
Línea 4071... Línea 4293...
4071
        $allsubmissions = $this->get_all_submissions($userid);
4293
        $allsubmissions = $this->get_all_submissions($userid);
-
 
4294
 
4072
 
4295
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4073
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4296
            $params = array(
-
 
4297
                'attemptnumber' => $attemptnumber + 1,
4074
            $params = array('attemptnumber' => $attemptnumber + 1,
4298
                'totalattempts' => count($allsubmissions)
4075
                            'totalattempts' => count($allsubmissions));
4299
            );
4076
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
4300
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
Línea -... Línea 4301...
-
 
4301
            $o .= $this->get_renderer()->notification($message);
4077
            $o .= $this->get_renderer()->notification($message);
4302
        }
4078
        }
4303
 
4079
 
4304
        $pagination = array(
4080
        $pagination = array('rownum' => $rownum,
4305
            'rownum' => $rownum,
4081
                            'useridlistid' => 0,
4306
            'useridlistid' => 0,
4082
                            'last' => $last,
4307
            'last' => $last,
-
 
4308
            'userid' => $userid,
Línea 4083... Línea 4309...
4083
                            'userid' => $userid,
4309
            'attemptnumber' => $attemptnumber,
4084
                            'attemptnumber' => $attemptnumber,
4310
            'gradingpanel' => true
4085
                            'gradingpanel' => true);
4311
        );
4086
 
4312
 
4087
        if (!empty($args['formdata'])) {
4313
        if (!empty($args['formdata'])) {
4088
            $data = (array) $data;
4314
            $data = (array) $data;
-
 
4315
            $data = (object) array_merge($data, $args['formdata']);
4089
            $data = (object) array_merge($data, $args['formdata']);
4316
        }
4090
        }
4317
        $formparams = array($this, $data, $pagination);
4091
        $formparams = array($this, $data, $pagination);
4318
        $mform = new mod_assign_grade_form(
4092
        $mform = new mod_assign_grade_form(null,
4319
            null,
-
 
4320
            $formparams,
Línea 4093... Línea 4321...
4093
                                           $formparams,
4321
            'post',
4094
                                           'post',
4322
            '',
4095
                                           '',
4323
            array('class' => 'gradeform')
4096
                                           array('class' => 'gradeform'));
4324
        );
Línea 4103... Línea 4331...
4103
 
4331
 
Línea 4104... Línea 4332...
4104
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4332
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4105
 
4333
 
4106
        if (count($allsubmissions) > 1) {
4334
        if (count($allsubmissions) > 1) {
-
 
4335
            $allgrades = $this->get_all_grades($userid);
4107
            $allgrades = $this->get_all_grades($userid);
4336
            $history = new assign_attempt_history_chooser(
4108
            $history = new assign_attempt_history_chooser($allsubmissions,
4337
                $allsubmissions,
4109
                                                          $allgrades,
4338
                $allgrades,
-
 
4339
                $this->get_course_module()->id,
Línea 4110... Línea 4340...
4110
                                                          $this->get_course_module()->id,
4340
                $userid
4111
                                                          $userid);
4341
            );
Línea 4112... Línea 4342...
4112
 
4342
 
Línea 4122... Línea 4352...
4122
     * Print the grading page for a single user submission.
4352
     * Print the grading page for a single user submission.
4123
     *
4353
     *
4124
     * @param moodleform $mform
4354
     * @param moodleform $mform
4125
     * @return string
4355
     * @return string
4126
     */
4356
     */
4127
    protected function view_single_grade_page($mform) {
4357
    protected function view_single_grade_page($mform)
-
 
4358
    {
4128
        global $DB, $CFG, $SESSION;
4359
        global $DB, $CFG, $SESSION;
Línea 4129... Línea 4360...
4129
 
4360
 
4130
        $o = '';
4361
        $o = '';
Línea 4131... Línea 4362...
4131
        $instance = $this->get_instance();
4362
        $instance = $this->get_instance();
Línea 4132... Línea 4363...
4132
 
4363
 
4133
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
4364
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
Línea 4134... Línea 4365...
4134
 
4365
 
-
 
4366
        // Need submit permission to submit an assignment.
4135
        // Need submit permission to submit an assignment.
4367
        require_capability('mod/assign:grade', $this->context);
4136
        require_capability('mod/assign:grade', $this->context);
4368
 
4137
 
4369
        $header = new assign_header(
4138
        $header = new assign_header($instance,
4370
            $instance,
-
 
4371
            $this->get_context(),
4139
                                    $this->get_context(),
4372
            false,
Línea 4140... Línea 4373...
4140
                                    false,
4373
            $this->get_course_module()->id,
4141
                                    $this->get_course_module()->id,
4374
            get_string('grading', 'assign')
4142
                                    get_string('grading', 'assign'));
4375
        );
Línea 4172... Línea 4405...
4172
 
4405
 
4173
        $user = $DB->get_record('user', array('id' => $userid));
4406
        $user = $DB->get_record('user', array('id' => $userid));
4174
        if ($user) {
4407
        if ($user) {
4175
            $this->update_effective_access($userid);
4408
            $this->update_effective_access($userid);
4176
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4409
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
-
 
4410
            $usersummary = new assign_user_summary(
4177
            $usersummary = new assign_user_summary($user,
4411
                $user,
4178
                                                   $this->get_course()->id,
4412
                $this->get_course()->id,
4179
                                                   $viewfullnames,
4413
                $viewfullnames,
4180
                                                   $this->is_blind_marking(),
4414
                $this->is_blind_marking(),
4181
                                                   $this->get_uniqueid_for_user($user->id),
4415
                $this->get_uniqueid_for_user($user->id),
4182
                                                   // TODO Does not support custom user profile fields (MDL-70456).
4416
                // TODO Does not support custom user profile fields (MDL-70456).
4183
                                                   \core_user\fields::get_identity_fields($this->get_context(), false),
4417
                \core_user\fields::get_identity_fields($this->get_context(), false),
-
 
4418
                !$this->is_active_user($userid)
4184
                                                   !$this->is_active_user($userid));
4419
            );
4185
            $o .= $this->get_renderer()->render($usersummary);
4420
            $o .= $this->get_renderer()->render($usersummary);
4186
        }
4421
        }
4187
        $submission = $this->get_user_submission($userid, false, $attemptnumber);
4422
        $submission = $this->get_user_submission($userid, false, $attemptnumber);
4188
        $submissiongroup = null;
4423
        $submissiongroup = null;
Línea 4194... Línea 4429...
4194
            $groupid = 0;
4429
            $groupid = 0;
4195
            if ($submissiongroup) {
4430
            if ($submissiongroup) {
4196
                $groupid = $submissiongroup->id;
4431
                $groupid = $submissiongroup->id;
4197
            }
4432
            }
4198
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4433
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
4199
 
-
 
4200
        }
4434
        }
Línea 4201... Línea 4435...
4201
 
4435
 
4202
        // Get the requested grade.
4436
        // Get the requested grade.
4203
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
4437
        $grade = $this->get_user_grade($userid, false, $attemptnumber);
Línea 4209... Línea 4443...
4209
                $extensionduedate = $flags->extensionduedate;
4443
                $extensionduedate = $flags->extensionduedate;
4210
            }
4444
            }
4211
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4445
            $showedit = $this->submissions_open($userid) && ($this->is_any_submission_plugin_enabled());
4212
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4446
            $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
4213
            $usergroups = $this->get_all_groups($user->id);
4447
            $usergroups = $this->get_all_groups($user->id);
4214
            $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
4448
            $submissionstatus = new assign_submission_status(
-
 
4449
                $instance->allowsubmissionsfromdate,
4215
                                                             $instance->alwaysshowdescription,
4450
                $instance->alwaysshowdescription,
4216
                                                             $submission,
4451
                $submission,
4217
                                                             $instance->teamsubmission,
4452
                $instance->teamsubmission,
4218
                                                             $teamsubmission,
4453
                $teamsubmission,
4219
                                                             $submissiongroup,
4454
                $submissiongroup,
4220
                                                             $notsubmitted,
4455
                $notsubmitted,
4221
                                                             $this->is_any_submission_plugin_enabled(),
4456
                $this->is_any_submission_plugin_enabled(),
4222
                                                             $submissionlocked,
4457
                $submissionlocked,
4223
                                                             $this->is_graded($userid),
4458
                $this->is_graded($userid),
4224
                                                             $instance->duedate,
4459
                $instance->duedate,
4225
                                                             $instance->cutoffdate,
4460
                $instance->cutoffdate,
4226
                                                             $this->get_submission_plugins(),
4461
                $this->get_submission_plugins(),
4227
                                                             $this->get_return_action(),
4462
                $this->get_return_action(),
4228
                                                             $this->get_return_params(),
4463
                $this->get_return_params(),
4229
                                                             $this->get_course_module()->id,
4464
                $this->get_course_module()->id,
4230
                                                             $this->get_course()->id,
4465
                $this->get_course()->id,
4231
                                                             assign_submission_status::GRADER_VIEW,
4466
                assign_submission_status::GRADER_VIEW,
4232
                                                             $showedit,
4467
                $showedit,
4233
                                                             false,
4468
                false,
4234
                                                             $viewfullnames,
4469
                $viewfullnames,
4235
                                                             $extensionduedate,
4470
                $extensionduedate,
4236
                                                             $this->get_context(),
4471
                $this->get_context(),
4237
                                                             $this->is_blind_marking(),
4472
                $this->is_blind_marking(),
4238
                                                             '',
4473
                '',
4239
                                                             $instance->attemptreopenmethod,
4474
                $instance->attemptreopenmethod,
4240
                                                             $instance->maxattempts,
4475
                $instance->maxattempts,
4241
                                                             $this->get_grading_status($userid),
4476
                $this->get_grading_status($userid),
4242
                                                             $instance->preventsubmissionnotingroup,
4477
                $instance->preventsubmissionnotingroup,
4243
                                                             $usergroups,
4478
                $usergroups,
4244
                                                             $instance->timelimit);
4479
                $instance->timelimit
-
 
4480
            );
4245
            $o .= $this->get_renderer()->render($submissionstatus);
4481
            $o .= $this->get_renderer()->render($submissionstatus);
4246
        }
4482
        }
Línea 4247... Línea 4483...
4247
 
4483
 
4248
        if ($grade) {
4484
        if ($grade) {
Línea 4264... Línea 4500...
4264
 
4500
 
4265
        // Warning if required.
4501
        // Warning if required.
Línea 4266... Línea 4502...
4266
        $allsubmissions = $this->get_all_submissions($userid);
4502
        $allsubmissions = $this->get_all_submissions($userid);
-
 
4503
 
4267
 
4504
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4268
        if ($attemptnumber != -1 && ($attemptnumber + 1) != count($allsubmissions)) {
4505
            $params = array(
-
 
4506
                'attemptnumber' => $attemptnumber + 1,
4269
            $params = array('attemptnumber'=>$attemptnumber + 1,
4507
                'totalattempts' => count($allsubmissions)
4270
                            'totalattempts'=>count($allsubmissions));
4508
            );
4271
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
4509
            $message = get_string('editingpreviousfeedbackwarning', 'assign', $params);
Línea 4272... Línea 4510...
4272
            $o .= $this->get_renderer()->notification($message);
4510
            $o .= $this->get_renderer()->notification($message);
4273
        }
4511
        }
-
 
4512
 
4274
 
4513
        // Now show the grading form.
4275
        // Now show the grading form.
4514
        if (!$mform) {
4276
        if (!$mform) {
4515
            $pagination = array(
4277
            $pagination = array('rownum' => $rownum,
4516
                'rownum' => $rownum,
4278
                                'useridlistid' => $useridlistid,
4517
                'useridlistid' => $useridlistid,
-
 
4518
                'last' => $last,
4279
                                'last' => $last,
4519
                'userid' => $userid,
4280
                                'userid' => $userid,
4520
                'attemptnumber' => $attemptnumber
-
 
4521
            );
4281
                                'attemptnumber' => $attemptnumber);
4522
            $formparams = array($this, $data, $pagination);
4282
            $formparams = array($this, $data, $pagination);
4523
            $mform = new mod_assign_grade_form(
4283
            $mform = new mod_assign_grade_form(null,
4524
                null,
4284
                                               $formparams,
4525
                $formparams,
-
 
4526
                'post',
4285
                                               'post',
4527
                '',
Línea 4286... Línea 4528...
4286
                                               '',
4528
                array('class' => 'gradeform')
Línea 4287... Línea 4529...
4287
                                               array('class'=>'gradeform'));
4529
            );
4288
        }
4530
        }
4289
 
4531
 
-
 
4532
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4290
        $o .= $this->get_renderer()->render(new assign_form('gradingform', $mform));
4533
 
4291
 
4534
        if (count($allsubmissions) > 1 && $attemptnumber == -1) {
4292
        if (count($allsubmissions) > 1 && $attemptnumber == -1) {
4535
            $allgrades = $this->get_all_grades($userid);
4293
            $allgrades = $this->get_all_grades($userid);
4536
            $history = new assign_attempt_history(
4294
            $history = new assign_attempt_history($allsubmissions,
4537
                $allsubmissions,
4295
                                                  $allgrades,
4538
                $allgrades,
4296
                                                  $this->get_submission_plugins(),
4539
                $this->get_submission_plugins(),
4297
                                                  $this->get_feedback_plugins(),
4540
                $this->get_feedback_plugins(),
4298
                                                  $this->get_course_module()->id,
4541
                $this->get_course_module()->id,
-
 
4542
                $this->get_return_action(),
Línea 4299... Línea 4543...
4299
                                                  $this->get_return_action(),
4543
                $this->get_return_params(),
4300
                                                  $this->get_return_params(),
4544
                true,
Línea 4301... Línea 4545...
4301
                                                  true,
4545
                $useridlistid,
Línea 4314... Línea 4558...
4314
    /**
4558
    /**
4315
     * Show a confirmation page to make sure they want to remove submission data.
4559
     * Show a confirmation page to make sure they want to remove submission data.
4316
     *
4560
     *
4317
     * @return string
4561
     * @return string
4318
     */
4562
     */
4319
    protected function view_remove_submission_confirm() {
4563
    protected function view_remove_submission_confirm()
-
 
4564
    {
4320
        global $USER;
4565
        global $USER;
Línea 4321... Línea 4566...
4321
 
4566
 
Línea 4322... Línea 4567...
4322
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4567
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4323
 
4568
 
4324
        if (!$this->can_edit_submission($userid, $USER->id)) {
4569
        if (!$this->can_edit_submission($userid, $USER->id)) {
4325
            throw new \moodle_exception('nopermission');
4570
            throw new \moodle_exception('nopermission');
Línea 4326... Línea 4571...
4326
        }
4571
        }
4327
        $user = core_user::get_user($userid, '*', MUST_EXIST);
4572
        $user = core_user::get_user($userid, '*', MUST_EXIST);
-
 
4573
 
4328
 
4574
        $o = '';
4329
        $o = '';
4575
        $header = new assign_header(
4330
        $header = new assign_header($this->get_instance(),
4576
            $this->get_instance(),
-
 
4577
            $this->get_context(),
4331
                                    $this->get_context(),
4578
            false,
Línea -... Línea 4579...
-
 
4579
            $this->get_course_module()->id
4332
                                    false,
4580
        );
4333
                                    $this->get_course_module()->id);
4581
        $o .= $this->get_renderer()->render($header);
4334
        $o .= $this->get_renderer()->render($header);
4582
 
4335
 
4583
        $urlparams = array(
-
 
4584
            'id' => $this->get_course_module()->id,
4336
        $urlparams = array('id' => $this->get_course_module()->id,
4585
            'action' => 'removesubmission',
Línea -... Línea 4586...
-
 
4586
            'userid' => $userid,
4337
                           'action' => 'removesubmission',
4587
            'sesskey' => sesskey()
4338
                           'userid' => $userid,
4588
        );
-
 
4589
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4339
                           'sesskey' => sesskey());
4590
 
Línea 4340... Línea 4591...
4340
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4591
        $urlparams = array(
4341
 
4592
            'id' => $this->get_course_module()->id,
4342
        $urlparams = array('id' => $this->get_course_module()->id,
4593
            'action' => 'view'
Línea 4354... Línea 4605...
4354
                $confirmstr = get_string('removesubmissionconfirmforstudentwithtimelimit', 'assign', $this->fullname($user));
4605
                $confirmstr = get_string('removesubmissionconfirmforstudentwithtimelimit', 'assign', $this->fullname($user));
4355
            } else {
4606
            } else {
4356
                $confirmstr = get_string('removesubmissionconfirmforstudent', 'assign', $this->fullname($user));
4607
                $confirmstr = get_string('removesubmissionconfirmforstudent', 'assign', $this->fullname($user));
4357
            }
4608
            }
4358
        }
4609
        }
4359
        $o .= $this->get_renderer()->confirm($confirmstr,
4610
        $o .= $this->get_renderer()->confirm(
-
 
4611
            $confirmstr,
4360
                                             $confirmurl,
4612
            $confirmurl,
4361
                                             $cancelurl);
4613
            $cancelurl
-
 
4614
        );
4362
        $o .= $this->view_footer();
4615
        $o .= $this->view_footer();
Línea 4363... Línea 4616...
4363
 
4616
 
Línea 4364... Línea 4617...
4364
        \mod_assign\event\remove_submission_form_viewed::create_from_user($this, $user)->trigger();
4617
        \mod_assign\event\remove_submission_form_viewed::create_from_user($this, $user)->trigger();
Línea 4370... Línea 4623...
4370
    /**
4623
    /**
4371
     * Show a confirmation page to make sure they want to release student identities.
4624
     * Show a confirmation page to make sure they want to release student identities.
4372
     *
4625
     *
4373
     * @return string
4626
     * @return string
4374
     */
4627
     */
4375
    protected function view_reveal_identities_confirm() {
4628
    protected function view_reveal_identities_confirm()
-
 
4629
    {
4376
        require_capability('mod/assign:revealidentities', $this->get_context());
4630
        require_capability('mod/assign:revealidentities', $this->get_context());
Línea 4377... Línea 4631...
4377
 
4631
 
4378
        $o = '';
4632
        $o = '';
-
 
4633
        $header = new assign_header(
4379
        $header = new assign_header($this->get_instance(),
4634
            $this->get_instance(),
4380
                                    $this->get_context(),
4635
            $this->get_context(),
4381
                                    false,
4636
            false,
-
 
4637
            $this->get_course_module()->id
4382
                                    $this->get_course_module()->id);
4638
        );
Línea -... Línea 4639...
-
 
4639
        $o .= $this->get_renderer()->render($header);
4383
        $o .= $this->get_renderer()->render($header);
4640
 
4384
 
4641
        $urlparams = array(
4385
        $urlparams = array('id'=>$this->get_course_module()->id,
4642
            'id' => $this->get_course_module()->id,
-
 
4643
            'action' => 'revealidentitiesconfirm',
4386
                           'action'=>'revealidentitiesconfirm',
4644
            'sesskey' => sesskey()
Línea -... Línea 4645...
-
 
4645
        );
4387
                           'sesskey'=>sesskey());
4646
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4388
        $confirmurl = new moodle_url('/mod/assign/view.php', $urlparams);
4647
 
-
 
4648
        $urlparams = array(
4389
 
4649
            'id' => $this->get_course_module()->id,
Línea -... Línea 4650...
-
 
4650
            'action' => 'grading'
4390
        $urlparams = array('id'=>$this->get_course_module()->id,
4651
        );
4391
                           'action'=>'grading');
4652
        $cancelurl = new moodle_url('/mod/assign/view.php', $urlparams);
4392
        $cancelurl = new moodle_url('/mod/assign/view.php', $urlparams);
4653
 
-
 
4654
        $o .= $this->get_renderer()->confirm(
4393
 
4655
            get_string('revealidentitiesconfirm', 'assign'),
Línea 4394... Línea 4656...
4394
        $o .= $this->get_renderer()->confirm(get_string('revealidentitiesconfirm', 'assign'),
4656
            $confirmurl,
Línea 4395... Línea 4657...
4395
                                             $confirmurl,
4657
            $cancelurl
Línea 4404... Línea 4666...
4404
    /**
4666
    /**
4405
     * View a link to go back to the previous page. Uses url parameters returnaction and returnparams.
4667
     * View a link to go back to the previous page. Uses url parameters returnaction and returnparams.
4406
     *
4668
     *
4407
     * @return string
4669
     * @return string
4408
     */
4670
     */
4409
    protected function view_return_links() {
4671
    protected function view_return_links()
-
 
4672
    {
4410
        $returnaction = optional_param('returnaction', '', PARAM_ALPHA);
4673
        $returnaction = optional_param('returnaction', '', PARAM_ALPHA);
4411
        $returnparams = optional_param('returnparams', '', PARAM_TEXT);
4674
        $returnparams = optional_param('returnparams', '', PARAM_TEXT);
Línea 4412... Línea 4675...
4412
 
4675
 
4413
        $params = array();
4676
        $params = array();
Línea 4423... Línea 4686...
4423
    /**
4686
    /**
4424
     * View the grading table of all submissions for this assignment.
4687
     * View the grading table of all submissions for this assignment.
4425
     *
4688
     *
4426
     * @return string
4689
     * @return string
4427
     */
4690
     */
4428
    protected function view_grading_table() {
4691
    protected function view_grading_table()
-
 
4692
    {
4429
        global $USER, $CFG, $SESSION, $PAGE;
4693
        global $USER, $CFG, $SESSION, $PAGE;
Línea 4430... Línea 4694...
4430
 
4694
 
4431
        // Include grading options form.
4695
        // Include grading options form.
4432
        require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
4696
        require_once($CFG->dirroot . '/mod/assign/gradingoptionsform.php');
4433
        require_once($CFG->dirroot . '/mod/assign/quickgradingform.php');
4697
        require_once($CFG->dirroot . '/mod/assign/quickgradingform.php');
4434
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
4698
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
4435
        $o = '';
4699
        $o = '';
Línea 4436... Línea 4700...
4436
        $cmid = $this->get_course_module()->id;
4700
        $cmid = $this->get_course_module()->id;
-
 
4701
 
4437
 
4702
        $links = array();
4438
        $links = array();
4703
        if (
-
 
4704
            has_capability('gradereport/grader:view', $this->get_course_context()) &&
4439
        if (has_capability('gradereport/grader:view', $this->get_course_context()) &&
4705
            has_capability('moodle/grade:viewall', $this->get_course_context())
4440
                has_capability('moodle/grade:viewall', $this->get_course_context())) {
4706
        ) {
4441
            $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
4707
            $gradebookurl = '/grade/report/grader/index.php?id=' . $this->get_course()->id;
-
 
4708
            $links[$gradebookurl] = get_string('viewgradebook', 'assign');
4442
            $links[$gradebookurl] = get_string('viewgradebook', 'assign');
4709
        }
4443
        }
4710
        if (
-
 
4711
            $this->is_blind_marking() &&
4444
        if ($this->is_blind_marking() &&
4712
            has_capability('mod/assign:revealidentities', $this->get_context())
4445
                has_capability('mod/assign:revealidentities', $this->get_context())) {
4713
        ) {
4446
            $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities';
4714
            $revealidentitiesurl = '/mod/assign/view.php?id=' . $cmid . '&action=revealidentities';
4447
            $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
4715
            $links[$revealidentitiesurl] = get_string('revealidentities', 'assign');
4448
        }
4716
        }
4449
        foreach ($this->get_feedback_plugins() as $plugin) {
4717
        foreach ($this->get_feedback_plugins() as $plugin) {
4450
            if ($plugin->is_enabled() && $plugin->is_visible()) {
4718
            if ($plugin->is_enabled() && $plugin->is_visible()) {
4451
                foreach ($plugin->get_grading_actions() as $action => $description) {
4719
                foreach ($plugin->get_grading_actions() as $action => $description) {
4452
                    $url = '/mod/assign/view.php' .
4720
                    $url = '/mod/assign/view.php' .
4453
                           '?id=' .  $cmid .
4721
                        '?id=' .  $cmid .
4454
                           '&plugin=' . $plugin->get_type() .
4722
                        '&plugin=' . $plugin->get_type() .
4455
                           '&pluginsubtype=assignfeedback' .
4723
                        '&pluginsubtype=assignfeedback' .
4456
                           '&action=viewpluginpage&pluginaction=' . $action;
4724
                        '&action=viewpluginpage&pluginaction=' . $action;
4457
                    $links[$url] = $description;
4725
                    $links[$url] = $description;
4458
                }
4726
                }
Línea 4498... Línea 4766...
4498
        $markingworkflow = $this->get_instance()->markingworkflow;
4766
        $markingworkflow = $this->get_instance()->markingworkflow;
4499
        // Get marking states to show in form.
4767
        // Get marking states to show in form.
4500
        $markingworkflowoptions = $this->get_marking_workflow_filters();
4768
        $markingworkflowoptions = $this->get_marking_workflow_filters();
Línea 4501... Línea 4769...
4501
 
4769
 
4502
        // Print options for changing the filter and changing the number of results per page.
4770
        // Print options for changing the filter and changing the number of results per page.
-
 
4771
        $gradingoptionsformparams = array(
4503
        $gradingoptionsformparams = array('cm'=>$cmid,
4772
            'cm' => $cmid,
4504
                                          'contextid'=>$this->context->id,
4773
            'contextid' => $this->context->id,
4505
                                          'userid'=>$USER->id,
4774
            'userid' => $USER->id,
4506
                                          'submissionsenabled'=>$this->is_any_submission_plugin_enabled(),
4775
            'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
4507
                                          'showquickgrading'=>$showquickgrading,
4776
            'showquickgrading' => $showquickgrading,
4508
                                          'quickgrading'=>$quickgrading,
4777
            'quickgrading' => $quickgrading,
4509
                                          'markingworkflowopt'=>$markingworkflowoptions,
4778
            'markingworkflowopt' => $markingworkflowoptions,
4510
                                          'markingallocationopt'=>$markingallocationoptions,
4779
            'markingallocationopt' => $markingallocationoptions,
4511
                                          'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
4780
            'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
4512
                                          'showonlyactiveenrol' => $this->show_only_active_users(),
4781
            'showonlyactiveenrol' => $this->show_only_active_users(),
-
 
4782
            'downloadasfolders' => $downloadasfolders
4513
                                          'downloadasfolders' => $downloadasfolders);
4783
        );
4514
 
4784
 
4515
        $classoptions = array('class'=>'gradingoptionsform');
4785
        $classoptions = array('class' => 'gradingoptionsform');
-
 
4786
        $gradingoptionsform = new mod_assign_grading_options_form(
4516
        $gradingoptionsform = new mod_assign_grading_options_form(null,
4787
            null,
4517
                                                                  $gradingoptionsformparams,
4788
            $gradingoptionsformparams,
4518
                                                                  'post',
4789
            'post',
4519
                                                                  '',
4790
            '',
-
 
4791
            $classoptions
4520
                                                                  $classoptions);
4792
        );
4521
 
4793
 
-
 
4794
        $batchformparams = array(
4522
        $batchformparams = array('cm'=>$cmid,
4795
            'cm' => $cmid,
4523
                                 'submissiondrafts'=>$this->get_instance()->submissiondrafts,
4796
            'submissiondrafts' => $this->get_instance()->submissiondrafts,
4524
                                 'duedate'=>$this->get_instance()->duedate,
4797
            'duedate' => $this->get_instance()->duedate,
4525
                                 'attemptreopenmethod'=>$this->get_instance()->attemptreopenmethod,
4798
            'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod,
4526
                                 'feedbackplugins'=>$this->get_feedback_plugins(),
4799
            'feedbackplugins' => $this->get_feedback_plugins(),
4527
                                 'context'=>$this->get_context(),
4800
            'context' => $this->get_context(),
4528
                                 'markingworkflow'=>$markingworkflow,
4801
            'markingworkflow' => $markingworkflow,
-
 
4802
            'markingallocation' => $markingallocation
4529
                                 'markingallocation'=>$markingallocation);
4803
        );
4530
        $classoptions = [
4804
        $classoptions = [
4531
            'class' => 'gradingbatchoperationsform',
4805
            'class' => 'gradingbatchoperationsform',
4532
            'data-double-submit-protection' => 'off',
4806
            'data-double-submit-protection' => 'off',
Línea 4533... Línea 4807...
4533
        ];
4807
        ];
-
 
4808
 
4534
 
4809
        $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(
4535
        $gradingbatchoperationsform = new mod_assign_grading_batch_operations_form(null,
4810
            null,
4536
                                                                                   $batchformparams,
4811
            $batchformparams,
4537
                                                                                   'post',
4812
            'post',
-
 
4813
            '',
Línea 4538... Línea 4814...
4538
                                                                                   '',
4814
            $classoptions
4539
                                                                                   $classoptions);
4815
        );
4540
 
4816
 
4541
        $gradingoptionsdata = new stdClass();
4817
        $gradingoptionsdata = new stdClass();
4542
        $gradingoptionsdata->perpage = $perpage;
4818
        $gradingoptionsdata->perpage = $perpage;
4543
        $gradingoptionsdata->filter = $filter;
4819
        $gradingoptionsdata->filter = $filter;
Línea 4544... Línea 4820...
4544
        $gradingoptionsdata->markerfilter = $markerfilter;
4820
        $gradingoptionsdata->markerfilter = $markerfilter;
-
 
4821
        $gradingoptionsdata->workflowfilter = $workflowfilter;
4545
        $gradingoptionsdata->workflowfilter = $workflowfilter;
4822
        $gradingoptionsform->set_data($gradingoptionsdata);
-
 
4823
 
-
 
4824
        $buttons = new \mod_assign\output\grading_actionmenu(
4546
        $gradingoptionsform->set_data($gradingoptionsdata);
4825
            $this->get_course_module()->id,
4547
 
4826
            $this->is_any_submission_plugin_enabled(),
Línea 4548... Línea 4827...
4548
        $buttons = new \mod_assign\output\grading_actionmenu($this->get_course_module()->id,
4827
            $this->count_submissions()
Línea 4549... Línea 4828...
4549
             $this->is_any_submission_plugin_enabled(), $this->count_submissions());
4828
        );
-
 
4829
        $actionformtext = $this->get_renderer()->render($buttons);
4550
        $actionformtext = $this->get_renderer()->render($buttons);
4830
        $PAGE->activityheader->set_attrs(['hidecompletion' => true]);
4551
        $PAGE->activityheader->set_attrs(['hidecompletion' => true]);
4831
 
4552
 
4832
        $currenturl = new moodle_url('/mod/assign/view.php', ['id' => $this->get_course_module()->id, 'action' => 'grading']);
4553
        $currenturl = new moodle_url('/mod/assign/view.php', ['id' => $this->get_course_module()->id, 'action' => 'grading']);
4833
 
4554
 
4834
        $header = new assign_header(
4555
        $header = new assign_header($this->get_instance(),
4835
            $this->get_instance(),
4556
                                    $this->get_context(),
4836
            $this->get_context(),
-
 
4837
            false,
4557
                                    false,
4838
            $this->get_course_module()->id,
Línea 4558... Línea 4839...
4558
                                    $this->get_course_module()->id,
4839
            get_string('grading', 'assign'),
Línea 4559... Línea 4840...
4559
                                    get_string('grading', 'assign'),
4840
            '',
Línea 4578... Línea 4859...
4578
        if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) {
4859
        if ($this->is_blind_marking() && has_capability('mod/assign:viewblinddetails', $this->get_context())) {
4579
            $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
4860
            $o .= $this->get_renderer()->notification(get_string('blindmarkingenabledwarning', 'assign'), 'notifymessage');
4580
        }
4861
        }
Línea 4581... Línea 4862...
4581
 
4862
 
-
 
4863
        // Load and print the table of submissions.
-
 
4864
        $assignform = new assign_form(
-
 
4865
            'gradingoptionsform',
-
 
4866
            $gradingoptionsform,
-
 
4867
            'M.mod_assign.init_grading_options'
-
 
4868
        );
4582
        // Load and print the table of submissions.
4869
        $o .= $this->get_renderer()->render($assignform);
4583
        if ($showquickgrading && $quickgrading) {
-
 
4584
            $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
4870
        if ($showquickgrading && $quickgrading) {
4585
            $table = $this->get_renderer()->render($gradingtable);
4871
            $table = $this->get_renderer()->render($gradingtable);
-
 
4872
            $page = optional_param('page', null, PARAM_INT);
4586
            $page = optional_param('page', null, PARAM_INT);
4873
            $quickformparams = array(
4587
            $quickformparams = array('cm'=>$this->get_course_module()->id,
4874
                'cm' => $this->get_course_module()->id,
4588
                                     'gradingtable'=>$table,
4875
                'gradingtable' => $table,
4589
                                     'sendstudentnotifications' => $this->get_instance()->sendstudentnotifications,
4876
                'sendstudentnotifications' => $this->get_instance()->sendstudentnotifications,
-
 
4877
                'page' => $page
-
 
4878
            );
4590
                                     'page' => $page);
4879
            $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, true);
Línea 4591... Línea 4880...
4591
            $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
4880
            $quickgradingform = new mod_assign_quick_grading_form(null, $quickformparams);
4592
 
4881
 
4593
            $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
4882
            $o .= $this->get_renderer()->render(new assign_form('quickgradingform', $quickgradingform));
Línea 4608... Línea 4897...
4608
        if (count($users) != 0 && $this->can_grade()) {
4897
        if (count($users) != 0 && $this->can_grade()) {
4609
            // If no enrolled user in a course then don't display the batch operations feature.
4898
            // If no enrolled user in a course then don't display the batch operations feature.
4610
            $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform);
4899
            $assignform = new assign_form('gradingbatchoperationsform', $gradingbatchoperationsform);
4611
            $o .= $this->get_renderer()->render($assignform);
4900
            $o .= $this->get_renderer()->render($assignform);
4612
        }
4901
        }
4613
        $assignform = new assign_form('gradingoptionsform',
-
 
4614
                                      $gradingoptionsform,
-
 
4615
                                      'M.mod_assign.init_grading_options');
-
 
4616
        $o .= $this->get_renderer()->render($assignform);
-
 
4617
        return $o;
4902
        return $o;
4618
    }
4903
    }
Línea 4619... Línea 4904...
4619
 
4904
 
4620
    /**
4905
    /**
4621
     * View entire grader app.
4906
     * View entire grader app.
4622
     *
4907
     *
4623
     * @return string
4908
     * @return string
4624
     */
4909
     */
-
 
4910
    protected function view_grader()
4625
    protected function view_grader() {
4911
    {
Línea 4626... Línea 4912...
4626
        global $USER, $PAGE;
4912
        global $USER, $PAGE;
4627
 
4913
 
4628
        $o = '';
4914
        $o = '';
Línea 4671... Línea 4957...
4671
    /**
4957
    /**
4672
     * View entire grading page.
4958
     * View entire grading page.
4673
     *
4959
     *
4674
     * @return string
4960
     * @return string
4675
     */
4961
     */
4676
    protected function view_grading_page() {
4962
    protected function view_grading_page()
-
 
4963
    {
4677
        global $CFG;
4964
        global $CFG;
Línea 4678... Línea 4965...
4678
 
4965
 
4679
        $o = '';
4966
        $o = '';
4680
        // Need submit permission to submit an assignment.
4967
        // Need submit permission to submit an assignment.
Línea 4696... Línea 4983...
4696
    /**
4983
    /**
4697
     * Capture the output of the plagiarism plugins disclosures and return it as a string.
4984
     * Capture the output of the plagiarism plugins disclosures and return it as a string.
4698
     *
4985
     *
4699
     * @return string
4986
     * @return string
4700
     */
4987
     */
4701
    protected function plagiarism_print_disclosure() {
4988
    protected function plagiarism_print_disclosure()
-
 
4989
    {
4702
        global $CFG;
4990
        global $CFG;
4703
        $o = '';
4991
        $o = '';
Línea 4704... Línea 4992...
4704
 
4992
 
4705
        if (!empty($CFG->enableplagiarism)) {
4993
        if (!empty($CFG->enableplagiarism)) {
Línea 4716... Línea 5004...
4716
     *
5004
     *
4717
     * @param string $title The page title
5005
     * @param string $title The page title
4718
     * @param array $notices The array of notices to show.
5006
     * @param array $notices The array of notices to show.
4719
     * @return string
5007
     * @return string
4720
     */
5008
     */
4721
    protected function view_notices($title, $notices) {
5009
    protected function view_notices($title, $notices)
-
 
5010
    {
4722
        global $CFG;
5011
        global $CFG;
Línea 4723... Línea 5012...
4723
 
5012
 
Línea 4724... Línea 5013...
4724
        $o = '';
5013
        $o = '';
-
 
5014
 
4725
 
5015
        $header = new assign_header(
4726
        $header = new assign_header($this->get_instance(),
5016
            $this->get_instance(),
4727
                                    $this->get_context(),
5017
            $this->get_context(),
4728
                                    $this->show_intro(),
5018
            $this->show_intro(),
-
 
5019
            $this->get_course_module()->id,
4729
                                    $this->get_course_module()->id,
5020
            $title
Línea 4730... Línea 5021...
4730
                                    $title);
5021
        );
4731
        $o .= $this->get_renderer()->render($header);
5022
        $o .= $this->get_renderer()->render($header);
4732
 
5023
 
Línea 4733... Línea 5024...
4733
        foreach ($notices as $notice) {
5024
        foreach ($notices as $notice) {
4734
            $o .= $this->get_renderer()->notification($notice);
5025
            $o .= $this->get_renderer()->notification($notice);
Línea 4735... Línea 5026...
4735
        }
5026
        }
Línea 4736... Línea 5027...
4736
 
5027
 
Línea 4746... Línea 5037...
4746
     * Get the name for a user - hiding their real name if blind marking is on.
5037
     * Get the name for a user - hiding their real name if blind marking is on.
4747
     *
5038
     *
4748
     * @param stdClass $user The user record as required by fullname()
5039
     * @param stdClass $user The user record as required by fullname()
4749
     * @return string The name.
5040
     * @return string The name.
4750
     */
5041
     */
4751
    public function fullname($user) {
5042
    public function fullname($user)
-
 
5043
    {
4752
        if ($this->is_blind_marking()) {
5044
        if ($this->is_blind_marking()) {
4753
            $hasviewblind = has_capability('mod/assign:viewblinddetails', $this->get_context());
5045
            $hasviewblind = has_capability('mod/assign:viewblinddetails', $this->get_context());
4754
            if (empty($user->recordid)) {
5046
            if (empty($user->recordid)) {
4755
                $uniqueid = $this->get_uniqueid_for_user($user->id);
5047
                $uniqueid = $this->get_uniqueid_for_user($user->id);
4756
            } else {
5048
            } else {
4757
                $uniqueid = $user->recordid;
5049
                $uniqueid = $user->recordid;
4758
            }
5050
            }
4759
            if ($hasviewblind) {
5051
            if ($hasviewblind) {
4760
                return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' .
5052
                return get_string('participant', 'assign') . ' ' . $uniqueid . ' (' .
4761
                        fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())) . ')';
5053
                    fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context())) . ')';
4762
            } else {
5054
            } else {
4763
                return get_string('participant', 'assign') . ' ' . $uniqueid;
5055
                return get_string('participant', 'assign') . ' ' . $uniqueid;
4764
            }
5056
            }
4765
        } else {
5057
        } else {
4766
            return fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
5058
            return fullname($user, has_capability('moodle/site:viewfullnames', $this->get_context()));
Línea 4773... Línea 5065...
4773
     * @param moodleform $mform
5065
     * @param moodleform $mform
4774
     * @param array $notices A list of notices to display at the top of the
5066
     * @param array $notices A list of notices to display at the top of the
4775
     *                       edit submission form (e.g. from plugins).
5067
     *                       edit submission form (e.g. from plugins).
4776
     * @return string The page output.
5068
     * @return string The page output.
4777
     */
5069
     */
4778
    protected function view_edit_submission_page($mform, $notices) {
5070
    protected function view_edit_submission_page($mform, $notices)
-
 
5071
    {
4779
        global $CFG, $USER, $DB, $PAGE;
5072
        global $CFG, $USER, $DB, $PAGE;
Línea 4780... Línea 5073...
4780
 
5073
 
4781
        $o = '';
5074
        $o = '';
4782
        require_once($CFG->dirroot . '/mod/assign/submission_form.php');
5075
        require_once($CFG->dirroot . '/mod/assign/submission_form.php');
4783
        // Need submit permission to submit an assignment.
5076
        // Need submit permission to submit an assignment.
4784
        $userid = optional_param('userid', $USER->id, PARAM_INT);
5077
        $userid = optional_param('userid', $USER->id, PARAM_INT);
4785
        $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
5078
        $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
Línea 4786... Línea 5079...
4786
        $timelimitenabled = get_config('assign', 'enabletimelimit');
5079
        $timelimitenabled = get_config('assign', 'enabletimelimit');
4787
 
5080
 
4788
        // This variation on the url will link direct to this student.
5081
        // This variation on the url will link direct to this student.
Línea 4840... Línea 5133...
4840
            $bc->content = $navbc;
5133
            $bc->content = $navbc;
4841
            $PAGE->blocks->add_fake_block($bc, reset($regions));
5134
            $PAGE->blocks->add_fake_block($bc, reset($regions));
4842
        }
5135
        }
Línea 4843... Línea 5136...
4843
 
5136
 
-
 
5137
        $o .= $this->get_renderer()->render(
4844
        $o .= $this->get_renderer()->render(
5138
            new assign_header(
4845
            new assign_header($this->get_instance(),
5139
                $this->get_instance(),
4846
                              $this->get_context(),
5140
                $this->get_context(),
4847
                              $this->show_intro(),
5141
                $this->show_intro(),
4848
                              $this->get_course_module()->id,
5142
                $this->get_course_module()->id,
4849
                              $title,
5143
                $title,
4850
                              '',
5144
                '',
4851
                              $postfix,
5145
                $postfix,
4852
                              null,
5146
                null,
4853
                              true
5147
                true
4854
            )
5148
            )
Línea 4855... Línea 5149...
4855
        );
5149
        );
4856
 
5150
 
Línea 4873... Línea 5167...
4873
     * Get the time limit panel object for this submission attempt.
5167
     * Get the time limit panel object for this submission attempt.
4874
     *
5168
     *
4875
     * @param stdClass $submission assign submission.
5169
     * @param stdClass $submission assign submission.
4876
     * @return string the panel output.
5170
     * @return string the panel output.
4877
     */
5171
     */
4878
    public function get_timelimit_panel(stdClass $submission): string {
5172
    public function get_timelimit_panel(stdClass $submission): string
-
 
5173
    {
4879
        global $USER;
5174
        global $USER;
Línea 4880... Línea 5175...
4880
 
5175
 
4881
        // Apply overrides.
5176
        // Apply overrides.
4882
        $this->update_effective_access($USER->id);
5177
        $this->update_effective_access($USER->id);
Línea 4888... Línea 5183...
4888
     * See if this assignment has a grade yet.
5183
     * See if this assignment has a grade yet.
4889
     *
5184
     *
4890
     * @param int $userid
5185
     * @param int $userid
4891
     * @return bool
5186
     * @return bool
4892
     */
5187
     */
4893
    protected function is_graded($userid) {
5188
    protected function is_graded($userid)
-
 
5189
    {
4894
        $grade = $this->get_user_grade($userid, false);
5190
        $grade = $this->get_user_grade($userid, false);
4895
        if ($grade) {
5191
        if ($grade) {
4896
            return ($grade->grade !== null && $grade->grade >= 0);
5192
            return ($grade->grade !== null && $grade->grade >= 0);
4897
        }
5193
        }
4898
        return false;
5194
        return false;
Línea 4902... Línea 5198...
4902
     * Perform an access check to see if the current $USER can edit this group submission.
5198
     * Perform an access check to see if the current $USER can edit this group submission.
4903
     *
5199
     *
4904
     * @param int $groupid
5200
     * @param int $groupid
4905
     * @return bool
5201
     * @return bool
4906
     */
5202
     */
4907
    public function can_edit_group_submission($groupid) {
5203
    public function can_edit_group_submission($groupid)
-
 
5204
    {
4908
        global $USER;
5205
        global $USER;
Línea 4909... Línea 5206...
4909
 
5206
 
4910
        $members = $this->get_submission_group_members($groupid, true);
5207
        $members = $this->get_submission_group_members($groupid, true);
4911
        foreach ($members as $member) {
5208
        foreach ($members as $member) {
Línea 4921... Línea 5218...
4921
     * Perform an access check to see if the current $USER can view this group submission.
5218
     * Perform an access check to see if the current $USER can view this group submission.
4922
     *
5219
     *
4923
     * @param int $groupid
5220
     * @param int $groupid
4924
     * @return bool
5221
     * @return bool
4925
     */
5222
     */
4926
    public function can_view_group_submission($groupid) {
5223
    public function can_view_group_submission($groupid)
-
 
5224
    {
4927
        global $USER;
5225
        global $USER;
Línea 4928... Línea 5226...
4928
 
5226
 
4929
        $members = $this->get_submission_group_members($groupid, true);
5227
        $members = $this->get_submission_group_members($groupid, true);
4930
        foreach ($members as $member) {
5228
        foreach ($members as $member) {
Línea 4940... Línea 5238...
4940
     * Perform an access check to see if the current $USER can view this users submission.
5238
     * Perform an access check to see if the current $USER can view this users submission.
4941
     *
5239
     *
4942
     * @param int $userid
5240
     * @param int $userid
4943
     * @return bool
5241
     * @return bool
4944
     */
5242
     */
4945
    public function can_view_submission($userid) {
5243
    public function can_view_submission($userid)
-
 
5244
    {
4946
        global $USER;
5245
        global $USER;
Línea 4947... Línea 5246...
4947
 
5246
 
4948
        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
5247
        if (!$this->is_active_user($userid) && !has_capability('moodle/course:viewsuspendedusers', $this->context)) {
4949
            return false;
5248
            return false;
Línea 4964... Línea 5263...
4964
     * Allows the plugin to show a batch grading operation page.
5263
     * Allows the plugin to show a batch grading operation page.
4965
     *
5264
     *
4966
     * @param moodleform $mform
5265
     * @param moodleform $mform
4967
     * @return none
5266
     * @return none
4968
     */
5267
     */
4969
    protected function view_plugin_grading_batch_operation($mform) {
5268
    protected function view_plugin_grading_batch_operation($mform)
-
 
5269
    {
4970
        require_capability('mod/assign:grade', $this->context);
5270
        require_capability('mod/assign:grade', $this->context);
4971
        $prefix = 'plugingradingbatchoperation_';
5271
        $prefix = 'plugingradingbatchoperation_';
Línea 4972... Línea 5272...
4972
 
5272
 
4973
        if ($data = $mform->get_data()) {
5273
        if ($data = $mform->get_data()) {
Línea 4989... Línea 5289...
4989
     * Ask the user to confirm they want to perform this batch operation
5289
     * Ask the user to confirm they want to perform this batch operation
4990
     *
5290
     *
4991
     * @param moodleform $mform Set to a grading batch operations form
5291
     * @param moodleform $mform Set to a grading batch operations form
4992
     * @return string - the page to view after processing these actions
5292
     * @return string - the page to view after processing these actions
4993
     */
5293
     */
4994
    protected function process_grading_batch_operation(& $mform) {
5294
    protected function process_grading_batch_operation(&$mform)
-
 
5295
    {
4995
        global $CFG;
5296
        global $CFG;
4996
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
5297
        require_once($CFG->dirroot . '/mod/assign/gradingbatchoperationsform.php');
4997
        require_sesskey();
5298
        require_sesskey();
Línea 4998... Línea 5299...
4998
 
5299
 
4999
        $markingallocation = $this->get_instance()->markingworkflow &&
5300
        $markingallocation = $this->get_instance()->markingworkflow &&
5000
            $this->get_instance()->markingallocation &&
5301
            $this->get_instance()->markingallocation &&
Línea -... Línea 5302...
-
 
5302
            has_capability('mod/assign:manageallocations', $this->context);
5001
            has_capability('mod/assign:manageallocations', $this->context);
5303
 
5002
 
5304
        $batchformparams = array(
5003
        $batchformparams = array('cm'=>$this->get_course_module()->id,
5305
            'cm' => $this->get_course_module()->id,
5004
                                 'submissiondrafts'=>$this->get_instance()->submissiondrafts,
5306
            'submissiondrafts' => $this->get_instance()->submissiondrafts,
5005
                                 'duedate'=>$this->get_instance()->duedate,
5307
            'duedate' => $this->get_instance()->duedate,
5006
                                 'attemptreopenmethod'=>$this->get_instance()->attemptreopenmethod,
5308
            'attemptreopenmethod' => $this->get_instance()->attemptreopenmethod,
5007
                                 'feedbackplugins'=>$this->get_feedback_plugins(),
5309
            'feedbackplugins' => $this->get_feedback_plugins(),
5008
                                 'context'=>$this->get_context(),
5310
            'context' => $this->get_context(),
-
 
5311
            'markingworkflow' => $this->get_instance()->markingworkflow,
5009
                                 'markingworkflow'=>$this->get_instance()->markingworkflow,
5312
            'markingallocation' => $markingallocation
5010
                                 'markingallocation'=>$markingallocation);
5313
        );
5011
        $formclasses = [
5314
        $formclasses = [
5012
            'class' => 'gradingbatchoperationsform',
5315
            'class' => 'gradingbatchoperationsform',
Línea 5013... Línea 5316...
5013
            'data-double-submit-protection' => 'off'
5316
            'data-double-submit-protection' => 'off'
-
 
5317
        ];
5014
        ];
5318
 
5015
 
5319
        $mform = new mod_assign_grading_batch_operations_form(
5016
        $mform = new mod_assign_grading_batch_operations_form(null,
5320
            null,
5017
                                                              $batchformparams,
5321
            $batchformparams,
-
 
5322
            'post',
Línea 5018... Línea 5323...
5018
                                                              'post',
5323
            '',
5019
                                                              '',
5324
            $formclasses
5020
                                                              $formclasses);
5325
        );
5021
 
5326
 
Línea 5076... Línea 5381...
5076
     * Shows a form that allows the workflow state for selected submissions to be changed.
5381
     * Shows a form that allows the workflow state for selected submissions to be changed.
5077
     *
5382
     *
5078
     * @param moodleform $mform Set to a grading batch operations form
5383
     * @param moodleform $mform Set to a grading batch operations form
5079
     * @return string - the page to view after processing these actions
5384
     * @return string - the page to view after processing these actions
5080
     */
5385
     */
5081
    protected function view_batch_set_workflow_state($mform) {
5386
    protected function view_batch_set_workflow_state($mform)
-
 
5387
    {
5082
        global $CFG, $DB;
5388
        global $CFG, $DB;
Línea 5083... Línea 5389...
5083
 
5389
 
Línea 5084... Línea 5390...
5084
        require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');
5390
        require_once($CFG->dirroot . '/mod/assign/batchsetmarkingworkflowstateform.php');
Línea 5085... Línea 5391...
5085
 
5391
 
5086
        $o = '';
5392
        $o = '';
5087
 
5393
 
Línea -... Línea 5394...
-
 
5394
        $submitteddata = $mform->get_data();
5088
        $submitteddata = $mform->get_data();
5395
        $users = $submitteddata->selectedusers;
5089
        $users = $submitteddata->selectedusers;
5396
        $userlist = explode(',', $users);
-
 
5397
 
Línea 5090... Línea 5398...
5090
        $userlist = explode(',', $users);
5398
        $formdata = array(
Línea 5091... Línea 5399...
5091
 
5399
            'id' => $this->get_course_module()->id,
5092
        $formdata = array('id' => $this->get_course_module()->id,
5400
            'selectedusers' => $users
Línea 5101... Línea 5409...
5101
        foreach ($userlist as $userid) {
5409
        foreach ($userlist as $userid) {
5102
            if ($usercount >= 5) {
5410
            if ($usercount >= 5) {
5103
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5411
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5104
                break;
5412
                break;
5105
            }
5413
            }
5106
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
5414
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
Línea 5107... Línea 5415...
5107
 
5415
 
-
 
5416
            $usershtml .= $this->get_renderer()->render(new assign_user_summary(
5108
            $usershtml .= $this->get_renderer()->render(new assign_user_summary($user,
5417
                $user,
5109
                                                                $this->get_course()->id,
5418
                $this->get_course()->id,
5110
                                                                $viewfullnames,
5419
                $viewfullnames,
5111
                                                                $this->is_blind_marking(),
5420
                $this->is_blind_marking(),
5112
                                                                $this->get_uniqueid_for_user($user->id),
5421
                $this->get_uniqueid_for_user($user->id),
5113
                                                                $extrauserfields,
5422
                $extrauserfields,
-
 
5423
                !$this->is_active_user($userid)
5114
                                                                !$this->is_active_user($userid)));
5424
            ));
5115
            $usercount += 1;
5425
            $usercount += 1;
Línea 5116... Línea 5426...
5116
        }
5426
        }
5117
 
5427
 
Línea 5121... Línea 5431...
5121
            'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
5431
            'markingworkflowstates' => $this->get_marking_workflow_states_for_current_user()
5122
        );
5432
        );
Línea 5123... Línea 5433...
5123
 
5433
 
5124
        $mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);
5434
        $mform = new mod_assign_batch_set_marking_workflow_state_form(null, $formparams);
5125
        $mform->set_data($formdata);    // Initialises the hidden elements.
5435
        $mform->set_data($formdata);    // Initialises the hidden elements.
-
 
5436
        $header = new assign_header(
5126
        $header = new assign_header($this->get_instance(),
5437
            $this->get_instance(),
5127
            $this->get_context(),
5438
            $this->get_context(),
5128
            $this->show_intro(),
5439
            $this->show_intro(),
5129
            $this->get_course_module()->id,
5440
            $this->get_course_module()->id,
-
 
5441
            get_string('setmarkingworkflowstate', 'assign')
5130
            get_string('setmarkingworkflowstate', 'assign'));
5442
        );
5131
        $o .= $this->get_renderer()->render($header);
5443
        $o .= $this->get_renderer()->render($header);
5132
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
5444
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
Línea 5133... Línea 5445...
5133
        $o .= $this->view_footer();
5445
        $o .= $this->view_footer();
Línea 5141... Línea 5453...
5141
     * Shows a form that allows the allocated marker for selected submissions to be changed.
5453
     * Shows a form that allows the allocated marker for selected submissions to be changed.
5142
     *
5454
     *
5143
     * @param moodleform $mform Set to a grading batch operations form
5455
     * @param moodleform $mform Set to a grading batch operations form
5144
     * @return string - the page to view after processing these actions
5456
     * @return string - the page to view after processing these actions
5145
     */
5457
     */
5146
    public function view_batch_markingallocation($mform) {
5458
    public function view_batch_markingallocation($mform)
-
 
5459
    {
5147
        global $CFG, $DB;
5460
        global $CFG, $DB;
Línea 5148... Línea 5461...
5148
 
5461
 
Línea 5149... Línea 5462...
5149
        require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
5462
        require_once($CFG->dirroot . '/mod/assign/batchsetallocatedmarkerform.php');
Línea 5150... Línea 5463...
5150
 
5463
 
5151
        $o = '';
5464
        $o = '';
5152
 
5465
 
Línea -... Línea 5466...
-
 
5466
        $submitteddata = $mform->get_data();
5153
        $submitteddata = $mform->get_data();
5467
        $users = $submitteddata->selectedusers;
5154
        $users = $submitteddata->selectedusers;
5468
        $userlist = explode(',', $users);
-
 
5469
 
Línea 5155... Línea 5470...
5155
        $userlist = explode(',', $users);
5470
        $formdata = array(
Línea 5156... Línea 5471...
5156
 
5471
            'id' => $this->get_course_module()->id,
5157
        $formdata = array('id' => $this->get_course_module()->id,
5472
            'selectedusers' => $users
Línea 5166... Línea 5481...
5166
        foreach ($userlist as $userid) {
5481
        foreach ($userlist as $userid) {
5167
            if ($usercount >= 5) {
5482
            if ($usercount >= 5) {
5168
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5483
                $usershtml .= get_string('moreusers', 'assign', count($userlist) - 5);
5169
                break;
5484
                break;
5170
            }
5485
            }
5171
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
5486
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
Línea 5172... Línea 5487...
5172
 
5487
 
-
 
5488
            $usershtml .= $this->get_renderer()->render(new assign_user_summary(
5173
            $usershtml .= $this->get_renderer()->render(new assign_user_summary($user,
5489
                $user,
5174
                $this->get_course()->id,
5490
                $this->get_course()->id,
5175
                $viewfullnames,
5491
                $viewfullnames,
5176
                $this->is_blind_marking(),
5492
                $this->is_blind_marking(),
5177
                $this->get_uniqueid_for_user($user->id),
5493
                $this->get_uniqueid_for_user($user->id),
5178
                $extrauserfields,
5494
                $extrauserfields,
-
 
5495
                !$this->is_active_user($userid)
5179
                !$this->is_active_user($userid)));
5496
            ));
5180
            $usercount += 1;
5497
            $usercount += 1;
Línea 5181... Línea 5498...
5181
        }
5498
        }
5182
 
5499
 
Línea 5195... Línea 5512...
5195
 
5512
 
Línea 5196... Línea 5513...
5196
        $formparams['markers'] = $markerlist;
5513
        $formparams['markers'] = $markerlist;
5197
 
5514
 
5198
        $mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);
5515
        $mform = new mod_assign_batch_set_allocatedmarker_form(null, $formparams);
-
 
5516
        $mform->set_data($formdata);    // Initialises the hidden elements.
5199
        $mform->set_data($formdata);    // Initialises the hidden elements.
5517
        $header = new assign_header(
5200
        $header = new assign_header($this->get_instance(),
5518
            $this->get_instance(),
5201
            $this->get_context(),
5519
            $this->get_context(),
5202
            $this->show_intro(),
5520
            $this->show_intro(),
-
 
5521
            $this->get_course_module()->id,
5203
            $this->get_course_module()->id,
5522
            get_string('setmarkingallocation', 'assign')
5204
            get_string('setmarkingallocation', 'assign'));
5523
        );
5205
        $o .= $this->get_renderer()->render($header);
5524
        $o .= $this->get_renderer()->render($header);
Línea 5206... Línea 5525...
5206
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
5525
        $o .= $this->get_renderer()->render(new assign_form('setworkflowstate', $mform));
Línea 5215... Línea 5534...
5215
     * Ask the user to confirm they want to submit their work for grading.
5534
     * Ask the user to confirm they want to submit their work for grading.
5216
     *
5535
     *
5217
     * @param moodleform $mform - null unless form validation has failed
5536
     * @param moodleform $mform - null unless form validation has failed
5218
     * @return string
5537
     * @return string
5219
     */
5538
     */
5220
    protected function check_submit_for_grading($mform) {
5539
    protected function check_submit_for_grading($mform)
-
 
5540
    {
5221
        global $USER, $CFG;
5541
        global $USER, $CFG;
Línea 5222... Línea 5542...
5222
 
5542
 
Línea 5223... Línea 5543...
5223
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
5543
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
Línea 5264... Línea 5584...
5264
        if (empty($submissionstatement)) {
5584
        if (empty($submissionstatement)) {
5265
            $requiresubmissionstatement = false;
5585
            $requiresubmissionstatement = false;
5266
        }
5586
        }
Línea 5267... Línea 5587...
5267
 
5587
 
5268
        if ($mform == null) {
5588
        if ($mform == null) {
5269
            $mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
5589
            $mform = new mod_assign_confirm_submission_form(null, array(
-
 
5590
                $requiresubmissionstatement,
5270
                                                                        $submissionstatement,
5591
                $submissionstatement,
5271
                                                                        $this->get_course_module()->id,
5592
                $this->get_course_module()->id,
-
 
5593
                $data
5272
                                                                        $data));
5594
            ));
5273
        }
5595
        }
5274
        $o = '';
5596
        $o = '';
-
 
5597
        $o .= $this->get_renderer()->render(new assign_header(
5275
        $o .= $this->get_renderer()->render(new assign_header($this->get_instance(),
5598
            $this->get_instance(),
5276
                                                              $this->get_context(),
5599
            $this->get_context(),
5277
                                                              $this->show_intro(),
5600
            $this->show_intro(),
5278
                                                              $this->get_course_module()->id,
5601
            $this->get_course_module()->id,
-
 
5602
            get_string('confirmsubmissionheading', 'assign')
5279
                                                              get_string('confirmsubmissionheading', 'assign')));
5603
        ));
-
 
5604
        $submitforgradingpage = new assign_submit_for_grading_page(
5280
        $submitforgradingpage = new assign_submit_for_grading_page($notifications,
5605
            $notifications,
5281
                                                                   $this->get_course_module()->id,
5606
            $this->get_course_module()->id,
-
 
5607
            $mform
5282
                                                                   $mform);
5608
        );
5283
        $o .= $this->get_renderer()->render($submitforgradingpage);
5609
        $o .= $this->get_renderer()->render($submitforgradingpage);
Línea 5284... Línea 5610...
5284
        $o .= $this->view_footer();
5610
        $o .= $this->view_footer();
Línea 5293... Línea 5619...
5293
     *
5619
     *
5294
     * @param stdClass $user the user to get the report for
5620
     * @param stdClass $user the user to get the report for
5295
     * @param bool $showlinks return plain text or links to the profile
5621
     * @param bool $showlinks return plain text or links to the profile
5296
     * @return assign_submission_status renderable object
5622
     * @return assign_submission_status renderable object
5297
     */
5623
     */
5298
    public function get_assign_submission_status_renderable($user, $showlinks) {
5624
    public function get_assign_submission_status_renderable($user, $showlinks)
-
 
5625
    {
5299
        global $PAGE;
5626
        global $PAGE;
Línea 5300... Línea 5627...
5300
 
5627
 
5301
        $instance = $this->get_instance();
5628
        $instance = $this->get_instance();
5302
        $flags = $this->get_user_flags($user->id, false);
5629
        $flags = $this->get_user_flags($user->id, false);
Línea 5314... Línea 5641...
5314
            }
5641
            }
5315
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
5642
            $notsubmitted = $this->get_submission_group_members_who_have_not_submitted($groupid, false);
5316
        }
5643
        }
Línea 5317... Línea 5644...
5317
 
5644
 
5318
        $showedit = $showlinks &&
5645
        $showedit = $showlinks &&
5319
                    ($this->is_any_submission_plugin_enabled()) &&
5646
            ($this->is_any_submission_plugin_enabled()) &&
Línea 5320... Línea 5647...
5320
                    $this->can_edit_submission($user->id);
5647
            $this->can_edit_submission($user->id);
Línea 5321... Línea 5648...
5321
 
5648
 
5322
        $submissionlocked = ($flags && $flags->locked);
5649
        $submissionlocked = ($flags && $flags->locked);
Línea 5340... Línea 5667...
5340
        }
5667
        }
5341
        $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
5668
        $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_context());
Línea 5342... Línea 5669...
5342
 
5669
 
5343
        $gradingstatus = $this->get_grading_status($user->id);
5670
        $gradingstatus = $this->get_grading_status($user->id);
5344
        $usergroups = $this->get_all_groups($user->id);
5671
        $usergroups = $this->get_all_groups($user->id);
-
 
5672
        $submissionstatus = new assign_submission_status(
5345
        $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate,
5673
            $instance->allowsubmissionsfromdate,
5346
                                                          $instance->alwaysshowdescription,
5674
            $instance->alwaysshowdescription,
5347
                                                          $submission,
5675
            $submission,
5348
                                                          $instance->teamsubmission,
5676
            $instance->teamsubmission,
5349
                                                          $teamsubmission,
5677
            $teamsubmission,
5350
                                                          $submissiongroup,
5678
            $submissiongroup,
5351
                                                          $notsubmitted,
5679
            $notsubmitted,
5352
                                                          $this->is_any_submission_plugin_enabled(),
5680
            $this->is_any_submission_plugin_enabled(),
5353
                                                          $submissionlocked,
5681
            $submissionlocked,
5354
                                                          $this->is_graded($user->id),
5682
            $this->is_graded($user->id),
5355
                                                          $instance->duedate,
5683
            $instance->duedate,
5356
                                                          $instance->cutoffdate,
5684
            $instance->cutoffdate,
5357
                                                          $this->get_submission_plugins(),
5685
            $this->get_submission_plugins(),
5358
                                                          $this->get_return_action(),
5686
            $this->get_return_action(),
5359
                                                          $this->get_return_params(),
5687
            $this->get_return_params(),
5360
                                                          $this->get_course_module()->id,
5688
            $this->get_course_module()->id,
5361
                                                          $this->get_course()->id,
5689
            $this->get_course()->id,
5362
                                                          assign_submission_status::STUDENT_VIEW,
5690
            assign_submission_status::STUDENT_VIEW,
5363
                                                          $showedit,
5691
            $showedit,
5364
                                                          $showsubmit,
5692
            $showsubmit,
5365
                                                          $viewfullnames,
5693
            $viewfullnames,
5366
                                                          $extensionduedate,
5694
            $extensionduedate,
5367
                                                          $this->get_context(),
5695
            $this->get_context(),
5368
                                                          $this->is_blind_marking(),
5696
            $this->is_blind_marking(),
5369
                                                          $gradingcontrollerpreview,
5697
            $gradingcontrollerpreview,
5370
                                                          $instance->attemptreopenmethod,
5698
            $instance->attemptreopenmethod,
5371
                                                          $instance->maxattempts,
5699
            $instance->maxattempts,
5372
                                                          $gradingstatus,
5700
            $gradingstatus,
5373
                                                          $instance->preventsubmissionnotingroup,
5701
            $instance->preventsubmissionnotingroup,
5374
                                                          $usergroups,
5702
            $usergroups,
-
 
5703
            $instance->timelimit
5375
                                                          $instance->timelimit);
5704
        );
5376
        return $submissionstatus;
5705
        return $submissionstatus;
Línea 5377... Línea 5706...
5377
    }
5706
    }
5378
 
5707
 
5379
 
5708
 
5380
    /**
5709
    /**
5381
     * Creates an assign_feedback_status renderable.
5710
     * Creates an assign_feedback_status renderable.
5382
     *
5711
     *
5383
     * @param stdClass $user the user to get the report for
5712
     * @param stdClass $user the user to get the report for
-
 
5713
     * @return assign_feedback_status renderable object
5384
     * @return assign_feedback_status renderable object
5714
     */
Línea 5385... Línea 5715...
5385
     */
5715
    public function get_assign_feedback_status_renderable($user)
5386
    public function get_assign_feedback_status_renderable($user) {
5716
    {
Línea 5387... Línea 5717...
5387
        global $CFG, $DB, $PAGE;
5717
        global $CFG, $DB, $PAGE;
5388
 
5718
 
5389
        require_once($CFG->libdir.'/gradelib.php');
5719
        require_once($CFG->libdir . '/gradelib.php');
Línea 5390... Línea 5720...
5390
        require_once($CFG->dirroot.'/grade/grading/lib.php');
5720
        require_once($CFG->dirroot . '/grade/grading/lib.php');
5391
 
5721
 
-
 
5722
        $instance = $this->get_instance();
5392
        $instance = $this->get_instance();
5723
        $grade = $this->get_user_grade($user->id, false);
5393
        $grade = $this->get_user_grade($user->id, false);
5724
        $gradingstatus = $this->get_grading_status($user->id);
5394
        $gradingstatus = $this->get_grading_status($user->id);
5725
 
-
 
5726
        $gradinginfo = grade_get_grades(
Línea 5395... Línea 5727...
5395
 
5727
            $this->get_course()->id,
5396
        $gradinginfo = grade_get_grades($this->get_course()->id,
5728
            'mod',
5397
                                    'mod',
5729
            'assign',
5398
                                    'assign',
5730
            $instance->id,
Línea 5422... Línea 5754...
5422
            $emptyplugins = true; // Don't show feedback plugins until released either.
5754
            $emptyplugins = true; // Don't show feedback plugins until released either.
5423
        }
5755
        }
Línea 5424... Línea 5756...
5424
 
5756
 
5425
        $cangrade = has_capability('mod/assign:grade', $this->get_context());
5757
        $cangrade = has_capability('mod/assign:grade', $this->get_context());
5426
        $hasgrade = $this->get_instance()->grade != GRADE_TYPE_NONE &&
5758
        $hasgrade = $this->get_instance()->grade != GRADE_TYPE_NONE &&
5427
                        !is_null($gradebookgrade) && !is_null($gradebookgrade->grade);
5759
            !is_null($gradebookgrade) && !is_null($gradebookgrade->grade);
5428
        $gradevisible = $cangrade || $this->get_instance()->grade == GRADE_TYPE_NONE ||
5760
        $gradevisible = $cangrade || $this->get_instance()->grade == GRADE_TYPE_NONE ||
5429
                        (!is_null($gradebookgrade) && !$gradebookgrade->hidden);
5761
            (!is_null($gradebookgrade) && !$gradebookgrade->hidden);
5430
        // If there is a visible grade, show the summary.
5762
        // If there is a visible grade, show the summary.
Línea 5431... Línea 5763...
5431
        if (($hasgrade || !$emptyplugins) && $gradevisible) {
5763
        if (($hasgrade || !$emptyplugins) && $gradevisible) {
5432
 
5764
 
Línea 5457... Línea 5789...
5457
                if (has_capability('mod/assign:showhiddengrader', $this->context) || !$this->is_hidden_grader()) {
5789
                if (has_capability('mod/assign:showhiddengrader', $this->context) || !$this->is_hidden_grader()) {
5458
                    // Only display the grader if it is in the right state.
5790
                    // Only display the grader if it is in the right state.
5459
                    if (in_array($gradingstatus, [ASSIGN_GRADING_STATUS_GRADED, ASSIGN_MARKING_WORKFLOW_STATE_RELEASED])) {
5791
                    if (in_array($gradingstatus, [ASSIGN_GRADING_STATUS_GRADED, ASSIGN_MARKING_WORKFLOW_STATE_RELEASED])) {
5460
                        if (isset($grade->grader) && $grade->grader > 0) {
5792
                        if (isset($grade->grader) && $grade->grader > 0) {
5461
                            $grader = $DB->get_record('user', array('id' => $grade->grader));
5793
                            $grader = $DB->get_record('user', array('id' => $grade->grader));
-
 
5794
                        } else if (
5462
                        } else if (isset($gradebookgrade->usermodified)
5795
                            isset($gradebookgrade->usermodified)
5463
                            && $gradebookgrade->usermodified > 0
5796
                            && $gradebookgrade->usermodified > 0
5464
                            && has_capability('mod/assign:grade', $this->get_context(), $gradebookgrade->usermodified)) {
5797
                            && has_capability('mod/assign:grade', $this->get_context(), $gradebookgrade->usermodified)
-
 
5798
                        ) {
5465
                            // Grader not provided. Check that usermodified is a user who can grade.
5799
                            // Grader not provided. Check that usermodified is a user who can grade.
5466
                            // Case 1: When an assignment is reopened an empty assign_grade is created so the feedback
5800
                            // Case 1: When an assignment is reopened an empty assign_grade is created so the feedback
5467
                            // plugin can know which attempt it's referring to. In this case, usermodifed is a student.
5801
                            // plugin can know which attempt it's referring to. In this case, usermodifed is a student.
5468
                            // Case 2: When an assignment's grade is overrided via the gradebook, usermodified is a grader.
5802
                            // Case 2: When an assignment's grade is overrided via the gradebook, usermodified is a grader.
5469
                            $grader = $DB->get_record('user', array('id' => $gradebookgrade->usermodified));
5803
                            $grader = $DB->get_record('user', array('id' => $gradebookgrade->usermodified));
Línea 5499... Línea 5833...
5499
     * Creates an assign_attempt_history renderable.
5833
     * Creates an assign_attempt_history renderable.
5500
     *
5834
     *
5501
     * @param stdClass $user the user to get the report for
5835
     * @param stdClass $user the user to get the report for
5502
     * @return assign_attempt_history renderable object
5836
     * @return assign_attempt_history renderable object
5503
     */
5837
     */
5504
    public function get_assign_attempt_history_renderable($user) {
5838
    public function get_assign_attempt_history_renderable($user)
-
 
5839
    {
Línea 5505... Línea 5840...
5505
 
5840
 
5506
        $allsubmissions = $this->get_all_submissions($user->id);
5841
        $allsubmissions = $this->get_all_submissions($user->id);
Línea 5507... Línea 5842...
5507
        $allgrades = $this->get_all_grades($user->id);
5842
        $allgrades = $this->get_all_grades($user->id);
-
 
5843
 
5508
 
5844
        $history = new assign_attempt_history(
5509
        $history = new assign_attempt_history($allsubmissions,
5845
            $allsubmissions,
5510
                                              $allgrades,
5846
            $allgrades,
5511
                                              $this->get_submission_plugins(),
5847
            $this->get_submission_plugins(),
5512
                                              $this->get_feedback_plugins(),
5848
            $this->get_feedback_plugins(),
5513
                                              $this->get_course_module()->id,
5849
            $this->get_course_module()->id,
5514
                                              $this->get_return_action(),
5850
            $this->get_return_action(),
5515
                                              $this->get_return_params(),
5851
            $this->get_return_params(),
5516
                                              false,
5852
            false,
-
 
5853
            0,
5517
                                              0,
5854
            0
5518
                                              0);
5855
        );
Línea 5519... Línea 5856...
5519
        return $history;
5856
        return $history;
5520
    }
5857
    }
Línea 5525... Línea 5862...
5525
     *
5862
     *
5526
     * @param stdClass $user the user to print the report for
5863
     * @param stdClass $user the user to print the report for
5527
     * @param bool $showlinks - Return plain text or links to the profile
5864
     * @param bool $showlinks - Return plain text or links to the profile
5528
     * @return string - the html summary
5865
     * @return string - the html summary
5529
     */
5866
     */
5530
    public function view_student_summary($user, $showlinks) {
5867
    public function view_student_summary($user, $showlinks)
-
 
5868
    {
Línea 5531... Línea 5869...
5531
 
5869
 
Línea 5532... Línea 5870...
5532
        $o = '';
5870
        $o = '';
5533
 
5871
 
Línea 5559... Línea 5897...
5559
     * @param stdClass $submission The users own submission record.
5897
     * @param stdClass $submission The users own submission record.
5560
     * @param stdClass $teamsubmission The users team submission record if there is one
5898
     * @param stdClass $teamsubmission The users team submission record if there is one
5561
     * @param int $userid The user
5899
     * @param int $userid The user
5562
     * @return bool
5900
     * @return bool
5563
     */
5901
     */
5564
    protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null) {
5902
    protected function show_submit_button($submission = null, $teamsubmission = null, $userid = null)
-
 
5903
    {
5565
        if (!has_capability('mod/assign:submit', $this->get_context(), $userid, false)) {
5904
        if (!has_capability('mod/assign:submit', $this->get_context(), $userid, false)) {
5566
            // The user does not have the capability to submit.
5905
            // The user does not have the capability to submit.
5567
            return false;
5906
            return false;
5568
        }
5907
        }
5569
        if ($teamsubmission) {
5908
        if ($teamsubmission) {
Línea 5604... Línea 5943...
5604
     * and gradefordisplay is added (rendered from grading manager).
5943
     * and gradefordisplay is added (rendered from grading manager).
5605
     *
5944
     *
5606
     * @param int $userid If not set, $USER->id will be used.
5945
     * @param int $userid If not set, $USER->id will be used.
5607
     * @return array $grades All grade records for this user.
5946
     * @return array $grades All grade records for this user.
5608
     */
5947
     */
5609
    protected function get_all_grades($userid) {
5948
    protected function get_all_grades($userid)
-
 
5949
    {
5610
        global $DB, $USER, $PAGE;
5950
        global $DB, $USER, $PAGE;
Línea 5611... Línea 5951...
5611
 
5951
 
5612
        // If the userid is not null then use userid.
5952
        // If the userid is not null then use userid.
5613
        if (!$userid) {
5953
        if (!$userid) {
5614
            $userid = $USER->id;
5954
            $userid = $USER->id;
Línea 5615... Línea 5955...
5615
        }
5955
        }
Línea 5616... Línea 5956...
5616
 
5956
 
Línea 5617... Línea 5957...
5617
        $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
5957
        $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
5618
 
5958
 
Línea 5629... Línea 5969...
5629
 
5969
 
5630
        // Need gradingitem and gradingmanager.
5970
        // Need gradingitem and gradingmanager.
5631
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
5971
        $gradingmanager = get_grading_manager($this->get_context(), 'mod_assign', 'submissions');
Línea 5632... Línea 5972...
5632
        $controller = $gradingmanager->get_active_controller();
5972
        $controller = $gradingmanager->get_active_controller();
5633
 
5973
 
-
 
5974
        $gradinginfo = grade_get_grades(
5634
        $gradinginfo = grade_get_grades($this->get_course()->id,
5975
            $this->get_course()->id,
5635
                                        'mod',
5976
            'mod',
5636
                                        'assign',
5977
            'assign',
-
 
5978
            $this->get_instance()->id,
Línea 5637... Línea 5979...
5637
                                        $this->get_instance()->id,
5979
            $userid
5638
                                        $userid);
5980
        );
5639
 
5981
 
5640
        $gradingitem = null;
5982
        $gradingitem = null;
Línea 5648... Línea 5990...
5648
                $grade->grader = null;
5990
                $grade->grader = null;
5649
            } else if (isset($gradercache[$grade->grader])) {
5991
            } else if (isset($gradercache[$grade->grader])) {
5650
                $grade->grader = $gradercache[$grade->grader];
5992
                $grade->grader = $gradercache[$grade->grader];
5651
            } else if ($grade->grader > 0) {
5993
            } else if ($grade->grader > 0) {
5652
                // Not in cache - need to load the grader record.
5994
                // Not in cache - need to load the grader record.
5653
                $grade->grader = $DB->get_record('user', array('id'=>$grade->grader));
5995
                $grade->grader = $DB->get_record('user', array('id' => $grade->grader));
5654
                if ($grade->grader) {
5996
                if ($grade->grader) {
5655
                    $gradercache[$grade->grader->id] = $grade->grader;
5997
                    $gradercache[$grade->grader->id] = $grade->grader;
5656
                }
5998
                }
5657
            }
5999
            }
Línea 5658... Línea 6000...
5658
 
6000
 
5659
            // Now get the gradefordisplay.
6001
            // Now get the gradefordisplay.
5660
            if ($controller) {
6002
            if ($controller) {
5661
                $controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
6003
                $controller->set_grade_range(make_grades_menu($this->get_instance()->grade), $this->get_instance()->grade > 0);
-
 
6004
                $grade->gradefordisplay = $controller->render_grade(
5662
                $grade->gradefordisplay = $controller->render_grade($PAGE,
6005
                    $PAGE,
5663
                                                                     $grade->id,
6006
                    $grade->id,
5664
                                                                     $gradingitem,
6007
                    $gradingitem,
5665
                                                                     $grade->grade,
6008
                    $grade->grade,
-
 
6009
                    $cangrade
5666
                                                                     $cangrade);
6010
                );
5667
            } else {
6011
            } else {
5668
                $grade->gradefordisplay = $this->display_grade($grade->grade, false);
6012
                $grade->gradefordisplay = $this->display_grade($grade->grade, false);
5669
            }
-
 
5670
 
6013
            }
Línea 5671... Línea 6014...
5671
        }
6014
        }
5672
 
6015
 
Línea 5677... Línea 6020...
5677
     * Get the submissions for all previous attempts.
6020
     * Get the submissions for all previous attempts.
5678
     *
6021
     *
5679
     * @param int $userid If not set, $USER->id will be used.
6022
     * @param int $userid If not set, $USER->id will be used.
5680
     * @return array $submissions All submission records for this user (or group).
6023
     * @return array $submissions All submission records for this user (or group).
5681
     */
6024
     */
5682
    public function get_all_submissions($userid) {
6025
    public function get_all_submissions($userid)
-
 
6026
    {
5683
        global $DB, $USER;
6027
        global $DB, $USER;
Línea 5684... Línea 6028...
5684
 
6028
 
5685
        // If the userid is not null then use userid.
6029
        // If the userid is not null then use userid.
5686
        if (!$userid) {
6030
        if (!$userid) {
Línea 5695... Línea 6039...
5695
            if ($group) {
6039
            if ($group) {
5696
                $groupid = $group->id;
6040
                $groupid = $group->id;
5697
            }
6041
            }
Línea 5698... Línea 6042...
5698
 
6042
 
5699
            // Params to get the group submissions.
6043
            // Params to get the group submissions.
5700
            $params = array('assignment'=>$this->get_instance()->id, 'groupid'=>$groupid, 'userid'=>0);
6044
            $params = array('assignment' => $this->get_instance()->id, 'groupid' => $groupid, 'userid' => 0);
5701
        } else {
6045
        } else {
5702
            // Params to get the user submissions.
6046
            // Params to get the user submissions.
5703
            $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
6047
            $params = array('assignment' => $this->get_instance()->id, 'userid' => $userid);
Línea 5704... Línea 6048...
5704
        }
6048
        }
5705
 
6049
 
Línea 5713... Línea 6057...
5713
     * Creates an assign_grading_summary renderable.
6057
     * Creates an assign_grading_summary renderable.
5714
     *
6058
     *
5715
     * @param mixed $activitygroup int|null the group for calculating the grading summary (if null the function will determine it)
6059
     * @param mixed $activitygroup int|null the group for calculating the grading summary (if null the function will determine it)
5716
     * @return assign_grading_summary renderable object
6060
     * @return assign_grading_summary renderable object
5717
     */
6061
     */
5718
    public function get_assign_grading_summary_renderable($activitygroup = null) {
6062
    public function get_assign_grading_summary_renderable($activitygroup = null)
-
 
6063
    {
Línea 5719... Línea 6064...
5719
 
6064
 
5720
        $instance = $this->get_default_instance(); // Grading summary requires the raw dates, regardless of relativedates mode.
6065
        $instance = $this->get_default_instance(); // Grading summary requires the raw dates, regardless of relativedates mode.
5721
        $cm = $this->get_course_module();
6066
        $cm = $this->get_course_module();
Línea 5790... Línea 6135...
5790
     * Helper function to allow up to fetch the group overrides via one query as opposed to many calls.
6135
     * Helper function to allow up to fetch the group overrides via one query as opposed to many calls.
5791
     *
6136
     *
5792
     * @param int $activitygroup The group we want to check the overrides of
6137
     * @param int $activitygroup The group we want to check the overrides of
5793
     * @return mixed Can return either a fetched DB object, local object or false
6138
     * @return mixed Can return either a fetched DB object, local object or false
5794
     */
6139
     */
5795
    private function get_override_data(int $activitygroup) {
6140
    private function get_override_data(int $activitygroup)
-
 
6141
    {
5796
        global $DB;
6142
        global $DB;
Línea 5797... Línea 6143...
5797
 
6143
 
5798
        $instanceid = $this->get_instance()->id;
6144
        $instanceid = $this->get_instance()->id;
5799
        $cachekey = "$instanceid-$activitygroup";
6145
        $cachekey = "$instanceid-$activitygroup";
Línea 5810... Línea 6156...
5810
     * Return group override duedate.
6156
     * Return group override duedate.
5811
     *
6157
     *
5812
     * @param int $activitygroup Activity active group
6158
     * @param int $activitygroup Activity active group
5813
     * @return int $duedate
6159
     * @return int $duedate
5814
     */
6160
     */
5815
    private function get_duedate($activitygroup = null) {
6161
    private function get_duedate($activitygroup = null)
-
 
6162
    {
5816
        if ($activitygroup === null) {
6163
        if ($activitygroup === null) {
5817
            $activitygroup = groups_get_activity_group($this->get_course_module());
6164
            $activitygroup = groups_get_activity_group($this->get_course_module());
5818
        }
6165
        }
5819
        if ($this->can_view_grades() && !empty($activitygroup)) {
6166
        if ($this->can_view_grades() && !empty($activitygroup)) {
5820
            $groupoverride = $this->get_override_data($activitygroup);
6167
            $groupoverride = $this->get_override_data($activitygroup);
Línea 5829... Línea 6176...
5829
     * Return group override timelimit.
6176
     * Return group override timelimit.
5830
     *
6177
     *
5831
     * @param null|int $activitygroup Activity active group
6178
     * @param null|int $activitygroup Activity active group
5832
     * @return int $timelimit
6179
     * @return int $timelimit
5833
     */
6180
     */
5834
    private function get_timelimit(?int $activitygroup = null): int {
6181
    private function get_timelimit(?int $activitygroup = null): int
-
 
6182
    {
5835
        if ($activitygroup === null) {
6183
        if ($activitygroup === null) {
5836
            $activitygroup = groups_get_activity_group($this->get_course_module());
6184
            $activitygroup = groups_get_activity_group($this->get_course_module());
5837
        }
6185
        }
5838
        if ($this->can_view_grades() && !empty($activitygroup)) {
6186
        if ($this->can_view_grades() && !empty($activitygroup)) {
5839
            $groupoverride = $this->get_override_data($activitygroup);
6187
            $groupoverride = $this->get_override_data($activitygroup);
Línea 5848... Línea 6196...
5848
     * Return group override cutoffdate.
6196
     * Return group override cutoffdate.
5849
     *
6197
     *
5850
     * @param null|int $activitygroup Activity active group
6198
     * @param null|int $activitygroup Activity active group
5851
     * @return int $cutoffdate
6199
     * @return int $cutoffdate
5852
     */
6200
     */
5853
    private function get_cutoffdate(?int $activitygroup = null): int {
6201
    private function get_cutoffdate(?int $activitygroup = null): int
-
 
6202
    {
5854
        if ($activitygroup === null) {
6203
        if ($activitygroup === null) {
5855
            $activitygroup = groups_get_activity_group($this->get_course_module());
6204
            $activitygroup = groups_get_activity_group($this->get_course_module());
5856
        }
6205
        }
5857
        if ($this->can_view_grades() && !empty($activitygroup)) {
6206
        if ($this->can_view_grades() && !empty($activitygroup)) {
5858
            $groupoverride = $this->get_override_data($activitygroup);
6207
            $groupoverride = $this->get_override_data($activitygroup);
Línea 5866... Línea 6215...
5866
    /**
6215
    /**
5867
     * View submissions page (contains details of current submission).
6216
     * View submissions page (contains details of current submission).
5868
     *
6217
     *
5869
     * @return string
6218
     * @return string
5870
     */
6219
     */
5871
    protected function view_submission_page() {
6220
    protected function view_submission_page()
-
 
6221
    {
5872
        global $CFG, $DB, $USER, $PAGE;
6222
        global $CFG, $DB, $USER, $PAGE;
Línea 5873... Línea 6223...
5873
 
6223
 
Línea 5874... Línea 6224...
5874
        $instance = $this->get_instance();
6224
        $instance = $this->get_instance();
Línea 5880... Línea 6230...
5880
        $postfix = '';
6230
        $postfix = '';
5881
        if ($this->has_visible_attachments() && (!$this->get_instance($USER->id)->submissionattachments)) {
6231
        if ($this->has_visible_attachments() && (!$this->get_instance($USER->id)->submissionattachments)) {
5882
            $postfix = $this->render_area_files('mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
6232
            $postfix = $this->render_area_files('mod_assign', ASSIGN_INTROATTACHMENT_FILEAREA, 0);
5883
        }
6233
        }
Línea 5884... Línea 6234...
5884
 
6234
 
-
 
6235
        $o .= $this->get_renderer()->render(new assign_header(
5885
        $o .= $this->get_renderer()->render(new assign_header($instance,
6236
            $instance,
5886
                                                      $this->get_context(),
6237
            $this->get_context(),
5887
                                                      $this->show_intro(),
6238
            $this->show_intro(),
-
 
6239
            $this->get_course_module()->id,
-
 
6240
            '',
5888
                                                      $this->get_course_module()->id,
6241
            '',
-
 
6242
            $postfix
Línea 5889... Línea 6243...
5889
                                                      '', '', $postfix));
6243
        ));
5890
 
6244
 
5891
        // Display plugin specific headers.
6245
        // Display plugin specific headers.
5892
        $plugins = array_merge($this->get_submission_plugins(), $this->get_feedback_plugins());
6246
        $plugins = array_merge($this->get_submission_plugins(), $this->get_feedback_plugins());
Línea 5921... Línea 6275...
5921
     *
6275
     *
5922
     * @param stdClass $instance The settings for the current instance of this assignment
6276
     * @param stdClass $instance The settings for the current instance of this assignment
5923
     * @param stdClass $user The user to print the action bar for
6277
     * @param stdClass $user The user to print the action bar for
5924
     * @return string
6278
     * @return string
5925
     */
6279
     */
5926
    public function view_submission_action_bar(stdClass $instance, stdClass $user): string {
6280
    public function view_submission_action_bar(stdClass $instance, stdClass $user): string
-
 
6281
    {
5927
        $submission = $this->get_user_submission($user->id, false);
6282
        $submission = $this->get_user_submission($user->id, false);
5928
        // Figure out if we are team or solitary submission.
6283
        // Figure out if we are team or solitary submission.
5929
        $teamsubmission = null;
6284
        $teamsubmission = null;
5930
        if ($instance->teamsubmission) {
6285
        if ($instance->teamsubmission) {
5931
            $teamsubmission = $this->get_group_submission($user->id, 0, false);
6286
            $teamsubmission = $this->get_group_submission($user->id, 0, false);
Línea 5959... Línea 6314...
5959
     * Convert the final raw grade(s) in the grading table for the gradebook.
6314
     * Convert the final raw grade(s) in the grading table for the gradebook.
5960
     *
6315
     *
5961
     * @param stdClass $grade
6316
     * @param stdClass $grade
5962
     * @return array
6317
     * @return array
5963
     */
6318
     */
5964
    protected function convert_grade_for_gradebook(stdClass $grade) {
6319
    protected function convert_grade_for_gradebook(stdClass $grade)
-
 
6320
    {
5965
        $gradebookgrade = array();
6321
        $gradebookgrade = array();
5966
        if ($grade->grade >= 0) {
6322
        if ($grade->grade >= 0) {
5967
            $gradebookgrade['rawgrade'] = $grade->grade;
6323
            $gradebookgrade['rawgrade'] = $grade->grade;
5968
        }
6324
        }
5969
        // Allow "no grade" to be chosen.
6325
        // Allow "no grade" to be chosen.
Línea 5991... Línea 6347...
5991
     * Convert submission details for the gradebook.
6347
     * Convert submission details for the gradebook.
5992
     *
6348
     *
5993
     * @param stdClass $submission
6349
     * @param stdClass $submission
5994
     * @return array
6350
     * @return array
5995
     */
6351
     */
5996
    protected function convert_submission_for_gradebook(stdClass $submission) {
6352
    protected function convert_submission_for_gradebook(stdClass $submission)
-
 
6353
    {
5997
        $gradebookgrade = array();
6354
        $gradebookgrade = array();
Línea 5998... Línea 6355...
5998
 
6355
 
5999
        $gradebookgrade['userid'] = $submission->userid;
6356
        $gradebookgrade['userid'] = $submission->userid;
6000
        $gradebookgrade['usermodified'] = $submission->userid;
6357
        $gradebookgrade['usermodified'] = $submission->userid;
Línea 6008... Línea 6365...
6008
     *
6365
     *
6009
     * @param mixed $submission stdClass|null
6366
     * @param mixed $submission stdClass|null
6010
     * @param mixed $grade stdClass|null
6367
     * @param mixed $grade stdClass|null
6011
     * @return bool
6368
     * @return bool
6012
     */
6369
     */
6013
    protected function gradebook_item_update($submission=null, $grade=null) {
6370
    protected function gradebook_item_update($submission = null, $grade = null)
-
 
6371
    {
6014
        global $CFG;
6372
        global $CFG;
Línea 6015... Línea 6373...
6015
 
6373
 
6016
        require_once($CFG->dirroot.'/mod/assign/lib.php');
6374
        require_once($CFG->dirroot . '/mod/assign/lib.php');
6017
        // Do not push grade to gradebook if blind marking is active as
6375
        // Do not push grade to gradebook if blind marking is active as
6018
        // the gradebook would reveal the students.
6376
        // the gradebook would reveal the students.
6019
        if ($this->is_blind_marking()) {
6377
        if ($this->is_blind_marking()) {
6020
            return false;
6378
            return false;
Línea 6021... Línea 6379...
6021
        }
6379
        }
-
 
6380
 
6022
 
6381
        // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook.
6023
        // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook.
6382
        if (
-
 
6383
            $this->get_instance()->markingworkflow && !empty($grade) &&
6024
        if ($this->get_instance()->markingworkflow && !empty($grade) &&
6384
            $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
6025
                $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
6385
        ) {
6026
            // Remove the grade (if it exists) from the gradebook as it is not 'final'.
6386
            // Remove the grade (if it exists) from the gradebook as it is not 'final'.
6027
            $grade->grade = -1;
6387
            $grade->grade = -1;
6028
            $grade->feedbacktext = '';
6388
            $grade->feedbacktext = '';
Línea 6042... Línea 6402...
6042
                }
6402
                }
6043
                return;
6403
                return;
6044
            }
6404
            }
Línea 6045... Línea 6405...
6045
 
6405
 
6046
            $gradebookgrade = $this->convert_submission_for_gradebook($submission);
-
 
6047
 
6406
            $gradebookgrade = $this->convert_submission_for_gradebook($submission);
6048
        } else {
6407
        } else {
6049
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
6408
            $gradebookgrade = $this->convert_grade_for_gradebook($grade);
6050
        }
6409
        }
6051
        // Grading is disabled, return.
6410
        // Grading is disabled, return.
Línea 6065... Línea 6424...
6065
     * @param stdClass $submission
6424
     * @param stdClass $submission
6066
     * @param int $userid
6425
     * @param int $userid
6067
     * @param bool $updatetime
6426
     * @param bool $updatetime
6068
     * @return bool
6427
     * @return bool
6069
     */
6428
     */
6070
    protected function update_team_submission(stdClass $submission, $userid, $updatetime) {
6429
    protected function update_team_submission(stdClass $submission, $userid, $updatetime)
-
 
6430
    {
6071
        global $DB;
6431
        global $DB;
Línea 6072... Línea 6432...
6072
 
6432
 
6073
        if ($updatetime) {
6433
        if ($updatetime) {
6074
            $submission->timemodified = time();
6434
            $submission->timemodified = time();
Línea 6089... Línea 6449...
6089
        if (!in_array($submission->status, [ASSIGN_SUBMISSION_STATUS_NEW, ASSIGN_SUBMISSION_STATUS_REOPENED])) {
6449
        if (!in_array($submission->status, [ASSIGN_SUBMISSION_STATUS_NEW, ASSIGN_SUBMISSION_STATUS_REOPENED])) {
6090
            foreach ($team as $member) {
6450
            foreach ($team as $member) {
6091
                $membersubmission = $this->get_user_submission($member->id, false, $submission->attemptnumber);
6451
                $membersubmission = $this->get_user_submission($member->id, false, $submission->attemptnumber);
Línea 6092... Línea 6452...
6092
 
6452
 
-
 
6453
                // If no submission found for team member and member is active then everyone has not submitted.
6093
                // If no submission found for team member and member is active then everyone has not submitted.
6454
                if (
6094
                if (!$membersubmission || $membersubmission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED
6455
                    !$membersubmission || $membersubmission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED
-
 
6456
                    && ($this->is_active_user($member->id))
6095
                        && ($this->is_active_user($member->id))) {
6457
                ) {
6096
                    $allsubmitted = false;
6458
                    $allsubmitted = false;
6097
                    if ($anysubmitted) {
6459
                    if ($anysubmitted) {
6098
                        break;
6460
                        break;
6099
                    }
6461
                    }
Línea 6137... Línea 6499...
6137
     * @param int $userid
6499
     * @param int $userid
6138
     * @param bool $updatetime
6500
     * @param bool $updatetime
6139
     * @param bool $teamsubmission
6501
     * @param bool $teamsubmission
6140
     * @return bool
6502
     * @return bool
6141
     */
6503
     */
6142
    protected function update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission) {
6504
    protected function update_submission(stdClass $submission, $userid, $updatetime, $teamsubmission)
-
 
6505
    {
6143
        global $DB;
6506
        global $DB;
Línea 6144... Línea 6507...
6144
 
6507
 
6145
        if ($teamsubmission) {
6508
        if ($teamsubmission) {
6146
            return $this->update_team_submission($submission, $userid, $updatetime);
6509
            return $this->update_team_submission($submission, $userid, $updatetime);
Línea 6147... Línea 6510...
6147
        }
6510
        }
6148
 
6511
 
6149
        if ($updatetime) {
6512
        if ($updatetime) {
6150
            $submission->timemodified = time();
6513
            $submission->timemodified = time();
6151
        }
6514
        }
6152
        $result= $DB->update_record('assign_submission', $submission);
6515
        $result = $DB->update_record('assign_submission', $submission);
6153
        if ($result) {
6516
        if ($result) {
6154
            $this->gradebook_item_update($submission);
6517
            $this->gradebook_item_update($submission);
6155
        }
6518
        }
Línea 6169... Línea 6532...
6169
     * @param stdClass $submission - Pre-fetched submission record (or false to fetch it)
6532
     * @param stdClass $submission - Pre-fetched submission record (or false to fetch it)
6170
     * @param stdClass $flags - Pre-fetched user flags record (or false to fetch it)
6533
     * @param stdClass $flags - Pre-fetched user flags record (or false to fetch it)
6171
     * @param stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)
6534
     * @param stdClass $gradinginfo - Pre-fetched user gradinginfo record (or false to fetch it)
6172
     * @return bool
6535
     * @return bool
6173
     */
6536
     */
6174
    public function submissions_open($userid = 0,
6537
    public function submissions_open(
-
 
6538
        $userid = 0,
6175
                                     $skipenrolled = false,
6539
        $skipenrolled = false,
6176
                                     $submission = false,
6540
        $submission = false,
6177
                                     $flags = false,
6541
        $flags = false,
6178
                                     $gradinginfo = false) {
6542
        $gradinginfo = false
-
 
6543
    ) {
6179
        global $USER;
6544
        global $USER;
Línea 6180... Línea 6545...
6180
 
6545
 
6181
        if (!$userid) {
6546
        if (!$userid) {
6182
            $userid = $USER->id;
6547
            $userid = $USER->id;
Línea 6236... Línea 6601...
6236
            }
6601
            }
6237
        }
6602
        }
Línea 6238... Línea 6603...
6238
 
6603
 
6239
        // See if this user grade is locked in the gradebook.
6604
        // See if this user grade is locked in the gradebook.
6240
        if ($gradinginfo === false) {
6605
        if ($gradinginfo === false) {
6241
            $gradinginfo = grade_get_grades($this->get_course()->id,
6606
            $gradinginfo = grade_get_grades(
-
 
6607
                $this->get_course()->id,
6242
                                            'mod',
6608
                'mod',
6243
                                            'assign',
6609
                'assign',
6244
                                            $this->get_instance()->id,
6610
                $this->get_instance()->id,
-
 
6611
                array($userid)
6245
                                            array($userid));
6612
            );
-
 
6613
        }
6246
        }
6614
        if (
6247
        if ($gradinginfo &&
6615
            $gradinginfo &&
6248
                isset($gradinginfo->items[0]->grades[$userid]) &&
6616
            isset($gradinginfo->items[0]->grades[$userid]) &&
-
 
6617
            $gradinginfo->items[0]->grades[$userid]->locked
6249
                $gradinginfo->items[0]->grades[$userid]->locked) {
6618
        ) {
6250
            return false;
6619
            return false;
Línea 6251... Línea 6620...
6251
        }
6620
        }
6252
 
6621
 
Línea 6259... Línea 6628...
6259
     * @param string $component
6628
     * @param string $component
6260
     * @param string $area
6629
     * @param string $area
6261
     * @param int $submissionid
6630
     * @param int $submissionid
6262
     * @return string
6631
     * @return string
6263
     */
6632
     */
6264
    public function render_area_files($component, $area, $submissionid) {
6633
    public function render_area_files($component, $area, $submissionid)
-
 
6634
    {
6265
        global $USER;
6635
        global $USER;
Línea 6266... Línea 6636...
6266
 
6636
 
-
 
6637
        return $this->get_renderer()->assign_files(
-
 
6638
            $this->context,
-
 
6639
            $submissionid,
-
 
6640
            $area,
-
 
6641
            $component,
6267
        return $this->get_renderer()->assign_files($this->context, $submissionid, $area, $component,
6642
            $this->course,
6268
                                                   $this->course, $this->coursemodule);
6643
            $this->coursemodule
6269
 
6644
        );
Línea 6270... Línea 6645...
6270
    }
6645
    }
6271
 
6646
 
6272
    /**
6647
    /**
6273
     * Capability check to make sure this grader can edit this submission.
6648
     * Capability check to make sure this grader can edit this submission.
6274
     *
6649
     *
6275
     * @param int $userid - The user whose submission is to be edited
6650
     * @param int $userid - The user whose submission is to be edited
6276
     * @param int $graderid (optional) - The user who will do the editing (default to $USER->id).
6651
     * @param int $graderid (optional) - The user who will do the editing (default to $USER->id).
6277
     * @return bool
6652
     * @return bool
-
 
6653
     */
6278
     */
6654
    public function can_edit_submission($userid, $graderid = 0)
Línea 6279... Línea 6655...
6279
    public function can_edit_submission($userid, $graderid = 0) {
6655
    {
6280
        global $USER;
6656
        global $USER;
6281
 
6657
 
Línea 6282... Línea 6658...
6282
        if (empty($graderid)) {
6658
        if (empty($graderid)) {
-
 
6659
            $graderid = $USER->id;
6283
            $graderid = $USER->id;
6660
        }
6284
        }
6661
 
6285
 
6662
        $instance = $this->get_instance();
6286
        $instance = $this->get_instance();
6663
        if (
-
 
6664
            $userid == $graderid &&
6287
        if ($userid == $graderid &&
6665
            $instance->teamsubmission &&
6288
            $instance->teamsubmission &&
6666
            $instance->preventsubmissionnotingroup &&
Línea 6289... Línea 6667...
6289
            $instance->preventsubmissionnotingroup &&
6667
            $this->get_submission_group($userid) == false
-
 
6668
        ) {
6290
            $this->get_submission_group($userid) == false) {
6669
            return false;
6291
            return false;
6670
        }
-
 
6671
 
6292
        }
6672
        if ($userid == $graderid) {
6293
 
6673
            if (
6294
        if ($userid == $graderid) {
6674
                $this->submissions_open($userid) &&
6295
            if ($this->submissions_open($userid) &&
6675
                has_capability('mod/assign:submit', $this->context, $graderid)
6296
                    has_capability('mod/assign:submit', $this->context, $graderid)) {
6676
            ) {
Línea 6319... Línea 6699...
6319
     *
6699
     *
6320
     * @param stdClass|cm_info $cm Course-module
6700
     * @param stdClass|cm_info $cm Course-module
6321
     * @param int $userid User ID
6701
     * @param int $userid User ID
6322
     * @return array An array of ID of users.
6702
     * @return array An array of ID of users.
6323
     */
6703
     */
6324
    public function get_shared_group_members($cm, $userid) {
6704
    public function get_shared_group_members($cm, $userid)
-
 
6705
    {
6325
        if (!isset($this->sharedgroupmembers[$userid])) {
6706
        if (!isset($this->sharedgroupmembers[$userid])) {
6326
            $this->sharedgroupmembers[$userid] = array();
6707
            $this->sharedgroupmembers[$userid] = array();
6327
            if ($members = groups_get_activity_shared_group_members($cm, $userid)) {
6708
            if ($members = groups_get_activity_shared_group_members($cm, $userid)) {
6328
                $this->sharedgroupmembers[$userid] = array_keys($members);
6709
                $this->sharedgroupmembers[$userid] = array_keys($members);
6329
            }
6710
            }
Línea 6336... Línea 6717...
6336
     * Returns a list of teachers that should be grading given submission.
6717
     * Returns a list of teachers that should be grading given submission.
6337
     *
6718
     *
6338
     * @param int $userid The submission to grade
6719
     * @param int $userid The submission to grade
6339
     * @return array
6720
     * @return array
6340
     */
6721
     */
6341
    protected function get_graders($userid) {
6722
    protected function get_graders($userid)
-
 
6723
    {
6342
        // Potential graders should be active users only.
6724
        // Potential graders should be active users only.
6343
        $potentialgraders = get_enrolled_users($this->context, "mod/assign:grade", null, 'u.*', null, null, null, true);
6725
        $potentialgraders = get_enrolled_users($this->context, "mod/assign:grade", null, 'u.*', null, null, null, true);
Línea 6344... Línea 6726...
6344
 
6726
 
6345
        $graders = array();
6727
        $graders = array();
Línea 6387... Línea 6769...
6387
     * Returns a list of users that should receive notification about given submission.
6769
     * Returns a list of users that should receive notification about given submission.
6388
     *
6770
     *
6389
     * @param int $userid The submission to grade
6771
     * @param int $userid The submission to grade
6390
     * @return array
6772
     * @return array
6391
     */
6773
     */
6392
    protected function get_notifiable_users($userid) {
6774
    protected function get_notifiable_users($userid)
-
 
6775
    {
6393
        // Potential users should be active users only.
6776
        // Potential users should be active users only.
6394
        $potentialusers = get_enrolled_users($this->context, "mod/assign:receivegradernotifications",
6777
        $potentialusers = get_enrolled_users(
-
 
6778
            $this->context,
6395
                                             null, 'u.*', null, null, null, true);
6779
            "mod/assign:receivegradernotifications",
-
 
6780
            null,
-
 
6781
            'u.*',
-
 
6782
            null,
-
 
6783
            null,
-
 
6784
            null,
-
 
6785
            true
-
 
6786
        );
Línea 6396... Línea 6787...
6396
 
6787
 
6397
        $notifiableusers = array();
6788
        $notifiableusers = array();
6398
        if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) {
6789
        if (groups_get_activity_groupmode($this->get_course_module()) == SEPARATEGROUPS) {
6399
            if ($groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_course_module()->groupingid)) {
6790
            if ($groups = groups_get_all_groups($this->get_course()->id, $userid, $this->get_course_module()->groupingid)) {
Línea 6443... Línea 6834...
6443
     * @param stdClass $course
6834
     * @param stdClass $course
6444
     * @param stdClass $context
6835
     * @param stdClass $context
6445
     * @param string $modulename
6836
     * @param string $modulename
6446
     * @param string $assignmentname
6837
     * @param string $assignmentname
6447
     */
6838
     */
6448
    protected static function format_notification_message_text($messagetype,
6839
    protected static function format_notification_message_text(
-
 
6840
        $messagetype,
6449
                                                             $info,
6841
        $info,
6450
                                                             $course,
6842
        $course,
6451
                                                             $context,
6843
        $context,
6452
                                                             $modulename,
6844
        $modulename,
6453
                                                             $assignmentname) {
6845
        $assignmentname
-
 
6846
    ) {
6454
        $formatparams = array('context' => $context->get_course_context());
6847
        $formatparams = array('context' => $context->get_course_context());
6455
        $posttext  = format_string($course->shortname, true, $formatparams) .
6848
        $posttext  = format_string($course->shortname, true, $formatparams) .
6456
                     ' -> ' .
6849
            ' -> ' .
6457
                     $modulename .
6850
            $modulename .
6458
                     ' -> ' .
6851
            ' -> ' .
6459
                     format_string($assignmentname, true, $formatparams) . "\n";
6852
            format_string($assignmentname, true, $formatparams) . "\n";
6460
        $posttext .= '---------------------------------------------------------------------' . "\n";
6853
        $posttext .= '---------------------------------------------------------------------' . "\n";
6461
        $posttext .= get_string($messagetype . 'text', 'assign', $info)."\n";
6854
        $posttext .= get_string($messagetype . 'text', 'assign', $info) . "\n";
6462
        $posttext .= "\n---------------------------------------------------------------------\n";
6855
        $posttext .= "\n---------------------------------------------------------------------\n";
6463
        return $posttext;
6856
        return $posttext;
6464
    }
6857
    }
Línea 6465... Línea 6858...
6465
 
6858
 
Línea 6472... Línea 6865...
6472
     * @param stdClass $context
6865
     * @param stdClass $context
6473
     * @param string $modulename
6866
     * @param string $modulename
6474
     * @param stdClass $coursemodule
6867
     * @param stdClass $coursemodule
6475
     * @param string $assignmentname
6868
     * @param string $assignmentname
6476
     */
6869
     */
6477
    protected static function format_notification_message_html($messagetype,
6870
    protected static function format_notification_message_html(
-
 
6871
        $messagetype,
6478
                                                             $info,
6872
        $info,
6479
                                                             $course,
6873
        $course,
6480
                                                             $context,
6874
        $context,
6481
                                                             $modulename,
6875
        $modulename,
6482
                                                             $coursemodule,
6876
        $coursemodule,
6483
                                                             $assignmentname) {
6877
        $assignmentname
-
 
6878
    ) {
6484
        global $CFG;
6879
        global $CFG;
6485
        $formatparams = array('context' => $context->get_course_context());
6880
        $formatparams = array('context' => $context->get_course_context());
6486
        $posthtml  = '<p><font face="sans-serif">' .
6881
        $posthtml  = '<p><font face="sans-serif">' .
6487
                     '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' .
6882
            '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $course->id . '">' .
6488
                     format_string($course->shortname, true, $formatparams) .
6883
            format_string($course->shortname, true, $formatparams) .
6489
                     '</a> ->' .
6884
            '</a> ->' .
6490
                     '<a href="' . $CFG->wwwroot . '/mod/assign/index.php?id=' . $course->id . '">' .
6885
            '<a href="' . $CFG->wwwroot . '/mod/assign/index.php?id=' . $course->id . '">' .
6491
                     $modulename .
6886
            $modulename .
6492
                     '</a> ->' .
6887
            '</a> ->' .
6493
                     '<a href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id . '">' .
6888
            '<a href="' . $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id . '">' .
6494
                     format_string($assignmentname, true, $formatparams) .
6889
            format_string($assignmentname, true, $formatparams) .
6495
                     '</a></font></p>';
6890
            '</a></font></p>';
6496
        $posthtml .= '<hr /><font face="sans-serif">';
6891
        $posthtml .= '<hr /><font face="sans-serif">';
6497
        $posthtml .= '<p>' . get_string($messagetype . 'html', 'assign', $info) . '</p>';
6892
        $posthtml .= '<p>' . get_string($messagetype . 'html', 'assign', $info) . '</p>';
6498
        $posthtml .= '</font><hr />';
6893
        $posthtml .= '</font><hr />';
6499
        return $posthtml;
6894
        return $posthtml;
6500
    }
6895
    }
Línea 6514... Línea 6909...
6514
     * @param string $assignmentname
6909
     * @param string $assignmentname
6515
     * @param bool $blindmarking
6910
     * @param bool $blindmarking
6516
     * @param int $uniqueidforuser
6911
     * @param int $uniqueidforuser
6517
     * @return void
6912
     * @return void
6518
     */
6913
     */
6519
    public static function send_assignment_notification($userfrom,
6914
    public static function send_assignment_notification(
-
 
6915
        $userfrom,
6520
                                                        $userto,
6916
        $userto,
6521
                                                        $messagetype,
6917
        $messagetype,
6522
                                                        $eventtype,
6918
        $eventtype,
6523
                                                        $updatetime,
6919
        $updatetime,
6524
                                                        $coursemodule,
6920
        $coursemodule,
6525
                                                        $context,
6921
        $context,
6526
                                                        $course,
6922
        $course,
6527
                                                        $modulename,
6923
        $modulename,
6528
                                                        $assignmentname,
6924
        $assignmentname,
6529
                                                        $blindmarking,
6925
        $blindmarking,
6530
                                                        $uniqueidforuser) {
6926
        $uniqueidforuser
-
 
6927
    ) {
6531
        global $CFG, $PAGE;
6928
        global $CFG, $PAGE;
Línea 6532... Línea 6929...
6532
 
6929
 
6533
        $info = new stdClass();
6930
        $info = new stdClass();
6534
        if ($blindmarking) {
6931
        if ($blindmarking) {
6535
            $userfrom = clone($userfrom);
6932
            $userfrom = clone ($userfrom);
6536
            $info->username = get_string('participant', 'assign') . ' ' . $uniqueidforuser;
6933
            $info->username = get_string('participant', 'assign') . ' ' . $uniqueidforuser;
6537
            $userfrom->firstname = get_string('participant', 'assign');
6934
            $userfrom->firstname = get_string('participant', 'assign');
6538
            $userfrom->lastname = $uniqueidforuser;
6935
            $userfrom->lastname = $uniqueidforuser;
6539
            $userfrom->email = $CFG->noreplyaddress;
6936
            $userfrom->email = $CFG->noreplyaddress;
6540
        } else {
6937
        } else {
6541
            $info->username = fullname($userfrom, true);
6938
            $info->username = fullname($userfrom, true);
6542
        }
6939
        }
6543
        $info->assignment = format_string($assignmentname, true, array('context'=>$context));
6940
        $info->assignment = format_string($assignmentname, true, array('context' => $context));
6544
        $info->url = $CFG->wwwroot.'/mod/assign/view.php?id='.$coursemodule->id;
6941
        $info->url = $CFG->wwwroot . '/mod/assign/view.php?id=' . $coursemodule->id;
Línea 6545... Línea 6942...
6545
        $info->timeupdated = userdate($updatetime, get_string('strftimerecentfull'));
6942
        $info->timeupdated = userdate($updatetime, get_string('strftimerecentfull'));
6546
 
6943
 
-
 
6944
        $postsubject = get_string($messagetype . 'small', 'assign', $info);
6547
        $postsubject = get_string($messagetype . 'small', 'assign', $info);
6945
        $posttext = self::format_notification_message_text(
6548
        $posttext = self::format_notification_message_text($messagetype,
6946
            $messagetype,
6549
                                                           $info,
6947
            $info,
6550
                                                           $course,
6948
            $course,
6551
                                                           $context,
6949
            $context,
-
 
6950
            $modulename,
6552
                                                           $modulename,
6951
            $assignmentname
6553
                                                           $assignmentname);
6952
        );
6554
        $posthtml = '';
6953
        $posthtml = '';
-
 
6954
        if ($userto->mailformat == 1) {
6555
        if ($userto->mailformat == 1) {
6955
            $posthtml = self::format_notification_message_html(
6556
            $posthtml = self::format_notification_message_html($messagetype,
6956
                $messagetype,
6557
                                                               $info,
6957
                $info,
6558
                                                               $course,
6958
                $course,
6559
                                                               $context,
6959
                $context,
6560
                                                               $modulename,
6960
                $modulename,
-
 
6961
                $coursemodule,
6561
                                                               $coursemodule,
6962
                $assignmentname
Línea 6562... Línea 6963...
6562
                                                               $assignmentname);
6963
            );
6563
        }
6964
        }
6564
 
6965
 
Línea 6605... Línea 7006...
6605
     * @param string $messagetype
7006
     * @param string $messagetype
6606
     * @param string $eventtype
7007
     * @param string $eventtype
6607
     * @param int $updatetime
7008
     * @param int $updatetime
6608
     * @return void
7009
     * @return void
6609
     */
7010
     */
6610
    public function send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime) {
7011
    public function send_notification($userfrom, $userto, $messagetype, $eventtype, $updatetime)
-
 
7012
    {
6611
        global $USER;
7013
        global $USER;
6612
        $userid = core_user::is_real_user($userfrom->id) ? $userfrom->id : $USER->id;
7014
        $userid = core_user::is_real_user($userfrom->id) ? $userfrom->id : $USER->id;
6613
        $uniqueid = $this->get_uniqueid_for_user($userid);
7015
        $uniqueid = $this->get_uniqueid_for_user($userid);
6614
        self::send_assignment_notification($userfrom,
7016
        self::send_assignment_notification(
-
 
7017
            $userfrom,
6615
                                           $userto,
7018
            $userto,
6616
                                           $messagetype,
7019
            $messagetype,
6617
                                           $eventtype,
7020
            $eventtype,
6618
                                           $updatetime,
7021
            $updatetime,
6619
                                           $this->get_course_module(),
7022
            $this->get_course_module(),
6620
                                           $this->get_context(),
7023
            $this->get_context(),
6621
                                           $this->get_course(),
7024
            $this->get_course(),
6622
                                           $this->get_module_name(),
7025
            $this->get_module_name(),
6623
                                           $this->get_instance()->name,
7026
            $this->get_instance()->name,
6624
                                           $this->is_blind_marking(),
7027
            $this->is_blind_marking(),
6625
                                           $uniqueid);
7028
            $uniqueid
-
 
7029
        );
6626
    }
7030
    }
Línea 6627... Línea 7031...
6627
 
7031
 
6628
    /**
7032
    /**
6629
     * Notify student upon successful submission copy.
7033
     * Notify student upon successful submission copy.
6630
     *
7034
     *
6631
     * @param stdClass $submission
7035
     * @param stdClass $submission
6632
     * @return void
7036
     * @return void
6633
     */
7037
     */
-
 
7038
    protected function notify_student_submission_copied(stdClass $submission)
6634
    protected function notify_student_submission_copied(stdClass $submission) {
7039
    {
Línea 6635... Línea 7040...
6635
        global $DB, $USER;
7040
        global $DB, $USER;
6636
 
7041
 
6637
        $adminconfig = $this->get_admin_config();
7042
        $adminconfig = $this->get_admin_config();
6638
        // Use the same setting for this - no need for another one.
7043
        // Use the same setting for this - no need for another one.
6639
        if (empty($adminconfig->submissionreceipts)) {
7044
        if (empty($adminconfig->submissionreceipts)) {
6640
            // No need to do anything.
7045
            // No need to do anything.
6641
            return;
7046
            return;
6642
        }
7047
        }
6643
        if ($submission->userid) {
7048
        if ($submission->userid) {
6644
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
7049
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6645
        } else {
7050
        } else {
6646
            $user = $USER;
7051
            $user = $USER;
-
 
7052
        }
6647
        }
7053
        $this->send_notification(
6648
        $this->send_notification($user,
7054
            $user,
6649
                                 $user,
7055
            $user,
6650
                                 'submissioncopied',
7056
            'submissioncopied',
-
 
7057
            'assign_notification',
6651
                                 'assign_notification',
7058
            $submission->timemodified
6652
                                 $submission->timemodified);
7059
        );
6653
    }
7060
    }
6654
    /**
7061
    /**
6655
     * Notify student upon successful submission.
7062
     * Notify student upon successful submission.
6656
     *
7063
     *
6657
     * @param stdClass $submission
7064
     * @param stdClass $submission
6658
     * @return void
7065
     * @return void
-
 
7066
     */
6659
     */
7067
    protected function notify_student_submission_receipt(stdClass $submission)
Línea 6660... Línea 7068...
6660
    protected function notify_student_submission_receipt(stdClass $submission) {
7068
    {
6661
        global $DB, $USER;
7069
        global $DB, $USER;
6662
 
7070
 
6663
        $adminconfig = $this->get_admin_config();
7071
        $adminconfig = $this->get_admin_config();
6664
        if (empty($adminconfig->submissionreceipts)) {
7072
        if (empty($adminconfig->submissionreceipts)) {
6665
            // No need to do anything.
7073
            // No need to do anything.
6666
            return;
7074
            return;
6667
        }
7075
        }
6668
        if ($submission->userid) {
7076
        if ($submission->userid) {
6669
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
7077
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6670
        } else {
7078
        } else {
-
 
7079
            $user = $USER;
6671
            $user = $USER;
7080
        }
6672
        }
7081
        if ($submission->userid == $USER->id) {
6673
        if ($submission->userid == $USER->id) {
7082
            $this->send_notification(
6674
            $this->send_notification(core_user::get_noreply_user(),
7083
                core_user::get_noreply_user(),
6675
                                     $user,
7084
                $user,
-
 
7085
                'submissionreceipt',
6676
                                     'submissionreceipt',
7086
                'assign_notification',
6677
                                     'assign_notification',
7087
                $submission->timemodified
-
 
7088
            );
6678
                                     $submission->timemodified);
7089
        } else {
6679
        } else {
7090
            $this->send_notification(
6680
            $this->send_notification($USER,
7091
                $USER,
6681
                                     $user,
7092
                $user,
-
 
7093
                'submissionreceiptother',
6682
                                     'submissionreceiptother',
7094
                'assign_notification',
6683
                                     'assign_notification',
7095
                $submission->timemodified
Línea 6684... Línea 7096...
6684
                                     $submission->timemodified);
7096
            );
6685
        }
7097
        }
6686
    }
7098
    }
6687
 
7099
 
6688
    /**
7100
    /**
6689
     * Send notifications to graders upon student submissions.
7101
     * Send notifications to graders upon student submissions.
6690
     *
7102
     *
-
 
7103
     * @param stdClass $submission
6691
     * @param stdClass $submission
7104
     * @return void
Línea 6692... Línea 7105...
6692
     * @return void
7105
     */
Línea 6693... Línea 7106...
6693
     */
7106
    protected function notify_graders(stdClass $submission)
Línea 6702... Línea 7115...
6702
            // No need to do anything.
7115
            // No need to do anything.
6703
            return;
7116
            return;
6704
        }
7117
        }
Línea 6705... Línea 7118...
6705
 
7118
 
6706
        if ($submission->userid) {
7119
        if ($submission->userid) {
6707
            $user = $DB->get_record('user', array('id'=>$submission->userid), '*', MUST_EXIST);
7120
            $user = $DB->get_record('user', array('id' => $submission->userid), '*', MUST_EXIST);
6708
        } else {
7121
        } else {
6709
            $user = $USER;
7122
            $user = $USER;
Línea 6710... Línea 7123...
6710
        }
7123
        }
6711
 
7124
 
6712
        if ($notifyusers = $this->get_notifiable_users($user->id)) {
7125
        if ($notifyusers = $this->get_notifiable_users($user->id)) {
-
 
7126
            foreach ($notifyusers as $notifyuser) {
6713
            foreach ($notifyusers as $notifyuser) {
7127
                $this->send_notification(
6714
                $this->send_notification($user,
7128
                    $user,
6715
                                         $notifyuser,
7129
                    $notifyuser,
6716
                                         'gradersubmissionupdated',
7130
                    'gradersubmissionupdated',
-
 
7131
                    'assign_notification',
6717
                                         'assign_notification',
7132
                    $submission->timemodified
6718
                                         $submission->timemodified);
7133
                );
6719
            }
7134
            }
Línea 6720... Línea 7135...
6720
        }
7135
        }
Línea 6725... Línea 7140...
6725
     *
7140
     *
6726
     * @param stdClass $data - The form data
7141
     * @param stdClass $data - The form data
6727
     * @param array $notices - List of error messages to display on an error condition.
7142
     * @param array $notices - List of error messages to display on an error condition.
6728
     * @return bool Return false if the submission was not submitted.
7143
     * @return bool Return false if the submission was not submitted.
6729
     */
7144
     */
6730
    public function submit_for_grading($data, $notices) {
7145
    public function submit_for_grading($data, $notices)
-
 
7146
    {
6731
        global $USER;
7147
        global $USER;
Línea 6732... Línea 7148...
6732
 
7148
 
6733
        $userid = $USER->id;
7149
        $userid = $USER->id;
6734
        if (!empty($data->userid)) {
7150
        if (!empty($data->userid)) {
Línea 6761... Línea 7177...
6761
        $submissionstatement = '';
7177
        $submissionstatement = '';
6762
        if ($instance->requiresubmissionstatement) {
7178
        if ($instance->requiresubmissionstatement) {
6763
            $submissionstatement = $this->get_submissionstatement($adminconfig, $instance, $this->context);
7179
            $submissionstatement = $this->get_submissionstatement($adminconfig, $instance, $this->context);
6764
        }
7180
        }
Línea -... Línea 7181...
-
 
7181
 
6765
 
7182
        if (
6766
        if (!empty($submissionstatement) && $instance->requiresubmissionstatement
7183
            !empty($submissionstatement) && $instance->requiresubmissionstatement
-
 
7184
            && empty($data->submissionstatement) && $USER->id == $userid
6767
                && empty($data->submissionstatement) && $USER->id == $userid) {
7185
        ) {
6768
            return false;
7186
            return false;
Línea 6769... Línea 7187...
6769
        }
7187
        }
6770
 
7188
 
Línea 6779... Línea 7197...
6779
 
7197
 
6780
            $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
7198
            $submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
6781
            $this->update_submission($submission, $userid, true, $instance->teamsubmission);
7199
            $this->update_submission($submission, $userid, true, $instance->teamsubmission);
6782
            $completion = new completion_info($this->get_course());
7200
            $completion = new completion_info($this->get_course());
6783
            if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7201
            if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
-
 
7202
                $this->update_activity_completion_records(
6784
                $this->update_activity_completion_records($instance->teamsubmission,
7203
                    $instance->teamsubmission,
6785
                                                          $instance->requireallteammemberssubmit,
7204
                    $instance->requireallteammemberssubmit,
6786
                                                          $submission,
7205
                    $submission,
6787
                                                          $userid,
7206
                    $userid,
6788
                                                          COMPLETION_COMPLETE,
7207
                    COMPLETION_COMPLETE,
-
 
7208
                    $completion
6789
                                                          $completion);
7209
                );
Línea 6790... Línea 7210...
6790
            }
7210
            }
6791
 
7211
 
6792
            if (!empty($data->submissionstatement) && $USER->id == $userid) {
7212
            if (!empty($data->submissionstatement) && $USER->id == $userid) {
Línea 6806... Línea 7226...
6806
    /**
7226
    /**
6807
     * A students submission is submitted for grading by a teacher.
7227
     * A students submission is submitted for grading by a teacher.
6808
     *
7228
     *
6809
     * @return bool
7229
     * @return bool
6810
     */
7230
     */
6811
    protected function process_submit_other_for_grading($mform, $notices) {
7231
    protected function process_submit_other_for_grading($mform, $notices)
-
 
7232
    {
6812
        global $USER, $CFG;
7233
        global $USER, $CFG;
Línea 6813... Línea 7234...
6813
 
7234
 
Línea 6814... Línea 7235...
6814
        require_sesskey();
7235
        require_sesskey();
Línea 6829... Línea 7250...
6829
     *
7250
     *
6830
     * @param moodleform|null $mform If validation failed when submitting this form - this is the moodleform.
7251
     * @param moodleform|null $mform If validation failed when submitting this form - this is the moodleform.
6831
     *               It can be null.
7252
     *               It can be null.
6832
     * @return bool Return false if the validation fails. This affects which page is displayed next.
7253
     * @return bool Return false if the validation fails. This affects which page is displayed next.
6833
     */
7254
     */
6834
    protected function process_submit_for_grading($mform, $notices) {
7255
    protected function process_submit_for_grading($mform, $notices)
-
 
7256
    {
6835
        global $CFG;
7257
        global $CFG;
Línea 6836... Línea 7258...
6836
 
7258
 
6837
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
7259
        require_once($CFG->dirroot . '/mod/assign/submissionconfirmform.php');
Línea 6856... Línea 7278...
6856
        if (empty($submissionstatement)) {
7278
        if (empty($submissionstatement)) {
6857
            $requiresubmissionstatement = false;
7279
            $requiresubmissionstatement = false;
6858
        }
7280
        }
Línea 6859... Línea 7281...
6859
 
7281
 
6860
        if ($mform == null) {
7282
        if ($mform == null) {
6861
            $mform = new mod_assign_confirm_submission_form(null, array($requiresubmissionstatement,
7283
            $mform = new mod_assign_confirm_submission_form(null, array(
-
 
7284
                $requiresubmissionstatement,
6862
                                                                    $submissionstatement,
7285
                $submissionstatement,
6863
                                                                    $this->get_course_module()->id,
7286
                $this->get_course_module()->id,
-
 
7287
                $data
6864
                                                                    $data));
7288
            ));
Línea 6865... Línea 7289...
6865
        }
7289
        }
6866
 
7290
 
6867
        $data = $mform->get_data();
7291
        $data = $mform->get_data();
Línea 6879... Línea 7303...
6879
     *
7303
     *
6880
     * @param int $userid The user id
7304
     * @param int $userid The user id
6881
     * @param mixed $extensionduedate Either an integer date or null
7305
     * @param mixed $extensionduedate Either an integer date or null
6882
     * @return boolean
7306
     * @return boolean
6883
     */
7307
     */
6884
    public function save_user_extension($userid, $extensionduedate) {
7308
    public function save_user_extension($userid, $extensionduedate)
-
 
7309
    {
6885
        global $DB;
7310
        global $DB;
Línea 6886... Línea 7311...
6886
 
7311
 
6887
        // Need submit permission to submit an assignment.
7312
        // Need submit permission to submit an assignment.
Línea 6920... Línea 7345...
6920
     * Save extension date.
7345
     * Save extension date.
6921
     *
7346
     *
6922
     * @param moodleform $mform The submitted form
7347
     * @param moodleform $mform The submitted form
6923
     * @return boolean
7348
     * @return boolean
6924
     */
7349
     */
6925
    protected function process_save_extension(& $mform) {
7350
    protected function process_save_extension(&$mform)
-
 
7351
    {
6926
        global $DB, $CFG;
7352
        global $DB, $CFG;
Línea 6927... Línea 7353...
6927
 
7353
 
6928
        // Include extension form.
7354
        // Include extension form.
6929
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
7355
        require_once($CFG->dirroot . '/mod/assign/extensionform.php');
Línea 6990... Línea 7416...
6990
    /**
7416
    /**
6991
     * Save quick grades.
7417
     * Save quick grades.
6992
     *
7418
     *
6993
     * @return string The result of the save operation
7419
     * @return string The result of the save operation
6994
     */
7420
     */
6995
    protected function process_save_quick_grades() {
7421
    protected function process_save_quick_grades()
-
 
7422
    {
6996
        global $USER, $DB, $CFG;
7423
        global $USER, $DB, $CFG;
Línea 6997... Línea 7424...
6997
 
7424
 
6998
        // Need grade permission.
7425
        // Need grade permission.
6999
        require_capability('mod/assign:grade', $this->context);
7426
        require_capability('mod/assign:grade', $this->context);
Línea 7020... Línea 7447...
7020
            // Gather the userid, updated grade and last modified value.
7447
            // Gather the userid, updated grade and last modified value.
7021
            $record = new stdClass();
7448
            $record = new stdClass();
7022
            $record->userid = $userid;
7449
            $record->userid = $userid;
7023
            if ($modified >= 0) {
7450
            if ($modified >= 0) {
7024
                $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT));
7451
                $record->grade = unformat_float(optional_param('quickgrade_' . $record->userid, -1, PARAM_TEXT));
7025
                $record->workflowstate = optional_param('quickgrade_' . $record->userid.'_workflowstate', false, PARAM_ALPHA);
7452
                $record->workflowstate = optional_param('quickgrade_' . $record->userid . '_workflowstate', false, PARAM_ALPHA);
7026
                $record->allocatedmarker = optional_param('quickgrade_' . $record->userid.'_allocatedmarker', false, PARAM_INT);
7453
                $record->allocatedmarker = optional_param('quickgrade_' . $record->userid . '_allocatedmarker', false, PARAM_INT);
7027
            } else {
7454
            } else {
7028
                // This user was not in the grading table.
7455
                // This user was not in the grading table.
7029
                continue;
7456
                continue;
7030
            }
7457
            }
7031
            $record->attemptnumber = $attemptnumber;
7458
            $record->attemptnumber = $attemptnumber;
7032
            $record->lastmodified = $modified;
7459
            $record->lastmodified = $modified;
7033
            $record->gradinginfo = grade_get_grades($this->get_course()->id,
7460
            $record->gradinginfo = grade_get_grades(
7034
                                                    'mod',
7461
                $this->get_course()->id,
-
 
7462
                'mod',
7035
                                                    'assign',
7463
                'assign',
7036
                                                    $this->get_instance()->id,
7464
                $this->get_instance()->id,
7037
                                                    array($userid));
7465
                array($userid)
-
 
7466
            );
7038
            $users[$userid] = $record;
7467
            $users[$userid] = $record;
7039
        }
7468
        }
Línea 7040... Línea 7469...
7040
 
7469
 
7041
        if (empty($users)) {
7470
        if (empty($users)) {
Línea 7105... Línea 7534...
7105
                    }
7534
                    }
7106
                }
7535
                }
7107
            }
7536
            }
Línea 7108... Línea 7537...
7108
 
7537
 
7109
            if (($current->grade < 0 || $current->grade === null) &&
7538
            if (($current->grade < 0 || $current->grade === null) &&
-
 
7539
                ($modified->grade < 0 || $modified->grade === null)
7110
                ($modified->grade < 0 || $modified->grade === null)) {
7540
            ) {
7111
                // Different ways to indicate no grade.
7541
                // Different ways to indicate no grade.
7112
                $modified->grade = $current->grade; // Keep existing grade.
7542
                $modified->grade = $current->grade; // Keep existing grade.
7113
            }
7543
            }
7114
            // Treat 0 and null as different values.
7544
            // Treat 0 and null as different values.
7115
            if ($current->grade !== null) {
7545
            if ($current->grade !== null) {
7116
                $current->grade = floatval($current->grade);
7546
                $current->grade = floatval($current->grade);
7117
            }
7547
            }
7118
            $gradechanged = $gradecolpresent && grade_floats_different($current->grade, $modified->grade);
7548
            $gradechanged = $gradecolpresent && grade_floats_different($current->grade, $modified->grade);
7119
            $markingallocationchanged = $this->get_instance()->markingworkflow &&
7549
            $markingallocationchanged = $this->get_instance()->markingworkflow &&
7120
                                        $this->get_instance()->markingallocation &&
7550
                $this->get_instance()->markingallocation &&
7121
                                            ($modified->allocatedmarker !== false) &&
7551
                ($modified->allocatedmarker !== false) &&
7122
                                            ($current->allocatedmarker != $modified->allocatedmarker);
7552
                ($current->allocatedmarker != $modified->allocatedmarker);
7123
            $workflowstatechanged = $this->get_instance()->markingworkflow &&
7553
            $workflowstatechanged = $this->get_instance()->markingworkflow &&
7124
                                            ($modified->workflowstate !== false) &&
7554
                ($modified->workflowstate !== false) &&
7125
                                            ($current->workflowstate != $modified->workflowstate);
7555
                ($current->workflowstate != $modified->workflowstate);
7126
            if ($gradechanged || $markingallocationchanged || $workflowstatechanged) {
7556
            if ($gradechanged || $markingallocationchanged || $workflowstatechanged) {
7127
                // Grade changed.
7557
                // Grade changed.
7128
                if ($this->grading_disabled($modified->userid)) {
7558
                if ($this->grading_disabled($modified->userid)) {
7129
                    continue;
7559
                    continue;
Línea 7137... Línea 7567...
7137
                    return $message;
7567
                    return $message;
7138
                } else {
7568
                } else {
7139
                    $modifiedusers[$modified->userid] = $modified;
7569
                    $modifiedusers[$modified->userid] = $modified;
7140
                }
7570
                }
7141
            }
7571
            }
7142
 
-
 
7143
        }
7572
        }
7144
        $currentgrades->close();
7573
        $currentgrades->close();
Línea 7145... Línea 7574...
7145
 
7574
 
7146
        $adminconfig = $this->get_admin_config();
7575
        $adminconfig = $this->get_admin_config();
Línea 7147... Línea 7576...
7147
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7576
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7148
 
7577
 
7149
        // Ok - ready to process the updates.
7578
        // Ok - ready to process the updates.
7150
        foreach ($modifiedusers as $userid => $modified) {
7579
        foreach ($modifiedusers as $userid => $modified) {
7151
            $grade = $this->get_user_grade($userid, true);
7580
            $grade = $this->get_user_grade($userid, true);
7152
            $flags = $this->get_user_flags($userid, true);
7581
            $flags = $this->get_user_flags($userid, true);
7153
            $grade->grade= grade_floatval(unformat_float($modified->grade));
7582
            $grade->grade = grade_floatval(unformat_float($modified->grade));
Línea 7154... Línea 7583...
7154
            $grade->grader= $USER->id;
7583
            $grade->grader = $USER->id;
7155
            $gradecolpresent = optional_param('quickgrade_' . $userid, false, PARAM_INT) !== false;
7584
            $gradecolpresent = optional_param('quickgrade_' . $userid, false, PARAM_INT) !== false;
7156
 
7585
 
Línea 7168... Línea 7597...
7168
            }
7597
            }
Línea 7169... Línea 7598...
7169
 
7598
 
7170
            // These will be set to false if they are not present in the quickgrading
7599
            // These will be set to false if they are not present in the quickgrading
7171
            // form (e.g. column hidden).
7600
            // form (e.g. column hidden).
7172
            $workflowstatemodified = ($modified->workflowstate !== false) &&
7601
            $workflowstatemodified = ($modified->workflowstate !== false) &&
Línea 7173... Línea 7602...
7173
                                        ($flags->workflowstate != $modified->workflowstate);
7602
                ($flags->workflowstate != $modified->workflowstate);
7174
 
7603
 
Línea 7175... Línea 7604...
7175
            $allocatedmarkermodified = ($modified->allocatedmarker !== false) &&
7604
            $allocatedmarkermodified = ($modified->allocatedmarker !== false) &&
7176
                                        ($flags->allocatedmarker != $modified->allocatedmarker);
7605
                ($flags->allocatedmarker != $modified->allocatedmarker);
7177
 
7606
 
7178
            if ($workflowstatemodified) {
7607
            if ($workflowstatemodified) {
Línea 7206... Línea 7635...
7206
                    if ($newoutcome !== false && ($oldoutcome != $newoutcome)) {
7635
                    if ($newoutcome !== false && ($oldoutcome != $newoutcome)) {
7207
                        $data[$outcomeid] = $newoutcome;
7636
                        $data[$outcomeid] = $newoutcome;
7208
                    }
7637
                    }
7209
                }
7638
                }
7210
                if (count($data) > 0) {
7639
                if (count($data) > 0) {
7211
                    grade_update_outcomes('mod/assign',
7640
                    grade_update_outcomes(
-
 
7641
                        'mod/assign',
7212
                                          $this->course->id,
7642
                        $this->course->id,
7213
                                          'mod',
7643
                        'mod',
7214
                                          'assign',
7644
                        'assign',
7215
                                          $this->get_instance()->id,
7645
                        $this->get_instance()->id,
7216
                                          $userid,
7646
                        $userid,
7217
                                          $data);
7647
                        $data
-
 
7648
                    );
7218
                }
7649
                }
7219
            }
7650
            }
7220
        }
7651
        }
Línea 7221... Línea 7652...
7221
 
7652
 
Línea 7225... Línea 7656...
7225
    /**
7656
    /**
7226
     * Reveal student identities to markers (and the gradebook).
7657
     * Reveal student identities to markers (and the gradebook).
7227
     *
7658
     *
7228
     * @return void
7659
     * @return void
7229
     */
7660
     */
7230
    public function reveal_identities() {
7661
    public function reveal_identities()
-
 
7662
    {
7231
        global $DB;
7663
        global $DB;
Línea 7232... Línea 7664...
7232
 
7664
 
Línea 7233... Línea 7665...
7233
        require_capability('mod/assign:revealidentities', $this->context);
7665
        require_capability('mod/assign:revealidentities', $this->context);
Línea 7252... Línea 7684...
7252
        // Now release all grades.
7684
        // Now release all grades.
Línea 7253... Línea 7685...
7253
 
7685
 
7254
        $adminconfig = $this->get_admin_config();
7686
        $adminconfig = $this->get_admin_config();
7255
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7687
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
7256
        $gradebookplugin = str_replace('assignfeedback_', '', $gradebookplugin);
7688
        $gradebookplugin = str_replace('assignfeedback_', '', $gradebookplugin);
Línea 7257... Línea 7689...
7257
        $grades = $DB->get_records('assign_grades', array('assignment'=>$this->get_instance()->id));
7689
        $grades = $DB->get_records('assign_grades', array('assignment' => $this->get_instance()->id));
Línea 7258... Línea 7690...
7258
 
7690
 
7259
        $plugin = $this->get_feedback_plugin_by_type($gradebookplugin);
7691
        $plugin = $this->get_feedback_plugin_by_type($gradebookplugin);
Línea 7274... Línea 7706...
7274
    /**
7706
    /**
7275
     * Reveal student identities to markers (and the gradebook).
7707
     * Reveal student identities to markers (and the gradebook).
7276
     *
7708
     *
7277
     * @return void
7709
     * @return void
7278
     */
7710
     */
7279
    protected function process_reveal_identities() {
7711
    protected function process_reveal_identities()
-
 
7712
    {
Línea 7280... Línea 7713...
7280
 
7713
 
7281
        if (!confirm_sesskey()) {
7714
        if (!confirm_sesskey()) {
7282
            return false;
7715
            return false;
Línea 7289... Línea 7722...
7289
    /**
7722
    /**
7290
     * Save grading options.
7723
     * Save grading options.
7291
     *
7724
     *
7292
     * @return void
7725
     * @return void
7293
     */
7726
     */
7294
    protected function process_save_grading_options() {
7727
    protected function process_save_grading_options()
-
 
7728
    {
7295
        global $USER, $CFG;
7729
        global $USER, $CFG;
Línea 7296... Línea 7730...
7296
 
7730
 
7297
        // Include grading options form.
7731
        // Include grading options form.
Línea 7328... Línea 7762...
7328
        }
7762
        }
Línea 7329... Línea 7763...
7329
 
7763
 
7330
        // Get marking states to show in form.
7764
        // Get marking states to show in form.
Línea -... Línea 7765...
-
 
7765
        $markingworkflowoptions = $this->get_marking_workflow_filters();
7331
        $markingworkflowoptions = $this->get_marking_workflow_filters();
7766
 
7332
 
7767
        $gradingoptionsparams = array(
7333
        $gradingoptionsparams = array('cm'=>$this->get_course_module()->id,
7768
            'cm' => $this->get_course_module()->id,
7334
                                      'contextid'=>$this->context->id,
7769
            'contextid' => $this->context->id,
7335
                                      'userid'=>$USER->id,
7770
            'userid' => $USER->id,
7336
                                      'submissionsenabled'=>$this->is_any_submission_plugin_enabled(),
7771
            'submissionsenabled' => $this->is_any_submission_plugin_enabled(),
7337
                                      'showquickgrading'=>$showquickgrading,
7772
            'showquickgrading' => $showquickgrading,
7338
                                      'quickgrading'=>false,
7773
            'quickgrading' => false,
7339
                                      'markingworkflowopt' => $markingworkflowoptions,
7774
            'markingworkflowopt' => $markingworkflowoptions,
7340
                                      'markingallocationopt' => $markingallocationoptions,
7775
            'markingallocationopt' => $markingallocationoptions,
7341
                                      'showonlyactiveenrolopt'=>$showonlyactiveenrolopt,
7776
            'showonlyactiveenrolopt' => $showonlyactiveenrolopt,
-
 
7777
            'showonlyactiveenrol' => $this->show_only_active_users(),
7342
                                      'showonlyactiveenrol' => $this->show_only_active_users(),
7778
            'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1)
7343
                                      'downloadasfolders' => get_user_preferences('assign_downloadasfolders', 1));
7779
        );
7344
        $mform = new mod_assign_grading_options_form(null, $gradingoptionsparams);
7780
        $mform = new mod_assign_grading_options_form(null, $gradingoptionsparams);
7345
        if ($formdata = $mform->get_data()) {
7781
        if ($formdata = $mform->get_data()) {
7346
            set_user_preference('assign_perpage', $formdata->perpage);
7782
            set_user_preference('assign_perpage', $formdata->perpage);
Línea 7370... Línea 7806...
7370
    }
7806
    }
Línea 7371... Línea 7807...
7371
 
7807
 
7372
    /**
7808
    /**
7373
     * @deprecated since 2.7
7809
     * @deprecated since 2.7
7374
     */
7810
     */
-
 
7811
    public function format_grade_for_log()
7375
    public function format_grade_for_log() {
7812
    {
7376
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
7813
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
Línea 7377... Línea 7814...
7377
    }
7814
    }
7378
 
7815
 
7379
    /**
7816
    /**
7380
     * @deprecated since 2.7
7817
     * @deprecated since 2.7
-
 
7818
     */
7381
     */
7819
    public function format_submission_for_log()
7382
    public function format_submission_for_log() {
7820
    {
Línea 7383... Línea 7821...
7383
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
7821
        throw new coding_exception(__FUNCTION__ . ' has been deprecated, please do not use it any more');
7384
    }
7822
    }
7385
 
7823
 
7386
    /**
7824
    /**
7387
     * Require a valid sess key and then call copy_previous_attempt.
7825
     * Require a valid sess key and then call copy_previous_attempt.
7388
     *
7826
     *
7389
     * @param  array $notices Any error messages that should be shown
7827
     * @param  array $notices Any error messages that should be shown
7390
     *                        to the user at the top of the edit submission form.
7828
     *                        to the user at the top of the edit submission form.
-
 
7829
     * @return bool
7391
     * @return bool
7830
     */
Línea 7392... Línea 7831...
7392
     */
7831
    protected function process_copy_previous_attempt(&$notices)
7393
    protected function process_copy_previous_attempt(&$notices) {
7832
    {
Línea 7401... Línea 7840...
7401
     *
7840
     *
7402
     * @param  array $notices Any error messages that should be shown
7841
     * @param  array $notices Any error messages that should be shown
7403
     *                        to the user at the top of the edit submission form.
7842
     *                        to the user at the top of the edit submission form.
7404
     * @return bool
7843
     * @return bool
7405
     */
7844
     */
7406
    public function copy_previous_attempt(&$notices) {
7845
    public function copy_previous_attempt(&$notices)
-
 
7846
    {
7407
        global $USER, $CFG;
7847
        global $USER, $CFG;
Línea 7408... Línea 7848...
7408
 
7848
 
Línea 7409... Línea 7849...
7409
        require_capability('mod/assign:submit', $this->context);
7849
        require_capability('mod/assign:submit', $this->context);
Línea 7463... Línea 7903...
7463
        if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
7903
        if ($submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
7464
            $complete = COMPLETION_COMPLETE;
7904
            $complete = COMPLETION_COMPLETE;
7465
        }
7905
        }
7466
        $completion = new completion_info($this->get_course());
7906
        $completion = new completion_info($this->get_course());
7467
        if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7907
        if ($completion->is_enabled($this->get_course_module()) && $instance->completionsubmit) {
7468
            $this->update_activity_completion_records($instance->teamsubmission,
7908
            $this->update_activity_completion_records(
-
 
7909
                $instance->teamsubmission,
7469
                                                      $instance->requireallteammemberssubmit,
7910
                $instance->requireallteammemberssubmit,
7470
                                                      $submission,
7911
                $submission,
7471
                                                      $USER->id,
7912
                $USER->id,
7472
                                                      $complete,
7913
                $complete,
7473
                                                      $completion);
7914
                $completion
-
 
7915
            );
7474
        }
7916
        }
Línea 7475... Línea 7917...
7475
 
7917
 
7476
        if (!$instance->submissiondrafts) {
7918
        if (!$instance->submissiondrafts) {
7477
            // There is a case for not notifying the student about the submission copy,
7919
            // There is a case for not notifying the student about the submission copy,
Línea 7492... Línea 7934...
7492
     * Determine if the current submission is empty or not.
7934
     * Determine if the current submission is empty or not.
7493
     *
7935
     *
7494
     * @param submission $submission the students submission record to check.
7936
     * @param submission $submission the students submission record to check.
7495
     * @return bool
7937
     * @return bool
7496
     */
7938
     */
7497
    public function submission_empty($submission) {
7939
    public function submission_empty($submission)
-
 
7940
    {
7498
        $allempty = true;
7941
        $allempty = true;
Línea 7499... Línea 7942...
7499
 
7942
 
7500
        foreach ($this->submissionplugins as $plugin) {
7943
        foreach ($this->submissionplugins as $plugin) {
7501
            if ($plugin->is_enabled() && $plugin->is_visible()) {
7944
            if ($plugin->is_enabled() && $plugin->is_visible()) {
Línea 7511... Línea 7954...
7511
     * Determine if a new submission is empty or not
7954
     * Determine if a new submission is empty or not
7512
     *
7955
     *
7513
     * @param stdClass $data Submission data
7956
     * @param stdClass $data Submission data
7514
     * @return bool
7957
     * @return bool
7515
     */
7958
     */
7516
    public function new_submission_empty($data) {
7959
    public function new_submission_empty($data)
-
 
7960
    {
7517
        foreach ($this->submissionplugins as $plugin) {
7961
        foreach ($this->submissionplugins as $plugin) {
-
 
7962
            if (
7518
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions() &&
7963
                $plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions() &&
7519
                    !$plugin->submission_is_empty($data)) {
7964
                !$plugin->submission_is_empty($data)
-
 
7965
            ) {
7520
                return false;
7966
                return false;
7521
            }
7967
            }
7522
        }
7968
        }
7523
        return true;
7969
        return true;
7524
    }
7970
    }
Línea 7529... Línea 7975...
7529
     * @param  stdClass $data
7975
     * @param  stdClass $data
7530
     * @param  array $notices Any error messages that should be shown
7976
     * @param  array $notices Any error messages that should be shown
7531
     *                        to the user.
7977
     *                        to the user.
7532
     * @return bool
7978
     * @return bool
7533
     */
7979
     */
7534
    public function save_submission(stdClass $data, & $notices) {
7980
    public function save_submission(stdClass $data, &$notices)
-
 
7981
    {
7535
        global $CFG, $USER, $DB;
7982
        global $CFG, $USER, $DB;
Línea 7536... Línea 7983...
7536
 
7983
 
7537
        $userid = $USER->id;
7984
        $userid = $USER->id;
7538
        if (!empty($data->userid)) {
7985
        if (!empty($data->userid)) {
7539
            $userid = $data->userid;
7986
            $userid = $data->userid;
Línea 7540... Línea 7987...
7540
        }
7987
        }
7541
 
7988
 
7542
        $user = clone($USER);
7989
        $user = clone ($USER);
7543
        if ($userid == $USER->id) {
7990
        if ($userid == $USER->id) {
7544
            require_capability('mod/assign:submit', $this->context);
7991
            require_capability('mod/assign:submit', $this->context);
7545
        } else {
7992
        } else {
7546
            $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
7993
            $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
7547
            if (!$this->can_edit_submission($userid, $USER->id)) {
7994
            if (!$this->can_edit_submission($userid, $USER->id)) {
7548
                throw new \moodle_exception('nopermission');
7995
                throw new \moodle_exception('nopermission');
7549
            }
7996
            }
Línea 7564... Línea 8011...
7564
        // Check that no one has modified the submission since we started looking at it.
8011
        // Check that no one has modified the submission since we started looking at it.
7565
        if (isset($data->lastmodified) && ($submission->timemodified > $data->lastmodified)) {
8012
        if (isset($data->lastmodified) && ($submission->timemodified > $data->lastmodified)) {
7566
            // Another user has submitted something. Notify the current user.
8013
            // Another user has submitted something. Notify the current user.
7567
            if ($submission->status !== ASSIGN_SUBMISSION_STATUS_NEW) {
8014
            if ($submission->status !== ASSIGN_SUBMISSION_STATUS_NEW) {
7568
                $notices[] = $instance->teamsubmission ? get_string('submissionmodifiedgroup', 'mod_assign')
8015
                $notices[] = $instance->teamsubmission ? get_string('submissionmodifiedgroup', 'mod_assign')
7569
                                                       : get_string('submissionmodified', 'mod_assign');
8016
                    : get_string('submissionmodified', 'mod_assign');
7570
                return false;
8017
                return false;
7571
            }
8018
            }
7572
        }
8019
        }
Línea 7573... Línea 8020...
7573
 
8020
 
Línea 7609... Línea 8056...
7609
        if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
8056
        if ($instance->teamsubmission && !$instance->requireallteammemberssubmit) {
7610
            $team = $this->get_submission_group_members($submission->groupid, true);
8057
            $team = $this->get_submission_group_members($submission->groupid, true);
Línea 7611... Línea 8058...
7611
 
8058
 
7612
            foreach ($team as $member) {
8059
            foreach ($team as $member) {
7613
                if ($member->id != $userid) {
8060
                if ($member->id != $userid) {
7614
                    $membersubmission = clone($submission);
8061
                    $membersubmission = clone ($submission);
7615
                    $this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
8062
                    $this->update_submission($membersubmission, $member->id, true, $instance->teamsubmission);
7616
                    $users[] = $member->id;
8063
                    $users[] = $member->id;
7617
                }
8064
                }
7618
            }
8065
            }
Línea 7649... Línea 8096...
7649
     * @param  moodleform $mform
8096
     * @param  moodleform $mform
7650
     * @param  array $notices Any error messages that should be shown
8097
     * @param  array $notices Any error messages that should be shown
7651
     *                        to the user at the top of the edit submission form.
8098
     *                        to the user at the top of the edit submission form.
7652
     * @return bool
8099
     * @return bool
7653
     */
8100
     */
7654
    protected function process_save_submission(&$mform, &$notices) {
8101
    protected function process_save_submission(&$mform, &$notices)
-
 
8102
    {
7655
        global $CFG, $USER;
8103
        global $CFG, $USER;
Línea 7656... Línea 8104...
7656
 
8104
 
7657
        // Include submission form.
8105
        // Include submission form.
Línea 7685... Línea 8133...
7685
     * @param int $userid - The student userid
8133
     * @param int $userid - The student userid
7686
     * @param bool $checkworkflow - whether to include a check for the workflow state.
8134
     * @param bool $checkworkflow - whether to include a check for the workflow state.
7687
     * @param stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.
8135
     * @param stdClass $gradinginfo - optional, allow gradinginfo to be passed for performance.
7688
     * @return bool $gradingdisabled
8136
     * @return bool $gradingdisabled
7689
     */
8137
     */
7690
    public function grading_disabled($userid, $checkworkflow = true, $gradinginfo = null) {
8138
    public function grading_disabled($userid, $checkworkflow = true, $gradinginfo = null)
-
 
8139
    {
7691
        if ($checkworkflow && $this->get_instance()->markingworkflow) {
8140
        if ($checkworkflow && $this->get_instance()->markingworkflow) {
7692
            $grade = $this->get_user_grade($userid, false);
8141
            $grade = $this->get_user_grade($userid, false);
7693
            $validstates = $this->get_marking_workflow_states_for_current_user();
8142
            $validstates = $this->get_marking_workflow_states_for_current_user();
7694
            if (!empty($grade) && !empty($grade->workflowstate) && !array_key_exists($grade->workflowstate, $validstates)) {
8143
            if (!empty($grade) && !empty($grade->workflowstate) && !array_key_exists($grade->workflowstate, $validstates)) {
7695
                return true;
8144
                return true;
7696
            }
8145
            }
7697
        }
8146
        }
Línea 7698... Línea 8147...
7698
 
8147
 
7699
        if (is_null($gradinginfo)) {
8148
        if (is_null($gradinginfo)) {
-
 
8149
            $gradinginfo = grade_get_grades(
7700
            $gradinginfo = grade_get_grades($this->get_course()->id,
8150
                $this->get_course()->id,
7701
                'mod',
8151
                'mod',
7702
                'assign',
8152
                'assign',
7703
                $this->get_instance()->id,
8153
                $this->get_instance()->id,
-
 
8154
                array($userid)
7704
                array($userid));
8155
            );
Línea 7705... Línea 8156...
7705
        }
8156
        }
7706
 
8157
 
7707
        if (!$gradinginfo) {
8158
        if (!$gradinginfo) {
Línea 7708... Línea 8159...
7708
            return false;
8159
            return false;
7709
        }
8160
        }
7710
 
8161
 
7711
        if (!isset($gradinginfo->items[0]->grades[$userid])) {
8162
        if (!isset($gradinginfo->items[0]->grades[$userid])) {
7712
            return false;
8163
            return false;
7713
        }
8164
        }
7714
        $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked ||
8165
        $gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked ||
Línea 7715... Línea 8166...
7715
                           $gradinginfo->items[0]->grades[$userid]->overridden;
8166
            $gradinginfo->items[0]->grades[$userid]->overridden;
Línea 7724... Línea 8175...
7724
     * @param int $userid - The student userid
8175
     * @param int $userid - The student userid
7725
     * @param stdClass|false $grade - The grade record
8176
     * @param stdClass|false $grade - The grade record
7726
     * @param bool $gradingdisabled
8177
     * @param bool $gradingdisabled
7727
     * @return mixed gradingform_instance|null $gradinginstance
8178
     * @return mixed gradingform_instance|null $gradinginstance
7728
     */
8179
     */
7729
    protected function get_grading_instance($userid, $grade, $gradingdisabled) {
8180
    protected function get_grading_instance($userid, $grade, $gradingdisabled)
-
 
8181
    {
7730
        global $CFG, $USER;
8182
        global $CFG, $USER;
Línea 7731... Línea 8183...
7731
 
8183
 
7732
        $grademenu = make_grades_menu($this->get_instance()->grade);
8184
        $grademenu = make_grades_menu($this->get_instance()->grade);
Línea 7744... Línea 8196...
7744
                }
8196
                }
7745
                if ($gradingdisabled && $itemid) {
8197
                if ($gradingdisabled && $itemid) {
7746
                    $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
8198
                    $gradinginstance = $controller->get_current_instance($USER->id, $itemid);
7747
                } else if (!$gradingdisabled) {
8199
                } else if (!$gradingdisabled) {
7748
                    $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
8200
                    $instanceid = optional_param('advancedgradinginstanceid', 0, PARAM_INT);
7749
                    $gradinginstance = $controller->get_or_create_instance($instanceid,
8201
                    $gradinginstance = $controller->get_or_create_instance(
-
 
8202
                        $instanceid,
7750
                                                                           $USER->id,
8203
                        $USER->id,
7751
                                                                           $itemid);
8204
                        $itemid
-
 
8205
                    );
7752
                }
8206
                }
7753
            } else {
8207
            } else {
7754
                $advancedgradingwarning = $controller->form_unavailable_notification();
8208
                $advancedgradingwarning = $controller->form_unavailable_notification();
7755
            }
8209
            }
7756
        }
8210
        }
Línea 7766... Línea 8220...
7766
     * @param MoodleQuickForm $mform
8220
     * @param MoodleQuickForm $mform
7767
     * @param stdClass $data
8221
     * @param stdClass $data
7768
     * @param array $params
8222
     * @param array $params
7769
     * @return void
8223
     * @return void
7770
     */
8224
     */
7771
    public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params) {
8225
    public function add_grade_form_elements(MoodleQuickForm $mform, stdClass $data, $params)
-
 
8226
    {
7772
        global $USER, $CFG, $SESSION;
8227
        global $USER, $CFG, $SESSION;
7773
        $settings = $this->get_instance();
8228
        $settings = $this->get_instance();
Línea 7774... Línea 8229...
7774
 
8229
 
7775
        $rownum = isset($params['rownum']) ? $params['rownum'] : 0;
8230
        $rownum = isset($params['rownum']) ? $params['rownum'] : 0;
Línea 7804... Línea 8259...
7804
        $gradingdisabled = $this->grading_disabled($userid);
8259
        $gradingdisabled = $this->grading_disabled($userid);
7805
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
8260
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
Línea 7806... Línea 8261...
7806
 
8261
 
7807
        $mform->addElement('header', 'gradeheader', get_string('gradenoun'));
8262
        $mform->addElement('header', 'gradeheader', get_string('gradenoun'));
7808
        if ($gradinginstance) {
8263
        if ($gradinginstance) {
-
 
8264
            $gradingelement = $mform->addElement(
7809
            $gradingelement = $mform->addElement('grading',
8265
                'grading',
7810
                                                 'advancedgrading',
8266
                'advancedgrading',
7811
                                                 get_string('gradenoun') . ':',
8267
                get_string('gradenoun') . ':',
-
 
8268
                array('gradinginstance' => $gradinginstance)
7812
                                                 array('gradinginstance' => $gradinginstance));
8269
            );
7813
            if ($gradingdisabled) {
8270
            if ($gradingdisabled) {
7814
                $gradingelement->freeze();
8271
                $gradingelement->freeze();
7815
            } else {
8272
            } else {
7816
                $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
8273
                $mform->addElement('hidden', 'advancedgradinginstanceid', $gradinginstance->get_id());
Línea 7844... Línea 8301...
7844
                    }
8301
                    }
7845
                }
8302
                }
7846
            }
8303
            }
7847
        }
8304
        }
Línea 7848... Línea 8305...
7848
 
8305
 
7849
        $gradinginfo = grade_get_grades($this->get_course()->id,
8306
        $gradinginfo = grade_get_grades(
-
 
8307
            $this->get_course()->id,
7850
                                        'mod',
8308
            'mod',
7851
                                        'assign',
8309
            'assign',
7852
                                        $this->get_instance()->id,
8310
            $this->get_instance()->id,
-
 
8311
            $userid
7853
                                        $userid);
8312
        );
7854
        if (!empty($CFG->enableoutcomes)) {
8313
        if (!empty($CFG->enableoutcomes)) {
7855
            foreach ($gradinginfo->outcomes as $index => $outcome) {
8314
            foreach ($gradinginfo->outcomes as $index => $outcome) {
7856
                $options = make_grades_menu(-$outcome->scaleid);
8315
                $options = make_grades_menu(-$outcome->scaleid);
7857
                $options[0] = get_string('nooutcome', 'grades');
8316
                $options[0] = get_string('nooutcome', 'grades');
7858
                if ($outcome->grades[$userid]->locked) {
8317
                if ($outcome->grades[$userid]->locked) {
-
 
8318
                    $mform->addElement(
7859
                    $mform->addElement('static',
8319
                        'static',
7860
                                       'outcome_' . $index . '[' . $userid . ']',
8320
                        'outcome_' . $index . '[' . $userid . ']',
7861
                                       $outcome->name . ':',
8321
                        $outcome->name . ':',
-
 
8322
                        $options[$outcome->grades[$userid]->grade]
7862
                                       $options[$outcome->grades[$userid]->grade]);
8323
                    );
7863
                } else {
8324
                } else {
7864
                    $attributes = array('id' => 'menuoutcome_' . $index );
8325
                    $attributes = array('id' => 'menuoutcome_' . $index);
-
 
8326
                    $mform->addElement(
7865
                    $mform->addElement('select',
8327
                        'select',
7866
                                       'outcome_' . $index . '[' . $userid . ']',
8328
                        'outcome_' . $index . '[' . $userid . ']',
7867
                                       $outcome->name.':',
8329
                        $outcome->name . ':',
7868
                                       $options,
8330
                        $options,
-
 
8331
                        $attributes
7869
                                       $attributes);
8332
                    );
-
 
8333
                    $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
7870
                    $mform->setType('outcome_' . $index . '[' . $userid . ']', PARAM_INT);
8334
                    $mform->setDefault(
7871
                    $mform->setDefault('outcome_' . $index . '[' . $userid . ']',
8335
                        'outcome_' . $index . '[' . $userid . ']',
-
 
8336
                        $outcome->grades[$userid]->grade
7872
                                       $outcome->grades[$userid]->grade);
8337
                    );
7873
                }
8338
                }
7874
            }
8339
            }
Línea 7875... Línea 8340...
7875
        }
8340
        }
7876
 
8341
 
7877
        $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
8342
        $capabilitylist = array('gradereport/grader:view', 'moodle/grade:viewall');
7878
        $usergrade = get_string('notgraded', 'assign');
8343
        $usergrade = get_string('notgraded', 'assign');
7879
        if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
8344
        if (has_all_capabilities($capabilitylist, $this->get_course_context())) {
7880
            $urlparams = array('id'=>$this->get_course()->id);
8345
            $urlparams = array('id' => $this->get_course()->id);
7881
            $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
8346
            $url = new moodle_url('/grade/report/grader/index.php', $urlparams);
7882
            if (isset($gradinginfo->items[0]->grades[$userid]->grade)) {
8347
            if (isset($gradinginfo->items[0]->grades[$userid]->grade)) {
7883
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
8348
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
7884
            }
8349
            }
-
 
8350
            $gradestring = $this->get_renderer()->action_link($url, $usergrade);
7885
            $gradestring = $this->get_renderer()->action_link($url, $usergrade);
8351
        } else {
7886
        } else {
8352
            if (
-
 
8353
                isset($gradinginfo->items[0]->grades[$userid]) &&
7887
            if (isset($gradinginfo->items[0]->grades[$userid]) &&
8354
                !$gradinginfo->items[0]->grades[$userid]->hidden
7888
                    !$gradinginfo->items[0]->grades[$userid]->hidden) {
8355
            ) {
7889
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
8356
                $usergrade = $gradinginfo->items[0]->grades[$userid]->str_grade;
7890
            }
8357
            }
Línea 7916... Línea 8383...
7916
                    $mform->addElement('static', 'currentassigngrade', $label, $assigngradestring);
8383
                    $mform->addElement('static', 'currentassigngrade', $label, $assigngradestring);
7917
                }
8384
                }
7918
            }
8385
            }
7919
        }
8386
        }
Línea -... Línea 8387...
-
 
8387
 
7920
 
8388
        if (
7921
        if ($this->get_instance()->markingworkflow &&
8389
            $this->get_instance()->markingworkflow &&
7922
            $this->get_instance()->markingallocation &&
8390
            $this->get_instance()->markingallocation &&
-
 
8391
            has_capability('mod/assign:manageallocations', $this->context)
Línea 7923... Línea 8392...
7923
            has_capability('mod/assign:manageallocations', $this->context)) {
8392
        ) {
7924
 
8393
 
7925
            list($sort, $params) = users_order_by_sql('u');
8394
            list($sort, $params) = users_order_by_sql('u');
7926
            // Only enrolled users could be assigned as potential markers.
8395
            // Only enrolled users could be assigned as potential markers.
Línea 7940... Línea 8409...
7940
 
8409
 
7941
        $gradestring = '<span class="currentgrade">' . $gradestring . '</span>';
8410
        $gradestring = '<span class="currentgrade">' . $gradestring . '</span>';
Línea 7942... Línea 8411...
7942
        $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
8411
        $mform->addElement('static', 'currentgrade', get_string('currentgrade', 'assign'), $gradestring);
7943
 
8412
 
7944
        if (count($useridlist) > 1) {
8413
        if (count($useridlist) > 1) {
7945
            $strparams = array('current'=>$rownum+1, 'total'=>count($useridlist));
8414
            $strparams = array('current' => $rownum + 1, 'total' => count($useridlist));
7946
            $name = get_string('outof', 'assign', $strparams);
8415
            $name = get_string('outof', 'assign', $strparams);
Línea 7947... Línea 8416...
7947
            $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
8416
            $mform->addElement('static', 'gradingstudent', get_string('gradingstudent', 'assign'), $name);
Línea 7971... Línea 8440...
7971
            $mform->setDefault('applytoall', 1);
8440
            $mform->setDefault('applytoall', 1);
7972
        }
8441
        }
Línea 7973... Línea 8442...
7973
 
8442
 
7974
        // Do not show if we are editing a previous attempt.
8443
        // Do not show if we are editing a previous attempt.
7975
        if (($attemptnumber == -1 ||
8444
        if (($attemptnumber == -1 ||
7976
            ($attemptnumber + 1) == count($this->get_all_submissions($userid))) &&
8445
                ($attemptnumber + 1) == count($this->get_all_submissions($userid))) &&
-
 
8446
            $this->get_instance()->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE
7977
            $this->get_instance()->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
8447
        ) {
7978
            $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign'));
8448
            $mform->addElement('header', 'attemptsettings', get_string('attemptsettings', 'assign'));
7979
            $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign');
8449
            $attemptreopenmethod = get_string('attemptreopenmethod_' . $this->get_instance()->attemptreopenmethod, 'assign');
Línea 7980... Línea 8450...
7980
            $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod);
8450
            $mform->addElement('static', 'attemptreopenmethod', get_string('attemptreopenmethod', 'assign'), $attemptreopenmethod);
Línea 7991... Línea 8461...
7991
            $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1);
8461
            $mform->addelement('static', 'attemptnumberlabel', get_string('attemptnumber', 'assign'), $attemptnumber + 1);
Línea 7992... Línea 8462...
7992
 
8462
 
7993
            $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
8463
            $ismanual = $this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
7994
            $issubmission = !empty($submission);
8464
            $issubmission = !empty($submission);
7995
            $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
8465
            $isunlimited = $this->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
Línea 7996... Línea 8466...
7996
            $islessthanmaxattempts = $issubmission && ($submission->attemptnumber < ($this->get_instance()->maxattempts-1));
8466
            $islessthanmaxattempts = $issubmission && ($submission->attemptnumber < ($this->get_instance()->maxattempts - 1));
7997
 
8467
 
7998
            if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) {
8468
            if ($ismanual && (!$issubmission || $isunlimited || $islessthanmaxattempts)) {
7999
                $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign'));
8469
                $mform->addElement('selectyesno', 'addattempt', get_string('addattempt', 'assign'));
Línea 8065... Línea 8535...
8065
     * @param MoodleQuickForm $mform
8535
     * @param MoodleQuickForm $mform
8066
     * @param stdClass $data
8536
     * @param stdClass $data
8067
     * @param int $userid The current userid (same as $USER->id)
8537
     * @param int $userid The current userid (same as $USER->id)
8068
     * @return void
8538
     * @return void
8069
     */
8539
     */
8070
    protected function add_plugin_submission_elements($submission,
8540
    protected function add_plugin_submission_elements(
-
 
8541
        $submission,
8071
                                                    MoodleQuickForm $mform,
8542
        MoodleQuickForm $mform,
8072
                                                    stdClass $data,
8543
        stdClass $data,
8073
                                                    $userid) {
8544
        $userid
-
 
8545
    ) {
8074
        foreach ($this->submissionplugins as $plugin) {
8546
        foreach ($this->submissionplugins as $plugin) {
8075
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
8547
            if ($plugin->is_enabled() && $plugin->is_visible() && $plugin->allow_submissions()) {
8076
                $plugin->get_form_elements_for_user($submission, $mform, $data, $userid);
8548
                $plugin->get_form_elements_for_user($submission, $mform, $data, $userid);
8077
            }
8549
            }
8078
        }
8550
        }
Línea 8081... Línea 8553...
8081
    /**
8553
    /**
8082
     * Check if feedback plugins installed are enabled.
8554
     * Check if feedback plugins installed are enabled.
8083
     *
8555
     *
8084
     * @return bool
8556
     * @return bool
8085
     */
8557
     */
8086
    public function is_any_feedback_plugin_enabled() {
8558
    public function is_any_feedback_plugin_enabled()
-
 
8559
    {
8087
        if (!isset($this->cache['any_feedback_plugin_enabled'])) {
8560
        if (!isset($this->cache['any_feedback_plugin_enabled'])) {
8088
            $this->cache['any_feedback_plugin_enabled'] = false;
8561
            $this->cache['any_feedback_plugin_enabled'] = false;
8089
            foreach ($this->feedbackplugins as $plugin) {
8562
            foreach ($this->feedbackplugins as $plugin) {
8090
                if ($plugin->is_enabled() && $plugin->is_visible()) {
8563
                if ($plugin->is_enabled() && $plugin->is_visible()) {
8091
                    $this->cache['any_feedback_plugin_enabled'] = true;
8564
                    $this->cache['any_feedback_plugin_enabled'] = true;
Línea 8093... Línea 8566...
8093
                }
8566
                }
8094
            }
8567
            }
8095
        }
8568
        }
Línea 8096... Línea 8569...
8096
 
8569
 
8097
        return $this->cache['any_feedback_plugin_enabled'];
-
 
8098
 
8570
        return $this->cache['any_feedback_plugin_enabled'];
Línea 8099... Línea 8571...
8099
    }
8571
    }
8100
 
8572
 
8101
    /**
8573
    /**
8102
     * Check if submission plugins installed are enabled.
8574
     * Check if submission plugins installed are enabled.
8103
     *
8575
     *
8104
     * @return bool
8576
     * @return bool
-
 
8577
     */
8105
     */
8578
    public function is_any_submission_plugin_enabled()
8106
    public function is_any_submission_plugin_enabled() {
8579
    {
8107
        if (!isset($this->cache['any_submission_plugin_enabled'])) {
8580
        if (!isset($this->cache['any_submission_plugin_enabled'])) {
8108
            $this->cache['any_submission_plugin_enabled'] = false;
8581
            $this->cache['any_submission_plugin_enabled'] = false;
8109
            foreach ($this->submissionplugins as $plugin) {
8582
            foreach ($this->submissionplugins as $plugin) {
Línea 8113... Línea 8586...
8113
                }
8586
                }
8114
            }
8587
            }
8115
        }
8588
        }
Línea 8116... Línea 8589...
8116
 
8589
 
8117
        return $this->cache['any_submission_plugin_enabled'];
-
 
8118
 
8590
        return $this->cache['any_submission_plugin_enabled'];
Línea 8119... Línea 8591...
8119
    }
8591
    }
8120
 
8592
 
8121
    /**
8593
    /**
8122
     * Add elements to submission form.
8594
     * Add elements to submission form.
8123
     * @param MoodleQuickForm $mform
8595
     * @param MoodleQuickForm $mform
8124
     * @param stdClass $data
8596
     * @param stdClass $data
8125
     * @return void
8597
     * @return void
-
 
8598
     */
8126
     */
8599
    public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data)
Línea 8127... Línea 8600...
8127
    public function add_submission_form_elements(MoodleQuickForm $mform, stdClass $data) {
8600
    {
8128
        global $USER;
8601
        global $USER;
8129
 
8602
 
Línea 8155... Línea 8628...
8155
        $mform->addElement('header', 'submission header', get_string('addsubmission', 'mod_assign'));
8628
        $mform->addElement('header', 'submission header', get_string('addsubmission', 'mod_assign'));
Línea 8156... Línea 8629...
8156
 
8629
 
8157
        // Only show submission statement if we are editing our own submission.
8630
        // Only show submission statement if we are editing our own submission.
8158
        if ($requiresubmissionstatement && !$draftsenabled && $userid == $USER->id) {
8631
        if ($requiresubmissionstatement && !$draftsenabled && $userid == $USER->id) {
-
 
8632
            $mform->addElement('checkbox', 'submissionstatement', '', $submissionstatement);
-
 
8633
            $mform->addRule(
8159
            $mform->addElement('checkbox', 'submissionstatement', '', $submissionstatement);
8634
                'submissionstatement',
8160
            $mform->addRule('submissionstatement', get_string('submissionstatementrequired', 'mod_assign'),
8635
                get_string('submissionstatementrequired', 'mod_assign'),
-
 
8636
                'required',
-
 
8637
                null,
-
 
8638
                'client'
8161
                'required', null, 'client');
8639
            );
Línea 8162... Línea 8640...
8162
        }
8640
        }
Línea 8163... Línea 8641...
8163
 
8641
 
Línea 8179... Línea 8657...
8179
     *
8657
     *
8180
     * @param int $userid
8658
     * @param int $userid
8181
     * @return boolean
8659
     * @return boolean
8182
     * @throws coding_exception
8660
     * @throws coding_exception
8183
     */
8661
     */
8184
    public function remove_submission($userid) {
8662
    public function remove_submission($userid)
-
 
8663
    {
8185
        global $USER;
8664
        global $USER;
Línea 8186... Línea 8665...
8186
 
8665
 
8187
        if (!$this->can_edit_submission($userid, $USER->id)) {
8666
        if (!$this->can_edit_submission($userid, $USER->id)) {
8188
            $user = core_user::get_user($userid);
8667
            $user = core_user::get_user($userid);
Línea 8210... Línea 8689...
8210
                $plugin->remove($submission);
8689
                $plugin->remove($submission);
8211
            }
8690
            }
8212
        }
8691
        }
Línea 8213... Línea 8692...
8213
 
8692
 
-
 
8693
        $completion = new completion_info($this->get_course());
8214
        $completion = new completion_info($this->get_course());
8694
        if (
8215
        if ($completion->is_enabled($this->get_course_module()) &&
8695
            $completion->is_enabled($this->get_course_module()) &&
-
 
8696
            $this->get_instance()->completionsubmit
8216
                $this->get_instance()->completionsubmit) {
8697
        ) {
8217
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8698
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
Línea 8218... Línea 8699...
8218
        }
8699
        }
8219
 
8700
 
Línea 8226... Línea 8707...
8226
     * Revert to draft.
8707
     * Revert to draft.
8227
     *
8708
     *
8228
     * @param int $userid
8709
     * @param int $userid
8229
     * @return boolean
8710
     * @return boolean
8230
     */
8711
     */
8231
    public function revert_to_draft($userid) {
8712
    public function revert_to_draft($userid)
-
 
8713
    {
8232
        global $DB, $USER;
8714
        global $DB, $USER;
Línea 8233... Línea 8715...
8233
 
8715
 
8234
        // Need grade permission.
8716
        // Need grade permission.
Línea 8257... Línea 8739...
8257
        $grade = $this->get_user_grade($userid, true);
8739
        $grade = $this->get_user_grade($userid, true);
8258
        $grade->grader = $USER->id;
8740
        $grade->grader = $USER->id;
8259
        $this->update_grade($grade);
8741
        $this->update_grade($grade);
Línea 8260... Línea 8742...
8260
 
8742
 
-
 
8743
        $completion = new completion_info($this->get_course());
8261
        $completion = new completion_info($this->get_course());
8744
        if (
8262
        if ($completion->is_enabled($this->get_course_module()) &&
8745
            $completion->is_enabled($this->get_course_module()) &&
-
 
8746
            $this->get_instance()->completionsubmit
8263
                $this->get_instance()->completionsubmit) {
8747
        ) {
8264
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8748
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
8265
        }
8749
        }
8266
        \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
8750
        \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
8267
        return true;
8751
        return true;
Línea 8271... Línea 8755...
8271
     * Remove the current submission.
8755
     * Remove the current submission.
8272
     *
8756
     *
8273
     * @param int $userid
8757
     * @param int $userid
8274
     * @return boolean
8758
     * @return boolean
8275
     */
8759
     */
8276
    protected function process_remove_submission($userid = 0) {
8760
    protected function process_remove_submission($userid = 0)
-
 
8761
    {
8277
        require_sesskey();
8762
        require_sesskey();
Línea 8278... Línea 8763...
8278
 
8763
 
8279
        if (!$userid) {
8764
        if (!$userid) {
8280
            $userid = required_param('userid', PARAM_INT);
8765
            $userid = required_param('userid', PARAM_INT);
Línea 8288... Línea 8773...
8288
     * Uses url parameter userid if userid not supplied as a parameter.
8773
     * Uses url parameter userid if userid not supplied as a parameter.
8289
     *
8774
     *
8290
     * @param int $userid
8775
     * @param int $userid
8291
     * @return boolean
8776
     * @return boolean
8292
     */
8777
     */
8293
    protected function process_revert_to_draft($userid = 0) {
8778
    protected function process_revert_to_draft($userid = 0)
-
 
8779
    {
8294
        require_sesskey();
8780
        require_sesskey();
Línea 8295... Línea 8781...
8295
 
8781
 
8296
        if (!$userid) {
8782
        if (!$userid) {
8297
            $userid = required_param('userid', PARAM_INT);
8783
            $userid = required_param('userid', PARAM_INT);
Línea 8304... Línea 8790...
8304
     * Prevent student updates to this submission
8790
     * Prevent student updates to this submission
8305
     *
8791
     *
8306
     * @param int $userid
8792
     * @param int $userid
8307
     * @return bool
8793
     * @return bool
8308
     */
8794
     */
8309
    public function lock_submission($userid) {
8795
    public function lock_submission($userid)
-
 
8796
    {
8310
        global $USER, $DB;
8797
        global $USER, $DB;
8311
        // Need grade permission.
8798
        // Need grade permission.
8312
        require_capability('mod/assign:grade', $this->context);
8799
        require_capability('mod/assign:grade', $this->context);
Línea 8313... Línea 8800...
8313
 
8800
 
Línea 8334... Línea 8821...
8334
    /**
8821
    /**
8335
     * Set the workflow state for multiple users
8822
     * Set the workflow state for multiple users
8336
     *
8823
     *
8337
     * @return void
8824
     * @return void
8338
     */
8825
     */
8339
    protected function process_set_batch_marking_workflow_state() {
8826
    protected function process_set_batch_marking_workflow_state()
-
 
8827
    {
8340
        global $CFG, $DB;
8828
        global $CFG, $DB;
Línea 8341... Línea 8829...
8341
 
8829
 
8342
        // Include batch marking workflow form.
8830
        // Include batch marking workflow form.
Línea 8366... Línea 8854...
8366
                // Clear the mailed flag if notification is requested, the student hasn't been
8854
                // Clear the mailed flag if notification is requested, the student hasn't been
8367
                // notified previously, the student can access the assignment, and the state
8855
                // notified previously, the student can access the assignment, and the state
8368
                // is "Released".
8856
                // is "Released".
8369
                $modinfo = get_fast_modinfo($this->course, $userid);
8857
                $modinfo = get_fast_modinfo($this->course, $userid);
8370
                $cm = $modinfo->get_cm($this->get_course_module()->id);
8858
                $cm = $modinfo->get_cm($this->get_course_module()->id);
-
 
8859
                if (
8371
                if ($formdata->sendstudentnotifications && $cm->uservisible &&
8860
                    $formdata->sendstudentnotifications && $cm->uservisible &&
8372
                        $state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
8861
                    $state == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
-
 
8862
                ) {
8373
                    $flags->mailed = 0;
8863
                    $flags->mailed = 0;
8374
                }
8864
                }
Línea 8375... Línea 8865...
8375
 
8865
 
Línea 8408... Línea 8898...
8408
    /**
8898
    /**
8409
     * Set the marking allocation for multiple users
8899
     * Set the marking allocation for multiple users
8410
     *
8900
     *
8411
     * @return void
8901
     * @return void
8412
     */
8902
     */
8413
    protected function process_set_batch_marking_allocation() {
8903
    protected function process_set_batch_marking_allocation()
-
 
8904
    {
8414
        global $CFG, $DB;
8905
        global $CFG, $DB;
Línea 8415... Línea 8906...
8415
 
8906
 
8416
        // Include batch marking allocation form.
8907
        // Include batch marking allocation form.
Línea 8441... Línea 8932...
8441
            $useridlist = explode(',', $formdata->selectedusers);
8932
            $useridlist = explode(',', $formdata->selectedusers);
8442
            $marker = $DB->get_record('user', array('id' => $formdata->allocatedmarker), '*', MUST_EXIST);
8933
            $marker = $DB->get_record('user', array('id' => $formdata->allocatedmarker), '*', MUST_EXIST);
Línea 8443... Línea 8934...
8443
 
8934
 
8444
            foreach ($useridlist as $userid) {
8935
            foreach ($useridlist as $userid) {
-
 
8936
                $flags = $this->get_user_flags($userid, true);
8445
                $flags = $this->get_user_flags($userid, true);
8937
                if (
8446
                if ($flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
8938
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW ||
8447
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
8939
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW ||
8448
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
8940
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE ||
-
 
8941
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
Línea 8449... Línea 8942...
8449
                    $flags->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
8942
                ) {
8450
 
8943
 
Línea 8451... Línea 8944...
8451
                    continue; // Allocated marker can only be changed in certain workflow states.
8944
                    continue; // Allocated marker can only be changed in certain workflow states.
Línea 8467... Línea 8960...
8467
     * Uses url parameter userid.
8960
     * Uses url parameter userid.
8468
     *
8961
     *
8469
     * @param int $userid
8962
     * @param int $userid
8470
     * @return void
8963
     * @return void
8471
     */
8964
     */
8472
    protected function process_lock_submission($userid = 0) {
8965
    protected function process_lock_submission($userid = 0)
-
 
8966
    {
Línea 8473... Línea 8967...
8473
 
8967
 
Línea 8474... Línea 8968...
8474
        require_sesskey();
8968
        require_sesskey();
8475
 
8969
 
Línea 8484... Línea 8978...
8484
     * Unlock the student submission.
8978
     * Unlock the student submission.
8485
     *
8979
     *
8486
     * @param int $userid
8980
     * @param int $userid
8487
     * @return bool
8981
     * @return bool
8488
     */
8982
     */
8489
    public function unlock_submission($userid) {
8983
    public function unlock_submission($userid)
-
 
8984
    {
8490
        global $USER, $DB;
8985
        global $USER, $DB;
Línea 8491... Línea 8986...
8491
 
8986
 
8492
        // Need grade permission.
8987
        // Need grade permission.
Línea 8516... Línea 9011...
8516
     * Uses url parameter userid.
9011
     * Uses url parameter userid.
8517
     *
9012
     *
8518
     * @param int $userid
9013
     * @param int $userid
8519
     * @return bool
9014
     * @return bool
8520
     */
9015
     */
8521
    protected function process_unlock_submission($userid = 0) {
9016
    protected function process_unlock_submission($userid = 0)
-
 
9017
    {
Línea 8522... Línea 9018...
8522
 
9018
 
Línea 8523... Línea 9019...
8523
        require_sesskey();
9019
        require_sesskey();
8524
 
9020
 
Línea 8535... Línea 9031...
8535
     * @param stdClass $formdata - the data from the form
9031
     * @param stdClass $formdata - the data from the form
8536
     * @param int $userid - the user to apply the grade to
9032
     * @param int $userid - the user to apply the grade to
8537
     * @param int $attemptnumber - The attempt number to apply the grade to.
9033
     * @param int $attemptnumber - The attempt number to apply the grade to.
8538
     * @return void
9034
     * @return void
8539
     */
9035
     */
8540
    protected function apply_grade_to_user($formdata, $userid, $attemptnumber) {
9036
    protected function apply_grade_to_user($formdata, $userid, $attemptnumber)
-
 
9037
    {
8541
        global $USER, $CFG, $DB;
9038
        global $USER, $CFG, $DB;
Línea 8542... Línea 9039...
8542
 
9039
 
8543
        $grade = $this->get_user_grade($userid, true, $attemptnumber);
9040
        $grade = $this->get_user_grade($userid, true, $attemptnumber);
8544
        $originalgrade = $grade->grade;
9041
        $originalgrade = $grade->grade;
8545
        $gradingdisabled = $this->grading_disabled($userid);
9042
        $gradingdisabled = $this->grading_disabled($userid);
8546
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
9043
        $gradinginstance = $this->get_grading_instance($userid, $grade, $gradingdisabled);
8547
        if (!$gradingdisabled) {
9044
        if (!$gradingdisabled) {
8548
            if ($gradinginstance) {
9045
            if ($gradinginstance) {
8549
                $grade->grade = $gradinginstance->submit_and_get_grade($formdata->advancedgrading,
9046
                $grade->grade = $gradinginstance->submit_and_get_grade(
-
 
9047
                    $formdata->advancedgrading,
-
 
9048
                    $grade->id
8550
                                                                       $grade->id);
9049
                );
8551
            } else {
9050
            } else {
8552
                // Handle the case when grade is set to No Grade.
9051
                // Handle the case when grade is set to No Grade.
8553
                if (isset($formdata->grade)) {
9052
                if (isset($formdata->grade)) {
8554
                    $grade->grade = grade_floatval(unformat_float($formdata->grade));
9053
                    $grade->grade = grade_floatval(unformat_float($formdata->grade));
Línea 8557... Línea 9056...
8557
            if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
9056
            if (isset($formdata->workflowstate) || isset($formdata->allocatedmarker)) {
8558
                $flags = $this->get_user_flags($userid, true);
9057
                $flags = $this->get_user_flags($userid, true);
8559
                $oldworkflowstate = $flags->workflowstate;
9058
                $oldworkflowstate = $flags->workflowstate;
8560
                $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
9059
                $flags->workflowstate = isset($formdata->workflowstate) ? $formdata->workflowstate : $flags->workflowstate;
8561
                $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
9060
                $flags->allocatedmarker = isset($formdata->allocatedmarker) ? $formdata->allocatedmarker : $flags->allocatedmarker;
-
 
9061
                if (
8562
                if ($this->update_user_flags($flags) &&
9062
                    $this->update_user_flags($flags) &&
8563
                        isset($formdata->workflowstate) &&
9063
                    isset($formdata->workflowstate) &&
8564
                        $formdata->workflowstate !== $oldworkflowstate) {
9064
                    $formdata->workflowstate !== $oldworkflowstate
-
 
9065
                ) {
8565
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
9066
                    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
8566
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $formdata->workflowstate)->trigger();
9067
                    \mod_assign\event\workflow_state_updated::create_from_user($this, $user, $formdata->workflowstate)->trigger();
8567
                }
9068
                }
8568
            }
9069
            }
8569
        }
9070
        }
8570
        $grade->grader= $USER->id;
9071
        $grade->grader = $USER->id;
Línea 8571... Línea 9072...
8571
 
9072
 
8572
        $adminconfig = $this->get_admin_config();
9073
        $adminconfig = $this->get_admin_config();
Línea 8573... Línea 9074...
8573
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
9074
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
Línea 8594... Línea 9095...
8594
                }
9095
                }
8595
            }
9096
            }
8596
        }
9097
        }
Línea 8597... Línea 9098...
8597
 
9098
 
-
 
9099
        // We do not want to update the timemodified if no grade was added.
8598
        // We do not want to update the timemodified if no grade was added.
9100
        if (
8599
        if (!empty($formdata->addattempt) ||
9101
            !empty($formdata->addattempt) ||
8600
                ($originalgrade !== null && $originalgrade != -1) ||
9102
            ($originalgrade !== null && $originalgrade != -1) ||
8601
                ($grade->grade !== null && $grade->grade != -1) ||
9103
            ($grade->grade !== null && $grade->grade != -1) ||
-
 
9104
            $feedbackmodified
8602
                $feedbackmodified) {
9105
        ) {
8603
            $this->update_grade($grade, !empty($formdata->addattempt));
9106
            $this->update_grade($grade, !empty($formdata->addattempt));
Línea 8604... Línea 9107...
8604
        }
9107
        }
-
 
9108
 
8605
 
9109
        // We never send notifications if we have marking workflow and the grade is not released.
8606
        // We never send notifications if we have marking workflow and the grade is not released.
9110
        if (
8607
        if ($this->get_instance()->markingworkflow &&
9111
            $this->get_instance()->markingworkflow &&
-
 
9112
            isset($formdata->workflowstate) &&
8608
                isset($formdata->workflowstate) &&
9113
            $formdata->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
8609
                $formdata->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
9114
        ) {
Línea 8610... Línea 9115...
8610
            $formdata->sendstudentnotifications = false;
9115
            $formdata->sendstudentnotifications = false;
8611
        }
9116
        }
Línea 8624... Línea 9129...
8624
     * @param int $userid
9129
     * @param int $userid
8625
     * @param stdClass $formdata
9130
     * @param stdClass $formdata
8626
     * @param int $sourceuserid The user ID under which the outcome data is accessible. This is relevant
9131
     * @param int $sourceuserid The user ID under which the outcome data is accessible. This is relevant
8627
     *                          for an outcome set to a user but applied to an entire group.
9132
     *                          for an outcome set to a user but applied to an entire group.
8628
     */
9133
     */
8629
    protected function process_outcomes($userid, $formdata, $sourceuserid = null) {
9134
    protected function process_outcomes($userid, $formdata, $sourceuserid = null)
-
 
9135
    {
8630
        global $CFG, $USER;
9136
        global $CFG, $USER;
Línea 8631... Línea 9137...
8631
 
9137
 
8632
        if (empty($CFG->enableoutcomes)) {
9138
        if (empty($CFG->enableoutcomes)) {
8633
            return;
9139
            return;
8634
        }
9140
        }
8635
        if ($this->grading_disabled($userid)) {
9141
        if ($this->grading_disabled($userid)) {
8636
            return;
9142
            return;
Línea 8637... Línea 9143...
8637
        }
9143
        }
Línea 8638... Línea 9144...
8638
 
9144
 
8639
        require_once($CFG->libdir.'/gradelib.php');
9145
        require_once($CFG->libdir . '/gradelib.php');
8640
 
9146
 
-
 
9147
        $data = array();
8641
        $data = array();
9148
        $gradinginfo = grade_get_grades(
8642
        $gradinginfo = grade_get_grades($this->get_course()->id,
9149
            $this->get_course()->id,
8643
                                        'mod',
9150
            'mod',
-
 
9151
            'assign',
Línea 8644... Línea 9152...
8644
                                        'assign',
9152
            $this->get_instance()->id,
8645
                                        $this->get_instance()->id,
9153
            $userid
8646
                                        $userid);
9154
        );
8647
 
9155
 
-
 
9156
        if (!empty($gradinginfo->outcomes)) {
8648
        if (!empty($gradinginfo->outcomes)) {
9157
            foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
8649
            foreach ($gradinginfo->outcomes as $index => $oldoutcome) {
9158
                $name = 'outcome_' . $index;
-
 
9159
                $sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
8650
                $name = 'outcome_'.$index;
9160
                if (
8651
                $sourceuserid = $sourceuserid !== null ? $sourceuserid : $userid;
9161
                    isset($formdata->{$name}[$sourceuserid]) &&
8652
                if (isset($formdata->{$name}[$sourceuserid]) &&
9162
                    $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]
8653
                        $oldoutcome->grades[$userid]->grade != $formdata->{$name}[$sourceuserid]) {
9163
                ) {
8654
                    $data[$index] = $formdata->{$name}[$sourceuserid];
9164
                    $data[$index] = $formdata->{$name}[$sourceuserid];
8655
                }
9165
                }
-
 
9166
            }
8656
            }
9167
        }
8657
        }
9168
        if (count($data) > 0) {
8658
        if (count($data) > 0) {
9169
            grade_update_outcomes(
8659
            grade_update_outcomes('mod/assign',
9170
                'mod/assign',
8660
                                  $this->course->id,
9171
                $this->course->id,
8661
                                  'mod',
9172
                'mod',
-
 
9173
                'assign',
8662
                                  'assign',
9174
                $this->get_instance()->id,
8663
                                  $this->get_instance()->id,
9175
                $userid,
Línea 8664... Línea 9176...
8664
                                  $userid,
9176
                $data
8665
                                  $data);
9177
            );
Línea 8673... Línea 9185...
8673
     * @param int $userid The userid.
9185
     * @param int $userid The userid.
8674
     * @param stdClass $submission The submission (may be a group submission).
9186
     * @param stdClass $submission The submission (may be a group submission).
8675
     * @param bool $addattempt - True if the "allow another attempt" checkbox was checked.
9187
     * @param bool $addattempt - True if the "allow another attempt" checkbox was checked.
8676
     * @return bool - true if another attempt was added.
9188
     * @return bool - true if another attempt was added.
8677
     */
9189
     */
8678
    protected function reopen_submission_if_required($userid, $submission, $addattempt) {
9190
    protected function reopen_submission_if_required($userid, $submission, $addattempt)
-
 
9191
    {
8679
        $instance = $this->get_instance();
9192
        $instance = $this->get_instance();
8680
        $maxattemptsreached = !empty($submission) &&
9193
        $maxattemptsreached = !empty($submission) &&
8681
                              $submission->attemptnumber >= ($instance->maxattempts - 1) &&
9194
            $submission->attemptnumber >= ($instance->maxattempts - 1) &&
8682
                              $instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
9195
            $instance->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS;
8683
        $shouldreopen = false;
9196
        $shouldreopen = false;
8684
        if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
9197
        if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS) {
8685
            // Check the gradetopass from the gradebook.
9198
            // Check the gradetopass from the gradebook.
8686
            $gradeitem = $this->get_grade_item();
9199
            $gradeitem = $this->get_grade_item();
8687
            if ($gradeitem) {
9200
            if ($gradeitem) {
Línea 8691... Línea 9204...
8691
                if ($gradegrade && ($gradegrade->is_passed() === false)) {
9204
                if ($gradegrade && ($gradegrade->is_passed() === false)) {
8692
                    $shouldreopen = true;
9205
                    $shouldreopen = true;
8693
                }
9206
                }
8694
            }
9207
            }
8695
        }
9208
        }
-
 
9209
        if (
8696
        if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL &&
9210
            $instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL &&
8697
                !empty($addattempt)) {
9211
            !empty($addattempt)
-
 
9212
        ) {
8698
            $shouldreopen = true;
9213
            $shouldreopen = true;
8699
        }
9214
        }
8700
        if ($shouldreopen && !$maxattemptsreached) {
9215
        if ($shouldreopen && !$maxattemptsreached) {
8701
            $this->add_attempt($userid);
9216
            $this->add_attempt($userid);
8702
            return true;
9217
            return true;
Línea 8709... Línea 9224...
8709
     *
9224
     *
8710
     * @param int $userid
9225
     * @param int $userid
8711
     * @param  stdClass $data
9226
     * @param  stdClass $data
8712
     * @return bool - was the grade saved
9227
     * @return bool - was the grade saved
8713
     */
9228
     */
8714
    public function save_grade($userid, $data) {
9229
    public function save_grade($userid, $data)
-
 
9230
    {
Línea 8715... Línea 9231...
8715
 
9231
 
8716
        // Need grade permission.
9232
        // Need grade permission.
Línea 8717... Línea 9233...
8717
        require_capability('mod/assign:grade', $this->context);
9233
        require_capability('mod/assign:grade', $this->context);
Línea 8758... Línea 9274...
8758
     * Save grade.
9274
     * Save grade.
8759
     *
9275
     *
8760
     * @param  moodleform $mform
9276
     * @param  moodleform $mform
8761
     * @return bool - was the grade saved
9277
     * @return bool - was the grade saved
8762
     */
9278
     */
8763
    protected function process_save_grade(&$mform) {
9279
    protected function process_save_grade(&$mform)
-
 
9280
    {
8764
        global $CFG, $SESSION;
9281
        global $CFG, $SESSION;
8765
        // Include grade form.
9282
        // Include grade form.
8766
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
9283
        require_once($CFG->dirroot . '/mod/assign/gradeform.php');
Línea 8767... Línea 9284...
8767
 
9284
 
Línea 8791... Línea 9308...
8791
            $last = true;
9308
            $last = true;
8792
        }
9309
        }
Línea 8793... Línea 9310...
8793
 
9310
 
Línea 8794... Línea 9311...
8794
        $data = new stdClass();
9311
        $data = new stdClass();
-
 
9312
 
8795
 
9313
        $gradeformparams = array(
8796
        $gradeformparams = array('rownum' => $rownum,
9314
            'rownum' => $rownum,
8797
                                 'useridlistid' => $useridlistid,
9315
            'useridlistid' => $useridlistid,
8798
                                 'last' => $last,
9316
            'last' => $last,
-
 
9317
            'attemptnumber' => $attemptnumber,
8799
                                 'attemptnumber' => $attemptnumber,
9318
            'userid' => $userid
-
 
9319
        );
8800
                                 'userid' => $userid);
9320
        $mform = new mod_assign_grade_form(
8801
        $mform = new mod_assign_grade_form(null,
9321
            null,
8802
                                           array($this, $data, $gradeformparams),
9322
            array($this, $data, $gradeformparams),
8803
                                           'post',
9323
            'post',
-
 
9324
            '',
Línea 8804... Línea 9325...
8804
                                           '',
9325
            array('class' => 'gradeform')
8805
                                           array('class'=>'gradeform'));
9326
        );
8806
 
9327
 
8807
        if ($formdata = $mform->get_data()) {
9328
        if ($formdata = $mform->get_data()) {
Línea 8816... Línea 9337...
8816
     *
9337
     *
8817
     * @param string $type The plugin type
9338
     * @param string $type The plugin type
8818
     * @param int $version The plugin version
9339
     * @param int $version The plugin version
8819
     * @return bool
9340
     * @return bool
8820
     */
9341
     */
8821
    public static function can_upgrade_assignment($type, $version) {
9342
    public static function can_upgrade_assignment($type, $version)
-
 
9343
    {
8822
        $assignment = new assign(null, null, null);
9344
        $assignment = new assign(null, null, null);
8823
        return $assignment->can_upgrade($type, $version);
9345
        return $assignment->can_upgrade($type, $version);
8824
    }
9346
    }
Línea 8825... Línea 9347...
8825
 
9347
 
Línea 8828... Línea 9350...
8828
     *
9350
     *
8829
     * @param string $type The plugin type
9351
     * @param string $type The plugin type
8830
     * @param int $version The plugin version
9352
     * @param int $version The plugin version
8831
     * @return bool
9353
     * @return bool
8832
     */
9354
     */
8833
    public function can_upgrade($type, $version) {
9355
    public function can_upgrade($type, $version)
-
 
9356
    {
8834
        if ($type == 'offline' && $version >= 2011112900) {
9357
        if ($type == 'offline' && $version >= 2011112900) {
8835
            return true;
9358
            return true;
8836
        }
9359
        }
8837
        foreach ($this->submissionplugins as $plugin) {
9360
        foreach ($this->submissionplugins as $plugin) {
8838
            if ($plugin->can_upgrade($type, $version)) {
9361
            if ($plugin->can_upgrade($type, $version)) {
Línea 8859... Línea 9382...
8859
     * @param int $newcomponent The new assignment component ('assignment')
9382
     * @param int $newcomponent The new assignment component ('assignment')
8860
     * @param int $newfilearea The new assignment filearea ('submissions')
9383
     * @param int $newfilearea The new assignment filearea ('submissions')
8861
     * @param int $newitemid The new submissionid (can be null e.g. intro)
9384
     * @param int $newitemid The new submissionid (can be null e.g. intro)
8862
     * @return int The number of files copied
9385
     * @return int The number of files copied
8863
     */
9386
     */
8864
    public function copy_area_files_for_upgrade($oldcontextid,
9387
    public function copy_area_files_for_upgrade(
-
 
9388
        $oldcontextid,
8865
                                                $oldcomponent,
9389
        $oldcomponent,
8866
                                                $oldfilearea,
9390
        $oldfilearea,
8867
                                                $olditemid,
9391
        $olditemid,
8868
                                                $newcontextid,
9392
        $newcontextid,
8869
                                                $newcomponent,
9393
        $newcomponent,
8870
                                                $newfilearea,
9394
        $newfilearea,
8871
                                                $newitemid) {
9395
        $newitemid
-
 
9396
    ) {
8872
        // Note, this code is based on some code in filestorage - but that code
9397
        // Note, this code is based on some code in filestorage - but that code
8873
        // deleted the old files (which we don't want).
9398
        // deleted the old files (which we don't want).
8874
        $count = 0;
9399
        $count = 0;
Línea 8875... Línea 9400...
8875
 
9400
 
Línea 8876... Línea 9401...
8876
        $fs = get_file_storage();
9401
        $fs = get_file_storage();
-
 
9402
 
8877
 
9403
        $oldfiles = $fs->get_area_files(
8878
        $oldfiles = $fs->get_area_files($oldcontextid,
9404
            $oldcontextid,
8879
                                        $oldcomponent,
9405
            $oldcomponent,
8880
                                        $oldfilearea,
9406
            $oldfilearea,
8881
                                        $olditemid,
9407
            $olditemid,
-
 
9408
            'id',
8882
                                        'id',
9409
            false
8883
                                        false);
9410
        );
8884
        foreach ($oldfiles as $oldfile) {
9411
        foreach ($oldfiles as $oldfile) {
8885
            $filerecord = new stdClass();
9412
            $filerecord = new stdClass();
8886
            $filerecord->contextid = $newcontextid;
9413
            $filerecord->contextid = $newcontextid;
Línea 8899... Línea 9426...
8899
     * at most 1 time.
9426
     * at most 1 time.
8900
     *
9427
     *
8901
     * @param array $useridlist Array of userids to reopen.
9428
     * @param array $useridlist Array of userids to reopen.
8902
     * @return bool
9429
     * @return bool
8903
     */
9430
     */
8904
    protected function process_add_attempt_group($useridlist) {
9431
    protected function process_add_attempt_group($useridlist)
-
 
9432
    {
8905
        $groupsprocessed = array();
9433
        $groupsprocessed = array();
8906
        $result = true;
9434
        $result = true;
Línea 8907... Línea 9435...
8907
 
9435
 
8908
        foreach ($useridlist as $userid) {
9436
        foreach ($useridlist as $userid) {
Línea 8929... Línea 9457...
8929
     * Check for a sess key and then call add_attempt.
9457
     * Check for a sess key and then call add_attempt.
8930
     *
9458
     *
8931
     * @param int $userid int The user to add the attempt for
9459
     * @param int $userid int The user to add the attempt for
8932
     * @return bool - true if successful.
9460
     * @return bool - true if successful.
8933
     */
9461
     */
8934
    protected function process_add_attempt($userid) {
9462
    protected function process_add_attempt($userid)
-
 
9463
    {
8935
        require_sesskey();
9464
        require_sesskey();
Línea 8936... Línea 9465...
8936
 
9465
 
8937
        return $this->add_attempt($userid);
9466
        return $this->add_attempt($userid);
Línea 8941... Línea 9470...
8941
     * Add a new attempt for a user.
9470
     * Add a new attempt for a user.
8942
     *
9471
     *
8943
     * @param int $userid int The user to add the attempt for
9472
     * @param int $userid int The user to add the attempt for
8944
     * @return bool - true if successful.
9473
     * @return bool - true if successful.
8945
     */
9474
     */
8946
    protected function add_attempt($userid) {
9475
    protected function add_attempt($userid)
-
 
9476
    {
8947
        require_capability('mod/assign:grade', $this->context);
9477
        require_capability('mod/assign:grade', $this->context);
Línea 8948... Línea 9478...
8948
 
9478
 
8949
        if ($this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
9479
        if ($this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
8950
            return false;
9480
            return false;
Línea 8959... Línea 9489...
8959
        if (!$oldsubmission) {
9489
        if (!$oldsubmission) {
8960
            return false;
9490
            return false;
8961
        }
9491
        }
Línea 8962... Línea 9492...
8962
 
9492
 
-
 
9493
        // No more than max attempts allowed.
8963
        // No more than max attempts allowed.
9494
        if (
8964
        if ($this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
9495
            $this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
-
 
9496
            $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)
8965
            $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)) {
9497
        ) {
8966
            return false;
9498
            return false;
Línea 8967... Línea 9499...
8967
        }
9499
        }
8968
 
9500
 
Línea 9014... Línea 9546...
9014
     *                                                   feedbackformat,
9546
     *                                                   feedbackformat,
9015
     *                                                   usermodified,
9547
     *                                                   usermodified,
9016
     *                                                   dategraded,
9548
     *                                                   dategraded,
9017
     *                                                   datesubmitted
9549
     *                                                   datesubmitted
9018
     */
9550
     */
9019
    public function get_user_grades_for_gradebook($userid) {
9551
    public function get_user_grades_for_gradebook($userid)
-
 
9552
    {
9020
        global $DB, $CFG;
9553
        global $DB, $CFG;
9021
        $grades = array();
9554
        $grades = array();
9022
        $assignmentid = $this->get_instance()->id;
9555
        $assignmentid = $this->get_instance()->id;
Línea 9023... Línea 9556...
9023
 
9556
 
Línea 9038... Línea 9571...
9038
        } else {
9571
        } else {
9039
            $where = ' WHERE u.id != :userid ';
9572
            $where = ' WHERE u.id != :userid ';
9040
        }
9573
        }
Línea 9041... Línea 9574...
9041
 
9574
 
-
 
9575
        // When the gradebook asks us for grades - only return the last attempt for each user.
9042
        // When the gradebook asks us for grades - only return the last attempt for each user.
9576
        $params = array(
9043
        $params = array('assignid1'=>$assignmentid,
9577
            'assignid1' => $assignmentid,
9044
                        'assignid2'=>$assignmentid,
9578
            'assignid2' => $assignmentid,
-
 
9579
            'userid' => $userid
9045
                        'userid'=>$userid);
9580
        );
9046
        $graderesults = $DB->get_recordset_sql('SELECT
9581
        $graderesults = $DB->get_recordset_sql('SELECT
9047
                                                    u.id as userid,
9582
                                                    u.id as userid,
9048
                                                    s.timemodified as datesubmitted,
9583
                                                    s.timemodified as datesubmitted,
9049
                                                    g.grade as rawgrade,
9584
                                                    g.grade as rawgrade,
Línea 9054... Línea 9589...
9054
                                                    ON u.id = s.userid and s.assignment = :assignid1 AND
9589
                                                    ON u.id = s.userid and s.assignment = :assignid1 AND
9055
                                                    s.latest = 1
9590
                                                    s.latest = 1
9056
                                                JOIN {assign_grades} g
9591
                                                JOIN {assign_grades} g
9057
                                                    ON u.id = g.userid and g.assignment = :assignid2 AND
9592
                                                    ON u.id = g.userid and g.assignment = :assignid2 AND
9058
                                                    g.attemptnumber = s.attemptnumber' .
9593
                                                    g.attemptnumber = s.attemptnumber' .
9059
                                                $where, $params);
9594
            $where, $params);
Línea 9060... Línea 9595...
9060
 
9595
 
9061
        foreach ($graderesults as $result) {
9596
        foreach ($graderesults as $result) {
9062
            $gradingstatus = $this->get_grading_status($result->userid);
9597
            $gradingstatus = $this->get_grading_status($result->userid);
9063
            if (!$this->get_instance()->markingworkflow || $gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
9598
            if (!$this->get_instance()->markingworkflow || $gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
Línea 9086... Línea 9621...
9086
     * Call the static version of this function
9621
     * Call the static version of this function
9087
     *
9622
     *
9088
     * @param int $userid The userid to lookup
9623
     * @param int $userid The userid to lookup
9089
     * @return int The unique id
9624
     * @return int The unique id
9090
     */
9625
     */
9091
    public function get_uniqueid_for_user($userid) {
9626
    public function get_uniqueid_for_user($userid)
-
 
9627
    {
9092
        return self::get_uniqueid_for_user_static($this->get_instance()->id, $userid);
9628
        return self::get_uniqueid_for_user_static($this->get_instance()->id, $userid);
9093
    }
9629
    }
Línea 9094... Línea 9630...
9094
 
9630
 
9095
    /**
9631
    /**
9096
     * Foreach participant in the course - assign them a random id.
9632
     * Foreach participant in the course - assign them a random id.
9097
     *
9633
     *
9098
     * @param int $assignid The assignid to lookup
9634
     * @param int $assignid The assignid to lookup
9099
     */
9635
     */
-
 
9636
    public static function allocate_unique_ids($assignid)
9100
    public static function allocate_unique_ids($assignid) {
9637
    {
Línea 9101... Línea 9638...
9101
        global $DB;
9638
        global $DB;
9102
 
9639
 
Línea 9108... Línea 9645...
9108
 
9645
 
9109
        // Shuffle the users.
9646
        // Shuffle the users.
Línea 9110... Línea 9647...
9110
        shuffle($users);
9647
        shuffle($users);
9111
 
9648
 
-
 
9649
        foreach ($users as $user) {
9112
        foreach ($users as $user) {
9650
            $record = $DB->get_record(
9113
            $record = $DB->get_record('assign_user_mapping',
9651
                'assign_user_mapping',
-
 
9652
                array('assignment' => $assignid, 'userid' => $user->id),
9114
                                      array('assignment'=>$assignid, 'userid'=>$user->id),
9653
                'id'
9115
                                     'id');
9654
            );
9116
            if (!$record) {
9655
            if (!$record) {
9117
                $record = new stdClass();
9656
                $record = new stdClass();
9118
                $record->assignment = $assignid;
9657
                $record->assignment = $assignid;
Línea 9127... Línea 9666...
9127
     *
9666
     *
9128
     * @param int $assignid The assignment id
9667
     * @param int $assignid The assignment id
9129
     * @param int $userid The userid to lookup
9668
     * @param int $userid The userid to lookup
9130
     * @return int The unique id
9669
     * @return int The unique id
9131
     */
9670
     */
9132
    public static function get_uniqueid_for_user_static($assignid, $userid) {
9671
    public static function get_uniqueid_for_user_static($assignid, $userid)
-
 
9672
    {
9133
        global $DB;
9673
        global $DB;
Línea 9134... Línea 9674...
9134
 
9674
 
9135
        // Search for a record.
9675
        // Search for a record.
9136
        $params = array('assignment'=>$assignid, 'userid'=>$userid);
9676
        $params = array('assignment' => $assignid, 'userid' => $userid);
9137
        if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) {
9677
        if ($record = $DB->get_record('assign_user_mapping', $params, 'id')) {
9138
            return $record->id;
9678
            return $record->id;
Línea 9139... Línea 9679...
9139
        }
9679
        }
Línea 9160... Línea 9700...
9160
     * Call the static version of this function.
9700
     * Call the static version of this function.
9161
     *
9701
     *
9162
     * @param int $uniqueid The uniqueid to lookup
9702
     * @param int $uniqueid The uniqueid to lookup
9163
     * @return int The user id or false if they don't exist
9703
     * @return int The user id or false if they don't exist
9164
     */
9704
     */
9165
    public function get_user_id_for_uniqueid($uniqueid) {
9705
    public function get_user_id_for_uniqueid($uniqueid)
-
 
9706
    {
9166
        return self::get_user_id_for_uniqueid_static($this->get_instance()->id, $uniqueid);
9707
        return self::get_user_id_for_uniqueid_static($this->get_instance()->id, $uniqueid);
9167
    }
9708
    }
Línea 9168... Línea 9709...
9168
 
9709
 
9169
    /**
9710
    /**
9170
     * Lookup this unique id and return the user id for this assignment.
9711
     * Lookup this unique id and return the user id for this assignment.
9171
     *
9712
     *
9172
     * @param int $assignid The id of the assignment this user mapping is in
9713
     * @param int $assignid The id of the assignment this user mapping is in
9173
     * @param int $uniqueid The uniqueid to lookup
9714
     * @param int $uniqueid The uniqueid to lookup
9174
     * @return int The user id or false if they don't exist
9715
     * @return int The user id or false if they don't exist
9175
     */
9716
     */
-
 
9717
    public static function get_user_id_for_uniqueid_static($assignid, $uniqueid)
9176
    public static function get_user_id_for_uniqueid_static($assignid, $uniqueid) {
9718
    {
Línea 9177... Línea 9719...
9177
        global $DB;
9719
        global $DB;
9178
 
9720
 
-
 
9721
        // Search for a record.
9179
        // Search for a record.
9722
        if ($record = $DB->get_record(
9180
        if ($record = $DB->get_record('assign_user_mapping',
9723
            'assign_user_mapping',
9181
                                      array('assignment'=>$assignid, 'id'=>$uniqueid),
9724
            array('assignment' => $assignid, 'id' => $uniqueid),
-
 
9725
            'userid',
9182
                                      'userid',
9726
            IGNORE_MISSING
9183
                                      IGNORE_MISSING)) {
9727
        )) {
Línea 9184... Línea 9728...
9184
            return $record->userid;
9728
            return $record->userid;
9185
        }
9729
        }
Línea 9190... Línea 9734...
9190
    /**
9734
    /**
9191
     * Get the list of marking_workflow states the current user has permission to transition a grade to.
9735
     * Get the list of marking_workflow states the current user has permission to transition a grade to.
9192
     *
9736
     *
9193
     * @return array of state => description
9737
     * @return array of state => description
9194
     */
9738
     */
9195
    public function get_marking_workflow_states_for_current_user() {
9739
    public function get_marking_workflow_states_for_current_user()
-
 
9740
    {
9196
        if (!empty($this->markingworkflowstates)) {
9741
        if (!empty($this->markingworkflowstates)) {
9197
            return $this->markingworkflowstates;
9742
            return $this->markingworkflowstates;
9198
        }
9743
        }
9199
        $states = array();
9744
        $states = array();
9200
        if (has_capability('mod/assign:grade', $this->context)) {
9745
        if (has_capability('mod/assign:grade', $this->context)) {
9201
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INMARKING] = get_string('markingworkflowstateinmarking', 'assign');
9746
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INMARKING] = get_string('markingworkflowstateinmarking', 'assign');
9202
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW] = get_string('markingworkflowstatereadyforreview', 'assign');
9747
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORREVIEW] = get_string('markingworkflowstatereadyforreview', 'assign');
9203
        }
9748
        }
9204
        if (has_any_capability(array('mod/assign:reviewgrades',
9749
        if (has_any_capability(array(
-
 
9750
            'mod/assign:reviewgrades',
9205
                                     'mod/assign:managegrades'), $this->context)) {
9751
            'mod/assign:managegrades'
-
 
9752
        ), $this->context)) {
9206
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW] = get_string('markingworkflowstateinreview', 'assign');
9753
            $states[ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW] = get_string('markingworkflowstateinreview', 'assign');
9207
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE] = get_string('markingworkflowstatereadyforrelease', 'assign');
9754
            $states[ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE] = get_string('markingworkflowstatereadyforrelease', 'assign');
9208
        }
9755
        }
9209
        if (has_any_capability(array('mod/assign:releasegrades',
9756
        if (has_any_capability(array(
-
 
9757
            'mod/assign:releasegrades',
9210
                                     'mod/assign:managegrades'), $this->context)) {
9758
            'mod/assign:managegrades'
-
 
9759
        ), $this->context)) {
9211
            $states[ASSIGN_MARKING_WORKFLOW_STATE_RELEASED] = get_string('markingworkflowstatereleased', 'assign');
9760
            $states[ASSIGN_MARKING_WORKFLOW_STATE_RELEASED] = get_string('markingworkflowstatereleased', 'assign');
9212
        }
9761
        }
9213
        $this->markingworkflowstates = $states;
9762
        $this->markingworkflowstates = $states;
9214
        return $this->markingworkflowstates;
9763
        return $this->markingworkflowstates;
9215
    }
9764
    }
Línea 9217... Línea 9766...
9217
    /**
9766
    /**
9218
     * Get the list of marking_workflow states.
9767
     * Get the list of marking_workflow states.
9219
     *
9768
     *
9220
     * @return array Array of multiple state => description.
9769
     * @return array Array of multiple state => description.
9221
     */
9770
     */
9222
    public function get_all_marking_workflow_states(): array {
9771
    public function get_all_marking_workflow_states(): array
-
 
9772
    {
9223
        if (!empty($this->allmarkingworkflowstates)) {
9773
        if (!empty($this->allmarkingworkflowstates)) {
9224
            return $this->allmarkingworkflowstates;
9774
            return $this->allmarkingworkflowstates;
9225
        }
9775
        }
Línea 9226... Línea 9776...
9226
 
9776
 
Línea 9239... Línea 9789...
9239
    /**
9789
    /**
9240
     * Check is only active users in course should be shown.
9790
     * Check is only active users in course should be shown.
9241
     *
9791
     *
9242
     * @return bool true if only active users should be shown.
9792
     * @return bool true if only active users should be shown.
9243
     */
9793
     */
9244
    public function show_only_active_users() {
9794
    public function show_only_active_users()
-
 
9795
    {
9245
        global $CFG;
9796
        global $CFG;
Línea 9246... Línea 9797...
9246
 
9797
 
9247
        if (is_null($this->showonlyactiveenrol)) {
9798
        if (is_null($this->showonlyactiveenrol)) {
9248
            $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
9799
            $defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
Línea 9249... Línea 9800...
9249
            $this->showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
9800
            $this->showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
9250
 
9801
 
9251
            if (!is_null($this->context)) {
9802
            if (!is_null($this->context)) {
9252
                $this->showonlyactiveenrol = $this->showonlyactiveenrol ||
9803
                $this->showonlyactiveenrol = $this->showonlyactiveenrol ||
9253
                            !has_capability('moodle/course:viewsuspendedusers', $this->context);
9804
                    !has_capability('moodle/course:viewsuspendedusers', $this->context);
9254
            }
9805
            }
9255
        }
9806
        }
Línea 9260... Línea 9811...
9260
     * Return true is user is active user in course else false
9811
     * Return true is user is active user in course else false
9261
     *
9812
     *
9262
     * @param int $userid
9813
     * @param int $userid
9263
     * @return bool true is user is active in course.
9814
     * @return bool true is user is active in course.
9264
     */
9815
     */
9265
    public function is_active_user($userid) {
9816
    public function is_active_user($userid)
-
 
9817
    {
9266
        return !in_array($userid, get_suspended_userids($this->context, true));
9818
        return !in_array($userid, get_suspended_userids($this->context, true));
9267
    }
9819
    }
Línea 9268... Línea 9820...
9268
 
9820
 
9269
    /**
9821
    /**
9270
     * Returns true if gradebook feedback plugin is enabled
9822
     * Returns true if gradebook feedback plugin is enabled
9271
     *
9823
     *
9272
     * @return bool true if gradebook feedback plugin is enabled and visible else false.
9824
     * @return bool true if gradebook feedback plugin is enabled and visible else false.
9273
     */
9825
     */
-
 
9826
    public function is_gradebook_feedback_enabled()
9274
    public function is_gradebook_feedback_enabled() {
9827
    {
9275
        // Get default grade book feedback plugin.
9828
        // Get default grade book feedback plugin.
9276
        $adminconfig = $this->get_admin_config();
9829
        $adminconfig = $this->get_admin_config();
9277
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
9830
        $gradebookplugin = $adminconfig->feedback_plugin_for_gradebook;
Línea 9296... Línea 9849...
9296
     * Returns the grading status.
9849
     * Returns the grading status.
9297
     *
9850
     *
9298
     * @param int $userid the user id
9851
     * @param int $userid the user id
9299
     * @return string returns the grading status
9852
     * @return string returns the grading status
9300
     */
9853
     */
9301
    public function get_grading_status($userid) {
9854
    public function get_grading_status($userid)
-
 
9855
    {
9302
        if ($this->get_instance()->markingworkflow) {
9856
        if ($this->get_instance()->markingworkflow) {
9303
            $flags = $this->get_user_flags($userid, false);
9857
            $flags = $this->get_user_flags($userid, false);
9304
            if (!empty($flags->workflowstate)) {
9858
            if (!empty($flags->workflowstate)) {
9305
                return $flags->workflowstate;
9859
                return $flags->workflowstate;
9306
            }
9860
            }
Línea 9320... Línea 9874...
9320
    /**
9874
    /**
9321
     * The id used to uniquily identify the cache for this instance of the assign object.
9875
     * The id used to uniquily identify the cache for this instance of the assign object.
9322
     *
9876
     *
9323
     * @return string
9877
     * @return string
9324
     */
9878
     */
9325
    public function get_useridlist_key_id() {
9879
    public function get_useridlist_key_id()
-
 
9880
    {
9326
        return $this->useridlistid;
9881
        return $this->useridlistid;
9327
    }
9882
    }
Línea 9328... Línea 9883...
9328
 
9883
 
9329
    /**
9884
    /**
9330
     * Generates the key that should be used for an entry in the useridlist cache.
9885
     * Generates the key that should be used for an entry in the useridlist cache.
9331
     *
9886
     *
9332
     * @param string $id Generate a key for this instance (optional)
9887
     * @param string $id Generate a key for this instance (optional)
9333
     * @return string The key for the id, or new entry if no $id is passed.
9888
     * @return string The key for the id, or new entry if no $id is passed.
9334
     */
9889
     */
-
 
9890
    public function get_useridlist_key($id = null)
9335
    public function get_useridlist_key($id = null) {
9891
    {
Línea 9336... Línea 9892...
9336
        global $SESSION;
9892
        global $SESSION;
9337
 
9893
 
9338
        // Ensure the user id list cache is initialised.
9894
        // Ensure the user id list cache is initialised.
Línea 9356... Línea 9912...
9356
     * @param int $complete
9912
     * @param int $complete
9357
     * @param obj $completion
9913
     * @param obj $completion
9358
     *
9914
     *
9359
     * @return null
9915
     * @return null
9360
     */
9916
     */
9361
    protected function update_activity_completion_records($teamsubmission,
9917
    protected function update_activity_completion_records(
-
 
9918
        $teamsubmission,
9362
                                                          $requireallteammemberssubmit,
9919
        $requireallteammemberssubmit,
9363
                                                          $submission,
9920
        $submission,
9364
                                                          $userid,
9921
        $userid,
9365
                                                          $complete,
9922
        $complete,
9366
                                                          $completion) {
9923
        $completion
-
 
9924
    ) {
Línea 9367... Línea 9925...
9367
 
9925
 
9368
        if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
9926
        if (($teamsubmission && $submission->groupid > 0 && !$requireallteammemberssubmit) ||
9369
            ($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
9927
            ($teamsubmission && $submission->groupid > 0 && $requireallteammemberssubmit &&
-
 
9928
                $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)
Línea 9370... Línea 9929...
9370
             $submission->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED)) {
9929
        ) {
Línea 9371... Línea 9930...
9371
 
9930
 
9372
            $members = groups_get_members($submission->groupid);
9931
            $members = groups_get_members($submission->groupid);
Línea 9384... Línea 9943...
9384
    /**
9943
    /**
9385
     * Update the module completion status (set it viewed) and trigger module viewed event.
9944
     * Update the module completion status (set it viewed) and trigger module viewed event.
9386
     *
9945
     *
9387
     * @since Moodle 3.2
9946
     * @since Moodle 3.2
9388
     */
9947
     */
9389
    public function set_module_viewed() {
9948
    public function set_module_viewed()
-
 
9949
    {
9390
        $completion = new completion_info($this->get_course());
9950
        $completion = new completion_info($this->get_course());
9391
        $completion->set_module_viewed($this->get_course_module());
9951
        $completion->set_module_viewed($this->get_course_module());
Línea 9392... Línea 9952...
9392
 
9952
 
9393
        // Trigger the course module viewed event.
9953
        // Trigger the course module viewed event.
Línea 9409... Línea 9969...
9409
    /**
9969
    /**
9410
     * Checks for any grade notices, and adds notifications. Will display on assignment main page and grading table.
9970
     * Checks for any grade notices, and adds notifications. Will display on assignment main page and grading table.
9411
     *
9971
     *
9412
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9972
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9413
     */
9973
     */
9414
    protected function add_grade_notices() {
9974
    protected function add_grade_notices()
-
 
9975
    {
9415
        if (has_capability('mod/assign:grade', $this->get_context()) && get_config('assign', 'has_rescaled_null_grades_' . $this->get_instance()->id)) {
9976
        if (has_capability('mod/assign:grade', $this->get_context()) && get_config('assign', 'has_rescaled_null_grades_' . $this->get_instance()->id)) {
9416
            $link = new \moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id, 'action' => 'fixrescalednullgrades'));
9977
            $link = new \moodle_url('/mod/assign/view.php', array('id' => $this->get_course_module()->id, 'action' => 'fixrescalednullgrades'));
9417
            \core\notification::warning(get_string('fixrescalednullgrades', 'mod_assign', ['link' => $link->out()]));
9978
            \core\notification::warning(get_string('fixrescalednullgrades', 'mod_assign', ['link' => $link->out()]));
9418
        }
9979
        }
9419
    }
9980
    }
Línea 9421... Línea 9982...
9421
    /**
9982
    /**
9422
     * View fix rescaled null grades.
9983
     * View fix rescaled null grades.
9423
     *
9984
     *
9424
     * @return bool True if null all grades are now fixed.
9985
     * @return bool True if null all grades are now fixed.
9425
     */
9986
     */
9426
    protected function fix_null_grades() {
9987
    protected function fix_null_grades()
-
 
9988
    {
9427
        global $DB;
9989
        global $DB;
9428
        $result = $DB->set_field_select(
9990
        $result = $DB->set_field_select(
9429
            'assign_grades',
9991
            'assign_grades',
9430
            'grade',
9992
            'grade',
9431
            ASSIGN_GRADE_NOT_SET,
9993
            ASSIGN_GRADE_NOT_SET,
Línea 9441... Línea 10003...
9441
    /**
10003
    /**
9442
     * View fix rescaled null grades.
10004
     * View fix rescaled null grades.
9443
     *
10005
     *
9444
     * @return void The notifications API will render the notifications at the appropriate part of the page.
10006
     * @return void The notifications API will render the notifications at the appropriate part of the page.
9445
     */
10007
     */
9446
    protected function view_fix_rescaled_null_grades() {
10008
    protected function view_fix_rescaled_null_grades()
-
 
10009
    {
9447
        global $OUTPUT;
10010
        global $OUTPUT;
Línea 9448... Línea 10011...
9448
 
10011
 
Línea 9449... Línea 10012...
9449
        $o = '';
10012
        $o = '';
Línea 9500... Línea 10063...
9500
     * attempt on a group assignment, and whether the gradebook should be updated.
10063
     * attempt on a group assignment, and whether the gradebook should be updated.
9501
     *
10064
     *
9502
     * @since Moodle 3.4
10065
     * @since Moodle 3.4
9503
     * @param stdClass $submission The most recent submission of the group.
10066
     * @param stdClass $submission The most recent submission of the group.
9504
     */
10067
     */
9505
    public function set_most_recent_team_submission($submission) {
10068
    public function set_most_recent_team_submission($submission)
-
 
10069
    {
9506
        $this->mostrecentteamsubmission = $submission;
10070
        $this->mostrecentteamsubmission = $submission;
9507
    }
10071
    }
Línea 9508... Línea 10072...
9508
 
10072
 
9509
    /**
10073
    /**
9510
     * Return array of valid grading allocation filters for the grading interface.
10074
     * Return array of valid grading allocation filters for the grading interface.
9511
     *
10075
     *
9512
     * @param boolean $export Export the list of filters for a template.
10076
     * @param boolean $export Export the list of filters for a template.
9513
     * @return array
10077
     * @return array
9514
     */
10078
     */
-
 
10079
    public function get_marking_allocation_filters($export = false)
9515
    public function get_marking_allocation_filters($export = false) {
10080
    {
9516
        $markingallocation = $this->get_instance()->markingworkflow &&
10081
        $markingallocation = $this->get_instance()->markingworkflow &&
9517
            $this->get_instance()->markingallocation &&
10082
            $this->get_instance()->markingallocation &&
9518
            has_capability('mod/assign:manageallocations', $this->context);
10083
            has_capability('mod/assign:manageallocations', $this->context);
9519
        // Get markers to use in drop lists.
10084
        // Get markers to use in drop lists.
Línea 9548... Línea 10113...
9548
     * Return array of valid grading workflow filters for the grading interface.
10113
     * Return array of valid grading workflow filters for the grading interface.
9549
     *
10114
     *
9550
     * @param boolean $export Export the list of filters for a template.
10115
     * @param boolean $export Export the list of filters for a template.
9551
     * @return array
10116
     * @return array
9552
     */
10117
     */
9553
    public function get_marking_workflow_filters($export = false) {
10118
    public function get_marking_workflow_filters($export = false)
-
 
10119
    {
9554
        $markingworkflow = $this->get_instance()->markingworkflow;
10120
        $markingworkflow = $this->get_instance()->markingworkflow;
9555
        // Get marking states to show in form.
10121
        // Get marking states to show in form.
9556
        $markingworkflowoptions = array();
10122
        $markingworkflowoptions = array();
9557
        if ($markingworkflow) {
10123
        if ($markingworkflow) {
9558
            $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
10124
            $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
Línea 9578... Línea 10144...
9578
    /**
10144
    /**
9579
     * Return array of valid search filters for the grading interface.
10145
     * Return array of valid search filters for the grading interface.
9580
     *
10146
     *
9581
     * @return array
10147
     * @return array
9582
     */
10148
     */
9583
    public function get_filters() {
10149
    public function get_filters()
-
 
10150
    {
9584
        $filterkeys = [
10151
        $filterkeys = [
9585
            ASSIGN_FILTER_NOT_SUBMITTED,
10152
            ASSIGN_FILTER_NOT_SUBMITTED,
9586
            ASSIGN_FILTER_DRAFT,
10153
            ASSIGN_FILTER_DRAFT,
9587
            ASSIGN_FILTER_SUBMITTED,
10154
            ASSIGN_FILTER_SUBMITTED,
9588
            ASSIGN_FILTER_REQUIRE_GRADING,
10155
            ASSIGN_FILTER_REQUIRE_GRADING,
Línea 9617... Línea 10184...
9617
     * @param stdClass $instance
10184
     * @param stdClass $instance
9618
     * @param context $context
10185
     * @param context $context
9619
     *
10186
     *
9620
     * @return string
10187
     * @return string
9621
     */
10188
     */
9622
    protected function get_submissionstatement($adminconfig, $instance, $context) {
10189
    protected function get_submissionstatement($adminconfig, $instance, $context)
-
 
10190
    {
9623
        $submissionstatement = '';
10191
        $submissionstatement = '';
Línea 9624... Línea 10192...
9624
 
10192
 
9625
        if (!($context instanceof context)) {
10193
        if (!($context instanceof context)) {
9626
            return $submissionstatement;
10194
            return $submissionstatement;
Línea 9645... Línea 10213...
9645
                // a form element.
10213
                // a form element.
9646
                $options = array(
10214
                $options = array(
9647
                    'context' => $context,
10215
                    'context' => $context,
9648
                    'para'    => false
10216
                    'para'    => false
9649
                );
10217
                );
-
 
10218
                $submissionstatement = format_text(
9650
                $submissionstatement = format_text($adminconfig->submissionstatementteamsubmission,
10219
                    $adminconfig->submissionstatementteamsubmission,
9651
                    FORMAT_MOODLE, $options);
10220
                    FORMAT_MOODLE,
-
 
10221
                    $options
-
 
10222
                );
-
 
10223
            } else if (
9652
            } else if (!empty($adminconfig->submissionstatementteamsubmissionallsubmit) &&
10224
                !empty($adminconfig->submissionstatementteamsubmissionallsubmit) &&
9653
                $instance->requireallteammemberssubmit) {
10225
                $instance->requireallteammemberssubmit
-
 
10226
            ) {
9654
                // All team members must submit.
10227
                // All team members must submit.
9655
                // Format the submission statement before its sent. We turn off para because this is going within
10228
                // Format the submission statement before its sent. We turn off para because this is going within
9656
                // a form element.
10229
                // a form element.
9657
                $options = array(
10230
                $options = array(
9658
                    'context' => $context,
10231
                    'context' => $context,
9659
                    'para'    => false
10232
                    'para'    => false
9660
                );
10233
                );
-
 
10234
                $submissionstatement = format_text(
9661
                $submissionstatement = format_text($adminconfig->submissionstatementteamsubmissionallsubmit,
10235
                    $adminconfig->submissionstatementteamsubmissionallsubmit,
9662
                    FORMAT_MOODLE, $options);
10236
                    FORMAT_MOODLE,
-
 
10237
                    $options
-
 
10238
                );
9663
            }
10239
            }
9664
        }
10240
        }
Línea 9665... Línea 10241...
9665
 
10241
 
9666
        return $submissionstatement;
10242
        return $submissionstatement;
Línea 9670... Línea 10246...
9670
     * Check if time limit for assignment enabled and set up.
10246
     * Check if time limit for assignment enabled and set up.
9671
     *
10247
     *
9672
     * @param int|null $userid User ID. If null, use global user.
10248
     * @param int|null $userid User ID. If null, use global user.
9673
     * @return bool
10249
     * @return bool
9674
     */
10250
     */
9675
    public function is_time_limit_enabled(?int $userid = null): bool {
10251
    public function is_time_limit_enabled(?int $userid = null): bool
-
 
10252
    {
9676
        $instance = $this->get_instance($userid);
10253
        $instance = $this->get_instance($userid);
9677
        return get_config('assign', 'enabletimelimit') && !empty($instance->timelimit);
10254
        return get_config('assign', 'enabletimelimit') && !empty($instance->timelimit);
9678
    }
10255
    }
Línea 9679... Línea 10256...
9679
 
10256
 
Línea 9683... Línea 10260...
9683
     * @param int|null $userid User ID. If null, use global user.
10260
     * @param int|null $userid User ID. If null, use global user.
9684
     * @param int $groupid Group ID. If 0, use user id to determine group.
10261
     * @param int $groupid Group ID. If 0, use user id to determine group.
9685
     * @param int $attemptnumber Attempt number. If -1, check latest submission.
10262
     * @param int $attemptnumber Attempt number. If -1, check latest submission.
9686
     * @return bool
10263
     * @return bool
9687
     */
10264
     */
9688
    public function is_attempt_in_progress(?int $userid = null, int $groupid = 0, int $attemptnumber = -1): bool {
10265
    public function is_attempt_in_progress(?int $userid = null, int $groupid = 0, int $attemptnumber = -1): bool
-
 
10266
    {
9689
        if ($this->get_instance($userid)->teamsubmission) {
10267
        if ($this->get_instance($userid)->teamsubmission) {
9690
            $submission = $this->get_group_submission($userid, $groupid, false, $attemptnumber);
10268
            $submission = $this->get_group_submission($userid, $groupid, false, $attemptnumber);
9691
        } else {
10269
        } else {
9692
            $submission = $this->get_user_submission($userid, false, $attemptnumber);
10270
            $submission = $this->get_user_submission($userid, false, $attemptnumber);
9693
        }
10271
        }
Línea 9707... Línea 10285...
9707
 *
10285
 *
9708
 * @package   mod_assign
10286
 * @package   mod_assign
9709
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
10287
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
9710
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
10288
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
9711
 */
10289
 */
9712
class assign_portfolio_caller extends portfolio_module_caller_base {
10290
class assign_portfolio_caller extends portfolio_module_caller_base
-
 
10291
{
Línea 9713... Línea 10292...
9713
 
10292
 
9714
    /** @var int callback arg - the id of submission we export */
10293
    /** @var int callback arg - the id of submission we export */
Línea 9715... Línea 10294...
9715
    protected $sid;
10294
    protected $sid;
Línea 9733... Línea 10312...
9733
    protected $editor;
10312
    protected $editor;
Línea 9734... Línea 10313...
9734
 
10313
 
9735
    /**
10314
    /**
9736
     * Callback arg for a single file export.
10315
     * Callback arg for a single file export.
9737
     */
10316
     */
-
 
10317
    public static function expected_callbackargs()
9738
    public static function expected_callbackargs() {
10318
    {
9739
        return array(
10319
        return array(
9740
            'cmid' => true,
10320
            'cmid' => true,
9741
            'sid' => false,
10321
            'sid' => false,
9742
            'area' => false,
10322
            'area' => false,
Línea 9750... Línea 10330...
9750
    /**
10330
    /**
9751
     * The constructor.
10331
     * The constructor.
9752
     *
10332
     *
9753
     * @param array $callbackargs
10333
     * @param array $callbackargs
9754
     */
10334
     */
9755
    public function __construct($callbackargs) {
10335
    public function __construct($callbackargs)
-
 
10336
    {
9756
        parent::__construct($callbackargs);
10337
        parent::__construct($callbackargs);
9757
        $this->cm = get_coursemodule_from_id('assign', $this->cmid, 0, false, MUST_EXIST);
10338
        $this->cm = get_coursemodule_from_id('assign', $this->cmid, 0, false, MUST_EXIST);
9758
    }
10339
    }
Línea 9759... Línea 10340...
9759
 
10340
 
Línea 9765... Línea 10346...
9765
     * submissionid and filearea (to export all data attached to the given submission file area)
10346
     * submissionid and filearea (to export all data attached to the given submission file area)
9766
     * via callback arguments.
10347
     * via callback arguments.
9767
     *
10348
     *
9768
     * @throws     portfolio_caller_exception
10349
     * @throws     portfolio_caller_exception
9769
     */
10350
     */
9770
    public function load_data() {
10351
    public function load_data()
-
 
10352
    {
9771
        global $DB;
10353
        global $DB;
Línea 9772... Línea 10354...
9772
 
10354
 
Línea 9773... Línea 10355...
9773
        $context = context_module::instance($this->cmid);
10355
        $context = context_module::instance($this->cmid);
Línea 9797... Línea 10379...
9797
        }
10379
        }
Línea 9798... Línea 10380...
9798
 
10380
 
9799
        // Export either an area of files or a single file (see function for more detail).
10381
        // Export either an area of files or a single file (see function for more detail).
9800
        // The first arg is an id or null. If it is an id, the rest of the args are ignored.
10382
        // The first arg is an id or null. If it is an id, the rest of the args are ignored.
9801
        // If it is null, the rest of the args are used to load a list of files from get_areafiles.
10383
        // If it is null, the rest of the args are used to load a list of files from get_areafiles.
-
 
10384
        $this->set_file_and_format_data(
9802
        $this->set_file_and_format_data($this->fileid,
10385
            $this->fileid,
9803
                                        $context->id,
10386
            $context->id,
9804
                                        $this->component,
10387
            $this->component,
9805
                                        $this->area,
10388
            $this->area,
9806
                                        $this->sid,
10389
            $this->sid,
9807
                                        'timemodified',
10390
            'timemodified',
9808
                                        false);
10391
            false
9809
 
10392
        );
Línea 9810... Línea 10393...
9810
    }
10393
    }
9811
 
10394
 
9812
    /**
10395
    /**
9813
     * Prepares the package up before control is passed to the portfolio plugin.
10396
     * Prepares the package up before control is passed to the portfolio plugin.
9814
     *
10397
     *
9815
     * @throws portfolio_caller_exception
10398
     * @throws portfolio_caller_exception
9816
     * @return mixed
10399
     * @return mixed
-
 
10400
     */
Línea 9817... Línea 10401...
9817
     */
10401
    public function prepare_package()
9818
    public function prepare_package() {
10402
    {
9819
 
10403
 
9820
        if ($this->plugin && $this->editor) {
10404
        if ($this->plugin && $this->editor) {
Línea 9826... Línea 10410...
9826
 
10410
 
9827
            $text = $plugin->get_editor_text($this->editor, $this->sid);
10411
            $text = $plugin->get_editor_text($this->editor, $this->sid);
Línea 9828... Línea 10412...
9828
            $format = $plugin->get_editor_format($this->editor, $this->sid);
10412
            $format = $plugin->get_editor_format($this->editor, $this->sid);
9829
 
10413
 
-
 
10414
            $html = format_text($text, $format, $options);
9830
            $html = format_text($text, $format, $options);
10415
            $html = portfolio_rewrite_pluginfile_urls(
9831
            $html = portfolio_rewrite_pluginfile_urls($html,
10416
                $html,
9832
                                                      $context->id,
10417
                $context->id,
9833
                                                      'mod_assign',
10418
                'mod_assign',
9834
                                                      $this->area,
10419
                $this->area,
-
 
10420
                $this->sid,
Línea 9835... Línea 10421...
9835
                                                      $this->sid,
10421
                $this->exporter->get('format')
9836
                                                      $this->exporter->get('format'));
10422
            );
9837
 
10423
 
9838
            $exporterclass = $this->exporter->get('formatclass');
10424
            $exporterclass = $this->exporter->get('formatclass');
Línea 9843... Línea 10429...
9843
                    }
10429
                    }
9844
                }
10430
                }
9845
                return $this->exporter->write_new_file($html, 'assignment.html', !empty($files));
10431
                return $this->exporter->write_new_file($html, 'assignment.html', !empty($files));
9846
            } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
10432
            } else if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
9847
                $leapwriter = $this->exporter->get('format')->leap2a_writer();
10433
                $leapwriter = $this->exporter->get('format')->leap2a_writer();
9848
                $entry = new portfolio_format_leap2a_entry($this->area . $this->cmid,
10434
                $entry = new portfolio_format_leap2a_entry(
-
 
10435
                    $this->area . $this->cmid,
9849
                                                           $context->get_context_name(),
10436
                    $context->get_context_name(),
9850
                                                           'resource',
10437
                    'resource',
9851
                                                           $html);
10438
                    $html
-
 
10439
                );
Línea 9852... Línea 10440...
9852
 
10440
 
9853
                $entry->add_category('web', 'resource_type');
10441
                $entry->add_category('web', 'resource_type');
9854
                $entry->author = $this->user;
10442
                $entry->author = $this->user;
9855
                $leapwriter->add_entry($entry);
10443
                $leapwriter->add_entry($entry);
9856
                if ($files = $this->exporter->get('caller')->get('multifiles')) {
10444
                if ($files = $this->exporter->get('caller')->get('multifiles')) {
9857
                    $leapwriter->link_files($entry, $files, $this->area . $this->cmid . 'file');
10445
                    $leapwriter->link_files($entry, $files, $this->area . $this->cmid . 'file');
9858
                    foreach ($files as $file) {
10446
                    foreach ($files as $file) {
9859
                        $this->exporter->copy_existing_file($file);
10447
                        $this->exporter->copy_existing_file($file);
9860
                    }
10448
                    }
9861
                }
10449
                }
-
 
10450
                return $this->exporter->write_new_file(
9862
                return $this->exporter->write_new_file($leapwriter->to_xml(),
10451
                    $leapwriter->to_xml(),
9863
                                                       $this->exporter->get('format')->manifest_name(),
10452
                    $this->exporter->get('format')->manifest_name(),
-
 
10453
                    true
9864
                                                       true);
10454
                );
9865
            } else {
10455
            } else {
9866
                debugging('invalid format class: ' . $this->exporter->get('formatclass'));
10456
                debugging('invalid format class: ' . $this->exporter->get('formatclass'));
9867
            }
-
 
9868
 
10457
            }
Línea 9869... Línea 10458...
9869
        }
10458
        }
9870
 
10459
 
9871
        if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
10460
        if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
9872
            $leapwriter = $this->exporter->get('format')->leap2a_writer();
10461
            $leapwriter = $this->exporter->get('format')->leap2a_writer();
9873
            $files = array();
10462
            $files = array();
9874
            if ($this->singlefile) {
10463
            if ($this->singlefile) {
9875
                $files[] = $this->singlefile;
10464
                $files[] = $this->singlefile;
9876
            } else if ($this->multifiles) {
10465
            } else if ($this->multifiles) {
9877
                $files = $this->multifiles;
10466
                $files = $this->multifiles;
-
 
10467
            } else {
9878
            } else {
10468
                throw new portfolio_caller_exception(
9879
                throw new portfolio_caller_exception('invalidpreparepackagefile',
10469
                    'invalidpreparepackagefile',
-
 
10470
                    'portfolio',
9880
                                                     'portfolio',
10471
                    $this->get_return_url()
Línea 9881... Línea 10472...
9881
                                                     $this->get_return_url());
10472
                );
9882
            }
10473
            }
9883
 
10474
 
Línea 9892... Línea 10483...
9892
            if (count($files) > 1) {
10483
            if (count($files) > 1) {
9893
                $baseid = 'assign' . $this->cmid . $this->area;
10484
                $baseid = 'assign' . $this->cmid . $this->area;
9894
                $context = context_module::instance($this->cmid);
10485
                $context = context_module::instance($this->cmid);
Línea 9895... Línea 10486...
9895
 
10486
 
9896
                // If we have multiple files, they should be grouped together into a folder.
10487
                // If we have multiple files, they should be grouped together into a folder.
-
 
10488
                $entry = new portfolio_format_leap2a_entry(
9897
                $entry = new portfolio_format_leap2a_entry($baseid . 'group',
10489
                    $baseid . 'group',
9898
                                                           $context->get_context_name(),
10490
                    $context->get_context_name(),
-
 
10491
                    'selection'
9899
                                                           'selection');
10492
                );
9900
                $leapwriter->add_entry($entry);
10493
                $leapwriter->add_entry($entry);
9901
                $leapwriter->make_selection($entry, $entryids, 'Folder');
10494
                $leapwriter->make_selection($entry, $entryids, 'Folder');
9902
            }
10495
            }
-
 
10496
            return $this->exporter->write_new_file(
9903
            return $this->exporter->write_new_file($leapwriter->to_xml(),
10497
                $leapwriter->to_xml(),
9904
                                                   $this->exporter->get('format')->manifest_name(),
10498
                $this->exporter->get('format')->manifest_name(),
-
 
10499
                true
9905
                                                   true);
10500
            );
9906
        }
10501
        }
9907
        return $this->prepare_package_file();
10502
        return $this->prepare_package_file();
Línea 9908... Línea 10503...
9908
    }
10503
    }
9909
 
10504
 
9910
    /**
10505
    /**
9911
     * Fetch the plugin by its type.
10506
     * Fetch the plugin by its type.
9912
     *
10507
     *
9913
     * @return assign_submission_plugin
10508
     * @return assign_submission_plugin
-
 
10509
     */
9914
     */
10510
    protected function get_submission_plugin()
9915
    protected function get_submission_plugin() {
10511
    {
9916
        global $CFG;
10512
        global $CFG;
9917
        if (!$this->plugin || !$this->cmid) {
10513
        if (!$this->plugin || !$this->cmid) {
Línea 9930... Línea 10526...
9930
     * Calculate a sha1 has of either a single file or a list
10526
     * Calculate a sha1 has of either a single file or a list
9931
     * of files based on the data set by load_data.
10527
     * of files based on the data set by load_data.
9932
     *
10528
     *
9933
     * @return string
10529
     * @return string
9934
     */
10530
     */
9935
    public function get_sha1() {
10531
    public function get_sha1()
-
 
10532
    {
Línea 9936... Línea 10533...
9936
 
10533
 
9937
        if ($this->plugin && $this->editor) {
10534
        if ($this->plugin && $this->editor) {
9938
            $plugin = $this->get_submission_plugin();
10535
            $plugin = $this->get_submission_plugin();
9939
            $options = portfolio_format_text_options();
10536
            $options = portfolio_format_text_options();
Línea -... Línea 10537...
-
 
10537
            $options->context = context_module::instance($this->cmid);
9940
            $options->context = context_module::instance($this->cmid);
10538
 
9941
 
10539
            $text = format_text(
9942
            $text = format_text($plugin->get_editor_text($this->editor, $this->sid),
10540
                $plugin->get_editor_text($this->editor, $this->sid),
-
 
10541
                $plugin->get_editor_format($this->editor, $this->sid),
9943
                                $plugin->get_editor_format($this->editor, $this->sid),
10542
                $options
9944
                                $options);
10543
            );
9945
            $textsha1 = sha1($text);
10544
            $textsha1 = sha1($text);
9946
            $filesha1 = '';
10545
            $filesha1 = '';
9947
            try {
10546
            try {
Línea 9958... Línea 10557...
9958
     * Calculate the time to transfer either a single file or a list
10557
     * Calculate the time to transfer either a single file or a list
9959
     * of files based on the data set by load_data.
10558
     * of files based on the data set by load_data.
9960
     *
10559
     *
9961
     * @return int
10560
     * @return int
9962
     */
10561
     */
9963
    public function expected_time() {
10562
    public function expected_time()
-
 
10563
    {
9964
        return $this->expected_time_file();
10564
        return $this->expected_time_file();
9965
    }
10565
    }
Línea 9966... Línea 10566...
9966
 
10566
 
9967
    /**
10567
    /**
9968
     * Checking the permissions.
10568
     * Checking the permissions.
9969
     *
10569
     *
9970
     * @return bool
10570
     * @return bool
9971
     */
10571
     */
-
 
10572
    public function check_permissions()
9972
    public function check_permissions() {
10573
    {
9973
        $context = context_module::instance($this->cmid);
10574
        $context = context_module::instance($this->cmid);
9974
        return has_capability('mod/assign:exportownsubmission', $context);
10575
        return has_capability('mod/assign:exportownsubmission', $context);
Línea 9975... Línea 10576...
9975
    }
10576
    }
9976
 
10577
 
9977
    /**
10578
    /**
9978
     * Display a module name.
10579
     * Display a module name.
9979
     *
10580
     *
9980
     * @return string
10581
     * @return string
-
 
10582
     */
9981
     */
10583
    public static function display_name()
9982
    public static function display_name() {
10584
    {
Línea 9983... Línea 10585...
9983
        return get_string('modulename', 'assign');
10585
        return get_string('modulename', 'assign');
9984
    }
10586
    }
9985
 
10587
 
9986
    /**
10588
    /**
9987
     * Return array of formats supported by this portfolio call back.
10589
     * Return array of formats supported by this portfolio call back.
9988
     *
10590
     *
-
 
10591
     * @return array
9989
     * @return array
10592
     */
9990
     */
10593
    public static function base_supported_formats()
9991
    public static function base_supported_formats() {
10594
    {
Línea 9992... Línea 10595...
9992
        return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
10595
        return array(PORTFOLIO_FORMAT_FILE, PORTFOLIO_FORMAT_LEAP2A);
Línea 9998... Línea 10601...
9998
 *
10601
 *
9999
 * @param int $courseid The course ID.
10602
 * @param int $courseid The course ID.
10000
 * @param int $groupid The group id if it is known
10603
 * @param int $groupid The group id if it is known
10001
 * @return void
10604
 * @return void
10002
 */
10605
 */
10003
function assign_process_group_deleted_in_course($courseid, $groupid = null) {
10606
function assign_process_group_deleted_in_course($courseid, $groupid = null)
-
 
10607
{
10004
    global $DB;
10608
    global $DB;
Línea 10005... Línea 10609...
10005
 
10609
 
10006
    $params = array('courseid' => $courseid);
10610
    $params = array('courseid' => $courseid);
10007
    if ($groupid) {
10611
    if ($groupid) {
Línea 10039... Línea 10643...
10039
 * @param int $id of the override
10643
 * @param int $id of the override
10040
 * @param string $move direction of move
10644
 * @param string $move direction of move
10041
 * @param int $assignid of the assignment
10645
 * @param int $assignid of the assignment
10042
 * @return bool success of operation
10646
 * @return bool success of operation
10043
 */
10647
 */
10044
function move_group_override($id, $move, $assignid) {
10648
function move_group_override($id, $move, $assignid)
-
 
10649
{
10045
    global $DB;
10650
    global $DB;
Línea 10046... Línea 10651...
10046
 
10651
 
10047
    // Get the override object.
10652
    // Get the override object.
10048
    if (!$override = $DB->get_record('assign_overrides', ['id' => $id, 'assignid' => $assignid], 'id, sortorder, groupid')) {
10653
    if (!$override = $DB->get_record('assign_overrides', ['id' => $id, 'assignid' => $assignid], 'id, sortorder, groupid')) {
10049
        return false;
10654
        return false;
10050
    }
10655
    }
10051
    // Count the number of group overrides.
10656
    // Count the number of group overrides.
Línea 10052... Línea 10657...
10052
    $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assignid));
10657
    $overridecountgroup = $DB->count_records('assign_overrides', array('userid' => null, 'assignid' => $assignid));
10053
 
10658
 
10054
    // Calculate the new sortorder.
10659
    // Calculate the new sortorder.
10055
    if ( ($move == 'up') and ($override->sortorder > 1)) {
10660
    if (($move == 'up') and ($override->sortorder > 1)) {
10056
        $neworder = $override->sortorder - 1;
10661
        $neworder = $override->sortorder - 1;
10057
    } else if (($move == 'down') and ($override->sortorder < $overridecountgroup)) {
10662
    } else if (($move == 'down') and ($override->sortorder < $overridecountgroup)) {
10058
        $neworder = $override->sortorder + 1;
10663
        $neworder = $override->sortorder + 1;
Línea 10085... Línea 10690...
10085
/**
10690
/**
10086
 * Reorder the overrides starting at the override at the given startorder.
10691
 * Reorder the overrides starting at the override at the given startorder.
10087
 *
10692
 *
10088
 * @param int $assignid of the assigment
10693
 * @param int $assignid of the assigment
10089
 */
10694
 */
10090
function reorder_group_overrides($assignid) {
10695
function reorder_group_overrides($assignid)
-
 
10696
{
10091
    global $DB;
10697
    global $DB;
Línea 10092... Línea 10698...
10092
 
10698
 
10093
    $i = 1;
10699
    $i = 1;
10094
    if ($overrides = $DB->get_records('assign_overrides', array('userid' => null, 'assignid' => $assignid), 'sortorder ASC')) {
10700
    if ($overrides = $DB->get_records('assign_overrides', array('userid' => null, 'assignid' => $assignid), 'sortorder ASC')) {
Línea 10113... Línea 10719...
10113
 
10719
 
10114
/**
10720
/**
10115
 * Get the information about the standard assign JavaScript module.
10721
 * Get the information about the standard assign JavaScript module.
10116
 * @return array a standard jsmodule structure.
10722
 * @return array a standard jsmodule structure.
10117
 */
10723
 */
-
 
10724
function assign_get_js_module()
10118
function assign_get_js_module() {
10725
{
10119
    return array(
10726
    return array(
10120
        'name' => 'mod_assign',
10727
        'name' => 'mod_assign',
10121
        'fullpath' => '/mod/assign/module.js',
10728
        'fullpath' => '/mod/assign/module.js',
10122
    );
10729
    );