WooThemes_Sensei_Email_Learner_Graded_Quiz   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 73
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B trigger() 0 43 3
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 17 and the first side effect is on line 3.

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
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;
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...
20
	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...
21
	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...
22
	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...
23
	var $user;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $user.

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...
24
25
	/**
26
	 * Constructor
27
	 *
28
	 * @access public
29
	 */
30
	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...
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 ) {
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...
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();