1: <?php
2:
3: if ( ! defined( 'ABSPATH' ) ) exit;
4:
5: if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Lesson' ) ) :
6:
7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class WooThemes_Sensei_Email_Teacher_Completed_Lesson {
18:
19: var $template;
20: var $subject;
21: var $heading;
22: var $recipient;
23: var $learner;
24: var $teacher;
25:
26: 27: 28:
29: function __construct() {
30: $this->template = 'teacher-completed-lesson';
31: $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a lesson', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
32: $this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a lesson', 'woothemes-sensei' ), $this->template );
33: }
34:
35: 36: 37: 38: 39: 40: 41: 42:
43: function trigger( $learner_id = 0, $lesson_id = 0 ) {
44:
45: global $sensei_email_data;
46:
47: if ( ! Sensei_Utils::user_started_lesson( $lesson_id, $learner_id ) ) {
48: return;
49: }
50:
51:
52: $this->learner = new WP_User( $learner_id );
53:
54:
55: $teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' );
56: $this->teacher = new WP_User( $teacher_id );
57:
58:
59: $sensei_email_data = apply_filters( 'sensei_email_data', array(
60: 'template' => $this->template,
61: 'heading' => $this->heading,
62: 'teacher_id' => $teacher_id,
63: 'learner_id' => $learner_id,
64: 'learner_name' => $this->learner->display_name,
65: 'lesson_id' => $lesson_id,
66: ), $this->template );
67:
68:
69: $this->recipient = stripslashes( $this->teacher->user_email );
70:
71:
72: Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
73: }
74: }
75:
76: endif;
77:
78: return new WooThemes_Sensei_Email_Teacher_Completed_Lesson();