Completed
Branch FET/table-schema-dms (6bf39e)
by
unknown
09:25 queued 06:29
created
core/db_models/fields/EE_Slug_Field.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -2,15 +2,15 @@
 block discarded – undo
2 2
 
3 3
 class EE_Slug_Field extends EE_Text_Field_Base
4 4
 {
5
-    /**
6
-     * ensures string is usable in URLs
7
-     *
8
-     * @param string $value_inputted_for_field_on_model_object
9
-     * @return string
10
-     */
11
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
12
-    {
13
-        // reminder: function prepares for use in URLs, not making human-readable.
14
-        return sanitize_title($value_inputted_for_field_on_model_object);
15
-    }
5
+	/**
6
+	 * ensures string is usable in URLs
7
+	 *
8
+	 * @param string $value_inputted_for_field_on_model_object
9
+	 * @return string
10
+	 */
11
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
12
+	{
13
+		// reminder: function prepares for use in URLs, not making human-readable.
14
+		return sanitize_title($value_inputted_for_field_on_model_object);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_Int_Field.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -3,27 +3,27 @@
 block discarded – undo
3 3
 class EE_Primary_Key_Int_Field extends EE_Primary_Key_Field_Base
4 4
 {
5 5
 
6
-    public function __construct($table_column, $nicename)
7
-    {
8
-        parent::__construct($table_column, $nicename, 0);
9
-        $this->setSchemaType('integer');
10
-    }
6
+	public function __construct($table_column, $nicename)
7
+	{
8
+		parent::__construct($table_column, $nicename, 0);
9
+		$this->setSchemaType('integer');
10
+	}
11 11
 
12
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
13
-    {
14
-        if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
15
-            $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
16
-        }
17
-        return absint($value_inputted_for_field_on_model_object);
18
-    }
12
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
13
+	{
14
+		if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) {
15
+			$value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID();
16
+		}
17
+		return absint($value_inputted_for_field_on_model_object);
18
+	}
19 19
 
20
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
21
-    {
22
-        return intval($value_found_in_db_for_model_object);
23
-    }
20
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
21
+	{
22
+		return intval($value_found_in_db_for_model_object);
23
+	}
24 24
 
25
-    public function is_auto_increment()
26
-    {
27
-        return true;
28
-    }
25
+	public function is_auto_increment()
26
+	{
27
+		return true;
28
+	}
29 29
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Type_Field.php.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field
7 7
 {
8
-    /**
9
-     * @param string $post_type the exact string to be used for the post type
10
-     *                          of all these post type model objects/rows
11
-     */
12
-    public function __construct($post_type)
13
-    {
14
-        parent::__construct('post_type', __("Post Type", 'event_espresso'), false, $post_type);
15
-    }
8
+	/**
9
+	 * @param string $post_type the exact string to be used for the post type
10
+	 *                          of all these post type model objects/rows
11
+	 */
12
+	public function __construct($post_type)
13
+	{
14
+		parent::__construct('post_type', __("Post Type", 'event_espresso'), false, $post_type);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Model_Field_Base.php 2 patches
Indentation   +646 added lines, -647 removed lines patch added patch discarded remove patch
@@ -19,651 +19,650 @@
 block discarded – undo
19 19
  */
20 20
 abstract class EE_Model_Field_Base implements HasSchemaInterface
21 21
 {
22
-    /**
23
-     * The alias for the table the column belongs to.
24
-     * @var string
25
-     */
26
-    protected $_table_alias;
27
-
28
-    /**
29
-     * The actual db column name for the table
30
-     * @var string
31
-     */
32
-    protected $_table_column;
33
-
34
-
35
-    /**
36
-     * The authoritative name for the table column (used by client code to reference the field).
37
-     * @var string
38
-     */
39
-    protected $_name;
40
-
41
-
42
-    /**
43
-     * A description for the field.
44
-     * @var string
45
-     */
46
-    protected $_nicename;
47
-
48
-
49
-    /**
50
-     * Whether the field is nullable or not
51
-     * @var bool
52
-     */
53
-    protected $_nullable;
54
-
55
-
56
-    /**
57
-     * What the default value for the field should be.
58
-     * @var mixed
59
-     */
60
-    protected $_default_value;
61
-
62
-
63
-    /**
64
-     * Other configuration for the field
65
-     * @var mixed
66
-     */
67
-    protected $_other_config;
68
-
69
-
70
-    /**
71
-     * The name of the model this field is instantiated for.
72
-     * @var string
73
-     */
74
-    protected $_model_name;
75
-
76
-
77
-    /**
78
-     * This should be a json-schema valid data type for the field.
79
-     * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
80
-     * @var string
81
-     */
82
-    private $_schema_type = 'string';
83
-
84
-
85
-    /**
86
-     * If the schema has a defined format then it should be defined via this property.
87
-     * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
88
-     * @var string
89
-     */
90
-    private $_schema_format = '';
91
-
92
-
93
-    /**
94
-     * Indicates that the value of the field is managed exclusively by the server/model and not something
95
-     * settable by client code.
96
-     * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
97
-     * @var bool
98
-     */
99
-    private $_schema_readonly = false;
100
-
101
-
102
-    /**
103
-     * @param string $table_column
104
-     * @param string $nicename
105
-     * @param bool   $nullable
106
-     * @param null   $default_value
107
-     */
108
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
109
-    {
110
-        $this->_table_column  = $table_column;
111
-        $this->_nicename      = $nicename;
112
-        $this->_nullable      = $nullable;
113
-        $this->_default_value = $default_value;
114
-    }
115
-
116
-
117
-    /**
118
-     * @param $table_alias
119
-     * @param $name
120
-     * @param $model_name
121
-     */
122
-    public function _construct_finalize($table_alias, $name, $model_name)
123
-    {
124
-        $this->_table_alias = $table_alias;
125
-        $this->_name        = $name;
126
-        $this->_model_name  = $model_name;
127
-        /**
128
-         * allow for changing the defaults
129
-         */
130
-        $this->_nicename      = apply_filters(
131
-            'FHEE__EE_Model_Field_Base___construct_finalize___nicename',
132
-            $this->_nicename,
133
-            $this
134
-        );
135
-        $this->_default_value = apply_filters(
136
-            'FHEE__EE_Model_Field_Base___construct_finalize___default_value',
137
-            $this->_default_value,
138
-            $this
139
-        );
140
-    }
141
-
142
-    public function get_table_alias()
143
-    {
144
-        return $this->_table_alias;
145
-    }
146
-
147
-    public function get_table_column()
148
-    {
149
-        return $this->_table_column;
150
-    }
151
-
152
-    /**
153
-     * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
154
-     *
155
-     * @return string
156
-     */
157
-    public function get_model_name()
158
-    {
159
-        return $this->_model_name;
160
-    }
161
-
162
-    /**
163
-     * @throws \EE_Error
164
-     * @return string
165
-     */
166
-    public function get_name()
167
-    {
168
-        if ($this->_name) {
169
-            return $this->_name;
170
-        } else {
171
-            throw new EE_Error(sprintf(__(
172
-                "Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
173
-                "event_espresso"
174
-            ), get_class($this)));
175
-        }
176
-    }
177
-
178
-    public function get_nicename()
179
-    {
180
-        return $this->_nicename;
181
-    }
182
-
183
-    public function is_nullable()
184
-    {
185
-        return $this->_nullable;
186
-    }
187
-
188
-    /**
189
-     * returns whether this field is an auto-increment field or not. If it is, then
190
-     * on insertion it can be null. However, on updates it must be present.
191
-     *
192
-     * @return boolean
193
-     */
194
-    public function is_auto_increment()
195
-    {
196
-        return false;
197
-    }
198
-
199
-    /**
200
-     * The default value in the model object's value domain. See lengthy comment about
201
-     * value domains at the top of EEM_Base
202
-     *
203
-     * @return mixed
204
-     */
205
-    public function get_default_value()
206
-    {
207
-        return $this->_default_value;
208
-    }
209
-
210
-    /**
211
-     * Returns the table alias joined to the table column, however this isn't the right
212
-     * table alias if the aliased table is being joined to. In that case, you can use
213
-     * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
214
-     * in the current query
215
-     *
216
-     * @return string
217
-     */
218
-    public function get_qualified_column()
219
-    {
220
-        return $this->get_table_alias() . "." . $this->get_table_column();
221
-    }
222
-
223
-    /**
224
-     * When get() is called on a model object (eg EE_Event), before returning its value,
225
-     * call this function on it, allowing us to customize the returned value based on
226
-     * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default,
227
-     * we simply return it.
228
-     *
229
-     * @param mixed $value_of_field_on_model_object
230
-     * @return mixed
231
-     */
232
-    public function prepare_for_get($value_of_field_on_model_object)
233
-    {
234
-        return $value_of_field_on_model_object;
235
-    }
236
-
237
-    /**
238
-     * When inserting or updating a field on a model object, run this function on each
239
-     * value to prepare it for insertion into the db. Generally this converts
240
-     * the validated input on the model object into the format used in the DB.
241
-     *
242
-     * @param mixed $value_of_field_on_model_object
243
-     * @return mixed
244
-     */
245
-    public function prepare_for_use_in_db($value_of_field_on_model_object)
246
-    {
247
-        return $value_of_field_on_model_object;
248
-    }
249
-
250
-    /**
251
-     * When creating a brand-new model object, or setting a particular value for one of its fields, this function
252
-     * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
253
-     * By default, we do nothing.
254
-     *
255
-     * If the model field is going to perform any validation on the input, this is where it should be done
256
-     * (once the value is on the model object, it may be used in other ways besides putting it into the DB
257
-     * so it's best to validate it right away).
258
-     *
259
-     * @param mixed $value_inputted_for_field_on_model_object
260
-     * @return mixed
261
-     */
262
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
263
-    {
264
-        return $value_inputted_for_field_on_model_object;
265
-    }
266
-
267
-
268
-    /**
269
-     * When instantiating a model object from DB results, this function is called before setting each field.
270
-     * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
271
-     * is the one child classes will most often define.
272
-     *
273
-     * @param mixed $value_found_in_db_for_model_object
274
-     * @return mixed
275
-     */
276
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
277
-    {
278
-        return $this->prepare_for_set($value_found_in_db_for_model_object);
279
-    }
280
-
281
-    /**
282
-     * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
283
-     * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
284
-     * 2013, at 3:23pm" instead of
285
-     * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
286
-     *
287
-     * @param mixed $value_on_field_to_be_outputted
288
-     * @return mixed
289
-     */
290
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
291
-    {
292
-        return $value_on_field_to_be_outputted;
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns whatever is set as the nicename for the object.
298
-     * @return string
299
-     */
300
-    public function getSchemaDescription()
301
-    {
302
-        return $this->get_nicename();
303
-    }
304
-
305
-
306
-    /**
307
-     * Returns whatever is set as the $_schema_type property for the object.
308
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
309
-     * @return string|array
310
-     */
311
-    public function getSchemaType()
312
-    {
313
-        if ($this->is_nullable()) {
314
-            $this->_schema_type = (array) $this->_schema_type;
315
-            if (! in_array('null', $this->_schema_type)) {
316
-                $this->_schema_type[] = 'null';
317
-            };
318
-        }
319
-        return $this->_schema_type;
320
-    }
321
-
322
-
323
-    /**
324
-     * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
325
-     * for this property.
326
-     * @param string|array $type
327
-     * @throws InvalidArgumentException
328
-     */
329
-    protected function setSchemaType($type)
330
-    {
331
-        $this->validateSchemaType($type);
332
-        $this->_schema_type = $type;
333
-    }
334
-
335
-
336
-    /**
337
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
338
-     * this method and return the properties for the schema.
339
-     *
340
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
341
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
342
-     *
343
-     * @return array
344
-     */
345
-    public function getSchemaProperties()
346
-    {
347
-        return array();
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * By default this returns the scalar default value that was sent in on the class prepped according to the class type
354
-     * as the default.  However, when there are schema properties, then the default property is setup to mirror the
355
-     * property keys and correctly prepare the default according to that expected property value.
356
-     * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type
357
-     *
358
-     * @return mixed
359
-     */
360
-    public function getSchemaDefault()
361
-    {
362
-        $default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value()));
363
-        $schema_properties = $this->getSchemaProperties();
364
-
365
-        // if this schema has properties than shape the default value to match the properties shape.
366
-        if ($schema_properties) {
367
-            $value_to_return = array();
368
-            foreach ($schema_properties as $property_key => $property_schema) {
369
-                switch ($property_key) {
370
-                    case 'pretty':
371
-                    case 'rendered':
372
-                        $value_to_return[ $property_key ] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
373
-                        break;
374
-                    default:
375
-                        $value_to_return[ $property_key ] = $default_value;
376
-                        break;
377
-                }
378
-            }
379
-            $default_value = $value_to_return;
380
-        }
381
-        return $default_value;
382
-    }
383
-
384
-
385
-
386
-
387
-    /**
388
-     * If a child class has enum values, they should override this method and provide a simple array
389
-     * of the enum values.
390
-
391
-     * The reason this is not a property on the class is because there may be filterable enum values that
392
-     * are set on the instantiated object that could be filtered after construct.
393
-     *
394
-     * @return array
395
-     */
396
-    public function getSchemaEnum()
397
-    {
398
-        return array();
399
-    }
400
-
401
-
402
-    /**
403
-     * This returns the value of the $_schema_format property on the object.
404
-     * @return string
405
-     */
406
-    public function getSchemaFormat()
407
-    {
408
-        return $this->_schema_format;
409
-    }
410
-
411
-
412
-    /**
413
-     * Sets the schema format property.
414
-     * @throws InvalidArgumentException
415
-     * @param string $format
416
-     */
417
-    protected function setSchemaFormat($format)
418
-    {
419
-        $this->validateSchemaFormat($format);
420
-        $this->_schema_format = $format;
421
-    }
422
-
423
-
424
-    /**
425
-     * This returns the value of the $_schema_readonly property on the object.
426
-     * @return bool
427
-     */
428
-    public function getSchemaReadonly()
429
-    {
430
-        return $this->_schema_readonly;
431
-    }
432
-
433
-
434
-    /**
435
-     * This sets the value for the $_schema_readonly property.
436
-     * @param bool $readonly  (only explicit boolean values are accepted)
437
-     */
438
-    protected function setSchemaReadOnly($readonly)
439
-    {
440
-        if (! is_bool($readonly)) {
441
-            throw new InvalidArgumentException(
442
-                sprintf(
443
-                    esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
444
-                    print_r($readonly, true)
445
-                )
446
-            );
447
-        }
448
-
449
-        $this->_schema_readonly = $readonly;
450
-    }
451
-
452
-
453
-
454
-
455
-    /**
456
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field.
457
-     * @uses _get_wpdb_data_type()
458
-     *
459
-     * @return string
460
-     */
461
-    public function get_wpdb_data_type()
462
-    {
463
-        return $this->_get_wpdb_data_type();
464
-    }
465
-
466
-
467
-    /**
468
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
469
-     * @param string $type  Included if a specific type is requested.
470
-     * @uses get_schema_type()
471
-     * @return string
472
-     */
473
-    protected function _get_wpdb_data_type($type = '')
474
-    {
475
-        $type = empty($type) ? $this->getSchemaType() : $type;
476
-
477
-        // if type is an array, then different parsing is required.
478
-        if (is_array($type)) {
479
-            return $this->_get_wpdb_data_type_for_type_array($type);
480
-        }
481
-
482
-        $wpdb_type = '%s';
483
-        switch ($type) {
484
-            case 'number':
485
-                $wpdb_type = '%f';
486
-                break;
487
-            case 'integer':
488
-            case 'boolean':
489
-                $wpdb_type = '%d';
490
-                break;
491
-            case 'object':
492
-                $properties = $this->getSchemaProperties();
493
-                if (isset($properties['raw'], $properties['raw']['type'])) {
494
-                    $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
495
-                }
496
-                break; // leave at default
497
-        }
498
-        return $wpdb_type;
499
-    }
500
-
501
-
502
-
503
-    protected function _get_wpdb_data_type_for_type_array($type)
504
-    {
505
-        $type = (array) $type;
506
-        // first let's flip because then we can do a faster key check
507
-        $type = array_flip($type);
508
-
509
-        // check for things that mean '%s'
510
-        if (isset($type['string'], $type['object'], $type['array'])) {
511
-            return '%s';
512
-        }
513
-
514
-        // if makes it past the above condition and there's float in the array
515
-        // then the type is %f
516
-        if (isset($type['number'])) {
517
-            return '%f';
518
-        }
519
-
520
-        // if it makes it above the above conditions and there is an integer in the array
521
-        // then the type is %d
522
-        if (isset($type['integer'])) {
523
-            return '%d';
524
-        }
525
-
526
-        // anything else is a string
527
-        return '%s';
528
-    }
529
-
530
-
531
-    /**
532
-     * This returns elements used to represent this field in the json schema.
533
-     *
534
-     * @link http://json-schema.org/
535
-     * @return array
536
-     */
537
-    public function getSchema()
538
-    {
539
-        $schema = array(
540
-            'description' => $this->getSchemaDescription(),
541
-            'type' => $this->getSchemaType(),
542
-            'readonly' => $this->getSchemaReadonly(),
543
-            'default' => $this->getSchemaDefault()
544
-        );
545
-
546
-        // optional properties of the schema
547
-        $enum = $this->getSchemaEnum();
548
-        $properties = $this->getSchemaProperties();
549
-        $format = $this->getSchemaFormat();
550
-        if ($enum) {
551
-            $schema['enum'] = $enum;
552
-        }
553
-
554
-        if ($properties) {
555
-            $schema['properties'] = $properties;
556
-        }
557
-
558
-        if ($format) {
559
-            $schema['format'] = $format;
560
-        }
561
-        return $schema;
562
-    }
563
-
564
-    /**
565
-     * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
566
-     * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
567
-     * want to see their value, then they shouldn't be db-only fields!)
568
-     * Eg, when doing events as custom post types, querying the post_type is essential, but
569
-     * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
570
-     * By default, all fields aren't db-only.
571
-     *
572
-     * @return boolean
573
-     */
574
-    public function is_db_only_field()
575
-    {
576
-        return false;
577
-    }
578
-
579
-
580
-    /**
581
-     * Validates the incoming string|array to ensure its an allowable type.
582
-     * @throws InvalidArgumentException
583
-     * @param string|array $type
584
-     */
585
-    private function validateSchemaType($type)
586
-    {
587
-        if (! (is_string($type) || is_array($type))) {
588
-            throw new InvalidArgumentException(
589
-                sprintf(
590
-                    esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
591
-                    print_r($type, true)
592
-                )
593
-            );
594
-        }
595
-
596
-        // validate allowable types.
597
-        // @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
598
-        $allowable_types = array_flip(
599
-            array(
600
-                'string',
601
-                'number',
602
-                'null',
603
-                'object',
604
-                'array',
605
-                'boolean',
606
-                'integer'
607
-            )
608
-        );
609
-
610
-        if (is_array($type)) {
611
-            foreach ($type as $item_in_type) {
612
-                $this->validateSchemaType($item_in_type);
613
-            }
614
-            return;
615
-        }
616
-
617
-        if (! isset($allowable_types[ $type ])) {
618
-            throw new InvalidArgumentException(
619
-                sprintf(
620
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
621
-                    $type,
622
-                    implode(',', array_flip($allowable_types))
623
-                )
624
-            );
625
-        }
626
-    }
627
-
628
-
629
-    /**
630
-     * Validates that the incoming format is an allowable string to use for the _schema_format property
631
-     * @throws InvalidArgumentException
632
-     * @param $format
633
-     */
634
-    private function validateSchemaFormat($format)
635
-    {
636
-        if (! is_string($format)) {
637
-            throw new InvalidArgumentException(
638
-                sprintf(
639
-                    esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
640
-                    print_r($format, true)
641
-                )
642
-            );
643
-        }
644
-
645
-        // validate allowable format values
646
-        // @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
647
-        $allowable_formats = array_flip(
648
-            array(
649
-                'date-time',
650
-                'email',
651
-                'hostname',
652
-                'ipv4',
653
-                'ipv6',
654
-                'uri',
655
-                'uriref'
656
-            )
657
-        );
658
-
659
-        if (! isset($allowable_formats[ $format ])) {
660
-            throw new InvalidArgumentException(
661
-                sprintf(
662
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
663
-                    $format,
664
-                    implode(',', array_flip($allowable_formats))
665
-                )
666
-            );
667
-        }
668
-    }
22
+	/**
23
+	 * The alias for the table the column belongs to.
24
+	 * @var string
25
+	 */
26
+	protected $_table_alias;
27
+
28
+	/**
29
+	 * The actual db column name for the table
30
+	 * @var string
31
+	 */
32
+	protected $_table_column;
33
+
34
+
35
+	/**
36
+	 * The authoritative name for the table column (used by client code to reference the field).
37
+	 * @var string
38
+	 */
39
+	protected $_name;
40
+
41
+
42
+	/**
43
+	 * A description for the field.
44
+	 * @var string
45
+	 */
46
+	protected $_nicename;
47
+
48
+
49
+	/**
50
+	 * Whether the field is nullable or not
51
+	 * @var bool
52
+	 */
53
+	protected $_nullable;
54
+
55
+
56
+	/**
57
+	 * What the default value for the field should be.
58
+	 * @var mixed
59
+	 */
60
+	protected $_default_value;
61
+
62
+
63
+	/**
64
+	 * Other configuration for the field
65
+	 * @var mixed
66
+	 */
67
+	protected $_other_config;
68
+
69
+
70
+	/**
71
+	 * The name of the model this field is instantiated for.
72
+	 * @var string
73
+	 */
74
+	protected $_model_name;
75
+
76
+
77
+	/**
78
+	 * This should be a json-schema valid data type for the field.
79
+	 * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
80
+	 * @var string
81
+	 */
82
+	private $_schema_type = 'string';
83
+
84
+
85
+	/**
86
+	 * If the schema has a defined format then it should be defined via this property.
87
+	 * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
88
+	 * @var string
89
+	 */
90
+	private $_schema_format = '';
91
+
92
+
93
+	/**
94
+	 * Indicates that the value of the field is managed exclusively by the server/model and not something
95
+	 * settable by client code.
96
+	 * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
97
+	 * @var bool
98
+	 */
99
+	private $_schema_readonly = false;
100
+
101
+
102
+	/**
103
+	 * @param string $table_column
104
+	 * @param string $nicename
105
+	 * @param bool   $nullable
106
+	 * @param null   $default_value
107
+	 */
108
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
109
+	{
110
+		$this->_table_column  = $table_column;
111
+		$this->_nicename      = $nicename;
112
+		$this->_nullable      = $nullable;
113
+		$this->_default_value = $default_value;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @param $table_alias
119
+	 * @param $name
120
+	 * @param $model_name
121
+	 */
122
+	public function _construct_finalize($table_alias, $name, $model_name)
123
+	{
124
+		$this->_table_alias = $table_alias;
125
+		$this->_name        = $name;
126
+		$this->_model_name  = $model_name;
127
+		/**
128
+		 * allow for changing the defaults
129
+		 */
130
+		$this->_nicename      = apply_filters(
131
+			'FHEE__EE_Model_Field_Base___construct_finalize___nicename',
132
+			$this->_nicename,
133
+			$this
134
+		);
135
+		$this->_default_value = apply_filters(
136
+			'FHEE__EE_Model_Field_Base___construct_finalize___default_value',
137
+			$this->_default_value,
138
+			$this
139
+		);
140
+	}
141
+
142
+	public function get_table_alias()
143
+	{
144
+		return $this->_table_alias;
145
+	}
146
+
147
+	public function get_table_column()
148
+	{
149
+		return $this->_table_column;
150
+	}
151
+
152
+	/**
153
+	 * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
154
+	 *
155
+	 * @return string
156
+	 */
157
+	public function get_model_name()
158
+	{
159
+		return $this->_model_name;
160
+	}
161
+
162
+	/**
163
+	 * @throws \EE_Error
164
+	 * @return string
165
+	 */
166
+	public function get_name()
167
+	{
168
+		if ($this->_name) {
169
+			return $this->_name;
170
+		} else {
171
+			throw new EE_Error(sprintf(__(
172
+				"Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
173
+				"event_espresso"
174
+			), get_class($this)));
175
+		}
176
+	}
177
+
178
+	public function get_nicename()
179
+	{
180
+		return $this->_nicename;
181
+	}
182
+
183
+	public function is_nullable()
184
+	{
185
+		return $this->_nullable;
186
+	}
187
+
188
+	/**
189
+	 * returns whether this field is an auto-increment field or not. If it is, then
190
+	 * on insertion it can be null. However, on updates it must be present.
191
+	 *
192
+	 * @return boolean
193
+	 */
194
+	public function is_auto_increment()
195
+	{
196
+		return false;
197
+	}
198
+
199
+	/**
200
+	 * The default value in the model object's value domain. See lengthy comment about
201
+	 * value domains at the top of EEM_Base
202
+	 *
203
+	 * @return mixed
204
+	 */
205
+	public function get_default_value()
206
+	{
207
+		return $this->_default_value;
208
+	}
209
+
210
+	/**
211
+	 * Returns the table alias joined to the table column, however this isn't the right
212
+	 * table alias if the aliased table is being joined to. In that case, you can use
213
+	 * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
214
+	 * in the current query
215
+	 *
216
+	 * @return string
217
+	 */
218
+	public function get_qualified_column()
219
+	{
220
+		return $this->get_table_alias() . "." . $this->get_table_column();
221
+	}
222
+
223
+	/**
224
+	 * When get() is called on a model object (eg EE_Event), before returning its value,
225
+	 * call this function on it, allowing us to customize the returned value based on
226
+	 * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default,
227
+	 * we simply return it.
228
+	 *
229
+	 * @param mixed $value_of_field_on_model_object
230
+	 * @return mixed
231
+	 */
232
+	public function prepare_for_get($value_of_field_on_model_object)
233
+	{
234
+		return $value_of_field_on_model_object;
235
+	}
236
+
237
+	/**
238
+	 * When inserting or updating a field on a model object, run this function on each
239
+	 * value to prepare it for insertion into the db. Generally this converts
240
+	 * the validated input on the model object into the format used in the DB.
241
+	 *
242
+	 * @param mixed $value_of_field_on_model_object
243
+	 * @return mixed
244
+	 */
245
+	public function prepare_for_use_in_db($value_of_field_on_model_object)
246
+	{
247
+		return $value_of_field_on_model_object;
248
+	}
249
+
250
+	/**
251
+	 * When creating a brand-new model object, or setting a particular value for one of its fields, this function
252
+	 * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
253
+	 * By default, we do nothing.
254
+	 *
255
+	 * If the model field is going to perform any validation on the input, this is where it should be done
256
+	 * (once the value is on the model object, it may be used in other ways besides putting it into the DB
257
+	 * so it's best to validate it right away).
258
+	 *
259
+	 * @param mixed $value_inputted_for_field_on_model_object
260
+	 * @return mixed
261
+	 */
262
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
263
+	{
264
+		return $value_inputted_for_field_on_model_object;
265
+	}
266
+
267
+
268
+	/**
269
+	 * When instantiating a model object from DB results, this function is called before setting each field.
270
+	 * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
271
+	 * is the one child classes will most often define.
272
+	 *
273
+	 * @param mixed $value_found_in_db_for_model_object
274
+	 * @return mixed
275
+	 */
276
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
277
+	{
278
+		return $this->prepare_for_set($value_found_in_db_for_model_object);
279
+	}
280
+
281
+	/**
282
+	 * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
283
+	 * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
284
+	 * 2013, at 3:23pm" instead of
285
+	 * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
286
+	 *
287
+	 * @param mixed $value_on_field_to_be_outputted
288
+	 * @return mixed
289
+	 */
290
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
291
+	{
292
+		return $value_on_field_to_be_outputted;
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns whatever is set as the nicename for the object.
298
+	 * @return string
299
+	 */
300
+	public function getSchemaDescription()
301
+	{
302
+		return $this->get_nicename();
303
+	}
304
+
305
+
306
+	/**
307
+	 * Returns whatever is set as the $_schema_type property for the object.
308
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
309
+	 * @return string|array
310
+	 */
311
+	public function getSchemaType()
312
+	{
313
+		if ($this->is_nullable()) {
314
+			$this->_schema_type = (array) $this->_schema_type;
315
+			if (! in_array('null', $this->_schema_type)) {
316
+				$this->_schema_type[] = 'null';
317
+			};
318
+		}
319
+		return $this->_schema_type;
320
+	}
321
+
322
+
323
+	/**
324
+	 * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
325
+	 * for this property.
326
+	 * @param string|array $type
327
+	 * @throws InvalidArgumentException
328
+	 */
329
+	protected function setSchemaType($type)
330
+	{
331
+		$this->validateSchemaType($type);
332
+		$this->_schema_type = $type;
333
+	}
334
+
335
+
336
+	/**
337
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
338
+	 * this method and return the properties for the schema.
339
+	 *
340
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
341
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
342
+	 *
343
+	 * @return array
344
+	 */
345
+	public function getSchemaProperties()
346
+	{
347
+		return array();
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * By default this returns the scalar default value that was sent in on the class prepped according to the class type
354
+	 * as the default.  However, when there are schema properties, then the default property is setup to mirror the
355
+	 * property keys and correctly prepare the default according to that expected property value.
356
+	 * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type
357
+	 *
358
+	 * @return mixed
359
+	 */
360
+	public function getSchemaDefault()
361
+	{
362
+		$default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value()));
363
+		$schema_properties = $this->getSchemaProperties();
364
+
365
+		// if this schema has properties than shape the default value to match the properties shape.
366
+		if ($schema_properties) {
367
+			$value_to_return = array();
368
+			foreach ($schema_properties as $property_key => $property_schema) {
369
+				switch ($property_key) {
370
+					case 'pretty':
371
+					case 'rendered':
372
+						$value_to_return[ $property_key ] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
373
+						break;
374
+					default:
375
+						$value_to_return[ $property_key ] = $default_value;
376
+						break;
377
+				}
378
+			}
379
+			$default_value = $value_to_return;
380
+		}
381
+		return $default_value;
382
+	}
383
+
384
+
385
+
386
+
387
+	/**
388
+	 * If a child class has enum values, they should override this method and provide a simple array
389
+	 * of the enum values.
390
+	 * The reason this is not a property on the class is because there may be filterable enum values that
391
+	 * are set on the instantiated object that could be filtered after construct.
392
+	 *
393
+	 * @return array
394
+	 */
395
+	public function getSchemaEnum()
396
+	{
397
+		return array();
398
+	}
399
+
400
+
401
+	/**
402
+	 * This returns the value of the $_schema_format property on the object.
403
+	 * @return string
404
+	 */
405
+	public function getSchemaFormat()
406
+	{
407
+		return $this->_schema_format;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Sets the schema format property.
413
+	 * @throws InvalidArgumentException
414
+	 * @param string $format
415
+	 */
416
+	protected function setSchemaFormat($format)
417
+	{
418
+		$this->validateSchemaFormat($format);
419
+		$this->_schema_format = $format;
420
+	}
421
+
422
+
423
+	/**
424
+	 * This returns the value of the $_schema_readonly property on the object.
425
+	 * @return bool
426
+	 */
427
+	public function getSchemaReadonly()
428
+	{
429
+		return $this->_schema_readonly;
430
+	}
431
+
432
+
433
+	/**
434
+	 * This sets the value for the $_schema_readonly property.
435
+	 * @param bool $readonly  (only explicit boolean values are accepted)
436
+	 */
437
+	protected function setSchemaReadOnly($readonly)
438
+	{
439
+		if (! is_bool($readonly)) {
440
+			throw new InvalidArgumentException(
441
+				sprintf(
442
+					esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
443
+					print_r($readonly, true)
444
+				)
445
+			);
446
+		}
447
+
448
+		$this->_schema_readonly = $readonly;
449
+	}
450
+
451
+
452
+
453
+
454
+	/**
455
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field.
456
+	 * @uses _get_wpdb_data_type()
457
+	 *
458
+	 * @return string
459
+	 */
460
+	public function get_wpdb_data_type()
461
+	{
462
+		return $this->_get_wpdb_data_type();
463
+	}
464
+
465
+
466
+	/**
467
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
468
+	 * @param string $type  Included if a specific type is requested.
469
+	 * @uses get_schema_type()
470
+	 * @return string
471
+	 */
472
+	protected function _get_wpdb_data_type($type = '')
473
+	{
474
+		$type = empty($type) ? $this->getSchemaType() : $type;
475
+
476
+		// if type is an array, then different parsing is required.
477
+		if (is_array($type)) {
478
+			return $this->_get_wpdb_data_type_for_type_array($type);
479
+		}
480
+
481
+		$wpdb_type = '%s';
482
+		switch ($type) {
483
+			case 'number':
484
+				$wpdb_type = '%f';
485
+				break;
486
+			case 'integer':
487
+			case 'boolean':
488
+				$wpdb_type = '%d';
489
+				break;
490
+			case 'object':
491
+				$properties = $this->getSchemaProperties();
492
+				if (isset($properties['raw'], $properties['raw']['type'])) {
493
+					$wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
494
+				}
495
+				break; // leave at default
496
+		}
497
+		return $wpdb_type;
498
+	}
499
+
500
+
501
+
502
+	protected function _get_wpdb_data_type_for_type_array($type)
503
+	{
504
+		$type = (array) $type;
505
+		// first let's flip because then we can do a faster key check
506
+		$type = array_flip($type);
507
+
508
+		// check for things that mean '%s'
509
+		if (isset($type['string'], $type['object'], $type['array'])) {
510
+			return '%s';
511
+		}
512
+
513
+		// if makes it past the above condition and there's float in the array
514
+		// then the type is %f
515
+		if (isset($type['number'])) {
516
+			return '%f';
517
+		}
518
+
519
+		// if it makes it above the above conditions and there is an integer in the array
520
+		// then the type is %d
521
+		if (isset($type['integer'])) {
522
+			return '%d';
523
+		}
524
+
525
+		// anything else is a string
526
+		return '%s';
527
+	}
528
+
529
+
530
+	/**
531
+	 * This returns elements used to represent this field in the json schema.
532
+	 *
533
+	 * @link http://json-schema.org/
534
+	 * @return array
535
+	 */
536
+	public function getSchema()
537
+	{
538
+		$schema = array(
539
+			'description' => $this->getSchemaDescription(),
540
+			'type' => $this->getSchemaType(),
541
+			'readonly' => $this->getSchemaReadonly(),
542
+			'default' => $this->getSchemaDefault()
543
+		);
544
+
545
+		// optional properties of the schema
546
+		$enum = $this->getSchemaEnum();
547
+		$properties = $this->getSchemaProperties();
548
+		$format = $this->getSchemaFormat();
549
+		if ($enum) {
550
+			$schema['enum'] = $enum;
551
+		}
552
+
553
+		if ($properties) {
554
+			$schema['properties'] = $properties;
555
+		}
556
+
557
+		if ($format) {
558
+			$schema['format'] = $format;
559
+		}
560
+		return $schema;
561
+	}
562
+
563
+	/**
564
+	 * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
565
+	 * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
566
+	 * want to see their value, then they shouldn't be db-only fields!)
567
+	 * Eg, when doing events as custom post types, querying the post_type is essential, but
568
+	 * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
569
+	 * By default, all fields aren't db-only.
570
+	 *
571
+	 * @return boolean
572
+	 */
573
+	public function is_db_only_field()
574
+	{
575
+		return false;
576
+	}
577
+
578
+
579
+	/**
580
+	 * Validates the incoming string|array to ensure its an allowable type.
581
+	 * @throws InvalidArgumentException
582
+	 * @param string|array $type
583
+	 */
584
+	private function validateSchemaType($type)
585
+	{
586
+		if (! (is_string($type) || is_array($type))) {
587
+			throw new InvalidArgumentException(
588
+				sprintf(
589
+					esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
590
+					print_r($type, true)
591
+				)
592
+			);
593
+		}
594
+
595
+		// validate allowable types.
596
+		// @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
597
+		$allowable_types = array_flip(
598
+			array(
599
+				'string',
600
+				'number',
601
+				'null',
602
+				'object',
603
+				'array',
604
+				'boolean',
605
+				'integer'
606
+			)
607
+		);
608
+
609
+		if (is_array($type)) {
610
+			foreach ($type as $item_in_type) {
611
+				$this->validateSchemaType($item_in_type);
612
+			}
613
+			return;
614
+		}
615
+
616
+		if (! isset($allowable_types[ $type ])) {
617
+			throw new InvalidArgumentException(
618
+				sprintf(
619
+					esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
620
+					$type,
621
+					implode(',', array_flip($allowable_types))
622
+				)
623
+			);
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Validates that the incoming format is an allowable string to use for the _schema_format property
630
+	 * @throws InvalidArgumentException
631
+	 * @param $format
632
+	 */
633
+	private function validateSchemaFormat($format)
634
+	{
635
+		if (! is_string($format)) {
636
+			throw new InvalidArgumentException(
637
+				sprintf(
638
+					esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
639
+					print_r($format, true)
640
+				)
641
+			);
642
+		}
643
+
644
+		// validate allowable format values
645
+		// @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
646
+		$allowable_formats = array_flip(
647
+			array(
648
+				'date-time',
649
+				'email',
650
+				'hostname',
651
+				'ipv4',
652
+				'ipv6',
653
+				'uri',
654
+				'uriref'
655
+			)
656
+		);
657
+
658
+		if (! isset($allowable_formats[ $format ])) {
659
+			throw new InvalidArgumentException(
660
+				sprintf(
661
+					esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
662
+					$format,
663
+					implode(',', array_flip($allowable_formats))
664
+				)
665
+			);
666
+		}
667
+	}
669 668
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         /**
128 128
          * allow for changing the defaults
129 129
          */
130
-        $this->_nicename      = apply_filters(
130
+        $this->_nicename = apply_filters(
131 131
             'FHEE__EE_Model_Field_Base___construct_finalize___nicename',
132 132
             $this->_nicename,
133 133
             $this
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
      */
218 218
     public function get_qualified_column()
219 219
     {
220
-        return $this->get_table_alias() . "." . $this->get_table_column();
220
+        return $this->get_table_alias().".".$this->get_table_column();
221 221
     }
222 222
 
223 223
     /**
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     {
313 313
         if ($this->is_nullable()) {
314 314
             $this->_schema_type = (array) $this->_schema_type;
315
-            if (! in_array('null', $this->_schema_type)) {
315
+            if ( ! in_array('null', $this->_schema_type)) {
316 316
                 $this->_schema_type[] = 'null';
317 317
             };
318 318
         }
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
                 switch ($property_key) {
370 370
                     case 'pretty':
371 371
                     case 'rendered':
372
-                        $value_to_return[ $property_key ] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
372
+                        $value_to_return[$property_key] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value));
373 373
                         break;
374 374
                     default:
375
-                        $value_to_return[ $property_key ] = $default_value;
375
+                        $value_to_return[$property_key] = $default_value;
376 376
                         break;
377 377
                 }
378 378
             }
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
      */
438 438
     protected function setSchemaReadOnly($readonly)
439 439
     {
440
-        if (! is_bool($readonly)) {
440
+        if ( ! is_bool($readonly)) {
441 441
             throw new InvalidArgumentException(
442 442
                 sprintf(
443 443
                     esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
      */
585 585
     private function validateSchemaType($type)
586 586
     {
587
-        if (! (is_string($type) || is_array($type))) {
587
+        if ( ! (is_string($type) || is_array($type))) {
588 588
             throw new InvalidArgumentException(
589 589
                 sprintf(
590 590
                     esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
             return;
615 615
         }
616 616
 
617
-        if (! isset($allowable_types[ $type ])) {
617
+        if ( ! isset($allowable_types[$type])) {
618 618
             throw new InvalidArgumentException(
619 619
                 sprintf(
620 620
                     esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
      */
634 634
     private function validateSchemaFormat($format)
635 635
     {
636
-        if (! is_string($format)) {
636
+        if ( ! is_string($format)) {
637 637
             throw new InvalidArgumentException(
638 638
                 sprintf(
639 639
                     esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
             )
657 657
         );
658 658
 
659
-        if (! isset($allowable_formats[ $format ])) {
659
+        if ( ! isset($allowable_formats[$format])) {
660 660
             throw new InvalidArgumentException(
661 661
                 sprintf(
662 662
                     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_Plain_Text_Field.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -2,14 +2,14 @@
 block discarded – undo
2 2
 
3 3
 class EE_Plain_Text_Field extends EE_Text_Field_Base
4 4
 {
5
-    /**
6
-     * removes all tags when setting
7
-     *
8
-     * @param string $value_inputted_for_field_on_model_object
9
-     * @return string
10
-     */
11
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
12
-    {
13
-        return wp_strip_all_tags(parent::prepare_for_set($value_inputted_for_field_on_model_object));
14
-    }
5
+	/**
6
+	 * removes all tags when setting
7
+	 *
8
+	 * @param string $value_inputted_for_field_on_model_object
9
+	 * @return string
10
+	 */
11
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
12
+	{
13
+		return wp_strip_all_tags(parent::prepare_for_set($value_inputted_for_field_on_model_object));
14
+	}
15 15
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Status_Field.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -3,114 +3,114 @@
 block discarded – undo
3 3
 class EE_WP_Post_Status_Field extends EE_Enum_Text_Field
4 4
 {
5 5
 
6
-    protected $_wp_post_stati;
6
+	protected $_wp_post_stati;
7 7
 
8 8
 
9
-    /**
10
-     * constructor
11
-     *
12
-     * @param string  $table_column       column on table
13
-     * @param string  $nicename           nice name for column(field)
14
-     * @param bool    $nullable           is this field nullable
15
-     * @param string  $default_value      default status
16
-     * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
-     *                                    they can be registered via this property.  The format of the array should be
18
-     *                                    as follows: array(
19
-     *                                    'status_reference' => array(
20
-     *                                    'label' => __('Status Reference Label', 'event_espresso')
21
-     *                                    'public' => true, //'Whether posts of this status should be shown on the
22
-     *                                    frontend of the site'
23
-     *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
-     *                                    excluded from wp searches'
25
-     *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
-     *                                    in queries for the admin "all" view in list table views.
27
-     *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
-     *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
-     *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
-     *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
-     *                                    on the admin screen( or you won't see your status count ).
32
-     *                                    )
33
-     *                                    )
34
-     * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
-     * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
-     *                                    set to true, it will be stored as an INT
37
-     */
38
-    public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
-    {
40
-        $this->_register_new_stati($new_stati);
41
-        $this->_set_allowed_enum_values();
42
-        parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
-    }
9
+	/**
10
+	 * constructor
11
+	 *
12
+	 * @param string  $table_column       column on table
13
+	 * @param string  $nicename           nice name for column(field)
14
+	 * @param bool    $nullable           is this field nullable
15
+	 * @param string  $default_value      default status
16
+	 * @param array   $new_stati          If additional stati are to be used other than the default WP statuses then
17
+	 *                                    they can be registered via this property.  The format of the array should be
18
+	 *                                    as follows: array(
19
+	 *                                    'status_reference' => array(
20
+	 *                                    'label' => __('Status Reference Label', 'event_espresso')
21
+	 *                                    'public' => true, //'Whether posts of this status should be shown on the
22
+	 *                                    frontend of the site'
23
+	 *                                    'exclude_from_search' => false, //'Whether posts of this status should be
24
+	 *                                    excluded from wp searches'
25
+	 *                                    'show_in_admin_all_list' => true, //whether posts of this status are included
26
+	 *                                    in queries for the admin "all" view in list table views.
27
+	 *                                    'show_in_admin_status_list' => true, //Show in the list of statuses with post
28
+	 *                                    counts at the top of the admin list tables (i.e. Status Reference(2) )
29
+	 *                                    'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>',
30
+	 *                                    'Status References <span class="count">(%s)</span>' ), //the text to display
31
+	 *                                    on the admin screen( or you won't see your status count ).
32
+	 *                                    )
33
+	 *                                    )
34
+	 * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info
35
+	 * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is
36
+	 *                                    set to true, it will be stored as an INT
37
+	 */
38
+	public function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array())
39
+	{
40
+		$this->_register_new_stati($new_stati);
41
+		$this->_set_allowed_enum_values();
42
+		parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values);
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * This registers any new statuses sent via the $new_stati array on construct
48
-     *
49
-     * @access protected
50
-     * @param  array $new_stati statuses
51
-     * @return void
52
-     */
53
-    protected function _register_new_stati($new_stati)
54
-    {
46
+	/**
47
+	 * This registers any new statuses sent via the $new_stati array on construct
48
+	 *
49
+	 * @access protected
50
+	 * @param  array $new_stati statuses
51
+	 * @return void
52
+	 */
53
+	protected function _register_new_stati($new_stati)
54
+	{
55 55
 
56
-        foreach ((array) $new_stati as $status_key => $status_args) {
57
-            $args = array(
58
-                'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
-                'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
-                'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
-                'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
-                'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
-                'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
-            );
65
-            register_post_status($status_key, $status_args);
66
-        }
67
-    }
56
+		foreach ((array) $new_stati as $status_key => $status_args) {
57
+			$args = array(
58
+				'label'                     => isset($status_args['label']) ? $status_args['label'] : $status_key,
59
+				'public'                    => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true,
60
+				'exclude_from_search'       => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false,
61
+				'show_in_admin_all_list'    => isset($status_args['show_in_admin_all_list']) && is_bool($status_args['show_in_admin_all_list']) ? $status_args['show_in_admin_all_list'] : false,
62
+				'show_in_admin_status_list' => isset($status_args['show_in_admin_status_list']) && is_bool($status_args['show_in_admin_status_list']) ? $status_args['show_in_admin_status_list'] : true,
63
+				'label_count'               => isset($status_args['label_count']) ? $status_args['label_count'] : '',
64
+			);
65
+			register_post_status($status_key, $status_args);
66
+		}
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * This sets the _allowed_enum_values property using the $wp_post_stati array
72
-     *
73
-     * @access protected
74
-     * @regurn void
75
-     */
76
-    protected function _set_allowed_enum_values()
77
-    {
78
-        // first let's get the post_statuses
79
-        global $wp_post_statuses;
80
-        $this->_wp_post_stati = $wp_post_statuses;
70
+	/**
71
+	 * This sets the _allowed_enum_values property using the $wp_post_stati array
72
+	 *
73
+	 * @access protected
74
+	 * @regurn void
75
+	 */
76
+	protected function _set_allowed_enum_values()
77
+	{
78
+		// first let's get the post_statuses
79
+		global $wp_post_statuses;
80
+		$this->_wp_post_stati = $wp_post_statuses;
81 81
 
82
-        foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
-        }
85
-    }
82
+		foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
+			$this->_allowed_enum_values[ $post_status ] = $args_object->label;
84
+		}
85
+	}
86 86
 
87
-    /**
88
-     * Before calling parent, first double-checks our list of acceptable post
89
-     * types is up-to-date
90
-     *
91
-     * @param string $value_inputted_for_field_on_model_object
92
-     * @return string
93
-     */
94
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
95
-    {
96
-        $this->_set_allowed_enum_values();
97
-        return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
-    }
87
+	/**
88
+	 * Before calling parent, first double-checks our list of acceptable post
89
+	 * types is up-to-date
90
+	 *
91
+	 * @param string $value_inputted_for_field_on_model_object
92
+	 * @return string
93
+	 */
94
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
95
+	{
96
+		$this->_set_allowed_enum_values();
97
+		return parent::prepare_for_set($value_inputted_for_field_on_model_object);
98
+	}
99 99
 
100 100
 
101 101
 
102
-    // helper methods for getting various $wp_post_statuses stuff.
102
+	// helper methods for getting various $wp_post_statuses stuff.
103 103
 
104
-    /**
105
-     * This just returns the status object for the given status
106
-     *
107
-     * @access public
108
-     * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
-     * @param  string $status What status object you want
110
-     * @return std_object         the status object or FALSE if it doesn't exist.
111
-     */
112
-    public function get_status_object($status)
113
-    {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
-    }
104
+	/**
105
+	 * This just returns the status object for the given status
106
+	 *
107
+	 * @access public
108
+	 * @see    wp_register_post_status in wp-includes/post.php for a list of properties of the status object
109
+	 * @param  string $status What status object you want
110
+	 * @return std_object         the status object or FALSE if it doesn't exist.
111
+	 */
112
+	public function get_status_object($status)
113
+	{
114
+		return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $this->_wp_post_stati = $wp_post_statuses;
81 81
 
82 82
         foreach ($this->_wp_post_stati as $post_status => $args_object) {
83
-            $this->_allowed_enum_values[ $post_status ] = $args_object->label;
83
+            $this->_allowed_enum_values[$post_status] = $args_object->label;
84 84
         }
85 85
     }
86 86
 
@@ -111,6 +111,6 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_status_object($status)
113 113
     {
114
-        return isset($this->_wp_post_stati[ $status ]) ? $this->_wp_post_stati[ $status ] : false;
114
+        return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false;
115 115
     }
116 116
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Trashed_Flag_Field.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,6 +2,6 @@
 block discarded – undo
2 2
 
3 3
 class EE_Trashed_Flag_Field extends EE_Boolean_Field
4 4
 {
5
-    // note: some client code simply checks if a field IS an EE_Trashed_Flag_Field
6
-    // ...otherwise, these fields are mostly the same as boolean fields
5
+	// note: some client code simply checks if a field IS an EE_Trashed_Flag_Field
6
+	// ...otherwise, these fields are mostly the same as boolean fields
7 7
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Integer_Field.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Integer_Field extends EE_Model_Field_Base
8 8
 {
9
-    /**
10
-     * @param string $table_column
11
-     * @param string $nicename
12
-     * @param bool   $nullable
13
-     * @param null   $default_value
14
-     */
15
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
16
-    {
17
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
18
-        $this->setSchemaType('integer');
19
-    }
9
+	/**
10
+	 * @param string $table_column
11
+	 * @param string $nicename
12
+	 * @param bool   $nullable
13
+	 * @param null   $default_value
14
+	 */
15
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
16
+	{
17
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
18
+		$this->setSchemaType('integer');
19
+	}
20 20
 
21 21
 
22
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
23
-    {
24
-        return intval($value_inputted_for_field_on_model_object);
25
-    }
22
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
23
+	{
24
+		return intval($value_inputted_for_field_on_model_object);
25
+	}
26 26
 
27
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
28
-    {
29
-        return intval($value_inputted_for_field_on_model_object);
30
-    }
27
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
28
+	{
29
+		return intval($value_inputted_for_field_on_model_object);
30
+	}
31 31
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Primary_Key_Field_Base.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -2,24 +2,24 @@
 block discarded – undo
2 2
 
3 3
 abstract class EE_Primary_Key_Field_Base extends EE_Field_With_Model_Name
4 4
 {
5
-    /**
6
-     * Overrides parent so it doesn't need to provide so many non-applicable fields
7
-     *
8
-     * @param string $table_column
9
-     * @param string $nicename
10
-     */
11
-    public function __construct($table_column, $nicename, $default)
12
-    {
13
-        parent::__construct($table_column, $nicename, false, $default, null);
14
-    }
5
+	/**
6
+	 * Overrides parent so it doesn't need to provide so many non-applicable fields
7
+	 *
8
+	 * @param string $table_column
9
+	 * @param string $nicename
10
+	 */
11
+	public function __construct($table_column, $nicename, $default)
12
+	{
13
+		parent::__construct($table_column, $nicename, false, $default, null);
14
+	}
15 15
 
16
-    /**
17
-     * @param $table_alias
18
-     * @param $name
19
-     */
20
-    public function _construct_finalize($table_alias, $name, $model_name)
21
-    {
22
-        $this->_model_name_pointed_to = $model_name;
23
-        parent::_construct_finalize($table_alias, $name, $model_name);
24
-    }
16
+	/**
17
+	 * @param $table_alias
18
+	 * @param $name
19
+	 */
20
+	public function _construct_finalize($table_alias, $name, $model_name)
21
+	{
22
+		$this->_model_name_pointed_to = $model_name;
23
+		parent::_construct_finalize($table_alias, $name, $model_name);
24
+	}
25 25
 }
Please login to merge, or discard this patch.