@@ -16,94 +16,94 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * get_join_statement |
|
21 | - * |
|
22 | - * @param string $model_relation_chain |
|
23 | - * @return string |
|
24 | - * @throws \EE_Error |
|
25 | - */ |
|
26 | - public function get_join_statement($model_relation_chain) |
|
27 | - { |
|
28 | - // create the sql string like |
|
29 | - $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
30 | - // ALSO, need to get the field with the model name |
|
31 | - $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name(); |
|
19 | + /** |
|
20 | + * get_join_statement |
|
21 | + * |
|
22 | + * @param string $model_relation_chain |
|
23 | + * @return string |
|
24 | + * @throws \EE_Error |
|
25 | + */ |
|
26 | + public function get_join_statement($model_relation_chain) |
|
27 | + { |
|
28 | + // create the sql string like |
|
29 | + $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
30 | + // ALSO, need to get the field with the model name |
|
31 | + $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name(); |
|
32 | 32 | |
33 | 33 | |
34 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
35 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
36 | - $model_relation_chain, |
|
37 | - $this->get_this_model()->get_this_model_name() |
|
38 | - ) . $this_table_fk_field->get_table_alias(); |
|
39 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
40 | - $model_relation_chain, |
|
41 | - $this->get_other_model()->get_this_model_name() |
|
42 | - ) . $other_table_pk_field->get_table_alias(); |
|
43 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
44 | - return $this->_left_join( |
|
45 | - $other_table, |
|
46 | - $other_table_alias, |
|
47 | - $other_table_pk_field->get_table_column(), |
|
48 | - $this_table_alias, |
|
49 | - $this_table_fk_field->get_table_column(), |
|
50 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
51 | - ) |
|
52 | - . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
53 | - } |
|
34 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
35 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
36 | + $model_relation_chain, |
|
37 | + $this->get_this_model()->get_this_model_name() |
|
38 | + ) . $this_table_fk_field->get_table_alias(); |
|
39 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
40 | + $model_relation_chain, |
|
41 | + $this->get_other_model()->get_this_model_name() |
|
42 | + ) . $other_table_pk_field->get_table_alias(); |
|
43 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
44 | + return $this->_left_join( |
|
45 | + $other_table, |
|
46 | + $other_table_alias, |
|
47 | + $other_table_pk_field->get_table_column(), |
|
48 | + $this_table_alias, |
|
49 | + $this_table_fk_field->get_table_column(), |
|
50 | + $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
51 | + ) |
|
52 | + . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
58 | - * you like. |
|
59 | - * |
|
60 | - * @param EE_Base_Class|int $this_obj_or_id |
|
61 | - * @param EE_Base_Class|int $other_obj_or_id |
|
62 | - * @param array $extra_join_model_fields_n_values |
|
63 | - * @return \EE_Base_Class |
|
64 | - * @throws \EE_Error |
|
65 | - */ |
|
66 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
67 | - { |
|
68 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
69 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
70 | - // find the field on THIS model which a foreign key to the other model |
|
71 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
72 | - // set that field on the other model to this model's ID |
|
73 | - $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
74 | - // and make sure this model's field with the foreign model name is set to the correct value |
|
75 | - $this_model_obj->set( |
|
76 | - $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
77 | - $this->get_other_model()->get_this_model_name() |
|
78 | - ); |
|
79 | - $this_model_obj->save(); |
|
80 | - return $other_model_obj; |
|
81 | - } |
|
56 | + /** |
|
57 | + * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
58 | + * you like. |
|
59 | + * |
|
60 | + * @param EE_Base_Class|int $this_obj_or_id |
|
61 | + * @param EE_Base_Class|int $other_obj_or_id |
|
62 | + * @param array $extra_join_model_fields_n_values |
|
63 | + * @return \EE_Base_Class |
|
64 | + * @throws \EE_Error |
|
65 | + */ |
|
66 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
67 | + { |
|
68 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
69 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
70 | + // find the field on THIS model which a foreign key to the other model |
|
71 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
72 | + // set that field on the other model to this model's ID |
|
73 | + $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
74 | + // and make sure this model's field with the foreign model name is set to the correct value |
|
75 | + $this_model_obj->set( |
|
76 | + $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
77 | + $this->get_other_model()->get_this_model_name() |
|
78 | + ); |
|
79 | + $this_model_obj->save(); |
|
80 | + return $other_model_obj; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
86 | - * |
|
87 | - * @param EE_Base_Class|int $this_obj_or_id |
|
88 | - * @param EE_Base_Class|int $other_obj_or_id |
|
89 | - * @param array $where_query |
|
90 | - * @return \EE_Base_Class |
|
91 | - * @throws \EE_Error |
|
92 | - */ |
|
93 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
94 | - { |
|
95 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
96 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
97 | - // find the field on the other model which is a foreign key to this model |
|
98 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
99 | - // set that field on the other model to this model's ID |
|
100 | - $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
101 | - $this_model_obj->set( |
|
102 | - $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
103 | - null, |
|
104 | - true |
|
105 | - ); |
|
106 | - $this_model_obj->save(); |
|
107 | - return $other_model_obj; |
|
108 | - } |
|
84 | + /** |
|
85 | + * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
86 | + * |
|
87 | + * @param EE_Base_Class|int $this_obj_or_id |
|
88 | + * @param EE_Base_Class|int $other_obj_or_id |
|
89 | + * @param array $where_query |
|
90 | + * @return \EE_Base_Class |
|
91 | + * @throws \EE_Error |
|
92 | + */ |
|
93 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
94 | + { |
|
95 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
96 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
97 | + // find the field on the other model which is a foreign key to this model |
|
98 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
99 | + // set that field on the other model to this model's ID |
|
100 | + $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
101 | + $this_model_obj->set( |
|
102 | + $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
103 | + null, |
|
104 | + true |
|
105 | + ); |
|
106 | + $this_model_obj->save(); |
|
107 | + return $other_model_obj; |
|
108 | + } |
|
109 | 109 | } |
@@ -35,19 +35,19 @@ |
||
35 | 35 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
36 | 36 | $model_relation_chain, |
37 | 37 | $this->get_this_model()->get_this_model_name() |
38 | - ) . $this_table_fk_field->get_table_alias(); |
|
39 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
38 | + ).$this_table_fk_field->get_table_alias(); |
|
39 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
40 | 40 | $model_relation_chain, |
41 | 41 | $this->get_other_model()->get_this_model_name() |
42 | - ) . $other_table_pk_field->get_table_alias(); |
|
43 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
42 | + ).$other_table_pk_field->get_table_alias(); |
|
43 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
44 | 44 | return $this->_left_join( |
45 | 45 | $other_table, |
46 | 46 | $other_table_alias, |
47 | 47 | $other_table_pk_field->get_table_column(), |
48 | 48 | $this_table_alias, |
49 | 49 | $this_table_fk_field->get_table_column(), |
50 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
50 | + $field_with_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
|
51 | 51 | ) |
52 | 52 | . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
53 | 53 | } |
@@ -11,102 +11,102 @@ |
||
11 | 11 | class EE_Has_Many_Relation extends EE_Model_Relation_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
16 | - * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
17 | - * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
18 | - * related models across the relation, and add-and-remove the relationships. |
|
19 | - * |
|
20 | - * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
21 | - * related models across this relation, block (prevent and add an |
|
22 | - * error) the deletion of this model |
|
23 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
24 | - * default |
|
25 | - */ |
|
26 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
27 | - { |
|
28 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
29 | - } |
|
14 | + /** |
|
15 | + * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
16 | + * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
17 | + * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
18 | + * related models across the relation, and add-and-remove the relationships. |
|
19 | + * |
|
20 | + * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
21 | + * related models across this relation, block (prevent and add an |
|
22 | + * error) the deletion of this model |
|
23 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
24 | + * default |
|
25 | + */ |
|
26 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
27 | + { |
|
28 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Gets the SQL string for performing the join between this model and the other model. |
|
34 | - * |
|
35 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
36 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
37 | - * other_model_primary_table.fk" etc |
|
38 | - * @throws \EE_Error |
|
39 | - */ |
|
40 | - public function get_join_statement($model_relation_chain) |
|
41 | - { |
|
42 | - // create the sql string like |
|
43 | - // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
44 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
45 | - $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
46 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
47 | - $model_relation_chain, |
|
48 | - $this->get_this_model()->get_this_model_name() |
|
49 | - ) . $this_table_pk_field->get_table_alias(); |
|
50 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
51 | - $model_relation_chain, |
|
52 | - $this->get_other_model()->get_this_model_name() |
|
53 | - ) . $other_table_fk_field->get_table_alias(); |
|
54 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
32 | + /** |
|
33 | + * Gets the SQL string for performing the join between this model and the other model. |
|
34 | + * |
|
35 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
36 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
37 | + * other_model_primary_table.fk" etc |
|
38 | + * @throws \EE_Error |
|
39 | + */ |
|
40 | + public function get_join_statement($model_relation_chain) |
|
41 | + { |
|
42 | + // create the sql string like |
|
43 | + // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
44 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
45 | + $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
46 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
47 | + $model_relation_chain, |
|
48 | + $this->get_this_model()->get_this_model_name() |
|
49 | + ) . $this_table_pk_field->get_table_alias(); |
|
50 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
51 | + $model_relation_chain, |
|
52 | + $this->get_other_model()->get_this_model_name() |
|
53 | + ) . $other_table_fk_field->get_table_alias(); |
|
54 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
55 | 55 | |
56 | - return $this->_left_join( |
|
57 | - $fk_table, |
|
58 | - $fk_table_alias, |
|
59 | - $other_table_fk_field->get_table_column(), |
|
60 | - $pk_table_alias, |
|
61 | - $this_table_pk_field->get_table_column() |
|
62 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
63 | - } |
|
56 | + return $this->_left_join( |
|
57 | + $fk_table, |
|
58 | + $fk_table_alias, |
|
59 | + $other_table_fk_field->get_table_column(), |
|
60 | + $pk_table_alias, |
|
61 | + $this_table_pk_field->get_table_column() |
|
62 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
68 | - * you like. |
|
69 | - * |
|
70 | - * @param EE_Base_Class|int $this_obj_or_id |
|
71 | - * @param EE_Base_Class|int $other_obj_or_id |
|
72 | - * @param array $extra_join_model_fields_n_values |
|
73 | - * @return \EE_Base_Class |
|
74 | - * @throws \EE_Error |
|
75 | - */ |
|
76 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
77 | - { |
|
78 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
79 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
66 | + /** |
|
67 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
68 | + * you like. |
|
69 | + * |
|
70 | + * @param EE_Base_Class|int $this_obj_or_id |
|
71 | + * @param EE_Base_Class|int $other_obj_or_id |
|
72 | + * @param array $extra_join_model_fields_n_values |
|
73 | + * @return \EE_Base_Class |
|
74 | + * @throws \EE_Error |
|
75 | + */ |
|
76 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
77 | + { |
|
78 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
79 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
80 | 80 | |
81 | - // find the field on the other model which is a foreign key to this model |
|
82 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
83 | - if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
84 | - // set that field on the other model to this model's ID |
|
85 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
86 | - $other_model_obj->save(); |
|
87 | - } |
|
88 | - return $other_model_obj; |
|
89 | - } |
|
81 | + // find the field on the other model which is a foreign key to this model |
|
82 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
83 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
84 | + // set that field on the other model to this model's ID |
|
85 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
86 | + $other_model_obj->save(); |
|
87 | + } |
|
88 | + return $other_model_obj; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
94 | - * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
95 | - * |
|
96 | - * @param EE_Base_Class|int $this_obj_or_id |
|
97 | - * @param EE_Base_Class|int $other_obj_or_id |
|
98 | - * @param array $where_query |
|
99 | - * @return \EE_Base_Class |
|
100 | - * @throws \EE_Error |
|
101 | - */ |
|
102 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
103 | - { |
|
104 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
105 | - // find the field on the other model which is a foreign key to this model |
|
106 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
107 | - // set that field on the other model to this model's ID |
|
108 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
109 | - $other_model_obj->save(); |
|
110 | - return $other_model_obj; |
|
111 | - } |
|
92 | + /** |
|
93 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
94 | + * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
95 | + * |
|
96 | + * @param EE_Base_Class|int $this_obj_or_id |
|
97 | + * @param EE_Base_Class|int $other_obj_or_id |
|
98 | + * @param array $where_query |
|
99 | + * @return \EE_Base_Class |
|
100 | + * @throws \EE_Error |
|
101 | + */ |
|
102 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
103 | + { |
|
104 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
105 | + // find the field on the other model which is a foreign key to this model |
|
106 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
107 | + // set that field on the other model to this model's ID |
|
108 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
109 | + $other_model_obj->save(); |
|
110 | + return $other_model_obj; |
|
111 | + } |
|
112 | 112 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
47 | 47 | $model_relation_chain, |
48 | 48 | $this->get_this_model()->get_this_model_name() |
49 | - ) . $this_table_pk_field->get_table_alias(); |
|
50 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
49 | + ).$this_table_pk_field->get_table_alias(); |
|
50 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
51 | 51 | $model_relation_chain, |
52 | 52 | $this->get_other_model()->get_this_model_name() |
53 | - ) . $other_table_fk_field->get_table_alias(); |
|
54 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
53 | + ).$other_table_fk_field->get_table_alias(); |
|
54 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
55 | 55 | |
56 | 56 | return $this->_left_join( |
57 | 57 | $fk_table, |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $other_table_fk_field->get_table_column(), |
60 | 60 | $pk_table_alias, |
61 | 61 | $this_table_pk_field->get_table_column() |
62 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
62 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 |
@@ -45,19 +45,19 @@ discard block |
||
45 | 45 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
46 | 46 | $model_relation_chain, |
47 | 47 | $this->get_this_model()->get_this_model_name() |
48 | - ) . $this_table_fk_field->get_table_alias(); |
|
49 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
48 | + ).$this_table_fk_field->get_table_alias(); |
|
49 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
50 | 50 | $model_relation_chain, |
51 | 51 | $this->get_other_model()->get_this_model_name() |
52 | - ) . $other_table_pk_field->get_table_alias(); |
|
53 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
52 | + ).$other_table_pk_field->get_table_alias(); |
|
53 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
54 | 54 | return $this->_left_join( |
55 | 55 | $other_table, |
56 | 56 | $other_table_alias, |
57 | 57 | $other_table_pk_field->get_table_column(), |
58 | 58 | $this_table_alias, |
59 | 59 | $this_table_fk_field->get_table_column() |
60 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
60 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name()); |
141 | 141 | // get all where their PK matches that value |
142 | - $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model; |
|
143 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
142 | + $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model; |
|
143 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
144 | 144 | // echo '$query_params'; |
145 | 145 | // var_dump($query_params); |
146 | 146 | return $this->get_other_model()->get_all($query_params); |
@@ -12,137 +12,137 @@ |
||
12 | 12 | class EE_Belongs_To_Relation extends EE_Model_Relation_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key |
|
17 | - * to the other model. This knows how to join the models, |
|
18 | - * get related models across the relation, and add-and-remove the relationships. |
|
19 | - * |
|
20 | - * @param boolean $block_deletes For Belongs_To relations, this is set to FALSE by |
|
21 | - * default. if there are related models across this |
|
22 | - * relation, block (prevent and add an error) the |
|
23 | - * deletion of this model |
|
24 | - * @param string $related_model_objects_deletion_error_message a customized error message on blocking deletes |
|
25 | - * instead of the default |
|
26 | - */ |
|
27 | - public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null) |
|
28 | - { |
|
29 | - parent::__construct($block_deletes, $related_model_objects_deletion_error_message); |
|
30 | - } |
|
15 | + /** |
|
16 | + * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key |
|
17 | + * to the other model. This knows how to join the models, |
|
18 | + * get related models across the relation, and add-and-remove the relationships. |
|
19 | + * |
|
20 | + * @param boolean $block_deletes For Belongs_To relations, this is set to FALSE by |
|
21 | + * default. if there are related models across this |
|
22 | + * relation, block (prevent and add an error) the |
|
23 | + * deletion of this model |
|
24 | + * @param string $related_model_objects_deletion_error_message a customized error message on blocking deletes |
|
25 | + * instead of the default |
|
26 | + */ |
|
27 | + public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null) |
|
28 | + { |
|
29 | + parent::__construct($block_deletes, $related_model_objects_deletion_error_message); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * get_join_statement |
|
35 | - * |
|
36 | - * @param string $model_relation_chain |
|
37 | - * @return string |
|
38 | - * @throws \EE_Error |
|
39 | - */ |
|
40 | - public function get_join_statement($model_relation_chain) |
|
41 | - { |
|
42 | - // create the sql string like |
|
43 | - $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
44 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
45 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
46 | - $model_relation_chain, |
|
47 | - $this->get_this_model()->get_this_model_name() |
|
48 | - ) . $this_table_fk_field->get_table_alias(); |
|
49 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
50 | - $model_relation_chain, |
|
51 | - $this->get_other_model()->get_this_model_name() |
|
52 | - ) . $other_table_pk_field->get_table_alias(); |
|
53 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
54 | - return $this->_left_join( |
|
55 | - $other_table, |
|
56 | - $other_table_alias, |
|
57 | - $other_table_pk_field->get_table_column(), |
|
58 | - $this_table_alias, |
|
59 | - $this_table_fk_field->get_table_column() |
|
60 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
61 | - } |
|
33 | + /** |
|
34 | + * get_join_statement |
|
35 | + * |
|
36 | + * @param string $model_relation_chain |
|
37 | + * @return string |
|
38 | + * @throws \EE_Error |
|
39 | + */ |
|
40 | + public function get_join_statement($model_relation_chain) |
|
41 | + { |
|
42 | + // create the sql string like |
|
43 | + $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
44 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
45 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
46 | + $model_relation_chain, |
|
47 | + $this->get_this_model()->get_this_model_name() |
|
48 | + ) . $this_table_fk_field->get_table_alias(); |
|
49 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
50 | + $model_relation_chain, |
|
51 | + $this->get_other_model()->get_this_model_name() |
|
52 | + ) . $other_table_pk_field->get_table_alias(); |
|
53 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
54 | + return $this->_left_join( |
|
55 | + $other_table, |
|
56 | + $other_table_alias, |
|
57 | + $other_table_pk_field->get_table_column(), |
|
58 | + $this_table_alias, |
|
59 | + $this_table_fk_field->get_table_column() |
|
60 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
66 | - * you like. |
|
67 | - * |
|
68 | - * @param EE_Base_Class|int $this_obj_or_id |
|
69 | - * @param EE_Base_Class|int $other_obj_or_id |
|
70 | - * @param array $extra_join_model_fields_n_values |
|
71 | - * @return \EE_Base_Class |
|
72 | - * @throws \EE_Error |
|
73 | - */ |
|
74 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
75 | - { |
|
76 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
77 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
78 | - // find the field on the other model which is a foreign key to this model |
|
79 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
80 | - if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) { |
|
81 | - // set that field on the other model to this model's ID |
|
82 | - $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
83 | - $this_model_obj->save(); |
|
84 | - } |
|
85 | - return $other_model_obj; |
|
86 | - } |
|
64 | + /** |
|
65 | + * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
66 | + * you like. |
|
67 | + * |
|
68 | + * @param EE_Base_Class|int $this_obj_or_id |
|
69 | + * @param EE_Base_Class|int $other_obj_or_id |
|
70 | + * @param array $extra_join_model_fields_n_values |
|
71 | + * @return \EE_Base_Class |
|
72 | + * @throws \EE_Error |
|
73 | + */ |
|
74 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
75 | + { |
|
76 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
77 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
78 | + // find the field on the other model which is a foreign key to this model |
|
79 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
80 | + if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) { |
|
81 | + // set that field on the other model to this model's ID |
|
82 | + $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
83 | + $this_model_obj->save(); |
|
84 | + } |
|
85 | + return $other_model_obj; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
91 | - * |
|
92 | - * @param EE_Base_Class|int $this_obj_or_id |
|
93 | - * @param EE_Base_Class|int $other_obj_or_id |
|
94 | - * @param array $where_query |
|
95 | - * @return \EE_Base_Class |
|
96 | - * @throws \EE_Error |
|
97 | - */ |
|
98 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
99 | - { |
|
100 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
101 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
102 | - // find the field on the other model which is a foreign key to this model |
|
103 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
104 | - // set that field on the other model to this model's ID |
|
105 | - $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
106 | - $this_model_obj->save(); |
|
107 | - return $other_model_obj; |
|
108 | - } |
|
89 | + /** |
|
90 | + * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
91 | + * |
|
92 | + * @param EE_Base_Class|int $this_obj_or_id |
|
93 | + * @param EE_Base_Class|int $other_obj_or_id |
|
94 | + * @param array $where_query |
|
95 | + * @return \EE_Base_Class |
|
96 | + * @throws \EE_Error |
|
97 | + */ |
|
98 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
99 | + { |
|
100 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
101 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
102 | + // find the field on the other model which is a foreign key to this model |
|
103 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
104 | + // set that field on the other model to this model's ID |
|
105 | + $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
106 | + $this_model_obj->save(); |
|
107 | + return $other_model_obj; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Overrides parent so that we don't NEED to save the $model_object before getting the related objects. |
|
113 | - * |
|
114 | - * @param EE_Base_Class $model_obj_or_id |
|
115 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
116 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
117 | - * @return EE_Base_Class[] |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public function get_all_related( |
|
121 | - $model_obj_or_id, |
|
122 | - $query_params = array(), |
|
123 | - $values_already_prepared_by_model_object = false |
|
124 | - ) { |
|
125 | - if ($values_already_prepared_by_model_object !== false) { |
|
126 | - EE_Error::doing_it_wrong( |
|
127 | - 'EE_Model_Relation_Base::get_all_related', |
|
128 | - __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
129 | - '4.8.1' |
|
130 | - ); |
|
131 | - } |
|
132 | - // get column on this model object which is a foreign key to the other model |
|
133 | - $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
134 | - // get its value |
|
135 | - if ($model_obj_or_id instanceof EE_Base_Class) { |
|
136 | - $model_obj = $model_obj_or_id; |
|
137 | - } else { |
|
138 | - $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id); |
|
139 | - } |
|
140 | - $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name()); |
|
141 | - // get all where their PK matches that value |
|
142 | - $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model; |
|
143 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
111 | + /** |
|
112 | + * Overrides parent so that we don't NEED to save the $model_object before getting the related objects. |
|
113 | + * |
|
114 | + * @param EE_Base_Class $model_obj_or_id |
|
115 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
116 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
117 | + * @return EE_Base_Class[] |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public function get_all_related( |
|
121 | + $model_obj_or_id, |
|
122 | + $query_params = array(), |
|
123 | + $values_already_prepared_by_model_object = false |
|
124 | + ) { |
|
125 | + if ($values_already_prepared_by_model_object !== false) { |
|
126 | + EE_Error::doing_it_wrong( |
|
127 | + 'EE_Model_Relation_Base::get_all_related', |
|
128 | + __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
129 | + '4.8.1' |
|
130 | + ); |
|
131 | + } |
|
132 | + // get column on this model object which is a foreign key to the other model |
|
133 | + $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
134 | + // get its value |
|
135 | + if ($model_obj_or_id instanceof EE_Base_Class) { |
|
136 | + $model_obj = $model_obj_or_id; |
|
137 | + } else { |
|
138 | + $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id); |
|
139 | + } |
|
140 | + $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name()); |
|
141 | + // get all where their PK matches that value |
|
142 | + $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model; |
|
143 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
144 | 144 | // echo '$query_params'; |
145 | 145 | // var_dump($query_params); |
146 | - return $this->get_other_model()->get_all($query_params); |
|
147 | - } |
|
146 | + return $this->get_other_model()->get_all($query_params); |
|
147 | + } |
|
148 | 148 | } |
@@ -10,294 +10,294 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_HABTM_Any_Relation extends EE_HABTM_Relation |
12 | 12 | { |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $_alphabetically_first_model_name; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $_alphabetically_first_model_name; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
20 | - * (and an ee joining-model.) This knows how to join the models, |
|
21 | - * get related models across the relation, and add-and-remove the relationships. |
|
22 | - * |
|
23 | - * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
24 | - * are related models across this relation, block (prevent and add an |
|
25 | - * error) the deletion of this model |
|
26 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
27 | - * default |
|
28 | - */ |
|
29 | - public function __construct($block_deletes = true, $blocking_delete_error_message = '') |
|
30 | - { |
|
31 | - parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
32 | - } |
|
18 | + /** |
|
19 | + * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
20 | + * (and an ee joining-model.) This knows how to join the models, |
|
21 | + * get related models across the relation, and add-and-remove the relationships. |
|
22 | + * |
|
23 | + * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
24 | + * are related models across this relation, block (prevent and add an |
|
25 | + * error) the deletion of this model |
|
26 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
27 | + * default |
|
28 | + */ |
|
29 | + public function __construct($block_deletes = true, $blocking_delete_error_message = '') |
|
30 | + { |
|
31 | + parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @param $this_model_name |
|
37 | - * @param $other_model_name |
|
38 | - * @throws EE_Error |
|
39 | - */ |
|
40 | - public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
41 | - { |
|
42 | - if ($this_model_name < $other_model_name) { |
|
43 | - $this->_alphabetically_first_model_name = $this_model_name; |
|
44 | - } else { |
|
45 | - $this->_alphabetically_first_model_name = $other_model_name; |
|
46 | - } |
|
47 | - parent::_construct_finalize_set_models($this_model_name, $other_model_name); |
|
48 | - } |
|
35 | + /** |
|
36 | + * @param $this_model_name |
|
37 | + * @param $other_model_name |
|
38 | + * @throws EE_Error |
|
39 | + */ |
|
40 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
41 | + { |
|
42 | + if ($this_model_name < $other_model_name) { |
|
43 | + $this->_alphabetically_first_model_name = $this_model_name; |
|
44 | + } else { |
|
45 | + $this->_alphabetically_first_model_name = $other_model_name; |
|
46 | + } |
|
47 | + parent::_construct_finalize_set_models($this_model_name, $other_model_name); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @param string $model_name |
|
53 | - * @param string $id_or_name_field should be the string 'ID' or 'name' only |
|
54 | - * @return EE_Model_Field_Base |
|
55 | - * @throws \EE_Error |
|
56 | - */ |
|
57 | - public function get_join_table_fk_field_to($model_name, $id_or_name_field) |
|
58 | - { |
|
59 | - $order = null; |
|
60 | - if ($model_name === $this->_alphabetically_first_model_name) { |
|
61 | - $order = 'first'; |
|
62 | - } else { |
|
63 | - $order = 'second'; |
|
64 | - } |
|
65 | - return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field); |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param string $model_name |
|
53 | + * @param string $id_or_name_field should be the string 'ID' or 'name' only |
|
54 | + * @return EE_Model_Field_Base |
|
55 | + * @throws \EE_Error |
|
56 | + */ |
|
57 | + public function get_join_table_fk_field_to($model_name, $id_or_name_field) |
|
58 | + { |
|
59 | + $order = null; |
|
60 | + if ($model_name === $this->_alphabetically_first_model_name) { |
|
61 | + $order = 'first'; |
|
62 | + } else { |
|
63 | + $order = 'second'; |
|
64 | + } |
|
65 | + return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
71 | - * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
72 | - * |
|
73 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
74 | - * @return string of SQL |
|
75 | - * @throws \EE_Error |
|
76 | - */ |
|
77 | - public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
78 | - { |
|
79 | - // create sql like |
|
80 | - // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
81 | - // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
82 | - // remember the model relation chain to the JOIN model, because we'll |
|
83 | - // need it for get_join_statement() |
|
84 | - $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
85 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
86 | - $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
87 | - $this->get_this_model()->get_this_model_name(), |
|
88 | - 'ID' |
|
89 | - ); |
|
90 | - $field_with_model_name = $this->get_join_table_fk_field_to( |
|
91 | - $this->get_this_model()->get_this_model_name(), |
|
92 | - 'name' |
|
93 | - ); |
|
94 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
95 | - $model_relation_chain, |
|
96 | - $this->get_this_model()->get_this_model_name() |
|
97 | - ) . $this_table_pk_field->get_table_alias(); |
|
98 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
99 | - $model_relation_chain, |
|
100 | - $this->get_join_model()->get_this_model_name() |
|
101 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
102 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
103 | - // phew! ok, we have all the info we need, now we can create the SQL join string |
|
104 | - $SQL = $this->_left_join( |
|
105 | - $join_table, |
|
106 | - $join_table_alias, |
|
107 | - $join_table_fk_field_to_this_table->get_table_column(), |
|
108 | - $this_table_alias, |
|
109 | - $this_table_pk_field->get_table_column(), |
|
110 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
111 | - ) . |
|
112 | - $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
69 | + /** |
|
70 | + * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
71 | + * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
72 | + * |
|
73 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
74 | + * @return string of SQL |
|
75 | + * @throws \EE_Error |
|
76 | + */ |
|
77 | + public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
78 | + { |
|
79 | + // create sql like |
|
80 | + // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
81 | + // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
82 | + // remember the model relation chain to the JOIN model, because we'll |
|
83 | + // need it for get_join_statement() |
|
84 | + $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
85 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
86 | + $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
87 | + $this->get_this_model()->get_this_model_name(), |
|
88 | + 'ID' |
|
89 | + ); |
|
90 | + $field_with_model_name = $this->get_join_table_fk_field_to( |
|
91 | + $this->get_this_model()->get_this_model_name(), |
|
92 | + 'name' |
|
93 | + ); |
|
94 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
95 | + $model_relation_chain, |
|
96 | + $this->get_this_model()->get_this_model_name() |
|
97 | + ) . $this_table_pk_field->get_table_alias(); |
|
98 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
99 | + $model_relation_chain, |
|
100 | + $this->get_join_model()->get_this_model_name() |
|
101 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
102 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
103 | + // phew! ok, we have all the info we need, now we can create the SQL join string |
|
104 | + $SQL = $this->_left_join( |
|
105 | + $join_table, |
|
106 | + $join_table_alias, |
|
107 | + $join_table_fk_field_to_this_table->get_table_column(), |
|
108 | + $this_table_alias, |
|
109 | + $this_table_pk_field->get_table_column(), |
|
110 | + $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
111 | + ) . |
|
112 | + $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
113 | 113 | |
114 | - return $SQL; |
|
115 | - } |
|
114 | + return $SQL; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | - /** |
|
119 | - * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
120 | - * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
121 | - * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
122 | - * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
123 | - * the intermediate join table, and then to the other model's pk's table |
|
124 | - * |
|
125 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
126 | - * @return string of SQL |
|
127 | - * @throws \EE_Error |
|
128 | - */ |
|
129 | - public function get_join_statement($model_relation_chain) |
|
130 | - { |
|
131 | - if ($this->_model_relation_chain_to_join_model === null) { |
|
132 | - throw new EE_Error(sprintf(__( |
|
133 | - 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
134 | - 'event_espresso' |
|
135 | - ))); |
|
136 | - } |
|
137 | - $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
138 | - $this->get_this_model()->get_this_model_name(), |
|
139 | - 'ID' |
|
140 | - ); |
|
141 | - $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to( |
|
142 | - $this->get_other_model()->get_this_model_name(), |
|
143 | - 'ID' |
|
144 | - ); |
|
145 | - $field_with_other_model_name = $this->get_join_table_fk_field_to( |
|
146 | - $this->get_other_model()->get_this_model_name(), |
|
147 | - 'name' |
|
148 | - ); |
|
118 | + /** |
|
119 | + * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
120 | + * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
121 | + * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
122 | + * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
123 | + * the intermediate join table, and then to the other model's pk's table |
|
124 | + * |
|
125 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
126 | + * @return string of SQL |
|
127 | + * @throws \EE_Error |
|
128 | + */ |
|
129 | + public function get_join_statement($model_relation_chain) |
|
130 | + { |
|
131 | + if ($this->_model_relation_chain_to_join_model === null) { |
|
132 | + throw new EE_Error(sprintf(__( |
|
133 | + 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
134 | + 'event_espresso' |
|
135 | + ))); |
|
136 | + } |
|
137 | + $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
138 | + $this->get_this_model()->get_this_model_name(), |
|
139 | + 'ID' |
|
140 | + ); |
|
141 | + $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to( |
|
142 | + $this->get_other_model()->get_this_model_name(), |
|
143 | + 'ID' |
|
144 | + ); |
|
145 | + $field_with_other_model_name = $this->get_join_table_fk_field_to( |
|
146 | + $this->get_other_model()->get_this_model_name(), |
|
147 | + 'name' |
|
148 | + ); |
|
149 | 149 | |
150 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
151 | - $this->_model_relation_chain_to_join_model, |
|
152 | - $this->get_join_model()->get_this_model_name() |
|
153 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
150 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
151 | + $this->_model_relation_chain_to_join_model, |
|
152 | + $this->get_join_model()->get_this_model_name() |
|
153 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
154 | 154 | |
155 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
156 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
157 | - $model_relation_chain, |
|
158 | - $this->get_other_model()->get_this_model_name() |
|
159 | - ) . $other_table_pk_field->get_table_alias(); |
|
160 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
155 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
156 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
157 | + $model_relation_chain, |
|
158 | + $this->get_other_model()->get_this_model_name() |
|
159 | + ) . $other_table_pk_field->get_table_alias(); |
|
160 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
161 | 161 | |
162 | - $SQL = $this->_left_join( |
|
163 | - $other_table, |
|
164 | - $other_table_alias, |
|
165 | - $other_table_pk_field->get_table_column(), |
|
166 | - $join_table_alias, |
|
167 | - $join_table_fk_field_to_other_table->get_table_column(), |
|
168 | - $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
169 | - ) . |
|
170 | - $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
171 | - return $SQL; |
|
172 | - } |
|
162 | + $SQL = $this->_left_join( |
|
163 | + $other_table, |
|
164 | + $other_table_alias, |
|
165 | + $other_table_pk_field->get_table_column(), |
|
166 | + $join_table_alias, |
|
167 | + $join_table_fk_field_to_other_table->get_table_column(), |
|
168 | + $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
169 | + ) . |
|
170 | + $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
171 | + return $SQL; |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
177 | - * |
|
178 | - * @param EE_Base_Class|int $this_obj_or_id |
|
179 | - * @param EE_Base_Class|int $other_obj_or_id |
|
180 | - * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
181 | - * checking existing values and for setting new rows if |
|
182 | - * no exact matches. |
|
183 | - * @return EE_Base_Class |
|
184 | - * @throws \EE_Error |
|
185 | - */ |
|
186 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
187 | - { |
|
188 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
189 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
190 | - // check if such a relationship already exists |
|
191 | - $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
192 | - $this->get_this_model()->get_this_model_name(), |
|
193 | - 'ID' |
|
194 | - ); |
|
195 | - $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
196 | - $this->get_this_model()->get_this_model_name(), |
|
197 | - 'name' |
|
198 | - ); |
|
199 | - $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
200 | - $this->get_other_model()->get_this_model_name(), |
|
201 | - 'ID' |
|
202 | - ); |
|
203 | - $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to( |
|
204 | - $this->get_other_model()->get_this_model_name(), |
|
205 | - 'name' |
|
206 | - ); |
|
175 | + /** |
|
176 | + * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
177 | + * |
|
178 | + * @param EE_Base_Class|int $this_obj_or_id |
|
179 | + * @param EE_Base_Class|int $other_obj_or_id |
|
180 | + * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
181 | + * checking existing values and for setting new rows if |
|
182 | + * no exact matches. |
|
183 | + * @return EE_Base_Class |
|
184 | + * @throws \EE_Error |
|
185 | + */ |
|
186 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
187 | + { |
|
188 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
189 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
190 | + // check if such a relationship already exists |
|
191 | + $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
192 | + $this->get_this_model()->get_this_model_name(), |
|
193 | + 'ID' |
|
194 | + ); |
|
195 | + $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
196 | + $this->get_this_model()->get_this_model_name(), |
|
197 | + 'name' |
|
198 | + ); |
|
199 | + $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
200 | + $this->get_other_model()->get_this_model_name(), |
|
201 | + 'ID' |
|
202 | + ); |
|
203 | + $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to( |
|
204 | + $this->get_other_model()->get_this_model_name(), |
|
205 | + 'name' |
|
206 | + ); |
|
207 | 207 | |
208 | - $cols_n_values = array( |
|
209 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
210 | - $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
|
211 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
212 | - $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(), |
|
213 | - ); |
|
208 | + $cols_n_values = array( |
|
209 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
210 | + $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
|
211 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
212 | + $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(), |
|
213 | + ); |
|
214 | 214 | |
215 | - // if $where_query exists lets add them to the query_params. |
|
216 | - if (! empty($extra_join_model_fields_n_values)) { |
|
217 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
218 | - // make sure we strip THIS models name from the query param |
|
219 | - $parsed_query = array(); |
|
220 | - foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
221 | - $query_param = str_replace( |
|
222 | - $this->get_join_model()->get_this_model_name() . ".", |
|
223 | - "", |
|
224 | - $query_param |
|
225 | - ); |
|
226 | - $parsed_query[ $query_param ] = $val; |
|
227 | - } |
|
228 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
229 | - } |
|
215 | + // if $where_query exists lets add them to the query_params. |
|
216 | + if (! empty($extra_join_model_fields_n_values)) { |
|
217 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
218 | + // make sure we strip THIS models name from the query param |
|
219 | + $parsed_query = array(); |
|
220 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
221 | + $query_param = str_replace( |
|
222 | + $this->get_join_model()->get_this_model_name() . ".", |
|
223 | + "", |
|
224 | + $query_param |
|
225 | + ); |
|
226 | + $parsed_query[ $query_param ] = $val; |
|
227 | + } |
|
228 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
229 | + } |
|
230 | 230 | |
231 | - $query_params = array($cols_n_values); |
|
231 | + $query_params = array($cols_n_values); |
|
232 | 232 | |
233 | 233 | |
234 | - $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
|
235 | - // if there is already an entry in the join table, indicating a relationship, we're done |
|
236 | - // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
237 | - // the other tables, use the joining model directly! |
|
238 | - if (! $existing_entry_in_join_table) { |
|
239 | - $this->get_join_model()->insert($cols_n_values); |
|
240 | - } |
|
241 | - return $other_model_obj; |
|
242 | - } |
|
234 | + $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
|
235 | + // if there is already an entry in the join table, indicating a relationship, we're done |
|
236 | + // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
237 | + // the other tables, use the joining model directly! |
|
238 | + if (! $existing_entry_in_join_table) { |
|
239 | + $this->get_join_model()->insert($cols_n_values); |
|
240 | + } |
|
241 | + return $other_model_obj; |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
247 | - * |
|
248 | - * @param EE_Base_Class|int $this_obj_or_id |
|
249 | - * @param EE_Base_Class|int $other_obj_or_id |
|
250 | - * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
251 | - * values and for removing existing rows if exact matches exist. |
|
252 | - * @return EE_Base_Class |
|
253 | - * @throws \EE_Error |
|
254 | - */ |
|
255 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
256 | - { |
|
257 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
258 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
259 | - // check if such a relationship already exists |
|
260 | - $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
261 | - $this->get_this_model()->get_this_model_name(), |
|
262 | - 'ID' |
|
263 | - ); |
|
264 | - $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
265 | - $this->get_this_model()->get_this_model_name(), |
|
266 | - 'name' |
|
267 | - ); |
|
268 | - $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
269 | - $this->get_other_model()->get_this_model_name(), |
|
270 | - 'ID' |
|
271 | - ); |
|
272 | - $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to( |
|
273 | - $this->get_other_model()->get_this_model_name(), |
|
274 | - 'name' |
|
275 | - ); |
|
245 | + /** |
|
246 | + * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
247 | + * |
|
248 | + * @param EE_Base_Class|int $this_obj_or_id |
|
249 | + * @param EE_Base_Class|int $other_obj_or_id |
|
250 | + * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
251 | + * values and for removing existing rows if exact matches exist. |
|
252 | + * @return EE_Base_Class |
|
253 | + * @throws \EE_Error |
|
254 | + */ |
|
255 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
256 | + { |
|
257 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
258 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
259 | + // check if such a relationship already exists |
|
260 | + $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
261 | + $this->get_this_model()->get_this_model_name(), |
|
262 | + 'ID' |
|
263 | + ); |
|
264 | + $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
265 | + $this->get_this_model()->get_this_model_name(), |
|
266 | + 'name' |
|
267 | + ); |
|
268 | + $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
269 | + $this->get_other_model()->get_this_model_name(), |
|
270 | + 'ID' |
|
271 | + ); |
|
272 | + $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to( |
|
273 | + $this->get_other_model()->get_this_model_name(), |
|
274 | + 'name' |
|
275 | + ); |
|
276 | 276 | |
277 | - $cols_n_values = array( |
|
278 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
279 | - $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
|
280 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
281 | - $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(), |
|
282 | - ); |
|
277 | + $cols_n_values = array( |
|
278 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
279 | + $join_model_name_field_to_this_model->get_name() => $this_model_obj->get_model()->get_this_model_name(), |
|
280 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
281 | + $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(), |
|
282 | + ); |
|
283 | 283 | |
284 | - // if $where_query exists lets add them to the query_params. |
|
285 | - if (! empty($where_query)) { |
|
286 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
287 | - // make sure we strip THIS models name from the query param |
|
288 | - $parsed_query = array(); |
|
289 | - foreach ($where_query as $query_param => $val) { |
|
290 | - $query_param = str_replace( |
|
291 | - $this->get_join_model()->get_this_model_name() . ".", |
|
292 | - "", |
|
293 | - $query_param |
|
294 | - ); |
|
295 | - $parsed_query[ $query_param ] = $val; |
|
296 | - } |
|
297 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
298 | - } |
|
284 | + // if $where_query exists lets add them to the query_params. |
|
285 | + if (! empty($where_query)) { |
|
286 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
287 | + // make sure we strip THIS models name from the query param |
|
288 | + $parsed_query = array(); |
|
289 | + foreach ($where_query as $query_param => $val) { |
|
290 | + $query_param = str_replace( |
|
291 | + $this->get_join_model()->get_this_model_name() . ".", |
|
292 | + "", |
|
293 | + $query_param |
|
294 | + ); |
|
295 | + $parsed_query[ $query_param ] = $val; |
|
296 | + } |
|
297 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
298 | + } |
|
299 | 299 | |
300 | - $this->get_join_model()->delete(array($cols_n_values)); |
|
301 | - return $other_model_obj; |
|
302 | - } |
|
300 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
301 | + return $other_model_obj; |
|
302 | + } |
|
303 | 303 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | } else { |
63 | 63 | $order = 'second'; |
64 | 64 | } |
65 | - return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field); |
|
65 | + return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
@@ -87,19 +87,19 @@ discard block |
||
87 | 87 | $this->get_this_model()->get_this_model_name(), |
88 | 88 | 'ID' |
89 | 89 | ); |
90 | - $field_with_model_name = $this->get_join_table_fk_field_to( |
|
90 | + $field_with_model_name = $this->get_join_table_fk_field_to( |
|
91 | 91 | $this->get_this_model()->get_this_model_name(), |
92 | 92 | 'name' |
93 | 93 | ); |
94 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
94 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
95 | 95 | $model_relation_chain, |
96 | 96 | $this->get_this_model()->get_this_model_name() |
97 | - ) . $this_table_pk_field->get_table_alias(); |
|
98 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
97 | + ).$this_table_pk_field->get_table_alias(); |
|
98 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
99 | 99 | $model_relation_chain, |
100 | 100 | $this->get_join_model()->get_this_model_name() |
101 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
102 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
101 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
102 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
103 | 103 | // phew! ok, we have all the info we need, now we can create the SQL join string |
104 | 104 | $SQL = $this->_left_join( |
105 | 105 | $join_table, |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $join_table_fk_field_to_this_table->get_table_column(), |
108 | 108 | $this_table_alias, |
109 | 109 | $this_table_pk_field->get_table_column(), |
110 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
111 | - ) . |
|
110 | + $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'" |
|
111 | + ). |
|
112 | 112 | $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
113 | 113 | |
114 | 114 | return $SQL; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | 'event_espresso' |
135 | 135 | ))); |
136 | 136 | } |
137 | - $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
137 | + $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to( |
|
138 | 138 | $this->get_this_model()->get_this_model_name(), |
139 | 139 | 'ID' |
140 | 140 | ); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $this->get_other_model()->get_this_model_name(), |
143 | 143 | 'ID' |
144 | 144 | ); |
145 | - $field_with_other_model_name = $this->get_join_table_fk_field_to( |
|
145 | + $field_with_other_model_name = $this->get_join_table_fk_field_to( |
|
146 | 146 | $this->get_other_model()->get_this_model_name(), |
147 | 147 | 'name' |
148 | 148 | ); |
@@ -150,14 +150,14 @@ discard block |
||
150 | 150 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
151 | 151 | $this->_model_relation_chain_to_join_model, |
152 | 152 | $this->get_join_model()->get_this_model_name() |
153 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
153 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
154 | 154 | |
155 | 155 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
156 | 156 | $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
157 | 157 | $model_relation_chain, |
158 | 158 | $this->get_other_model()->get_this_model_name() |
159 | - ) . $other_table_pk_field->get_table_alias(); |
|
160 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
159 | + ).$other_table_pk_field->get_table_alias(); |
|
160 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
161 | 161 | |
162 | 162 | $SQL = $this->_left_join( |
163 | 163 | $other_table, |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | $other_table_pk_field->get_table_column(), |
166 | 166 | $join_table_alias, |
167 | 167 | $join_table_fk_field_to_other_table->get_table_column(), |
168 | - $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
169 | - ) . |
|
168 | + $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
|
169 | + ). |
|
170 | 170 | $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
171 | 171 | return $SQL; |
172 | 172 | } |
@@ -188,15 +188,15 @@ discard block |
||
188 | 188 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
189 | 189 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
190 | 190 | // check if such a relationship already exists |
191 | - $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
191 | + $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
192 | 192 | $this->get_this_model()->get_this_model_name(), |
193 | 193 | 'ID' |
194 | 194 | ); |
195 | - $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
195 | + $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
196 | 196 | $this->get_this_model()->get_this_model_name(), |
197 | 197 | 'name' |
198 | 198 | ); |
199 | - $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
199 | + $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
200 | 200 | $this->get_other_model()->get_this_model_name(), |
201 | 201 | 'ID' |
202 | 202 | ); |
@@ -213,17 +213,17 @@ discard block |
||
213 | 213 | ); |
214 | 214 | |
215 | 215 | // if $where_query exists lets add them to the query_params. |
216 | - if (! empty($extra_join_model_fields_n_values)) { |
|
216 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
217 | 217 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
218 | 218 | // make sure we strip THIS models name from the query param |
219 | 219 | $parsed_query = array(); |
220 | 220 | foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
221 | - $query_param = str_replace( |
|
222 | - $this->get_join_model()->get_this_model_name() . ".", |
|
221 | + $query_param = str_replace( |
|
222 | + $this->get_join_model()->get_this_model_name().".", |
|
223 | 223 | "", |
224 | 224 | $query_param |
225 | 225 | ); |
226 | - $parsed_query[ $query_param ] = $val; |
|
226 | + $parsed_query[$query_param] = $val; |
|
227 | 227 | } |
228 | 228 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
229 | 229 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | // if there is already an entry in the join table, indicating a relationship, we're done |
236 | 236 | // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
237 | 237 | // the other tables, use the joining model directly! |
238 | - if (! $existing_entry_in_join_table) { |
|
238 | + if ( ! $existing_entry_in_join_table) { |
|
239 | 239 | $this->get_join_model()->insert($cols_n_values); |
240 | 240 | } |
241 | 241 | return $other_model_obj; |
@@ -257,15 +257,15 @@ discard block |
||
257 | 257 | $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
258 | 258 | $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
259 | 259 | // check if such a relationship already exists |
260 | - $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
260 | + $join_model_fk_to_this_model = $this->get_join_table_fk_field_to( |
|
261 | 261 | $this->get_this_model()->get_this_model_name(), |
262 | 262 | 'ID' |
263 | 263 | ); |
264 | - $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
264 | + $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to( |
|
265 | 265 | $this->get_this_model()->get_this_model_name(), |
266 | 266 | 'name' |
267 | 267 | ); |
268 | - $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
268 | + $join_model_fk_to_other_model = $this->get_join_table_fk_field_to( |
|
269 | 269 | $this->get_other_model()->get_this_model_name(), |
270 | 270 | 'ID' |
271 | 271 | ); |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | ); |
283 | 283 | |
284 | 284 | // if $where_query exists lets add them to the query_params. |
285 | - if (! empty($where_query)) { |
|
285 | + if ( ! empty($where_query)) { |
|
286 | 286 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
287 | 287 | // make sure we strip THIS models name from the query param |
288 | 288 | $parsed_query = array(); |
289 | 289 | foreach ($where_query as $query_param => $val) { |
290 | - $query_param = str_replace( |
|
291 | - $this->get_join_model()->get_this_model_name() . ".", |
|
290 | + $query_param = str_replace( |
|
291 | + $this->get_join_model()->get_this_model_name().".", |
|
292 | 292 | "", |
293 | 293 | $query_param |
294 | 294 | ); |
295 | - $parsed_query[ $query_param ] = $val; |
|
295 | + $parsed_query[$query_param] = $val; |
|
296 | 296 | } |
297 | 297 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
298 | 298 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects); |
191 | 191 | foreach ($autosave_relations as $a_r) { |
192 | 192 | $pid = $a_r->parent(); |
193 | - if (! empty($pid)) { |
|
193 | + if ( ! empty($pid)) { |
|
194 | 194 | $parent_ids[] = $pid; |
195 | 195 | } else { |
196 | 196 | $return_objs[] = $a_r; |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | // now we setup the query to get all the parents |
209 | - if (! empty($parent_ids)) { |
|
210 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
211 | - $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids); |
|
209 | + if ( ! empty($parent_ids)) { |
|
210 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name(); |
|
211 | + $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids); |
|
212 | 212 | $parents = $this->get_other_model()->get_all($query_params); |
213 | 213 | } |
214 | 214 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | var_dump($this_obj); |
244 | 244 | var_dump($other_obj);/**/ |
245 | 245 | |
246 | - if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
246 | + if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
247 | 247 | // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table. |
248 | 248 | $has_parent_obj = $this->get_other_model()->get_one(array( |
249 | 249 | array( |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $other_obj->set($pk_on_related_model, $has_parent_obj->ID()); |
260 | 260 | $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
261 | 261 | |
262 | - if (! $remove_relation) { |
|
262 | + if ( ! $remove_relation) { |
|
263 | 263 | $other_obj->save(); |
264 | 264 | return array($other_obj); |
265 | 265 | } elseif ($remove_relation && ! $this->_blocking_delete) { |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method. |
288 | 288 | } else { |
289 | 289 | // we only need to do the below IF this is not a remove relation |
290 | - if (! $remove_relation) { |
|
290 | + if ( ! $remove_relation) { |
|
291 | 291 | // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object. |
292 | 292 | // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first. |
293 | 293 | $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID()); |
@@ -12,303 +12,303 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for |
|
17 | - * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this |
|
18 | - * value). The _primary_cpt_field is what is equivalent to the post_id field on a cpt join. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - private $_primary_cpt_field; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * This is what field serves as the "parent" column that is linked with whatever the main model's calling this |
|
27 | - * relation has as a primary key. In other words EEM_Event has 'Datetime' => new |
|
28 | - * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent'). That means that in the EEM_Datetime model the |
|
29 | - * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the |
|
30 | - * primary key in the other model (EEM_Datetime). |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - private $_parent_pk_relation_field; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
39 | - * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
40 | - * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
41 | - * related models across the relation, and add-and-remove the relationships. |
|
42 | - * |
|
43 | - * @param string $primary_cpt_field See property description for details |
|
44 | - * @param string $parent_pk_relation_field This is the field that is "connected" to the $primary_cpt_field. |
|
45 | - * See property desc for details. |
|
46 | - * @param boolean $block_deletes For this type of relation, we block by default. If there are |
|
47 | - * related models across this relation, block (prevent and add an |
|
48 | - * error) the deletion of this model |
|
49 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
50 | - * default |
|
51 | - */ |
|
52 | - public function __construct( |
|
53 | - $primary_cpt_field, |
|
54 | - $parent_pk_relation_field, |
|
55 | - $block_deletes = true, |
|
56 | - $blocking_delete_error_message = null |
|
57 | - ) { |
|
58 | - $this->_primary_cpt_field = $primary_cpt_field; |
|
59 | - $this->_parent_pk_relation_field = $parent_pk_relation_field; |
|
60 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
66 | - * you like. |
|
67 | - * |
|
68 | - * @param EE_Base_Class|int $this_obj_or_id |
|
69 | - * @param EE_Base_Class|int $other_obj_or_id |
|
70 | - * @param array $extra_join_model_fields_n_values |
|
71 | - * @return \EE_Base_Class |
|
72 | - * @throws \EE_Error |
|
73 | - */ |
|
74 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
75 | - { |
|
76 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
77 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
78 | - |
|
79 | - // handle possible revisions |
|
80 | - $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj); |
|
81 | - |
|
82 | - // if is array, then we've already done the add_relation so let's get out |
|
83 | - if (is_array($other_model_obj)) { |
|
84 | - return $other_model_obj[0]; |
|
85 | - } |
|
86 | - // find the field on the other model which is a foreign key to this model |
|
87 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
88 | - // set that field on the other model to this model's ID |
|
89 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
90 | - $other_model_obj->save(); |
|
91 | - return $other_model_obj; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object |
|
97 | - * |
|
98 | - * @param EE_Base_Class|int $this_obj_or_id |
|
99 | - * @param EE_Base_Class|int $other_obj_or_id |
|
100 | - * @param array $where_query |
|
101 | - * @return \EE_Base_Class |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
105 | - { |
|
106 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id); |
|
107 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
108 | - // handle possible revisions |
|
109 | - $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true); |
|
110 | - |
|
111 | - |
|
112 | - // if is array, then we've already done the add_relation so let's get out |
|
113 | - if (is_array($other_model_obj)) { |
|
114 | - return $other_model_obj[0]; |
|
115 | - } |
|
116 | - |
|
117 | - // find the field on the other model which is a foreign key to this model |
|
118 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
119 | - |
|
120 | - |
|
121 | - // set that field on the other model to this model's ID |
|
122 | - if ($this->_blocking_delete) { |
|
123 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
124 | - $other_model_obj->save(); |
|
125 | - } else { |
|
126 | - $other_model_obj->delete(); |
|
127 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
128 | - return $other_model_obj; |
|
129 | - } |
|
130 | - return $other_model_obj; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions |
|
136 | - * in here. |
|
137 | - * |
|
138 | - * @param EE_Base_Class|int $model_object_or_id |
|
139 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
140 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
141 | - * @return EE_Base_Class[] |
|
142 | - * @throws \EE_Error |
|
143 | - */ |
|
144 | - public function get_all_related( |
|
145 | - $model_object_or_id, |
|
146 | - $query_params = array(), |
|
147 | - $values_already_prepared_by_model_object = false |
|
148 | - ) { |
|
149 | - if ($values_already_prepared_by_model_object !== false) { |
|
150 | - EE_Error::doing_it_wrong( |
|
151 | - 'EE_Model_Relation_Base::get_all_related', |
|
152 | - __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
153 | - '4.8.1' |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - // if this is an autosave then we're going to get things differently |
|
158 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
159 | - return $this->_do_autosave_get_all($model_object_or_id, $query_params); |
|
160 | - } |
|
161 | - |
|
162 | - return parent::get_all_related($model_object_or_id, $query_params); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * If we're in the midst of an autosave then we're going to do things a bit differently than the usual |
|
168 | - * get_all_related (commenting within). For description of params see the get_all_related() comments |
|
169 | - * |
|
170 | - * @access protected |
|
171 | - * @param $model_object_or_id |
|
172 | - * @param $query_params |
|
173 | - * @param bool $deprecated |
|
174 | - * @return \EE_Base_Class[] |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false) |
|
178 | - { |
|
179 | - |
|
180 | - // first we check if the post_id for the incoming query is for an autosave. If it isn't that's what we want! |
|
181 | - $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
182 | - |
|
183 | - $autosave = wp_get_post_autosave($model_object_id); |
|
184 | - $id_to_use = $autosave ? $autosave->ID : $model_object_id; |
|
185 | - |
|
186 | - $autosave_relations = parent::get_all_related($id_to_use, $query_params); |
|
187 | - $parent_ids = $parents = array(); |
|
188 | - $return_objs = array(); |
|
189 | - |
|
190 | - // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects); |
|
191 | - foreach ($autosave_relations as $a_r) { |
|
192 | - $pid = $a_r->parent(); |
|
193 | - if (! empty($pid)) { |
|
194 | - $parent_ids[] = $pid; |
|
195 | - } else { |
|
196 | - $return_objs[] = $a_r; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - // we have to make sure we also include the ORIGINAL values |
|
201 | - $originals = parent::get_all_related($model_object_or_id, $query_params); |
|
202 | - |
|
203 | - // merge $originals with $return_objs |
|
204 | - if ($originals) { |
|
205 | - $return_objs = array_merge($originals, $return_objs); |
|
206 | - } |
|
207 | - |
|
208 | - // now we setup the query to get all the parents |
|
209 | - if (! empty($parent_ids)) { |
|
210 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
211 | - $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids); |
|
212 | - $parents = $this->get_other_model()->get_all($query_params); |
|
213 | - } |
|
214 | - |
|
215 | - // var_dump($parents); |
|
216 | - |
|
217 | - |
|
218 | - // now merge parents with our current $return_objs and send back |
|
219 | - return array_merge($parents, $return_objs); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it |
|
225 | - * is a revision save. If so, then we change things before sending back. We also do verifications when this IS |
|
226 | - * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is |
|
227 | - * sometime delayed if the object is created/saved first by the autosave) |
|
228 | - * |
|
229 | - * @param EE_Base_Class $this_obj |
|
230 | - * @param EE_Base_Class $other_obj |
|
231 | - * @param boolean $remove_relation Indicates whether we're doing a remove_relation or add_relation. |
|
232 | - * @return EE_Base_Class. ($other_obj); |
|
233 | - * @throws \EE_Error |
|
234 | - */ |
|
235 | - protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false) |
|
236 | - { |
|
237 | - $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name(); |
|
238 | - // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling |
|
239 | - if ($this_obj->post_type() === 'revision') { |
|
240 | - // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one. |
|
241 | - $parent_evt_id = $this_obj->parent(); |
|
242 | - /*var_dump($parent_evt_id); |
|
15 | + /** |
|
16 | + * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for |
|
17 | + * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this |
|
18 | + * value). The _primary_cpt_field is what is equivalent to the post_id field on a cpt join. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + private $_primary_cpt_field; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * This is what field serves as the "parent" column that is linked with whatever the main model's calling this |
|
27 | + * relation has as a primary key. In other words EEM_Event has 'Datetime' => new |
|
28 | + * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent'). That means that in the EEM_Datetime model the |
|
29 | + * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the |
|
30 | + * primary key in the other model (EEM_Datetime). |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + private $_parent_pk_relation_field; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
39 | + * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
40 | + * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
41 | + * related models across the relation, and add-and-remove the relationships. |
|
42 | + * |
|
43 | + * @param string $primary_cpt_field See property description for details |
|
44 | + * @param string $parent_pk_relation_field This is the field that is "connected" to the $primary_cpt_field. |
|
45 | + * See property desc for details. |
|
46 | + * @param boolean $block_deletes For this type of relation, we block by default. If there are |
|
47 | + * related models across this relation, block (prevent and add an |
|
48 | + * error) the deletion of this model |
|
49 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
50 | + * default |
|
51 | + */ |
|
52 | + public function __construct( |
|
53 | + $primary_cpt_field, |
|
54 | + $parent_pk_relation_field, |
|
55 | + $block_deletes = true, |
|
56 | + $blocking_delete_error_message = null |
|
57 | + ) { |
|
58 | + $this->_primary_cpt_field = $primary_cpt_field; |
|
59 | + $this->_parent_pk_relation_field = $parent_pk_relation_field; |
|
60 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
66 | + * you like. |
|
67 | + * |
|
68 | + * @param EE_Base_Class|int $this_obj_or_id |
|
69 | + * @param EE_Base_Class|int $other_obj_or_id |
|
70 | + * @param array $extra_join_model_fields_n_values |
|
71 | + * @return \EE_Base_Class |
|
72 | + * @throws \EE_Error |
|
73 | + */ |
|
74 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
75 | + { |
|
76 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
77 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
78 | + |
|
79 | + // handle possible revisions |
|
80 | + $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj); |
|
81 | + |
|
82 | + // if is array, then we've already done the add_relation so let's get out |
|
83 | + if (is_array($other_model_obj)) { |
|
84 | + return $other_model_obj[0]; |
|
85 | + } |
|
86 | + // find the field on the other model which is a foreign key to this model |
|
87 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
88 | + // set that field on the other model to this model's ID |
|
89 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
90 | + $other_model_obj->save(); |
|
91 | + return $other_model_obj; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object |
|
97 | + * |
|
98 | + * @param EE_Base_Class|int $this_obj_or_id |
|
99 | + * @param EE_Base_Class|int $other_obj_or_id |
|
100 | + * @param array $where_query |
|
101 | + * @return \EE_Base_Class |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
105 | + { |
|
106 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id); |
|
107 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
108 | + // handle possible revisions |
|
109 | + $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true); |
|
110 | + |
|
111 | + |
|
112 | + // if is array, then we've already done the add_relation so let's get out |
|
113 | + if (is_array($other_model_obj)) { |
|
114 | + return $other_model_obj[0]; |
|
115 | + } |
|
116 | + |
|
117 | + // find the field on the other model which is a foreign key to this model |
|
118 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
119 | + |
|
120 | + |
|
121 | + // set that field on the other model to this model's ID |
|
122 | + if ($this->_blocking_delete) { |
|
123 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
124 | + $other_model_obj->save(); |
|
125 | + } else { |
|
126 | + $other_model_obj->delete(); |
|
127 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
128 | + return $other_model_obj; |
|
129 | + } |
|
130 | + return $other_model_obj; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions |
|
136 | + * in here. |
|
137 | + * |
|
138 | + * @param EE_Base_Class|int $model_object_or_id |
|
139 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
140 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
141 | + * @return EE_Base_Class[] |
|
142 | + * @throws \EE_Error |
|
143 | + */ |
|
144 | + public function get_all_related( |
|
145 | + $model_object_or_id, |
|
146 | + $query_params = array(), |
|
147 | + $values_already_prepared_by_model_object = false |
|
148 | + ) { |
|
149 | + if ($values_already_prepared_by_model_object !== false) { |
|
150 | + EE_Error::doing_it_wrong( |
|
151 | + 'EE_Model_Relation_Base::get_all_related', |
|
152 | + __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
153 | + '4.8.1' |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + // if this is an autosave then we're going to get things differently |
|
158 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
159 | + return $this->_do_autosave_get_all($model_object_or_id, $query_params); |
|
160 | + } |
|
161 | + |
|
162 | + return parent::get_all_related($model_object_or_id, $query_params); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * If we're in the midst of an autosave then we're going to do things a bit differently than the usual |
|
168 | + * get_all_related (commenting within). For description of params see the get_all_related() comments |
|
169 | + * |
|
170 | + * @access protected |
|
171 | + * @param $model_object_or_id |
|
172 | + * @param $query_params |
|
173 | + * @param bool $deprecated |
|
174 | + * @return \EE_Base_Class[] |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false) |
|
178 | + { |
|
179 | + |
|
180 | + // first we check if the post_id for the incoming query is for an autosave. If it isn't that's what we want! |
|
181 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
182 | + |
|
183 | + $autosave = wp_get_post_autosave($model_object_id); |
|
184 | + $id_to_use = $autosave ? $autosave->ID : $model_object_id; |
|
185 | + |
|
186 | + $autosave_relations = parent::get_all_related($id_to_use, $query_params); |
|
187 | + $parent_ids = $parents = array(); |
|
188 | + $return_objs = array(); |
|
189 | + |
|
190 | + // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects); |
|
191 | + foreach ($autosave_relations as $a_r) { |
|
192 | + $pid = $a_r->parent(); |
|
193 | + if (! empty($pid)) { |
|
194 | + $parent_ids[] = $pid; |
|
195 | + } else { |
|
196 | + $return_objs[] = $a_r; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + // we have to make sure we also include the ORIGINAL values |
|
201 | + $originals = parent::get_all_related($model_object_or_id, $query_params); |
|
202 | + |
|
203 | + // merge $originals with $return_objs |
|
204 | + if ($originals) { |
|
205 | + $return_objs = array_merge($originals, $return_objs); |
|
206 | + } |
|
207 | + |
|
208 | + // now we setup the query to get all the parents |
|
209 | + if (! empty($parent_ids)) { |
|
210 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
211 | + $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids); |
|
212 | + $parents = $this->get_other_model()->get_all($query_params); |
|
213 | + } |
|
214 | + |
|
215 | + // var_dump($parents); |
|
216 | + |
|
217 | + |
|
218 | + // now merge parents with our current $return_objs and send back |
|
219 | + return array_merge($parents, $return_objs); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it |
|
225 | + * is a revision save. If so, then we change things before sending back. We also do verifications when this IS |
|
226 | + * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is |
|
227 | + * sometime delayed if the object is created/saved first by the autosave) |
|
228 | + * |
|
229 | + * @param EE_Base_Class $this_obj |
|
230 | + * @param EE_Base_Class $other_obj |
|
231 | + * @param boolean $remove_relation Indicates whether we're doing a remove_relation or add_relation. |
|
232 | + * @return EE_Base_Class. ($other_obj); |
|
233 | + * @throws \EE_Error |
|
234 | + */ |
|
235 | + protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false) |
|
236 | + { |
|
237 | + $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name(); |
|
238 | + // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling |
|
239 | + if ($this_obj->post_type() === 'revision') { |
|
240 | + // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one. |
|
241 | + $parent_evt_id = $this_obj->parent(); |
|
242 | + /*var_dump($parent_evt_id); |
|
243 | 243 | var_dump($this_obj); |
244 | 244 | var_dump($other_obj);/**/ |
245 | 245 | |
246 | - if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
247 | - // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table. |
|
248 | - $has_parent_obj = $this->get_other_model()->get_one(array( |
|
249 | - array( |
|
250 | - $this->_parent_pk_relation_field => $other_obj->ID(), |
|
251 | - $this->_primary_cpt_field => $this_obj->ID(), |
|
252 | - ), |
|
253 | - )); |
|
254 | - |
|
255 | - if ($has_parent_obj) { |
|
256 | - // this makes sure the update on the current obj happens to the revision's row NOT the parent row. |
|
257 | - |
|
258 | - $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
259 | - $other_obj->set($pk_on_related_model, $has_parent_obj->ID()); |
|
260 | - $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
261 | - |
|
262 | - if (! $remove_relation) { |
|
263 | - $other_obj->save(); |
|
264 | - return array($other_obj); |
|
265 | - } elseif ($remove_relation && ! $this->_blocking_delete) { |
|
266 | - $other_obj->delete(); |
|
267 | - $other_obj->set($this->_parent_pk_relation_field, null, true); |
|
268 | - return array($other_obj); |
|
269 | - } |
|
270 | - } else { |
|
271 | - $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
272 | - $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
273 | - $other_obj->set( |
|
274 | - $pk_on_related_model, |
|
275 | - null, |
|
276 | - true |
|
277 | - ); // ensure we create a new row for the autosave with parent id the same as the incoming ID. |
|
278 | - $other_obj->save(); // make sure we insert. |
|
279 | - return array($other_obj); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - // var_dump('what makes it here'); |
|
284 | - // var_dump($other_obj); |
|
285 | - // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it) |
|
286 | - |
|
287 | - // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method. |
|
288 | - } else { |
|
289 | - // we only need to do the below IF this is not a remove relation |
|
290 | - if (! $remove_relation) { |
|
291 | - // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object. |
|
292 | - // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first. |
|
293 | - $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID()); |
|
294 | - $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null; |
|
295 | - |
|
296 | - if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) { |
|
297 | - // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision. |
|
298 | - $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
299 | - $other_obj->save(); |
|
300 | - |
|
301 | - // now create a new other_obj and fill with details from existing object |
|
302 | - $new_obj = $other_obj; |
|
303 | - $new_obj->set($this->_primary_cpt_field, $potential_revision_id); |
|
304 | - $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
305 | - $new_obj->set($pk_on_related_model, null); |
|
306 | - $new_obj->save(); |
|
307 | - return array($new_obj); |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - return $other_obj; |
|
313 | - } |
|
246 | + if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) { |
|
247 | + // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table. |
|
248 | + $has_parent_obj = $this->get_other_model()->get_one(array( |
|
249 | + array( |
|
250 | + $this->_parent_pk_relation_field => $other_obj->ID(), |
|
251 | + $this->_primary_cpt_field => $this_obj->ID(), |
|
252 | + ), |
|
253 | + )); |
|
254 | + |
|
255 | + if ($has_parent_obj) { |
|
256 | + // this makes sure the update on the current obj happens to the revision's row NOT the parent row. |
|
257 | + |
|
258 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
259 | + $other_obj->set($pk_on_related_model, $has_parent_obj->ID()); |
|
260 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
261 | + |
|
262 | + if (! $remove_relation) { |
|
263 | + $other_obj->save(); |
|
264 | + return array($other_obj); |
|
265 | + } elseif ($remove_relation && ! $this->_blocking_delete) { |
|
266 | + $other_obj->delete(); |
|
267 | + $other_obj->set($this->_parent_pk_relation_field, null, true); |
|
268 | + return array($other_obj); |
|
269 | + } |
|
270 | + } else { |
|
271 | + $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
272 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
273 | + $other_obj->set( |
|
274 | + $pk_on_related_model, |
|
275 | + null, |
|
276 | + true |
|
277 | + ); // ensure we create a new row for the autosave with parent id the same as the incoming ID. |
|
278 | + $other_obj->save(); // make sure we insert. |
|
279 | + return array($other_obj); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + // var_dump('what makes it here'); |
|
284 | + // var_dump($other_obj); |
|
285 | + // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it) |
|
286 | + |
|
287 | + // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method. |
|
288 | + } else { |
|
289 | + // we only need to do the below IF this is not a remove relation |
|
290 | + if (! $remove_relation) { |
|
291 | + // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object. |
|
292 | + // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first. |
|
293 | + $existing_other_obj = $this->get_other_model()->get_one_by_ID($other_obj->ID()); |
|
294 | + $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null; |
|
295 | + |
|
296 | + if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) { |
|
297 | + // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision. |
|
298 | + $other_obj->set($this->_primary_cpt_field, $this_obj->ID()); |
|
299 | + $other_obj->save(); |
|
300 | + |
|
301 | + // now create a new other_obj and fill with details from existing object |
|
302 | + $new_obj = $other_obj; |
|
303 | + $new_obj->set($this->_primary_cpt_field, $potential_revision_id); |
|
304 | + $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID()); |
|
305 | + $new_obj->set($pk_on_related_model, null); |
|
306 | + $new_obj->save(); |
|
307 | + return array($new_obj); |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + return $other_obj; |
|
313 | + } |
|
314 | 314 | } |
@@ -15,94 +15,94 @@ |
||
15 | 15 | class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Gets the SQL string for performing the join between this model and the other model. |
|
20 | - * |
|
21 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
22 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
23 | - * other_model_primary_table.fk" etc |
|
24 | - * @throws \EE_Error |
|
25 | - */ |
|
26 | - public function get_join_statement($model_relation_chain) |
|
27 | - { |
|
28 | - // create the sql string like |
|
29 | - // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
30 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
31 | - $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
32 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
33 | - $model_relation_chain, |
|
34 | - $this->get_this_model()->get_this_model_name() |
|
35 | - ) . $this_table_pk_field->get_table_alias(); |
|
36 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
37 | - $model_relation_chain, |
|
38 | - $this->get_other_model()->get_this_model_name() |
|
39 | - ) . $other_table_fk_field->get_table_alias(); |
|
40 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
41 | - $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name(); |
|
18 | + /** |
|
19 | + * Gets the SQL string for performing the join between this model and the other model. |
|
20 | + * |
|
21 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
22 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
23 | + * other_model_primary_table.fk" etc |
|
24 | + * @throws \EE_Error |
|
25 | + */ |
|
26 | + public function get_join_statement($model_relation_chain) |
|
27 | + { |
|
28 | + // create the sql string like |
|
29 | + // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
30 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
31 | + $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
32 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
33 | + $model_relation_chain, |
|
34 | + $this->get_this_model()->get_this_model_name() |
|
35 | + ) . $this_table_pk_field->get_table_alias(); |
|
36 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
37 | + $model_relation_chain, |
|
38 | + $this->get_other_model()->get_this_model_name() |
|
39 | + ) . $other_table_fk_field->get_table_alias(); |
|
40 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
41 | + $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name(); |
|
42 | 42 | |
43 | - return $this->_left_join( |
|
44 | - $fk_table, |
|
45 | - $fk_table_alias, |
|
46 | - $other_table_fk_field->get_table_column(), |
|
47 | - $pk_table_alias, |
|
48 | - $this_table_pk_field->get_table_column(), |
|
49 | - $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
50 | - ) |
|
51 | - . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
52 | - } |
|
43 | + return $this->_left_join( |
|
44 | + $fk_table, |
|
45 | + $fk_table_alias, |
|
46 | + $other_table_fk_field->get_table_column(), |
|
47 | + $pk_table_alias, |
|
48 | + $this_table_pk_field->get_table_column(), |
|
49 | + $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
50 | + ) |
|
51 | + . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
57 | - * you like. |
|
58 | - * |
|
59 | - * @param EE_Base_Class|int $this_obj_or_id |
|
60 | - * @param EE_Base_Class|int $other_obj_or_id |
|
61 | - * @param array $extra_join_model_fields_n_values |
|
62 | - * @return \EE_Base_Class |
|
63 | - * @throws \EE_Error |
|
64 | - */ |
|
65 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
66 | - { |
|
67 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
68 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
55 | + /** |
|
56 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
57 | + * you like. |
|
58 | + * |
|
59 | + * @param EE_Base_Class|int $this_obj_or_id |
|
60 | + * @param EE_Base_Class|int $other_obj_or_id |
|
61 | + * @param array $extra_join_model_fields_n_values |
|
62 | + * @return \EE_Base_Class |
|
63 | + * @throws \EE_Error |
|
64 | + */ |
|
65 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
66 | + { |
|
67 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
68 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
69 | 69 | |
70 | - // find the field on the other model which is a foreign key to this model |
|
71 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
72 | - // set that field on the other model to this model's ID |
|
73 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
74 | - $other_model_obj->set( |
|
75 | - $this->get_other_model()->get_field_containing_related_model_name()->get_name(), |
|
76 | - $this->get_this_model()->get_this_model_name() |
|
77 | - ); |
|
78 | - $other_model_obj->save(); |
|
79 | - return $other_model_obj; |
|
80 | - } |
|
70 | + // find the field on the other model which is a foreign key to this model |
|
71 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
72 | + // set that field on the other model to this model's ID |
|
73 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
74 | + $other_model_obj->set( |
|
75 | + $this->get_other_model()->get_field_containing_related_model_name()->get_name(), |
|
76 | + $this->get_this_model()->get_this_model_name() |
|
77 | + ); |
|
78 | + $other_model_obj->save(); |
|
79 | + return $other_model_obj; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
85 | - * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
86 | - * |
|
87 | - * @param EE_Base_Class|int $this_obj_or_id |
|
88 | - * @param EE_Base_Class|int $other_obj_or_id |
|
89 | - * @param array $where_query |
|
90 | - * @return \EE_Base_Class |
|
91 | - * @throws \EE_Error |
|
92 | - */ |
|
93 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
94 | - { |
|
95 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
96 | - // find the field on the other model which is a foreign key to this model |
|
97 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
98 | - // set that field on the other model to this model's ID |
|
99 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
100 | - $other_model_obj->set( |
|
101 | - $this->get_other_model()->get_field_containing_related_model_name()->get_name(), |
|
102 | - null, |
|
103 | - true |
|
104 | - ); |
|
105 | - $other_model_obj->save(); |
|
106 | - return $other_model_obj; |
|
107 | - } |
|
83 | + /** |
|
84 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
85 | + * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
86 | + * |
|
87 | + * @param EE_Base_Class|int $this_obj_or_id |
|
88 | + * @param EE_Base_Class|int $other_obj_or_id |
|
89 | + * @param array $where_query |
|
90 | + * @return \EE_Base_Class |
|
91 | + * @throws \EE_Error |
|
92 | + */ |
|
93 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
94 | + { |
|
95 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
96 | + // find the field on the other model which is a foreign key to this model |
|
97 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
98 | + // set that field on the other model to this model's ID |
|
99 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
100 | + $other_model_obj->set( |
|
101 | + $this->get_other_model()->get_field_containing_related_model_name()->get_name(), |
|
102 | + null, |
|
103 | + true |
|
104 | + ); |
|
105 | + $other_model_obj->save(); |
|
106 | + return $other_model_obj; |
|
107 | + } |
|
108 | 108 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
33 | 33 | $model_relation_chain, |
34 | 34 | $this->get_this_model()->get_this_model_name() |
35 | - ) . $this_table_pk_field->get_table_alias(); |
|
36 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
35 | + ).$this_table_pk_field->get_table_alias(); |
|
36 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
37 | 37 | $model_relation_chain, |
38 | 38 | $this->get_other_model()->get_this_model_name() |
39 | - ) . $other_table_fk_field->get_table_alias(); |
|
39 | + ).$other_table_fk_field->get_table_alias(); |
|
40 | 40 | $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
41 | 41 | $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name(); |
42 | 42 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | $other_table_fk_field->get_table_column(), |
47 | 47 | $pk_table_alias, |
48 | 48 | $this_table_pk_field->get_table_column(), |
49 | - $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'" |
|
49 | + $fk_table_alias.'.'.$field_with_model_name->get_table_column()."='".$this->get_this_model()->get_this_model_name()."'" |
|
50 | 50 | ) |
51 | 51 | . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
52 | 52 | } |
@@ -11,292 +11,292 @@ |
||
11 | 11 | class EEM_Status extends EEM_Base |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the Attendee object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Attendee object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @return EEM_Status |
|
20 | - */ |
|
21 | - protected function __construct($timezone = null) |
|
22 | - { |
|
23 | - $this->singular_item = __('Status', 'event_espresso'); |
|
24 | - $this->plural_item = __('Stati', 'event_espresso'); |
|
25 | - $this->_tables = array( |
|
26 | - 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
27 | - ); |
|
28 | - $this->_fields = array( |
|
29 | - 'StatusTable' => array( |
|
30 | - 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')), |
|
31 | - 'STS_code' => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''), |
|
32 | - 'STS_type' => new EE_Enum_Text_Field( |
|
33 | - 'STS_type', |
|
34 | - __("Type", "event_espresso"), |
|
35 | - false, |
|
36 | - 'event', |
|
37 | - array( |
|
38 | - 'event' => __("Event", "event_espresso"),// deprecated |
|
39 | - 'registration' => __("Registration", "event_espresso"), |
|
40 | - 'transaction' => __("Transaction", "event_espresso"), |
|
41 | - 'payment' => __("Payment", "event_espresso"), |
|
42 | - 'email' => __("Email", "event_espresso"), |
|
43 | - 'message' => __("Message", "event_espresso"), |
|
44 | - ) |
|
45 | - ), |
|
46 | - 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false), |
|
47 | - 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''), |
|
48 | - 'STS_open' => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false), |
|
49 | - ), |
|
50 | - ); |
|
51 | - $this->_model_relations = array( |
|
52 | - 'Registration' => new EE_Has_Many_Relation(), |
|
53 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
54 | - 'Payment' => new EE_Has_Many_Relation(), |
|
55 | - ); |
|
56 | - // this model is generally available for reading |
|
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
18 | + /** |
|
19 | + * @return EEM_Status |
|
20 | + */ |
|
21 | + protected function __construct($timezone = null) |
|
22 | + { |
|
23 | + $this->singular_item = __('Status', 'event_espresso'); |
|
24 | + $this->plural_item = __('Stati', 'event_espresso'); |
|
25 | + $this->_tables = array( |
|
26 | + 'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'), |
|
27 | + ); |
|
28 | + $this->_fields = array( |
|
29 | + 'StatusTable' => array( |
|
30 | + 'STS_ID' => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')), |
|
31 | + 'STS_code' => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''), |
|
32 | + 'STS_type' => new EE_Enum_Text_Field( |
|
33 | + 'STS_type', |
|
34 | + __("Type", "event_espresso"), |
|
35 | + false, |
|
36 | + 'event', |
|
37 | + array( |
|
38 | + 'event' => __("Event", "event_espresso"),// deprecated |
|
39 | + 'registration' => __("Registration", "event_espresso"), |
|
40 | + 'transaction' => __("Transaction", "event_espresso"), |
|
41 | + 'payment' => __("Payment", "event_espresso"), |
|
42 | + 'email' => __("Email", "event_espresso"), |
|
43 | + 'message' => __("Message", "event_espresso"), |
|
44 | + ) |
|
45 | + ), |
|
46 | + 'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false), |
|
47 | + 'STS_desc' => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''), |
|
48 | + 'STS_open' => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false), |
|
49 | + ), |
|
50 | + ); |
|
51 | + $this->_model_relations = array( |
|
52 | + 'Registration' => new EE_Has_Many_Relation(), |
|
53 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
54 | + 'Payment' => new EE_Has_Many_Relation(), |
|
55 | + ); |
|
56 | + // this model is generally available for reading |
|
57 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
58 | 58 | |
59 | - parent::__construct($timezone); |
|
60 | - } |
|
59 | + parent::__construct($timezone); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * This method provides the localized singular or plural string for a given status id |
|
65 | - * |
|
66 | - * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
67 | - * That way if there isn't a translation in the index we'll return the default code. |
|
68 | - * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
69 | - * same as the singular (in English), however, this may NOT be the case with other |
|
70 | - * languages |
|
71 | - * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
72 | - * the status string returned ( UPPER, lower, Sentence) |
|
73 | - * @throws EE_Error |
|
74 | - * @return array an array of translated strings for the incoming status id. |
|
75 | - */ |
|
76 | - public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
77 | - { |
|
78 | - // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
79 | - $translation_array = array( |
|
80 | - EEM_Registration::status_id_pending_payment => array( |
|
81 | - __('pending payment', 'event_espresso'), // singular |
|
82 | - __('pending payments', 'event_espresso') // plural |
|
83 | - ), |
|
84 | - EEM_Registration::status_id_approved => array( |
|
85 | - __('approved', 'event_espresso'), // singular |
|
86 | - __('approved', 'event_espresso') // plural |
|
87 | - ), |
|
88 | - EEM_Registration::status_id_not_approved => array( |
|
89 | - __('not approved', 'event_espresso'), |
|
90 | - __('not approved', 'event_espresso'), |
|
91 | - ), |
|
92 | - EEM_Registration::status_id_cancelled => array( |
|
93 | - __('cancelled', 'event_espresso'), |
|
94 | - __('cancelled', 'event_espresso'), |
|
95 | - ), |
|
96 | - EEM_Registration::status_id_incomplete => array( |
|
97 | - __('incomplete', 'event_espresso'), |
|
98 | - __('incomplete', 'event_espresso'), |
|
99 | - ), |
|
100 | - EEM_Registration::status_id_declined => array( |
|
101 | - __('declined', 'event_espresso'), |
|
102 | - __('declined', 'event_espresso'), |
|
103 | - ), |
|
104 | - EEM_Registration::status_id_wait_list => array( |
|
105 | - __('wait list', 'event_espresso'), |
|
106 | - __('wait list', 'event_espresso'), |
|
107 | - ), |
|
108 | - EEM_Transaction::overpaid_status_code => array( |
|
109 | - __('overpaid', 'event_espresso'), |
|
110 | - __('overpaid', 'event_espresso'), |
|
111 | - ), |
|
112 | - EEM_Transaction::complete_status_code => array( |
|
113 | - __('complete', 'event_espresso'), |
|
114 | - __('complete', 'event_espresso'), |
|
115 | - ), |
|
116 | - EEM_Transaction::incomplete_status_code => array( |
|
117 | - __('incomplete', 'event_espresso'), |
|
118 | - __('incomplete', 'event_espresso'), |
|
119 | - ), |
|
120 | - EEM_Transaction::failed_status_code => array( |
|
121 | - __('failed', 'event_espresso'), |
|
122 | - __('failed', 'event_espresso'), |
|
123 | - ), |
|
124 | - EEM_Transaction::abandoned_status_code => array( |
|
125 | - __('abandoned', 'event_espresso'), |
|
126 | - __('abandoned', 'event_espresso'), |
|
127 | - ), |
|
128 | - EEM_Payment::status_id_approved => array( |
|
129 | - __('accepted', 'event_espresso'), |
|
130 | - __('accepted', 'event_espresso'), |
|
131 | - ), |
|
132 | - EEM_Payment::status_id_pending => array( |
|
133 | - __('pending', 'event_espresso'), |
|
134 | - __('pending', 'event_espresso'), |
|
135 | - ), |
|
136 | - EEM_Payment::status_id_cancelled => array( |
|
137 | - __('cancelled', 'event_espresso'), |
|
138 | - __('cancelled', 'event_espresso'), |
|
139 | - ), |
|
140 | - EEM_Payment::status_id_declined => array( |
|
141 | - __('declined', 'event_espresso'), |
|
142 | - __('declined', 'event_espresso'), |
|
143 | - ), |
|
144 | - EEM_Payment::status_id_failed => array( |
|
145 | - __('failed', 'event_espresso'), |
|
146 | - __('failed', 'event_espresso'), |
|
147 | - ), |
|
148 | - // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
149 | - EEM_Event::sold_out => array( |
|
150 | - __('sold out', 'event_espresso'), |
|
151 | - __('sold out', 'event_espresso'), |
|
152 | - ), |
|
153 | - EEM_Event::postponed => array( |
|
154 | - __('postponed', 'event_espresso'), |
|
155 | - __('Postponed', 'event_espresso'), |
|
156 | - ), |
|
157 | - EEM_Event::cancelled => array( |
|
158 | - __('cancelled', 'event_espresso'), |
|
159 | - __('cancelled', 'event_espresso'), |
|
160 | - ), |
|
161 | - EE_Ticket::archived => array( |
|
162 | - __('archived', 'event_espresso'), |
|
163 | - __('archived', 'event_espresso'), |
|
164 | - ), |
|
165 | - EE_Ticket::expired => array( |
|
166 | - __('expired', 'event_espresso'), |
|
167 | - __('expired', 'event_espresso'), |
|
168 | - ), |
|
169 | - EE_Ticket::sold_out => array( |
|
170 | - __('sold out', 'event_espresso'), |
|
171 | - __('sold out', 'event_espresso'), |
|
172 | - ), |
|
173 | - EE_Ticket::pending => array( |
|
174 | - __('upcoming', 'event_espresso'), |
|
175 | - __('upcoming', 'event_espresso'), |
|
176 | - ), |
|
177 | - EE_Ticket::onsale => array( |
|
178 | - __('on sale', 'event_espresso'), |
|
179 | - __('on sale', 'event_espresso'), |
|
180 | - ), |
|
181 | - EE_Datetime::cancelled => array( |
|
182 | - __('cancelled', 'event_espresso'), |
|
183 | - __('cancelled', 'event_espresso'), |
|
184 | - ), |
|
185 | - EE_Datetime::sold_out => array( |
|
186 | - __('sold out', 'event_espresso'), |
|
187 | - __('sold out', 'event_espresso'), |
|
188 | - ), |
|
189 | - EE_Datetime::expired => array( |
|
190 | - __('expired', 'event_espresso'), |
|
191 | - __('expired', 'event_espresso'), |
|
192 | - ), |
|
193 | - EE_Datetime::inactive => array( |
|
194 | - __('inactive', 'event_espresso'), |
|
195 | - __('inactive', 'event_espresso'), |
|
196 | - ), |
|
197 | - EE_Datetime::upcoming => array( |
|
198 | - __('upcoming', 'event_espresso'), |
|
199 | - __('upcoming', 'event_espresso'), |
|
200 | - ), |
|
201 | - EE_Datetime::active => array( |
|
202 | - __('active', 'event_espresso'), |
|
203 | - __('active', 'event_espresso'), |
|
204 | - ), |
|
205 | - EE_Datetime::postponed => array( |
|
206 | - __('postponed', 'event_espresso'), |
|
207 | - __('postponed', 'event_espresso'), |
|
208 | - ), |
|
209 | - // messages related |
|
210 | - EEM_Message::status_sent => array( |
|
211 | - __('sent', 'event_espresso'), |
|
212 | - __('sent', 'event_espresso'), |
|
213 | - ), |
|
214 | - EEM_Message::status_idle => array( |
|
215 | - __('queued for sending', 'event_espresso'), |
|
216 | - __('queued for sending', 'event_espresso'), |
|
217 | - ), |
|
218 | - EEM_Message::status_failed => array( |
|
219 | - __('failed', 'event_espresso'), |
|
220 | - __('failed', 'event_espresso'), |
|
221 | - ), |
|
222 | - EEM_Message::status_debug_only => array( |
|
223 | - __('debug only', 'event_espresso'), |
|
224 | - __('debug only', 'event_espresso'), |
|
225 | - ), |
|
226 | - EEM_Message::status_messenger_executing => array( |
|
227 | - __('messenger is executing', 'event_espresso'), |
|
228 | - __('messenger is executing', 'event_espresso'), |
|
229 | - ), |
|
230 | - EEM_Message::status_resend => array( |
|
231 | - __('queued for resending', 'event_espresso'), |
|
232 | - __('queued for resending', 'event_espresso'), |
|
233 | - ), |
|
234 | - EEM_Message::status_incomplete => array( |
|
235 | - __('queued for generating', 'event_espresso'), |
|
236 | - __('queued for generating', 'event_espresso'), |
|
237 | - ), |
|
238 | - EEM_Message::status_retry => array( |
|
239 | - __('failed sending, can be retried', 'event_espresso'), |
|
240 | - __('failed sending, can be retried', 'event_espresso'), |
|
241 | - ), |
|
242 | - EEM_CPT_Base::post_status_publish => array( |
|
243 | - __('published', 'event_espresso'), |
|
244 | - __('published', 'event_espresso'), |
|
245 | - ), |
|
246 | - EEM_CPT_Base::post_status_future => array( |
|
247 | - __('scheduled', 'event_espresso'), |
|
248 | - __('scheduled', 'event_espresso'), |
|
249 | - ), |
|
250 | - EEM_CPT_Base::post_status_draft => array( |
|
251 | - __('draft', 'event_espresso'), |
|
252 | - __('draft', 'event_espresso'), |
|
253 | - ), |
|
254 | - EEM_CPT_Base::post_status_pending => array( |
|
255 | - __('pending', 'event_espresso'), |
|
256 | - __('pending', 'event_espresso'), |
|
257 | - ), |
|
258 | - EEM_CPT_Base::post_status_private => array( |
|
259 | - __('private', 'event_espresso'), |
|
260 | - __('private', 'event_espresso'), |
|
261 | - ), |
|
262 | - EEM_CPT_Base::post_status_trashed => array( |
|
263 | - __('trashed', 'event_espresso'), |
|
264 | - __('trashed', 'event_espresso'), |
|
265 | - ), |
|
266 | - ); |
|
63 | + /** |
|
64 | + * This method provides the localized singular or plural string for a given status id |
|
65 | + * |
|
66 | + * @param array $statuses This should be an array of statuses in the format array( $status_id, $status_code ). |
|
67 | + * That way if there isn't a translation in the index we'll return the default code. |
|
68 | + * @param boolean $plural Whether to return plural string or not. Note, nearly all of the plural strings are the |
|
69 | + * same as the singular (in English), however, this may NOT be the case with other |
|
70 | + * languages |
|
71 | + * @param string $schema This can be either 'upper', 'lower', or 'sentence'. Basically indicates how we want |
|
72 | + * the status string returned ( UPPER, lower, Sentence) |
|
73 | + * @throws EE_Error |
|
74 | + * @return array an array of translated strings for the incoming status id. |
|
75 | + */ |
|
76 | + public function localized_status($statuses, $plural = false, $schema = 'upper') |
|
77 | + { |
|
78 | + // note these are all in lower case because ucwords() on upper case will NOT convert. |
|
79 | + $translation_array = array( |
|
80 | + EEM_Registration::status_id_pending_payment => array( |
|
81 | + __('pending payment', 'event_espresso'), // singular |
|
82 | + __('pending payments', 'event_espresso') // plural |
|
83 | + ), |
|
84 | + EEM_Registration::status_id_approved => array( |
|
85 | + __('approved', 'event_espresso'), // singular |
|
86 | + __('approved', 'event_espresso') // plural |
|
87 | + ), |
|
88 | + EEM_Registration::status_id_not_approved => array( |
|
89 | + __('not approved', 'event_espresso'), |
|
90 | + __('not approved', 'event_espresso'), |
|
91 | + ), |
|
92 | + EEM_Registration::status_id_cancelled => array( |
|
93 | + __('cancelled', 'event_espresso'), |
|
94 | + __('cancelled', 'event_espresso'), |
|
95 | + ), |
|
96 | + EEM_Registration::status_id_incomplete => array( |
|
97 | + __('incomplete', 'event_espresso'), |
|
98 | + __('incomplete', 'event_espresso'), |
|
99 | + ), |
|
100 | + EEM_Registration::status_id_declined => array( |
|
101 | + __('declined', 'event_espresso'), |
|
102 | + __('declined', 'event_espresso'), |
|
103 | + ), |
|
104 | + EEM_Registration::status_id_wait_list => array( |
|
105 | + __('wait list', 'event_espresso'), |
|
106 | + __('wait list', 'event_espresso'), |
|
107 | + ), |
|
108 | + EEM_Transaction::overpaid_status_code => array( |
|
109 | + __('overpaid', 'event_espresso'), |
|
110 | + __('overpaid', 'event_espresso'), |
|
111 | + ), |
|
112 | + EEM_Transaction::complete_status_code => array( |
|
113 | + __('complete', 'event_espresso'), |
|
114 | + __('complete', 'event_espresso'), |
|
115 | + ), |
|
116 | + EEM_Transaction::incomplete_status_code => array( |
|
117 | + __('incomplete', 'event_espresso'), |
|
118 | + __('incomplete', 'event_espresso'), |
|
119 | + ), |
|
120 | + EEM_Transaction::failed_status_code => array( |
|
121 | + __('failed', 'event_espresso'), |
|
122 | + __('failed', 'event_espresso'), |
|
123 | + ), |
|
124 | + EEM_Transaction::abandoned_status_code => array( |
|
125 | + __('abandoned', 'event_espresso'), |
|
126 | + __('abandoned', 'event_espresso'), |
|
127 | + ), |
|
128 | + EEM_Payment::status_id_approved => array( |
|
129 | + __('accepted', 'event_espresso'), |
|
130 | + __('accepted', 'event_espresso'), |
|
131 | + ), |
|
132 | + EEM_Payment::status_id_pending => array( |
|
133 | + __('pending', 'event_espresso'), |
|
134 | + __('pending', 'event_espresso'), |
|
135 | + ), |
|
136 | + EEM_Payment::status_id_cancelled => array( |
|
137 | + __('cancelled', 'event_espresso'), |
|
138 | + __('cancelled', 'event_espresso'), |
|
139 | + ), |
|
140 | + EEM_Payment::status_id_declined => array( |
|
141 | + __('declined', 'event_espresso'), |
|
142 | + __('declined', 'event_espresso'), |
|
143 | + ), |
|
144 | + EEM_Payment::status_id_failed => array( |
|
145 | + __('failed', 'event_espresso'), |
|
146 | + __('failed', 'event_espresso'), |
|
147 | + ), |
|
148 | + // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here. |
|
149 | + EEM_Event::sold_out => array( |
|
150 | + __('sold out', 'event_espresso'), |
|
151 | + __('sold out', 'event_espresso'), |
|
152 | + ), |
|
153 | + EEM_Event::postponed => array( |
|
154 | + __('postponed', 'event_espresso'), |
|
155 | + __('Postponed', 'event_espresso'), |
|
156 | + ), |
|
157 | + EEM_Event::cancelled => array( |
|
158 | + __('cancelled', 'event_espresso'), |
|
159 | + __('cancelled', 'event_espresso'), |
|
160 | + ), |
|
161 | + EE_Ticket::archived => array( |
|
162 | + __('archived', 'event_espresso'), |
|
163 | + __('archived', 'event_espresso'), |
|
164 | + ), |
|
165 | + EE_Ticket::expired => array( |
|
166 | + __('expired', 'event_espresso'), |
|
167 | + __('expired', 'event_espresso'), |
|
168 | + ), |
|
169 | + EE_Ticket::sold_out => array( |
|
170 | + __('sold out', 'event_espresso'), |
|
171 | + __('sold out', 'event_espresso'), |
|
172 | + ), |
|
173 | + EE_Ticket::pending => array( |
|
174 | + __('upcoming', 'event_espresso'), |
|
175 | + __('upcoming', 'event_espresso'), |
|
176 | + ), |
|
177 | + EE_Ticket::onsale => array( |
|
178 | + __('on sale', 'event_espresso'), |
|
179 | + __('on sale', 'event_espresso'), |
|
180 | + ), |
|
181 | + EE_Datetime::cancelled => array( |
|
182 | + __('cancelled', 'event_espresso'), |
|
183 | + __('cancelled', 'event_espresso'), |
|
184 | + ), |
|
185 | + EE_Datetime::sold_out => array( |
|
186 | + __('sold out', 'event_espresso'), |
|
187 | + __('sold out', 'event_espresso'), |
|
188 | + ), |
|
189 | + EE_Datetime::expired => array( |
|
190 | + __('expired', 'event_espresso'), |
|
191 | + __('expired', 'event_espresso'), |
|
192 | + ), |
|
193 | + EE_Datetime::inactive => array( |
|
194 | + __('inactive', 'event_espresso'), |
|
195 | + __('inactive', 'event_espresso'), |
|
196 | + ), |
|
197 | + EE_Datetime::upcoming => array( |
|
198 | + __('upcoming', 'event_espresso'), |
|
199 | + __('upcoming', 'event_espresso'), |
|
200 | + ), |
|
201 | + EE_Datetime::active => array( |
|
202 | + __('active', 'event_espresso'), |
|
203 | + __('active', 'event_espresso'), |
|
204 | + ), |
|
205 | + EE_Datetime::postponed => array( |
|
206 | + __('postponed', 'event_espresso'), |
|
207 | + __('postponed', 'event_espresso'), |
|
208 | + ), |
|
209 | + // messages related |
|
210 | + EEM_Message::status_sent => array( |
|
211 | + __('sent', 'event_espresso'), |
|
212 | + __('sent', 'event_espresso'), |
|
213 | + ), |
|
214 | + EEM_Message::status_idle => array( |
|
215 | + __('queued for sending', 'event_espresso'), |
|
216 | + __('queued for sending', 'event_espresso'), |
|
217 | + ), |
|
218 | + EEM_Message::status_failed => array( |
|
219 | + __('failed', 'event_espresso'), |
|
220 | + __('failed', 'event_espresso'), |
|
221 | + ), |
|
222 | + EEM_Message::status_debug_only => array( |
|
223 | + __('debug only', 'event_espresso'), |
|
224 | + __('debug only', 'event_espresso'), |
|
225 | + ), |
|
226 | + EEM_Message::status_messenger_executing => array( |
|
227 | + __('messenger is executing', 'event_espresso'), |
|
228 | + __('messenger is executing', 'event_espresso'), |
|
229 | + ), |
|
230 | + EEM_Message::status_resend => array( |
|
231 | + __('queued for resending', 'event_espresso'), |
|
232 | + __('queued for resending', 'event_espresso'), |
|
233 | + ), |
|
234 | + EEM_Message::status_incomplete => array( |
|
235 | + __('queued for generating', 'event_espresso'), |
|
236 | + __('queued for generating', 'event_espresso'), |
|
237 | + ), |
|
238 | + EEM_Message::status_retry => array( |
|
239 | + __('failed sending, can be retried', 'event_espresso'), |
|
240 | + __('failed sending, can be retried', 'event_espresso'), |
|
241 | + ), |
|
242 | + EEM_CPT_Base::post_status_publish => array( |
|
243 | + __('published', 'event_espresso'), |
|
244 | + __('published', 'event_espresso'), |
|
245 | + ), |
|
246 | + EEM_CPT_Base::post_status_future => array( |
|
247 | + __('scheduled', 'event_espresso'), |
|
248 | + __('scheduled', 'event_espresso'), |
|
249 | + ), |
|
250 | + EEM_CPT_Base::post_status_draft => array( |
|
251 | + __('draft', 'event_espresso'), |
|
252 | + __('draft', 'event_espresso'), |
|
253 | + ), |
|
254 | + EEM_CPT_Base::post_status_pending => array( |
|
255 | + __('pending', 'event_espresso'), |
|
256 | + __('pending', 'event_espresso'), |
|
257 | + ), |
|
258 | + EEM_CPT_Base::post_status_private => array( |
|
259 | + __('private', 'event_espresso'), |
|
260 | + __('private', 'event_espresso'), |
|
261 | + ), |
|
262 | + EEM_CPT_Base::post_status_trashed => array( |
|
263 | + __('trashed', 'event_espresso'), |
|
264 | + __('trashed', 'event_espresso'), |
|
265 | + ), |
|
266 | + ); |
|
267 | 267 | |
268 | - $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
268 | + $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array); |
|
269 | 269 | |
270 | - if (! is_array($statuses)) { |
|
271 | - throw new EE_Error(__( |
|
272 | - 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
273 | - 'event_espresso' |
|
274 | - )); |
|
275 | - } |
|
270 | + if (! is_array($statuses)) { |
|
271 | + throw new EE_Error(__( |
|
272 | + 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code', |
|
273 | + 'event_espresso' |
|
274 | + )); |
|
275 | + } |
|
276 | 276 | |
277 | - $translation = array(); |
|
277 | + $translation = array(); |
|
278 | 278 | |
279 | - foreach ($statuses as $id => $code) { |
|
280 | - if (isset($translation_array[ $id ])) { |
|
281 | - $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
282 | - } else { |
|
283 | - $translation[ $id ] = $code; |
|
284 | - } |
|
279 | + foreach ($statuses as $id => $code) { |
|
280 | + if (isset($translation_array[ $id ])) { |
|
281 | + $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0]; |
|
282 | + } else { |
|
283 | + $translation[ $id ] = $code; |
|
284 | + } |
|
285 | 285 | |
286 | - // schema |
|
287 | - switch ($schema) { |
|
288 | - case 'lower': |
|
289 | - $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
290 | - break; |
|
291 | - case 'sentence': |
|
292 | - $translation[ $id ] = ucwords($translation[ $id ]); |
|
293 | - break; |
|
294 | - case 'upper': |
|
295 | - $translation[ $id ] = strtoupper($translation[ $id ]); |
|
296 | - break; |
|
297 | - } |
|
298 | - } |
|
286 | + // schema |
|
287 | + switch ($schema) { |
|
288 | + case 'lower': |
|
289 | + $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter. |
|
290 | + break; |
|
291 | + case 'sentence': |
|
292 | + $translation[ $id ] = ucwords($translation[ $id ]); |
|
293 | + break; |
|
294 | + case 'upper': |
|
295 | + $translation[ $id ] = strtoupper($translation[ $id ]); |
|
296 | + break; |
|
297 | + } |
|
298 | + } |
|
299 | 299 | |
300 | - return $translation; |
|
301 | - } |
|
300 | + return $translation; |
|
301 | + } |
|
302 | 302 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | false, |
36 | 36 | 'event', |
37 | 37 | array( |
38 | - 'event' => __("Event", "event_espresso"),// deprecated |
|
38 | + 'event' => __("Event", "event_espresso"), // deprecated |
|
39 | 39 | 'registration' => __("Registration", "event_espresso"), |
40 | 40 | 'transaction' => __("Transaction", "event_espresso"), |
41 | 41 | 'payment' => __("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(__( |
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 | } |
@@ -11,43 +11,43 @@ |
||
11 | 11 | class EEM_Ticket_Price extends EEM_Base |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the EEM_Ticket_Price object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Ticket_Price object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access protected |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = __('Ticket Price', 'event_espresso'); |
|
27 | - $this->plural_item = __('Ticket Prices', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access protected |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = __('Ticket Price', 'event_espresso'); |
|
27 | + $this->plural_item = __('Ticket Prices', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Ticket_Price'=>new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Ticket_Price'=> array( |
|
34 | - 'TKP_ID'=>new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | - 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | - 'PRC_ID'=>new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | - 'Price'=>new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | - // account for default tickets in the caps |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - // follow the caps of the ticket |
|
50 | - $this->_caps_slug = 'tickets'; |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Ticket_Price'=>new EE_Primary_Table('esp_ticket_price', 'TKP_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Ticket_Price'=> array( |
|
34 | + 'TKP_ID'=>new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'), |
|
35 | + 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'), |
|
36 | + 'PRC_ID'=>new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | + 'Price'=>new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + // account for default tickets in the caps |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + // follow the caps of the ticket |
|
50 | + $this->_caps_slug = 'tickets'; |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | 53 | } |
@@ -41,11 +41,11 @@ |
||
41 | 41 | 'Price'=>new EE_Belongs_To_Relation() |
42 | 42 | ); |
43 | 43 | $this->_model_chain_to_wp_user = 'Ticket'; |
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
44 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | 45 | // account for default tickets in the caps |
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | 49 | // follow the caps of the ticket |
50 | 50 | $this->_caps_slug = 'tickets'; |
51 | 51 | parent::__construct($timezone); |
@@ -6,45 +6,45 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_Index |
8 | 8 | { |
9 | - protected $_name; |
|
10 | - protected $_field_names; |
|
11 | - protected $_model_name; |
|
12 | - public function __construct($fields) |
|
13 | - { |
|
14 | - $this->_field_names = $fields; |
|
15 | - } |
|
16 | - public function _construct_finalize($name, $model_name) |
|
17 | - { |
|
18 | - $this->_name = $name; |
|
19 | - $this->_model_name = $model_name; |
|
20 | - } |
|
21 | - public function field_names() |
|
22 | - { |
|
23 | - return $this->_field_names; |
|
24 | - } |
|
25 | - /** |
|
26 | - * Internally used by get_this_model() and get_other_model() |
|
27 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | - * @return EEM_Base |
|
29 | - */ |
|
30 | - protected function _get_model($model_name) |
|
31 | - { |
|
32 | - $modelInstance=call_user_func("EEM_".$model_name."::instance"); |
|
33 | - return $modelInstance; |
|
34 | - } |
|
35 | - /** |
|
36 | - * Gets all the fields for this index |
|
37 | - * @return EE_Model_Field_Base[] |
|
38 | - */ |
|
39 | - public function fields() |
|
40 | - { |
|
41 | - $fields = array(); |
|
42 | - $model = $this->_get_model($this->_model_name); |
|
43 | - foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | - if (in_array($field_name, $this->field_names())) { |
|
45 | - $fields[ $field_name ] = $field_obj; |
|
46 | - } |
|
47 | - } |
|
48 | - return $fields; |
|
49 | - } |
|
9 | + protected $_name; |
|
10 | + protected $_field_names; |
|
11 | + protected $_model_name; |
|
12 | + public function __construct($fields) |
|
13 | + { |
|
14 | + $this->_field_names = $fields; |
|
15 | + } |
|
16 | + public function _construct_finalize($name, $model_name) |
|
17 | + { |
|
18 | + $this->_name = $name; |
|
19 | + $this->_model_name = $model_name; |
|
20 | + } |
|
21 | + public function field_names() |
|
22 | + { |
|
23 | + return $this->_field_names; |
|
24 | + } |
|
25 | + /** |
|
26 | + * Internally used by get_this_model() and get_other_model() |
|
27 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
28 | + * @return EEM_Base |
|
29 | + */ |
|
30 | + protected function _get_model($model_name) |
|
31 | + { |
|
32 | + $modelInstance=call_user_func("EEM_".$model_name."::instance"); |
|
33 | + return $modelInstance; |
|
34 | + } |
|
35 | + /** |
|
36 | + * Gets all the fields for this index |
|
37 | + * @return EE_Model_Field_Base[] |
|
38 | + */ |
|
39 | + public function fields() |
|
40 | + { |
|
41 | + $fields = array(); |
|
42 | + $model = $this->_get_model($this->_model_name); |
|
43 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
44 | + if (in_array($field_name, $this->field_names())) { |
|
45 | + $fields[ $field_name ] = $field_obj; |
|
46 | + } |
|
47 | + } |
|
48 | + return $fields; |
|
49 | + } |
|
50 | 50 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | protected function _get_model($model_name) |
31 | 31 | { |
32 | - $modelInstance=call_user_func("EEM_".$model_name."::instance"); |
|
32 | + $modelInstance = call_user_func("EEM_".$model_name."::instance"); |
|
33 | 33 | return $modelInstance; |
34 | 34 | } |
35 | 35 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $model = $this->_get_model($this->_model_name); |
43 | 43 | foreach ($model->field_settings() as $field_name => $field_obj) { |
44 | 44 | if (in_array($field_name, $this->field_names())) { |
45 | - $fields[ $field_name ] = $field_obj; |
|
45 | + $fields[$field_name] = $field_obj; |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | return $fields; |