Completed
Branch FET/rule-specific-exclusions-l... (334422)
by
unknown
17:10 queued 32s
created
core/db_classes/EE_Question_Group.class.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      * Adds the question to this question group
216 216
      *
217 217
      * @param EE_Question || int $question object or ID
218
-     * @return boolean if successful
218
+     * @return EE_Base_Class if successful
219 219
      */
220 220
     public function add_question($questionObjectOrID)
221 221
     {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      * Removes the question from this question group
228 228
      *
229 229
      * @param EE_Question || int $question object or ID
230
-     * @return boolean of success
230
+     * @return EE_Base_Class of success
231 231
      */
232 232
     public function remove_question($questionObjectOrID)
233 233
     {
Please login to merge, or discard this patch.
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -12,280 +12,280 @@
 block discarded – undo
12 12
 class EE_Question_Group extends EE_Soft_Delete_Base_Class
13 13
 {
14 14
 
15
-    /**
16
-     * @param array $props_n_values
17
-     * @return EE_Question_Group|mixed
18
-     */
19
-    public static function new_instance($props_n_values = array())
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
-        return $has_object ? $has_object : new self($props_n_values);
23
-    }
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Question_Group
29
-     */
30
-    public static function new_instance_from_db($props_n_values = array())
31
-    {
32
-        return new self($props_n_values, true);
33
-    }
34
-
35
-
36
-    /**
37
-     * gets the question group's name
38
-     *
39
-     * @access public
40
-     * @param bool $pretty
41
-     * @return string
42
-     */
43
-    public function name($pretty = false)
44
-    {
45
-        return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name');
46
-    }
47
-
48
-
49
-    /**
50
-     * Gets the question group's internal name
51
-     *
52
-     * @access public
53
-     * @return string
54
-     */
55
-    public function identifier()
56
-    {
57
-        return $this->get('QSG_identifier');
58
-    }
59
-
60
-
61
-    /**
62
-     * Gets the question group's description
63
-     *
64
-     * @access public
65
-     * @param bool $pretty
66
-     * @return string
67
-     */
68
-    public function desc($pretty = false)
69
-    {
70
-        return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc');
71
-    }
72
-
73
-
74
-    /**
75
-     * Gets the question group's order number in a sequence
76
-     * of other question groups
77
-     *
78
-     * @access public
79
-     * @return int
80
-     */
81
-    public function order()
82
-    {
83
-        return $this->get('QSG_order');
84
-    }
85
-
86
-
87
-    /**
88
-     * Returns whether to show the group's name on the frontend
89
-     *
90
-     * @access public
91
-     * @return boolean
92
-     */
93
-    public function show_group_name()
94
-    {
95
-        return $this->get('QSG_show_group_name');
96
-    }
97
-
98
-
99
-    /**
100
-     * Returns whether to show the group's description
101
-     * on the frontend
102
-     *
103
-     * @access public
104
-     * @return boolean
105
-     */
106
-    public function show_group_desc()
107
-    {
108
-        return $this->get('QSG_show_group_desc');
109
-    }
110
-
111
-
112
-    /**
113
-     * Returns whether this is a 'system group' (meaning
114
-     * a question group integral to the system, whose questions
115
-     * relate to the attendee table)
116
-     *
117
-     * @access public
118
-     * @return int
119
-     */
120
-    public function system_group()
121
-    {
122
-        return $this->get('QSG_system');
123
-    }
124
-
125
-
126
-    /**
127
-     * get the author of the question group.
128
-     *
129
-     * @since 4.5.0
130
-     *
131
-     * @return int
132
-     */
133
-    public function wp_user()
134
-    {
135
-        return $this->get('QSG_wp_user');
136
-    }
137
-
138
-
139
-    /**
140
-     * Returns whether this question group has
141
-     * been deleted
142
-     *
143
-     * @access public
144
-     * @return boolean
145
-     */
146
-    public function deleted()
147
-    {
148
-        return $this->get('QST_deleted');
149
-    }
150
-
151
-
152
-    /**
153
-     * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group
154
-     * at the end of the array.  Questions in the group are ordered by Question_Group_Question.QGQ_order and questions
155
-     * NOT in the group are ordered by Question.QGQ_order
156
-     *
157
-     * @return EE_Question[]
158
-     */
159
-    public function questions_in_and_not_in_group()
160
-    {
161
-        $questions_in_group = $this->questions();
162
-        $exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array();
163
-        $questions_not_in_group = $this->questions_not_in_group($exclude_question_ids);
164
-        return $questions_in_group + $questions_not_in_group;
165
-    }
166
-
167
-
168
-    /**
169
-     * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order)
170
-     *
171
-     * @param array $query_params
172
-     * @return EE_Question[]
173
-     */
174
-    public function questions($query_params = array())
175
-    {
176
-        $query_params = ! empty($query_params) ? $query_params
177
-            : array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC'));
178
-        return $this->ID() ? $this->get_many_related('Question', $query_params) : array();
179
-    }
180
-
181
-
182
-    /**
183
-     * Gets all the questions which are NOT part of this question group.
184
-     *
185
-     * @param  mixed $question_IDS_in_group if empty array then all questions returned.  if FALSE then we first get
186
-     *                                      questions in this group and exclude them from questions get all. IF empty
187
-     *                                      array then we just return all questions.
188
-     * @return EE_Question[]
189
-     */
190
-    public function questions_not_in_group($question_IDS_in_group = false)
191
-    {
192
-        if ($question_IDS_in_group === false) {
193
-            $questions = $this->questions();
194
-            $question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array();
195
-        }
196
-        $_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group))
197
-            : array();
198
-
199
-        return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC')));
200
-    }
201
-
202
-
203
-    /**
204
-     * Gets all events which are related to this question group
205
-     *
206
-     * @return EE_Event[]
207
-     */
208
-    public function events()
209
-    {
210
-        return $this->get_many_related('Event');
211
-    }
212
-
213
-
214
-    /**
215
-     * Adds the question to this question group
216
-     *
217
-     * @param EE_Question || int $question object or ID
218
-     * @return boolean if successful
219
-     */
220
-    public function add_question($questionObjectOrID)
221
-    {
222
-        return $this->_add_relation_to($questionObjectOrID, 'Question');
223
-    }
224
-
225
-
226
-    /**
227
-     * Removes the question from this question group
228
-     *
229
-     * @param EE_Question || int $question object or ID
230
-     * @return boolean of success
231
-     */
232
-    public function remove_question($questionObjectOrID)
233
-    {
234
-        return $this->_remove_relation_to($questionObjectOrID, 'Question');
235
-    }
236
-
237
-
238
-    /**
239
-     * @param $questionObjectOrID
240
-     * @param $qst_order
241
-     * @return int
242
-     */
243
-    public function update_question_order($questionObjectOrID, $qst_order)
244
-    {
245
-        $qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID;
246
-        return EEM_Question_Group_Question::instance()->update(
247
-            array('QGQ_order' => $qst_order),
248
-            array(
249
-                array(
250
-                    'QST_ID' => $qst_ID,
251
-                    'QSG_ID' => $this->ID(),
252
-                ),
253
-            )
254
-        );
255
-    }
256
-
257
-
258
-    /**
259
-     * Basically this is method just returns whether the question group has any questions with answers.  This is used
260
-     * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c
261
-     * question groups with questions that have answers should not be possible to delete permanently
262
-     *
263
-     * @return boolean true if has questions with answers, false if not.
264
-     */
265
-    public function has_questions_with_answers()
266
-    {
267
-        $has_answers = false;
268
-        $questions = $this->get_many_related('Question');
269
-        foreach ($questions as $question) {
270
-            if ($question->count_related('Answer') > 0) {
271
-                $has_answers = true;
272
-            }
273
-        }
274
-        return $has_answers;
275
-    }
276
-
277
-
278
-    /**
279
-     * The purpose of this method is set the question group order for this question group to be the max out of all
280
-     * question groups
281
-     *
282
-     * @access public
283
-     * @return void
284
-     */
285
-    public function set_order_to_latest()
286
-    {
287
-        $latest_order = $this->get_model()->get_latest_question_group_order();
288
-        $latest_order++;
289
-        $this->set('QSG_order', $latest_order);
290
-    }
15
+	/**
16
+	 * @param array $props_n_values
17
+	 * @return EE_Question_Group|mixed
18
+	 */
19
+	public static function new_instance($props_n_values = array())
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
+		return $has_object ? $has_object : new self($props_n_values);
23
+	}
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Question_Group
29
+	 */
30
+	public static function new_instance_from_db($props_n_values = array())
31
+	{
32
+		return new self($props_n_values, true);
33
+	}
34
+
35
+
36
+	/**
37
+	 * gets the question group's name
38
+	 *
39
+	 * @access public
40
+	 * @param bool $pretty
41
+	 * @return string
42
+	 */
43
+	public function name($pretty = false)
44
+	{
45
+		return $pretty ? $this->get_pretty('QSG_name') : $this->get('QSG_name');
46
+	}
47
+
48
+
49
+	/**
50
+	 * Gets the question group's internal name
51
+	 *
52
+	 * @access public
53
+	 * @return string
54
+	 */
55
+	public function identifier()
56
+	{
57
+		return $this->get('QSG_identifier');
58
+	}
59
+
60
+
61
+	/**
62
+	 * Gets the question group's description
63
+	 *
64
+	 * @access public
65
+	 * @param bool $pretty
66
+	 * @return string
67
+	 */
68
+	public function desc($pretty = false)
69
+	{
70
+		return $pretty ? $this->get_pretty('QSG_desc') : $this->get('QSG_desc');
71
+	}
72
+
73
+
74
+	/**
75
+	 * Gets the question group's order number in a sequence
76
+	 * of other question groups
77
+	 *
78
+	 * @access public
79
+	 * @return int
80
+	 */
81
+	public function order()
82
+	{
83
+		return $this->get('QSG_order');
84
+	}
85
+
86
+
87
+	/**
88
+	 * Returns whether to show the group's name on the frontend
89
+	 *
90
+	 * @access public
91
+	 * @return boolean
92
+	 */
93
+	public function show_group_name()
94
+	{
95
+		return $this->get('QSG_show_group_name');
96
+	}
97
+
98
+
99
+	/**
100
+	 * Returns whether to show the group's description
101
+	 * on the frontend
102
+	 *
103
+	 * @access public
104
+	 * @return boolean
105
+	 */
106
+	public function show_group_desc()
107
+	{
108
+		return $this->get('QSG_show_group_desc');
109
+	}
110
+
111
+
112
+	/**
113
+	 * Returns whether this is a 'system group' (meaning
114
+	 * a question group integral to the system, whose questions
115
+	 * relate to the attendee table)
116
+	 *
117
+	 * @access public
118
+	 * @return int
119
+	 */
120
+	public function system_group()
121
+	{
122
+		return $this->get('QSG_system');
123
+	}
124
+
125
+
126
+	/**
127
+	 * get the author of the question group.
128
+	 *
129
+	 * @since 4.5.0
130
+	 *
131
+	 * @return int
132
+	 */
133
+	public function wp_user()
134
+	{
135
+		return $this->get('QSG_wp_user');
136
+	}
137
+
138
+
139
+	/**
140
+	 * Returns whether this question group has
141
+	 * been deleted
142
+	 *
143
+	 * @access public
144
+	 * @return boolean
145
+	 */
146
+	public function deleted()
147
+	{
148
+		return $this->get('QST_deleted');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Gets an array of questions with questions IN the group at the start of the array and questions NOT in the group
154
+	 * at the end of the array.  Questions in the group are ordered by Question_Group_Question.QGQ_order and questions
155
+	 * NOT in the group are ordered by Question.QGQ_order
156
+	 *
157
+	 * @return EE_Question[]
158
+	 */
159
+	public function questions_in_and_not_in_group()
160
+	{
161
+		$questions_in_group = $this->questions();
162
+		$exclude_question_ids = ! empty($questions_in_group) ? array_keys($questions_in_group) : array();
163
+		$questions_not_in_group = $this->questions_not_in_group($exclude_question_ids);
164
+		return $questions_in_group + $questions_not_in_group;
165
+	}
166
+
167
+
168
+	/**
169
+	 * Gets all the questions which are part of this question group (ordered Question_Group_Question.QGQ_order)
170
+	 *
171
+	 * @param array $query_params
172
+	 * @return EE_Question[]
173
+	 */
174
+	public function questions($query_params = array())
175
+	{
176
+		$query_params = ! empty($query_params) ? $query_params
177
+			: array('order_by' => array('Question_Group_Question.QGQ_order' => 'ASC'));
178
+		return $this->ID() ? $this->get_many_related('Question', $query_params) : array();
179
+	}
180
+
181
+
182
+	/**
183
+	 * Gets all the questions which are NOT part of this question group.
184
+	 *
185
+	 * @param  mixed $question_IDS_in_group if empty array then all questions returned.  if FALSE then we first get
186
+	 *                                      questions in this group and exclude them from questions get all. IF empty
187
+	 *                                      array then we just return all questions.
188
+	 * @return EE_Question[]
189
+	 */
190
+	public function questions_not_in_group($question_IDS_in_group = false)
191
+	{
192
+		if ($question_IDS_in_group === false) {
193
+			$questions = $this->questions();
194
+			$question_IDS_in_group = ! empty($questions) ? array_keys($questions) : array();
195
+		}
196
+		$_where = ! empty($question_IDS_in_group) ? array('QST_ID' => array('not_in', $question_IDS_in_group))
197
+			: array();
198
+
199
+		return EEM_Question::instance()->get_all(array($_where, 'order_by' => array('QST_ID' => 'ASC')));
200
+	}
201
+
202
+
203
+	/**
204
+	 * Gets all events which are related to this question group
205
+	 *
206
+	 * @return EE_Event[]
207
+	 */
208
+	public function events()
209
+	{
210
+		return $this->get_many_related('Event');
211
+	}
212
+
213
+
214
+	/**
215
+	 * Adds the question to this question group
216
+	 *
217
+	 * @param EE_Question || int $question object or ID
218
+	 * @return boolean if successful
219
+	 */
220
+	public function add_question($questionObjectOrID)
221
+	{
222
+		return $this->_add_relation_to($questionObjectOrID, 'Question');
223
+	}
224
+
225
+
226
+	/**
227
+	 * Removes the question from this question group
228
+	 *
229
+	 * @param EE_Question || int $question object or ID
230
+	 * @return boolean of success
231
+	 */
232
+	public function remove_question($questionObjectOrID)
233
+	{
234
+		return $this->_remove_relation_to($questionObjectOrID, 'Question');
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param $questionObjectOrID
240
+	 * @param $qst_order
241
+	 * @return int
242
+	 */
243
+	public function update_question_order($questionObjectOrID, $qst_order)
244
+	{
245
+		$qst_ID = $questionObjectOrID instanceof EE_Question ? $questionObjectOrID->ID() : (int) $questionObjectOrID;
246
+		return EEM_Question_Group_Question::instance()->update(
247
+			array('QGQ_order' => $qst_order),
248
+			array(
249
+				array(
250
+					'QST_ID' => $qst_ID,
251
+					'QSG_ID' => $this->ID(),
252
+				),
253
+			)
254
+		);
255
+	}
256
+
257
+
258
+	/**
259
+	 * Basically this is method just returns whether the question group has any questions with answers.  This is used
260
+	 * by the admin currently to determine whether we should display the ui for deleting permanently or not b/c
261
+	 * question groups with questions that have answers should not be possible to delete permanently
262
+	 *
263
+	 * @return boolean true if has questions with answers, false if not.
264
+	 */
265
+	public function has_questions_with_answers()
266
+	{
267
+		$has_answers = false;
268
+		$questions = $this->get_many_related('Question');
269
+		foreach ($questions as $question) {
270
+			if ($question->count_related('Answer') > 0) {
271
+				$has_answers = true;
272
+			}
273
+		}
274
+		return $has_answers;
275
+	}
276
+
277
+
278
+	/**
279
+	 * The purpose of this method is set the question group order for this question group to be the max out of all
280
+	 * question groups
281
+	 *
282
+	 * @access public
283
+	 * @return void
284
+	 */
285
+	public function set_order_to_latest()
286
+	{
287
+		$latest_order = $this->get_model()->get_latest_question_group_order();
288
+		$latest_order++;
289
+		$this->set('QSG_order', $latest_order);
290
+	}
291 291
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Question_Option.class.php 2 patches
Doc Comments   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param array  $props_n_values  incoming values from the database
40 40
      * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
41 41
      *                                the website will be used.
42
-     * @return EE_Attendee
42
+     * @return EE_Question_Option
43 43
      */
44 44
     public static function new_instance_from_db($props_n_values = array(), $timezone = null)
45 45
     {
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      * Sets the option's key value
52 52
      *
53 53
      * @param string $value
54
-     * @return bool success
54
+     * @return boolean|null success
55 55
      */
56 56
     public function set_value($value)
57 57
     {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * Sets the option's Display Text
64 64
      *
65 65
      * @param string $text
66
-     * @return bool success
66
+     * @return boolean|null success
67 67
      */
68 68
     public function set_desc($text)
69 69
     {
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @access public
78 78
      * @param integer $order
79
-     * @return bool      $success
79
+     * @return boolean|null      $success
80 80
      */
81 81
     public function set_order($order)
82 82
     {
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
      * Sets the ID of the related question
89 89
      *
90 90
      * @param int $question_ID
91
-     * @return bool success
91
+     * @return boolean|null success
92 92
      */
93 93
     public function set_question_ID($question_ID)
94 94
     {
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
      * Sets the option's opt_group
101 101
      *
102 102
      * @param string $text
103
-     * @return bool success
103
+     * @return string success
104 104
      */
105 105
     public function set_opt_group($text)
106 106
     {
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      * Sets QSO_system
221 221
      *
222 222
      * @param string $QSO_system
223
-     * @return bool
223
+     * @return boolean|null
224 224
      */
225 225
     public function set_system($QSO_system)
226 226
     {
Please login to merge, or discard this patch.
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -10,220 +10,220 @@
 block discarded – undo
10 10
 class EE_Question_Option extends EE_Soft_Delete_Base_Class implements EEI_Duplicatable
11 11
 {
12 12
 
13
-    /**
14
-     * Question Option Opt Group Name
15
-     *
16
-     * @access protected
17
-     * @var string
18
-     */
19
-    protected $_QSO_opt_group = null;
20
-
21
-
22
-    /**
23
-     *
24
-     * @param array  $props_n_values          incoming values
25
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
26
-     *                                        used.)
27
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
28
-     *                                        date_format and the second value is the time format
29
-     * @return EE_Attendee
30
-     */
31
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
32
-    {
33
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
34
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
35
-    }
36
-
37
-
38
-    /**
39
-     * @param array  $props_n_values  incoming values from the database
40
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
41
-     *                                the website will be used.
42
-     * @return EE_Attendee
43
-     */
44
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
45
-    {
46
-        return new self($props_n_values, true, $timezone);
47
-    }
48
-
49
-
50
-    /**
51
-     * Sets the option's key value
52
-     *
53
-     * @param string $value
54
-     * @return bool success
55
-     */
56
-    public function set_value($value)
57
-    {
58
-        $this->set('QSO_value', $value);
59
-    }
60
-
61
-
62
-    /**
63
-     * Sets the option's Display Text
64
-     *
65
-     * @param string $text
66
-     * @return bool success
67
-     */
68
-    public function set_desc($text)
69
-    {
70
-        $this->set('QSO_desc', $text);
71
-    }
72
-
73
-
74
-    /**
75
-     * Sets the order for this option
76
-     *
77
-     * @access public
78
-     * @param integer $order
79
-     * @return bool      $success
80
-     */
81
-    public function set_order($order)
82
-    {
83
-        $this->set('QSO_order', $order);
84
-    }
85
-
86
-
87
-    /**
88
-     * Sets the ID of the related question
89
-     *
90
-     * @param int $question_ID
91
-     * @return bool success
92
-     */
93
-    public function set_question_ID($question_ID)
94
-    {
95
-        $this->set('QST_ID', $question_ID);
96
-    }
97
-
98
-
99
-    /**
100
-     * Sets the option's opt_group
101
-     *
102
-     * @param string $text
103
-     * @return bool success
104
-     */
105
-    public function set_opt_group($text)
106
-    {
107
-        return $this->_QSO_opt_group = $text;
108
-    }
109
-
110
-
111
-    /**
112
-     * Gets the option's key value
113
-     *
114
-     * @return string
115
-     */
116
-    public function value()
117
-    {
118
-        return $this->get('QSO_value');
119
-    }
120
-
121
-
122
-    /**
123
-     * Gets the option's display text
124
-     *
125
-     * @return string
126
-     */
127
-    public function desc()
128
-    {
129
-        return $this->get('QSO_desc');
130
-    }
131
-
132
-
133
-    /**
134
-     * Returns whether this option has been deleted or not
135
-     *
136
-     * @return boolean
137
-     */
138
-    public function deleted()
139
-    {
140
-        return $this->get('QSO_deleted');
141
-    }
142
-
143
-
144
-    /**
145
-     * Returns the order or the Question Option
146
-     *
147
-     * @access public
148
-     * @return integer
149
-     */
150
-    public function order()
151
-    {
152
-        return $this->get('QSO_option');
153
-    }
154
-
155
-
156
-    /**
157
-     * Gets the related question's ID
158
-     *
159
-     * @return int
160
-     */
161
-    public function question_ID()
162
-    {
163
-        return $this->get('QST_ID');
164
-    }
165
-
166
-
167
-    /**
168
-     * Returns the question related to this question option
169
-     *
170
-     * @return EE_Question
171
-     */
172
-    public function question()
173
-    {
174
-        return $this->get_first_related('Question');
175
-    }
176
-
177
-
178
-    /**
179
-     * Gets the option's opt_group
180
-     *
181
-     * @return string
182
-     */
183
-    public function opt_group()
184
-    {
185
-        return $this->_QSO_opt_group;
186
-    }
187
-
188
-    /**
189
-     * Duplicates this question option. By default the new question option will be for the same question,
190
-     * but that can be overriden by setting the 'QST_ID' option
191
-     *
192
-     * @param array $options {
193
-     * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
194
-     *                       as the original
195
-     */
196
-    public function duplicate($options = array())
197
-    {
198
-        $new_question_option = clone $this;
199
-        $new_question_option->set('QSO_ID', null);
200
-        if (array_key_exists(
201
-            'QST_ID',
202
-            $options
203
-        )) {// use array_key_exists instead of isset because NULL might be a valid value
204
-            $new_question_option->set_question_ID($options['QST_ID']);
205
-        }
206
-        $new_question_option->save();
207
-    }
208
-
209
-    /**
210
-     * Gets the QSO_system value
211
-     *
212
-     * @return string|null
213
-     */
214
-    public function system()
215
-    {
216
-        return $this->get('QSO_system');
217
-    }
218
-
219
-    /**
220
-     * Sets QSO_system
221
-     *
222
-     * @param string $QSO_system
223
-     * @return bool
224
-     */
225
-    public function set_system($QSO_system)
226
-    {
227
-        return $this->set('QSO_system', $QSO_system);
228
-    }
13
+	/**
14
+	 * Question Option Opt Group Name
15
+	 *
16
+	 * @access protected
17
+	 * @var string
18
+	 */
19
+	protected $_QSO_opt_group = null;
20
+
21
+
22
+	/**
23
+	 *
24
+	 * @param array  $props_n_values          incoming values
25
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
26
+	 *                                        used.)
27
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
28
+	 *                                        date_format and the second value is the time format
29
+	 * @return EE_Attendee
30
+	 */
31
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
32
+	{
33
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
34
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
35
+	}
36
+
37
+
38
+	/**
39
+	 * @param array  $props_n_values  incoming values from the database
40
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
41
+	 *                                the website will be used.
42
+	 * @return EE_Attendee
43
+	 */
44
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
45
+	{
46
+		return new self($props_n_values, true, $timezone);
47
+	}
48
+
49
+
50
+	/**
51
+	 * Sets the option's key value
52
+	 *
53
+	 * @param string $value
54
+	 * @return bool success
55
+	 */
56
+	public function set_value($value)
57
+	{
58
+		$this->set('QSO_value', $value);
59
+	}
60
+
61
+
62
+	/**
63
+	 * Sets the option's Display Text
64
+	 *
65
+	 * @param string $text
66
+	 * @return bool success
67
+	 */
68
+	public function set_desc($text)
69
+	{
70
+		$this->set('QSO_desc', $text);
71
+	}
72
+
73
+
74
+	/**
75
+	 * Sets the order for this option
76
+	 *
77
+	 * @access public
78
+	 * @param integer $order
79
+	 * @return bool      $success
80
+	 */
81
+	public function set_order($order)
82
+	{
83
+		$this->set('QSO_order', $order);
84
+	}
85
+
86
+
87
+	/**
88
+	 * Sets the ID of the related question
89
+	 *
90
+	 * @param int $question_ID
91
+	 * @return bool success
92
+	 */
93
+	public function set_question_ID($question_ID)
94
+	{
95
+		$this->set('QST_ID', $question_ID);
96
+	}
97
+
98
+
99
+	/**
100
+	 * Sets the option's opt_group
101
+	 *
102
+	 * @param string $text
103
+	 * @return bool success
104
+	 */
105
+	public function set_opt_group($text)
106
+	{
107
+		return $this->_QSO_opt_group = $text;
108
+	}
109
+
110
+
111
+	/**
112
+	 * Gets the option's key value
113
+	 *
114
+	 * @return string
115
+	 */
116
+	public function value()
117
+	{
118
+		return $this->get('QSO_value');
119
+	}
120
+
121
+
122
+	/**
123
+	 * Gets the option's display text
124
+	 *
125
+	 * @return string
126
+	 */
127
+	public function desc()
128
+	{
129
+		return $this->get('QSO_desc');
130
+	}
131
+
132
+
133
+	/**
134
+	 * Returns whether this option has been deleted or not
135
+	 *
136
+	 * @return boolean
137
+	 */
138
+	public function deleted()
139
+	{
140
+		return $this->get('QSO_deleted');
141
+	}
142
+
143
+
144
+	/**
145
+	 * Returns the order or the Question Option
146
+	 *
147
+	 * @access public
148
+	 * @return integer
149
+	 */
150
+	public function order()
151
+	{
152
+		return $this->get('QSO_option');
153
+	}
154
+
155
+
156
+	/**
157
+	 * Gets the related question's ID
158
+	 *
159
+	 * @return int
160
+	 */
161
+	public function question_ID()
162
+	{
163
+		return $this->get('QST_ID');
164
+	}
165
+
166
+
167
+	/**
168
+	 * Returns the question related to this question option
169
+	 *
170
+	 * @return EE_Question
171
+	 */
172
+	public function question()
173
+	{
174
+		return $this->get_first_related('Question');
175
+	}
176
+
177
+
178
+	/**
179
+	 * Gets the option's opt_group
180
+	 *
181
+	 * @return string
182
+	 */
183
+	public function opt_group()
184
+	{
185
+		return $this->_QSO_opt_group;
186
+	}
187
+
188
+	/**
189
+	 * Duplicates this question option. By default the new question option will be for the same question,
190
+	 * but that can be overriden by setting the 'QST_ID' option
191
+	 *
192
+	 * @param array $options {
193
+	 * @type int    $QST_ID  the QST_ID attribute of this question option, otherwise it will be for the same question
194
+	 *                       as the original
195
+	 */
196
+	public function duplicate($options = array())
197
+	{
198
+		$new_question_option = clone $this;
199
+		$new_question_option->set('QSO_ID', null);
200
+		if (array_key_exists(
201
+			'QST_ID',
202
+			$options
203
+		)) {// use array_key_exists instead of isset because NULL might be a valid value
204
+			$new_question_option->set_question_ID($options['QST_ID']);
205
+		}
206
+		$new_question_option->save();
207
+	}
208
+
209
+	/**
210
+	 * Gets the QSO_system value
211
+	 *
212
+	 * @return string|null
213
+	 */
214
+	public function system()
215
+	{
216
+		return $this->get('QSO_system');
217
+	}
218
+
219
+	/**
220
+	 * Sets QSO_system
221
+	 *
222
+	 * @param string $QSO_system
223
+	 * @return bool
224
+	 */
225
+	public function set_system($QSO_system)
226
+	{
227
+		return $this->set('QSO_system', $QSO_system);
228
+	}
229 229
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Status.class.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      * Sets code
53 53
      *
54 54
      * @param string $code
55
-     * @return boolean
55
+     * @return boolean|null
56 56
      */
57 57
     public function set_code($code)
58 58
     {
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
      * Sets desc
76 76
      *
77 77
      * @param string $desc
78
-     * @return boolean
78
+     * @return boolean|null
79 79
      */
80 80
     public function set_desc($desc)
81 81
     {
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      * Sets type
99 99
      *
100 100
      * @param string $type
101
-     * @return boolean
101
+     * @return boolean|null
102 102
      */
103 103
     public function set_type($type)
104 104
     {
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      * Sets can_edit
122 122
      *
123 123
      * @param boolean $can_edit
124
-     * @return boolean
124
+     * @return boolean|null
125 125
      */
126 126
     public function set_can_edit($can_edit)
127 127
     {
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      * Sets open
145 145
      *
146 146
      * @param boolean $open
147
-     * @return boolean
147
+     * @return boolean|null
148 148
      */
149 149
     public function set_open($open)
150 150
     {
Please login to merge, or discard this patch.
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -12,142 +12,142 @@
 block discarded – undo
12 12
 class EE_Status extends EE_Base_Class
13 13
 {
14 14
 
15
-    /**
16
-     * @param array $props_n_values
17
-     * @return EE_Status
18
-     */
19
-    public static function new_instance($props_n_values = array())
20
-    {
21
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
-        return $has_object ? $has_object : new self($props_n_values);
23
-    }
24
-
25
-
26
-    /**
27
-     * @param array $props_n_values
28
-     * @return EE_Status
29
-     */
30
-    public static function new_instance_from_db($props_n_values = array())
31
-    {
32
-        return new self($props_n_values, true);
33
-    }
34
-
35
-
36
-    /**
37
-     * Gets code
38
-     *
39
-     * @param bool   $plural
40
-     * @param string $schema
41
-     * @return string
42
-     */
43
-    public function code($plural = false, $schema = 'upper')
44
-    {
45
-        $id = $this->get('STS_ID');
46
-        $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema);
47
-        return $code[ $id ];
48
-    }
49
-
50
-
51
-    /**
52
-     * Sets code
53
-     *
54
-     * @param string $code
55
-     * @return boolean
56
-     */
57
-    public function set_code($code)
58
-    {
59
-        $this->set('STS_code', $code);
60
-    }
61
-
62
-
63
-    /**
64
-     * Gets desc
65
-     *
66
-     * @return string
67
-     */
68
-    public function desc()
69
-    {
70
-        return $this->get('STS_desc');
71
-    }
72
-
73
-
74
-    /**
75
-     * Sets desc
76
-     *
77
-     * @param string $desc
78
-     * @return boolean
79
-     */
80
-    public function set_desc($desc)
81
-    {
82
-        $this->set('STS_desc', $desc);
83
-    }
84
-
85
-
86
-    /**
87
-     * Gets type
88
-     *
89
-     * @return string
90
-     */
91
-    public function type()
92
-    {
93
-        return $this->get('STS_type');
94
-    }
95
-
96
-
97
-    /**
98
-     * Sets type
99
-     *
100
-     * @param string $type
101
-     * @return boolean
102
-     */
103
-    public function set_type($type)
104
-    {
105
-        $this->set('STS_type', $type);
106
-    }
107
-
108
-
109
-    /**
110
-     * Gets can_edit
111
-     *
112
-     * @return boolean
113
-     */
114
-    public function can_edit()
115
-    {
116
-        return $this->get('STS_can_edit');
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets can_edit
122
-     *
123
-     * @param boolean $can_edit
124
-     * @return boolean
125
-     */
126
-    public function set_can_edit($can_edit)
127
-    {
128
-        $this->set('STS_can_edit', $can_edit);
129
-    }
130
-
131
-
132
-    /**
133
-     * Gets open
134
-     *
135
-     * @return boolean
136
-     */
137
-    public function open()
138
-    {
139
-        return $this->get('STS_open');
140
-    }
141
-
142
-
143
-    /**
144
-     * Sets open
145
-     *
146
-     * @param boolean $open
147
-     * @return boolean
148
-     */
149
-    public function set_open($open)
150
-    {
151
-        $this->set('STS_open', $open);
152
-    }
15
+	/**
16
+	 * @param array $props_n_values
17
+	 * @return EE_Status
18
+	 */
19
+	public static function new_instance($props_n_values = array())
20
+	{
21
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
22
+		return $has_object ? $has_object : new self($props_n_values);
23
+	}
24
+
25
+
26
+	/**
27
+	 * @param array $props_n_values
28
+	 * @return EE_Status
29
+	 */
30
+	public static function new_instance_from_db($props_n_values = array())
31
+	{
32
+		return new self($props_n_values, true);
33
+	}
34
+
35
+
36
+	/**
37
+	 * Gets code
38
+	 *
39
+	 * @param bool   $plural
40
+	 * @param string $schema
41
+	 * @return string
42
+	 */
43
+	public function code($plural = false, $schema = 'upper')
44
+	{
45
+		$id = $this->get('STS_ID');
46
+		$code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema);
47
+		return $code[ $id ];
48
+	}
49
+
50
+
51
+	/**
52
+	 * Sets code
53
+	 *
54
+	 * @param string $code
55
+	 * @return boolean
56
+	 */
57
+	public function set_code($code)
58
+	{
59
+		$this->set('STS_code', $code);
60
+	}
61
+
62
+
63
+	/**
64
+	 * Gets desc
65
+	 *
66
+	 * @return string
67
+	 */
68
+	public function desc()
69
+	{
70
+		return $this->get('STS_desc');
71
+	}
72
+
73
+
74
+	/**
75
+	 * Sets desc
76
+	 *
77
+	 * @param string $desc
78
+	 * @return boolean
79
+	 */
80
+	public function set_desc($desc)
81
+	{
82
+		$this->set('STS_desc', $desc);
83
+	}
84
+
85
+
86
+	/**
87
+	 * Gets type
88
+	 *
89
+	 * @return string
90
+	 */
91
+	public function type()
92
+	{
93
+		return $this->get('STS_type');
94
+	}
95
+
96
+
97
+	/**
98
+	 * Sets type
99
+	 *
100
+	 * @param string $type
101
+	 * @return boolean
102
+	 */
103
+	public function set_type($type)
104
+	{
105
+		$this->set('STS_type', $type);
106
+	}
107
+
108
+
109
+	/**
110
+	 * Gets can_edit
111
+	 *
112
+	 * @return boolean
113
+	 */
114
+	public function can_edit()
115
+	{
116
+		return $this->get('STS_can_edit');
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets can_edit
122
+	 *
123
+	 * @param boolean $can_edit
124
+	 * @return boolean
125
+	 */
126
+	public function set_can_edit($can_edit)
127
+	{
128
+		$this->set('STS_can_edit', $can_edit);
129
+	}
130
+
131
+
132
+	/**
133
+	 * Gets open
134
+	 *
135
+	 * @return boolean
136
+	 */
137
+	public function open()
138
+	{
139
+		return $this->get('STS_open');
140
+	}
141
+
142
+
143
+	/**
144
+	 * Sets open
145
+	 *
146
+	 * @param boolean $open
147
+	 * @return boolean
148
+	 */
149
+	public function set_open($open)
150
+	{
151
+		$this->set('STS_open', $open);
152
+	}
153 153
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     {
45 45
         $id = $this->get('STS_ID');
46 46
         $code = EEM_Status::instance()->localized_status(array($id => $this->get('STS_code')), $plural, $schema);
47
-        return $code[ $id ];
47
+        return $code[$id];
48 48
     }
49 49
 
50 50
 
Please login to merge, or discard this patch.
core/db_classes/EE_Term.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * Sets name
67 67
      *
68 68
      * @param string $name
69
-     * @return boolean
69
+     * @return boolean|null
70 70
      */
71 71
     public function set_name($name)
72 72
     {
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * Sets slug
90 90
      *
91 91
      * @param string $slug
92
-     * @return boolean
92
+     * @return boolean|null
93 93
      */
94 94
     public function set_slug($slug)
95 95
     {
Please login to merge, or discard this patch.
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -12,87 +12,87 @@
 block discarded – undo
12 12
 class EE_Term extends EE_Base_Class
13 13
 {
14 14
 
15
-    public $post_type;
15
+	public $post_type;
16 16
 
17
-    /**
18
-     * Sets some dynamic defaults
19
-     *
20
-     * @param array  $fieldValues
21
-     * @param bool   $bydb
22
-     * @param string $timezone
23
-     */
24
-    protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
25
-    {
26
-        if (! isset($fieldValues['slug'])) {
27
-            $fieldValues['slug'] = $fieldValues['name'];
28
-        }
29
-        parent::__construct($fieldValues, $bydb, $timezone);
30
-    }
17
+	/**
18
+	 * Sets some dynamic defaults
19
+	 *
20
+	 * @param array  $fieldValues
21
+	 * @param bool   $bydb
22
+	 * @param string $timezone
23
+	 */
24
+	protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
25
+	{
26
+		if (! isset($fieldValues['slug'])) {
27
+			$fieldValues['slug'] = $fieldValues['name'];
28
+		}
29
+		parent::__construct($fieldValues, $bydb, $timezone);
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * @param array $props_n_values
35
-     * @return EE_Term|mixed
36
-     */
37
-    public static function new_instance($props_n_values = array())
38
-    {
39
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
40
-        return $has_object ? $has_object : new self($props_n_values);
41
-    }
33
+	/**
34
+	 * @param array $props_n_values
35
+	 * @return EE_Term|mixed
36
+	 */
37
+	public static function new_instance($props_n_values = array())
38
+	{
39
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
40
+		return $has_object ? $has_object : new self($props_n_values);
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param array $props_n_values
46
-     * @return EE_Term
47
-     */
48
-    public static function new_instance_from_db($props_n_values = array())
49
-    {
50
-        return new self($props_n_values, true);
51
-    }
44
+	/**
45
+	 * @param array $props_n_values
46
+	 * @return EE_Term
47
+	 */
48
+	public static function new_instance_from_db($props_n_values = array())
49
+	{
50
+		return new self($props_n_values, true);
51
+	}
52 52
 
53 53
 
54
-    /**
55
-     * Gets name
56
-     *
57
-     * @return string
58
-     */
59
-    public function name()
60
-    {
61
-        return $this->get('name');
62
-    }
54
+	/**
55
+	 * Gets name
56
+	 *
57
+	 * @return string
58
+	 */
59
+	public function name()
60
+	{
61
+		return $this->get('name');
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * Sets name
67
-     *
68
-     * @param string $name
69
-     * @return boolean
70
-     */
71
-    public function set_name($name)
72
-    {
73
-        $this->set('name', $name);
74
-    }
65
+	/**
66
+	 * Sets name
67
+	 *
68
+	 * @param string $name
69
+	 * @return boolean
70
+	 */
71
+	public function set_name($name)
72
+	{
73
+		$this->set('name', $name);
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * Gets slug
79
-     *
80
-     * @return string
81
-     */
82
-    public function slug()
83
-    {
84
-        return $this->get('slug');
85
-    }
77
+	/**
78
+	 * Gets slug
79
+	 *
80
+	 * @return string
81
+	 */
82
+	public function slug()
83
+	{
84
+		return $this->get('slug');
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * Sets slug
90
-     *
91
-     * @param string $slug
92
-     * @return boolean
93
-     */
94
-    public function set_slug($slug)
95
-    {
96
-        $this->set('slug', $slug);
97
-    }
88
+	/**
89
+	 * Sets slug
90
+	 *
91
+	 * @param string $slug
92
+	 * @return boolean
93
+	 */
94
+	public function set_slug($slug)
95
+	{
96
+		$this->set('slug', $slug);
97
+	}
98 98
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
      */
24 24
     protected function __construct($fieldValues = array(), $bydb = false, $timezone = '')
25 25
     {
26
-        if (! isset($fieldValues['slug'])) {
26
+        if ( ! isset($fieldValues['slug'])) {
27 27
             $fieldValues['slug'] = $fieldValues['name'];
28 28
         }
29 29
         parent::__construct($fieldValues, $bydb, $timezone);
Please login to merge, or discard this patch.
core/db_classes/EE_Term_Taxonomy.class.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * Sets taxonomy
48 48
      *
49 49
      * @param string $taxonomy
50
-     * @return boolean
50
+     * @return boolean|null
51 51
      */
52 52
     public function set_taxonomy($taxonomy)
53 53
     {
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
      * Sets term_count
71 71
      *
72 72
      * @param int $term_count
73
-     * @return boolean
73
+     * @return boolean|null
74 74
      */
75 75
     public function set_count($term_count)
76 76
     {
Please login to merge, or discard this patch.
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -11,80 +11,80 @@
 block discarded – undo
11 11
 class EE_Term_Taxonomy extends EE_Base_Class
12 12
 {
13 13
 
14
-    /**
15
-     * @param array $props_n_values
16
-     * @return EE_Term_Taxonomy
17
-     */
18
-    public static function new_instance($props_n_values = array())
19
-    {
20
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
21
-        return $has_object ? $has_object : new self($props_n_values);
22
-    }
14
+	/**
15
+	 * @param array $props_n_values
16
+	 * @return EE_Term_Taxonomy
17
+	 */
18
+	public static function new_instance($props_n_values = array())
19
+	{
20
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
21
+		return $has_object ? $has_object : new self($props_n_values);
22
+	}
23 23
 
24 24
 
25
-    /**
26
-     * @param array $props_n_values
27
-     * @return EE_Term_Taxonomy
28
-     */
29
-    public static function new_instance_from_db($props_n_values = array())
30
-    {
31
-        return new self($props_n_values, true);
32
-    }
25
+	/**
26
+	 * @param array $props_n_values
27
+	 * @return EE_Term_Taxonomy
28
+	 */
29
+	public static function new_instance_from_db($props_n_values = array())
30
+	{
31
+		return new self($props_n_values, true);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Gets taxonomy
37
-     *
38
-     * @return string
39
-     */
40
-    public function taxonomy()
41
-    {
42
-        return $this->get('taxonomy');
43
-    }
35
+	/**
36
+	 * Gets taxonomy
37
+	 *
38
+	 * @return string
39
+	 */
40
+	public function taxonomy()
41
+	{
42
+		return $this->get('taxonomy');
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * Sets taxonomy
48
-     *
49
-     * @param string $taxonomy
50
-     * @return boolean
51
-     */
52
-    public function set_taxonomy($taxonomy)
53
-    {
54
-        $this->set('taxonomy', $taxonomy);
55
-    }
46
+	/**
47
+	 * Sets taxonomy
48
+	 *
49
+	 * @param string $taxonomy
50
+	 * @return boolean
51
+	 */
52
+	public function set_taxonomy($taxonomy)
53
+	{
54
+		$this->set('taxonomy', $taxonomy);
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Gets term_count
60
-     *
61
-     * @return int
62
-     */
63
-    public function count()
64
-    {
65
-        return $this->get('term_count');
66
-    }
58
+	/**
59
+	 * Gets term_count
60
+	 *
61
+	 * @return int
62
+	 */
63
+	public function count()
64
+	{
65
+		return $this->get('term_count');
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Sets term_count
71
-     *
72
-     * @param int $term_count
73
-     * @return boolean
74
-     */
75
-    public function set_count($term_count)
76
-    {
77
-        $this->set('term_count', $term_count);
78
-    }
69
+	/**
70
+	 * Sets term_count
71
+	 *
72
+	 * @param int $term_count
73
+	 * @return boolean
74
+	 */
75
+	public function set_count($term_count)
76
+	{
77
+		$this->set('term_count', $term_count);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     * Gets the term for this term taxonomy
83
-     *
84
-     * @return EE_Term
85
-     */
86
-    public function term()
87
-    {
88
-        return $this->get_first_related('Term');
89
-    }
81
+	/**
82
+	 * Gets the term for this term taxonomy
83
+	 *
84
+	 * @return EE_Term
85
+	 */
86
+	public function term()
87
+	{
88
+		return $this->get_first_related('Term');
89
+	}
90 90
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -121,7 +121,8 @@
 block discarded – undo
121 121
      *                               relevant status const
122 122
      * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
123 123
      *               further processing
124
-     * @return mixed status int if the display string isn't requested
124
+     * @param boolean $remaining
125
+     * @return string status int if the display string isn't requested
125 126
      * @throws \EE_Error
126 127
      */
127 128
     public function ticket_status($display = false, $remaining = null)
Please login to merge, or discard this patch.
Indentation   +1460 added lines, -1460 removed lines patch added patch discarded remove patch
@@ -12,1464 +12,1464 @@
 block discarded – undo
12 12
 class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon
13 13
 {
14 14
 
15
-    /**
16
-     * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not.
17
-     */
18
-    const sold_out = 'TKS';
19
-
20
-    /**
21
-     *
22
-     */
23
-    const expired = 'TKE';
24
-
25
-    /**
26
-     *
27
-     */
28
-    const archived = 'TKA';
29
-
30
-    /**
31
-     *
32
-     */
33
-    const pending = 'TKP';
34
-
35
-    /**
36
-     *
37
-     */
38
-    const onsale = 'TKO';
39
-
40
-    /**
41
-     * extra meta key for tracking ticket reservations
42
-     *
43
-     * @type string
44
-     */
45
-    const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
46
-
47
-    /**
48
-     * cached result from method of the same name
49
-     *
50
-     * @var float $_ticket_total_with_taxes
51
-     */
52
-    private $_ticket_total_with_taxes;
53
-
54
-
55
-    /**
56
-     * @param array  $props_n_values          incoming values
57
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
58
-     *                                        used.)
59
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
60
-     *                                        date_format and the second value is the time format
61
-     * @return EE_Ticket
62
-     * @throws \EE_Error
63
-     */
64
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
65
-    {
66
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
67
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
68
-    }
69
-
70
-
71
-    /**
72
-     * @param array  $props_n_values  incoming values from the database
73
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
74
-     *                                the website will be used.
75
-     * @return EE_Ticket
76
-     * @throws \EE_Error
77
-     */
78
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
-    {
80
-        return new self($props_n_values, true, $timezone);
81
-    }
82
-
83
-
84
-    /**
85
-     * @return bool
86
-     * @throws \EE_Error
87
-     */
88
-    public function parent()
89
-    {
90
-        return $this->get('TKT_parent');
91
-    }
92
-
93
-
94
-    /**
95
-     * return if a ticket has quantities available for purchase
96
-     *
97
-     * @param  int $DTT_ID the primary key for a particular datetime
98
-     * @return boolean
99
-     * @throws \EE_Error
100
-     */
101
-    public function available($DTT_ID = 0)
102
-    {
103
-        // are we checking availability for a particular datetime ?
104
-        if ($DTT_ID) {
105
-            // get that datetime object
106
-            $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
107
-            // if  ticket sales for this datetime have exceeded the reg limit...
108
-            if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
109
-                return false;
110
-            }
111
-        }
112
-        // datetime is still open for registration, but is this ticket sold out ?
113
-        return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false;
114
-    }
115
-
116
-
117
-    /**
118
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
119
-     *
120
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
121
-     *                               relevant status const
122
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
123
-     *               further processing
124
-     * @return mixed status int if the display string isn't requested
125
-     * @throws \EE_Error
126
-     */
127
-    public function ticket_status($display = false, $remaining = null)
128
-    {
129
-        $remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
130
-        if (! $remaining) {
131
-            return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
132
-        }
133
-        if ($this->get('TKT_deleted')) {
134
-            return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
135
-        }
136
-        if ($this->is_expired()) {
137
-            return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
138
-        }
139
-        if ($this->is_pending()) {
140
-            return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
141
-        }
142
-        if ($this->is_on_sale()) {
143
-            return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
144
-        }
145
-        return '';
146
-    }
147
-
148
-
149
-    /**
150
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
151
-     * considering ALL the factors used for figuring that out.
152
-     *
153
-     * @access public
154
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
155
-     * @return boolean         true = tickets remaining, false not.
156
-     * @throws \EE_Error
157
-     */
158
-    public function is_remaining($DTT_ID = 0)
159
-    {
160
-        $num_remaining = $this->remaining($DTT_ID);
161
-        if ($num_remaining === 0) {
162
-            return false;
163
-        }
164
-        if ($num_remaining > 0 && $num_remaining < $this->min()) {
165
-            return false;
166
-        }
167
-        return true;
168
-    }
169
-
170
-
171
-    /**
172
-     * return the total number of tickets available for purchase
173
-     *
174
-     * @param  int $DTT_ID the primary key for a particular datetime.
175
-     *                     set to 0 for all related datetimes
176
-     * @return int
177
-     * @throws \EE_Error
178
-     */
179
-    public function remaining($DTT_ID = 0)
180
-    {
181
-        return $this->real_quantity_on_ticket('saleable', $DTT_ID);
182
-    }
183
-
184
-
185
-    /**
186
-     * Gets min
187
-     *
188
-     * @return int
189
-     * @throws \EE_Error
190
-     */
191
-    public function min()
192
-    {
193
-        return $this->get('TKT_min');
194
-    }
195
-
196
-
197
-    /**
198
-     * return if a ticket is no longer available cause its available dates have expired.
199
-     *
200
-     * @return boolean
201
-     * @throws \EE_Error
202
-     */
203
-    public function is_expired()
204
-    {
205
-        return ($this->get_raw('TKT_end_date') < time());
206
-    }
207
-
208
-
209
-    /**
210
-     * Return if a ticket is yet to go on sale or not
211
-     *
212
-     * @return boolean
213
-     * @throws \EE_Error
214
-     */
215
-    public function is_pending()
216
-    {
217
-        return ($this->get_raw('TKT_start_date') > time());
218
-    }
219
-
220
-
221
-    /**
222
-     * Return if a ticket is on sale or not
223
-     *
224
-     * @return boolean
225
-     * @throws \EE_Error
226
-     */
227
-    public function is_on_sale()
228
-    {
229
-        return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
230
-    }
231
-
232
-
233
-    /**
234
-     * This returns the chronologically last datetime that this ticket is associated with
235
-     *
236
-     * @param string $dt_frmt
237
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
238
-     *                            the end date ie: Jan 01 "to" Dec 31
239
-     * @return string
240
-     * @throws \EE_Error
241
-     */
242
-    public function date_range($dt_frmt = '', $conjunction = ' - ')
243
-    {
244
-        $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt)
245
-            : '';
246
-        $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
247
-
248
-        return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
249
-    }
250
-
251
-
252
-    /**
253
-     * This returns the chronologically first datetime that this ticket is associated with
254
-     *
255
-     * @return EE_Datetime
256
-     * @throws \EE_Error
257
-     */
258
-    public function first_datetime()
259
-    {
260
-        $datetimes = $this->datetimes(array('limit' => 1));
261
-        return reset($datetimes);
262
-    }
263
-
264
-
265
-    /**
266
-     * Gets all the datetimes this ticket can be used for attending.
267
-     * Unless otherwise specified, orders datetimes by start date.
268
-     *
269
-     * @param array $query_params see EEM_Base::get_all()
270
-     * @return EE_Datetime[]|EE_Base_Class[]
271
-     * @throws \EE_Error
272
-     */
273
-    public function datetimes($query_params = array())
274
-    {
275
-        if (! isset($query_params['order_by'])) {
276
-            $query_params['order_by']['DTT_order'] = 'ASC';
277
-        }
278
-        return $this->get_many_related('Datetime', $query_params);
279
-    }
280
-
281
-
282
-    /**
283
-     * This returns the chronologically last datetime that this ticket is associated with
284
-     *
285
-     * @return EE_Datetime
286
-     * @throws \EE_Error
287
-     */
288
-    public function last_datetime()
289
-    {
290
-        $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
291
-        return end($datetimes);
292
-    }
293
-
294
-
295
-    /**
296
-     * This returns the total tickets sold depending on the given parameters.
297
-     *
298
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
299
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
300
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
301
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
302
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
303
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
304
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
305
-     * @return mixed (array|int)          how many tickets have sold
306
-     * @throws \EE_Error
307
-     */
308
-    public function tickets_sold($what = 'ticket', $dtt_id = null)
309
-    {
310
-        $total = 0;
311
-        $tickets_sold = $this->_all_tickets_sold();
312
-        switch ($what) {
313
-            case 'ticket':
314
-                return $tickets_sold['ticket'];
315
-                break;
316
-            case 'datetime':
317
-                if (empty($tickets_sold['datetime'])) {
318
-                    return $total;
319
-                }
320
-                if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
321
-                    EE_Error::add_error(
322
-                        __(
323
-                            'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?',
324
-                            'event_espresso'
325
-                        ),
326
-                        __FILE__,
327
-                        __FUNCTION__,
328
-                        __LINE__
329
-                    );
330
-                    return $total;
331
-                }
332
-                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
333
-                break;
334
-            default:
335
-                return $total;
336
-        }
337
-    }
338
-
339
-
340
-    /**
341
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
342
-     *
343
-     * @return EE_Ticket[]
344
-     * @throws \EE_Error
345
-     */
346
-    protected function _all_tickets_sold()
347
-    {
348
-        $datetimes = $this->get_many_related('Datetime');
349
-        $tickets_sold = array();
350
-        if (! empty($datetimes)) {
351
-            foreach ($datetimes as $datetime) {
352
-                $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
353
-            }
354
-        }
355
-        // Tickets sold
356
-        $tickets_sold['ticket'] = $this->sold();
357
-        return $tickets_sold;
358
-    }
359
-
360
-
361
-    /**
362
-     * This returns the base price object for the ticket.
363
-     *
364
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
365
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
366
-     * @throws \EE_Error
367
-     */
368
-    public function base_price($return_array = false)
369
-    {
370
-        $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
371
-        return $return_array
372
-            ? $this->get_many_related('Price', array($_where))
373
-            : $this->get_first_related('Price', array($_where));
374
-    }
375
-
376
-
377
-    /**
378
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
379
-     *
380
-     * @access public
381
-     * @return EE_Price[]
382
-     * @throws \EE_Error
383
-     */
384
-    public function price_modifiers()
385
-    {
386
-        $query_params = array(
387
-            0 => array(
388
-                'Price_Type.PBT_ID' => array(
389
-                    'NOT IN',
390
-                    array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax),
391
-                ),
392
-            ),
393
-        );
394
-        return $this->prices($query_params);
395
-    }
396
-
397
-
398
-    /**
399
-     * Gets all the prices that combine to form the final price of this ticket
400
-     *
401
-     * @param array $query_params like EEM_Base::get_all
402
-     * @return EE_Price[]|EE_Base_Class[]
403
-     * @throws \EE_Error
404
-     */
405
-    public function prices($query_params = array())
406
-    {
407
-        return $this->get_many_related('Price', $query_params);
408
-    }
409
-
410
-
411
-    /**
412
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
413
-     *
414
-     * @param array $query_params see EEM_Base::get_all()
415
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
416
-     * @throws \EE_Error
417
-     */
418
-    public function datetime_tickets($query_params = array())
419
-    {
420
-        return $this->get_many_related('Datetime_Ticket', $query_params);
421
-    }
422
-
423
-
424
-    /**
425
-     * Gets all the datetimes from the db ordered by DTT_order
426
-     *
427
-     * @param boolean $show_expired
428
-     * @param boolean $show_deleted
429
-     * @return EE_Datetime[]
430
-     * @throws \EE_Error
431
-     */
432
-    public function datetimes_ordered($show_expired = true, $show_deleted = false)
433
-    {
434
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
435
-            $this->ID(),
436
-            $show_expired,
437
-            $show_deleted
438
-        );
439
-    }
440
-
441
-
442
-    /**
443
-     * Gets ID
444
-     *
445
-     * @return string
446
-     * @throws \EE_Error
447
-     */
448
-    public function ID()
449
-    {
450
-        return $this->get('TKT_ID');
451
-    }
452
-
453
-
454
-    /**
455
-     * get the author of the ticket.
456
-     *
457
-     * @since 4.5.0
458
-     * @return int
459
-     * @throws \EE_Error
460
-     */
461
-    public function wp_user()
462
-    {
463
-        return $this->get('TKT_wp_user');
464
-    }
465
-
466
-
467
-    /**
468
-     * Gets the template for the ticket
469
-     *
470
-     * @return EE_Ticket_Template|EE_Base_Class
471
-     * @throws \EE_Error
472
-     */
473
-    public function template()
474
-    {
475
-        return $this->get_first_related('Ticket_Template');
476
-    }
477
-
478
-
479
-    /**
480
-     * Simply returns an array of EE_Price objects that are taxes.
481
-     *
482
-     * @return EE_Price[]
483
-     * @throws \EE_Error
484
-     */
485
-    public function get_ticket_taxes_for_admin()
486
-    {
487
-        return EE_Taxes::get_taxes_for_admin();
488
-    }
489
-
490
-
491
-    /**
492
-     * @return float
493
-     * @throws \EE_Error
494
-     */
495
-    public function ticket_price()
496
-    {
497
-        return $this->get('TKT_price');
498
-    }
499
-
500
-
501
-    /**
502
-     * @return mixed
503
-     * @throws \EE_Error
504
-     */
505
-    public function pretty_price()
506
-    {
507
-        return $this->get_pretty('TKT_price');
508
-    }
509
-
510
-
511
-    /**
512
-     * @return bool
513
-     * @throws \EE_Error
514
-     */
515
-    public function is_free()
516
-    {
517
-        return $this->get_ticket_total_with_taxes() === (float) 0;
518
-    }
519
-
520
-
521
-    /**
522
-     * get_ticket_total_with_taxes
523
-     *
524
-     * @param bool $no_cache
525
-     * @return float
526
-     * @throws \EE_Error
527
-     */
528
-    public function get_ticket_total_with_taxes($no_cache = false)
529
-    {
530
-        if ($this->_ticket_total_with_taxes === null || $no_cache) {
531
-            $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
532
-        }
533
-        return (float) $this->_ticket_total_with_taxes;
534
-    }
535
-
536
-
537
-    public function ensure_TKT_Price_correct()
538
-    {
539
-        $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
540
-        $this->save();
541
-    }
542
-
543
-
544
-    /**
545
-     * @return float
546
-     * @throws \EE_Error
547
-     */
548
-    public function get_ticket_subtotal()
549
-    {
550
-        return EE_Taxes::get_subtotal_for_admin($this);
551
-    }
552
-
553
-
554
-    /**
555
-     * Returns the total taxes applied to this ticket
556
-     *
557
-     * @return float
558
-     * @throws \EE_Error
559
-     */
560
-    public function get_ticket_taxes_total_for_admin()
561
-    {
562
-        return EE_Taxes::get_total_taxes_for_admin($this);
563
-    }
564
-
565
-
566
-    /**
567
-     * Sets name
568
-     *
569
-     * @param string $name
570
-     * @throws \EE_Error
571
-     */
572
-    public function set_name($name)
573
-    {
574
-        $this->set('TKT_name', $name);
575
-    }
576
-
577
-
578
-    /**
579
-     * Gets description
580
-     *
581
-     * @return string
582
-     * @throws \EE_Error
583
-     */
584
-    public function description()
585
-    {
586
-        return $this->get('TKT_description');
587
-    }
588
-
589
-
590
-    /**
591
-     * Sets description
592
-     *
593
-     * @param string $description
594
-     * @throws \EE_Error
595
-     */
596
-    public function set_description($description)
597
-    {
598
-        $this->set('TKT_description', $description);
599
-    }
600
-
601
-
602
-    /**
603
-     * Gets start_date
604
-     *
605
-     * @param string $dt_frmt
606
-     * @param string $tm_frmt
607
-     * @return string
608
-     * @throws \EE_Error
609
-     */
610
-    public function start_date($dt_frmt = '', $tm_frmt = '')
611
-    {
612
-        return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
613
-    }
614
-
615
-
616
-    /**
617
-     * Sets start_date
618
-     *
619
-     * @param string $start_date
620
-     * @return void
621
-     * @throws \EE_Error
622
-     */
623
-    public function set_start_date($start_date)
624
-    {
625
-        $this->_set_date_time('B', $start_date, 'TKT_start_date');
626
-    }
627
-
628
-
629
-    /**
630
-     * Gets end_date
631
-     *
632
-     * @param string $dt_frmt
633
-     * @param string $tm_frmt
634
-     * @return string
635
-     * @throws \EE_Error
636
-     */
637
-    public function end_date($dt_frmt = '', $tm_frmt = '')
638
-    {
639
-        return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
640
-    }
641
-
642
-
643
-    /**
644
-     * Sets end_date
645
-     *
646
-     * @param string $end_date
647
-     * @return void
648
-     * @throws \EE_Error
649
-     */
650
-    public function set_end_date($end_date)
651
-    {
652
-        $this->_set_date_time('B', $end_date, 'TKT_end_date');
653
-    }
654
-
655
-
656
-    /**
657
-     * Sets sell until time
658
-     *
659
-     * @since 4.5.0
660
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
661
-     * @throws \EE_Error
662
-     */
663
-    public function set_end_time($time)
664
-    {
665
-        $this->_set_time_for($time, 'TKT_end_date');
666
-    }
667
-
668
-
669
-    /**
670
-     * Sets min
671
-     *
672
-     * @param int $min
673
-     * @return void
674
-     * @throws \EE_Error
675
-     */
676
-    public function set_min($min)
677
-    {
678
-        $this->set('TKT_min', $min);
679
-    }
680
-
681
-
682
-    /**
683
-     * Gets max
684
-     *
685
-     * @return int
686
-     * @throws \EE_Error
687
-     */
688
-    public function max()
689
-    {
690
-        return $this->get('TKT_max');
691
-    }
692
-
693
-
694
-    /**
695
-     * Sets max
696
-     *
697
-     * @param int $max
698
-     * @return void
699
-     * @throws \EE_Error
700
-     */
701
-    public function set_max($max)
702
-    {
703
-        $this->set('TKT_max', $max);
704
-    }
705
-
706
-
707
-    /**
708
-     * Sets price
709
-     *
710
-     * @param float $price
711
-     * @return void
712
-     * @throws \EE_Error
713
-     */
714
-    public function set_price($price)
715
-    {
716
-        $this->set('TKT_price', $price);
717
-    }
718
-
719
-
720
-    /**
721
-     * Gets sold
722
-     *
723
-     * @return int
724
-     * @throws \EE_Error
725
-     */
726
-    public function sold()
727
-    {
728
-        return $this->get_raw('TKT_sold');
729
-    }
730
-
731
-
732
-    /**
733
-     * Sets sold
734
-     *
735
-     * @param int $sold
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
739
-    public function set_sold($sold)
740
-    {
741
-        // sold can not go below zero
742
-        $sold = max(0, $sold);
743
-        $this->set('TKT_sold', $sold);
744
-    }
745
-
746
-
747
-    /**
748
-     * increments sold by amount passed by $qty
749
-     *
750
-     * @param int $qty
751
-     * @return void
752
-     * @throws \EE_Error
753
-     */
754
-    public function increase_sold($qty = 1)
755
-    {
756
-        $sold = $this->sold() + $qty;
757
-        // remove ticket reservation, but don't adjust datetime reservations,  because that will happen
758
-        // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
759
-        $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')');
760
-        $this->_increase_sold_for_datetimes($qty);
761
-        $this->set_sold($sold);
762
-        do_action(
763
-            'AHEE__EE_Ticket__increase_sold',
764
-            $this,
765
-            $qty,
766
-            $sold
767
-        );
768
-    }
769
-
770
-
771
-    /**
772
-     * Increases sold on related datetimes
773
-     *
774
-     * @param int $qty
775
-     * @return void
776
-     * @throws \EE_Error
777
-     */
778
-    protected function _increase_sold_for_datetimes($qty = 1)
779
-    {
780
-        $datetimes = $this->datetimes();
781
-        if (is_array($datetimes)) {
782
-            foreach ($datetimes as $datetime) {
783
-                if ($datetime instanceof EE_Datetime) {
784
-                    $datetime->increase_sold($qty);
785
-                    $datetime->save();
786
-                }
787
-            }
788
-        }
789
-    }
790
-
791
-
792
-    /**
793
-     * decrements (subtracts) sold by amount passed by $qty
794
-     *
795
-     * @param int $qty
796
-     * @return void
797
-     * @throws \EE_Error
798
-     */
799
-    public function decrease_sold($qty = 1)
800
-    {
801
-        $sold = $this->sold() - $qty;
802
-        $this->_decrease_sold_for_datetimes($qty);
803
-        $this->set_sold($sold);
804
-        do_action(
805
-            'AHEE__EE_Ticket__decrease_sold',
806
-            $this,
807
-            $qty,
808
-            $sold
809
-        );
810
-    }
811
-
812
-
813
-    /**
814
-     * Decreases sold on related datetimes
815
-     *
816
-     * @param int $qty
817
-     * @return void
818
-     * @throws \EE_Error
819
-     */
820
-    protected function _decrease_sold_for_datetimes($qty = 1)
821
-    {
822
-        $datetimes = $this->datetimes();
823
-        if (is_array($datetimes)) {
824
-            foreach ($datetimes as $datetime) {
825
-                if ($datetime instanceof EE_Datetime) {
826
-                    $datetime->decrease_sold($qty);
827
-                    $datetime->save();
828
-                }
829
-            }
830
-        }
831
-    }
832
-
833
-
834
-    /**
835
-     * Gets qty of reserved tickets
836
-     *
837
-     * @return int
838
-     * @throws \EE_Error
839
-     */
840
-    public function reserved()
841
-    {
842
-        return $this->get_raw('TKT_reserved');
843
-    }
844
-
845
-
846
-    /**
847
-     * Sets reserved
848
-     *
849
-     * @param int $reserved
850
-     * @return void
851
-     * @throws \EE_Error
852
-     */
853
-    public function set_reserved($reserved)
854
-    {
855
-        // reserved can not go below zero
856
-        $reserved = max(0, (int) $reserved);
857
-        $this->set('TKT_reserved', $reserved);
858
-    }
859
-
860
-
861
-    /**
862
-     * increments reserved by amount passed by $qty
863
-     *
864
-     * @param int    $qty
865
-     * @param string $source
866
-     * @return void
867
-     * @throws EE_Error
868
-     * @throws InvalidArgumentException
869
-     * @throws ReflectionException
870
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
871
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
872
-     */
873
-    public function increase_reserved($qty = 1, $source = 'unknown')
874
-    {
875
-        $qty = absint($qty);
876
-        $reserved = $this->reserved() + $qty;
877
-        if ($reserved
878
-            && $this->add_extra_meta(
879
-                EE_Ticket::META_KEY_TICKET_RESERVATIONS,
880
-                "{$qty} from {$source}"
881
-            )
882
-        ) {
883
-            $this->_increase_reserved_for_datetimes($qty);
884
-            $this->set_reserved($reserved);
885
-            do_action(
886
-                'AHEE__EE_Ticket__increase_reserved',
887
-                $this,
888
-                $qty,
889
-                $reserved
890
-            );
891
-        }
892
-    }
893
-
894
-
895
-    /**
896
-     * Increases sold on related datetimes
897
-     *
898
-     * @param int $qty
899
-     * @return void
900
-     * @throws \EE_Error
901
-     */
902
-    protected function _increase_reserved_for_datetimes($qty = 1)
903
-    {
904
-        $datetimes = $this->datetimes();
905
-        if (is_array($datetimes)) {
906
-            foreach ($datetimes as $datetime) {
907
-                if ($datetime instanceof EE_Datetime) {
908
-                    $datetime->increase_reserved($qty);
909
-                    $datetime->save();
910
-                }
911
-            }
912
-        }
913
-    }
914
-
915
-
916
-    /**
917
-     * decrements (subtracts) reserved by amount passed by $qty
918
-     *
919
-     * @param int    $qty
920
-     * @param bool   $adjust_datetimes
921
-     * @param string $source
922
-     * @return void
923
-     * @throws EE_Error
924
-     * @throws InvalidArgumentException
925
-     * @throws ReflectionException
926
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
927
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
928
-     */
929
-    public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
930
-    {
931
-        $reserved = $this->reserved() - absint($qty);
932
-        if ($this->add_extra_meta(
933
-            EE_Ticket::META_KEY_TICKET_RESERVATIONS,
934
-            "-{$qty} from {$source}"
935
-        )) {
936
-            if ($adjust_datetimes) {
937
-                $this->_decrease_reserved_for_datetimes($qty);
938
-            }
939
-            $this->set_reserved($reserved);
940
-            do_action(
941
-                'AHEE__EE_Ticket__decrease_reserved',
942
-                $this,
943
-                $qty,
944
-                $reserved
945
-            );
946
-        }
947
-    }
948
-
949
-
950
-    /**
951
-     * Increases sold on related datetimes
952
-     *
953
-     * @param int $qty
954
-     * @return void
955
-     * @throws \EE_Error
956
-     */
957
-    protected function _decrease_reserved_for_datetimes($qty = 1)
958
-    {
959
-        $datetimes = $this->datetimes();
960
-        if (is_array($datetimes)) {
961
-            foreach ($datetimes as $datetime) {
962
-                if ($datetime instanceof EE_Datetime) {
963
-                    $datetime->decrease_reserved($qty);
964
-                    $datetime->save();
965
-                }
966
-            }
967
-        }
968
-    }
969
-
970
-
971
-    /**
972
-     * Gets ticket quantity
973
-     *
974
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
975
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
976
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
977
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
978
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
979
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
980
-     * @return int
981
-     * @throws \EE_Error
982
-     */
983
-    public function qty($context = '')
984
-    {
985
-        switch ($context) {
986
-            case 'reg_limit':
987
-                return $this->real_quantity_on_ticket();
988
-            case 'saleable':
989
-                return $this->real_quantity_on_ticket('saleable');
990
-            default:
991
-                return $this->get_raw('TKT_qty');
992
-        }
993
-    }
994
-
995
-
996
-    /**
997
-     * Gets ticket quantity
998
-     *
999
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1000
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1001
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1002
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1003
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
1004
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
1005
-     *                            set to 0 for all related datetimes
1006
-     * @return int
1007
-     * @throws \EE_Error
1008
-     */
1009
-    public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1010
-    {
1011
-        $raw = $this->get_raw('TKT_qty');
1012
-        // return immediately if it's zero
1013
-        if ($raw === 0) {
1014
-            return $raw;
1015
-        }
1016
-        // echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1017
-        // ensure qty doesn't exceed raw value for THIS ticket
1018
-        $qty = min(EE_INF, $raw);
1019
-        // echo "\n . qty: " . $qty . '<br />';
1020
-        // calculate this ticket's total sales and reservations
1021
-        $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1022
-        // echo "\n . sold: " . $this->sold() . '<br />';
1023
-        // echo "\n . reserved: " . $this->reserved() . '<br />';
1024
-        // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1025
-        // first we need to calculate the maximum number of tickets available for the datetime
1026
-        // do we want data for one datetime or all of them ?
1027
-        $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
1028
-        $datetimes = $this->datetimes($query_params);
1029
-        if (is_array($datetimes) && ! empty($datetimes)) {
1030
-            foreach ($datetimes as $datetime) {
1031
-                if ($datetime instanceof EE_Datetime) {
1032
-                    $datetime->refresh_from_db();
1033
-                    // echo "\n . . datetime name: " . $datetime->name() . '<br />';
1034
-                    // echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1035
-                    // initialize with no restrictions for each datetime
1036
-                    // but adjust datetime qty based on datetime reg limit
1037
-                    $datetime_qty = min(EE_INF, $datetime->reg_limit());
1038
-                    // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1039
-                    // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1040
-                    // if we want the actual saleable amount, then we need to consider OTHER ticket sales
1041
-                    // and reservations for this datetime, that do NOT include sales and reservations
1042
-                    // for this ticket (so we add $this->sold() and $this->reserved() back in)
1043
-                    if ($context === 'saleable') {
1044
-                        $datetime_qty = max(
1045
-                            $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1046
-                            0
1047
-                        );
1048
-                        // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1049
-                        // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1050
-                        // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1051
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1052
-                        $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1053
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1054
-                    }
1055
-                    $qty = min($datetime_qty, $qty);
1056
-                    // echo "\n . . qty: " . $qty . '<br />';
1057
-                }
1058
-            }
1059
-        }
1060
-        // NOW that we know the  maximum number of tickets available for the datetime
1061
-        // we can finally factor in the details for this specific ticket
1062
-        if ($qty > 0 && $context === 'saleable') {
1063
-            // and subtract the sales for THIS ticket
1064
-            $qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1065
-            // echo "\n . qty: " . $qty . '<br />';
1066
-        }
1067
-        // echo "\nFINAL QTY: " . $qty . "<br /><br />";
1068
-        return $qty;
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1074
-     *
1075
-     * @param int $qty
1076
-     * @return void
1077
-     * @throws \EE_Error
1078
-     */
1079
-    public function set_qty($qty)
1080
-    {
1081
-        $datetimes = $this->datetimes();
1082
-        foreach ($datetimes as $datetime) {
1083
-            if ($datetime instanceof EE_Datetime) {
1084
-                $qty = min($qty, $datetime->reg_limit());
1085
-            }
1086
-        }
1087
-        $this->set('TKT_qty', $qty);
1088
-    }
1089
-
1090
-
1091
-    /**
1092
-     * Gets uses
1093
-     *
1094
-     * @return int
1095
-     * @throws \EE_Error
1096
-     */
1097
-    public function uses()
1098
-    {
1099
-        return $this->get('TKT_uses');
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * Sets uses
1105
-     *
1106
-     * @param int $uses
1107
-     * @return void
1108
-     * @throws \EE_Error
1109
-     */
1110
-    public function set_uses($uses)
1111
-    {
1112
-        $this->set('TKT_uses', $uses);
1113
-    }
1114
-
1115
-
1116
-    /**
1117
-     * returns whether ticket is required or not.
1118
-     *
1119
-     * @return boolean
1120
-     * @throws \EE_Error
1121
-     */
1122
-    public function required()
1123
-    {
1124
-        return $this->get('TKT_required');
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * sets the TKT_required property
1130
-     *
1131
-     * @param boolean $required
1132
-     * @return void
1133
-     * @throws \EE_Error
1134
-     */
1135
-    public function set_required($required)
1136
-    {
1137
-        $this->set('TKT_required', $required);
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * Gets taxable
1143
-     *
1144
-     * @return boolean
1145
-     * @throws \EE_Error
1146
-     */
1147
-    public function taxable()
1148
-    {
1149
-        return $this->get('TKT_taxable');
1150
-    }
1151
-
1152
-
1153
-    /**
1154
-     * Sets taxable
1155
-     *
1156
-     * @param boolean $taxable
1157
-     * @return void
1158
-     * @throws \EE_Error
1159
-     */
1160
-    public function set_taxable($taxable)
1161
-    {
1162
-        $this->set('TKT_taxable', $taxable);
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * Gets is_default
1168
-     *
1169
-     * @return boolean
1170
-     * @throws \EE_Error
1171
-     */
1172
-    public function is_default()
1173
-    {
1174
-        return $this->get('TKT_is_default');
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Sets is_default
1180
-     *
1181
-     * @param boolean $is_default
1182
-     * @return void
1183
-     * @throws \EE_Error
1184
-     */
1185
-    public function set_is_default($is_default)
1186
-    {
1187
-        $this->set('TKT_is_default', $is_default);
1188
-    }
1189
-
1190
-
1191
-    /**
1192
-     * Gets order
1193
-     *
1194
-     * @return int
1195
-     * @throws \EE_Error
1196
-     */
1197
-    public function order()
1198
-    {
1199
-        return $this->get('TKT_order');
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * Sets order
1205
-     *
1206
-     * @param int $order
1207
-     * @return void
1208
-     * @throws \EE_Error
1209
-     */
1210
-    public function set_order($order)
1211
-    {
1212
-        $this->set('TKT_order', $order);
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * Gets row
1218
-     *
1219
-     * @return int
1220
-     * @throws \EE_Error
1221
-     */
1222
-    public function row()
1223
-    {
1224
-        return $this->get('TKT_row');
1225
-    }
1226
-
1227
-
1228
-    /**
1229
-     * Sets row
1230
-     *
1231
-     * @param int $row
1232
-     * @return void
1233
-     * @throws \EE_Error
1234
-     */
1235
-    public function set_row($row)
1236
-    {
1237
-        $this->set('TKT_row', $row);
1238
-    }
1239
-
1240
-
1241
-    /**
1242
-     * Gets deleted
1243
-     *
1244
-     * @return boolean
1245
-     * @throws \EE_Error
1246
-     */
1247
-    public function deleted()
1248
-    {
1249
-        return $this->get('TKT_deleted');
1250
-    }
1251
-
1252
-
1253
-    /**
1254
-     * Sets deleted
1255
-     *
1256
-     * @param boolean $deleted
1257
-     * @return void
1258
-     * @throws \EE_Error
1259
-     */
1260
-    public function set_deleted($deleted)
1261
-    {
1262
-        $this->set('TKT_deleted', $deleted);
1263
-    }
1264
-
1265
-
1266
-    /**
1267
-     * Gets parent
1268
-     *
1269
-     * @return int
1270
-     * @throws \EE_Error
1271
-     */
1272
-    public function parent_ID()
1273
-    {
1274
-        return $this->get('TKT_parent');
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     * Sets parent
1280
-     *
1281
-     * @param int $parent
1282
-     * @return void
1283
-     * @throws \EE_Error
1284
-     */
1285
-    public function set_parent_ID($parent)
1286
-    {
1287
-        $this->set('TKT_parent', $parent);
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1293
-     *
1294
-     * @return string
1295
-     * @throws \EE_Error
1296
-     */
1297
-    public function name_and_info()
1298
-    {
1299
-        $times = array();
1300
-        foreach ($this->datetimes() as $datetime) {
1301
-            $times[] = $datetime->start_date_and_time();
1302
-        }
1303
-        return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * Gets name
1309
-     *
1310
-     * @return string
1311
-     * @throws \EE_Error
1312
-     */
1313
-    public function name()
1314
-    {
1315
-        return $this->get('TKT_name');
1316
-    }
1317
-
1318
-
1319
-    /**
1320
-     * Gets price
1321
-     *
1322
-     * @return float
1323
-     * @throws \EE_Error
1324
-     */
1325
-    public function price()
1326
-    {
1327
-        return $this->get('TKT_price');
1328
-    }
1329
-
1330
-
1331
-    /**
1332
-     * Gets all the registrations for this ticket
1333
-     *
1334
-     * @param array $query_params like EEM_Base::get_all's
1335
-     * @return EE_Registration[]|EE_Base_Class[]
1336
-     * @throws \EE_Error
1337
-     */
1338
-    public function registrations($query_params = array())
1339
-    {
1340
-        return $this->get_many_related('Registration', $query_params);
1341
-    }
1342
-
1343
-
1344
-    /**
1345
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1346
-     * into account
1347
-     *
1348
-     * @return int
1349
-     * @throws \EE_Error
1350
-     */
1351
-    public function update_tickets_sold()
1352
-    {
1353
-        $count_regs_for_this_ticket = $this->count_registrations(
1354
-            array(
1355
-                array(
1356
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1357
-                    'REG_deleted' => 0,
1358
-                ),
1359
-            )
1360
-        );
1361
-        $sold = $this->sold();
1362
-        if ($count_regs_for_this_ticket > $sold) {
1363
-            $this->increase_sold($count_regs_for_this_ticket - $sold);
1364
-            $this->save();
1365
-        } elseif ($count_regs_for_this_ticket < $sold) {
1366
-            $this->decrease_sold($count_regs_for_this_ticket - $sold);
1367
-            $this->save();
1368
-        }
1369
-        return $count_regs_for_this_ticket;
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * Counts the registrations for this ticket
1375
-     *
1376
-     * @param array $query_params like EEM_Base::get_all's
1377
-     * @return int
1378
-     */
1379
-    public function count_registrations($query_params = array())
1380
-    {
1381
-        return $this->count_related('Registration', $query_params);
1382
-    }
1383
-
1384
-
1385
-    /**
1386
-     * Implementation for EEI_Has_Icon interface method.
1387
-     *
1388
-     * @see EEI_Visual_Representation for comments
1389
-     * @return string
1390
-     */
1391
-    public function get_icon()
1392
-    {
1393
-        return '<span class="dashicons dashicons-tickets-alt"></span>';
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * Implementation of the EEI_Event_Relation interface method
1399
-     *
1400
-     * @see EEI_Event_Relation for comments
1401
-     * @return EE_Event
1402
-     * @throws \EE_Error
1403
-     * @throws UnexpectedEntityException
1404
-     */
1405
-    public function get_related_event()
1406
-    {
1407
-        // get one datetime to use for getting the event
1408
-        $datetime = $this->first_datetime();
1409
-        if (! $datetime instanceof \EE_Datetime) {
1410
-            throw new UnexpectedEntityException(
1411
-                $datetime,
1412
-                'EE_Datetime',
1413
-                sprintf(
1414
-                    __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1415
-                    $this->name()
1416
-                )
1417
-            );
1418
-        }
1419
-        $event = $datetime->event();
1420
-        if (! $event instanceof \EE_Event) {
1421
-            throw new UnexpectedEntityException(
1422
-                $event,
1423
-                'EE_Event',
1424
-                sprintf(
1425
-                    __('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1426
-                    $this->name()
1427
-                )
1428
-            );
1429
-        }
1430
-        return $event;
1431
-    }
1432
-
1433
-
1434
-    /**
1435
-     * Implementation of the EEI_Event_Relation interface method
1436
-     *
1437
-     * @see EEI_Event_Relation for comments
1438
-     * @return string
1439
-     * @throws UnexpectedEntityException
1440
-     * @throws \EE_Error
1441
-     */
1442
-    public function get_event_name()
1443
-    {
1444
-        $event = $this->get_related_event();
1445
-        return $event instanceof EE_Event ? $event->name() : '';
1446
-    }
1447
-
1448
-
1449
-    /**
1450
-     * Implementation of the EEI_Event_Relation interface method
1451
-     *
1452
-     * @see EEI_Event_Relation for comments
1453
-     * @return int
1454
-     * @throws UnexpectedEntityException
1455
-     * @throws \EE_Error
1456
-     */
1457
-    public function get_event_ID()
1458
-    {
1459
-        $event = $this->get_related_event();
1460
-        return $event instanceof EE_Event ? $event->ID() : 0;
1461
-    }
1462
-
1463
-
1464
-    /**
1465
-     * This simply returns whether a ticket can be permanently deleted or not.
1466
-     * The criteria for determining this is whether the ticket has any related registrations.
1467
-     * If there are none then it can be permanently deleted.
1468
-     *
1469
-     * @return bool
1470
-     */
1471
-    public function is_permanently_deleteable()
1472
-    {
1473
-        return $this->count_registrations() === 0;
1474
-    }
15
+	/**
16
+	 * The following constants are used by the ticket_status() method to indicate whether a ticket is on sale or not.
17
+	 */
18
+	const sold_out = 'TKS';
19
+
20
+	/**
21
+	 *
22
+	 */
23
+	const expired = 'TKE';
24
+
25
+	/**
26
+	 *
27
+	 */
28
+	const archived = 'TKA';
29
+
30
+	/**
31
+	 *
32
+	 */
33
+	const pending = 'TKP';
34
+
35
+	/**
36
+	 *
37
+	 */
38
+	const onsale = 'TKO';
39
+
40
+	/**
41
+	 * extra meta key for tracking ticket reservations
42
+	 *
43
+	 * @type string
44
+	 */
45
+	const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
46
+
47
+	/**
48
+	 * cached result from method of the same name
49
+	 *
50
+	 * @var float $_ticket_total_with_taxes
51
+	 */
52
+	private $_ticket_total_with_taxes;
53
+
54
+
55
+	/**
56
+	 * @param array  $props_n_values          incoming values
57
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
58
+	 *                                        used.)
59
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
60
+	 *                                        date_format and the second value is the time format
61
+	 * @return EE_Ticket
62
+	 * @throws \EE_Error
63
+	 */
64
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
65
+	{
66
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
67
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param array  $props_n_values  incoming values from the database
73
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
74
+	 *                                the website will be used.
75
+	 * @return EE_Ticket
76
+	 * @throws \EE_Error
77
+	 */
78
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
+	{
80
+		return new self($props_n_values, true, $timezone);
81
+	}
82
+
83
+
84
+	/**
85
+	 * @return bool
86
+	 * @throws \EE_Error
87
+	 */
88
+	public function parent()
89
+	{
90
+		return $this->get('TKT_parent');
91
+	}
92
+
93
+
94
+	/**
95
+	 * return if a ticket has quantities available for purchase
96
+	 *
97
+	 * @param  int $DTT_ID the primary key for a particular datetime
98
+	 * @return boolean
99
+	 * @throws \EE_Error
100
+	 */
101
+	public function available($DTT_ID = 0)
102
+	{
103
+		// are we checking availability for a particular datetime ?
104
+		if ($DTT_ID) {
105
+			// get that datetime object
106
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
107
+			// if  ticket sales for this datetime have exceeded the reg limit...
108
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
109
+				return false;
110
+			}
111
+		}
112
+		// datetime is still open for registration, but is this ticket sold out ?
113
+		return $this->qty() < 1 || $this->qty() > $this->sold() ? true : false;
114
+	}
115
+
116
+
117
+	/**
118
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
119
+	 *
120
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
121
+	 *                               relevant status const
122
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
123
+	 *               further processing
124
+	 * @return mixed status int if the display string isn't requested
125
+	 * @throws \EE_Error
126
+	 */
127
+	public function ticket_status($display = false, $remaining = null)
128
+	{
129
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
130
+		if (! $remaining) {
131
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
132
+		}
133
+		if ($this->get('TKT_deleted')) {
134
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
135
+		}
136
+		if ($this->is_expired()) {
137
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
138
+		}
139
+		if ($this->is_pending()) {
140
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
141
+		}
142
+		if ($this->is_on_sale()) {
143
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
144
+		}
145
+		return '';
146
+	}
147
+
148
+
149
+	/**
150
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
151
+	 * considering ALL the factors used for figuring that out.
152
+	 *
153
+	 * @access public
154
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
155
+	 * @return boolean         true = tickets remaining, false not.
156
+	 * @throws \EE_Error
157
+	 */
158
+	public function is_remaining($DTT_ID = 0)
159
+	{
160
+		$num_remaining = $this->remaining($DTT_ID);
161
+		if ($num_remaining === 0) {
162
+			return false;
163
+		}
164
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
165
+			return false;
166
+		}
167
+		return true;
168
+	}
169
+
170
+
171
+	/**
172
+	 * return the total number of tickets available for purchase
173
+	 *
174
+	 * @param  int $DTT_ID the primary key for a particular datetime.
175
+	 *                     set to 0 for all related datetimes
176
+	 * @return int
177
+	 * @throws \EE_Error
178
+	 */
179
+	public function remaining($DTT_ID = 0)
180
+	{
181
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Gets min
187
+	 *
188
+	 * @return int
189
+	 * @throws \EE_Error
190
+	 */
191
+	public function min()
192
+	{
193
+		return $this->get('TKT_min');
194
+	}
195
+
196
+
197
+	/**
198
+	 * return if a ticket is no longer available cause its available dates have expired.
199
+	 *
200
+	 * @return boolean
201
+	 * @throws \EE_Error
202
+	 */
203
+	public function is_expired()
204
+	{
205
+		return ($this->get_raw('TKT_end_date') < time());
206
+	}
207
+
208
+
209
+	/**
210
+	 * Return if a ticket is yet to go on sale or not
211
+	 *
212
+	 * @return boolean
213
+	 * @throws \EE_Error
214
+	 */
215
+	public function is_pending()
216
+	{
217
+		return ($this->get_raw('TKT_start_date') > time());
218
+	}
219
+
220
+
221
+	/**
222
+	 * Return if a ticket is on sale or not
223
+	 *
224
+	 * @return boolean
225
+	 * @throws \EE_Error
226
+	 */
227
+	public function is_on_sale()
228
+	{
229
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
230
+	}
231
+
232
+
233
+	/**
234
+	 * This returns the chronologically last datetime that this ticket is associated with
235
+	 *
236
+	 * @param string $dt_frmt
237
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
238
+	 *                            the end date ie: Jan 01 "to" Dec 31
239
+	 * @return string
240
+	 * @throws \EE_Error
241
+	 */
242
+	public function date_range($dt_frmt = '', $conjunction = ' - ')
243
+	{
244
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt)
245
+			: '';
246
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
247
+
248
+		return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
249
+	}
250
+
251
+
252
+	/**
253
+	 * This returns the chronologically first datetime that this ticket is associated with
254
+	 *
255
+	 * @return EE_Datetime
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function first_datetime()
259
+	{
260
+		$datetimes = $this->datetimes(array('limit' => 1));
261
+		return reset($datetimes);
262
+	}
263
+
264
+
265
+	/**
266
+	 * Gets all the datetimes this ticket can be used for attending.
267
+	 * Unless otherwise specified, orders datetimes by start date.
268
+	 *
269
+	 * @param array $query_params see EEM_Base::get_all()
270
+	 * @return EE_Datetime[]|EE_Base_Class[]
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function datetimes($query_params = array())
274
+	{
275
+		if (! isset($query_params['order_by'])) {
276
+			$query_params['order_by']['DTT_order'] = 'ASC';
277
+		}
278
+		return $this->get_many_related('Datetime', $query_params);
279
+	}
280
+
281
+
282
+	/**
283
+	 * This returns the chronologically last datetime that this ticket is associated with
284
+	 *
285
+	 * @return EE_Datetime
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function last_datetime()
289
+	{
290
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
291
+		return end($datetimes);
292
+	}
293
+
294
+
295
+	/**
296
+	 * This returns the total tickets sold depending on the given parameters.
297
+	 *
298
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
299
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
300
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
301
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
302
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
303
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
304
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
305
+	 * @return mixed (array|int)          how many tickets have sold
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function tickets_sold($what = 'ticket', $dtt_id = null)
309
+	{
310
+		$total = 0;
311
+		$tickets_sold = $this->_all_tickets_sold();
312
+		switch ($what) {
313
+			case 'ticket':
314
+				return $tickets_sold['ticket'];
315
+				break;
316
+			case 'datetime':
317
+				if (empty($tickets_sold['datetime'])) {
318
+					return $total;
319
+				}
320
+				if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
321
+					EE_Error::add_error(
322
+						__(
323
+							'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?',
324
+							'event_espresso'
325
+						),
326
+						__FILE__,
327
+						__FUNCTION__,
328
+						__LINE__
329
+					);
330
+					return $total;
331
+				}
332
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
333
+				break;
334
+			default:
335
+				return $total;
336
+		}
337
+	}
338
+
339
+
340
+	/**
341
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
342
+	 *
343
+	 * @return EE_Ticket[]
344
+	 * @throws \EE_Error
345
+	 */
346
+	protected function _all_tickets_sold()
347
+	{
348
+		$datetimes = $this->get_many_related('Datetime');
349
+		$tickets_sold = array();
350
+		if (! empty($datetimes)) {
351
+			foreach ($datetimes as $datetime) {
352
+				$tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
353
+			}
354
+		}
355
+		// Tickets sold
356
+		$tickets_sold['ticket'] = $this->sold();
357
+		return $tickets_sold;
358
+	}
359
+
360
+
361
+	/**
362
+	 * This returns the base price object for the ticket.
363
+	 *
364
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
365
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
366
+	 * @throws \EE_Error
367
+	 */
368
+	public function base_price($return_array = false)
369
+	{
370
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
371
+		return $return_array
372
+			? $this->get_many_related('Price', array($_where))
373
+			: $this->get_first_related('Price', array($_where));
374
+	}
375
+
376
+
377
+	/**
378
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
379
+	 *
380
+	 * @access public
381
+	 * @return EE_Price[]
382
+	 * @throws \EE_Error
383
+	 */
384
+	public function price_modifiers()
385
+	{
386
+		$query_params = array(
387
+			0 => array(
388
+				'Price_Type.PBT_ID' => array(
389
+					'NOT IN',
390
+					array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax),
391
+				),
392
+			),
393
+		);
394
+		return $this->prices($query_params);
395
+	}
396
+
397
+
398
+	/**
399
+	 * Gets all the prices that combine to form the final price of this ticket
400
+	 *
401
+	 * @param array $query_params like EEM_Base::get_all
402
+	 * @return EE_Price[]|EE_Base_Class[]
403
+	 * @throws \EE_Error
404
+	 */
405
+	public function prices($query_params = array())
406
+	{
407
+		return $this->get_many_related('Price', $query_params);
408
+	}
409
+
410
+
411
+	/**
412
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
413
+	 *
414
+	 * @param array $query_params see EEM_Base::get_all()
415
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
416
+	 * @throws \EE_Error
417
+	 */
418
+	public function datetime_tickets($query_params = array())
419
+	{
420
+		return $this->get_many_related('Datetime_Ticket', $query_params);
421
+	}
422
+
423
+
424
+	/**
425
+	 * Gets all the datetimes from the db ordered by DTT_order
426
+	 *
427
+	 * @param boolean $show_expired
428
+	 * @param boolean $show_deleted
429
+	 * @return EE_Datetime[]
430
+	 * @throws \EE_Error
431
+	 */
432
+	public function datetimes_ordered($show_expired = true, $show_deleted = false)
433
+	{
434
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
435
+			$this->ID(),
436
+			$show_expired,
437
+			$show_deleted
438
+		);
439
+	}
440
+
441
+
442
+	/**
443
+	 * Gets ID
444
+	 *
445
+	 * @return string
446
+	 * @throws \EE_Error
447
+	 */
448
+	public function ID()
449
+	{
450
+		return $this->get('TKT_ID');
451
+	}
452
+
453
+
454
+	/**
455
+	 * get the author of the ticket.
456
+	 *
457
+	 * @since 4.5.0
458
+	 * @return int
459
+	 * @throws \EE_Error
460
+	 */
461
+	public function wp_user()
462
+	{
463
+		return $this->get('TKT_wp_user');
464
+	}
465
+
466
+
467
+	/**
468
+	 * Gets the template for the ticket
469
+	 *
470
+	 * @return EE_Ticket_Template|EE_Base_Class
471
+	 * @throws \EE_Error
472
+	 */
473
+	public function template()
474
+	{
475
+		return $this->get_first_related('Ticket_Template');
476
+	}
477
+
478
+
479
+	/**
480
+	 * Simply returns an array of EE_Price objects that are taxes.
481
+	 *
482
+	 * @return EE_Price[]
483
+	 * @throws \EE_Error
484
+	 */
485
+	public function get_ticket_taxes_for_admin()
486
+	{
487
+		return EE_Taxes::get_taxes_for_admin();
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return float
493
+	 * @throws \EE_Error
494
+	 */
495
+	public function ticket_price()
496
+	{
497
+		return $this->get('TKT_price');
498
+	}
499
+
500
+
501
+	/**
502
+	 * @return mixed
503
+	 * @throws \EE_Error
504
+	 */
505
+	public function pretty_price()
506
+	{
507
+		return $this->get_pretty('TKT_price');
508
+	}
509
+
510
+
511
+	/**
512
+	 * @return bool
513
+	 * @throws \EE_Error
514
+	 */
515
+	public function is_free()
516
+	{
517
+		return $this->get_ticket_total_with_taxes() === (float) 0;
518
+	}
519
+
520
+
521
+	/**
522
+	 * get_ticket_total_with_taxes
523
+	 *
524
+	 * @param bool $no_cache
525
+	 * @return float
526
+	 * @throws \EE_Error
527
+	 */
528
+	public function get_ticket_total_with_taxes($no_cache = false)
529
+	{
530
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
531
+			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
532
+		}
533
+		return (float) $this->_ticket_total_with_taxes;
534
+	}
535
+
536
+
537
+	public function ensure_TKT_Price_correct()
538
+	{
539
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
540
+		$this->save();
541
+	}
542
+
543
+
544
+	/**
545
+	 * @return float
546
+	 * @throws \EE_Error
547
+	 */
548
+	public function get_ticket_subtotal()
549
+	{
550
+		return EE_Taxes::get_subtotal_for_admin($this);
551
+	}
552
+
553
+
554
+	/**
555
+	 * Returns the total taxes applied to this ticket
556
+	 *
557
+	 * @return float
558
+	 * @throws \EE_Error
559
+	 */
560
+	public function get_ticket_taxes_total_for_admin()
561
+	{
562
+		return EE_Taxes::get_total_taxes_for_admin($this);
563
+	}
564
+
565
+
566
+	/**
567
+	 * Sets name
568
+	 *
569
+	 * @param string $name
570
+	 * @throws \EE_Error
571
+	 */
572
+	public function set_name($name)
573
+	{
574
+		$this->set('TKT_name', $name);
575
+	}
576
+
577
+
578
+	/**
579
+	 * Gets description
580
+	 *
581
+	 * @return string
582
+	 * @throws \EE_Error
583
+	 */
584
+	public function description()
585
+	{
586
+		return $this->get('TKT_description');
587
+	}
588
+
589
+
590
+	/**
591
+	 * Sets description
592
+	 *
593
+	 * @param string $description
594
+	 * @throws \EE_Error
595
+	 */
596
+	public function set_description($description)
597
+	{
598
+		$this->set('TKT_description', $description);
599
+	}
600
+
601
+
602
+	/**
603
+	 * Gets start_date
604
+	 *
605
+	 * @param string $dt_frmt
606
+	 * @param string $tm_frmt
607
+	 * @return string
608
+	 * @throws \EE_Error
609
+	 */
610
+	public function start_date($dt_frmt = '', $tm_frmt = '')
611
+	{
612
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
613
+	}
614
+
615
+
616
+	/**
617
+	 * Sets start_date
618
+	 *
619
+	 * @param string $start_date
620
+	 * @return void
621
+	 * @throws \EE_Error
622
+	 */
623
+	public function set_start_date($start_date)
624
+	{
625
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
626
+	}
627
+
628
+
629
+	/**
630
+	 * Gets end_date
631
+	 *
632
+	 * @param string $dt_frmt
633
+	 * @param string $tm_frmt
634
+	 * @return string
635
+	 * @throws \EE_Error
636
+	 */
637
+	public function end_date($dt_frmt = '', $tm_frmt = '')
638
+	{
639
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
640
+	}
641
+
642
+
643
+	/**
644
+	 * Sets end_date
645
+	 *
646
+	 * @param string $end_date
647
+	 * @return void
648
+	 * @throws \EE_Error
649
+	 */
650
+	public function set_end_date($end_date)
651
+	{
652
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
653
+	}
654
+
655
+
656
+	/**
657
+	 * Sets sell until time
658
+	 *
659
+	 * @since 4.5.0
660
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
661
+	 * @throws \EE_Error
662
+	 */
663
+	public function set_end_time($time)
664
+	{
665
+		$this->_set_time_for($time, 'TKT_end_date');
666
+	}
667
+
668
+
669
+	/**
670
+	 * Sets min
671
+	 *
672
+	 * @param int $min
673
+	 * @return void
674
+	 * @throws \EE_Error
675
+	 */
676
+	public function set_min($min)
677
+	{
678
+		$this->set('TKT_min', $min);
679
+	}
680
+
681
+
682
+	/**
683
+	 * Gets max
684
+	 *
685
+	 * @return int
686
+	 * @throws \EE_Error
687
+	 */
688
+	public function max()
689
+	{
690
+		return $this->get('TKT_max');
691
+	}
692
+
693
+
694
+	/**
695
+	 * Sets max
696
+	 *
697
+	 * @param int $max
698
+	 * @return void
699
+	 * @throws \EE_Error
700
+	 */
701
+	public function set_max($max)
702
+	{
703
+		$this->set('TKT_max', $max);
704
+	}
705
+
706
+
707
+	/**
708
+	 * Sets price
709
+	 *
710
+	 * @param float $price
711
+	 * @return void
712
+	 * @throws \EE_Error
713
+	 */
714
+	public function set_price($price)
715
+	{
716
+		$this->set('TKT_price', $price);
717
+	}
718
+
719
+
720
+	/**
721
+	 * Gets sold
722
+	 *
723
+	 * @return int
724
+	 * @throws \EE_Error
725
+	 */
726
+	public function sold()
727
+	{
728
+		return $this->get_raw('TKT_sold');
729
+	}
730
+
731
+
732
+	/**
733
+	 * Sets sold
734
+	 *
735
+	 * @param int $sold
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739
+	public function set_sold($sold)
740
+	{
741
+		// sold can not go below zero
742
+		$sold = max(0, $sold);
743
+		$this->set('TKT_sold', $sold);
744
+	}
745
+
746
+
747
+	/**
748
+	 * increments sold by amount passed by $qty
749
+	 *
750
+	 * @param int $qty
751
+	 * @return void
752
+	 * @throws \EE_Error
753
+	 */
754
+	public function increase_sold($qty = 1)
755
+	{
756
+		$sold = $this->sold() + $qty;
757
+		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
758
+		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
759
+		$this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')');
760
+		$this->_increase_sold_for_datetimes($qty);
761
+		$this->set_sold($sold);
762
+		do_action(
763
+			'AHEE__EE_Ticket__increase_sold',
764
+			$this,
765
+			$qty,
766
+			$sold
767
+		);
768
+	}
769
+
770
+
771
+	/**
772
+	 * Increases sold on related datetimes
773
+	 *
774
+	 * @param int $qty
775
+	 * @return void
776
+	 * @throws \EE_Error
777
+	 */
778
+	protected function _increase_sold_for_datetimes($qty = 1)
779
+	{
780
+		$datetimes = $this->datetimes();
781
+		if (is_array($datetimes)) {
782
+			foreach ($datetimes as $datetime) {
783
+				if ($datetime instanceof EE_Datetime) {
784
+					$datetime->increase_sold($qty);
785
+					$datetime->save();
786
+				}
787
+			}
788
+		}
789
+	}
790
+
791
+
792
+	/**
793
+	 * decrements (subtracts) sold by amount passed by $qty
794
+	 *
795
+	 * @param int $qty
796
+	 * @return void
797
+	 * @throws \EE_Error
798
+	 */
799
+	public function decrease_sold($qty = 1)
800
+	{
801
+		$sold = $this->sold() - $qty;
802
+		$this->_decrease_sold_for_datetimes($qty);
803
+		$this->set_sold($sold);
804
+		do_action(
805
+			'AHEE__EE_Ticket__decrease_sold',
806
+			$this,
807
+			$qty,
808
+			$sold
809
+		);
810
+	}
811
+
812
+
813
+	/**
814
+	 * Decreases sold on related datetimes
815
+	 *
816
+	 * @param int $qty
817
+	 * @return void
818
+	 * @throws \EE_Error
819
+	 */
820
+	protected function _decrease_sold_for_datetimes($qty = 1)
821
+	{
822
+		$datetimes = $this->datetimes();
823
+		if (is_array($datetimes)) {
824
+			foreach ($datetimes as $datetime) {
825
+				if ($datetime instanceof EE_Datetime) {
826
+					$datetime->decrease_sold($qty);
827
+					$datetime->save();
828
+				}
829
+			}
830
+		}
831
+	}
832
+
833
+
834
+	/**
835
+	 * Gets qty of reserved tickets
836
+	 *
837
+	 * @return int
838
+	 * @throws \EE_Error
839
+	 */
840
+	public function reserved()
841
+	{
842
+		return $this->get_raw('TKT_reserved');
843
+	}
844
+
845
+
846
+	/**
847
+	 * Sets reserved
848
+	 *
849
+	 * @param int $reserved
850
+	 * @return void
851
+	 * @throws \EE_Error
852
+	 */
853
+	public function set_reserved($reserved)
854
+	{
855
+		// reserved can not go below zero
856
+		$reserved = max(0, (int) $reserved);
857
+		$this->set('TKT_reserved', $reserved);
858
+	}
859
+
860
+
861
+	/**
862
+	 * increments reserved by amount passed by $qty
863
+	 *
864
+	 * @param int    $qty
865
+	 * @param string $source
866
+	 * @return void
867
+	 * @throws EE_Error
868
+	 * @throws InvalidArgumentException
869
+	 * @throws ReflectionException
870
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
871
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
872
+	 */
873
+	public function increase_reserved($qty = 1, $source = 'unknown')
874
+	{
875
+		$qty = absint($qty);
876
+		$reserved = $this->reserved() + $qty;
877
+		if ($reserved
878
+			&& $this->add_extra_meta(
879
+				EE_Ticket::META_KEY_TICKET_RESERVATIONS,
880
+				"{$qty} from {$source}"
881
+			)
882
+		) {
883
+			$this->_increase_reserved_for_datetimes($qty);
884
+			$this->set_reserved($reserved);
885
+			do_action(
886
+				'AHEE__EE_Ticket__increase_reserved',
887
+				$this,
888
+				$qty,
889
+				$reserved
890
+			);
891
+		}
892
+	}
893
+
894
+
895
+	/**
896
+	 * Increases sold on related datetimes
897
+	 *
898
+	 * @param int $qty
899
+	 * @return void
900
+	 * @throws \EE_Error
901
+	 */
902
+	protected function _increase_reserved_for_datetimes($qty = 1)
903
+	{
904
+		$datetimes = $this->datetimes();
905
+		if (is_array($datetimes)) {
906
+			foreach ($datetimes as $datetime) {
907
+				if ($datetime instanceof EE_Datetime) {
908
+					$datetime->increase_reserved($qty);
909
+					$datetime->save();
910
+				}
911
+			}
912
+		}
913
+	}
914
+
915
+
916
+	/**
917
+	 * decrements (subtracts) reserved by amount passed by $qty
918
+	 *
919
+	 * @param int    $qty
920
+	 * @param bool   $adjust_datetimes
921
+	 * @param string $source
922
+	 * @return void
923
+	 * @throws EE_Error
924
+	 * @throws InvalidArgumentException
925
+	 * @throws ReflectionException
926
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
927
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
928
+	 */
929
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
930
+	{
931
+		$reserved = $this->reserved() - absint($qty);
932
+		if ($this->add_extra_meta(
933
+			EE_Ticket::META_KEY_TICKET_RESERVATIONS,
934
+			"-{$qty} from {$source}"
935
+		)) {
936
+			if ($adjust_datetimes) {
937
+				$this->_decrease_reserved_for_datetimes($qty);
938
+			}
939
+			$this->set_reserved($reserved);
940
+			do_action(
941
+				'AHEE__EE_Ticket__decrease_reserved',
942
+				$this,
943
+				$qty,
944
+				$reserved
945
+			);
946
+		}
947
+	}
948
+
949
+
950
+	/**
951
+	 * Increases sold on related datetimes
952
+	 *
953
+	 * @param int $qty
954
+	 * @return void
955
+	 * @throws \EE_Error
956
+	 */
957
+	protected function _decrease_reserved_for_datetimes($qty = 1)
958
+	{
959
+		$datetimes = $this->datetimes();
960
+		if (is_array($datetimes)) {
961
+			foreach ($datetimes as $datetime) {
962
+				if ($datetime instanceof EE_Datetime) {
963
+					$datetime->decrease_reserved($qty);
964
+					$datetime->save();
965
+				}
966
+			}
967
+		}
968
+	}
969
+
970
+
971
+	/**
972
+	 * Gets ticket quantity
973
+	 *
974
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
975
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
976
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
977
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
978
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
979
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
980
+	 * @return int
981
+	 * @throws \EE_Error
982
+	 */
983
+	public function qty($context = '')
984
+	{
985
+		switch ($context) {
986
+			case 'reg_limit':
987
+				return $this->real_quantity_on_ticket();
988
+			case 'saleable':
989
+				return $this->real_quantity_on_ticket('saleable');
990
+			default:
991
+				return $this->get_raw('TKT_qty');
992
+		}
993
+	}
994
+
995
+
996
+	/**
997
+	 * Gets ticket quantity
998
+	 *
999
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1000
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1001
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1002
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1003
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
1004
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
1005
+	 *                            set to 0 for all related datetimes
1006
+	 * @return int
1007
+	 * @throws \EE_Error
1008
+	 */
1009
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1010
+	{
1011
+		$raw = $this->get_raw('TKT_qty');
1012
+		// return immediately if it's zero
1013
+		if ($raw === 0) {
1014
+			return $raw;
1015
+		}
1016
+		// echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1017
+		// ensure qty doesn't exceed raw value for THIS ticket
1018
+		$qty = min(EE_INF, $raw);
1019
+		// echo "\n . qty: " . $qty . '<br />';
1020
+		// calculate this ticket's total sales and reservations
1021
+		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1022
+		// echo "\n . sold: " . $this->sold() . '<br />';
1023
+		// echo "\n . reserved: " . $this->reserved() . '<br />';
1024
+		// echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1025
+		// first we need to calculate the maximum number of tickets available for the datetime
1026
+		// do we want data for one datetime or all of them ?
1027
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
1028
+		$datetimes = $this->datetimes($query_params);
1029
+		if (is_array($datetimes) && ! empty($datetimes)) {
1030
+			foreach ($datetimes as $datetime) {
1031
+				if ($datetime instanceof EE_Datetime) {
1032
+					$datetime->refresh_from_db();
1033
+					// echo "\n . . datetime name: " . $datetime->name() . '<br />';
1034
+					// echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1035
+					// initialize with no restrictions for each datetime
1036
+					// but adjust datetime qty based on datetime reg limit
1037
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
1038
+					// echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1039
+					// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1040
+					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
1041
+					// and reservations for this datetime, that do NOT include sales and reservations
1042
+					// for this ticket (so we add $this->sold() and $this->reserved() back in)
1043
+					if ($context === 'saleable') {
1044
+						$datetime_qty = max(
1045
+							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1046
+							0
1047
+						);
1048
+						// echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1049
+						// echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1050
+						// echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1051
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1052
+						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1053
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1054
+					}
1055
+					$qty = min($datetime_qty, $qty);
1056
+					// echo "\n . . qty: " . $qty . '<br />';
1057
+				}
1058
+			}
1059
+		}
1060
+		// NOW that we know the  maximum number of tickets available for the datetime
1061
+		// we can finally factor in the details for this specific ticket
1062
+		if ($qty > 0 && $context === 'saleable') {
1063
+			// and subtract the sales for THIS ticket
1064
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1065
+			// echo "\n . qty: " . $qty . '<br />';
1066
+		}
1067
+		// echo "\nFINAL QTY: " . $qty . "<br /><br />";
1068
+		return $qty;
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1074
+	 *
1075
+	 * @param int $qty
1076
+	 * @return void
1077
+	 * @throws \EE_Error
1078
+	 */
1079
+	public function set_qty($qty)
1080
+	{
1081
+		$datetimes = $this->datetimes();
1082
+		foreach ($datetimes as $datetime) {
1083
+			if ($datetime instanceof EE_Datetime) {
1084
+				$qty = min($qty, $datetime->reg_limit());
1085
+			}
1086
+		}
1087
+		$this->set('TKT_qty', $qty);
1088
+	}
1089
+
1090
+
1091
+	/**
1092
+	 * Gets uses
1093
+	 *
1094
+	 * @return int
1095
+	 * @throws \EE_Error
1096
+	 */
1097
+	public function uses()
1098
+	{
1099
+		return $this->get('TKT_uses');
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * Sets uses
1105
+	 *
1106
+	 * @param int $uses
1107
+	 * @return void
1108
+	 * @throws \EE_Error
1109
+	 */
1110
+	public function set_uses($uses)
1111
+	{
1112
+		$this->set('TKT_uses', $uses);
1113
+	}
1114
+
1115
+
1116
+	/**
1117
+	 * returns whether ticket is required or not.
1118
+	 *
1119
+	 * @return boolean
1120
+	 * @throws \EE_Error
1121
+	 */
1122
+	public function required()
1123
+	{
1124
+		return $this->get('TKT_required');
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * sets the TKT_required property
1130
+	 *
1131
+	 * @param boolean $required
1132
+	 * @return void
1133
+	 * @throws \EE_Error
1134
+	 */
1135
+	public function set_required($required)
1136
+	{
1137
+		$this->set('TKT_required', $required);
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * Gets taxable
1143
+	 *
1144
+	 * @return boolean
1145
+	 * @throws \EE_Error
1146
+	 */
1147
+	public function taxable()
1148
+	{
1149
+		return $this->get('TKT_taxable');
1150
+	}
1151
+
1152
+
1153
+	/**
1154
+	 * Sets taxable
1155
+	 *
1156
+	 * @param boolean $taxable
1157
+	 * @return void
1158
+	 * @throws \EE_Error
1159
+	 */
1160
+	public function set_taxable($taxable)
1161
+	{
1162
+		$this->set('TKT_taxable', $taxable);
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * Gets is_default
1168
+	 *
1169
+	 * @return boolean
1170
+	 * @throws \EE_Error
1171
+	 */
1172
+	public function is_default()
1173
+	{
1174
+		return $this->get('TKT_is_default');
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Sets is_default
1180
+	 *
1181
+	 * @param boolean $is_default
1182
+	 * @return void
1183
+	 * @throws \EE_Error
1184
+	 */
1185
+	public function set_is_default($is_default)
1186
+	{
1187
+		$this->set('TKT_is_default', $is_default);
1188
+	}
1189
+
1190
+
1191
+	/**
1192
+	 * Gets order
1193
+	 *
1194
+	 * @return int
1195
+	 * @throws \EE_Error
1196
+	 */
1197
+	public function order()
1198
+	{
1199
+		return $this->get('TKT_order');
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * Sets order
1205
+	 *
1206
+	 * @param int $order
1207
+	 * @return void
1208
+	 * @throws \EE_Error
1209
+	 */
1210
+	public function set_order($order)
1211
+	{
1212
+		$this->set('TKT_order', $order);
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * Gets row
1218
+	 *
1219
+	 * @return int
1220
+	 * @throws \EE_Error
1221
+	 */
1222
+	public function row()
1223
+	{
1224
+		return $this->get('TKT_row');
1225
+	}
1226
+
1227
+
1228
+	/**
1229
+	 * Sets row
1230
+	 *
1231
+	 * @param int $row
1232
+	 * @return void
1233
+	 * @throws \EE_Error
1234
+	 */
1235
+	public function set_row($row)
1236
+	{
1237
+		$this->set('TKT_row', $row);
1238
+	}
1239
+
1240
+
1241
+	/**
1242
+	 * Gets deleted
1243
+	 *
1244
+	 * @return boolean
1245
+	 * @throws \EE_Error
1246
+	 */
1247
+	public function deleted()
1248
+	{
1249
+		return $this->get('TKT_deleted');
1250
+	}
1251
+
1252
+
1253
+	/**
1254
+	 * Sets deleted
1255
+	 *
1256
+	 * @param boolean $deleted
1257
+	 * @return void
1258
+	 * @throws \EE_Error
1259
+	 */
1260
+	public function set_deleted($deleted)
1261
+	{
1262
+		$this->set('TKT_deleted', $deleted);
1263
+	}
1264
+
1265
+
1266
+	/**
1267
+	 * Gets parent
1268
+	 *
1269
+	 * @return int
1270
+	 * @throws \EE_Error
1271
+	 */
1272
+	public function parent_ID()
1273
+	{
1274
+		return $this->get('TKT_parent');
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 * Sets parent
1280
+	 *
1281
+	 * @param int $parent
1282
+	 * @return void
1283
+	 * @throws \EE_Error
1284
+	 */
1285
+	public function set_parent_ID($parent)
1286
+	{
1287
+		$this->set('TKT_parent', $parent);
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1293
+	 *
1294
+	 * @return string
1295
+	 * @throws \EE_Error
1296
+	 */
1297
+	public function name_and_info()
1298
+	{
1299
+		$times = array();
1300
+		foreach ($this->datetimes() as $datetime) {
1301
+			$times[] = $datetime->start_date_and_time();
1302
+		}
1303
+		return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * Gets name
1309
+	 *
1310
+	 * @return string
1311
+	 * @throws \EE_Error
1312
+	 */
1313
+	public function name()
1314
+	{
1315
+		return $this->get('TKT_name');
1316
+	}
1317
+
1318
+
1319
+	/**
1320
+	 * Gets price
1321
+	 *
1322
+	 * @return float
1323
+	 * @throws \EE_Error
1324
+	 */
1325
+	public function price()
1326
+	{
1327
+		return $this->get('TKT_price');
1328
+	}
1329
+
1330
+
1331
+	/**
1332
+	 * Gets all the registrations for this ticket
1333
+	 *
1334
+	 * @param array $query_params like EEM_Base::get_all's
1335
+	 * @return EE_Registration[]|EE_Base_Class[]
1336
+	 * @throws \EE_Error
1337
+	 */
1338
+	public function registrations($query_params = array())
1339
+	{
1340
+		return $this->get_many_related('Registration', $query_params);
1341
+	}
1342
+
1343
+
1344
+	/**
1345
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1346
+	 * into account
1347
+	 *
1348
+	 * @return int
1349
+	 * @throws \EE_Error
1350
+	 */
1351
+	public function update_tickets_sold()
1352
+	{
1353
+		$count_regs_for_this_ticket = $this->count_registrations(
1354
+			array(
1355
+				array(
1356
+					'STS_ID'      => EEM_Registration::status_id_approved,
1357
+					'REG_deleted' => 0,
1358
+				),
1359
+			)
1360
+		);
1361
+		$sold = $this->sold();
1362
+		if ($count_regs_for_this_ticket > $sold) {
1363
+			$this->increase_sold($count_regs_for_this_ticket - $sold);
1364
+			$this->save();
1365
+		} elseif ($count_regs_for_this_ticket < $sold) {
1366
+			$this->decrease_sold($count_regs_for_this_ticket - $sold);
1367
+			$this->save();
1368
+		}
1369
+		return $count_regs_for_this_ticket;
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * Counts the registrations for this ticket
1375
+	 *
1376
+	 * @param array $query_params like EEM_Base::get_all's
1377
+	 * @return int
1378
+	 */
1379
+	public function count_registrations($query_params = array())
1380
+	{
1381
+		return $this->count_related('Registration', $query_params);
1382
+	}
1383
+
1384
+
1385
+	/**
1386
+	 * Implementation for EEI_Has_Icon interface method.
1387
+	 *
1388
+	 * @see EEI_Visual_Representation for comments
1389
+	 * @return string
1390
+	 */
1391
+	public function get_icon()
1392
+	{
1393
+		return '<span class="dashicons dashicons-tickets-alt"></span>';
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * Implementation of the EEI_Event_Relation interface method
1399
+	 *
1400
+	 * @see EEI_Event_Relation for comments
1401
+	 * @return EE_Event
1402
+	 * @throws \EE_Error
1403
+	 * @throws UnexpectedEntityException
1404
+	 */
1405
+	public function get_related_event()
1406
+	{
1407
+		// get one datetime to use for getting the event
1408
+		$datetime = $this->first_datetime();
1409
+		if (! $datetime instanceof \EE_Datetime) {
1410
+			throw new UnexpectedEntityException(
1411
+				$datetime,
1412
+				'EE_Datetime',
1413
+				sprintf(
1414
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1415
+					$this->name()
1416
+				)
1417
+			);
1418
+		}
1419
+		$event = $datetime->event();
1420
+		if (! $event instanceof \EE_Event) {
1421
+			throw new UnexpectedEntityException(
1422
+				$event,
1423
+				'EE_Event',
1424
+				sprintf(
1425
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1426
+					$this->name()
1427
+				)
1428
+			);
1429
+		}
1430
+		return $event;
1431
+	}
1432
+
1433
+
1434
+	/**
1435
+	 * Implementation of the EEI_Event_Relation interface method
1436
+	 *
1437
+	 * @see EEI_Event_Relation for comments
1438
+	 * @return string
1439
+	 * @throws UnexpectedEntityException
1440
+	 * @throws \EE_Error
1441
+	 */
1442
+	public function get_event_name()
1443
+	{
1444
+		$event = $this->get_related_event();
1445
+		return $event instanceof EE_Event ? $event->name() : '';
1446
+	}
1447
+
1448
+
1449
+	/**
1450
+	 * Implementation of the EEI_Event_Relation interface method
1451
+	 *
1452
+	 * @see EEI_Event_Relation for comments
1453
+	 * @return int
1454
+	 * @throws UnexpectedEntityException
1455
+	 * @throws \EE_Error
1456
+	 */
1457
+	public function get_event_ID()
1458
+	{
1459
+		$event = $this->get_related_event();
1460
+		return $event instanceof EE_Event ? $event->ID() : 0;
1461
+	}
1462
+
1463
+
1464
+	/**
1465
+	 * This simply returns whether a ticket can be permanently deleted or not.
1466
+	 * The criteria for determining this is whether the ticket has any related registrations.
1467
+	 * If there are none then it can be permanently deleted.
1468
+	 *
1469
+	 * @return bool
1470
+	 */
1471
+	public function is_permanently_deleteable()
1472
+	{
1473
+		return $this->count_registrations() === 0;
1474
+	}
1475 1475
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     public function ticket_status($display = false, $remaining = null)
128 128
     {
129 129
         $remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
130
-        if (! $remaining) {
130
+        if ( ! $remaining) {
131 131
             return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
132 132
         }
133 133
         if ($this->get('TKT_deleted')) {
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
             : '';
246 246
         $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
247 247
 
248
-        return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
248
+        return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
249 249
     }
250 250
 
251 251
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
      */
273 273
     public function datetimes($query_params = array())
274 274
     {
275
-        if (! isset($query_params['order_by'])) {
275
+        if ( ! isset($query_params['order_by'])) {
276 276
             $query_params['order_by']['DTT_order'] = 'ASC';
277 277
         }
278 278
         return $this->get_many_related('Datetime', $query_params);
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
                 if (empty($tickets_sold['datetime'])) {
318 318
                     return $total;
319 319
                 }
320
-                if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
320
+                if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
321 321
                     EE_Error::add_error(
322 322
                         __(
323 323
                             'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?',
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
                     );
330 330
                     return $total;
331 331
                 }
332
-                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
332
+                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
333 333
                 break;
334 334
             default:
335 335
                 return $total;
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
     {
348 348
         $datetimes = $this->get_many_related('Datetime');
349 349
         $tickets_sold = array();
350
-        if (! empty($datetimes)) {
350
+        if ( ! empty($datetimes)) {
351 351
             foreach ($datetimes as $datetime) {
352
-                $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
352
+                $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
353 353
             }
354 354
         }
355 355
         // Tickets sold
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
         $sold = $this->sold() + $qty;
757 757
         // remove ticket reservation, but don't adjust datetime reservations,  because that will happen
758 758
         // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
759
-        $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')');
759
+        $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:".__LINE__.')');
760 760
         $this->_increase_sold_for_datetimes($qty);
761 761
         $this->set_sold($sold);
762 762
         do_action(
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
         foreach ($this->datetimes() as $datetime) {
1301 1301
             $times[] = $datetime->start_date_and_time();
1302 1302
         }
1303
-        return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1303
+        return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1304 1304
     }
1305 1305
 
1306 1306
 
@@ -1406,7 +1406,7 @@  discard block
 block discarded – undo
1406 1406
     {
1407 1407
         // get one datetime to use for getting the event
1408 1408
         $datetime = $this->first_datetime();
1409
-        if (! $datetime instanceof \EE_Datetime) {
1409
+        if ( ! $datetime instanceof \EE_Datetime) {
1410 1410
             throw new UnexpectedEntityException(
1411 1411
                 $datetime,
1412 1412
                 'EE_Datetime',
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
             );
1418 1418
         }
1419 1419
         $event = $datetime->event();
1420
-        if (! $event instanceof \EE_Event) {
1420
+        if ( ! $event instanceof \EE_Event) {
1421 1421
             throw new UnexpectedEntityException(
1422 1422
                 $event,
1423 1423
                 'EE_Event',
Please login to merge, or discard this patch.
core/db_classes/EE_Venue.class.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
      * @param array  $props_n_values  incoming values from the database
31 31
      * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32 32
      *                                the website will be used.
33
-     * @return EE_Attendee
33
+     * @return EE_Venue
34 34
      */
35 35
     public static function new_instance_from_db($props_n_values = array(), $timezone = null)
36 36
     {
Please login to merge, or discard this patch.
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -10,564 +10,564 @@
 block discarded – undo
10 10
 class EE_Venue extends EE_CPT_Base implements EEI_Address
11 11
 {
12 12
 
13
-    /**
14
-     *
15
-     * @param array  $props_n_values          incoming values
16
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
-     *                                        used.)
18
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
-     *                                        date_format and the second value is the time format
20
-     * @return EE_Attendee
21
-     */
22
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
23
-    {
24
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
-    }
27
-
28
-
29
-    /**
30
-     * @param array  $props_n_values  incoming values from the database
31
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
-     *                                the website will be used.
33
-     * @return EE_Attendee
34
-     */
35
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
36
-    {
37
-        return new self($props_n_values, true, $timezone);
38
-    }
39
-
40
-
41
-    /**
42
-     * Gets name
43
-     *
44
-     * @return string
45
-     */
46
-    public function name()
47
-    {
48
-        return $this->get('VNU_name');
49
-    }
50
-
51
-
52
-    /**
53
-     * Gets phone
54
-     *
55
-     * @return string
56
-     */
57
-    public function phone()
58
-    {
59
-        return $this->get('VNU_phone');
60
-    }
61
-
62
-
63
-    /**
64
-     * venue_url
65
-     *
66
-     * @return string
67
-     */
68
-    public function venue_url()
69
-    {
70
-        return $this->get('VNU_url');
71
-    }
72
-
73
-
74
-    /**
75
-     * Gets desc
76
-     *
77
-     * @return string
78
-     */
79
-    public function description()
80
-    {
81
-        return $this->get('VNU_desc');
82
-    }
83
-
84
-
85
-    /**
86
-     * Gets short description (AKA: the excerpt)
87
-     *
88
-     * @return string
89
-     */
90
-    public function excerpt()
91
-    {
92
-        return $this->get('VNU_short_desc');
93
-    }
94
-
95
-
96
-    /**
97
-     * Gets identifier
98
-     *
99
-     * @return string
100
-     */
101
-    public function identifier()
102
-    {
103
-        return $this->get('VNU_identifier');
104
-    }
105
-
106
-
107
-    /**
108
-     * Gets address
109
-     *
110
-     * @return string
111
-     */
112
-    public function address()
113
-    {
114
-        return $this->get('VNU_address');
115
-    }
116
-
117
-
118
-    /**
119
-     * Gets address2
120
-     *
121
-     * @return string
122
-     */
123
-    public function address2()
124
-    {
125
-        return $this->get('VNU_address2');
126
-    }
127
-
128
-
129
-    /**
130
-     * Gets city
131
-     *
132
-     * @return string
133
-     */
134
-    public function city()
135
-    {
136
-        return $this->get('VNU_city');
137
-    }
138
-
139
-    /**
140
-     * Gets state
141
-     *
142
-     * @return int
143
-     */
144
-    public function state_ID()
145
-    {
146
-        return $this->get('STA_ID');
147
-    }
148
-
149
-
150
-    /**
151
-     * @return string
152
-     */
153
-    public function state_abbrev()
154
-    {
155
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
156
-    }
157
-
158
-
159
-    /**
160
-     * @return string
161
-     */
162
-    public function state_name()
163
-    {
164
-        return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : '';
165
-    }
166
-
167
-
168
-    /**
169
-     * Gets the state for this venue
170
-     *
171
-     * @return EE_State
172
-     */
173
-    public function state_obj()
174
-    {
175
-        return $this->get_first_related('State');
176
-    }
177
-
178
-
179
-    /**
180
-     * either displays the state abbreviation or the state name, as determined
181
-     * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
182
-     * defaults to abbreviation
183
-     *
184
-     * @return string
185
-     */
186
-    public function state()
187
-    {
188
-        if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
189
-            return $this->state_abbrev();
190
-        } else {
191
-            return $this->state_name();
192
-        }
193
-    }
194
-
195
-
196
-    /**
197
-     * country_ID
198
-     *
199
-     * @return string
200
-     */
201
-    public function country_ID()
202
-    {
203
-        return $this->get('CNT_ISO');
204
-    }
205
-
206
-
207
-    /**
208
-     * @return string
209
-     */
210
-    public function country_name()
211
-    {
212
-        return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : '';
213
-    }
214
-
215
-
216
-    /**
217
-     * Gets the country of this venue
218
-     *
219
-     * @return EE_Country
220
-     */
221
-    public function country_obj()
222
-    {
223
-        return $this->get_first_related('Country');
224
-    }
225
-
226
-
227
-    /**
228
-     * either displays the country ISO2 code or the country name, as determined
229
-     * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
230
-     * defaults to abbreviation
231
-     *
232
-     * @return string
233
-     */
234
-    public function country()
235
-    {
236
-        if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
237
-            return $this->country_ID();
238
-        } else {
239
-            return $this->country_name();
240
-        }
241
-    }
242
-
243
-
244
-    /**
245
-     * Gets zip
246
-     *
247
-     * @return string
248
-     */
249
-    public function zip()
250
-    {
251
-        return $this->get('VNU_zip');
252
-    }
253
-
254
-
255
-    /**
256
-     * Gets capacity
257
-     *
258
-     * @return int
259
-     */
260
-    public function capacity()
261
-    {
262
-        return $this->get_pretty('VNU_capacity', 'symbol');
263
-    }
264
-
265
-
266
-    /**
267
-     * Gets created
268
-     *
269
-     * @return string
270
-     */
271
-    public function created()
272
-    {
273
-        return $this->get('VNU_created');
274
-    }
275
-
276
-
277
-    /**
278
-     * Gets modified
279
-     *
280
-     * @return string
281
-     */
282
-    public function modified()
283
-    {
284
-        return $this->get('VNU_modified');
285
-    }
286
-
287
-
288
-    /**
289
-     * Gets order
290
-     *
291
-     * @return int
292
-     */
293
-    public function order()
294
-    {
295
-        return $this->get('VNU_order');
296
-    }
297
-
298
-
299
-    /**
300
-     * Gets wp_user
301
-     *
302
-     * @return int
303
-     */
304
-    public function wp_user()
305
-    {
306
-        return $this->get('VNU_wp_user');
307
-    }
308
-
309
-
310
-    /**
311
-     * @return string
312
-     */
313
-    public function virtual_phone()
314
-    {
315
-        return $this->get('VNU_virtual_phone');
316
-    }
317
-
318
-
319
-    /**
320
-     * @return string
321
-     */
322
-    public function virtual_url()
323
-    {
324
-        return $this->get('VNU_virtual_url');
325
-    }
326
-
327
-
328
-    /**
329
-     * @return bool
330
-     */
331
-    public function enable_for_gmap()
332
-    {
333
-        return $this->get('VNU_enable_for_gmap');
334
-    }
335
-
336
-
337
-    /**
338
-     * @return string
339
-     */
340
-    public function google_map_link()
341
-    {
342
-        return $this->get('VNU_google_map_link');
343
-    }
344
-
345
-
346
-    /**
347
-     * Gets all events happening at this venue. Query parameters can be added to
348
-     * fetch a subset of those events.
349
-     *
350
-     * @param array $query_params like EEM_Base::get_all's $query_params
351
-     * @param bool  $upcoming
352
-     * @return EE_Event[]
353
-     */
354
-    public function events($query_params = array(), $upcoming = false)
355
-    {
356
-        if ($upcoming) {
357
-            $query_params = array(
358
-                array(
359
-                    'status'                 => 'publish',
360
-                    'Datetime.DTT_EVT_start' => array(
361
-                        '>',
362
-                        EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
363
-                    ),
364
-                ),
365
-            );
366
-        }
367
-        return $this->get_many_related('Event', $query_params);
368
-    }
369
-
370
-
371
-    /**
372
-     * Sets address
373
-     */
374
-    public function set_address($address = '')
375
-    {
376
-        $this->set('VNU_address', $address);
377
-    }
378
-
379
-
380
-    /**
381
-     * @param string $address2
382
-     */
383
-    public function set_address2($address2 = '')
384
-    {
385
-        $this->set('VNU_address2', $address2);
386
-    }
387
-
388
-
389
-    /**
390
-     * @param string $city
391
-     */
392
-    public function set_city($city = '')
393
-    {
394
-        $this->set('VNU_city', $city);
395
-    }
396
-
397
-
398
-    /**
399
-     * @param int $state
400
-     */
401
-    public function set_state_ID($state = 0)
402
-    {
403
-        $this->set('STA_ID', $state);
404
-    }
405
-
406
-
407
-    /**
408
-     * Sets the state, given either a state id or state object
409
-     *
410
-     * @param EE_State /int $state_id_or_obj
411
-     * @return EE_State
412
-     */
413
-    public function set_state_obj($state_id_or_obj)
414
-    {
415
-        return $this->_add_relation_to($state_id_or_obj, 'State');
416
-    }
417
-
418
-
419
-    /**
420
-     * @param int $country_ID
421
-     */
422
-    public function set_country_ID($country_ID = 0)
423
-    {
424
-        $this->set('CNT_ISO', $country_ID);
425
-    }
426
-
427
-
428
-    /**
429
-     * Sets the country on the venue
430
-     *
431
-     * @param EE_Country /string $country_id_or_obj
432
-     * @return EE_Country
433
-     */
434
-    public function set_country_obj($country_id_or_obj)
435
-    {
436
-        return $this->_add_relation_to($country_id_or_obj, 'Country');
437
-    }
438
-
439
-
440
-    /**
441
-     * @param string $zip
442
-     */
443
-    public function set_zip($zip = '')
444
-    {
445
-        $this->set('VNU_zip', $zip);
446
-    }
447
-
448
-
449
-    /**
450
-     * @param int $capacity
451
-     */
452
-    public function set_capacity($capacity = 0)
453
-    {
454
-        $this->set('VNU_capacity', $capacity);
455
-    }
456
-
457
-
458
-    /**
459
-     * @param string $created
460
-     */
461
-    public function set_created($created = '')
462
-    {
463
-        $this->set('VNU_created', $created);
464
-    }
465
-
466
-
467
-    /**
468
-     * @param string $desc
469
-     */
470
-    public function set_description($desc = '')
471
-    {
472
-        $this->set('VNU_desc', $desc);
473
-    }
474
-
475
-
476
-    /**
477
-     * @param string $identifier
478
-     */
479
-    public function set_identifier($identifier = '')
480
-    {
481
-        $this->set('VNU_identifier', $identifier);
482
-    }
483
-
484
-
485
-    /**
486
-     * @param string $modified
487
-     */
488
-    public function set_modified($modified = '')
489
-    {
490
-        $this->set('VNU_modified', $modified);
491
-    }
492
-
493
-
494
-    /**
495
-     * @param string $name
496
-     */
497
-    public function set_name($name = '')
498
-    {
499
-        $this->set('VNU_name', $name);
500
-    }
501
-
502
-
503
-    /**
504
-     * @param int $order
505
-     */
506
-    public function set_order($order = 0)
507
-    {
508
-        $this->set('VNU_order', $order);
509
-    }
510
-
511
-
512
-    /**
513
-     * @param string $phone
514
-     */
515
-    public function set_phone($phone = '')
516
-    {
517
-        $this->set('VNU_phone', $phone);
518
-    }
519
-
520
-
521
-    /**
522
-     * @param int $wp_user
523
-     */
524
-    public function set_wp_user($wp_user = 1)
525
-    {
526
-        $this->set('VNU_wp_user', $wp_user);
527
-    }
528
-
529
-
530
-    /**
531
-     * @param string $url
532
-     */
533
-    public function set_venue_url($url = '')
534
-    {
535
-        $this->set('VNU_url', $url);
536
-    }
537
-
538
-
539
-    /**
540
-     * @param string $phone
541
-     */
542
-    public function set_virtual_phone($phone = '')
543
-    {
544
-        $this->set('VNU_virtual_phone', $phone);
545
-    }
546
-
547
-
548
-    /**
549
-     * @param string $url
550
-     */
551
-    public function set_virtual_url($url = '')
552
-    {
553
-        $this->set('VNU_virtual_url', $url);
554
-    }
555
-
556
-
557
-    /**
558
-     * @param string $enable
559
-     */
560
-    public function set_enable_for_gmap($enable = '')
561
-    {
562
-        $this->set('VNU_enable_for_gmap', $enable);
563
-    }
564
-
565
-
566
-    /**
567
-     * @param string $google_map_link
568
-     */
569
-    public function set_google_map_link($google_map_link = '')
570
-    {
571
-        $this->set('VNU_google_map_link', $google_map_link);
572
-    }
13
+	/**
14
+	 *
15
+	 * @param array  $props_n_values          incoming values
16
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
17
+	 *                                        used.)
18
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
19
+	 *                                        date_format and the second value is the time format
20
+	 * @return EE_Attendee
21
+	 */
22
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
23
+	{
24
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
25
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
26
+	}
27
+
28
+
29
+	/**
30
+	 * @param array  $props_n_values  incoming values from the database
31
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
32
+	 *                                the website will be used.
33
+	 * @return EE_Attendee
34
+	 */
35
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
36
+	{
37
+		return new self($props_n_values, true, $timezone);
38
+	}
39
+
40
+
41
+	/**
42
+	 * Gets name
43
+	 *
44
+	 * @return string
45
+	 */
46
+	public function name()
47
+	{
48
+		return $this->get('VNU_name');
49
+	}
50
+
51
+
52
+	/**
53
+	 * Gets phone
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function phone()
58
+	{
59
+		return $this->get('VNU_phone');
60
+	}
61
+
62
+
63
+	/**
64
+	 * venue_url
65
+	 *
66
+	 * @return string
67
+	 */
68
+	public function venue_url()
69
+	{
70
+		return $this->get('VNU_url');
71
+	}
72
+
73
+
74
+	/**
75
+	 * Gets desc
76
+	 *
77
+	 * @return string
78
+	 */
79
+	public function description()
80
+	{
81
+		return $this->get('VNU_desc');
82
+	}
83
+
84
+
85
+	/**
86
+	 * Gets short description (AKA: the excerpt)
87
+	 *
88
+	 * @return string
89
+	 */
90
+	public function excerpt()
91
+	{
92
+		return $this->get('VNU_short_desc');
93
+	}
94
+
95
+
96
+	/**
97
+	 * Gets identifier
98
+	 *
99
+	 * @return string
100
+	 */
101
+	public function identifier()
102
+	{
103
+		return $this->get('VNU_identifier');
104
+	}
105
+
106
+
107
+	/**
108
+	 * Gets address
109
+	 *
110
+	 * @return string
111
+	 */
112
+	public function address()
113
+	{
114
+		return $this->get('VNU_address');
115
+	}
116
+
117
+
118
+	/**
119
+	 * Gets address2
120
+	 *
121
+	 * @return string
122
+	 */
123
+	public function address2()
124
+	{
125
+		return $this->get('VNU_address2');
126
+	}
127
+
128
+
129
+	/**
130
+	 * Gets city
131
+	 *
132
+	 * @return string
133
+	 */
134
+	public function city()
135
+	{
136
+		return $this->get('VNU_city');
137
+	}
138
+
139
+	/**
140
+	 * Gets state
141
+	 *
142
+	 * @return int
143
+	 */
144
+	public function state_ID()
145
+	{
146
+		return $this->get('STA_ID');
147
+	}
148
+
149
+
150
+	/**
151
+	 * @return string
152
+	 */
153
+	public function state_abbrev()
154
+	{
155
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : '';
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return string
161
+	 */
162
+	public function state_name()
163
+	{
164
+		return $this->state_obj() instanceof EE_State ? $this->state_obj()->name() : '';
165
+	}
166
+
167
+
168
+	/**
169
+	 * Gets the state for this venue
170
+	 *
171
+	 * @return EE_State
172
+	 */
173
+	public function state_obj()
174
+	{
175
+		return $this->get_first_related('State');
176
+	}
177
+
178
+
179
+	/**
180
+	 * either displays the state abbreviation or the state name, as determined
181
+	 * by the "FHEE__EEI_Address__state__use_abbreviation" filter.
182
+	 * defaults to abbreviation
183
+	 *
184
+	 * @return string
185
+	 */
186
+	public function state()
187
+	{
188
+		if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) {
189
+			return $this->state_abbrev();
190
+		} else {
191
+			return $this->state_name();
192
+		}
193
+	}
194
+
195
+
196
+	/**
197
+	 * country_ID
198
+	 *
199
+	 * @return string
200
+	 */
201
+	public function country_ID()
202
+	{
203
+		return $this->get('CNT_ISO');
204
+	}
205
+
206
+
207
+	/**
208
+	 * @return string
209
+	 */
210
+	public function country_name()
211
+	{
212
+		return $this->country_obj() instanceof EE_Country ? $this->country_obj()->name() : '';
213
+	}
214
+
215
+
216
+	/**
217
+	 * Gets the country of this venue
218
+	 *
219
+	 * @return EE_Country
220
+	 */
221
+	public function country_obj()
222
+	{
223
+		return $this->get_first_related('Country');
224
+	}
225
+
226
+
227
+	/**
228
+	 * either displays the country ISO2 code or the country name, as determined
229
+	 * by the "FHEE__EEI_Address__country__use_abbreviation" filter.
230
+	 * defaults to abbreviation
231
+	 *
232
+	 * @return string
233
+	 */
234
+	public function country()
235
+	{
236
+		if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) {
237
+			return $this->country_ID();
238
+		} else {
239
+			return $this->country_name();
240
+		}
241
+	}
242
+
243
+
244
+	/**
245
+	 * Gets zip
246
+	 *
247
+	 * @return string
248
+	 */
249
+	public function zip()
250
+	{
251
+		return $this->get('VNU_zip');
252
+	}
253
+
254
+
255
+	/**
256
+	 * Gets capacity
257
+	 *
258
+	 * @return int
259
+	 */
260
+	public function capacity()
261
+	{
262
+		return $this->get_pretty('VNU_capacity', 'symbol');
263
+	}
264
+
265
+
266
+	/**
267
+	 * Gets created
268
+	 *
269
+	 * @return string
270
+	 */
271
+	public function created()
272
+	{
273
+		return $this->get('VNU_created');
274
+	}
275
+
276
+
277
+	/**
278
+	 * Gets modified
279
+	 *
280
+	 * @return string
281
+	 */
282
+	public function modified()
283
+	{
284
+		return $this->get('VNU_modified');
285
+	}
286
+
287
+
288
+	/**
289
+	 * Gets order
290
+	 *
291
+	 * @return int
292
+	 */
293
+	public function order()
294
+	{
295
+		return $this->get('VNU_order');
296
+	}
297
+
298
+
299
+	/**
300
+	 * Gets wp_user
301
+	 *
302
+	 * @return int
303
+	 */
304
+	public function wp_user()
305
+	{
306
+		return $this->get('VNU_wp_user');
307
+	}
308
+
309
+
310
+	/**
311
+	 * @return string
312
+	 */
313
+	public function virtual_phone()
314
+	{
315
+		return $this->get('VNU_virtual_phone');
316
+	}
317
+
318
+
319
+	/**
320
+	 * @return string
321
+	 */
322
+	public function virtual_url()
323
+	{
324
+		return $this->get('VNU_virtual_url');
325
+	}
326
+
327
+
328
+	/**
329
+	 * @return bool
330
+	 */
331
+	public function enable_for_gmap()
332
+	{
333
+		return $this->get('VNU_enable_for_gmap');
334
+	}
335
+
336
+
337
+	/**
338
+	 * @return string
339
+	 */
340
+	public function google_map_link()
341
+	{
342
+		return $this->get('VNU_google_map_link');
343
+	}
344
+
345
+
346
+	/**
347
+	 * Gets all events happening at this venue. Query parameters can be added to
348
+	 * fetch a subset of those events.
349
+	 *
350
+	 * @param array $query_params like EEM_Base::get_all's $query_params
351
+	 * @param bool  $upcoming
352
+	 * @return EE_Event[]
353
+	 */
354
+	public function events($query_params = array(), $upcoming = false)
355
+	{
356
+		if ($upcoming) {
357
+			$query_params = array(
358
+				array(
359
+					'status'                 => 'publish',
360
+					'Datetime.DTT_EVT_start' => array(
361
+						'>',
362
+						EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
363
+					),
364
+				),
365
+			);
366
+		}
367
+		return $this->get_many_related('Event', $query_params);
368
+	}
369
+
370
+
371
+	/**
372
+	 * Sets address
373
+	 */
374
+	public function set_address($address = '')
375
+	{
376
+		$this->set('VNU_address', $address);
377
+	}
378
+
379
+
380
+	/**
381
+	 * @param string $address2
382
+	 */
383
+	public function set_address2($address2 = '')
384
+	{
385
+		$this->set('VNU_address2', $address2);
386
+	}
387
+
388
+
389
+	/**
390
+	 * @param string $city
391
+	 */
392
+	public function set_city($city = '')
393
+	{
394
+		$this->set('VNU_city', $city);
395
+	}
396
+
397
+
398
+	/**
399
+	 * @param int $state
400
+	 */
401
+	public function set_state_ID($state = 0)
402
+	{
403
+		$this->set('STA_ID', $state);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Sets the state, given either a state id or state object
409
+	 *
410
+	 * @param EE_State /int $state_id_or_obj
411
+	 * @return EE_State
412
+	 */
413
+	public function set_state_obj($state_id_or_obj)
414
+	{
415
+		return $this->_add_relation_to($state_id_or_obj, 'State');
416
+	}
417
+
418
+
419
+	/**
420
+	 * @param int $country_ID
421
+	 */
422
+	public function set_country_ID($country_ID = 0)
423
+	{
424
+		$this->set('CNT_ISO', $country_ID);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Sets the country on the venue
430
+	 *
431
+	 * @param EE_Country /string $country_id_or_obj
432
+	 * @return EE_Country
433
+	 */
434
+	public function set_country_obj($country_id_or_obj)
435
+	{
436
+		return $this->_add_relation_to($country_id_or_obj, 'Country');
437
+	}
438
+
439
+
440
+	/**
441
+	 * @param string $zip
442
+	 */
443
+	public function set_zip($zip = '')
444
+	{
445
+		$this->set('VNU_zip', $zip);
446
+	}
447
+
448
+
449
+	/**
450
+	 * @param int $capacity
451
+	 */
452
+	public function set_capacity($capacity = 0)
453
+	{
454
+		$this->set('VNU_capacity', $capacity);
455
+	}
456
+
457
+
458
+	/**
459
+	 * @param string $created
460
+	 */
461
+	public function set_created($created = '')
462
+	{
463
+		$this->set('VNU_created', $created);
464
+	}
465
+
466
+
467
+	/**
468
+	 * @param string $desc
469
+	 */
470
+	public function set_description($desc = '')
471
+	{
472
+		$this->set('VNU_desc', $desc);
473
+	}
474
+
475
+
476
+	/**
477
+	 * @param string $identifier
478
+	 */
479
+	public function set_identifier($identifier = '')
480
+	{
481
+		$this->set('VNU_identifier', $identifier);
482
+	}
483
+
484
+
485
+	/**
486
+	 * @param string $modified
487
+	 */
488
+	public function set_modified($modified = '')
489
+	{
490
+		$this->set('VNU_modified', $modified);
491
+	}
492
+
493
+
494
+	/**
495
+	 * @param string $name
496
+	 */
497
+	public function set_name($name = '')
498
+	{
499
+		$this->set('VNU_name', $name);
500
+	}
501
+
502
+
503
+	/**
504
+	 * @param int $order
505
+	 */
506
+	public function set_order($order = 0)
507
+	{
508
+		$this->set('VNU_order', $order);
509
+	}
510
+
511
+
512
+	/**
513
+	 * @param string $phone
514
+	 */
515
+	public function set_phone($phone = '')
516
+	{
517
+		$this->set('VNU_phone', $phone);
518
+	}
519
+
520
+
521
+	/**
522
+	 * @param int $wp_user
523
+	 */
524
+	public function set_wp_user($wp_user = 1)
525
+	{
526
+		$this->set('VNU_wp_user', $wp_user);
527
+	}
528
+
529
+
530
+	/**
531
+	 * @param string $url
532
+	 */
533
+	public function set_venue_url($url = '')
534
+	{
535
+		$this->set('VNU_url', $url);
536
+	}
537
+
538
+
539
+	/**
540
+	 * @param string $phone
541
+	 */
542
+	public function set_virtual_phone($phone = '')
543
+	{
544
+		$this->set('VNU_virtual_phone', $phone);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param string $url
550
+	 */
551
+	public function set_virtual_url($url = '')
552
+	{
553
+		$this->set('VNU_virtual_url', $url);
554
+	}
555
+
556
+
557
+	/**
558
+	 * @param string $enable
559
+	 */
560
+	public function set_enable_for_gmap($enable = '')
561
+	{
562
+		$this->set('VNU_enable_for_gmap', $enable);
563
+	}
564
+
565
+
566
+	/**
567
+	 * @param string $google_map_link
568
+	 */
569
+	public function set_google_map_link($google_map_link = '')
570
+	{
571
+		$this->set('VNU_google_map_link', $google_map_link);
572
+	}
573 573
 }
Please login to merge, or discard this patch.
modules/single_page_checkout/inc/EE_Checkout.class.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 
320 320
     /**
321 321
      * @param $REG_ID
322
-     * @param $reg_status
322
+     * @param boolean $reg_status
323 323
      */
324 324
     public function set_reg_status_updated($REG_ID, $reg_status)
325 325
     {
@@ -1237,6 +1237,7 @@  discard block
 block discarded – undo
1237 1237
      *
1238 1238
      * @param    string | int    $reg_cache_ID
1239 1239
      * @param    EE_Registration $registration
1240
+     * @param integer $reg_cache_ID
1240 1241
      * @return void
1241 1242
      * @throws \EE_Error
1242 1243
      */
Please login to merge, or discard this patch.
Indentation   +1425 added lines, -1425 removed lines patch added patch discarded remove patch
@@ -15,1429 +15,1429 @@
 block discarded – undo
15 15
 class EE_Checkout
16 16
 {
17 17
 
18
-    /**
19
-     *    whether current request originated from the EE admin
20
-     *
21
-     * @type bool
22
-     */
23
-    public $admin_request = false;
24
-
25
-    /**
26
-     * whether returning to edit attendee information or to retry a payment
27
-     *
28
-     * @type bool
29
-     */
30
-    public $revisit = false;
31
-
32
-    /**
33
-     * whether the primary registrant is returning to edit attendee information or to retry a payment
34
-     *
35
-     * @type bool
36
-     */
37
-    public $primary_revisit = false;
38
-
39
-    /**
40
-     * is registration allowed to progress or halted for some reason such as failing to pass recaptcha?
41
-     *
42
-     * @type bool
43
-     */
44
-    public $continue_reg = true;
45
-
46
-    /**
47
-     * redirect to thank you page ?
48
-     *
49
-     * @type bool
50
-     */
51
-    public $redirect = false;
52
-
53
-    /**
54
-     * generate the reg form or not ?
55
-     *
56
-     * @type bool
57
-     */
58
-    public $generate_reg_form = true;
59
-
60
-    /**
61
-     * process a reg form submission or not ?
62
-     *
63
-     * @type bool
64
-     */
65
-    public $process_form_submission = false;
66
-
67
-    /**
68
-     * tracks whether the TXN status modified during this checkout
69
-     *
70
-     * @type bool
71
-     */
72
-    public $txn_status_updated = false;
73
-
74
-    /**
75
-     * only triggered to true after absolutely everything has finished.
76
-     *
77
-     * @type bool
78
-     */
79
-    protected $exit_spco = false;
80
-
81
-    /**
82
-     * tracks whether any of the TXN's Registrations statuses modified during this checkout
83
-     * indexed by registration ID
84
-     *
85
-     * @type array
86
-     */
87
-    protected $reg_status_updated = array();
88
-
89
-    /**
90
-     * timestamp when redirected from Ticket Selector to the checkout
91
-     *
92
-     * @type int
93
-     */
94
-    public $uts = 0;
95
-
96
-    /**
97
-     * total number of tickets that were in the cart
98
-     *
99
-     * @type int
100
-     */
101
-    public $total_ticket_count = 0;
102
-
103
-    /**
104
-     * corresponds loosely to EE_Transaction::remaining()
105
-     * but can be modified by SPCO
106
-     *
107
-     * @type float
108
-     */
109
-    public $amount_owing = 0;
110
-
111
-    /**
112
-     * the reg step slug from the incoming request
113
-     *
114
-     * @type string
115
-     */
116
-    public $step = '';
117
-
118
-    /**
119
-     * the reg step slug for a step being edited
120
-     *
121
-     * @type string
122
-     */
123
-    public $edit_step = '';
124
-
125
-    /**
126
-     * the action being performed on the current step
127
-     *
128
-     * @type string
129
-     */
130
-    public $action = '';
131
-
132
-    /**
133
-     * reg_url_link for a previously saved registration
134
-     *
135
-     * @type string
136
-     */
137
-    public $reg_url_link = '';
138
-
139
-    /**
140
-     * string slug for the payment method that was selected during the payment options step
141
-     *
142
-     * @type string
143
-     */
144
-    public $selected_method_of_payment = '';
145
-
146
-    /**
147
-     * base url for the site's registration checkout page - additional url params will be added to this
148
-     *
149
-     * @type string
150
-     */
151
-    public $reg_page_base_url = '';
152
-
153
-    /**
154
-     * base url for the site's registration cancelled page - additional url params will be added to this
155
-     *
156
-     * @type string
157
-     */
158
-    public $cancel_page_url = '';
159
-
160
-    /**
161
-     * base url for the site's thank you page - additional url params will be added to this
162
-     *
163
-     * @type string
164
-     */
165
-    public $thank_you_page_url = '';
166
-
167
-    /**
168
-     * base url for any redirects - additional url params will be added to this
169
-     *
170
-     * @type string
171
-     */
172
-    public $redirect_url = '';
173
-
174
-    /**
175
-     * form of POST data for use with off-site gateways
176
-     *
177
-     * @type string
178
-     */
179
-    public $redirect_form = '';
180
-
181
-    /**
182
-     * array of query where params to use when retrieving cached registrations from $this->checkout->transaction
183
-     *
184
-     * @type array
185
-     */
186
-    public $reg_cache_where_params = array();
187
-
188
-    /**
189
-     * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX
190
-     * requests
191
-     *
192
-     * @type EE_SPCO_JSON_Response
193
-     */
194
-    public $json_response;
195
-
196
-    /**
197
-     * where we are going next in the reg process
198
-     *
199
-     * @type EE_SPCO_Reg_Step
200
-     */
201
-    public $next_step;
202
-
203
-    /**
204
-     * where we are in the reg process
205
-     *
206
-     * @type EE_SPCO_Reg_Step
207
-     */
208
-    public $current_step;
209
-
210
-    /**
211
-     *    $_cart - the current cart object
212
-     *
213
-     * @var EE_CART
214
-     */
215
-    public $cart;
216
-
217
-    /**
218
-     *    $_transaction - the current transaction object
219
-     *
220
-     * @var EE_Transaction
221
-     */
222
-    public $transaction;
223
-
224
-    /**
225
-     *    the related attendee object for the primary registrant
226
-     *
227
-     * @type EE_Attendee
228
-     */
229
-    public $primary_attendee_obj;
230
-
231
-    /**
232
-     *    $payment_method - the payment method object for the selected method of payment
233
-     *
234
-     * @type EE_Payment_Method
235
-     */
236
-    public $payment_method;
237
-
238
-    /**
239
-     *    $payment - if a payment was successfully made during the reg process,
240
-     *    then here it is !!!
241
-     *
242
-     * @type EE_Payment
243
-     */
244
-    public $payment;
245
-
246
-    /**
247
-     *    if a payment method was selected that uses an on-site gateway, then this is the billing form
248
-     *
249
-     * @type EE_Billing_Info_Form | EE_Billing_Attendee_Info_Form
250
-     */
251
-    public $billing_form;
252
-
253
-    /**
254
-     *    the entire registration form composed of ALL of the subsections generated by the various reg steps
255
-     *
256
-     * @type EE_Form_Section_Proper
257
-     */
258
-    public $registration_form;
259
-
260
-    /**
261
-     * array of EE_SPCO_Reg_Step objects
262
-     *
263
-     * @type EE_SPCO_Reg_Step[]
264
-     */
265
-    public $reg_steps = array();
266
-
267
-    /**
268
-     * array of EE_Payment_Method objects
269
-     *
270
-     * @type EE_Payment_Method[]
271
-     */
272
-    public $available_payment_methods = array();
273
-
274
-
275
-    /**
276
-     *    class constructor
277
-     *
278
-     * @access    public
279
-     */
280
-    public function __construct()
281
-    {
282
-        $this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
283
-        $this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
284
-        $this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
285
-        $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
286
-        $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax;
287
-        $this->reg_cache_where_params = array(
288
-            0          => array('REG_deleted' => false),
289
-            'order_by' => array('REG_count' => 'ASC'),
290
-        );
291
-    }
292
-
293
-
294
-    /**
295
-     * returns true if ANY reg status was updated during checkout
296
-     *
297
-     * @return boolean
298
-     */
299
-    public function any_reg_status_updated()
300
-    {
301
-        foreach ($this->reg_status_updated as $reg_status) {
302
-            if ($reg_status) {
303
-                return true;
304
-            }
305
-        }
306
-        return false;
307
-    }
308
-
309
-
310
-    /**
311
-     * @param $REG_ID
312
-     * @return boolean
313
-     */
314
-    public function reg_status_updated($REG_ID)
315
-    {
316
-        return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false;
317
-    }
318
-
319
-
320
-    /**
321
-     * @param $REG_ID
322
-     * @param $reg_status
323
-     */
324
-    public function set_reg_status_updated($REG_ID, $reg_status)
325
-    {
326
-        $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
327
-    }
328
-
329
-
330
-    /**
331
-     * exit_spco
332
-     *
333
-     * @return bool
334
-     */
335
-    public function exit_spco()
336
-    {
337
-        return $this->exit_spco;
338
-    }
339
-
340
-
341
-    /**
342
-     * set_exit_spco
343
-     * can ONLY be set by the  Finalize_Registration reg step
344
-     */
345
-    public function set_exit_spco()
346
-    {
347
-        if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
348
-            $this->exit_spco = true;
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     *    reset_for_current_request
355
-     *
356
-     * @access    public
357
-     * @return    void
358
-     */
359
-    public function reset_for_current_request()
360
-    {
361
-        $this->process_form_submission = false;
362
-        $this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
363
-        $this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax;
364
-        $this->continue_reg = true;
365
-        $this->redirect = false;
366
-        // don't reset the cached redirect form if we're about to be asked to display it !!!
367
-        if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') {
368
-            $this->redirect_form = '';
369
-        }
370
-        $this->redirect_url = '';
371
-        $this->json_response = new EE_SPCO_JSON_Response();
372
-        EE_Form_Section_Proper::reset_js_localization();
373
-    }
374
-
375
-
376
-    /**
377
-     *    add_reg_step
378
-     *
379
-     * @access    public
380
-     * @param EE_SPCO_Reg_Step $reg_step_obj
381
-     * @return    void
382
-     */
383
-    public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj)
384
-    {
385
-        $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj;
386
-    }
387
-
388
-
389
-    /**
390
-     * skip_reg_step
391
-     * if the current reg step does not need to run for some reason,
392
-     * then this will advance SPCO to the next reg step,
393
-     * and mark the skipped step as completed
394
-     *
395
-     * @access    public
396
-     * @param string $reg_step_slug
397
-     * @return    void
398
-     * @throws \EE_Error
399
-     */
400
-    public function skip_reg_step($reg_step_slug = '')
401
-    {
402
-        $step_to_skip = $this->find_reg_step($reg_step_slug);
403
-        if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
404
-            $step_to_skip->set_is_current_step(false);
405
-            $step_to_skip->set_completed();
406
-            // advance to the next step
407
-            $this->set_current_step($this->next_step->slug());
408
-            // also reset the step param in the request in case any other code references that directly
409
-            EE_Registry::instance()->REQ->set('step', $this->current_step->slug());
410
-            // since we are skipping a step and setting the current step to be what was previously the next step,
411
-            // we need to check that the next step is now correct, and not still set to the current step.
412
-            if ($this->current_step->slug() === $this->next_step->slug()) {
413
-                // correctly setup the next step
414
-                $this->set_next_step();
415
-            }
416
-            $this->set_reg_step_initiated($this->current_step);
417
-        }
418
-    }
419
-
420
-
421
-    /**
422
-     *    remove_reg_step
423
-     *
424
-     * @access    public
425
-     * @param string $reg_step_slug
426
-     * @param bool   $reset whether to reset reg steps after removal
427
-     * @throws EE_Error
428
-     */
429
-    public function remove_reg_step($reg_step_slug = '', $reset = true)
430
-    {
431
-        unset($this->reg_steps[ $reg_step_slug ]);
432
-        if ($this->transaction instanceof EE_Transaction) {
433
-            // now remove reg step from TXN and save
434
-            $this->transaction->remove_reg_step($reg_step_slug);
435
-            $this->transaction->save();
436
-        }
437
-        if ($reset) {
438
-            $this->reset_reg_steps();
439
-        }
440
-    }
441
-
442
-
443
-    /**
444
-     *    set_reg_step_order
445
-     *
446
-     * @access    public
447
-     * @param string $reg_step_slug
448
-     * @param int    $order
449
-     * @return    void
450
-     */
451
-    public function set_reg_step_order($reg_step_slug = '', $order = 100)
452
-    {
453
-        if (isset($this->reg_steps[ $reg_step_slug ])) {
454
-            $this->reg_steps[ $reg_step_slug ]->set_order($order);
455
-        }
456
-    }
457
-
458
-
459
-    /**
460
-     *    set_current_step
461
-     *
462
-     * @access    public
463
-     * @param string $current_step
464
-     * @return    void
465
-     */
466
-    public function set_current_step($current_step)
467
-    {
468
-        // grab what step we're on
469
-        $this->current_step = isset($this->reg_steps[ $current_step ])
470
-            ? $this->reg_steps[ $current_step ]
471
-            : reset(
472
-                $this->reg_steps
473
-            );
474
-        // verify instance
475
-        if ($this->current_step instanceof EE_SPCO_Reg_Step) {
476
-            // we don't want to repeat completed steps if this is the first time through SPCO
477
-            if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
478
-                // so advance to the next step
479
-                $this->set_next_step();
480
-                if ($this->next_step instanceof EE_SPCO_Reg_Step) {
481
-                    // and attempt to set it as the current step
482
-                    $this->set_current_step($this->next_step->slug());
483
-                }
484
-                return;
485
-            }
486
-            $this->current_step->set_is_current_step(true);
487
-        } else {
488
-            EE_Error::add_error(
489
-                __('The current step could not be set.', 'event_espresso'),
490
-                __FILE__,
491
-                __FUNCTION__,
492
-                __LINE__
493
-            );
494
-        }
495
-    }
496
-
497
-
498
-    /**
499
-     *    set_next_step
500
-     * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step
501
-     *
502
-     * @access    public
503
-     * @return    void
504
-     */
505
-    public function set_next_step()
506
-    {
507
-        // set pointer to start of array
508
-        reset($this->reg_steps);
509
-        // if there is more than one step
510
-        if (count($this->reg_steps) > 1) {
511
-            // advance to the current step and set pointer
512
-            while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
513
-                next($this->reg_steps);
514
-            }
515
-        }
516
-        // advance one more spot ( if it exists )
517
-        $this->next_step = next($this->reg_steps);
518
-        // verify instance
519
-        $this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null;
520
-        // then back to current step to reset
521
-        prev($this->reg_steps);
522
-    }
523
-
524
-
525
-    /**
526
-     *    get_next_reg_step
527
-     *    this simply returns the next step from reg_steps array
528
-     *
529
-     * @access    public
530
-     * @return    EE_SPCO_Reg_Step | null
531
-     */
532
-    public function get_next_reg_step()
533
-    {
534
-        $next = next($this->reg_steps);
535
-        prev($this->reg_steps);
536
-        return $next instanceof EE_SPCO_Reg_Step ? $next : null;
537
-    }
538
-
539
-
540
-    /**
541
-     * get_prev_reg_step
542
-     *    this simply returns the previous step from reg_steps array
543
-     *
544
-     * @access    public
545
-     * @return    EE_SPCO_Reg_Step | null
546
-     */
547
-    public function get_prev_reg_step()
548
-    {
549
-        $prev = prev($this->reg_steps);
550
-        next($this->reg_steps);
551
-        return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
552
-    }
553
-
554
-
555
-    /**
556
-     * sort_reg_steps
557
-     *
558
-     * @access public
559
-     * @return void
560
-     */
561
-    public function sort_reg_steps()
562
-    {
563
-        $reg_step_sorting_callback = apply_filters(
564
-            'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback',
565
-            'reg_step_sorting_callback'
566
-        );
567
-        uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
568
-    }
569
-
570
-
571
-    /**
572
-     * find_reg_step
573
-     * finds a reg step by the given slug
574
-     *
575
-     * @access    public
576
-     * @param string $reg_step_slug
577
-     * @return EE_SPCO_Reg_Step|null
578
-     */
579
-    public function find_reg_step($reg_step_slug = '')
580
-    {
581
-        if (! empty($reg_step_slug)) {
582
-            // copy reg step array
583
-            $reg_steps = $this->reg_steps;
584
-            // set pointer to start of array
585
-            reset($reg_steps);
586
-            // if there is more than one step
587
-            if (count($reg_steps) > 1) {
588
-                // advance to the current step and set pointer
589
-                while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
590
-                    next($reg_steps);
591
-                }
592
-                return current($reg_steps);
593
-            }
594
-        }
595
-        return null;
596
-    }
597
-
598
-
599
-    /**
600
-     * reg_step_sorting_callback
601
-     *
602
-     * @access public
603
-     * @param EE_SPCO_Reg_Step $reg_step_A
604
-     * @param EE_SPCO_Reg_Step $reg_step_B
605
-     * @return int
606
-     */
607
-    public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B)
608
-    {
609
-        // send finalize_registration step to the end of the array
610
-        if ($reg_step_A->slug() === 'finalize_registration') {
611
-            return 1;
612
-        } elseif ($reg_step_B->slug() === 'finalize_registration') {
613
-            return -1;
614
-        }
615
-        if ($reg_step_A->order() === $reg_step_B->order()) {
616
-            return 0;
617
-        }
618
-        return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
619
-    }
620
-
621
-
622
-    /**
623
-     * set_reg_step_initiated
624
-     *
625
-     * @access    public
626
-     * @param    EE_SPCO_Reg_Step $reg_step
627
-     * @throws \EE_Error
628
-     */
629
-    public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step)
630
-    {
631
-        // call set_reg_step_initiated ???
632
-        if (// first time visiting SPCO ?
633
-            ! $this->revisit
634
-            && (
635
-                // and displaying the reg step form for the first time ?
636
-                $this->action === 'display_spco_reg_step'
637
-                // or initializing the final step
638
-                || $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration
639
-            )
640
-        ) {
641
-            // set the start time for this reg step
642
-            if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
643
-                if (WP_DEBUG) {
644
-                    EE_Error::add_error(
645
-                        sprintf(
646
-                            __('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
647
-                            $reg_step->name()
648
-                        ),
649
-                        __FILE__,
650
-                        __FUNCTION__,
651
-                        __LINE__
652
-                    );
653
-                }
654
-            }
655
-        }
656
-    }
657
-
658
-
659
-    /**
660
-     *    set_reg_step_JSON_info
661
-     *
662
-     * @access public
663
-     * @return    void
664
-     */
665
-    public function set_reg_step_JSON_info()
666
-    {
667
-        EE_Registry::$i18n_js_strings['reg_steps'] = array();
668
-        // pass basic reg step data to JS
669
-        foreach ($this->reg_steps as $reg_step) {
670
-            EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
671
-        }
672
-        // reset reg step html
673
-        // $this->json_response->set_reg_step_html('');
674
-    }
675
-
676
-
677
-    /**
678
-     *    reset_reg_steps
679
-     *
680
-     * @access public
681
-     * @return void
682
-     */
683
-    public function reset_reg_steps()
684
-    {
685
-        $this->sort_reg_steps();
686
-        $this->set_current_step(EE_Registry::instance()->REQ->get('step'));
687
-        $this->set_next_step();
688
-        // the text that appears on the reg step form submit button
689
-        $this->current_step->set_submit_button_text();
690
-        $this->set_reg_step_JSON_info();
691
-    }
692
-
693
-
694
-    /**
695
-     *    get_registration_time_limit
696
-     *
697
-     * @access    public
698
-     * @return        string
699
-     */
700
-    public function get_registration_time_limit()
701
-    {
702
-
703
-        $registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time());
704
-        $time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
705
-        $registration_time_limit = date($time_limit_format, $registration_time_limit);
706
-        return apply_filters(
707
-            'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
708
-            $registration_time_limit
709
-        );
710
-    }
711
-
712
-
713
-    /**
714
-     * payment_required
715
-     *
716
-     * @return boolean
717
-     */
718
-    public function payment_required()
719
-    {
720
-        // if NOT:
721
-        //     registration via admin
722
-        //      completed TXN
723
-        //      overpaid TXN
724
-        //      free TXN(total = 0.00)
725
-        //      then payment required is TRUE
726
-        return ! ($this->admin_request
727
-                  || $this->transaction->is_completed()
728
-                  || $this->transaction->is_overpaid()
729
-                  || $this->transaction->is_free()) ? true : false;
730
-    }
731
-
732
-
733
-    /**
734
-     * get_cart_for_transaction
735
-     *
736
-     * @access public
737
-     * @param EE_Transaction $transaction
738
-     * @return EE_Cart
739
-     */
740
-    public function get_cart_for_transaction($transaction)
741
-    {
742
-        $session = EE_Registry::instance()->load_core('Session');
743
-        $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
744
-        // verify cart
745
-        if (! $cart instanceof EE_Cart) {
746
-            $cart = EE_Registry::instance()->load_core('Cart');
747
-        }
748
-
749
-        return $cart;
750
-    }
751
-
752
-
753
-    /**
754
-     *    initialize_txn_reg_steps_array
755
-     *
756
-     * @access public
757
-     * @return    array
758
-     */
759
-    public function initialize_txn_reg_steps_array()
760
-    {
761
-        $txn_reg_steps_array = array();
762
-        foreach ($this->reg_steps as $reg_step) {
763
-            $txn_reg_steps_array[ $reg_step->slug() ] = false;
764
-        }
765
-        return $txn_reg_steps_array;
766
-    }
767
-
768
-
769
-    /**
770
-     *    update_txn_reg_steps_array
771
-     *
772
-     * @access public
773
-     * @return    bool
774
-     * @throws \EE_Error
775
-     */
776
-    public function update_txn_reg_steps_array()
777
-    {
778
-        $updated = false;
779
-        foreach ($this->reg_steps as $reg_step) {
780
-            if ($reg_step->completed()) {
781
-                $updated = $this->transaction->set_reg_step_completed($reg_step->slug())
782
-                    ? true
783
-                    : $updated;
784
-            }
785
-        }
786
-        if ($updated) {
787
-            $this->transaction->save();
788
-        }
789
-        return $updated;
790
-    }
791
-
792
-
793
-    /**
794
-     *    stash_transaction_and_checkout
795
-     *
796
-     * @access public
797
-     * @return    void
798
-     * @throws \EE_Error
799
-     */
800
-    public function stash_transaction_and_checkout()
801
-    {
802
-        if (! $this->revisit) {
803
-            $this->update_txn_reg_steps_array();
804
-        }
805
-        $this->track_transaction_and_registration_status_updates();
806
-        // save all data to the db, but suppress errors
807
-        // $this->save_all_data( FALSE );
808
-        // cache the checkout in the session
809
-        EE_Registry::instance()->SSN->set_checkout($this);
810
-    }
811
-
812
-
813
-    /**
814
-     *    track_transaction_and_registration_status_updates
815
-     *    stores whether any updates were made to the TXN or it's related registrations
816
-     *
817
-     * @access public
818
-     * @return void
819
-     * @throws \EE_Error
820
-     */
821
-    public function track_transaction_and_registration_status_updates()
822
-    {
823
-        // verify the transaction
824
-        if ($this->transaction instanceof EE_Transaction) {
825
-            // has there been a TXN status change during this checkout?
826
-            $this->txn_status_updated = $this->transaction->txn_status_updated();
827
-            /** @type EE_Registration_Processor $registration_processor */
828
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
829
-            // grab the saved registrations from the transaction
830
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
831
-                if ($registration_processor->reg_status_updated($registration->ID())) {
832
-                    $this->set_reg_status_updated($registration->ID(), true);
833
-                }
834
-            }
835
-        }
836
-    }
837
-
838
-
839
-    /**
840
-     *    visit_allows_processing_of_this_registration
841
-     *    determines if the current SPCO visit should allow the passed EE_Registration to be used in processing.
842
-     *    one of the following conditions must be met:
843
-     *        EITHER:    A) first time thru SPCO -> process ALL registrations ( NOT a revisit )
844
-     *        OR :        B) primary registrant is editing info -> process ALL registrations ( primary_revisit )
845
-     *        OR :        C) another registrant is editing info -> ONLY process their registration ( revisit AND their
846
-     *        reg_url_link matches )
847
-     *
848
-     * @access public
849
-     * @param    EE_Registration $registration
850
-     * @return    bool
851
-     * @throws \EE_Error
852
-     */
853
-    public function visit_allows_processing_of_this_registration(EE_Registration $registration)
854
-    {
855
-        return ! $this->revisit
856
-               || $this->primary_revisit
857
-               || (
858
-                   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
859
-               )
860
-            ? true
861
-            : false;
862
-    }
863
-
864
-
865
-    /**
866
-     *    _transaction_has_primary_registration
867
-     *
868
-     * @access        private
869
-     * @return        bool
870
-     */
871
-    public function transaction_has_primary_registrant()
872
-    {
873
-        return $this->primary_attendee_obj instanceof EE_Attendee ? true : false;
874
-    }
875
-
876
-
877
-    /**
878
-     *    save_all_data
879
-     *    simply loops through the current transaction and saves all data for each registration
880
-     *
881
-     * @access public
882
-     * @param bool $show_errors
883
-     * @return bool
884
-     * @throws \EE_Error
885
-     */
886
-    public function save_all_data($show_errors = true)
887
-    {
888
-        // verify the transaction
889
-        if ($this->transaction instanceof EE_Transaction) {
890
-            // save to ensure that TXN has ID
891
-            $this->transaction->save();
892
-            // grab the saved registrations from the transaction
893
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
894
-                $this->_save_registration($registration, $show_errors);
895
-            }
896
-        } else {
897
-            if ($show_errors) {
898
-                EE_Error::add_error(
899
-                    __(
900
-                        'A valid Transaction was not found when attempting to save your registration information.',
901
-                        'event_espresso'
902
-                    ),
903
-                    __FILE__,
904
-                    __FUNCTION__,
905
-                    __LINE__
906
-                );
907
-            }
908
-            return false;
909
-        }
910
-        return true;
911
-    }
912
-
913
-
914
-    /**
915
-     * _save_registration_attendee
916
-     *
917
-     * @param    EE_Registration $registration
918
-     * @param bool               $show_errors
919
-     * @return void
920
-     * @throws \EE_Error
921
-     */
922
-    private function _save_registration($registration, $show_errors = true)
923
-    {
924
-        // verify object
925
-        if ($registration instanceof EE_Registration) {
926
-            // should this registration be processed during this visit ?
927
-            if ($this->visit_allows_processing_of_this_registration($registration)) {
928
-                // set TXN ID
929
-                if (! $registration->transaction_ID()) {
930
-                    $registration->set_transaction_id($this->transaction->ID());
931
-                }
932
-                // verify and save the attendee
933
-                $this->_save_registration_attendee($registration, $show_errors);
934
-                // save answers to reg form questions
935
-                $this->_save_registration_answers($registration, $show_errors);
936
-                // save changes
937
-                $registration->save();
938
-                // update txn cache
939
-                if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
940
-                    if ($show_errors) {
941
-                        EE_Error::add_error(
942
-                            __(
943
-                                'The newly saved Registration object could not be cached on the Transaction.',
944
-                                'event_espresso'
945
-                            ),
946
-                            __FILE__,
947
-                            __FUNCTION__,
948
-                            __LINE__
949
-                        );
950
-                    }
951
-                }
952
-            }
953
-        } else {
954
-            if ($show_errors) {
955
-                EE_Error::add_error(
956
-                    __(
957
-                        'An invalid Registration object was discovered when attempting to save your registration information.',
958
-                        'event_espresso'
959
-                    ),
960
-                    __FILE__,
961
-                    __FUNCTION__,
962
-                    __LINE__
963
-                );
964
-            }
965
-        }
966
-    }
967
-
968
-
969
-    /**
970
-     * _save_registration_attendee
971
-     *
972
-     * @param    EE_Registration $registration
973
-     * @param bool               $show_errors
974
-     * @return void
975
-     * @throws \EE_Error
976
-     */
977
-    private function _save_registration_attendee($registration, $show_errors = true)
978
-    {
979
-        if ($registration->attendee() instanceof EE_Attendee) {
980
-            // save so that ATT has ID
981
-            $registration->attendee()->save();
982
-            if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
983
-                if ($show_errors) {
984
-                    EE_Error::add_error(
985
-                        __(
986
-                            'The newly saved Attendee object could not be cached on the registration.',
987
-                            'event_espresso'
988
-                        ),
989
-                        __FILE__,
990
-                        __FUNCTION__,
991
-                        __LINE__
992
-                    );
993
-                }
994
-            }
995
-        } else {
996
-            if ($show_errors) {
997
-                EE_Error::add_error(
998
-                    sprintf(
999
-                        '%1$s||%1$s $attendee = %2$s',
1000
-                        __(
1001
-                            'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.',
1002
-                            'event_espresso'
1003
-                        ),
1004
-                        var_export($registration->attendee(), true)
1005
-                    ),
1006
-                    __FILE__,
1007
-                    __FUNCTION__,
1008
-                    __LINE__
1009
-                );
1010
-            }
1011
-        }
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * _save_question_answers
1017
-     *
1018
-     * @param    EE_Registration $registration
1019
-     * @param bool               $show_errors
1020
-     * @return void
1021
-     * @throws \EE_Error
1022
-     */
1023
-    private function _save_registration_answers($registration, $show_errors = true)
1024
-    {
1025
-        // now save the answers
1026
-        foreach ($registration->answers() as $cache_key => $answer) {
1027
-            // verify object
1028
-            if ($answer instanceof EE_Answer) {
1029
-                $answer->set_registration($registration->ID());
1030
-                $answer->save();
1031
-                if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1032
-                    if ($show_errors) {
1033
-                        EE_Error::add_error(
1034
-                            __(
1035
-                                'The newly saved Answer object could not be cached on the registration.',
1036
-                                'event_espresso'
1037
-                            ),
1038
-                            __FILE__,
1039
-                            __FUNCTION__,
1040
-                            __LINE__
1041
-                        );
1042
-                    }
1043
-                }
1044
-            } else {
1045
-                if ($show_errors) {
1046
-                    EE_Error::add_error(
1047
-                        __(
1048
-                            'An invalid Answer object was discovered when attempting to save your registration information.',
1049
-                            'event_espresso'
1050
-                        ),
1051
-                        __FILE__,
1052
-                        __FUNCTION__,
1053
-                        __LINE__
1054
-                    );
1055
-                }
1056
-            }
1057
-        }
1058
-    }
1059
-
1060
-
1061
-    /**
1062
-     *    refresh_all_entities
1063
-     *   will either refresh the entity map with objects form the db or from the checkout cache
1064
-     *
1065
-     * @access public
1066
-     * @param bool $from_db
1067
-     * @return bool
1068
-     * @throws \EE_Error
1069
-     */
1070
-    public function refresh_all_entities($from_db = false)
1071
-    {
1072
-        $from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
1073
-            ? true
1074
-            : $from_db;
1075
-        // $this->log(
1076
-        //     __CLASS__,
1077
-        //     __FUNCTION__,
1078
-        //     __LINE__,
1079
-        //     array('from_db' => $from_db)
1080
-        // );
1081
-        return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map();
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     *  refresh_entity_map
1087
-     *  simply loops through the current transaction and updates each
1088
-     *  model's entity map using EEM_Base::refresh_entity_map_from_db()
1089
-     *
1090
-     * @access public
1091
-     * @return bool
1092
-     * @throws \EE_Error
1093
-     */
1094
-    protected function refresh_from_db()
1095
-    {
1096
-        // verify the transaction
1097
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1098
-            // pull fresh TXN data from the db
1099
-            $this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1100
-            // update EE_Checkout's cached primary_attendee object
1101
-            $this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1102
-            // update EE_Checkout's cached payment object
1103
-            $payment = $this->transaction->last_payment();
1104
-            $this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
1105
-            // update EE_Checkout's cached payment_method object
1106
-            $payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1107
-            $this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method
1108
-                : $this->payment_method;
1109
-            // now refresh the cart, based on the TXN
1110
-            $this->cart = $this->get_cart_for_transaction($this->transaction);
1111
-        } else {
1112
-            EE_Error::add_error(
1113
-                __(
1114
-                    'A valid Transaction was not found when attempting to update the model entity mapper.',
1115
-                    'event_espresso'
1116
-                ),
1117
-                __FILE__,
1118
-                __FUNCTION__,
1119
-                __LINE__
1120
-            );
1121
-            return false;
1122
-        }
1123
-        return true;
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * _refresh_primary_attendee_obj_from_db
1129
-     *
1130
-     * @param   EE_Transaction $transaction
1131
-     * @return  EE_Attendee | null
1132
-     * @throws \EE_Error
1133
-     */
1134
-    protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction)
1135
-    {
1136
-
1137
-        $primary_attendee_obj = null;
1138
-        // grab the saved registrations from the transaction
1139
-        foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1140
-            // verify object
1141
-            if ($registration instanceof EE_Registration) {
1142
-                $attendee = $registration->attendee();
1143
-                // verify object && maybe cache primary_attendee_obj ?
1144
-                if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1145
-                    $primary_attendee_obj = $attendee;
1146
-                }
1147
-            } else {
1148
-                EE_Error::add_error(
1149
-                    __(
1150
-                        'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1151
-                        'event_espresso'
1152
-                    ),
1153
-                    __FILE__,
1154
-                    __FUNCTION__,
1155
-                    __LINE__
1156
-                );
1157
-            }
1158
-        }
1159
-        return $primary_attendee_obj;
1160
-    }
1161
-
1162
-
1163
-    /**
1164
-     *  refresh_entity_map
1165
-     *  simply loops through the current transaction and updates
1166
-     *  each model's entity map using EEM_Base::refresh_entity_map_with()
1167
-     *
1168
-     * @access public
1169
-     * @return bool
1170
-     * @throws \EE_Error
1171
-     */
1172
-    protected function refresh_entity_map()
1173
-    {
1174
-        // verify the transaction
1175
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1176
-            // never cache payment info
1177
-            $this->transaction->clear_cache('Payment');
1178
-            // is the Payment Options Reg Step completed ?
1179
-            if ($this->transaction->reg_step_completed('payment_options')) {
1180
-                // then check for payments and update TXN accordingly
1181
-                /** @type EE_Transaction_Payments $transaction_payments */
1182
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1183
-                $transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1184
-            }
1185
-            // grab the saved registrations from the transaction
1186
-            foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) {
1187
-                $this->_refresh_registration($reg_cache_ID, $registration);
1188
-            }
1189
-            // make sure our cached TXN is added to the model entity mapper
1190
-            $this->transaction = $this->transaction->get_model()->refresh_entity_map_with(
1191
-                $this->transaction->ID(),
1192
-                $this->transaction
1193
-            );
1194
-        } else {
1195
-            EE_Error::add_error(
1196
-                __(
1197
-                    'A valid Transaction was not found when attempting to update the model entity mapper.',
1198
-                    'event_espresso'
1199
-                ),
1200
-                __FILE__,
1201
-                __FUNCTION__,
1202
-                __LINE__
1203
-            );
1204
-            return false;
1205
-        }
1206
-        // verify and update the cart because inaccurate totals are not so much fun
1207
-        if ($this->cart instanceof EE_Cart) {
1208
-            $grand_total = $this->cart->get_grand_total();
1209
-            if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1210
-                $grand_total->recalculate_total_including_taxes();
1211
-                $grand_total = $grand_total->get_model()->refresh_entity_map_with(
1212
-                    $this->cart->get_grand_total()->ID(),
1213
-                    $this->cart->get_grand_total()
1214
-                );
1215
-            }
1216
-            if ($grand_total instanceof EE_Line_Item) {
1217
-                $this->cart = EE_Cart::instance($grand_total);
1218
-            } else {
1219
-                EE_Error::add_error(
1220
-                    __(
1221
-                        'A valid Cart was not found when attempting to update the model entity mapper.',
1222
-                        'event_espresso'
1223
-                    ),
1224
-                    __FILE__,
1225
-                    __FUNCTION__,
1226
-                    __LINE__
1227
-                );
1228
-                return false;
1229
-            }
1230
-        }
1231
-        return true;
1232
-    }
1233
-
1234
-
1235
-    /**
1236
-     * _refresh_registration
1237
-     *
1238
-     * @param    string | int    $reg_cache_ID
1239
-     * @param    EE_Registration $registration
1240
-     * @return void
1241
-     * @throws \EE_Error
1242
-     */
1243
-    protected function _refresh_registration($reg_cache_ID, $registration)
1244
-    {
1245
-
1246
-        // verify object
1247
-        if ($registration instanceof EE_Registration) {
1248
-            // update the entity mapper attendee
1249
-            $this->_refresh_registration_attendee($registration);
1250
-            // update the entity mapper answers for reg form questions
1251
-            $this->_refresh_registration_answers($registration);
1252
-            // make sure the cached registration is added to the model entity mapper
1253
-            $registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1254
-        } else {
1255
-            EE_Error::add_error(
1256
-                __(
1257
-                    'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1258
-                    'event_espresso'
1259
-                ),
1260
-                __FILE__,
1261
-                __FUNCTION__,
1262
-                __LINE__
1263
-            );
1264
-        }
1265
-    }
1266
-
1267
-
1268
-    /**
1269
-     * _save_registration_attendee
1270
-     *
1271
-     * @param    EE_Registration $registration
1272
-     * @return void
1273
-     * @throws \EE_Error
1274
-     */
1275
-    protected function _refresh_registration_attendee($registration)
1276
-    {
1277
-
1278
-        $attendee = $registration->attendee();
1279
-        // verify object
1280
-        if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1281
-            // make sure the cached attendee is added to the model entity mapper
1282
-            $registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1283
-            // maybe cache primary_attendee_obj ?
1284
-            if ($registration->is_primary_registrant()) {
1285
-                $this->primary_attendee_obj = $attendee;
1286
-            }
1287
-        }
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * _refresh_registration_answers
1293
-     *
1294
-     * @param    EE_Registration $registration
1295
-     * @return void
1296
-     * @throws \EE_Error
1297
-     */
1298
-    protected function _refresh_registration_answers($registration)
1299
-    {
1300
-
1301
-        // now update the answers
1302
-        foreach ($registration->answers() as $cache_key => $answer) {
1303
-            // verify object
1304
-            if ($answer instanceof EE_Answer) {
1305
-                if ($answer->ID()) {
1306
-                    // make sure the cached answer is added to the model entity mapper
1307
-                    $answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1308
-                }
1309
-            } else {
1310
-                EE_Error::add_error(
1311
-                    __(
1312
-                        'An invalid Answer object was discovered when attempting to update the model entity mapper.',
1313
-                        'event_espresso'
1314
-                    ),
1315
-                    __FILE__,
1316
-                    __FUNCTION__,
1317
-                    __LINE__
1318
-                );
1319
-            }
1320
-        }
1321
-    }
1322
-
1323
-
1324
-    /**
1325
-     *    __sleep
1326
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
1327
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
1328
-     * reg form, because if needed, it will be regenerated anyways
1329
-     *
1330
-     * @return array
1331
-     * @throws \EE_Error
1332
-     */
1333
-    public function __sleep()
1334
-    {
1335
-        if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1336
-            $this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1337
-        }        // remove the reg form and the checkout
1338
-        if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1339
-            $this->transaction = $this->transaction->ID();
1340
-        }        // remove the reg form and the checkout
1341
-        return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1342
-    }
1343
-
1344
-
1345
-    /**
1346
-     *    __wakeup
1347
-     * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
1348
-     * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1349
-     */
1350
-    public function __wakeup()
1351
-    {
1352
-        if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1353
-            // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1354
-            $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1355
-        }
1356
-        if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1357
-            // $this->transaction is actually just an ID, so use it to get the object from the db
1358
-            $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1359
-        }
1360
-        foreach ($this->reg_steps as $reg_step) {
1361
-            $reg_step->checkout = $this;
1362
-        }
1363
-    }
1364
-
1365
-
1366
-    /**
1367
-     * debug
1368
-     *
1369
-     * @param string $class
1370
-     * @param string $func
1371
-     * @param string $line
1372
-     * @param array  $info
1373
-     * @param bool   $display_request
1374
-     * @throws \EE_Error
1375
-     */
1376
-    public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false)
1377
-    {
1378
-        $disabled = true;
1379
-        if (WP_DEBUG && ! $disabled) {
1380
-            $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
1381
-            $default_data = array(
1382
-                $class                    => $func . '() : ' . $line,
1383
-                'request->step'           => $this->step,
1384
-                'request->action'         => $this->action,
1385
-                'current_step->slug'      => $this->current_step instanceof EE_SPCO_Reg_Step ?
1386
-                    $this->current_step->slug() : '',
1387
-                'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ?
1388
-                    $this->current_step->completed() : '',
1389
-                'txn_status_updated'      => $this->transaction->txn_status_updated(),
1390
-                'reg_status_updated'      => $this->reg_status_updated,
1391
-                'reg_url_link'            => $this->reg_url_link,
1392
-                'REQ'                     => $display_request ? $_REQUEST : '',
1393
-            );
1394
-            if ($this->transaction instanceof EE_Transaction) {
1395
-                $default_data['TXN_status'] = $this->transaction->status_ID();
1396
-                $default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1397
-                foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1398
-                    $default_data['registrations'][ $REG_ID ] = $registration->status_ID();
1399
-                }
1400
-                if ($this->transaction->ID()) {
1401
-                    $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1402
-                    // don't serialize objects
1403
-                    $info = $this->_strip_objects($info);
1404
-                    if (! isset($debug_data[ $TXN_ID ])) {
1405
-                        $debug_data[ $TXN_ID ] = array();
1406
-                    }
1407
-                    $debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1408
-                        $default_data,
1409
-                        $info
1410
-                    );
1411
-                    update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
1412
-                }
1413
-            }
1414
-        }
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * _strip_objects
1420
-     *
1421
-     * @param array $info
1422
-     * @return array
1423
-     */
1424
-    public function _strip_objects($info = array())
1425
-    {
1426
-        foreach ((array) $info as $key => $value) {
1427
-            if (is_array($value)) {
1428
-                $info[ $key ] = $this->_strip_objects($value);
1429
-            } elseif (is_object($value)) {
1430
-                $object_class = get_class($value);
1431
-                $info[ $object_class ] = array();
1432
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1433
-                if (method_exists($value, 'status')) {
1434
-                    $info[ $object_class ]['status'] = $value->status();
1435
-                } elseif (method_exists($value, 'status_ID')) {
1436
-                    $info[ $object_class ]['status'] = $value->status_ID();
1437
-                }
1438
-                unset($info[ $key ]);
1439
-            }
1440
-        }
1441
-        return (array) $info;
1442
-    }
18
+	/**
19
+	 *    whether current request originated from the EE admin
20
+	 *
21
+	 * @type bool
22
+	 */
23
+	public $admin_request = false;
24
+
25
+	/**
26
+	 * whether returning to edit attendee information or to retry a payment
27
+	 *
28
+	 * @type bool
29
+	 */
30
+	public $revisit = false;
31
+
32
+	/**
33
+	 * whether the primary registrant is returning to edit attendee information or to retry a payment
34
+	 *
35
+	 * @type bool
36
+	 */
37
+	public $primary_revisit = false;
38
+
39
+	/**
40
+	 * is registration allowed to progress or halted for some reason such as failing to pass recaptcha?
41
+	 *
42
+	 * @type bool
43
+	 */
44
+	public $continue_reg = true;
45
+
46
+	/**
47
+	 * redirect to thank you page ?
48
+	 *
49
+	 * @type bool
50
+	 */
51
+	public $redirect = false;
52
+
53
+	/**
54
+	 * generate the reg form or not ?
55
+	 *
56
+	 * @type bool
57
+	 */
58
+	public $generate_reg_form = true;
59
+
60
+	/**
61
+	 * process a reg form submission or not ?
62
+	 *
63
+	 * @type bool
64
+	 */
65
+	public $process_form_submission = false;
66
+
67
+	/**
68
+	 * tracks whether the TXN status modified during this checkout
69
+	 *
70
+	 * @type bool
71
+	 */
72
+	public $txn_status_updated = false;
73
+
74
+	/**
75
+	 * only triggered to true after absolutely everything has finished.
76
+	 *
77
+	 * @type bool
78
+	 */
79
+	protected $exit_spco = false;
80
+
81
+	/**
82
+	 * tracks whether any of the TXN's Registrations statuses modified during this checkout
83
+	 * indexed by registration ID
84
+	 *
85
+	 * @type array
86
+	 */
87
+	protected $reg_status_updated = array();
88
+
89
+	/**
90
+	 * timestamp when redirected from Ticket Selector to the checkout
91
+	 *
92
+	 * @type int
93
+	 */
94
+	public $uts = 0;
95
+
96
+	/**
97
+	 * total number of tickets that were in the cart
98
+	 *
99
+	 * @type int
100
+	 */
101
+	public $total_ticket_count = 0;
102
+
103
+	/**
104
+	 * corresponds loosely to EE_Transaction::remaining()
105
+	 * but can be modified by SPCO
106
+	 *
107
+	 * @type float
108
+	 */
109
+	public $amount_owing = 0;
110
+
111
+	/**
112
+	 * the reg step slug from the incoming request
113
+	 *
114
+	 * @type string
115
+	 */
116
+	public $step = '';
117
+
118
+	/**
119
+	 * the reg step slug for a step being edited
120
+	 *
121
+	 * @type string
122
+	 */
123
+	public $edit_step = '';
124
+
125
+	/**
126
+	 * the action being performed on the current step
127
+	 *
128
+	 * @type string
129
+	 */
130
+	public $action = '';
131
+
132
+	/**
133
+	 * reg_url_link for a previously saved registration
134
+	 *
135
+	 * @type string
136
+	 */
137
+	public $reg_url_link = '';
138
+
139
+	/**
140
+	 * string slug for the payment method that was selected during the payment options step
141
+	 *
142
+	 * @type string
143
+	 */
144
+	public $selected_method_of_payment = '';
145
+
146
+	/**
147
+	 * base url for the site's registration checkout page - additional url params will be added to this
148
+	 *
149
+	 * @type string
150
+	 */
151
+	public $reg_page_base_url = '';
152
+
153
+	/**
154
+	 * base url for the site's registration cancelled page - additional url params will be added to this
155
+	 *
156
+	 * @type string
157
+	 */
158
+	public $cancel_page_url = '';
159
+
160
+	/**
161
+	 * base url for the site's thank you page - additional url params will be added to this
162
+	 *
163
+	 * @type string
164
+	 */
165
+	public $thank_you_page_url = '';
166
+
167
+	/**
168
+	 * base url for any redirects - additional url params will be added to this
169
+	 *
170
+	 * @type string
171
+	 */
172
+	public $redirect_url = '';
173
+
174
+	/**
175
+	 * form of POST data for use with off-site gateways
176
+	 *
177
+	 * @type string
178
+	 */
179
+	public $redirect_form = '';
180
+
181
+	/**
182
+	 * array of query where params to use when retrieving cached registrations from $this->checkout->transaction
183
+	 *
184
+	 * @type array
185
+	 */
186
+	public $reg_cache_where_params = array();
187
+
188
+	/**
189
+	 * a class for managing and creating the JSON encoded array of data that gets passed back to the client during AJAX
190
+	 * requests
191
+	 *
192
+	 * @type EE_SPCO_JSON_Response
193
+	 */
194
+	public $json_response;
195
+
196
+	/**
197
+	 * where we are going next in the reg process
198
+	 *
199
+	 * @type EE_SPCO_Reg_Step
200
+	 */
201
+	public $next_step;
202
+
203
+	/**
204
+	 * where we are in the reg process
205
+	 *
206
+	 * @type EE_SPCO_Reg_Step
207
+	 */
208
+	public $current_step;
209
+
210
+	/**
211
+	 *    $_cart - the current cart object
212
+	 *
213
+	 * @var EE_CART
214
+	 */
215
+	public $cart;
216
+
217
+	/**
218
+	 *    $_transaction - the current transaction object
219
+	 *
220
+	 * @var EE_Transaction
221
+	 */
222
+	public $transaction;
223
+
224
+	/**
225
+	 *    the related attendee object for the primary registrant
226
+	 *
227
+	 * @type EE_Attendee
228
+	 */
229
+	public $primary_attendee_obj;
230
+
231
+	/**
232
+	 *    $payment_method - the payment method object for the selected method of payment
233
+	 *
234
+	 * @type EE_Payment_Method
235
+	 */
236
+	public $payment_method;
237
+
238
+	/**
239
+	 *    $payment - if a payment was successfully made during the reg process,
240
+	 *    then here it is !!!
241
+	 *
242
+	 * @type EE_Payment
243
+	 */
244
+	public $payment;
245
+
246
+	/**
247
+	 *    if a payment method was selected that uses an on-site gateway, then this is the billing form
248
+	 *
249
+	 * @type EE_Billing_Info_Form | EE_Billing_Attendee_Info_Form
250
+	 */
251
+	public $billing_form;
252
+
253
+	/**
254
+	 *    the entire registration form composed of ALL of the subsections generated by the various reg steps
255
+	 *
256
+	 * @type EE_Form_Section_Proper
257
+	 */
258
+	public $registration_form;
259
+
260
+	/**
261
+	 * array of EE_SPCO_Reg_Step objects
262
+	 *
263
+	 * @type EE_SPCO_Reg_Step[]
264
+	 */
265
+	public $reg_steps = array();
266
+
267
+	/**
268
+	 * array of EE_Payment_Method objects
269
+	 *
270
+	 * @type EE_Payment_Method[]
271
+	 */
272
+	public $available_payment_methods = array();
273
+
274
+
275
+	/**
276
+	 *    class constructor
277
+	 *
278
+	 * @access    public
279
+	 */
280
+	public function __construct()
281
+	{
282
+		$this->reg_page_base_url = EE_Registry::instance()->CFG->core->reg_page_url();
283
+		$this->thank_you_page_url = EE_Registry::instance()->CFG->core->thank_you_page_url();
284
+		$this->cancel_page_url = EE_Registry::instance()->CFG->core->cancel_page_url();
285
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
286
+		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->ajax;
287
+		$this->reg_cache_where_params = array(
288
+			0          => array('REG_deleted' => false),
289
+			'order_by' => array('REG_count' => 'ASC'),
290
+		);
291
+	}
292
+
293
+
294
+	/**
295
+	 * returns true if ANY reg status was updated during checkout
296
+	 *
297
+	 * @return boolean
298
+	 */
299
+	public function any_reg_status_updated()
300
+	{
301
+		foreach ($this->reg_status_updated as $reg_status) {
302
+			if ($reg_status) {
303
+				return true;
304
+			}
305
+		}
306
+		return false;
307
+	}
308
+
309
+
310
+	/**
311
+	 * @param $REG_ID
312
+	 * @return boolean
313
+	 */
314
+	public function reg_status_updated($REG_ID)
315
+	{
316
+		return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false;
317
+	}
318
+
319
+
320
+	/**
321
+	 * @param $REG_ID
322
+	 * @param $reg_status
323
+	 */
324
+	public function set_reg_status_updated($REG_ID, $reg_status)
325
+	{
326
+		$this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
327
+	}
328
+
329
+
330
+	/**
331
+	 * exit_spco
332
+	 *
333
+	 * @return bool
334
+	 */
335
+	public function exit_spco()
336
+	{
337
+		return $this->exit_spco;
338
+	}
339
+
340
+
341
+	/**
342
+	 * set_exit_spco
343
+	 * can ONLY be set by the  Finalize_Registration reg step
344
+	 */
345
+	public function set_exit_spco()
346
+	{
347
+		if ($this->current_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
348
+			$this->exit_spco = true;
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 *    reset_for_current_request
355
+	 *
356
+	 * @access    public
357
+	 * @return    void
358
+	 */
359
+	public function reset_for_current_request()
360
+	{
361
+		$this->process_form_submission = false;
362
+		$this->continue_reg = apply_filters('FHEE__EE_Checkout___construct___continue_reg', true);
363
+		$this->admin_request = is_admin() && ! EE_Registry::instance()->REQ->front_ajax;
364
+		$this->continue_reg = true;
365
+		$this->redirect = false;
366
+		// don't reset the cached redirect form if we're about to be asked to display it !!!
367
+		if (EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step') !== 'redirect_form') {
368
+			$this->redirect_form = '';
369
+		}
370
+		$this->redirect_url = '';
371
+		$this->json_response = new EE_SPCO_JSON_Response();
372
+		EE_Form_Section_Proper::reset_js_localization();
373
+	}
374
+
375
+
376
+	/**
377
+	 *    add_reg_step
378
+	 *
379
+	 * @access    public
380
+	 * @param EE_SPCO_Reg_Step $reg_step_obj
381
+	 * @return    void
382
+	 */
383
+	public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj)
384
+	{
385
+		$this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj;
386
+	}
387
+
388
+
389
+	/**
390
+	 * skip_reg_step
391
+	 * if the current reg step does not need to run for some reason,
392
+	 * then this will advance SPCO to the next reg step,
393
+	 * and mark the skipped step as completed
394
+	 *
395
+	 * @access    public
396
+	 * @param string $reg_step_slug
397
+	 * @return    void
398
+	 * @throws \EE_Error
399
+	 */
400
+	public function skip_reg_step($reg_step_slug = '')
401
+	{
402
+		$step_to_skip = $this->find_reg_step($reg_step_slug);
403
+		if ($step_to_skip instanceof EE_SPCO_Reg_Step && $step_to_skip->is_current_step()) {
404
+			$step_to_skip->set_is_current_step(false);
405
+			$step_to_skip->set_completed();
406
+			// advance to the next step
407
+			$this->set_current_step($this->next_step->slug());
408
+			// also reset the step param in the request in case any other code references that directly
409
+			EE_Registry::instance()->REQ->set('step', $this->current_step->slug());
410
+			// since we are skipping a step and setting the current step to be what was previously the next step,
411
+			// we need to check that the next step is now correct, and not still set to the current step.
412
+			if ($this->current_step->slug() === $this->next_step->slug()) {
413
+				// correctly setup the next step
414
+				$this->set_next_step();
415
+			}
416
+			$this->set_reg_step_initiated($this->current_step);
417
+		}
418
+	}
419
+
420
+
421
+	/**
422
+	 *    remove_reg_step
423
+	 *
424
+	 * @access    public
425
+	 * @param string $reg_step_slug
426
+	 * @param bool   $reset whether to reset reg steps after removal
427
+	 * @throws EE_Error
428
+	 */
429
+	public function remove_reg_step($reg_step_slug = '', $reset = true)
430
+	{
431
+		unset($this->reg_steps[ $reg_step_slug ]);
432
+		if ($this->transaction instanceof EE_Transaction) {
433
+			// now remove reg step from TXN and save
434
+			$this->transaction->remove_reg_step($reg_step_slug);
435
+			$this->transaction->save();
436
+		}
437
+		if ($reset) {
438
+			$this->reset_reg_steps();
439
+		}
440
+	}
441
+
442
+
443
+	/**
444
+	 *    set_reg_step_order
445
+	 *
446
+	 * @access    public
447
+	 * @param string $reg_step_slug
448
+	 * @param int    $order
449
+	 * @return    void
450
+	 */
451
+	public function set_reg_step_order($reg_step_slug = '', $order = 100)
452
+	{
453
+		if (isset($this->reg_steps[ $reg_step_slug ])) {
454
+			$this->reg_steps[ $reg_step_slug ]->set_order($order);
455
+		}
456
+	}
457
+
458
+
459
+	/**
460
+	 *    set_current_step
461
+	 *
462
+	 * @access    public
463
+	 * @param string $current_step
464
+	 * @return    void
465
+	 */
466
+	public function set_current_step($current_step)
467
+	{
468
+		// grab what step we're on
469
+		$this->current_step = isset($this->reg_steps[ $current_step ])
470
+			? $this->reg_steps[ $current_step ]
471
+			: reset(
472
+				$this->reg_steps
473
+			);
474
+		// verify instance
475
+		if ($this->current_step instanceof EE_SPCO_Reg_Step) {
476
+			// we don't want to repeat completed steps if this is the first time through SPCO
477
+			if ($this->continue_reg && ! $this->revisit && $this->current_step->completed()) {
478
+				// so advance to the next step
479
+				$this->set_next_step();
480
+				if ($this->next_step instanceof EE_SPCO_Reg_Step) {
481
+					// and attempt to set it as the current step
482
+					$this->set_current_step($this->next_step->slug());
483
+				}
484
+				return;
485
+			}
486
+			$this->current_step->set_is_current_step(true);
487
+		} else {
488
+			EE_Error::add_error(
489
+				__('The current step could not be set.', 'event_espresso'),
490
+				__FILE__,
491
+				__FUNCTION__,
492
+				__LINE__
493
+			);
494
+		}
495
+	}
496
+
497
+
498
+	/**
499
+	 *    set_next_step
500
+	 * advances the reg_steps array pointer and sets the next step, then reverses pointer back to the current step
501
+	 *
502
+	 * @access    public
503
+	 * @return    void
504
+	 */
505
+	public function set_next_step()
506
+	{
507
+		// set pointer to start of array
508
+		reset($this->reg_steps);
509
+		// if there is more than one step
510
+		if (count($this->reg_steps) > 1) {
511
+			// advance to the current step and set pointer
512
+			while (key($this->reg_steps) !== $this->current_step->slug() && key($this->reg_steps) !== '') {
513
+				next($this->reg_steps);
514
+			}
515
+		}
516
+		// advance one more spot ( if it exists )
517
+		$this->next_step = next($this->reg_steps);
518
+		// verify instance
519
+		$this->next_step = $this->next_step instanceof EE_SPCO_Reg_Step ? $this->next_step : null;
520
+		// then back to current step to reset
521
+		prev($this->reg_steps);
522
+	}
523
+
524
+
525
+	/**
526
+	 *    get_next_reg_step
527
+	 *    this simply returns the next step from reg_steps array
528
+	 *
529
+	 * @access    public
530
+	 * @return    EE_SPCO_Reg_Step | null
531
+	 */
532
+	public function get_next_reg_step()
533
+	{
534
+		$next = next($this->reg_steps);
535
+		prev($this->reg_steps);
536
+		return $next instanceof EE_SPCO_Reg_Step ? $next : null;
537
+	}
538
+
539
+
540
+	/**
541
+	 * get_prev_reg_step
542
+	 *    this simply returns the previous step from reg_steps array
543
+	 *
544
+	 * @access    public
545
+	 * @return    EE_SPCO_Reg_Step | null
546
+	 */
547
+	public function get_prev_reg_step()
548
+	{
549
+		$prev = prev($this->reg_steps);
550
+		next($this->reg_steps);
551
+		return $prev instanceof EE_SPCO_Reg_Step ? $prev : null;
552
+	}
553
+
554
+
555
+	/**
556
+	 * sort_reg_steps
557
+	 *
558
+	 * @access public
559
+	 * @return void
560
+	 */
561
+	public function sort_reg_steps()
562
+	{
563
+		$reg_step_sorting_callback = apply_filters(
564
+			'FHEE__EE_Checkout__sort_reg_steps__reg_step_sorting_callback',
565
+			'reg_step_sorting_callback'
566
+		);
567
+		uasort($this->reg_steps, array($this, $reg_step_sorting_callback));
568
+	}
569
+
570
+
571
+	/**
572
+	 * find_reg_step
573
+	 * finds a reg step by the given slug
574
+	 *
575
+	 * @access    public
576
+	 * @param string $reg_step_slug
577
+	 * @return EE_SPCO_Reg_Step|null
578
+	 */
579
+	public function find_reg_step($reg_step_slug = '')
580
+	{
581
+		if (! empty($reg_step_slug)) {
582
+			// copy reg step array
583
+			$reg_steps = $this->reg_steps;
584
+			// set pointer to start of array
585
+			reset($reg_steps);
586
+			// if there is more than one step
587
+			if (count($reg_steps) > 1) {
588
+				// advance to the current step and set pointer
589
+				while (key($reg_steps) !== $reg_step_slug && key($reg_steps) !== '') {
590
+					next($reg_steps);
591
+				}
592
+				return current($reg_steps);
593
+			}
594
+		}
595
+		return null;
596
+	}
597
+
598
+
599
+	/**
600
+	 * reg_step_sorting_callback
601
+	 *
602
+	 * @access public
603
+	 * @param EE_SPCO_Reg_Step $reg_step_A
604
+	 * @param EE_SPCO_Reg_Step $reg_step_B
605
+	 * @return int
606
+	 */
607
+	public function reg_step_sorting_callback(EE_SPCO_Reg_Step $reg_step_A, EE_SPCO_Reg_Step $reg_step_B)
608
+	{
609
+		// send finalize_registration step to the end of the array
610
+		if ($reg_step_A->slug() === 'finalize_registration') {
611
+			return 1;
612
+		} elseif ($reg_step_B->slug() === 'finalize_registration') {
613
+			return -1;
614
+		}
615
+		if ($reg_step_A->order() === $reg_step_B->order()) {
616
+			return 0;
617
+		}
618
+		return ($reg_step_A->order() > $reg_step_B->order()) ? 1 : -1;
619
+	}
620
+
621
+
622
+	/**
623
+	 * set_reg_step_initiated
624
+	 *
625
+	 * @access    public
626
+	 * @param    EE_SPCO_Reg_Step $reg_step
627
+	 * @throws \EE_Error
628
+	 */
629
+	public function set_reg_step_initiated(EE_SPCO_Reg_Step $reg_step)
630
+	{
631
+		// call set_reg_step_initiated ???
632
+		if (// first time visiting SPCO ?
633
+			! $this->revisit
634
+			&& (
635
+				// and displaying the reg step form for the first time ?
636
+				$this->action === 'display_spco_reg_step'
637
+				// or initializing the final step
638
+				|| $reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration
639
+			)
640
+		) {
641
+			// set the start time for this reg step
642
+			if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
643
+				if (WP_DEBUG) {
644
+					EE_Error::add_error(
645
+						sprintf(
646
+							__('The "%1$s" registration step was not initialized properly.', 'event_espresso'),
647
+							$reg_step->name()
648
+						),
649
+						__FILE__,
650
+						__FUNCTION__,
651
+						__LINE__
652
+					);
653
+				}
654
+			}
655
+		}
656
+	}
657
+
658
+
659
+	/**
660
+	 *    set_reg_step_JSON_info
661
+	 *
662
+	 * @access public
663
+	 * @return    void
664
+	 */
665
+	public function set_reg_step_JSON_info()
666
+	{
667
+		EE_Registry::$i18n_js_strings['reg_steps'] = array();
668
+		// pass basic reg step data to JS
669
+		foreach ($this->reg_steps as $reg_step) {
670
+			EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step->slug();
671
+		}
672
+		// reset reg step html
673
+		// $this->json_response->set_reg_step_html('');
674
+	}
675
+
676
+
677
+	/**
678
+	 *    reset_reg_steps
679
+	 *
680
+	 * @access public
681
+	 * @return void
682
+	 */
683
+	public function reset_reg_steps()
684
+	{
685
+		$this->sort_reg_steps();
686
+		$this->set_current_step(EE_Registry::instance()->REQ->get('step'));
687
+		$this->set_next_step();
688
+		// the text that appears on the reg step form submit button
689
+		$this->current_step->set_submit_button_text();
690
+		$this->set_reg_step_JSON_info();
691
+	}
692
+
693
+
694
+	/**
695
+	 *    get_registration_time_limit
696
+	 *
697
+	 * @access    public
698
+	 * @return        string
699
+	 */
700
+	public function get_registration_time_limit()
701
+	{
702
+
703
+		$registration_time_limit = (float) (EE_Registry::instance()->SSN->expiration() - time());
704
+		$time_limit_format = $registration_time_limit > 60 * MINUTE_IN_SECONDS ? 'H:i:s' : 'i:s';
705
+		$registration_time_limit = date($time_limit_format, $registration_time_limit);
706
+		return apply_filters(
707
+			'FHEE__EE_Checkout__get_registration_time_limit__registration_time_limit',
708
+			$registration_time_limit
709
+		);
710
+	}
711
+
712
+
713
+	/**
714
+	 * payment_required
715
+	 *
716
+	 * @return boolean
717
+	 */
718
+	public function payment_required()
719
+	{
720
+		// if NOT:
721
+		//     registration via admin
722
+		//      completed TXN
723
+		//      overpaid TXN
724
+		//      free TXN(total = 0.00)
725
+		//      then payment required is TRUE
726
+		return ! ($this->admin_request
727
+				  || $this->transaction->is_completed()
728
+				  || $this->transaction->is_overpaid()
729
+				  || $this->transaction->is_free()) ? true : false;
730
+	}
731
+
732
+
733
+	/**
734
+	 * get_cart_for_transaction
735
+	 *
736
+	 * @access public
737
+	 * @param EE_Transaction $transaction
738
+	 * @return EE_Cart
739
+	 */
740
+	public function get_cart_for_transaction($transaction)
741
+	{
742
+		$session = EE_Registry::instance()->load_core('Session');
743
+		$cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
744
+		// verify cart
745
+		if (! $cart instanceof EE_Cart) {
746
+			$cart = EE_Registry::instance()->load_core('Cart');
747
+		}
748
+
749
+		return $cart;
750
+	}
751
+
752
+
753
+	/**
754
+	 *    initialize_txn_reg_steps_array
755
+	 *
756
+	 * @access public
757
+	 * @return    array
758
+	 */
759
+	public function initialize_txn_reg_steps_array()
760
+	{
761
+		$txn_reg_steps_array = array();
762
+		foreach ($this->reg_steps as $reg_step) {
763
+			$txn_reg_steps_array[ $reg_step->slug() ] = false;
764
+		}
765
+		return $txn_reg_steps_array;
766
+	}
767
+
768
+
769
+	/**
770
+	 *    update_txn_reg_steps_array
771
+	 *
772
+	 * @access public
773
+	 * @return    bool
774
+	 * @throws \EE_Error
775
+	 */
776
+	public function update_txn_reg_steps_array()
777
+	{
778
+		$updated = false;
779
+		foreach ($this->reg_steps as $reg_step) {
780
+			if ($reg_step->completed()) {
781
+				$updated = $this->transaction->set_reg_step_completed($reg_step->slug())
782
+					? true
783
+					: $updated;
784
+			}
785
+		}
786
+		if ($updated) {
787
+			$this->transaction->save();
788
+		}
789
+		return $updated;
790
+	}
791
+
792
+
793
+	/**
794
+	 *    stash_transaction_and_checkout
795
+	 *
796
+	 * @access public
797
+	 * @return    void
798
+	 * @throws \EE_Error
799
+	 */
800
+	public function stash_transaction_and_checkout()
801
+	{
802
+		if (! $this->revisit) {
803
+			$this->update_txn_reg_steps_array();
804
+		}
805
+		$this->track_transaction_and_registration_status_updates();
806
+		// save all data to the db, but suppress errors
807
+		// $this->save_all_data( FALSE );
808
+		// cache the checkout in the session
809
+		EE_Registry::instance()->SSN->set_checkout($this);
810
+	}
811
+
812
+
813
+	/**
814
+	 *    track_transaction_and_registration_status_updates
815
+	 *    stores whether any updates were made to the TXN or it's related registrations
816
+	 *
817
+	 * @access public
818
+	 * @return void
819
+	 * @throws \EE_Error
820
+	 */
821
+	public function track_transaction_and_registration_status_updates()
822
+	{
823
+		// verify the transaction
824
+		if ($this->transaction instanceof EE_Transaction) {
825
+			// has there been a TXN status change during this checkout?
826
+			$this->txn_status_updated = $this->transaction->txn_status_updated();
827
+			/** @type EE_Registration_Processor $registration_processor */
828
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
829
+			// grab the saved registrations from the transaction
830
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
831
+				if ($registration_processor->reg_status_updated($registration->ID())) {
832
+					$this->set_reg_status_updated($registration->ID(), true);
833
+				}
834
+			}
835
+		}
836
+	}
837
+
838
+
839
+	/**
840
+	 *    visit_allows_processing_of_this_registration
841
+	 *    determines if the current SPCO visit should allow the passed EE_Registration to be used in processing.
842
+	 *    one of the following conditions must be met:
843
+	 *        EITHER:    A) first time thru SPCO -> process ALL registrations ( NOT a revisit )
844
+	 *        OR :        B) primary registrant is editing info -> process ALL registrations ( primary_revisit )
845
+	 *        OR :        C) another registrant is editing info -> ONLY process their registration ( revisit AND their
846
+	 *        reg_url_link matches )
847
+	 *
848
+	 * @access public
849
+	 * @param    EE_Registration $registration
850
+	 * @return    bool
851
+	 * @throws \EE_Error
852
+	 */
853
+	public function visit_allows_processing_of_this_registration(EE_Registration $registration)
854
+	{
855
+		return ! $this->revisit
856
+			   || $this->primary_revisit
857
+			   || (
858
+				   $this->revisit && $this->reg_url_link === $registration->reg_url_link()
859
+			   )
860
+			? true
861
+			: false;
862
+	}
863
+
864
+
865
+	/**
866
+	 *    _transaction_has_primary_registration
867
+	 *
868
+	 * @access        private
869
+	 * @return        bool
870
+	 */
871
+	public function transaction_has_primary_registrant()
872
+	{
873
+		return $this->primary_attendee_obj instanceof EE_Attendee ? true : false;
874
+	}
875
+
876
+
877
+	/**
878
+	 *    save_all_data
879
+	 *    simply loops through the current transaction and saves all data for each registration
880
+	 *
881
+	 * @access public
882
+	 * @param bool $show_errors
883
+	 * @return bool
884
+	 * @throws \EE_Error
885
+	 */
886
+	public function save_all_data($show_errors = true)
887
+	{
888
+		// verify the transaction
889
+		if ($this->transaction instanceof EE_Transaction) {
890
+			// save to ensure that TXN has ID
891
+			$this->transaction->save();
892
+			// grab the saved registrations from the transaction
893
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $registration) {
894
+				$this->_save_registration($registration, $show_errors);
895
+			}
896
+		} else {
897
+			if ($show_errors) {
898
+				EE_Error::add_error(
899
+					__(
900
+						'A valid Transaction was not found when attempting to save your registration information.',
901
+						'event_espresso'
902
+					),
903
+					__FILE__,
904
+					__FUNCTION__,
905
+					__LINE__
906
+				);
907
+			}
908
+			return false;
909
+		}
910
+		return true;
911
+	}
912
+
913
+
914
+	/**
915
+	 * _save_registration_attendee
916
+	 *
917
+	 * @param    EE_Registration $registration
918
+	 * @param bool               $show_errors
919
+	 * @return void
920
+	 * @throws \EE_Error
921
+	 */
922
+	private function _save_registration($registration, $show_errors = true)
923
+	{
924
+		// verify object
925
+		if ($registration instanceof EE_Registration) {
926
+			// should this registration be processed during this visit ?
927
+			if ($this->visit_allows_processing_of_this_registration($registration)) {
928
+				// set TXN ID
929
+				if (! $registration->transaction_ID()) {
930
+					$registration->set_transaction_id($this->transaction->ID());
931
+				}
932
+				// verify and save the attendee
933
+				$this->_save_registration_attendee($registration, $show_errors);
934
+				// save answers to reg form questions
935
+				$this->_save_registration_answers($registration, $show_errors);
936
+				// save changes
937
+				$registration->save();
938
+				// update txn cache
939
+				if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
940
+					if ($show_errors) {
941
+						EE_Error::add_error(
942
+							__(
943
+								'The newly saved Registration object could not be cached on the Transaction.',
944
+								'event_espresso'
945
+							),
946
+							__FILE__,
947
+							__FUNCTION__,
948
+							__LINE__
949
+						);
950
+					}
951
+				}
952
+			}
953
+		} else {
954
+			if ($show_errors) {
955
+				EE_Error::add_error(
956
+					__(
957
+						'An invalid Registration object was discovered when attempting to save your registration information.',
958
+						'event_espresso'
959
+					),
960
+					__FILE__,
961
+					__FUNCTION__,
962
+					__LINE__
963
+				);
964
+			}
965
+		}
966
+	}
967
+
968
+
969
+	/**
970
+	 * _save_registration_attendee
971
+	 *
972
+	 * @param    EE_Registration $registration
973
+	 * @param bool               $show_errors
974
+	 * @return void
975
+	 * @throws \EE_Error
976
+	 */
977
+	private function _save_registration_attendee($registration, $show_errors = true)
978
+	{
979
+		if ($registration->attendee() instanceof EE_Attendee) {
980
+			// save so that ATT has ID
981
+			$registration->attendee()->save();
982
+			if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
983
+				if ($show_errors) {
984
+					EE_Error::add_error(
985
+						__(
986
+							'The newly saved Attendee object could not be cached on the registration.',
987
+							'event_espresso'
988
+						),
989
+						__FILE__,
990
+						__FUNCTION__,
991
+						__LINE__
992
+					);
993
+				}
994
+			}
995
+		} else {
996
+			if ($show_errors) {
997
+				EE_Error::add_error(
998
+					sprintf(
999
+						'%1$s||%1$s $attendee = %2$s',
1000
+						__(
1001
+							'Either no Attendee information was found, or an invalid Attendee object was discovered when attempting to save your registration information.',
1002
+							'event_espresso'
1003
+						),
1004
+						var_export($registration->attendee(), true)
1005
+					),
1006
+					__FILE__,
1007
+					__FUNCTION__,
1008
+					__LINE__
1009
+				);
1010
+			}
1011
+		}
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * _save_question_answers
1017
+	 *
1018
+	 * @param    EE_Registration $registration
1019
+	 * @param bool               $show_errors
1020
+	 * @return void
1021
+	 * @throws \EE_Error
1022
+	 */
1023
+	private function _save_registration_answers($registration, $show_errors = true)
1024
+	{
1025
+		// now save the answers
1026
+		foreach ($registration->answers() as $cache_key => $answer) {
1027
+			// verify object
1028
+			if ($answer instanceof EE_Answer) {
1029
+				$answer->set_registration($registration->ID());
1030
+				$answer->save();
1031
+				if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1032
+					if ($show_errors) {
1033
+						EE_Error::add_error(
1034
+							__(
1035
+								'The newly saved Answer object could not be cached on the registration.',
1036
+								'event_espresso'
1037
+							),
1038
+							__FILE__,
1039
+							__FUNCTION__,
1040
+							__LINE__
1041
+						);
1042
+					}
1043
+				}
1044
+			} else {
1045
+				if ($show_errors) {
1046
+					EE_Error::add_error(
1047
+						__(
1048
+							'An invalid Answer object was discovered when attempting to save your registration information.',
1049
+							'event_espresso'
1050
+						),
1051
+						__FILE__,
1052
+						__FUNCTION__,
1053
+						__LINE__
1054
+					);
1055
+				}
1056
+			}
1057
+		}
1058
+	}
1059
+
1060
+
1061
+	/**
1062
+	 *    refresh_all_entities
1063
+	 *   will either refresh the entity map with objects form the db or from the checkout cache
1064
+	 *
1065
+	 * @access public
1066
+	 * @param bool $from_db
1067
+	 * @return bool
1068
+	 * @throws \EE_Error
1069
+	 */
1070
+	public function refresh_all_entities($from_db = false)
1071
+	{
1072
+		$from_db = $this->current_step->is_final_step() || $this->action === 'process_gateway_response'
1073
+			? true
1074
+			: $from_db;
1075
+		// $this->log(
1076
+		//     __CLASS__,
1077
+		//     __FUNCTION__,
1078
+		//     __LINE__,
1079
+		//     array('from_db' => $from_db)
1080
+		// );
1081
+		return $from_db ? $this->refresh_from_db() : $this->refresh_entity_map();
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 *  refresh_entity_map
1087
+	 *  simply loops through the current transaction and updates each
1088
+	 *  model's entity map using EEM_Base::refresh_entity_map_from_db()
1089
+	 *
1090
+	 * @access public
1091
+	 * @return bool
1092
+	 * @throws \EE_Error
1093
+	 */
1094
+	protected function refresh_from_db()
1095
+	{
1096
+		// verify the transaction
1097
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1098
+			// pull fresh TXN data from the db
1099
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_from_db($this->transaction->ID());
1100
+			// update EE_Checkout's cached primary_attendee object
1101
+			$this->primary_attendee_obj = $this->_refresh_primary_attendee_obj_from_db($this->transaction);
1102
+			// update EE_Checkout's cached payment object
1103
+			$payment = $this->transaction->last_payment();
1104
+			$this->payment = $payment instanceof EE_Payment ? $payment : $this->payment;
1105
+			// update EE_Checkout's cached payment_method object
1106
+			$payment_method = $this->payment instanceof EE_Payment ? $this->payment->payment_method() : null;
1107
+			$this->payment_method = $payment_method instanceof EE_Payment_Method ? $payment_method
1108
+				: $this->payment_method;
1109
+			// now refresh the cart, based on the TXN
1110
+			$this->cart = $this->get_cart_for_transaction($this->transaction);
1111
+		} else {
1112
+			EE_Error::add_error(
1113
+				__(
1114
+					'A valid Transaction was not found when attempting to update the model entity mapper.',
1115
+					'event_espresso'
1116
+				),
1117
+				__FILE__,
1118
+				__FUNCTION__,
1119
+				__LINE__
1120
+			);
1121
+			return false;
1122
+		}
1123
+		return true;
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * _refresh_primary_attendee_obj_from_db
1129
+	 *
1130
+	 * @param   EE_Transaction $transaction
1131
+	 * @return  EE_Attendee | null
1132
+	 * @throws \EE_Error
1133
+	 */
1134
+	protected function _refresh_primary_attendee_obj_from_db(EE_Transaction $transaction)
1135
+	{
1136
+
1137
+		$primary_attendee_obj = null;
1138
+		// grab the saved registrations from the transaction
1139
+		foreach ($transaction->registrations($this->reg_cache_where_params, true) as $registration) {
1140
+			// verify object
1141
+			if ($registration instanceof EE_Registration) {
1142
+				$attendee = $registration->attendee();
1143
+				// verify object && maybe cache primary_attendee_obj ?
1144
+				if ($attendee instanceof EE_Attendee && $registration->is_primary_registrant()) {
1145
+					$primary_attendee_obj = $attendee;
1146
+				}
1147
+			} else {
1148
+				EE_Error::add_error(
1149
+					__(
1150
+						'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1151
+						'event_espresso'
1152
+					),
1153
+					__FILE__,
1154
+					__FUNCTION__,
1155
+					__LINE__
1156
+				);
1157
+			}
1158
+		}
1159
+		return $primary_attendee_obj;
1160
+	}
1161
+
1162
+
1163
+	/**
1164
+	 *  refresh_entity_map
1165
+	 *  simply loops through the current transaction and updates
1166
+	 *  each model's entity map using EEM_Base::refresh_entity_map_with()
1167
+	 *
1168
+	 * @access public
1169
+	 * @return bool
1170
+	 * @throws \EE_Error
1171
+	 */
1172
+	protected function refresh_entity_map()
1173
+	{
1174
+		// verify the transaction
1175
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1176
+			// never cache payment info
1177
+			$this->transaction->clear_cache('Payment');
1178
+			// is the Payment Options Reg Step completed ?
1179
+			if ($this->transaction->reg_step_completed('payment_options')) {
1180
+				// then check for payments and update TXN accordingly
1181
+				/** @type EE_Transaction_Payments $transaction_payments */
1182
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1183
+				$transaction_payments->calculate_total_payments_and_update_status($this->transaction);
1184
+			}
1185
+			// grab the saved registrations from the transaction
1186
+			foreach ($this->transaction->registrations($this->reg_cache_where_params) as $reg_cache_ID => $registration) {
1187
+				$this->_refresh_registration($reg_cache_ID, $registration);
1188
+			}
1189
+			// make sure our cached TXN is added to the model entity mapper
1190
+			$this->transaction = $this->transaction->get_model()->refresh_entity_map_with(
1191
+				$this->transaction->ID(),
1192
+				$this->transaction
1193
+			);
1194
+		} else {
1195
+			EE_Error::add_error(
1196
+				__(
1197
+					'A valid Transaction was not found when attempting to update the model entity mapper.',
1198
+					'event_espresso'
1199
+				),
1200
+				__FILE__,
1201
+				__FUNCTION__,
1202
+				__LINE__
1203
+			);
1204
+			return false;
1205
+		}
1206
+		// verify and update the cart because inaccurate totals are not so much fun
1207
+		if ($this->cart instanceof EE_Cart) {
1208
+			$grand_total = $this->cart->get_grand_total();
1209
+			if ($grand_total instanceof EE_Line_Item && $grand_total->ID()) {
1210
+				$grand_total->recalculate_total_including_taxes();
1211
+				$grand_total = $grand_total->get_model()->refresh_entity_map_with(
1212
+					$this->cart->get_grand_total()->ID(),
1213
+					$this->cart->get_grand_total()
1214
+				);
1215
+			}
1216
+			if ($grand_total instanceof EE_Line_Item) {
1217
+				$this->cart = EE_Cart::instance($grand_total);
1218
+			} else {
1219
+				EE_Error::add_error(
1220
+					__(
1221
+						'A valid Cart was not found when attempting to update the model entity mapper.',
1222
+						'event_espresso'
1223
+					),
1224
+					__FILE__,
1225
+					__FUNCTION__,
1226
+					__LINE__
1227
+				);
1228
+				return false;
1229
+			}
1230
+		}
1231
+		return true;
1232
+	}
1233
+
1234
+
1235
+	/**
1236
+	 * _refresh_registration
1237
+	 *
1238
+	 * @param    string | int    $reg_cache_ID
1239
+	 * @param    EE_Registration $registration
1240
+	 * @return void
1241
+	 * @throws \EE_Error
1242
+	 */
1243
+	protected function _refresh_registration($reg_cache_ID, $registration)
1244
+	{
1245
+
1246
+		// verify object
1247
+		if ($registration instanceof EE_Registration) {
1248
+			// update the entity mapper attendee
1249
+			$this->_refresh_registration_attendee($registration);
1250
+			// update the entity mapper answers for reg form questions
1251
+			$this->_refresh_registration_answers($registration);
1252
+			// make sure the cached registration is added to the model entity mapper
1253
+			$registration->get_model()->refresh_entity_map_with($reg_cache_ID, $registration);
1254
+		} else {
1255
+			EE_Error::add_error(
1256
+				__(
1257
+					'An invalid Registration object was discovered when attempting to update the model entity mapper.',
1258
+					'event_espresso'
1259
+				),
1260
+				__FILE__,
1261
+				__FUNCTION__,
1262
+				__LINE__
1263
+			);
1264
+		}
1265
+	}
1266
+
1267
+
1268
+	/**
1269
+	 * _save_registration_attendee
1270
+	 *
1271
+	 * @param    EE_Registration $registration
1272
+	 * @return void
1273
+	 * @throws \EE_Error
1274
+	 */
1275
+	protected function _refresh_registration_attendee($registration)
1276
+	{
1277
+
1278
+		$attendee = $registration->attendee();
1279
+		// verify object
1280
+		if ($attendee instanceof EE_Attendee && $attendee->ID()) {
1281
+			// make sure the cached attendee is added to the model entity mapper
1282
+			$registration->attendee()->get_model()->refresh_entity_map_with($attendee->ID(), $attendee);
1283
+			// maybe cache primary_attendee_obj ?
1284
+			if ($registration->is_primary_registrant()) {
1285
+				$this->primary_attendee_obj = $attendee;
1286
+			}
1287
+		}
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * _refresh_registration_answers
1293
+	 *
1294
+	 * @param    EE_Registration $registration
1295
+	 * @return void
1296
+	 * @throws \EE_Error
1297
+	 */
1298
+	protected function _refresh_registration_answers($registration)
1299
+	{
1300
+
1301
+		// now update the answers
1302
+		foreach ($registration->answers() as $cache_key => $answer) {
1303
+			// verify object
1304
+			if ($answer instanceof EE_Answer) {
1305
+				if ($answer->ID()) {
1306
+					// make sure the cached answer is added to the model entity mapper
1307
+					$answer->get_model()->refresh_entity_map_with($answer->ID(), $answer);
1308
+				}
1309
+			} else {
1310
+				EE_Error::add_error(
1311
+					__(
1312
+						'An invalid Answer object was discovered when attempting to update the model entity mapper.',
1313
+						'event_espresso'
1314
+					),
1315
+					__FILE__,
1316
+					__FUNCTION__,
1317
+					__LINE__
1318
+				);
1319
+			}
1320
+		}
1321
+	}
1322
+
1323
+
1324
+	/**
1325
+	 *    __sleep
1326
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
1327
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
1328
+	 * reg form, because if needed, it will be regenerated anyways
1329
+	 *
1330
+	 * @return array
1331
+	 * @throws \EE_Error
1332
+	 */
1333
+	public function __sleep()
1334
+	{
1335
+		if ($this->primary_attendee_obj instanceof EE_Attendee && $this->primary_attendee_obj->ID()) {
1336
+			$this->primary_attendee_obj = $this->primary_attendee_obj->ID();
1337
+		}        // remove the reg form and the checkout
1338
+		if ($this->transaction instanceof EE_Transaction && $this->transaction->ID()) {
1339
+			$this->transaction = $this->transaction->ID();
1340
+		}        // remove the reg form and the checkout
1341
+		return array_diff(array_keys(get_object_vars($this)), array('billing_form', 'registration_form'));
1342
+	}
1343
+
1344
+
1345
+	/**
1346
+	 *    __wakeup
1347
+	 * to conserve db space, we are removing the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization
1348
+	 * this will reinstate the EE_Checkout object on each EE_SPCO_Reg_Step object
1349
+	 */
1350
+	public function __wakeup()
1351
+	{
1352
+		if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1353
+			// $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1354
+			$this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1355
+		}
1356
+		if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1357
+			// $this->transaction is actually just an ID, so use it to get the object from the db
1358
+			$this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1359
+		}
1360
+		foreach ($this->reg_steps as $reg_step) {
1361
+			$reg_step->checkout = $this;
1362
+		}
1363
+	}
1364
+
1365
+
1366
+	/**
1367
+	 * debug
1368
+	 *
1369
+	 * @param string $class
1370
+	 * @param string $func
1371
+	 * @param string $line
1372
+	 * @param array  $info
1373
+	 * @param bool   $display_request
1374
+	 * @throws \EE_Error
1375
+	 */
1376
+	public function log($class = '', $func = '', $line = '', $info = array(), $display_request = false)
1377
+	{
1378
+		$disabled = true;
1379
+		if (WP_DEBUG && ! $disabled) {
1380
+			$debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
1381
+			$default_data = array(
1382
+				$class                    => $func . '() : ' . $line,
1383
+				'request->step'           => $this->step,
1384
+				'request->action'         => $this->action,
1385
+				'current_step->slug'      => $this->current_step instanceof EE_SPCO_Reg_Step ?
1386
+					$this->current_step->slug() : '',
1387
+				'current_step->completed' => $this->current_step instanceof EE_SPCO_Reg_Step ?
1388
+					$this->current_step->completed() : '',
1389
+				'txn_status_updated'      => $this->transaction->txn_status_updated(),
1390
+				'reg_status_updated'      => $this->reg_status_updated,
1391
+				'reg_url_link'            => $this->reg_url_link,
1392
+				'REQ'                     => $display_request ? $_REQUEST : '',
1393
+			);
1394
+			if ($this->transaction instanceof EE_Transaction) {
1395
+				$default_data['TXN_status'] = $this->transaction->status_ID();
1396
+				$default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1397
+				foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1398
+					$default_data['registrations'][ $REG_ID ] = $registration->status_ID();
1399
+				}
1400
+				if ($this->transaction->ID()) {
1401
+					$TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1402
+					// don't serialize objects
1403
+					$info = $this->_strip_objects($info);
1404
+					if (! isset($debug_data[ $TXN_ID ])) {
1405
+						$debug_data[ $TXN_ID ] = array();
1406
+					}
1407
+					$debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1408
+						$default_data,
1409
+						$info
1410
+					);
1411
+					update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
1412
+				}
1413
+			}
1414
+		}
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * _strip_objects
1420
+	 *
1421
+	 * @param array $info
1422
+	 * @return array
1423
+	 */
1424
+	public function _strip_objects($info = array())
1425
+	{
1426
+		foreach ((array) $info as $key => $value) {
1427
+			if (is_array($value)) {
1428
+				$info[ $key ] = $this->_strip_objects($value);
1429
+			} elseif (is_object($value)) {
1430
+				$object_class = get_class($value);
1431
+				$info[ $object_class ] = array();
1432
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1433
+				if (method_exists($value, 'status')) {
1434
+					$info[ $object_class ]['status'] = $value->status();
1435
+				} elseif (method_exists($value, 'status_ID')) {
1436
+					$info[ $object_class ]['status'] = $value->status_ID();
1437
+				}
1438
+				unset($info[ $key ]);
1439
+			}
1440
+		}
1441
+		return (array) $info;
1442
+	}
1443 1443
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
      */
314 314
     public function reg_status_updated($REG_ID)
315 315
     {
316
-        return isset($this->reg_status_updated[ $REG_ID ]) ? $this->reg_status_updated[ $REG_ID ] : false;
316
+        return isset($this->reg_status_updated[$REG_ID]) ? $this->reg_status_updated[$REG_ID] : false;
317 317
     }
318 318
 
319 319
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
      */
324 324
     public function set_reg_status_updated($REG_ID, $reg_status)
325 325
     {
326
-        $this->reg_status_updated[ $REG_ID ] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
326
+        $this->reg_status_updated[$REG_ID] = filter_var($reg_status, FILTER_VALIDATE_BOOLEAN);
327 327
     }
328 328
 
329 329
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
      */
383 383
     public function add_reg_step(EE_SPCO_Reg_Step $reg_step_obj)
384 384
     {
385
-        $this->reg_steps[ $reg_step_obj->slug() ] = $reg_step_obj;
385
+        $this->reg_steps[$reg_step_obj->slug()] = $reg_step_obj;
386 386
     }
387 387
 
388 388
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
      */
429 429
     public function remove_reg_step($reg_step_slug = '', $reset = true)
430 430
     {
431
-        unset($this->reg_steps[ $reg_step_slug ]);
431
+        unset($this->reg_steps[$reg_step_slug]);
432 432
         if ($this->transaction instanceof EE_Transaction) {
433 433
             // now remove reg step from TXN and save
434 434
             $this->transaction->remove_reg_step($reg_step_slug);
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
      */
451 451
     public function set_reg_step_order($reg_step_slug = '', $order = 100)
452 452
     {
453
-        if (isset($this->reg_steps[ $reg_step_slug ])) {
454
-            $this->reg_steps[ $reg_step_slug ]->set_order($order);
453
+        if (isset($this->reg_steps[$reg_step_slug])) {
454
+            $this->reg_steps[$reg_step_slug]->set_order($order);
455 455
         }
456 456
     }
457 457
 
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
     public function set_current_step($current_step)
467 467
     {
468 468
         // grab what step we're on
469
-        $this->current_step = isset($this->reg_steps[ $current_step ])
470
-            ? $this->reg_steps[ $current_step ]
469
+        $this->current_step = isset($this->reg_steps[$current_step])
470
+            ? $this->reg_steps[$current_step]
471 471
             : reset(
472 472
                 $this->reg_steps
473 473
             );
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
      */
579 579
     public function find_reg_step($reg_step_slug = '')
580 580
     {
581
-        if (! empty($reg_step_slug)) {
581
+        if ( ! empty($reg_step_slug)) {
582 582
             // copy reg step array
583 583
             $reg_steps = $this->reg_steps;
584 584
             // set pointer to start of array
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
             )
640 640
         ) {
641 641
             // set the start time for this reg step
642
-            if (! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
642
+            if ( ! $this->transaction->set_reg_step_initiated($reg_step->slug())) {
643 643
                 if (WP_DEBUG) {
644 644
                     EE_Error::add_error(
645 645
                         sprintf(
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
         $session = EE_Registry::instance()->load_core('Session');
743 743
         $cart = $transaction instanceof EE_Transaction ? EE_Cart::get_cart_from_txn($transaction, $session) : null;
744 744
         // verify cart
745
-        if (! $cart instanceof EE_Cart) {
745
+        if ( ! $cart instanceof EE_Cart) {
746 746
             $cart = EE_Registry::instance()->load_core('Cart');
747 747
         }
748 748
 
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
     {
761 761
         $txn_reg_steps_array = array();
762 762
         foreach ($this->reg_steps as $reg_step) {
763
-            $txn_reg_steps_array[ $reg_step->slug() ] = false;
763
+            $txn_reg_steps_array[$reg_step->slug()] = false;
764 764
         }
765 765
         return $txn_reg_steps_array;
766 766
     }
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
      */
800 800
     public function stash_transaction_and_checkout()
801 801
     {
802
-        if (! $this->revisit) {
802
+        if ( ! $this->revisit) {
803 803
             $this->update_txn_reg_steps_array();
804 804
         }
805 805
         $this->track_transaction_and_registration_status_updates();
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
             // should this registration be processed during this visit ?
927 927
             if ($this->visit_allows_processing_of_this_registration($registration)) {
928 928
                 // set TXN ID
929
-                if (! $registration->transaction_ID()) {
929
+                if ( ! $registration->transaction_ID()) {
930 930
                     $registration->set_transaction_id($this->transaction->ID());
931 931
                 }
932 932
                 // verify and save the attendee
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
                 // save changes
937 937
                 $registration->save();
938 938
                 // update txn cache
939
-                if (! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
939
+                if ( ! $this->transaction->update_cache_after_object_save('Registration', $registration)) {
940 940
                     if ($show_errors) {
941 941
                         EE_Error::add_error(
942 942
                             __(
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
         if ($registration->attendee() instanceof EE_Attendee) {
980 980
             // save so that ATT has ID
981 981
             $registration->attendee()->save();
982
-            if (! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
982
+            if ( ! $registration->update_cache_after_object_save('Attendee', $registration->attendee())) {
983 983
                 if ($show_errors) {
984 984
                     EE_Error::add_error(
985 985
                         __(
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
             if ($answer instanceof EE_Answer) {
1029 1029
                 $answer->set_registration($registration->ID());
1030 1030
                 $answer->save();
1031
-                if (! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1031
+                if ( ! $registration->update_cache_after_object_save('Answer', $answer, $cache_key)) {
1032 1032
                     if ($show_errors) {
1033 1033
                         EE_Error::add_error(
1034 1034
                             __(
@@ -1349,11 +1349,11 @@  discard block
 block discarded – undo
1349 1349
      */
1350 1350
     public function __wakeup()
1351 1351
     {
1352
-        if (! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1352
+        if ( ! $this->primary_attendee_obj instanceof EE_Attendee && absint($this->primary_attendee_obj) !== 0) {
1353 1353
             // $this->primary_attendee_obj is actually just an ID, so use it to get the object from the db
1354 1354
             $this->primary_attendee_obj = EEM_Attendee::instance()->get_one_by_ID($this->primary_attendee_obj);
1355 1355
         }
1356
-        if (! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1356
+        if ( ! $this->transaction instanceof EE_Transaction && absint($this->transaction) !== 0) {
1357 1357
             // $this->transaction is actually just an ID, so use it to get the object from the db
1358 1358
             $this->transaction = EEM_Transaction::instance()->get_one_by_ID($this->transaction);
1359 1359
         }
@@ -1377,9 +1377,9 @@  discard block
 block discarded – undo
1377 1377
     {
1378 1378
         $disabled = true;
1379 1379
         if (WP_DEBUG && ! $disabled) {
1380
-            $debug_data = get_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), array());
1380
+            $debug_data = get_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), array());
1381 1381
             $default_data = array(
1382
-                $class                    => $func . '() : ' . $line,
1382
+                $class                    => $func.'() : '.$line,
1383 1383
                 'request->step'           => $this->step,
1384 1384
                 'request->action'         => $this->action,
1385 1385
                 'current_step->slug'      => $this->current_step instanceof EE_SPCO_Reg_Step ?
@@ -1395,20 +1395,20 @@  discard block
 block discarded – undo
1395 1395
                 $default_data['TXN_status'] = $this->transaction->status_ID();
1396 1396
                 $default_data['TXN_reg_steps'] = $this->transaction->reg_steps();
1397 1397
                 foreach ($this->transaction->registrations($this->reg_cache_where_params) as $REG_ID => $registration) {
1398
-                    $default_data['registrations'][ $REG_ID ] = $registration->status_ID();
1398
+                    $default_data['registrations'][$REG_ID] = $registration->status_ID();
1399 1399
                 }
1400 1400
                 if ($this->transaction->ID()) {
1401
-                    $TXN_ID = 'EE_Transaction: ' . $this->transaction->ID();
1401
+                    $TXN_ID = 'EE_Transaction: '.$this->transaction->ID();
1402 1402
                     // don't serialize objects
1403 1403
                     $info = $this->_strip_objects($info);
1404
-                    if (! isset($debug_data[ $TXN_ID ])) {
1405
-                        $debug_data[ $TXN_ID ] = array();
1404
+                    if ( ! isset($debug_data[$TXN_ID])) {
1405
+                        $debug_data[$TXN_ID] = array();
1406 1406
                     }
1407
-                    $debug_data[ $TXN_ID ][ microtime() ] = array_merge(
1407
+                    $debug_data[$TXN_ID][microtime()] = array_merge(
1408 1408
                         $default_data,
1409 1409
                         $info
1410 1410
                     );
1411
-                    update_option('EE_DEBUG_SPCO_' . EE_Session::instance()->id(), $debug_data);
1411
+                    update_option('EE_DEBUG_SPCO_'.EE_Session::instance()->id(), $debug_data);
1412 1412
                 }
1413 1413
             }
1414 1414
         }
@@ -1425,17 +1425,17 @@  discard block
 block discarded – undo
1425 1425
     {
1426 1426
         foreach ((array) $info as $key => $value) {
1427 1427
             if (is_array($value)) {
1428
-                $info[ $key ] = $this->_strip_objects($value);
1428
+                $info[$key] = $this->_strip_objects($value);
1429 1429
             } elseif (is_object($value)) {
1430 1430
                 $object_class = get_class($value);
1431
-                $info[ $object_class ] = array();
1432
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1431
+                $info[$object_class] = array();
1432
+                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : 0;
1433 1433
                 if (method_exists($value, 'status')) {
1434
-                    $info[ $object_class ]['status'] = $value->status();
1434
+                    $info[$object_class]['status'] = $value->status();
1435 1435
                 } elseif (method_exists($value, 'status_ID')) {
1436
-                    $info[ $object_class ]['status'] = $value->status_ID();
1436
+                    $info[$object_class]['status'] = $value->status_ID();
1437 1437
                 }
1438
-                unset($info[ $key ]);
1438
+                unset($info[$key]);
1439 1439
             }
1440 1440
         }
1441 1441
         return (array) $info;
Please login to merge, or discard this patch.
caffeinated/EE_Caf_Messages.class.php 2 patches
Indentation   +799 added lines, -799 removed lines patch added patch discarded remove patch
@@ -13,803 +13,803 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * constructor.
18
-     */
19
-    public function __construct()
20
-    {
21
-        $this->_caf_hooks();
22
-    }
23
-
24
-
25
-    /**
26
-     * Contains all the hooks filters for setting up caffeinated messages functionality.
27
-     *
28
-     * @since 4.3.2
29
-     *
30
-     * @return void
31
-     */
32
-    private function _caf_hooks()
33
-    {
34
-        add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
35
-        add_filter(
36
-            'FHEE__EE_Email_messenger__get_validator_config',
37
-            array($this, 'email_messenger_validator_config'),
38
-            5,
39
-            2
40
-        );
41
-        add_filter(
42
-            'FHEE__EE_Email_messenger__get_template_fields',
43
-            array($this, 'email_messenger_template_fields'),
44
-            5,
45
-            2
46
-        );
47
-        add_filter(
48
-            'FHEE__EE_Html_messenger__get_template_fields',
49
-            array($this, 'html_messenger_template_fields'),
50
-            5,
51
-            2
52
-        );
53
-        add_filter(
54
-            'FHEE__EE_Html_messenger__get_validator_config',
55
-            array($this, 'html_messenger_validator_config'),
56
-            5,
57
-            2
58
-        );
59
-        add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
60
-        add_filter(
61
-            'FHEE__EE_Pdf_messenger__get_validator_config',
62
-            array($this, 'pdf_messenger_validator_config'),
63
-            5,
64
-            2
65
-        );
66
-        add_filter(
67
-            'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
68
-            array($this, 'new_default_templates'),
69
-            5,
70
-            7
71
-        );
72
-        add_filter(
73
-            'FHEE__EE_Messages_Base__get_valid_shortcodes',
74
-            array($this, 'message_types_valid_shortcodes'),
75
-            5,
76
-            2
77
-        );
78
-
79
-        // shortcode parsers
80
-        add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
81
-        add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
82
-        add_filter(
83
-            'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
84
-            array($this, 'additional_recipient_details_shortcodes'),
85
-            5,
86
-            2
87
-        );
88
-        add_filter(
89
-            'FHEE__EE_Recipient_List_Shortcodes__parser_after',
90
-            array($this, 'additional_recipient_details_parser'),
91
-            5,
92
-            5
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
96
-            array($this, 'additional_primary_registration_details_shortcodes'),
97
-            5,
98
-            2
99
-        );
100
-        add_filter(
101
-            'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
102
-            array($this, 'additional_primary_registration_details_parser'),
103
-            5,
104
-            5
105
-        );
106
-
107
-        /**
108
-         * @since 4.2.0
109
-         */
110
-        add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
111
-        add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
112
-
113
-        /**
114
-         * @since 4.3.0
115
-         */
116
-        // eat our own dog food!
117
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
118
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
119
-        do_action('EE_Brewing_Regular___messages_caf');
120
-    }
121
-
122
-
123
-    /**
124
-     * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
125
-     * messages system.
126
-     *
127
-     * @param  array $dir_ref original array of paths
128
-     *
129
-     * @return array           appended paths
130
-     */
131
-    public function messages_autoload_paths($dir_ref)
132
-    {
133
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
134
-
135
-        return $dir_ref;
136
-    }
137
-
138
-
139
-    public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
140
-    {
141
-        $validator_config['attendee_list'] = array(
142
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
143
-            'required'   => array('[ATTENDEE_LIST]'),
144
-        );
145
-        $validator_config['question_list'] = array(
146
-            'shortcodes' => array('question'),
147
-            'required'   => array('[QUESTION_LIST]'),
148
-        );
149
-
150
-        return $validator_config;
151
-    }
152
-
153
-
154
-    public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
155
-    {
156
-        $validator_config['attendee_list'] = array(
157
-            'shortcodes' => array('attendee', 'question_list'),
158
-            'required'   => array('[ATTENDEE_LIST]'),
159
-        );
160
-        $validator_config['question_list'] = array(
161
-            'shortcodes' => array('question'),
162
-            'required'   => array('[QUESTION_LIST]'),
163
-        );
164
-
165
-        return $validator_config;
166
-    }
167
-
168
-
169
-    public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
170
-    {
171
-        $validator_config['attendee_list'] = array(
172
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
173
-            'required'   => array('[ATTENDEE_LIST]'),
174
-        );
175
-        $validator_config['question_list'] = array(
176
-            'shortcodes' => array('question'),
177
-            'required'   => array('[QUESTION_LIST]'),
178
-        );
179
-
180
-        return $validator_config;
181
-    }
182
-
183
-
184
-    public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
185
-    {
186
-        $template_fields['extra']['content']['question_list'] = array(
187
-            'input'               => 'textarea',
188
-            'label'               => '[QUESTION_LIST]',
189
-            'type'                => 'string',
190
-            'required'            => true,
191
-            'validation'          => true,
192
-            'format'              => '%s',
193
-            'css_class'           => 'large-text',
194
-            'rows'                => '5',
195
-            'shortcodes_required' => array('[QUESTION_LIST]'),
196
-        );
197
-
198
-        return $template_fields;
199
-    }
200
-
201
-
202
-    public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
203
-    {
204
-        $template_fields['extra']['content']['question_list'] = array(
205
-            'input'               => 'textarea',
206
-            'label'               => '[QUESTION_LIST]',
207
-            'type'                => 'string',
208
-            'required'            => true,
209
-            'validation'          => true,
210
-            'format'              => '%s',
211
-            'css_class'           => 'large-text',
212
-            'rows'                => '5',
213
-            'shortcodes_required' => array('[QUESTION_LIST]'),
214
-        );
215
-
216
-        return $template_fields;
217
-    }
218
-
219
-
220
-    public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
221
-    {
222
-        $template_fields['extra']['content']['question_list'] = array(
223
-            'input'               => 'textarea',
224
-            'label'               => '[QUESTION_LIST]',
225
-            'type'                => 'string',
226
-            'required'            => true,
227
-            'validation'          => true,
228
-            'format'              => '%s',
229
-            'css_class'           => 'large-text',
230
-            'rows'                => '5',
231
-            'shortcodes_required' => array('[QUESTION_LIST]'),
232
-        );
233
-
234
-        return $template_fields;
235
-    }
236
-
237
-
238
-    public function new_default_templates(
239
-        $contents,
240
-        $actual_path,
241
-        EE_messenger $messenger,
242
-        EE_message_type $message_type,
243
-        $field,
244
-        $context,
245
-        EE_Messages_Template_Pack $template_pack
246
-    ) {
247
-
248
-        // we're only modifying templates for the default template pack
249
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250
-            return $contents;
251
-        }
252
-
253
-        // the template file name we're replacing contents for.
254
-        $template_file_prefix = $field . '_' . $context;
255
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
256
-
257
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
258
-
259
-        if ($messenger->name == 'email' && $message_type->name == 'registration') {
260
-            switch ($template_file_prefix) {
261
-                case 'question_list_admin':
262
-                case 'question_list_attendee':
263
-                case 'question_list_primary_attendee':
264
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
265
-                    $contents = EEH_Template::display_template($path, array(), true);
266
-                    break;
267
-
268
-                case 'attendee_list_primary_attendee':
269
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
270
-                    $contents = EEH_Template::display_template($path, array(), true);
271
-                    break;
272
-
273
-                case 'attendee_list_admin':
274
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
275
-                    $contents = EEH_Template::display_template(
276
-                        $path,
277
-                        array(),
278
-                        true
279
-                    );
280
-                    break;
281
-
282
-                case 'attendee_list_attendee':
283
-                    $contents = '';
284
-                    break;
285
-
286
-                case 'event_list_attendee':
287
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
288
-                    $contents = EEH_Template::display_template($path, array(), true);
289
-                    break;
290
-            }
291
-        } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292
-            switch ($template_file_prefix) {
293
-                case 'content_attendee':
294
-                    $path = $base_path . $msg_prefix . 'content.template.php';
295
-                    $contents = EEH_Template::display_template($path, array(), true);
296
-                    break;
297
-
298
-                case 'newsletter_content_attendee':
299
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
300
-                    $contents = EEH_Template::display_template($path, array(), true);
301
-                    break;
302
-
303
-                case 'newsletter_subject_attendee':
304
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
305
-                    $contents = EEH_Template::display_template($path, array(), true);
306
-                    break;
307
-            }
308
-        } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309
-            switch ($template_file_prefix) {
310
-                case 'attendee_list_purchaser':
311
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
312
-                    $contents = EEH_Template::display_template($path, array(), true);
313
-                    break;
314
-            }
315
-        }
316
-
317
-        return $contents;
318
-    }
319
-
320
-
321
-    public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
322
-    {
323
-        // make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
324
-        $include_with = array(
325
-            'registration',
326
-            'cancelled_registration',
327
-            'declined_registration',
328
-            'not_approved_registration',
329
-            'payment_declined',
330
-            'payment_failed',
331
-            'payment_cancelled',
332
-            'payment',
333
-            'payment_reminder',
334
-            'pending_approval',
335
-            'registration_summary',
336
-            'invoice',
337
-            'receipt',
338
-        );
339
-        if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340
-            $contexts = array_keys($msg->get_contexts());
341
-            foreach ($contexts as $context) {
342
-                $valid_shortcodes[ $context ][] = 'question_list';
343
-                $valid_shortcodes[ $context ][] = 'question';
344
-            }
345
-        }
346
-
347
-        return $valid_shortcodes;
348
-    }
349
-
350
-
351
-    public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
352
-    {
353
-        $shortcodes['[ANSWER_*]'] = __(
354
-            'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
355
-            'event_espresso'
356
-        );
357
-
358
-        return $shortcodes;
359
-    }
360
-
361
-
362
-    public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
363
-    {
364
-
365
-        if (strpos($shortcode, '[ANSWER_*') === false
366
-            || ! isset($extra_data['data']->questions)
367
-            || ! isset($extra_data['data']->registrations)
368
-        ) {
369
-            return $parsed;
370
-        }
371
-
372
-        // let's get the question from the code.
373
-        $shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
-        $shortcode = trim(str_replace(']', '', $shortcode));
375
-
376
-        $registration = $data instanceof EE_Registration ? $data : null;
377
-        $registration = ! $registration instanceof EE_Registration && is_array(
378
-            $extra_data
379
-        ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
-
381
-        $aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
-        $aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
-            $extra_data
384
-        ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
-
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
-            return $parsed;
388
-        }
389
-
390
-        // now let's figure out which question has this text.
391
-        foreach ($aee->questions as $ansid => $question) {
392
-            if ($question instanceof EE_Question
393
-                && trim($question->display_text()) == trim($shortcode)
394
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
395
-            ) {
396
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
397
-                    'ANS_value',
398
-                    'no_wpautop'
399
-                );
400
-            }
401
-        }
402
-
403
-        // nothing!
404
-        return $parsed;
405
-    }
406
-
407
-
408
-    /**
409
-     * Callback for additional shortcodes filter for adding additional datetime shortcodes.
410
-     *
411
-     * @since  4.2
412
-     *
413
-     * @param  array                  $shortcodes         array of shortcodes and
414
-     *                                                    descriptions
415
-     * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
416
-     *
417
-     * @return array                                        array of shortcodes and
418
-     *                                                        descriptions
419
-     */
420
-    public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
421
-    {
422
-        $shortcodes['[DTT_NAME]'] = __(
423
-            'This will be parsed to the Title given for a Datetime',
424
-            'event_espresso'
425
-        );
426
-        $shortcodes['[DTT_DESCRIPTION]'] = __(
427
-            'This will be parsed to the description for a Datetime',
428
-            'event_espresso'
429
-        );
430
-        $shortcodes['[DTT_NAME_OR_DATES]'] = __(
431
-            'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
432
-            'event_espresso'
433
-        );
434
-
435
-        return $shortcodes;
436
-    }
437
-
438
-
439
-    /**
440
-     * Callback for additional shortcodes parser filter used for adding parser for new
441
-     * Datetime shortcodes
442
-     *
443
-     * @since  4.2
444
-     *
445
-     * @param  string                 $parsed     The finished parsed string for the given shortcode.
446
-     * @param  string                 $shortcode  The shortcode being parsed.
447
-     * @param  object                 $data       The incoming data object for the Shortcode Parser.
448
-     * @param  object                 $extra_data The incoming extra date object for the Shortcode
449
-     *                                            Parser.
450
-     * @param  EE_Datetime_Shortcodes $shortcode_parser
451
-     *
452
-     * @return string                   The new parsed string.
453
-     */
454
-    public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455
-    {
456
-
457
-        if (! $data instanceof EE_Datetime) {
458
-            return ''; // get out because we can only parse with the datetime object.
459
-        }
460
-
461
-        switch ($shortcode) {
462
-            case '[DTT_NAME]':
463
-                return $data->name();
464
-                break;
465
-            case '[DTT_DESCRIPTION]':
466
-                return $data->description();
467
-                break;
468
-            case '[DTT_NAME_OR_DATES]':
469
-                return $data->get_dtt_display_name(true);
470
-                break;
471
-            default:
472
-                return $parsed;
473
-                break;
474
-        }
475
-    }
476
-
477
-
478
-    public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
479
-    {
480
-        $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
481
-            'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
482
-            'event_espresso'
483
-        );
484
-
485
-        return $shortcodes;
486
-    }
487
-
488
-
489
-    /**
490
-     * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
491
-     *
492
-     * @param string         $parsed           The original parsed content for the shortcode
493
-     * @param string         $shortcode        The shortcode being parsed
494
-     * @param array          $data             The shortcode parser data array
495
-     * @param array          $extra_data       The shortcode parser extra data array
496
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
497
-     *
498
-     * @return string
499
-     */
500
-    public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
501
-    {
502
-
503
-        if (array($data) && ! isset($data['data'])) {
504
-            return $parsed;
505
-        }
506
-
507
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509
-
510
-        if (! $recipient instanceof EE_Messages_Addressee) {
511
-            return $parsed;
512
-        }
513
-
514
-        switch ($shortcode) {
515
-            case '[RECIPIENT_QUESTION_LIST]':
516
-                $att = $recipient->att_obj;
517
-                $registrations_on_attendee = $att instanceof EE_Attendee
518
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
519
-                    : array();
520
-                $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521
-                $answers = array();
522
-
523
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
524
-                    ? $data['template']['question_list']
525
-                    : $extra_data['template']['question_list'];
526
-                $valid_shortcodes = array('question');
527
-
528
-                // if the context is main_content then get all answers for all registrations on this attendee
529
-                if ($data['data'] instanceof EE_Messages_Addressee) {
530
-                    foreach ($registrations_on_attendee as $reg) {
531
-                        if ($reg instanceof EE_Registration) {
532
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
534
-                                : array();
535
-                            foreach ($anss as $ans) {
536
-                                if ($ans instanceof EE_Answer) {
537
-                                    $answers[ $ans->ID() ] = $ans;
538
-                                }
539
-                            }
540
-                        }
541
-                    }
542
-                }
543
-
544
-                // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
545
-                if ($data['data'] instanceof EE_Event) {
546
-                    $event = $data['data'];
547
-                    foreach ($registrations_on_attendee as $reg) {
548
-                        if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
551
-                                : array();
552
-                            foreach ($anss as $ans) {
553
-                                if ($ans instanceof EE_Answer) {
554
-                                    $answers[ $ans->ID() ] = $ans;
555
-                                }
556
-                            }
557
-                        }
558
-                    }
559
-                }
560
-
561
-                $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
562
-
563
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564
-                // object on it.
565
-                if (! isset($extra_data['data'])) {
566
-                    $extra_data['data'] = $recipient;
567
-                }
568
-
569
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
570
-                    $shortcode_parser,
571
-                    $questions,
572
-                    $answers,
573
-                    $template,
574
-                    $valid_shortcodes,
575
-                    $extra_data
576
-                );
577
-                break;
578
-
579
-            default:
580
-                return $parsed;
581
-                break;
582
-        }
583
-    }
584
-
585
-
586
-    public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
587
-    {
588
-        $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
589
-            'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
590
-            'event_espresso'
591
-        );
592
-
593
-        return $shortcodes;
594
-    }
595
-
596
-
597
-    /**
598
-     * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
599
-     *
600
-     * @param string         $parsed           The original parsed content for the shortcode
601
-     * @param string         $shortcode        The shortcode being parsed
602
-     * @param array          $data             The shortcode parser data array
603
-     * @param array          $extra_data       The shortcode parser extra data array
604
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
605
-     *
606
-     * @return string
607
-     */
608
-    public function additional_primary_registration_details_parser(
609
-        $parsed,
610
-        $shortcode,
611
-        $data,
612
-        $extra_data,
613
-        $shortcode_parser
614
-    ) {
615
-        if (array($data) && ! isset($data['data'])) {
616
-            return $parsed;
617
-        }
618
-
619
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621
-
622
-        if (! $recipient instanceof EE_Messages_Addressee) {
623
-            return $parsed;
624
-        }
625
-
626
-        switch ($shortcode) {
627
-            case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629
-                    return '';
630
-                }
631
-                $registration = $recipient->primary_reg_obj;
632
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
634
-                    : array();
635
-                if (empty($answers)) {
636
-                    return '';
637
-                }
638
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
639
-                    ? $data['template']['question_list']
640
-                    : $extra_data['template']['question_list'];
641
-                $valid_shortcodes = array('question');
642
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
643
-                $questions = isset($recipient->questions) ? $recipient->questions : array();
644
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645
-                // object on it.
646
-                if (! isset($extra_data['data'])) {
647
-                    $extra_data['data'] = $recipient;
648
-                }
649
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
650
-                    $shortcode_parser,
651
-                    $questions,
652
-                    $answers,
653
-                    $template,
654
-                    $valid_shortcodes,
655
-                    $extra_data
656
-                );
657
-                break;
658
-
659
-            default:
660
-                return $parsed;
661
-                break;
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * Takes care of registering the  message types that are only available in caffeinated EE.
668
-     *
669
-     * @since   4.3.2
670
-     *
671
-     * @return  void
672
-     */
673
-    public function register_caf_message_types()
674
-    {
675
-        // register newsletter message type
676
-        $setup_args = array(
677
-            'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678
-            'autoloadpaths'                                    => array(
679
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
680
-            ),
681
-            'messengers_to_activate_with'                      => array('email'),
682
-            'messengers_to_validate_with'                      => array('email'),
683
-            'messengers_supporting_default_template_pack_with' => array('email'),
684
-        );
685
-        EE_Register_Message_Type::register('newsletter', $setup_args);
686
-
687
-        // register payment reminder message type
688
-        $setup_args = array(
689
-            'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
691
-            'messengers_to_activate_with'                      => array('email'),
692
-            'messengers_to_validate_with'                      => array('email'),
693
-            'messengers_supporting_default_template_pack_with' => array('email'),
694
-        );
695
-        EE_Register_Message_Type::register('payment_reminder', $setup_args);
696
-
697
-        // register payment declined message type
698
-        $setup_args = array(
699
-            'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
701
-            'messengers_to_activate_with'                      => array('email'),
702
-            'messengers_to_validate_with'                      => array('email'),
703
-            'messengers_supporting_default_template_pack_with' => array('email'),
704
-        );
705
-        EE_Register_Message_Type::register('payment_declined', $setup_args);
706
-
707
-        // register registration declined message type
708
-        $setup_args = array(
709
-            'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
711
-            'messengers_to_activate_with'                      => array('email'),
712
-            'messengers_to_validate_with'                      => array('email'),
713
-            'messengers_supporting_default_template_pack_with' => array('email'),
714
-        );
715
-        EE_Register_Message_Type::register('declined_registration', $setup_args);
716
-
717
-        // register registration cancelled message type
718
-        $setup_args = array(
719
-            'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
721
-            'messengers_to_activate_with'                      => array('email'),
722
-            'messengers_to_validate_with'                      => array('email'),
723
-            'messengers_supporting_default_template_pack_with' => array('email'),
724
-        );
725
-        EE_Register_Message_Type::register('cancelled_registration', $setup_args);
726
-
727
-
728
-        // register payment failed message type
729
-        $setup_args = array(
730
-            'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
732
-            'messengers_to_activate_with'                      => array('email'),
733
-            'messengers_to_validate_with'                      => array('email'),
734
-            'messengers_supporting_default_template_pack_with' => array('email'),
735
-        );
736
-        EE_Register_Message_Type::register('payment_failed', $setup_args);
737
-
738
-        // register payment declined message type
739
-        $setup_args = array(
740
-            'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
742
-            'messengers_to_activate_with'                      => array('email'),
743
-            'messengers_to_validate_with'                      => array('email'),
744
-            'messengers_supporting_default_template_pack_with' => array('email'),
745
-        );
746
-        EE_Register_Message_Type::register('payment_cancelled', $setup_args);
747
-    }
748
-
749
-
750
-    /**
751
-     * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
752
-     *
753
-     * @since   4.3.2
754
-     *
755
-     * @return void
756
-     */
757
-    public function register_caf_shortcodes()
758
-    {
759
-        $setup_args = array(
760
-            'autoloadpaths'                 => array(
761
-                EE_CAF_LIBRARIES . 'shortcodes/',
762
-            ),
763
-            'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764
-            'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
765
-            'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
766
-        );
767
-        EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
768
-    }
769
-
770
-
771
-    /**
772
-     * Parses a question list shortcode using given data and template
773
-     *
774
-     * @param \EE_Shortcodes $shortcode_parser
775
-     * @param EE_Question[]  $questions        An array of questions indexed by answer id.
776
-     * @param EE_Answer[]    $answers          An array of answer objects
777
-     * @param string         $template         Template content to be parsed.
778
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
779
-     * @param array          $extra_data       Extra data that might be used when parsing the template.
780
-     */
781
-    protected function _parse_question_list_for_primary_or_recipient_registration(
782
-        $shortcode_parser,
783
-        $questions,
784
-        $answers,
785
-        $template,
786
-        $valid_shortcodes,
787
-        $extra_data
788
-    ) {
789
-        $question_list = '';
790
-        /** @var EEH_Parse_Shortcodes $shortcode_helper */
791
-        $shortcode_helper = $shortcode_parser->get_shortcode_helper();
792
-        foreach ($answers as $answer) {
793
-            if ($answer instanceof EE_Answer) {
794
-                // first see if the question is in our $questions array. If not then try to get from answer object.
795
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
796
-                $question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
-                if (! $question instanceof EE_Question
798
-                    || (
799
-                        $question instanceof EE_Question
800
-                        && $question->admin_only()
801
-                    )
802
-                ) {
803
-                    continue;
804
-                }
805
-                $question_list .= $shortcode_helper->parse_question_list_template(
806
-                    $template,
807
-                    $answer,
808
-                    $valid_shortcodes,
809
-                    $extra_data
810
-                );
811
-            }
812
-        }
813
-        return $question_list;
814
-    }
16
+	/**
17
+	 * constructor.
18
+	 */
19
+	public function __construct()
20
+	{
21
+		$this->_caf_hooks();
22
+	}
23
+
24
+
25
+	/**
26
+	 * Contains all the hooks filters for setting up caffeinated messages functionality.
27
+	 *
28
+	 * @since 4.3.2
29
+	 *
30
+	 * @return void
31
+	 */
32
+	private function _caf_hooks()
33
+	{
34
+		add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
35
+		add_filter(
36
+			'FHEE__EE_Email_messenger__get_validator_config',
37
+			array($this, 'email_messenger_validator_config'),
38
+			5,
39
+			2
40
+		);
41
+		add_filter(
42
+			'FHEE__EE_Email_messenger__get_template_fields',
43
+			array($this, 'email_messenger_template_fields'),
44
+			5,
45
+			2
46
+		);
47
+		add_filter(
48
+			'FHEE__EE_Html_messenger__get_template_fields',
49
+			array($this, 'html_messenger_template_fields'),
50
+			5,
51
+			2
52
+		);
53
+		add_filter(
54
+			'FHEE__EE_Html_messenger__get_validator_config',
55
+			array($this, 'html_messenger_validator_config'),
56
+			5,
57
+			2
58
+		);
59
+		add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
60
+		add_filter(
61
+			'FHEE__EE_Pdf_messenger__get_validator_config',
62
+			array($this, 'pdf_messenger_validator_config'),
63
+			5,
64
+			2
65
+		);
66
+		add_filter(
67
+			'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
68
+			array($this, 'new_default_templates'),
69
+			5,
70
+			7
71
+		);
72
+		add_filter(
73
+			'FHEE__EE_Messages_Base__get_valid_shortcodes',
74
+			array($this, 'message_types_valid_shortcodes'),
75
+			5,
76
+			2
77
+		);
78
+
79
+		// shortcode parsers
80
+		add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
81
+		add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
82
+		add_filter(
83
+			'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
84
+			array($this, 'additional_recipient_details_shortcodes'),
85
+			5,
86
+			2
87
+		);
88
+		add_filter(
89
+			'FHEE__EE_Recipient_List_Shortcodes__parser_after',
90
+			array($this, 'additional_recipient_details_parser'),
91
+			5,
92
+			5
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
96
+			array($this, 'additional_primary_registration_details_shortcodes'),
97
+			5,
98
+			2
99
+		);
100
+		add_filter(
101
+			'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
102
+			array($this, 'additional_primary_registration_details_parser'),
103
+			5,
104
+			5
105
+		);
106
+
107
+		/**
108
+		 * @since 4.2.0
109
+		 */
110
+		add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
111
+		add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
112
+
113
+		/**
114
+		 * @since 4.3.0
115
+		 */
116
+		// eat our own dog food!
117
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
118
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
119
+		do_action('EE_Brewing_Regular___messages_caf');
120
+	}
121
+
122
+
123
+	/**
124
+	 * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
125
+	 * messages system.
126
+	 *
127
+	 * @param  array $dir_ref original array of paths
128
+	 *
129
+	 * @return array           appended paths
130
+	 */
131
+	public function messages_autoload_paths($dir_ref)
132
+	{
133
+		$dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
134
+
135
+		return $dir_ref;
136
+	}
137
+
138
+
139
+	public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
140
+	{
141
+		$validator_config['attendee_list'] = array(
142
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
143
+			'required'   => array('[ATTENDEE_LIST]'),
144
+		);
145
+		$validator_config['question_list'] = array(
146
+			'shortcodes' => array('question'),
147
+			'required'   => array('[QUESTION_LIST]'),
148
+		);
149
+
150
+		return $validator_config;
151
+	}
152
+
153
+
154
+	public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
155
+	{
156
+		$validator_config['attendee_list'] = array(
157
+			'shortcodes' => array('attendee', 'question_list'),
158
+			'required'   => array('[ATTENDEE_LIST]'),
159
+		);
160
+		$validator_config['question_list'] = array(
161
+			'shortcodes' => array('question'),
162
+			'required'   => array('[QUESTION_LIST]'),
163
+		);
164
+
165
+		return $validator_config;
166
+	}
167
+
168
+
169
+	public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
170
+	{
171
+		$validator_config['attendee_list'] = array(
172
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
173
+			'required'   => array('[ATTENDEE_LIST]'),
174
+		);
175
+		$validator_config['question_list'] = array(
176
+			'shortcodes' => array('question'),
177
+			'required'   => array('[QUESTION_LIST]'),
178
+		);
179
+
180
+		return $validator_config;
181
+	}
182
+
183
+
184
+	public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
185
+	{
186
+		$template_fields['extra']['content']['question_list'] = array(
187
+			'input'               => 'textarea',
188
+			'label'               => '[QUESTION_LIST]',
189
+			'type'                => 'string',
190
+			'required'            => true,
191
+			'validation'          => true,
192
+			'format'              => '%s',
193
+			'css_class'           => 'large-text',
194
+			'rows'                => '5',
195
+			'shortcodes_required' => array('[QUESTION_LIST]'),
196
+		);
197
+
198
+		return $template_fields;
199
+	}
200
+
201
+
202
+	public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
203
+	{
204
+		$template_fields['extra']['content']['question_list'] = array(
205
+			'input'               => 'textarea',
206
+			'label'               => '[QUESTION_LIST]',
207
+			'type'                => 'string',
208
+			'required'            => true,
209
+			'validation'          => true,
210
+			'format'              => '%s',
211
+			'css_class'           => 'large-text',
212
+			'rows'                => '5',
213
+			'shortcodes_required' => array('[QUESTION_LIST]'),
214
+		);
215
+
216
+		return $template_fields;
217
+	}
218
+
219
+
220
+	public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
221
+	{
222
+		$template_fields['extra']['content']['question_list'] = array(
223
+			'input'               => 'textarea',
224
+			'label'               => '[QUESTION_LIST]',
225
+			'type'                => 'string',
226
+			'required'            => true,
227
+			'validation'          => true,
228
+			'format'              => '%s',
229
+			'css_class'           => 'large-text',
230
+			'rows'                => '5',
231
+			'shortcodes_required' => array('[QUESTION_LIST]'),
232
+		);
233
+
234
+		return $template_fields;
235
+	}
236
+
237
+
238
+	public function new_default_templates(
239
+		$contents,
240
+		$actual_path,
241
+		EE_messenger $messenger,
242
+		EE_message_type $message_type,
243
+		$field,
244
+		$context,
245
+		EE_Messages_Template_Pack $template_pack
246
+	) {
247
+
248
+		// we're only modifying templates for the default template pack
249
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250
+			return $contents;
251
+		}
252
+
253
+		// the template file name we're replacing contents for.
254
+		$template_file_prefix = $field . '_' . $context;
255
+		$msg_prefix = $messenger->name . '_' . $message_type->name . '_';
256
+
257
+		$base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
258
+
259
+		if ($messenger->name == 'email' && $message_type->name == 'registration') {
260
+			switch ($template_file_prefix) {
261
+				case 'question_list_admin':
262
+				case 'question_list_attendee':
263
+				case 'question_list_primary_attendee':
264
+					$path = $base_path . $msg_prefix . 'question_list.template.php';
265
+					$contents = EEH_Template::display_template($path, array(), true);
266
+					break;
267
+
268
+				case 'attendee_list_primary_attendee':
269
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
270
+					$contents = EEH_Template::display_template($path, array(), true);
271
+					break;
272
+
273
+				case 'attendee_list_admin':
274
+					$path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
275
+					$contents = EEH_Template::display_template(
276
+						$path,
277
+						array(),
278
+						true
279
+					);
280
+					break;
281
+
282
+				case 'attendee_list_attendee':
283
+					$contents = '';
284
+					break;
285
+
286
+				case 'event_list_attendee':
287
+					$path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
288
+					$contents = EEH_Template::display_template($path, array(), true);
289
+					break;
290
+			}
291
+		} elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292
+			switch ($template_file_prefix) {
293
+				case 'content_attendee':
294
+					$path = $base_path . $msg_prefix . 'content.template.php';
295
+					$contents = EEH_Template::display_template($path, array(), true);
296
+					break;
297
+
298
+				case 'newsletter_content_attendee':
299
+					$path = $base_path . $msg_prefix . 'newsletter_content.template.php';
300
+					$contents = EEH_Template::display_template($path, array(), true);
301
+					break;
302
+
303
+				case 'newsletter_subject_attendee':
304
+					$path = $base_path . $msg_prefix . 'subject.template.php';
305
+					$contents = EEH_Template::display_template($path, array(), true);
306
+					break;
307
+			}
308
+		} elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309
+			switch ($template_file_prefix) {
310
+				case 'attendee_list_purchaser':
311
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
312
+					$contents = EEH_Template::display_template($path, array(), true);
313
+					break;
314
+			}
315
+		}
316
+
317
+		return $contents;
318
+	}
319
+
320
+
321
+	public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
322
+	{
323
+		// make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
324
+		$include_with = array(
325
+			'registration',
326
+			'cancelled_registration',
327
+			'declined_registration',
328
+			'not_approved_registration',
329
+			'payment_declined',
330
+			'payment_failed',
331
+			'payment_cancelled',
332
+			'payment',
333
+			'payment_reminder',
334
+			'pending_approval',
335
+			'registration_summary',
336
+			'invoice',
337
+			'receipt',
338
+		);
339
+		if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340
+			$contexts = array_keys($msg->get_contexts());
341
+			foreach ($contexts as $context) {
342
+				$valid_shortcodes[ $context ][] = 'question_list';
343
+				$valid_shortcodes[ $context ][] = 'question';
344
+			}
345
+		}
346
+
347
+		return $valid_shortcodes;
348
+	}
349
+
350
+
351
+	public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
352
+	{
353
+		$shortcodes['[ANSWER_*]'] = __(
354
+			'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
355
+			'event_espresso'
356
+		);
357
+
358
+		return $shortcodes;
359
+	}
360
+
361
+
362
+	public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
363
+	{
364
+
365
+		if (strpos($shortcode, '[ANSWER_*') === false
366
+			|| ! isset($extra_data['data']->questions)
367
+			|| ! isset($extra_data['data']->registrations)
368
+		) {
369
+			return $parsed;
370
+		}
371
+
372
+		// let's get the question from the code.
373
+		$shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
+		$shortcode = trim(str_replace(']', '', $shortcode));
375
+
376
+		$registration = $data instanceof EE_Registration ? $data : null;
377
+		$registration = ! $registration instanceof EE_Registration && is_array(
378
+			$extra_data
379
+		) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
+
381
+		$aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
+		$aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
+			$extra_data
384
+		) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
+
386
+		if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
+			return $parsed;
388
+		}
389
+
390
+		// now let's figure out which question has this text.
391
+		foreach ($aee->questions as $ansid => $question) {
392
+			if ($question instanceof EE_Question
393
+				&& trim($question->display_text()) == trim($shortcode)
394
+				&& isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
395
+			) {
396
+				return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
397
+					'ANS_value',
398
+					'no_wpautop'
399
+				);
400
+			}
401
+		}
402
+
403
+		// nothing!
404
+		return $parsed;
405
+	}
406
+
407
+
408
+	/**
409
+	 * Callback for additional shortcodes filter for adding additional datetime shortcodes.
410
+	 *
411
+	 * @since  4.2
412
+	 *
413
+	 * @param  array                  $shortcodes         array of shortcodes and
414
+	 *                                                    descriptions
415
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
416
+	 *
417
+	 * @return array                                        array of shortcodes and
418
+	 *                                                        descriptions
419
+	 */
420
+	public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
421
+	{
422
+		$shortcodes['[DTT_NAME]'] = __(
423
+			'This will be parsed to the Title given for a Datetime',
424
+			'event_espresso'
425
+		);
426
+		$shortcodes['[DTT_DESCRIPTION]'] = __(
427
+			'This will be parsed to the description for a Datetime',
428
+			'event_espresso'
429
+		);
430
+		$shortcodes['[DTT_NAME_OR_DATES]'] = __(
431
+			'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
432
+			'event_espresso'
433
+		);
434
+
435
+		return $shortcodes;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Callback for additional shortcodes parser filter used for adding parser for new
441
+	 * Datetime shortcodes
442
+	 *
443
+	 * @since  4.2
444
+	 *
445
+	 * @param  string                 $parsed     The finished parsed string for the given shortcode.
446
+	 * @param  string                 $shortcode  The shortcode being parsed.
447
+	 * @param  object                 $data       The incoming data object for the Shortcode Parser.
448
+	 * @param  object                 $extra_data The incoming extra date object for the Shortcode
449
+	 *                                            Parser.
450
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser
451
+	 *
452
+	 * @return string                   The new parsed string.
453
+	 */
454
+	public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455
+	{
456
+
457
+		if (! $data instanceof EE_Datetime) {
458
+			return ''; // get out because we can only parse with the datetime object.
459
+		}
460
+
461
+		switch ($shortcode) {
462
+			case '[DTT_NAME]':
463
+				return $data->name();
464
+				break;
465
+			case '[DTT_DESCRIPTION]':
466
+				return $data->description();
467
+				break;
468
+			case '[DTT_NAME_OR_DATES]':
469
+				return $data->get_dtt_display_name(true);
470
+				break;
471
+			default:
472
+				return $parsed;
473
+				break;
474
+		}
475
+	}
476
+
477
+
478
+	public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
479
+	{
480
+		$shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
481
+			'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
482
+			'event_espresso'
483
+		);
484
+
485
+		return $shortcodes;
486
+	}
487
+
488
+
489
+	/**
490
+	 * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
491
+	 *
492
+	 * @param string         $parsed           The original parsed content for the shortcode
493
+	 * @param string         $shortcode        The shortcode being parsed
494
+	 * @param array          $data             The shortcode parser data array
495
+	 * @param array          $extra_data       The shortcode parser extra data array
496
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
497
+	 *
498
+	 * @return string
499
+	 */
500
+	public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
501
+	{
502
+
503
+		if (array($data) && ! isset($data['data'])) {
504
+			return $parsed;
505
+		}
506
+
507
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509
+
510
+		if (! $recipient instanceof EE_Messages_Addressee) {
511
+			return $parsed;
512
+		}
513
+
514
+		switch ($shortcode) {
515
+			case '[RECIPIENT_QUESTION_LIST]':
516
+				$att = $recipient->att_obj;
517
+				$registrations_on_attendee = $att instanceof EE_Attendee
518
+					? $recipient->attendees[ $att->ID() ]['reg_objs']
519
+					: array();
520
+				$registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521
+				$answers = array();
522
+
523
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
524
+					? $data['template']['question_list']
525
+					: $extra_data['template']['question_list'];
526
+				$valid_shortcodes = array('question');
527
+
528
+				// if the context is main_content then get all answers for all registrations on this attendee
529
+				if ($data['data'] instanceof EE_Messages_Addressee) {
530
+					foreach ($registrations_on_attendee as $reg) {
531
+						if ($reg instanceof EE_Registration) {
532
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
534
+								: array();
535
+							foreach ($anss as $ans) {
536
+								if ($ans instanceof EE_Answer) {
537
+									$answers[ $ans->ID() ] = $ans;
538
+								}
539
+							}
540
+						}
541
+					}
542
+				}
543
+
544
+				// if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
545
+				if ($data['data'] instanceof EE_Event) {
546
+					$event = $data['data'];
547
+					foreach ($registrations_on_attendee as $reg) {
548
+						if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
551
+								: array();
552
+							foreach ($anss as $ans) {
553
+								if ($ans instanceof EE_Answer) {
554
+									$answers[ $ans->ID() ] = $ans;
555
+								}
556
+							}
557
+						}
558
+					}
559
+				}
560
+
561
+				$questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
562
+
563
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564
+				// object on it.
565
+				if (! isset($extra_data['data'])) {
566
+					$extra_data['data'] = $recipient;
567
+				}
568
+
569
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
570
+					$shortcode_parser,
571
+					$questions,
572
+					$answers,
573
+					$template,
574
+					$valid_shortcodes,
575
+					$extra_data
576
+				);
577
+				break;
578
+
579
+			default:
580
+				return $parsed;
581
+				break;
582
+		}
583
+	}
584
+
585
+
586
+	public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
587
+	{
588
+		$shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
589
+			'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
590
+			'event_espresso'
591
+		);
592
+
593
+		return $shortcodes;
594
+	}
595
+
596
+
597
+	/**
598
+	 * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
599
+	 *
600
+	 * @param string         $parsed           The original parsed content for the shortcode
601
+	 * @param string         $shortcode        The shortcode being parsed
602
+	 * @param array          $data             The shortcode parser data array
603
+	 * @param array          $extra_data       The shortcode parser extra data array
604
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
605
+	 *
606
+	 * @return string
607
+	 */
608
+	public function additional_primary_registration_details_parser(
609
+		$parsed,
610
+		$shortcode,
611
+		$data,
612
+		$extra_data,
613
+		$shortcode_parser
614
+	) {
615
+		if (array($data) && ! isset($data['data'])) {
616
+			return $parsed;
617
+		}
618
+
619
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621
+
622
+		if (! $recipient instanceof EE_Messages_Addressee) {
623
+			return $parsed;
624
+		}
625
+
626
+		switch ($shortcode) {
627
+			case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
+				if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629
+					return '';
630
+				}
631
+				$registration = $recipient->primary_reg_obj;
632
+				$answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
+					? $recipient->registrations[ $registration->ID() ]['ans_objs']
634
+					: array();
635
+				if (empty($answers)) {
636
+					return '';
637
+				}
638
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
639
+					? $data['template']['question_list']
640
+					: $extra_data['template']['question_list'];
641
+				$valid_shortcodes = array('question');
642
+				$answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
643
+				$questions = isset($recipient->questions) ? $recipient->questions : array();
644
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645
+				// object on it.
646
+				if (! isset($extra_data['data'])) {
647
+					$extra_data['data'] = $recipient;
648
+				}
649
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
650
+					$shortcode_parser,
651
+					$questions,
652
+					$answers,
653
+					$template,
654
+					$valid_shortcodes,
655
+					$extra_data
656
+				);
657
+				break;
658
+
659
+			default:
660
+				return $parsed;
661
+				break;
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * Takes care of registering the  message types that are only available in caffeinated EE.
668
+	 *
669
+	 * @since   4.3.2
670
+	 *
671
+	 * @return  void
672
+	 */
673
+	public function register_caf_message_types()
674
+	{
675
+		// register newsletter message type
676
+		$setup_args = array(
677
+			'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678
+			'autoloadpaths'                                    => array(
679
+				EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
680
+			),
681
+			'messengers_to_activate_with'                      => array('email'),
682
+			'messengers_to_validate_with'                      => array('email'),
683
+			'messengers_supporting_default_template_pack_with' => array('email'),
684
+		);
685
+		EE_Register_Message_Type::register('newsletter', $setup_args);
686
+
687
+		// register payment reminder message type
688
+		$setup_args = array(
689
+			'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
691
+			'messengers_to_activate_with'                      => array('email'),
692
+			'messengers_to_validate_with'                      => array('email'),
693
+			'messengers_supporting_default_template_pack_with' => array('email'),
694
+		);
695
+		EE_Register_Message_Type::register('payment_reminder', $setup_args);
696
+
697
+		// register payment declined message type
698
+		$setup_args = array(
699
+			'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
701
+			'messengers_to_activate_with'                      => array('email'),
702
+			'messengers_to_validate_with'                      => array('email'),
703
+			'messengers_supporting_default_template_pack_with' => array('email'),
704
+		);
705
+		EE_Register_Message_Type::register('payment_declined', $setup_args);
706
+
707
+		// register registration declined message type
708
+		$setup_args = array(
709
+			'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
711
+			'messengers_to_activate_with'                      => array('email'),
712
+			'messengers_to_validate_with'                      => array('email'),
713
+			'messengers_supporting_default_template_pack_with' => array('email'),
714
+		);
715
+		EE_Register_Message_Type::register('declined_registration', $setup_args);
716
+
717
+		// register registration cancelled message type
718
+		$setup_args = array(
719
+			'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
721
+			'messengers_to_activate_with'                      => array('email'),
722
+			'messengers_to_validate_with'                      => array('email'),
723
+			'messengers_supporting_default_template_pack_with' => array('email'),
724
+		);
725
+		EE_Register_Message_Type::register('cancelled_registration', $setup_args);
726
+
727
+
728
+		// register payment failed message type
729
+		$setup_args = array(
730
+			'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
732
+			'messengers_to_activate_with'                      => array('email'),
733
+			'messengers_to_validate_with'                      => array('email'),
734
+			'messengers_supporting_default_template_pack_with' => array('email'),
735
+		);
736
+		EE_Register_Message_Type::register('payment_failed', $setup_args);
737
+
738
+		// register payment declined message type
739
+		$setup_args = array(
740
+			'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
742
+			'messengers_to_activate_with'                      => array('email'),
743
+			'messengers_to_validate_with'                      => array('email'),
744
+			'messengers_supporting_default_template_pack_with' => array('email'),
745
+		);
746
+		EE_Register_Message_Type::register('payment_cancelled', $setup_args);
747
+	}
748
+
749
+
750
+	/**
751
+	 * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
752
+	 *
753
+	 * @since   4.3.2
754
+	 *
755
+	 * @return void
756
+	 */
757
+	public function register_caf_shortcodes()
758
+	{
759
+		$setup_args = array(
760
+			'autoloadpaths'                 => array(
761
+				EE_CAF_LIBRARIES . 'shortcodes/',
762
+			),
763
+			'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764
+			'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
765
+			'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
766
+		);
767
+		EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
768
+	}
769
+
770
+
771
+	/**
772
+	 * Parses a question list shortcode using given data and template
773
+	 *
774
+	 * @param \EE_Shortcodes $shortcode_parser
775
+	 * @param EE_Question[]  $questions        An array of questions indexed by answer id.
776
+	 * @param EE_Answer[]    $answers          An array of answer objects
777
+	 * @param string         $template         Template content to be parsed.
778
+	 * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
779
+	 * @param array          $extra_data       Extra data that might be used when parsing the template.
780
+	 */
781
+	protected function _parse_question_list_for_primary_or_recipient_registration(
782
+		$shortcode_parser,
783
+		$questions,
784
+		$answers,
785
+		$template,
786
+		$valid_shortcodes,
787
+		$extra_data
788
+	) {
789
+		$question_list = '';
790
+		/** @var EEH_Parse_Shortcodes $shortcode_helper */
791
+		$shortcode_helper = $shortcode_parser->get_shortcode_helper();
792
+		foreach ($answers as $answer) {
793
+			if ($answer instanceof EE_Answer) {
794
+				// first see if the question is in our $questions array. If not then try to get from answer object.
795
+				$question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
796
+				$question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
+				if (! $question instanceof EE_Question
798
+					|| (
799
+						$question instanceof EE_Question
800
+						&& $question->admin_only()
801
+					)
802
+				) {
803
+					continue;
804
+				}
805
+				$question_list .= $shortcode_helper->parse_question_list_template(
806
+					$template,
807
+					$answer,
808
+					$valid_shortcodes,
809
+					$extra_data
810
+				);
811
+			}
812
+		}
813
+		return $question_list;
814
+	}
815 815
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function messages_autoload_paths($dir_ref)
132 132
     {
133
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
133
+        $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/';
134 134
 
135 135
         return $dir_ref;
136 136
     }
@@ -246,32 +246,32 @@  discard block
 block discarded – undo
246 246
     ) {
247 247
 
248 248
         // we're only modifying templates for the default template pack
249
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
249
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250 250
             return $contents;
251 251
         }
252 252
 
253 253
         // the template file name we're replacing contents for.
254
-        $template_file_prefix = $field . '_' . $context;
255
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
254
+        $template_file_prefix = $field.'_'.$context;
255
+        $msg_prefix = $messenger->name.'_'.$message_type->name.'_';
256 256
 
257
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
257
+        $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/';
258 258
 
259 259
         if ($messenger->name == 'email' && $message_type->name == 'registration') {
260 260
             switch ($template_file_prefix) {
261 261
                 case 'question_list_admin':
262 262
                 case 'question_list_attendee':
263 263
                 case 'question_list_primary_attendee':
264
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
264
+                    $path = $base_path.$msg_prefix.'question_list.template.php';
265 265
                     $contents = EEH_Template::display_template($path, array(), true);
266 266
                     break;
267 267
 
268 268
                 case 'attendee_list_primary_attendee':
269
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
269
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
270 270
                     $contents = EEH_Template::display_template($path, array(), true);
271 271
                     break;
272 272
 
273 273
                 case 'attendee_list_admin':
274
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
274
+                    $path = $base_path.$msg_prefix.'attendee_list_admin.template.php';
275 275
                     $contents = EEH_Template::display_template(
276 276
                         $path,
277 277
                         array(),
@@ -284,31 +284,31 @@  discard block
 block discarded – undo
284 284
                     break;
285 285
 
286 286
                 case 'event_list_attendee':
287
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
287
+                    $path = $base_path.$msg_prefix.'event_list_attendee.template.php';
288 288
                     $contents = EEH_Template::display_template($path, array(), true);
289 289
                     break;
290 290
             }
291 291
         } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292 292
             switch ($template_file_prefix) {
293 293
                 case 'content_attendee':
294
-                    $path = $base_path . $msg_prefix . 'content.template.php';
294
+                    $path = $base_path.$msg_prefix.'content.template.php';
295 295
                     $contents = EEH_Template::display_template($path, array(), true);
296 296
                     break;
297 297
 
298 298
                 case 'newsletter_content_attendee':
299
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
299
+                    $path = $base_path.$msg_prefix.'newsletter_content.template.php';
300 300
                     $contents = EEH_Template::display_template($path, array(), true);
301 301
                     break;
302 302
 
303 303
                 case 'newsletter_subject_attendee':
304
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
304
+                    $path = $base_path.$msg_prefix.'subject.template.php';
305 305
                     $contents = EEH_Template::display_template($path, array(), true);
306 306
                     break;
307 307
             }
308 308
         } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309 309
             switch ($template_file_prefix) {
310 310
                 case 'attendee_list_purchaser':
311
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
311
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
312 312
                     $contents = EEH_Template::display_template($path, array(), true);
313 313
                     break;
314 314
             }
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
         if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340 340
             $contexts = array_keys($msg->get_contexts());
341 341
             foreach ($contexts as $context) {
342
-                $valid_shortcodes[ $context ][] = 'question_list';
343
-                $valid_shortcodes[ $context ][] = 'question';
342
+                $valid_shortcodes[$context][] = 'question_list';
343
+                $valid_shortcodes[$context][] = 'question';
344 344
             }
345 345
         }
346 346
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
             $extra_data
384 384
         ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385 385
 
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
386
+        if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387 387
             return $parsed;
388 388
         }
389 389
 
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
         foreach ($aee->questions as $ansid => $question) {
392 392
             if ($question instanceof EE_Question
393 393
                 && trim($question->display_text()) == trim($shortcode)
394
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
394
+                && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid])
395 395
             ) {
396
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
396
+                return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty(
397 397
                     'ANS_value',
398 398
                     'no_wpautop'
399 399
                 );
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455 455
     {
456 456
 
457
-        if (! $data instanceof EE_Datetime) {
457
+        if ( ! $data instanceof EE_Datetime) {
458 458
             return ''; // get out because we can only parse with the datetime object.
459 459
         }
460 460
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508 508
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509 509
 
510
-        if (! $recipient instanceof EE_Messages_Addressee) {
510
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
511 511
             return $parsed;
512 512
         }
513 513
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
             case '[RECIPIENT_QUESTION_LIST]':
516 516
                 $att = $recipient->att_obj;
517 517
                 $registrations_on_attendee = $att instanceof EE_Attendee
518
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
518
+                    ? $recipient->attendees[$att->ID()]['reg_objs']
519 519
                     : array();
520 520
                 $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521 521
                 $answers = array();
@@ -529,12 +529,12 @@  discard block
 block discarded – undo
529 529
                 if ($data['data'] instanceof EE_Messages_Addressee) {
530 530
                     foreach ($registrations_on_attendee as $reg) {
531 531
                         if ($reg instanceof EE_Registration) {
532
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
532
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
533
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
534 534
                                 : array();
535 535
                             foreach ($anss as $ans) {
536 536
                                 if ($ans instanceof EE_Answer) {
537
-                                    $answers[ $ans->ID() ] = $ans;
537
+                                    $answers[$ans->ID()] = $ans;
538 538
                                 }
539 539
                             }
540 540
                         }
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
                     $event = $data['data'];
547 547
                     foreach ($registrations_on_attendee as $reg) {
548 548
                         if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
549
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
550
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
551 551
                                 : array();
552 552
                             foreach ($anss as $ans) {
553 553
                                 if ($ans instanceof EE_Answer) {
554
-                                    $answers[ $ans->ID() ] = $ans;
554
+                                    $answers[$ans->ID()] = $ans;
555 555
                                 }
556 556
                             }
557 557
                         }
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 
563 563
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564 564
                 // object on it.
565
-                if (! isset($extra_data['data'])) {
565
+                if ( ! isset($extra_data['data'])) {
566 566
                     $extra_data['data'] = $recipient;
567 567
                 }
568 568
 
@@ -619,18 +619,18 @@  discard block
 block discarded – undo
619 619
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620 620
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621 621
 
622
-        if (! $recipient instanceof EE_Messages_Addressee) {
622
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
623 623
             return $parsed;
624 624
         }
625 625
 
626 626
         switch ($shortcode) {
627 627
             case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
628
+                if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629 629
                     return '';
630 630
                 }
631 631
                 $registration = $recipient->primary_reg_obj;
632
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
632
+                $answers = isset($recipient->registrations[$registration->ID()]['ans_objs'])
633
+                    ? $recipient->registrations[$registration->ID()]['ans_objs']
634 634
                     : array();
635 635
                 if (empty($answers)) {
636 636
                     return '';
@@ -639,11 +639,11 @@  discard block
 block discarded – undo
639 639
                     ? $data['template']['question_list']
640 640
                     : $extra_data['template']['question_list'];
641 641
                 $valid_shortcodes = array('question');
642
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
642
+                $answers = $recipient->registrations[$registration->ID()]['ans_objs'];
643 643
                 $questions = isset($recipient->questions) ? $recipient->questions : array();
644 644
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645 645
                 // object on it.
646
-                if (! isset($extra_data['data'])) {
646
+                if ( ! isset($extra_data['data'])) {
647 647
                     $extra_data['data'] = $recipient;
648 648
                 }
649 649
                 return $this->_parse_question_list_for_primary_or_recipient_registration(
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         $setup_args = array(
677 677
             'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678 678
             'autoloadpaths'                                    => array(
679
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
679
+                EE_CAF_LIBRARIES.'messages/message_type/newsletter/',
680 680
             ),
681 681
             'messengers_to_activate_with'                      => array('email'),
682 682
             'messengers_to_validate_with'                      => array('email'),
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
         // register payment reminder message type
688 688
         $setup_args = array(
689 689
             'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
690
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'),
691 691
             'messengers_to_activate_with'                      => array('email'),
692 692
             'messengers_to_validate_with'                      => array('email'),
693 693
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
         // register payment declined message type
698 698
         $setup_args = array(
699 699
             'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
700
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'),
701 701
             'messengers_to_activate_with'                      => array('email'),
702 702
             'messengers_to_validate_with'                      => array('email'),
703 703
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
         // register registration declined message type
708 708
         $setup_args = array(
709 709
             'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
710
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'),
711 711
             'messengers_to_activate_with'                      => array('email'),
712 712
             'messengers_to_validate_with'                      => array('email'),
713 713
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         // register registration cancelled message type
718 718
         $setup_args = array(
719 719
             'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
720
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'),
721 721
             'messengers_to_activate_with'                      => array('email'),
722 722
             'messengers_to_validate_with'                      => array('email'),
723 723
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
         // register payment failed message type
729 729
         $setup_args = array(
730 730
             'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
731
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'),
732 732
             'messengers_to_activate_with'                      => array('email'),
733 733
             'messengers_to_validate_with'                      => array('email'),
734 734
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
         // register payment declined message type
739 739
         $setup_args = array(
740 740
             'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
741
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'),
742 742
             'messengers_to_activate_with'                      => array('email'),
743 743
             'messengers_to_validate_with'                      => array('email'),
744 744
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
     {
759 759
         $setup_args = array(
760 760
             'autoloadpaths'                 => array(
761
-                EE_CAF_LIBRARIES . 'shortcodes/',
761
+                EE_CAF_LIBRARIES.'shortcodes/',
762 762
             ),
763 763
             'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764 764
             'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
         foreach ($answers as $answer) {
793 793
             if ($answer instanceof EE_Answer) {
794 794
                 // first see if the question is in our $questions array. If not then try to get from answer object.
795
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
795
+                $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null;
796 796
                 $question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
-                if (! $question instanceof EE_Question
797
+                if ( ! $question instanceof EE_Question
798 798
                     || (
799 799
                         $question instanceof EE_Question
800 800
                         && $question->admin_only()
Please login to merge, or discard this patch.