Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
105:07 queued 90:18
created
core/libraries/form_sections/base/EE_Form_Section_Base.form.php 2 patches
Indentation   +446 added lines, -446 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -19,462 +19,462 @@  discard block
 block discarded – undo
19 19
 abstract class EE_Form_Section_Base
20 20
 {
21 21
 
22
-    /**
23
-     * the URL the form is submitted to
24
-     *
25
-     * @var string
26
-     */
27
-    protected $_action;
28
-
29
-    /**
30
-     * POST (default) or GET
31
-     *
32
-     * @var string
33
-     */
34
-    protected $_method;
35
-
36
-    /**
37
-     * html_id and html_name are derived from this by default
38
-     *
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-    /**
44
-     * $_html_id
45
-     * @var string
46
-     */
47
-    protected $_html_id;
48
-
49
-    /**
50
-     * $_html_class
51
-     * @var string
52
-     */
53
-    protected $_html_class;
54
-
55
-    /**
56
-     * $_html_style
57
-     * @var string
58
-     */
59
-    protected $_html_style;
60
-
61
-    /**
62
-     * $_other_html_attributes
63
-     * @var string
64
-     */
65
-    protected $_other_html_attributes;
66
-
67
-    /**
68
-     * The form section of which this form section is a part
69
-     *
70
-     * @var EE_Form_Section_Proper
71
-     */
72
-    protected $_parent_section;
73
-
74
-    /**
75
-     * flag indicating that _construct_finalize has been called.
76
-     * If it hasn't been called and we try to use functions which require it, we call it
77
-     * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
-     *
79
-     * @var boolean
80
-     */
81
-    protected $_construction_finalized;
82
-
83
-    /**
84
-     * Strategy for parsing the form HTML upon display
85
-     *
86
-     * @var FormHtmlFilter
87
-     */
88
-    protected $_form_html_filter;
89
-
90
-
91
-
92
-    /**
93
-     * @param array $options_array {
94
-     * @type        $name          string the name for this form section, if you want to explicitly define it
95
-     *                             }
96
-     */
97
-    public function __construct($options_array = array())
98
-    {
99
-        // used by display strategies
100
-        // assign incoming values to properties
101
-        foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
103
-            if (property_exists($this, $key) && empty($this->{$key})) {
104
-                $this->{$key} = $value;
105
-            }
106
-        }
107
-        // set parser which allows the form section's rendered HTML to be filtered
108
-        if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
-            $this->_form_html_filter = $options_array['form_html_filter'];
110
-        }
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param $parent_form_section
117
-     * @param $name
118
-     * @throws \EE_Error
119
-     */
120
-    protected function _construct_finalize($parent_form_section, $name)
121
-    {
122
-        $this->_construction_finalized = true;
123
-        $this->_parent_section = $parent_form_section;
124
-        if ($name !== null) {
125
-            $this->_name = $name;
126
-        }
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * make sure construction finalized was called, otherwise children might not be ready
133
-     *
134
-     * @return void
135
-     * @throws \EE_Error
136
-     */
137
-    public function ensure_construct_finalized_called()
138
-    {
139
-        if (! $this->_construction_finalized) {
140
-            $this->_construct_finalize($this->_parent_section, $this->_name);
141
-        }
142
-    }
143
-
144
-
145
-
146
-    /**
147
-     * @return string
148
-     */
149
-    public function action()
150
-    {
151
-        return $this->_action;
152
-    }
153
-
154
-
155
-
156
-    /**
157
-     * @param string $action
158
-     */
159
-    public function set_action($action)
160
-    {
161
-        $this->_action = $action;
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @return string
168
-     */
169
-    public function method()
170
-    {
171
-        return ! empty($this->_method) ? $this->_method : 'POST';
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * @param string $method
178
-     */
179
-    public function set_method($method)
180
-    {
181
-        switch ($method) {
182
-            case 'get' :
183
-            case 'GET' :
184
-                $this->_method = 'GET';
185
-                break;
186
-            default :
187
-                $this->_method = 'POST';
188
-        }
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * Sets the html_id to its default value, if none was specified in the constructor.
195
-     * Calculation involves using the name and the parent's html id
196
-     * return void
197
-     *
198
-     * @throws \EE_Error
199
-     */
200
-    protected function _set_default_html_id_if_empty()
201
-    {
202
-        if (! $this->_html_id) {
203
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
-                $this->_html_id = $this->_parent_section->html_id()
205
-                                  . '-'
206
-                                  . $this->_prep_name_for_html_id($this->name());
207
-            } else {
208
-                $this->_html_id = $this->_prep_name_for_html_id($this->name());
209
-            }
210
-        }
211
-    }
212
-
213
-
214
-
215
-    /**
216
-     * _prep_name_for_html_id
217
-     *
218
-     * @param $name
219
-     * @return string
220
-     */
221
-    private function _prep_name_for_html_id($name)
222
-    {
223
-        return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name));
224
-    }
22
+	/**
23
+	 * the URL the form is submitted to
24
+	 *
25
+	 * @var string
26
+	 */
27
+	protected $_action;
28
+
29
+	/**
30
+	 * POST (default) or GET
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $_method;
35
+
36
+	/**
37
+	 * html_id and html_name are derived from this by default
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+	/**
44
+	 * $_html_id
45
+	 * @var string
46
+	 */
47
+	protected $_html_id;
48
+
49
+	/**
50
+	 * $_html_class
51
+	 * @var string
52
+	 */
53
+	protected $_html_class;
54
+
55
+	/**
56
+	 * $_html_style
57
+	 * @var string
58
+	 */
59
+	protected $_html_style;
60
+
61
+	/**
62
+	 * $_other_html_attributes
63
+	 * @var string
64
+	 */
65
+	protected $_other_html_attributes;
66
+
67
+	/**
68
+	 * The form section of which this form section is a part
69
+	 *
70
+	 * @var EE_Form_Section_Proper
71
+	 */
72
+	protected $_parent_section;
73
+
74
+	/**
75
+	 * flag indicating that _construct_finalize has been called.
76
+	 * If it hasn't been called and we try to use functions which require it, we call it
77
+	 * with no parameters. But normally, _construct_finalize should be called by the instantiating class
78
+	 *
79
+	 * @var boolean
80
+	 */
81
+	protected $_construction_finalized;
82
+
83
+	/**
84
+	 * Strategy for parsing the form HTML upon display
85
+	 *
86
+	 * @var FormHtmlFilter
87
+	 */
88
+	protected $_form_html_filter;
89
+
90
+
91
+
92
+	/**
93
+	 * @param array $options_array {
94
+	 * @type        $name          string the name for this form section, if you want to explicitly define it
95
+	 *                             }
96
+	 */
97
+	public function __construct($options_array = array())
98
+	{
99
+		// used by display strategies
100
+		// assign incoming values to properties
101
+		foreach ($options_array as $key => $value) {
102
+			$key = '_' . $key;
103
+			if (property_exists($this, $key) && empty($this->{$key})) {
104
+				$this->{$key} = $value;
105
+			}
106
+		}
107
+		// set parser which allows the form section's rendered HTML to be filtered
108
+		if (isset($options_array['form_html_filter']) && $options_array['form_html_filter'] instanceof FormHtmlFilter) {
109
+			$this->_form_html_filter = $options_array['form_html_filter'];
110
+		}
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param $parent_form_section
117
+	 * @param $name
118
+	 * @throws \EE_Error
119
+	 */
120
+	protected function _construct_finalize($parent_form_section, $name)
121
+	{
122
+		$this->_construction_finalized = true;
123
+		$this->_parent_section = $parent_form_section;
124
+		if ($name !== null) {
125
+			$this->_name = $name;
126
+		}
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * make sure construction finalized was called, otherwise children might not be ready
133
+	 *
134
+	 * @return void
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function ensure_construct_finalized_called()
138
+	{
139
+		if (! $this->_construction_finalized) {
140
+			$this->_construct_finalize($this->_parent_section, $this->_name);
141
+		}
142
+	}
143
+
144
+
145
+
146
+	/**
147
+	 * @return string
148
+	 */
149
+	public function action()
150
+	{
151
+		return $this->_action;
152
+	}
153
+
154
+
155
+
156
+	/**
157
+	 * @param string $action
158
+	 */
159
+	public function set_action($action)
160
+	{
161
+		$this->_action = $action;
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @return string
168
+	 */
169
+	public function method()
170
+	{
171
+		return ! empty($this->_method) ? $this->_method : 'POST';
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * @param string $method
178
+	 */
179
+	public function set_method($method)
180
+	{
181
+		switch ($method) {
182
+			case 'get' :
183
+			case 'GET' :
184
+				$this->_method = 'GET';
185
+				break;
186
+			default :
187
+				$this->_method = 'POST';
188
+		}
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * Sets the html_id to its default value, if none was specified in the constructor.
195
+	 * Calculation involves using the name and the parent's html id
196
+	 * return void
197
+	 *
198
+	 * @throws \EE_Error
199
+	 */
200
+	protected function _set_default_html_id_if_empty()
201
+	{
202
+		if (! $this->_html_id) {
203
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204
+				$this->_html_id = $this->_parent_section->html_id()
205
+								  . '-'
206
+								  . $this->_prep_name_for_html_id($this->name());
207
+			} else {
208
+				$this->_html_id = $this->_prep_name_for_html_id($this->name());
209
+			}
210
+		}
211
+	}
212
+
213
+
214
+
215
+	/**
216
+	 * _prep_name_for_html_id
217
+	 *
218
+	 * @param $name
219
+	 * @return string
220
+	 */
221
+	private function _prep_name_for_html_id($name)
222
+	{
223
+		return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name));
224
+	}
225 225
 
226 226
 
227 227
 
228
-    /**
229
-     * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
-     * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
-     * and call get_html when you want to output the html. Calling get_html_and_js after
232
-     * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
-     * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
-     * and so might stop working anytime.
235
-     *
236
-     * @return string
237
-     */
238
-    public function get_html_and_js()
239
-    {
240
-        return $this->get_html();
241
-    }
228
+	/**
229
+	 * Returns the HTML, JS, and CSS necessary to display this form section on a page.
230
+	 * Note however, it's recommended that you instead call enqueue_js on the "wp_enqueue_scripts" action,
231
+	 * and call get_html when you want to output the html. Calling get_html_and_js after
232
+	 * "wp_enqueue_scripts" has already fired seems to work for now, but is contrary
233
+	 * to the instructions on https://developer.wordpress.org/reference/functions/wp_enqueue_script/
234
+	 * and so might stop working anytime.
235
+	 *
236
+	 * @return string
237
+	 */
238
+	public function get_html_and_js()
239
+	{
240
+		return $this->get_html();
241
+	}
242 242
 
243 243
 
244 244
 
245
-    /**
246
-     * Gets the HTML for displaying this form section
247
-     *
248
-     * @return string
249
-     */
250
-    public abstract function get_html();
245
+	/**
246
+	 * Gets the HTML for displaying this form section
247
+	 *
248
+	 * @return string
249
+	 */
250
+	public abstract function get_html();
251 251
 
252 252
 
253 253
 
254
-    /**
255
-     * @param bool $add_pound_sign
256
-     * @return string
257
-     */
258
-    public function html_id($add_pound_sign = false)
259
-    {
260
-        $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
-    }
254
+	/**
255
+	 * @param bool $add_pound_sign
256
+	 * @return string
257
+	 */
258
+	public function html_id($add_pound_sign = false)
259
+	{
260
+		$this->_set_default_html_id_if_empty();
261
+		return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
262
+	}
263 263
 
264 264
 
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function html_class()
270
-    {
271
-        return $this->_html_class;
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @return string
278
-     */
279
-    public function html_style()
280
-    {
281
-        return $this->_html_style;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param mixed $html_class
288
-     */
289
-    public function set_html_class($html_class)
290
-    {
291
-        $this->_html_class = $html_class;
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param mixed $html_id
298
-     */
299
-    public function set_html_id($html_id)
300
-    {
301
-        $this->_html_id = $html_id;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * @param mixed $html_style
308
-     */
309
-    public function set_html_style($html_style)
310
-    {
311
-        $this->_html_style = $html_style;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * @param string $other_html_attributes
318
-     */
319
-    public function set_other_html_attributes($other_html_attributes)
320
-    {
321
-        $this->_other_html_attributes = $other_html_attributes;
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * @return string
328
-     */
329
-    public function other_html_attributes()
330
-    {
331
-        return $this->_other_html_attributes;
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * Gets the name of the form section. This is not the same as the HTML name.
338
-     *
339
-     * @throws EE_Error
340
-     * @return string
341
-     */
342
-    public function name()
343
-    {
344
-        if (! $this->_construction_finalized) {
345
-            throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
-                'event_espresso'), get_class($this)));
347
-        }
348
-        return $this->_name;
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * Gets the parent section
355
-     *
356
-     * @return EE_Form_Section_Proper
357
-     */
358
-    public function parent_section()
359
-    {
360
-        return $this->_parent_section;
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * returns HTML for generating the opening form HTML tag (<form>)
367
-     *
368
-     * @param string $action           the URL the form is submitted to
369
-     * @param string $method           POST (default) or GET
370
-     * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
-     * @return string
372
-     */
373
-    public function form_open($action = '', $method = '', $other_attributes = '')
374
-    {
375
-        if (! empty($action)) {
376
-            $this->set_action($action);
377
-        }
378
-        if (! empty($method)) {
379
-            $this->set_method($method);
380
-        }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
386
-        return $html;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * returns HTML for generating the closing form HTML tag (</form>)
393
-     *
394
-     * @return string
395
-     */
396
-    public function form_close()
397
-    {
398
-        return EEH_HTML::nl(-1, 'form')
399
-               . '</form>'
400
-               . EEH_HTML::nl()
401
-               . '<!-- end of ee-'
402
-               . $this->html_id()
403
-               . '-form -->'
404
-               . EEH_HTML::nl();
405
-    }
406
-
407
-
408
-
409
-    /**
410
-     * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
411
-     * wp_enqueue_style; the scripts could have optionally been registered earlier)
412
-     * Default does nothing, but child classes can override
413
-     *
414
-     * @return void
415
-     */
416
-    public function enqueue_js()
417
-    {
418
-        //defaults to enqueue NO js or css
419
-    }
420
-
421
-
422
-
423
-    /**
424
-     * Adds any extra data needed by js. Eventually we'll call wp_localize_script
425
-     * with it, and it will be on each form section's 'other_data' property.
426
-     * By default nothing is added, but child classes can extend this method to add something.
427
-     * Eg, if you have an input that will cause a modal dialog to appear,
428
-     * here you could add an entry like 'modal_dialog_inputs' to this array
429
-     * to map between the input's html ID and the modal dialogue's ID, so that
430
-     * your JS code will know where to find the modal dialog when the input is pressed.
431
-     * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
432
-     *
433
-     * @param array $form_other_js_data
434
-     * @return array
435
-     */
436
-    public function get_other_js_data($form_other_js_data = array())
437
-    {
438
-        return $form_other_js_data;
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * This isn't just the name of an input, it's a path pointing to an input. The
445
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
446
-     * dot-dot-slash (../) means to ascend into the parent section.
447
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
448
-     * which will be returned.
449
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
450
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
451
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
452
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
453
-     * Etc
454
-     *
455
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
456
-     * @return EE_Form_Section_Base
457
-     */
458
-    public function find_section_from_path($form_section_path)
459
-    {
460
-        if (strpos($form_section_path, '/') === 0) {
461
-            $form_section_path = substr($form_section_path, strlen('/'));
462
-        }
463
-        if (empty($form_section_path)) {
464
-            return $this;
465
-        }
466
-        if (strpos($form_section_path, '../') === 0) {
467
-            $parent = $this->parent_section();
468
-            $form_section_path = substr($form_section_path, strlen('../'));
469
-            if ($parent instanceof EE_Form_Section_Base) {
470
-                return $parent->find_section_from_path($form_section_path);
471
-            } elseif (empty($form_section_path)) {
472
-                return $this;
473
-            }
474
-        }
475
-        //couldn't find it using simple parent following
476
-        return null;
477
-    }
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function html_class()
270
+	{
271
+		return $this->_html_class;
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @return string
278
+	 */
279
+	public function html_style()
280
+	{
281
+		return $this->_html_style;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param mixed $html_class
288
+	 */
289
+	public function set_html_class($html_class)
290
+	{
291
+		$this->_html_class = $html_class;
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param mixed $html_id
298
+	 */
299
+	public function set_html_id($html_id)
300
+	{
301
+		$this->_html_id = $html_id;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * @param mixed $html_style
308
+	 */
309
+	public function set_html_style($html_style)
310
+	{
311
+		$this->_html_style = $html_style;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * @param string $other_html_attributes
318
+	 */
319
+	public function set_other_html_attributes($other_html_attributes)
320
+	{
321
+		$this->_other_html_attributes = $other_html_attributes;
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * @return string
328
+	 */
329
+	public function other_html_attributes()
330
+	{
331
+		return $this->_other_html_attributes;
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * Gets the name of the form section. This is not the same as the HTML name.
338
+	 *
339
+	 * @throws EE_Error
340
+	 * @return string
341
+	 */
342
+	public function name()
343
+	{
344
+		if (! $this->_construction_finalized) {
345
+			throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346
+				'event_espresso'), get_class($this)));
347
+		}
348
+		return $this->_name;
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * Gets the parent section
355
+	 *
356
+	 * @return EE_Form_Section_Proper
357
+	 */
358
+	public function parent_section()
359
+	{
360
+		return $this->_parent_section;
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * returns HTML for generating the opening form HTML tag (<form>)
367
+	 *
368
+	 * @param string $action           the URL the form is submitted to
369
+	 * @param string $method           POST (default) or GET
370
+	 * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML
371
+	 * @return string
372
+	 */
373
+	public function form_open($action = '', $method = '', $other_attributes = '')
374
+	{
375
+		if (! empty($action)) {
376
+			$this->set_action($action);
377
+		}
378
+		if (! empty($method)) {
379
+			$this->set_method($method);
380
+		}
381
+		$html = EEH_HTML::nl(1, 'form') . '<form';
382
+		$html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : '';
383
+		$html .= ' action="' . $this->action() . '"';
384
+		$html .= ' method="' . $this->method() . '"';
385
+		$html .= $other_attributes . '>';
386
+		return $html;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * returns HTML for generating the closing form HTML tag (</form>)
393
+	 *
394
+	 * @return string
395
+	 */
396
+	public function form_close()
397
+	{
398
+		return EEH_HTML::nl(-1, 'form')
399
+			   . '</form>'
400
+			   . EEH_HTML::nl()
401
+			   . '<!-- end of ee-'
402
+			   . $this->html_id()
403
+			   . '-form -->'
404
+			   . EEH_HTML::nl();
405
+	}
406
+
407
+
408
+
409
+	/**
410
+	 * enqueues JS (and CSS) for the form (ie immediately call wp_enqueue_script and
411
+	 * wp_enqueue_style; the scripts could have optionally been registered earlier)
412
+	 * Default does nothing, but child classes can override
413
+	 *
414
+	 * @return void
415
+	 */
416
+	public function enqueue_js()
417
+	{
418
+		//defaults to enqueue NO js or css
419
+	}
420
+
421
+
422
+
423
+	/**
424
+	 * Adds any extra data needed by js. Eventually we'll call wp_localize_script
425
+	 * with it, and it will be on each form section's 'other_data' property.
426
+	 * By default nothing is added, but child classes can extend this method to add something.
427
+	 * Eg, if you have an input that will cause a modal dialog to appear,
428
+	 * here you could add an entry like 'modal_dialog_inputs' to this array
429
+	 * to map between the input's html ID and the modal dialogue's ID, so that
430
+	 * your JS code will know where to find the modal dialog when the input is pressed.
431
+	 * Eg $form_other_js_data['modal_dialog_inputs']['some-input-id']='modal-dialog-id';
432
+	 *
433
+	 * @param array $form_other_js_data
434
+	 * @return array
435
+	 */
436
+	public function get_other_js_data($form_other_js_data = array())
437
+	{
438
+		return $form_other_js_data;
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * This isn't just the name of an input, it's a path pointing to an input. The
445
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
446
+	 * dot-dot-slash (../) means to ascend into the parent section.
447
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
448
+	 * which will be returned.
449
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
450
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
451
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
452
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
453
+	 * Etc
454
+	 *
455
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
456
+	 * @return EE_Form_Section_Base
457
+	 */
458
+	public function find_section_from_path($form_section_path)
459
+	{
460
+		if (strpos($form_section_path, '/') === 0) {
461
+			$form_section_path = substr($form_section_path, strlen('/'));
462
+		}
463
+		if (empty($form_section_path)) {
464
+			return $this;
465
+		}
466
+		if (strpos($form_section_path, '../') === 0) {
467
+			$parent = $this->parent_section();
468
+			$form_section_path = substr($form_section_path, strlen('../'));
469
+			if ($parent instanceof EE_Form_Section_Base) {
470
+				return $parent->find_section_from_path($form_section_path);
471
+			} elseif (empty($form_section_path)) {
472
+				return $this;
473
+			}
474
+		}
475
+		//couldn't find it using simple parent following
476
+		return null;
477
+	}
478 478
 
479 479
 
480 480
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use EventEspresso\core\libraries\form_sections\strategies\filter\FormHtmlFilter;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         // used by display strategies
100 100
         // assign incoming values to properties
101 101
         foreach ($options_array as $key => $value) {
102
-            $key = '_' . $key;
102
+            $key = '_'.$key;
103 103
             if (property_exists($this, $key) && empty($this->{$key})) {
104 104
                 $this->{$key} = $value;
105 105
             }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      */
137 137
     public function ensure_construct_finalized_called()
138 138
     {
139
-        if (! $this->_construction_finalized) {
139
+        if ( ! $this->_construction_finalized) {
140 140
             $this->_construct_finalize($this->_parent_section, $this->_name);
141 141
         }
142 142
     }
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     protected function _set_default_html_id_if_empty()
201 201
     {
202
-        if (! $this->_html_id) {
202
+        if ( ! $this->_html_id) {
203 203
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
204 204
                 $this->_html_id = $this->_parent_section->html_id()
205 205
                                   . '-'
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     public function html_id($add_pound_sign = false)
259 259
     {
260 260
         $this->_set_default_html_id_if_empty();
261
-        return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id;
261
+        return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id;
262 262
     }
263 263
 
264 264
 
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function name()
343 343
     {
344
-        if (! $this->_construction_finalized) {
344
+        if ( ! $this->_construction_finalized) {
345 345
             throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'',
346 346
                 'event_espresso'), get_class($this)));
347 347
         }
@@ -372,17 +372,17 @@  discard block
 block discarded – undo
372 372
      */
373 373
     public function form_open($action = '', $method = '', $other_attributes = '')
374 374
     {
375
-        if (! empty($action)) {
375
+        if ( ! empty($action)) {
376 376
             $this->set_action($action);
377 377
         }
378
-        if (! empty($method)) {
378
+        if ( ! empty($method)) {
379 379
             $this->set_method($method);
380 380
         }
381
-        $html = EEH_HTML::nl(1, 'form') . '<form';
382
-        $html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : '';
383
-        $html .= ' action="' . $this->action() . '"';
384
-        $html .= ' method="' . $this->method() . '"';
385
-        $html .= $other_attributes . '>';
381
+        $html = EEH_HTML::nl(1, 'form').'<form';
382
+        $html .= $this->html_id() !== '' ? ' id="'.$this->html_id().'"' : '';
383
+        $html .= ' action="'.$this->action().'"';
384
+        $html .= ' method="'.$this->method().'"';
385
+        $html .= $other_attributes.'>';
386 386
         return $html;
387 387
     }
388 388
 
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/layout/EE_No_Layout.strategy.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,110 +13,110 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * This is a flag indicating whether to use '<br>' tags after each input in the layout
18
-     * strategy.
19
-     *
20
-     * @var bool
21
-     */
22
-    protected $_use_break_tags = true;
16
+	/**
17
+	 * This is a flag indicating whether to use '<br>' tags after each input in the layout
18
+	 * strategy.
19
+	 *
20
+	 * @var bool
21
+	 */
22
+	protected $_use_break_tags = true;
23 23
 
24 24
 
25
-    /**
26
-     * EE_No_Layout constructor.
27
-     *
28
-     * @param array $options  Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags
29
-     *                        property on the class.
30
-     */
31
-    public function __construct($options = array())
32
-    {
33
-        $this->_use_break_tags = is_array($options) && isset($options['use_break_tags'])
34
-            ? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN)
35
-            : $this->_use_break_tags;
36
-        parent::__construct();
37
-    }
25
+	/**
26
+	 * EE_No_Layout constructor.
27
+	 *
28
+	 * @param array $options  Currently if this has a 'use_break_tags' key that is used to set the _use_break_tags
29
+	 *                        property on the class.
30
+	 */
31
+	public function __construct($options = array())
32
+	{
33
+		$this->_use_break_tags = is_array($options) && isset($options['use_break_tags'])
34
+			? filter_var($options['use_break_tags'], FILTER_VALIDATE_BOOLEAN)
35
+			: $this->_use_break_tags;
36
+		parent::__construct();
37
+	}
38 38
 
39
-    /**
40
-     * Add line break at beginning of form
41
-     *
42
-     * @return string
43
-     */
44
-    public function layout_form_begin()
45
-    {
46
-        return EEH_HTML::nl(1);
47
-    }
39
+	/**
40
+	 * Add line break at beginning of form
41
+	 *
42
+	 * @return string
43
+	 */
44
+	public function layout_form_begin()
45
+	{
46
+		return EEH_HTML::nl(1);
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * Lays out the row for the input, including label and errors
52
-     *
53
-     * @param EE_Form_Input_Base $input
54
-     * @return string
55
-     * @throws \EE_Error
56
-     */
57
-    public function layout_input($input)
58
-    {
59
-        $html = '';
60
-        if ($input instanceof EE_Hidden_Input) {
61
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
62
-        } else if ($input instanceof EE_Submit_Input) {
63
-            $html .= $this->br();
64
-            $html .= $input->get_html_for_input();
65
-        } else if ($input instanceof EE_Select_Input) {
66
-            $html .= $this->br();
67
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
68
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
69
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
70
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
71
-            $html .= $this->br();
72
-        } else if ($input instanceof EE_Form_Input_With_Options_Base) {
73
-            $html .= $this->br();
74
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
75
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
76
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
77
-        } else {
78
-            $html .= $this->br();
79
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
80
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
81
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
82
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
83
-        }
84
-        $html .= EEH_HTML::nl(-1);
85
-        return $html;
86
-    }
50
+	/**
51
+	 * Lays out the row for the input, including label and errors
52
+	 *
53
+	 * @param EE_Form_Input_Base $input
54
+	 * @return string
55
+	 * @throws \EE_Error
56
+	 */
57
+	public function layout_input($input)
58
+	{
59
+		$html = '';
60
+		if ($input instanceof EE_Hidden_Input) {
61
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
62
+		} else if ($input instanceof EE_Submit_Input) {
63
+			$html .= $this->br();
64
+			$html .= $input->get_html_for_input();
65
+		} else if ($input instanceof EE_Select_Input) {
66
+			$html .= $this->br();
67
+			$html .= EEH_HTML::nl(1) . $input->get_html_for_label();
68
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
69
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
70
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
71
+			$html .= $this->br();
72
+		} else if ($input instanceof EE_Form_Input_With_Options_Base) {
73
+			$html .= $this->br();
74
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
75
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
76
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
77
+		} else {
78
+			$html .= $this->br();
79
+			$html .= EEH_HTML::nl(1) . $input->get_html_for_label();
80
+			$html .= EEH_HTML::nl() . $input->get_html_for_errors();
81
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
82
+			$html .= EEH_HTML::nl() . $input->get_html_for_help();
83
+		}
84
+		$html .= EEH_HTML::nl(-1);
85
+		return $html;
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Lays out a row for the subsection
91
-     *
92
-     * @param EE_Form_Section_Proper $form_section
93
-     * @return string
94
-     */
95
-    public function layout_subsection($form_section)
96
-    {
89
+	/**
90
+	 * Lays out a row for the subsection
91
+	 *
92
+	 * @param EE_Form_Section_Proper $form_section
93
+	 * @return string
94
+	 */
95
+	public function layout_subsection($form_section)
96
+	{
97 97
 //		d( $form_section );
98
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
99
-    }
98
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * Add line break at end of form.
104
-     *
105
-     * @return string
106
-     */
107
-    public function layout_form_end()
108
-    {
109
-        return EEH_HTML::nl(-1);
110
-    }
102
+	/**
103
+	 * Add line break at end of form.
104
+	 *
105
+	 * @return string
106
+	 */
107
+	public function layout_form_end()
108
+	{
109
+		return EEH_HTML::nl(-1);
110
+	}
111 111
 
112 112
 
113
-    /**
114
-     * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property.
115
-     *
116
-     * @return string
117
-     */
118
-    protected function br()
119
-    {
120
-        return $this->_use_break_tags ? EEH_HTML::br() : '';
121
-    }
113
+	/**
114
+	 * This returns a break tag or an empty string depending on the value of the `_use_break_tags` property.
115
+	 *
116
+	 * @return string
117
+	 */
118
+	protected function br()
119
+	{
120
+		return $this->_use_break_tags ? EEH_HTML::br() : '';
121
+	}
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -58,28 +58,28 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $html = '';
60 60
         if ($input instanceof EE_Hidden_Input) {
61
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
61
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
62 62
         } else if ($input instanceof EE_Submit_Input) {
63 63
             $html .= $this->br();
64 64
             $html .= $input->get_html_for_input();
65 65
         } else if ($input instanceof EE_Select_Input) {
66 66
             $html .= $this->br();
67
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
68
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
69
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
70
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
67
+            $html .= EEH_HTML::nl(1).$input->get_html_for_label();
68
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
69
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
70
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
71 71
             $html .= $this->br();
72 72
         } else if ($input instanceof EE_Form_Input_With_Options_Base) {
73 73
             $html .= $this->br();
74
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
75
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
76
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
74
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
75
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
76
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
77 77
         } else {
78 78
             $html .= $this->br();
79
-            $html .= EEH_HTML::nl(1) . $input->get_html_for_label();
80
-            $html .= EEH_HTML::nl() . $input->get_html_for_errors();
81
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
82
-            $html .= EEH_HTML::nl() . $input->get_html_for_help();
79
+            $html .= EEH_HTML::nl(1).$input->get_html_for_label();
80
+            $html .= EEH_HTML::nl().$input->get_html_for_errors();
81
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
82
+            $html .= EEH_HTML::nl().$input->get_html_for_help();
83 83
         }
84 84
         $html .= EEH_HTML::nl(-1);
85 85
         return $html;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function layout_subsection($form_section)
96 96
     {
97 97
 //		d( $form_section );
98
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
98
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
99 99
     }
100 100
 
101 101
 
Please login to merge, or discard this patch.
core/libraries/form_sections/strategies/filter/FormHtmlFilter.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@
 block discarded – undo
18 18
 abstract class FormHtmlFilter
19 19
 {
20 20
 
21
-    /**
22
-     * @param                        $html
23
-     * @param EE_Form_Section_Validatable $form_section
24
-     * @return string
25
-     */
26
-    abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
21
+	/**
22
+	 * @param                        $html
23
+	 * @param EE_Form_Section_Validatable $form_section
24
+	 * @return string
25
+	 */
26
+	abstract public function filterHtml($html, EE_Form_Section_Validatable $form_section);
27 27
 
28 28
 }
29 29
 // End of file FormHtmlFilter.php
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Integer_Input.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -15,37 +15,37 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @param array $input_settings
20
-     */
21
-    public function __construct($input_settings = array())
22
-    {
23
-        $this->_set_display_strategy(
24
-            new EE_Number_Input_Display_Strategy(
25
-                isset($input_settings['min_value'])
26
-                    ? $input_settings['min_value']
27
-                    : null,
28
-                isset($input_settings['max_value'])
29
-                    ? $input_settings['max_value']
30
-                    : null
31
-            )
32
-        );
33
-        $this->_set_normalization_strategy(
34
-            new EE_Int_Normalization(
35
-                isset($input_settings['validation_error_message'])
36
-                    ? $input_settings['validation_error_message']
37
-                    : null
38
-            )
39
-        );
40
-        $this->_add_validation_strategy(
41
-            new EE_Int_Validation_Strategy(
42
-                isset($input_settings['validation_error_message'])
43
-                    ? $input_settings['validation_error_message']
44
-                    : null
45
-            )
46
-        );
47
-        parent::__construct($input_settings);
48
-    }
18
+	/**
19
+	 * @param array $input_settings
20
+	 */
21
+	public function __construct($input_settings = array())
22
+	{
23
+		$this->_set_display_strategy(
24
+			new EE_Number_Input_Display_Strategy(
25
+				isset($input_settings['min_value'])
26
+					? $input_settings['min_value']
27
+					: null,
28
+				isset($input_settings['max_value'])
29
+					? $input_settings['max_value']
30
+					: null
31
+			)
32
+		);
33
+		$this->_set_normalization_strategy(
34
+			new EE_Int_Normalization(
35
+				isset($input_settings['validation_error_message'])
36
+					? $input_settings['validation_error_message']
37
+					: null
38
+			)
39
+		);
40
+		$this->_add_validation_strategy(
41
+			new EE_Int_Validation_Strategy(
42
+				isset($input_settings['validation_error_message'])
43
+					? $input_settings['validation_error_message']
44
+					: null
45
+			)
46
+		);
47
+		parent::__construct($input_settings);
48
+	}
49 49
 
50 50
 }
51 51
 // End of file EE_Integer_Input.php
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Float_Input.input.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,6 +16,6 @@
 block discarded – undo
16 16
 		$this->_set_normalization_strategy(new EE_Float_Normalization( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) );
17 17
 		$this->_add_validation_strategy( new EE_Float_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) );
18 18
 		parent::__construct($input_settings);
19
-        $this->_other_html_attributes .= ' step="any"';
19
+		$this->_other_html_attributes .= ' step="any"';
20 20
 	}
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
  * @subpackage
7 7
  * @author				Mike Nelson
8 8
  */
9
-class EE_Float_Input extends EE_Form_Input_Base{
9
+class EE_Float_Input extends EE_Form_Input_Base {
10 10
 
11 11
 	/**
12 12
 	 * @param array $input_settings
13 13
 	 */
14
-	function __construct($input_settings = array()){
14
+	function __construct($input_settings = array()) {
15 15
 		$this->_set_display_strategy(new EE_Number_Input_Display_Strategy());
16
-		$this->_set_normalization_strategy(new EE_Float_Normalization( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) );
17
-		$this->_add_validation_strategy( new EE_Float_Validation_Strategy( isset( $input_settings[ 'validation_error_message' ] ) ? $input_settings[ 'validation_error_message' ] : NULL ) );
16
+		$this->_set_normalization_strategy(new EE_Float_Normalization(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL));
17
+		$this->_add_validation_strategy(new EE_Float_Validation_Strategy(isset($input_settings['validation_error_message']) ? $input_settings['validation_error_message'] : NULL));
18 18
 		parent::__construct($input_settings);
19 19
         $this->_other_html_attributes .= ' step="any"';
20 20
 	}
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Display_Strategy_Base.strategy.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     protected function _append_chars($string = '', $chars = '-')
63 63
     {
64
-        return $this->_remove_chars($string, $chars) . $chars;
64
+        return $this->_remove_chars($string, $chars).$chars;
65 65
     }
66 66
 
67 67
 
Please login to merge, or discard this patch.
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -16,229 +16,229 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * @var string $_tag
21
-     */
22
-    protected $_tag = '';
19
+	/**
20
+	 * @var string $_tag
21
+	 */
22
+	protected $_tag = '';
23 23
 
24 24
 
25 25
 
26 26
 
27 27
 
28
-    /**
29
-     * returns HTML and javascript related to the displaying of this input
30
-     *
31
-     * @return string
32
-     */
33
-    abstract public function display();
28
+	/**
29
+	 * returns HTML and javascript related to the displaying of this input
30
+	 *
31
+	 * @return string
32
+	 */
33
+	abstract public function display();
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
39
-     * is already there
40
-     *
41
-     * @param string $string - the string being processed
42
-     * @param string $chars  - exact string of characters to remove
43
-     * @return string
44
-     */
45
-    protected function _remove_chars($string = '', $chars = '-')
46
-    {
47
-        $char_length = strlen($chars) * -1;
48
-        // if last three characters of string is  " - ", then remove it
49
-        return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string;
50
-    }
37
+	/**
38
+	 * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars
39
+	 * is already there
40
+	 *
41
+	 * @param string $string - the string being processed
42
+	 * @param string $chars  - exact string of characters to remove
43
+	 * @return string
44
+	 */
45
+	protected function _remove_chars($string = '', $chars = '-')
46
+	{
47
+		$char_length = strlen($chars) * -1;
48
+		// if last three characters of string is  " - ", then remove it
49
+		return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string;
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
56
-     * already there
57
-     *
58
-     * @param string $string - the string being processed
59
-     * @param string $chars  - exact string of characters to be added to end of string
60
-     * @return string
61
-     */
62
-    protected function _append_chars($string = '', $chars = '-')
63
-    {
64
-        return $this->_remove_chars($string, $chars) . $chars;
65
-    }
54
+	/**
55
+	 * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not
56
+	 * already there
57
+	 *
58
+	 * @param string $string - the string being processed
59
+	 * @param string $chars  - exact string of characters to be added to end of string
60
+	 * @return string
61
+	 */
62
+	protected function _append_chars($string = '', $chars = '-')
63
+	{
64
+		return $this->_remove_chars($string, $chars) . $chars;
65
+	}
66 66
 
67 67
 
68
-
69
-    /**
70
-     * Gets the HTML IDs of all the inputs
71
-     *
72
-     * @param bool $add_pound_sign
73
-     * @return array
74
-     */
75
-    public function get_html_input_ids($add_pound_sign = false)
76
-    {
77
-        return array($this->get_input()->html_id($add_pound_sign));
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * Adds js variables for localization to the $other_js_data. These should be put
84
-     * in each form's "other_data" javascript object.
85
-     *
86
-     * @param array $other_js_data
87
-     * @return array
88
-     */
89
-    public function get_other_js_data($other_js_data = array())
90
-    {
91
-        return $other_js_data;
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
98
-     * This should be called during wp_enqueue_scripts
99
-     */
100
-    public function enqueue_js()
101
-    {
102
-    }
103
-
104
-
105
-
106
-    /**
107
-     * returns string like: '<tag'
108
-     *
109
-     * @param string $tag
110
-     * @return string
111
-     */
112
-    protected function _opening_tag($tag)
113
-    {
114
-        $this->_tag = $tag;
115
-        return "<{$this->_tag}";
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * returns string like: '</tag>
122
-     *
123
-     * @return string
124
-     */
125
-    protected function _closing_tag()
126
-    {
127
-        return "</{$this->_tag}>";
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * returns string like: '/>'
134
-     *
135
-     * @return string
136
-     */
137
-    protected function _close_tag()
138
-    {
139
-        return '/>';
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * returns an array of standard HTML attributes that get added to nearly all inputs,
146
-     * where string keys represent named attributes like id, class, etc
147
-     * and numeric keys represent single attributes like 'required'.
148
-     * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
149
-     * it.
150
-     *
151
-     * @return array
152
-     */
153
-    protected function _standard_attributes_array()
154
-    {
155
-        return array(
156
-            'name'  => $this->_input->html_name(),
157
-            'id'    => $this->_input->html_id(),
158
-            'class' => $this->_input->html_class(true),
159
-            0       => array('required', $this->_input->required()),
160
-            1       => $this->_input->other_html_attributes(),
161
-            'style' => $this->_input->html_style(),
162
-        );
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * sets the attributes using the incoming array
169
-     * and returns a string of all attributes rendered as valid HTML
170
-     *
171
-     * @param array $attributes
172
-     * @return string
173
-     */
174
-    protected function _attributes_string($attributes = array())
175
-    {
176
-        $attributes = apply_filters(
177
-            'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
178
-            $attributes,
179
-            $this,
180
-            $this->_input
181
-        );
182
-        $attributes_string = '';
183
-        foreach ($attributes as $attribute => $value) {
184
-            if (is_numeric($attribute)) {
185
-                $add = true;
186
-                if (is_array($value)) {
187
-                    $attribute = isset($value[0]) ? $value[0] : '';
188
-                    $add = isset($value[1]) ? $value[1] : false;
189
-                } else {
190
-                    $attribute = $value;
191
-                }
192
-                $attributes_string .= $this->_single_attribute($attribute, $add);
193
-            } else {
194
-                $attributes_string .= $this->_attribute($attribute, $value);
195
-            }
196
-        }
197
-        return $attributes_string;
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * returns string like: ' attribute="value"'
204
-     * returns an empty string if $value is null
205
-     *
206
-     * @param string $attribute
207
-     * @param string $value
208
-     * @return string
209
-     */
210
-    protected function _attribute($attribute, $value = '')
211
-    {
212
-        return $value !== null ? " {$attribute}=\"{$value}\"" : '';
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns string like: ' data-attribute="value"'
219
-     * returns an empty string if $value is null
220
-     *
221
-     * @param string $attribute
222
-     * @param string $value
223
-     * @return string
224
-     */
225
-    protected function _data_attribute($attribute, $value = '')
226
-    {
227
-        return $value !== null ? " data-{$attribute}=\"{$value}\"" : '';
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * returns string like: ' attribute' if $add is true
234
-     *
235
-     * @param string  $attribute
236
-     * @param boolean $add
237
-     * @return string
238
-     */
239
-    protected function _single_attribute($attribute, $add = true)
240
-    {
241
-        return $add ? " {$attribute}" : '';
242
-    }
68
+
69
+	/**
70
+	 * Gets the HTML IDs of all the inputs
71
+	 *
72
+	 * @param bool $add_pound_sign
73
+	 * @return array
74
+	 */
75
+	public function get_html_input_ids($add_pound_sign = false)
76
+	{
77
+		return array($this->get_input()->html_id($add_pound_sign));
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * Adds js variables for localization to the $other_js_data. These should be put
84
+	 * in each form's "other_data" javascript object.
85
+	 *
86
+	 * @param array $other_js_data
87
+	 * @return array
88
+	 */
89
+	public function get_other_js_data($other_js_data = array())
90
+	{
91
+		return $other_js_data;
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style.
98
+	 * This should be called during wp_enqueue_scripts
99
+	 */
100
+	public function enqueue_js()
101
+	{
102
+	}
103
+
104
+
105
+
106
+	/**
107
+	 * returns string like: '<tag'
108
+	 *
109
+	 * @param string $tag
110
+	 * @return string
111
+	 */
112
+	protected function _opening_tag($tag)
113
+	{
114
+		$this->_tag = $tag;
115
+		return "<{$this->_tag}";
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * returns string like: '</tag>
122
+	 *
123
+	 * @return string
124
+	 */
125
+	protected function _closing_tag()
126
+	{
127
+		return "</{$this->_tag}>";
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * returns string like: '/>'
134
+	 *
135
+	 * @return string
136
+	 */
137
+	protected function _close_tag()
138
+	{
139
+		return '/>';
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * returns an array of standard HTML attributes that get added to nearly all inputs,
146
+	 * where string keys represent named attributes like id, class, etc
147
+	 * and numeric keys represent single attributes like 'required'.
148
+	 * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use
149
+	 * it.
150
+	 *
151
+	 * @return array
152
+	 */
153
+	protected function _standard_attributes_array()
154
+	{
155
+		return array(
156
+			'name'  => $this->_input->html_name(),
157
+			'id'    => $this->_input->html_id(),
158
+			'class' => $this->_input->html_class(true),
159
+			0       => array('required', $this->_input->required()),
160
+			1       => $this->_input->other_html_attributes(),
161
+			'style' => $this->_input->html_style(),
162
+		);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * sets the attributes using the incoming array
169
+	 * and returns a string of all attributes rendered as valid HTML
170
+	 *
171
+	 * @param array $attributes
172
+	 * @return string
173
+	 */
174
+	protected function _attributes_string($attributes = array())
175
+	{
176
+		$attributes = apply_filters(
177
+			'FHEE__EE_Display_Strategy_Base__attributes_string__attributes',
178
+			$attributes,
179
+			$this,
180
+			$this->_input
181
+		);
182
+		$attributes_string = '';
183
+		foreach ($attributes as $attribute => $value) {
184
+			if (is_numeric($attribute)) {
185
+				$add = true;
186
+				if (is_array($value)) {
187
+					$attribute = isset($value[0]) ? $value[0] : '';
188
+					$add = isset($value[1]) ? $value[1] : false;
189
+				} else {
190
+					$attribute = $value;
191
+				}
192
+				$attributes_string .= $this->_single_attribute($attribute, $add);
193
+			} else {
194
+				$attributes_string .= $this->_attribute($attribute, $value);
195
+			}
196
+		}
197
+		return $attributes_string;
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * returns string like: ' attribute="value"'
204
+	 * returns an empty string if $value is null
205
+	 *
206
+	 * @param string $attribute
207
+	 * @param string $value
208
+	 * @return string
209
+	 */
210
+	protected function _attribute($attribute, $value = '')
211
+	{
212
+		return $value !== null ? " {$attribute}=\"{$value}\"" : '';
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns string like: ' data-attribute="value"'
219
+	 * returns an empty string if $value is null
220
+	 *
221
+	 * @param string $attribute
222
+	 * @param string $value
223
+	 * @return string
224
+	 */
225
+	protected function _data_attribute($attribute, $value = '')
226
+	{
227
+		return $value !== null ? " data-{$attribute}=\"{$value}\"" : '';
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * returns string like: ' attribute' if $add is true
234
+	 *
235
+	 * @param string  $attribute
236
+	 * @param boolean $add
237
+	 * @return string
238
+	 */
239
+	protected function _single_attribute($attribute, $add = true)
240
+	{
241
+		return $add ? " {$attribute}" : '';
242
+	}
243 243
 
244 244
 }
245 245
\ No newline at end of file
Please login to merge, or discard this patch.
libraries/form_sections/strategies/EE_Form_Input_Strategy_Base.strategy.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,40 +9,40 @@
 block discarded – undo
9 9
 abstract class EE_Form_Input_Strategy_Base
10 10
 {
11 11
 
12
-    /**
13
-     * Form Input to display
14
-     *
15
-     * @var EE_Form_Input_Base
16
-     */
17
-    protected $_input;
12
+	/**
13
+	 * Form Input to display
14
+	 *
15
+	 * @var EE_Form_Input_Base
16
+	 */
17
+	protected $_input;
18 18
 
19 19
 
20 20
 
21
-    public function __construct()
22
-    {
23
-    }
21
+	public function __construct()
22
+	{
23
+	}
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * The form input on which this strategy is to perform
29
-     *
30
-     * @param EE_Form_Input_Base $form_input
31
-     */
32
-    public function _construct_finalize(EE_Form_Input_Base $form_input)
33
-    {
34
-        $this->_input = $form_input;
35
-    }
27
+	/**
28
+	 * The form input on which this strategy is to perform
29
+	 *
30
+	 * @param EE_Form_Input_Base $form_input
31
+	 */
32
+	public function _construct_finalize(EE_Form_Input_Base $form_input)
33
+	{
34
+		$this->_input = $form_input;
35
+	}
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * Gets this strategy's input
41
-     *
42
-     * @return EE_Form_Input_Base
43
-     */
44
-    public function get_input()
45
-    {
46
-        return $this->_input;
47
-    }
39
+	/**
40
+	 * Gets this strategy's input
41
+	 *
42
+	 * @return EE_Form_Input_Base
43
+	 */
44
+	public function get_input()
45
+	{
46
+		return $this->_input;
47
+	}
48 48
 }
49 49
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_classes/EE_Question.class.php 1 patch
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 *                             		    date_format and the second value is the time format
38 38
 	 * @return EE_Question
39 39
 	 */
40
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
41
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
42
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
40
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
41
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
42
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
43 43
 	}
44 44
 
45 45
 
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 *                          		the website will be used.
51 51
 	 * @return EE_Question
52 52
 	 */
53
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
54
-		return new self( $props_n_values, TRUE, $timezone );
53
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
54
+		return new self($props_n_values, TRUE, $timezone);
55 55
 	}
56 56
 
57 57
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 * @access        public
63 63
 	 * @param string $QST_display_text
64 64
 	 */
65
-	public function set_display_text( $QST_display_text = '' ) {
66
-		$this->set( 'QST_display_text', $QST_display_text );
65
+	public function set_display_text($QST_display_text = '') {
66
+		$this->set('QST_display_text', $QST_display_text);
67 67
 	}
68 68
 
69 69
 
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
 	 * @access        public
75 75
 	 * @param        string $QST_admin_label
76 76
 	 */
77
-	public function set_admin_label( $QST_admin_label = '' ) {
78
-		$this->set( 'QST_admin_label', $QST_admin_label );
77
+	public function set_admin_label($QST_admin_label = '') {
78
+		$this->set('QST_admin_label', $QST_admin_label);
79 79
 	}
80 80
 
81 81
 
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
 	 * @access        public
87 87
 	 * @param        mixed $QST_system
88 88
 	 */
89
-	public function set_system_ID( $QST_system = '' ) {
90
-		$this->set( 'QST_system', $QST_system );
89
+	public function set_system_ID($QST_system = '') {
90
+		$this->set('QST_system', $QST_system);
91 91
 	}
92 92
 
93 93
 
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
 	 * @access        public
99 99
 	 * @param        string $QST_type
100 100
 	 */
101
-	public function set_question_type( $QST_type = '' ) {
102
-		$this->set( 'QST_type', $QST_type );
101
+	public function set_question_type($QST_type = '') {
102
+		$this->set('QST_type', $QST_type);
103 103
 	}
104 104
 
105 105
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @access        public
111 111
 	 * @param        bool $QST_required
112 112
 	 */
113
-	public function set_required( $QST_required = FALSE ) {
114
-		$this->set( 'QST_required', $QST_required );
113
+	public function set_required($QST_required = FALSE) {
114
+		$this->set('QST_required', $QST_required);
115 115
 	}
116 116
 
117 117
 
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
 	 * @access        public
123 123
 	 * @param        string $QST_required_text
124 124
 	 */
125
-	public function set_required_text( $QST_required_text = '' ) {
126
-		$this->set( 'QST_required_text', $QST_required_text );
125
+	public function set_required_text($QST_required_text = '') {
126
+		$this->set('QST_required_text', $QST_required_text);
127 127
 	}
128 128
 
129 129
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 	 * @access        public
135 135
 	 * @param        int $QST_order
136 136
 	 */
137
-	public function set_order( $QST_order = 0 ) {
138
-		$this->set( 'QST_order', $QST_order );
137
+	public function set_order($QST_order = 0) {
138
+		$this->set('QST_order', $QST_order);
139 139
 	}
140 140
 
141 141
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 	 * @access        public
147 147
 	 * @param        bool $QST_admin_only
148 148
 	 */
149
-	public function set_admin_only( $QST_admin_only = FALSE ) {
150
-		$this->set( 'QST_admin_only', $QST_admin_only );
149
+	public function set_admin_only($QST_admin_only = FALSE) {
150
+		$this->set('QST_admin_only', $QST_admin_only);
151 151
 	}
152 152
 
153 153
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @access        public
159 159
 	 * @param        int $QST_wp_user
160 160
 	 */
161
-	public function set_wp_user( $QST_wp_user = 1 ) {
162
-		$this->set( 'QST_wp_user', $QST_wp_user );
161
+	public function set_wp_user($QST_wp_user = 1) {
162
+		$this->set('QST_wp_user', $QST_wp_user);
163 163
 	}
164 164
 
165 165
 
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
 	 * @access        public
176 176
 	 * @param 	bool $QST_deleted
177 177
 	 */
178
-	public function set_deleted( $QST_deleted = FALSE ) {
179
-		$this->set( 'QST_deleted', $QST_deleted );
178
+	public function set_deleted($QST_deleted = FALSE) {
179
+		$this->set('QST_deleted', $QST_deleted);
180 180
 	}
181 181
 
182 182
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 * @return string
188 188
 	 */
189 189
 	public function display_text() {
190
-		return $this->get( 'QST_display_text' );
190
+		return $this->get('QST_display_text');
191 191
 	}
192 192
 
193 193
 
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return string
199 199
 	 */
200 200
 	public function admin_label() {
201
-		return $this->get( 'QST_admin_label' );
201
+		return $this->get('QST_admin_label');
202 202
 	}
203 203
 
204 204
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @return string
210 210
 	 */
211 211
 	public function system_ID() {
212
-		return $this->get( 'QST_system' );
212
+		return $this->get('QST_system');
213 213
 	}
214 214
 
215 215
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * @return boolean
221 221
 	 */
222 222
 	public function required() {
223
-		return $this->get( 'QST_required' );
223
+		return $this->get('QST_required');
224 224
 	}
225 225
 
226 226
 
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 * @return string
233 233
 	 */
234 234
 	public function required_text() {
235
-		return $this->get( 'QST_required_text' );
235
+		return $this->get('QST_required_text');
236 236
 	}
237 237
 
238 238
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * @return string
244 244
 	 */
245 245
 	public function type() {
246
-		return $this->get( 'QST_type' );
246
+		return $this->get('QST_type');
247 247
 	}
248 248
 
249 249
 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @return int
256 256
 	 */
257 257
 	public function order() {
258
-		return $this->get( 'QST_order' );
258
+		return $this->get('QST_order');
259 259
 	}
260 260
 
261 261
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return boolean
268 268
 	 */
269 269
 	public function admin_only() {
270
-		return $this->get( 'QST_admin_only' );
270
+		return $this->get('QST_admin_only');
271 271
 	}
272 272
 
273 273
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @return int
279 279
 	 */
280 280
 	public function wp_user() {
281
-		return $this->get( 'QST_wp_user' );
281
+		return $this->get('QST_wp_user');
282 282
 	}
283 283
 
284 284
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 	 * @return boolean
290 290
 	 */
291 291
 	public function deleted() {
292
-		return $this->get( 'QST_deleted' );
292
+		return $this->get('QST_deleted');
293 293
 	}
294 294
 
295 295
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @return EE_Answer[]
300 300
 	 */
301 301
 	public function answers() {
302
-		return $this->get_many_related( 'Answer' );
302
+		return $this->get_many_related('Answer');
303 303
 	}
304 304
 
305 305
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 	 * @return boolean true = has answers, false = no answers.
310 310
 	 */
311 311
 	public function has_answers() {
312
-		return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE;
312
+		return $this->count_related('Answer') > 0 ? TRUE : FALSE;
313 313
 	}
314 314
 
315 315
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @return EE_Question_Group[]
320 320
 	 */
321 321
 	public function question_groups() {
322
-		return $this->get_many_related( 'Question_Group' );
322
+		return $this->get_many_related('Question_Group');
323 323
 	}
324 324
 
325 325
 
@@ -333,24 +333,24 @@  discard block
 block discarded – undo
333 333
 	 *                                                       whether it was trashed or not.
334 334
 	 * @return EE_Question_Option[]
335 335
 	 */
336
-	public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) {
337
-		if ( ! $this->ID() ) {
336
+	public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) {
337
+		if ( ! $this->ID()) {
338 338
 			return array();
339 339
 		}
340 340
 		$query_params = array();
341
-		if ( $selected_value_to_always_include ) {
342
-			if ( is_array( $selected_value_to_always_include ) ) {
343
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include );
341
+		if ($selected_value_to_always_include) {
342
+			if (is_array($selected_value_to_always_include)) {
343
+				$query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include);
344 344
 			} else {
345
-				$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include;
345
+				$query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include;
346 346
 			}
347 347
 		}
348
-		if ( $notDeletedOptionsOnly ) {
349
-			$query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE;
348
+		if ($notDeletedOptionsOnly) {
349
+			$query_params[0]['OR*options-query']['QSO_deleted'] = FALSE;
350 350
 		}
351 351
 		//order by QSO_order
352
-		$query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' );
353
-		return $this->get_many_related( 'Question_Option', $query_params );
352
+		$query_params['order_by'] = array('QSO_order' => 'ASC');
353
+		return $this->get_many_related('Question_Option', $query_params);
354 354
 	}
355 355
 
356 356
 
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 	 * @return \EE_Question_Option[]
361 361
 	 */
362 362
 	public function temp_options() {
363
-		return $this->_model_relations[ 'Question_Option' ];
363
+		return $this->_model_relations['Question_Option'];
364 364
 	}
365 365
 
366 366
 
@@ -371,8 +371,8 @@  discard block
 block discarded – undo
371 371
 	 * @param EE_Question_Option $option
372 372
 	 * @return boolean success
373 373
 	 */
374
-	public function add_option( EE_Question_Option $option ) {
375
-		return $this->_add_relation_to( $option, 'Question_Option' );
374
+	public function add_option(EE_Question_Option $option) {
375
+		return $this->_add_relation_to($option, 'Question_Option');
376 376
 	}
377 377
 
378 378
 
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 	 * @param EE_Question_Option $option
383 383
 	 * @return boolean success
384 384
 	 */
385
-	public function add_temp_option( EE_Question_Option $option ) {
386
-		$this->_model_relations[ 'Question_Option' ][ ] = $option;
385
+	public function add_temp_option(EE_Question_Option $option) {
386
+		$this->_model_relations['Question_Option'][] = $option;
387 387
 		return TRUE;
388 388
 	}
389 389
 
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @param EE_Question_Option $option
395 395
 	 * @return boolean success
396 396
 	 */
397
-	public function remove_option( EE_Question_Option $option ) {
398
-		return $this->_remove_relation_to( $option, 'Question_Option' );
397
+	public function remove_option(EE_Question_Option $option) {
398
+		return $this->_remove_relation_to($option, 'Question_Option');
399 399
 	}
400 400
 
401 401
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 	 * @return bool
405 405
 	 */
406 406
 	public function is_system_question() {
407
-		$system_ID = $this->get( 'QST_system' );
408
-		return ! empty( $system_ID ) ? TRUE : FALSE;
407
+		$system_ID = $this->get('QST_system');
408
+		return ! empty($system_ID) ? TRUE : FALSE;
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 */
419 419
 	public function set_order_to_latest() {
420 420
 		$latest_order = $this->get_model()->get_latest_question_order();
421
-		$latest_order ++;
422
-		$this->set( 'QST_order', $latest_order );
421
+		$latest_order++;
422
+		$this->set('QST_order', $latest_order);
423 423
 	}
424 424
 
425 425
 
@@ -438,20 +438,20 @@  discard block
 block discarded – undo
438 438
 	 * Duplicates this question and its question options
439 439
 	 * @return \EE_Question
440 440
 	 */
441
-	public function duplicate( $options = array() ) {
441
+	public function duplicate($options = array()) {
442 442
 		$new_question = clone $this;
443
-		$new_question->set( 'QST_ID', null );
444
-		$new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) );
445
-		$new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) );
446
-		$new_question->set_system_ID( null );
447
-		$new_question->set_wp_user( get_current_user_id() );
443
+		$new_question->set('QST_ID', null);
444
+		$new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text()));
445
+		$new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label()));
446
+		$new_question->set_system_ID(null);
447
+		$new_question->set_wp_user(get_current_user_id());
448 448
                 //if we're duplicating a trashed question, assume we don't want the new one to be trashed
449
-                $new_question->set_deleted( false );
449
+                $new_question->set_deleted(false);
450 450
 		$success = $new_question->save();
451
-		if( $success ) {
451
+		if ($success) {
452 452
 			//we don't totally want to duplicate the question options, because we want them to be for the NEW question
453
-			foreach( $this->options() as $question_option ) {
454
-				$question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) );
453
+			foreach ($this->options() as $question_option) {
454
+				$question_option->duplicate(array('QST_ID' => $new_question->ID()));
455 455
 			}
456 456
 			return $new_question;
457 457
 		} else {
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @return int|float
465 465
 	 */
466 466
 	public function max() {
467
-		return $this->get( 'QST_max' );
467
+		return $this->get('QST_max');
468 468
 	}
469 469
 
470 470
 	/**
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
 	 * @param int|float $new_max
473 473
 	 * @return void
474 474
 	 */
475
-	public function set_max( $new_max ) {
476
-		$this->set( 'QST_max', $new_max );
475
+	public function set_max($new_max) {
476
+		$this->set('QST_max', $new_max);
477 477
 	}
478 478
 
479 479
 
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 	 * @param array $input_constructor_args
486 486
 	 * @return EE_Form_Input_Base
487 487
 	 */
488
-	public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) {
488
+	public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) {
489 489
 		$identifier = $this->is_system_question() ? $this->system_ID() : $this->ID();
490 490
 
491 491
 		$input_constructor_args = array_merge(
@@ -496,29 +496,29 @@  discard block
 block discarded – undo
496 496
 				),
497 497
 				$input_constructor_args
498 498
 			);
499
-		if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) {
500
-			$answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() );
499
+		if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) {
500
+			$answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID());
501 501
 		}
502 502
 		// has this question been answered ?
503
-		if ( $answer instanceof EE_Answer
503
+		if ($answer instanceof EE_Answer
504 504
              && $answer->value() !== ''
505 505
         ) {
506 506
 			//answer gets htmlspecialchars called on it, undo that please
507 507
 			//because the form input's display strategy may call esc_attr too
508 508
 			//which also does html special characters
509 509
 			$values_with_html_special_chars = $answer->value();
510
-			if( is_array( $values_with_html_special_chars ) ) {
511
-				$default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars );
510
+			if (is_array($values_with_html_special_chars)) {
511
+				$default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars);
512 512
 			} else {
513
-				$default_value = htmlspecialchars_decode( $values_with_html_special_chars );
513
+				$default_value = htmlspecialchars_decode($values_with_html_special_chars);
514 514
 			}
515 515
 			$input_constructor_args['default'] = $default_value;
516 516
 		}
517
-		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() );
518
-		if( EEM_Question::instance()->question_type_is_in_category(  $this->type(), 'text' ) ) {
519
-			$input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy(
517
+		$max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID());
518
+		if (EEM_Question::instance()->question_type_is_in_category($this->type(), 'text')) {
519
+			$input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy(
520 520
 				null,
521
-				min( $max_max_for_question, $this->max() )
521
+				min($max_max_for_question, $this->max())
522 522
 			);
523 523
 		}
524 524
 		$input_constructor_args = apply_filters(
@@ -530,22 +530,22 @@  discard block
 block discarded – undo
530 530
 		);
531 531
 
532 532
 		$result = null;
533
-		switch ( $this->type() ) {
533
+		switch ($this->type()) {
534 534
 			// Text
535 535
 			case EEM_Question::QST_type_text :
536
-				$result = new EE_Text_Input( $input_constructor_args );
536
+				$result = new EE_Text_Input($input_constructor_args);
537 537
 				break;
538 538
 			// Textarea
539 539
 			case EEM_Question::QST_type_textarea :
540
-				$result = new EE_Text_Area_Input( $input_constructor_args );
540
+				$result = new EE_Text_Area_Input($input_constructor_args);
541 541
 				break;
542 542
 			// Radio Buttons
543 543
 			case EEM_Question::QST_type_radio :
544
-				$result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args );
544
+				$result = new EE_Radio_Button_Input($this->options(), $input_constructor_args);
545 545
 				break;
546 546
 			// Dropdown
547 547
 			case EEM_Question::QST_type_dropdown :
548
-				$result = new EE_Select_Input( $this->options(), $input_constructor_args );
548
+				$result = new EE_Select_Input($this->options(), $input_constructor_args);
549 549
 				break;
550 550
 			// State Dropdown
551 551
 			case EEM_Question::QST_type_state :
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
 					$registration,
557 557
 					$answer
558 558
 				);				
559
-				$result = new EE_State_Select_Input( $state_options, $input_constructor_args );
559
+				$result = new EE_State_Select_Input($state_options, $input_constructor_args);
560 560
 				break;
561 561
 			// Country Dropdown
562 562
 			case EEM_Question::QST_type_country :
@@ -567,47 +567,47 @@  discard block
 block discarded – undo
567 567
 					$registration,
568 568
 					$answer
569 569
 				);
570
-				$result = new EE_Country_Select_Input( $country_options, $input_constructor_args );
570
+				$result = new EE_Country_Select_Input($country_options, $input_constructor_args);
571 571
 				break;
572 572
 			// Checkboxes
573 573
 			case EEM_Question::QST_type_checkbox :
574
-				$result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args );
574
+				$result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args);
575 575
 				break;
576 576
 			// Date
577 577
 			case EEM_Question::QST_type_date :
578
-				$result = new EE_Datepicker_Input( $input_constructor_args );
578
+				$result = new EE_Datepicker_Input($input_constructor_args);
579 579
 				break;
580 580
 			case EEM_Question::QST_type_html_textarea :
581
-				$input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy();
582
-				$result =  new EE_Text_Area_Input( $input_constructor_args );
583
-				$result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' );
581
+				$input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy();
582
+				$result = new EE_Text_Area_Input($input_constructor_args);
583
+				$result->remove_validation_strategy('EE_Plaintext_Validation_Strategy');
584 584
 				break;
585 585
 			case EEM_Question::QST_type_email :
586
-				$result = new EE_Email_Input( $input_constructor_args );
586
+				$result = new EE_Email_Input($input_constructor_args);
587 587
 				break;
588 588
 			case EEM_Question::QST_type_us_phone :
589
-				$result = new EE_Phone_Input( $input_constructor_args );
589
+				$result = new EE_Phone_Input($input_constructor_args);
590 590
 				break;
591 591
 			case EEM_Question::QST_type_int :
592
-				$result = new EE_Integer_Input( $input_constructor_args );
592
+				$result = new EE_Integer_Input($input_constructor_args);
593 593
 				break;
594 594
 			case EEM_Question::QST_type_decimal :
595
-				$result = new EE_Float_Input( $input_constructor_args );
595
+				$result = new EE_Float_Input($input_constructor_args);
596 596
 				break;
597 597
 			case EEM_Question::QST_type_url :
598
-				$input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy();
599
-				$result = new EE_Text_Input( $input_constructor_args );
598
+				$input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy();
599
+				$result = new EE_Text_Input($input_constructor_args);
600 600
 				break;
601 601
 			case EEM_Question::QST_type_year :
602 602
 				$result = new EE_Year_Input(
603 603
 						$input_constructor_args,
604
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ),
605
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ),
606
-						apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this )
604
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this),
605
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this),
606
+						apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this)
607 607
 						);
608 608
 				break;
609 609
 			case EEM_Question::QST_type_multi_select :
610
-				$result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args );
610
+				$result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args);
611 611
 				break;
612 612
 			// fallback
613 613
 			default :
@@ -618,12 +618,12 @@  discard block
 block discarded – undo
618 618
 					$this,
619 619
 					$input_constructor_args
620 620
 				);
621
-				if( ! $default_input ){
622
-					$default_input = new EE_Text_Input( $input_constructor_args );
621
+				if ( ! $default_input) {
622
+					$default_input = new EE_Text_Input($input_constructor_args);
623 623
 				}
624 624
 				$result = $default_input;
625 625
 		}
626
-		return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer );
626
+		return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer);
627 627
 	}
628 628
 
629 629
 
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Repository.lib.php 2 patches
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,256 +16,256 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     *    EE_Message_Repository constructor
21
-     */
22
-    public function __construct()
23
-    {
24
-        $this->interface = 'EE_Message';
25
-        parent::__construct();
26
-    }
27
-
28
-
29
-    /**
30
-     * Add the EE_Message to the repository.
31
-     * This also ensures that the MSG_token is saves as a part of the info for retrieval.
32
-     *
33
-     * @param EE_Message $message
34
-     * @param mixed      $info Any included data is saved in the attached object info array indexed by 'data'
35
-     * @return bool
36
-     */
37
-    public function add($message, $info = null)
38
-    {
39
-        $attached = parent::add($message);
40
-        //ensure $info is an array if not already
41
-        $info = $info === null ? $info = array() : (array)$info;
42
-        $data = $this->_init_data($info, $attached, $message);
43
-        if ($attached) {
44
-            $this->set_info($message, $data);
45
-        }
46
-        return $attached;
47
-    }
48
-
49
-
50
-    /**
51
-     * Initializes the data from the incoming info.
52
-     *
53
-     * @param array      $info     incoming data.
54
-     * @param bool       $attached Indicates whether the object was attached successfully.
55
-     * @param EE_Message $message
56
-     * @return array
57
-     */
58
-    protected function _init_data($info, $attached, $message)
59
-    {
60
-        $data = array(
61
-            'test_send'               => false,
62
-            'preview'                 => false,
63
-            'data_handler_class_name' => '',
64
-            'data'                    => array(
65
-                'MSG_generation_data' => array(),
66
-            ),
67
-        );
68
-        if (isset($info['preview'])) {
69
-            $data['preview'] = $info['preview'];
70
-            unset($info['preview']);
71
-        }
72
-        if (isset($info['test_send'])) {
73
-            $data['test_send'] = $info['test_send'];
74
-            unset($info['test_send']);
75
-        }
76
-        if (isset($info['data_handler_class_name'])) {
77
-            $data['data_handler_class_name'] = $info['data_handler_class_name'];
78
-            unset($info['data_handler_class_name']);
79
-        }
80
-        if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) {
81
-            $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array();
82
-            //if data isn't in $info...let's see if its available via the message object
83
-            $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data;
84
-            //still empty then let's just use info
85
-            $generation_data                     = ! $generation_data ? $info : $generation_data;
86
-            $data['data']['MSG_generation_data'] = $generation_data;
87
-        }
88
-        return $data;
89
-    }
90
-
91
-
92
-    /**
93
-     * Save all EE_Message objects to the db.
94
-     *
95
-     * @param bool $do_hooks_only  When true, only the hooks related to saving are fired.
96
-     * @return array array(
97
-     *                  'updated' => 0, //count of how many messages updated
98
-     *                  'notupdated' => 0, //count of how many messages not updated.
99
-     *                  'errors' => array( $token ), //array of message object tokens that had errors in saving
100
-     *                  )
101
-     */
102
-    public function saveAll($do_hooks_only = false)
103
-    {
104
-        $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array());
105
-
106
-        if (! $do_hooks_only) {
107
-            $this->rewind();
108
-            //exit early if there is nothing to save.
109
-            if ($this->count() < 1) {
110
-                return $save_tracking;
111
-            }
112
-
113
-            while ($this->valid()) {
114
-                $saved = $this->current()->save();
115
-                if ($saved === false) {
116
-                    $save_tracking['errors'][] = $this->current()->MSG_token();
117
-                } elseif ($saved) {
118
-                    $save_tracking['updated']++;
119
-                } else {
120
-                    $save_tracking['notupdated']++;
121
-                }
122
-                //maybe persist generation data if this is an incomplete EE_Message.
123
-                $this->_maybe_persist_attached_data();
124
-
125
-                $this->next();
126
-            }
127
-        }
128
-        do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only);
129
-        return $save_tracking;
130
-    }
131
-
132
-
133
-    /**
134
-     * Retrieves a EE_Message from the repository that matches the given token.
135
-     *
136
-     * @param string $token Token.
137
-     * @return EE_Message | null
138
-     */
139
-    public function getMessageByToken($token)
140
-    {
141
-        $this->rewind();
142
-        while ($this->valid()) {
143
-            if ($this->current()->MSG_token() === $token) {
144
-                $message = $this->current();
145
-                $this->rewind();
146
-                return $message;
147
-            }
148
-            $this->next();
149
-        }
150
-        return null;
151
-    }
152
-
153
-
154
-    /**
155
-     * This retrieves any data required for generation that may be saved with the current EE_Message in storage.
156
-     *
157
-     * @return array();
158
-     */
159
-    public function get_generation_data()
160
-    {
161
-        //first verify we're at a valid iterator point.
162
-        if ( ! $this->valid()) {
163
-            return array();
164
-        }
165
-        $info = $this->getInfo();
166
-        return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
167
-    }
168
-
169
-
170
-    /**
171
-     * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator.
172
-     *
173
-     * @return string
174
-     */
175
-    public function get_data_handler()
176
-    {
177
-        if ( ! $this->valid()) {
178
-            return '';
179
-        }
180
-        $info = $this->getInfo();
181
-        return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
182
-    }
183
-
184
-
185
-    /**
186
-     * Returns whether this EE_Message is for a preview or not.
187
-     *
188
-     * @return bool
189
-     */
190
-    public function is_preview()
191
-    {
192
-        if ( ! $this->valid()) {
193
-            return false;
194
-        }
195
-        $info = $this->getInfo();
196
-        return $info['preview'];
197
-    }
198
-
199
-
200
-    /**
201
-     * Returns whether the current message pointed to is for a test send.
202
-     *
203
-     * @return bool
204
-     */
205
-    public function is_test_send()
206
-    {
207
-        if ( ! $this->valid()) {
208
-            return false;
209
-        }
210
-        $info = $this->getInfo();
211
-        return $info['test_send'];
212
-    }
213
-
214
-
215
-    /**
216
-     *  This checks if the current EE_Message in the iterator is incomplete. If it is, then
217
-     *  data is attached for later retrieval (batch generation).
218
-     */
219
-    protected function _maybe_persist_attached_data()
220
-    {
221
-        if ( ! $this->valid()) {
222
-            return;
223
-        }
224
-
225
-        $info                    = $this->getInfo();
226
-        $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
227
-        $data                    = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
228
-        if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) {
229
-            $this->current()->set_generation_data($data);
230
-            $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name);
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * This method returns a count of messages in the repository that have a given priority.
237
-     *
238
-     * @param int   $priority the priority that is being filtered for the count.
239
-     * @param array $status   the optional status(es) that will also be filtered by when priority matches.
240
-     * @return int  count of messages in the queue matching the conditions.
241
-     */
242
-    public function count_by_priority_and_status($priority, $status = array())
243
-    {
244
-        if ( ! empty($status)) {
245
-            $status = is_array($status) ? $status : array($status);
246
-        }
247
-
248
-        $count = 0;
249
-        $this->rewind();
250
-        while ($this->valid()) {
251
-            if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(),
252
-                            $status)) || ! $status)
253
-            ) {
254
-                $count++;
255
-            }
256
-            $this->next();
257
-        }
258
-        return $count;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return EE_Message
264
-     */
265
-    public function current()
266
-    {
267
-        return parent::current();
268
-    }
19
+	/**
20
+	 *    EE_Message_Repository constructor
21
+	 */
22
+	public function __construct()
23
+	{
24
+		$this->interface = 'EE_Message';
25
+		parent::__construct();
26
+	}
27
+
28
+
29
+	/**
30
+	 * Add the EE_Message to the repository.
31
+	 * This also ensures that the MSG_token is saves as a part of the info for retrieval.
32
+	 *
33
+	 * @param EE_Message $message
34
+	 * @param mixed      $info Any included data is saved in the attached object info array indexed by 'data'
35
+	 * @return bool
36
+	 */
37
+	public function add($message, $info = null)
38
+	{
39
+		$attached = parent::add($message);
40
+		//ensure $info is an array if not already
41
+		$info = $info === null ? $info = array() : (array)$info;
42
+		$data = $this->_init_data($info, $attached, $message);
43
+		if ($attached) {
44
+			$this->set_info($message, $data);
45
+		}
46
+		return $attached;
47
+	}
48
+
49
+
50
+	/**
51
+	 * Initializes the data from the incoming info.
52
+	 *
53
+	 * @param array      $info     incoming data.
54
+	 * @param bool       $attached Indicates whether the object was attached successfully.
55
+	 * @param EE_Message $message
56
+	 * @return array
57
+	 */
58
+	protected function _init_data($info, $attached, $message)
59
+	{
60
+		$data = array(
61
+			'test_send'               => false,
62
+			'preview'                 => false,
63
+			'data_handler_class_name' => '',
64
+			'data'                    => array(
65
+				'MSG_generation_data' => array(),
66
+			),
67
+		);
68
+		if (isset($info['preview'])) {
69
+			$data['preview'] = $info['preview'];
70
+			unset($info['preview']);
71
+		}
72
+		if (isset($info['test_send'])) {
73
+			$data['test_send'] = $info['test_send'];
74
+			unset($info['test_send']);
75
+		}
76
+		if (isset($info['data_handler_class_name'])) {
77
+			$data['data_handler_class_name'] = $info['data_handler_class_name'];
78
+			unset($info['data_handler_class_name']);
79
+		}
80
+		if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) {
81
+			$generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array();
82
+			//if data isn't in $info...let's see if its available via the message object
83
+			$generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data;
84
+			//still empty then let's just use info
85
+			$generation_data                     = ! $generation_data ? $info : $generation_data;
86
+			$data['data']['MSG_generation_data'] = $generation_data;
87
+		}
88
+		return $data;
89
+	}
90
+
91
+
92
+	/**
93
+	 * Save all EE_Message objects to the db.
94
+	 *
95
+	 * @param bool $do_hooks_only  When true, only the hooks related to saving are fired.
96
+	 * @return array array(
97
+	 *                  'updated' => 0, //count of how many messages updated
98
+	 *                  'notupdated' => 0, //count of how many messages not updated.
99
+	 *                  'errors' => array( $token ), //array of message object tokens that had errors in saving
100
+	 *                  )
101
+	 */
102
+	public function saveAll($do_hooks_only = false)
103
+	{
104
+		$save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array());
105
+
106
+		if (! $do_hooks_only) {
107
+			$this->rewind();
108
+			//exit early if there is nothing to save.
109
+			if ($this->count() < 1) {
110
+				return $save_tracking;
111
+			}
112
+
113
+			while ($this->valid()) {
114
+				$saved = $this->current()->save();
115
+				if ($saved === false) {
116
+					$save_tracking['errors'][] = $this->current()->MSG_token();
117
+				} elseif ($saved) {
118
+					$save_tracking['updated']++;
119
+				} else {
120
+					$save_tracking['notupdated']++;
121
+				}
122
+				//maybe persist generation data if this is an incomplete EE_Message.
123
+				$this->_maybe_persist_attached_data();
124
+
125
+				$this->next();
126
+			}
127
+		}
128
+		do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only);
129
+		return $save_tracking;
130
+	}
131
+
132
+
133
+	/**
134
+	 * Retrieves a EE_Message from the repository that matches the given token.
135
+	 *
136
+	 * @param string $token Token.
137
+	 * @return EE_Message | null
138
+	 */
139
+	public function getMessageByToken($token)
140
+	{
141
+		$this->rewind();
142
+		while ($this->valid()) {
143
+			if ($this->current()->MSG_token() === $token) {
144
+				$message = $this->current();
145
+				$this->rewind();
146
+				return $message;
147
+			}
148
+			$this->next();
149
+		}
150
+		return null;
151
+	}
152
+
153
+
154
+	/**
155
+	 * This retrieves any data required for generation that may be saved with the current EE_Message in storage.
156
+	 *
157
+	 * @return array();
158
+	 */
159
+	public function get_generation_data()
160
+	{
161
+		//first verify we're at a valid iterator point.
162
+		if ( ! $this->valid()) {
163
+			return array();
164
+		}
165
+		$info = $this->getInfo();
166
+		return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
167
+	}
168
+
169
+
170
+	/**
171
+	 * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator.
172
+	 *
173
+	 * @return string
174
+	 */
175
+	public function get_data_handler()
176
+	{
177
+		if ( ! $this->valid()) {
178
+			return '';
179
+		}
180
+		$info = $this->getInfo();
181
+		return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
182
+	}
183
+
184
+
185
+	/**
186
+	 * Returns whether this EE_Message is for a preview or not.
187
+	 *
188
+	 * @return bool
189
+	 */
190
+	public function is_preview()
191
+	{
192
+		if ( ! $this->valid()) {
193
+			return false;
194
+		}
195
+		$info = $this->getInfo();
196
+		return $info['preview'];
197
+	}
198
+
199
+
200
+	/**
201
+	 * Returns whether the current message pointed to is for a test send.
202
+	 *
203
+	 * @return bool
204
+	 */
205
+	public function is_test_send()
206
+	{
207
+		if ( ! $this->valid()) {
208
+			return false;
209
+		}
210
+		$info = $this->getInfo();
211
+		return $info['test_send'];
212
+	}
213
+
214
+
215
+	/**
216
+	 *  This checks if the current EE_Message in the iterator is incomplete. If it is, then
217
+	 *  data is attached for later retrieval (batch generation).
218
+	 */
219
+	protected function _maybe_persist_attached_data()
220
+	{
221
+		if ( ! $this->valid()) {
222
+			return;
223
+		}
224
+
225
+		$info                    = $this->getInfo();
226
+		$data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
227
+		$data                    = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
228
+		if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) {
229
+			$this->current()->set_generation_data($data);
230
+			$this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name);
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * This method returns a count of messages in the repository that have a given priority.
237
+	 *
238
+	 * @param int   $priority the priority that is being filtered for the count.
239
+	 * @param array $status   the optional status(es) that will also be filtered by when priority matches.
240
+	 * @return int  count of messages in the queue matching the conditions.
241
+	 */
242
+	public function count_by_priority_and_status($priority, $status = array())
243
+	{
244
+		if ( ! empty($status)) {
245
+			$status = is_array($status) ? $status : array($status);
246
+		}
247
+
248
+		$count = 0;
249
+		$this->rewind();
250
+		while ($this->valid()) {
251
+			if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(),
252
+							$status)) || ! $status)
253
+			) {
254
+				$count++;
255
+			}
256
+			$this->next();
257
+		}
258
+		return $count;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return EE_Message
264
+	 */
265
+	public function current()
266
+	{
267
+		return parent::current();
268
+	}
269 269
 
270 270
 
271 271
 }
272 272
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $attached = parent::add($message);
40 40
         //ensure $info is an array if not already
41
-        $info = $info === null ? $info = array() : (array)$info;
41
+        $info = $info === null ? $info = array() : (array) $info;
42 42
         $data = $this->_init_data($info, $attached, $message);
43 43
         if ($attached) {
44 44
             $this->set_info($message, $data);
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
     {
104 104
         $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array());
105 105
 
106
-        if (! $do_hooks_only) {
106
+        if ( ! $do_hooks_only) {
107 107
             $this->rewind();
108 108
             //exit early if there is nothing to save.
109 109
             if ($this->count() < 1) {
Please login to merge, or discard this patch.