Completed
Push — issues/611 ( 19900c...46c90d )
by Ravinder
21:01
created

get_notification_status_field()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 18
nc 2
nop 2
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Email Notification Setting Fields
5
 *
6
 * @package     Give
7
 * @subpackage  Classes/Emails
8
 * @copyright   Copyright (c) 2016, WordImpress
9
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
10
 * @since       1.9
11
 */
12
class Give_Email_Setting_Field {
13
	/**
14
	 * Get setting field.
15
	 *
16
	 * @since  1.9
17
	 * @access public
18
	 *
19
	 * @param Give_Email_Notification $email
20
	 * @param int                     $form_id
21
	 *
22
	 * @return array
23
	 */
24
	public static function get_setting_fields( Give_Email_Notification $email, $form_id = 0 ) {
25
		$setting_fields = self::get_default_setting_fields( $email, $form_id );
26
27
		// Recipient field.
28
		if ( $email->has_recipient_field() ) {
29
			$setting_fields[] = self::get_recipient_setting_field( $email, $form_id );
30
		}
31
32
		// Preview field.
33
		if ( $email->has_preview() ) {
34
			$setting_fields[] = self::get_preview_setting_field( $email, $form_id );
35
		}
36
37
		// Add extra setting field.
38
		if ( $extra_setting_field = $email->get_extra_setting_fields( $form_id ) ) {
39
			$setting_fields = array_merge( $setting_fields, $extra_setting_field );
40
		}
41
42
		$setting_fields = self::add_section_end( $setting_fields, $email );
43
44
		return $setting_fields;
45
	}
46
47
48
	/**
49
	 * Check if email notification setting has section end or not.
50
	 *
51
	 * @since  1.9
52
	 * @access private
53
	 *
54
	 * @param $setting
55
	 *
56
	 * @return bool
57
	 */
58
	public static function has_section_end( $setting ) {
59
		$last_field      = end( $setting );
60
		$has_section_end = false;
61
62
		if ( 'sectionend' === $last_field['type'] ) {
63
			$has_section_end = true;
64
		}
65
66
		return $has_section_end;
67
	}
68
69
	/**
70
	 * Check if email notification setting has section end or not.
71
	 *
72
	 * @since  1.9
73
	 * @access private
74
	 *
75
	 * @param array                   $setting
76
	 * @param Give_Email_Notification $email
77
	 *
78
	 * @return array
79
	 */
80
	public static function add_section_end( $setting, Give_Email_Notification $email ) {
81
		if ( ! self::has_section_end( $setting ) ) {
82
			// Add section end field.
83
			$setting[] = array(
84
				'id'   => "give_title_email_settings_{$email->get_id()}",
85
				'type' => 'sectionend',
86
			);
87
		}
88
89
		return $setting;
90
	}
91
92
	/**
93
	 * Get default setting field.
94
	 *
95
	 * @since  1.9
96
	 * @access static
97
	 *
98
	 * @param Give_Email_Notification $email
99
	 * @param int                     $form_id
100
	 *
101
	 * @return array
102
	 */
103
	public static function get_default_setting_fields( Give_Email_Notification $email, $form_id = 0 ) {
104
		return array(
105
			array(
106
				'id'    => "give_title_email_settings_{$email->get_id()}",
107
				'type'  => 'title',
108
				'title' => $email->get_label(),
109
			),
110
			self::get_notification_status_field( $email, $form_id ),
111
			self::get_email_subject_field( $email, $form_id ),
112
			self::get_email_message_field( $email, $form_id ),
113
		);
114
	}
115
116
	/**
117
	 * Get notification status setting field.
118
	 *
119
	 * @since  1.9
120
	 * @access static
121
	 *
122
	 * @param Give_Email_Notification $email
123
	 * @param int                     $form_id
124
	 *
125
	 * @return array
126
	 */
127
	public static function get_notification_status_field( Give_Email_Notification $email, $form_id = 0 ) {
128
		$option = array(
129
			'enabled'  => __( 'Enabled', 'give' ),
130
			'disabled' => __( 'Disabled', 'give' ),
131
		);
132
133
		$default_value = $email->get_notification_status();
134
135
		// Remove global options.
136
		if ( $form_id ) {
137
			$option = array(
138
				'global'   => __( 'Global Options' ),
139
				'enabled'  => __( 'Customize', 'give' ),
140
				'disabled' => __( 'Disabled', 'give' ),
141
			);
142
143
			$default_value = 'global';
144
		}
145
146
		return array(
147
			'name'    => esc_html__( 'Notification', 'give' ),
148
			'desc'    => esc_html__( 'Choose option if you want to send email notification or not.', 'give' ),
149
			'id'      => "{$email->get_id()}_notification",
150
			'type'    => 'radio_inline',
151
			'default' => $default_value,
152
			'options' => $option,
153
		);
154
	}
155
156
	/**
157
	 * Get email subject setting field.
158
	 *
159
	 * @since  1.9
160
	 * @access static
161
	 *
162
	 * @param Give_Email_Notification $email
163
	 * @param int                     $form_id
164
	 *
165
	 * @return array
166
	 */
167
	public static function get_email_subject_field( Give_Email_Notification $email, $form_id = 0 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
		return array(
169
			'id'      => "{$email->get_id()}_email_subject",
170
			'name'    => esc_html__( 'Email Subject', 'give' ),
171
			'desc'    => esc_html__( 'Enter the subject line for email.', 'give' ),
172
			'default' => $email->get_default_email_subject(),
173
			'type'    => 'text',
174
		);
175
	}
176
177
	/**
178
	 * Get email message setting field.
179
	 *
180
	 * @since  1.9
181
	 * @access static
182
	 *
183
	 * @param Give_Email_Notification $email
184
	 * @param int                     $form_id
185
	 *
186
	 * @return array
187
	 */
188
	public static function get_email_message_field( Give_Email_Notification $email, $form_id = 0 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
189
		return array(
190
			'id'      => "{$email->get_id()}_email_message",
191
			'name'    => esc_html__( 'Email message', 'give' ),
192
			'desc'    => $email->get_email_message_field_description(),
193
			'type'    => 'wysiwyg',
194
			'default' => $email->get_default_email_message(),
195
		);
196
	}
197
198
199
	/**
200
	 * Get recipient setting field.
201
	 *
202
	 * @since  1.9
203
	 * @access static
204
	 *
205
	 * @param Give_Email_Notification $email
206
	 * @param int                     $form_id
207
	 *
208
	 * @return array
209
	 */
210
	public static function get_recipient_setting_field( Give_Email_Notification $email, $form_id = 0 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
211
		return array(
212
			'id'               => "{$email->get_id()}_recipient",
213
			'name'             => esc_html__( 'Email Recipients', 'give' ),
214
			'desc'             => __( 'Enter the email address(es) that should receive a notification anytime a donation is made.', 'give' ),
215
			'type'             => 'email',
216
			'default'          => get_bloginfo( 'admin_email' ),
217
			'repeat'           => true,
218
			'repeat_btn_title' => esc_html__( 'Add Recipient', 'give' ),
219
		);
220
	}
221
222
	/**
223
	 * Get preview setting field.
224
	 *
225
	 * @since  1.9
226
	 * @access static
227
	 *
228
	 * @param Give_Email_Notification $email
229
	 * @param int                     $form_id
230
	 *
231
	 * @return array
232
	 */
233
	public static function get_preview_setting_field( Give_Email_Notification $email, $form_id = 0 ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
234
		return array(
235
			'name' => esc_html__( 'Preview Email', 'give' ),
236
			'desc' => esc_html__( 'Click the buttons to preview emails.', 'give' ),
237
			'id'   => "{$email->get_id()}_preview_buttons",
238
			'type' => 'email_preview_buttons',
239
		);
240
	}
241
}