@@ -9,142 +9,142 @@ |
||
9 | 9 | class EEM_Answer extends EEM_Base |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * private instance of the EEM_Answer object |
|
14 | - * @type EEM_Answer |
|
15 | - */ |
|
16 | - protected static $_instance = null; |
|
12 | + /** |
|
13 | + * private instance of the EEM_Answer object |
|
14 | + * @type EEM_Answer |
|
15 | + */ |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Mapping from system question ids to attendee field names |
|
20 | - * @type array |
|
21 | - * @deprecated since version 4.8.8 |
|
22 | - */ |
|
23 | - protected $_question_id_to_att_field_map = array( |
|
24 | - EEM_Attendee::fname_question_id => 'ATT_fname', |
|
25 | - EEM_Attendee::lname_question_id => 'ATT_lname', |
|
26 | - EEM_Attendee::email_question_id => 'ATT_email', |
|
27 | - EEM_Attendee::address_question_id => 'ATT_address', |
|
28 | - EEM_Attendee::address2_question_id => 'ATT_address2', |
|
29 | - EEM_Attendee::city_question_id => 'ATT_city', |
|
30 | - EEM_Attendee::state_question_id => 'STA_ID', |
|
31 | - EEM_Attendee::country_question_id => 'CNT_ISO', |
|
32 | - EEM_Attendee::zip_question_id => 'ATT_zip', |
|
33 | - EEM_Attendee::phone_question_id => 'ATT_phone' |
|
34 | - ); |
|
18 | + /** |
|
19 | + * Mapping from system question ids to attendee field names |
|
20 | + * @type array |
|
21 | + * @deprecated since version 4.8.8 |
|
22 | + */ |
|
23 | + protected $_question_id_to_att_field_map = array( |
|
24 | + EEM_Attendee::fname_question_id => 'ATT_fname', |
|
25 | + EEM_Attendee::lname_question_id => 'ATT_lname', |
|
26 | + EEM_Attendee::email_question_id => 'ATT_email', |
|
27 | + EEM_Attendee::address_question_id => 'ATT_address', |
|
28 | + EEM_Attendee::address2_question_id => 'ATT_address2', |
|
29 | + EEM_Attendee::city_question_id => 'ATT_city', |
|
30 | + EEM_Attendee::state_question_id => 'STA_ID', |
|
31 | + EEM_Attendee::country_question_id => 'CNT_ISO', |
|
32 | + EEM_Attendee::zip_question_id => 'ATT_zip', |
|
33 | + EEM_Attendee::phone_question_id => 'ATT_phone' |
|
34 | + ); |
|
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * constructor |
|
40 | - */ |
|
41 | - protected function __construct($timezone = null) |
|
42 | - { |
|
43 | - $this->singular_item = __('Answer', 'event_espresso'); |
|
44 | - $this->plural_item = __('Answers', 'event_espresso'); |
|
45 | - $this->_tables = array( |
|
46 | - 'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
47 | - ); |
|
48 | - $this->_fields = array( |
|
49 | - 'Answer'=>array( |
|
50 | - 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
51 | - 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
52 | - 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
53 | - 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
54 | - )); |
|
55 | - $this->_model_relations = array( |
|
56 | - 'Registration'=>new EE_Belongs_To_Relation(), |
|
57 | - 'Question'=>new EE_Belongs_To_Relation() |
|
58 | - ); |
|
59 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
60 | - $this->_caps_slug = 'registrations'; |
|
61 | - parent::__construct($timezone); |
|
62 | - } |
|
38 | + /** |
|
39 | + * constructor |
|
40 | + */ |
|
41 | + protected function __construct($timezone = null) |
|
42 | + { |
|
43 | + $this->singular_item = __('Answer', 'event_espresso'); |
|
44 | + $this->plural_item = __('Answers', 'event_espresso'); |
|
45 | + $this->_tables = array( |
|
46 | + 'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') |
|
47 | + ); |
|
48 | + $this->_fields = array( |
|
49 | + 'Answer'=>array( |
|
50 | + 'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), |
|
51 | + 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
52 | + 'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
53 | + 'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') |
|
54 | + )); |
|
55 | + $this->_model_relations = array( |
|
56 | + 'Registration'=>new EE_Belongs_To_Relation(), |
|
57 | + 'Question'=>new EE_Belongs_To_Relation() |
|
58 | + ); |
|
59 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
60 | + $this->_caps_slug = 'registrations'; |
|
61 | + parent::__construct($timezone); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Gets the string answer to the question for this registration (it could either be stored |
|
68 | - * on the attendee or in the answer table. This function finds its value regardless) |
|
69 | - * @param EE_Registration $registration |
|
70 | - * @param int $question_id |
|
71 | - * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
75 | - { |
|
76 | - $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
77 | - if ($value === null) { |
|
78 | - $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
79 | - if ($answer_obj instanceof EE_Answer) { |
|
80 | - if ($pretty_answer) { |
|
81 | - $value = $answer_obj->pretty_value(); |
|
82 | - } else { |
|
83 | - $value = $answer_obj->value(); |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
87 | - return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
88 | - } |
|
66 | + /** |
|
67 | + * Gets the string answer to the question for this registration (it could either be stored |
|
68 | + * on the attendee or in the answer table. This function finds its value regardless) |
|
69 | + * @param EE_Registration $registration |
|
70 | + * @param int $question_id |
|
71 | + * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + public function get_answer_value_to_question(EE_Registration $registration, $question_id = null, $pretty_answer = false) |
|
75 | + { |
|
76 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); |
|
77 | + if ($value === null) { |
|
78 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); |
|
79 | + if ($answer_obj instanceof EE_Answer) { |
|
80 | + if ($pretty_answer) { |
|
81 | + $value = $answer_obj->pretty_value(); |
|
82 | + } else { |
|
83 | + $value = $answer_obj->value(); |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | + return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 | |
92 | - /** |
|
93 | - * Gets the EE_Answer object for the question for this registration (if it exists) |
|
94 | - * @param EE_Registration $registration |
|
95 | - * @param int $question_id |
|
96 | - * @return EE_Answer |
|
97 | - */ |
|
98 | - public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
99 | - { |
|
100 | - $answer_obj = $this->get_one(array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
101 | - return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
102 | - } |
|
92 | + /** |
|
93 | + * Gets the EE_Answer object for the question for this registration (if it exists) |
|
94 | + * @param EE_Registration $registration |
|
95 | + * @param int $question_id |
|
96 | + * @return EE_Answer |
|
97 | + */ |
|
98 | + public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
|
99 | + { |
|
100 | + $answer_obj = $this->get_one(array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
101 | + return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Gets the string answer to the question for this registration's attendee |
|
108 | - * @param EE_Registration $registration |
|
109 | - * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string then it should be its QST_system value. |
|
110 | - * Passing in the QST_system value is more efficient |
|
111 | - * @param boolean $pretty_answer |
|
112 | - * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for |
|
113 | - * a question corresponding to an attendee field, returns null) |
|
114 | - */ |
|
115 | - public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
116 | - { |
|
117 | - $field_name = null; |
|
118 | - $value = null; |
|
119 | - // backward compat: we still want to find the question's ID |
|
120 | - if (is_numeric($question_system_id)) { |
|
121 | - // find this question's QST_system value |
|
122 | - $question_id = $question_system_id; |
|
123 | - $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
124 | - } else { |
|
125 | - $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
126 | - } |
|
127 | - // only bother checking if the registration has an attendee |
|
128 | - if ($registration->attendee() instanceof EE_Attendee) { |
|
129 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
130 | - if ($field_name) { |
|
131 | - if ($pretty_answer) { |
|
132 | - if ($field_name === 'STA_ID') { |
|
133 | - $state = $registration->attendee()->state_obj(); |
|
134 | - $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
135 | - } elseif ($field_name === 'CNT_ISO') { |
|
136 | - $country = $registration->attendee()->country_obj(); |
|
137 | - $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
138 | - } else { |
|
139 | - $value = $registration->attendee()->get_pretty($field_name); |
|
140 | - } |
|
141 | - // if field name is blank, leave the value as null too |
|
142 | - } else { |
|
143 | - $value = $registration->attendee()->get($field_name); |
|
144 | - } |
|
145 | - } |
|
146 | - // if no field was found, leave value blank |
|
147 | - } |
|
148 | - return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
149 | - } |
|
106 | + /** |
|
107 | + * Gets the string answer to the question for this registration's attendee |
|
108 | + * @param EE_Registration $registration |
|
109 | + * @param int|string $question_system_id if an INT this is understood to be the question's ID; if a string then it should be its QST_system value. |
|
110 | + * Passing in the QST_system value is more efficient |
|
111 | + * @param boolean $pretty_answer |
|
112 | + * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for |
|
113 | + * a question corresponding to an attendee field, returns null) |
|
114 | + */ |
|
115 | + public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = null, $pretty_answer = false) |
|
116 | + { |
|
117 | + $field_name = null; |
|
118 | + $value = null; |
|
119 | + // backward compat: we still want to find the question's ID |
|
120 | + if (is_numeric($question_system_id)) { |
|
121 | + // find this question's QST_system value |
|
122 | + $question_id = $question_system_id; |
|
123 | + $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
124 | + } else { |
|
125 | + $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
126 | + } |
|
127 | + // only bother checking if the registration has an attendee |
|
128 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
129 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); |
|
130 | + if ($field_name) { |
|
131 | + if ($pretty_answer) { |
|
132 | + if ($field_name === 'STA_ID') { |
|
133 | + $state = $registration->attendee()->state_obj(); |
|
134 | + $value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); |
|
135 | + } elseif ($field_name === 'CNT_ISO') { |
|
136 | + $country = $registration->attendee()->country_obj(); |
|
137 | + $value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); |
|
138 | + } else { |
|
139 | + $value = $registration->attendee()->get_pretty($field_name); |
|
140 | + } |
|
141 | + // if field name is blank, leave the value as null too |
|
142 | + } else { |
|
143 | + $value = $registration->attendee()->get($field_name); |
|
144 | + } |
|
145 | + } |
|
146 | + // if no field was found, leave value blank |
|
147 | + } |
|
148 | + return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); |
|
149 | + } |
|
150 | 150 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null) |
99 | 99 | { |
100 | - $answer_obj = $this->get_one(array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); |
|
100 | + $answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID()))); |
|
101 | 101 | return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); |
102 | 102 | } |
103 | 103 | |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | if (is_numeric($question_system_id)) { |
121 | 121 | // find this question's QST_system value |
122 | 122 | $question_id = $question_system_id; |
123 | - $question_system_id = EEM_Question::instance()->get_var(array( array( 'QST_ID' => $question_system_id ) ), 'QST_system'); |
|
123 | + $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); |
|
124 | 124 | } else { |
125 | - $question_id = (int) EEM_Question::instance()->get_var(array( array( 'QST_system' => $question_system_id ) ), 'QST_ID'); |
|
125 | + $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'); |
|
126 | 126 | } |
127 | 127 | // only bother checking if the registration has an attendee |
128 | 128 | if ($registration->attendee() instanceof EE_Attendee) { |
@@ -13,45 +13,45 @@ |
||
13 | 13 | */ |
14 | 14 | class EEM_Message_Template extends EEM_Base |
15 | 15 | { |
16 | - // private instance of the EEM_Message_Template object |
|
17 | - protected static $_instance = null; |
|
16 | + // private instance of the EEM_Message_Template object |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * private constructor to prevent direct creation |
|
23 | - * |
|
24 | - * @Constructor |
|
25 | - * @access protected |
|
26 | - * @param string $timezone |
|
27 | - * @throws \EE_Error |
|
28 | - */ |
|
29 | - protected function __construct($timezone = null) |
|
30 | - { |
|
31 | - $this->singular_item = __('Message Template', 'event_espresso'); |
|
32 | - $this->plural_item = __('Message Templates', 'event_espresso'); |
|
21 | + /** |
|
22 | + * private constructor to prevent direct creation |
|
23 | + * |
|
24 | + * @Constructor |
|
25 | + * @access protected |
|
26 | + * @param string $timezone |
|
27 | + * @throws \EE_Error |
|
28 | + */ |
|
29 | + protected function __construct($timezone = null) |
|
30 | + { |
|
31 | + $this->singular_item = __('Message Template', 'event_espresso'); |
|
32 | + $this->plural_item = __('Message Templates', 'event_espresso'); |
|
33 | 33 | |
34 | - $this->_tables = array( |
|
35 | - 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
36 | - ); |
|
37 | - $this->_fields = array( |
|
38 | - 'Message_Template'=> array( |
|
39 | - 'MTP_ID'=> new EE_Primary_Key_Int_Field('MTP_ID', __('Message Template ID', 'event_espresso')), |
|
40 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
41 | - 'MTP_template_field'=>new EE_Plain_Text_Field('MTP_template_field', __('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
42 | - 'MTP_context'=>new EE_Plain_Text_Field('MTP_context', __('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
43 | - 'MTP_content'=>new EE_Serialized_Text_Field('MTP_content', __('The field content for the template', 'event_espresso'), false, ''), |
|
44 | - ) |
|
45 | - ); |
|
34 | + $this->_tables = array( |
|
35 | + 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
36 | + ); |
|
37 | + $this->_fields = array( |
|
38 | + 'Message_Template'=> array( |
|
39 | + 'MTP_ID'=> new EE_Primary_Key_Int_Field('MTP_ID', __('Message Template ID', 'event_espresso')), |
|
40 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', __('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
41 | + 'MTP_template_field'=>new EE_Plain_Text_Field('MTP_template_field', __('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
42 | + 'MTP_context'=>new EE_Plain_Text_Field('MTP_context', __('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
43 | + 'MTP_content'=>new EE_Serialized_Text_Field('MTP_content', __('The field content for the template', 'event_espresso'), false, ''), |
|
44 | + ) |
|
45 | + ); |
|
46 | 46 | |
47 | - $this->_model_relations = array( |
|
48 | - 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
49 | - ); |
|
50 | - $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
51 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
52 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
53 | - } |
|
54 | - $this->_caps_slug = 'messages'; |
|
55 | - parent::__construct($timezone); |
|
56 | - } |
|
47 | + $this->_model_relations = array( |
|
48 | + 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
49 | + ); |
|
50 | + $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
51 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
52 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
53 | + } |
|
54 | + $this->_caps_slug = 'messages'; |
|
55 | + parent::__construct($timezone); |
|
56 | + } |
|
57 | 57 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | ); |
50 | 50 | $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
51 | 51 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
52 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
52 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
53 | 53 | } |
54 | 54 | $this->_caps_slug = 'messages'; |
55 | 55 | parent::__construct($timezone); |
@@ -11,232 +11,232 @@ |
||
11 | 11 | class EEM_Payment extends EEM_Base implements EEMI_Payment |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the Payment object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the Payment object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | 19 | /** |
20 | - * Status id in esp_status table that represents an approved payment |
|
21 | - */ |
|
22 | - const status_id_approved = 'PAP'; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Status id in esp_status table that represents a pending payment |
|
27 | - */ |
|
28 | - const status_id_pending = 'PPN'; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Status id in esp_status table that represents a cancelled payment (eg, the |
|
33 | - * user went to PayPal, but on the paypal site decided to cancel the payment) |
|
34 | - */ |
|
35 | - const status_id_cancelled = 'PCN'; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Status id in esp_status table that represents a payment that was declined by |
|
41 | - * the gateway. (eg, the user's card had no funds, or it was a fraudulent card) |
|
42 | - */ |
|
43 | - const status_id_declined = 'PDC'; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Status id in esp_status table that represents a payment that failed for technical reasons. |
|
49 | - * (Eg, there was some error in communicating with the payment gateway.) |
|
50 | - */ |
|
51 | - const status_id_failed = 'PFL'; |
|
52 | - |
|
53 | - /** |
|
54 | - * private constructor to prevent direct creation |
|
55 | - * @Constructor |
|
56 | - * @access protected |
|
57 | - * @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) |
|
58 | - * @return EEM_Payment |
|
59 | - */ |
|
60 | - protected function __construct($timezone) |
|
61 | - { |
|
62 | - |
|
63 | - $this->singular_item = __('Payment', 'event_espresso'); |
|
64 | - $this->plural_item = __('Payments', 'event_espresso'); |
|
65 | - |
|
66 | - $this->_tables = array( |
|
67 | - 'Payment'=>new EE_Primary_Table('esp_payment', 'PAY_ID') |
|
68 | - ); |
|
69 | - $this->_fields = array( |
|
70 | - 'Payment'=>array( |
|
71 | - 'PAY_ID'=>new EE_Primary_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso')), |
|
72 | - 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
73 | - 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'), |
|
74 | - 'PAY_timestamp'=> new EE_Datetime_Field('PAY_timestamp', __('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
75 | - 'PAY_source'=>new EE_All_Caps_Text_Field('PAY_source', __('User-friendly description of payment', 'event_espresso'), false, 'CART'), |
|
76 | - 'PAY_amount'=>new EE_Money_Field('PAY_amount', __('Amount Payment should be for', 'event_espresso'), false, 0), |
|
77 | - 'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'), |
|
78 | - 'PAY_gateway_response'=>new EE_Plain_Text_Field('PAY_gateway_response', __('Response from Gateway about the payment', 'event_espresso'), false, ''), |
|
79 | - 'PAY_txn_id_chq_nmbr'=>new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', __('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''), |
|
80 | - 'PAY_po_number'=>new EE_Plain_Text_Field('PAY_po_number', __('Purchase or Sales Number', 'event_espresso'), true, ''), |
|
81 | - 'PAY_extra_accntng'=>new EE_Simple_HTML_Field('PAY_extra_accntng', __('Extra Account Info', 'event_espresso'), true, ''), |
|
82 | - 'PAY_details'=>new EE_Serialized_Text_Field('PAY_details', __('Full Gateway response about payment', 'event_espresso'), true, ''), |
|
83 | - 'PAY_redirect_url'=>new EE_Plain_Text_Field('PAY_redirect_url', __("Redirect URL", 'event_espresso'), true), |
|
84 | - 'PAY_redirect_args'=>new EE_Serialized_Text_Field('PAY_redirect_args', __("Key-Value POST vars to send along with redirect", 'event_espresso'), true) |
|
85 | - ) |
|
86 | - ); |
|
87 | - $this->_model_relations = array( |
|
88 | - 'Transaction'=> new EE_Belongs_To_Relation(), |
|
89 | - 'Status'=> new EE_Belongs_To_Relation(), |
|
90 | - 'Payment_Method'=>new EE_Belongs_To_Relation(), |
|
91 | - 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
92 | - 'Registration' => new EE_HABTM_Relation('Registration_Payment'), |
|
93 | - ); |
|
94 | - $this->_model_chain_to_wp_user = 'Payment_Method'; |
|
95 | - $this->_caps_slug = 'transactions'; |
|
96 | - parent::__construct($timezone); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned |
|
104 | - * to the payment. This is handy for verifying an IPN hasn't already been processed. |
|
105 | - * @param string $PAY_txn_id_chq_nmbr |
|
106 | - * @return EE_Payment |
|
107 | - */ |
|
108 | - public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr) |
|
109 | - { |
|
110 | - return $this->get_one(array(array('PAY_txn_id_chq_nmbr'=>$PAY_txn_id_chq_nmbr))); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * retrieve all payments from db for a particular transaction, optionally with |
|
118 | - * a particular status |
|
119 | - * |
|
120 | - * @access public |
|
121 | - * @param $TXN_ID |
|
122 | - * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status |
|
123 | - * @return EE_Payment[] |
|
124 | - */ |
|
125 | - public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
|
126 | - { |
|
127 | - // all payments for a TXN ordered chronologically |
|
128 | - $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
129 | - // if provided with a status, search specifically for that status. Otherwise get them all |
|
130 | - if ($status_of_payment) { |
|
131 | - $query_params[0]['STS_ID'] = $status_of_payment; |
|
132 | - } |
|
133 | - // retrieve payments |
|
134 | - return $this->get_all($query_params); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Only gets payments which have been approved |
|
141 | - * @param int $TXN_ID |
|
142 | - * @return EE_Payment[] |
|
143 | - */ |
|
144 | - public function get_approved_payments_for_transaction($TXN_ID = 0) |
|
145 | - { |
|
146 | - return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * retrieve all payments from db between two dates, |
|
155 | - * |
|
156 | - * @param string $start_date incoming start date. If empty the beginning of today is used. |
|
157 | - * @param string $end_date incoming end date. If empty the end of today is used. |
|
158 | - * @param string $format If you include $start_date or $end_date then you must include the format string |
|
159 | - * for the format your date is in. |
|
160 | - * @param string $timezone If your range is in a different timezone then the current setting on this |
|
161 | - * WordPress install, then include it here. |
|
162 | - * @throws EE_Error |
|
163 | - * |
|
164 | - * @return EE_Payment[] |
|
165 | - */ |
|
166 | - public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '') |
|
167 | - { |
|
168 | - $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
169 | - // if $start_date or $end date, verify $format is included. |
|
170 | - if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
171 | - throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
|
172 | - } |
|
173 | - $now = new DateTime('now'); |
|
174 | - // setup timezone objects once |
|
175 | - $modelDateTimeZone = new DateTimeZone($this->_timezone); |
|
176 | - $passedDateTimeZone = new DateTimeZone($timezone); |
|
177 | - // setup start date |
|
178 | - $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
|
179 | - EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
|
180 | - $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
181 | - $start_date = strtotime($start_date); |
|
182 | - // setup end date |
|
183 | - $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
|
184 | - EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
|
185 | - $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
186 | - $end_date = strtotime($end_date); |
|
187 | - |
|
188 | - // make sure our start date is the lowest value and vice versa |
|
189 | - $start = min($start_date, $end_date); |
|
190 | - $end = max($start_date, $end_date); |
|
191 | - |
|
192 | - // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
|
193 | - $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
194 | - $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | - |
|
196 | - return $this->get_all(array(array('PAY_timestamp'=>array('>=',$start_date),'PAY_timestamp*'=>array('<=',$end_date)))); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * methods for EEMI_Payment |
|
201 | - */ |
|
202 | - /** |
|
203 | - * returns a string for the approved status |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function approved_status() |
|
207 | - { |
|
208 | - return self::status_id_approved; |
|
209 | - } |
|
210 | - /** |
|
211 | - * returns a string for the pending status |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function pending_status() |
|
215 | - { |
|
216 | - return self::status_id_pending; |
|
217 | - } |
|
218 | - /** |
|
219 | - * returns a string for the cancelled status |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function cancelled_status() |
|
223 | - { |
|
224 | - return self::status_id_cancelled; |
|
225 | - } |
|
226 | - /** |
|
227 | - * returns a string for the failed status |
|
228 | - * @return string |
|
229 | - */ |
|
230 | - public function failed_status() |
|
231 | - { |
|
232 | - return self::status_id_failed; |
|
233 | - } |
|
234 | - /** |
|
235 | - * returns a string for the declined status |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public function declined_status() |
|
239 | - { |
|
240 | - return self::status_id_declined; |
|
241 | - } |
|
20 | + * Status id in esp_status table that represents an approved payment |
|
21 | + */ |
|
22 | + const status_id_approved = 'PAP'; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Status id in esp_status table that represents a pending payment |
|
27 | + */ |
|
28 | + const status_id_pending = 'PPN'; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Status id in esp_status table that represents a cancelled payment (eg, the |
|
33 | + * user went to PayPal, but on the paypal site decided to cancel the payment) |
|
34 | + */ |
|
35 | + const status_id_cancelled = 'PCN'; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Status id in esp_status table that represents a payment that was declined by |
|
41 | + * the gateway. (eg, the user's card had no funds, or it was a fraudulent card) |
|
42 | + */ |
|
43 | + const status_id_declined = 'PDC'; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Status id in esp_status table that represents a payment that failed for technical reasons. |
|
49 | + * (Eg, there was some error in communicating with the payment gateway.) |
|
50 | + */ |
|
51 | + const status_id_failed = 'PFL'; |
|
52 | + |
|
53 | + /** |
|
54 | + * private constructor to prevent direct creation |
|
55 | + * @Constructor |
|
56 | + * @access protected |
|
57 | + * @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) |
|
58 | + * @return EEM_Payment |
|
59 | + */ |
|
60 | + protected function __construct($timezone) |
|
61 | + { |
|
62 | + |
|
63 | + $this->singular_item = __('Payment', 'event_espresso'); |
|
64 | + $this->plural_item = __('Payments', 'event_espresso'); |
|
65 | + |
|
66 | + $this->_tables = array( |
|
67 | + 'Payment'=>new EE_Primary_Table('esp_payment', 'PAY_ID') |
|
68 | + ); |
|
69 | + $this->_fields = array( |
|
70 | + 'Payment'=>array( |
|
71 | + 'PAY_ID'=>new EE_Primary_Key_Int_Field('PAY_ID', __('Payment ID', 'event_espresso')), |
|
72 | + 'TXN_ID'=>new EE_Foreign_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso'), false, 0, 'Transaction'), |
|
73 | + 'STS_ID'=>new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), false, EEM_Payment::status_id_failed, 'Status'), |
|
74 | + 'PAY_timestamp'=> new EE_Datetime_Field('PAY_timestamp', __('Timestamp of when payment was attempted', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
75 | + 'PAY_source'=>new EE_All_Caps_Text_Field('PAY_source', __('User-friendly description of payment', 'event_espresso'), false, 'CART'), |
|
76 | + 'PAY_amount'=>new EE_Money_Field('PAY_amount', __('Amount Payment should be for', 'event_espresso'), false, 0), |
|
77 | + 'PMD_ID'=>new EE_Foreign_Key_Int_Field('PMD_ID', __("Payment Method ID", 'event_espresso'), false, null, 'Payment_Method'), |
|
78 | + 'PAY_gateway_response'=>new EE_Plain_Text_Field('PAY_gateway_response', __('Response from Gateway about the payment', 'event_espresso'), false, ''), |
|
79 | + 'PAY_txn_id_chq_nmbr'=>new EE_Plain_Text_Field('PAY_txn_id_chq_nmbr', __('Gateway Transaction ID or Cheque Number', 'event_espresso'), true, ''), |
|
80 | + 'PAY_po_number'=>new EE_Plain_Text_Field('PAY_po_number', __('Purchase or Sales Number', 'event_espresso'), true, ''), |
|
81 | + 'PAY_extra_accntng'=>new EE_Simple_HTML_Field('PAY_extra_accntng', __('Extra Account Info', 'event_espresso'), true, ''), |
|
82 | + 'PAY_details'=>new EE_Serialized_Text_Field('PAY_details', __('Full Gateway response about payment', 'event_espresso'), true, ''), |
|
83 | + 'PAY_redirect_url'=>new EE_Plain_Text_Field('PAY_redirect_url', __("Redirect URL", 'event_espresso'), true), |
|
84 | + 'PAY_redirect_args'=>new EE_Serialized_Text_Field('PAY_redirect_args', __("Key-Value POST vars to send along with redirect", 'event_espresso'), true) |
|
85 | + ) |
|
86 | + ); |
|
87 | + $this->_model_relations = array( |
|
88 | + 'Transaction'=> new EE_Belongs_To_Relation(), |
|
89 | + 'Status'=> new EE_Belongs_To_Relation(), |
|
90 | + 'Payment_Method'=>new EE_Belongs_To_Relation(), |
|
91 | + 'Registration_Payment' => new EE_Has_Many_Relation(), |
|
92 | + 'Registration' => new EE_HABTM_Relation('Registration_Payment'), |
|
93 | + ); |
|
94 | + $this->_model_chain_to_wp_user = 'Payment_Method'; |
|
95 | + $this->_caps_slug = 'transactions'; |
|
96 | + parent::__construct($timezone); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Gets the payment by the gateway server's unique ID. Eg, the unique ID PayPal assigned |
|
104 | + * to the payment. This is handy for verifying an IPN hasn't already been processed. |
|
105 | + * @param string $PAY_txn_id_chq_nmbr |
|
106 | + * @return EE_Payment |
|
107 | + */ |
|
108 | + public function get_payment_by_txn_id_chq_nmbr($PAY_txn_id_chq_nmbr) |
|
109 | + { |
|
110 | + return $this->get_one(array(array('PAY_txn_id_chq_nmbr'=>$PAY_txn_id_chq_nmbr))); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * retrieve all payments from db for a particular transaction, optionally with |
|
118 | + * a particular status |
|
119 | + * |
|
120 | + * @access public |
|
121 | + * @param $TXN_ID |
|
122 | + * @param string $status_of_payment one of EEM_Payment::status_id_*, like 'PAP','PCN',etc. If none is provided, gets payments with any status |
|
123 | + * @return EE_Payment[] |
|
124 | + */ |
|
125 | + public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
|
126 | + { |
|
127 | + // all payments for a TXN ordered chronologically |
|
128 | + $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
129 | + // if provided with a status, search specifically for that status. Otherwise get them all |
|
130 | + if ($status_of_payment) { |
|
131 | + $query_params[0]['STS_ID'] = $status_of_payment; |
|
132 | + } |
|
133 | + // retrieve payments |
|
134 | + return $this->get_all($query_params); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Only gets payments which have been approved |
|
141 | + * @param int $TXN_ID |
|
142 | + * @return EE_Payment[] |
|
143 | + */ |
|
144 | + public function get_approved_payments_for_transaction($TXN_ID = 0) |
|
145 | + { |
|
146 | + return $this->get_payments_for_transaction($TXN_ID, EEM_Payment::status_id_approved); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * retrieve all payments from db between two dates, |
|
155 | + * |
|
156 | + * @param string $start_date incoming start date. If empty the beginning of today is used. |
|
157 | + * @param string $end_date incoming end date. If empty the end of today is used. |
|
158 | + * @param string $format If you include $start_date or $end_date then you must include the format string |
|
159 | + * for the format your date is in. |
|
160 | + * @param string $timezone If your range is in a different timezone then the current setting on this |
|
161 | + * WordPress install, then include it here. |
|
162 | + * @throws EE_Error |
|
163 | + * |
|
164 | + * @return EE_Payment[] |
|
165 | + */ |
|
166 | + public function get_payments_made_between_dates($start_date = '', $end_date = '', $format = '', $timezone = '') |
|
167 | + { |
|
168 | + $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
|
169 | + // if $start_date or $end date, verify $format is included. |
|
170 | + if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
171 | + throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
|
172 | + } |
|
173 | + $now = new DateTime('now'); |
|
174 | + // setup timezone objects once |
|
175 | + $modelDateTimeZone = new DateTimeZone($this->_timezone); |
|
176 | + $passedDateTimeZone = new DateTimeZone($timezone); |
|
177 | + // setup start date |
|
178 | + $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
|
179 | + EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
|
180 | + $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
181 | + $start_date = strtotime($start_date); |
|
182 | + // setup end date |
|
183 | + $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
|
184 | + EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
|
185 | + $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
186 | + $end_date = strtotime($end_date); |
|
187 | + |
|
188 | + // make sure our start date is the lowest value and vice versa |
|
189 | + $start = min($start_date, $end_date); |
|
190 | + $end = max($start_date, $end_date); |
|
191 | + |
|
192 | + // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
|
193 | + $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
194 | + $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | + |
|
196 | + return $this->get_all(array(array('PAY_timestamp'=>array('>=',$start_date),'PAY_timestamp*'=>array('<=',$end_date)))); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * methods for EEMI_Payment |
|
201 | + */ |
|
202 | + /** |
|
203 | + * returns a string for the approved status |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function approved_status() |
|
207 | + { |
|
208 | + return self::status_id_approved; |
|
209 | + } |
|
210 | + /** |
|
211 | + * returns a string for the pending status |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function pending_status() |
|
215 | + { |
|
216 | + return self::status_id_pending; |
|
217 | + } |
|
218 | + /** |
|
219 | + * returns a string for the cancelled status |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function cancelled_status() |
|
223 | + { |
|
224 | + return self::status_id_cancelled; |
|
225 | + } |
|
226 | + /** |
|
227 | + * returns a string for the failed status |
|
228 | + * @return string |
|
229 | + */ |
|
230 | + public function failed_status() |
|
231 | + { |
|
232 | + return self::status_id_failed; |
|
233 | + } |
|
234 | + /** |
|
235 | + * returns a string for the declined status |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public function declined_status() |
|
239 | + { |
|
240 | + return self::status_id_declined; |
|
241 | + } |
|
242 | 242 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | public function get_payments_for_transaction($TXN_ID = false, $status_of_payment = null) |
126 | 126 | { |
127 | 127 | // all payments for a TXN ordered chronologically |
128 | - $query_params = array( array( 'TXN_ID' => $TXN_ID ), 'order_by' => array( 'PAY_timestamp' => 'ASC' )); |
|
128 | + $query_params = array(array('TXN_ID' => $TXN_ID), 'order_by' => array('PAY_timestamp' => 'ASC')); |
|
129 | 129 | // if provided with a status, search specifically for that status. Otherwise get them all |
130 | 130 | if ($status_of_payment) { |
131 | 131 | $query_params[0]['STS_ID'] = $status_of_payment; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | $timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone; |
169 | 169 | // if $start_date or $end date, verify $format is included. |
170 | - if (( ! empty($start_date) || ! empty($end_date) ) && empty($format)) { |
|
170 | + if (( ! empty($start_date) || ! empty($end_date)) && empty($format)) { |
|
171 | 171 | throw new EE_Error(__('You included a start date and/or a end date for this method but did not include a format string. The format string is needed for setting up the query', 'event_espresso')); |
172 | 172 | } |
173 | 173 | $now = new DateTime('now'); |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | // setup start date |
178 | 178 | $start_date = ! empty($start_date) ? date_create_from_format($format, $start_date, $passedDateTimeZone) : $now; |
179 | 179 | EEH_DTT_Helper::setTimezone($start_date, $modelDateTimeZone); |
180 | - $start_date = $start_date->format('Y-m-d') . ' 00:00:00'; |
|
180 | + $start_date = $start_date->format('Y-m-d').' 00:00:00'; |
|
181 | 181 | $start_date = strtotime($start_date); |
182 | 182 | // setup end date |
183 | 183 | $end_date = ! empty($end_date) ? date_create_from_format($format, $end_date, $passedDateTimeZone) : $now; |
184 | 184 | EEH_DTT_Helper::setTimezone($end_date, $modelDateTimeZone); |
185 | - $end_date = $end_date->format('Y-m-d') . ' 23:59:59'; |
|
185 | + $end_date = $end_date->format('Y-m-d').' 23:59:59'; |
|
186 | 186 | $end_date = strtotime($end_date); |
187 | 187 | |
188 | 188 | // make sure our start date is the lowest value and vice versa |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | $end = max($start_date, $end_date); |
191 | 191 | |
192 | 192 | // yes we generated the date and time string in utc but we WANT this start date and time used in the set timezone on the model. |
193 | - $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start) . ' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
194 | - $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end) . ' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
193 | + $start_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $start).' 00:00:00', 'Y-m-d H:i:s', $this->get_timezone()); |
|
194 | + $end_date = $this->convert_datetime_for_query('PAY_timestamp', date('Y-m-d', $end).' 23:59:59', 'Y-m-d H:i:s', $this->get_timezone()); |
|
195 | 195 | |
196 | - return $this->get_all(array(array('PAY_timestamp'=>array('>=',$start_date),'PAY_timestamp*'=>array('<=',$end_date)))); |
|
196 | + return $this->get_all(array(array('PAY_timestamp'=>array('>=', $start_date), 'PAY_timestamp*'=>array('<=', $end_date)))); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -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 | } |