LLMS_Notification_View_Quiz_Graded

LLMS_Notification_View_Quiz_Graded class


Source Source

File: includes/notifications/views/class.llms.notification.view.quiz.graded.php

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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
class LLMS_Notification_View_Quiz_Graded extends LLMS_Abstract_Notification_View {
 
    /**
     * Notification Trigger ID
     *
     * @var string
     */
    public $trigger_id = 'quiz_graded';
 
    /**
     * Settings for basic notifications
     *
     * @var array
     */
    protected $basic_options = array(
        /**
         * Time in milliseconds to show a notification before automatically dismissing it
         */
        'auto_dismiss' => 10000,
        /**
         * Enables manual dismissal of notifications
         */
        'dismissible'  => true,
    );
 
    /**
     * Setup body content for output
     *
     * @since 3.24.0
     *
     * @return string
     */
    protected function set_body() {
        if ( 'email' === $this->notification->get( 'type' ) ) {
            return $this->set_body_email();
        }
        // Translators: %s = Quiz attempt grade.
        $content = sprintf( __( 'You received a %1$s', 'lifterlms' ), '{{GRADE}}' );
        return $content;
    }
 
    /**
     * Setup body for email notification
     *
     * @since 3.24.0
     * @since 5.2.0 Build the table with mailer helper.
     *
     * @return string
     */
    protected function set_body_email() {
 
        $mailer = llms()->mailer();
 
        $btn_style = $mailer->get_button_style();
 
        $rows = array(
            'QUIZ_TITLE'   => __( 'Quiz', 'lifterlms' ),
            'LESSON_TITLE' => __( 'Lesson', 'lifterlms' ),
            'COURSE_TITLE' => __( 'Course', 'lifterlms' ),
            'GRADE'        => __( 'Grade', 'lifterlms' ),
            'STATUS'       => __( 'Status', 'lifterlms' ),
        );
 
        ob_start();
        echo $mailer->get_table_html( $rows );
        ?>
        <p><a href="{{REVIEW_URL}}" style="<?php echo $btn_style; ?>"><?php _e( 'View the whole attempt', 'lifterlms' ); ?></a></p>
        <p><small><?php _e( 'Trouble clicking? Copy and paste this URL into your browser:', 'lifterlms' ); ?><br><a href="{{REVIEW_URL}}">{{REVIEW_URL}}</a></small></p>
        <?php
        return ob_get_clean();
 
    }
 
    /**
     * Setup notification icon for output
     *
     * @since 3.24.0
     *
     * @return string
     */
    protected function set_icon() {
        return $this->get_icon_default( 'warning' );
    }
 
    /**
     * Setup footer content for output
     *
     * @since 3.24.0
     * @since 3.29.0 Unknown.
     *
     * @return string
     */
    protected function set_footer() {
 
        $attempt = new LLMS_Quiz_Attempt( $this->notification->get( 'post_id' ) );
        if ( ! $attempt->exists() ) {
            return '';
        }
 
        $permalink = $attempt->get_permalink();
        if ( ! $permalink ) {
            return '';
        }
 
        return '<a href="' . esc_url( $permalink ) . '">' . __( 'View the attempt', 'lifterlms' ) . '</a>';
    }
 
    /**
     * Setup merge codes that can be used with the notification
     *
     * @since 3.24.0
     *
     * @return array
     */
    protected function set_merge_codes() {
        return array(
            '{{COURSE_TITLE}}' => __( 'Course Title', 'lifterlms' ),
            '{{GRADE}}'        => __( 'Grade', 'lifterlms' ),
            '{{LESSON_TITLE}}' => __( 'Lesson Title', 'lifterlms' ),
            '{{QUIZ_TITLE}}'   => __( 'Quiz Title', 'lifterlms' ),
            '{{REVIEW_URL}}'   => __( 'Review URL', 'lifterlms' ),
            '{{STATUS}}'       => __( 'Quiz Status', 'lifterlms' ),
            '{{STUDENT_NAME}}' => __( 'Student Name', 'lifterlms' ),
        );
    }
 
    /**
     * Replace merge codes with actual values
     *
     * @since 3.24.0
     *
     * @param string $code The merge code to get merged data for.
     * @return string
     */
    protected function set_merge_data( $code ) {
 
        $attempt = new LLMS_Quiz_Attempt( $this->notification->get( 'post_id' ) );
        if ( ! $attempt->exists() ) {
            return '';
        }
        $lesson = llms_get_post( $attempt->get( 'lesson_id' ) );
        if ( ! $lesson ) {
            return '';
        }
 
        switch ( $code ) {
 
            case '{{COURSE_TITLE}}':
                $course = $lesson->get_course();
                if ( $course ) {
                    $code = $course->get( 'title' );
                } else {
                    $code = '';
                }
                break;
 
            case '{{GRADE}}':
                $code = llms()->grades()->round( $attempt->get( 'grade' ) ) . '%';
                break;
 
            case '{{LESSON_TITLE}}':
                $code = $lesson->get( 'title' );
                break;
 
            case '{{QUIZ_TITLE}}':
                $code = get_the_title( $attempt->get( 'quiz_id' ) );
                break;
 
            case '{{REVIEW_URL}}':
                $code = $attempt->get_permalink();
                break;
 
            case '{{STATUS}}':
                $code = $attempt->l10n( 'status' );
                break;
 
            case '{{STUDENT_NAME}}':
                $code = $this->user->get_name();
                break;
 
        }// End switch().
 
        return $code;
 
    }
 
    /**
     * Setup notification subject for output
     *
     * @since 3.24.0
     *
     * @return string
     */
    protected function set_subject() {
        // Translators: %s = Quiz Title.
        return sprintf( __( 'Your quiz "%s" has been reviewed', 'lifterlms' ), '{{QUIZ_TITLE}}' );
    }
 
    /**
     * Setup notification title for output
     *
     * @since 3.24.0
     *
     * @return string
     */
    protected function set_title() {
        return __( 'Quiz Review Details', 'lifterlms' );
    }
 
}


Top ↑

Methods Methods


Top ↑

Changelog Changelog

Changelog
Version Description
3.29.0 Unknown.
3.24.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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