Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace mod_quiz\task;
17
namespace mod_quiz\task;
Línea 18... Línea 18...
18
 
18
 
19
defined('MOODLE_INTERNAL') || die();
19
defined('MOODLE_INTERNAL') || die();
20
 
20
 
21
use context_course;
21
use context_module;
22
use core_user;
22
use core_user;
23
use mod_quiz\quiz_attempt;
23
use mod_quiz\quiz_attempt;
Línea 39... Línea 39...
39
    /**
39
    /**
40
     * @var int|null For using in unit testing only. Override the time we consider as now.
40
     * @var int|null For using in unit testing only. Override the time we consider as now.
41
     */
41
     */
42
    protected $forcedtime = null;
42
    protected $forcedtime = null;
Línea 43... Línea -...
43
 
-
 
44
    /**
-
 
45
     * Get name of schedule task.
-
 
46
     *
43
 
47
     * @return string
-
 
48
     */
44
    #[\Override]
49
    public function get_name(): string {
45
    public function get_name(): string {
50
        return get_string('notifyattemptsgradedtask', 'mod_quiz');
46
        return get_string('notifyattemptsgradedtask', 'mod_quiz');
Línea 51... Línea 47...
51
    }
47
    }
Línea 73... Línea 69...
73
            throw new \coding_exception('set_time_for_testing should only be used in unit tests.');
69
            throw new \coding_exception('set_time_for_testing should only be used in unit tests.');
74
        }
70
        }
75
        $this->forcedtime = $time;
71
        $this->forcedtime = $time;
76
    }
72
    }
Línea 77... Línea -...
77
 
-
 
78
    /**
-
 
79
     * Execute sending notification for manual graded attempts.
73
 
80
     */
74
    #[\Override]
81
    public function execute() {
75
    public function execute(): void {
Línea 82... Línea 76...
82
        global $DB;
76
        global $DB;
Línea 83... Línea 77...
83
 
77
 
Línea 92... Línea 86...
92
            mtrace('Checking attempt ' . $attempt->id . ' at quiz ' . $attempt->quiz . '.');
86
            mtrace('Checking attempt ' . $attempt->id . ' at quiz ' . $attempt->quiz . '.');
Línea 93... Línea 87...
93
 
87
 
94
            if (!$quiz || $attempt->quiz != $quiz->id) {
88
            if (!$quiz || $attempt->quiz != $quiz->id) {
95
                $quiz = $DB->get_record('quiz', ['id' => $attempt->quiz], '*', MUST_EXIST);
89
                $quiz = $DB->get_record('quiz', ['id' => $attempt->quiz], '*', MUST_EXIST);
-
 
90
                $cm = get_coursemodule_from_instance('quiz', $attempt->quiz);
96
                $cm = get_coursemodule_from_instance('quiz', $attempt->quiz);
91
                $quizcontext = context_module::instance($cm->id);
Línea 97... Línea 92...
97
            }
92
            }
98
 
93
 
99
            if (!$course || $course->id != $quiz->course) {
-
 
100
                $course = get_course($quiz->course);
94
            if (!$course || $course->id != $quiz->course) {
Línea 101... Línea 95...
101
                $coursecontext = context_course::instance($quiz->course);
95
                $course = get_course($quiz->course);
102
            }
96
            }
103
 
97
 
Línea 104... Línea 98...
104
            $quiz = quiz_update_effective_access($quiz, $attempt->userid);
98
            $quiz = quiz_update_effective_access($quiz, $attempt->userid);
105
            $attemptobj = new quiz_attempt($attempt, $quiz, $cm, $course, false);
99
            $attemptobj = new quiz_attempt($attempt, $quiz, $cm, $course, false);
106
            $options = display_options::make_from_quiz($quiz, quiz_attempt_state($quiz, $attempt));
100
            $options = display_options::make_from_quiz($quiz, quiz_attempt_state($quiz, $attempt));
-
 
101
 
107
 
102
            if ($options->manualcomment == question_display_options::HIDDEN) {
108
            if ($options->manualcomment == question_display_options::HIDDEN) {
103
                // User cannot currently see the feedback, so don't message them.
Línea 109... Línea 104...
109
                // User cannot currently see the feedback, so don't message them.
104
                // However, this may change in future, so leave them on the list.
110
                // However, this may change in future, so leave them on the list.
105
                mtrace('Not sending an email because manualcomment review option is not set.');
-
 
106
                continue;
111
                continue;
107
            }
112
            }
108
 
113
 
109
            if (!has_capability('mod/quiz:emailnotifyattemptgraded', $quizcontext, $attempt->userid, false)) {
Línea 114... Línea 110...
114
            if (!has_capability('mod/quiz:emailnotifyattemptgraded', $coursecontext, $attempt->userid, false)) {
110
                // User not eligible to get a notification. Mark them done while doing nothing.