Completed
Branch BUG-10381-asset-loading (f91422)
by
unknown
170:16 queued 157:41
created
core/db_models/fields/EE_Full_HTML_Field.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      * @param string $table_column
20 20
      * @param string $nicename
21 21
      * @param bool   $nullable
22
-     * @param null   $default_value
22
+     * @param string   $default_value
23 23
      */
24 24
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
25 25
     {
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -15,57 +15,57 @@
 block discarded – undo
15 15
 class EE_Full_HTML_Field extends EE_Text_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * @param string $table_column
20
-     * @param string $nicename
21
-     * @param bool   $nullable
22
-     * @param null   $default_value
23
-     */
24
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
25
-    {
26
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
27
-        $this->setSchemaType('object');
28
-    }
18
+	/**
19
+	 * @param string $table_column
20
+	 * @param string $nicename
21
+	 * @param bool   $nullable
22
+	 * @param null   $default_value
23
+	 */
24
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
25
+	{
26
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
27
+		$this->setSchemaType('object');
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
33
-     *
34
-     * @param type $value_on_field_to_be_outputted
35
-     * @param type $schema
36
-     * @return string
37
-     */
38
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
39
-    {
40
-        if ($schema == 'form_input') {
41
-            return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
42
-        } elseif ($schema == 'no_wpautop') {
43
-            return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
44
-        } else {
45
-            return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
46
-        }
47
-    }
31
+	/**
32
+	 * Does shortcodes and auto-paragraphs the content (unless schema is 'no_wpautop')
33
+	 *
34
+	 * @param type $value_on_field_to_be_outputted
35
+	 * @param type $schema
36
+	 * @return string
37
+	 */
38
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
39
+	{
40
+		if ($schema == 'form_input') {
41
+			return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema);
42
+		} elseif ($schema == 'no_wpautop') {
43
+			return do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema));
44
+		} else {
45
+			return wpautop(do_shortcode(parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema)));
46
+		}
47
+	}
48 48
 
49 49
 
50 50
 
51
-    public function getSchemaProperties()
52
-    {
53
-        return array(
54
-            'raw' => array(
55
-                'description' =>  sprintf(
56
-                    __('%s - the value in the database.', 'event_espresso'),
57
-                    $this->get_nicename()
58
-                ),
59
-                'type' => 'string'
60
-            ),
61
-            'rendered' => array(
62
-                'description' =>  sprintf(
63
-                    __('%s - transformed for display.', 'event_espresso'),
64
-                    $this->get_nicename()
65
-                ),
66
-                'type' => 'string',
67
-                'readonly' => true
68
-            )
69
-        );
70
-    }
51
+	public function getSchemaProperties()
52
+	{
53
+		return array(
54
+			'raw' => array(
55
+				'description' =>  sprintf(
56
+					__('%s - the value in the database.', 'event_espresso'),
57
+					$this->get_nicename()
58
+				),
59
+				'type' => 'string'
60
+			),
61
+			'rendered' => array(
62
+				'description' =>  sprintf(
63
+					__('%s - transformed for display.', 'event_espresso'),
64
+					$this->get_nicename()
65
+				),
66
+				'type' => 'string',
67
+				'readonly' => true
68
+			)
69
+		);
70
+	}
71 71
 }
72 72
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Integer_Field.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
      * @param string $table_column
12 12
      * @param string $nicename
13 13
      * @param bool   $nullable
14
-     * @param null   $default_value
14
+     * @param integer|null   $default_value
15 15
      */
16 16
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
17 17
     {
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -7,26 +7,26 @@
 block discarded – undo
7 7
  */
8 8
 class EE_Integer_Field extends EE_Model_Field_Base
9 9
 {
10
-    /**
11
-     * @param string $table_column
12
-     * @param string $nicename
13
-     * @param bool   $nullable
14
-     * @param null   $default_value
15
-     */
16
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
-    {
18
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
19
-        $this->setSchemaType('integer');
20
-    }
10
+	/**
11
+	 * @param string $table_column
12
+	 * @param string $nicename
13
+	 * @param bool   $nullable
14
+	 * @param null   $default_value
15
+	 */
16
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
17
+	{
18
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
19
+		$this->setSchemaType('integer');
20
+	}
21 21
 
22 22
 
23
-    function prepare_for_set($value_inputted_for_field_on_model_object)
24
-    {
25
-        return intval($value_inputted_for_field_on_model_object);
26
-    }
23
+	function prepare_for_set($value_inputted_for_field_on_model_object)
24
+	{
25
+		return intval($value_inputted_for_field_on_model_object);
26
+	}
27 27
 
28
-    function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
29
-    {
30
-        return intval($value_inputted_for_field_on_model_object);
31
-    }
28
+	function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
29
+	{
30
+		return intval($value_inputted_for_field_on_model_object);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Model_Field_Base.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -582,7 +582,7 @@
 block discarded – undo
582 582
     /**
583 583
      * Validates that the incoming format is an allowable string to use for the _schema_format property
584 584
      * @throws InvalidArgumentException
585
-     * @param $format
585
+     * @param string $format
586 586
      */
587 587
     private function validateSchemaFormat($format)
588 588
     {
Please login to merge, or discard this patch.
Indentation   +597 added lines, -598 removed lines patch added patch discarded remove patch
@@ -21,602 +21,601 @@
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Model_Field_Base implements HasSchemaInterface
23 23
 {
24
-    /**
25
-     * The alias for the table the column belongs to.
26
-     * @var string
27
-     */
28
-    protected $_table_alias;
29
-
30
-    /**
31
-     * The actual db column name for the table
32
-     * @var string
33
-     */
34
-    protected $_table_column;
35
-
36
-
37
-    /**
38
-     * The authoritative name for the table column (used by client code to reference the field).
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-
44
-    /**
45
-     * A description for the field.
46
-     * @var string
47
-     */
48
-    protected $_nicename;
49
-
50
-
51
-    /**
52
-     * Whether the field is nullable or not
53
-     * @var bool
54
-     */
55
-    protected $_nullable;
56
-
57
-
58
-    /**
59
-     * What the default value for the field should be.
60
-     * @var mixed
61
-     */
62
-    protected $_default_value;
63
-
64
-
65
-    /**
66
-     * Other configuration for the field
67
-     * @var mixed
68
-     */
69
-    protected $_other_config;
70
-
71
-
72
-    /**
73
-     * The name of the model this field is instantiated for.
74
-     * @var string
75
-     */
76
-    protected $_model_name;
77
-
78
-
79
-    /**
80
-     * This should be a json-schema valid data type for the field.
81
-     * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
-     * @var string
83
-     */
84
-    private $_schema_type = 'string';
85
-
86
-
87
-    /**
88
-     * If the schema has a defined format then it should be defined via this property.
89
-     * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
-     * @var string
91
-     */
92
-    private $_schema_format = '';
93
-
94
-
95
-    /**
96
-     * Indicates that the value of the field is managed exclusively by the server/model and not something
97
-     * settable by client code.
98
-     * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
-     * @var bool
100
-     */
101
-    private $_schema_readonly = false;
102
-
103
-
104
-    /**
105
-     * @param string $table_column
106
-     * @param string $nicename
107
-     * @param bool   $nullable
108
-     * @param null   $default_value
109
-     */
110
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
-    {
112
-        $this->_table_column  = $table_column;
113
-        $this->_nicename      = $nicename;
114
-        $this->_nullable      = $nullable;
115
-        $this->_default_value = $default_value;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $table_alias
121
-     * @param $name
122
-     * @param $model_name
123
-     */
124
-    public function _construct_finalize($table_alias, $name, $model_name)
125
-    {
126
-        $this->_table_alias = $table_alias;
127
-        $this->_name        = $name;
128
-        $this->_model_name  = $model_name;
129
-        /**
130
-         * allow for changing the defaults
131
-         */
132
-        $this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
-            $this->_nicename, $this);
134
-        $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
-            $this->_default_value, $this);
136
-    }
137
-
138
-    public function get_table_alias()
139
-    {
140
-        return $this->_table_alias;
141
-    }
142
-
143
-    public function get_table_column()
144
-    {
145
-        return $this->_table_column;
146
-    }
147
-
148
-    /**
149
-     * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
-     *
151
-     * @return string
152
-     */
153
-    public function get_model_name()
154
-    {
155
-        return $this->_model_name;
156
-    }
157
-
158
-    /**
159
-     * @throws \EE_Error
160
-     * @return string
161
-     */
162
-    public function get_name()
163
-    {
164
-        if ($this->_name) {
165
-            return $this->_name;
166
-        } else {
167
-            throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
-                "event_espresso"), get_class($this)));
169
-        }
170
-    }
171
-
172
-    public function get_nicename()
173
-    {
174
-        return $this->_nicename;
175
-    }
176
-
177
-    public function is_nullable()
178
-    {
179
-        return $this->_nullable;
180
-    }
181
-
182
-    /**
183
-     * returns whether this field is an auto-increment field or not. If it is, then
184
-     * on insertion it can be null. However, on updates it must be present.
185
-     *
186
-     * @return boolean
187
-     */
188
-    public function is_auto_increment()
189
-    {
190
-        return false;
191
-    }
192
-
193
-    /**
194
-     * The default value in the model object's value domain. See lengthy comment about
195
-     * value domains at the top of EEM_Base
196
-     *
197
-     * @return mixed
198
-     */
199
-    public function get_default_value()
200
-    {
201
-        return $this->_default_value;
202
-    }
203
-
204
-    /**
205
-     * Returns the table alias joined to the table column, however this isn't the right
206
-     * table alias if the aliased table is being joined to. In that case, you can use
207
-     * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
-     * in the current query
209
-     *
210
-     * @return string
211
-     */
212
-    public function get_qualified_column()
213
-    {
214
-        return $this->get_table_alias() . "." . $this->get_table_column();
215
-    }
216
-
217
-    /**
218
-     * When get() is called on a model object (eg EE_Event), before returning its value,
219
-     * call this function on it, allowing us to customize the returned value based on
220
-     * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
-     * we simply return it.
222
-     *
223
-     * @param mixed $value_of_field_on_model_object
224
-     * @return mixed
225
-     */
226
-    public function prepare_for_get($value_of_field_on_model_object)
227
-    {
228
-        return $value_of_field_on_model_object;
229
-    }
230
-
231
-    /**
232
-     * When inserting or updating a field on a model object, run this function on each
233
-     * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
-     * By default, we do nothing.
235
-     *
236
-     * @param mixed $value_of_field_on_model_object
237
-     * @return mixed
238
-     */
239
-    public function prepare_for_use_in_db($value_of_field_on_model_object)
240
-    {
241
-        return $value_of_field_on_model_object;
242
-    }
243
-
244
-    /**
245
-     * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
-     * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
-     * By default, we do nothing.
248
-     *
249
-     * @param mixed $value_inputted_for_field_on_model_object
250
-     * @return mixed
251
-     */
252
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
253
-    {
254
-        return $value_inputted_for_field_on_model_object;
255
-    }
256
-
257
-
258
-    /**
259
-     * When instantiating a model object from DB results, this function is called before setting each field.
260
-     * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
-     * is the one child classes will most often define.
262
-     *
263
-     * @param mixed $value_found_in_db_for_model_object
264
-     * @return mixed
265
-     */
266
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
-    {
268
-        return $this->prepare_for_set($value_found_in_db_for_model_object);
269
-    }
270
-
271
-    /**
272
-     * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
-     * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
-     * 2013, at 3:23pm" instead of
275
-     * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
-     *
277
-     * @param mixed $value_on_field_to_be_outputted
278
-     * @return mixed
279
-     */
280
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
-    {
282
-        return $value_on_field_to_be_outputted;
283
-    }
284
-
285
-
286
-    /**
287
-     * Returns whatever is set as the nicename for the object.
288
-     * @return string
289
-     */
290
-    public function getSchemaDescription()
291
-    {
292
-        return $this->get_nicename();
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns whatever is set as the $_schema_type property for the object.
298
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
-     * @return string|array
300
-     */
301
-    public function getSchemaType()
302
-    {
303
-        if ($this->is_nullable()) {
304
-            $this->_schema_type = (array) $this->_schema_type;
305
-            if (! in_array('null', $this->_schema_type)) {
306
-                $this->_schema_type[] = 'null';
307
-            };
308
-        }
309
-        return $this->_schema_type;
310
-    }
311
-
312
-
313
-    /**
314
-     * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
-     * for this property.
316
-     * @param string|array $type
317
-     * @throws InvalidArgumentException
318
-     */
319
-    protected function setSchemaType($type)
320
-    {
321
-        $this->validateSchemaType($type);
322
-        $this->_schema_type = $type;
323
-    }
324
-
325
-
326
-    /**
327
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
-     * this method and return the properties for the schema.
329
-     *
330
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
331
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
-     *
333
-     * @return array
334
-     */
335
-    public function getSchemaProperties()
336
-    {
337
-        return array();
338
-    }
339
-
340
-
341
-    /**
342
-     * If a child class has enum values, they should override this method and provide a simple array
343
-     * of the enum values.
344
-
345
-     * The reason this is not a property on the class is because there may be filterable enum values that
346
-     * are set on the instantiated object that could be filtered after construct.
347
-     *
348
-     * @return array
349
-     */
350
-    public function getSchemaEnum()
351
-    {
352
-        return array();
353
-    }
354
-
355
-
356
-    /**
357
-     * This returns the value of the $_schema_format property on the object.
358
-     * @return string
359
-     */
360
-    public function getSchemaFormat()
361
-    {
362
-        return $this->_schema_format;
363
-    }
364
-
365
-
366
-    /**
367
-     * Sets the schema format property.
368
-     * @throws InvalidArgumentException
369
-     * @param string $format
370
-     */
371
-    protected function setSchemaFormat($format)
372
-    {
373
-        $this->validateSchemaFormat($format);
374
-        $this->_schema_format = $format;
375
-    }
376
-
377
-
378
-    /**
379
-     * This returns the value of the $_schema_readonly property on the object.
380
-     * @return bool
381
-     */
382
-    public function getSchemaReadonly()
383
-    {
384
-        return $this->_schema_readonly;
385
-    }
386
-
387
-
388
-    /**
389
-     * This sets the value for the $_schema_readonly property.
390
-     * @param bool $readonly  (only explicit boolean values are accepted)
391
-     */
392
-    protected function setSchemaReadOnly($readonly)
393
-    {
394
-        if (! is_bool($readonly)) {
395
-            throw new InvalidArgumentException(
396
-                sprintf(
397
-                    esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
398
-                    print_r($readonly, true)
399
-                )
400
-            );
401
-        }
402
-
403
-        $this->_schema_readonly = $readonly;
404
-    }
405
-
406
-
407
-
408
-
409
-    /**
410
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field.
411
-     * @uses _get_wpdb_data_type()
412
-     *
413
-     * @return string
414
-     */
415
-    public function get_wpdb_data_type()
416
-    {
417
-        return $this->_get_wpdb_data_type();
418
-    }
419
-
420
-
421
-    /**
422
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
423
-     * @param string $type  Included if a specific type is requested.
424
-     * @uses get_schema_type()
425
-     * @return string
426
-     */
427
-    protected function _get_wpdb_data_type($type='')
428
-    {
429
-        $type = empty($type) ? $this->getSchemaType() : $type;
430
-
431
-        //if type is an array, then different parsing is required.
432
-        if (is_array($type)) {
433
-            return $this->_get_wpdb_data_type_for_type_array($type);
434
-        }
435
-
436
-        $wpdb_type = '%s';
437
-        switch ($type) {
438
-            case 'number':
439
-                $wpdb_type = '%f';
440
-                break;
441
-            case 'integer':
442
-            case 'boolean':
443
-                $wpdb_type = '%d';
444
-                break;
445
-            case 'object':
446
-                $properties = $this->getSchemaProperties();
447
-                if (isset($properties['raw'], $properties['raw']['type'])) {
448
-                    $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
449
-                }
450
-                break; //leave at default
451
-        }
452
-        return $wpdb_type;
453
-    }
454
-
455
-
456
-
457
-    protected function _get_wpdb_data_type_for_type_array($type)
458
-    {
459
-        $type = (array) $type;
460
-        //first let's flip because then we can do a faster key check
461
-        $type = array_flip($type);
462
-
463
-        //check for things that mean '%s'
464
-        if (isset($type['string'],$type['object'],$type['array'])) {
465
-            return '%s';
466
-        }
467
-
468
-        //if makes it past the above condition and there's float in the array
469
-        //then the type is %f
470
-        if (isset($type['number'])) {
471
-            return '%f';
472
-        }
473
-
474
-        //if it makes it above the above conditions and there is an integer in the array
475
-        //then the type is %d
476
-        if (isset($type['integer'])) {
477
-            return '%d';
478
-        }
479
-
480
-        //anything else is a string
481
-        return '%s';
482
-    }
483
-
484
-
485
-    /**
486
-     * This returns elements used to represent this field in the json schema.
487
-     *
488
-     * @link http://json-schema.org/
489
-     * @return array
490
-     */
491
-    public function getSchema()
492
-    {
493
-        $schema = array(
494
-            'description' => $this->getSchemaDescription(),
495
-            'type' => $this->getSchemaType(),
496
-            'readonly' => $this->getSchemaReadonly(),
497
-        );
498
-
499
-        //optional properties of the schema
500
-        $enum = $this->getSchemaEnum();
501
-        $properties = $this->getSchemaProperties();
502
-        $format = $this->getSchemaFormat();
503
-        if ($enum) {
504
-            $schema['enum'] = $enum;
505
-        }
506
-
507
-        if ($properties) {
508
-            $schema['properties'] = $properties;
509
-        }
510
-
511
-        if ($format) {
512
-            $schema['format'] = $format;
513
-        }
514
-        return $schema;
515
-    }
516
-
517
-    /**
518
-     * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
519
-     * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
520
-     * want to see their value, then they shouldn't be db-only fields!)
521
-     * Eg, when doing events as custom post types, querying the post_type is essential, but
522
-     * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
523
-     * By default, all fields aren't db-only.
524
-     *
525
-     * @return boolean
526
-     */
527
-    public function is_db_only_field()
528
-    {
529
-        return false;
530
-    }
531
-
532
-
533
-    /**
534
-     * Validates the incoming string|array to ensure its an allowable type.
535
-     * @throws InvalidArgumentException
536
-     * @param string|array $type
537
-     */
538
-    private function validateSchemaType($type)
539
-    {
540
-        if (! (is_string($type) || is_array($type))) {
541
-            throw new InvalidArgumentException(
542
-                sprintf(
543
-                    esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
544
-                    print_r($type, true)
545
-                )
546
-            );
547
-        }
548
-
549
-        //validate allowable types.
550
-        //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
551
-        $allowable_types = array_flip(
552
-            array(
553
-                'string',
554
-                'number',
555
-                'null',
556
-                'object',
557
-                'array',
558
-                'boolean',
559
-                'integer'
560
-            )
561
-        );
562
-
563
-        if (is_array($type)) {
564
-            foreach ($type as $item_in_type) {
565
-                $this->validateSchemaType($item_in_type);
566
-            }
567
-            return;
568
-        }
569
-
570
-        if (! isset($allowable_types[$type])) {
571
-            throw new InvalidArgumentException(
572
-                sprintf(
573
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
574
-                    $type,
575
-                    implode(',', array_flip($allowable_types))
576
-                )
577
-            );
578
-        }
579
-    }
580
-
581
-
582
-    /**
583
-     * Validates that the incoming format is an allowable string to use for the _schema_format property
584
-     * @throws InvalidArgumentException
585
-     * @param $format
586
-     */
587
-    private function validateSchemaFormat($format)
588
-    {
589
-        if (! is_string($format)) {
590
-            throw new InvalidArgumentException(
591
-                sprintf(
592
-                    esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
593
-                    print_r($format, true)
594
-                )
595
-            );
596
-        }
597
-
598
-        //validate allowable format values
599
-        //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
600
-        $allowable_formats = array_flip(
601
-            array(
602
-                'date-time',
603
-                'email',
604
-                'hostname',
605
-                'ipv4',
606
-                'ipv6',
607
-                'uri',
608
-                'uriref'
609
-            )
610
-        );
611
-
612
-        if (! isset($allowable_formats[$format])) {
613
-            throw new InvalidArgumentException(
614
-                sprintf(
615
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
616
-                    $format,
617
-                    implode(',', array_flip($allowable_formats))
618
-                )
619
-            );
620
-        }
621
-    }
24
+	/**
25
+	 * The alias for the table the column belongs to.
26
+	 * @var string
27
+	 */
28
+	protected $_table_alias;
29
+
30
+	/**
31
+	 * The actual db column name for the table
32
+	 * @var string
33
+	 */
34
+	protected $_table_column;
35
+
36
+
37
+	/**
38
+	 * The authoritative name for the table column (used by client code to reference the field).
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+
44
+	/**
45
+	 * A description for the field.
46
+	 * @var string
47
+	 */
48
+	protected $_nicename;
49
+
50
+
51
+	/**
52
+	 * Whether the field is nullable or not
53
+	 * @var bool
54
+	 */
55
+	protected $_nullable;
56
+
57
+
58
+	/**
59
+	 * What the default value for the field should be.
60
+	 * @var mixed
61
+	 */
62
+	protected $_default_value;
63
+
64
+
65
+	/**
66
+	 * Other configuration for the field
67
+	 * @var mixed
68
+	 */
69
+	protected $_other_config;
70
+
71
+
72
+	/**
73
+	 * The name of the model this field is instantiated for.
74
+	 * @var string
75
+	 */
76
+	protected $_model_name;
77
+
78
+
79
+	/**
80
+	 * This should be a json-schema valid data type for the field.
81
+	 * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
+	 * @var string
83
+	 */
84
+	private $_schema_type = 'string';
85
+
86
+
87
+	/**
88
+	 * If the schema has a defined format then it should be defined via this property.
89
+	 * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
+	 * @var string
91
+	 */
92
+	private $_schema_format = '';
93
+
94
+
95
+	/**
96
+	 * Indicates that the value of the field is managed exclusively by the server/model and not something
97
+	 * settable by client code.
98
+	 * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
+	 * @var bool
100
+	 */
101
+	private $_schema_readonly = false;
102
+
103
+
104
+	/**
105
+	 * @param string $table_column
106
+	 * @param string $nicename
107
+	 * @param bool   $nullable
108
+	 * @param null   $default_value
109
+	 */
110
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
+	{
112
+		$this->_table_column  = $table_column;
113
+		$this->_nicename      = $nicename;
114
+		$this->_nullable      = $nullable;
115
+		$this->_default_value = $default_value;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $table_alias
121
+	 * @param $name
122
+	 * @param $model_name
123
+	 */
124
+	public function _construct_finalize($table_alias, $name, $model_name)
125
+	{
126
+		$this->_table_alias = $table_alias;
127
+		$this->_name        = $name;
128
+		$this->_model_name  = $model_name;
129
+		/**
130
+		 * allow for changing the defaults
131
+		 */
132
+		$this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
+			$this->_nicename, $this);
134
+		$this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
+			$this->_default_value, $this);
136
+	}
137
+
138
+	public function get_table_alias()
139
+	{
140
+		return $this->_table_alias;
141
+	}
142
+
143
+	public function get_table_column()
144
+	{
145
+		return $this->_table_column;
146
+	}
147
+
148
+	/**
149
+	 * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
+	 *
151
+	 * @return string
152
+	 */
153
+	public function get_model_name()
154
+	{
155
+		return $this->_model_name;
156
+	}
157
+
158
+	/**
159
+	 * @throws \EE_Error
160
+	 * @return string
161
+	 */
162
+	public function get_name()
163
+	{
164
+		if ($this->_name) {
165
+			return $this->_name;
166
+		} else {
167
+			throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
+				"event_espresso"), get_class($this)));
169
+		}
170
+	}
171
+
172
+	public function get_nicename()
173
+	{
174
+		return $this->_nicename;
175
+	}
176
+
177
+	public function is_nullable()
178
+	{
179
+		return $this->_nullable;
180
+	}
181
+
182
+	/**
183
+	 * returns whether this field is an auto-increment field or not. If it is, then
184
+	 * on insertion it can be null. However, on updates it must be present.
185
+	 *
186
+	 * @return boolean
187
+	 */
188
+	public function is_auto_increment()
189
+	{
190
+		return false;
191
+	}
192
+
193
+	/**
194
+	 * The default value in the model object's value domain. See lengthy comment about
195
+	 * value domains at the top of EEM_Base
196
+	 *
197
+	 * @return mixed
198
+	 */
199
+	public function get_default_value()
200
+	{
201
+		return $this->_default_value;
202
+	}
203
+
204
+	/**
205
+	 * Returns the table alias joined to the table column, however this isn't the right
206
+	 * table alias if the aliased table is being joined to. In that case, you can use
207
+	 * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
+	 * in the current query
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function get_qualified_column()
213
+	{
214
+		return $this->get_table_alias() . "." . $this->get_table_column();
215
+	}
216
+
217
+	/**
218
+	 * When get() is called on a model object (eg EE_Event), before returning its value,
219
+	 * call this function on it, allowing us to customize the returned value based on
220
+	 * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
+	 * we simply return it.
222
+	 *
223
+	 * @param mixed $value_of_field_on_model_object
224
+	 * @return mixed
225
+	 */
226
+	public function prepare_for_get($value_of_field_on_model_object)
227
+	{
228
+		return $value_of_field_on_model_object;
229
+	}
230
+
231
+	/**
232
+	 * When inserting or updating a field on a model object, run this function on each
233
+	 * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
+	 * By default, we do nothing.
235
+	 *
236
+	 * @param mixed $value_of_field_on_model_object
237
+	 * @return mixed
238
+	 */
239
+	public function prepare_for_use_in_db($value_of_field_on_model_object)
240
+	{
241
+		return $value_of_field_on_model_object;
242
+	}
243
+
244
+	/**
245
+	 * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
+	 * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
+	 * By default, we do nothing.
248
+	 *
249
+	 * @param mixed $value_inputted_for_field_on_model_object
250
+	 * @return mixed
251
+	 */
252
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
253
+	{
254
+		return $value_inputted_for_field_on_model_object;
255
+	}
256
+
257
+
258
+	/**
259
+	 * When instantiating a model object from DB results, this function is called before setting each field.
260
+	 * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
+	 * is the one child classes will most often define.
262
+	 *
263
+	 * @param mixed $value_found_in_db_for_model_object
264
+	 * @return mixed
265
+	 */
266
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
+	{
268
+		return $this->prepare_for_set($value_found_in_db_for_model_object);
269
+	}
270
+
271
+	/**
272
+	 * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
+	 * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
+	 * 2013, at 3:23pm" instead of
275
+	 * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
+	 *
277
+	 * @param mixed $value_on_field_to_be_outputted
278
+	 * @return mixed
279
+	 */
280
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
+	{
282
+		return $value_on_field_to_be_outputted;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Returns whatever is set as the nicename for the object.
288
+	 * @return string
289
+	 */
290
+	public function getSchemaDescription()
291
+	{
292
+		return $this->get_nicename();
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns whatever is set as the $_schema_type property for the object.
298
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
+	 * @return string|array
300
+	 */
301
+	public function getSchemaType()
302
+	{
303
+		if ($this->is_nullable()) {
304
+			$this->_schema_type = (array) $this->_schema_type;
305
+			if (! in_array('null', $this->_schema_type)) {
306
+				$this->_schema_type[] = 'null';
307
+			};
308
+		}
309
+		return $this->_schema_type;
310
+	}
311
+
312
+
313
+	/**
314
+	 * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
+	 * for this property.
316
+	 * @param string|array $type
317
+	 * @throws InvalidArgumentException
318
+	 */
319
+	protected function setSchemaType($type)
320
+	{
321
+		$this->validateSchemaType($type);
322
+		$this->_schema_type = $type;
323
+	}
324
+
325
+
326
+	/**
327
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
+	 * this method and return the properties for the schema.
329
+	 *
330
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
331
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
+	 *
333
+	 * @return array
334
+	 */
335
+	public function getSchemaProperties()
336
+	{
337
+		return array();
338
+	}
339
+
340
+
341
+	/**
342
+	 * If a child class has enum values, they should override this method and provide a simple array
343
+	 * of the enum values.
344
+	 * The reason this is not a property on the class is because there may be filterable enum values that
345
+	 * are set on the instantiated object that could be filtered after construct.
346
+	 *
347
+	 * @return array
348
+	 */
349
+	public function getSchemaEnum()
350
+	{
351
+		return array();
352
+	}
353
+
354
+
355
+	/**
356
+	 * This returns the value of the $_schema_format property on the object.
357
+	 * @return string
358
+	 */
359
+	public function getSchemaFormat()
360
+	{
361
+		return $this->_schema_format;
362
+	}
363
+
364
+
365
+	/**
366
+	 * Sets the schema format property.
367
+	 * @throws InvalidArgumentException
368
+	 * @param string $format
369
+	 */
370
+	protected function setSchemaFormat($format)
371
+	{
372
+		$this->validateSchemaFormat($format);
373
+		$this->_schema_format = $format;
374
+	}
375
+
376
+
377
+	/**
378
+	 * This returns the value of the $_schema_readonly property on the object.
379
+	 * @return bool
380
+	 */
381
+	public function getSchemaReadonly()
382
+	{
383
+		return $this->_schema_readonly;
384
+	}
385
+
386
+
387
+	/**
388
+	 * This sets the value for the $_schema_readonly property.
389
+	 * @param bool $readonly  (only explicit boolean values are accepted)
390
+	 */
391
+	protected function setSchemaReadOnly($readonly)
392
+	{
393
+		if (! is_bool($readonly)) {
394
+			throw new InvalidArgumentException(
395
+				sprintf(
396
+					esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
397
+					print_r($readonly, true)
398
+				)
399
+			);
400
+		}
401
+
402
+		$this->_schema_readonly = $readonly;
403
+	}
404
+
405
+
406
+
407
+
408
+	/**
409
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field.
410
+	 * @uses _get_wpdb_data_type()
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public function get_wpdb_data_type()
415
+	{
416
+		return $this->_get_wpdb_data_type();
417
+	}
418
+
419
+
420
+	/**
421
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
422
+	 * @param string $type  Included if a specific type is requested.
423
+	 * @uses get_schema_type()
424
+	 * @return string
425
+	 */
426
+	protected function _get_wpdb_data_type($type='')
427
+	{
428
+		$type = empty($type) ? $this->getSchemaType() : $type;
429
+
430
+		//if type is an array, then different parsing is required.
431
+		if (is_array($type)) {
432
+			return $this->_get_wpdb_data_type_for_type_array($type);
433
+		}
434
+
435
+		$wpdb_type = '%s';
436
+		switch ($type) {
437
+			case 'number':
438
+				$wpdb_type = '%f';
439
+				break;
440
+			case 'integer':
441
+			case 'boolean':
442
+				$wpdb_type = '%d';
443
+				break;
444
+			case 'object':
445
+				$properties = $this->getSchemaProperties();
446
+				if (isset($properties['raw'], $properties['raw']['type'])) {
447
+					$wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
448
+				}
449
+				break; //leave at default
450
+		}
451
+		return $wpdb_type;
452
+	}
453
+
454
+
455
+
456
+	protected function _get_wpdb_data_type_for_type_array($type)
457
+	{
458
+		$type = (array) $type;
459
+		//first let's flip because then we can do a faster key check
460
+		$type = array_flip($type);
461
+
462
+		//check for things that mean '%s'
463
+		if (isset($type['string'],$type['object'],$type['array'])) {
464
+			return '%s';
465
+		}
466
+
467
+		//if makes it past the above condition and there's float in the array
468
+		//then the type is %f
469
+		if (isset($type['number'])) {
470
+			return '%f';
471
+		}
472
+
473
+		//if it makes it above the above conditions and there is an integer in the array
474
+		//then the type is %d
475
+		if (isset($type['integer'])) {
476
+			return '%d';
477
+		}
478
+
479
+		//anything else is a string
480
+		return '%s';
481
+	}
482
+
483
+
484
+	/**
485
+	 * This returns elements used to represent this field in the json schema.
486
+	 *
487
+	 * @link http://json-schema.org/
488
+	 * @return array
489
+	 */
490
+	public function getSchema()
491
+	{
492
+		$schema = array(
493
+			'description' => $this->getSchemaDescription(),
494
+			'type' => $this->getSchemaType(),
495
+			'readonly' => $this->getSchemaReadonly(),
496
+		);
497
+
498
+		//optional properties of the schema
499
+		$enum = $this->getSchemaEnum();
500
+		$properties = $this->getSchemaProperties();
501
+		$format = $this->getSchemaFormat();
502
+		if ($enum) {
503
+			$schema['enum'] = $enum;
504
+		}
505
+
506
+		if ($properties) {
507
+			$schema['properties'] = $properties;
508
+		}
509
+
510
+		if ($format) {
511
+			$schema['format'] = $format;
512
+		}
513
+		return $schema;
514
+	}
515
+
516
+	/**
517
+	 * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
518
+	 * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
519
+	 * want to see their value, then they shouldn't be db-only fields!)
520
+	 * Eg, when doing events as custom post types, querying the post_type is essential, but
521
+	 * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
522
+	 * By default, all fields aren't db-only.
523
+	 *
524
+	 * @return boolean
525
+	 */
526
+	public function is_db_only_field()
527
+	{
528
+		return false;
529
+	}
530
+
531
+
532
+	/**
533
+	 * Validates the incoming string|array to ensure its an allowable type.
534
+	 * @throws InvalidArgumentException
535
+	 * @param string|array $type
536
+	 */
537
+	private function validateSchemaType($type)
538
+	{
539
+		if (! (is_string($type) || is_array($type))) {
540
+			throw new InvalidArgumentException(
541
+				sprintf(
542
+					esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
543
+					print_r($type, true)
544
+				)
545
+			);
546
+		}
547
+
548
+		//validate allowable types.
549
+		//@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
550
+		$allowable_types = array_flip(
551
+			array(
552
+				'string',
553
+				'number',
554
+				'null',
555
+				'object',
556
+				'array',
557
+				'boolean',
558
+				'integer'
559
+			)
560
+		);
561
+
562
+		if (is_array($type)) {
563
+			foreach ($type as $item_in_type) {
564
+				$this->validateSchemaType($item_in_type);
565
+			}
566
+			return;
567
+		}
568
+
569
+		if (! isset($allowable_types[$type])) {
570
+			throw new InvalidArgumentException(
571
+				sprintf(
572
+					esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
573
+					$type,
574
+					implode(',', array_flip($allowable_types))
575
+				)
576
+			);
577
+		}
578
+	}
579
+
580
+
581
+	/**
582
+	 * Validates that the incoming format is an allowable string to use for the _schema_format property
583
+	 * @throws InvalidArgumentException
584
+	 * @param $format
585
+	 */
586
+	private function validateSchemaFormat($format)
587
+	{
588
+		if (! is_string($format)) {
589
+			throw new InvalidArgumentException(
590
+				sprintf(
591
+					esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
592
+					print_r($format, true)
593
+				)
594
+			);
595
+		}
596
+
597
+		//validate allowable format values
598
+		//@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
599
+		$allowable_formats = array_flip(
600
+			array(
601
+				'date-time',
602
+				'email',
603
+				'hostname',
604
+				'ipv4',
605
+				'ipv6',
606
+				'uri',
607
+				'uriref'
608
+			)
609
+		);
610
+
611
+		if (! isset($allowable_formats[$format])) {
612
+			throw new InvalidArgumentException(
613
+				sprintf(
614
+					esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
615
+					$format,
616
+					implode(',', array_flip($allowable_formats))
617
+				)
618
+			);
619
+		}
620
+	}
622 621
 }
623 622
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      */
212 212
     public function get_qualified_column()
213 213
     {
214
-        return $this->get_table_alias() . "." . $this->get_table_column();
214
+        return $this->get_table_alias().".".$this->get_table_column();
215 215
     }
216 216
 
217 217
     /**
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
     {
303 303
         if ($this->is_nullable()) {
304 304
             $this->_schema_type = (array) $this->_schema_type;
305
-            if (! in_array('null', $this->_schema_type)) {
305
+            if ( ! in_array('null', $this->_schema_type)) {
306 306
                 $this->_schema_type[] = 'null';
307 307
             };
308 308
         }
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      */
392 392
     protected function setSchemaReadOnly($readonly)
393 393
     {
394
-        if (! is_bool($readonly)) {
394
+        if ( ! is_bool($readonly)) {
395 395
             throw new InvalidArgumentException(
396 396
                 sprintf(
397 397
                     esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
      * @uses get_schema_type()
425 425
      * @return string
426 426
      */
427
-    protected function _get_wpdb_data_type($type='')
427
+    protected function _get_wpdb_data_type($type = '')
428 428
     {
429 429
         $type = empty($type) ? $this->getSchemaType() : $type;
430 430
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         $type = array_flip($type);
462 462
 
463 463
         //check for things that mean '%s'
464
-        if (isset($type['string'],$type['object'],$type['array'])) {
464
+        if (isset($type['string'], $type['object'], $type['array'])) {
465 465
             return '%s';
466 466
         }
467 467
 
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      */
538 538
     private function validateSchemaType($type)
539 539
     {
540
-        if (! (is_string($type) || is_array($type))) {
540
+        if ( ! (is_string($type) || is_array($type))) {
541 541
             throw new InvalidArgumentException(
542 542
                 sprintf(
543 543
                     esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
             return;
568 568
         }
569 569
 
570
-        if (! isset($allowable_types[$type])) {
570
+        if ( ! isset($allowable_types[$type])) {
571 571
             throw new InvalidArgumentException(
572 572
                 sprintf(
573 573
                     esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
      */
587 587
     private function validateSchemaFormat($format)
588 588
     {
589
-        if (! is_string($format)) {
589
+        if ( ! is_string($format)) {
590 590
             throw new InvalidArgumentException(
591 591
                 sprintf(
592 592
                     esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
             )
610 610
         );
611 611
 
612
-        if (! isset($allowable_formats[$format])) {
612
+        if ( ! isset($allowable_formats[$format])) {
613 613
             throw new InvalidArgumentException(
614 614
                 sprintf(
615 615
                     esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
Please login to merge, or discard this patch.
core/db_models/fields/EE_Money_Field.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      * @param string $table_column
13 13
      * @param string $nicename
14 14
      * @param bool   $nullable
15
-     * @param null   $default_value
15
+     * @param integer   $default_value
16 16
      */
17 17
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
18 18
     {
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -8,91 +8,91 @@
 block discarded – undo
8 8
 class EE_Money_Field extends EE_Float_Field
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('object');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('object');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * Schemas:
26
-     *    'localized_float': "3,023.00"
27
-     *    'no_currency_code': "$3,023.00"
28
-     *    null: "$3,023.00<span>USD</span>"
29
-     *
30
-     * @param string $value_on_field_to_be_outputted
31
-     * @param string $schema
32
-     * @return string
33
-     */
34
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
-    {
36
-        $pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
24
+	/**
25
+	 * Schemas:
26
+	 *    'localized_float': "3,023.00"
27
+	 *    'no_currency_code': "$3,023.00"
28
+	 *    null: "$3,023.00<span>USD</span>"
29
+	 *
30
+	 * @param string $value_on_field_to_be_outputted
31
+	 * @param string $schema
32
+	 * @return string
33
+	 */
34
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
35
+	{
36
+		$pretty_float = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted);
37 37
 
38
-        if ($schema == 'localized_float') {
39
-            return $pretty_float;
40
-        }
41
-        if ($schema == 'no_currency_code') {
38
+		if ($schema == 'localized_float') {
39
+			return $pretty_float;
40
+		}
41
+		if ($schema == 'no_currency_code') {
42 42
 //			echo "schema no currency!";
43
-            $display_code = false;
44
-        } else {
45
-            $display_code = true;
46
-        }
47
-        //we don't use the $pretty_float because format_currency will take care of it.
48
-        return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
49
-    }
43
+			$display_code = false;
44
+		} else {
45
+			$display_code = true;
46
+		}
47
+		//we don't use the $pretty_float because format_currency will take care of it.
48
+		return EEH_Template::format_currency($value_on_field_to_be_outputted, false, $display_code);
49
+	}
50 50
 
51
-    /**
52
-     * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
-     * Rounds the float to the correct number of decimal places for this country's currency.
54
-     * Also, interprets periods and commas according to the country's currency settings.
55
-     * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
-     *
57
-     * @param string $value_inputted_for_field_on_model_object
58
-     * @return float
59
-     */
60
-    function prepare_for_set($value_inputted_for_field_on_model_object)
61
-    {
62
-        //remove any currencies etc.
51
+	/**
52
+	 * If provided with a string, strips out money-related formatting to turn it into a proper float.
53
+	 * Rounds the float to the correct number of decimal places for this country's currency.
54
+	 * Also, interprets periods and commas according to the country's currency settings.
55
+	 * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first.
56
+	 *
57
+	 * @param string $value_inputted_for_field_on_model_object
58
+	 * @return float
59
+	 */
60
+	function prepare_for_set($value_inputted_for_field_on_model_object)
61
+	{
62
+		//remove any currencies etc.
63 63
 //		if(is_string($value_inputted_for_field_on_model_object)){
64 64
 //			$value_inputted_for_field_on_model_object = preg_replace("/[^0-9,.]/", "", $value_inputted_for_field_on_model_object);
65 65
 //		}
66
-        //now it's a float-style string or number
67
-        $float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
68
-        //round to the correctly number of decimal places for this  currency
69
-        $rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
70
-        return $rounded_value;
71
-    }
66
+		//now it's a float-style string or number
67
+		$float_val = parent::prepare_for_set($value_inputted_for_field_on_model_object);
68
+		//round to the correctly number of decimal places for this  currency
69
+		$rounded_value = round($float_val, EE_Registry::instance()->CFG->currency->dec_plc);
70
+		return $rounded_value;
71
+	}
72 72
 
73
-    function prepare_for_get($value_of_field_on_model_object)
74
-    {
75
-        $c = EE_Registry::instance()->CFG->currency;
76
-        return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
77
-    }
73
+	function prepare_for_get($value_of_field_on_model_object)
74
+	{
75
+		$c = EE_Registry::instance()->CFG->currency;
76
+		return round(parent::prepare_for_get($value_of_field_on_model_object), $c->dec_plc);
77
+	}
78 78
 
79
-    public function getSchemaProperties()
80
-    {
81
-        return array(
82
-            'raw' => array(
83
-                'description' =>  sprintf(
84
-                    __('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
85
-                    $this->get_nicename()
86
-                ),
87
-                'type' => 'number'
88
-            ),
89
-            'pretty' => array(
90
-                'description' =>  sprintf(
91
-                    __('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
92
-                    $this->get_nicename()
93
-                ),
94
-                'type' => 'string'
95
-            )
96
-        );
97
-    }
79
+	public function getSchemaProperties()
80
+	{
81
+		return array(
82
+			'raw' => array(
83
+				'description' =>  sprintf(
84
+					__('%s - the raw value as it exists in the database as a simple float.', 'event_espresso'),
85
+					$this->get_nicename()
86
+				),
87
+				'type' => 'number'
88
+			),
89
+			'pretty' => array(
90
+				'description' =>  sprintf(
91
+					__('%s - formatted for display in the set currency and decimal places.', 'event_espresso'),
92
+					$this->get_nicename()
93
+				),
94
+				'type' => 'string'
95
+			)
96
+		);
97
+	}
98 98
 }
99 99
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/rest_api/Model_Version_Info.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
 
90 90
 
91 91
 
92
-    /**
93
-     * Model_Version_Info constructor.
94
-     *
95
-     * @param string $requested_version
96
-     */
97
-    public function __construct( $requested_version ) {
92
+	/**
93
+	 * Model_Version_Info constructor.
94
+	 *
95
+	 * @param string $requested_version
96
+	 */
97
+	public function __construct( $requested_version ) {
98 98
 		$this->_requested_version = $requested_version;
99 99
 		$this->_model_changes = array(
100 100
 			'4.8.29' => array(
@@ -209,10 +209,10 @@  discard block
 block discarded – undo
209 209
 				}
210 210
 			}
211 211
 			$this->_cached_models_for_requested_version = apply_filters(
212
-			    'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
213
-                $all_models_in_current_version,
214
-                $this
215
-            );
212
+				'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version',
213
+				$all_models_in_current_version,
214
+				$this
215
+			);
216 216
 		}
217 217
 		return $this->_cached_models_for_requested_version;
218 218
 	}
Please login to merge, or discard this patch.
core/db_models/fields/EE_DB_Only_Int_Field.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,15 +3,15 @@
 block discarded – undo
3 3
 
4 4
 class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base
5 5
 {
6
-    /**
7
-     * @param string $table_column
8
-     * @param string $nicename
9
-     * @param bool   $nullable
10
-     * @param null   $default_value
11
-     */
12
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
-    {
14
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
15
-        $this->setSchemaType('integer');
16
-    }
6
+	/**
7
+	 * @param string $table_column
8
+	 * @param string $nicename
9
+	 * @param bool   $nullable
10
+	 * @param null   $default_value
11
+	 */
12
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
+	{
14
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
15
+		$this->setSchemaType('integer');
16
+	}
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Infinite_Integer_Field.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
 class EE_Infinite_Integer_Field extends EE_Model_Field_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @param string $table_column
16
-     * @param string $nicename
17
-     * @param bool   $nullable
18
-     * @param null   $default_value
19
-     */
20
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
21
-    {
22
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
23
-        $this->setSchemaType(array('integer', 'null'));
24
-    }
14
+	/**
15
+	 * @param string $table_column
16
+	 * @param string $nicename
17
+	 * @param bool   $nullable
18
+	 * @param null   $default_value
19
+	 */
20
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
21
+	{
22
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
23
+		$this->setSchemaType(array('integer', 'null'));
24
+	}
25 25
 
26 26
 
27
-    function prepare_for_use_in_db($value_of_field_on_model_object)
28
-    {
29
-        if ($value_of_field_on_model_object === EE_INF) {
30
-            return EE_INF_IN_DB;
31
-        } else {
32
-            return intval($value_of_field_on_model_object);
33
-        }
34
-    }
27
+	function prepare_for_use_in_db($value_of_field_on_model_object)
28
+	{
29
+		if ($value_of_field_on_model_object === EE_INF) {
30
+			return EE_INF_IN_DB;
31
+		} else {
32
+			return intval($value_of_field_on_model_object);
33
+		}
34
+	}
35 35
 
36
-    function prepare_for_set($value_inputted_for_field_on_model_object)
37
-    {
38
-        if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
-            $value_inputted_for_field_on_model_object === EE_INF ||
40
-            $value_inputted_for_field_on_model_object === "EE_INF" ||
41
-            $value_inputted_for_field_on_model_object === ""
42
-        ) {
43
-            return EE_INF;
44
-        } else {
45
-            return intval($value_inputted_for_field_on_model_object);
46
-        }
47
-    }
36
+	function prepare_for_set($value_inputted_for_field_on_model_object)
37
+	{
38
+		if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
+			$value_inputted_for_field_on_model_object === EE_INF ||
40
+			$value_inputted_for_field_on_model_object === "EE_INF" ||
41
+			$value_inputted_for_field_on_model_object === ""
42
+		) {
43
+			return EE_INF;
44
+		} else {
45
+			return intval($value_inputted_for_field_on_model_object);
46
+		}
47
+	}
48 48
 
49
-    function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
-    {
51
-        $intval = intval($value_inputted_for_field_on_model_object);
52
-        if ($intval == EE_INF_IN_DB) {
53
-            return EE_INF;
54
-        } else {
55
-            return $intval;
56
-        }
57
-    }
49
+	function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
+	{
51
+		$intval = intval($value_inputted_for_field_on_model_object);
52
+		if ($intval == EE_INF_IN_DB) {
53
+			return EE_INF;
54
+		} else {
55
+			return $intval;
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * For outputting this field's value. If you want to output it into an input or something,
61
-     * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
-     * as it will replace EE_INF with i18n Infinite
63
-     *
64
-     * @param type   $value_on_field_to_be_outputted
65
-     * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
-     * @return string
67
-     */
68
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
-    {
70
-        if ($value_on_field_to_be_outputted === EE_INF) {
71
-            switch ($schema) {
72
-                case 'input':
73
-                case 'form_input':
74
-                    return '';
75
-                case 'symbol':
76
-                    return "&infin;";
77
-                case 'text':
78
-                case null:
79
-                    return __("Unlimited", "event_espresso");
80
-                default:
81
-                    return $schema;
82
-            }
83
-        } else {
84
-            return $value_on_field_to_be_outputted;
85
-        }
86
-    }
59
+	/**
60
+	 * For outputting this field's value. If you want to output it into an input or something,
61
+	 * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
+	 * as it will replace EE_INF with i18n Infinite
63
+	 *
64
+	 * @param type   $value_on_field_to_be_outputted
65
+	 * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
+	 * @return string
67
+	 */
68
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
+	{
70
+		if ($value_on_field_to_be_outputted === EE_INF) {
71
+			switch ($schema) {
72
+				case 'input':
73
+				case 'form_input':
74
+					return '';
75
+				case 'symbol':
76
+					return "&infin;";
77
+				case 'text':
78
+				case null:
79
+					return __("Unlimited", "event_espresso");
80
+				default:
81
+					return $schema;
82
+			}
83
+		} else {
84
+			return $value_on_field_to_be_outputted;
85
+		}
86
+	}
87 87
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Serialized_Text_Field.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -10,72 +10,72 @@
 block discarded – undo
10 10
 class EE_Serialized_Text_Field extends EE_Text_Field_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @param string $table_column
15
-     * @param string $nicename
16
-     * @param bool   $nullable
17
-     * @param null   $default_value
18
-     */
19
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
-    {
21
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
22
-        $this->setSchemaType(array('object','string'));
23
-    }
13
+	/**
14
+	 * @param string $table_column
15
+	 * @param string $nicename
16
+	 * @param bool   $nullable
17
+	 * @param null   $default_value
18
+	 */
19
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
+	{
21
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
22
+		$this->setSchemaType(array('object','string'));
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Value SHOULD be an array, and we want to now convert it to a serialized string
28
-     *
29
-     * @param array $value_of_field_on_model_object
30
-     * @return string
31
-     */
32
-    function prepare_for_use_in_db($value_of_field_on_model_object)
33
-    {
34
-        return maybe_serialize($value_of_field_on_model_object);
35
-    }
26
+	/**
27
+	 * Value SHOULD be an array, and we want to now convert it to a serialized string
28
+	 *
29
+	 * @param array $value_of_field_on_model_object
30
+	 * @return string
31
+	 */
32
+	function prepare_for_use_in_db($value_of_field_on_model_object)
33
+	{
34
+		return maybe_serialize($value_of_field_on_model_object);
35
+	}
36 36
 
37
-    function prepare_for_set($value_inputted_for_field_on_model_object)
38
-    {
39
-        $value_inputted_for_field_on_model_object = EEH_Array::maybe_unserialize($value_inputted_for_field_on_model_object);
40
-        if (is_string($value_inputted_for_field_on_model_object)) {
41
-            return parent::prepare_for_set($value_inputted_for_field_on_model_object);
42
-        } elseif (is_array($value_inputted_for_field_on_model_object)) {
43
-            return array_map(array($this, 'prepare_for_set'), $value_inputted_for_field_on_model_object);
44
-        } else {//so they passed NULL or an INT or something wack
45
-            return $value_inputted_for_field_on_model_object;
46
-        }
47
-    }
37
+	function prepare_for_set($value_inputted_for_field_on_model_object)
38
+	{
39
+		$value_inputted_for_field_on_model_object = EEH_Array::maybe_unserialize($value_inputted_for_field_on_model_object);
40
+		if (is_string($value_inputted_for_field_on_model_object)) {
41
+			return parent::prepare_for_set($value_inputted_for_field_on_model_object);
42
+		} elseif (is_array($value_inputted_for_field_on_model_object)) {
43
+			return array_map(array($this, 'prepare_for_set'), $value_inputted_for_field_on_model_object);
44
+		} else {//so they passed NULL or an INT or something wack
45
+			return $value_inputted_for_field_on_model_object;
46
+		}
47
+	}
48 48
 
49
-    /**
50
-     * Value provided should definetely be a serialized string. We should unserialize into an array
51
-     *
52
-     * @param string $value_found_in_db_for_model_object
53
-     * @return array
54
-     */
55
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
56
-    {
57
-        return EEH_Array::maybe_unserialize($value_found_in_db_for_model_object);
58
-    }
49
+	/**
50
+	 * Value provided should definetely be a serialized string. We should unserialize into an array
51
+	 *
52
+	 * @param string $value_found_in_db_for_model_object
53
+	 * @return array
54
+	 */
55
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
56
+	{
57
+		return EEH_Array::maybe_unserialize($value_found_in_db_for_model_object);
58
+	}
59 59
 
60
-    /**
61
-     * Gets a string representation of the array
62
-     *
63
-     * @param type   $value_on_field_to_be_outputted
64
-     * @param string $schema , possible values are ',', others can be added
65
-     * @return string
66
-     */
67
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
-    {
69
-        switch ($schema) {
70
-            case 'print_r':
71
-                $pretty_value = print_r($value_on_field_to_be_outputted, true);
72
-                break;
73
-            case 'as_table':
74
-                $pretty_value = EEH_Template::layout_array_as_table($value_on_field_to_be_outputted);
75
-                break;
76
-            default:
77
-                $pretty_value = implode(", ", $value_on_field_to_be_outputted);
78
-        }
79
-        return $pretty_value;
80
-    }
60
+	/**
61
+	 * Gets a string representation of the array
62
+	 *
63
+	 * @param type   $value_on_field_to_be_outputted
64
+	 * @param string $schema , possible values are ',', others can be added
65
+	 * @return string
66
+	 */
67
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
+	{
69
+		switch ($schema) {
70
+			case 'print_r':
71
+				$pretty_value = print_r($value_on_field_to_be_outputted, true);
72
+				break;
73
+			case 'as_table':
74
+				$pretty_value = EEH_Template::layout_array_as_table($value_on_field_to_be_outputted);
75
+				break;
76
+			default:
77
+				$pretty_value = implode(", ", $value_on_field_to_be_outputted);
78
+		}
79
+		return $pretty_value;
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
20 20
     {
21 21
         parent::__construct($table_column, $nicename, $nullable, $default_value);
22
-        $this->setSchemaType(array('object','string'));
22
+        $this->setSchemaType(array('object', 'string'));
23 23
     }
24 24
 
25 25
 
Please login to merge, or discard this patch.
core/db_models/fields/EE_Enum_Integer_Field.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -10,115 +10,115 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Enum_Integer_Field extends EE_Integer_Field
12 12
 {
13
-    /**
14
-     * @var array $_allowed_enum_values
15
-     */
16
-    public $_allowed_enum_values;
13
+	/**
14
+	 * @var array $_allowed_enum_values
15
+	 */
16
+	public $_allowed_enum_values;
17 17
 
18 18
 
19
-    /**
20
-     * @param string  $table_column
21
-     * @param string  $nicename
22
-     * @param boolean $nullable
23
-     * @param int     $default_value
24
-     * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
25
-     */
26
-    public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
27
-    {
28
-        $this->_allowed_enum_values = $allowed_enum_values;
29
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
30
-        $this->setSchemaType('object');
31
-    }
19
+	/**
20
+	 * @param string  $table_column
21
+	 * @param string  $nicename
22
+	 * @param boolean $nullable
23
+	 * @param int     $default_value
24
+	 * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
25
+	 */
26
+	public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
27
+	{
28
+		$this->_allowed_enum_values = $allowed_enum_values;
29
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
30
+		$this->setSchemaType('object');
31
+	}
32 32
 
33
-    /**
34
-     * Returns the list of allowed enum options, but filterable.
35
-     * This is used internally
36
-     *
37
-     * @return array
38
-     */
39
-    protected function _allowed_enum_values()
40
-    {
41
-        return (array)apply_filters(
42
-            'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43
-            $this->_allowed_enum_values,
44
-            $this
45
-        );
46
-    }
33
+	/**
34
+	 * Returns the list of allowed enum options, but filterable.
35
+	 * This is used internally
36
+	 *
37
+	 * @return array
38
+	 */
39
+	protected function _allowed_enum_values()
40
+	{
41
+		return (array)apply_filters(
42
+			'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43
+			$this->_allowed_enum_values,
44
+			$this
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * When setting, just verify that the value being used matches what we've defined as allowable enum values.
50
-     * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
51
-     *
52
-     * @param int $value_inputted_for_field_on_model_object
53
-     * @return int
54
-     * @throws EE_Error
55
-     */
56
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
57
-    {
58
-        $allowed_enum_values = $this->_allowed_enum_values();
59
-        if (
60
-            $value_inputted_for_field_on_model_object !== null
61
-            && ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
62
-        ) {
63
-            if (defined('WP_DEBUG') && WP_DEBUG) {
64
-                $msg = sprintf(
65
-                    __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
66
-                    $value_inputted_for_field_on_model_object,
67
-                    $this->_name
68
-                );
69
-                $msg2 = sprintf(
70
-                    __('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
71
-                    $this->_name,
72
-                    implode(', ', array_keys($allowed_enum_values)),
73
-                    $value_inputted_for_field_on_model_object
74
-                );
75
-                EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
76
-            }
77
-            return $this->get_default_value();
78
-        }
79
-        return (int)$value_inputted_for_field_on_model_object;
80
-    }
48
+	/**
49
+	 * When setting, just verify that the value being used matches what we've defined as allowable enum values.
50
+	 * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
51
+	 *
52
+	 * @param int $value_inputted_for_field_on_model_object
53
+	 * @return int
54
+	 * @throws EE_Error
55
+	 */
56
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
57
+	{
58
+		$allowed_enum_values = $this->_allowed_enum_values();
59
+		if (
60
+			$value_inputted_for_field_on_model_object !== null
61
+			&& ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
62
+		) {
63
+			if (defined('WP_DEBUG') && WP_DEBUG) {
64
+				$msg = sprintf(
65
+					__('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
66
+					$value_inputted_for_field_on_model_object,
67
+					$this->_name
68
+				);
69
+				$msg2 = sprintf(
70
+					__('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
71
+					$this->_name,
72
+					implode(', ', array_keys($allowed_enum_values)),
73
+					$value_inputted_for_field_on_model_object
74
+				);
75
+				EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
76
+			}
77
+			return $this->get_default_value();
78
+		}
79
+		return (int)$value_inputted_for_field_on_model_object;
80
+	}
81 81
 
82 82
 
83 83
 
84
-    /**
85
-     * Gets the pretty version of the enum's value.
86
-     *
87
-     * @param int | string $value_on_field_to_be_outputted
88
-     * @param null         $schema
89
-     * @return string
90
-     */
91
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
92
-    {
93
-        $options = $this->_allowed_enum_values();
94
-        if (isset($options[$value_on_field_to_be_outputted])) {
95
-            return $options[$value_on_field_to_be_outputted];
96
-        } else {
97
-            return $value_on_field_to_be_outputted;
98
-        }
99
-    }
84
+	/**
85
+	 * Gets the pretty version of the enum's value.
86
+	 *
87
+	 * @param int | string $value_on_field_to_be_outputted
88
+	 * @param null         $schema
89
+	 * @return string
90
+	 */
91
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
92
+	{
93
+		$options = $this->_allowed_enum_values();
94
+		if (isset($options[$value_on_field_to_be_outputted])) {
95
+			return $options[$value_on_field_to_be_outputted];
96
+		} else {
97
+			return $value_on_field_to_be_outputted;
98
+		}
99
+	}
100 100
 
101 101
 
102
-    public function getSchemaProperties()
103
-    {
104
-        return array(
105
-            'raw' => array(
106
-                'description' =>  sprintf(
107
-                    __('%s - the value in the database.', 'event_espresso'),
108
-                    $this->get_nicename()
109
-                ),
110
-                'enum' => array_keys($this->_allowed_enum_values()),
111
-                'type' => 'integer'
112
-            ),
113
-            'pretty' => array(
114
-                'description' =>  sprintf(
115
-                    __('%s - the value for display.', 'event_espresso'),
116
-                    $this->get_nicename()
117
-                ),
118
-                'enum' => array_values($this->_allowed_enum_values()),
119
-                'type' => 'string',
120
-                'read_only' => true
121
-            )
122
-        );
123
-    }
102
+	public function getSchemaProperties()
103
+	{
104
+		return array(
105
+			'raw' => array(
106
+				'description' =>  sprintf(
107
+					__('%s - the value in the database.', 'event_espresso'),
108
+					$this->get_nicename()
109
+				),
110
+				'enum' => array_keys($this->_allowed_enum_values()),
111
+				'type' => 'integer'
112
+			),
113
+			'pretty' => array(
114
+				'description' =>  sprintf(
115
+					__('%s - the value for display.', 'event_espresso'),
116
+					$this->get_nicename()
117
+				),
118
+				'enum' => array_values($this->_allowed_enum_values()),
119
+				'type' => 'string',
120
+				'read_only' => true
121
+			)
122
+		);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     protected function _allowed_enum_values()
40 40
     {
41
-        return (array)apply_filters(
41
+        return (array) apply_filters(
42 42
             'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43 43
             $this->_allowed_enum_values,
44 44
             $this
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             }
77 77
             return $this->get_default_value();
78 78
         }
79
-        return (int)$value_inputted_for_field_on_model_object;
79
+        return (int) $value_inputted_for_field_on_model_object;
80 80
     }
81 81
 
82 82
 
Please login to merge, or discard this patch.