QuizQuery.php 2.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace local_asystgrade\db;

class QuizQuery implements QuizQueryInterface
{
    private $db;

    public function __construct() {
        global $DB;
        $this->db = $DB;
    }

    /**
     * @param $qid
     * @param $slot
     * @return mixed
     */
    public function get_question_attempts($qid, $slot) {
        return $this->db->get_recordset(
            'question_attempts',
            [
                'questionid' => $qid,
                'slot' => $slot
            ],
            '',
            '*'
        );
    }

    /**
     * @param $qid
     * @return mixed
     */
    public function get_reference_answer($qid) {
        return $this->db->get_record(
            'qtype_essay_options',
            [
                'questionid' => $qid
            ],
            '*',
            MUST_EXIST
        )->graderinfo;
    }

    /**
     * @param $question_attempt_id
     * @return mixed
     */
    public function get_attempt_steps($question_attempt_id) {
        return $this->db->get_recordset(
            'question_attempt_steps',
            [
                'questionattemptid' => $question_attempt_id
            ],
            '',
            '*'
        );
    }

    /**
     * @param $attemptstepid
     * @return mixed
     */
    public function get_student_answer($attemptstepid) {
        return $this->db->get_record(
            'question_attempt_step_data',
            [
                'attemptstepid' => $attemptstepid,
                'name' => 'answer'
            ],
            '*',
            MUST_EXIST
        )->value;
    }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

    /**
     * Checks if scores exist for a given quizid and userid.
     * *
     * * @param int $quizid quiz ID.
     * * @param int $userid user ID.
     * * @return bool Returns true if scores exist for a given quizid and userid, otherwise false.
 */
    public function gradesExist(int $quizid, int $userid): bool {
        global $DB;

        // Check for the presence of an entry in the mdl_quiz_grades table for this quizid and userid
        return $DB->record_exists(
            'quiz_grades',
            [
                'quiz' => $quizid,
                'userid' => $userid
            ]
        );
    }
95
}