@@ -23,32 +23,32 @@ |
||
23 | 23 | */ |
24 | 24 | class EEM_Extra_Join extends EEM_Base |
25 | 25 | { |
26 | - // private instance of the Extra Join object |
|
27 | - protected static $_instance = null; |
|
26 | + // private instance of the Extra Join object |
|
27 | + protected static $_instance = null; |
|
28 | 28 | |
29 | - public function __construct($timezone = null) |
|
30 | - { |
|
31 | - $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
32 | - $this->_tables = array( |
|
33 | - 'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'), |
|
34 | - ); |
|
35 | - $this->_fields = array( |
|
36 | - 'Extra_Join' => array( |
|
37 | - 'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')), |
|
38 | - 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', esc_html__('First Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
39 | - 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', esc_html__('First Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
40 | - 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', esc_html__('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
41 | - 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', esc_html__('Second Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
29 | + public function __construct($timezone = null) |
|
30 | + { |
|
31 | + $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
32 | + $this->_tables = array( |
|
33 | + 'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'), |
|
34 | + ); |
|
35 | + $this->_fields = array( |
|
36 | + 'Extra_Join' => array( |
|
37 | + 'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')), |
|
38 | + 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', esc_html__('First Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
39 | + 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', esc_html__('First Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
40 | + 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', esc_html__('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
41 | + 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', esc_html__('Second Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
42 | 42 | |
43 | - ) |
|
44 | - ); |
|
45 | - // this model is weird in that it has two foreign key columns which can point to any model/table. |
|
46 | - // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other |
|
47 | - // model linked to is alphabetically greater than event (eg venue). |
|
48 | - // but if the model linked to is alphabetically lower (eg attendee), |
|
49 | - // the foreign key to the event will be in "EXJ_second_model_ID" |
|
50 | - // so normal usage of foreign keys is weird. So don't define any |
|
51 | - // relations to other models because they won't work properly with this model |
|
52 | - parent::__construct($timezone); |
|
53 | - } |
|
43 | + ) |
|
44 | + ); |
|
45 | + // this model is weird in that it has two foreign key columns which can point to any model/table. |
|
46 | + // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other |
|
47 | + // model linked to is alphabetically greater than event (eg venue). |
|
48 | + // but if the model linked to is alphabetically lower (eg attendee), |
|
49 | + // the foreign key to the event will be in "EXJ_second_model_ID" |
|
50 | + // so normal usage of foreign keys is weird. So don't define any |
|
51 | + // relations to other models because they won't work properly with this model |
|
52 | + parent::__construct($timezone); |
|
53 | + } |
|
54 | 54 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
24 | - $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
24 | + $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
25 | 25 | |
26 | 26 | $this->_tables = array( |
27 | 27 | 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
@@ -12,34 +12,34 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_Registration_Payment extends EEM_Base |
14 | 14 | { |
15 | - // private instance |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | 18 | |
19 | - protected function __construct($timezone = null) |
|
20 | - { |
|
19 | + protected function __construct($timezone = null) |
|
20 | + { |
|
21 | 21 | |
22 | - $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
|
23 | - $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
22 | + $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
|
23 | + $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
24 | 24 | |
25 | - $this->_tables = array( |
|
26 | - 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | - ); |
|
25 | + $this->_tables = array( |
|
26 | + 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | + ); |
|
28 | 28 | |
29 | - $this->_fields = array( |
|
30 | - 'Registration_Payment' => array( |
|
31 | - 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', esc_html__('Registration Payment ID', 'event_espresso')), |
|
32 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | - 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | - 'RPY_amount' => new EE_Money_Field('RPY_amount', esc_html__('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | - ) |
|
36 | - ); |
|
29 | + $this->_fields = array( |
|
30 | + 'Registration_Payment' => array( |
|
31 | + 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', esc_html__('Registration Payment ID', 'event_espresso')), |
|
32 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | + 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | + 'RPY_amount' => new EE_Money_Field('RPY_amount', esc_html__('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | + ) |
|
36 | + ); |
|
37 | 37 | |
38 | - $this->_model_relations = array( |
|
39 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | - 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | - ); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | + 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | + ); |
|
42 | 42 | |
43 | - parent::__construct($timezone); |
|
44 | - } |
|
43 | + parent::__construct($timezone); |
|
44 | + } |
|
45 | 45 | } |
@@ -84,63 +84,63 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | // set default wp post statuses if child has not already set. |
87 | - if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
88 | - $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
87 | + if ( ! isset($this->_fields[$primary_table_name]['status'])) { |
|
88 | + $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field( |
|
89 | 89 | 'post_status', |
90 | 90 | esc_html__("Event Status", "event_espresso"), |
91 | 91 | false, |
92 | 92 | 'draft' |
93 | 93 | ); |
94 | 94 | } |
95 | - if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
96 | - $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
95 | + if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) { |
|
96 | + $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field( |
|
97 | 97 | 'to_ping', |
98 | 98 | esc_html__('To Ping', 'event_espresso'), |
99 | 99 | false, |
100 | 100 | '' |
101 | 101 | ); |
102 | 102 | } |
103 | - if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
104 | - $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
103 | + if ( ! isset($this->_fields[$primary_table_name]['pinged'])) { |
|
104 | + $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field( |
|
105 | 105 | 'pinged', |
106 | 106 | esc_html__('Pinged', 'event_espresso'), |
107 | 107 | false, |
108 | 108 | '' |
109 | 109 | ); |
110 | 110 | } |
111 | - if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
112 | - $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
111 | + if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) { |
|
112 | + $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field( |
|
113 | 113 | 'comment_status', |
114 | 114 | esc_html__('Comment Status', 'event_espresso'), |
115 | 115 | false, |
116 | 116 | 'open' |
117 | 117 | ); |
118 | 118 | } |
119 | - if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
120 | - $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
119 | + if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) { |
|
120 | + $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field( |
|
121 | 121 | 'ping_status', |
122 | 122 | esc_html__('Ping Status', 'event_espresso'), |
123 | 123 | false, |
124 | 124 | 'open' |
125 | 125 | ); |
126 | 126 | } |
127 | - if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
128 | - $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
127 | + if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) { |
|
128 | + $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
129 | 129 | 'post_content_filtered', |
130 | 130 | esc_html__('Post Content Filtered', 'event_espresso'), |
131 | 131 | false, |
132 | 132 | '' |
133 | 133 | ); |
134 | 134 | } |
135 | - if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | + if ( ! isset($this->_model_relations['Post_Meta'])) { |
|
136 | 136 | // don't block deletes though because we want to maintain the current behaviour |
137 | 137 | $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
138 | 138 | } |
139 | - if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | + if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
140 | 140 | // nothing was set during child constructor, so set default |
141 | 141 | $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
142 | 142 | } |
143 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
144 | 144 | // nothing was set during child constructor, so set default |
145 | 145 | // it's ok for child classes to specify this, but generally this is more DRY |
146 | 146 | $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | protected function _alter_query_params_so_only_trashed_items_included($query_params) |
215 | 215 | { |
216 | 216 | $post_status_field_name = $this->post_status_field_name(); |
217 | - $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
217 | + $query_params[0][$post_status_field_name] = self::post_status_trashed; |
|
218 | 218 | return $query_params; |
219 | 219 | } |
220 | 220 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
283 | 283 | } |
284 | 284 | } |
285 | - if (! $all) { |
|
285 | + if ( ! $all) { |
|
286 | 286 | foreach ($all_fields as $name => $obj) { |
287 | 287 | if ($obj instanceof EE_DB_Only_Field_Base) { |
288 | 288 | continue; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $parent_term_taxonomy_id = null |
315 | 315 | ) { |
316 | 316 | // create term |
317 | - require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
317 | + require_once(EE_MODELS.'EEM_Term.model.php'); |
|
318 | 318 | // first, check for a term by the same name or slug |
319 | 319 | $category_slug = sanitize_title($category_name); |
320 | 320 | $term = EEM_Term::instance()->get_one( |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | ), |
329 | 329 | ) |
330 | 330 | ); |
331 | - if (! $term) { |
|
331 | + if ( ! $term) { |
|
332 | 332 | $term = EE_Term::new_instance( |
333 | 333 | array( |
334 | 334 | 'name' => $category_name, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $term->save(); |
339 | 339 | } |
340 | 340 | // make sure there's a term-taxonomy entry too |
341 | - require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
341 | + require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php'); |
|
342 | 342 | $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
343 | 343 | array( |
344 | 344 | array( |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ) |
349 | 349 | ); |
350 | 350 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
351 | - if (! $term_taxonomy) { |
|
351 | + if ( ! $term_taxonomy) { |
|
352 | 352 | $term_taxonomy = EE_Term_Taxonomy::new_instance( |
353 | 353 | array( |
354 | 354 | 'term_id' => $term->ID(), |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | global $wp_post_statuses; |
422 | 422 | $statuses = array(); |
423 | 423 | foreach ($wp_post_statuses as $post_status => $args_object) { |
424 | - $statuses[ $post_status ] = $args_object->label; |
|
424 | + $statuses[$post_status] = $args_object->label; |
|
425 | 425 | } |
426 | 426 | return $statuses; |
427 | 427 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | // first the global filter |
439 | 439 | $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
440 | 440 | // now the class specific filter |
441 | - $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
441 | + $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses); |
|
442 | 442 | return $statuses; |
443 | 443 | } |
444 | 444 | |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | { |
453 | 453 | $new_stati = array(); |
454 | 454 | foreach ($this->_custom_stati as $status => $props) { |
455 | - $new_stati[ $status ] = $props['label']; |
|
455 | + $new_stati[$status] = $props['label']; |
|
456 | 456 | } |
457 | 457 | return $new_stati; |
458 | 458 | } |
@@ -476,15 +476,15 @@ discard block |
||
476 | 476 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
477 | 477 | foreach ($fields_for_that_table as $field_obj) { |
478 | 478 | if ( |
479 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
480 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | + ! isset($post[$field_obj->get_table_column()]) |
|
480 | + && ! isset($post[$field_obj->get_qualified_column()]) |
|
481 | 481 | ) { |
482 | 482 | $has_all_necessary_fields_for_table = false; |
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
486 | 486 | // if we don't have all the fields we need, then just fetch the proper model from the DB |
487 | - if (! $has_all_necessary_fields_for_table) { |
|
487 | + if ( ! $has_all_necessary_fields_for_table) { |
|
488 | 488 | return $this->get_one_by_ID($post['ID']); |
489 | 489 | } else { |
490 | 490 | return $this->instantiate_class_from_array_or_object($post); |
@@ -508,10 +508,10 @@ discard block |
||
508 | 508 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
509 | 509 | foreach ($fields_for_that_table as $field_obj) { |
510 | 510 | if ( |
511 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
512 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | + ! isset($post[$field_obj->get_table_column()]) |
|
512 | + && ! isset($post[$field_obj->get_qualified_column()]) |
|
513 | 513 | ) { |
514 | - $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
514 | + $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | ARRAY_A, |
538 | 538 | ) |
539 | 539 | ); |
540 | - if (! empty($missing_data)) { |
|
540 | + if ( ! empty($missing_data)) { |
|
541 | 541 | $post = array_merge($post, $missing_data); |
542 | 542 | } |
543 | 543 | } else { |
@@ -14,564 +14,564 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base |
16 | 16 | { |
17 | - const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories'; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var string post_status_publish - the wp post status for published cpts |
|
21 | - */ |
|
22 | - const post_status_publish = 'publish'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string post_status_future - the wp post status for scheduled cpts |
|
26 | - */ |
|
27 | - const post_status_future = 'future'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string post_status_draft - the wp post status for draft cpts |
|
31 | - */ |
|
32 | - const post_status_draft = 'draft'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string post_status_pending - the wp post status for pending cpts |
|
36 | - */ |
|
37 | - const post_status_pending = 'pending'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string post_status_private - the wp post status for private cpts |
|
41 | - */ |
|
42 | - const post_status_private = 'private'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string post_status_trashed - the wp post status for trashed cpts |
|
46 | - */ |
|
47 | - const post_status_trashed = 'trash'; |
|
48 | - |
|
49 | - /** |
|
50 | - * This is an array of custom statuses for the given CPT model (modified by children) |
|
51 | - * format: |
|
52 | - * array( |
|
53 | - * 'status_name' => array( |
|
54 | - * 'label' => esc_html__('Status Name', 'event_espresso'), |
|
55 | - * 'public' => TRUE //whether a public status or not. |
|
56 | - * ) |
|
57 | - * ) |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $_custom_stati = array(); |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
66 | - * |
|
67 | - * @param string $timezone |
|
68 | - * @throws \EE_Error |
|
69 | - */ |
|
70 | - protected function __construct($timezone = null) |
|
71 | - { |
|
72 | - // adds a relationship to Term_Taxonomy for all these models. For this to work |
|
73 | - // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
|
74 | - // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
|
75 | - // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
|
76 | - // must also be new EE_HABTM_Relation('Term_Relationship'); |
|
77 | - $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | - $primary_table_name = null; |
|
79 | - // add the common _status field to all CPT primary tables. |
|
80 | - foreach ($this->_tables as $alias => $table_obj) { |
|
81 | - if ($table_obj instanceof EE_Primary_Table) { |
|
82 | - $primary_table_name = $alias; |
|
83 | - } |
|
84 | - } |
|
85 | - // set default wp post statuses if child has not already set. |
|
86 | - if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
87 | - $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
88 | - 'post_status', |
|
89 | - esc_html__("Event Status", "event_espresso"), |
|
90 | - false, |
|
91 | - 'draft' |
|
92 | - ); |
|
93 | - } |
|
94 | - if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
95 | - $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
96 | - 'to_ping', |
|
97 | - esc_html__('To Ping', 'event_espresso'), |
|
98 | - false, |
|
99 | - '' |
|
100 | - ); |
|
101 | - } |
|
102 | - if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
103 | - $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
104 | - 'pinged', |
|
105 | - esc_html__('Pinged', 'event_espresso'), |
|
106 | - false, |
|
107 | - '' |
|
108 | - ); |
|
109 | - } |
|
110 | - if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
111 | - $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
112 | - 'comment_status', |
|
113 | - esc_html__('Comment Status', 'event_espresso'), |
|
114 | - false, |
|
115 | - 'open' |
|
116 | - ); |
|
117 | - } |
|
118 | - if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
119 | - $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
120 | - 'ping_status', |
|
121 | - esc_html__('Ping Status', 'event_espresso'), |
|
122 | - false, |
|
123 | - 'open' |
|
124 | - ); |
|
125 | - } |
|
126 | - if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
127 | - $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
128 | - 'post_content_filtered', |
|
129 | - esc_html__('Post Content Filtered', 'event_espresso'), |
|
130 | - false, |
|
131 | - '' |
|
132 | - ); |
|
133 | - } |
|
134 | - if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | - // don't block deletes though because we want to maintain the current behaviour |
|
136 | - $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
137 | - } |
|
138 | - if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | - // nothing was set during child constructor, so set default |
|
140 | - $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
141 | - } |
|
142 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | - // nothing was set during child constructor, so set default |
|
144 | - // it's ok for child classes to specify this, but generally this is more DRY |
|
145 | - $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
146 | - } |
|
147 | - parent::__construct($timezone); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function public_event_stati() |
|
155 | - { |
|
156 | - // @see wp-includes/post.php |
|
157 | - return get_post_stati(array('public' => true)); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
163 | - * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name |
|
164 | - * |
|
165 | - * @return string |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - public function deleted_field_name() |
|
169 | - { |
|
170 | - throw new EE_Error( |
|
171 | - sprintf( |
|
172 | - esc_html__( |
|
173 | - '%1$s should not call deleted_field_name()! It should instead use post_status_field_name', |
|
174 | - "event_espresso" |
|
175 | - ), |
|
176 | - get_called_class() |
|
177 | - ) |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Gets the field's name that sets the post status |
|
184 | - * |
|
185 | - * @return string |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - public function post_status_field_name() |
|
189 | - { |
|
190 | - $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
|
191 | - if ($field) { |
|
192 | - return $field->get_name(); |
|
193 | - } else { |
|
194 | - throw new EE_Error( |
|
195 | - sprintf( |
|
196 | - esc_html__( |
|
197 | - 'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
198 | - 'event_espresso' |
|
199 | - ), |
|
200 | - get_called_class(), |
|
201 | - get_called_class() |
|
202 | - ) |
|
203 | - ); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
210 | - * |
|
211 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
212 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
213 | - */ |
|
214 | - protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
215 | - { |
|
216 | - $post_status_field_name = $this->post_status_field_name(); |
|
217 | - $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
218 | - return $query_params; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Alters the query params so each item's deleted status is ignored. |
|
224 | - * |
|
225 | - * @param array $query_params |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
229 | - { |
|
230 | - $query_params['default_where_conditions'] = 'minimum'; |
|
231 | - return $query_params; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
237 | - * |
|
238 | - * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
239 | - * @param array $query_params |
|
240 | - * @return boolean success |
|
241 | - * @throws EE_Error |
|
242 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | - */ |
|
244 | - public function delete_or_restore($delete = true, $query_params = array()) |
|
245 | - { |
|
246 | - $post_status_field_name = $this->post_status_field_name(); |
|
247 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
248 | - $new_status = $delete ? self::post_status_trashed : 'draft'; |
|
249 | - return (bool) $this->update([$post_status_field_name => $new_status], $query_params); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * meta_table |
|
255 | - * returns first EE_Secondary_Table table name |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function meta_table() |
|
261 | - { |
|
262 | - $meta_table = $this->_get_other_tables(); |
|
263 | - $meta_table = reset($meta_table); |
|
264 | - return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * This simply returns an array of the meta table fields (useful for when we just need to update those fields) |
|
270 | - * |
|
271 | - * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no |
|
272 | - * db only fields) |
|
273 | - * @return array |
|
274 | - */ |
|
275 | - public function get_meta_table_fields($all = false) |
|
276 | - { |
|
277 | - $all_fields = $fields_to_return = array(); |
|
278 | - foreach ($this->_tables as $alias => $table_obj) { |
|
279 | - if ($table_obj instanceof EE_Secondary_Table) { |
|
280 | - $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
281 | - } |
|
282 | - } |
|
283 | - if (! $all) { |
|
284 | - foreach ($all_fields as $name => $obj) { |
|
285 | - if ($obj instanceof EE_DB_Only_Field_Base) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - $fields_to_return[] = $name; |
|
289 | - } |
|
290 | - } else { |
|
291 | - $fields_to_return = array_keys($all_fields); |
|
292 | - } |
|
293 | - return $fields_to_return; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Adds an event category with the specified name and description to the specified |
|
299 | - * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary, |
|
300 | - * and adds an entry in the term_relationship if necessary. |
|
301 | - * |
|
302 | - * @param EE_CPT_Base $cpt_model_object |
|
303 | - * @param string $category_name (used to derive the term slug too) |
|
304 | - * @param string $category_description |
|
305 | - * @param int $parent_term_taxonomy_id |
|
306 | - * @return EE_Term_Taxonomy |
|
307 | - */ |
|
308 | - public function add_event_category( |
|
309 | - EE_CPT_Base $cpt_model_object, |
|
310 | - $category_name, |
|
311 | - $category_description = '', |
|
312 | - $parent_term_taxonomy_id = null |
|
313 | - ) { |
|
314 | - // create term |
|
315 | - require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
316 | - // first, check for a term by the same name or slug |
|
317 | - $category_slug = sanitize_title($category_name); |
|
318 | - $term = EEM_Term::instance()->get_one( |
|
319 | - array( |
|
320 | - array( |
|
321 | - 'OR' => array( |
|
322 | - 'name' => $category_name, |
|
323 | - 'slug' => $category_slug, |
|
324 | - ), |
|
325 | - 'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY |
|
326 | - ), |
|
327 | - ) |
|
328 | - ); |
|
329 | - if (! $term) { |
|
330 | - $term = EE_Term::new_instance( |
|
331 | - array( |
|
332 | - 'name' => $category_name, |
|
333 | - 'slug' => $category_slug, |
|
334 | - ) |
|
335 | - ); |
|
336 | - $term->save(); |
|
337 | - } |
|
338 | - // make sure there's a term-taxonomy entry too |
|
339 | - require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
340 | - $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
|
341 | - array( |
|
342 | - array( |
|
343 | - 'term_id' => $term->ID(), |
|
344 | - 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
345 | - ), |
|
346 | - ) |
|
347 | - ); |
|
348 | - /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
349 | - if (! $term_taxonomy) { |
|
350 | - $term_taxonomy = EE_Term_Taxonomy::new_instance( |
|
351 | - array( |
|
352 | - 'term_id' => $term->ID(), |
|
353 | - 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
354 | - 'description' => $category_description, |
|
355 | - 'term_count' => 1, |
|
356 | - 'parent' => $parent_term_taxonomy_id, |
|
357 | - ) |
|
358 | - ); |
|
359 | - $term_taxonomy->save(); |
|
360 | - } else { |
|
361 | - $term_taxonomy->set_count($term_taxonomy->count() + 1); |
|
362 | - $term_taxonomy->save(); |
|
363 | - } |
|
364 | - return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy'); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Removed the category specified by name as having a relation to this event. |
|
370 | - * Does not remove the term or term_taxonomy. |
|
371 | - * |
|
372 | - * @param EE_CPT_Base $cpt_model_object_event |
|
373 | - * @param string $category_name name of the event category (term) |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) |
|
377 | - { |
|
378 | - // find the term_taxonomy by that name |
|
379 | - $term_taxonomy = $this->get_first_related( |
|
380 | - $cpt_model_object_event, |
|
381 | - 'Term_Taxonomy', |
|
382 | - array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY)) |
|
383 | - ); |
|
384 | - /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
385 | - if ($term_taxonomy) { |
|
386 | - $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
387 | - $term_taxonomy->save(); |
|
388 | - } |
|
389 | - return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy'); |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the |
|
395 | - * given CPT ID. It accepts the same params as what get_the_post_thumbnail() accepts. |
|
396 | - * |
|
397 | - * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
398 | - * @access public |
|
399 | - * @param int $id the ID for the cpt we want the feature image for |
|
400 | - * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
401 | - * representing width and height in pixels (i.e. array(32,32) ). |
|
402 | - * @param string|array $attr Optional. Query string or array of attributes. |
|
403 | - * @return string HTML image element |
|
404 | - */ |
|
405 | - public function get_feature_image($id, $size = 'thumbnail', $attr = '') |
|
406 | - { |
|
407 | - return get_the_post_thumbnail($id, $size, $attr); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Just a handy way to get the list of post statuses currently registered with WP. |
|
413 | - * |
|
414 | - * @global array $wp_post_statuses set in wp core for storing all the post stati |
|
415 | - * @return array |
|
416 | - */ |
|
417 | - public function get_post_statuses() |
|
418 | - { |
|
419 | - global $wp_post_statuses; |
|
420 | - $statuses = array(); |
|
421 | - foreach ($wp_post_statuses as $post_status => $args_object) { |
|
422 | - $statuses[ $post_status ] = $args_object->label; |
|
423 | - } |
|
424 | - return $statuses; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * public method that can be used to retrieve the protected status array on the instantiated cpt model |
|
430 | - * |
|
431 | - * @return array array of statuses. |
|
432 | - */ |
|
433 | - public function get_status_array() |
|
434 | - { |
|
435 | - $statuses = $this->get_post_statuses(); |
|
436 | - // first the global filter |
|
437 | - $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
438 | - // now the class specific filter |
|
439 | - $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
440 | - return $statuses; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * this returns the post statuses that are NOT the default wordpress status |
|
446 | - * |
|
447 | - * @return array |
|
448 | - */ |
|
449 | - public function get_custom_post_statuses() |
|
450 | - { |
|
451 | - $new_stati = array(); |
|
452 | - foreach ($this->_custom_stati as $status => $props) { |
|
453 | - $new_stati[ $status ] = $props['label']; |
|
454 | - } |
|
455 | - return $new_stati; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which |
|
461 | - * are a row from the posts table. If we're missing any fields required for the model, |
|
462 | - * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries, |
|
463 | - * make sure you are attaching all the model's fields onto the post) |
|
464 | - * |
|
465 | - * @param WP_Post|array $post |
|
466 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
467 | - */ |
|
468 | - public function instantiate_class_from_post_object_orig($post) |
|
469 | - { |
|
470 | - $post = (array) $post; |
|
471 | - $has_all_necessary_fields_for_table = true; |
|
472 | - // check if the post has fields on the meta table already |
|
473 | - foreach ($this->_get_other_tables() as $table_obj) { |
|
474 | - $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
475 | - foreach ($fields_for_that_table as $field_obj) { |
|
476 | - if ( |
|
477 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
478 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | - ) { |
|
480 | - $has_all_necessary_fields_for_table = false; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
485 | - if (! $has_all_necessary_fields_for_table) { |
|
486 | - return $this->get_one_by_ID($post['ID']); |
|
487 | - } else { |
|
488 | - return $this->instantiate_class_from_array_or_object($post); |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * @param null $post |
|
495 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
496 | - */ |
|
497 | - public function instantiate_class_from_post_object($post = null) |
|
498 | - { |
|
499 | - if (empty($post)) { |
|
500 | - global $post; |
|
501 | - } |
|
502 | - $post = (array) $post; |
|
503 | - $tables_needing_to_be_queried = array(); |
|
504 | - // check if the post has fields on the meta table already |
|
505 | - foreach ($this->get_tables() as $table_obj) { |
|
506 | - $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
507 | - foreach ($fields_for_that_table as $field_obj) { |
|
508 | - if ( |
|
509 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
510 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | - ) { |
|
512 | - $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
513 | - } |
|
514 | - } |
|
515 | - } |
|
516 | - // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
517 | - if ($tables_needing_to_be_queried) { |
|
518 | - if ( |
|
519 | - count($tables_needing_to_be_queried) == 1 |
|
520 | - && reset($tables_needing_to_be_queried) |
|
521 | - instanceof |
|
522 | - EE_Secondary_Table |
|
523 | - ) { |
|
524 | - // so we're only missing data from a secondary table. Well that's not too hard to query for |
|
525 | - $table_to_query = reset($tables_needing_to_be_queried); |
|
526 | - $missing_data = $this->_do_wpdb_query( |
|
527 | - 'get_row', |
|
528 | - array( |
|
529 | - 'SELECT * FROM ' |
|
530 | - . $table_to_query->get_table_name() |
|
531 | - . ' WHERE ' |
|
532 | - . $table_to_query->get_fk_on_table() |
|
533 | - . ' = ' |
|
534 | - . $post['ID'], |
|
535 | - ARRAY_A, |
|
536 | - ) |
|
537 | - ); |
|
538 | - if (! empty($missing_data)) { |
|
539 | - $post = array_merge($post, $missing_data); |
|
540 | - } |
|
541 | - } else { |
|
542 | - return $this->get_one_by_ID($post['ID']); |
|
543 | - } |
|
544 | - } |
|
545 | - return $this->instantiate_class_from_array_or_object($post); |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Gets the post type associated with this |
|
551 | - * |
|
552 | - * @throws EE_Error |
|
553 | - * @return string |
|
554 | - */ |
|
555 | - public function post_type() |
|
556 | - { |
|
557 | - $post_type_field = null; |
|
558 | - foreach ($this->field_settings(true) as $field_obj) { |
|
559 | - if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
560 | - $post_type_field = $field_obj; |
|
561 | - break; |
|
562 | - } |
|
563 | - } |
|
564 | - if ($post_type_field == null) { |
|
565 | - throw new EE_Error( |
|
566 | - sprintf( |
|
567 | - esc_html__( |
|
568 | - "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", |
|
569 | - "event_espresso" |
|
570 | - ), |
|
571 | - get_class($this) |
|
572 | - ) |
|
573 | - ); |
|
574 | - } |
|
575 | - return $post_type_field->get_default_value(); |
|
576 | - } |
|
17 | + const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories'; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var string post_status_publish - the wp post status for published cpts |
|
21 | + */ |
|
22 | + const post_status_publish = 'publish'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string post_status_future - the wp post status for scheduled cpts |
|
26 | + */ |
|
27 | + const post_status_future = 'future'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string post_status_draft - the wp post status for draft cpts |
|
31 | + */ |
|
32 | + const post_status_draft = 'draft'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string post_status_pending - the wp post status for pending cpts |
|
36 | + */ |
|
37 | + const post_status_pending = 'pending'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string post_status_private - the wp post status for private cpts |
|
41 | + */ |
|
42 | + const post_status_private = 'private'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string post_status_trashed - the wp post status for trashed cpts |
|
46 | + */ |
|
47 | + const post_status_trashed = 'trash'; |
|
48 | + |
|
49 | + /** |
|
50 | + * This is an array of custom statuses for the given CPT model (modified by children) |
|
51 | + * format: |
|
52 | + * array( |
|
53 | + * 'status_name' => array( |
|
54 | + * 'label' => esc_html__('Status Name', 'event_espresso'), |
|
55 | + * 'public' => TRUE //whether a public status or not. |
|
56 | + * ) |
|
57 | + * ) |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $_custom_stati = array(); |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
66 | + * |
|
67 | + * @param string $timezone |
|
68 | + * @throws \EE_Error |
|
69 | + */ |
|
70 | + protected function __construct($timezone = null) |
|
71 | + { |
|
72 | + // adds a relationship to Term_Taxonomy for all these models. For this to work |
|
73 | + // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
|
74 | + // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
|
75 | + // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
|
76 | + // must also be new EE_HABTM_Relation('Term_Relationship'); |
|
77 | + $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | + $primary_table_name = null; |
|
79 | + // add the common _status field to all CPT primary tables. |
|
80 | + foreach ($this->_tables as $alias => $table_obj) { |
|
81 | + if ($table_obj instanceof EE_Primary_Table) { |
|
82 | + $primary_table_name = $alias; |
|
83 | + } |
|
84 | + } |
|
85 | + // set default wp post statuses if child has not already set. |
|
86 | + if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
87 | + $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
88 | + 'post_status', |
|
89 | + esc_html__("Event Status", "event_espresso"), |
|
90 | + false, |
|
91 | + 'draft' |
|
92 | + ); |
|
93 | + } |
|
94 | + if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
95 | + $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
96 | + 'to_ping', |
|
97 | + esc_html__('To Ping', 'event_espresso'), |
|
98 | + false, |
|
99 | + '' |
|
100 | + ); |
|
101 | + } |
|
102 | + if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
103 | + $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
104 | + 'pinged', |
|
105 | + esc_html__('Pinged', 'event_espresso'), |
|
106 | + false, |
|
107 | + '' |
|
108 | + ); |
|
109 | + } |
|
110 | + if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
111 | + $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
112 | + 'comment_status', |
|
113 | + esc_html__('Comment Status', 'event_espresso'), |
|
114 | + false, |
|
115 | + 'open' |
|
116 | + ); |
|
117 | + } |
|
118 | + if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
119 | + $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
120 | + 'ping_status', |
|
121 | + esc_html__('Ping Status', 'event_espresso'), |
|
122 | + false, |
|
123 | + 'open' |
|
124 | + ); |
|
125 | + } |
|
126 | + if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
127 | + $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
128 | + 'post_content_filtered', |
|
129 | + esc_html__('Post Content Filtered', 'event_espresso'), |
|
130 | + false, |
|
131 | + '' |
|
132 | + ); |
|
133 | + } |
|
134 | + if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | + // don't block deletes though because we want to maintain the current behaviour |
|
136 | + $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
137 | + } |
|
138 | + if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | + // nothing was set during child constructor, so set default |
|
140 | + $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
141 | + } |
|
142 | + if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | + // nothing was set during child constructor, so set default |
|
144 | + // it's ok for child classes to specify this, but generally this is more DRY |
|
145 | + $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
146 | + } |
|
147 | + parent::__construct($timezone); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function public_event_stati() |
|
155 | + { |
|
156 | + // @see wp-includes/post.php |
|
157 | + return get_post_stati(array('public' => true)); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
163 | + * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name |
|
164 | + * |
|
165 | + * @return string |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + public function deleted_field_name() |
|
169 | + { |
|
170 | + throw new EE_Error( |
|
171 | + sprintf( |
|
172 | + esc_html__( |
|
173 | + '%1$s should not call deleted_field_name()! It should instead use post_status_field_name', |
|
174 | + "event_espresso" |
|
175 | + ), |
|
176 | + get_called_class() |
|
177 | + ) |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Gets the field's name that sets the post status |
|
184 | + * |
|
185 | + * @return string |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + public function post_status_field_name() |
|
189 | + { |
|
190 | + $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
|
191 | + if ($field) { |
|
192 | + return $field->get_name(); |
|
193 | + } else { |
|
194 | + throw new EE_Error( |
|
195 | + sprintf( |
|
196 | + esc_html__( |
|
197 | + 'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
198 | + 'event_espresso' |
|
199 | + ), |
|
200 | + get_called_class(), |
|
201 | + get_called_class() |
|
202 | + ) |
|
203 | + ); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
210 | + * |
|
211 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
212 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
213 | + */ |
|
214 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
215 | + { |
|
216 | + $post_status_field_name = $this->post_status_field_name(); |
|
217 | + $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
218 | + return $query_params; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Alters the query params so each item's deleted status is ignored. |
|
224 | + * |
|
225 | + * @param array $query_params |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
229 | + { |
|
230 | + $query_params['default_where_conditions'] = 'minimum'; |
|
231 | + return $query_params; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
237 | + * |
|
238 | + * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
239 | + * @param array $query_params |
|
240 | + * @return boolean success |
|
241 | + * @throws EE_Error |
|
242 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | + */ |
|
244 | + public function delete_or_restore($delete = true, $query_params = array()) |
|
245 | + { |
|
246 | + $post_status_field_name = $this->post_status_field_name(); |
|
247 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
248 | + $new_status = $delete ? self::post_status_trashed : 'draft'; |
|
249 | + return (bool) $this->update([$post_status_field_name => $new_status], $query_params); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * meta_table |
|
255 | + * returns first EE_Secondary_Table table name |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function meta_table() |
|
261 | + { |
|
262 | + $meta_table = $this->_get_other_tables(); |
|
263 | + $meta_table = reset($meta_table); |
|
264 | + return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * This simply returns an array of the meta table fields (useful for when we just need to update those fields) |
|
270 | + * |
|
271 | + * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no |
|
272 | + * db only fields) |
|
273 | + * @return array |
|
274 | + */ |
|
275 | + public function get_meta_table_fields($all = false) |
|
276 | + { |
|
277 | + $all_fields = $fields_to_return = array(); |
|
278 | + foreach ($this->_tables as $alias => $table_obj) { |
|
279 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
280 | + $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
281 | + } |
|
282 | + } |
|
283 | + if (! $all) { |
|
284 | + foreach ($all_fields as $name => $obj) { |
|
285 | + if ($obj instanceof EE_DB_Only_Field_Base) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + $fields_to_return[] = $name; |
|
289 | + } |
|
290 | + } else { |
|
291 | + $fields_to_return = array_keys($all_fields); |
|
292 | + } |
|
293 | + return $fields_to_return; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Adds an event category with the specified name and description to the specified |
|
299 | + * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary, |
|
300 | + * and adds an entry in the term_relationship if necessary. |
|
301 | + * |
|
302 | + * @param EE_CPT_Base $cpt_model_object |
|
303 | + * @param string $category_name (used to derive the term slug too) |
|
304 | + * @param string $category_description |
|
305 | + * @param int $parent_term_taxonomy_id |
|
306 | + * @return EE_Term_Taxonomy |
|
307 | + */ |
|
308 | + public function add_event_category( |
|
309 | + EE_CPT_Base $cpt_model_object, |
|
310 | + $category_name, |
|
311 | + $category_description = '', |
|
312 | + $parent_term_taxonomy_id = null |
|
313 | + ) { |
|
314 | + // create term |
|
315 | + require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
316 | + // first, check for a term by the same name or slug |
|
317 | + $category_slug = sanitize_title($category_name); |
|
318 | + $term = EEM_Term::instance()->get_one( |
|
319 | + array( |
|
320 | + array( |
|
321 | + 'OR' => array( |
|
322 | + 'name' => $category_name, |
|
323 | + 'slug' => $category_slug, |
|
324 | + ), |
|
325 | + 'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY |
|
326 | + ), |
|
327 | + ) |
|
328 | + ); |
|
329 | + if (! $term) { |
|
330 | + $term = EE_Term::new_instance( |
|
331 | + array( |
|
332 | + 'name' => $category_name, |
|
333 | + 'slug' => $category_slug, |
|
334 | + ) |
|
335 | + ); |
|
336 | + $term->save(); |
|
337 | + } |
|
338 | + // make sure there's a term-taxonomy entry too |
|
339 | + require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
340 | + $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
|
341 | + array( |
|
342 | + array( |
|
343 | + 'term_id' => $term->ID(), |
|
344 | + 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
345 | + ), |
|
346 | + ) |
|
347 | + ); |
|
348 | + /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
349 | + if (! $term_taxonomy) { |
|
350 | + $term_taxonomy = EE_Term_Taxonomy::new_instance( |
|
351 | + array( |
|
352 | + 'term_id' => $term->ID(), |
|
353 | + 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
354 | + 'description' => $category_description, |
|
355 | + 'term_count' => 1, |
|
356 | + 'parent' => $parent_term_taxonomy_id, |
|
357 | + ) |
|
358 | + ); |
|
359 | + $term_taxonomy->save(); |
|
360 | + } else { |
|
361 | + $term_taxonomy->set_count($term_taxonomy->count() + 1); |
|
362 | + $term_taxonomy->save(); |
|
363 | + } |
|
364 | + return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy'); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Removed the category specified by name as having a relation to this event. |
|
370 | + * Does not remove the term or term_taxonomy. |
|
371 | + * |
|
372 | + * @param EE_CPT_Base $cpt_model_object_event |
|
373 | + * @param string $category_name name of the event category (term) |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) |
|
377 | + { |
|
378 | + // find the term_taxonomy by that name |
|
379 | + $term_taxonomy = $this->get_first_related( |
|
380 | + $cpt_model_object_event, |
|
381 | + 'Term_Taxonomy', |
|
382 | + array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY)) |
|
383 | + ); |
|
384 | + /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
385 | + if ($term_taxonomy) { |
|
386 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
387 | + $term_taxonomy->save(); |
|
388 | + } |
|
389 | + return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy'); |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the |
|
395 | + * given CPT ID. It accepts the same params as what get_the_post_thumbnail() accepts. |
|
396 | + * |
|
397 | + * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
398 | + * @access public |
|
399 | + * @param int $id the ID for the cpt we want the feature image for |
|
400 | + * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
401 | + * representing width and height in pixels (i.e. array(32,32) ). |
|
402 | + * @param string|array $attr Optional. Query string or array of attributes. |
|
403 | + * @return string HTML image element |
|
404 | + */ |
|
405 | + public function get_feature_image($id, $size = 'thumbnail', $attr = '') |
|
406 | + { |
|
407 | + return get_the_post_thumbnail($id, $size, $attr); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Just a handy way to get the list of post statuses currently registered with WP. |
|
413 | + * |
|
414 | + * @global array $wp_post_statuses set in wp core for storing all the post stati |
|
415 | + * @return array |
|
416 | + */ |
|
417 | + public function get_post_statuses() |
|
418 | + { |
|
419 | + global $wp_post_statuses; |
|
420 | + $statuses = array(); |
|
421 | + foreach ($wp_post_statuses as $post_status => $args_object) { |
|
422 | + $statuses[ $post_status ] = $args_object->label; |
|
423 | + } |
|
424 | + return $statuses; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * public method that can be used to retrieve the protected status array on the instantiated cpt model |
|
430 | + * |
|
431 | + * @return array array of statuses. |
|
432 | + */ |
|
433 | + public function get_status_array() |
|
434 | + { |
|
435 | + $statuses = $this->get_post_statuses(); |
|
436 | + // first the global filter |
|
437 | + $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
438 | + // now the class specific filter |
|
439 | + $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
440 | + return $statuses; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * this returns the post statuses that are NOT the default wordpress status |
|
446 | + * |
|
447 | + * @return array |
|
448 | + */ |
|
449 | + public function get_custom_post_statuses() |
|
450 | + { |
|
451 | + $new_stati = array(); |
|
452 | + foreach ($this->_custom_stati as $status => $props) { |
|
453 | + $new_stati[ $status ] = $props['label']; |
|
454 | + } |
|
455 | + return $new_stati; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which |
|
461 | + * are a row from the posts table. If we're missing any fields required for the model, |
|
462 | + * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries, |
|
463 | + * make sure you are attaching all the model's fields onto the post) |
|
464 | + * |
|
465 | + * @param WP_Post|array $post |
|
466 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
467 | + */ |
|
468 | + public function instantiate_class_from_post_object_orig($post) |
|
469 | + { |
|
470 | + $post = (array) $post; |
|
471 | + $has_all_necessary_fields_for_table = true; |
|
472 | + // check if the post has fields on the meta table already |
|
473 | + foreach ($this->_get_other_tables() as $table_obj) { |
|
474 | + $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
475 | + foreach ($fields_for_that_table as $field_obj) { |
|
476 | + if ( |
|
477 | + ! isset($post[ $field_obj->get_table_column() ]) |
|
478 | + && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | + ) { |
|
480 | + $has_all_necessary_fields_for_table = false; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
485 | + if (! $has_all_necessary_fields_for_table) { |
|
486 | + return $this->get_one_by_ID($post['ID']); |
|
487 | + } else { |
|
488 | + return $this->instantiate_class_from_array_or_object($post); |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * @param null $post |
|
495 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
496 | + */ |
|
497 | + public function instantiate_class_from_post_object($post = null) |
|
498 | + { |
|
499 | + if (empty($post)) { |
|
500 | + global $post; |
|
501 | + } |
|
502 | + $post = (array) $post; |
|
503 | + $tables_needing_to_be_queried = array(); |
|
504 | + // check if the post has fields on the meta table already |
|
505 | + foreach ($this->get_tables() as $table_obj) { |
|
506 | + $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
507 | + foreach ($fields_for_that_table as $field_obj) { |
|
508 | + if ( |
|
509 | + ! isset($post[ $field_obj->get_table_column() ]) |
|
510 | + && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | + ) { |
|
512 | + $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
513 | + } |
|
514 | + } |
|
515 | + } |
|
516 | + // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
517 | + if ($tables_needing_to_be_queried) { |
|
518 | + if ( |
|
519 | + count($tables_needing_to_be_queried) == 1 |
|
520 | + && reset($tables_needing_to_be_queried) |
|
521 | + instanceof |
|
522 | + EE_Secondary_Table |
|
523 | + ) { |
|
524 | + // so we're only missing data from a secondary table. Well that's not too hard to query for |
|
525 | + $table_to_query = reset($tables_needing_to_be_queried); |
|
526 | + $missing_data = $this->_do_wpdb_query( |
|
527 | + 'get_row', |
|
528 | + array( |
|
529 | + 'SELECT * FROM ' |
|
530 | + . $table_to_query->get_table_name() |
|
531 | + . ' WHERE ' |
|
532 | + . $table_to_query->get_fk_on_table() |
|
533 | + . ' = ' |
|
534 | + . $post['ID'], |
|
535 | + ARRAY_A, |
|
536 | + ) |
|
537 | + ); |
|
538 | + if (! empty($missing_data)) { |
|
539 | + $post = array_merge($post, $missing_data); |
|
540 | + } |
|
541 | + } else { |
|
542 | + return $this->get_one_by_ID($post['ID']); |
|
543 | + } |
|
544 | + } |
|
545 | + return $this->instantiate_class_from_array_or_object($post); |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Gets the post type associated with this |
|
551 | + * |
|
552 | + * @throws EE_Error |
|
553 | + * @return string |
|
554 | + */ |
|
555 | + public function post_type() |
|
556 | + { |
|
557 | + $post_type_field = null; |
|
558 | + foreach ($this->field_settings(true) as $field_obj) { |
|
559 | + if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
560 | + $post_type_field = $field_obj; |
|
561 | + break; |
|
562 | + } |
|
563 | + } |
|
564 | + if ($post_type_field == null) { |
|
565 | + throw new EE_Error( |
|
566 | + sprintf( |
|
567 | + esc_html__( |
|
568 | + "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", |
|
569 | + "event_espresso" |
|
570 | + ), |
|
571 | + get_class($this) |
|
572 | + ) |
|
573 | + ); |
|
574 | + } |
|
575 | + return $post_type_field->get_default_value(); |
|
576 | + } |
|
577 | 577 | } |
@@ -16,502 +16,502 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class EE_Model_Relation_Base implements HasSchemaInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
21 | - * |
|
22 | - * @var string eg Event, Question_Group, Registration |
|
23 | - */ |
|
24 | - private $_this_model_name; |
|
25 | - /** |
|
26 | - * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
27 | - * |
|
28 | - * @var string eg Event, Question_Group, Registration |
|
29 | - */ |
|
30 | - private $_other_model_name; |
|
31 | - |
|
32 | - /** |
|
33 | - * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
34 | - * initiating model. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $_timezone; |
|
39 | - |
|
40 | - /** |
|
41 | - * If you try to delete "this_model", and there are related "other_models", |
|
42 | - * and this isn't null, then abandon the deletion and add this warning. |
|
43 | - * This effectively makes it impossible to delete "this_model" while there are |
|
44 | - * related "other_models" along this relation. |
|
45 | - * |
|
46 | - * @var string (internationalized) |
|
47 | - */ |
|
48 | - protected $_blocking_delete_error_message; |
|
49 | - |
|
50 | - protected $_blocking_delete = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * Object representing the relationship between two models. This knows how to join the models, |
|
54 | - * get related models across the relation, and add-and-remove the relationships. |
|
55 | - * |
|
56 | - * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
57 | - * and add an error) the deletion of this model |
|
58 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
59 | - * default |
|
60 | - */ |
|
61 | - public function __construct($block_deletes, $blocking_delete_error_message) |
|
62 | - { |
|
63 | - $this->_blocking_delete = $block_deletes; |
|
64 | - $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param $this_model_name |
|
70 | - * @param $other_model_name |
|
71 | - * @throws EE_Error |
|
72 | - */ |
|
73 | - public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
74 | - { |
|
75 | - $this->_this_model_name = $this_model_name; |
|
76 | - $this->_other_model_name = $other_model_name; |
|
77 | - if (is_string($this->_blocking_delete)) { |
|
78 | - throw new EE_Error(sprintf( |
|
79 | - esc_html__( |
|
80 | - "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
81 | - "event_espresso" |
|
82 | - ), |
|
83 | - get_class($this), |
|
84 | - $this_model_name, |
|
85 | - $other_model_name, |
|
86 | - $this->_blocking_delete |
|
87 | - )); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Gets the model where this relation is defined. |
|
94 | - * |
|
95 | - * @return EEM_Base |
|
96 | - */ |
|
97 | - public function get_this_model() |
|
98 | - { |
|
99 | - return $this->_get_model($this->_this_model_name); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Gets the model which this relation establishes the relation TO (ie, |
|
105 | - * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
106 | - * |
|
107 | - * @return EEM_Base |
|
108 | - */ |
|
109 | - public function get_other_model() |
|
110 | - { |
|
111 | - return $this->_get_model($this->_other_model_name); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Internally used by get_this_model() and get_other_model() |
|
117 | - * |
|
118 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
119 | - * @return EEM_Base |
|
120 | - */ |
|
121 | - protected function _get_model($model_name) |
|
122 | - { |
|
123 | - $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
124 | - $modelInstance->set_timezone($this->_timezone); |
|
125 | - return $modelInstance; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
131 | - * timezone set correctly. |
|
132 | - * |
|
133 | - * @param string $timezone timezone to set. |
|
134 | - */ |
|
135 | - public function set_timezone($timezone) |
|
136 | - { |
|
137 | - if ($timezone !== null) { |
|
138 | - $this->_timezone = $timezone; |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $other_table |
|
145 | - * @param $other_table_alias |
|
146 | - * @param $other_table_column |
|
147 | - * @param $this_table_alias |
|
148 | - * @param $this_table_join_column |
|
149 | - * @param string $extra_join_sql |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - protected function _left_join( |
|
153 | - $other_table, |
|
154 | - $other_table_alias, |
|
155 | - $other_table_column, |
|
156 | - $this_table_alias, |
|
157 | - $this_table_join_column, |
|
158 | - $extra_join_sql = '' |
|
159 | - ) { |
|
160 | - 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" : ''); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Gets all the model objects of type of other model related to $model_object, |
|
166 | - * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
167 | - * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
168 | - * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
169 | - * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
170 | - * |
|
171 | - * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
172 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
173 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
174 | - * @return EE_Base_Class[] |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public function get_all_related( |
|
178 | - $model_object_or_id, |
|
179 | - $query_params = array(), |
|
180 | - $values_already_prepared_by_model_object = false |
|
181 | - ) { |
|
182 | - if ($values_already_prepared_by_model_object !== false) { |
|
183 | - EE_Error::doing_it_wrong( |
|
184 | - 'EE_Model_Relation_Base::get_all_related', |
|
185 | - esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
186 | - '4.8.1' |
|
187 | - ); |
|
188 | - } |
|
189 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
190 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
191 | - . "." |
|
192 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
193 | - $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
194 | - $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
195 | - return $this->get_other_model()->get_all($query_params); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
201 | - * |
|
202 | - * @param string $query_params |
|
203 | - * @return array |
|
204 | - */ |
|
205 | - protected function _disable_default_where_conditions_on_query_param($query_params) |
|
206 | - { |
|
207 | - if (! isset($query_params['default_where_conditions'])) { |
|
208 | - $query_params['default_where_conditions'] = 'none'; |
|
209 | - } |
|
210 | - return $query_params; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Deletes the related model objects which meet the query parameters. If no |
|
216 | - * parameters are specified, then all related model objects will be deleted. |
|
217 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
218 | - * model objects will only be soft-deleted. |
|
219 | - * |
|
220 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
221 | - * @param array $query_params |
|
222 | - * @return int of how many related models got deleted |
|
223 | - * @throws \EE_Error |
|
224 | - */ |
|
225 | - public function delete_all_related($model_object_or_id, $query_params = array()) |
|
226 | - { |
|
227 | - // for each thing we would delete, |
|
228 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
229 | - // determine if it's blocked by anything else before it can be deleted |
|
230 | - $deleted_count = 0; |
|
231 | - foreach ($related_model_objects as $related_model_object) { |
|
232 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
233 | - $related_model_object, |
|
234 | - $model_object_or_id |
|
235 | - ); |
|
236 | - /* @var $model_object_or_id EE_Base_Class */ |
|
237 | - if (! $delete_is_blocked) { |
|
238 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
239 | - $related_model_object->delete(); |
|
240 | - $deleted_count++; |
|
241 | - } |
|
242 | - } |
|
243 | - return $deleted_count; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Deletes the related model objects which meet the query parameters. If no |
|
249 | - * parameters are specified, then all related model objects will be deleted. |
|
250 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
251 | - * model objects will only be soft-deleted. |
|
252 | - * |
|
253 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
254 | - * @param array $query_params |
|
255 | - * @return int of how many related models got deleted |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
259 | - { |
|
260 | - // for each thing we would delete, |
|
261 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
262 | - // determine if it's blocked by anything else before it can be deleted |
|
263 | - $deleted_count = 0; |
|
264 | - foreach ($related_model_objects as $related_model_object) { |
|
265 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
266 | - $related_model_object, |
|
267 | - $model_object_or_id |
|
268 | - ); |
|
269 | - /* @var $model_object_or_id EE_Base_Class */ |
|
270 | - if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
271 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
272 | - $deleted_count++; |
|
273 | - if (! $delete_is_blocked) { |
|
274 | - $related_model_object->delete_permanently(); |
|
275 | - } else { |
|
276 | - // delete is blocked |
|
277 | - // brent and darren, in this case, wanted to just soft delete it then |
|
278 | - $related_model_object->delete(); |
|
279 | - } |
|
280 | - } else { |
|
281 | - // its not a soft-deletable thing anyways. do the normal logic. |
|
282 | - if (! $delete_is_blocked) { |
|
283 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
284 | - $related_model_object->delete(); |
|
285 | - $deleted_count++; |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - return $deleted_count; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * this just returns a model_object_id for incoming item that could be an object or id. |
|
295 | - * |
|
296 | - * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
297 | - * @throws EE_Error |
|
298 | - * @return int |
|
299 | - */ |
|
300 | - protected function _get_model_object_id($model_object_or_id) |
|
301 | - { |
|
302 | - $model_object_id = $model_object_or_id; |
|
303 | - if ($model_object_or_id instanceof EE_Base_Class) { |
|
304 | - $model_object_id = $model_object_or_id->ID(); |
|
305 | - } |
|
306 | - if (! $model_object_id) { |
|
307 | - throw new EE_Error(sprintf( |
|
308 | - esc_html__( |
|
309 | - "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", |
|
310 | - "event_espresso" |
|
311 | - ), |
|
312 | - $this->get_other_model()->get_this_model_name(), |
|
313 | - $this->get_this_model()->get_this_model_name() |
|
314 | - )); |
|
315 | - } |
|
316 | - return $model_object_id; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * Gets the SQL string for performing the join between this model and the other model. |
|
322 | - * |
|
323 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
324 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
325 | - * other_model_primary_table.fk" etc |
|
326 | - */ |
|
327 | - abstract public function get_join_statement($model_relation_chain); |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
332 | - * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
333 | - * relationship only allows this model to be related to a single other model of this type) |
|
334 | - * |
|
335 | - * @param $this_obj_or_id |
|
336 | - * @param $other_obj_or_id |
|
337 | - * @param array $extra_join_model_fields_n_values |
|
338 | - * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
339 | - * $other_obj_or_id) |
|
340 | - */ |
|
341 | - abstract public function add_relation_to( |
|
342 | - $this_obj_or_id, |
|
343 | - $other_obj_or_id, |
|
344 | - $extra_join_model_fields_n_values = array() |
|
345 | - ); |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
350 | - * model objects |
|
351 | - * |
|
352 | - * @param $this_obj_or_id |
|
353 | - * @param $other_obj_or_id |
|
354 | - * @param array $where_query |
|
355 | - * @return bool |
|
356 | - */ |
|
357 | - abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Removes ALL relation instances for this relation obj |
|
362 | - * |
|
363 | - * @param EE_Base_Class|int $this_obj_or_id |
|
364 | - * @param array $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
365 | - * @return EE_Base_Class[] |
|
366 | - * @throws \EE_Error |
|
367 | - */ |
|
368 | - public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
369 | - { |
|
370 | - $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
371 | - $objs_removed = array(); |
|
372 | - foreach ($related_things as $related_thing) { |
|
373 | - $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
374 | - } |
|
375 | - return $objs_removed; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * If you aren't allowed to delete this model when there are related models across this |
|
381 | - * relation object, return true. Otherwise, if you can delete this model even though |
|
382 | - * related objects exist, returns false. |
|
383 | - * |
|
384 | - * @return boolean |
|
385 | - */ |
|
386 | - public function block_delete_if_related_models_exist() |
|
387 | - { |
|
388 | - return $this->_blocking_delete; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Gets the error message to show |
|
394 | - * |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function get_deletion_error_message() |
|
398 | - { |
|
399 | - if ($this->_blocking_delete_error_message) { |
|
400 | - return $this->_blocking_delete_error_message; |
|
401 | - } else { |
|
19 | + /** |
|
20 | + * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
21 | + * |
|
22 | + * @var string eg Event, Question_Group, Registration |
|
23 | + */ |
|
24 | + private $_this_model_name; |
|
25 | + /** |
|
26 | + * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
27 | + * |
|
28 | + * @var string eg Event, Question_Group, Registration |
|
29 | + */ |
|
30 | + private $_other_model_name; |
|
31 | + |
|
32 | + /** |
|
33 | + * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
34 | + * initiating model. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $_timezone; |
|
39 | + |
|
40 | + /** |
|
41 | + * If you try to delete "this_model", and there are related "other_models", |
|
42 | + * and this isn't null, then abandon the deletion and add this warning. |
|
43 | + * This effectively makes it impossible to delete "this_model" while there are |
|
44 | + * related "other_models" along this relation. |
|
45 | + * |
|
46 | + * @var string (internationalized) |
|
47 | + */ |
|
48 | + protected $_blocking_delete_error_message; |
|
49 | + |
|
50 | + protected $_blocking_delete = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * Object representing the relationship between two models. This knows how to join the models, |
|
54 | + * get related models across the relation, and add-and-remove the relationships. |
|
55 | + * |
|
56 | + * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
57 | + * and add an error) the deletion of this model |
|
58 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
59 | + * default |
|
60 | + */ |
|
61 | + public function __construct($block_deletes, $blocking_delete_error_message) |
|
62 | + { |
|
63 | + $this->_blocking_delete = $block_deletes; |
|
64 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param $this_model_name |
|
70 | + * @param $other_model_name |
|
71 | + * @throws EE_Error |
|
72 | + */ |
|
73 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
74 | + { |
|
75 | + $this->_this_model_name = $this_model_name; |
|
76 | + $this->_other_model_name = $other_model_name; |
|
77 | + if (is_string($this->_blocking_delete)) { |
|
78 | + throw new EE_Error(sprintf( |
|
79 | + esc_html__( |
|
80 | + "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
81 | + "event_espresso" |
|
82 | + ), |
|
83 | + get_class($this), |
|
84 | + $this_model_name, |
|
85 | + $other_model_name, |
|
86 | + $this->_blocking_delete |
|
87 | + )); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Gets the model where this relation is defined. |
|
94 | + * |
|
95 | + * @return EEM_Base |
|
96 | + */ |
|
97 | + public function get_this_model() |
|
98 | + { |
|
99 | + return $this->_get_model($this->_this_model_name); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Gets the model which this relation establishes the relation TO (ie, |
|
105 | + * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
106 | + * |
|
107 | + * @return EEM_Base |
|
108 | + */ |
|
109 | + public function get_other_model() |
|
110 | + { |
|
111 | + return $this->_get_model($this->_other_model_name); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Internally used by get_this_model() and get_other_model() |
|
117 | + * |
|
118 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
119 | + * @return EEM_Base |
|
120 | + */ |
|
121 | + protected function _get_model($model_name) |
|
122 | + { |
|
123 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
124 | + $modelInstance->set_timezone($this->_timezone); |
|
125 | + return $modelInstance; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
131 | + * timezone set correctly. |
|
132 | + * |
|
133 | + * @param string $timezone timezone to set. |
|
134 | + */ |
|
135 | + public function set_timezone($timezone) |
|
136 | + { |
|
137 | + if ($timezone !== null) { |
|
138 | + $this->_timezone = $timezone; |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $other_table |
|
145 | + * @param $other_table_alias |
|
146 | + * @param $other_table_column |
|
147 | + * @param $this_table_alias |
|
148 | + * @param $this_table_join_column |
|
149 | + * @param string $extra_join_sql |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + protected function _left_join( |
|
153 | + $other_table, |
|
154 | + $other_table_alias, |
|
155 | + $other_table_column, |
|
156 | + $this_table_alias, |
|
157 | + $this_table_join_column, |
|
158 | + $extra_join_sql = '' |
|
159 | + ) { |
|
160 | + 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" : ''); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Gets all the model objects of type of other model related to $model_object, |
|
166 | + * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
167 | + * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
168 | + * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
169 | + * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
170 | + * |
|
171 | + * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
172 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
173 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
174 | + * @return EE_Base_Class[] |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public function get_all_related( |
|
178 | + $model_object_or_id, |
|
179 | + $query_params = array(), |
|
180 | + $values_already_prepared_by_model_object = false |
|
181 | + ) { |
|
182 | + if ($values_already_prepared_by_model_object !== false) { |
|
183 | + EE_Error::doing_it_wrong( |
|
184 | + 'EE_Model_Relation_Base::get_all_related', |
|
185 | + esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
186 | + '4.8.1' |
|
187 | + ); |
|
188 | + } |
|
189 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
190 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
191 | + . "." |
|
192 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
193 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
194 | + $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
195 | + return $this->get_other_model()->get_all($query_params); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
201 | + * |
|
202 | + * @param string $query_params |
|
203 | + * @return array |
|
204 | + */ |
|
205 | + protected function _disable_default_where_conditions_on_query_param($query_params) |
|
206 | + { |
|
207 | + if (! isset($query_params['default_where_conditions'])) { |
|
208 | + $query_params['default_where_conditions'] = 'none'; |
|
209 | + } |
|
210 | + return $query_params; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Deletes the related model objects which meet the query parameters. If no |
|
216 | + * parameters are specified, then all related model objects will be deleted. |
|
217 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
218 | + * model objects will only be soft-deleted. |
|
219 | + * |
|
220 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
221 | + * @param array $query_params |
|
222 | + * @return int of how many related models got deleted |
|
223 | + * @throws \EE_Error |
|
224 | + */ |
|
225 | + public function delete_all_related($model_object_or_id, $query_params = array()) |
|
226 | + { |
|
227 | + // for each thing we would delete, |
|
228 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
229 | + // determine if it's blocked by anything else before it can be deleted |
|
230 | + $deleted_count = 0; |
|
231 | + foreach ($related_model_objects as $related_model_object) { |
|
232 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
233 | + $related_model_object, |
|
234 | + $model_object_or_id |
|
235 | + ); |
|
236 | + /* @var $model_object_or_id EE_Base_Class */ |
|
237 | + if (! $delete_is_blocked) { |
|
238 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
239 | + $related_model_object->delete(); |
|
240 | + $deleted_count++; |
|
241 | + } |
|
242 | + } |
|
243 | + return $deleted_count; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Deletes the related model objects which meet the query parameters. If no |
|
249 | + * parameters are specified, then all related model objects will be deleted. |
|
250 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
251 | + * model objects will only be soft-deleted. |
|
252 | + * |
|
253 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
254 | + * @param array $query_params |
|
255 | + * @return int of how many related models got deleted |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
259 | + { |
|
260 | + // for each thing we would delete, |
|
261 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
262 | + // determine if it's blocked by anything else before it can be deleted |
|
263 | + $deleted_count = 0; |
|
264 | + foreach ($related_model_objects as $related_model_object) { |
|
265 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
266 | + $related_model_object, |
|
267 | + $model_object_or_id |
|
268 | + ); |
|
269 | + /* @var $model_object_or_id EE_Base_Class */ |
|
270 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
271 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
272 | + $deleted_count++; |
|
273 | + if (! $delete_is_blocked) { |
|
274 | + $related_model_object->delete_permanently(); |
|
275 | + } else { |
|
276 | + // delete is blocked |
|
277 | + // brent and darren, in this case, wanted to just soft delete it then |
|
278 | + $related_model_object->delete(); |
|
279 | + } |
|
280 | + } else { |
|
281 | + // its not a soft-deletable thing anyways. do the normal logic. |
|
282 | + if (! $delete_is_blocked) { |
|
283 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
284 | + $related_model_object->delete(); |
|
285 | + $deleted_count++; |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + return $deleted_count; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * this just returns a model_object_id for incoming item that could be an object or id. |
|
295 | + * |
|
296 | + * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
297 | + * @throws EE_Error |
|
298 | + * @return int |
|
299 | + */ |
|
300 | + protected function _get_model_object_id($model_object_or_id) |
|
301 | + { |
|
302 | + $model_object_id = $model_object_or_id; |
|
303 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
304 | + $model_object_id = $model_object_or_id->ID(); |
|
305 | + } |
|
306 | + if (! $model_object_id) { |
|
307 | + throw new EE_Error(sprintf( |
|
308 | + esc_html__( |
|
309 | + "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", |
|
310 | + "event_espresso" |
|
311 | + ), |
|
312 | + $this->get_other_model()->get_this_model_name(), |
|
313 | + $this->get_this_model()->get_this_model_name() |
|
314 | + )); |
|
315 | + } |
|
316 | + return $model_object_id; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * Gets the SQL string for performing the join between this model and the other model. |
|
322 | + * |
|
323 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
324 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
325 | + * other_model_primary_table.fk" etc |
|
326 | + */ |
|
327 | + abstract public function get_join_statement($model_relation_chain); |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
332 | + * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
333 | + * relationship only allows this model to be related to a single other model of this type) |
|
334 | + * |
|
335 | + * @param $this_obj_or_id |
|
336 | + * @param $other_obj_or_id |
|
337 | + * @param array $extra_join_model_fields_n_values |
|
338 | + * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
339 | + * $other_obj_or_id) |
|
340 | + */ |
|
341 | + abstract public function add_relation_to( |
|
342 | + $this_obj_or_id, |
|
343 | + $other_obj_or_id, |
|
344 | + $extra_join_model_fields_n_values = array() |
|
345 | + ); |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
350 | + * model objects |
|
351 | + * |
|
352 | + * @param $this_obj_or_id |
|
353 | + * @param $other_obj_or_id |
|
354 | + * @param array $where_query |
|
355 | + * @return bool |
|
356 | + */ |
|
357 | + abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Removes ALL relation instances for this relation obj |
|
362 | + * |
|
363 | + * @param EE_Base_Class|int $this_obj_or_id |
|
364 | + * @param array $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
365 | + * @return EE_Base_Class[] |
|
366 | + * @throws \EE_Error |
|
367 | + */ |
|
368 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
369 | + { |
|
370 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
371 | + $objs_removed = array(); |
|
372 | + foreach ($related_things as $related_thing) { |
|
373 | + $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
374 | + } |
|
375 | + return $objs_removed; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * If you aren't allowed to delete this model when there are related models across this |
|
381 | + * relation object, return true. Otherwise, if you can delete this model even though |
|
382 | + * related objects exist, returns false. |
|
383 | + * |
|
384 | + * @return boolean |
|
385 | + */ |
|
386 | + public function block_delete_if_related_models_exist() |
|
387 | + { |
|
388 | + return $this->_blocking_delete; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Gets the error message to show |
|
394 | + * |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function get_deletion_error_message() |
|
398 | + { |
|
399 | + if ($this->_blocking_delete_error_message) { |
|
400 | + return $this->_blocking_delete_error_message; |
|
401 | + } else { |
|
402 | 402 | // return sprintf(esc_html__('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)); |
403 | - return sprintf( |
|
404 | - esc_html__( |
|
405 | - '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.', |
|
406 | - "event_espresso" |
|
407 | - ), |
|
408 | - $this->get_this_model()->item_name(1), |
|
409 | - $this->get_other_model()->item_name(1), |
|
410 | - $this->get_other_model()->item_name(2) |
|
411 | - ); |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Returns whatever is set as the nicename for the object. |
|
417 | - * |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public function getSchemaDescription() |
|
421 | - { |
|
422 | - $description = $this instanceof EE_Belongs_To_Relation |
|
423 | - ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
424 | - : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
425 | - return sprintf( |
|
426 | - $description, |
|
427 | - $this->get_other_model()->get_this_model_name(), |
|
428 | - $this->get_this_model()->get_this_model_name() |
|
429 | - ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Returns whatever is set as the $_schema_type property for the object. |
|
434 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
435 | - * |
|
436 | - * @return string|array |
|
437 | - */ |
|
438 | - public function getSchemaType() |
|
439 | - { |
|
440 | - return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
445 | - * this method and return the properties for the schema. |
|
446 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
447 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
448 | - * |
|
449 | - * @return array |
|
450 | - */ |
|
451 | - public function getSchemaProperties() |
|
452 | - { |
|
453 | - return array(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * If a child class has enum values, they should override this method and provide a simple array |
|
458 | - * of the enum values. |
|
459 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
460 | - * are set on the instantiated object that could be filtered after construct. |
|
461 | - * |
|
462 | - * @return array |
|
463 | - */ |
|
464 | - public function getSchemaEnum() |
|
465 | - { |
|
466 | - return array(); |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * This returns the value of the $_schema_format property on the object. |
|
471 | - * |
|
472 | - * @return string |
|
473 | - */ |
|
474 | - public function getSchemaFormat() |
|
475 | - { |
|
476 | - return array(); |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * This returns the value of the $_schema_readonly property on the object. |
|
481 | - * |
|
482 | - * @return bool |
|
483 | - */ |
|
484 | - public function getSchemaReadonly() |
|
485 | - { |
|
486 | - return true; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * This returns elements used to represent this field in the json schema. |
|
491 | - * |
|
492 | - * @link http://json-schema.org/ |
|
493 | - * @return array |
|
494 | - */ |
|
495 | - public function getSchema() |
|
496 | - { |
|
497 | - $schema = array( |
|
498 | - 'description' => $this->getSchemaDescription(), |
|
499 | - 'type' => $this->getSchemaType(), |
|
500 | - 'relation' => true, |
|
501 | - 'relation_type' => get_class($this), |
|
502 | - 'readonly' => $this->getSchemaReadonly() |
|
503 | - ); |
|
504 | - |
|
505 | - if ($this instanceof EE_HABTM_Relation) { |
|
506 | - $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
507 | - } |
|
508 | - |
|
509 | - if ($this->getSchemaType() === 'array') { |
|
510 | - $schema['items'] = array( |
|
511 | - 'type' => 'object' |
|
512 | - ); |
|
513 | - } |
|
514 | - |
|
515 | - return $schema; |
|
516 | - } |
|
403 | + return sprintf( |
|
404 | + esc_html__( |
|
405 | + '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.', |
|
406 | + "event_espresso" |
|
407 | + ), |
|
408 | + $this->get_this_model()->item_name(1), |
|
409 | + $this->get_other_model()->item_name(1), |
|
410 | + $this->get_other_model()->item_name(2) |
|
411 | + ); |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Returns whatever is set as the nicename for the object. |
|
417 | + * |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public function getSchemaDescription() |
|
421 | + { |
|
422 | + $description = $this instanceof EE_Belongs_To_Relation |
|
423 | + ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
424 | + : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
425 | + return sprintf( |
|
426 | + $description, |
|
427 | + $this->get_other_model()->get_this_model_name(), |
|
428 | + $this->get_this_model()->get_this_model_name() |
|
429 | + ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Returns whatever is set as the $_schema_type property for the object. |
|
434 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
435 | + * |
|
436 | + * @return string|array |
|
437 | + */ |
|
438 | + public function getSchemaType() |
|
439 | + { |
|
440 | + return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
445 | + * this method and return the properties for the schema. |
|
446 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
447 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
448 | + * |
|
449 | + * @return array |
|
450 | + */ |
|
451 | + public function getSchemaProperties() |
|
452 | + { |
|
453 | + return array(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * If a child class has enum values, they should override this method and provide a simple array |
|
458 | + * of the enum values. |
|
459 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
460 | + * are set on the instantiated object that could be filtered after construct. |
|
461 | + * |
|
462 | + * @return array |
|
463 | + */ |
|
464 | + public function getSchemaEnum() |
|
465 | + { |
|
466 | + return array(); |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * This returns the value of the $_schema_format property on the object. |
|
471 | + * |
|
472 | + * @return string |
|
473 | + */ |
|
474 | + public function getSchemaFormat() |
|
475 | + { |
|
476 | + return array(); |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * This returns the value of the $_schema_readonly property on the object. |
|
481 | + * |
|
482 | + * @return bool |
|
483 | + */ |
|
484 | + public function getSchemaReadonly() |
|
485 | + { |
|
486 | + return true; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * This returns elements used to represent this field in the json schema. |
|
491 | + * |
|
492 | + * @link http://json-schema.org/ |
|
493 | + * @return array |
|
494 | + */ |
|
495 | + public function getSchema() |
|
496 | + { |
|
497 | + $schema = array( |
|
498 | + 'description' => $this->getSchemaDescription(), |
|
499 | + 'type' => $this->getSchemaType(), |
|
500 | + 'relation' => true, |
|
501 | + 'relation_type' => get_class($this), |
|
502 | + 'readonly' => $this->getSchemaReadonly() |
|
503 | + ); |
|
504 | + |
|
505 | + if ($this instanceof EE_HABTM_Relation) { |
|
506 | + $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
507 | + } |
|
508 | + |
|
509 | + if ($this->getSchemaType() === 'array') { |
|
510 | + $schema['items'] = array( |
|
511 | + 'type' => 'object' |
|
512 | + ); |
|
513 | + } |
|
514 | + |
|
515 | + return $schema; |
|
516 | + } |
|
517 | 517 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this_table_join_column, |
158 | 158 | $extra_join_sql = '' |
159 | 159 | ) { |
160 | - 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" : ''); |
|
160 | + 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" : ''); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | . "." |
192 | 192 | . $this->get_this_model()->get_primary_key_field()->get_name(); |
193 | 193 | $model_object_id = $this->_get_model_object_id($model_object_or_id); |
194 | - $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
194 | + $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
195 | 195 | return $this->get_other_model()->get_all($query_params); |
196 | 196 | } |
197 | 197 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function _disable_default_where_conditions_on_query_param($query_params) |
206 | 206 | { |
207 | - if (! isset($query_params['default_where_conditions'])) { |
|
207 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
208 | 208 | $query_params['default_where_conditions'] = 'none'; |
209 | 209 | } |
210 | 210 | return $query_params; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $model_object_or_id |
235 | 235 | ); |
236 | 236 | /* @var $model_object_or_id EE_Base_Class */ |
237 | - if (! $delete_is_blocked) { |
|
237 | + if ( ! $delete_is_blocked) { |
|
238 | 238 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
239 | 239 | $related_model_object->delete(); |
240 | 240 | $deleted_count++; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
271 | 271 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
272 | 272 | $deleted_count++; |
273 | - if (! $delete_is_blocked) { |
|
273 | + if ( ! $delete_is_blocked) { |
|
274 | 274 | $related_model_object->delete_permanently(); |
275 | 275 | } else { |
276 | 276 | // delete is blocked |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | } |
280 | 280 | } else { |
281 | 281 | // its not a soft-deletable thing anyways. do the normal logic. |
282 | - if (! $delete_is_blocked) { |
|
282 | + if ( ! $delete_is_blocked) { |
|
283 | 283 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
284 | 284 | $related_model_object->delete(); |
285 | 285 | $deleted_count++; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | if ($model_object_or_id instanceof EE_Base_Class) { |
304 | 304 | $model_object_id = $model_object_or_id->ID(); |
305 | 305 | } |
306 | - if (! $model_object_id) { |
|
306 | + if ( ! $model_object_id) { |
|
307 | 307 | throw new EE_Error(sprintf( |
308 | 308 | esc_html__( |
309 | 309 | "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", |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get_base_type_name($base_type_int) |
44 | 44 | { |
45 | - return $this->base_types[ $base_type_int ]; |
|
45 | + return $this->base_types[$base_type_int]; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | 'WP_User' => new EE_Belongs_To_Relation(), |
96 | 96 | ); |
97 | 97 | // this model is generally available for reading |
98 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
98 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
99 | 99 | // all price types are "default" in terms of capability names |
100 | 100 | $this->_caps_slug = 'default_price_types'; |
101 | 101 | parent::__construct($timezone); |
@@ -142,15 +142,15 @@ discard block |
||
142 | 142 | $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
143 | 143 | $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
144 | 144 | |
145 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
145 | + $ID = $query_params[0][$this->get_primary_key_field()->get_name()]; |
|
146 | 146 | |
147 | 147 | // check if any prices use this price type |
148 | - $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids))); |
|
148 | + $prc_query_params = array(array('PRT_ID' => array('IN', $would_be_deleted_price_type_ids))); |
|
149 | 149 | if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
150 | 150 | $prices_names_and_ids = array(); |
151 | 151 | foreach ($prices as $price) { |
152 | 152 | /* @var $price EE_Price */ |
153 | - $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
153 | + $prices_names_and_ids[] = $price->name()."(".$price->ID().")"; |
|
154 | 154 | } |
155 | 155 | $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids)); |
156 | 156 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -11,142 +11,142 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Price_Type extends EEM_Soft_Delete_Base |
13 | 13 | { |
14 | - // private instance of the Price Type object |
|
15 | - protected static $_instance = null; |
|
16 | - // An array of the price type objects |
|
17 | - public $type = null; |
|
14 | + // private instance of the Price Type object |
|
15 | + protected static $_instance = null; |
|
16 | + // An array of the price type objects |
|
17 | + public $type = null; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Price Base types |
|
21 | - * |
|
22 | - * @access private |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - public $base_types = null; |
|
19 | + /** |
|
20 | + * Price Base types |
|
21 | + * |
|
22 | + * @access private |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + public $base_types = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * return an array of Base types. Keys are INTs which are used in the database, |
|
29 | - * values are text-representations of the base type. |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function get_base_types() |
|
33 | - { |
|
34 | - return $this->base_types; |
|
35 | - } |
|
27 | + /** |
|
28 | + * return an array of Base types. Keys are INTs which are used in the database, |
|
29 | + * values are text-representations of the base type. |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function get_base_types() |
|
33 | + { |
|
34 | + return $this->base_types; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Gets the name of the base |
|
39 | - * @param type $base_type_int |
|
40 | - * @return type |
|
41 | - */ |
|
42 | - public function get_base_type_name($base_type_int) |
|
43 | - { |
|
44 | - return $this->base_types[ $base_type_int ]; |
|
45 | - } |
|
37 | + /** |
|
38 | + * Gets the name of the base |
|
39 | + * @param type $base_type_int |
|
40 | + * @return type |
|
41 | + */ |
|
42 | + public function get_base_type_name($base_type_int) |
|
43 | + { |
|
44 | + return $this->base_types[ $base_type_int ]; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * constants for price base types. In the DB, we decided to store the price base type |
|
49 | - * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for |
|
50 | - * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
51 | - * So, as an example, to query for all price types that are a tax, we'd do |
|
52 | - * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
53 | - * instead of |
|
54 | - * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
55 | - * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
56 | - * change, we can continue to use the constant, by simply change its value. |
|
57 | - */ |
|
58 | - const base_type_base_price = 1; |
|
59 | - const base_type_discount = 2; |
|
60 | - const base_type_surcharge = 3; |
|
61 | - const base_type_tax = 4; |
|
62 | - /** |
|
63 | - * private constructor to prevent direct creation |
|
64 | - * @Constructor |
|
65 | - * @access protected |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - protected function __construct($timezone = null) |
|
69 | - { |
|
70 | - $this->base_types = array( |
|
71 | - EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'), |
|
72 | - EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'), |
|
73 | - EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'), |
|
74 | - EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') ); |
|
75 | - $this->singular_item = esc_html__('Price Type', 'event_espresso'); |
|
76 | - $this->plural_item = esc_html__('Price Types', 'event_espresso'); |
|
47 | + /** |
|
48 | + * constants for price base types. In the DB, we decided to store the price base type |
|
49 | + * as an integer. So, to avoid just having magic numbers everwhere (eg, querying for |
|
50 | + * all price types with PBT_ID = 2), we define these constants, to make code more understandable. |
|
51 | + * So, as an example, to query for all price types that are a tax, we'd do |
|
52 | + * EEM_PRice_Type::instance()->get_all(array(array('PBT_ID'=>EEM_Price_Type::base_type_tax))) |
|
53 | + * instead of |
|
54 | + * EEM_Price_Type::instance()->get_all(array(array('PBT_ID'=>2))) |
|
55 | + * Although the 2nd is shorter, it's much less obvious what it's doing. Also, should these magic IDs ever |
|
56 | + * change, we can continue to use the constant, by simply change its value. |
|
57 | + */ |
|
58 | + const base_type_base_price = 1; |
|
59 | + const base_type_discount = 2; |
|
60 | + const base_type_surcharge = 3; |
|
61 | + const base_type_tax = 4; |
|
62 | + /** |
|
63 | + * private constructor to prevent direct creation |
|
64 | + * @Constructor |
|
65 | + * @access protected |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + protected function __construct($timezone = null) |
|
69 | + { |
|
70 | + $this->base_types = array( |
|
71 | + EEM_Price_Type::base_type_base_price => esc_html__('Price', 'event_espresso'), |
|
72 | + EEM_Price_Type::base_type_discount => esc_html__('Discount', 'event_espresso'), |
|
73 | + EEM_Price_Type::base_type_surcharge => esc_html__('Surcharge', 'event_espresso'), |
|
74 | + EEM_Price_Type::base_type_tax => esc_html__('Tax', 'event_espresso') ); |
|
75 | + $this->singular_item = esc_html__('Price Type', 'event_espresso'); |
|
76 | + $this->plural_item = esc_html__('Price Types', 'event_espresso'); |
|
77 | 77 | |
78 | - $this->_tables = array( |
|
79 | - 'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID') |
|
80 | - ); |
|
81 | - $this->_fields = array( |
|
82 | - 'Price_Type' => array( |
|
83 | - 'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')), |
|
84 | - 'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''), |
|
85 | - 'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types), |
|
86 | - 'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false), |
|
87 | - 'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0), |
|
88 | - 'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false), |
|
89 | - 'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false), |
|
90 | - ) |
|
91 | - ); |
|
92 | - $this->_model_relations = array( |
|
93 | - 'Price' => new EE_Has_Many_Relation(), |
|
94 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
95 | - ); |
|
96 | - // this model is generally available for reading |
|
97 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
98 | - // all price types are "default" in terms of capability names |
|
99 | - $this->_caps_slug = 'default_price_types'; |
|
100 | - parent::__construct($timezone); |
|
101 | - } |
|
78 | + $this->_tables = array( |
|
79 | + 'Price_Type' => new EE_Primary_Table('esp_price_type', 'PRT_ID') |
|
80 | + ); |
|
81 | + $this->_fields = array( |
|
82 | + 'Price_Type' => array( |
|
83 | + 'PRT_ID' => new EE_Primary_Key_Int_Field('PRT_ID', esc_html__('Price Type ID', 'event_espresso')), |
|
84 | + 'PRT_name' => new EE_Plain_Text_Field('PRT_name', esc_html__('Price Type Name', 'event_espresso'), false, ''), |
|
85 | + 'PBT_ID' => new EE_Enum_Integer_Field('PBT_ID', esc_html__('Price Base type ID, 1 = Price , 2 = Discount , 3 = Surcharge , 4 = Tax', 'event_espresso'), false, EEM_Price_Type::base_type_base_price, $this->base_types), |
|
86 | + 'PRT_is_percent' => new EE_Boolean_Field('PRT_is_percent', esc_html__('Flag indicating price is a percentage', 'event_espresso'), false, false), |
|
87 | + 'PRT_order' => new EE_Integer_Field('PRT_order', esc_html__('Order in which price should be applied. ', 'event_espresso'), false, 0), |
|
88 | + 'PRT_deleted' => new EE_Trashed_Flag_Field('PRT_deleted', esc_html__('Flag indicating price type has been trashed', 'event_espresso'), false, false), |
|
89 | + 'PRT_wp_user' => new EE_WP_User_Field('PRT_wp_user', esc_html__('Price Type Creator ID', 'event_espresso'), false), |
|
90 | + ) |
|
91 | + ); |
|
92 | + $this->_model_relations = array( |
|
93 | + 'Price' => new EE_Has_Many_Relation(), |
|
94 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
95 | + ); |
|
96 | + // this model is generally available for reading |
|
97 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
98 | + // all price types are "default" in terms of capability names |
|
99 | + $this->_caps_slug = 'default_price_types'; |
|
100 | + parent::__construct($timezone); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * instantiate a new price type object with blank/empty properties |
|
108 | - * |
|
109 | - * @access public |
|
110 | - * @return mixed array on success, FALSE on fail |
|
111 | - */ |
|
112 | - public function get_new_price_type() |
|
113 | - { |
|
114 | - return EE_Price_Type::new_instance(); |
|
115 | - } |
|
106 | + /** |
|
107 | + * instantiate a new price type object with blank/empty properties |
|
108 | + * |
|
109 | + * @access public |
|
110 | + * @return mixed array on success, FALSE on fail |
|
111 | + */ |
|
112 | + public function get_new_price_type() |
|
113 | + { |
|
114 | + return EE_Price_Type::new_instance(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * |
|
120 | - * @param array $query_params |
|
121 | - * @param bool $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
122 | - * that blocks it (ie, there' sno other data that depends on this data); |
|
123 | - * if false, deletes regardless of other objects which may depend on it. |
|
124 | - * Its generally advisable to always leave this as TRUE, |
|
125 | - * otherwise you could easily corrupt your DB |
|
126 | - * @return bool |
|
127 | - * @throws EE_Error |
|
128 | - * @throws ReflectionException |
|
129 | - */ |
|
130 | - public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
131 | - { |
|
132 | - $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
133 | - $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
118 | + /** |
|
119 | + * |
|
120 | + * @param array $query_params |
|
121 | + * @param bool $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info |
|
122 | + * that blocks it (ie, there' sno other data that depends on this data); |
|
123 | + * if false, deletes regardless of other objects which may depend on it. |
|
124 | + * Its generally advisable to always leave this as TRUE, |
|
125 | + * otherwise you could easily corrupt your DB |
|
126 | + * @return bool |
|
127 | + * @throws EE_Error |
|
128 | + * @throws ReflectionException |
|
129 | + */ |
|
130 | + public function delete_permanently($query_params = array(), $allow_blocking = true) |
|
131 | + { |
|
132 | + $would_be_deleted_price_types = $this->get_all_deleted_and_undeleted($query_params); |
|
133 | + $would_be_deleted_price_type_ids = array_keys($would_be_deleted_price_types); |
|
134 | 134 | |
135 | - $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
135 | + $ID = $query_params[0][ $this->get_primary_key_field()->get_name() ]; |
|
136 | 136 | |
137 | - // check if any prices use this price type |
|
138 | - $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids))); |
|
139 | - if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
140 | - $prices_names_and_ids = array(); |
|
141 | - foreach ($prices as $price) { |
|
142 | - /* @var $price EE_Price */ |
|
143 | - $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
144 | - } |
|
145 | - $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids)); |
|
146 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
147 | - return false; |
|
148 | - } |
|
137 | + // check if any prices use this price type |
|
138 | + $prc_query_params = array(array('PRT_ID' => array('IN',$would_be_deleted_price_type_ids))); |
|
139 | + if ($prices = $this->get_all_related($ID, 'Price', $prc_query_params)) { |
|
140 | + $prices_names_and_ids = array(); |
|
141 | + foreach ($prices as $price) { |
|
142 | + /* @var $price EE_Price */ |
|
143 | + $prices_names_and_ids[] = $price->name() . "(" . $price->ID() . ")"; |
|
144 | + } |
|
145 | + $msg = sprintf(esc_html__('The Price Type(s) could not be deleted because there are existing Prices that currently use this Price Type. If you still wish to delete this Price Type, then either delete those Prices or change them to use other Price Types.The prices are: %s', 'event_espresso'), implode(",", $prices_names_and_ids)); |
|
146 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
147 | + return false; |
|
148 | + } |
|
149 | 149 | |
150 | - return parent::delete_permanently($query_params); |
|
151 | - } |
|
150 | + return parent::delete_permanently($query_params); |
|
151 | + } |
|
152 | 152 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | false, |
36 | 36 | 'event', |
37 | 37 | array( |
38 | - 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | + 'event' => esc_html__("Event", "event_espresso"), // deprecated |
|
39 | 39 | 'registration' => esc_html__("Registration", "event_espresso"), |
40 | 40 | 'transaction' => esc_html__("Transaction", "event_espresso"), |
41 | 41 | 'payment' => esc_html__("Payment", "event_espresso"), |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'Payment' => new EE_Has_Many_Relation(), |
55 | 55 | ); |
56 | 56 | // this model is generally available for reading |
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
57 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
58 | 58 | |
59 | 59 | parent::__construct($timezone); |
60 | 60 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
269 | 269 | |
270 | - if (! is_array($statuses)) { |
|
270 | + if ( ! is_array($statuses)) { |
|
271 | 271 | throw new EE_Error(esc_html__( |
272 | 272 | 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
273 | 273 | 'event_espresso' |
@@ -277,22 +277,22 @@ discard block |
||
277 | 277 | $translation = array(); |
278 | 278 | |
279 | 279 | foreach ($statuses as $id => $code) { |
280 | - if (isset($translation_array[ $id ])) { |
|
281 | - $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
280 | + if (isset($translation_array[$id])) { |
|
281 | + $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0]; |
|
282 | 282 | } else { |
283 | - $translation[ $id ] = $code; |
|
283 | + $translation[$id] = $code; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // schema |
287 | 287 | switch ($schema) { |
288 | 288 | case 'lower': |
289 | - $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | + $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter. |
|
290 | 290 | break; |
291 | 291 | case 'sentence': |
292 | - $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | + $translation[$id] = ucwords($translation[$id]); |
|
293 | 293 | break; |
294 | 294 | case 'upper': |
295 | - $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | + $translation[$id] = strtoupper($translation[$id]); |
|
296 | 296 | break; |
297 | 297 | } |
298 | 298 | } |
@@ -10,292 +10,292 @@ |
||
10 | 10 | */ |
11 | 11 | class EEM_Status extends EEM_Base |
12 | 12 | { |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @return EEM_Status |
|
19 | - */ |
|
20 | - protected function __construct($timezone = null) |
|
21 | - { |
|
22 | - $this->singular_item = esc_html__('Status', 'event_espresso'); |
|
23 | - $this->plural_item = esc_html__('Stati', 'event_espresso'); |
|
24 | - $this->_tables = array( |
|
25 | - 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
26 | - ); |
|
27 | - $this->_fields = array( |
|
28 | - 'StatusTable' => array( |
|
29 | - 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')), |
|
30 | - 'STS_code' => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''), |
|
31 | - 'STS_type' => new EE_Enum_Text_Field( |
|
32 | - 'STS_type', |
|
33 | - esc_html__("Type", "event_espresso"), |
|
34 | - false, |
|
35 | - 'event', |
|
36 | - array( |
|
37 | - 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | - 'registration' => esc_html__("Registration", "event_espresso"), |
|
39 | - 'transaction' => esc_html__("Transaction", "event_espresso"), |
|
40 | - 'payment' => esc_html__("Payment", "event_espresso"), |
|
41 | - 'email' => esc_html__("Email", "event_espresso"), |
|
42 | - 'message' => esc_html__("Message", "event_espresso"), |
|
43 | - ) |
|
44 | - ), |
|
45 | - 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false), |
|
46 | - 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''), |
|
47 | - 'STS_open' => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false), |
|
48 | - ), |
|
49 | - ); |
|
50 | - $this->_model_relations = array( |
|
51 | - 'Registration' => new EE_Has_Many_Relation(), |
|
52 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
53 | - 'Payment' => new EE_Has_Many_Relation(), |
|
54 | - ); |
|
55 | - // this model is generally available for reading |
|
56 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
17 | + /** |
|
18 | + * @return EEM_Status |
|
19 | + */ |
|
20 | + protected function __construct($timezone = null) |
|
21 | + { |
|
22 | + $this->singular_item = esc_html__('Status', 'event_espresso'); |
|
23 | + $this->plural_item = esc_html__('Stati', 'event_espresso'); |
|
24 | + $this->_tables = array( |
|
25 | + 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
26 | + ); |
|
27 | + $this->_fields = array( |
|
28 | + 'StatusTable' => array( |
|
29 | + 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', esc_html__('Status ID', 'event_espresso')), |
|
30 | + 'STS_code' => new EE_Plain_Text_Field('STS_code', esc_html__('Status Code', 'event_espresso'), false, ''), |
|
31 | + 'STS_type' => new EE_Enum_Text_Field( |
|
32 | + 'STS_type', |
|
33 | + esc_html__("Type", "event_espresso"), |
|
34 | + false, |
|
35 | + 'event', |
|
36 | + array( |
|
37 | + 'event' => esc_html__("Event", "event_espresso"),// deprecated |
|
38 | + 'registration' => esc_html__("Registration", "event_espresso"), |
|
39 | + 'transaction' => esc_html__("Transaction", "event_espresso"), |
|
40 | + 'payment' => esc_html__("Payment", "event_espresso"), |
|
41 | + 'email' => esc_html__("Email", "event_espresso"), |
|
42 | + 'message' => esc_html__("Message", "event_espresso"), |
|
43 | + ) |
|
44 | + ), |
|
45 | + 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', esc_html__('Editable?', 'event_espresso'), false, false), |
|
46 | + 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', esc_html__("Description", "event_espresso"), false, ''), |
|
47 | + 'STS_open' => new EE_Boolean_Field('STS_open', esc_html__("Open?", "event_espresso"), false, false), |
|
48 | + ), |
|
49 | + ); |
|
50 | + $this->_model_relations = array( |
|
51 | + 'Registration' => new EE_Has_Many_Relation(), |
|
52 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
53 | + 'Payment' => new EE_Has_Many_Relation(), |
|
54 | + ); |
|
55 | + // this model is generally available for reading |
|
56 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
57 | 57 | |
58 | - parent::__construct($timezone); |
|
59 | - } |
|
58 | + parent::__construct($timezone); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * This method provides the localized singular or plural string for a given status id |
|
64 | - * |
|
65 | - * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
66 | - * That way if there isn't a translation in the index we'll return the default code. |
|
67 | - * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
68 | - * same as the singular (in English), however, this may NOT be the case with other |
|
69 | - * languages |
|
70 | - * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
71 | - * the status string returned ( UPPER, lower, Sentence) |
|
72 | - * @throws EE_Error |
|
73 | - * @return array an array of translated strings for the incoming status id. |
|
74 | - */ |
|
75 | - public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
76 | - { |
|
77 | - // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
78 | - $translation_array = array( |
|
79 | - EEM_Registration::status_id_pending_payment => array( |
|
80 | - esc_html__('pending payment', 'event_espresso'), // singular |
|
81 | - esc_html__('pending payments', 'event_espresso') // plural |
|
82 | - ), |
|
83 | - EEM_Registration::status_id_approved => array( |
|
84 | - esc_html__('approved', 'event_espresso'), // singular |
|
85 | - esc_html__('approved', 'event_espresso') // plural |
|
86 | - ), |
|
87 | - EEM_Registration::status_id_not_approved => array( |
|
88 | - esc_html__('not approved', 'event_espresso'), |
|
89 | - esc_html__('not approved', 'event_espresso'), |
|
90 | - ), |
|
91 | - EEM_Registration::status_id_cancelled => array( |
|
92 | - esc_html__('cancelled', 'event_espresso'), |
|
93 | - esc_html__('cancelled', 'event_espresso'), |
|
94 | - ), |
|
95 | - EEM_Registration::status_id_incomplete => array( |
|
96 | - esc_html__('incomplete', 'event_espresso'), |
|
97 | - esc_html__('incomplete', 'event_espresso'), |
|
98 | - ), |
|
99 | - EEM_Registration::status_id_declined => array( |
|
100 | - esc_html__('declined', 'event_espresso'), |
|
101 | - esc_html__('declined', 'event_espresso'), |
|
102 | - ), |
|
103 | - EEM_Registration::status_id_wait_list => array( |
|
104 | - esc_html__('wait list', 'event_espresso'), |
|
105 | - esc_html__('wait list', 'event_espresso'), |
|
106 | - ), |
|
107 | - EEM_Transaction::overpaid_status_code => array( |
|
108 | - esc_html__('overpaid', 'event_espresso'), |
|
109 | - esc_html__('overpaid', 'event_espresso'), |
|
110 | - ), |
|
111 | - EEM_Transaction::complete_status_code => array( |
|
112 | - esc_html__('complete', 'event_espresso'), |
|
113 | - esc_html__('complete', 'event_espresso'), |
|
114 | - ), |
|
115 | - EEM_Transaction::incomplete_status_code => array( |
|
116 | - esc_html__('incomplete', 'event_espresso'), |
|
117 | - esc_html__('incomplete', 'event_espresso'), |
|
118 | - ), |
|
119 | - EEM_Transaction::failed_status_code => array( |
|
120 | - esc_html__('failed', 'event_espresso'), |
|
121 | - esc_html__('failed', 'event_espresso'), |
|
122 | - ), |
|
123 | - EEM_Transaction::abandoned_status_code => array( |
|
124 | - esc_html__('abandoned', 'event_espresso'), |
|
125 | - esc_html__('abandoned', 'event_espresso'), |
|
126 | - ), |
|
127 | - EEM_Payment::status_id_approved => array( |
|
128 | - esc_html__('accepted', 'event_espresso'), |
|
129 | - esc_html__('accepted', 'event_espresso'), |
|
130 | - ), |
|
131 | - EEM_Payment::status_id_pending => array( |
|
132 | - esc_html__('pending', 'event_espresso'), |
|
133 | - esc_html__('pending', 'event_espresso'), |
|
134 | - ), |
|
135 | - EEM_Payment::status_id_cancelled => array( |
|
136 | - esc_html__('cancelled', 'event_espresso'), |
|
137 | - esc_html__('cancelled', 'event_espresso'), |
|
138 | - ), |
|
139 | - EEM_Payment::status_id_declined => array( |
|
140 | - esc_html__('declined', 'event_espresso'), |
|
141 | - esc_html__('declined', 'event_espresso'), |
|
142 | - ), |
|
143 | - EEM_Payment::status_id_failed => array( |
|
144 | - esc_html__('failed', 'event_espresso'), |
|
145 | - esc_html__('failed', 'event_espresso'), |
|
146 | - ), |
|
147 | - // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
148 | - EEM_Event::sold_out => array( |
|
149 | - esc_html__('sold out', 'event_espresso'), |
|
150 | - esc_html__('sold out', 'event_espresso'), |
|
151 | - ), |
|
152 | - EEM_Event::postponed => array( |
|
153 | - esc_html__('postponed', 'event_espresso'), |
|
154 | - esc_html__('Postponed', 'event_espresso'), |
|
155 | - ), |
|
156 | - EEM_Event::cancelled => array( |
|
157 | - esc_html__('cancelled', 'event_espresso'), |
|
158 | - esc_html__('cancelled', 'event_espresso'), |
|
159 | - ), |
|
160 | - EE_Ticket::archived => array( |
|
161 | - esc_html__('archived', 'event_espresso'), |
|
162 | - esc_html__('archived', 'event_espresso'), |
|
163 | - ), |
|
164 | - EE_Ticket::expired => array( |
|
165 | - esc_html__('expired', 'event_espresso'), |
|
166 | - esc_html__('expired', 'event_espresso'), |
|
167 | - ), |
|
168 | - EE_Ticket::sold_out => array( |
|
169 | - esc_html__('sold out', 'event_espresso'), |
|
170 | - esc_html__('sold out', 'event_espresso'), |
|
171 | - ), |
|
172 | - EE_Ticket::pending => array( |
|
173 | - esc_html__('upcoming', 'event_espresso'), |
|
174 | - esc_html__('upcoming', 'event_espresso'), |
|
175 | - ), |
|
176 | - EE_Ticket::onsale => array( |
|
177 | - esc_html__('on sale', 'event_espresso'), |
|
178 | - esc_html__('on sale', 'event_espresso'), |
|
179 | - ), |
|
180 | - EE_Datetime::cancelled => array( |
|
181 | - esc_html__('cancelled', 'event_espresso'), |
|
182 | - esc_html__('cancelled', 'event_espresso'), |
|
183 | - ), |
|
184 | - EE_Datetime::sold_out => array( |
|
185 | - esc_html__('sold out', 'event_espresso'), |
|
186 | - esc_html__('sold out', 'event_espresso'), |
|
187 | - ), |
|
188 | - EE_Datetime::expired => array( |
|
189 | - esc_html__('expired', 'event_espresso'), |
|
190 | - esc_html__('expired', 'event_espresso'), |
|
191 | - ), |
|
192 | - EE_Datetime::inactive => array( |
|
193 | - esc_html__('inactive', 'event_espresso'), |
|
194 | - esc_html__('inactive', 'event_espresso'), |
|
195 | - ), |
|
196 | - EE_Datetime::upcoming => array( |
|
197 | - esc_html__('upcoming', 'event_espresso'), |
|
198 | - esc_html__('upcoming', 'event_espresso'), |
|
199 | - ), |
|
200 | - EE_Datetime::active => array( |
|
201 | - esc_html__('active', 'event_espresso'), |
|
202 | - esc_html__('active', 'event_espresso'), |
|
203 | - ), |
|
204 | - EE_Datetime::postponed => array( |
|
205 | - esc_html__('postponed', 'event_espresso'), |
|
206 | - esc_html__('postponed', 'event_espresso'), |
|
207 | - ), |
|
208 | - // messages related |
|
209 | - EEM_Message::status_sent => array( |
|
210 | - esc_html__('sent', 'event_espresso'), |
|
211 | - esc_html__('sent', 'event_espresso'), |
|
212 | - ), |
|
213 | - EEM_Message::status_idle => array( |
|
214 | - esc_html__('queued for sending', 'event_espresso'), |
|
215 | - esc_html__('queued for sending', 'event_espresso'), |
|
216 | - ), |
|
217 | - EEM_Message::status_failed => array( |
|
218 | - esc_html__('failed', 'event_espresso'), |
|
219 | - esc_html__('failed', 'event_espresso'), |
|
220 | - ), |
|
221 | - EEM_Message::status_debug_only => array( |
|
222 | - esc_html__('debug only', 'event_espresso'), |
|
223 | - esc_html__('debug only', 'event_espresso'), |
|
224 | - ), |
|
225 | - EEM_Message::status_messenger_executing => array( |
|
226 | - esc_html__('messenger is executing', 'event_espresso'), |
|
227 | - esc_html__('messenger is executing', 'event_espresso'), |
|
228 | - ), |
|
229 | - EEM_Message::status_resend => array( |
|
230 | - esc_html__('queued for resending', 'event_espresso'), |
|
231 | - esc_html__('queued for resending', 'event_espresso'), |
|
232 | - ), |
|
233 | - EEM_Message::status_incomplete => array( |
|
234 | - esc_html__('queued for generating', 'event_espresso'), |
|
235 | - esc_html__('queued for generating', 'event_espresso'), |
|
236 | - ), |
|
237 | - EEM_Message::status_retry => array( |
|
238 | - esc_html__('failed sending, can be retried', 'event_espresso'), |
|
239 | - esc_html__('failed sending, can be retried', 'event_espresso'), |
|
240 | - ), |
|
241 | - EEM_CPT_Base::post_status_publish => array( |
|
242 | - esc_html__('published', 'event_espresso'), |
|
243 | - esc_html__('published', 'event_espresso'), |
|
244 | - ), |
|
245 | - EEM_CPT_Base::post_status_future => array( |
|
246 | - esc_html__('scheduled', 'event_espresso'), |
|
247 | - esc_html__('scheduled', 'event_espresso'), |
|
248 | - ), |
|
249 | - EEM_CPT_Base::post_status_draft => array( |
|
250 | - esc_html__('draft', 'event_espresso'), |
|
251 | - esc_html__('draft', 'event_espresso'), |
|
252 | - ), |
|
253 | - EEM_CPT_Base::post_status_pending => array( |
|
254 | - esc_html__('pending', 'event_espresso'), |
|
255 | - esc_html__('pending', 'event_espresso'), |
|
256 | - ), |
|
257 | - EEM_CPT_Base::post_status_private => array( |
|
258 | - esc_html__('private', 'event_espresso'), |
|
259 | - esc_html__('private', 'event_espresso'), |
|
260 | - ), |
|
261 | - EEM_CPT_Base::post_status_trashed => array( |
|
262 | - esc_html__('trashed', 'event_espresso'), |
|
263 | - esc_html__('trashed', 'event_espresso'), |
|
264 | - ), |
|
265 | - ); |
|
62 | + /** |
|
63 | + * This method provides the localized singular or plural string for a given status id |
|
64 | + * |
|
65 | + * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
66 | + * That way if there isn't a translation in the index we'll return the default code. |
|
67 | + * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
68 | + * same as the singular (in English), however, this may NOT be the case with other |
|
69 | + * languages |
|
70 | + * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
71 | + * the status string returned ( UPPER, lower, Sentence) |
|
72 | + * @throws EE_Error |
|
73 | + * @return array an array of translated strings for the incoming status id. |
|
74 | + */ |
|
75 | + public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
76 | + { |
|
77 | + // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
78 | + $translation_array = array( |
|
79 | + EEM_Registration::status_id_pending_payment => array( |
|
80 | + esc_html__('pending payment', 'event_espresso'), // singular |
|
81 | + esc_html__('pending payments', 'event_espresso') // plural |
|
82 | + ), |
|
83 | + EEM_Registration::status_id_approved => array( |
|
84 | + esc_html__('approved', 'event_espresso'), // singular |
|
85 | + esc_html__('approved', 'event_espresso') // plural |
|
86 | + ), |
|
87 | + EEM_Registration::status_id_not_approved => array( |
|
88 | + esc_html__('not approved', 'event_espresso'), |
|
89 | + esc_html__('not approved', 'event_espresso'), |
|
90 | + ), |
|
91 | + EEM_Registration::status_id_cancelled => array( |
|
92 | + esc_html__('cancelled', 'event_espresso'), |
|
93 | + esc_html__('cancelled', 'event_espresso'), |
|
94 | + ), |
|
95 | + EEM_Registration::status_id_incomplete => array( |
|
96 | + esc_html__('incomplete', 'event_espresso'), |
|
97 | + esc_html__('incomplete', 'event_espresso'), |
|
98 | + ), |
|
99 | + EEM_Registration::status_id_declined => array( |
|
100 | + esc_html__('declined', 'event_espresso'), |
|
101 | + esc_html__('declined', 'event_espresso'), |
|
102 | + ), |
|
103 | + EEM_Registration::status_id_wait_list => array( |
|
104 | + esc_html__('wait list', 'event_espresso'), |
|
105 | + esc_html__('wait list', 'event_espresso'), |
|
106 | + ), |
|
107 | + EEM_Transaction::overpaid_status_code => array( |
|
108 | + esc_html__('overpaid', 'event_espresso'), |
|
109 | + esc_html__('overpaid', 'event_espresso'), |
|
110 | + ), |
|
111 | + EEM_Transaction::complete_status_code => array( |
|
112 | + esc_html__('complete', 'event_espresso'), |
|
113 | + esc_html__('complete', 'event_espresso'), |
|
114 | + ), |
|
115 | + EEM_Transaction::incomplete_status_code => array( |
|
116 | + esc_html__('incomplete', 'event_espresso'), |
|
117 | + esc_html__('incomplete', 'event_espresso'), |
|
118 | + ), |
|
119 | + EEM_Transaction::failed_status_code => array( |
|
120 | + esc_html__('failed', 'event_espresso'), |
|
121 | + esc_html__('failed', 'event_espresso'), |
|
122 | + ), |
|
123 | + EEM_Transaction::abandoned_status_code => array( |
|
124 | + esc_html__('abandoned', 'event_espresso'), |
|
125 | + esc_html__('abandoned', 'event_espresso'), |
|
126 | + ), |
|
127 | + EEM_Payment::status_id_approved => array( |
|
128 | + esc_html__('accepted', 'event_espresso'), |
|
129 | + esc_html__('accepted', 'event_espresso'), |
|
130 | + ), |
|
131 | + EEM_Payment::status_id_pending => array( |
|
132 | + esc_html__('pending', 'event_espresso'), |
|
133 | + esc_html__('pending', 'event_espresso'), |
|
134 | + ), |
|
135 | + EEM_Payment::status_id_cancelled => array( |
|
136 | + esc_html__('cancelled', 'event_espresso'), |
|
137 | + esc_html__('cancelled', 'event_espresso'), |
|
138 | + ), |
|
139 | + EEM_Payment::status_id_declined => array( |
|
140 | + esc_html__('declined', 'event_espresso'), |
|
141 | + esc_html__('declined', 'event_espresso'), |
|
142 | + ), |
|
143 | + EEM_Payment::status_id_failed => array( |
|
144 | + esc_html__('failed', 'event_espresso'), |
|
145 | + esc_html__('failed', 'event_espresso'), |
|
146 | + ), |
|
147 | + // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
148 | + EEM_Event::sold_out => array( |
|
149 | + esc_html__('sold out', 'event_espresso'), |
|
150 | + esc_html__('sold out', 'event_espresso'), |
|
151 | + ), |
|
152 | + EEM_Event::postponed => array( |
|
153 | + esc_html__('postponed', 'event_espresso'), |
|
154 | + esc_html__('Postponed', 'event_espresso'), |
|
155 | + ), |
|
156 | + EEM_Event::cancelled => array( |
|
157 | + esc_html__('cancelled', 'event_espresso'), |
|
158 | + esc_html__('cancelled', 'event_espresso'), |
|
159 | + ), |
|
160 | + EE_Ticket::archived => array( |
|
161 | + esc_html__('archived', 'event_espresso'), |
|
162 | + esc_html__('archived', 'event_espresso'), |
|
163 | + ), |
|
164 | + EE_Ticket::expired => array( |
|
165 | + esc_html__('expired', 'event_espresso'), |
|
166 | + esc_html__('expired', 'event_espresso'), |
|
167 | + ), |
|
168 | + EE_Ticket::sold_out => array( |
|
169 | + esc_html__('sold out', 'event_espresso'), |
|
170 | + esc_html__('sold out', 'event_espresso'), |
|
171 | + ), |
|
172 | + EE_Ticket::pending => array( |
|
173 | + esc_html__('upcoming', 'event_espresso'), |
|
174 | + esc_html__('upcoming', 'event_espresso'), |
|
175 | + ), |
|
176 | + EE_Ticket::onsale => array( |
|
177 | + esc_html__('on sale', 'event_espresso'), |
|
178 | + esc_html__('on sale', 'event_espresso'), |
|
179 | + ), |
|
180 | + EE_Datetime::cancelled => array( |
|
181 | + esc_html__('cancelled', 'event_espresso'), |
|
182 | + esc_html__('cancelled', 'event_espresso'), |
|
183 | + ), |
|
184 | + EE_Datetime::sold_out => array( |
|
185 | + esc_html__('sold out', 'event_espresso'), |
|
186 | + esc_html__('sold out', 'event_espresso'), |
|
187 | + ), |
|
188 | + EE_Datetime::expired => array( |
|
189 | + esc_html__('expired', 'event_espresso'), |
|
190 | + esc_html__('expired', 'event_espresso'), |
|
191 | + ), |
|
192 | + EE_Datetime::inactive => array( |
|
193 | + esc_html__('inactive', 'event_espresso'), |
|
194 | + esc_html__('inactive', 'event_espresso'), |
|
195 | + ), |
|
196 | + EE_Datetime::upcoming => array( |
|
197 | + esc_html__('upcoming', 'event_espresso'), |
|
198 | + esc_html__('upcoming', 'event_espresso'), |
|
199 | + ), |
|
200 | + EE_Datetime::active => array( |
|
201 | + esc_html__('active', 'event_espresso'), |
|
202 | + esc_html__('active', 'event_espresso'), |
|
203 | + ), |
|
204 | + EE_Datetime::postponed => array( |
|
205 | + esc_html__('postponed', 'event_espresso'), |
|
206 | + esc_html__('postponed', 'event_espresso'), |
|
207 | + ), |
|
208 | + // messages related |
|
209 | + EEM_Message::status_sent => array( |
|
210 | + esc_html__('sent', 'event_espresso'), |
|
211 | + esc_html__('sent', 'event_espresso'), |
|
212 | + ), |
|
213 | + EEM_Message::status_idle => array( |
|
214 | + esc_html__('queued for sending', 'event_espresso'), |
|
215 | + esc_html__('queued for sending', 'event_espresso'), |
|
216 | + ), |
|
217 | + EEM_Message::status_failed => array( |
|
218 | + esc_html__('failed', 'event_espresso'), |
|
219 | + esc_html__('failed', 'event_espresso'), |
|
220 | + ), |
|
221 | + EEM_Message::status_debug_only => array( |
|
222 | + esc_html__('debug only', 'event_espresso'), |
|
223 | + esc_html__('debug only', 'event_espresso'), |
|
224 | + ), |
|
225 | + EEM_Message::status_messenger_executing => array( |
|
226 | + esc_html__('messenger is executing', 'event_espresso'), |
|
227 | + esc_html__('messenger is executing', 'event_espresso'), |
|
228 | + ), |
|
229 | + EEM_Message::status_resend => array( |
|
230 | + esc_html__('queued for resending', 'event_espresso'), |
|
231 | + esc_html__('queued for resending', 'event_espresso'), |
|
232 | + ), |
|
233 | + EEM_Message::status_incomplete => array( |
|
234 | + esc_html__('queued for generating', 'event_espresso'), |
|
235 | + esc_html__('queued for generating', 'event_espresso'), |
|
236 | + ), |
|
237 | + EEM_Message::status_retry => array( |
|
238 | + esc_html__('failed sending, can be retried', 'event_espresso'), |
|
239 | + esc_html__('failed sending, can be retried', 'event_espresso'), |
|
240 | + ), |
|
241 | + EEM_CPT_Base::post_status_publish => array( |
|
242 | + esc_html__('published', 'event_espresso'), |
|
243 | + esc_html__('published', 'event_espresso'), |
|
244 | + ), |
|
245 | + EEM_CPT_Base::post_status_future => array( |
|
246 | + esc_html__('scheduled', 'event_espresso'), |
|
247 | + esc_html__('scheduled', 'event_espresso'), |
|
248 | + ), |
|
249 | + EEM_CPT_Base::post_status_draft => array( |
|
250 | + esc_html__('draft', 'event_espresso'), |
|
251 | + esc_html__('draft', 'event_espresso'), |
|
252 | + ), |
|
253 | + EEM_CPT_Base::post_status_pending => array( |
|
254 | + esc_html__('pending', 'event_espresso'), |
|
255 | + esc_html__('pending', 'event_espresso'), |
|
256 | + ), |
|
257 | + EEM_CPT_Base::post_status_private => array( |
|
258 | + esc_html__('private', 'event_espresso'), |
|
259 | + esc_html__('private', 'event_espresso'), |
|
260 | + ), |
|
261 | + EEM_CPT_Base::post_status_trashed => array( |
|
262 | + esc_html__('trashed', 'event_espresso'), |
|
263 | + esc_html__('trashed', 'event_espresso'), |
|
264 | + ), |
|
265 | + ); |
|
266 | 266 | |
267 | - $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
267 | + $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
268 | 268 | |
269 | - if (! is_array($statuses)) { |
|
270 | - throw new EE_Error(esc_html__( |
|
271 | - 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
272 | - 'event_espresso' |
|
273 | - )); |
|
274 | - } |
|
269 | + if (! is_array($statuses)) { |
|
270 | + throw new EE_Error(esc_html__( |
|
271 | + 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
272 | + 'event_espresso' |
|
273 | + )); |
|
274 | + } |
|
275 | 275 | |
276 | - $translation = array(); |
|
276 | + $translation = array(); |
|
277 | 277 | |
278 | - foreach ($statuses as $id => $code) { |
|
279 | - if (isset($translation_array[ $id ])) { |
|
280 | - $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
281 | - } else { |
|
282 | - $translation[ $id ] = $code; |
|
283 | - } |
|
278 | + foreach ($statuses as $id => $code) { |
|
279 | + if (isset($translation_array[ $id ])) { |
|
280 | + $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
281 | + } else { |
|
282 | + $translation[ $id ] = $code; |
|
283 | + } |
|
284 | 284 | |
285 | - // schema |
|
286 | - switch ($schema) { |
|
287 | - case 'lower': |
|
288 | - $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | - break; |
|
290 | - case 'sentence': |
|
291 | - $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | - break; |
|
293 | - case 'upper': |
|
294 | - $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | - break; |
|
296 | - } |
|
297 | - } |
|
285 | + // schema |
|
286 | + switch ($schema) { |
|
287 | + case 'lower': |
|
288 | + $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
289 | + break; |
|
290 | + case 'sentence': |
|
291 | + $translation[ $id ] = ucwords($translation[ $id ]); |
|
292 | + break; |
|
293 | + case 'upper': |
|
294 | + $translation[ $id ] = strtoupper($translation[ $id ]); |
|
295 | + break; |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | - return $translation; |
|
300 | - } |
|
299 | + return $translation; |
|
300 | + } |
|
301 | 301 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'WP_User' => new EE_Belongs_To_Relation() |
49 | 49 | ); |
50 | 50 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
51 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
52 | 52 | } |
53 | 53 | $this->_caps_slug = 'messages'; |
54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $limit = null, |
76 | 76 | $count = false |
77 | 77 | ) { |
78 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
79 | 79 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
80 | 80 | } |
81 | 81 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
94 | 94 | { |
95 | 95 | return $this->get_all_deleted_and_undeleted( |
96 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | + array(array('MTP_messenger' => $messenger), 'order_by' => array($orderby => $order)) |
|
97 | 97 | ); |
98 | 98 | } |
99 | 99 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $global = true, |
146 | 146 | $user_check = false |
147 | 147 | ) { |
148 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
149 | 149 | $_where['MTP_is_active'] = true; |
150 | 150 | $_where = $this->_maybe_mtp_filters($_where); |
151 | 151 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $_where['MTP_user_id'] = get_current_user_id(); |
161 | 161 | } |
162 | 162 | |
163 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
164 | 164 | |
165 | 165 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
166 | 166 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | { |
182 | 182 | $_where = $this->_maybe_mtp_filters(); |
183 | 183 | |
184 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
185 | 185 | |
186 | 186 | $r_templates = $count |
187 | 187 | ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
203 | 203 | { |
204 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | + $where = array_merge($query_params, array('Event.EVT_ID' => $EVT_ID)); |
|
205 | 205 | return $this->get_all( |
206 | - array( $where ) |
|
206 | + array($where) |
|
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | $count = false, |
229 | 229 | $global = true |
230 | 230 | ) { |
231 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | + $_where = $global ? array('MTP_is_global' => true) : array('MTP_is_global' => false); |
|
232 | 232 | $_where['MTP_is_active'] = true; |
233 | 233 | $_where = $this->_maybe_mtp_filters($_where); |
234 | 234 | |
235 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
236 | 236 | |
237 | 237 | return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
238 | 238 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'MTP_is_active' => $active |
271 | 271 | ); |
272 | 272 | |
273 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
274 | 274 | |
275 | 275 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
276 | 276 | } |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $_where['MTP_is_active'] = $active; |
311 | 311 | } |
312 | 312 | |
313 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
314 | 314 | |
315 | 315 | return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
316 | 316 | } |
@@ -368,19 +368,19 @@ discard block |
||
368 | 368 | // first let's figure out if the value['content'] in the current index is an array. |
369 | 369 | // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
370 | 370 | if (is_array($value['content'])) { |
371 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | + $assembled_fields[$value['name']] = $value['content']['main']; |
|
372 | 372 | // loop through the content and get the other fields. |
373 | 373 | foreach ($value['content'] as $name => $val) { |
374 | 374 | if ($name == 'main') { |
375 | 375 | continue; |
376 | 376 | } |
377 | - $assembled_fields[ $name ] = $val; |
|
377 | + $assembled_fields[$name] = $val; |
|
378 | 378 | } |
379 | 379 | continue; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // okay if we're here then this is just a straight field=>$value arrangement |
383 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | + $assembled_fields[$value['name']] = $value['content']; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | // now we've got the assembled_fields. |
@@ -390,9 +390,9 @@ discard block |
||
390 | 390 | $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
391 | 391 | $mt_ref = str_replace(' ', '_', $mt_ref); |
392 | 392 | |
393 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | + $classname = 'EE_Messages_'.$m_ref.'_'.$mt_ref.'_Validator'; |
|
394 | 394 | |
395 | - if (!class_exists($classname)) { |
|
395 | + if ( ! class_exists($classname)) { |
|
396 | 396 | $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
397 | 397 | $msg[] = sprintf( |
398 | 398 | esc_html__( |
@@ -430,12 +430,12 @@ discard block |
||
430 | 430 | if (empty($messenger_names) && empty($message_type_names)) { |
431 | 431 | return 0; |
432 | 432 | } |
433 | - if (! empty($messenger_names)) { |
|
434 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
433 | + if ( ! empty($messenger_names)) { |
|
434 | + $query_args[0]['MTP_messenger'] = array('IN', (array) $messenger_names); |
|
435 | 435 | } |
436 | - if (! empty($message_type_names)) { |
|
437 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
436 | + if ( ! empty($message_type_names)) { |
|
437 | + $query_args[0]['MTP_message_type'] = array('IN', (array) $message_type_names); |
|
438 | 438 | } |
439 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | + return $this->update(array('MTP_is_active' => false), $query_args); |
|
440 | 440 | } |
441 | 441 | } |
@@ -14,427 +14,427 @@ |
||
14 | 14 | */ |
15 | 15 | class EEM_Message_Template_Group extends EEM_Soft_Delete_Base |
16 | 16 | { |
17 | - // private instance of the EEM_Message_Template_Group object |
|
18 | - protected static $_instance = null; |
|
19 | - |
|
20 | - |
|
21 | - |
|
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
25 | - $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
28 | - ); |
|
29 | - $this->_fields = array( |
|
30 | - 'Message_Template_Group' => array( |
|
31 | - 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')), |
|
32 | - 'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''), |
|
33 | - 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''), |
|
34 | - 'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
35 | - 'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
36 | - 'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'), |
|
37 | - 'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
38 | - 'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
39 | - 'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
40 | - 'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
41 | - ) |
|
42 | - ); |
|
43 | - $this->_model_relations = array( |
|
44 | - 'Message_Template' => new EE_Has_Many_Relation(), |
|
45 | - 'Message' => new EE_Has_Many_Relation(), |
|
46 | - 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
47 | - 'WP_User' => new EE_Belongs_To_Relation() |
|
48 | - ); |
|
49 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
50 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | - } |
|
52 | - $this->_caps_slug = 'messages'; |
|
53 | - |
|
54 | - parent::__construct($timezone); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * get_all_trashed_message_templates_by_event |
|
61 | - * |
|
62 | - * @access public |
|
63 | - * @param int $EVT_ID specific event id |
|
64 | - * @param string $orderby |
|
65 | - * @param string $order |
|
66 | - * @param null $limit |
|
67 | - * @param bool $count |
|
68 | - * @return array message template objects that are attached to a specific event. |
|
69 | - */ |
|
70 | - public function get_all_trashed_message_templates_by_event( |
|
71 | - $EVT_ID, |
|
72 | - $orderby = 'GRP_ID', |
|
73 | - $order = 'ASC', |
|
74 | - $limit = null, |
|
75 | - $count = false |
|
76 | - ) { |
|
77 | - $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * get_all_message_templates_by_messenger |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @param $messenger |
|
88 | - * @param string $orderby |
|
89 | - * @param string $order |
|
90 | - * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
91 | - */ |
|
92 | - public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
93 | - { |
|
94 | - return $this->get_all_deleted_and_undeleted( |
|
95 | - array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * This simply adds on any messenger/message type filters that may be present in the request |
|
102 | - * |
|
103 | - * @param array $_where any existing where conditions to append these to. |
|
104 | - * @return array original where conditions or original with additional filters. |
|
105 | - */ |
|
106 | - protected function _maybe_mtp_filters($_where = array()) |
|
107 | - { |
|
108 | - /** @var RequestInterface $request */ |
|
109 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
110 | - $messenger = $request->getRequestParam('ee_messenger_filter_by'); |
|
111 | - // account for messenger or message type filters |
|
112 | - if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') { |
|
113 | - $_where['MTP_messenger'] = $messenger; |
|
114 | - } |
|
115 | - $message_type = $request->getRequestParam('ee_message_type_filter_by'); |
|
116 | - if ( |
|
117 | - $message_type !== '' && $message_type !== 'none_selected' |
|
118 | - ) { |
|
119 | - $_where['MTP_message_type'] = $message_type; |
|
120 | - } |
|
121 | - |
|
122 | - return $_where; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * get_all_active_message_templates groups |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $orderby |
|
132 | - * @param string $order |
|
133 | - * @param null $limit |
|
134 | - * @param bool $count |
|
135 | - * @param bool $global |
|
136 | - * @param bool $user_check |
|
137 | - * @return array all active (non_trashed, active) message template objects |
|
138 | - */ |
|
139 | - public function get_all_active_message_templates( |
|
140 | - $orderby = 'GRP_ID', |
|
141 | - $order = 'ASC', |
|
142 | - $limit = null, |
|
143 | - $count = false, |
|
144 | - $global = true, |
|
145 | - $user_check = false |
|
146 | - ) { |
|
147 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | - $_where['MTP_is_active'] = true; |
|
149 | - $_where = $this->_maybe_mtp_filters($_where); |
|
150 | - |
|
151 | - if ( |
|
152 | - $user_check |
|
153 | - && ! $global |
|
154 | - && ! EE_Registry::instance()->CAP->current_user_can( |
|
155 | - 'ee_read_others_messages', |
|
156 | - 'get_all_active_message_templates' |
|
157 | - ) |
|
158 | - ) { |
|
159 | - $_where['MTP_user_id'] = get_current_user_id(); |
|
160 | - } |
|
161 | - |
|
162 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | - |
|
164 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * retrieve ALL message_template groups from db regardless of wht |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param string $orderby |
|
174 | - * @param string $order |
|
175 | - * @param null $limit |
|
176 | - * @param bool $count |
|
177 | - * @return mixed array on success, FALSE on fail |
|
178 | - */ |
|
179 | - public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
180 | - { |
|
181 | - $_where = $this->_maybe_mtp_filters(); |
|
182 | - |
|
183 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | - |
|
185 | - $r_templates = $count |
|
186 | - ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
187 | - : $this->get_all_deleted_and_undeleted($query_params); |
|
188 | - |
|
189 | - return $r_templates; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This gets all the custom templates attached to a specific event |
|
197 | - * @param int $EVT_ID event id |
|
198 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
199 | - * @return EE_Message_Template_Group[] |
|
200 | - */ |
|
201 | - public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
202 | - { |
|
203 | - $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | - return $this->get_all( |
|
205 | - array( $where ) |
|
206 | - ); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * get_all_trashed_grouped_message_templates |
|
213 | - * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string $orderby |
|
217 | - * @param string $order |
|
218 | - * @param null $limit |
|
219 | - * @param bool $count |
|
220 | - * @param bool $global |
|
221 | - * @return \EE_Message_Template_Group[] message template groups. |
|
222 | - */ |
|
223 | - public function get_all_trashed_grouped_message_templates( |
|
224 | - $orderby = 'GRP_ID', |
|
225 | - $order = 'ASC', |
|
226 | - $limit = null, |
|
227 | - $count = false, |
|
228 | - $global = true |
|
229 | - ) { |
|
230 | - $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | - $_where['MTP_is_active'] = true; |
|
232 | - $_where = $this->_maybe_mtp_filters($_where); |
|
233 | - |
|
234 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | - |
|
236 | - return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * this returns the message template group(s) for a given event, messenger, and message template |
|
243 | - * |
|
244 | - * @param string $messenger |
|
245 | - * @param string $message_type |
|
246 | - * @param $evt_id |
|
247 | - * @param string $orderby pointless at this point but still included |
|
248 | - * @param string $order |
|
249 | - * @param mixed (array|null) $limit array($offset, $num) |
|
250 | - * @param bool $count true = just return count, false = objects |
|
251 | - * @param bool $active ignore "active" or not. (default only return active) |
|
252 | - * @return \mixed[]) depending on $count. |
|
253 | - */ |
|
254 | - public function get_event_message_templates_by_m_and_mt_and_evt( |
|
255 | - $messenger, |
|
256 | - $message_type, |
|
257 | - $evt_id, |
|
258 | - $orderby = 'GRP_ID', |
|
259 | - $order = 'ASC', |
|
260 | - $limit = null, |
|
261 | - $count = false, |
|
262 | - $active = true |
|
263 | - ) { |
|
264 | - $_where = array( |
|
265 | - 'MTP_messenger' => $messenger, |
|
266 | - 'MTP_message_type' => $message_type, |
|
267 | - 'Event.EVT_ID' => $evt_id, |
|
268 | - 'MTP_is_global' => true, |
|
269 | - 'MTP_is_active' => $active |
|
270 | - ); |
|
271 | - |
|
272 | - $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | - |
|
274 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * get all GLOBAL message template groups for the given messenger and message type |
|
282 | - * |
|
283 | - * @param string $messenger slug for messenger |
|
284 | - * @param string $message_type slug for message type |
|
285 | - * @param string $orderby what column to orderby |
|
286 | - * @param string $order ASC or DESC |
|
287 | - * @param mixed (array|null) $limit array($offset, $num) |
|
288 | - * @param bool $count true = just return count, false = objects |
|
289 | - * @param bool $active ignore "active" or not. (default only return active) - |
|
290 | - * 'all' means return both inactive AND inactive. |
|
291 | - * @return array message template objects that are global (i.e. non-event) |
|
292 | - */ |
|
293 | - public function get_global_message_template_by_m_and_mt( |
|
294 | - $messenger, |
|
295 | - $message_type, |
|
296 | - $orderby = 'GRP_ID', |
|
297 | - $order = 'ASC', |
|
298 | - $limit = null, |
|
299 | - $count = false, |
|
300 | - $active = true |
|
301 | - ) { |
|
302 | - $_where = array( |
|
303 | - 'MTP_messenger' => $messenger, |
|
304 | - 'MTP_message_type' => $message_type, |
|
305 | - 'MTP_is_global' => true, |
|
306 | - ); |
|
307 | - |
|
308 | - if ($active != 'all') { |
|
309 | - $_where['MTP_is_active'] = $active; |
|
310 | - } |
|
311 | - |
|
312 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | - |
|
314 | - return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * get all custom message template groups for the given messenger and message type |
|
322 | - * @param string $messenger messenger |
|
323 | - * @param string $message_type messagetype |
|
324 | - * @param array $query_params same as EEM_Base->get_all() |
|
325 | - * @return EE_Message_Template_Group[] |
|
326 | - */ |
|
327 | - public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
328 | - { |
|
329 | - return $this->get_all( |
|
330 | - array_merge( |
|
331 | - $query_params, |
|
332 | - array( |
|
333 | - array( |
|
334 | - 'MTP_is_global' => false, |
|
335 | - 'MTP_messenger' => $messenger, |
|
336 | - 'MTP_message_type' => $message_type |
|
337 | - ) |
|
338 | - ) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * This sends things to the validator for the given messenger and message type. |
|
347 | - * |
|
348 | - * @param array $fields the incoming fields to check. |
|
349 | - * Note this array is in the formatted fields from the form fields setup. |
|
350 | - * So we need to reformat this into an array of expected field refs by the validator. |
|
351 | - * Note also that this is not only the fields for the Message Template Group |
|
352 | - * but ALSO for Message Template. |
|
353 | - * @param string $context The context the fields were obtained from. |
|
354 | - * @param string $messenger The messenger we are validating |
|
355 | - * @param string $message_type The message type we are validating. |
|
356 | - * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
357 | - * (indexed by field name); |
|
358 | - * @throws \EE_Error |
|
359 | - */ |
|
360 | - public function validate($fields, $context, $messenger, $message_type) |
|
361 | - { |
|
362 | - |
|
363 | - $assembled_fields = array(); |
|
364 | - |
|
365 | - // let's loop through all the fields and set them up in the right format |
|
366 | - foreach ($fields as $index => $value) { |
|
367 | - // first let's figure out if the value['content'] in the current index is an array. |
|
368 | - // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
369 | - if (is_array($value['content'])) { |
|
370 | - $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | - // loop through the content and get the other fields. |
|
372 | - foreach ($value['content'] as $name => $val) { |
|
373 | - if ($name == 'main') { |
|
374 | - continue; |
|
375 | - } |
|
376 | - $assembled_fields[ $name ] = $val; |
|
377 | - } |
|
378 | - continue; |
|
379 | - } |
|
380 | - |
|
381 | - // okay if we're here then this is just a straight field=>$value arrangement |
|
382 | - $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | - } |
|
384 | - |
|
385 | - // now we've got the assembled_fields. |
|
386 | - // We need to setup the string for the appropriate validator class and call that. |
|
387 | - $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
388 | - $m_ref = str_replace(' ', '_', $m_ref); |
|
389 | - $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
390 | - $mt_ref = str_replace(' ', '_', $mt_ref); |
|
391 | - |
|
392 | - $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | - |
|
394 | - if (!class_exists($classname)) { |
|
395 | - $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
396 | - $msg[] = sprintf( |
|
397 | - esc_html__( |
|
398 | - 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
399 | - 'event_espresso' |
|
400 | - ), |
|
401 | - $classname |
|
402 | - ); |
|
403 | - throw new EE_Error(implode('||', $msg)); |
|
404 | - } |
|
405 | - |
|
406 | - $a = new ReflectionClass($classname); |
|
407 | - $_VLD = $a->newInstance($assembled_fields, $context); |
|
408 | - $result = $_VLD->validate(); |
|
409 | - return $result; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Updates all message template groups matching the incoming arguments to inactive status. |
|
416 | - * |
|
417 | - * @param array $messenger_names The messenger slugs. |
|
418 | - * If empty then all templates matching the message types are marked inactive. |
|
419 | - * Otherwise only templates matching the messengers and message types. |
|
420 | - * @param array $message_type_names The message type slugs. |
|
421 | - * If empty then all templates matching the messengers are marked inactive. |
|
422 | - * Otherwise only templates matching the messengers and message types. |
|
423 | - * |
|
424 | - * @return int count of updated records. |
|
425 | - */ |
|
426 | - public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
427 | - { |
|
428 | - $query_args = array(); |
|
429 | - if (empty($messenger_names) && empty($message_type_names)) { |
|
430 | - return 0; |
|
431 | - } |
|
432 | - if (! empty($messenger_names)) { |
|
433 | - $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
434 | - } |
|
435 | - if (! empty($message_type_names)) { |
|
436 | - $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
437 | - } |
|
438 | - return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | - } |
|
17 | + // private instance of the EEM_Message_Template_Group object |
|
18 | + protected static $_instance = null; |
|
19 | + |
|
20 | + |
|
21 | + |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = esc_html__('Message Template Group', 'event_espresso'); |
|
25 | + $this->plural_item = esc_html__('Message Template Groups', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Message_Template_Group' => new EE_Primary_Table('esp_message_template_group', 'GRP_ID') |
|
28 | + ); |
|
29 | + $this->_fields = array( |
|
30 | + 'Message_Template_Group' => array( |
|
31 | + 'GRP_ID' => new EE_Primary_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso')), |
|
32 | + 'MTP_name' => new EE_Plain_Text_Field('MTP_name', esc_html__('The name of the template group', 'event_espresso'), false, ''), |
|
33 | + 'MTP_description' => new EE_Simple_HTML_Field('MTP_description', esc_html__('A brief description about this template.', 'event_espresso'), false, ''), |
|
34 | + 'MTP_user_id' => new EE_WP_User_Field('MTP_user_id', esc_html__('Template Creator ID', 'event_espresso'), false, get_current_user_id()), |
|
35 | + 'MTP_messenger' => new EE_Plain_Text_Field('MTP_messenger', esc_html__('Messenger Used for Template', 'event_espresso'), false, 'email'), |
|
36 | + 'MTP_message_type' => new EE_Plain_Text_Field('MTP_message_type', esc_html__('Message Type', 'event_espresso'), false, 'registration'), |
|
37 | + 'MTP_is_global' => new EE_Boolean_Field('MTP_is_global', esc_html__('Flag indicating if Template Group is Global', 'event_espresso'), false, true), |
|
38 | + 'MTP_is_override' => new EE_Boolean_Field('MTP_is_override', esc_html__('Flag indicating if Template Group overrides any other Templates for the messenger/messagetype combination', 'event_espresso'), false, false), |
|
39 | + 'MTP_deleted' => new EE_Trashed_Flag_Field('MTP_deleted', esc_html__('Flag indicating whether this has been trashed', 'event_espresso'), false, false), |
|
40 | + 'MTP_is_active' => new EE_Boolean_Field('MTP_is_active', esc_html__('Flag indicating whether template group is active', 'event_espresso'), false, true) |
|
41 | + ) |
|
42 | + ); |
|
43 | + $this->_model_relations = array( |
|
44 | + 'Message_Template' => new EE_Has_Many_Relation(), |
|
45 | + 'Message' => new EE_Has_Many_Relation(), |
|
46 | + 'Event' => new EE_HABTM_Relation('Event_Message_Template'), |
|
47 | + 'WP_User' => new EE_Belongs_To_Relation() |
|
48 | + ); |
|
49 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
50 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('MTP_is_global'); |
|
51 | + } |
|
52 | + $this->_caps_slug = 'messages'; |
|
53 | + |
|
54 | + parent::__construct($timezone); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * get_all_trashed_message_templates_by_event |
|
61 | + * |
|
62 | + * @access public |
|
63 | + * @param int $EVT_ID specific event id |
|
64 | + * @param string $orderby |
|
65 | + * @param string $order |
|
66 | + * @param null $limit |
|
67 | + * @param bool $count |
|
68 | + * @return array message template objects that are attached to a specific event. |
|
69 | + */ |
|
70 | + public function get_all_trashed_message_templates_by_event( |
|
71 | + $EVT_ID, |
|
72 | + $orderby = 'GRP_ID', |
|
73 | + $order = 'ASC', |
|
74 | + $limit = null, |
|
75 | + $count = false |
|
76 | + ) { |
|
77 | + $query_params = array( array('Event.EVT_ID' => $EVT_ID), 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
78 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * get_all_message_templates_by_messenger |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @param $messenger |
|
88 | + * @param string $orderby |
|
89 | + * @param string $order |
|
90 | + * @return array all (including trashed or inactive) message template group objects for the given messenger |
|
91 | + */ |
|
92 | + public function get_all_message_templates_by_messenger($messenger, $orderby = 'GRP_ID', $order = 'ASC') |
|
93 | + { |
|
94 | + return $this->get_all_deleted_and_undeleted( |
|
95 | + array( array( 'MTP_messenger' => $messenger ), 'order_by' => array( $orderby => $order ) ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * This simply adds on any messenger/message type filters that may be present in the request |
|
102 | + * |
|
103 | + * @param array $_where any existing where conditions to append these to. |
|
104 | + * @return array original where conditions or original with additional filters. |
|
105 | + */ |
|
106 | + protected function _maybe_mtp_filters($_where = array()) |
|
107 | + { |
|
108 | + /** @var RequestInterface $request */ |
|
109 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
110 | + $messenger = $request->getRequestParam('ee_messenger_filter_by'); |
|
111 | + // account for messenger or message type filters |
|
112 | + if ($messenger !== '' && $messenger !== 'none_selected' && $messenger !== 'all') { |
|
113 | + $_where['MTP_messenger'] = $messenger; |
|
114 | + } |
|
115 | + $message_type = $request->getRequestParam('ee_message_type_filter_by'); |
|
116 | + if ( |
|
117 | + $message_type !== '' && $message_type !== 'none_selected' |
|
118 | + ) { |
|
119 | + $_where['MTP_message_type'] = $message_type; |
|
120 | + } |
|
121 | + |
|
122 | + return $_where; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * get_all_active_message_templates groups |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $orderby |
|
132 | + * @param string $order |
|
133 | + * @param null $limit |
|
134 | + * @param bool $count |
|
135 | + * @param bool $global |
|
136 | + * @param bool $user_check |
|
137 | + * @return array all active (non_trashed, active) message template objects |
|
138 | + */ |
|
139 | + public function get_all_active_message_templates( |
|
140 | + $orderby = 'GRP_ID', |
|
141 | + $order = 'ASC', |
|
142 | + $limit = null, |
|
143 | + $count = false, |
|
144 | + $global = true, |
|
145 | + $user_check = false |
|
146 | + ) { |
|
147 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
148 | + $_where['MTP_is_active'] = true; |
|
149 | + $_where = $this->_maybe_mtp_filters($_where); |
|
150 | + |
|
151 | + if ( |
|
152 | + $user_check |
|
153 | + && ! $global |
|
154 | + && ! EE_Registry::instance()->CAP->current_user_can( |
|
155 | + 'ee_read_others_messages', |
|
156 | + 'get_all_active_message_templates' |
|
157 | + ) |
|
158 | + ) { |
|
159 | + $_where['MTP_user_id'] = get_current_user_id(); |
|
160 | + } |
|
161 | + |
|
162 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
163 | + |
|
164 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * retrieve ALL message_template groups from db regardless of wht |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param string $orderby |
|
174 | + * @param string $order |
|
175 | + * @param null $limit |
|
176 | + * @param bool $count |
|
177 | + * @return mixed array on success, FALSE on fail |
|
178 | + */ |
|
179 | + public function get_all_message_templates($orderby = 'GRP_ID', $order = 'ASC', $limit = null, $count = false) |
|
180 | + { |
|
181 | + $_where = $this->_maybe_mtp_filters(); |
|
182 | + |
|
183 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
184 | + |
|
185 | + $r_templates = $count |
|
186 | + ? $this->count_deleted_and_undeleted($query_params, 'GRP_ID', true) |
|
187 | + : $this->get_all_deleted_and_undeleted($query_params); |
|
188 | + |
|
189 | + return $r_templates; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This gets all the custom templates attached to a specific event |
|
197 | + * @param int $EVT_ID event id |
|
198 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
199 | + * @return EE_Message_Template_Group[] |
|
200 | + */ |
|
201 | + public function get_all_custom_templates_by_event($EVT_ID, $query_params = array()) |
|
202 | + { |
|
203 | + $where = array_merge($query_params, array( 'Event.EVT_ID' => $EVT_ID )); |
|
204 | + return $this->get_all( |
|
205 | + array( $where ) |
|
206 | + ); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * get_all_trashed_grouped_message_templates |
|
213 | + * this returns ONLY the template groups where ALL contexts are trashed and none of the group are non-trashed |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string $orderby |
|
217 | + * @param string $order |
|
218 | + * @param null $limit |
|
219 | + * @param bool $count |
|
220 | + * @param bool $global |
|
221 | + * @return \EE_Message_Template_Group[] message template groups. |
|
222 | + */ |
|
223 | + public function get_all_trashed_grouped_message_templates( |
|
224 | + $orderby = 'GRP_ID', |
|
225 | + $order = 'ASC', |
|
226 | + $limit = null, |
|
227 | + $count = false, |
|
228 | + $global = true |
|
229 | + ) { |
|
230 | + $_where = $global ? array('MTP_is_global' => true ) : array('MTP_is_global' => false ); |
|
231 | + $_where['MTP_is_active'] = true; |
|
232 | + $_where = $this->_maybe_mtp_filters($_where); |
|
233 | + |
|
234 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
235 | + |
|
236 | + return $count ? $this->count_deleted($query_params, 'GRP_ID', true) : $this->get_all_deleted($query_params); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * this returns the message template group(s) for a given event, messenger, and message template |
|
243 | + * |
|
244 | + * @param string $messenger |
|
245 | + * @param string $message_type |
|
246 | + * @param $evt_id |
|
247 | + * @param string $orderby pointless at this point but still included |
|
248 | + * @param string $order |
|
249 | + * @param mixed (array|null) $limit array($offset, $num) |
|
250 | + * @param bool $count true = just return count, false = objects |
|
251 | + * @param bool $active ignore "active" or not. (default only return active) |
|
252 | + * @return \mixed[]) depending on $count. |
|
253 | + */ |
|
254 | + public function get_event_message_templates_by_m_and_mt_and_evt( |
|
255 | + $messenger, |
|
256 | + $message_type, |
|
257 | + $evt_id, |
|
258 | + $orderby = 'GRP_ID', |
|
259 | + $order = 'ASC', |
|
260 | + $limit = null, |
|
261 | + $count = false, |
|
262 | + $active = true |
|
263 | + ) { |
|
264 | + $_where = array( |
|
265 | + 'MTP_messenger' => $messenger, |
|
266 | + 'MTP_message_type' => $message_type, |
|
267 | + 'Event.EVT_ID' => $evt_id, |
|
268 | + 'MTP_is_global' => true, |
|
269 | + 'MTP_is_active' => $active |
|
270 | + ); |
|
271 | + |
|
272 | + $query_params = array( $_where, 'order_by' => array($orderby => $order), 'limit' => $limit ); |
|
273 | + |
|
274 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * get all GLOBAL message template groups for the given messenger and message type |
|
282 | + * |
|
283 | + * @param string $messenger slug for messenger |
|
284 | + * @param string $message_type slug for message type |
|
285 | + * @param string $orderby what column to orderby |
|
286 | + * @param string $order ASC or DESC |
|
287 | + * @param mixed (array|null) $limit array($offset, $num) |
|
288 | + * @param bool $count true = just return count, false = objects |
|
289 | + * @param bool $active ignore "active" or not. (default only return active) - |
|
290 | + * 'all' means return both inactive AND inactive. |
|
291 | + * @return array message template objects that are global (i.e. non-event) |
|
292 | + */ |
|
293 | + public function get_global_message_template_by_m_and_mt( |
|
294 | + $messenger, |
|
295 | + $message_type, |
|
296 | + $orderby = 'GRP_ID', |
|
297 | + $order = 'ASC', |
|
298 | + $limit = null, |
|
299 | + $count = false, |
|
300 | + $active = true |
|
301 | + ) { |
|
302 | + $_where = array( |
|
303 | + 'MTP_messenger' => $messenger, |
|
304 | + 'MTP_message_type' => $message_type, |
|
305 | + 'MTP_is_global' => true, |
|
306 | + ); |
|
307 | + |
|
308 | + if ($active != 'all') { |
|
309 | + $_where['MTP_is_active'] = $active; |
|
310 | + } |
|
311 | + |
|
312 | + $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
313 | + |
|
314 | + return $count ? $this->count($query_params, 'GRP_ID', true) : $this->get_all($query_params); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * get all custom message template groups for the given messenger and message type |
|
322 | + * @param string $messenger messenger |
|
323 | + * @param string $message_type messagetype |
|
324 | + * @param array $query_params same as EEM_Base->get_all() |
|
325 | + * @return EE_Message_Template_Group[] |
|
326 | + */ |
|
327 | + public function get_custom_message_template_by_m_and_mt($messenger, $message_type, $query_params = array()) |
|
328 | + { |
|
329 | + return $this->get_all( |
|
330 | + array_merge( |
|
331 | + $query_params, |
|
332 | + array( |
|
333 | + array( |
|
334 | + 'MTP_is_global' => false, |
|
335 | + 'MTP_messenger' => $messenger, |
|
336 | + 'MTP_message_type' => $message_type |
|
337 | + ) |
|
338 | + ) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * This sends things to the validator for the given messenger and message type. |
|
347 | + * |
|
348 | + * @param array $fields the incoming fields to check. |
|
349 | + * Note this array is in the formatted fields from the form fields setup. |
|
350 | + * So we need to reformat this into an array of expected field refs by the validator. |
|
351 | + * Note also that this is not only the fields for the Message Template Group |
|
352 | + * but ALSO for Message Template. |
|
353 | + * @param string $context The context the fields were obtained from. |
|
354 | + * @param string $messenger The messenger we are validating |
|
355 | + * @param string $message_type The message type we are validating. |
|
356 | + * @return mixed If the fields all check out then we return true otherwise error messages are returned |
|
357 | + * (indexed by field name); |
|
358 | + * @throws \EE_Error |
|
359 | + */ |
|
360 | + public function validate($fields, $context, $messenger, $message_type) |
|
361 | + { |
|
362 | + |
|
363 | + $assembled_fields = array(); |
|
364 | + |
|
365 | + // let's loop through all the fields and set them up in the right format |
|
366 | + foreach ($fields as $index => $value) { |
|
367 | + // first let's figure out if the value['content'] in the current index is an array. |
|
368 | + // If it is then this is special fields that are used in parsing special shortcodes (i.e. 'attendee_list'). |
|
369 | + if (is_array($value['content'])) { |
|
370 | + $assembled_fields[ $value['name'] ] = $value['content']['main']; |
|
371 | + // loop through the content and get the other fields. |
|
372 | + foreach ($value['content'] as $name => $val) { |
|
373 | + if ($name == 'main') { |
|
374 | + continue; |
|
375 | + } |
|
376 | + $assembled_fields[ $name ] = $val; |
|
377 | + } |
|
378 | + continue; |
|
379 | + } |
|
380 | + |
|
381 | + // okay if we're here then this is just a straight field=>$value arrangement |
|
382 | + $assembled_fields[ $value['name'] ] = $value['content']; |
|
383 | + } |
|
384 | + |
|
385 | + // now we've got the assembled_fields. |
|
386 | + // We need to setup the string for the appropriate validator class and call that. |
|
387 | + $m_ref = ucwords(str_replace('_', ' ', $messenger)); |
|
388 | + $m_ref = str_replace(' ', '_', $m_ref); |
|
389 | + $mt_ref = ucwords(str_replace('_', ' ', $message_type)); |
|
390 | + $mt_ref = str_replace(' ', '_', $mt_ref); |
|
391 | + |
|
392 | + $classname = 'EE_Messages_' . $m_ref . '_' . $mt_ref . '_Validator'; |
|
393 | + |
|
394 | + if (!class_exists($classname)) { |
|
395 | + $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); |
|
396 | + $msg[] = sprintf( |
|
397 | + esc_html__( |
|
398 | + 'The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', |
|
399 | + 'event_espresso' |
|
400 | + ), |
|
401 | + $classname |
|
402 | + ); |
|
403 | + throw new EE_Error(implode('||', $msg)); |
|
404 | + } |
|
405 | + |
|
406 | + $a = new ReflectionClass($classname); |
|
407 | + $_VLD = $a->newInstance($assembled_fields, $context); |
|
408 | + $result = $_VLD->validate(); |
|
409 | + return $result; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Updates all message template groups matching the incoming arguments to inactive status. |
|
416 | + * |
|
417 | + * @param array $messenger_names The messenger slugs. |
|
418 | + * If empty then all templates matching the message types are marked inactive. |
|
419 | + * Otherwise only templates matching the messengers and message types. |
|
420 | + * @param array $message_type_names The message type slugs. |
|
421 | + * If empty then all templates matching the messengers are marked inactive. |
|
422 | + * Otherwise only templates matching the messengers and message types. |
|
423 | + * |
|
424 | + * @return int count of updated records. |
|
425 | + */ |
|
426 | + public function deactivate_message_template_groups_for($messenger_names = array(), $message_type_names = array()) |
|
427 | + { |
|
428 | + $query_args = array(); |
|
429 | + if (empty($messenger_names) && empty($message_type_names)) { |
|
430 | + return 0; |
|
431 | + } |
|
432 | + if (! empty($messenger_names)) { |
|
433 | + $query_args[0]['MTP_messenger'] = array( 'IN', (array) $messenger_names ); |
|
434 | + } |
|
435 | + if (! empty($message_type_names)) { |
|
436 | + $query_args[0]['MTP_message_type'] = array( 'IN', (array) $message_type_names ); |
|
437 | + } |
|
438 | + return $this->update(array( 'MTP_is_active' => false ), $query_args); |
|
439 | + } |
|
440 | 440 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -13,39 +13,39 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_WP_User_Field extends EE_Foreign_Key_Int_Field |
15 | 15 | { |
16 | - /** |
|
17 | - * No need to provide a default or the model pointed to- the default is |
|
18 | - * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | - * |
|
20 | - * @param string $table_column name fo column for field |
|
21 | - * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | - * @param boolean $nullable |
|
23 | - */ |
|
24 | - public function __construct($table_column, $nicename, $nullable) |
|
25 | - { |
|
26 | - parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | - } |
|
16 | + /** |
|
17 | + * No need to provide a default or the model pointed to- the default is |
|
18 | + * always get_current_user_id() and the model pointed to is always WP_User |
|
19 | + * |
|
20 | + * @param string $table_column name fo column for field |
|
21 | + * @param string $nicename should eb internationalized with esc_html__('blah','event_espresso') |
|
22 | + * @param boolean $nullable |
|
23 | + */ |
|
24 | + public function __construct($table_column, $nicename, $nullable) |
|
25 | + { |
|
26 | + parent::__construct($table_column, $nicename, $nullable, null, 'WP_User'); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Gets the default which is always the current user. This can't be set when initially |
|
31 | - * constructing the model field because that's done before $current_user is set |
|
32 | - * |
|
33 | - * @return mixed |
|
34 | - */ |
|
35 | - public function get_default_value() |
|
36 | - { |
|
37 | - if (did_action('init')) { |
|
38 | - return get_current_user_id(); |
|
39 | - } else { |
|
40 | - EE_Error::doing_it_wrong( |
|
41 | - 'EE_WP_User_Field::get_default_value', |
|
42 | - esc_html__( |
|
43 | - 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '4.6.20' |
|
47 | - ); |
|
48 | - return 1; |
|
49 | - } |
|
50 | - } |
|
29 | + /** |
|
30 | + * Gets the default which is always the current user. This can't be set when initially |
|
31 | + * constructing the model field because that's done before $current_user is set |
|
32 | + * |
|
33 | + * @return mixed |
|
34 | + */ |
|
35 | + public function get_default_value() |
|
36 | + { |
|
37 | + if (did_action('init')) { |
|
38 | + return get_current_user_id(); |
|
39 | + } else { |
|
40 | + EE_Error::doing_it_wrong( |
|
41 | + 'EE_WP_User_Field::get_default_value', |
|
42 | + esc_html__( |
|
43 | + 'You cant get a default value for a wp_User_Field because the "init" action is called, because current_user global hasnt yet been setup. Consider doing your business logic on the "init" hook or later.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '4.6.20' |
|
47 | + ); |
|
48 | + return 1; |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |