@@ -11,59 +11,59 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Maybe_Serialized_Simple_HTML_Field extends EE_Maybe_Serialized_Text_Field |
13 | 13 | { |
14 | - /** |
|
15 | - * removes all non-basic tags when setting |
|
16 | - * |
|
17 | - * @param string $value_inputted_for_field_on_model_object |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
21 | - { |
|
22 | - return parent::prepare_for_set($this->_remove_tags($value_inputted_for_field_on_model_object)); |
|
23 | - } |
|
14 | + /** |
|
15 | + * removes all non-basic tags when setting |
|
16 | + * |
|
17 | + * @param string $value_inputted_for_field_on_model_object |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
21 | + { |
|
22 | + return parent::prepare_for_set($this->_remove_tags($value_inputted_for_field_on_model_object)); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Remove any non-"simple" html tags. @see EE_Simple_HTML_Field |
|
27 | - * |
|
28 | - * @param array|string $value |
|
29 | - * @return array|string |
|
30 | - */ |
|
31 | - protected function _remove_tags($value) |
|
32 | - { |
|
33 | - if (is_array($value)) { |
|
34 | - foreach ($value as $key => $v) { |
|
35 | - $value[ $key ] = $this->_remove_tags($v); |
|
36 | - } |
|
37 | - } elseif (is_string($value)) { |
|
38 | - $value = wp_kses("$value", $this->_get_allowed_tags()); |
|
39 | - } |
|
40 | - return $value; |
|
41 | - } |
|
25 | + /** |
|
26 | + * Remove any non-"simple" html tags. @see EE_Simple_HTML_Field |
|
27 | + * |
|
28 | + * @param array|string $value |
|
29 | + * @return array|string |
|
30 | + */ |
|
31 | + protected function _remove_tags($value) |
|
32 | + { |
|
33 | + if (is_array($value)) { |
|
34 | + foreach ($value as $key => $v) { |
|
35 | + $value[ $key ] = $this->_remove_tags($v); |
|
36 | + } |
|
37 | + } elseif (is_string($value)) { |
|
38 | + $value = wp_kses("$value", $this->_get_allowed_tags()); |
|
39 | + } |
|
40 | + return $value; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * In case unsafe data somehow got inserted into the database, we want to remove tags again |
|
45 | - * |
|
46 | - * @param array|string $value_found_in_db_for_model_object |
|
47 | - * @return array|string |
|
48 | - */ |
|
49 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
50 | - { |
|
51 | - return $this->_remove_tags(parent::prepare_for_set_from_db($value_found_in_db_for_model_object)); |
|
52 | - } |
|
43 | + /** |
|
44 | + * In case unsafe data somehow got inserted into the database, we want to remove tags again |
|
45 | + * |
|
46 | + * @param array|string $value_found_in_db_for_model_object |
|
47 | + * @return array|string |
|
48 | + */ |
|
49 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
50 | + { |
|
51 | + return $this->_remove_tags(parent::prepare_for_set_from_db($value_found_in_db_for_model_object)); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Determines what tags to allow in this model field |
|
57 | - * |
|
58 | - * @global array $allowedtags |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function _get_allowed_tags() |
|
62 | - { |
|
63 | - return apply_filters( |
|
64 | - 'FHEE__EE_Maybe_Serialized_Simple_HTML_Field___get_allowed_tags', |
|
65 | - EEH_HTML::get_simple_tags(), |
|
66 | - $this |
|
67 | - ); |
|
68 | - } |
|
55 | + /** |
|
56 | + * Determines what tags to allow in this model field |
|
57 | + * |
|
58 | + * @global array $allowedtags |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function _get_allowed_tags() |
|
62 | + { |
|
63 | + return apply_filters( |
|
64 | + 'FHEE__EE_Maybe_Serialized_Simple_HTML_Field___get_allowed_tags', |
|
65 | + EEH_HTML::get_simple_tags(), |
|
66 | + $this |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | { |
33 | 33 | if (is_array($value)) { |
34 | 34 | foreach ($value as $key => $v) { |
35 | - $value[ $key ] = $this->_remove_tags($v); |
|
35 | + $value[$key] = $this->_remove_tags($v); |
|
36 | 36 | } |
37 | 37 | } elseif (is_string($value)) { |
38 | 38 | $value = wp_kses("$value", $this->_get_allowed_tags()); |
@@ -10,28 +10,28 @@ |
||
10 | 10 | abstract class EE_DB_Only_Field_Base extends EE_Model_Field_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param string $table_column |
|
15 | - * @param string $nicename |
|
16 | - * @param bool $nullable |
|
17 | - * @param null $default_value |
|
18 | - */ |
|
19 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
20 | - { |
|
21 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
22 | - $this->setSchemaReadOnly(true); |
|
23 | - } |
|
13 | + /** |
|
14 | + * @param string $table_column |
|
15 | + * @param string $nicename |
|
16 | + * @param bool $nullable |
|
17 | + * @param null $default_value |
|
18 | + */ |
|
19 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
20 | + { |
|
21 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
22 | + $this->setSchemaReadOnly(true); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * All these children classes are for the db-only (meaning, we should select them |
|
28 | - * on get_all queries, update, delete, and will still want to set their default value |
|
29 | - * on inserts, but the model object won't have reference to these fields) |
|
30 | - * |
|
31 | - * @return boolean |
|
32 | - */ |
|
33 | - public function is_db_only_field() |
|
34 | - { |
|
35 | - return true; |
|
36 | - } |
|
26 | + /** |
|
27 | + * All these children classes are for the db-only (meaning, we should select them |
|
28 | + * on get_all queries, update, delete, and will still want to set their default value |
|
29 | + * on inserts, but the model object won't have reference to these fields) |
|
30 | + * |
|
31 | + * @return boolean |
|
32 | + */ |
|
33 | + public function is_db_only_field() |
|
34 | + { |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | } |
@@ -3,22 +3,22 @@ |
||
3 | 3 | class EE_Primary_Key_String_Field extends EE_Primary_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - public function __construct($table_column, $nicename) |
|
7 | - { |
|
8 | - parent::__construct($table_column, $nicename, null); |
|
9 | - } |
|
6 | + public function __construct($table_column, $nicename) |
|
7 | + { |
|
8 | + parent::__construct($table_column, $nicename, null); |
|
9 | + } |
|
10 | 10 | |
11 | - /** |
|
12 | - * removes all tags when setting |
|
13 | - * |
|
14 | - * @param string $value_inputted_for_field_on_model_object |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
18 | - { |
|
19 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
20 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
21 | - } |
|
22 | - return wp_strip_all_tags($value_inputted_for_field_on_model_object); |
|
23 | - } |
|
11 | + /** |
|
12 | + * removes all tags when setting |
|
13 | + * |
|
14 | + * @param string $value_inputted_for_field_on_model_object |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
18 | + { |
|
19 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
20 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
21 | + } |
|
22 | + return wp_strip_all_tags($value_inputted_for_field_on_model_object); |
|
23 | + } |
|
24 | 24 | } |
@@ -3,36 +3,36 @@ |
||
3 | 3 | class EE_Foreign_Key_Int_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | 5 | |
6 | - /** |
|
7 | - * @param string $table_column name fo column for field |
|
8 | - * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
9 | - * @param boolean $nullable |
|
10 | - * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | - * dbe a string |
|
12 | - * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | - * "EEM_" |
|
14 | - */ |
|
15 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | - { |
|
17 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | - $this->setSchemaType('integer'); |
|
19 | - } |
|
6 | + /** |
|
7 | + * @param string $table_column name fo column for field |
|
8 | + * @param string $nicename should eb internationalized with __('blah','event_espresso') |
|
9 | + * @param boolean $nullable |
|
10 | + * @param mixed $default_value if this is a integer field, it shoudl be an int. if it's a string field, it shoul |
|
11 | + * dbe a string |
|
12 | + * @param string $model_name eg 'Event','Answer','Term', etc. Basically its the model class's name without the |
|
13 | + * "EEM_" |
|
14 | + */ |
|
15 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name) |
|
16 | + { |
|
17 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
18 | + $this->setSchemaType('integer'); |
|
19 | + } |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | - * @return int |
|
25 | - */ |
|
26 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | - { |
|
28 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | - } |
|
31 | - return absint($value_inputted_for_field_on_model_object); |
|
32 | - } |
|
22 | + /** |
|
23 | + * @param int|EE_Base_Class $value_inputted_for_field_on_model_object |
|
24 | + * @return int |
|
25 | + */ |
|
26 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
27 | + { |
|
28 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
29 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
30 | + } |
|
31 | + return absint($value_inputted_for_field_on_model_object); |
|
32 | + } |
|
33 | 33 | |
34 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | - { |
|
36 | - return intval($value_found_in_db_for_model_object); |
|
37 | - } |
|
34 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
35 | + { |
|
36 | + return intval($value_found_in_db_for_model_object); |
|
37 | + } |
|
38 | 38 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | ); |
50 | 50 | $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
51 | 51 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
52 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
52 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
53 | 53 | } |
54 | 54 | $this->_caps_slug = 'messages'; |
55 | 55 | parent::__construct($timezone); |
@@ -14,45 +14,45 @@ |
||
14 | 14 | */ |
15 | 15 | class EEM_Message_Template extends EEM_Base |
16 | 16 | { |
17 | - // private instance of the EEM_Message_Template object |
|
18 | - protected static $_instance = null; |
|
17 | + // private instance of the EEM_Message_Template object |
|
18 | + protected static $_instance = null; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * private constructor to prevent direct creation |
|
24 | - * |
|
25 | - * @Constructor |
|
26 | - * @access protected |
|
27 | - * @param string $timezone |
|
28 | - * @throws \EE_Error |
|
29 | - */ |
|
30 | - protected function __construct($timezone = null) |
|
31 | - { |
|
32 | - $this->singular_item = __('Message Template', 'event_espresso'); |
|
33 | - $this->plural_item = __('Message Templates', 'event_espresso'); |
|
22 | + /** |
|
23 | + * private constructor to prevent direct creation |
|
24 | + * |
|
25 | + * @Constructor |
|
26 | + * @access protected |
|
27 | + * @param string $timezone |
|
28 | + * @throws \EE_Error |
|
29 | + */ |
|
30 | + protected function __construct($timezone = null) |
|
31 | + { |
|
32 | + $this->singular_item = __('Message Template', 'event_espresso'); |
|
33 | + $this->plural_item = __('Message Templates', 'event_espresso'); |
|
34 | 34 | |
35 | - $this->_tables = array( |
|
36 | - 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
37 | - ); |
|
38 | - $this->_fields = array( |
|
39 | - 'Message_Template' => array( |
|
40 | - 'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', __('Message Template ID', 'event_espresso')), |
|
41 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
42 | - 'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', __('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
43 | - 'MTP_context' => new EE_Plain_Text_Field('MTP_context', __('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
44 | - 'MTP_content' => new EE_Serialized_Text_Field('MTP_content', __('The field content for the template', 'event_espresso'), false, ''), |
|
45 | - ) |
|
46 | - ); |
|
35 | + $this->_tables = array( |
|
36 | + 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
37 | + ); |
|
38 | + $this->_fields = array( |
|
39 | + 'Message_Template' => array( |
|
40 | + 'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', __('Message Template ID', 'event_espresso')), |
|
41 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
42 | + 'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', __('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
43 | + 'MTP_context' => new EE_Plain_Text_Field('MTP_context', __('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
44 | + 'MTP_content' => new EE_Serialized_Text_Field('MTP_content', __('The field content for the template', 'event_espresso'), false, ''), |
|
45 | + ) |
|
46 | + ); |
|
47 | 47 | |
48 | - $this->_model_relations = array( |
|
49 | - 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
50 | - ); |
|
51 | - $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
52 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
53 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
54 | - } |
|
55 | - $this->_caps_slug = 'messages'; |
|
56 | - parent::__construct($timezone); |
|
57 | - } |
|
48 | + $this->_model_relations = array( |
|
49 | + 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
50 | + ); |
|
51 | + $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
52 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
53 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
54 | + } |
|
55 | + $this->_caps_slug = 'messages'; |
|
56 | + parent::__construct($timezone); |
|
57 | + } |
|
58 | 58 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | $this->singular_item = __('Registration Payment', 'event_espresso'); |
23 | - $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
23 | + $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
24 | 24 | |
25 | 25 | $this->_tables = array( |
26 | 26 | 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
@@ -13,34 +13,34 @@ |
||
13 | 13 | class EEM_Registration_Payment extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - // private instance |
|
17 | - protected static $_instance = null; |
|
16 | + // private instance |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | - protected function __construct($timezone = null) |
|
21 | - { |
|
20 | + protected function __construct($timezone = null) |
|
21 | + { |
|
22 | 22 | |
23 | - $this->singular_item = __('Registration Payment', 'event_espresso'); |
|
24 | - $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
23 | + $this->singular_item = __('Registration Payment', 'event_espresso'); |
|
24 | + $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
25 | 25 | |
26 | - $this->_tables = array( |
|
27 | - 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
28 | - ); |
|
26 | + $this->_tables = array( |
|
27 | + 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
28 | + ); |
|
29 | 29 | |
30 | - $this->_fields = array( |
|
31 | - 'Registration_Payment' => array( |
|
32 | - 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')), |
|
33 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
34 | - 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
35 | - 'RPY_amount' => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
36 | - ) |
|
37 | - ); |
|
30 | + $this->_fields = array( |
|
31 | + 'Registration_Payment' => array( |
|
32 | + 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')), |
|
33 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
34 | + 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
35 | + 'RPY_amount' => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
36 | + ) |
|
37 | + ); |
|
38 | 38 | |
39 | - $this->_model_relations = array( |
|
40 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
41 | - 'Payment' => new EE_Belongs_To_Relation(), |
|
42 | - ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
41 | + 'Payment' => new EE_Belongs_To_Relation(), |
|
42 | + ); |
|
43 | 43 | |
44 | - parent::__construct($timezone); |
|
45 | - } |
|
44 | + parent::__construct($timezone); |
|
45 | + } |
|
46 | 46 | } |
@@ -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 | } |