1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
4
|
|
|
|
5
|
|
|
if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Graded_Quiz' ) ) : |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Learner Graded Quiz |
9
|
|
|
* |
10
|
|
|
* An email sent to the learner when their quiz has been graded (auto or manual). |
11
|
|
|
* |
12
|
|
|
* @package Users |
13
|
|
|
* @author Automattic |
14
|
|
|
* |
15
|
|
|
* @since 1.6.0 |
16
|
|
|
*/ |
17
|
|
|
class WooThemes_Sensei_Email_Learner_Graded_Quiz { |
18
|
|
|
|
19
|
|
|
var $template; |
|
|
|
|
20
|
|
|
var $subject; |
|
|
|
|
21
|
|
|
var $heading; |
|
|
|
|
22
|
|
|
var $recipient; |
|
|
|
|
23
|
|
|
var $user; |
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Constructor |
27
|
|
|
* |
28
|
|
|
* @access public |
29
|
|
|
*/ |
30
|
|
|
function __construct() { |
|
|
|
|
31
|
|
|
$this->template = 'learner-graded-quiz'; |
32
|
|
|
$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your quiz has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
33
|
|
|
$this->heading = apply_filters( 'sensei_email_heading', __( 'Your quiz has been graded', 'woothemes-sensei' ), $this->template ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* trigger function. |
38
|
|
|
* |
39
|
|
|
* @param int $user_id |
40
|
|
|
* @param int $quiz_id |
41
|
|
|
* @param int $grade |
42
|
|
|
* @param int $passmark |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) { |
|
|
|
|
47
|
|
|
|
48
|
|
|
global $sensei_email_data; |
49
|
|
|
|
50
|
|
|
// Get learner user object |
51
|
|
|
$this->user = new WP_User( $user_id ); |
52
|
|
|
|
53
|
|
|
// Get passed flag |
54
|
|
|
$passed = __( 'failed', 'woothemes-sensei' ); |
55
|
|
|
if( $grade >= $passmark ) { |
56
|
|
|
$passed = __( 'passed', 'woothemes-sensei' ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Get grade tye (auto/manual) |
60
|
|
|
$grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true ); |
61
|
|
|
|
62
|
|
|
if( 'auto' == $grade_type ) { |
63
|
|
|
$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a quiz', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
64
|
|
|
$this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a quiz', 'woothemes-sensei' ), $this->template ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true ); |
68
|
|
|
|
69
|
|
|
// Construct data array |
70
|
|
|
$sensei_email_data = apply_filters( 'sensei_email_data', array( |
71
|
|
|
'template' => $this->template, |
72
|
|
|
'heading' => $this->heading, |
73
|
|
|
'user_id' => $user_id, |
74
|
|
|
'user_name' => stripslashes( $this->user->display_name ), |
75
|
|
|
'lesson_id' => $lesson_id, |
76
|
|
|
'quiz_id' => $quiz_id, |
77
|
|
|
'grade' => $grade, |
78
|
|
|
'passmark' => $passmark, |
79
|
|
|
'passed' => $passed, |
80
|
|
|
'grade_type' => $grade_type, |
81
|
|
|
), $this->template ); |
82
|
|
|
|
83
|
|
|
// Set recipient (learner) |
84
|
|
|
$this->recipient = stripslashes( $this->user->user_email ); |
85
|
|
|
|
86
|
|
|
// Send mail |
87
|
|
|
Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
endif; |
92
|
|
|
|
93
|
|
|
return new WooThemes_Sensei_Email_Learner_Graded_Quiz(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.