LLMS_Quiz_Data

Query data about a quiz


Source Source

File: includes/class.llms.quiz.data.php

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
class LLMS_Quiz_Data extends LLMS_Abstract_Post_Data {
 
    /**
     * Constructor
     *
     * @since    3.16.0
     *
     * @param    int $quiz_id  WP Post ID of the quiz
     */
    public function __construct( $quiz_id ) {
 
        $this->quiz_id = $quiz_id;
        $this->quiz    = llms_get_post( $this->quiz_id );
        parent::__construct( $quiz_id );
 
    }
 
    /**
     * Retrieve # of quiz attempts within the period
     *
     * @since    3.16.0
     *
     * @param    string $period  date period [current|previous]
     * @return   int
     */
    public function get_attempt_count( $period = 'current' ) {
 
        global $wpdb;
 
        return $wpdb->get_var(
            $wpdb->prepare(
                "
            SELECT COUNT( id )
            FROM {$wpdb->prefix}lifterlms_quiz_attempts
            WHERE quiz_id = %d
              AND update_date BETWEEN %s AND %s
            ",
                $this->post_id,
                $this->get_date( $period, 'start' ),
                $this->get_date( $period, 'end' )
            )
        );
 
    }
 
    /**
     * Retrieve avg grade of quiz attempts within the period
     *
     * @since    3.16.0
     *
     * @param    string $period  date period [current|previous]
     * @return   int
     */
    public function get_average_grade( $period = 'current' ) {
 
        global $wpdb;
 
        $grade = $wpdb->get_var(
            $wpdb->prepare(
                "
            SELECT ROUND( AVG( grade ), 3 )
            FROM {$wpdb->prefix}lifterlms_quiz_attempts
            WHERE quiz_id = %d
              AND update_date BETWEEN %s AND %s
            ",
                $this->post_id,
                $this->get_date( $period, 'start' ),
                $this->get_date( $period, 'end' )
            )
        );
 
        return $grade ? $grade : 0;
 
    }
 
    /**
     * Retrieve the number assignments with a given status
     *
     * @since    3.24.0
     *
     * @param    string $status  status name
     * @param    string $period  date period [current|previous]
     * @return   int
     */
    public function get_count_by_status( $status, $period = 'current' ) {
 
        global $wpdb;
 
        return $wpdb->get_var(
            $wpdb->prepare(
                "
            SELECT COUNT( id )
            FROM {$wpdb->prefix}lifterlms_quiz_attempts
            WHERE quiz_id = %d
              AND status = %s
              AND update_date BETWEEN %s AND %s
            ",
                $this->post_id,
                $status,
                $this->get_date( $period, 'start' ),
                $this->get_date( $period, 'end' )
            )
        );
 
    }
 
    /**
     * Retrieve # of quiz fails within the period
     *
     * @since    3.16.0
     *
     * @param    string $period  date period [current|previous]
     * @return   int
     */
    public function get_fail_count( $period = 'current' ) {
        return $this->get_count_by_status( 'fail', $period );
    }
 
    /**
     * Retrieve # of quiz passes within the period
     *
     * @since    3.16.0
     *
     * @param    string $period  date period [current|previous]
     * @return   int
     */
    public function get_pass_count( $period = 'current' ) {
        return $this->get_count_by_status( 'pass', $period );
    }
 
    /**
     * Retrieve recent LLMS_User_Postmeta for the quiz.
     * This overrides the LLMS_Abstract_Post_Data method.
     *
     * @since    3.16.0
     *
     * @return   array
     */
    public function recent_events( $args = array() ) {
 
        $query_args = wp_parse_args(
            $args,
            array(
                'types' => array(),
            )
        );
 
        return parent::recent_events( $query_args );
    }
}


Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
4.0.0 Removed deprecated properties $quiz and $quiz_id.
3.31.0 Extends LLMS_Abstract_Post_Data.
3.30.3 Explicitly define class properties.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.