@@ -1,5 +1,5 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Foreign_Key_Field_Base.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Foreign_Key_Field_Base.php'); |
|
3 | 3 | |
4 | 4 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
5 | 5 | { |
@@ -3,32 +3,32 @@ |
||
3 | 3 | |
4 | 4 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
5 | 5 | { |
6 | - function get_wpdb_data_type() |
|
7 | - { |
|
8 | - return '%d'; |
|
9 | - } |
|
6 | + function get_wpdb_data_type() |
|
7 | + { |
|
8 | + return '%d'; |
|
9 | + } |
|
10 | 10 | |
11 | - /** |
|
12 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
13 | - * @return int |
|
14 | - */ |
|
15 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
16 | - { |
|
17 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
18 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
19 | - } |
|
20 | - return absint($value_inputted_for_field_on_model_object); |
|
21 | - } |
|
11 | + /** |
|
12 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
13 | + * @return int |
|
14 | + */ |
|
15 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
16 | + { |
|
17 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
18 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
19 | + } |
|
20 | + return absint($value_inputted_for_field_on_model_object); |
|
21 | + } |
|
22 | 22 | |
23 | - function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
24 | - { |
|
25 | - return intval($value_found_in_db_for_model_object); |
|
26 | - } |
|
23 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
24 | + { |
|
25 | + return intval($value_found_in_db_for_model_object); |
|
26 | + } |
|
27 | 27 | |
28 | - public function get_schema() |
|
29 | - { |
|
30 | - $schema = parent::get_schema(); |
|
31 | - $schema['type'] = 'integer'; |
|
32 | - return $schema; |
|
33 | - } |
|
28 | + public function get_schema() |
|
29 | + { |
|
30 | + $schema = parent::get_schema(); |
|
31 | + $schema['type'] = 'integer'; |
|
32 | + return $schema; |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -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 |
@@ -3,8 +3,8 @@ |
||
3 | 3 | |
4 | 4 | class EE_DB_Only_Text_Field extends EE_DB_Only_Field_Base |
5 | 5 | { |
6 | - function get_wpdb_data_type() |
|
7 | - { |
|
8 | - return '%s'; |
|
9 | - } |
|
6 | + function get_wpdb_data_type() |
|
7 | + { |
|
8 | + return '%s'; |
|
9 | + } |
|
10 | 10 | } |
11 | 11 | \ No newline at end of file |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php'); |
|
3 | +require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php'); |
|
4 | 4 | |
5 | 5 | class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base |
6 | 6 | { |
@@ -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 @@ |
||
1 | 1 | <?php |
2 | -require_once(EE_MODELS . 'fields/EE_Integer_Field.php'); |
|
2 | +require_once(EE_MODELS.'fields/EE_Integer_Field.php'); |
|
3 | 3 | |
4 | 4 | class EE_Boolean_Field extends EE_Integer_Field |
5 | 5 | { |
@@ -3,47 +3,47 @@ |
||
3 | 3 | |
4 | 4 | class EE_Boolean_Field extends EE_Integer_Field |
5 | 5 | { |
6 | - function prepare_for_set($value_inputted_for_field_on_model_object) |
|
7 | - { |
|
8 | - if ($value_inputted_for_field_on_model_object) { |
|
9 | - return true; |
|
10 | - } else { |
|
11 | - return false; |
|
12 | - } |
|
13 | - } |
|
6 | + function prepare_for_set($value_inputted_for_field_on_model_object) |
|
7 | + { |
|
8 | + if ($value_inputted_for_field_on_model_object) { |
|
9 | + return true; |
|
10 | + } else { |
|
11 | + return false; |
|
12 | + } |
|
13 | + } |
|
14 | 14 | |
15 | - /** |
|
16 | - * Make sure we're returning booleans |
|
17 | - * |
|
18 | - * @param string $value_inputted_for_field_on_model_object |
|
19 | - * @return boolean |
|
20 | - */ |
|
21 | - function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
22 | - { |
|
23 | - return intval($value_inputted_for_field_on_model_object) ? true : false; |
|
24 | - } |
|
15 | + /** |
|
16 | + * Make sure we're returning booleans |
|
17 | + * |
|
18 | + * @param string $value_inputted_for_field_on_model_object |
|
19 | + * @return boolean |
|
20 | + */ |
|
21 | + function prepare_for_set_from_db($value_inputted_for_field_on_model_object) |
|
22 | + { |
|
23 | + return intval($value_inputted_for_field_on_model_object) ? true : false; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Gets a nice Yes/No value for this field |
|
28 | - * |
|
29 | - * @param boolean $value_on_field_to_be_outputted |
|
30 | - * @return string Yes or No |
|
31 | - */ |
|
32 | - function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
33 | - { |
|
34 | - return apply_filters( |
|
35 | - 'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return', |
|
36 | - $value_on_field_to_be_outputted ? __('Yes', 'event_espresso') : __('No', 'event_espresso'), |
|
37 | - $value_on_field_to_be_outputted |
|
38 | - ); |
|
39 | - } |
|
26 | + /** |
|
27 | + * Gets a nice Yes/No value for this field |
|
28 | + * |
|
29 | + * @param boolean $value_on_field_to_be_outputted |
|
30 | + * @return string Yes or No |
|
31 | + */ |
|
32 | + function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
33 | + { |
|
34 | + return apply_filters( |
|
35 | + 'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return', |
|
36 | + $value_on_field_to_be_outputted ? __('Yes', 'event_espresso') : __('No', 'event_espresso'), |
|
37 | + $value_on_field_to_be_outputted |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - public function get_schema() |
|
43 | - { |
|
44 | - $schema = parent::get_schema(); |
|
45 | - $schema['type'] = 'boolean'; |
|
46 | - return $schema; |
|
47 | - } |
|
42 | + public function get_schema() |
|
43 | + { |
|
44 | + $schema = parent::get_schema(); |
|
45 | + $schema['type'] = 'boolean'; |
|
46 | + return $schema; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php'); |
|
3 | +require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php'); |
|
4 | 4 | |
5 | 5 | class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base |
6 | 6 | { |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base |
6 | 6 | { |
7 | - function get_wpdb_data_type() |
|
8 | - { |
|
9 | - return '%d'; |
|
10 | - } |
|
7 | + function get_wpdb_data_type() |
|
8 | + { |
|
9 | + return '%d'; |
|
10 | + } |
|
11 | 11 | |
12 | - public function get_schema() |
|
13 | - { |
|
14 | - $schema = parent::get_schema(); |
|
15 | - $schema['type'] = 'integer'; |
|
16 | - return $schema; |
|
17 | - } |
|
12 | + public function get_schema() |
|
13 | + { |
|
14 | + $schema = parent::get_schema(); |
|
15 | + $schema['type'] = 'integer'; |
|
16 | + return $schema; |
|
17 | + } |
|
18 | 18 | } |
19 | 19 | \ No newline at end of file |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param $other_table |
136 | - * @param $other_table_alias |
|
136 | + * @param string $other_table_alias |
|
137 | 137 | * @param $other_table_column |
138 | - * @param $this_table_alias |
|
138 | + * @param string $this_table_alias |
|
139 | 139 | * @param $this_table_join_column |
140 | 140 | * @param string $extra_join_sql |
141 | 141 | * @return string |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Alters the $query_params to disable default where conditions, unless otherwise specified |
190 | 190 | * |
191 | 191 | * @param string $query_params |
192 | - * @return array |
|
192 | + * @return string |
|
193 | 193 | */ |
194 | 194 | protected function _disable_default_where_conditions_on_query_param($query_params) |
195 | 195 | { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
207 | 207 | * model objects will only be soft-deleted. |
208 | 208 | * |
209 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
209 | + * @param EE_Base_Class|null $model_object_or_id |
|
210 | 210 | * @param array $query_params |
211 | 211 | * @return int of how many related models got deleted |
212 | 212 | * @throws \EE_Error |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
238 | 238 | * model objects will only be soft-deleted. |
239 | 239 | * |
240 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
240 | + * @param EE_Base_Class|null $model_object_or_id |
|
241 | 241 | * @param array $query_params |
242 | 242 | * @return int of how many related models got deleted |
243 | 243 | * @throws \EE_Error |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $this_table_join_column, |
149 | 149 | $extra_join_sql = '' |
150 | 150 | ) { |
151 | - return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
151 | + return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function _disable_default_where_conditions_on_query_param($query_params) |
195 | 195 | { |
196 | - if (! isset($query_params['default_where_conditions'])) { |
|
196 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
197 | 197 | $query_params['default_where_conditions'] = 'none'; |
198 | 198 | } |
199 | 199 | return $query_params; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
222 | 222 | $model_object_or_id); |
223 | 223 | /* @var $model_object_or_id EE_Base_Class */ |
224 | - if (! $delete_is_blocked) { |
|
224 | + if ( ! $delete_is_blocked) { |
|
225 | 225 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
226 | 226 | $related_model_object->delete(); |
227 | 227 | $deleted_count++; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
256 | 256 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
257 | 257 | $deleted_count++; |
258 | - if (! $delete_is_blocked) { |
|
258 | + if ( ! $delete_is_blocked) { |
|
259 | 259 | $related_model_object->delete_permanently(); |
260 | 260 | } else { |
261 | 261 | //delete is blocked |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | } |
265 | 265 | } else { |
266 | 266 | //its not a soft-deletable thing anyways. do the normal logic. |
267 | - if (! $delete_is_blocked) { |
|
267 | + if ( ! $delete_is_blocked) { |
|
268 | 268 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
269 | 269 | $related_model_object->delete(); |
270 | 270 | $deleted_count++; |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | if ($model_object_or_id instanceof EE_Base_Class) { |
289 | 289 | $model_object_id = $model_object_or_id->ID(); |
290 | 290 | } |
291 | - if (! $model_object_id) { |
|
291 | + if ( ! $model_object_id) { |
|
292 | 292 | throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
293 | 293 | "event_espresso"), $this->get_other_model()->get_this_model_name(), |
294 | 294 | $this->get_this_model()->get_this_model_name())); |
@@ -14,402 +14,402 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EE_Model_Relation_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
19 | - * |
|
20 | - * @var string eg Event, Question_Group, Registration |
|
21 | - */ |
|
22 | - private $_this_model_name; |
|
23 | - /** |
|
24 | - * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
25 | - * |
|
26 | - * @var string eg Event, Question_Group, Registration |
|
27 | - */ |
|
28 | - private $_other_model_name; |
|
29 | - |
|
30 | - /** |
|
31 | - * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
32 | - * initiating model. |
|
33 | - * |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $_timezone; |
|
37 | - |
|
38 | - /** |
|
39 | - * If you try to delete "this_model", and there are related "other_models", |
|
40 | - * and this isn't null, then abandon the deletion and add this warning. |
|
41 | - * This effectively makes it impossible to delete "this_model" while there are |
|
42 | - * related "other_models" along this relation. |
|
43 | - * |
|
44 | - * @var string (internationalized) |
|
45 | - */ |
|
46 | - protected $_blocking_delete_error_message; |
|
47 | - |
|
48 | - protected $_blocking_delete = false; |
|
49 | - |
|
50 | - /** |
|
51 | - * Object representing the relationship between two models. This knows how to join the models, |
|
52 | - * get related models across the relation, and add-and-remove the relationships. |
|
53 | - * |
|
54 | - * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
55 | - * and add an error) the deletion of this model |
|
56 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
57 | - * default |
|
58 | - */ |
|
59 | - public function __construct($block_deletes, $blocking_delete_error_message) |
|
60 | - { |
|
61 | - $this->_blocking_delete = $block_deletes; |
|
62 | - $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @param $this_model_name |
|
68 | - * @param $other_model_name |
|
69 | - * @throws EE_Error |
|
70 | - */ |
|
71 | - public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
72 | - { |
|
73 | - $this->_this_model_name = $this_model_name; |
|
74 | - $this->_other_model_name = $other_model_name; |
|
75 | - if (is_string($this->_blocking_delete)) { |
|
76 | - throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
77 | - "event_espresso"), |
|
78 | - get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Gets the model where this relation is defined. |
|
85 | - * |
|
86 | - * @return EEM_Base |
|
87 | - */ |
|
88 | - public function get_this_model() |
|
89 | - { |
|
90 | - return $this->_get_model($this->_this_model_name); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Gets the model which this relation establishes the relation TO (ie, |
|
96 | - * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
97 | - * |
|
98 | - * @return EEM_Base |
|
99 | - */ |
|
100 | - public function get_other_model() |
|
101 | - { |
|
102 | - return $this->_get_model($this->_other_model_name); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Internally used by get_this_model() and get_other_model() |
|
108 | - * |
|
109 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
110 | - * @return EEM_Base |
|
111 | - */ |
|
112 | - protected function _get_model($model_name) |
|
113 | - { |
|
114 | - $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
115 | - $modelInstance->set_timezone($this->_timezone); |
|
116 | - return $modelInstance; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
122 | - * timezone set correctly. |
|
123 | - * |
|
124 | - * @param string $timezone timezone to set. |
|
125 | - */ |
|
126 | - public function set_timezone($timezone) |
|
127 | - { |
|
128 | - if ($timezone !== null) { |
|
129 | - $this->_timezone = $timezone; |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param $other_table |
|
136 | - * @param $other_table_alias |
|
137 | - * @param $other_table_column |
|
138 | - * @param $this_table_alias |
|
139 | - * @param $this_table_join_column |
|
140 | - * @param string $extra_join_sql |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - protected function _left_join( |
|
144 | - $other_table, |
|
145 | - $other_table_alias, |
|
146 | - $other_table_column, |
|
147 | - $this_table_alias, |
|
148 | - $this_table_join_column, |
|
149 | - $extra_join_sql = '' |
|
150 | - ) { |
|
151 | - return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Gets all the model objects of type of other model related to $model_object, |
|
157 | - * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
158 | - * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
159 | - * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
160 | - * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
161 | - * |
|
162 | - * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
163 | - * @param array $query_params like EEM_Base::get_all's $query_params |
|
164 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
165 | - * @return EE_Base_Class[] |
|
166 | - * @throws \EE_Error |
|
167 | - */ |
|
168 | - public function get_all_related( |
|
169 | - $model_object_or_id, |
|
170 | - $query_params = array(), |
|
171 | - $values_already_prepared_by_model_object = false |
|
172 | - ) { |
|
173 | - if ($values_already_prepared_by_model_object !== false) { |
|
174 | - EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', |
|
175 | - __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
176 | - '4.8.1'); |
|
177 | - } |
|
178 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
179 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
180 | - . "." |
|
181 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
182 | - $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
183 | - $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
184 | - return $this->get_other_model()->get_all($query_params); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
190 | - * |
|
191 | - * @param string $query_params |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - protected function _disable_default_where_conditions_on_query_param($query_params) |
|
195 | - { |
|
196 | - if (! isset($query_params['default_where_conditions'])) { |
|
197 | - $query_params['default_where_conditions'] = 'none'; |
|
198 | - } |
|
199 | - return $query_params; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Deletes the related model objects which meet the query parameters. If no |
|
205 | - * parameters are specified, then all related model objects will be deleted. |
|
206 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
207 | - * model objects will only be soft-deleted. |
|
208 | - * |
|
209 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
210 | - * @param array $query_params |
|
211 | - * @return int of how many related models got deleted |
|
212 | - * @throws \EE_Error |
|
213 | - */ |
|
214 | - public function delete_all_related($model_object_or_id, $query_params = array()) |
|
215 | - { |
|
216 | - //for each thing we would delete, |
|
217 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
218 | - //determine if it's blocked by anything else before it can be deleted |
|
219 | - $deleted_count = 0; |
|
220 | - foreach ($related_model_objects as $related_model_object) { |
|
221 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
222 | - $model_object_or_id); |
|
223 | - /* @var $model_object_or_id EE_Base_Class */ |
|
224 | - if (! $delete_is_blocked) { |
|
225 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
226 | - $related_model_object->delete(); |
|
227 | - $deleted_count++; |
|
228 | - } |
|
229 | - } |
|
230 | - return $deleted_count; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * Deletes the related model objects which meet the query parameters. If no |
|
236 | - * parameters are specified, then all related model objects will be deleted. |
|
237 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
238 | - * model objects will only be soft-deleted. |
|
239 | - * |
|
240 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
241 | - * @param array $query_params |
|
242 | - * @return int of how many related models got deleted |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
246 | - { |
|
247 | - //for each thing we would delete, |
|
248 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
249 | - //determine if it's blocked by anything else before it can be deleted |
|
250 | - $deleted_count = 0; |
|
251 | - foreach ($related_model_objects as $related_model_object) { |
|
252 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
253 | - $model_object_or_id); |
|
254 | - /* @var $model_object_or_id EE_Base_Class */ |
|
255 | - if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
256 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
257 | - $deleted_count++; |
|
258 | - if (! $delete_is_blocked) { |
|
259 | - $related_model_object->delete_permanently(); |
|
260 | - } else { |
|
261 | - //delete is blocked |
|
262 | - //brent and darren, in this case, wanted to just soft delete it then |
|
263 | - $related_model_object->delete(); |
|
264 | - } |
|
265 | - } else { |
|
266 | - //its not a soft-deletable thing anyways. do the normal logic. |
|
267 | - if (! $delete_is_blocked) { |
|
268 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
269 | - $related_model_object->delete(); |
|
270 | - $deleted_count++; |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - return $deleted_count; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * this just returns a model_object_id for incoming item that could be an object or id. |
|
280 | - * |
|
281 | - * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
282 | - * @throws EE_Error |
|
283 | - * @return int |
|
284 | - */ |
|
285 | - protected function _get_model_object_id($model_object_or_id) |
|
286 | - { |
|
287 | - $model_object_id = $model_object_or_id; |
|
288 | - if ($model_object_or_id instanceof EE_Base_Class) { |
|
289 | - $model_object_id = $model_object_or_id->ID(); |
|
290 | - } |
|
291 | - if (! $model_object_id) { |
|
292 | - throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
293 | - "event_espresso"), $this->get_other_model()->get_this_model_name(), |
|
294 | - $this->get_this_model()->get_this_model_name())); |
|
295 | - } |
|
296 | - return $model_object_id; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Gets the SQL string for performing the join between this model and the other model. |
|
302 | - * |
|
303 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
304 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
305 | - * other_model_primary_table.fk" etc |
|
306 | - */ |
|
307 | - abstract public function get_join_statement($model_relation_chain); |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
312 | - * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
313 | - * relationship only allows this model to be related to a single other model of this type) |
|
314 | - * |
|
315 | - * @param $this_obj_or_id |
|
316 | - * @param $other_obj_or_id |
|
317 | - * @param array $extra_join_model_fields_n_values |
|
318 | - * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
319 | - * $other_obj_or_id) |
|
320 | - */ |
|
321 | - abstract public function add_relation_to( |
|
322 | - $this_obj_or_id, |
|
323 | - $other_obj_or_id, |
|
324 | - $extra_join_model_fields_n_values = array() |
|
325 | - ); |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
330 | - * model objects |
|
331 | - * |
|
332 | - * @param $this_obj_or_id |
|
333 | - * @param $other_obj_or_id |
|
334 | - * @param array $where_query |
|
335 | - * @return bool |
|
336 | - */ |
|
337 | - abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Removes ALL relation instances for this relation obj |
|
342 | - * |
|
343 | - * @param EE_Base_Class|int $this_obj_or_id |
|
344 | - * @param array $where_query_param like EEM_Base::get_all's $query_params[0] (where conditions) |
|
345 | - * @return EE_Base_Class[] |
|
346 | - * @throws \EE_Error |
|
347 | - */ |
|
348 | - public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
349 | - { |
|
350 | - $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
351 | - $objs_removed = array(); |
|
352 | - foreach ($related_things as $related_thing) { |
|
353 | - $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
354 | - } |
|
355 | - return $objs_removed; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * If you aren't allowed to delete this model when there are related models across this |
|
361 | - * relation object, return true. Otherwise, if you can delete this model even though |
|
362 | - * related objects exist, returns false. |
|
363 | - * |
|
364 | - * @return boolean |
|
365 | - */ |
|
366 | - public function block_delete_if_related_models_exist() |
|
367 | - { |
|
368 | - return $this->_blocking_delete; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Gets the error message to show |
|
374 | - * |
|
375 | - * @return string |
|
376 | - */ |
|
377 | - public function get_deletion_error_message() |
|
378 | - { |
|
379 | - if ($this->_blocking_delete_error_message) { |
|
380 | - return $this->_blocking_delete_error_message; |
|
381 | - } else { |
|
17 | + /** |
|
18 | + * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
19 | + * |
|
20 | + * @var string eg Event, Question_Group, Registration |
|
21 | + */ |
|
22 | + private $_this_model_name; |
|
23 | + /** |
|
24 | + * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
25 | + * |
|
26 | + * @var string eg Event, Question_Group, Registration |
|
27 | + */ |
|
28 | + private $_other_model_name; |
|
29 | + |
|
30 | + /** |
|
31 | + * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
32 | + * initiating model. |
|
33 | + * |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $_timezone; |
|
37 | + |
|
38 | + /** |
|
39 | + * If you try to delete "this_model", and there are related "other_models", |
|
40 | + * and this isn't null, then abandon the deletion and add this warning. |
|
41 | + * This effectively makes it impossible to delete "this_model" while there are |
|
42 | + * related "other_models" along this relation. |
|
43 | + * |
|
44 | + * @var string (internationalized) |
|
45 | + */ |
|
46 | + protected $_blocking_delete_error_message; |
|
47 | + |
|
48 | + protected $_blocking_delete = false; |
|
49 | + |
|
50 | + /** |
|
51 | + * Object representing the relationship between two models. This knows how to join the models, |
|
52 | + * get related models across the relation, and add-and-remove the relationships. |
|
53 | + * |
|
54 | + * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
55 | + * and add an error) the deletion of this model |
|
56 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
57 | + * default |
|
58 | + */ |
|
59 | + public function __construct($block_deletes, $blocking_delete_error_message) |
|
60 | + { |
|
61 | + $this->_blocking_delete = $block_deletes; |
|
62 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @param $this_model_name |
|
68 | + * @param $other_model_name |
|
69 | + * @throws EE_Error |
|
70 | + */ |
|
71 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
72 | + { |
|
73 | + $this->_this_model_name = $this_model_name; |
|
74 | + $this->_other_model_name = $other_model_name; |
|
75 | + if (is_string($this->_blocking_delete)) { |
|
76 | + throw new EE_Error(sprintf(__("When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
77 | + "event_espresso"), |
|
78 | + get_class($this), $this_model_name, $other_model_name, $this->_blocking_delete)); |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Gets the model where this relation is defined. |
|
85 | + * |
|
86 | + * @return EEM_Base |
|
87 | + */ |
|
88 | + public function get_this_model() |
|
89 | + { |
|
90 | + return $this->_get_model($this->_this_model_name); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Gets the model which this relation establishes the relation TO (ie, |
|
96 | + * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
97 | + * |
|
98 | + * @return EEM_Base |
|
99 | + */ |
|
100 | + public function get_other_model() |
|
101 | + { |
|
102 | + return $this->_get_model($this->_other_model_name); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Internally used by get_this_model() and get_other_model() |
|
108 | + * |
|
109 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
110 | + * @return EEM_Base |
|
111 | + */ |
|
112 | + protected function _get_model($model_name) |
|
113 | + { |
|
114 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
115 | + $modelInstance->set_timezone($this->_timezone); |
|
116 | + return $modelInstance; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
122 | + * timezone set correctly. |
|
123 | + * |
|
124 | + * @param string $timezone timezone to set. |
|
125 | + */ |
|
126 | + public function set_timezone($timezone) |
|
127 | + { |
|
128 | + if ($timezone !== null) { |
|
129 | + $this->_timezone = $timezone; |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param $other_table |
|
136 | + * @param $other_table_alias |
|
137 | + * @param $other_table_column |
|
138 | + * @param $this_table_alias |
|
139 | + * @param $this_table_join_column |
|
140 | + * @param string $extra_join_sql |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + protected function _left_join( |
|
144 | + $other_table, |
|
145 | + $other_table_alias, |
|
146 | + $other_table_column, |
|
147 | + $this_table_alias, |
|
148 | + $this_table_join_column, |
|
149 | + $extra_join_sql = '' |
|
150 | + ) { |
|
151 | + return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Gets all the model objects of type of other model related to $model_object, |
|
157 | + * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
158 | + * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
159 | + * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
160 | + * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
161 | + * |
|
162 | + * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
163 | + * @param array $query_params like EEM_Base::get_all's $query_params |
|
164 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
165 | + * @return EE_Base_Class[] |
|
166 | + * @throws \EE_Error |
|
167 | + */ |
|
168 | + public function get_all_related( |
|
169 | + $model_object_or_id, |
|
170 | + $query_params = array(), |
|
171 | + $values_already_prepared_by_model_object = false |
|
172 | + ) { |
|
173 | + if ($values_already_prepared_by_model_object !== false) { |
|
174 | + EE_Error::doing_it_wrong('EE_Model_Relation_Base::get_all_related', |
|
175 | + __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
176 | + '4.8.1'); |
|
177 | + } |
|
178 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
179 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
180 | + . "." |
|
181 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
182 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
183 | + $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
184 | + return $this->get_other_model()->get_all($query_params); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
190 | + * |
|
191 | + * @param string $query_params |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + protected function _disable_default_where_conditions_on_query_param($query_params) |
|
195 | + { |
|
196 | + if (! isset($query_params['default_where_conditions'])) { |
|
197 | + $query_params['default_where_conditions'] = 'none'; |
|
198 | + } |
|
199 | + return $query_params; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Deletes the related model objects which meet the query parameters. If no |
|
205 | + * parameters are specified, then all related model objects will be deleted. |
|
206 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
207 | + * model objects will only be soft-deleted. |
|
208 | + * |
|
209 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
210 | + * @param array $query_params |
|
211 | + * @return int of how many related models got deleted |
|
212 | + * @throws \EE_Error |
|
213 | + */ |
|
214 | + public function delete_all_related($model_object_or_id, $query_params = array()) |
|
215 | + { |
|
216 | + //for each thing we would delete, |
|
217 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
218 | + //determine if it's blocked by anything else before it can be deleted |
|
219 | + $deleted_count = 0; |
|
220 | + foreach ($related_model_objects as $related_model_object) { |
|
221 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
222 | + $model_object_or_id); |
|
223 | + /* @var $model_object_or_id EE_Base_Class */ |
|
224 | + if (! $delete_is_blocked) { |
|
225 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
226 | + $related_model_object->delete(); |
|
227 | + $deleted_count++; |
|
228 | + } |
|
229 | + } |
|
230 | + return $deleted_count; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Deletes the related model objects which meet the query parameters. If no |
|
236 | + * parameters are specified, then all related model objects will be deleted. |
|
237 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
238 | + * model objects will only be soft-deleted. |
|
239 | + * |
|
240 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
241 | + * @param array $query_params |
|
242 | + * @return int of how many related models got deleted |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
246 | + { |
|
247 | + //for each thing we would delete, |
|
248 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
249 | + //determine if it's blocked by anything else before it can be deleted |
|
250 | + $deleted_count = 0; |
|
251 | + foreach ($related_model_objects as $related_model_object) { |
|
252 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models($related_model_object, |
|
253 | + $model_object_or_id); |
|
254 | + /* @var $model_object_or_id EE_Base_Class */ |
|
255 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
256 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
257 | + $deleted_count++; |
|
258 | + if (! $delete_is_blocked) { |
|
259 | + $related_model_object->delete_permanently(); |
|
260 | + } else { |
|
261 | + //delete is blocked |
|
262 | + //brent and darren, in this case, wanted to just soft delete it then |
|
263 | + $related_model_object->delete(); |
|
264 | + } |
|
265 | + } else { |
|
266 | + //its not a soft-deletable thing anyways. do the normal logic. |
|
267 | + if (! $delete_is_blocked) { |
|
268 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
269 | + $related_model_object->delete(); |
|
270 | + $deleted_count++; |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + return $deleted_count; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * this just returns a model_object_id for incoming item that could be an object or id. |
|
280 | + * |
|
281 | + * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
282 | + * @throws EE_Error |
|
283 | + * @return int |
|
284 | + */ |
|
285 | + protected function _get_model_object_id($model_object_or_id) |
|
286 | + { |
|
287 | + $model_object_id = $model_object_or_id; |
|
288 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
289 | + $model_object_id = $model_object_or_id->ID(); |
|
290 | + } |
|
291 | + if (! $model_object_id) { |
|
292 | + throw new EE_Error(sprintf(__("Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
293 | + "event_espresso"), $this->get_other_model()->get_this_model_name(), |
|
294 | + $this->get_this_model()->get_this_model_name())); |
|
295 | + } |
|
296 | + return $model_object_id; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Gets the SQL string for performing the join between this model and the other model. |
|
302 | + * |
|
303 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
304 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
305 | + * other_model_primary_table.fk" etc |
|
306 | + */ |
|
307 | + abstract public function get_join_statement($model_relation_chain); |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
312 | + * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
313 | + * relationship only allows this model to be related to a single other model of this type) |
|
314 | + * |
|
315 | + * @param $this_obj_or_id |
|
316 | + * @param $other_obj_or_id |
|
317 | + * @param array $extra_join_model_fields_n_values |
|
318 | + * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
319 | + * $other_obj_or_id) |
|
320 | + */ |
|
321 | + abstract public function add_relation_to( |
|
322 | + $this_obj_or_id, |
|
323 | + $other_obj_or_id, |
|
324 | + $extra_join_model_fields_n_values = array() |
|
325 | + ); |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
330 | + * model objects |
|
331 | + * |
|
332 | + * @param $this_obj_or_id |
|
333 | + * @param $other_obj_or_id |
|
334 | + * @param array $where_query |
|
335 | + * @return bool |
|
336 | + */ |
|
337 | + abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Removes ALL relation instances for this relation obj |
|
342 | + * |
|
343 | + * @param EE_Base_Class|int $this_obj_or_id |
|
344 | + * @param array $where_query_param like EEM_Base::get_all's $query_params[0] (where conditions) |
|
345 | + * @return EE_Base_Class[] |
|
346 | + * @throws \EE_Error |
|
347 | + */ |
|
348 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
349 | + { |
|
350 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
351 | + $objs_removed = array(); |
|
352 | + foreach ($related_things as $related_thing) { |
|
353 | + $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
354 | + } |
|
355 | + return $objs_removed; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * If you aren't allowed to delete this model when there are related models across this |
|
361 | + * relation object, return true. Otherwise, if you can delete this model even though |
|
362 | + * related objects exist, returns false. |
|
363 | + * |
|
364 | + * @return boolean |
|
365 | + */ |
|
366 | + public function block_delete_if_related_models_exist() |
|
367 | + { |
|
368 | + return $this->_blocking_delete; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Gets the error message to show |
|
374 | + * |
|
375 | + * @return string |
|
376 | + */ |
|
377 | + public function get_deletion_error_message() |
|
378 | + { |
|
379 | + if ($this->_blocking_delete_error_message) { |
|
380 | + return $this->_blocking_delete_error_message; |
|
381 | + } else { |
|
382 | 382 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
383 | - return sprintf( |
|
384 | - __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
385 | - "event_espresso"), |
|
386 | - $this->get_this_model()->item_name(1), |
|
387 | - $this->get_other_model()->item_name(1), |
|
388 | - $this->get_other_model()->item_name(2) |
|
389 | - ); |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This returns an array representing a schema for the relation instance. |
|
396 | - * Typically this is used by \EventEspresso\core\db_models\helpers\ModelSchema when it builds an array representing |
|
397 | - * the schema for a model. |
|
398 | - * @return array |
|
399 | - */ |
|
400 | - public function get_schema() |
|
401 | - { |
|
402 | - return array( |
|
403 | - 'type' => 'object', |
|
404 | - 'description' => sprintf(__('Schema for %s relation.', 'event_espresso'), get_class($this)), |
|
405 | - 'properties' => array( |
|
406 | - 'name' => array( |
|
407 | - 'type' => 'string', |
|
408 | - 'enum' => array(str_replace('EE_', '', get_class($this))) |
|
409 | - ) |
|
410 | - ), |
|
411 | - 'readonly' => true |
|
412 | - ); |
|
413 | - } |
|
383 | + return sprintf( |
|
384 | + __('This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
385 | + "event_espresso"), |
|
386 | + $this->get_this_model()->item_name(1), |
|
387 | + $this->get_other_model()->item_name(1), |
|
388 | + $this->get_other_model()->item_name(2) |
|
389 | + ); |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This returns an array representing a schema for the relation instance. |
|
396 | + * Typically this is used by \EventEspresso\core\db_models\helpers\ModelSchema when it builds an array representing |
|
397 | + * the schema for a model. |
|
398 | + * @return array |
|
399 | + */ |
|
400 | + public function get_schema() |
|
401 | + { |
|
402 | + return array( |
|
403 | + 'type' => 'object', |
|
404 | + 'description' => sprintf(__('Schema for %s relation.', 'event_espresso'), get_class($this)), |
|
405 | + 'properties' => array( |
|
406 | + 'name' => array( |
|
407 | + 'type' => 'string', |
|
408 | + 'enum' => array(str_replace('EE_', '', get_class($this))) |
|
409 | + ) |
|
410 | + ), |
|
411 | + 'readonly' => true |
|
412 | + ); |
|
413 | + } |
|
414 | 414 | |
415 | 415 | } |
@@ -3,8 +3,8 @@ |
||
3 | 3 | |
4 | 4 | class EE_DB_Only_Text_Field extends EE_DB_Only_Field_Base |
5 | 5 | { |
6 | - function get_wpdb_data_type() |
|
7 | - { |
|
8 | - return '%s'; |
|
9 | - } |
|
6 | + function get_wpdb_data_type() |
|
7 | + { |
|
8 | + return '%s'; |
|
9 | + } |
|
10 | 10 | } |
11 | 11 | \ No newline at end of file |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php'); |
|
3 | +require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php'); |
|
4 | 4 | |
5 | 5 | class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base |
6 | 6 | { |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once(EE_MODELS . 'fields/EE_DB_Only_Field_Base.php'); |
|
3 | +require_once(EE_MODELS.'fields/EE_DB_Only_Field_Base.php'); |
|
4 | 4 | |
5 | 5 | class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base |
6 | 6 | { |
@@ -3,15 +3,15 @@ |
||
3 | 3 | |
4 | 4 | class EE_DB_Only_Float_Field extends EE_DB_Only_Field_Base |
5 | 5 | { |
6 | - function get_wpdb_data_type() |
|
7 | - { |
|
8 | - return '%f'; |
|
9 | - } |
|
6 | + function get_wpdb_data_type() |
|
7 | + { |
|
8 | + return '%f'; |
|
9 | + } |
|
10 | 10 | |
11 | - public function get_schema() |
|
12 | - { |
|
13 | - $schema = parent::get_schema(); |
|
14 | - $schema['type'] = 'number'; |
|
15 | - return $schema; |
|
16 | - } |
|
11 | + public function get_schema() |
|
12 | + { |
|
13 | + $schema = parent::get_schema(); |
|
14 | + $schema['type'] = 'number'; |
|
15 | + return $schema; |
|
16 | + } |
|
17 | 17 | } |