1: <?php
2:
3: if ( ! defined( 'ABSPATH' ) ) exit;
4:
5: if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Graded_Quiz' ) ) :
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 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: 27: 28: 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: 38: 39: 40: 41: 42: 43: 44: 45:
46: function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) {
47:
48: global $sensei_email_data;
49:
50: $lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
51:
52: if ( ! Sensei_Utils::user_started_lesson( $lesson_id, $user_id ) ) {
53: return;
54: }
55:
56:
57: $this->user = new WP_User( $user_id );
58:
59:
60: $passed = __( 'failed', 'woothemes-sensei' );
61: if( $grade >= $passmark ) {
62: $passed = __( 'passed', 'woothemes-sensei' );
63: }
64:
65:
66: $grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
67:
68: if( 'auto' == $grade_type ) {
69: $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a quiz', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
70: $this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a quiz', 'woothemes-sensei' ), $this->template );
71: }
72:
73:
74: $sensei_email_data = apply_filters( 'sensei_email_data', array(
75: 'template' => $this->template,
76: 'heading' => $this->heading,
77: 'user_id' => $user_id,
78: 'user_name' => stripslashes( $this->user->display_name ),
79: 'lesson_id' => $lesson_id,
80: 'quiz_id' => $quiz_id,
81: 'grade' => $grade,
82: 'passmark' => $passmark,
83: 'passed' => $passed,
84: 'grade_type' => $grade_type,
85: ), $this->template );
86:
87:
88: $this->recipient = stripslashes( $this->user->user_email );
89:
90:
91: Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
92: }
93: }
94:
95: endif;
96:
97: return new WooThemes_Sensei_Email_Learner_Graded_Quiz();