__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 6.

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.

Loading history...
2
/**
3
 * This email will be sent to a teacher when a course is assigned to them.
4
 */
5
6
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
7
8
if (  class_exists('Sensei_Email_Teacher_New_Course_Assignment') ){
9
    return;
10
}
11
12
/**
13
 * Teacher Started Course
14
 *
15
 * An email sent to the teacher when one of their students starts a course.
16
 *
17
 * @package Users
18
 * @author Automattic
19
 *
20
 * @since		1.6.0
21
 */
22
class Sensei_Email_Teacher_New_Course_Assignment {
23
24
	var $template;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $template.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
25
	var $subject;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $subject.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
26
	var $heading;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $heading.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
27
	var $recipient;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $recipient.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
28
	var $learner;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $learner.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
29
	var $teacher;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $teacher.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
30
31
	/**
32
	 * Constructor
33
	 * @since 1.8.0
34
	 * @access public
35
	 */
36
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
38
        $this->template = 'teacher-new-course-assignment';
39
		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have been assigned to a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
40
		$this->heading = apply_filters( 'sensei_email_heading', __( 'Course assigned to you', 'woothemes-sensei' ), $this->template );
41
        return;
42
	}
43
44
	/**
45
	 * trigger function.
46
	 *
47
	 * @access public
48
     * @param $teacher_id
49
     * @param $course_id
50
	 * @return void
51
	 */
52
	function trigger( $teacher_id = 0, $course_id = 0 ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
53
		global $sensei_email_data;
54
55
		$this->teacher = new WP_User( $teacher_id );
56
        $this->recipient = stripslashes( $this->teacher->user_email );
57
        $this->subject = __( 'New course assigned to you', 'woothemes-sensei' );
58
59
        //course edit link
60
        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
61
62
        // Course name
63
        $course = get_post( $course_id);
64
		// Construct data array
65
		$sensei_email_data = apply_filters( 'sensei_email_data', array(
66
			'template'			=> $this->template,
67
			'heading'			=> $this->heading,
68
			'teacher_id'		=> $teacher_id,
69
			'course_id'			=> $course_id,
70
            'course_name'			=> $course->post_title,
71
            'course_edit_link' => $course_edit_link,
72
		), $this->template );
73
74
		// Send mail
75
		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
76
	}
77
}
78
79
/**
80
 * Return a new instance of this files class
81
 */
82
return new Sensei_Email_Teacher_New_Course_Assignment();
83