@@ -16,220 +16,220 @@ |
||
16 | 16 | class Prices_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - private $_PRT; |
|
20 | - |
|
21 | - /** |
|
22 | - * Array of price types. |
|
23 | - * |
|
24 | - * @var EE_Price_Type[] |
|
25 | - */ |
|
26 | - protected $_price_types = array(); |
|
27 | - |
|
28 | - public function __construct($admin_page) |
|
29 | - { |
|
30 | - parent::__construct($admin_page); |
|
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | - $this->_PRT = EEM_Price_Type::instance(); |
|
33 | - $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - protected function _setup_data() |
|
38 | - { |
|
39 | - $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | - $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | - $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | - $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - protected function _set_properties() |
|
47 | - { |
|
48 | - $this->_wp_list_args = array( |
|
49 | - 'singular' => __('price', 'event_espresso'), |
|
50 | - 'plural' => __('prices', 'event_espresso'), |
|
51 | - 'ajax' => true, |
|
52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | - ); |
|
54 | - |
|
55 | - $this->_columns = array( |
|
56 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | - 'name' => __('Name', 'event_espresso'), |
|
58 | - 'type' => __('Price Type', 'event_espresso'), |
|
59 | - 'description' => __('Description', 'event_espresso'), |
|
60 | - 'amount' => __('Amount', 'event_espresso'), |
|
61 | - ); |
|
62 | - |
|
63 | - $this->_sortable_columns = array( |
|
64 | - // true means its already sorted |
|
65 | - 'name' => array('name' => false), |
|
66 | - 'type' => array('type' => false), |
|
67 | - 'amount' => array('amount' => false), |
|
68 | - ); |
|
69 | - |
|
70 | - $this->_hidden_columns = array(); |
|
71 | - |
|
72 | - $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - protected function _get_table_filters() |
|
77 | - { |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - protected function _add_view_counts() |
|
82 | - { |
|
83 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | - * |
|
93 | - * @param object $item the current item |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function _get_row_class($item) |
|
97 | - { |
|
98 | - static $row_class = ''; |
|
99 | - $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | - |
|
101 | - $new_row = $row_class; |
|
102 | - |
|
103 | - if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | - $new_row .= ' rowsortable'; |
|
105 | - } |
|
106 | - |
|
107 | - return ' class="' . $new_row . '"'; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - public function column_cb($item) |
|
112 | - { |
|
113 | - if ($item->type_obj()->base_type() !== 1) { |
|
114 | - return sprintf( |
|
115 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | - $item->ID() |
|
117 | - ); |
|
118 | - } |
|
119 | - return ''; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - public function column_name($item) |
|
124 | - { |
|
125 | - |
|
126 | - // Build row actions |
|
127 | - $actions = array(); |
|
128 | - // edit price link |
|
129 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | - 'ee_edit_default_price', |
|
131 | - 'pricing_edit_price', |
|
132 | - $item->ID() |
|
133 | - )) { |
|
134 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | - 'action' => 'edit_price', |
|
136 | - 'id' => $item->ID(), |
|
137 | - ), PRICING_ADMIN_URL); |
|
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
141 | - } |
|
142 | - |
|
143 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | - 'ee_edit_default_price', |
|
145 | - 'edit_price', |
|
146 | - $item->ID() |
|
147 | - ) |
|
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
151 | - : $item->name(); |
|
152 | - |
|
153 | - if ($item->type_obj()->base_type() !== 1) { |
|
154 | - if ($this->_view == 'all') { |
|
155 | - // trash price link |
|
156 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | - 'ee_delete_default_price', |
|
158 | - 'pricing_trash_price', |
|
159 | - $item->ID() |
|
160 | - )) { |
|
161 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | - 'action' => 'trash_price', |
|
163 | - 'id' => $item->ID(), |
|
164 | - 'noheader' => true, |
|
165 | - ), PRICING_ADMIN_URL); |
|
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | - } |
|
170 | - } else { |
|
171 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | - 'ee_delete_default_price', |
|
173 | - 'pricing_restore_price', |
|
174 | - $item->ID() |
|
175 | - )) { |
|
176 | - // restore price link |
|
177 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | - 'action' => 'restore_price', |
|
179 | - 'id' => $item->ID(), |
|
180 | - 'noheader' => true, |
|
181 | - ), PRICING_ADMIN_URL); |
|
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
185 | - } |
|
186 | - |
|
187 | - // delete price link |
|
188 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | - 'ee_delete_default_price', |
|
190 | - 'pricing_delete_price', |
|
191 | - $item->ID() |
|
192 | - )) { |
|
193 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | - 'action' => 'delete_price', |
|
195 | - 'id' => $item->ID(), |
|
196 | - 'noheader' => true, |
|
197 | - ), PRICING_ADMIN_URL); |
|
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - // Return the name contents |
|
206 | - return sprintf( |
|
207 | - '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | - $name_link, |
|
209 | - $item->ID(), |
|
210 | - $this->row_actions($actions) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - public function column_type($item) |
|
216 | - { |
|
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - public function column_description($item) |
|
222 | - { |
|
223 | - return stripslashes($item->desc()); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - public function column_amount($item) |
|
228 | - { |
|
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | - } else { |
|
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | - } |
|
234 | - } |
|
19 | + private $_PRT; |
|
20 | + |
|
21 | + /** |
|
22 | + * Array of price types. |
|
23 | + * |
|
24 | + * @var EE_Price_Type[] |
|
25 | + */ |
|
26 | + protected $_price_types = array(); |
|
27 | + |
|
28 | + public function __construct($admin_page) |
|
29 | + { |
|
30 | + parent::__construct($admin_page); |
|
31 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | + $this->_PRT = EEM_Price_Type::instance(); |
|
33 | + $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + protected function _setup_data() |
|
38 | + { |
|
39 | + $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | + $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | + $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | + $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + protected function _set_properties() |
|
47 | + { |
|
48 | + $this->_wp_list_args = array( |
|
49 | + 'singular' => __('price', 'event_espresso'), |
|
50 | + 'plural' => __('prices', 'event_espresso'), |
|
51 | + 'ajax' => true, |
|
52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | + ); |
|
54 | + |
|
55 | + $this->_columns = array( |
|
56 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | + 'name' => __('Name', 'event_espresso'), |
|
58 | + 'type' => __('Price Type', 'event_espresso'), |
|
59 | + 'description' => __('Description', 'event_espresso'), |
|
60 | + 'amount' => __('Amount', 'event_espresso'), |
|
61 | + ); |
|
62 | + |
|
63 | + $this->_sortable_columns = array( |
|
64 | + // true means its already sorted |
|
65 | + 'name' => array('name' => false), |
|
66 | + 'type' => array('type' => false), |
|
67 | + 'amount' => array('amount' => false), |
|
68 | + ); |
|
69 | + |
|
70 | + $this->_hidden_columns = array(); |
|
71 | + |
|
72 | + $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + protected function _get_table_filters() |
|
77 | + { |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + protected function _add_view_counts() |
|
82 | + { |
|
83 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | + * |
|
93 | + * @param object $item the current item |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function _get_row_class($item) |
|
97 | + { |
|
98 | + static $row_class = ''; |
|
99 | + $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | + |
|
101 | + $new_row = $row_class; |
|
102 | + |
|
103 | + if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | + $new_row .= ' rowsortable'; |
|
105 | + } |
|
106 | + |
|
107 | + return ' class="' . $new_row . '"'; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + public function column_cb($item) |
|
112 | + { |
|
113 | + if ($item->type_obj()->base_type() !== 1) { |
|
114 | + return sprintf( |
|
115 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | + $item->ID() |
|
117 | + ); |
|
118 | + } |
|
119 | + return ''; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + public function column_name($item) |
|
124 | + { |
|
125 | + |
|
126 | + // Build row actions |
|
127 | + $actions = array(); |
|
128 | + // edit price link |
|
129 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | + 'ee_edit_default_price', |
|
131 | + 'pricing_edit_price', |
|
132 | + $item->ID() |
|
133 | + )) { |
|
134 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | + 'action' => 'edit_price', |
|
136 | + 'id' => $item->ID(), |
|
137 | + ), PRICING_ADMIN_URL); |
|
138 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | + . __('Edit', 'event_espresso') . '</a>'; |
|
141 | + } |
|
142 | + |
|
143 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | + 'ee_edit_default_price', |
|
145 | + 'edit_price', |
|
146 | + $item->ID() |
|
147 | + ) |
|
148 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | + . stripslashes($item->name()) . '</a>' |
|
151 | + : $item->name(); |
|
152 | + |
|
153 | + if ($item->type_obj()->base_type() !== 1) { |
|
154 | + if ($this->_view == 'all') { |
|
155 | + // trash price link |
|
156 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | + 'ee_delete_default_price', |
|
158 | + 'pricing_trash_price', |
|
159 | + $item->ID() |
|
160 | + )) { |
|
161 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | + 'action' => 'trash_price', |
|
163 | + 'id' => $item->ID(), |
|
164 | + 'noheader' => true, |
|
165 | + ), PRICING_ADMIN_URL); |
|
166 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | + . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | + } |
|
170 | + } else { |
|
171 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | + 'ee_delete_default_price', |
|
173 | + 'pricing_restore_price', |
|
174 | + $item->ID() |
|
175 | + )) { |
|
176 | + // restore price link |
|
177 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | + 'action' => 'restore_price', |
|
179 | + 'id' => $item->ID(), |
|
180 | + 'noheader' => true, |
|
181 | + ), PRICING_ADMIN_URL); |
|
182 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | + . __('Restore', 'event_espresso') . '</a>'; |
|
185 | + } |
|
186 | + |
|
187 | + // delete price link |
|
188 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | + 'ee_delete_default_price', |
|
190 | + 'pricing_delete_price', |
|
191 | + $item->ID() |
|
192 | + )) { |
|
193 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | + 'action' => 'delete_price', |
|
195 | + 'id' => $item->ID(), |
|
196 | + 'noheader' => true, |
|
197 | + ), PRICING_ADMIN_URL); |
|
198 | + $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | + . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + // Return the name contents |
|
206 | + return sprintf( |
|
207 | + '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | + $name_link, |
|
209 | + $item->ID(), |
|
210 | + $this->row_actions($actions) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + public function column_type($item) |
|
216 | + { |
|
217 | + return $this->_price_types[ $item->type() ]->name(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + public function column_description($item) |
|
222 | + { |
|
223 | + return stripslashes($item->desc()); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + public function column_amount($item) |
|
228 | + { |
|
229 | + if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | + } else { |
|
232 | + return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function __construct($admin_page) |
29 | 29 | { |
30 | 30 | parent::__construct($admin_page); |
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
31 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
32 | 32 | $this->_PRT = EEM_Price_Type::instance(); |
33 | 33 | $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
34 | 34 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $new_row .= ' rowsortable'; |
105 | 105 | } |
106 | 106 | |
107 | - return ' class="' . $new_row . '"'; |
|
107 | + return ' class="'.$new_row.'"'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | 'action' => 'edit_price', |
136 | 136 | 'id' => $item->ID(), |
137 | 137 | ), PRICING_ADMIN_URL); |
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
138 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
140 | + . __('Edit', 'event_espresso').'</a>'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | 'edit_price', |
146 | 146 | $item->ID() |
147 | 147 | ) |
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
148 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
150 | + . stripslashes($item->name()).'</a>' |
|
151 | 151 | : $item->name(); |
152 | 152 | |
153 | 153 | if ($item->type_obj()->base_type() !== 1) { |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | 'id' => $item->ID(), |
164 | 164 | 'noheader' => true, |
165 | 165 | ), PRICING_ADMIN_URL); |
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
166 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso').'">' |
|
168 | + . __('Move to Trash', 'event_espresso').'</a>'; |
|
169 | 169 | } |
170 | 170 | } else { |
171 | 171 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'id' => $item->ID(), |
180 | 180 | 'noheader' => true, |
181 | 181 | ), PRICING_ADMIN_URL); |
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
182 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso').'">' |
|
184 | + . __('Restore', 'event_espresso').'</a>'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // delete price link |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | 'id' => $item->ID(), |
196 | 196 | 'noheader' => true, |
197 | 197 | ), PRICING_ADMIN_URL); |
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
198 | + $actions['delete'] = '<a href="'.$delete_lnk_url.'" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso').'">' |
|
200 | + . __('Delete Permanently', 'event_espresso').'</a>'; |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | public function column_type($item) |
216 | 216 | { |
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
217 | + return $this->_price_types[$item->type()]->name(); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | public function column_amount($item) |
228 | 228 | { |
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
229 | + if ($this->_price_types[$item->type()]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">'.number_format($item->amount(), 1).'%</div>'; |
|
231 | 231 | } else { |
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
232 | + return '<div class="pad-amnt-rght">'.EEH_Template::format_currency($item->amount()).'</div>'; |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | } |
@@ -10,138 +10,138 @@ |
||
10 | 10 | class EE_Taxes extends EE_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * This is used for when EE_Taxes is used statically by the admin |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - private static $_subtotal = array(); |
|
13 | + /** |
|
14 | + * This is used for when EE_Taxes is used statically by the admin |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + private static $_subtotal = array(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | - * |
|
23 | - * @var EE_Price[] |
|
24 | - */ |
|
25 | - private static $_default_taxes = array(); |
|
20 | + /** |
|
21 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | + * |
|
23 | + * @var EE_Price[] |
|
24 | + */ |
|
25 | + private static $_default_taxes = array(); |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | - * calc of taxes for tickets listed in the event editor. |
|
32 | - * |
|
33 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | - * @return float total taxes to apply to ticket. |
|
35 | - * @throws \EE_Error |
|
36 | - */ |
|
37 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | - { |
|
39 | - $tax = 0; |
|
40 | - $total_tax = 0; |
|
41 | - // This first checks to see if the given ticket is taxable. |
|
42 | - if (! $ticket->get('TKT_taxable')) { |
|
43 | - return $tax; |
|
44 | - } |
|
45 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | - $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | - // get taxes |
|
48 | - $taxes = self::get_taxes_for_admin(); |
|
49 | - // apply taxes to subtotal |
|
50 | - foreach ($taxes as $tax) { |
|
51 | - // assuming taxes are not cumulative |
|
52 | - $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | - } |
|
54 | - return $total_tax; |
|
55 | - } |
|
28 | + /** |
|
29 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | + * calc of taxes for tickets listed in the event editor. |
|
32 | + * |
|
33 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | + * @return float total taxes to apply to ticket. |
|
35 | + * @throws \EE_Error |
|
36 | + */ |
|
37 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | + { |
|
39 | + $tax = 0; |
|
40 | + $total_tax = 0; |
|
41 | + // This first checks to see if the given ticket is taxable. |
|
42 | + if (! $ticket->get('TKT_taxable')) { |
|
43 | + return $tax; |
|
44 | + } |
|
45 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | + $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | + // get taxes |
|
48 | + $taxes = self::get_taxes_for_admin(); |
|
49 | + // apply taxes to subtotal |
|
50 | + foreach ($taxes as $tax) { |
|
51 | + // assuming taxes are not cumulative |
|
52 | + $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | + } |
|
54 | + return $total_tax; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | - * |
|
61 | - * @return float the percentage of tax that should be added to taxable items |
|
62 | - * @throws \EE_Error |
|
63 | - * eg 20 for %20 tax (NOT 0.20, which |
|
64 | - */ |
|
65 | - public static function get_total_taxes_percentage() |
|
66 | - { |
|
67 | - $total_tax_percent = 0; |
|
68 | - foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | - } |
|
71 | - return $total_tax_percent; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | + * |
|
61 | + * @return float the percentage of tax that should be added to taxable items |
|
62 | + * @throws \EE_Error |
|
63 | + * eg 20 for %20 tax (NOT 0.20, which |
|
64 | + */ |
|
65 | + public static function get_total_taxes_percentage() |
|
66 | + { |
|
67 | + $total_tax_percent = 0; |
|
68 | + foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | + } |
|
71 | + return $total_tax_percent; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param EE_Ticket $ticket |
|
77 | - * @return float |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | - { |
|
82 | - $TKT_ID = $ticket->ID(); |
|
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
85 | - : self::_get_subtotal_for_admin($ticket); |
|
86 | - } |
|
75 | + /** |
|
76 | + * @param EE_Ticket $ticket |
|
77 | + * @return float |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | + { |
|
82 | + $TKT_ID = $ticket->ID(); |
|
83 | + return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | + ? self::$_subtotal[ $TKT_ID ] |
|
85 | + : self::_get_subtotal_for_admin($ticket); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | - * |
|
92 | - * @param EE_Ticket $ticket |
|
93 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | - * @throws \EE_Error |
|
95 | - */ |
|
96 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | - { |
|
98 | - $subtotal = 0; |
|
99 | - // get all prices |
|
100 | - $prices = $ticket->get_many_related( |
|
101 | - 'Price', |
|
102 | - array( |
|
103 | - 'default_where_conditions' => 'none', |
|
104 | - 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | - ) |
|
106 | - ); |
|
107 | - // let's loop through them (base price is always the first item) |
|
108 | - foreach ($prices as $price) { |
|
109 | - if ($price instanceof EE_Price) { |
|
110 | - $price_type = $price->type_obj(); |
|
111 | - if ($price_type instanceof EE_Price_Type) { |
|
112 | - switch ($price->type_obj()->base_type()) { |
|
113 | - case 1: // base price |
|
114 | - case 3: // surcharges |
|
115 | - $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | - : $price->get('PRC_amount'); |
|
117 | - break; |
|
118 | - case 2: // discounts |
|
119 | - $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | - : $price->get('PRC_amount'); |
|
121 | - break; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - $TKT_ID = $ticket->ID(); |
|
127 | - self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | - return $subtotal; |
|
129 | - } |
|
89 | + /** |
|
90 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | + * |
|
92 | + * @param EE_Ticket $ticket |
|
93 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | + * @throws \EE_Error |
|
95 | + */ |
|
96 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | + { |
|
98 | + $subtotal = 0; |
|
99 | + // get all prices |
|
100 | + $prices = $ticket->get_many_related( |
|
101 | + 'Price', |
|
102 | + array( |
|
103 | + 'default_where_conditions' => 'none', |
|
104 | + 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | + ) |
|
106 | + ); |
|
107 | + // let's loop through them (base price is always the first item) |
|
108 | + foreach ($prices as $price) { |
|
109 | + if ($price instanceof EE_Price) { |
|
110 | + $price_type = $price->type_obj(); |
|
111 | + if ($price_type instanceof EE_Price_Type) { |
|
112 | + switch ($price->type_obj()->base_type()) { |
|
113 | + case 1: // base price |
|
114 | + case 3: // surcharges |
|
115 | + $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | + : $price->get('PRC_amount'); |
|
117 | + break; |
|
118 | + case 2: // discounts |
|
119 | + $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | + : $price->get('PRC_amount'); |
|
121 | + break; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + $TKT_ID = $ticket->ID(); |
|
127 | + self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | + return $subtotal; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | - * |
|
135 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | - * @throws \EE_Error |
|
137 | - */ |
|
138 | - public static function get_taxes_for_admin() |
|
139 | - { |
|
140 | - if (empty(self::$_default_taxes)) { |
|
141 | - self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | - array(array('Price_Type.PBT_ID' => 4)) |
|
143 | - ); |
|
144 | - } |
|
145 | - return self::$_default_taxes; |
|
146 | - } |
|
132 | + /** |
|
133 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | + * |
|
135 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | + * @throws \EE_Error |
|
137 | + */ |
|
138 | + public static function get_taxes_for_admin() |
|
139 | + { |
|
140 | + if (empty(self::$_default_taxes)) { |
|
141 | + self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | + array(array('Price_Type.PBT_ID' => 4)) |
|
143 | + ); |
|
144 | + } |
|
145 | + return self::$_default_taxes; |
|
146 | + } |
|
147 | 147 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $tax = 0; |
40 | 40 | $total_tax = 0; |
41 | 41 | // This first checks to see if the given ticket is taxable. |
42 | - if (! $ticket->get('TKT_taxable')) { |
|
42 | + if ( ! $ticket->get('TKT_taxable')) { |
|
43 | 43 | return $tax; |
44 | 44 | } |
45 | 45 | // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
81 | 81 | { |
82 | 82 | $TKT_ID = $ticket->ID(); |
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
83 | + return isset(self::$_subtotal[$TKT_ID]) |
|
84 | + ? self::$_subtotal[$TKT_ID] |
|
85 | 85 | : self::_get_subtotal_for_admin($ticket); |
86 | 86 | } |
87 | 87 |
@@ -11,80 +11,80 @@ |
||
11 | 11 | class EE_Term_Taxonomy extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $props_n_values |
|
16 | - * @return EE_Term_Taxonomy |
|
17 | - */ |
|
18 | - public static function new_instance($props_n_values = array()) |
|
19 | - { |
|
20 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
21 | - return $has_object ? $has_object : new self($props_n_values); |
|
22 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values |
|
16 | + * @return EE_Term_Taxonomy |
|
17 | + */ |
|
18 | + public static function new_instance($props_n_values = array()) |
|
19 | + { |
|
20 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
21 | + return $has_object ? $has_object : new self($props_n_values); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Term_Taxonomy |
|
28 | - */ |
|
29 | - public static function new_instance_from_db($props_n_values = array()) |
|
30 | - { |
|
31 | - return new self($props_n_values, true); |
|
32 | - } |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Term_Taxonomy |
|
28 | + */ |
|
29 | + public static function new_instance_from_db($props_n_values = array()) |
|
30 | + { |
|
31 | + return new self($props_n_values, true); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * Gets taxonomy |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function taxonomy() |
|
41 | - { |
|
42 | - return $this->get('taxonomy'); |
|
43 | - } |
|
35 | + /** |
|
36 | + * Gets taxonomy |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function taxonomy() |
|
41 | + { |
|
42 | + return $this->get('taxonomy'); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Sets taxonomy |
|
48 | - * |
|
49 | - * @param string $taxonomy |
|
50 | - * @return boolean |
|
51 | - */ |
|
52 | - public function set_taxonomy($taxonomy) |
|
53 | - { |
|
54 | - $this->set('taxonomy', $taxonomy); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Sets taxonomy |
|
48 | + * |
|
49 | + * @param string $taxonomy |
|
50 | + * @return boolean |
|
51 | + */ |
|
52 | + public function set_taxonomy($taxonomy) |
|
53 | + { |
|
54 | + $this->set('taxonomy', $taxonomy); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets term_count |
|
60 | - * |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public function count() |
|
64 | - { |
|
65 | - return $this->get('term_count'); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Gets term_count |
|
60 | + * |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public function count() |
|
64 | + { |
|
65 | + return $this->get('term_count'); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Sets term_count |
|
71 | - * |
|
72 | - * @param int $term_count |
|
73 | - * @return boolean |
|
74 | - */ |
|
75 | - public function set_count($term_count) |
|
76 | - { |
|
77 | - $this->set('term_count', $term_count); |
|
78 | - } |
|
69 | + /** |
|
70 | + * Sets term_count |
|
71 | + * |
|
72 | + * @param int $term_count |
|
73 | + * @return boolean |
|
74 | + */ |
|
75 | + public function set_count($term_count) |
|
76 | + { |
|
77 | + $this->set('term_count', $term_count); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Gets the term for this term taxonomy |
|
83 | - * |
|
84 | - * @return EE_Term |
|
85 | - */ |
|
86 | - public function term() |
|
87 | - { |
|
88 | - return $this->get_first_related('Term'); |
|
89 | - } |
|
81 | + /** |
|
82 | + * Gets the term for this term taxonomy |
|
83 | + * |
|
84 | + * @return EE_Term |
|
85 | + */ |
|
86 | + public function term() |
|
87 | + { |
|
88 | + return $this->get_first_related('Term'); |
|
89 | + } |
|
90 | 90 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function set_message_type($message_type = false) |
50 | 50 | { |
51 | - if (! $message_type) { |
|
51 | + if ( ! $message_type) { |
|
52 | 52 | throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
53 | 53 | } |
54 | 54 | $this->set('MTP_message_type', $message_type); |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function set_messenger($messenger = false) |
63 | 63 | { |
64 | - if (! $messenger) { |
|
64 | + if ( ! $messenger) { |
|
65 | 65 | throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
66 | 66 | } |
67 | 67 | $this->set('MTP_messenger', $messenger); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function set_group_template_id($GRP_ID = false) |
76 | 76 | { |
77 | - if (! $GRP_ID) { |
|
77 | + if ( ! $GRP_ID) { |
|
78 | 78 | throw new EE_Error( |
79 | 79 | esc_html__( |
80 | 80 | 'Missing required value for the message template group id', |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } |
291 | 291 | // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
292 | 292 | foreach ($mtps as $mtp) { |
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
293 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
294 | 294 | } |
295 | 295 | return $mtps_arr; |
296 | 296 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | public function deactivate_context($context) |
431 | 431 | { |
432 | 432 | $this->validate_context($context); |
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | public function activate_context($context) |
446 | 446 | { |
447 | 447 | $this->validate_context($context); |
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | { |
466 | 466 | $this->validate_context($context); |
467 | 467 | return filter_var( |
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true), |
|
469 | 469 | FILTER_VALIDATE_BOOLEAN |
470 | 470 | ); |
471 | 471 | } |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | public function validate_context($context) |
482 | 482 | { |
483 | 483 | $contexts = $this->contexts_config(); |
484 | - if (! isset($contexts[ $context ])) { |
|
484 | + if ( ! isset($contexts[$context])) { |
|
485 | 485 | throw new InvalidIdentifierException( |
486 | 486 | '', |
487 | 487 | '', |
@@ -13,487 +13,487 @@ |
||
13 | 13 | class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | - */ |
|
19 | - const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | - |
|
21 | - /** |
|
22 | - * @param array $props_n_values |
|
23 | - * @param string $timezone |
|
24 | - * @return EE_Message_Template_Group|mixed |
|
25 | - * @throws EE_Error |
|
26 | - */ |
|
27 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | - { |
|
29 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @param array $props_n_values |
|
36 | - * @param string $timezone |
|
37 | - * @return EE_Message_Template_Group |
|
38 | - */ |
|
39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | - { |
|
41 | - return new self($props_n_values, true, $timezone); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param bool $message_type |
|
47 | - * @throws EE_Error |
|
48 | - */ |
|
49 | - public function set_message_type($message_type = false) |
|
50 | - { |
|
51 | - if (! $message_type) { |
|
52 | - throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | - } |
|
54 | - $this->set('MTP_message_type', $message_type); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param bool $messenger |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function set_messenger($messenger = false) |
|
63 | - { |
|
64 | - if (! $messenger) { |
|
65 | - throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | - } |
|
67 | - $this->set('MTP_messenger', $messenger); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param bool $GRP_ID |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public function set_group_template_id($GRP_ID = false) |
|
76 | - { |
|
77 | - if (! $GRP_ID) { |
|
78 | - throw new EE_Error( |
|
79 | - esc_html__( |
|
80 | - 'Missing required value for the message template group id', |
|
81 | - 'event_espresso' |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
85 | - $this->set('GRP_ID', $GRP_ID); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * get Group ID |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return int |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public function GRP_ID() |
|
97 | - { |
|
98 | - return $this->get('GRP_ID'); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * get User ID |
|
104 | - * |
|
105 | - * @access public |
|
106 | - * @return int |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - public function user() |
|
110 | - { |
|
111 | - $user_id = $this->get('MTP_user_id'); |
|
112 | - return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Wrapper for the user function() (preserve backward compat) |
|
118 | - * |
|
119 | - * @since 4.5.0 |
|
120 | - * @return int |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - public function wp_user() |
|
124 | - { |
|
125 | - return $this->user(); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * This simply returns a count of all related events to this message template group |
|
131 | - * |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function count_events() |
|
135 | - { |
|
136 | - return $this->count_related('Event'); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * returns the name saved in the db for this template |
|
142 | - * |
|
143 | - * @return string |
|
144 | - * @throws EE_Error |
|
145 | - */ |
|
146 | - public function name() |
|
147 | - { |
|
148 | - return $this->get('MTP_name'); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Returns the description saved in the db for this template group |
|
154 | - * |
|
155 | - * @return string |
|
156 | - * @throws EE_Error |
|
157 | - */ |
|
158 | - public function description() |
|
159 | - { |
|
160 | - return $this->get('MTP_description'); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * returns all related EE_Message_Template objects |
|
166 | - * |
|
167 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
168 | - * @return EE_Message_Template[] |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - public function message_templates($query_params = array()) |
|
172 | - { |
|
173 | - return $this->get_many_related('Message_Template', $query_params); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get Message Messenger |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @return string |
|
182 | - * @throws EE_Error |
|
183 | - */ |
|
184 | - public function messenger() |
|
185 | - { |
|
186 | - return $this->get('MTP_messenger'); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * get Message Messenger OBJECT |
|
192 | - * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | - * appropriately. |
|
195 | - * |
|
196 | - * @return EE_messenger |
|
197 | - * @throws EE_Error |
|
198 | - */ |
|
199 | - public function messenger_obj() |
|
200 | - { |
|
201 | - $messenger = $this->messenger(); |
|
202 | - try { |
|
203 | - $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | - // class for this messenger in this group. |
|
207 | - $this->set('MTP_is_active', false); |
|
208 | - $this->save(); |
|
209 | - return null; |
|
210 | - } |
|
211 | - return $messenger; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * get Message Type |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @return string |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function message_type() |
|
223 | - { |
|
224 | - return $this->get('MTP_message_type'); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * get Message type OBJECT |
|
230 | - * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | - * appropriately. |
|
233 | - * |
|
234 | - * @throws EE_Error |
|
235 | - * @return EE_message_type|false if exception thrown. |
|
236 | - */ |
|
237 | - public function message_type_obj() |
|
238 | - { |
|
239 | - $message_type = $this->message_type(); |
|
240 | - try { |
|
241 | - $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | - } catch (EE_Error $e) { |
|
243 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | - // class for the message type in this group. |
|
245 | - $this->set('MTP_is_active', false); |
|
246 | - $this->save(); |
|
247 | - return null; |
|
248 | - } |
|
249 | - return $message_type; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @return array |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - public function contexts_config() |
|
258 | - { |
|
259 | - return $this->message_type_obj()->get_contexts(); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * This returns the context_label for contexts as set in the message type object |
|
265 | - * Note this is an array with singular and plural keys |
|
266 | - * |
|
267 | - * @access public |
|
268 | - * @return array labels for "context" |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - public function context_label() |
|
272 | - { |
|
273 | - $obj = $this->message_type_obj(); |
|
274 | - return $obj->get_context_label(); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | - * |
|
281 | - * @return array () |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function context_templates() |
|
285 | - { |
|
286 | - $mtps_arr = array(); |
|
287 | - $mtps = $this->get_many_related('Message_Template'); |
|
288 | - if (empty($mtps)) { |
|
289 | - return array(); |
|
290 | - } |
|
291 | - // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | - foreach ($mtps as $mtp) { |
|
293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | - } |
|
295 | - return $mtps_arr; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * this returns if the template group this template belongs to is global |
|
301 | - * |
|
302 | - * @return bool true if it is, false if it isn't |
|
303 | - * @throws EE_Error |
|
304 | - */ |
|
305 | - public function is_global() |
|
306 | - { |
|
307 | - return $this->get('MTP_is_global'); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | - * |
|
314 | - * @return bool true if it is, false if it isn't |
|
315 | - * @throws EE_Error |
|
316 | - */ |
|
317 | - public function is_active() |
|
318 | - { |
|
319 | - return $this->get('MTP_is_active'); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | - * this template. |
|
326 | - * |
|
327 | - * @since 4.3.0 |
|
328 | - * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | - * @param string $context what context we're going to return shortcodes for |
|
330 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | - * to be returned. |
|
332 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | - * unique shortcodes for all the given (or all) fields. |
|
334 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | - * shortcodes found. |
|
336 | - * @throws EE_Error |
|
337 | - */ |
|
338 | - public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | - { |
|
340 | - $messenger = $this->messenger(); |
|
341 | - $message_type = $this->message_type(); |
|
342 | - return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | - * use the default template pack. |
|
349 | - * |
|
350 | - * @since 4.5.0 |
|
351 | - * @return string |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public function get_template_pack_name() |
|
355 | - { |
|
356 | - return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | - * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | - * |
|
364 | - * @since 4.5.0 |
|
365 | - * @return EE_Messages_Template_Pack |
|
366 | - * @throws EE_Error |
|
367 | - * @throws InvalidArgumentException |
|
368 | - * @throws ReflectionException |
|
369 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | - */ |
|
372 | - public function get_template_pack() |
|
373 | - { |
|
374 | - $pack_name = $this->get_template_pack_name(); |
|
375 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | - return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | - * use the default template variation. |
|
383 | - * |
|
384 | - * @since 4.5.0 |
|
385 | - * @return string |
|
386 | - * @throws EE_Error |
|
387 | - */ |
|
388 | - public function get_template_pack_variation() |
|
389 | - { |
|
390 | - return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * This just sets the template pack name attached to this message template group. |
|
396 | - * |
|
397 | - * @since 4.5.0 |
|
398 | - * @param string $template_pack_name What message template pack is assigned. |
|
399 | - * @return int |
|
400 | - * @throws EE_Error |
|
401 | - */ |
|
402 | - public function set_template_pack_name($template_pack_name) |
|
403 | - { |
|
404 | - return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * This just sets the template pack variation attached to this message template group. |
|
410 | - * |
|
411 | - * @since 4.5.0 |
|
412 | - * @param string $variation What variation is being set on the message template group. |
|
413 | - * @return int |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - public function set_template_pack_variation($variation) |
|
417 | - { |
|
418 | - return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Deactivates the given context. |
|
424 | - * |
|
425 | - * @param $context |
|
426 | - * @return bool|int |
|
427 | - * @throws EE_Error |
|
428 | - * @throws InvalidIdentifierException |
|
429 | - */ |
|
430 | - public function deactivate_context($context) |
|
431 | - { |
|
432 | - $this->validate_context($context); |
|
433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Activates the given context. |
|
439 | - * |
|
440 | - * @param $context |
|
441 | - * @return bool|int |
|
442 | - * @throws EE_Error |
|
443 | - * @throws InvalidIdentifierException |
|
444 | - */ |
|
445 | - public function activate_context($context) |
|
446 | - { |
|
447 | - $this->validate_context($context); |
|
448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * Returns whether the context is active or not. |
|
454 | - * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | - * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | - * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | - * whether a context is "active" or not. |
|
458 | - * |
|
459 | - * @param $context |
|
460 | - * @return bool |
|
461 | - * @throws EE_Error |
|
462 | - * @throws InvalidIdentifierException |
|
463 | - */ |
|
464 | - public function is_context_active($context) |
|
465 | - { |
|
466 | - $this->validate_context($context); |
|
467 | - return filter_var( |
|
468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | - FILTER_VALIDATE_BOOLEAN |
|
470 | - ); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | - * |
|
477 | - * @param string $context |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidIdentifierException |
|
480 | - */ |
|
481 | - public function validate_context($context) |
|
482 | - { |
|
483 | - $contexts = $this->contexts_config(); |
|
484 | - if (! isset($contexts[ $context ])) { |
|
485 | - throw new InvalidIdentifierException( |
|
486 | - '', |
|
487 | - '', |
|
488 | - sprintf( |
|
489 | - esc_html__( |
|
490 | - 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | - 'event_espresso' |
|
492 | - ), |
|
493 | - $context, |
|
494 | - implode(',', array_keys($contexts)) |
|
495 | - ) |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
16 | + /** |
|
17 | + * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
18 | + */ |
|
19 | + const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
20 | + |
|
21 | + /** |
|
22 | + * @param array $props_n_values |
|
23 | + * @param string $timezone |
|
24 | + * @return EE_Message_Template_Group|mixed |
|
25 | + * @throws EE_Error |
|
26 | + */ |
|
27 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
28 | + { |
|
29 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
30 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @param array $props_n_values |
|
36 | + * @param string $timezone |
|
37 | + * @return EE_Message_Template_Group |
|
38 | + */ |
|
39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
40 | + { |
|
41 | + return new self($props_n_values, true, $timezone); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param bool $message_type |
|
47 | + * @throws EE_Error |
|
48 | + */ |
|
49 | + public function set_message_type($message_type = false) |
|
50 | + { |
|
51 | + if (! $message_type) { |
|
52 | + throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
53 | + } |
|
54 | + $this->set('MTP_message_type', $message_type); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param bool $messenger |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function set_messenger($messenger = false) |
|
63 | + { |
|
64 | + if (! $messenger) { |
|
65 | + throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
66 | + } |
|
67 | + $this->set('MTP_messenger', $messenger); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param bool $GRP_ID |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public function set_group_template_id($GRP_ID = false) |
|
76 | + { |
|
77 | + if (! $GRP_ID) { |
|
78 | + throw new EE_Error( |
|
79 | + esc_html__( |
|
80 | + 'Missing required value for the message template group id', |
|
81 | + 'event_espresso' |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | + $this->set('GRP_ID', $GRP_ID); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * get Group ID |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return int |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public function GRP_ID() |
|
97 | + { |
|
98 | + return $this->get('GRP_ID'); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * get User ID |
|
104 | + * |
|
105 | + * @access public |
|
106 | + * @return int |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + public function user() |
|
110 | + { |
|
111 | + $user_id = $this->get('MTP_user_id'); |
|
112 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Wrapper for the user function() (preserve backward compat) |
|
118 | + * |
|
119 | + * @since 4.5.0 |
|
120 | + * @return int |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + public function wp_user() |
|
124 | + { |
|
125 | + return $this->user(); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * This simply returns a count of all related events to this message template group |
|
131 | + * |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function count_events() |
|
135 | + { |
|
136 | + return $this->count_related('Event'); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * returns the name saved in the db for this template |
|
142 | + * |
|
143 | + * @return string |
|
144 | + * @throws EE_Error |
|
145 | + */ |
|
146 | + public function name() |
|
147 | + { |
|
148 | + return $this->get('MTP_name'); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Returns the description saved in the db for this template group |
|
154 | + * |
|
155 | + * @return string |
|
156 | + * @throws EE_Error |
|
157 | + */ |
|
158 | + public function description() |
|
159 | + { |
|
160 | + return $this->get('MTP_description'); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * returns all related EE_Message_Template objects |
|
166 | + * |
|
167 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
168 | + * @return EE_Message_Template[] |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + public function message_templates($query_params = array()) |
|
172 | + { |
|
173 | + return $this->get_many_related('Message_Template', $query_params); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get Message Messenger |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @return string |
|
182 | + * @throws EE_Error |
|
183 | + */ |
|
184 | + public function messenger() |
|
185 | + { |
|
186 | + return $this->get('MTP_messenger'); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * get Message Messenger OBJECT |
|
192 | + * If an attempt to get the corresponding messenger object fails, then we set this message |
|
193 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
194 | + * appropriately. |
|
195 | + * |
|
196 | + * @return EE_messenger |
|
197 | + * @throws EE_Error |
|
198 | + */ |
|
199 | + public function messenger_obj() |
|
200 | + { |
|
201 | + $messenger = $this->messenger(); |
|
202 | + try { |
|
203 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
206 | + // class for this messenger in this group. |
|
207 | + $this->set('MTP_is_active', false); |
|
208 | + $this->save(); |
|
209 | + return null; |
|
210 | + } |
|
211 | + return $messenger; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * get Message Type |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @return string |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function message_type() |
|
223 | + { |
|
224 | + return $this->get('MTP_message_type'); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * get Message type OBJECT |
|
230 | + * If an attempt to get the corresponding message type object fails, then we set this message |
|
231 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
232 | + * appropriately. |
|
233 | + * |
|
234 | + * @throws EE_Error |
|
235 | + * @return EE_message_type|false if exception thrown. |
|
236 | + */ |
|
237 | + public function message_type_obj() |
|
238 | + { |
|
239 | + $message_type = $this->message_type(); |
|
240 | + try { |
|
241 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
242 | + } catch (EE_Error $e) { |
|
243 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
244 | + // class for the message type in this group. |
|
245 | + $this->set('MTP_is_active', false); |
|
246 | + $this->save(); |
|
247 | + return null; |
|
248 | + } |
|
249 | + return $message_type; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @return array |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + public function contexts_config() |
|
258 | + { |
|
259 | + return $this->message_type_obj()->get_contexts(); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * This returns the context_label for contexts as set in the message type object |
|
265 | + * Note this is an array with singular and plural keys |
|
266 | + * |
|
267 | + * @access public |
|
268 | + * @return array labels for "context" |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + public function context_label() |
|
272 | + { |
|
273 | + $obj = $this->message_type_obj(); |
|
274 | + return $obj->get_context_label(); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * This returns an array of EE_Message_Template objects indexed by context and field. |
|
280 | + * |
|
281 | + * @return array () |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function context_templates() |
|
285 | + { |
|
286 | + $mtps_arr = array(); |
|
287 | + $mtps = $this->get_many_related('Message_Template'); |
|
288 | + if (empty($mtps)) { |
|
289 | + return array(); |
|
290 | + } |
|
291 | + // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
292 | + foreach ($mtps as $mtp) { |
|
293 | + $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
294 | + } |
|
295 | + return $mtps_arr; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * this returns if the template group this template belongs to is global |
|
301 | + * |
|
302 | + * @return bool true if it is, false if it isn't |
|
303 | + * @throws EE_Error |
|
304 | + */ |
|
305 | + public function is_global() |
|
306 | + { |
|
307 | + return $this->get('MTP_is_global'); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
313 | + * |
|
314 | + * @return bool true if it is, false if it isn't |
|
315 | + * @throws EE_Error |
|
316 | + */ |
|
317 | + public function is_active() |
|
318 | + { |
|
319 | + return $this->get('MTP_is_active'); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
325 | + * this template. |
|
326 | + * |
|
327 | + * @since 4.3.0 |
|
328 | + * @uses EEH_MSG_Template::get_shortcodes() |
|
329 | + * @param string $context what context we're going to return shortcodes for |
|
330 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
331 | + * to be returned. |
|
332 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
333 | + * unique shortcodes for all the given (or all) fields. |
|
334 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
335 | + * shortcodes found. |
|
336 | + * @throws EE_Error |
|
337 | + */ |
|
338 | + public function get_shortcodes($context, $fields = array(), $merged = false) |
|
339 | + { |
|
340 | + $messenger = $this->messenger(); |
|
341 | + $message_type = $this->message_type(); |
|
342 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
348 | + * use the default template pack. |
|
349 | + * |
|
350 | + * @since 4.5.0 |
|
351 | + * @return string |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public function get_template_pack_name() |
|
355 | + { |
|
356 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * This returns the specific template pack object referenced by the template pack name attached to this message |
|
362 | + * template group. If no template pack is assigned then the default template pack is retrieved. |
|
363 | + * |
|
364 | + * @since 4.5.0 |
|
365 | + * @return EE_Messages_Template_Pack |
|
366 | + * @throws EE_Error |
|
367 | + * @throws InvalidArgumentException |
|
368 | + * @throws ReflectionException |
|
369 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
370 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
371 | + */ |
|
372 | + public function get_template_pack() |
|
373 | + { |
|
374 | + $pack_name = $this->get_template_pack_name(); |
|
375 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
376 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
382 | + * use the default template variation. |
|
383 | + * |
|
384 | + * @since 4.5.0 |
|
385 | + * @return string |
|
386 | + * @throws EE_Error |
|
387 | + */ |
|
388 | + public function get_template_pack_variation() |
|
389 | + { |
|
390 | + return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * This just sets the template pack name attached to this message template group. |
|
396 | + * |
|
397 | + * @since 4.5.0 |
|
398 | + * @param string $template_pack_name What message template pack is assigned. |
|
399 | + * @return int |
|
400 | + * @throws EE_Error |
|
401 | + */ |
|
402 | + public function set_template_pack_name($template_pack_name) |
|
403 | + { |
|
404 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * This just sets the template pack variation attached to this message template group. |
|
410 | + * |
|
411 | + * @since 4.5.0 |
|
412 | + * @param string $variation What variation is being set on the message template group. |
|
413 | + * @return int |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + public function set_template_pack_variation($variation) |
|
417 | + { |
|
418 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Deactivates the given context. |
|
424 | + * |
|
425 | + * @param $context |
|
426 | + * @return bool|int |
|
427 | + * @throws EE_Error |
|
428 | + * @throws InvalidIdentifierException |
|
429 | + */ |
|
430 | + public function deactivate_context($context) |
|
431 | + { |
|
432 | + $this->validate_context($context); |
|
433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Activates the given context. |
|
439 | + * |
|
440 | + * @param $context |
|
441 | + * @return bool|int |
|
442 | + * @throws EE_Error |
|
443 | + * @throws InvalidIdentifierException |
|
444 | + */ |
|
445 | + public function activate_context($context) |
|
446 | + { |
|
447 | + $this->validate_context($context); |
|
448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * Returns whether the context is active or not. |
|
454 | + * Note, this will default to true if the extra meta record doesn't exist. |
|
455 | + * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
456 | + * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
457 | + * whether a context is "active" or not. |
|
458 | + * |
|
459 | + * @param $context |
|
460 | + * @return bool |
|
461 | + * @throws EE_Error |
|
462 | + * @throws InvalidIdentifierException |
|
463 | + */ |
|
464 | + public function is_context_active($context) |
|
465 | + { |
|
466 | + $this->validate_context($context); |
|
467 | + return filter_var( |
|
468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
469 | + FILTER_VALIDATE_BOOLEAN |
|
470 | + ); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * Validates the incoming context to verify it matches a registered context for the related message type. |
|
476 | + * |
|
477 | + * @param string $context |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidIdentifierException |
|
480 | + */ |
|
481 | + public function validate_context($context) |
|
482 | + { |
|
483 | + $contexts = $this->contexts_config(); |
|
484 | + if (! isset($contexts[ $context ])) { |
|
485 | + throw new InvalidIdentifierException( |
|
486 | + '', |
|
487 | + '', |
|
488 | + sprintf( |
|
489 | + esc_html__( |
|
490 | + 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
491 | + 'event_espresso' |
|
492 | + ), |
|
493 | + $context, |
|
494 | + implode(',', array_keys($contexts)) |
|
495 | + ) |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | 499 | } |
@@ -13,173 +13,173 @@ |
||
13 | 13 | class EE_Message_Template extends EE_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values |
|
18 | - * @param string $timezone |
|
19 | - * @return EE_Message_Template|mixed |
|
20 | - */ |
|
21 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | - { |
|
23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param array $props_n_values |
|
30 | - * @param string $timezone |
|
31 | - * @return EE_Message_Template |
|
32 | - */ |
|
33 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | - { |
|
35 | - return new self($props_n_values, true, $timezone); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param bool $GRP_ID |
|
41 | - * @throws EE_Error |
|
42 | - */ |
|
43 | - public function set_group_template_id($GRP_ID = false) |
|
44 | - { |
|
45 | - if (! $GRP_ID) { |
|
46 | - throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | - } |
|
48 | - $this->set('GRP_ID', $GRP_ID); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * get Group ID |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - public function GRP_ID() |
|
59 | - { |
|
60 | - return $this->get('GRP_ID'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * get User ID |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function user() |
|
71 | - { |
|
72 | - return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * get Message Messenger |
|
78 | - * |
|
79 | - * @access public |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function messenger() |
|
83 | - { |
|
84 | - return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * get Message Messenger OBJECT |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @return object Messenger Object for the given messenger |
|
93 | - */ |
|
94 | - public function messenger_obj() |
|
95 | - { |
|
96 | - return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * get Message Type |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function message_type() |
|
107 | - { |
|
108 | - return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * get Message type OBJECT |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @return object Message Type object for the given message type |
|
117 | - */ |
|
118 | - public function message_type_obj() |
|
119 | - { |
|
120 | - return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This returns the set context array configured in the message type object |
|
126 | - * |
|
127 | - * @access public |
|
128 | - * @return array array of contexts and their configuration. |
|
129 | - */ |
|
130 | - public function contexts_config() |
|
131 | - { |
|
132 | - return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This returns the context_label for contexts as set in the message type object |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @return string label for "context" |
|
141 | - */ |
|
142 | - public function context_label() |
|
143 | - { |
|
144 | - return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * this returns if the template group this template belongs to is global |
|
150 | - * |
|
151 | - * @return boolean true if it is, false if it isn't |
|
152 | - */ |
|
153 | - public function is_global() |
|
154 | - { |
|
155 | - return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | - * |
|
162 | - * @return boolean true if it is, false if it isn't |
|
163 | - */ |
|
164 | - public function is_active() |
|
165 | - { |
|
166 | - return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | - * this template. |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param string $context what context we're going to return shortcodes for |
|
176 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | - * to be merged and returned. |
|
178 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | - * shortcodes found. |
|
180 | - */ |
|
181 | - public function get_shortcodes($context, $fields = array()) |
|
182 | - { |
|
183 | - return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values |
|
18 | + * @param string $timezone |
|
19 | + * @return EE_Message_Template|mixed |
|
20 | + */ |
|
21 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | + { |
|
23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param array $props_n_values |
|
30 | + * @param string $timezone |
|
31 | + * @return EE_Message_Template |
|
32 | + */ |
|
33 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | + { |
|
35 | + return new self($props_n_values, true, $timezone); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param bool $GRP_ID |
|
41 | + * @throws EE_Error |
|
42 | + */ |
|
43 | + public function set_group_template_id($GRP_ID = false) |
|
44 | + { |
|
45 | + if (! $GRP_ID) { |
|
46 | + throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | + } |
|
48 | + $this->set('GRP_ID', $GRP_ID); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * get Group ID |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + public function GRP_ID() |
|
59 | + { |
|
60 | + return $this->get('GRP_ID'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * get User ID |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function user() |
|
71 | + { |
|
72 | + return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * get Message Messenger |
|
78 | + * |
|
79 | + * @access public |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function messenger() |
|
83 | + { |
|
84 | + return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * get Message Messenger OBJECT |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @return object Messenger Object for the given messenger |
|
93 | + */ |
|
94 | + public function messenger_obj() |
|
95 | + { |
|
96 | + return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * get Message Type |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function message_type() |
|
107 | + { |
|
108 | + return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * get Message type OBJECT |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @return object Message Type object for the given message type |
|
117 | + */ |
|
118 | + public function message_type_obj() |
|
119 | + { |
|
120 | + return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This returns the set context array configured in the message type object |
|
126 | + * |
|
127 | + * @access public |
|
128 | + * @return array array of contexts and their configuration. |
|
129 | + */ |
|
130 | + public function contexts_config() |
|
131 | + { |
|
132 | + return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This returns the context_label for contexts as set in the message type object |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @return string label for "context" |
|
141 | + */ |
|
142 | + public function context_label() |
|
143 | + { |
|
144 | + return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * this returns if the template group this template belongs to is global |
|
150 | + * |
|
151 | + * @return boolean true if it is, false if it isn't |
|
152 | + */ |
|
153 | + public function is_global() |
|
154 | + { |
|
155 | + return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | + * |
|
162 | + * @return boolean true if it is, false if it isn't |
|
163 | + */ |
|
164 | + public function is_active() |
|
165 | + { |
|
166 | + return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | + * this template. |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param string $context what context we're going to return shortcodes for |
|
176 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | + * to be merged and returned. |
|
178 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | + * shortcodes found. |
|
180 | + */ |
|
181 | + public function get_shortcodes($context, $fields = array()) |
|
182 | + { |
|
183 | + return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | + } |
|
185 | 185 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function set_group_template_id($GRP_ID = false) |
44 | 44 | { |
45 | - if (! $GRP_ID) { |
|
45 | + if ( ! $GRP_ID) { |
|
46 | 46 | throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
47 | 47 | } |
48 | 48 | $this->set('GRP_ID', $GRP_ID); |
@@ -14,429 +14,429 @@ |
||
14 | 14 | abstract class EE_CPT_Base extends EE_Soft_Delete_Base_Class |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
19 | - * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $_feature_image = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
27 | - */ |
|
28 | - protected $_wp_post; |
|
29 | - |
|
30 | - |
|
31 | - abstract public function wp_user(); |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
36 | - * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
37 | - * |
|
38 | - * @return WP_Post |
|
39 | - */ |
|
40 | - public function wp_post() |
|
41 | - { |
|
42 | - global $wpdb; |
|
43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
44 | - if ($this->ID()) { |
|
45 | - $this->_wp_post = get_post($this->ID()); |
|
46 | - } else { |
|
47 | - $simulated_db_result = new stdClass(); |
|
48 | - foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
49 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
50 | - === $wpdb->posts |
|
51 | - ) { |
|
52 | - $column = $field_obj->get_table_column(); |
|
53 | - |
|
54 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
55 | - $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
56 | - } elseif ($field_obj->is_db_only_field()) { |
|
57 | - $value_on_model_obj = $field_obj->get_default_value(); |
|
58 | - } else { |
|
59 | - $value_on_model_obj = $this->get_raw($field_name); |
|
60 | - } |
|
61 | - $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
62 | - } |
|
63 | - } |
|
64 | - $this->_wp_post = new WP_Post($simulated_db_result); |
|
65 | - } |
|
66 | - // and let's make retrieving the EE CPT object easy too |
|
67 | - $classname = get_class($this); |
|
68 | - if (! isset($this->_wp_post->{$classname})) { |
|
69 | - $this->_wp_post->{$classname} = $this; |
|
70 | - } |
|
71 | - } |
|
72 | - return $this->_wp_post; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * When fetching a new value for a post field that uses the global $post for rendering, |
|
77 | - * set the global $post temporarily to be this model object; and afterwards restore it |
|
78 | - * |
|
79 | - * @param string $fieldname |
|
80 | - * @param bool $pretty |
|
81 | - * @param string $extra_cache_ref |
|
82 | - * @return mixed |
|
83 | - */ |
|
84 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
85 | - { |
|
86 | - global $post; |
|
87 | - |
|
88 | - if ($pretty |
|
89 | - && ( |
|
90 | - ! ( |
|
91 | - $post instanceof WP_Post |
|
92 | - && $post->ID |
|
93 | - ) |
|
94 | - || (int) $post->ID !== $this->ID() |
|
95 | - ) |
|
96 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
97 | - $old_post = $post; |
|
98 | - $post = $this->wp_post(); |
|
99 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
100 | - $post = $old_post; |
|
101 | - } else { |
|
102 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
103 | - } |
|
104 | - return $return_value; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Adds to the specified event category. If it category doesn't exist, creates it. |
|
109 | - * |
|
110 | - * @param string $category_name |
|
111 | - * @param string $category_description optional |
|
112 | - * @param int $parent_term_taxonomy_id optional |
|
113 | - * @return EE_Term_Taxonomy |
|
114 | - */ |
|
115 | - public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
116 | - { |
|
117 | - return $this->get_model()->add_event_category( |
|
118 | - $this, |
|
119 | - $category_name, |
|
120 | - $category_description, |
|
121 | - $parent_term_taxonomy_id |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Removes the event category by specified name from being related ot this event |
|
128 | - * |
|
129 | - * @param string $category_name |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public function remove_event_category($category_name) |
|
133 | - { |
|
134 | - return $this->get_model()->remove_event_category($this, $category_name); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * Removes the relation to the specified term taxonomy, and maintains the |
|
140 | - * data integrity of the term taxonomy provided |
|
141 | - * |
|
142 | - * @param EE_Term_Taxonomy $term_taxonomy |
|
143 | - * @return EE_Base_Class the relation was removed from |
|
144 | - */ |
|
145 | - public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
146 | - { |
|
147 | - if (! $term_taxonomy) { |
|
148 | - EE_Error::add_error( |
|
149 | - sprintf( |
|
150 | - __( |
|
151 | - "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
152 | - "event_espresso" |
|
153 | - ), |
|
154 | - get_class($this), |
|
155 | - $this->ID() |
|
156 | - ), |
|
157 | - __FILE__, |
|
158 | - __FUNCTION__, |
|
159 | - __LINE__ |
|
160 | - ); |
|
161 | - return null; |
|
162 | - } |
|
163 | - $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
164 | - $term_taxonomy->save(); |
|
165 | - return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * The main purpose of this method is to return the post type for the model object |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function post_type() |
|
176 | - { |
|
177 | - return $this->get_model()->post_type(); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * The main purpose of this method is to return the parent for the model object |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * @return int |
|
186 | - */ |
|
187 | - public function parent() |
|
188 | - { |
|
189 | - return $this->get('parent'); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * return the _status property |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function status() |
|
199 | - { |
|
200 | - return $this->get('status'); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param string $status |
|
206 | - */ |
|
207 | - public function set_status($status) |
|
208 | - { |
|
209 | - $this->set('status', $status); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
215 | - * WordPress' get_the_post_thumbnail() function. |
|
216 | - * |
|
217 | - * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
218 | - * @access protected |
|
219 | - * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
220 | - * representing width and height in pixels (i.e. array(32,32) ). |
|
221 | - * @param string|array $attr Optional. Query string or array of attributes. |
|
222 | - * @return string HTML image element |
|
223 | - */ |
|
224 | - protected function _get_feature_image($size, $attr) |
|
225 | - { |
|
226 | - // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
227 | - $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
228 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | - return $this->_feature_image[ $cache_key ]; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * See _get_feature_image. Returns the HTML to display a featured image |
|
237 | - * |
|
238 | - * @param string $size |
|
239 | - * @param string|array $attr |
|
240 | - * @return string of html |
|
241 | - */ |
|
242 | - public function feature_image($size = 'thumbnail', $attr = '') |
|
243 | - { |
|
244 | - return $this->_get_feature_image($size, $attr); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
250 | - * using the given size params. |
|
251 | - * |
|
252 | - * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
253 | - * representing width and height in pixels eg. array(32,32). |
|
254 | - * @return string|boolean the url of the image or false if not found |
|
255 | - */ |
|
256 | - public function feature_image_url($size = 'thumbnail') |
|
257 | - { |
|
258 | - $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
259 | - return ! empty($attachment) ? $attachment[0] : false; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * This is a method for restoring this_obj using details from the given $revision_id |
|
265 | - * |
|
266 | - * @param int $revision_id ID of the revision we're getting data from |
|
267 | - * @param array $related_obj_names if included this will be used to restore for related obj |
|
268 | - * if not included then we just do restore on the meta. |
|
269 | - * We will accept an array of related_obj_names for restoration here. |
|
270 | - * @param array $where_query You can optionally include an array of key=>value pairs |
|
271 | - * that allow you to further constrict the relation to being added. |
|
272 | - * However, keep in mind that the columns (keys) given |
|
273 | - * must match a column on the JOIN table and currently |
|
274 | - * only the HABTM models accept these additional conditions. |
|
275 | - * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
276 | - * then a NEW row is created in the join table. |
|
277 | - * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
278 | - * sent); |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
282 | - { |
|
283 | - // get revision object |
|
284 | - $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
285 | - if ($revision_obj instanceof EE_CPT_Base) { |
|
286 | - // no related_obj_name so we assume we're saving a revision on this object. |
|
287 | - if (empty($related_obj_names)) { |
|
288 | - $fields = $this->get_model()->get_meta_table_fields(); |
|
289 | - foreach ($fields as $field) { |
|
290 | - $this->set($field, $revision_obj->get($field)); |
|
291 | - } |
|
292 | - $this->save(); |
|
293 | - } |
|
294 | - $related_obj_names = (array) $related_obj_names; |
|
295 | - foreach ($related_obj_names as $related_name) { |
|
296 | - // related_obj_name so we're saving a revision on an object related to this object |
|
297 | - // do we have $where_query params for this related object? If we do then we include that. |
|
298 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
299 | - $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
300 | - $related_objs = $this->get_many_related($related_name, $where_params); |
|
301 | - $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
302 | - // load helper |
|
303 | - // remove related objs from this object that are not in revision |
|
304 | - // array_diff *should* work cause I think objects are indexed by ID? |
|
305 | - $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
306 | - foreach ($related_to_remove as $rr) { |
|
307 | - $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
308 | - } |
|
309 | - // add all related objs attached to revision to this object |
|
310 | - foreach ($revision_related_objs as $r_obj) { |
|
311 | - $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
320 | - * |
|
321 | - * @param string $meta_key |
|
322 | - * @param boolean $single |
|
323 | - * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
324 | - * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
325 | - * specified key.</li> |
|
326 | - * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
327 | - * array</li></ul> |
|
328 | - */ |
|
329 | - public function get_post_meta($meta_key = null, $single = false) |
|
330 | - { |
|
331 | - return get_post_meta($this->ID(), $meta_key, $single); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
337 | - * |
|
338 | - * @param string $meta_key |
|
339 | - * @param mixed $meta_value |
|
340 | - * @param mixed $prev_value |
|
341 | - * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
342 | - * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
343 | - * database, this function returns false. |
|
344 | - */ |
|
345 | - public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
346 | - { |
|
347 | - if (! $this->ID()) { |
|
348 | - $this->save(); |
|
349 | - } |
|
350 | - return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
356 | - * |
|
357 | - * @param mixed $meta_key |
|
358 | - * @param mixed $meta_value |
|
359 | - * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
360 | - * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
361 | - * key already exists, in which case false is returned. |
|
362 | - */ |
|
363 | - public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
364 | - { |
|
365 | - if ($this->ID()) { |
|
366 | - $this->save(); |
|
367 | - } |
|
368 | - return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
374 | - * |
|
375 | - * @param mixed $meta_key |
|
376 | - * @param mixed $meta_value |
|
377 | - * @return boolean False for failure. True for success. |
|
378 | - */ |
|
379 | - public function delete_post_meta($meta_key, $meta_value = '') |
|
380 | - { |
|
381 | - if (! $this->ID()) { |
|
382 | - // there are obviously no postmetas for this if it's not saved |
|
383 | - // so let's just report this as a success |
|
384 | - return true; |
|
385 | - } |
|
386 | - return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Gets the URL for viewing this event on the front-end |
|
392 | - * |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - public function get_permalink() |
|
396 | - { |
|
397 | - return get_permalink($this->ID()); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Gets all the term-taxonomies for this CPT |
|
403 | - * |
|
404 | - * @param array $query_params |
|
405 | - * @return EE_Term_Taxonomy |
|
406 | - */ |
|
407 | - public function term_taxonomies($query_params = array()) |
|
408 | - { |
|
409 | - return $this->get_many_related('Term_Taxonomy', $query_params); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * @return mixed |
|
415 | - */ |
|
416 | - public function get_custom_post_statuses() |
|
417 | - { |
|
418 | - return $this->get_model()->get_custom_post_statuses(); |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @return mixed |
|
424 | - */ |
|
425 | - public function get_all_post_statuses() |
|
426 | - { |
|
427 | - return $this->get_model()->get_status_array(); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
433 | - * |
|
434 | - * @return array |
|
435 | - */ |
|
436 | - public function __sleep() |
|
437 | - { |
|
438 | - $properties_to_serialize = parent::__sleep(); |
|
439 | - $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
440 | - return $properties_to_serialize; |
|
441 | - } |
|
17 | + /** |
|
18 | + * This is a property for holding cached feature images on CPT objects. Cache's are set on the first |
|
19 | + * "feature_image()" method call. Each key in the array corresponds to the requested size. |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $_feature_image = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
27 | + */ |
|
28 | + protected $_wp_post; |
|
29 | + |
|
30 | + |
|
31 | + abstract public function wp_user(); |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
36 | + * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
37 | + * |
|
38 | + * @return WP_Post |
|
39 | + */ |
|
40 | + public function wp_post() |
|
41 | + { |
|
42 | + global $wpdb; |
|
43 | + if (! $this->_wp_post instanceof WP_Post) { |
|
44 | + if ($this->ID()) { |
|
45 | + $this->_wp_post = get_post($this->ID()); |
|
46 | + } else { |
|
47 | + $simulated_db_result = new stdClass(); |
|
48 | + foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
49 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() |
|
50 | + === $wpdb->posts |
|
51 | + ) { |
|
52 | + $column = $field_obj->get_table_column(); |
|
53 | + |
|
54 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
55 | + $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
56 | + } elseif ($field_obj->is_db_only_field()) { |
|
57 | + $value_on_model_obj = $field_obj->get_default_value(); |
|
58 | + } else { |
|
59 | + $value_on_model_obj = $this->get_raw($field_name); |
|
60 | + } |
|
61 | + $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
62 | + } |
|
63 | + } |
|
64 | + $this->_wp_post = new WP_Post($simulated_db_result); |
|
65 | + } |
|
66 | + // and let's make retrieving the EE CPT object easy too |
|
67 | + $classname = get_class($this); |
|
68 | + if (! isset($this->_wp_post->{$classname})) { |
|
69 | + $this->_wp_post->{$classname} = $this; |
|
70 | + } |
|
71 | + } |
|
72 | + return $this->_wp_post; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * When fetching a new value for a post field that uses the global $post for rendering, |
|
77 | + * set the global $post temporarily to be this model object; and afterwards restore it |
|
78 | + * |
|
79 | + * @param string $fieldname |
|
80 | + * @param bool $pretty |
|
81 | + * @param string $extra_cache_ref |
|
82 | + * @return mixed |
|
83 | + */ |
|
84 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
85 | + { |
|
86 | + global $post; |
|
87 | + |
|
88 | + if ($pretty |
|
89 | + && ( |
|
90 | + ! ( |
|
91 | + $post instanceof WP_Post |
|
92 | + && $post->ID |
|
93 | + ) |
|
94 | + || (int) $post->ID !== $this->ID() |
|
95 | + ) |
|
96 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
97 | + $old_post = $post; |
|
98 | + $post = $this->wp_post(); |
|
99 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
100 | + $post = $old_post; |
|
101 | + } else { |
|
102 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
103 | + } |
|
104 | + return $return_value; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Adds to the specified event category. If it category doesn't exist, creates it. |
|
109 | + * |
|
110 | + * @param string $category_name |
|
111 | + * @param string $category_description optional |
|
112 | + * @param int $parent_term_taxonomy_id optional |
|
113 | + * @return EE_Term_Taxonomy |
|
114 | + */ |
|
115 | + public function add_event_category($category_name, $category_description = null, $parent_term_taxonomy_id = null) |
|
116 | + { |
|
117 | + return $this->get_model()->add_event_category( |
|
118 | + $this, |
|
119 | + $category_name, |
|
120 | + $category_description, |
|
121 | + $parent_term_taxonomy_id |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Removes the event category by specified name from being related ot this event |
|
128 | + * |
|
129 | + * @param string $category_name |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public function remove_event_category($category_name) |
|
133 | + { |
|
134 | + return $this->get_model()->remove_event_category($this, $category_name); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * Removes the relation to the specified term taxonomy, and maintains the |
|
140 | + * data integrity of the term taxonomy provided |
|
141 | + * |
|
142 | + * @param EE_Term_Taxonomy $term_taxonomy |
|
143 | + * @return EE_Base_Class the relation was removed from |
|
144 | + */ |
|
145 | + public function remove_relation_to_term_taxonomy($term_taxonomy) |
|
146 | + { |
|
147 | + if (! $term_taxonomy) { |
|
148 | + EE_Error::add_error( |
|
149 | + sprintf( |
|
150 | + __( |
|
151 | + "No Term_Taxonomy provided which to remove from model object of type %s and id %d", |
|
152 | + "event_espresso" |
|
153 | + ), |
|
154 | + get_class($this), |
|
155 | + $this->ID() |
|
156 | + ), |
|
157 | + __FILE__, |
|
158 | + __FUNCTION__, |
|
159 | + __LINE__ |
|
160 | + ); |
|
161 | + return null; |
|
162 | + } |
|
163 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
164 | + $term_taxonomy->save(); |
|
165 | + return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * The main purpose of this method is to return the post type for the model object |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function post_type() |
|
176 | + { |
|
177 | + return $this->get_model()->post_type(); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * The main purpose of this method is to return the parent for the model object |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * @return int |
|
186 | + */ |
|
187 | + public function parent() |
|
188 | + { |
|
189 | + return $this->get('parent'); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * return the _status property |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function status() |
|
199 | + { |
|
200 | + return $this->get('status'); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param string $status |
|
206 | + */ |
|
207 | + public function set_status($status) |
|
208 | + { |
|
209 | + $this->set('status', $status); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * This calls the equivalent model method for retrieving the feature image which in turn is a wrapper for |
|
215 | + * WordPress' get_the_post_thumbnail() function. |
|
216 | + * |
|
217 | + * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
218 | + * @access protected |
|
219 | + * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
220 | + * representing width and height in pixels (i.e. array(32,32) ). |
|
221 | + * @param string|array $attr Optional. Query string or array of attributes. |
|
222 | + * @return string HTML image element |
|
223 | + */ |
|
224 | + protected function _get_feature_image($size, $attr) |
|
225 | + { |
|
226 | + // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
|
227 | + $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
228 | + $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | + $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | + ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | + return $this->_feature_image[ $cache_key ]; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * See _get_feature_image. Returns the HTML to display a featured image |
|
237 | + * |
|
238 | + * @param string $size |
|
239 | + * @param string|array $attr |
|
240 | + * @return string of html |
|
241 | + */ |
|
242 | + public function feature_image($size = 'thumbnail', $attr = '') |
|
243 | + { |
|
244 | + return $this->_get_feature_image($size, $attr); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * This uses the wp "wp_get_attachment_image_src()" function to return the feature image for the current class |
|
250 | + * using the given size params. |
|
251 | + * |
|
252 | + * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array |
|
253 | + * representing width and height in pixels eg. array(32,32). |
|
254 | + * @return string|boolean the url of the image or false if not found |
|
255 | + */ |
|
256 | + public function feature_image_url($size = 'thumbnail') |
|
257 | + { |
|
258 | + $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
259 | + return ! empty($attachment) ? $attachment[0] : false; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * This is a method for restoring this_obj using details from the given $revision_id |
|
265 | + * |
|
266 | + * @param int $revision_id ID of the revision we're getting data from |
|
267 | + * @param array $related_obj_names if included this will be used to restore for related obj |
|
268 | + * if not included then we just do restore on the meta. |
|
269 | + * We will accept an array of related_obj_names for restoration here. |
|
270 | + * @param array $where_query You can optionally include an array of key=>value pairs |
|
271 | + * that allow you to further constrict the relation to being added. |
|
272 | + * However, keep in mind that the columns (keys) given |
|
273 | + * must match a column on the JOIN table and currently |
|
274 | + * only the HABTM models accept these additional conditions. |
|
275 | + * Also remember that if an exact match isn't found for these extra cols/val pairs, |
|
276 | + * then a NEW row is created in the join table. |
|
277 | + * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names |
|
278 | + * sent); |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) |
|
282 | + { |
|
283 | + // get revision object |
|
284 | + $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
285 | + if ($revision_obj instanceof EE_CPT_Base) { |
|
286 | + // no related_obj_name so we assume we're saving a revision on this object. |
|
287 | + if (empty($related_obj_names)) { |
|
288 | + $fields = $this->get_model()->get_meta_table_fields(); |
|
289 | + foreach ($fields as $field) { |
|
290 | + $this->set($field, $revision_obj->get($field)); |
|
291 | + } |
|
292 | + $this->save(); |
|
293 | + } |
|
294 | + $related_obj_names = (array) $related_obj_names; |
|
295 | + foreach ($related_obj_names as $related_name) { |
|
296 | + // related_obj_name so we're saving a revision on an object related to this object |
|
297 | + // do we have $where_query params for this related object? If we do then we include that. |
|
298 | + $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
299 | + $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
300 | + $related_objs = $this->get_many_related($related_name, $where_params); |
|
301 | + $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
302 | + // load helper |
|
303 | + // remove related objs from this object that are not in revision |
|
304 | + // array_diff *should* work cause I think objects are indexed by ID? |
|
305 | + $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
306 | + foreach ($related_to_remove as $rr) { |
|
307 | + $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
308 | + } |
|
309 | + // add all related objs attached to revision to this object |
|
310 | + foreach ($revision_related_objs as $r_obj) { |
|
311 | + $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Wrapper for get_post_meta, http://codex.wordpress.org/Function_Reference/get_post_meta |
|
320 | + * |
|
321 | + * @param string $meta_key |
|
322 | + * @param boolean $single |
|
323 | + * @return mixed <ul><li>If only $id is set it will return all meta values in an associative array.</li> |
|
324 | + * <li>If $single is set to false, or left blank, the function returns an array containing all values of the |
|
325 | + * specified key.</li> |
|
326 | + * <li>If $single is set to true, the function returns the first value of the specified key (not in an |
|
327 | + * array</li></ul> |
|
328 | + */ |
|
329 | + public function get_post_meta($meta_key = null, $single = false) |
|
330 | + { |
|
331 | + return get_post_meta($this->ID(), $meta_key, $single); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Wrapper for update_post_meta, http://codex.wordpress.org/Function_Reference/update_post_meta |
|
337 | + * |
|
338 | + * @param string $meta_key |
|
339 | + * @param mixed $meta_value |
|
340 | + * @param mixed $prev_value |
|
341 | + * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. |
|
342 | + * NOTE: If the meta_value passed to this function is the same as the value that is already in the |
|
343 | + * database, this function returns false. |
|
344 | + */ |
|
345 | + public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
|
346 | + { |
|
347 | + if (! $this->ID()) { |
|
348 | + $this->save(); |
|
349 | + } |
|
350 | + return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Wrapper for add_post_meta, http://codex.wordpress.org/Function_Reference/add_post_meta |
|
356 | + * |
|
357 | + * @param mixed $meta_key |
|
358 | + * @param mixed $meta_value |
|
359 | + * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
|
360 | + * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given |
|
361 | + * key already exists, in which case false is returned. |
|
362 | + */ |
|
363 | + public function add_post_meta($meta_key, $meta_value, $unique = false) |
|
364 | + { |
|
365 | + if ($this->ID()) { |
|
366 | + $this->save(); |
|
367 | + } |
|
368 | + return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Wrapper for delete_post_meta, http://codex.wordpress.org/Function_Reference/delete_post_meta |
|
374 | + * |
|
375 | + * @param mixed $meta_key |
|
376 | + * @param mixed $meta_value |
|
377 | + * @return boolean False for failure. True for success. |
|
378 | + */ |
|
379 | + public function delete_post_meta($meta_key, $meta_value = '') |
|
380 | + { |
|
381 | + if (! $this->ID()) { |
|
382 | + // there are obviously no postmetas for this if it's not saved |
|
383 | + // so let's just report this as a success |
|
384 | + return true; |
|
385 | + } |
|
386 | + return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Gets the URL for viewing this event on the front-end |
|
392 | + * |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + public function get_permalink() |
|
396 | + { |
|
397 | + return get_permalink($this->ID()); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Gets all the term-taxonomies for this CPT |
|
403 | + * |
|
404 | + * @param array $query_params |
|
405 | + * @return EE_Term_Taxonomy |
|
406 | + */ |
|
407 | + public function term_taxonomies($query_params = array()) |
|
408 | + { |
|
409 | + return $this->get_many_related('Term_Taxonomy', $query_params); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * @return mixed |
|
415 | + */ |
|
416 | + public function get_custom_post_statuses() |
|
417 | + { |
|
418 | + return $this->get_model()->get_custom_post_statuses(); |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @return mixed |
|
424 | + */ |
|
425 | + public function get_all_post_statuses() |
|
426 | + { |
|
427 | + return $this->get_model()->get_status_array(); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
433 | + * |
|
434 | + * @return array |
|
435 | + */ |
|
436 | + public function __sleep() |
|
437 | + { |
|
438 | + $properties_to_serialize = parent::__sleep(); |
|
439 | + $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
440 | + return $properties_to_serialize; |
|
441 | + } |
|
442 | 442 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function wp_post() |
41 | 41 | { |
42 | 42 | global $wpdb; |
43 | - if (! $this->_wp_post instanceof WP_Post) { |
|
43 | + if ( ! $this->_wp_post instanceof WP_Post) { |
|
44 | 44 | if ($this->ID()) { |
45 | 45 | $this->_wp_post = get_post($this->ID()); |
46 | 46 | } else { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | // and let's make retrieving the EE CPT object easy too |
67 | 67 | $classname = get_class($this); |
68 | - if (! isset($this->_wp_post->{$classname})) { |
|
68 | + if ( ! isset($this->_wp_post->{$classname})) { |
|
69 | 69 | $this->_wp_post->{$classname} = $this; |
70 | 70 | } |
71 | 71 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function remove_relation_to_term_taxonomy($term_taxonomy) |
146 | 146 | { |
147 | - if (! $term_taxonomy) { |
|
147 | + if ( ! $term_taxonomy) { |
|
148 | 148 | EE_Error::add_error( |
149 | 149 | sprintf( |
150 | 150 | __( |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | { |
226 | 226 | // first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
227 | 227 | $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
228 | - $cache_key = is_array($size) ? implode('_', $size) . $attr_key : $size . $attr_key; |
|
229 | - $this->_feature_image[ $cache_key ] = isset($this->_feature_image[ $cache_key ]) |
|
230 | - ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | - return $this->_feature_image[ $cache_key ]; |
|
228 | + $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key; |
|
229 | + $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) |
|
230 | + ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
231 | + return $this->_feature_image[$cache_key]; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | foreach ($related_obj_names as $related_name) { |
296 | 296 | // related_obj_name so we're saving a revision on an object related to this object |
297 | 297 | // do we have $where_query params for this related object? If we do then we include that. |
298 | - $cols_n_values = isset($where_query[ $related_name ]) ? $where_query[ $related_name ] : array(); |
|
298 | + $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array(); |
|
299 | 299 | $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
300 | 300 | $related_objs = $this->get_many_related($related_name, $where_params); |
301 | 301 | $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function update_post_meta($meta_key, $meta_value, $prev_value = null) |
346 | 346 | { |
347 | - if (! $this->ID()) { |
|
347 | + if ( ! $this->ID()) { |
|
348 | 348 | $this->save(); |
349 | 349 | } |
350 | 350 | return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function delete_post_meta($meta_key, $meta_value = '') |
380 | 380 | { |
381 | - if (! $this->ID()) { |
|
381 | + if ( ! $this->ID()) { |
|
382 | 382 | // there are obviously no postmetas for this if it's not saved |
383 | 383 | // so let's just report this as a success |
384 | 384 | return true; |
@@ -11,25 +11,25 @@ |
||
11 | 11 | class EE_Ticket_Price extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $props_n_values |
|
16 | - * @param string $timezone |
|
17 | - * @return EE_Ticket_Price|mixed |
|
18 | - */ |
|
19 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | - { |
|
21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values |
|
16 | + * @param string $timezone |
|
17 | + * @return EE_Ticket_Price|mixed |
|
18 | + */ |
|
19 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | + { |
|
21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param array $props_n_values |
|
28 | - * @param string $timezone |
|
29 | - * @return EE_Ticket_Price |
|
30 | - */ |
|
31 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | - { |
|
33 | - return new self($props_n_values, true, $timezone); |
|
34 | - } |
|
26 | + /** |
|
27 | + * @param array $props_n_values |
|
28 | + * @param string $timezone |
|
29 | + * @return EE_Ticket_Price |
|
30 | + */ |
|
31 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | + { |
|
33 | + return new self($props_n_values, true, $timezone); |
|
34 | + } |
|
35 | 35 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | class EE_Ticket_Template extends EE_Base_Class |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @param array $props_n_values |
|
17 | - * @param string $timezone |
|
18 | - * @return EE_Ticket_Template|mixed |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | - { |
|
22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | - } |
|
15 | + /** |
|
16 | + * @param array $props_n_values |
|
17 | + * @param string $timezone |
|
18 | + * @return EE_Ticket_Template|mixed |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | + { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param array $props_n_values |
|
29 | - * @param string $timezone |
|
30 | - * @return EE_Ticket_Template |
|
31 | - */ |
|
32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | - { |
|
34 | - return new self($props_n_values, true, $timezone); |
|
35 | - } |
|
27 | + /** |
|
28 | + * @param array $props_n_values |
|
29 | + * @param string $timezone |
|
30 | + * @return EE_Ticket_Template |
|
31 | + */ |
|
32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | + { |
|
34 | + return new self($props_n_values, true, $timezone); |
|
35 | + } |
|
36 | 36 | } |
@@ -10,115 +10,115 @@ |
||
10 | 10 | class EE_Extra_Meta extends EE_Base_Class |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $props_n_values |
|
15 | - * @return EE_Extra_Meta|mixed |
|
16 | - */ |
|
17 | - public static function new_instance($props_n_values = array()) |
|
18 | - { |
|
19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | - return $has_object ? $has_object : new self($props_n_values); |
|
21 | - } |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param array $props_n_values |
|
26 | - * @return EE_Extra_Meta |
|
27 | - */ |
|
28 | - public static function new_instance_from_db($props_n_values = array()) |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Gets FK_ID |
|
36 | - * |
|
37 | - * @return int |
|
38 | - */ |
|
39 | - public function FK_ID() |
|
40 | - { |
|
41 | - return $this->get('FK_ID'); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Sets FK_ID |
|
47 | - * |
|
48 | - * @param int $FK_ID |
|
49 | - * @return boolean |
|
50 | - */ |
|
51 | - public function set_FK_ID($FK_ID) |
|
52 | - { |
|
53 | - $this->set('FK_ID', $FK_ID); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Gets model |
|
59 | - * |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function model() |
|
63 | - { |
|
64 | - return $this->get('EXM_model'); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Sets model |
|
70 | - * |
|
71 | - * @param string $model |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - public function set_model($model) |
|
75 | - { |
|
76 | - $this->set('EXM_model', $model); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Gets key |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function key() |
|
86 | - { |
|
87 | - return $this->get('EXM_key'); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets key |
|
93 | - * |
|
94 | - * @param string $key |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public function set_key($key) |
|
98 | - { |
|
99 | - $this->set('EXM_key', $key); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Gets value |
|
105 | - * |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function value() |
|
109 | - { |
|
110 | - return $this->get('EXM_value'); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Sets value |
|
116 | - * |
|
117 | - * @param string $value |
|
118 | - * @return boolean |
|
119 | - */ |
|
120 | - public function set_value($value) |
|
121 | - { |
|
122 | - $this->set('EXM_value', $value); |
|
123 | - } |
|
13 | + /** |
|
14 | + * @param array $props_n_values |
|
15 | + * @return EE_Extra_Meta|mixed |
|
16 | + */ |
|
17 | + public static function new_instance($props_n_values = array()) |
|
18 | + { |
|
19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | + return $has_object ? $has_object : new self($props_n_values); |
|
21 | + } |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param array $props_n_values |
|
26 | + * @return EE_Extra_Meta |
|
27 | + */ |
|
28 | + public static function new_instance_from_db($props_n_values = array()) |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Gets FK_ID |
|
36 | + * |
|
37 | + * @return int |
|
38 | + */ |
|
39 | + public function FK_ID() |
|
40 | + { |
|
41 | + return $this->get('FK_ID'); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Sets FK_ID |
|
47 | + * |
|
48 | + * @param int $FK_ID |
|
49 | + * @return boolean |
|
50 | + */ |
|
51 | + public function set_FK_ID($FK_ID) |
|
52 | + { |
|
53 | + $this->set('FK_ID', $FK_ID); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Gets model |
|
59 | + * |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function model() |
|
63 | + { |
|
64 | + return $this->get('EXM_model'); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Sets model |
|
70 | + * |
|
71 | + * @param string $model |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + public function set_model($model) |
|
75 | + { |
|
76 | + $this->set('EXM_model', $model); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Gets key |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function key() |
|
86 | + { |
|
87 | + return $this->get('EXM_key'); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets key |
|
93 | + * |
|
94 | + * @param string $key |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public function set_key($key) |
|
98 | + { |
|
99 | + $this->set('EXM_key', $key); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Gets value |
|
105 | + * |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function value() |
|
109 | + { |
|
110 | + return $this->get('EXM_value'); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Sets value |
|
116 | + * |
|
117 | + * @param string $value |
|
118 | + * @return boolean |
|
119 | + */ |
|
120 | + public function set_value($value) |
|
121 | + { |
|
122 | + $this->set('EXM_value', $value); |
|
123 | + } |
|
124 | 124 | } |