@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Text_Field_Base.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Text_Field_Base.php'); |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Only allows a select, small number of html tags: |
@@ -11,14 +11,14 @@ |
||
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | - * |
|
17 | - * @param string $value |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function prepare_for_set($value) |
|
21 | - { |
|
22 | - return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | - } |
|
14 | + /** |
|
15 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | + * |
|
17 | + * @param string $value |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function prepare_for_set($value) |
|
21 | + { |
|
22 | + return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | + } |
|
24 | 24 | } |
@@ -4,116 +4,116 @@ |
||
4 | 4 | class EE_WP_Post_Status_Field extends EE_Enum_Text_Field |
5 | 5 | { |
6 | 6 | |
7 | - protected $_wp_post_stati; |
|
8 | - |
|
9 | - |
|
10 | - /** |
|
11 | - * constructor |
|
12 | - * |
|
13 | - * @param string $table_column column on table |
|
14 | - * @param string $nicename nice name for column(field) |
|
15 | - * @param bool $nullable is this field nullable |
|
16 | - * @param string $default_value default status |
|
17 | - * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
18 | - * they can be registered via this property. The format of the array should be |
|
19 | - * as follows: array( |
|
20 | - * 'status_reference' => array( |
|
21 | - * 'label' => __('Status Reference Label', 'event_espresso') |
|
22 | - * 'public' => true, //'Whether posts of this status should be shown on the |
|
23 | - * frontend of the site' |
|
24 | - * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
25 | - * excluded from wp searches' |
|
26 | - * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
27 | - * in queries for the admin "all" view in list table views. |
|
28 | - * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
29 | - * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
30 | - * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
31 | - * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
32 | - * on the admin screen( or you won't see your status count ). |
|
33 | - * ) |
|
34 | - * ) |
|
35 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
36 | - * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
37 | - * set to true, it will be stored as an INT |
|
38 | - */ |
|
39 | - function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
40 | - { |
|
41 | - $this->_register_new_stati($new_stati); |
|
42 | - $this->_set_allowed_enum_values(); |
|
43 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This registers any new statuses sent via the $new_stati array on construct |
|
49 | - * |
|
50 | - * @access protected |
|
51 | - * @param array $new_stati statuses |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - protected function _register_new_stati($new_stati) |
|
55 | - { |
|
56 | - |
|
57 | - foreach ((array)$new_stati as $status_key => $status_args) { |
|
58 | - $args = array( |
|
59 | - 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
60 | - 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
61 | - 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
62 | - '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, |
|
63 | - '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, |
|
64 | - 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
65 | - ); |
|
66 | - register_post_status($status_key, $status_args); |
|
67 | - } |
|
68 | - |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
74 | - * |
|
75 | - * @access protected |
|
76 | - * @regurn void |
|
77 | - */ |
|
78 | - protected function _set_allowed_enum_values() |
|
79 | - { |
|
80 | - //first let's get the post_statuses |
|
81 | - global $wp_post_statuses; |
|
82 | - $this->_wp_post_stati = $wp_post_statuses; |
|
83 | - |
|
84 | - foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
85 | - $this->_allowed_enum_values[$post_status] = $args_object->label; |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Before calling parent, first double-checks our list of acceptable post |
|
92 | - * types is up-to-date |
|
93 | - * |
|
94 | - * @param string $value_inputted_for_field_on_model_object |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
98 | - { |
|
99 | - $this->_set_allowed_enum_values(); |
|
100 | - return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - //helper methods for getting various $wp_post_statuses stuff. |
|
106 | - |
|
107 | - /** |
|
108 | - * This just returns the status object for the given status |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
112 | - * @param string $status What status object you want |
|
113 | - * @return std_object the status object or FALSE if it doesn't exist. |
|
114 | - */ |
|
115 | - public function get_status_object($status) |
|
116 | - { |
|
117 | - return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false; |
|
118 | - } |
|
7 | + protected $_wp_post_stati; |
|
8 | + |
|
9 | + |
|
10 | + /** |
|
11 | + * constructor |
|
12 | + * |
|
13 | + * @param string $table_column column on table |
|
14 | + * @param string $nicename nice name for column(field) |
|
15 | + * @param bool $nullable is this field nullable |
|
16 | + * @param string $default_value default status |
|
17 | + * @param array $new_stati If additional stati are to be used other than the default WP statuses then |
|
18 | + * they can be registered via this property. The format of the array should be |
|
19 | + * as follows: array( |
|
20 | + * 'status_reference' => array( |
|
21 | + * 'label' => __('Status Reference Label', 'event_espresso') |
|
22 | + * 'public' => true, //'Whether posts of this status should be shown on the |
|
23 | + * frontend of the site' |
|
24 | + * 'exclude_from_search' => false, //'Whether posts of this status should be |
|
25 | + * excluded from wp searches' |
|
26 | + * 'show_in_admin_all_list' => true, //whether posts of this status are included |
|
27 | + * in queries for the admin "all" view in list table views. |
|
28 | + * 'show_in_admin_status_list' => true, //Show in the list of statuses with post |
|
29 | + * counts at the top of the admin list tables (i.e. Status Reference(2) ) |
|
30 | + * 'label_count' => _n_noop( 'Status Reference <span class="count">(%s)</span>', |
|
31 | + * 'Status References <span class="count">(%s)</span>' ), //the text to display |
|
32 | + * on the admin screen( or you won't see your status count ). |
|
33 | + * ) |
|
34 | + * ) |
|
35 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
36 | + * @param boolean $store_in_db_as_int By default, enums are stored as STRINGS in the DB. However, if this var is |
|
37 | + * set to true, it will be stored as an INT |
|
38 | + */ |
|
39 | + function __construct($table_column, $nicename, $nullable, $default_value, $new_stati = array()) |
|
40 | + { |
|
41 | + $this->_register_new_stati($new_stati); |
|
42 | + $this->_set_allowed_enum_values(); |
|
43 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $this->_allowed_enum_values); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This registers any new statuses sent via the $new_stati array on construct |
|
49 | + * |
|
50 | + * @access protected |
|
51 | + * @param array $new_stati statuses |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + protected function _register_new_stati($new_stati) |
|
55 | + { |
|
56 | + |
|
57 | + foreach ((array)$new_stati as $status_key => $status_args) { |
|
58 | + $args = array( |
|
59 | + 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
|
60 | + 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
|
61 | + 'exclude_from_search' => isset($status_args['exclude_from_search']) && is_bool($status_args['exclude_from_search']) ? $status_args['exclude_from_search'] : false, |
|
62 | + '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, |
|
63 | + '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, |
|
64 | + 'label_count' => isset($status_args['label_count']) ? $status_args['label_count'] : '', |
|
65 | + ); |
|
66 | + register_post_status($status_key, $status_args); |
|
67 | + } |
|
68 | + |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * This sets the _allowed_enum_values property using the $wp_post_stati array |
|
74 | + * |
|
75 | + * @access protected |
|
76 | + * @regurn void |
|
77 | + */ |
|
78 | + protected function _set_allowed_enum_values() |
|
79 | + { |
|
80 | + //first let's get the post_statuses |
|
81 | + global $wp_post_statuses; |
|
82 | + $this->_wp_post_stati = $wp_post_statuses; |
|
83 | + |
|
84 | + foreach ($this->_wp_post_stati as $post_status => $args_object) { |
|
85 | + $this->_allowed_enum_values[$post_status] = $args_object->label; |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Before calling parent, first double-checks our list of acceptable post |
|
92 | + * types is up-to-date |
|
93 | + * |
|
94 | + * @param string $value_inputted_for_field_on_model_object |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
98 | + { |
|
99 | + $this->_set_allowed_enum_values(); |
|
100 | + return parent::prepare_for_set($value_inputted_for_field_on_model_object); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + //helper methods for getting various $wp_post_statuses stuff. |
|
106 | + |
|
107 | + /** |
|
108 | + * This just returns the status object for the given status |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @see wp_register_post_status in wp-includes/post.php for a list of properties of the status object |
|
112 | + * @param string $status What status object you want |
|
113 | + * @return std_object the status object or FALSE if it doesn't exist. |
|
114 | + */ |
|
115 | + public function get_status_object($status) |
|
116 | + { |
|
117 | + return isset($this->_wp_post_stati[$status]) ? $this->_wp_post_stati[$status] : false; |
|
118 | + } |
|
119 | 119 | } |
120 | 120 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Enum_Text_Field.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Enum_Text_Field.php'); |
|
3 | 3 | |
4 | 4 | class EE_WP_Post_Status_Field extends EE_Enum_Text_Field |
5 | 5 | { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | protected function _register_new_stati($new_stati) |
55 | 55 | { |
56 | 56 | |
57 | - foreach ((array)$new_stati as $status_key => $status_args) { |
|
57 | + foreach ((array) $new_stati as $status_key => $status_args) { |
|
58 | 58 | $args = array( |
59 | 59 | 'label' => isset($status_args['label']) ? $status_args['label'] : $status_key, |
60 | 60 | 'public' => isset($status_args['public']) && is_bool($status_args['public']) ? $status_args['public'] : true, |
@@ -3,15 +3,15 @@ |
||
3 | 3 | |
4 | 4 | class EE_Slug_Field extends EE_Text_Field_Base |
5 | 5 | { |
6 | - /** |
|
7 | - * ensures string is usable in URLs |
|
8 | - * |
|
9 | - * @param string $value_inputted_for_field_on_model_object |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
13 | - { |
|
14 | - //reminder: function prepares for use in URLs, not making human-readable. |
|
15 | - return sanitize_title($value_inputted_for_field_on_model_object); |
|
16 | - } |
|
6 | + /** |
|
7 | + * ensures string is usable in URLs |
|
8 | + * |
|
9 | + * @param string $value_inputted_for_field_on_model_object |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
13 | + { |
|
14 | + //reminder: function prepares for use in URLs, not making human-readable. |
|
15 | + return sanitize_title($value_inputted_for_field_on_model_object); |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Text_Field_Base.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Text_Field_Base.php'); |
|
3 | 3 | |
4 | 4 | class EE_Slug_Field extends EE_Text_Field_Base |
5 | 5 | { |
@@ -8,36 +8,36 @@ |
||
8 | 8 | |
9 | 9 | class EE_Maybe_Serialized_Text_Field extends EE_Serialized_Text_Field |
10 | 10 | { |
11 | - /** |
|
12 | - * Value could be an array or a string. If its an array, serialize it. Otherwise, leave it as a string |
|
13 | - * |
|
14 | - * @param array|string $value_of_field_on_model_object |
|
15 | - * @return string (possibly serialized) |
|
16 | - */ |
|
17 | - function prepare_for_use_in_db($value_of_field_on_model_object) |
|
18 | - { |
|
19 | - if (is_array($value_of_field_on_model_object)) { |
|
20 | - return parent::prepare_for_use_in_db($value_of_field_on_model_object); |
|
21 | - } else { |
|
22 | - return $value_of_field_on_model_object; |
|
23 | - } |
|
24 | - } |
|
11 | + /** |
|
12 | + * Value could be an array or a string. If its an array, serialize it. Otherwise, leave it as a string |
|
13 | + * |
|
14 | + * @param array|string $value_of_field_on_model_object |
|
15 | + * @return string (possibly serialized) |
|
16 | + */ |
|
17 | + function prepare_for_use_in_db($value_of_field_on_model_object) |
|
18 | + { |
|
19 | + if (is_array($value_of_field_on_model_object)) { |
|
20 | + return parent::prepare_for_use_in_db($value_of_field_on_model_object); |
|
21 | + } else { |
|
22 | + return $value_of_field_on_model_object; |
|
23 | + } |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Formats the array (or string) according to $schema. Right now, just implode with commas |
|
28 | - * |
|
29 | - * @param type $value_on_field_to_be_outputted |
|
30 | - * @param type $schema |
|
31 | - * @return strubg |
|
32 | - */ |
|
33 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
34 | - { |
|
35 | - $pretty_value = null; |
|
36 | - if (is_array($value_on_field_to_be_outputted)) { |
|
37 | - $pretty_value = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
38 | - } else { |
|
39 | - $pretty_value = $value_on_field_to_be_outputted; |
|
40 | - } |
|
41 | - return $pretty_value; |
|
42 | - } |
|
26 | + /** |
|
27 | + * Formats the array (or string) according to $schema. Right now, just implode with commas |
|
28 | + * |
|
29 | + * @param type $value_on_field_to_be_outputted |
|
30 | + * @param type $schema |
|
31 | + * @return strubg |
|
32 | + */ |
|
33 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
34 | + { |
|
35 | + $pretty_value = null; |
|
36 | + if (is_array($value_on_field_to_be_outputted)) { |
|
37 | + $pretty_value = parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
38 | + } else { |
|
39 | + $pretty_value = $value_on_field_to_be_outputted; |
|
40 | + } |
|
41 | + return $pretty_value; |
|
42 | + } |
|
43 | 43 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | /** |
5 | 5 | * For a db text column, which can either be an array in PHP code or a string. |
6 | 6 | */ |
7 | -require_once(EE_MODELS . 'fields/EE_Text_Field_Base.php'); |
|
7 | +require_once(EE_MODELS.'fields/EE_Text_Field_Base.php'); |
|
8 | 8 | |
9 | 9 | class EE_Maybe_Serialized_Text_Field extends EE_Serialized_Text_Field |
10 | 10 | { |
@@ -5,12 +5,12 @@ |
||
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 | - 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 | + function __construct($post_type) |
|
13 | + { |
|
14 | + parent::__construct('post_type', __("Post Type", 'event_espresso'), false, $post_type); |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php'); |
|
3 | 3 | |
4 | 4 | class EE_DB_Only_Text_Field extends EE_DB_Only_Field_Base |
5 | 5 | { |
@@ -8,83 +8,83 @@ |
||
8 | 8 | */ |
9 | 9 | abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base |
10 | 10 | { |
11 | - /** |
|
12 | - * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | - * it can actually be an array of models |
|
14 | - * |
|
15 | - * @var string or array |
|
16 | - */ |
|
17 | - protected $_model_name_pointed_to; |
|
11 | + /** |
|
12 | + * Usually the name of a single model. However, as in the case for custom post types, |
|
13 | + * it can actually be an array of models |
|
14 | + * |
|
15 | + * @var string or array |
|
16 | + */ |
|
17 | + protected $_model_name_pointed_to; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
24 | - * dbe a string |
|
25 | - * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
26 | - * "EEM_" |
|
27 | - */ |
|
28 | - function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
29 | - { |
|
30 | - $this->_model_name_pointed_to = $model_name; |
|
31 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | - } |
|
19 | + /** |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
24 | + * dbe a string |
|
25 | + * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
26 | + * "EEM_" |
|
27 | + */ |
|
28 | + function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
29 | + { |
|
30 | + $this->_model_name_pointed_to = $model_name; |
|
31 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Returns the name of the model(s) pointed to |
|
36 | - * |
|
37 | - * @deprecated since version 4.6.7 |
|
38 | - * @return mixed string or array of strings |
|
39 | - */ |
|
40 | - function get_model_name_pointed_to() |
|
41 | - { |
|
42 | - EE_Error::doing_it_wrong('get_model_name_pointed_to', |
|
43 | - __('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
44 | - 'event_espresso'), '4.6.7'); |
|
45 | - return $this->_model_name_pointed_to; |
|
46 | - } |
|
34 | + /** |
|
35 | + * Returns the name of the model(s) pointed to |
|
36 | + * |
|
37 | + * @deprecated since version 4.6.7 |
|
38 | + * @return mixed string or array of strings |
|
39 | + */ |
|
40 | + function get_model_name_pointed_to() |
|
41 | + { |
|
42 | + EE_Error::doing_it_wrong('get_model_name_pointed_to', |
|
43 | + __('This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array', |
|
44 | + 'event_espresso'), '4.6.7'); |
|
45 | + return $this->_model_name_pointed_to; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Gets the model names pointed to by this field, always as an array |
|
50 | - * (even if there's only one) |
|
51 | - * |
|
52 | - * @return array of model names pointed to by this field |
|
53 | - */ |
|
54 | - function get_model_names_pointed_to() |
|
55 | - { |
|
56 | - if (is_array($this->_model_name_pointed_to)) { |
|
57 | - return $this->_model_name_pointed_to; |
|
58 | - } else { |
|
59 | - return array($this->_model_name_pointed_to); |
|
60 | - } |
|
61 | - } |
|
48 | + /** |
|
49 | + * Gets the model names pointed to by this field, always as an array |
|
50 | + * (even if there's only one) |
|
51 | + * |
|
52 | + * @return array of model names pointed to by this field |
|
53 | + */ |
|
54 | + function get_model_names_pointed_to() |
|
55 | + { |
|
56 | + if (is_array($this->_model_name_pointed_to)) { |
|
57 | + return $this->_model_name_pointed_to; |
|
58 | + } else { |
|
59 | + return array($this->_model_name_pointed_to); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Returns the model's classname (eg EE_Event instead of just Event) |
|
65 | - * |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - function get_model_class_names_pointed_to() |
|
69 | - { |
|
70 | - $model_names = array(); |
|
71 | - if (is_array($this->_model_name_pointed_to)) { |
|
72 | - foreach ($this->_model_name_pointed_to as $model_name) { |
|
73 | - $model_names[] = "EE_" . $model_name; |
|
74 | - } |
|
75 | - } else { |
|
76 | - $model_names = array("EE_" . $this->_model_name_pointed_to); |
|
77 | - } |
|
78 | - return $model_names; |
|
79 | - } |
|
63 | + /** |
|
64 | + * Returns the model's classname (eg EE_Event instead of just Event) |
|
65 | + * |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + function get_model_class_names_pointed_to() |
|
69 | + { |
|
70 | + $model_names = array(); |
|
71 | + if (is_array($this->_model_name_pointed_to)) { |
|
72 | + foreach ($this->_model_name_pointed_to as $model_name) { |
|
73 | + $model_names[] = "EE_" . $model_name; |
|
74 | + } |
|
75 | + } else { |
|
76 | + $model_names = array("EE_" . $this->_model_name_pointed_to); |
|
77 | + } |
|
78 | + return $model_names; |
|
79 | + } |
|
80 | 80 | |
81 | - function is_model_obj_of_type_pointed_to($model_obj_or_ID) |
|
82 | - { |
|
83 | - foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
84 | - if ($model_obj_or_ID instanceof $model_obj_classname) { |
|
85 | - return true; |
|
86 | - } |
|
87 | - } |
|
88 | - return false; |
|
89 | - } |
|
81 | + function is_model_obj_of_type_pointed_to($model_obj_or_ID) |
|
82 | + { |
|
83 | + foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) { |
|
84 | + if ($model_obj_or_ID instanceof $model_obj_classname) { |
|
85 | + return true; |
|
86 | + } |
|
87 | + } |
|
88 | + return false; |
|
89 | + } |
|
90 | 90 | } |
@@ -70,10 +70,10 @@ |
||
70 | 70 | $model_names = array(); |
71 | 71 | if (is_array($this->_model_name_pointed_to)) { |
72 | 72 | foreach ($this->_model_name_pointed_to as $model_name) { |
73 | - $model_names[] = "EE_" . $model_name; |
|
73 | + $model_names[] = "EE_".$model_name; |
|
74 | 74 | } |
75 | 75 | } else { |
76 | - $model_names = array("EE_" . $this->_model_name_pointed_to); |
|
76 | + $model_names = array("EE_".$this->_model_name_pointed_to); |
|
77 | 77 | } |
78 | 78 | return $model_names; |
79 | 79 | } |
@@ -3,14 +3,14 @@ |
||
3 | 3 | |
4 | 4 | class EE_Plain_Text_Field extends EE_Text_Field_Base |
5 | 5 | { |
6 | - /** |
|
7 | - * removes all tags when setting |
|
8 | - * |
|
9 | - * @param string $value_inputted_for_field_on_model_object |
|
10 | - * @return string |
|
11 | - */ |
|
12 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
13 | - { |
|
14 | - return wp_strip_all_tags(parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
15 | - } |
|
6 | + /** |
|
7 | + * removes all tags when setting |
|
8 | + * |
|
9 | + * @param string $value_inputted_for_field_on_model_object |
|
10 | + * @return string |
|
11 | + */ |
|
12 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
13 | + { |
|
14 | + return wp_strip_all_tags(parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Text_Field_Base.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Text_Field_Base.php'); |
|
3 | 3 | |
4 | 4 | class EE_Plain_Text_Field extends EE_Text_Field_Base |
5 | 5 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'relations/EE_Model_Relation_Base.php'); |
|
2 | +require_once(EE_MODELS.'relations/EE_Model_Relation_Base.php'); |
|
3 | 3 | |
4 | 4 | |
5 | 5 | /** |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
47 | 47 | $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
48 | 48 | $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
49 | - $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
49 | + $this->get_this_model()->get_this_model_name()).$this_table_pk_field->get_table_alias(); |
|
50 | 50 | $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
51 | - $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
51 | + $this->get_other_model()->get_this_model_name()).$other_table_fk_field->get_table_alias(); |
|
52 | 52 | $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
53 | 53 | |
54 | 54 | return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
55 | - $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
55 | + $this_table_pk_field->get_table_column()).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 |
@@ -13,93 +13,93 @@ |
||
13 | 13 | class EE_Has_Many_Relation extends EE_Model_Relation_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
18 | - * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
19 | - * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
20 | - * related models across the relation, and add-and-remove the relationships. |
|
21 | - * |
|
22 | - * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
23 | - * related models across this relation, block (prevent and add an |
|
24 | - * error) the deletion of this model |
|
25 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
26 | - * default |
|
27 | - */ |
|
28 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
29 | - { |
|
30 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
31 | - } |
|
16 | + /** |
|
17 | + * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
18 | + * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
19 | + * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
20 | + * related models across the relation, and add-and-remove the relationships. |
|
21 | + * |
|
22 | + * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
23 | + * related models across this relation, block (prevent and add an |
|
24 | + * error) the deletion of this model |
|
25 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
26 | + * default |
|
27 | + */ |
|
28 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
29 | + { |
|
30 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Gets the SQL string for performing the join between this model and the other model. |
|
36 | - * |
|
37 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
38 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
39 | - * other_model_primary_table.fk" etc |
|
40 | - * @throws \EE_Error |
|
41 | - */ |
|
42 | - public function get_join_statement($model_relation_chain) |
|
43 | - { |
|
44 | - //create the sql string like |
|
45 | - // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
46 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
47 | - $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
48 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
49 | - $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
50 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
51 | - $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
52 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
34 | + /** |
|
35 | + * Gets the SQL string for performing the join between this model and the other model. |
|
36 | + * |
|
37 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
38 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
39 | + * other_model_primary_table.fk" etc |
|
40 | + * @throws \EE_Error |
|
41 | + */ |
|
42 | + public function get_join_statement($model_relation_chain) |
|
43 | + { |
|
44 | + //create the sql string like |
|
45 | + // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
46 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
47 | + $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
48 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
49 | + $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
50 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
51 | + $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
52 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
53 | 53 | |
54 | - return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
55 | - $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
56 | - } |
|
54 | + return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
55 | + $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
61 | - * you like. |
|
62 | - * |
|
63 | - * @param EE_Base_Class|int $this_obj_or_id |
|
64 | - * @param EE_Base_Class|int $other_obj_or_id |
|
65 | - * @param array $extra_join_model_fields_n_values |
|
66 | - * @return \EE_Base_Class |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
70 | - { |
|
71 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
72 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
59 | + /** |
|
60 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
61 | + * you like. |
|
62 | + * |
|
63 | + * @param EE_Base_Class|int $this_obj_or_id |
|
64 | + * @param EE_Base_Class|int $other_obj_or_id |
|
65 | + * @param array $extra_join_model_fields_n_values |
|
66 | + * @return \EE_Base_Class |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
70 | + { |
|
71 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
72 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
73 | 73 | |
74 | - //find the field on the other model which is a foreign key to this model |
|
75 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
76 | - if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
77 | - //set that field on the other model to this model's ID |
|
78 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
79 | - $other_model_obj->save(); |
|
80 | - } |
|
81 | - return $other_model_obj; |
|
82 | - } |
|
74 | + //find the field on the other model which is a foreign key to this model |
|
75 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
76 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
77 | + //set that field on the other model to this model's ID |
|
78 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
79 | + $other_model_obj->save(); |
|
80 | + } |
|
81 | + return $other_model_obj; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
87 | - * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
88 | - * |
|
89 | - * @param EE_Base_Class|int $this_obj_or_id |
|
90 | - * @param EE_Base_Class|int $other_obj_or_id |
|
91 | - * @param array $where_query |
|
92 | - * @return \EE_Base_Class |
|
93 | - * @throws \EE_Error |
|
94 | - */ |
|
95 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
96 | - { |
|
97 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
98 | - //find the field on the other model which is a foreign key to this model |
|
99 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
100 | - //set that field on the other model to this model's ID |
|
101 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
102 | - $other_model_obj->save(); |
|
103 | - return $other_model_obj; |
|
104 | - } |
|
85 | + /** |
|
86 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
87 | + * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
88 | + * |
|
89 | + * @param EE_Base_Class|int $this_obj_or_id |
|
90 | + * @param EE_Base_Class|int $other_obj_or_id |
|
91 | + * @param array $where_query |
|
92 | + * @return \EE_Base_Class |
|
93 | + * @throws \EE_Error |
|
94 | + */ |
|
95 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
96 | + { |
|
97 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
98 | + //find the field on the other model which is a foreign key to this model |
|
99 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
100 | + //set that field on the other model to this model's ID |
|
101 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
102 | + $other_model_obj->save(); |
|
103 | + return $other_model_obj; |
|
104 | + } |
|
105 | 105 | } |