@@ -16,38 +16,38 @@ |
||
16 | 16 | class EEM_Question_Group_Question extends EEM_Base |
17 | 17 | { |
18 | 18 | |
19 | - // private instance of the Attendee object |
|
20 | - protected static $_instance = null; |
|
19 | + // private instance of the Attendee object |
|
20 | + protected static $_instance = null; |
|
21 | 21 | |
22 | 22 | |
23 | - protected function __construct($timezone = null) |
|
24 | - { |
|
25 | - $this->singular_item = __('Question Group to Question Link', 'event_espresso'); |
|
26 | - $this->plural_item = __('Question Group to Question Links', 'event_espresso'); |
|
27 | - $this->_tables = array( |
|
28 | - 'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question', 'QGQ_ID') |
|
29 | - ); |
|
30 | - $this->_fields = array( |
|
31 | - 'Question_Group_Question'=>array( |
|
32 | - 'QGQ_ID'=>new EE_Primary_Key_Int_Field('QGQ_ID', __('Question Group to Question Link ID', 'event_espresso')), |
|
33 | - 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'), |
|
34 | - 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question Id', 'event_espresso'), false, 0, 'Question'), |
|
35 | - 'QGQ_order' => new EE_Integer_Field('QGQ_order', __('Question Group Question Order', 'event_espresso'), false, 0) |
|
36 | - ) |
|
37 | - ); |
|
38 | - $this->_model_relations = array( |
|
39 | - 'Question_Group'=>new EE_Belongs_To_Relation(), |
|
40 | - 'Question'=>new EE_Belongs_To_Relation() |
|
41 | - ); |
|
23 | + protected function __construct($timezone = null) |
|
24 | + { |
|
25 | + $this->singular_item = __('Question Group to Question Link', 'event_espresso'); |
|
26 | + $this->plural_item = __('Question Group to Question Links', 'event_espresso'); |
|
27 | + $this->_tables = array( |
|
28 | + 'Question_Group_Question'=>new EE_Primary_Table('esp_question_group_question', 'QGQ_ID') |
|
29 | + ); |
|
30 | + $this->_fields = array( |
|
31 | + 'Question_Group_Question'=>array( |
|
32 | + 'QGQ_ID'=>new EE_Primary_Key_Int_Field('QGQ_ID', __('Question Group to Question Link ID', 'event_espresso')), |
|
33 | + 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'), |
|
34 | + 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question Id', 'event_espresso'), false, 0, 'Question'), |
|
35 | + 'QGQ_order' => new EE_Integer_Field('QGQ_order', __('Question Group Question Order', 'event_espresso'), false, 0) |
|
36 | + ) |
|
37 | + ); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Question_Group'=>new EE_Belongs_To_Relation(), |
|
40 | + 'Question'=>new EE_Belongs_To_Relation() |
|
41 | + ); |
|
42 | 42 | |
43 | - $this->_model_chain_to_wp_user = 'Question_Group'; |
|
44 | - // this model is generally available for reading |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
49 | - // use the caps for question groups |
|
50 | - $this->_caps_slug = 'question_groups'; |
|
51 | - parent::__construct($timezone); |
|
52 | - } |
|
43 | + $this->_model_chain_to_wp_user = 'Question_Group'; |
|
44 | + // this model is generally available for reading |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
49 | + // use the caps for question groups |
|
50 | + $this->_caps_slug = 'question_groups'; |
|
51 | + parent::__construct($timezone); |
|
52 | + } |
|
53 | 53 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | |
43 | 43 | $this->_model_chain_to_wp_user = 'Question_Group'; |
44 | 44 | // this model is generally available for reading |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
49 | 49 | // use the caps for question groups |
50 | 50 | $this->_caps_slug = 'question_groups'; |
51 | 51 | parent::__construct($timezone); |
@@ -12,34 +12,34 @@ |
||
12 | 12 | class EEM_Registration_Payment extends EEM_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | 18 | |
19 | - protected function __construct($timezone = null) |
|
20 | - { |
|
19 | + protected function __construct($timezone = null) |
|
20 | + { |
|
21 | 21 | |
22 | - $this->singular_item = __('Registration Payment', 'event_espresso'); |
|
23 | - $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
22 | + $this->singular_item = __('Registration Payment', 'event_espresso'); |
|
23 | + $this->plural_item = __('Registration Payments', 'event_espresso'); |
|
24 | 24 | |
25 | - $this->_tables = array( |
|
26 | - 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | - ); |
|
25 | + $this->_tables = array( |
|
26 | + 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | + ); |
|
28 | 28 | |
29 | - $this->_fields = array( |
|
30 | - 'Registration_Payment'=>array( |
|
31 | - 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')), |
|
32 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | - 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | - 'RPY_amount' => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | - ) |
|
36 | - ); |
|
29 | + $this->_fields = array( |
|
30 | + 'Registration_Payment'=>array( |
|
31 | + 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', __('Registration Payment ID', 'event_espresso')), |
|
32 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | + 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | + 'RPY_amount' => new EE_Money_Field('RPY_amount', __('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | + ) |
|
36 | + ); |
|
37 | 37 | |
38 | - $this->_model_relations = array( |
|
39 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | - 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | - ); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | + 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | + ); |
|
42 | 42 | |
43 | - parent::__construct($timezone); |
|
44 | - } |
|
43 | + parent::__construct($timezone); |
|
44 | + } |
|
45 | 45 | } |
@@ -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') |
@@ -10,166 +10,166 @@ |
||
10 | 10 | class EEM_Venue extends EEM_CPT_Base |
11 | 11 | { |
12 | 12 | |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - protected function __construct($timezone = null) |
|
19 | - { |
|
20 | - $this->singular_item = __('Venue', 'event_espresso'); |
|
21 | - $this->plural_item = __('Venues', 'event_espresso'); |
|
22 | - $this->_tables = array( |
|
23 | - 'Venue_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
24 | - 'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'), |
|
25 | - ); |
|
26 | - $this->_fields = array( |
|
27 | - 'Venue_CPT' => array( |
|
28 | - 'VNU_ID' => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")), |
|
29 | - 'VNU_name' => new EE_Plain_Text_Field( |
|
30 | - 'post_title', |
|
31 | - __("Venue Name", "event_espresso"), |
|
32 | - false, |
|
33 | - '' |
|
34 | - ), |
|
35 | - 'VNU_desc' => new EE_Post_Content_Field( |
|
36 | - 'post_content', |
|
37 | - __("Venue Description", "event_espresso"), |
|
38 | - false, |
|
39 | - '' |
|
40 | - ), |
|
41 | - 'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''), |
|
42 | - 'VNU_created' => new EE_Datetime_Field( |
|
43 | - 'post_date', |
|
44 | - __("Date Venue Created", "event_espresso"), |
|
45 | - false, |
|
46 | - EE_Datetime_Field::now |
|
47 | - ), |
|
48 | - 'VNU_short_desc' => new EE_Plain_Text_Field( |
|
49 | - 'post_excerpt', |
|
50 | - __("Short Description of Venue", "event_espresso"), |
|
51 | - true, |
|
52 | - '' |
|
53 | - ), |
|
54 | - 'VNU_modified' => new EE_Datetime_Field( |
|
55 | - 'post_modified', |
|
56 | - __("Venue Modified Date", "event_espresso"), |
|
57 | - false, |
|
58 | - EE_Datetime_Field::now |
|
59 | - ), |
|
60 | - 'VNU_wp_user' => new EE_WP_User_Field( |
|
61 | - 'post_author', |
|
62 | - __("Venue Creator ID", "event_espresso"), |
|
63 | - false |
|
64 | - ), |
|
65 | - 'parent' => new EE_Integer_Field( |
|
66 | - 'post_parent', |
|
67 | - __("Venue Parent ID", "event_espresso"), |
|
68 | - false, |
|
69 | - 0 |
|
70 | - ), |
|
71 | - 'VNU_order' => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1), |
|
72 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_venues'), |
|
73 | - // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'), |
|
74 | - ), |
|
75 | - 'Venue_Meta' => array( |
|
76 | - 'VNUM_ID' => new EE_DB_Only_Int_Field( |
|
77 | - 'VNUM_ID', |
|
78 | - __("ID of Venue Meta Row", "event_espresso"), |
|
79 | - false |
|
80 | - ), |
|
81 | - 'VNU_ID_fk' => new EE_DB_Only_Int_Field( |
|
82 | - 'VNU_ID', |
|
83 | - __("Foreign Key to Venue Post ", "event_espresso"), |
|
84 | - false |
|
85 | - ), |
|
86 | - 'VNU_address' => new EE_Plain_Text_Field( |
|
87 | - 'VNU_address', |
|
88 | - __("Venue Address line 1", "event_espresso"), |
|
89 | - true, |
|
90 | - '' |
|
91 | - ), |
|
92 | - 'VNU_address2' => new EE_Plain_Text_Field( |
|
93 | - 'VNU_address2', |
|
94 | - __("Venue Address line 2", "event_espresso"), |
|
95 | - true, |
|
96 | - '' |
|
97 | - ), |
|
98 | - 'VNU_city' => new EE_Plain_Text_Field( |
|
99 | - 'VNU_city', |
|
100 | - __("Venue City", "event_espresso"), |
|
101 | - true, |
|
102 | - '' |
|
103 | - ), |
|
104 | - 'STA_ID' => new EE_Foreign_Key_Int_Field( |
|
105 | - 'STA_ID', |
|
106 | - __("State ID", "event_espresso"), |
|
107 | - true, |
|
108 | - null, |
|
109 | - 'State' |
|
110 | - ), |
|
111 | - 'CNT_ISO' => new EE_Foreign_Key_String_Field( |
|
112 | - 'CNT_ISO', |
|
113 | - __("Country Code", "event_espresso"), |
|
114 | - true, |
|
115 | - null, |
|
116 | - 'Country' |
|
117 | - ), |
|
118 | - 'VNU_zip' => new EE_Plain_Text_Field( |
|
119 | - 'VNU_zip', |
|
120 | - __("Venue Zip/Postal Code", "event_espresso"), |
|
121 | - true |
|
122 | - ), |
|
123 | - 'VNU_phone' => new EE_Plain_Text_Field( |
|
124 | - 'VNU_phone', |
|
125 | - __("Venue Phone", "event_espresso"), |
|
126 | - true |
|
127 | - ), |
|
128 | - 'VNU_capacity' => new EE_Infinite_Integer_Field( |
|
129 | - 'VNU_capacity', |
|
130 | - __("Venue Capacity", "event_espresso"), |
|
131 | - true, |
|
132 | - EE_INF |
|
133 | - ), |
|
134 | - 'VNU_url' => new EE_Plain_Text_Field( |
|
135 | - 'VNU_url', |
|
136 | - __('Venue Website', 'event_espresso'), |
|
137 | - true |
|
138 | - ), |
|
139 | - 'VNU_virtual_phone' => new EE_Plain_Text_Field( |
|
140 | - 'VNU_virtual_phone', |
|
141 | - __('Call in Number', 'event_espresso'), |
|
142 | - true |
|
143 | - ), |
|
144 | - 'VNU_virtual_url' => new EE_Plain_Text_Field( |
|
145 | - 'VNU_virtual_url', |
|
146 | - __('Virtual URL', 'event_espresso'), |
|
147 | - true |
|
148 | - ), |
|
149 | - 'VNU_google_map_link' => new EE_Plain_Text_Field( |
|
150 | - 'VNU_google_map_link', |
|
151 | - __('Google Map Link', 'event_espresso'), |
|
152 | - true |
|
153 | - ), |
|
154 | - 'VNU_enable_for_gmap' => new EE_Boolean_Field( |
|
155 | - 'VNU_enable_for_gmap', |
|
156 | - __('Show Google Map?', 'event_espresso'), |
|
157 | - false, |
|
158 | - false |
|
159 | - ), |
|
160 | - ), |
|
161 | - ); |
|
162 | - $this->_model_relations = array( |
|
163 | - 'Event' => new EE_HABTM_Relation('Event_Venue'), |
|
164 | - 'State' => new EE_Belongs_To_Relation(), |
|
165 | - 'Country' => new EE_Belongs_To_Relation(), |
|
166 | - 'Event_Venue' => new EE_Has_Many_Relation(), |
|
167 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
168 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
169 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
170 | - ); |
|
171 | - // this model is generally available for reading |
|
172 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
173 | - parent::__construct($timezone); |
|
174 | - } |
|
18 | + protected function __construct($timezone = null) |
|
19 | + { |
|
20 | + $this->singular_item = __('Venue', 'event_espresso'); |
|
21 | + $this->plural_item = __('Venues', 'event_espresso'); |
|
22 | + $this->_tables = array( |
|
23 | + 'Venue_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
24 | + 'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'), |
|
25 | + ); |
|
26 | + $this->_fields = array( |
|
27 | + 'Venue_CPT' => array( |
|
28 | + 'VNU_ID' => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")), |
|
29 | + 'VNU_name' => new EE_Plain_Text_Field( |
|
30 | + 'post_title', |
|
31 | + __("Venue Name", "event_espresso"), |
|
32 | + false, |
|
33 | + '' |
|
34 | + ), |
|
35 | + 'VNU_desc' => new EE_Post_Content_Field( |
|
36 | + 'post_content', |
|
37 | + __("Venue Description", "event_espresso"), |
|
38 | + false, |
|
39 | + '' |
|
40 | + ), |
|
41 | + 'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''), |
|
42 | + 'VNU_created' => new EE_Datetime_Field( |
|
43 | + 'post_date', |
|
44 | + __("Date Venue Created", "event_espresso"), |
|
45 | + false, |
|
46 | + EE_Datetime_Field::now |
|
47 | + ), |
|
48 | + 'VNU_short_desc' => new EE_Plain_Text_Field( |
|
49 | + 'post_excerpt', |
|
50 | + __("Short Description of Venue", "event_espresso"), |
|
51 | + true, |
|
52 | + '' |
|
53 | + ), |
|
54 | + 'VNU_modified' => new EE_Datetime_Field( |
|
55 | + 'post_modified', |
|
56 | + __("Venue Modified Date", "event_espresso"), |
|
57 | + false, |
|
58 | + EE_Datetime_Field::now |
|
59 | + ), |
|
60 | + 'VNU_wp_user' => new EE_WP_User_Field( |
|
61 | + 'post_author', |
|
62 | + __("Venue Creator ID", "event_espresso"), |
|
63 | + false |
|
64 | + ), |
|
65 | + 'parent' => new EE_Integer_Field( |
|
66 | + 'post_parent', |
|
67 | + __("Venue Parent ID", "event_espresso"), |
|
68 | + false, |
|
69 | + 0 |
|
70 | + ), |
|
71 | + 'VNU_order' => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1), |
|
72 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_venues'), |
|
73 | + // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'), |
|
74 | + ), |
|
75 | + 'Venue_Meta' => array( |
|
76 | + 'VNUM_ID' => new EE_DB_Only_Int_Field( |
|
77 | + 'VNUM_ID', |
|
78 | + __("ID of Venue Meta Row", "event_espresso"), |
|
79 | + false |
|
80 | + ), |
|
81 | + 'VNU_ID_fk' => new EE_DB_Only_Int_Field( |
|
82 | + 'VNU_ID', |
|
83 | + __("Foreign Key to Venue Post ", "event_espresso"), |
|
84 | + false |
|
85 | + ), |
|
86 | + 'VNU_address' => new EE_Plain_Text_Field( |
|
87 | + 'VNU_address', |
|
88 | + __("Venue Address line 1", "event_espresso"), |
|
89 | + true, |
|
90 | + '' |
|
91 | + ), |
|
92 | + 'VNU_address2' => new EE_Plain_Text_Field( |
|
93 | + 'VNU_address2', |
|
94 | + __("Venue Address line 2", "event_espresso"), |
|
95 | + true, |
|
96 | + '' |
|
97 | + ), |
|
98 | + 'VNU_city' => new EE_Plain_Text_Field( |
|
99 | + 'VNU_city', |
|
100 | + __("Venue City", "event_espresso"), |
|
101 | + true, |
|
102 | + '' |
|
103 | + ), |
|
104 | + 'STA_ID' => new EE_Foreign_Key_Int_Field( |
|
105 | + 'STA_ID', |
|
106 | + __("State ID", "event_espresso"), |
|
107 | + true, |
|
108 | + null, |
|
109 | + 'State' |
|
110 | + ), |
|
111 | + 'CNT_ISO' => new EE_Foreign_Key_String_Field( |
|
112 | + 'CNT_ISO', |
|
113 | + __("Country Code", "event_espresso"), |
|
114 | + true, |
|
115 | + null, |
|
116 | + 'Country' |
|
117 | + ), |
|
118 | + 'VNU_zip' => new EE_Plain_Text_Field( |
|
119 | + 'VNU_zip', |
|
120 | + __("Venue Zip/Postal Code", "event_espresso"), |
|
121 | + true |
|
122 | + ), |
|
123 | + 'VNU_phone' => new EE_Plain_Text_Field( |
|
124 | + 'VNU_phone', |
|
125 | + __("Venue Phone", "event_espresso"), |
|
126 | + true |
|
127 | + ), |
|
128 | + 'VNU_capacity' => new EE_Infinite_Integer_Field( |
|
129 | + 'VNU_capacity', |
|
130 | + __("Venue Capacity", "event_espresso"), |
|
131 | + true, |
|
132 | + EE_INF |
|
133 | + ), |
|
134 | + 'VNU_url' => new EE_Plain_Text_Field( |
|
135 | + 'VNU_url', |
|
136 | + __('Venue Website', 'event_espresso'), |
|
137 | + true |
|
138 | + ), |
|
139 | + 'VNU_virtual_phone' => new EE_Plain_Text_Field( |
|
140 | + 'VNU_virtual_phone', |
|
141 | + __('Call in Number', 'event_espresso'), |
|
142 | + true |
|
143 | + ), |
|
144 | + 'VNU_virtual_url' => new EE_Plain_Text_Field( |
|
145 | + 'VNU_virtual_url', |
|
146 | + __('Virtual URL', 'event_espresso'), |
|
147 | + true |
|
148 | + ), |
|
149 | + 'VNU_google_map_link' => new EE_Plain_Text_Field( |
|
150 | + 'VNU_google_map_link', |
|
151 | + __('Google Map Link', 'event_espresso'), |
|
152 | + true |
|
153 | + ), |
|
154 | + 'VNU_enable_for_gmap' => new EE_Boolean_Field( |
|
155 | + 'VNU_enable_for_gmap', |
|
156 | + __('Show Google Map?', 'event_espresso'), |
|
157 | + false, |
|
158 | + false |
|
159 | + ), |
|
160 | + ), |
|
161 | + ); |
|
162 | + $this->_model_relations = array( |
|
163 | + 'Event' => new EE_HABTM_Relation('Event_Venue'), |
|
164 | + 'State' => new EE_Belongs_To_Relation(), |
|
165 | + 'Country' => new EE_Belongs_To_Relation(), |
|
166 | + 'Event_Venue' => new EE_Has_Many_Relation(), |
|
167 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
168 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
169 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
170 | + ); |
|
171 | + // this model is generally available for reading |
|
172 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
173 | + parent::__construct($timezone); |
|
174 | + } |
|
175 | 175 | } |
@@ -169,7 +169,7 @@ |
||
169 | 169 | 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
170 | 170 | ); |
171 | 171 | // this model is generally available for reading |
172 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
172 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
173 | 173 | parent::__construct($timezone); |
174 | 174 | } |
175 | 175 | } |
@@ -13,40 +13,40 @@ |
||
13 | 13 | class EEM_Checkin extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - // private instance of the EEM_Checkin object |
|
17 | - protected static $_instance = null; |
|
16 | + // private instance of the EEM_Checkin object |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * private constructor to prevent direct creation |
|
23 | - * @Constructor |
|
24 | - * @access protected |
|
25 | - * @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) |
|
26 | - * @return void |
|
27 | - */ |
|
28 | - protected function __construct($timezone = null) |
|
29 | - { |
|
30 | - $this->singular_item = __('Check-In', 'event_espresso'); |
|
31 | - $this->plural_item = __('Check-Ins', 'event_espresso'); |
|
21 | + /** |
|
22 | + * private constructor to prevent direct creation |
|
23 | + * @Constructor |
|
24 | + * @access protected |
|
25 | + * @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) |
|
26 | + * @return void |
|
27 | + */ |
|
28 | + protected function __construct($timezone = null) |
|
29 | + { |
|
30 | + $this->singular_item = __('Check-In', 'event_espresso'); |
|
31 | + $this->plural_item = __('Check-Ins', 'event_espresso'); |
|
32 | 32 | |
33 | - $this->_tables = array( |
|
34 | - 'Checkin'=>new EE_Primary_Table('esp_checkin', 'CHK_ID') |
|
35 | - ); |
|
36 | - $this->_fields = array( |
|
37 | - 'Checkin'=> array( |
|
38 | - 'CHK_ID'=>new EE_Primary_Key_Int_Field('CHK_ID', 'Check-in ID'), |
|
39 | - 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'), |
|
40 | - 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'), |
|
41 | - 'CHK_in'=>new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true), |
|
42 | - 'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified', 'event_espresso'), false, EE_Datetime_Field::now, $timezone) |
|
43 | - ) |
|
44 | - ); |
|
45 | - $this->_model_relations = array( |
|
46 | - 'Registration'=>new EE_Belongs_To_Relation(), |
|
47 | - 'Datetime'=>new EE_Belongs_To_Relation() |
|
48 | - ); |
|
49 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
50 | - parent::__construct($timezone); |
|
51 | - } |
|
33 | + $this->_tables = array( |
|
34 | + 'Checkin'=>new EE_Primary_Table('esp_checkin', 'CHK_ID') |
|
35 | + ); |
|
36 | + $this->_fields = array( |
|
37 | + 'Checkin'=> array( |
|
38 | + 'CHK_ID'=>new EE_Primary_Key_Int_Field('CHK_ID', 'Check-in ID'), |
|
39 | + 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'), |
|
40 | + 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'), |
|
41 | + 'CHK_in'=>new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true), |
|
42 | + 'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified', 'event_espresso'), false, EE_Datetime_Field::now, $timezone) |
|
43 | + ) |
|
44 | + ); |
|
45 | + $this->_model_relations = array( |
|
46 | + 'Registration'=>new EE_Belongs_To_Relation(), |
|
47 | + 'Datetime'=>new EE_Belongs_To_Relation() |
|
48 | + ); |
|
49 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
50 | + parent::__construct($timezone); |
|
51 | + } |
|
52 | 52 | } |
@@ -9,227 +9,227 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_HABTM_Relation extends EE_Model_Relation_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | - * which joins EE_Event and EE_Question_Group |
|
15 | - * |
|
16 | - * @var EEM_Base |
|
17 | - */ |
|
18 | - protected $_joining_model_name; |
|
19 | - |
|
20 | - protected $_model_relation_chain_to_join_model; |
|
21 | - |
|
22 | - |
|
23 | - /** |
|
24 | - * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | - * (and an ee joining-model.) This knows how to join the models, |
|
26 | - * get related models across the relation, and add-and-remove the relationships. |
|
27 | - * |
|
28 | - * @param bool $joining_model_name |
|
29 | - * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | - * are related models across this relation, block (prevent and add an |
|
31 | - * error) the deletion of this model |
|
32 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | - * default |
|
34 | - */ |
|
35 | - public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | - { |
|
37 | - $this->_joining_model_name = $joining_model_name; |
|
38 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Gets the joining model's object |
|
43 | - * |
|
44 | - * @return EEM_Base |
|
45 | - */ |
|
46 | - public function get_join_model() |
|
47 | - { |
|
48 | - return $this->_get_model($this->_joining_model_name); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | - * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | - * |
|
56 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | - * @return string of SQL |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | - { |
|
62 | - // create sql like |
|
63 | - // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | - // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | - // remember the model relation chain to the JOIN model, because we'll |
|
66 | - // need it for get_join_statement() |
|
67 | - $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | - $model_relation_chain, |
|
72 | - $this->get_this_model()->get_this_model_name() |
|
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
74 | - |
|
75 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | - $model_relation_chain, |
|
77 | - $this->get_join_model()->get_this_model_name() |
|
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | - // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | - $SQL = $this->_left_join( |
|
82 | - $join_table, |
|
83 | - $join_table_alias, |
|
84 | - $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | - $this_table_alias, |
|
86 | - $this_table_pk_field->get_table_column() |
|
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | - |
|
89 | - return $SQL; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | - * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | - * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | - * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | - * the intermediate join table, and then to the other model's pk's table |
|
99 | - * |
|
100 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | - * @return string of SQL |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function get_join_statement($model_relation_chain) |
|
105 | - { |
|
106 | - if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | - throw new EE_Error(sprintf(__( |
|
108 | - 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | - 'event_espresso' |
|
110 | - ))); |
|
111 | - } |
|
112 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | - $this->_model_relation_chain_to_join_model, |
|
115 | - $this->get_join_model()->get_this_model_name() |
|
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | - $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | - $model_relation_chain, |
|
121 | - $this->get_other_model()->get_this_model_name() |
|
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | - |
|
125 | - $SQL = $this->_left_join( |
|
126 | - $other_table, |
|
127 | - $other_table_alias, |
|
128 | - $other_table_pk_field->get_table_column(), |
|
129 | - $join_table_alias, |
|
130 | - $join_table_fk_field_to_other_table->get_table_column() |
|
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | - return $SQL; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | - * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | - * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | - * columns' values |
|
141 | - * |
|
142 | - * @param EE_Base_Class|int $this_obj_or_id |
|
143 | - * @param EE_Base_Class|int $other_obj_or_id |
|
144 | - * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | - * checking existing values and for setting new rows if |
|
146 | - * no exact matches. |
|
147 | - * @return EE_Base_Class |
|
148 | - * @throws \EE_Error |
|
149 | - */ |
|
150 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | - { |
|
152 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | - // check if such a relationship already exists |
|
155 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
157 | - |
|
158 | - $cols_n_values = array( |
|
159 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | - ); |
|
162 | - |
|
163 | - // if $where_query exists lets add them to the query_params. |
|
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
165 | - // 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) |
|
166 | - // make sure we strip THIS models name from the query param |
|
167 | - $parsed_query = array(); |
|
168 | - foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
171 | - "", |
|
172 | - $query_param |
|
173 | - ); |
|
174 | - $parsed_query[ $query_param ] = $val; |
|
175 | - } |
|
176 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
177 | - } |
|
178 | - |
|
179 | - $query_params = array($cols_n_values); |
|
180 | - |
|
181 | - |
|
182 | - $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
|
183 | - // if there is already an entry in the join table, indicating a relationship, we're done |
|
184 | - // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
185 | - // the other tables, use the joining model directly! |
|
186 | - if (! $existing_entry_in_join_table) { |
|
187 | - $this->get_join_model()->insert($cols_n_values); |
|
188 | - } |
|
189 | - return $other_model_obj; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
195 | - * |
|
196 | - * @param EE_Base_Class|int $this_obj_or_id |
|
197 | - * @param EE_Base_Class|int $other_obj_or_id |
|
198 | - * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
199 | - * values and for removing existing rows if exact matches exist. |
|
200 | - * @return EE_Base_Class |
|
201 | - * @throws \EE_Error |
|
202 | - */ |
|
203 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
204 | - { |
|
205 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
206 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
207 | - // check if such a relationship already exists |
|
208 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
209 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
210 | - |
|
211 | - $cols_n_values = array( |
|
212 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
213 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
214 | - ); |
|
215 | - |
|
216 | - // if $where_query exists lets add them to the query_params. |
|
217 | - if (! empty($where_query)) { |
|
218 | - // 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) |
|
219 | - // make sure we strip THIS models name from the query param |
|
220 | - $parsed_query = array(); |
|
221 | - foreach ($where_query as $query_param => $val) { |
|
222 | - $query_param = str_replace( |
|
223 | - $this->get_join_model()->get_this_model_name() . ".", |
|
224 | - "", |
|
225 | - $query_param |
|
226 | - ); |
|
227 | - $parsed_query[ $query_param ] = $val; |
|
228 | - } |
|
229 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
230 | - } |
|
231 | - |
|
232 | - $this->get_join_model()->delete(array($cols_n_values)); |
|
233 | - return $other_model_obj; |
|
234 | - } |
|
12 | + /** |
|
13 | + * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | + * which joins EE_Event and EE_Question_Group |
|
15 | + * |
|
16 | + * @var EEM_Base |
|
17 | + */ |
|
18 | + protected $_joining_model_name; |
|
19 | + |
|
20 | + protected $_model_relation_chain_to_join_model; |
|
21 | + |
|
22 | + |
|
23 | + /** |
|
24 | + * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | + * (and an ee joining-model.) This knows how to join the models, |
|
26 | + * get related models across the relation, and add-and-remove the relationships. |
|
27 | + * |
|
28 | + * @param bool $joining_model_name |
|
29 | + * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | + * are related models across this relation, block (prevent and add an |
|
31 | + * error) the deletion of this model |
|
32 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | + * default |
|
34 | + */ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | + { |
|
37 | + $this->_joining_model_name = $joining_model_name; |
|
38 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Gets the joining model's object |
|
43 | + * |
|
44 | + * @return EEM_Base |
|
45 | + */ |
|
46 | + public function get_join_model() |
|
47 | + { |
|
48 | + return $this->_get_model($this->_joining_model_name); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | + * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | + * |
|
56 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | + * @return string of SQL |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | + { |
|
62 | + // create sql like |
|
63 | + // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | + // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | + // remember the model relation chain to the JOIN model, because we'll |
|
66 | + // need it for get_join_statement() |
|
67 | + $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | + $model_relation_chain, |
|
72 | + $this->get_this_model()->get_this_model_name() |
|
73 | + ) . $this_table_pk_field->get_table_alias(); |
|
74 | + |
|
75 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | + $model_relation_chain, |
|
77 | + $this->get_join_model()->get_this_model_name() |
|
78 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | + // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | + $SQL = $this->_left_join( |
|
82 | + $join_table, |
|
83 | + $join_table_alias, |
|
84 | + $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | + $this_table_alias, |
|
86 | + $this_table_pk_field->get_table_column() |
|
87 | + ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | + |
|
89 | + return $SQL; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | + * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | + * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | + * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | + * the intermediate join table, and then to the other model's pk's table |
|
99 | + * |
|
100 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | + * @return string of SQL |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function get_join_statement($model_relation_chain) |
|
105 | + { |
|
106 | + if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | + throw new EE_Error(sprintf(__( |
|
108 | + 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | + 'event_espresso' |
|
110 | + ))); |
|
111 | + } |
|
112 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | + $this->_model_relation_chain_to_join_model, |
|
115 | + $this->get_join_model()->get_this_model_name() |
|
116 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | + $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | + $model_relation_chain, |
|
121 | + $this->get_other_model()->get_this_model_name() |
|
122 | + ) . $other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | + |
|
125 | + $SQL = $this->_left_join( |
|
126 | + $other_table, |
|
127 | + $other_table_alias, |
|
128 | + $other_table_pk_field->get_table_column(), |
|
129 | + $join_table_alias, |
|
130 | + $join_table_fk_field_to_other_table->get_table_column() |
|
131 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | + return $SQL; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | + * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | + * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | + * columns' values |
|
141 | + * |
|
142 | + * @param EE_Base_Class|int $this_obj_or_id |
|
143 | + * @param EE_Base_Class|int $other_obj_or_id |
|
144 | + * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | + * checking existing values and for setting new rows if |
|
146 | + * no exact matches. |
|
147 | + * @return EE_Base_Class |
|
148 | + * @throws \EE_Error |
|
149 | + */ |
|
150 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | + { |
|
152 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | + // check if such a relationship already exists |
|
155 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
157 | + |
|
158 | + $cols_n_values = array( |
|
159 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | + ); |
|
162 | + |
|
163 | + // if $where_query exists lets add them to the query_params. |
|
164 | + if (! empty($extra_join_model_fields_n_values)) { |
|
165 | + // 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) |
|
166 | + // make sure we strip THIS models name from the query param |
|
167 | + $parsed_query = array(); |
|
168 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name() . ".", |
|
171 | + "", |
|
172 | + $query_param |
|
173 | + ); |
|
174 | + $parsed_query[ $query_param ] = $val; |
|
175 | + } |
|
176 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
177 | + } |
|
178 | + |
|
179 | + $query_params = array($cols_n_values); |
|
180 | + |
|
181 | + |
|
182 | + $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params); |
|
183 | + // if there is already an entry in the join table, indicating a relationship, we're done |
|
184 | + // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
185 | + // the other tables, use the joining model directly! |
|
186 | + if (! $existing_entry_in_join_table) { |
|
187 | + $this->get_join_model()->insert($cols_n_values); |
|
188 | + } |
|
189 | + return $other_model_obj; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
195 | + * |
|
196 | + * @param EE_Base_Class|int $this_obj_or_id |
|
197 | + * @param EE_Base_Class|int $other_obj_or_id |
|
198 | + * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
199 | + * values and for removing existing rows if exact matches exist. |
|
200 | + * @return EE_Base_Class |
|
201 | + * @throws \EE_Error |
|
202 | + */ |
|
203 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
204 | + { |
|
205 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
206 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
207 | + // check if such a relationship already exists |
|
208 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
209 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
210 | + |
|
211 | + $cols_n_values = array( |
|
212 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
213 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
214 | + ); |
|
215 | + |
|
216 | + // if $where_query exists lets add them to the query_params. |
|
217 | + if (! empty($where_query)) { |
|
218 | + // 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) |
|
219 | + // make sure we strip THIS models name from the query param |
|
220 | + $parsed_query = array(); |
|
221 | + foreach ($where_query as $query_param => $val) { |
|
222 | + $query_param = str_replace( |
|
223 | + $this->get_join_model()->get_this_model_name() . ".", |
|
224 | + "", |
|
225 | + $query_param |
|
226 | + ); |
|
227 | + $parsed_query[ $query_param ] = $val; |
|
228 | + } |
|
229 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
230 | + } |
|
231 | + |
|
232 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
233 | + return $other_model_obj; |
|
234 | + } |
|
235 | 235 | } |
@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | // remember the model relation chain to the JOIN model, because we'll |
66 | 66 | // need it for get_join_statement() |
67 | 67 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); // get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | 69 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
70 | 70 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
71 | 71 | $model_relation_chain, |
72 | 72 | $this->get_this_model()->get_this_model_name() |
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
73 | + ).$this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | 75 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
76 | 76 | $model_relation_chain, |
77 | 77 | $this->get_join_model()->get_this_model_name() |
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
78 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | 80 | // phew! ok, we have all the info we need, now we can create the SQL join string |
81 | 81 | $SQL = $this->_left_join( |
82 | 82 | $join_table, |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $join_table_fk_field_to_this_table->get_table_column(), |
85 | 85 | $this_table_alias, |
86 | 86 | $this_table_pk_field->get_table_column() |
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
87 | + ).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | 89 | return $SQL; |
90 | 90 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
114 | 114 | $this->_model_relation_chain_to_join_model, |
115 | 115 | $this->get_join_model()->get_this_model_name() |
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
116 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | 117 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
118 | 118 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
119 | 119 | $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
120 | 120 | $model_relation_chain, |
121 | 121 | $this->get_other_model()->get_this_model_name() |
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
122 | + ).$other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | 125 | $SQL = $this->_left_join( |
126 | 126 | $other_table, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $other_table_pk_field->get_table_column(), |
129 | 129 | $join_table_alias, |
130 | 130 | $join_table_fk_field_to_other_table->get_table_column() |
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
131 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | 132 | return $SQL; |
133 | 133 | } |
134 | 134 | |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | ); |
162 | 162 | |
163 | 163 | // if $where_query exists lets add them to the query_params. |
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
164 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
165 | 165 | // 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) |
166 | 166 | // make sure we strip THIS models name from the query param |
167 | 167 | $parsed_query = array(); |
168 | 168 | foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name().".", |
|
171 | 171 | "", |
172 | 172 | $query_param |
173 | 173 | ); |
174 | - $parsed_query[ $query_param ] = $val; |
|
174 | + $parsed_query[$query_param] = $val; |
|
175 | 175 | } |
176 | 176 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | // if there is already an entry in the join table, indicating a relationship, we're done |
184 | 184 | // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
185 | 185 | // the other tables, use the joining model directly! |
186 | - if (! $existing_entry_in_join_table) { |
|
186 | + if ( ! $existing_entry_in_join_table) { |
|
187 | 187 | $this->get_join_model()->insert($cols_n_values); |
188 | 188 | } |
189 | 189 | return $other_model_obj; |
@@ -214,17 +214,17 @@ discard block |
||
214 | 214 | ); |
215 | 215 | |
216 | 216 | // if $where_query exists lets add them to the query_params. |
217 | - if (! empty($where_query)) { |
|
217 | + if ( ! empty($where_query)) { |
|
218 | 218 | // 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) |
219 | 219 | // make sure we strip THIS models name from the query param |
220 | 220 | $parsed_query = array(); |
221 | 221 | foreach ($where_query as $query_param => $val) { |
222 | - $query_param = str_replace( |
|
223 | - $this->get_join_model()->get_this_model_name() . ".", |
|
222 | + $query_param = str_replace( |
|
223 | + $this->get_join_model()->get_this_model_name().".", |
|
224 | 224 | "", |
225 | 225 | $query_param |
226 | 226 | ); |
227 | - $parsed_query[ $query_param ] = $val; |
|
227 | + $parsed_query[$query_param] = $val; |
|
228 | 228 | } |
229 | 229 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
230 | 230 | } |
@@ -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 |
@@ -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 like EEM_Base::get_all's $query_params |
|
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 like EEM_Base::get_all's $query_params |
|
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 | } |
@@ -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); |
@@ -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 | } |