@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
277 | 277 | { |
278 | 278 | $this->_initialize_collections(); |
279 | - return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
279 | + return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | { |
305 | 305 | $settings = array(); |
306 | 306 | if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
307 | - $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']) |
|
308 | - ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] |
|
307 | + $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings']) |
|
308 | + ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] |
|
309 | 309 | : array(); |
310 | 310 | } |
311 | 311 | return $settings; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | $this->_initialize_collections(); |
325 | 325 | return |
326 | 326 | ! empty($this->_active_message_types[$messenger_name]) |
327 | - && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']); |
|
327 | + && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types']); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | public function get_active_message_types_for_messenger($messenger_name) |
340 | 340 | { |
341 | 341 | $message_types = array(); |
342 | - if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
342 | + if ( ! $this->messenger_has_active_message_types($messenger_name)) { |
|
343 | 343 | return $message_types; |
344 | 344 | } |
345 | 345 | $installed_message_types = $this->installed_message_types(); |
@@ -364,11 +364,11 @@ discard block |
||
364 | 364 | $active_message_type_names = array(); |
365 | 365 | $this->_initialize_collections(); |
366 | 366 | foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
367 | - if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) { |
|
367 | + if ( ! isset($messenger_settings['settings'][$messenger.'-message_types'])) { |
|
368 | 368 | continue; |
369 | 369 | } |
370 | - foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) { |
|
371 | - if (! in_array($message_type_name, $active_message_type_names)) { |
|
370 | + foreach ($messenger_settings['settings'][$messenger.'-message_types'] as $message_type_name => $message_type_config) { |
|
371 | + if ( ! in_array($message_type_name, $active_message_type_names)) { |
|
372 | 372 | $active_message_type_names[] = $message_type_name; |
373 | 373 | } |
374 | 374 | } |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
445 | 445 | { |
446 | 446 | $valid_message_types = $messenger->get_valid_message_types(); |
447 | - if (! in_array($message_type_name, $valid_message_types)) { |
|
447 | + if ( ! in_array($message_type_name, $valid_message_types)) { |
|
448 | 448 | throw new EE_Error( |
449 | 449 | sprintf( |
450 | 450 | __( |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | */ |
568 | 568 | public function ensure_messenger_is_active($messenger_name, $update_option = true) |
569 | 569 | { |
570 | - if (! isset($this->_active_messengers[$messenger_name])) { |
|
570 | + if ( ! isset($this->_active_messengers[$messenger_name])) { |
|
571 | 571 | try { |
572 | 572 | $this->activate_messenger($messenger_name, array(), $update_option); |
573 | 573 | } catch (EE_Error $e) { |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | $this->ensure_messenger_is_active($messenger_name, $update_option); |
613 | 613 | } |
614 | 614 | |
615 | - if (! empty($not_installed_messenger)) { |
|
615 | + if ( ! empty($not_installed_messenger)) { |
|
616 | 616 | EE_Error::add_error( |
617 | 617 | sprintf( |
618 | 618 | __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | //ensure messenger is active (that's an inherent coupling between active message types and the |
644 | 644 | //messenger they are being activated for. |
645 | 645 | try { |
646 | - if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
646 | + if ( ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
647 | 647 | //all is good so let's just get it active |
648 | 648 | $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
649 | 649 | } |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | */ |
672 | 672 | public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) |
673 | 673 | { |
674 | - $message_type_names = (array)$message_type_names; |
|
674 | + $message_type_names = (array) $message_type_names; |
|
675 | 675 | foreach ($message_type_names as $message_type_name) { |
676 | 676 | // note, intentionally not updating option here because we're in a loop. |
677 | 677 | // We'll follow the instructions of the incoming $update_option argument after the loop. |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | //generate new templates if necessary and ensure all related templates that are already in the database are |
718 | 718 | //marked active. Note, this will also deactivate a message type for a messenger if the template |
719 | 719 | //cannot be successfully created during its attempt (only happens for global template attempts). |
720 | - if (! empty($message_type_names)) { |
|
720 | + if ( ! empty($message_type_names)) { |
|
721 | 721 | $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
722 | 722 | EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
723 | 723 | } |
@@ -743,10 +743,10 @@ discard block |
||
743 | 743 | //only override _active_message_types when an explicit array of $message_type_names has been provided. |
744 | 744 | $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name]) |
745 | 745 | ? $messenger->get_default_message_types() |
746 | - : (array)$message_type_names; |
|
746 | + : (array) $message_type_names; |
|
747 | 747 | |
748 | 748 | //now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
749 | - if (! isset($this->_active_message_types[$messenger->name])) { |
|
749 | + if ( ! isset($this->_active_message_types[$messenger->name])) { |
|
750 | 750 | $this->_active_message_types[$messenger->name]['settings'] = array(); |
751 | 751 | } |
752 | 752 | |
@@ -792,12 +792,12 @@ discard block |
||
792 | 792 | $existing_settings[$field] = $new_settings[$field]; |
793 | 793 | continue; |
794 | 794 | } |
795 | - if (! isset($existing_settings[$field])) { |
|
795 | + if ( ! isset($existing_settings[$field])) { |
|
796 | 796 | $existing_settings[$field] = $values['default']; |
797 | 797 | } |
798 | 798 | } |
799 | 799 | } |
800 | - $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
800 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -818,11 +818,11 @@ discard block |
||
818 | 818 | } |
819 | 819 | |
820 | 820 | // make sure this messenger has a record in the has_activated array |
821 | - if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
821 | + if ( ! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
822 | 822 | $this->_has_activated_messengers_and_message_types[$messenger->name] = array(); |
823 | 823 | } |
824 | 824 | // check if message type has already been added |
825 | - if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
825 | + if ( ! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
826 | 826 | $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name; |
827 | 827 | } |
828 | 828 | } |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | $messenger = $this->get_messenger($messenger_name); |
842 | 842 | if ($messenger instanceof EE_messenger) { |
843 | 843 | $msgr_settings = $messenger->get_admin_settings_fields(); |
844 | - if (! empty($msgr_settings)) { |
|
844 | + if ( ! empty($msgr_settings)) { |
|
845 | 845 | foreach ($msgr_settings as $field => $value) { |
846 | 846 | //is there a new setting for this? |
847 | 847 | if (isset($new_settings[$field])) { |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | continue; |
850 | 850 | } |
851 | 851 | //only set the default if it isn't already set. |
852 | - if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
852 | + if ( ! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
853 | 853 | $this->_active_message_types[$messenger->name]['settings'][$field] = $value; |
854 | 854 | } |
855 | 855 | } |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | } |
894 | 894 | foreach ($this->_active_message_types as $messenger_name => $settings) { |
895 | 895 | unset( |
896 | - $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name] |
|
896 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name] |
|
897 | 897 | ); |
898 | 898 | |
899 | 899 | //we always record (even on deactivation) that a message type has been activated because there should at |
@@ -919,7 +919,7 @@ discard block |
||
919 | 919 | { |
920 | 920 | $this->_initialize_collections(); |
921 | 921 | if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
922 | - unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
922 | + unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name.'-message_types'][$message_type_name]); |
|
923 | 923 | } |
924 | 924 | $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name), |
925 | 925 | array($message_type_name)); |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | $all_message_types_valid = true; |
1014 | 1014 | //loop through list of active message types and verify they are installed. |
1015 | 1015 | foreach ($list_of_active_message_type_names as $message_type_name) { |
1016 | - if (! isset($installed_message_types[$message_type_name])) { |
|
1016 | + if ( ! isset($installed_message_types[$message_type_name])) { |
|
1017 | 1017 | $this->remove_message_type_has_been_activated_from_all_messengers( |
1018 | 1018 | $message_type_name, |
1019 | 1019 | true |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | $message_type_name, |
1088 | 1088 | $consider_current_state = false |
1089 | 1089 | ) { |
1090 | - foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1090 | + foreach (array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1091 | 1091 | $this->remove_message_type_has_been_activated_for_messenger( |
1092 | 1092 | $message_type_name, |
1093 | 1093 | $messenger_name, |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,1117 +17,1117 @@ discard block |
||
17 | 17 | class EE_Message_Resource_Manager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * This option in the database is used to keep a record of message types that have been activated for a messenger |
|
22 | - * at some point in the history of the site. It is utilized by the implementation of the 'force' flag in |
|
23 | - * EE_Register_Message_Type. The force flag is an indication of whether a message type should be activated by |
|
24 | - * default when the message type is registered. However, if a user has explicitly deactivated a message type, then |
|
25 | - * the force flag is ignored. The method by which the code knows whether to ignore this flag is via this option. |
|
26 | - * Note, that this is NOT a historical record. Its entirely possible for a message type to have been activated for |
|
27 | - * a messenger and yet not have a record in this option. This occurs when a message type is inactivated through an |
|
28 | - * automated process (when an add-on registering the message type deactivates, or when some other code calls the |
|
29 | - * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure |
|
30 | - * the "force" flag is respected if that message type is later re-registered. |
|
31 | - * |
|
32 | - * This option should NOT be used to determine the current "active" state of a message type for a given messenger. |
|
33 | - * |
|
34 | - * The name of this option (and related methods/properties) is due to matching the original intended purpose for the |
|
35 | - * option that got superseded by later behaviour requirements. |
|
36 | - */ |
|
37 | - const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type boolean $_initialized |
|
41 | - */ |
|
42 | - protected $_initialized = false; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Messenger_Collection $_messenger_collection_loader |
|
46 | - */ |
|
47 | - protected $_messenger_collection_loader; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Message_Type_Collection $_message_type_collection_loader |
|
51 | - */ |
|
52 | - protected $_message_type_collection_loader; |
|
53 | - |
|
54 | - /** |
|
55 | - * @type EEM_Message_Template_Group $_message_template_group_model |
|
56 | - */ |
|
57 | - protected $_message_template_group_model; |
|
58 | - |
|
59 | - /** |
|
60 | - * @type EE_messenger[] |
|
61 | - */ |
|
62 | - protected $_installed_messengers = array(); |
|
63 | - |
|
64 | - /** |
|
65 | - * @type EE_message_type[] |
|
66 | - */ |
|
67 | - protected $_installed_message_types = array(); |
|
68 | - |
|
69 | - /** |
|
70 | - * Array of active messengers. |
|
71 | - * Format is this: |
|
72 | - * array( |
|
73 | - * 'messenger_name' => EE_messenger |
|
74 | - * ) |
|
75 | - * |
|
76 | - * @type EE_messenger[] |
|
77 | - */ |
|
78 | - protected $_active_messengers = array(); |
|
79 | - |
|
80 | - /** |
|
81 | - * Formatted array of active message types grouped per messenger. |
|
82 | - * Format is this: |
|
83 | - * array( |
|
84 | - * 'messenger_name' => array( |
|
85 | - * 'settings' => array( |
|
86 | - * '{messenger_name}-message_types' => array( |
|
87 | - * 'message_type_name' => array() //variable array of settings corresponding to message type. |
|
88 | - * ) |
|
89 | - * ) |
|
90 | - * ) |
|
91 | - * ) |
|
92 | - * |
|
93 | - * @type array |
|
94 | - */ |
|
95 | - protected $_active_message_types = array(); |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * This holds the array of messengers and their corresponding message types that have |
|
100 | - * been activated on a site at some point. This is an important record that helps the messages system |
|
101 | - * not accidentally reactivate something that was intentionally deactivated by a user. |
|
102 | - * |
|
103 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
104 | - * |
|
105 | - * @type array |
|
106 | - */ |
|
107 | - protected $_has_activated_messengers_and_message_types = array(); |
|
108 | - |
|
109 | - /** |
|
110 | - * An array of unique message type contexts across all active message types. |
|
111 | - * The array will be indexed by either 'slugs' or 'all'. |
|
112 | - * The slugs index contains an array indexed by unique context slugs with the latest label representation for that |
|
113 | - * slug. array( |
|
114 | - * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
115 | - * ); |
|
116 | - * The all index returns an array in this format: |
|
117 | - * array( |
|
118 | - * 'message_type_name' => array( |
|
119 | - * 'context_slug' => array( |
|
120 | - * 'label' => 'localized label for context', |
|
121 | - * 'description' => 'localized description for context' |
|
122 | - * ) |
|
123 | - * ) |
|
124 | - * ); |
|
125 | - * |
|
126 | - * @type array |
|
127 | - */ |
|
128 | - protected $_contexts = array(); |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * EE_Message_Resource_Manager constructor. |
|
133 | - * |
|
134 | - * @param \EE_Messenger_Collection_Loader $Messenger_Collection_Loader |
|
135 | - * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader |
|
136 | - * @param \EEM_Message_Template_Group $Message_Template_Group_Model |
|
137 | - */ |
|
138 | - function __construct( |
|
139 | - EE_Messenger_Collection_Loader $Messenger_Collection_Loader, |
|
140 | - EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader, |
|
141 | - EEM_Message_Template_Group $Message_Template_Group_Model |
|
142 | - ) { |
|
143 | - $this->_messenger_collection_loader = $Messenger_Collection_Loader; |
|
144 | - $this->_message_type_collection_loader = $Message_Type_Collection_Loader; |
|
145 | - $this->_message_template_group_model = $Message_Template_Group_Model; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - protected function _initialize_collections() |
|
153 | - { |
|
154 | - if ($this->_initialized) { |
|
155 | - return; |
|
156 | - } |
|
157 | - $this->_initialized = true; |
|
158 | - $this->_messenger_collection_loader->load_messengers_from_folder(); |
|
159 | - $this->_message_type_collection_loader->load_message_types_from_folder(); |
|
160 | - $this->get_has_activated_messengers_option(true); |
|
161 | - $this->_set_active_messengers_and_message_types(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return EE_Messenger_Collection |
|
167 | - */ |
|
168 | - public function messenger_collection() |
|
169 | - { |
|
170 | - $this->_initialize_collections(); |
|
171 | - return $this->_messenger_collection_loader->messenger_collection(); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return EE_messenger[] |
|
177 | - */ |
|
178 | - public function active_messengers() |
|
179 | - { |
|
180 | - $this->_initialize_collections(); |
|
181 | - return $this->_active_messengers; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $messenger_name |
|
187 | - * @return \EE_messenger |
|
188 | - */ |
|
189 | - public function get_messenger($messenger_name) |
|
190 | - { |
|
191 | - return $this->messenger_collection()->get_by_info($messenger_name); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * This returns the corresponding EE_messenger object for the given string if it is active. |
|
197 | - * |
|
198 | - * @param string $messenger |
|
199 | - * @return EE_messenger | null |
|
200 | - */ |
|
201 | - public function get_active_messenger($messenger) |
|
202 | - { |
|
203 | - $this->_initialize_collections(); |
|
204 | - return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * @return \EE_messenger[] |
|
210 | - */ |
|
211 | - public function installed_messengers() |
|
212 | - { |
|
213 | - if (empty($this->_installed_messengers)) { |
|
214 | - $this->_installed_messengers = array(); |
|
215 | - $this->messenger_collection()->rewind(); |
|
216 | - while ($this->messenger_collection()->valid()) { |
|
217 | - $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current(); |
|
218 | - $this->messenger_collection()->next(); |
|
219 | - } |
|
220 | - } |
|
221 | - return $this->_installed_messengers; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @param string $messenger_name |
|
227 | - * @return \EE_messenger |
|
228 | - * @throws \EE_Error |
|
229 | - */ |
|
230 | - public function valid_messenger($messenger_name) |
|
231 | - { |
|
232 | - $messenger = $this->get_messenger($messenger_name); |
|
233 | - if ($messenger instanceof EE_messenger) { |
|
234 | - return $messenger; |
|
235 | - } |
|
236 | - throw new EE_Error( |
|
237 | - sprintf( |
|
238 | - __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'), |
|
239 | - $messenger_name |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return EE_Message_Type_Collection |
|
247 | - */ |
|
248 | - public function message_type_collection() |
|
249 | - { |
|
250 | - $this->_initialize_collections(); |
|
251 | - return $this->_message_type_collection_loader->message_type_collection(); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function active_message_types() |
|
259 | - { |
|
260 | - $this->_initialize_collections(); |
|
261 | - return $this->_active_message_types; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param string $message_type_name |
|
267 | - * @return \EE_message_type |
|
268 | - */ |
|
269 | - public function get_message_type($message_type_name) |
|
270 | - { |
|
271 | - return $this->message_type_collection()->get_by_info($message_type_name); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * This returns the EE_message_type from the active message types array ( if present ); |
|
277 | - * |
|
278 | - * @param string $messenger_name |
|
279 | - * @param string $message_type_name |
|
280 | - * @return \EE_message_type|null |
|
281 | - */ |
|
282 | - public function get_active_message_type_for_messenger($messenger_name, $message_type_name) |
|
283 | - { |
|
284 | - return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
285 | - ? $this->get_message_type($message_type_name) |
|
286 | - : null; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Returns whether the given message type is active for the given messenger. |
|
292 | - * |
|
293 | - * @param string $messenger_name |
|
294 | - * @param string $message_type_name |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
298 | - { |
|
299 | - $this->_initialize_collections(); |
|
300 | - return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns whether the given messenger is active. |
|
306 | - * |
|
307 | - * @param string $messenger_name the name of the messenger to check if active. |
|
308 | - * @return bool |
|
309 | - */ |
|
310 | - public function is_messenger_active($messenger_name) |
|
311 | - { |
|
312 | - $this->_initialize_collections(); |
|
313 | - return ! empty($this->_active_message_types[$messenger_name]); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * This returns any settings that might be on a message type for a messenger |
|
319 | - * |
|
320 | - * @param string $messenger_name The slug of the messenger |
|
321 | - * @param string $message_type_name The slug of the message type getting the settings for. |
|
322 | - * @return array |
|
323 | - */ |
|
324 | - public function get_message_type_settings_for_messenger($messenger_name, $message_type_name) |
|
325 | - { |
|
326 | - $settings = array(); |
|
327 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
328 | - $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']) |
|
329 | - ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] |
|
330 | - : array(); |
|
331 | - } |
|
332 | - return $settings; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Returns whether the given messenger name has active message types on it. |
|
338 | - * Infers whether the messenger is active or not as well. |
|
339 | - * |
|
340 | - * @param string $messenger_name |
|
341 | - * @return bool |
|
342 | - */ |
|
343 | - public function messenger_has_active_message_types($messenger_name) |
|
344 | - { |
|
345 | - $this->_initialize_collections(); |
|
346 | - return |
|
347 | - ! empty($this->_active_message_types[$messenger_name]) |
|
348 | - && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * This checks the _active_message_types property for any active message types |
|
354 | - * that are present for the given messenger and returns them. |
|
355 | - * |
|
356 | - * @since 4.9.0 |
|
357 | - * @param string $messenger_name The messenger being checked |
|
358 | - * @return EE_message_type[]|array (empty array if no active_message_types) |
|
359 | - */ |
|
360 | - public function get_active_message_types_for_messenger($messenger_name) |
|
361 | - { |
|
362 | - $message_types = array(); |
|
363 | - if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
364 | - return $message_types; |
|
365 | - } |
|
366 | - $installed_message_types = $this->installed_message_types(); |
|
367 | - foreach ($installed_message_types as $message_type_name => $message_type) { |
|
368 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
369 | - $message_types[$message_type_name] = $message_type; |
|
370 | - } |
|
371 | - } |
|
372 | - return $message_types; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * This does NOT return the _active_message_types property but |
|
378 | - * simply returns an array of active message type names from that property. |
|
379 | - * (The _active_message_types property is indexed by messenger and active message_types per messenger). |
|
380 | - * |
|
381 | - * @return array message_type references (string) |
|
382 | - */ |
|
383 | - public function list_of_active_message_types() |
|
384 | - { |
|
385 | - $active_message_type_names = array(); |
|
386 | - $this->_initialize_collections(); |
|
387 | - foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
|
388 | - if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) { |
|
389 | - continue; |
|
390 | - } |
|
391 | - foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) { |
|
392 | - if (! in_array($message_type_name, $active_message_type_names)) { |
|
393 | - $active_message_type_names[] = $message_type_name; |
|
394 | - } |
|
395 | - } |
|
396 | - } |
|
397 | - return $active_message_type_names; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Same as list_of_active_message_types() except this returns actual EE_message_type objects |
|
403 | - * |
|
404 | - * @since 4.9.0 |
|
405 | - * @return \EE_message_type[] |
|
406 | - */ |
|
407 | - public function get_active_message_type_objects() |
|
408 | - { |
|
409 | - $active_message_types = array(); |
|
410 | - $installed_message_types = $this->installed_message_types(); |
|
411 | - $active_message_type_names = $this->list_of_active_message_types(); |
|
412 | - foreach ($active_message_type_names as $active_message_type_name) { |
|
413 | - if (isset($installed_message_types[$active_message_type_name])) { |
|
414 | - $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name]; |
|
415 | - } |
|
416 | - } |
|
417 | - return $active_message_types; |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * @return \EE_message_type[] |
|
423 | - */ |
|
424 | - public function installed_message_types() |
|
425 | - { |
|
426 | - if (empty($this->_installed_message_types)) { |
|
427 | - $this->message_type_collection()->rewind(); |
|
428 | - while ($this->message_type_collection()->valid()) { |
|
429 | - $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current(); |
|
430 | - $this->message_type_collection()->next(); |
|
431 | - } |
|
432 | - } |
|
433 | - return $this->_installed_message_types; |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * @param string $message_type_name |
|
439 | - * @return \EE_message_type |
|
440 | - * @throws \EE_Error |
|
441 | - */ |
|
442 | - public function valid_message_type($message_type_name) |
|
443 | - { |
|
444 | - $message_type = $this->get_message_type($message_type_name); |
|
445 | - if ($message_type instanceof EE_message_type) { |
|
446 | - return $message_type; |
|
447 | - } |
|
448 | - throw new EE_Error( |
|
449 | - sprintf( |
|
450 | - __('The "%1$s" message type is either invalid or not installed', 'event_espresso'), |
|
451 | - $message_type_name |
|
452 | - ) |
|
453 | - ); |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * valid_message_type_for_messenger |
|
459 | - * |
|
460 | - * @param EE_messenger $messenger |
|
461 | - * @param string $message_type_name |
|
462 | - * @return boolean |
|
463 | - * @throws \EE_Error |
|
464 | - */ |
|
465 | - public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
|
466 | - { |
|
467 | - $valid_message_types = $messenger->get_valid_message_types(); |
|
468 | - if (! in_array($message_type_name, $valid_message_types)) { |
|
469 | - throw new EE_Error( |
|
470 | - sprintf( |
|
471 | - __( |
|
472 | - 'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger. Double-check the spelling and verify that message type has been registered as a valid type with the messenger.', |
|
473 | - 'event_espresso' |
|
474 | - ), |
|
475 | - $message_type_name, |
|
476 | - __METHOD__, |
|
477 | - $messenger->name |
|
478 | - ) |
|
479 | - ); |
|
480 | - } |
|
481 | - return true; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Used to return active messengers array stored in the wp options table. |
|
487 | - * If no value is present in the option then an empty array is returned. |
|
488 | - * |
|
489 | - * @param bool $reset If true then we ignore whether the option is cached on the _active_message_types |
|
490 | - * property and pull directly from the db. Otherwise whatever is currently on the |
|
491 | - * $_active_message_types property is pulled. |
|
492 | - * @return array |
|
493 | - */ |
|
494 | - public function get_active_messengers_option($reset = false) |
|
495 | - { |
|
496 | - if ($reset) { |
|
497 | - $this->_active_message_types = get_option('ee_active_messengers', array()); |
|
498 | - } |
|
499 | - return $this->_active_message_types; |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Used to update the active messengers array stored in the wp options table. |
|
505 | - * |
|
506 | - * @param array $active_messenger_settings Incoming data to save. If empty, then the internal cached property |
|
507 | - * representing this data is used. |
|
508 | - * @return bool FALSE if not updated, TRUE if updated. |
|
509 | - */ |
|
510 | - public function update_active_messengers_option($active_messenger_settings = array()) |
|
511 | - { |
|
512 | - $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings; |
|
513 | - //make sure _active_message_types is updated (this is the internal cache for the settings). |
|
514 | - $this->_active_message_types = $active_messenger_settings; |
|
515 | - return update_option('ee_active_messengers', $active_messenger_settings); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Used to return has activated message types for messengers array stored in the wp options table. |
|
521 | - * If no value is present in the option then an empty array is returned. |
|
522 | - * The value is cached on the $_has_activated_messengers_and_message_types property for future calls. |
|
523 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
524 | - * |
|
525 | - * @param bool $reset Used to indicate that any cached value should be ignored. |
|
526 | - * @return array |
|
527 | - */ |
|
528 | - public function get_has_activated_messengers_option($reset = false) |
|
529 | - { |
|
530 | - if ($reset || empty($this->_has_activated_messengers_and_message_types)) { |
|
531 | - $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array()); |
|
532 | - } |
|
533 | - return $this->_has_activated_messengers_and_message_types; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Used to update the has activated option in the db. |
|
539 | - * |
|
540 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
541 | - * |
|
542 | - * @param array $has_activated_messengers Incoming data to save. If empty, then the internal cached property |
|
543 | - * representing this data is used. |
|
544 | - * @return bool FALSE if not updated, TRUE if updated. |
|
545 | - */ |
|
546 | - public function update_has_activated_messengers_option($has_activated_messengers = array()) |
|
547 | - { |
|
548 | - //make sure the option has been retrieved from first so we don't overwrite it accidentally. |
|
549 | - if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) { |
|
550 | - $this->get_has_activated_messengers_option(); |
|
551 | - } |
|
552 | - $has_activated_messengers = empty($has_activated_messengers) |
|
553 | - ? $this->_has_activated_messengers_and_message_types |
|
554 | - : $has_activated_messengers; |
|
555 | - return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * wrapper for _set_active_messengers_and_message_types() |
|
561 | - */ |
|
562 | - public function reset_active_messengers_and_message_types() |
|
563 | - { |
|
564 | - $this->_set_active_messengers_and_message_types(); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * Generate list of active messengers and message types from collection. |
|
570 | - * This sets up the active messengers from what is present in the database. |
|
571 | - */ |
|
572 | - protected function _set_active_messengers_and_message_types() |
|
573 | - { |
|
574 | - //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n"; |
|
575 | - // list of activated messengers as set via the admin |
|
576 | - // note calling `get_active_messengers_options` also initializes the _active_message_types property. |
|
577 | - $this->get_active_messengers_option(true); |
|
578 | - $this->ensure_messengers_are_active(array(), false, true); |
|
579 | - $this->update_active_messengers_option(); |
|
580 | - $this->update_has_activated_messengers_option(); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Ensures that the specified messenger is currently active. |
|
586 | - * If not, activates it and its default message types. |
|
587 | - * |
|
588 | - * @param string $messenger_name |
|
589 | - * @param bool $update_option Whether to update the option in the db or not. |
|
590 | - * @return boolean true if either already active or successfully activated. |
|
591 | - */ |
|
592 | - public function ensure_messenger_is_active($messenger_name, $update_option = true) |
|
593 | - { |
|
594 | - if (! isset($this->_active_messengers[$messenger_name])) { |
|
595 | - try { |
|
596 | - $this->activate_messenger($messenger_name, array(), $update_option); |
|
597 | - } catch (EE_Error $e) { |
|
598 | - EE_Error::add_error( |
|
599 | - $e->getMessage(), |
|
600 | - __FILE__, |
|
601 | - __FUNCTION__, |
|
602 | - __LINE__ |
|
603 | - ); |
|
604 | - return false; |
|
605 | - } |
|
606 | - } |
|
607 | - return true; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * This ensures the given array of messenger names is active in the system. |
|
613 | - * Note, this method will not activate any NEW message types for the messenger when it is called. Instead, |
|
614 | - * it will automatically activate the default message types for the messenger if its not active. |
|
615 | - * |
|
616 | - * @param array $messenger_names Array of messenger names for messengers to be activated. If an empty array |
|
617 | - * (default) then will attempt to set the active messengers from the |
|
618 | - * activated_messengers option |
|
619 | - * (stored in $_active_message_types property). |
|
620 | - * @param bool $update_option Whether to update the related active messengers option. |
|
621 | - * @param bool $verify Whether to verify the messengers are installed before activating. Note if this is |
|
622 | - * set to true and a messenger is indicated as active, but is NOT installed, then it |
|
623 | - * will automatically be deactivated. |
|
624 | - */ |
|
625 | - public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false) |
|
626 | - { |
|
627 | - $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names; |
|
628 | - |
|
629 | - $not_installed = array(); |
|
630 | - foreach ($messenger_names as $messenger_name) { |
|
631 | - if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) { |
|
632 | - $not_installed[] = $messenger_name; |
|
633 | - $this->deactivate_messenger($messenger_name); |
|
634 | - continue; |
|
635 | - } |
|
636 | - $this->ensure_messenger_is_active($messenger_name, $update_option); |
|
637 | - } |
|
638 | - |
|
639 | - if (! empty($not_installed_messenger)) { |
|
640 | - EE_Error::add_error( |
|
641 | - sprintf( |
|
642 | - __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
|
643 | - '<br />', |
|
644 | - implode(', ', $not_installed_messenger) |
|
645 | - ), |
|
646 | - __FILE__, __FUNCTION__, __LINE__ |
|
647 | - ); |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Ensures that the specified message type for the given messenger is currently active, if not activates it. |
|
654 | - * This ALSO ensures that the given messenger is active as well! |
|
655 | - * |
|
656 | - * @param string $message_type_name message type name. |
|
657 | - * @param $messenger_name |
|
658 | - * @param bool $update_option Whether to update the option in the db or not. |
|
659 | - * @return bool Returns true if already is active or if was activated successfully. |
|
660 | - * @throws \EE_Error |
|
661 | - */ |
|
662 | - public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true) |
|
663 | - { |
|
664 | - // grab the messenger to work with. |
|
665 | - $messenger = $this->valid_messenger($messenger_name); |
|
666 | - if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) { |
|
667 | - //ensure messenger is active (that's an inherent coupling between active message types and the |
|
668 | - //messenger they are being activated for. |
|
669 | - try { |
|
670 | - if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
671 | - //all is good so let's just get it active |
|
672 | - $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
|
673 | - } |
|
674 | - } catch (EE_Error $e) { |
|
675 | - EE_Error::add_error( |
|
676 | - $e->getMessage(), |
|
677 | - __FILE__, |
|
678 | - __FUNCTION__, |
|
679 | - __LINE__ |
|
680 | - ); |
|
681 | - return false; |
|
682 | - } |
|
683 | - } |
|
684 | - return true; |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a |
|
690 | - * messenger are active in one go. |
|
691 | - * |
|
692 | - * @param array $message_type_names Array of message type names to ensure are active. |
|
693 | - * @param string $messenger_name The name of the messenger that the message types are to be activated on. |
|
694 | - * @param bool $update_option Whether to persist the activation to the database or not (default true). |
|
695 | - */ |
|
696 | - public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) |
|
697 | - { |
|
698 | - $message_type_names = (array)$message_type_names; |
|
699 | - foreach ($message_type_names as $message_type_name) { |
|
700 | - // note, intentionally not updating option here because we're in a loop. |
|
701 | - // We'll follow the instructions of the incoming $update_option argument after the loop. |
|
702 | - $this->ensure_message_type_is_active($message_type_name, $messenger_name, false); |
|
703 | - } |
|
704 | - if ($update_option) { |
|
705 | - $this->update_active_messengers_option(); |
|
706 | - $this->update_has_activated_messengers_option(); |
|
707 | - } |
|
708 | - } |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * Activates the specified messenger. |
|
713 | - * |
|
714 | - * @param string $messenger_name |
|
715 | - * @param array $message_type_names An array of message type names to activate with this messenger. |
|
716 | - * If included we do NOT setup the default message types |
|
717 | - * (assuming they are already setup.) |
|
718 | - * @param bool $update_active_messengers_option |
|
719 | - * @return array of generated templates |
|
720 | - * @throws \EE_Error |
|
721 | - */ |
|
722 | - public function activate_messenger( |
|
723 | - $messenger_name, |
|
724 | - $message_type_names = array(), |
|
725 | - $update_active_messengers_option = true |
|
726 | - ) { |
|
727 | - $templates = array(); |
|
728 | - // grab the messenger to work with. |
|
729 | - $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
|
730 | - // it's inactive. Activate it. |
|
731 | - if ($messenger instanceof EE_messenger) { |
|
732 | - $this->_active_messengers[$messenger->name] = $messenger; |
|
733 | - //activate incoming message types set to be activated with messenger. |
|
734 | - $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
|
735 | - // setup any initial settings for the messenger if necessary. |
|
736 | - $this->add_settings_for_messenger($messenger->name); |
|
737 | - if ($update_active_messengers_option) { |
|
738 | - $this->update_active_messengers_option(); |
|
739 | - $this->update_has_activated_messengers_option(); |
|
740 | - } |
|
741 | - //generate new templates if necessary and ensure all related templates that are already in the database are |
|
742 | - //marked active. Note, this will also deactivate a message type for a messenger if the template |
|
743 | - //cannot be successfully created during its attempt (only happens for global template attempts). |
|
744 | - if (! empty($message_type_names)) { |
|
745 | - $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
|
746 | - EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
|
747 | - } |
|
748 | - } |
|
749 | - return $templates; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Activates given message types for the given EE_messenger object. |
|
755 | - * Note: (very important) This method does not persist the activation to the database. |
|
756 | - * See code implementing this method in this class for examples of how to persist. |
|
757 | - * |
|
758 | - * @param \EE_messenger $messenger |
|
759 | - * @param array $message_type_names |
|
760 | - * @return array |
|
761 | - */ |
|
762 | - protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array()) |
|
763 | - { |
|
764 | - //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means |
|
765 | - //things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
|
766 | - //So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
|
767 | - //only override _active_message_types when an explicit array of $message_type_names has been provided. |
|
768 | - $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name]) |
|
769 | - ? $messenger->get_default_message_types() |
|
770 | - : (array)$message_type_names; |
|
771 | - |
|
772 | - //now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
|
773 | - if (! isset($this->_active_message_types[$messenger->name])) { |
|
774 | - $this->_active_message_types[$messenger->name]['settings'] = array(); |
|
775 | - } |
|
776 | - |
|
777 | - if ($message_type_names) { |
|
778 | - // cycle thru message types |
|
779 | - foreach ($message_type_names as $message_type_name) { |
|
780 | - //only register the message type as active IF it isn't already active |
|
781 | - //and if its actually installed. |
|
782 | - if ( |
|
783 | - ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
784 | - ) { |
|
785 | - $this->add_settings_for_message_type($messenger->name, $message_type_name); |
|
786 | - $this->_set_messenger_has_activated_message_type( |
|
787 | - $messenger, |
|
788 | - $message_type_name |
|
789 | - ); |
|
790 | - } |
|
791 | - } |
|
792 | - } |
|
793 | - return $message_type_names; |
|
794 | - } |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * add_settings_for_message_type |
|
799 | - * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
800 | - * $this->update_active_messengers_option to persist. |
|
801 | - * |
|
802 | - * @param string $messenger_name The name of the messenger adding the settings for |
|
803 | - * @param string $message_type_name The name of the message type adding the settings for |
|
804 | - * @param array $new_settings Any new settings being set for the message type and messenger |
|
805 | - */ |
|
806 | - public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array()) |
|
807 | - { |
|
808 | - // get installed message type from collection |
|
809 | - $message_type = $this->message_type_collection()->get_by_info($message_type_name); |
|
810 | - $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name); |
|
811 | - //we need to setup any initial settings for message types |
|
812 | - if ($message_type instanceof EE_message_type) { |
|
813 | - $default_settings = $message_type->get_admin_settings_fields(); |
|
814 | - foreach ($default_settings as $field => $values) { |
|
815 | - if (isset($new_settings[$field])) { |
|
816 | - $existing_settings[$field] = $new_settings[$field]; |
|
817 | - continue; |
|
818 | - } |
|
819 | - if (! isset($existing_settings[$field])) { |
|
820 | - $existing_settings[$field] = $values['default']; |
|
821 | - } |
|
822 | - } |
|
823 | - } |
|
824 | - $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger |
|
830 | - * and message type. |
|
831 | - * |
|
832 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
833 | - * |
|
834 | - * @access protected |
|
835 | - * @param \EE_messenger $messenger |
|
836 | - * @param string $message_type_name |
|
837 | - */ |
|
838 | - protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name) |
|
839 | - { |
|
840 | - |
|
841 | - //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized |
|
842 | - if (empty($this->_has_activated_messengers_and_message_types)) { |
|
843 | - $this->get_has_activated_messengers_option(); |
|
844 | - } |
|
845 | - |
|
846 | - // make sure this messenger has a record in the has_activated array |
|
847 | - if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
848 | - $this->_has_activated_messengers_and_message_types[$messenger->name] = array(); |
|
849 | - } |
|
850 | - // check if message type has already been added |
|
851 | - if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
852 | - $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name; |
|
853 | - } |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * add_settings_for_messenger |
|
859 | - * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
860 | - * $this->update_active_messengers_option to persist. |
|
861 | - * |
|
862 | - * @param string $messenger_name The name of the messenger the settings is being added for. |
|
863 | - * @param array $new_settings An array of settings to update the existing settings. |
|
864 | - */ |
|
865 | - public function add_settings_for_messenger($messenger_name, $new_settings = array()) |
|
866 | - { |
|
867 | - $messenger = $this->get_messenger($messenger_name); |
|
868 | - if ($messenger instanceof EE_messenger) { |
|
869 | - $msgr_settings = $messenger->get_admin_settings_fields(); |
|
870 | - if (! empty($msgr_settings)) { |
|
871 | - foreach ($msgr_settings as $field => $value) { |
|
872 | - //is there a new setting for this? |
|
873 | - if (isset($new_settings[$field])) { |
|
874 | - $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field]; |
|
875 | - continue; |
|
876 | - } |
|
877 | - //only set the default if it isn't already set. |
|
878 | - if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
879 | - $this->_active_message_types[$messenger->name]['settings'][$field] = $value; |
|
880 | - } |
|
881 | - } |
|
882 | - } |
|
883 | - } |
|
884 | - } |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * deactivate_messenger |
|
889 | - * |
|
890 | - * @param string|EE_messenger $messenger_name name of messenger |
|
891 | - * @return void |
|
892 | - */ |
|
893 | - public function deactivate_messenger($messenger_name) |
|
894 | - { |
|
895 | - $this->_initialize_collections(); |
|
896 | - if ($messenger_name instanceof EE_messenger) { |
|
897 | - $messenger_name = $messenger_name->name; |
|
898 | - } |
|
899 | - unset($this->_active_messengers[$messenger_name]); |
|
900 | - unset($this->_active_message_types[$messenger_name]); |
|
901 | - $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
|
902 | - $this->update_active_messengers_option(); |
|
903 | - } |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * Deactivates a message type (note this will deactivate across all messenger's it is active on. |
|
908 | - * |
|
909 | - * @param string $message_type_name name of message type being deactivated |
|
910 | - * @param bool $set_has_active_record By default we always record the has_active record when deactivating a message |
|
911 | - * type. However, this can be overridden if we don't want this set (usually when |
|
912 | - * this is called as a part of deregistration of a custom message type) |
|
913 | - */ |
|
914 | - public function deactivate_message_type($message_type_name, $set_has_active_record = true) |
|
915 | - { |
|
916 | - $this->_initialize_collections(); |
|
917 | - if ($message_type_name instanceof EE_message_type) { |
|
918 | - $message_type_name = $message_type_name->name; |
|
919 | - } |
|
920 | - foreach ($this->_active_message_types as $messenger_name => $settings) { |
|
921 | - unset( |
|
922 | - $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name] |
|
923 | - ); |
|
924 | - |
|
925 | - //we always record (even on deactivation) that a message type has been activated because there should at |
|
926 | - //least be a record in the "has_activated" option that it WAS active at one point. |
|
927 | - if ($set_has_active_record) { |
|
928 | - $messenger = $this->get_messenger($messenger_name); |
|
929 | - $this->_set_messenger_has_activated_message_type($messenger, $message_type_name); |
|
930 | - } |
|
931 | - } |
|
932 | - $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name); |
|
933 | - $this->update_active_messengers_option(); |
|
934 | - $this->update_has_activated_messengers_option(); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Deactivates a message type for a specific messenger as opposed to all messengers. |
|
940 | - * |
|
941 | - * @param string $message_type_name Name of message type being deactivated. |
|
942 | - * @param string $messenger_name Name of messenger the message type is being deactivated for. |
|
943 | - */ |
|
944 | - public function deactivate_message_type_for_messenger($message_type_name, $messenger_name) |
|
945 | - { |
|
946 | - $this->_initialize_collections(); |
|
947 | - if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
948 | - unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
949 | - } |
|
950 | - $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name), |
|
951 | - array($message_type_name)); |
|
952 | - $this->update_active_messengers_option(); |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * Used to verify if a message can be sent for the given messenger and message type |
|
958 | - * and that it is a generating messenger (used for generating message templates). |
|
959 | - * |
|
960 | - * @param EE_messenger $messenger messenger used in trigger |
|
961 | - * @param EE_message_type $message_type message type used in trigger |
|
962 | - * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
963 | - */ |
|
964 | - public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
965 | - { |
|
966 | - //get the $messengers the message type says it can be used with. |
|
967 | - foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) { |
|
968 | - if ( |
|
969 | - $messenger->name === $generating_messenger |
|
970 | - && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name) |
|
971 | - ) { |
|
972 | - return true; |
|
973 | - } |
|
974 | - } |
|
975 | - return false; |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - /** |
|
980 | - * This returns all the contexts that are registered by all message types. |
|
981 | - * If $slugs_only is true, |
|
982 | - * then just an array indexed by unique context slugs with the latest label representation for that slug. |
|
983 | - * array( |
|
984 | - * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
985 | - * ); |
|
986 | - * If $slugs_only is false, then the format is: |
|
987 | - * array( |
|
988 | - * 'message_type_name' => array( |
|
989 | - * 'context_slug' => array( |
|
990 | - * 'label' => 'localized label for context', |
|
991 | - * 'description' => 'localized description for context' |
|
992 | - * ) |
|
993 | - * ) |
|
994 | - * ); |
|
995 | - * Keep in mind that although different message types may share the same context slugs, |
|
996 | - * it is possible that the context is described differently by the message type. |
|
997 | - * |
|
998 | - * @since 4.9.0 |
|
999 | - * @param bool $slugs_only Whether to return an array of just slugs and labels (true) |
|
1000 | - * or all contexts indexed by message type. |
|
1001 | - * @return array |
|
1002 | - */ |
|
1003 | - public function get_all_contexts($slugs_only = true) |
|
1004 | - { |
|
1005 | - $key = $slugs_only ? 'slugs' : 'all'; |
|
1006 | - // check if contexts has been setup yet. |
|
1007 | - if (empty($this->_contexts[$key])) { |
|
1008 | - // So let's get all active message type objects and loop through to get all unique contexts |
|
1009 | - foreach ($this->get_active_message_type_objects() as $message_type) { |
|
1010 | - if ($message_type instanceof EE_message_type) { |
|
1011 | - $message_type_contexts = $message_type->get_contexts(); |
|
1012 | - if ($slugs_only) { |
|
1013 | - foreach ($message_type_contexts as $context => $context_details) { |
|
1014 | - $this->_contexts[$key][$context] = $context_details['label']; |
|
1015 | - } |
|
1016 | - } else { |
|
1017 | - $this->_contexts[$key][$message_type->name] = $message_type_contexts; |
|
1018 | - } |
|
1019 | - } |
|
1020 | - } |
|
1021 | - } |
|
1022 | - return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array(); |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * This checks the internal record of what message types are considered "active" and verifies that |
|
1028 | - * there is an installed class definition for that message type. If the active message type does not have a |
|
1029 | - * corresponding accessible message type class then it will be deactivated from all messengers it is active on and |
|
1030 | - * any related message templates will be inactivated as well. |
|
1031 | - * |
|
1032 | - * @return bool true means all active message types are valid, false means at least one message type was |
|
1033 | - * deactivated. |
|
1034 | - */ |
|
1035 | - public function validate_active_message_types_are_installed() |
|
1036 | - { |
|
1037 | - $list_of_active_message_type_names = $this->list_of_active_message_types(); |
|
1038 | - $installed_message_types = $this->installed_message_types(); |
|
1039 | - $all_message_types_valid = true; |
|
1040 | - //loop through list of active message types and verify they are installed. |
|
1041 | - foreach ($list_of_active_message_type_names as $message_type_name) { |
|
1042 | - if (! isset($installed_message_types[$message_type_name])) { |
|
1043 | - $this->remove_message_type_has_been_activated_from_all_messengers( |
|
1044 | - $message_type_name, |
|
1045 | - true |
|
1046 | - ); |
|
1047 | - $this->deactivate_message_type($message_type_name, false); |
|
1048 | - $all_message_types_valid = false; |
|
1049 | - } |
|
1050 | - } |
|
1051 | - return $all_message_types_valid; |
|
1052 | - } |
|
1053 | - |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been |
|
1057 | - * activated for the given messenger. This can be called by client code on plugin updates etc to determine whether |
|
1058 | - * to attempt automatically reactivating message types that should be activated by default or not. |
|
1059 | - * |
|
1060 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1061 | - * |
|
1062 | - * @param $message_type_name |
|
1063 | - * @param $messenger_name |
|
1064 | - * @return bool |
|
1065 | - */ |
|
1066 | - public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) |
|
1067 | - { |
|
1068 | - $has_activated = $this->get_has_activated_messengers_option(); |
|
1069 | - return isset($has_activated[$messenger_name]) |
|
1070 | - && in_array($message_type_name, $has_activated[$messenger_name]); |
|
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * This method unsets a message type from the given messenger has activated option. |
|
1076 | - * |
|
1077 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1078 | - * |
|
1079 | - * @param string $message_type_name |
|
1080 | - * @param string $messenger_name |
|
1081 | - * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1082 | - * If it is currently active, then remove. Otherwise leave it alone. |
|
1083 | - */ |
|
1084 | - public function remove_message_type_has_been_activated_for_messenger( |
|
1085 | - $message_type_name, |
|
1086 | - $messenger_name, |
|
1087 | - $consider_current_state = false |
|
1088 | - ) { |
|
1089 | - if ($consider_current_state |
|
1090 | - && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
1091 | - ) { |
|
1092 | - //when consider current state is true, this means we don't want to change anything on the "has_activated" |
|
1093 | - //record if the message type is currently active for this messenger. This is used when we want to retain |
|
1094 | - //the record for user initiated inactivations of the message type. |
|
1095 | - return; |
|
1096 | - } |
|
1097 | - $has_activated = $this->get_has_activated_messengers_option(); |
|
1098 | - $key_for_message_type = isset($has_activated[$messenger_name]) |
|
1099 | - ? array_search($message_type_name, $has_activated[$messenger_name], true) |
|
1100 | - : false; |
|
1101 | - if ($key_for_message_type !== false) { |
|
1102 | - unset($has_activated[$messenger_name][$key_for_message_type]); |
|
1103 | - $this->update_has_activated_messengers_option($has_activated); |
|
1104 | - //reset the internal cached property |
|
1105 | - $this->get_has_activated_messengers_option(true); |
|
1106 | - } |
|
1107 | - } |
|
1108 | - |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * Removes a message type active record from all messengers it is attached to. |
|
1112 | - * |
|
1113 | - * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1114 | - * |
|
1115 | - * @param $message_type_name |
|
1116 | - * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1117 | - * If it is currently active, then remove. Otherwise leave it alone. |
|
1118 | - */ |
|
1119 | - public function remove_message_type_has_been_activated_from_all_messengers( |
|
1120 | - $message_type_name, |
|
1121 | - $consider_current_state = false |
|
1122 | - ) { |
|
1123 | - foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1124 | - $this->remove_message_type_has_been_activated_for_messenger( |
|
1125 | - $message_type_name, |
|
1126 | - $messenger_name, |
|
1127 | - $consider_current_state |
|
1128 | - ); |
|
1129 | - } |
|
1130 | - } |
|
20 | + /** |
|
21 | + * This option in the database is used to keep a record of message types that have been activated for a messenger |
|
22 | + * at some point in the history of the site. It is utilized by the implementation of the 'force' flag in |
|
23 | + * EE_Register_Message_Type. The force flag is an indication of whether a message type should be activated by |
|
24 | + * default when the message type is registered. However, if a user has explicitly deactivated a message type, then |
|
25 | + * the force flag is ignored. The method by which the code knows whether to ignore this flag is via this option. |
|
26 | + * Note, that this is NOT a historical record. Its entirely possible for a message type to have been activated for |
|
27 | + * a messenger and yet not have a record in this option. This occurs when a message type is inactivated through an |
|
28 | + * automated process (when an add-on registering the message type deactivates, or when some other code calls the |
|
29 | + * EE_Registery_Message_Type::deregister method) and the related record(s) is(are) removed from this option to ensure |
|
30 | + * the "force" flag is respected if that message type is later re-registered. |
|
31 | + * |
|
32 | + * This option should NOT be used to determine the current "active" state of a message type for a given messenger. |
|
33 | + * |
|
34 | + * The name of this option (and related methods/properties) is due to matching the original intended purpose for the |
|
35 | + * option that got superseded by later behaviour requirements. |
|
36 | + */ |
|
37 | + const HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME = 'ee_has_activated_messenger'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type boolean $_initialized |
|
41 | + */ |
|
42 | + protected $_initialized = false; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Messenger_Collection $_messenger_collection_loader |
|
46 | + */ |
|
47 | + protected $_messenger_collection_loader; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Message_Type_Collection $_message_type_collection_loader |
|
51 | + */ |
|
52 | + protected $_message_type_collection_loader; |
|
53 | + |
|
54 | + /** |
|
55 | + * @type EEM_Message_Template_Group $_message_template_group_model |
|
56 | + */ |
|
57 | + protected $_message_template_group_model; |
|
58 | + |
|
59 | + /** |
|
60 | + * @type EE_messenger[] |
|
61 | + */ |
|
62 | + protected $_installed_messengers = array(); |
|
63 | + |
|
64 | + /** |
|
65 | + * @type EE_message_type[] |
|
66 | + */ |
|
67 | + protected $_installed_message_types = array(); |
|
68 | + |
|
69 | + /** |
|
70 | + * Array of active messengers. |
|
71 | + * Format is this: |
|
72 | + * array( |
|
73 | + * 'messenger_name' => EE_messenger |
|
74 | + * ) |
|
75 | + * |
|
76 | + * @type EE_messenger[] |
|
77 | + */ |
|
78 | + protected $_active_messengers = array(); |
|
79 | + |
|
80 | + /** |
|
81 | + * Formatted array of active message types grouped per messenger. |
|
82 | + * Format is this: |
|
83 | + * array( |
|
84 | + * 'messenger_name' => array( |
|
85 | + * 'settings' => array( |
|
86 | + * '{messenger_name}-message_types' => array( |
|
87 | + * 'message_type_name' => array() //variable array of settings corresponding to message type. |
|
88 | + * ) |
|
89 | + * ) |
|
90 | + * ) |
|
91 | + * ) |
|
92 | + * |
|
93 | + * @type array |
|
94 | + */ |
|
95 | + protected $_active_message_types = array(); |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * This holds the array of messengers and their corresponding message types that have |
|
100 | + * been activated on a site at some point. This is an important record that helps the messages system |
|
101 | + * not accidentally reactivate something that was intentionally deactivated by a user. |
|
102 | + * |
|
103 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
104 | + * |
|
105 | + * @type array |
|
106 | + */ |
|
107 | + protected $_has_activated_messengers_and_message_types = array(); |
|
108 | + |
|
109 | + /** |
|
110 | + * An array of unique message type contexts across all active message types. |
|
111 | + * The array will be indexed by either 'slugs' or 'all'. |
|
112 | + * The slugs index contains an array indexed by unique context slugs with the latest label representation for that |
|
113 | + * slug. array( |
|
114 | + * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
115 | + * ); |
|
116 | + * The all index returns an array in this format: |
|
117 | + * array( |
|
118 | + * 'message_type_name' => array( |
|
119 | + * 'context_slug' => array( |
|
120 | + * 'label' => 'localized label for context', |
|
121 | + * 'description' => 'localized description for context' |
|
122 | + * ) |
|
123 | + * ) |
|
124 | + * ); |
|
125 | + * |
|
126 | + * @type array |
|
127 | + */ |
|
128 | + protected $_contexts = array(); |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * EE_Message_Resource_Manager constructor. |
|
133 | + * |
|
134 | + * @param \EE_Messenger_Collection_Loader $Messenger_Collection_Loader |
|
135 | + * @param \EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader |
|
136 | + * @param \EEM_Message_Template_Group $Message_Template_Group_Model |
|
137 | + */ |
|
138 | + function __construct( |
|
139 | + EE_Messenger_Collection_Loader $Messenger_Collection_Loader, |
|
140 | + EE_Message_Type_Collection_Loader $Message_Type_Collection_Loader, |
|
141 | + EEM_Message_Template_Group $Message_Template_Group_Model |
|
142 | + ) { |
|
143 | + $this->_messenger_collection_loader = $Messenger_Collection_Loader; |
|
144 | + $this->_message_type_collection_loader = $Message_Type_Collection_Loader; |
|
145 | + $this->_message_template_group_model = $Message_Template_Group_Model; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + protected function _initialize_collections() |
|
153 | + { |
|
154 | + if ($this->_initialized) { |
|
155 | + return; |
|
156 | + } |
|
157 | + $this->_initialized = true; |
|
158 | + $this->_messenger_collection_loader->load_messengers_from_folder(); |
|
159 | + $this->_message_type_collection_loader->load_message_types_from_folder(); |
|
160 | + $this->get_has_activated_messengers_option(true); |
|
161 | + $this->_set_active_messengers_and_message_types(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return EE_Messenger_Collection |
|
167 | + */ |
|
168 | + public function messenger_collection() |
|
169 | + { |
|
170 | + $this->_initialize_collections(); |
|
171 | + return $this->_messenger_collection_loader->messenger_collection(); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return EE_messenger[] |
|
177 | + */ |
|
178 | + public function active_messengers() |
|
179 | + { |
|
180 | + $this->_initialize_collections(); |
|
181 | + return $this->_active_messengers; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $messenger_name |
|
187 | + * @return \EE_messenger |
|
188 | + */ |
|
189 | + public function get_messenger($messenger_name) |
|
190 | + { |
|
191 | + return $this->messenger_collection()->get_by_info($messenger_name); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * This returns the corresponding EE_messenger object for the given string if it is active. |
|
197 | + * |
|
198 | + * @param string $messenger |
|
199 | + * @return EE_messenger | null |
|
200 | + */ |
|
201 | + public function get_active_messenger($messenger) |
|
202 | + { |
|
203 | + $this->_initialize_collections(); |
|
204 | + return ! empty($this->_active_messengers[$messenger]) ? $this->_active_messengers[$messenger] : null; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * @return \EE_messenger[] |
|
210 | + */ |
|
211 | + public function installed_messengers() |
|
212 | + { |
|
213 | + if (empty($this->_installed_messengers)) { |
|
214 | + $this->_installed_messengers = array(); |
|
215 | + $this->messenger_collection()->rewind(); |
|
216 | + while ($this->messenger_collection()->valid()) { |
|
217 | + $this->_installed_messengers[$this->messenger_collection()->current()->name] = $this->messenger_collection()->current(); |
|
218 | + $this->messenger_collection()->next(); |
|
219 | + } |
|
220 | + } |
|
221 | + return $this->_installed_messengers; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @param string $messenger_name |
|
227 | + * @return \EE_messenger |
|
228 | + * @throws \EE_Error |
|
229 | + */ |
|
230 | + public function valid_messenger($messenger_name) |
|
231 | + { |
|
232 | + $messenger = $this->get_messenger($messenger_name); |
|
233 | + if ($messenger instanceof EE_messenger) { |
|
234 | + return $messenger; |
|
235 | + } |
|
236 | + throw new EE_Error( |
|
237 | + sprintf( |
|
238 | + __('The "%1$s" messenger is either invalid or not installed', 'event_espresso'), |
|
239 | + $messenger_name |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return EE_Message_Type_Collection |
|
247 | + */ |
|
248 | + public function message_type_collection() |
|
249 | + { |
|
250 | + $this->_initialize_collections(); |
|
251 | + return $this->_message_type_collection_loader->message_type_collection(); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function active_message_types() |
|
259 | + { |
|
260 | + $this->_initialize_collections(); |
|
261 | + return $this->_active_message_types; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param string $message_type_name |
|
267 | + * @return \EE_message_type |
|
268 | + */ |
|
269 | + public function get_message_type($message_type_name) |
|
270 | + { |
|
271 | + return $this->message_type_collection()->get_by_info($message_type_name); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * This returns the EE_message_type from the active message types array ( if present ); |
|
277 | + * |
|
278 | + * @param string $messenger_name |
|
279 | + * @param string $message_type_name |
|
280 | + * @return \EE_message_type|null |
|
281 | + */ |
|
282 | + public function get_active_message_type_for_messenger($messenger_name, $message_type_name) |
|
283 | + { |
|
284 | + return $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
285 | + ? $this->get_message_type($message_type_name) |
|
286 | + : null; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Returns whether the given message type is active for the given messenger. |
|
292 | + * |
|
293 | + * @param string $messenger_name |
|
294 | + * @param string $message_type_name |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
298 | + { |
|
299 | + $this->_initialize_collections(); |
|
300 | + return ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns whether the given messenger is active. |
|
306 | + * |
|
307 | + * @param string $messenger_name the name of the messenger to check if active. |
|
308 | + * @return bool |
|
309 | + */ |
|
310 | + public function is_messenger_active($messenger_name) |
|
311 | + { |
|
312 | + $this->_initialize_collections(); |
|
313 | + return ! empty($this->_active_message_types[$messenger_name]); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * This returns any settings that might be on a message type for a messenger |
|
319 | + * |
|
320 | + * @param string $messenger_name The slug of the messenger |
|
321 | + * @param string $message_type_name The slug of the message type getting the settings for. |
|
322 | + * @return array |
|
323 | + */ |
|
324 | + public function get_message_type_settings_for_messenger($messenger_name, $message_type_name) |
|
325 | + { |
|
326 | + $settings = array(); |
|
327 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
328 | + $settings = isset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings']) |
|
329 | + ? $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] |
|
330 | + : array(); |
|
331 | + } |
|
332 | + return $settings; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Returns whether the given messenger name has active message types on it. |
|
338 | + * Infers whether the messenger is active or not as well. |
|
339 | + * |
|
340 | + * @param string $messenger_name |
|
341 | + * @return bool |
|
342 | + */ |
|
343 | + public function messenger_has_active_message_types($messenger_name) |
|
344 | + { |
|
345 | + $this->_initialize_collections(); |
|
346 | + return |
|
347 | + ! empty($this->_active_message_types[$messenger_name]) |
|
348 | + && ! empty($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types']); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * This checks the _active_message_types property for any active message types |
|
354 | + * that are present for the given messenger and returns them. |
|
355 | + * |
|
356 | + * @since 4.9.0 |
|
357 | + * @param string $messenger_name The messenger being checked |
|
358 | + * @return EE_message_type[]|array (empty array if no active_message_types) |
|
359 | + */ |
|
360 | + public function get_active_message_types_for_messenger($messenger_name) |
|
361 | + { |
|
362 | + $message_types = array(); |
|
363 | + if (! $this->messenger_has_active_message_types($messenger_name)) { |
|
364 | + return $message_types; |
|
365 | + } |
|
366 | + $installed_message_types = $this->installed_message_types(); |
|
367 | + foreach ($installed_message_types as $message_type_name => $message_type) { |
|
368 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
369 | + $message_types[$message_type_name] = $message_type; |
|
370 | + } |
|
371 | + } |
|
372 | + return $message_types; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * This does NOT return the _active_message_types property but |
|
378 | + * simply returns an array of active message type names from that property. |
|
379 | + * (The _active_message_types property is indexed by messenger and active message_types per messenger). |
|
380 | + * |
|
381 | + * @return array message_type references (string) |
|
382 | + */ |
|
383 | + public function list_of_active_message_types() |
|
384 | + { |
|
385 | + $active_message_type_names = array(); |
|
386 | + $this->_initialize_collections(); |
|
387 | + foreach ($this->_active_message_types as $messenger => $messenger_settings) { |
|
388 | + if (! isset($messenger_settings['settings'][$messenger . '-message_types'])) { |
|
389 | + continue; |
|
390 | + } |
|
391 | + foreach ($messenger_settings['settings'][$messenger . '-message_types'] as $message_type_name => $message_type_config) { |
|
392 | + if (! in_array($message_type_name, $active_message_type_names)) { |
|
393 | + $active_message_type_names[] = $message_type_name; |
|
394 | + } |
|
395 | + } |
|
396 | + } |
|
397 | + return $active_message_type_names; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Same as list_of_active_message_types() except this returns actual EE_message_type objects |
|
403 | + * |
|
404 | + * @since 4.9.0 |
|
405 | + * @return \EE_message_type[] |
|
406 | + */ |
|
407 | + public function get_active_message_type_objects() |
|
408 | + { |
|
409 | + $active_message_types = array(); |
|
410 | + $installed_message_types = $this->installed_message_types(); |
|
411 | + $active_message_type_names = $this->list_of_active_message_types(); |
|
412 | + foreach ($active_message_type_names as $active_message_type_name) { |
|
413 | + if (isset($installed_message_types[$active_message_type_name])) { |
|
414 | + $active_message_types[$active_message_type_name] = $installed_message_types[$active_message_type_name]; |
|
415 | + } |
|
416 | + } |
|
417 | + return $active_message_types; |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * @return \EE_message_type[] |
|
423 | + */ |
|
424 | + public function installed_message_types() |
|
425 | + { |
|
426 | + if (empty($this->_installed_message_types)) { |
|
427 | + $this->message_type_collection()->rewind(); |
|
428 | + while ($this->message_type_collection()->valid()) { |
|
429 | + $this->_installed_message_types[$this->message_type_collection()->current()->name] = $this->message_type_collection()->current(); |
|
430 | + $this->message_type_collection()->next(); |
|
431 | + } |
|
432 | + } |
|
433 | + return $this->_installed_message_types; |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * @param string $message_type_name |
|
439 | + * @return \EE_message_type |
|
440 | + * @throws \EE_Error |
|
441 | + */ |
|
442 | + public function valid_message_type($message_type_name) |
|
443 | + { |
|
444 | + $message_type = $this->get_message_type($message_type_name); |
|
445 | + if ($message_type instanceof EE_message_type) { |
|
446 | + return $message_type; |
|
447 | + } |
|
448 | + throw new EE_Error( |
|
449 | + sprintf( |
|
450 | + __('The "%1$s" message type is either invalid or not installed', 'event_espresso'), |
|
451 | + $message_type_name |
|
452 | + ) |
|
453 | + ); |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * valid_message_type_for_messenger |
|
459 | + * |
|
460 | + * @param EE_messenger $messenger |
|
461 | + * @param string $message_type_name |
|
462 | + * @return boolean |
|
463 | + * @throws \EE_Error |
|
464 | + */ |
|
465 | + public function valid_message_type_for_messenger(EE_messenger $messenger, $message_type_name) |
|
466 | + { |
|
467 | + $valid_message_types = $messenger->get_valid_message_types(); |
|
468 | + if (! in_array($message_type_name, $valid_message_types)) { |
|
469 | + throw new EE_Error( |
|
470 | + sprintf( |
|
471 | + __( |
|
472 | + 'The message type (%1$s) sent to "%2$s" is not valid for the "%3$s" messenger. Double-check the spelling and verify that message type has been registered as a valid type with the messenger.', |
|
473 | + 'event_espresso' |
|
474 | + ), |
|
475 | + $message_type_name, |
|
476 | + __METHOD__, |
|
477 | + $messenger->name |
|
478 | + ) |
|
479 | + ); |
|
480 | + } |
|
481 | + return true; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Used to return active messengers array stored in the wp options table. |
|
487 | + * If no value is present in the option then an empty array is returned. |
|
488 | + * |
|
489 | + * @param bool $reset If true then we ignore whether the option is cached on the _active_message_types |
|
490 | + * property and pull directly from the db. Otherwise whatever is currently on the |
|
491 | + * $_active_message_types property is pulled. |
|
492 | + * @return array |
|
493 | + */ |
|
494 | + public function get_active_messengers_option($reset = false) |
|
495 | + { |
|
496 | + if ($reset) { |
|
497 | + $this->_active_message_types = get_option('ee_active_messengers', array()); |
|
498 | + } |
|
499 | + return $this->_active_message_types; |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Used to update the active messengers array stored in the wp options table. |
|
505 | + * |
|
506 | + * @param array $active_messenger_settings Incoming data to save. If empty, then the internal cached property |
|
507 | + * representing this data is used. |
|
508 | + * @return bool FALSE if not updated, TRUE if updated. |
|
509 | + */ |
|
510 | + public function update_active_messengers_option($active_messenger_settings = array()) |
|
511 | + { |
|
512 | + $active_messenger_settings = empty($active_messenger_settings) ? $this->_active_message_types : $active_messenger_settings; |
|
513 | + //make sure _active_message_types is updated (this is the internal cache for the settings). |
|
514 | + $this->_active_message_types = $active_messenger_settings; |
|
515 | + return update_option('ee_active_messengers', $active_messenger_settings); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Used to return has activated message types for messengers array stored in the wp options table. |
|
521 | + * If no value is present in the option then an empty array is returned. |
|
522 | + * The value is cached on the $_has_activated_messengers_and_message_types property for future calls. |
|
523 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
524 | + * |
|
525 | + * @param bool $reset Used to indicate that any cached value should be ignored. |
|
526 | + * @return array |
|
527 | + */ |
|
528 | + public function get_has_activated_messengers_option($reset = false) |
|
529 | + { |
|
530 | + if ($reset || empty($this->_has_activated_messengers_and_message_types)) { |
|
531 | + $this->_has_activated_messengers_and_message_types = get_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, array()); |
|
532 | + } |
|
533 | + return $this->_has_activated_messengers_and_message_types; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Used to update the has activated option in the db. |
|
539 | + * |
|
540 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
541 | + * |
|
542 | + * @param array $has_activated_messengers Incoming data to save. If empty, then the internal cached property |
|
543 | + * representing this data is used. |
|
544 | + * @return bool FALSE if not updated, TRUE if updated. |
|
545 | + */ |
|
546 | + public function update_has_activated_messengers_option($has_activated_messengers = array()) |
|
547 | + { |
|
548 | + //make sure the option has been retrieved from first so we don't overwrite it accidentally. |
|
549 | + if (empty($has_activated_messengers) && empty($this->_has_activated_messengers_and_message_types)) { |
|
550 | + $this->get_has_activated_messengers_option(); |
|
551 | + } |
|
552 | + $has_activated_messengers = empty($has_activated_messengers) |
|
553 | + ? $this->_has_activated_messengers_and_message_types |
|
554 | + : $has_activated_messengers; |
|
555 | + return update_option(self::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME, $has_activated_messengers); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * wrapper for _set_active_messengers_and_message_types() |
|
561 | + */ |
|
562 | + public function reset_active_messengers_and_message_types() |
|
563 | + { |
|
564 | + $this->_set_active_messengers_and_message_types(); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * Generate list of active messengers and message types from collection. |
|
570 | + * This sets up the active messengers from what is present in the database. |
|
571 | + */ |
|
572 | + protected function _set_active_messengers_and_message_types() |
|
573 | + { |
|
574 | + //echo "\n\n " . __LINE__ . ") " . __METHOD__ . "() \n"; |
|
575 | + // list of activated messengers as set via the admin |
|
576 | + // note calling `get_active_messengers_options` also initializes the _active_message_types property. |
|
577 | + $this->get_active_messengers_option(true); |
|
578 | + $this->ensure_messengers_are_active(array(), false, true); |
|
579 | + $this->update_active_messengers_option(); |
|
580 | + $this->update_has_activated_messengers_option(); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Ensures that the specified messenger is currently active. |
|
586 | + * If not, activates it and its default message types. |
|
587 | + * |
|
588 | + * @param string $messenger_name |
|
589 | + * @param bool $update_option Whether to update the option in the db or not. |
|
590 | + * @return boolean true if either already active or successfully activated. |
|
591 | + */ |
|
592 | + public function ensure_messenger_is_active($messenger_name, $update_option = true) |
|
593 | + { |
|
594 | + if (! isset($this->_active_messengers[$messenger_name])) { |
|
595 | + try { |
|
596 | + $this->activate_messenger($messenger_name, array(), $update_option); |
|
597 | + } catch (EE_Error $e) { |
|
598 | + EE_Error::add_error( |
|
599 | + $e->getMessage(), |
|
600 | + __FILE__, |
|
601 | + __FUNCTION__, |
|
602 | + __LINE__ |
|
603 | + ); |
|
604 | + return false; |
|
605 | + } |
|
606 | + } |
|
607 | + return true; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * This ensures the given array of messenger names is active in the system. |
|
613 | + * Note, this method will not activate any NEW message types for the messenger when it is called. Instead, |
|
614 | + * it will automatically activate the default message types for the messenger if its not active. |
|
615 | + * |
|
616 | + * @param array $messenger_names Array of messenger names for messengers to be activated. If an empty array |
|
617 | + * (default) then will attempt to set the active messengers from the |
|
618 | + * activated_messengers option |
|
619 | + * (stored in $_active_message_types property). |
|
620 | + * @param bool $update_option Whether to update the related active messengers option. |
|
621 | + * @param bool $verify Whether to verify the messengers are installed before activating. Note if this is |
|
622 | + * set to true and a messenger is indicated as active, but is NOT installed, then it |
|
623 | + * will automatically be deactivated. |
|
624 | + */ |
|
625 | + public function ensure_messengers_are_active($messenger_names = array(), $update_option = true, $verify = false) |
|
626 | + { |
|
627 | + $messenger_names = empty($messenger_names) ? array_keys($this->_active_message_types) : $messenger_names; |
|
628 | + |
|
629 | + $not_installed = array(); |
|
630 | + foreach ($messenger_names as $messenger_name) { |
|
631 | + if ($verify && ! $this->messenger_collection()->has_by_name($messenger_name)) { |
|
632 | + $not_installed[] = $messenger_name; |
|
633 | + $this->deactivate_messenger($messenger_name); |
|
634 | + continue; |
|
635 | + } |
|
636 | + $this->ensure_messenger_is_active($messenger_name, $update_option); |
|
637 | + } |
|
638 | + |
|
639 | + if (! empty($not_installed_messenger)) { |
|
640 | + EE_Error::add_error( |
|
641 | + sprintf( |
|
642 | + __('The following messengers are either not installed or are invalid:%1$s %2$s', 'event_espresso'), |
|
643 | + '<br />', |
|
644 | + implode(', ', $not_installed_messenger) |
|
645 | + ), |
|
646 | + __FILE__, __FUNCTION__, __LINE__ |
|
647 | + ); |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Ensures that the specified message type for the given messenger is currently active, if not activates it. |
|
654 | + * This ALSO ensures that the given messenger is active as well! |
|
655 | + * |
|
656 | + * @param string $message_type_name message type name. |
|
657 | + * @param $messenger_name |
|
658 | + * @param bool $update_option Whether to update the option in the db or not. |
|
659 | + * @return bool Returns true if already is active or if was activated successfully. |
|
660 | + * @throws \EE_Error |
|
661 | + */ |
|
662 | + public function ensure_message_type_is_active($message_type_name, $messenger_name, $update_option = true) |
|
663 | + { |
|
664 | + // grab the messenger to work with. |
|
665 | + $messenger = $this->valid_messenger($messenger_name); |
|
666 | + if ($this->valid_message_type_for_messenger($messenger, $message_type_name)) { |
|
667 | + //ensure messenger is active (that's an inherent coupling between active message types and the |
|
668 | + //messenger they are being activated for. |
|
669 | + try { |
|
670 | + if (! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
671 | + //all is good so let's just get it active |
|
672 | + $this->activate_messenger($messenger_name, array($message_type_name), $update_option); |
|
673 | + } |
|
674 | + } catch (EE_Error $e) { |
|
675 | + EE_Error::add_error( |
|
676 | + $e->getMessage(), |
|
677 | + __FILE__, |
|
678 | + __FUNCTION__, |
|
679 | + __LINE__ |
|
680 | + ); |
|
681 | + return false; |
|
682 | + } |
|
683 | + } |
|
684 | + return true; |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * This is a wrapper for `ensure_message_type_is_active` that will handle ensuring multiple message types for a |
|
690 | + * messenger are active in one go. |
|
691 | + * |
|
692 | + * @param array $message_type_names Array of message type names to ensure are active. |
|
693 | + * @param string $messenger_name The name of the messenger that the message types are to be activated on. |
|
694 | + * @param bool $update_option Whether to persist the activation to the database or not (default true). |
|
695 | + */ |
|
696 | + public function ensure_message_types_are_active($message_type_names, $messenger_name, $update_option = true) |
|
697 | + { |
|
698 | + $message_type_names = (array)$message_type_names; |
|
699 | + foreach ($message_type_names as $message_type_name) { |
|
700 | + // note, intentionally not updating option here because we're in a loop. |
|
701 | + // We'll follow the instructions of the incoming $update_option argument after the loop. |
|
702 | + $this->ensure_message_type_is_active($message_type_name, $messenger_name, false); |
|
703 | + } |
|
704 | + if ($update_option) { |
|
705 | + $this->update_active_messengers_option(); |
|
706 | + $this->update_has_activated_messengers_option(); |
|
707 | + } |
|
708 | + } |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * Activates the specified messenger. |
|
713 | + * |
|
714 | + * @param string $messenger_name |
|
715 | + * @param array $message_type_names An array of message type names to activate with this messenger. |
|
716 | + * If included we do NOT setup the default message types |
|
717 | + * (assuming they are already setup.) |
|
718 | + * @param bool $update_active_messengers_option |
|
719 | + * @return array of generated templates |
|
720 | + * @throws \EE_Error |
|
721 | + */ |
|
722 | + public function activate_messenger( |
|
723 | + $messenger_name, |
|
724 | + $message_type_names = array(), |
|
725 | + $update_active_messengers_option = true |
|
726 | + ) { |
|
727 | + $templates = array(); |
|
728 | + // grab the messenger to work with. |
|
729 | + $messenger = $this->messenger_collection()->get_by_info($messenger_name); |
|
730 | + // it's inactive. Activate it. |
|
731 | + if ($messenger instanceof EE_messenger) { |
|
732 | + $this->_active_messengers[$messenger->name] = $messenger; |
|
733 | + //activate incoming message types set to be activated with messenger. |
|
734 | + $message_type_names = $this->_activate_message_types($messenger, $message_type_names); |
|
735 | + // setup any initial settings for the messenger if necessary. |
|
736 | + $this->add_settings_for_messenger($messenger->name); |
|
737 | + if ($update_active_messengers_option) { |
|
738 | + $this->update_active_messengers_option(); |
|
739 | + $this->update_has_activated_messengers_option(); |
|
740 | + } |
|
741 | + //generate new templates if necessary and ensure all related templates that are already in the database are |
|
742 | + //marked active. Note, this will also deactivate a message type for a messenger if the template |
|
743 | + //cannot be successfully created during its attempt (only happens for global template attempts). |
|
744 | + if (! empty($message_type_names)) { |
|
745 | + $templates = EEH_MSG_Template::generate_new_templates($messenger->name, $message_type_names, 0, true); |
|
746 | + EEH_MSG_Template::update_to_active(array($messenger->name), $message_type_names); |
|
747 | + } |
|
748 | + } |
|
749 | + return $templates; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Activates given message types for the given EE_messenger object. |
|
755 | + * Note: (very important) This method does not persist the activation to the database. |
|
756 | + * See code implementing this method in this class for examples of how to persist. |
|
757 | + * |
|
758 | + * @param \EE_messenger $messenger |
|
759 | + * @param array $message_type_names |
|
760 | + * @return array |
|
761 | + */ |
|
762 | + protected function _activate_message_types(EE_messenger $messenger, $message_type_names = array()) |
|
763 | + { |
|
764 | + //If $message_type_names is empty, AND $this->_active_message_types is empty, then that means |
|
765 | + //things have never been initialized (which should happen on EEH_Activation::generate_message_templates). |
|
766 | + //So ONLY then do we need to actually grab defaults and cycle through them. Otherwise we |
|
767 | + //only override _active_message_types when an explicit array of $message_type_names has been provided. |
|
768 | + $message_type_names = empty($message_type_names) && ! isset($this->_active_message_types[$messenger->name]) |
|
769 | + ? $messenger->get_default_message_types() |
|
770 | + : (array)$message_type_names; |
|
771 | + |
|
772 | + //now we ALWAYS need to make sure that the messenger is active for the message types we're activating! |
|
773 | + if (! isset($this->_active_message_types[$messenger->name])) { |
|
774 | + $this->_active_message_types[$messenger->name]['settings'] = array(); |
|
775 | + } |
|
776 | + |
|
777 | + if ($message_type_names) { |
|
778 | + // cycle thru message types |
|
779 | + foreach ($message_type_names as $message_type_name) { |
|
780 | + //only register the message type as active IF it isn't already active |
|
781 | + //and if its actually installed. |
|
782 | + if ( |
|
783 | + ! $this->is_message_type_active_for_messenger($messenger->name, $message_type_name) |
|
784 | + ) { |
|
785 | + $this->add_settings_for_message_type($messenger->name, $message_type_name); |
|
786 | + $this->_set_messenger_has_activated_message_type( |
|
787 | + $messenger, |
|
788 | + $message_type_name |
|
789 | + ); |
|
790 | + } |
|
791 | + } |
|
792 | + } |
|
793 | + return $message_type_names; |
|
794 | + } |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * add_settings_for_message_type |
|
799 | + * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
800 | + * $this->update_active_messengers_option to persist. |
|
801 | + * |
|
802 | + * @param string $messenger_name The name of the messenger adding the settings for |
|
803 | + * @param string $message_type_name The name of the message type adding the settings for |
|
804 | + * @param array $new_settings Any new settings being set for the message type and messenger |
|
805 | + */ |
|
806 | + public function add_settings_for_message_type($messenger_name, $message_type_name, $new_settings = array()) |
|
807 | + { |
|
808 | + // get installed message type from collection |
|
809 | + $message_type = $this->message_type_collection()->get_by_info($message_type_name); |
|
810 | + $existing_settings = $this->get_message_type_settings_for_messenger($messenger_name, $message_type_name); |
|
811 | + //we need to setup any initial settings for message types |
|
812 | + if ($message_type instanceof EE_message_type) { |
|
813 | + $default_settings = $message_type->get_admin_settings_fields(); |
|
814 | + foreach ($default_settings as $field => $values) { |
|
815 | + if (isset($new_settings[$field])) { |
|
816 | + $existing_settings[$field] = $new_settings[$field]; |
|
817 | + continue; |
|
818 | + } |
|
819 | + if (! isset($existing_settings[$field])) { |
|
820 | + $existing_settings[$field] = $values['default']; |
|
821 | + } |
|
822 | + } |
|
823 | + } |
|
824 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]['settings'] = $existing_settings; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * Updates the internal cached _has_activated_messengers_and_message_types property with the given messenger |
|
830 | + * and message type. |
|
831 | + * |
|
832 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
833 | + * |
|
834 | + * @access protected |
|
835 | + * @param \EE_messenger $messenger |
|
836 | + * @param string $message_type_name |
|
837 | + */ |
|
838 | + protected function _set_messenger_has_activated_message_type(EE_messenger $messenger, $message_type_name) |
|
839 | + { |
|
840 | + |
|
841 | + //if _has_activated_messengers_and_message_types is empty then lets ensure its initialized |
|
842 | + if (empty($this->_has_activated_messengers_and_message_types)) { |
|
843 | + $this->get_has_activated_messengers_option(); |
|
844 | + } |
|
845 | + |
|
846 | + // make sure this messenger has a record in the has_activated array |
|
847 | + if (! isset($this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
848 | + $this->_has_activated_messengers_and_message_types[$messenger->name] = array(); |
|
849 | + } |
|
850 | + // check if message type has already been added |
|
851 | + if (! in_array($message_type_name, $this->_has_activated_messengers_and_message_types[$messenger->name])) { |
|
852 | + $this->_has_activated_messengers_and_message_types[$messenger->name][] = $message_type_name; |
|
853 | + } |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * add_settings_for_messenger |
|
859 | + * NOTE This does NOT automatically persist any settings to the db. Client code should call |
|
860 | + * $this->update_active_messengers_option to persist. |
|
861 | + * |
|
862 | + * @param string $messenger_name The name of the messenger the settings is being added for. |
|
863 | + * @param array $new_settings An array of settings to update the existing settings. |
|
864 | + */ |
|
865 | + public function add_settings_for_messenger($messenger_name, $new_settings = array()) |
|
866 | + { |
|
867 | + $messenger = $this->get_messenger($messenger_name); |
|
868 | + if ($messenger instanceof EE_messenger) { |
|
869 | + $msgr_settings = $messenger->get_admin_settings_fields(); |
|
870 | + if (! empty($msgr_settings)) { |
|
871 | + foreach ($msgr_settings as $field => $value) { |
|
872 | + //is there a new setting for this? |
|
873 | + if (isset($new_settings[$field])) { |
|
874 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $new_settings[$field]; |
|
875 | + continue; |
|
876 | + } |
|
877 | + //only set the default if it isn't already set. |
|
878 | + if (! isset($this->_active_message_types[$messenger->name]['settings'][$field])) { |
|
879 | + $this->_active_message_types[$messenger->name]['settings'][$field] = $value; |
|
880 | + } |
|
881 | + } |
|
882 | + } |
|
883 | + } |
|
884 | + } |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * deactivate_messenger |
|
889 | + * |
|
890 | + * @param string|EE_messenger $messenger_name name of messenger |
|
891 | + * @return void |
|
892 | + */ |
|
893 | + public function deactivate_messenger($messenger_name) |
|
894 | + { |
|
895 | + $this->_initialize_collections(); |
|
896 | + if ($messenger_name instanceof EE_messenger) { |
|
897 | + $messenger_name = $messenger_name->name; |
|
898 | + } |
|
899 | + unset($this->_active_messengers[$messenger_name]); |
|
900 | + unset($this->_active_message_types[$messenger_name]); |
|
901 | + $this->_message_template_group_model->deactivate_message_template_groups_for($messenger_name); |
|
902 | + $this->update_active_messengers_option(); |
|
903 | + } |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * Deactivates a message type (note this will deactivate across all messenger's it is active on. |
|
908 | + * |
|
909 | + * @param string $message_type_name name of message type being deactivated |
|
910 | + * @param bool $set_has_active_record By default we always record the has_active record when deactivating a message |
|
911 | + * type. However, this can be overridden if we don't want this set (usually when |
|
912 | + * this is called as a part of deregistration of a custom message type) |
|
913 | + */ |
|
914 | + public function deactivate_message_type($message_type_name, $set_has_active_record = true) |
|
915 | + { |
|
916 | + $this->_initialize_collections(); |
|
917 | + if ($message_type_name instanceof EE_message_type) { |
|
918 | + $message_type_name = $message_type_name->name; |
|
919 | + } |
|
920 | + foreach ($this->_active_message_types as $messenger_name => $settings) { |
|
921 | + unset( |
|
922 | + $this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name] |
|
923 | + ); |
|
924 | + |
|
925 | + //we always record (even on deactivation) that a message type has been activated because there should at |
|
926 | + //least be a record in the "has_activated" option that it WAS active at one point. |
|
927 | + if ($set_has_active_record) { |
|
928 | + $messenger = $this->get_messenger($messenger_name); |
|
929 | + $this->_set_messenger_has_activated_message_type($messenger, $message_type_name); |
|
930 | + } |
|
931 | + } |
|
932 | + $this->_message_template_group_model->deactivate_message_template_groups_for('', $message_type_name); |
|
933 | + $this->update_active_messengers_option(); |
|
934 | + $this->update_has_activated_messengers_option(); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Deactivates a message type for a specific messenger as opposed to all messengers. |
|
940 | + * |
|
941 | + * @param string $message_type_name Name of message type being deactivated. |
|
942 | + * @param string $messenger_name Name of messenger the message type is being deactivated for. |
|
943 | + */ |
|
944 | + public function deactivate_message_type_for_messenger($message_type_name, $messenger_name) |
|
945 | + { |
|
946 | + $this->_initialize_collections(); |
|
947 | + if ($this->is_message_type_active_for_messenger($messenger_name, $message_type_name)) { |
|
948 | + unset($this->_active_message_types[$messenger_name]['settings'][$messenger_name . '-message_types'][$message_type_name]); |
|
949 | + } |
|
950 | + $this->_message_template_group_model->deactivate_message_template_groups_for(array($messenger_name), |
|
951 | + array($message_type_name)); |
|
952 | + $this->update_active_messengers_option(); |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * Used to verify if a message can be sent for the given messenger and message type |
|
958 | + * and that it is a generating messenger (used for generating message templates). |
|
959 | + * |
|
960 | + * @param EE_messenger $messenger messenger used in trigger |
|
961 | + * @param EE_message_type $message_type message type used in trigger |
|
962 | + * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
|
963 | + */ |
|
964 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) |
|
965 | + { |
|
966 | + //get the $messengers the message type says it can be used with. |
|
967 | + foreach ($message_type->with_messengers() as $generating_messenger => $secondary_messengers) { |
|
968 | + if ( |
|
969 | + $messenger->name === $generating_messenger |
|
970 | + && $this->is_message_type_active_for_messenger($messenger->name, $message_type->name) |
|
971 | + ) { |
|
972 | + return true; |
|
973 | + } |
|
974 | + } |
|
975 | + return false; |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + /** |
|
980 | + * This returns all the contexts that are registered by all message types. |
|
981 | + * If $slugs_only is true, |
|
982 | + * then just an array indexed by unique context slugs with the latest label representation for that slug. |
|
983 | + * array( |
|
984 | + * 'context_slug' => 'localized label for context obtained from latest message type in the loop'. |
|
985 | + * ); |
|
986 | + * If $slugs_only is false, then the format is: |
|
987 | + * array( |
|
988 | + * 'message_type_name' => array( |
|
989 | + * 'context_slug' => array( |
|
990 | + * 'label' => 'localized label for context', |
|
991 | + * 'description' => 'localized description for context' |
|
992 | + * ) |
|
993 | + * ) |
|
994 | + * ); |
|
995 | + * Keep in mind that although different message types may share the same context slugs, |
|
996 | + * it is possible that the context is described differently by the message type. |
|
997 | + * |
|
998 | + * @since 4.9.0 |
|
999 | + * @param bool $slugs_only Whether to return an array of just slugs and labels (true) |
|
1000 | + * or all contexts indexed by message type. |
|
1001 | + * @return array |
|
1002 | + */ |
|
1003 | + public function get_all_contexts($slugs_only = true) |
|
1004 | + { |
|
1005 | + $key = $slugs_only ? 'slugs' : 'all'; |
|
1006 | + // check if contexts has been setup yet. |
|
1007 | + if (empty($this->_contexts[$key])) { |
|
1008 | + // So let's get all active message type objects and loop through to get all unique contexts |
|
1009 | + foreach ($this->get_active_message_type_objects() as $message_type) { |
|
1010 | + if ($message_type instanceof EE_message_type) { |
|
1011 | + $message_type_contexts = $message_type->get_contexts(); |
|
1012 | + if ($slugs_only) { |
|
1013 | + foreach ($message_type_contexts as $context => $context_details) { |
|
1014 | + $this->_contexts[$key][$context] = $context_details['label']; |
|
1015 | + } |
|
1016 | + } else { |
|
1017 | + $this->_contexts[$key][$message_type->name] = $message_type_contexts; |
|
1018 | + } |
|
1019 | + } |
|
1020 | + } |
|
1021 | + } |
|
1022 | + return ! empty($this->_contexts[$key]) ? $this->_contexts[$key] : array(); |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * This checks the internal record of what message types are considered "active" and verifies that |
|
1028 | + * there is an installed class definition for that message type. If the active message type does not have a |
|
1029 | + * corresponding accessible message type class then it will be deactivated from all messengers it is active on and |
|
1030 | + * any related message templates will be inactivated as well. |
|
1031 | + * |
|
1032 | + * @return bool true means all active message types are valid, false means at least one message type was |
|
1033 | + * deactivated. |
|
1034 | + */ |
|
1035 | + public function validate_active_message_types_are_installed() |
|
1036 | + { |
|
1037 | + $list_of_active_message_type_names = $this->list_of_active_message_types(); |
|
1038 | + $installed_message_types = $this->installed_message_types(); |
|
1039 | + $all_message_types_valid = true; |
|
1040 | + //loop through list of active message types and verify they are installed. |
|
1041 | + foreach ($list_of_active_message_type_names as $message_type_name) { |
|
1042 | + if (! isset($installed_message_types[$message_type_name])) { |
|
1043 | + $this->remove_message_type_has_been_activated_from_all_messengers( |
|
1044 | + $message_type_name, |
|
1045 | + true |
|
1046 | + ); |
|
1047 | + $this->deactivate_message_type($message_type_name, false); |
|
1048 | + $all_message_types_valid = false; |
|
1049 | + } |
|
1050 | + } |
|
1051 | + return $all_message_types_valid; |
|
1052 | + } |
|
1053 | + |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * This method checks the `ee_has_activated_messenger` option to see if the message type has ever been |
|
1057 | + * activated for the given messenger. This can be called by client code on plugin updates etc to determine whether |
|
1058 | + * to attempt automatically reactivating message types that should be activated by default or not. |
|
1059 | + * |
|
1060 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1061 | + * |
|
1062 | + * @param $message_type_name |
|
1063 | + * @param $messenger_name |
|
1064 | + * @return bool |
|
1065 | + */ |
|
1066 | + public function has_message_type_been_activated_for_messenger($message_type_name, $messenger_name) |
|
1067 | + { |
|
1068 | + $has_activated = $this->get_has_activated_messengers_option(); |
|
1069 | + return isset($has_activated[$messenger_name]) |
|
1070 | + && in_array($message_type_name, $has_activated[$messenger_name]); |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * This method unsets a message type from the given messenger has activated option. |
|
1076 | + * |
|
1077 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1078 | + * |
|
1079 | + * @param string $message_type_name |
|
1080 | + * @param string $messenger_name |
|
1081 | + * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1082 | + * If it is currently active, then remove. Otherwise leave it alone. |
|
1083 | + */ |
|
1084 | + public function remove_message_type_has_been_activated_for_messenger( |
|
1085 | + $message_type_name, |
|
1086 | + $messenger_name, |
|
1087 | + $consider_current_state = false |
|
1088 | + ) { |
|
1089 | + if ($consider_current_state |
|
1090 | + && ! $this->is_message_type_active_for_messenger($messenger_name, $message_type_name) |
|
1091 | + ) { |
|
1092 | + //when consider current state is true, this means we don't want to change anything on the "has_activated" |
|
1093 | + //record if the message type is currently active for this messenger. This is used when we want to retain |
|
1094 | + //the record for user initiated inactivations of the message type. |
|
1095 | + return; |
|
1096 | + } |
|
1097 | + $has_activated = $this->get_has_activated_messengers_option(); |
|
1098 | + $key_for_message_type = isset($has_activated[$messenger_name]) |
|
1099 | + ? array_search($message_type_name, $has_activated[$messenger_name], true) |
|
1100 | + : false; |
|
1101 | + if ($key_for_message_type !== false) { |
|
1102 | + unset($has_activated[$messenger_name][$key_for_message_type]); |
|
1103 | + $this->update_has_activated_messengers_option($has_activated); |
|
1104 | + //reset the internal cached property |
|
1105 | + $this->get_has_activated_messengers_option(true); |
|
1106 | + } |
|
1107 | + } |
|
1108 | + |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * Removes a message type active record from all messengers it is attached to. |
|
1112 | + * |
|
1113 | + * @see phpdocs on EE_Message_Resource_Manager::HAS_ACTIVATED_MESSAGE_TYPE_FOR_MESSENGER_OPTION_NAME for more details. |
|
1114 | + * |
|
1115 | + * @param $message_type_name |
|
1116 | + * @param bool $consider_current_state Whether to consider whether the message type is currently active or not. |
|
1117 | + * If it is currently active, then remove. Otherwise leave it alone. |
|
1118 | + */ |
|
1119 | + public function remove_message_type_has_been_activated_from_all_messengers( |
|
1120 | + $message_type_name, |
|
1121 | + $consider_current_state = false |
|
1122 | + ) { |
|
1123 | + foreach(array_keys($this->get_has_activated_messengers_option()) as $messenger_name) { |
|
1124 | + $this->remove_message_type_has_been_activated_for_messenger( |
|
1125 | + $message_type_name, |
|
1126 | + $messenger_name, |
|
1127 | + $consider_current_state |
|
1128 | + ); |
|
1129 | + } |
|
1130 | + } |
|
1131 | 1131 | } |
1132 | 1132 | // End of file EE_Message_Resource_Manager.lib.php |
1133 | 1133 | // Location: /EE_Message_Resource_Manager.lib.php |
1134 | 1134 | \ No newline at end of file |
@@ -20,33 +20,33 @@ |
||
20 | 20 | class Windows1252 extends FormatterBase |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Converts the string to windows-1252 encoding. |
|
25 | - * |
|
26 | - * @param string|int|float $input anything easily cast into a string |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function format($input) |
|
30 | - { |
|
31 | - //in case an int or float etc was passed in |
|
32 | - $input = (string)$input; |
|
33 | - if (function_exists('iconv')) { |
|
34 | - $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
35 | - } elseif ( WP_DEBUG) { |
|
36 | - trigger_error( |
|
37 | - sprintf( |
|
38 | - // @codingStandardsIgnoreStart |
|
39 | - esc_html__('%1$s could not format the string "%2$s" because the function "%3$s" does not exist. Please verify PHP is installed with this function, see %4$s', 'event_espresso'), |
|
40 | - // @codingStandardsIgnoreEnd |
|
41 | - get_class($this), |
|
42 | - $input, |
|
43 | - 'iconv', |
|
44 | - '<a href="http://php.net/manual/en/iconv.installation.php">http://php.net/manual/en/iconv.installation.php</a>' |
|
45 | - ) |
|
46 | - ); |
|
47 | - } |
|
48 | - return $input; |
|
49 | - } |
|
23 | + /** |
|
24 | + * Converts the string to windows-1252 encoding. |
|
25 | + * |
|
26 | + * @param string|int|float $input anything easily cast into a string |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function format($input) |
|
30 | + { |
|
31 | + //in case an int or float etc was passed in |
|
32 | + $input = (string)$input; |
|
33 | + if (function_exists('iconv')) { |
|
34 | + $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
35 | + } elseif ( WP_DEBUG) { |
|
36 | + trigger_error( |
|
37 | + sprintf( |
|
38 | + // @codingStandardsIgnoreStart |
|
39 | + esc_html__('%1$s could not format the string "%2$s" because the function "%3$s" does not exist. Please verify PHP is installed with this function, see %4$s', 'event_espresso'), |
|
40 | + // @codingStandardsIgnoreEnd |
|
41 | + get_class($this), |
|
42 | + $input, |
|
43 | + 'iconv', |
|
44 | + '<a href="http://php.net/manual/en/iconv.installation.php">http://php.net/manual/en/iconv.installation.php</a>' |
|
45 | + ) |
|
46 | + ); |
|
47 | + } |
|
48 | + return $input; |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | // End of file EmojiRemoval.php |
52 | 52 | // Location: core\services\formatters/EmojiRemoval.php |
@@ -29,10 +29,10 @@ |
||
29 | 29 | public function format($input) |
30 | 30 | { |
31 | 31 | //in case an int or float etc was passed in |
32 | - $input = (string)$input; |
|
32 | + $input = (string) $input; |
|
33 | 33 | if (function_exists('iconv')) { |
34 | 34 | $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
35 | - } elseif ( WP_DEBUG) { |
|
35 | + } elseif (WP_DEBUG) { |
|
36 | 36 | trigger_error( |
37 | 37 | sprintf( |
38 | 38 | // @codingStandardsIgnoreStart |
@@ -17,254 +17,252 @@ |
||
17 | 17 | class TableManager extends \EE_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var TableAnalysis $table_analysis |
|
22 | - */ |
|
23 | - private $table_analysis; |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * TableManager constructor. |
|
29 | - * |
|
30 | - * @param TableAnalysis $TableAnalysis |
|
31 | - */ |
|
32 | - public function __construct(TableAnalysis $TableAnalysis) |
|
33 | - { |
|
34 | - $this->table_analysis = $TableAnalysis; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the injected table analyzer, or throws an exception |
|
41 | - * |
|
42 | - * @return TableAnalysis |
|
43 | - * @throws \EE_Error |
|
44 | - */ |
|
45 | - protected function getTableAnalysis() |
|
46 | - { |
|
47 | - if ($this->table_analysis instanceof TableAnalysis) { |
|
48 | - return $this->table_analysis; |
|
49 | - } else { |
|
50 | - throw new \EE_Error( |
|
51 | - sprintf( |
|
52 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
53 | - get_class($this) |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
63 | - * @param string $column_name |
|
64 | - * @param string $column_info |
|
65 | - * @return bool|false|int |
|
66 | - */ |
|
67 | - public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
68 | - { |
|
69 | - if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
70 | - return false; |
|
71 | - } |
|
72 | - global $wpdb; |
|
73 | - $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
74 | - $columns = $this->getTableColumns($table_name); |
|
75 | - if ( ! in_array($column_name, $columns)) { |
|
76 | - $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
77 | - return $wpdb->query($alter_query); |
|
78 | - } |
|
79 | - return true; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Gets the name of all columns on the table. $table_name can |
|
86 | - * optionally start with $wpdb->prefix or not |
|
87 | - * |
|
88 | - * @global \wpdb $wpdb |
|
89 | - * @param string $table_name |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function getTableColumns($table_name) |
|
93 | - { |
|
94 | - global $wpdb; |
|
95 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
96 | - $field_array = array(); |
|
97 | - if ( ! empty($table_name)) { |
|
98 | - $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
99 | - if ($columns !== false) { |
|
100 | - foreach ($columns as $column) { |
|
101 | - $field_array[] = $column->Field; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return $field_array; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Drops the specified table from the database. $table_name can |
|
112 | - * optionally start with $wpdb->prefix or not |
|
113 | - * |
|
114 | - * @global \wpdb $wpdb |
|
115 | - * @param string $table_name |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function dropTable($table_name) |
|
119 | - { |
|
120 | - global $wpdb; |
|
121 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
122 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
123 | - return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
124 | - } |
|
125 | - return 0; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
132 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
133 | - * Returns the list actually deleted |
|
134 | - * |
|
135 | - * @global WPDB $wpdb |
|
136 | - * @param array $table_names |
|
137 | - * @return array of table names which we deleted |
|
138 | - */ |
|
139 | - public function dropTables($table_names) |
|
140 | - { |
|
141 | - $tables_to_delete = array(); |
|
142 | - foreach ($table_names as $table_name) { |
|
143 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
144 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
145 | - $tables_to_delete[] = $table_name; |
|
146 | - } |
|
147 | - } |
|
148 | - if( ! empty( $tables_to_delete ) ) { |
|
149 | - global $wpdb; |
|
150 | - //make sure we only have a unique strings in the array. |
|
151 | - $tables_to_delete = array_unique($tables_to_delete); |
|
152 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
153 | - } |
|
154 | - return $tables_to_delete; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Drops the specified index from the specified table. $table_name can |
|
161 | - * optionally start with $wpdb->prefix or not |
|
162 | - |
|
163 | - * |
|
20 | + /** |
|
21 | + * @var TableAnalysis $table_analysis |
|
22 | + */ |
|
23 | + private $table_analysis; |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * TableManager constructor. |
|
29 | + * |
|
30 | + * @param TableAnalysis $TableAnalysis |
|
31 | + */ |
|
32 | + public function __construct(TableAnalysis $TableAnalysis) |
|
33 | + { |
|
34 | + $this->table_analysis = $TableAnalysis; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the injected table analyzer, or throws an exception |
|
41 | + * |
|
42 | + * @return TableAnalysis |
|
43 | + * @throws \EE_Error |
|
44 | + */ |
|
45 | + protected function getTableAnalysis() |
|
46 | + { |
|
47 | + if ($this->table_analysis instanceof TableAnalysis) { |
|
48 | + return $this->table_analysis; |
|
49 | + } else { |
|
50 | + throw new \EE_Error( |
|
51 | + sprintf( |
|
52 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
53 | + get_class($this) |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
63 | + * @param string $column_name |
|
64 | + * @param string $column_info |
|
65 | + * @return bool|false|int |
|
66 | + */ |
|
67 | + public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
68 | + { |
|
69 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
70 | + return false; |
|
71 | + } |
|
72 | + global $wpdb; |
|
73 | + $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
74 | + $columns = $this->getTableColumns($table_name); |
|
75 | + if ( ! in_array($column_name, $columns)) { |
|
76 | + $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
77 | + return $wpdb->query($alter_query); |
|
78 | + } |
|
79 | + return true; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Gets the name of all columns on the table. $table_name can |
|
86 | + * optionally start with $wpdb->prefix or not |
|
87 | + * |
|
88 | + * @global \wpdb $wpdb |
|
89 | + * @param string $table_name |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function getTableColumns($table_name) |
|
93 | + { |
|
94 | + global $wpdb; |
|
95 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
96 | + $field_array = array(); |
|
97 | + if ( ! empty($table_name)) { |
|
98 | + $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
99 | + if ($columns !== false) { |
|
100 | + foreach ($columns as $column) { |
|
101 | + $field_array[] = $column->Field; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return $field_array; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Drops the specified table from the database. $table_name can |
|
112 | + * optionally start with $wpdb->prefix or not |
|
113 | + * |
|
114 | + * @global \wpdb $wpdb |
|
115 | + * @param string $table_name |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function dropTable($table_name) |
|
119 | + { |
|
120 | + global $wpdb; |
|
121 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
122 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
123 | + return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
124 | + } |
|
125 | + return 0; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
132 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
133 | + * Returns the list actually deleted |
|
134 | + * |
|
135 | + * @global WPDB $wpdb |
|
136 | + * @param array $table_names |
|
137 | + * @return array of table names which we deleted |
|
138 | + */ |
|
139 | + public function dropTables($table_names) |
|
140 | + { |
|
141 | + $tables_to_delete = array(); |
|
142 | + foreach ($table_names as $table_name) { |
|
143 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
144 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
145 | + $tables_to_delete[] = $table_name; |
|
146 | + } |
|
147 | + } |
|
148 | + if( ! empty( $tables_to_delete ) ) { |
|
149 | + global $wpdb; |
|
150 | + //make sure we only have a unique strings in the array. |
|
151 | + $tables_to_delete = array_unique($tables_to_delete); |
|
152 | + $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
153 | + } |
|
154 | + return $tables_to_delete; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Drops the specified index from the specified table. $table_name can |
|
161 | + * optionally start with $wpdb->prefix or not |
|
162 | + * |
|
164 | 163 | *@global \wpdb $wpdb |
165 | - * @param string $table_name |
|
166 | - * @param string $index_name |
|
167 | - * @return int the number of indexes dropped. False if there was a datbase error |
|
168 | - */ |
|
169 | - public function dropIndex($table_name, $index_name) |
|
170 | - { |
|
171 | - if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
172 | - return 0; |
|
173 | - } |
|
174 | - global $wpdb; |
|
175 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
176 | - $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'"; |
|
177 | - if ( |
|
178 | - $this->getTableAnalysis()->tableExists($table_name) |
|
179 | - && $wpdb->get_var($index_exists_query) |
|
180 | - === $table_name //using get_var with the $index_exists_query returns the table's name |
|
181 | - ) { |
|
182 | - return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
183 | - } |
|
184 | - return 0; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Just creates the requested table. $table_name can |
|
191 | - * optionally start with $wpdb->prefix or not |
|
192 | - |
|
193 | - * |
|
164 | + * @param string $table_name |
|
165 | + * @param string $index_name |
|
166 | + * @return int the number of indexes dropped. False if there was a datbase error |
|
167 | + */ |
|
168 | + public function dropIndex($table_name, $index_name) |
|
169 | + { |
|
170 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
171 | + return 0; |
|
172 | + } |
|
173 | + global $wpdb; |
|
174 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
175 | + $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'"; |
|
176 | + if ( |
|
177 | + $this->getTableAnalysis()->tableExists($table_name) |
|
178 | + && $wpdb->get_var($index_exists_query) |
|
179 | + === $table_name //using get_var with the $index_exists_query returns the table's name |
|
180 | + ) { |
|
181 | + return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
182 | + } |
|
183 | + return 0; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Just creates the requested table. $table_name can |
|
190 | + * optionally start with $wpdb->prefix or not |
|
191 | + * |
|
194 | 192 | *@param string $table_name |
195 | - * @param string $create_sql defining the table's columns and indexes |
|
196 | - * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
197 | - * @return void |
|
198 | - * @throws \EE_Error |
|
199 | - */ |
|
200 | - public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
201 | - { |
|
202 | - // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
203 | - if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
204 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
205 | - /** @var \wpdb $wpdb */ |
|
206 | - global $wpdb; |
|
207 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
208 | - |
|
209 | - //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
210 | - //happened. And then we can choose to tell the end user |
|
211 | - $old_show_errors_policy = $wpdb->show_errors(true); |
|
212 | - $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
213 | - ob_start(); |
|
214 | - dbDelta($SQL); |
|
215 | - $output = ob_get_contents(); |
|
216 | - ob_end_clean(); |
|
217 | - $wpdb->show_errors($old_show_errors_policy); |
|
218 | - $wpdb->suppress_errors($old_error_suppression_policy); |
|
219 | - if ( ! empty($output)) { |
|
220 | - throw new \EE_Error($output); |
|
221 | - } |
|
222 | - } else { |
|
223 | - throw new \EE_Error( |
|
224 | - sprintf( |
|
225 | - __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
226 | - 'event_espresso'), |
|
227 | - '<br />', |
|
228 | - $create_sql |
|
229 | - ) |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Drops the specified index if it's size differs from $desired_index_size. |
|
238 | - * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
239 | - * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
240 | - * If the table doesn't exist, or it exists but the index does not, or returns false |
|
241 | - * |
|
242 | - * @param string $table_name |
|
243 | - * @param string $index_name |
|
244 | - * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE) |
|
245 | - * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
246 | - * @return bool whether an index was dropped or not |
|
247 | - * @throws /EE_Error if table analysis object isn't defined |
|
248 | - */ |
|
249 | - public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
|
250 | - { |
|
251 | - if($column_name === null){ |
|
252 | - $column_name = $index_name; |
|
253 | - } |
|
254 | - if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
255 | - return false; |
|
256 | - } |
|
257 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
258 | - if(empty($index_entries)){ |
|
259 | - return false; |
|
260 | - } |
|
261 | - foreach($index_entries as $index_entry){ |
|
262 | - if( $column_name === $index_entry->Column_name |
|
263 | - && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
264 | - return $this->dropIndex($table_name,$index_name); |
|
265 | - } |
|
266 | - } |
|
267 | - return false; |
|
268 | - } |
|
193 | + * @param string $create_sql defining the table's columns and indexes |
|
194 | + * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
195 | + * @return void |
|
196 | + * @throws \EE_Error |
|
197 | + */ |
|
198 | + public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
199 | + { |
|
200 | + // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
201 | + if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
202 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
203 | + /** @var \wpdb $wpdb */ |
|
204 | + global $wpdb; |
|
205 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
206 | + |
|
207 | + //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
208 | + //happened. And then we can choose to tell the end user |
|
209 | + $old_show_errors_policy = $wpdb->show_errors(true); |
|
210 | + $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
211 | + ob_start(); |
|
212 | + dbDelta($SQL); |
|
213 | + $output = ob_get_contents(); |
|
214 | + ob_end_clean(); |
|
215 | + $wpdb->show_errors($old_show_errors_policy); |
|
216 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
217 | + if ( ! empty($output)) { |
|
218 | + throw new \EE_Error($output); |
|
219 | + } |
|
220 | + } else { |
|
221 | + throw new \EE_Error( |
|
222 | + sprintf( |
|
223 | + __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
224 | + 'event_espresso'), |
|
225 | + '<br />', |
|
226 | + $create_sql |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Drops the specified index if it's size differs from $desired_index_size. |
|
236 | + * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
237 | + * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
238 | + * If the table doesn't exist, or it exists but the index does not, or returns false |
|
239 | + * |
|
240 | + * @param string $table_name |
|
241 | + * @param string $index_name |
|
242 | + * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE) |
|
243 | + * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
244 | + * @return bool whether an index was dropped or not |
|
245 | + * @throws /EE_Error if table analysis object isn't defined |
|
246 | + */ |
|
247 | + public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
|
248 | + { |
|
249 | + if($column_name === null){ |
|
250 | + $column_name = $index_name; |
|
251 | + } |
|
252 | + if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
253 | + return false; |
|
254 | + } |
|
255 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
256 | + if(empty($index_entries)){ |
|
257 | + return false; |
|
258 | + } |
|
259 | + foreach($index_entries as $index_entry){ |
|
260 | + if( $column_name === $index_entry->Column_name |
|
261 | + && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
262 | + return $this->dropIndex($table_name,$index_name); |
|
263 | + } |
|
264 | + } |
|
265 | + return false; |
|
266 | + } |
|
269 | 267 | |
270 | 268 | } |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | $tables_to_delete[] = $table_name; |
146 | 146 | } |
147 | 147 | } |
148 | - if( ! empty( $tables_to_delete ) ) { |
|
148 | + if ( ! empty($tables_to_delete)) { |
|
149 | 149 | global $wpdb; |
150 | 150 | //make sure we only have a unique strings in the array. |
151 | 151 | $tables_to_delete = array_unique($tables_to_delete); |
152 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
152 | + $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete)); |
|
153 | 153 | } |
154 | 154 | return $tables_to_delete; |
155 | 155 | } |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
205 | 205 | /** @var \wpdb $wpdb */ |
206 | 206 | global $wpdb; |
207 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
207 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate(); |
|
208 | 208 | |
209 | 209 | //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
210 | 210 | //happened. And then we can choose to tell the end user |
@@ -248,20 +248,20 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
250 | 250 | { |
251 | - if($column_name === null){ |
|
251 | + if ($column_name === null) { |
|
252 | 252 | $column_name = $index_name; |
253 | 253 | } |
254 | - if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
254 | + if ( ! $this->getTableAnalysis()->tableExists($table_name)) { |
|
255 | 255 | return false; |
256 | 256 | } |
257 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
258 | - if(empty($index_entries)){ |
|
257 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
258 | + if (empty($index_entries)) { |
|
259 | 259 | return false; |
260 | 260 | } |
261 | - foreach($index_entries as $index_entry){ |
|
262 | - if( $column_name === $index_entry->Column_name |
|
263 | - && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
264 | - return $this->dropIndex($table_name,$index_name); |
|
261 | + foreach ($index_entries as $index_entry) { |
|
262 | + if ($column_name === $index_entry->Column_name |
|
263 | + && (string) $desired_index_size !== $index_entry->Sub_part) { |
|
264 | + return $this->dropIndex($table_name, $index_name); |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | return false; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,1142 +16,1142 @@ discard block |
||
16 | 16 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * the input's name attribute |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_html_name; |
|
25 | - |
|
26 | - /** |
|
27 | - * id for the html label tag |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_html_label_id; |
|
32 | - |
|
33 | - /** |
|
34 | - * class for teh html label tag |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $_html_label_class; |
|
39 | - |
|
40 | - /** |
|
41 | - * any additional html attributes that you may want to add |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - protected $_html_other_attributes; |
|
46 | - |
|
47 | - /** |
|
48 | - * style for teh html label tag |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - protected $_html_label_style; |
|
53 | - |
|
54 | - /** |
|
55 | - * text to be placed in the html label |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $_html_label_text; |
|
60 | - |
|
61 | - /** |
|
62 | - * the full html label. If used, all other html_label_* properties are invalid |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - protected $_html_label; |
|
67 | - |
|
68 | - /** |
|
69 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | - * has a class of 'description' |
|
71 | - * |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - protected $_html_help_text; |
|
75 | - |
|
76 | - /** |
|
77 | - * CSS classes for displaying the help span |
|
78 | - * |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - protected $_html_help_class = 'description'; |
|
82 | - |
|
83 | - /** |
|
84 | - * CSS to put in the style attribute on the help span |
|
85 | - * |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $_html_help_style; |
|
89 | - |
|
90 | - /** |
|
91 | - * Stores whether or not this input's response is required. |
|
92 | - * Because certain styling elements may also want to know that this |
|
93 | - * input is required etc. |
|
94 | - * |
|
95 | - * @var boolean |
|
96 | - */ |
|
97 | - protected $_required; |
|
98 | - |
|
99 | - /** |
|
100 | - * css class added to required inputs |
|
101 | - * |
|
102 | - * @var string |
|
103 | - */ |
|
104 | - protected $_required_css_class = 'ee-required'; |
|
105 | - |
|
106 | - /** |
|
107 | - * css styles applied to button type inputs |
|
108 | - * |
|
109 | - * @var string |
|
110 | - */ |
|
111 | - protected $_button_css_attributes; |
|
112 | - |
|
113 | - /** |
|
114 | - * The raw data submitted for this, like in the $_POST super global. |
|
115 | - * Generally unsafe for usage in client code |
|
116 | - * |
|
117 | - * @var mixed string or array |
|
118 | - */ |
|
119 | - protected $_raw_value; |
|
120 | - |
|
121 | - /** |
|
122 | - * Value normalized according to the input's normalization strategy. |
|
123 | - * The normalization strategy dictates whether this is a string, int, float, |
|
124 | - * boolean, or array of any of those. |
|
125 | - * |
|
126 | - * @var mixed |
|
127 | - */ |
|
128 | - protected $_normalized_value; |
|
129 | - |
|
130 | - /** |
|
131 | - * Strategy used for displaying this field. |
|
132 | - * Child classes must use _get_display_strategy to access it. |
|
133 | - * |
|
134 | - * @var EE_Display_Strategy_Base |
|
135 | - */ |
|
136 | - private $_display_strategy; |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets all the validation strategies used on this field |
|
140 | - * |
|
141 | - * @var EE_Validation_Strategy_Base[] |
|
142 | - */ |
|
143 | - private $_validation_strategies = array(); |
|
144 | - |
|
145 | - /** |
|
146 | - * The normalization strategy for this field |
|
147 | - * |
|
148 | - * @var EE_Normalization_Strategy_Base |
|
149 | - */ |
|
150 | - private $_normalization_strategy; |
|
151 | - |
|
152 | - /** |
|
153 | - * Strategy for removing sensitive data after we're done with the form input |
|
154 | - * |
|
155 | - * @var EE_Sensitive_Data_Removal_Base |
|
156 | - */ |
|
157 | - protected $_sensitive_data_removal_strategy; |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param array $input_args { |
|
163 | - * @type string $html_name the html name for the input |
|
164 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
165 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
166 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
167 | - * @type string $html_label_text the text to put in the label tag |
|
168 | - * @type string $html_label the full html label. If used, |
|
169 | - * all other html_label_* args are invalid |
|
170 | - * @type string $html_help_text text to put in help element |
|
171 | - * @type string $html_help_style style attribute to give to teh help element |
|
172 | - * @type string $html_help_class class attribute to give to the help element |
|
173 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
174 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
175 | - * @type EE_Display_Strategy_Base $display strategy |
|
176 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
177 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
178 | - * } |
|
179 | - */ |
|
180 | - public function __construct($input_args = array()) |
|
181 | - { |
|
182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | - // the following properties must be cast as arrays |
|
184 | - if (isset($input_args['validation_strategies'])) { |
|
185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
186 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
187 | - $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
188 | - } |
|
189 | - } |
|
190 | - unset($input_args['validation_strategies']); |
|
191 | - } |
|
192 | - // loop thru incoming options |
|
193 | - foreach ($input_args as $key => $value) { |
|
194 | - // add underscore to $key to match property names |
|
195 | - $_key = '_' . $key; |
|
196 | - if (property_exists($this, $_key)) { |
|
197 | - $this->{$_key} = $value; |
|
198 | - } |
|
199 | - } |
|
200 | - // ensure that "required" is set correctly |
|
201 | - $this->set_required( |
|
202 | - $this->_required, isset($input_args['required_validation_error_message']) |
|
203 | - ? $input_args['required_validation_error_message'] |
|
204 | - : null |
|
205 | - ); |
|
206 | - //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
207 | - $this->_display_strategy->_construct_finalize($this); |
|
208 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
209 | - $validation_strategy->_construct_finalize($this); |
|
210 | - } |
|
211 | - if (! $this->_normalization_strategy) { |
|
212 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
213 | - } |
|
214 | - $this->_normalization_strategy->_construct_finalize($this); |
|
215 | - //at least we can use the normalization strategy to populate the default |
|
216 | - if (isset($input_args['default'])) { |
|
217 | - $this->set_default($input_args['default']); |
|
218 | - } |
|
219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
220 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
221 | - } |
|
222 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
223 | - parent::__construct($input_args); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
230 | - * Calculation involves using the name and the parent's html_name |
|
231 | - * |
|
232 | - * @throws \EE_Error |
|
233 | - */ |
|
234 | - protected function _set_default_html_name_if_empty() |
|
235 | - { |
|
236 | - if (! $this->_html_name) { |
|
237 | - $this->_html_name = $this->name(); |
|
238 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param $parent_form_section |
|
248 | - * @param $name |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public function _construct_finalize($parent_form_section, $name) |
|
252 | - { |
|
253 | - parent::_construct_finalize($parent_form_section, $name); |
|
254 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
255 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
256 | - } |
|
257 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
264 | - * |
|
265 | - * @return EE_Display_Strategy_Base |
|
266 | - * @throws EE_Error |
|
267 | - */ |
|
268 | - protected function _get_display_strategy() |
|
269 | - { |
|
270 | - $this->ensure_construct_finalized_called(); |
|
271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | - throw new EE_Error( |
|
273 | - sprintf( |
|
274 | - __( |
|
275 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
276 | - "event_espresso" |
|
277 | - ), |
|
278 | - $this->html_name(), |
|
279 | - $this->html_id() |
|
280 | - ) |
|
281 | - ); |
|
282 | - } else { |
|
283 | - return $this->_display_strategy; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * Sets the display strategy. |
|
291 | - * |
|
292 | - * @param EE_Display_Strategy_Base $strategy |
|
293 | - */ |
|
294 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
295 | - { |
|
296 | - $this->_display_strategy = $strategy; |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Sets the sanitization strategy |
|
303 | - * |
|
304 | - * @param EE_Normalization_Strategy_Base $strategy |
|
305 | - */ |
|
306 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
307 | - { |
|
308 | - $this->_normalization_strategy = $strategy; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets sensitive_data_removal_strategy |
|
315 | - * |
|
316 | - * @return EE_Sensitive_Data_Removal_Base |
|
317 | - */ |
|
318 | - public function get_sensitive_data_removal_strategy() |
|
319 | - { |
|
320 | - return $this->_sensitive_data_removal_strategy; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Sets sensitive_data_removal_strategy |
|
327 | - * |
|
328 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
329 | - * @return boolean |
|
330 | - */ |
|
331 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
332 | - { |
|
333 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets the display strategy for this input |
|
340 | - * |
|
341 | - * @return EE_Display_Strategy_Base |
|
342 | - */ |
|
343 | - public function get_display_strategy() |
|
344 | - { |
|
345 | - return $this->_display_strategy; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * Overwrites the display strategy |
|
352 | - * |
|
353 | - * @param EE_Display_Strategy_Base $display_strategy |
|
354 | - */ |
|
355 | - public function set_display_strategy($display_strategy) |
|
356 | - { |
|
357 | - $this->_display_strategy = $display_strategy; |
|
358 | - $this->_display_strategy->_construct_finalize($this); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Gets the normalization strategy set on this input |
|
365 | - * |
|
366 | - * @return EE_Normalization_Strategy_Base |
|
367 | - */ |
|
368 | - public function get_normalization_strategy() |
|
369 | - { |
|
370 | - return $this->_normalization_strategy; |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Overwrites the normalization strategy |
|
377 | - * |
|
378 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
379 | - */ |
|
380 | - public function set_normalization_strategy($normalization_strategy) |
|
381 | - { |
|
382 | - $this->_normalization_strategy = $normalization_strategy; |
|
383 | - $this->_normalization_strategy->_construct_finalize($this); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
390 | - * |
|
391 | - * @return EE_Validation_Strategy_Base[] |
|
392 | - */ |
|
393 | - public function get_validation_strategies() |
|
394 | - { |
|
395 | - return $this->_validation_strategies; |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
402 | - * |
|
403 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
404 | - * @return void |
|
405 | - */ |
|
406 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
407 | - { |
|
408 | - $validation_strategy->_construct_finalize($this); |
|
409 | - $this->_validation_strategies[] = $validation_strategy; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Adds a new validation strategy onto the form input |
|
416 | - * |
|
417 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
418 | - * @return void |
|
419 | - */ |
|
420 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
421 | - { |
|
422 | - $this->_add_validation_strategy($validation_strategy); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * The classname of the validation strategy to remove |
|
429 | - * |
|
430 | - * @param string $validation_strategy_classname |
|
431 | - */ |
|
432 | - public function remove_validation_strategy($validation_strategy_classname) |
|
433 | - { |
|
434 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
435 | - if ( |
|
436 | - $validation_strategy instanceof $validation_strategy_classname |
|
437 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
438 | - ) { |
|
439 | - unset($this->_validation_strategies[$key]); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
448 | - * |
|
449 | - * @param array $validation_strategy_classnames |
|
450 | - * @return bool |
|
451 | - */ |
|
452 | - public function has_validation_strategy($validation_strategy_classnames) |
|
453 | - { |
|
454 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
455 | - ? $validation_strategy_classnames |
|
456 | - : array($validation_strategy_classnames); |
|
457 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
458 | - if (in_array($key, $validation_strategy_classnames)) { |
|
459 | - return true; |
|
460 | - } |
|
461 | - } |
|
462 | - return false; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * Gets the HTML |
|
469 | - * |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function get_html() |
|
473 | - { |
|
474 | - return $this->_parent_section->get_html_for_input($this); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
481 | - * input's display strategy |
|
482 | - * Makes sure the JS and CSS are enqueued for it |
|
483 | - * |
|
484 | - * @return string |
|
485 | - * @throws \EE_Error |
|
486 | - */ |
|
487 | - public function get_html_for_input() |
|
488 | - { |
|
489 | - return $this->_form_html_filter |
|
490 | - ? $this->_form_html_filter->filterHtml( |
|
491 | - $this->_get_display_strategy()->display(), |
|
492 | - $this |
|
493 | - ) |
|
494 | - : $this->_get_display_strategy()->display(); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * @return string |
|
501 | - */ |
|
502 | - public function html_other_attributes() |
|
503 | - { |
|
504 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @param string $html_other_attributes |
|
511 | - */ |
|
512 | - public function set_html_other_attributes($html_other_attributes) |
|
513 | - { |
|
514 | - $this->_html_other_attributes = $html_other_attributes; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Gets the HTML for displaying the label for this form input |
|
521 | - * according to the form section's layout strategy |
|
522 | - * |
|
523 | - * @return string |
|
524 | - */ |
|
525 | - public function get_html_for_label() |
|
526 | - { |
|
527 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * Gets the HTML for displaying the errors section for this form input |
|
534 | - * according to the form section's layout strategy |
|
535 | - * |
|
536 | - * @return string |
|
537 | - */ |
|
538 | - public function get_html_for_errors() |
|
539 | - { |
|
540 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
541 | - } |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Gets the HTML for displaying the help text for this form input |
|
547 | - * according to the form section's layout strategy |
|
548 | - * |
|
549 | - * @return string |
|
550 | - */ |
|
551 | - public function get_html_for_help() |
|
552 | - { |
|
553 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
560 | - * and returns whether or not the form input's submitted value is value |
|
561 | - * |
|
562 | - * @return boolean |
|
563 | - */ |
|
564 | - protected function _validate() |
|
565 | - { |
|
566 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
567 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
568 | - try { |
|
569 | - $validation_strategy->validate($this->normalized_value()); |
|
570 | - } catch (EE_Validation_Error $e) { |
|
571 | - $this->add_validation_error($e); |
|
572 | - } |
|
573 | - } |
|
574 | - } |
|
575 | - if ($this->get_validation_errors()) { |
|
576 | - return false; |
|
577 | - } else { |
|
578 | - return true; |
|
579 | - } |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
586 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
587 | - * |
|
588 | - * @param string $value |
|
589 | - * @return null|string |
|
590 | - */ |
|
591 | - private function _sanitize($value) |
|
592 | - { |
|
593 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * Picks out the form value that relates to this form input, |
|
600 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
601 | - * Returns whether or not any validation errors occurred |
|
602 | - * |
|
603 | - * @param array $req_data like $_POST |
|
604 | - * @return boolean whether or not there was an error |
|
605 | - * @throws \EE_Error |
|
606 | - */ |
|
607 | - protected function _normalize($req_data) |
|
608 | - { |
|
609 | - //any existing validation errors don't apply so clear them |
|
610 | - $this->_validation_errors = array(); |
|
611 | - try { |
|
612 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
613 | - //super simple sanitization for now |
|
614 | - if (is_array($raw_input)) { |
|
615 | - $raw_value = array(); |
|
616 | - foreach ($raw_input as $key => $value) { |
|
617 | - $raw_value[$key] = $this->_sanitize($value); |
|
618 | - } |
|
619 | - $this->_set_raw_value($raw_value); |
|
620 | - } else { |
|
621 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
622 | - } |
|
623 | - //we want to mostly leave the input alone in case we need to re-display it to the user |
|
624 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
625 | - } catch (EE_Validation_Error $e) { |
|
626 | - $this->add_validation_error($e); |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * @return string |
|
634 | - */ |
|
635 | - public function html_name() |
|
636 | - { |
|
637 | - $this->_set_default_html_name_if_empty(); |
|
638 | - return $this->_html_name; |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * @return string |
|
645 | - */ |
|
646 | - public function html_label_id() |
|
647 | - { |
|
648 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * @return string |
|
655 | - */ |
|
656 | - public function html_label_class() |
|
657 | - { |
|
658 | - return $this->_html_label_class; |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * @return string |
|
665 | - */ |
|
666 | - public function html_label_style() |
|
667 | - { |
|
668 | - return $this->_html_label_style; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * @return string |
|
675 | - */ |
|
676 | - public function html_label_text() |
|
677 | - { |
|
678 | - return $this->_html_label_text; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * @return string |
|
685 | - */ |
|
686 | - public function html_help_text() |
|
687 | - { |
|
688 | - return $this->_html_help_text; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * @return string |
|
695 | - */ |
|
696 | - public function html_help_class() |
|
697 | - { |
|
698 | - return $this->_html_help_class; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * @return string |
|
705 | - */ |
|
706 | - public function html_help_style() |
|
707 | - { |
|
708 | - return $this->_html_style; |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
715 | - * Please note that almost all client code should instead use the normalized_value; |
|
716 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
717 | - * mostly by escaping quotes) |
|
718 | - * Note, we do not store the exact original value sent in the user's request because |
|
719 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
720 | - * in which case, we would have stored the malicious content to our database. |
|
721 | - * |
|
722 | - * @return string |
|
723 | - */ |
|
724 | - public function raw_value() |
|
725 | - { |
|
726 | - return $this->_raw_value; |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * Returns a string safe to usage in form inputs when displaying, because |
|
733 | - * it escapes all html entities |
|
734 | - * |
|
735 | - * @return string |
|
736 | - */ |
|
737 | - public function raw_value_in_form() |
|
738 | - { |
|
739 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - |
|
744 | - /** |
|
745 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
746 | - * in PHP. Eg, a string, an int, an array, |
|
747 | - * |
|
748 | - * @return mixed |
|
749 | - */ |
|
750 | - public function normalized_value() |
|
751 | - { |
|
752 | - return $this->_normalized_value; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * Returns the normalized value is a presentable way. By default this is just |
|
759 | - * the normalized value by itself, but it can be overridden for when that's not |
|
760 | - * the best thing to display |
|
761 | - * |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public function pretty_value() |
|
765 | - { |
|
766 | - return $this->_normalized_value; |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * When generating the JS for the jquery validation rules like<br> |
|
773 | - * <code>$( "#myform" ).validate({ |
|
774 | - * rules: { |
|
775 | - * password: "required", |
|
776 | - * password_again: { |
|
777 | - * equalTo: "#password" |
|
778 | - * } |
|
779 | - * } |
|
780 | - * });</code> |
|
781 | - * if this field had the name 'password_again', it should return |
|
782 | - * <br><code>password_again: { |
|
783 | - * equalTo: "#password" |
|
784 | - * }</code> |
|
785 | - * |
|
786 | - * @return array |
|
787 | - */ |
|
788 | - public function get_jquery_validation_rules() |
|
789 | - { |
|
790 | - $jquery_validation_js = array(); |
|
791 | - $jquery_validation_rules = array(); |
|
792 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
793 | - $jquery_validation_rules = array_replace_recursive( |
|
794 | - $jquery_validation_rules, |
|
795 | - $validation_strategy->get_jquery_validation_rule_array() |
|
796 | - ); |
|
797 | - } |
|
798 | - if (! empty($jquery_validation_rules)) { |
|
799 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
800 | - $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
801 | - } |
|
802 | - } |
|
803 | - return $jquery_validation_js; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
810 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
811 | - * |
|
812 | - * @param mixed $value |
|
813 | - * @return void |
|
814 | - */ |
|
815 | - public function set_default($value) |
|
816 | - { |
|
817 | - $this->_set_normalized_value($value); |
|
818 | - $this->_set_raw_value($value); |
|
819 | - } |
|
820 | - |
|
821 | - |
|
822 | - |
|
823 | - /** |
|
824 | - * Sets the normalized value on this input |
|
825 | - * |
|
826 | - * @param mixed $value |
|
827 | - */ |
|
828 | - protected function _set_normalized_value($value) |
|
829 | - { |
|
830 | - $this->_normalized_value = $value; |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - |
|
835 | - /** |
|
836 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
837 | - * |
|
838 | - * @param mixed $value |
|
839 | - */ |
|
840 | - protected function _set_raw_value($value) |
|
841 | - { |
|
842 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
843 | - } |
|
844 | - |
|
845 | - |
|
846 | - |
|
847 | - /** |
|
848 | - * Sets the HTML label text after it has already been defined |
|
849 | - * |
|
850 | - * @param string $label |
|
851 | - * @return void |
|
852 | - */ |
|
853 | - public function set_html_label_text($label) |
|
854 | - { |
|
855 | - $this->_html_label_text = $label; |
|
856 | - } |
|
857 | - |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
862 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
863 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
864 | - * |
|
865 | - * @param boolean $required boolean |
|
866 | - * @param null $required_text |
|
867 | - */ |
|
868 | - public function set_required($required = true, $required_text = null) |
|
869 | - { |
|
870 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
871 | - //whether $required is a string or a boolean, we want to add a required validation strategy |
|
872 | - if ($required) { |
|
873 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
874 | - } else { |
|
875 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
876 | - } |
|
877 | - $this->_required = $required; |
|
878 | - } |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * Returns whether or not this field is required |
|
884 | - * |
|
885 | - * @return boolean |
|
886 | - */ |
|
887 | - public function required() |
|
888 | - { |
|
889 | - return $this->_required; |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * @param string $required_css_class |
|
896 | - */ |
|
897 | - public function set_required_css_class($required_css_class) |
|
898 | - { |
|
899 | - $this->_required_css_class = $required_css_class; |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * @return string |
|
906 | - */ |
|
907 | - public function required_css_class() |
|
908 | - { |
|
909 | - return $this->_required_css_class; |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * @param bool $add_required |
|
916 | - * @return string |
|
917 | - */ |
|
918 | - public function html_class($add_required = false) |
|
919 | - { |
|
920 | - return $add_required && $this->required() |
|
921 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
922 | - : $this->_html_class; |
|
923 | - } |
|
924 | - |
|
925 | - |
|
926 | - /** |
|
927 | - * Sets the help text, in case |
|
928 | - * |
|
929 | - * @param string $text |
|
930 | - */ |
|
931 | - public function set_html_help_text($text) |
|
932 | - { |
|
933 | - $this->_html_help_text = $text; |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
940 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
941 | - * out the raw value completely |
|
942 | - * |
|
943 | - * @return void |
|
944 | - */ |
|
945 | - public function clean_sensitive_data() |
|
946 | - { |
|
947 | - //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
948 | - //if we need more logic than this we'll make a strategy for it |
|
949 | - if ($this->_sensitive_data_removal_strategy |
|
950 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
951 | - ) { |
|
952 | - $this->_set_raw_value(null); |
|
953 | - } |
|
954 | - //and clean the normalized value according to the appropriate strategy |
|
955 | - $this->_set_normalized_value( |
|
956 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
957 | - $this->_normalized_value |
|
958 | - ) |
|
959 | - ); |
|
960 | - } |
|
961 | - |
|
962 | - |
|
963 | - |
|
964 | - /** |
|
965 | - * @param bool $primary |
|
966 | - * @param string $button_size |
|
967 | - * @param string $other_attributes |
|
968 | - */ |
|
969 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
970 | - { |
|
971 | - $button_css_attributes = 'button'; |
|
972 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
973 | - switch ($button_size) { |
|
974 | - case 'xs' : |
|
975 | - case 'extra-small' : |
|
976 | - $button_css_attributes .= ' button-xs'; |
|
977 | - break; |
|
978 | - case 'sm' : |
|
979 | - case 'small' : |
|
980 | - $button_css_attributes .= ' button-sm'; |
|
981 | - break; |
|
982 | - case 'lg' : |
|
983 | - case 'large' : |
|
984 | - $button_css_attributes .= ' button-lg'; |
|
985 | - break; |
|
986 | - case 'block' : |
|
987 | - $button_css_attributes .= ' button-block'; |
|
988 | - break; |
|
989 | - case 'md' : |
|
990 | - case 'medium' : |
|
991 | - default : |
|
992 | - $button_css_attributes .= ''; |
|
993 | - } |
|
994 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
995 | - ? $button_css_attributes . ' ' . $other_attributes |
|
996 | - : $button_css_attributes; |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * @return string |
|
1003 | - */ |
|
1004 | - public function button_css_attributes() |
|
1005 | - { |
|
1006 | - if (empty($this->_button_css_attributes)) { |
|
1007 | - $this->set_button_css_attributes(); |
|
1008 | - } |
|
1009 | - return $this->_button_css_attributes; |
|
1010 | - } |
|
1011 | - |
|
1012 | - |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * find_form_data_for_this_section |
|
1016 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1017 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1018 | - * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1019 | - * (If that doesn't exist, we also check for this subsection's name |
|
1020 | - * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1021 | - * This function finds its value in the form. |
|
1022 | - * |
|
1023 | - * @param array $req_data |
|
1024 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1025 | - * @throws \EE_Error |
|
1026 | - */ |
|
1027 | - public function find_form_data_for_this_section($req_data) |
|
1028 | - { |
|
1029 | - // break up the html name by "[]" |
|
1030 | - if (strpos($this->html_name(), '[') !== false) { |
|
1031 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1032 | - } else { |
|
1033 | - $before_any_brackets = $this->html_name(); |
|
1034 | - } |
|
1035 | - // grab all of the segments |
|
1036 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1037 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1038 | - $name_parts = $matches[1]; |
|
1039 | - array_unshift($name_parts, $before_any_brackets); |
|
1040 | - } else { |
|
1041 | - $name_parts = array($before_any_brackets); |
|
1042 | - } |
|
1043 | - // now get the value for the input |
|
1044 | - $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1045 | - // check if this thing's name is at the TOP level of the request data |
|
1046 | - if ($value === null && isset($req_data[$this->name()])) { |
|
1047 | - $value = $req_data[$this->name()]; |
|
1048 | - } |
|
1049 | - return $value; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @param array $html_name_parts |
|
1056 | - * @param array $req_data |
|
1057 | - * @return array | NULL |
|
1058 | - */ |
|
1059 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1060 | - { |
|
1061 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1062 | - if (isset($req_data[$first_part_to_consider])) { |
|
1063 | - if (empty($html_name_parts)) { |
|
1064 | - return $req_data[$first_part_to_consider]; |
|
1065 | - } else { |
|
1066 | - return $this->_find_form_data_for_this_section_using_name_parts( |
|
1067 | - $html_name_parts, |
|
1068 | - $req_data[$first_part_to_consider] |
|
1069 | - ); |
|
1070 | - } |
|
1071 | - } else { |
|
1072 | - return null; |
|
1073 | - } |
|
1074 | - } |
|
1075 | - |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * Checks if this form input's data is in the request data |
|
1080 | - * |
|
1081 | - * @param array $req_data like $_POST |
|
1082 | - * @return boolean |
|
1083 | - * @throws \EE_Error |
|
1084 | - */ |
|
1085 | - public function form_data_present_in($req_data = null) |
|
1086 | - { |
|
1087 | - if ($req_data === null) { |
|
1088 | - $req_data = $_POST; |
|
1089 | - } |
|
1090 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1091 | - if ($checked_value !== null) { |
|
1092 | - return true; |
|
1093 | - } else { |
|
1094 | - return false; |
|
1095 | - } |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Overrides parent to add js data from validation and display strategies |
|
1102 | - * |
|
1103 | - * @param array $form_other_js_data |
|
1104 | - * @return array |
|
1105 | - */ |
|
1106 | - public function get_other_js_data($form_other_js_data = array()) |
|
1107 | - { |
|
1108 | - $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1109 | - return $form_other_js_data; |
|
1110 | - } |
|
1111 | - |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * Gets other JS data for localization from this input's strategies, like |
|
1116 | - * the validation strategies and the display strategy |
|
1117 | - * |
|
1118 | - * @param array $form_other_js_data |
|
1119 | - * @return array |
|
1120 | - */ |
|
1121 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1122 | - { |
|
1123 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1124 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1125 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1126 | - } |
|
1127 | - return $form_other_js_data; |
|
1128 | - } |
|
1129 | - |
|
1130 | - |
|
1131 | - |
|
1132 | - /** |
|
1133 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1134 | - * |
|
1135 | - * @return void |
|
1136 | - */ |
|
1137 | - public function enqueue_js() |
|
1138 | - { |
|
1139 | - //ask our display strategy and validation strategies if they have js to enqueue |
|
1140 | - $this->enqueue_js_from_strategies(); |
|
1141 | - } |
|
1142 | - |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * Tells strategies when its ok to enqueue their js and css |
|
1147 | - * |
|
1148 | - * @return void |
|
1149 | - */ |
|
1150 | - public function enqueue_js_from_strategies() |
|
1151 | - { |
|
1152 | - $this->get_display_strategy()->enqueue_js(); |
|
1153 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1154 | - $validation_strategy->enqueue_js(); |
|
1155 | - } |
|
1156 | - } |
|
19 | + /** |
|
20 | + * the input's name attribute |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_html_name; |
|
25 | + |
|
26 | + /** |
|
27 | + * id for the html label tag |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_html_label_id; |
|
32 | + |
|
33 | + /** |
|
34 | + * class for teh html label tag |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $_html_label_class; |
|
39 | + |
|
40 | + /** |
|
41 | + * any additional html attributes that you may want to add |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + protected $_html_other_attributes; |
|
46 | + |
|
47 | + /** |
|
48 | + * style for teh html label tag |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + protected $_html_label_style; |
|
53 | + |
|
54 | + /** |
|
55 | + * text to be placed in the html label |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $_html_label_text; |
|
60 | + |
|
61 | + /** |
|
62 | + * the full html label. If used, all other html_label_* properties are invalid |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + protected $_html_label; |
|
67 | + |
|
68 | + /** |
|
69 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
70 | + * has a class of 'description' |
|
71 | + * |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + protected $_html_help_text; |
|
75 | + |
|
76 | + /** |
|
77 | + * CSS classes for displaying the help span |
|
78 | + * |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + protected $_html_help_class = 'description'; |
|
82 | + |
|
83 | + /** |
|
84 | + * CSS to put in the style attribute on the help span |
|
85 | + * |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $_html_help_style; |
|
89 | + |
|
90 | + /** |
|
91 | + * Stores whether or not this input's response is required. |
|
92 | + * Because certain styling elements may also want to know that this |
|
93 | + * input is required etc. |
|
94 | + * |
|
95 | + * @var boolean |
|
96 | + */ |
|
97 | + protected $_required; |
|
98 | + |
|
99 | + /** |
|
100 | + * css class added to required inputs |
|
101 | + * |
|
102 | + * @var string |
|
103 | + */ |
|
104 | + protected $_required_css_class = 'ee-required'; |
|
105 | + |
|
106 | + /** |
|
107 | + * css styles applied to button type inputs |
|
108 | + * |
|
109 | + * @var string |
|
110 | + */ |
|
111 | + protected $_button_css_attributes; |
|
112 | + |
|
113 | + /** |
|
114 | + * The raw data submitted for this, like in the $_POST super global. |
|
115 | + * Generally unsafe for usage in client code |
|
116 | + * |
|
117 | + * @var mixed string or array |
|
118 | + */ |
|
119 | + protected $_raw_value; |
|
120 | + |
|
121 | + /** |
|
122 | + * Value normalized according to the input's normalization strategy. |
|
123 | + * The normalization strategy dictates whether this is a string, int, float, |
|
124 | + * boolean, or array of any of those. |
|
125 | + * |
|
126 | + * @var mixed |
|
127 | + */ |
|
128 | + protected $_normalized_value; |
|
129 | + |
|
130 | + /** |
|
131 | + * Strategy used for displaying this field. |
|
132 | + * Child classes must use _get_display_strategy to access it. |
|
133 | + * |
|
134 | + * @var EE_Display_Strategy_Base |
|
135 | + */ |
|
136 | + private $_display_strategy; |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets all the validation strategies used on this field |
|
140 | + * |
|
141 | + * @var EE_Validation_Strategy_Base[] |
|
142 | + */ |
|
143 | + private $_validation_strategies = array(); |
|
144 | + |
|
145 | + /** |
|
146 | + * The normalization strategy for this field |
|
147 | + * |
|
148 | + * @var EE_Normalization_Strategy_Base |
|
149 | + */ |
|
150 | + private $_normalization_strategy; |
|
151 | + |
|
152 | + /** |
|
153 | + * Strategy for removing sensitive data after we're done with the form input |
|
154 | + * |
|
155 | + * @var EE_Sensitive_Data_Removal_Base |
|
156 | + */ |
|
157 | + protected $_sensitive_data_removal_strategy; |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param array $input_args { |
|
163 | + * @type string $html_name the html name for the input |
|
164 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
165 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
166 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
167 | + * @type string $html_label_text the text to put in the label tag |
|
168 | + * @type string $html_label the full html label. If used, |
|
169 | + * all other html_label_* args are invalid |
|
170 | + * @type string $html_help_text text to put in help element |
|
171 | + * @type string $html_help_style style attribute to give to teh help element |
|
172 | + * @type string $html_help_class class attribute to give to the help element |
|
173 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
174 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
175 | + * @type EE_Display_Strategy_Base $display strategy |
|
176 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
177 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
178 | + * } |
|
179 | + */ |
|
180 | + public function __construct($input_args = array()) |
|
181 | + { |
|
182 | + $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | + // the following properties must be cast as arrays |
|
184 | + if (isset($input_args['validation_strategies'])) { |
|
185 | + foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
186 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
187 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
188 | + } |
|
189 | + } |
|
190 | + unset($input_args['validation_strategies']); |
|
191 | + } |
|
192 | + // loop thru incoming options |
|
193 | + foreach ($input_args as $key => $value) { |
|
194 | + // add underscore to $key to match property names |
|
195 | + $_key = '_' . $key; |
|
196 | + if (property_exists($this, $_key)) { |
|
197 | + $this->{$_key} = $value; |
|
198 | + } |
|
199 | + } |
|
200 | + // ensure that "required" is set correctly |
|
201 | + $this->set_required( |
|
202 | + $this->_required, isset($input_args['required_validation_error_message']) |
|
203 | + ? $input_args['required_validation_error_message'] |
|
204 | + : null |
|
205 | + ); |
|
206 | + //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
207 | + $this->_display_strategy->_construct_finalize($this); |
|
208 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
209 | + $validation_strategy->_construct_finalize($this); |
|
210 | + } |
|
211 | + if (! $this->_normalization_strategy) { |
|
212 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
213 | + } |
|
214 | + $this->_normalization_strategy->_construct_finalize($this); |
|
215 | + //at least we can use the normalization strategy to populate the default |
|
216 | + if (isset($input_args['default'])) { |
|
217 | + $this->set_default($input_args['default']); |
|
218 | + } |
|
219 | + if (! $this->_sensitive_data_removal_strategy) { |
|
220 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
221 | + } |
|
222 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
223 | + parent::__construct($input_args); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
230 | + * Calculation involves using the name and the parent's html_name |
|
231 | + * |
|
232 | + * @throws \EE_Error |
|
233 | + */ |
|
234 | + protected function _set_default_html_name_if_empty() |
|
235 | + { |
|
236 | + if (! $this->_html_name) { |
|
237 | + $this->_html_name = $this->name(); |
|
238 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
239 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param $parent_form_section |
|
248 | + * @param $name |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public function _construct_finalize($parent_form_section, $name) |
|
252 | + { |
|
253 | + parent::_construct_finalize($parent_form_section, $name); |
|
254 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
255 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
256 | + } |
|
257 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
264 | + * |
|
265 | + * @return EE_Display_Strategy_Base |
|
266 | + * @throws EE_Error |
|
267 | + */ |
|
268 | + protected function _get_display_strategy() |
|
269 | + { |
|
270 | + $this->ensure_construct_finalized_called(); |
|
271 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | + throw new EE_Error( |
|
273 | + sprintf( |
|
274 | + __( |
|
275 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
276 | + "event_espresso" |
|
277 | + ), |
|
278 | + $this->html_name(), |
|
279 | + $this->html_id() |
|
280 | + ) |
|
281 | + ); |
|
282 | + } else { |
|
283 | + return $this->_display_strategy; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * Sets the display strategy. |
|
291 | + * |
|
292 | + * @param EE_Display_Strategy_Base $strategy |
|
293 | + */ |
|
294 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
295 | + { |
|
296 | + $this->_display_strategy = $strategy; |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Sets the sanitization strategy |
|
303 | + * |
|
304 | + * @param EE_Normalization_Strategy_Base $strategy |
|
305 | + */ |
|
306 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
307 | + { |
|
308 | + $this->_normalization_strategy = $strategy; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets sensitive_data_removal_strategy |
|
315 | + * |
|
316 | + * @return EE_Sensitive_Data_Removal_Base |
|
317 | + */ |
|
318 | + public function get_sensitive_data_removal_strategy() |
|
319 | + { |
|
320 | + return $this->_sensitive_data_removal_strategy; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Sets sensitive_data_removal_strategy |
|
327 | + * |
|
328 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
329 | + * @return boolean |
|
330 | + */ |
|
331 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
332 | + { |
|
333 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets the display strategy for this input |
|
340 | + * |
|
341 | + * @return EE_Display_Strategy_Base |
|
342 | + */ |
|
343 | + public function get_display_strategy() |
|
344 | + { |
|
345 | + return $this->_display_strategy; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * Overwrites the display strategy |
|
352 | + * |
|
353 | + * @param EE_Display_Strategy_Base $display_strategy |
|
354 | + */ |
|
355 | + public function set_display_strategy($display_strategy) |
|
356 | + { |
|
357 | + $this->_display_strategy = $display_strategy; |
|
358 | + $this->_display_strategy->_construct_finalize($this); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Gets the normalization strategy set on this input |
|
365 | + * |
|
366 | + * @return EE_Normalization_Strategy_Base |
|
367 | + */ |
|
368 | + public function get_normalization_strategy() |
|
369 | + { |
|
370 | + return $this->_normalization_strategy; |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Overwrites the normalization strategy |
|
377 | + * |
|
378 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
379 | + */ |
|
380 | + public function set_normalization_strategy($normalization_strategy) |
|
381 | + { |
|
382 | + $this->_normalization_strategy = $normalization_strategy; |
|
383 | + $this->_normalization_strategy->_construct_finalize($this); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
390 | + * |
|
391 | + * @return EE_Validation_Strategy_Base[] |
|
392 | + */ |
|
393 | + public function get_validation_strategies() |
|
394 | + { |
|
395 | + return $this->_validation_strategies; |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
402 | + * |
|
403 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
404 | + * @return void |
|
405 | + */ |
|
406 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
407 | + { |
|
408 | + $validation_strategy->_construct_finalize($this); |
|
409 | + $this->_validation_strategies[] = $validation_strategy; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Adds a new validation strategy onto the form input |
|
416 | + * |
|
417 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
418 | + * @return void |
|
419 | + */ |
|
420 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
421 | + { |
|
422 | + $this->_add_validation_strategy($validation_strategy); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * The classname of the validation strategy to remove |
|
429 | + * |
|
430 | + * @param string $validation_strategy_classname |
|
431 | + */ |
|
432 | + public function remove_validation_strategy($validation_strategy_classname) |
|
433 | + { |
|
434 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
435 | + if ( |
|
436 | + $validation_strategy instanceof $validation_strategy_classname |
|
437 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
438 | + ) { |
|
439 | + unset($this->_validation_strategies[$key]); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
448 | + * |
|
449 | + * @param array $validation_strategy_classnames |
|
450 | + * @return bool |
|
451 | + */ |
|
452 | + public function has_validation_strategy($validation_strategy_classnames) |
|
453 | + { |
|
454 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
455 | + ? $validation_strategy_classnames |
|
456 | + : array($validation_strategy_classnames); |
|
457 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
458 | + if (in_array($key, $validation_strategy_classnames)) { |
|
459 | + return true; |
|
460 | + } |
|
461 | + } |
|
462 | + return false; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * Gets the HTML |
|
469 | + * |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function get_html() |
|
473 | + { |
|
474 | + return $this->_parent_section->get_html_for_input($this); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
481 | + * input's display strategy |
|
482 | + * Makes sure the JS and CSS are enqueued for it |
|
483 | + * |
|
484 | + * @return string |
|
485 | + * @throws \EE_Error |
|
486 | + */ |
|
487 | + public function get_html_for_input() |
|
488 | + { |
|
489 | + return $this->_form_html_filter |
|
490 | + ? $this->_form_html_filter->filterHtml( |
|
491 | + $this->_get_display_strategy()->display(), |
|
492 | + $this |
|
493 | + ) |
|
494 | + : $this->_get_display_strategy()->display(); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * @return string |
|
501 | + */ |
|
502 | + public function html_other_attributes() |
|
503 | + { |
|
504 | + return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @param string $html_other_attributes |
|
511 | + */ |
|
512 | + public function set_html_other_attributes($html_other_attributes) |
|
513 | + { |
|
514 | + $this->_html_other_attributes = $html_other_attributes; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Gets the HTML for displaying the label for this form input |
|
521 | + * according to the form section's layout strategy |
|
522 | + * |
|
523 | + * @return string |
|
524 | + */ |
|
525 | + public function get_html_for_label() |
|
526 | + { |
|
527 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * Gets the HTML for displaying the errors section for this form input |
|
534 | + * according to the form section's layout strategy |
|
535 | + * |
|
536 | + * @return string |
|
537 | + */ |
|
538 | + public function get_html_for_errors() |
|
539 | + { |
|
540 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
541 | + } |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Gets the HTML for displaying the help text for this form input |
|
547 | + * according to the form section's layout strategy |
|
548 | + * |
|
549 | + * @return string |
|
550 | + */ |
|
551 | + public function get_html_for_help() |
|
552 | + { |
|
553 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
560 | + * and returns whether or not the form input's submitted value is value |
|
561 | + * |
|
562 | + * @return boolean |
|
563 | + */ |
|
564 | + protected function _validate() |
|
565 | + { |
|
566 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
567 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
568 | + try { |
|
569 | + $validation_strategy->validate($this->normalized_value()); |
|
570 | + } catch (EE_Validation_Error $e) { |
|
571 | + $this->add_validation_error($e); |
|
572 | + } |
|
573 | + } |
|
574 | + } |
|
575 | + if ($this->get_validation_errors()) { |
|
576 | + return false; |
|
577 | + } else { |
|
578 | + return true; |
|
579 | + } |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
586 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
587 | + * |
|
588 | + * @param string $value |
|
589 | + * @return null|string |
|
590 | + */ |
|
591 | + private function _sanitize($value) |
|
592 | + { |
|
593 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * Picks out the form value that relates to this form input, |
|
600 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
601 | + * Returns whether or not any validation errors occurred |
|
602 | + * |
|
603 | + * @param array $req_data like $_POST |
|
604 | + * @return boolean whether or not there was an error |
|
605 | + * @throws \EE_Error |
|
606 | + */ |
|
607 | + protected function _normalize($req_data) |
|
608 | + { |
|
609 | + //any existing validation errors don't apply so clear them |
|
610 | + $this->_validation_errors = array(); |
|
611 | + try { |
|
612 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
613 | + //super simple sanitization for now |
|
614 | + if (is_array($raw_input)) { |
|
615 | + $raw_value = array(); |
|
616 | + foreach ($raw_input as $key => $value) { |
|
617 | + $raw_value[$key] = $this->_sanitize($value); |
|
618 | + } |
|
619 | + $this->_set_raw_value($raw_value); |
|
620 | + } else { |
|
621 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
622 | + } |
|
623 | + //we want to mostly leave the input alone in case we need to re-display it to the user |
|
624 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
625 | + } catch (EE_Validation_Error $e) { |
|
626 | + $this->add_validation_error($e); |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * @return string |
|
634 | + */ |
|
635 | + public function html_name() |
|
636 | + { |
|
637 | + $this->_set_default_html_name_if_empty(); |
|
638 | + return $this->_html_name; |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * @return string |
|
645 | + */ |
|
646 | + public function html_label_id() |
|
647 | + { |
|
648 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * @return string |
|
655 | + */ |
|
656 | + public function html_label_class() |
|
657 | + { |
|
658 | + return $this->_html_label_class; |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * @return string |
|
665 | + */ |
|
666 | + public function html_label_style() |
|
667 | + { |
|
668 | + return $this->_html_label_style; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * @return string |
|
675 | + */ |
|
676 | + public function html_label_text() |
|
677 | + { |
|
678 | + return $this->_html_label_text; |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * @return string |
|
685 | + */ |
|
686 | + public function html_help_text() |
|
687 | + { |
|
688 | + return $this->_html_help_text; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * @return string |
|
695 | + */ |
|
696 | + public function html_help_class() |
|
697 | + { |
|
698 | + return $this->_html_help_class; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * @return string |
|
705 | + */ |
|
706 | + public function html_help_style() |
|
707 | + { |
|
708 | + return $this->_html_style; |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
715 | + * Please note that almost all client code should instead use the normalized_value; |
|
716 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
717 | + * mostly by escaping quotes) |
|
718 | + * Note, we do not store the exact original value sent in the user's request because |
|
719 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
720 | + * in which case, we would have stored the malicious content to our database. |
|
721 | + * |
|
722 | + * @return string |
|
723 | + */ |
|
724 | + public function raw_value() |
|
725 | + { |
|
726 | + return $this->_raw_value; |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * Returns a string safe to usage in form inputs when displaying, because |
|
733 | + * it escapes all html entities |
|
734 | + * |
|
735 | + * @return string |
|
736 | + */ |
|
737 | + public function raw_value_in_form() |
|
738 | + { |
|
739 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + |
|
744 | + /** |
|
745 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
746 | + * in PHP. Eg, a string, an int, an array, |
|
747 | + * |
|
748 | + * @return mixed |
|
749 | + */ |
|
750 | + public function normalized_value() |
|
751 | + { |
|
752 | + return $this->_normalized_value; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * Returns the normalized value is a presentable way. By default this is just |
|
759 | + * the normalized value by itself, but it can be overridden for when that's not |
|
760 | + * the best thing to display |
|
761 | + * |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public function pretty_value() |
|
765 | + { |
|
766 | + return $this->_normalized_value; |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * When generating the JS for the jquery validation rules like<br> |
|
773 | + * <code>$( "#myform" ).validate({ |
|
774 | + * rules: { |
|
775 | + * password: "required", |
|
776 | + * password_again: { |
|
777 | + * equalTo: "#password" |
|
778 | + * } |
|
779 | + * } |
|
780 | + * });</code> |
|
781 | + * if this field had the name 'password_again', it should return |
|
782 | + * <br><code>password_again: { |
|
783 | + * equalTo: "#password" |
|
784 | + * }</code> |
|
785 | + * |
|
786 | + * @return array |
|
787 | + */ |
|
788 | + public function get_jquery_validation_rules() |
|
789 | + { |
|
790 | + $jquery_validation_js = array(); |
|
791 | + $jquery_validation_rules = array(); |
|
792 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
793 | + $jquery_validation_rules = array_replace_recursive( |
|
794 | + $jquery_validation_rules, |
|
795 | + $validation_strategy->get_jquery_validation_rule_array() |
|
796 | + ); |
|
797 | + } |
|
798 | + if (! empty($jquery_validation_rules)) { |
|
799 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
800 | + $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
|
801 | + } |
|
802 | + } |
|
803 | + return $jquery_validation_js; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
810 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
811 | + * |
|
812 | + * @param mixed $value |
|
813 | + * @return void |
|
814 | + */ |
|
815 | + public function set_default($value) |
|
816 | + { |
|
817 | + $this->_set_normalized_value($value); |
|
818 | + $this->_set_raw_value($value); |
|
819 | + } |
|
820 | + |
|
821 | + |
|
822 | + |
|
823 | + /** |
|
824 | + * Sets the normalized value on this input |
|
825 | + * |
|
826 | + * @param mixed $value |
|
827 | + */ |
|
828 | + protected function _set_normalized_value($value) |
|
829 | + { |
|
830 | + $this->_normalized_value = $value; |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + |
|
835 | + /** |
|
836 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
837 | + * |
|
838 | + * @param mixed $value |
|
839 | + */ |
|
840 | + protected function _set_raw_value($value) |
|
841 | + { |
|
842 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
843 | + } |
|
844 | + |
|
845 | + |
|
846 | + |
|
847 | + /** |
|
848 | + * Sets the HTML label text after it has already been defined |
|
849 | + * |
|
850 | + * @param string $label |
|
851 | + * @return void |
|
852 | + */ |
|
853 | + public function set_html_label_text($label) |
|
854 | + { |
|
855 | + $this->_html_label_text = $label; |
|
856 | + } |
|
857 | + |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
862 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
863 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
864 | + * |
|
865 | + * @param boolean $required boolean |
|
866 | + * @param null $required_text |
|
867 | + */ |
|
868 | + public function set_required($required = true, $required_text = null) |
|
869 | + { |
|
870 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
871 | + //whether $required is a string or a boolean, we want to add a required validation strategy |
|
872 | + if ($required) { |
|
873 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
874 | + } else { |
|
875 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
876 | + } |
|
877 | + $this->_required = $required; |
|
878 | + } |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * Returns whether or not this field is required |
|
884 | + * |
|
885 | + * @return boolean |
|
886 | + */ |
|
887 | + public function required() |
|
888 | + { |
|
889 | + return $this->_required; |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * @param string $required_css_class |
|
896 | + */ |
|
897 | + public function set_required_css_class($required_css_class) |
|
898 | + { |
|
899 | + $this->_required_css_class = $required_css_class; |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * @return string |
|
906 | + */ |
|
907 | + public function required_css_class() |
|
908 | + { |
|
909 | + return $this->_required_css_class; |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * @param bool $add_required |
|
916 | + * @return string |
|
917 | + */ |
|
918 | + public function html_class($add_required = false) |
|
919 | + { |
|
920 | + return $add_required && $this->required() |
|
921 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
922 | + : $this->_html_class; |
|
923 | + } |
|
924 | + |
|
925 | + |
|
926 | + /** |
|
927 | + * Sets the help text, in case |
|
928 | + * |
|
929 | + * @param string $text |
|
930 | + */ |
|
931 | + public function set_html_help_text($text) |
|
932 | + { |
|
933 | + $this->_html_help_text = $text; |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
940 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
941 | + * out the raw value completely |
|
942 | + * |
|
943 | + * @return void |
|
944 | + */ |
|
945 | + public function clean_sensitive_data() |
|
946 | + { |
|
947 | + //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
948 | + //if we need more logic than this we'll make a strategy for it |
|
949 | + if ($this->_sensitive_data_removal_strategy |
|
950 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
951 | + ) { |
|
952 | + $this->_set_raw_value(null); |
|
953 | + } |
|
954 | + //and clean the normalized value according to the appropriate strategy |
|
955 | + $this->_set_normalized_value( |
|
956 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
957 | + $this->_normalized_value |
|
958 | + ) |
|
959 | + ); |
|
960 | + } |
|
961 | + |
|
962 | + |
|
963 | + |
|
964 | + /** |
|
965 | + * @param bool $primary |
|
966 | + * @param string $button_size |
|
967 | + * @param string $other_attributes |
|
968 | + */ |
|
969 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
970 | + { |
|
971 | + $button_css_attributes = 'button'; |
|
972 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
973 | + switch ($button_size) { |
|
974 | + case 'xs' : |
|
975 | + case 'extra-small' : |
|
976 | + $button_css_attributes .= ' button-xs'; |
|
977 | + break; |
|
978 | + case 'sm' : |
|
979 | + case 'small' : |
|
980 | + $button_css_attributes .= ' button-sm'; |
|
981 | + break; |
|
982 | + case 'lg' : |
|
983 | + case 'large' : |
|
984 | + $button_css_attributes .= ' button-lg'; |
|
985 | + break; |
|
986 | + case 'block' : |
|
987 | + $button_css_attributes .= ' button-block'; |
|
988 | + break; |
|
989 | + case 'md' : |
|
990 | + case 'medium' : |
|
991 | + default : |
|
992 | + $button_css_attributes .= ''; |
|
993 | + } |
|
994 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
995 | + ? $button_css_attributes . ' ' . $other_attributes |
|
996 | + : $button_css_attributes; |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * @return string |
|
1003 | + */ |
|
1004 | + public function button_css_attributes() |
|
1005 | + { |
|
1006 | + if (empty($this->_button_css_attributes)) { |
|
1007 | + $this->set_button_css_attributes(); |
|
1008 | + } |
|
1009 | + return $this->_button_css_attributes; |
|
1010 | + } |
|
1011 | + |
|
1012 | + |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * find_form_data_for_this_section |
|
1016 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1017 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1018 | + * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1019 | + * (If that doesn't exist, we also check for this subsection's name |
|
1020 | + * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1021 | + * This function finds its value in the form. |
|
1022 | + * |
|
1023 | + * @param array $req_data |
|
1024 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1025 | + * @throws \EE_Error |
|
1026 | + */ |
|
1027 | + public function find_form_data_for_this_section($req_data) |
|
1028 | + { |
|
1029 | + // break up the html name by "[]" |
|
1030 | + if (strpos($this->html_name(), '[') !== false) { |
|
1031 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1032 | + } else { |
|
1033 | + $before_any_brackets = $this->html_name(); |
|
1034 | + } |
|
1035 | + // grab all of the segments |
|
1036 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1037 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1038 | + $name_parts = $matches[1]; |
|
1039 | + array_unshift($name_parts, $before_any_brackets); |
|
1040 | + } else { |
|
1041 | + $name_parts = array($before_any_brackets); |
|
1042 | + } |
|
1043 | + // now get the value for the input |
|
1044 | + $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
|
1045 | + // check if this thing's name is at the TOP level of the request data |
|
1046 | + if ($value === null && isset($req_data[$this->name()])) { |
|
1047 | + $value = $req_data[$this->name()]; |
|
1048 | + } |
|
1049 | + return $value; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @param array $html_name_parts |
|
1056 | + * @param array $req_data |
|
1057 | + * @return array | NULL |
|
1058 | + */ |
|
1059 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) |
|
1060 | + { |
|
1061 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1062 | + if (isset($req_data[$first_part_to_consider])) { |
|
1063 | + if (empty($html_name_parts)) { |
|
1064 | + return $req_data[$first_part_to_consider]; |
|
1065 | + } else { |
|
1066 | + return $this->_find_form_data_for_this_section_using_name_parts( |
|
1067 | + $html_name_parts, |
|
1068 | + $req_data[$first_part_to_consider] |
|
1069 | + ); |
|
1070 | + } |
|
1071 | + } else { |
|
1072 | + return null; |
|
1073 | + } |
|
1074 | + } |
|
1075 | + |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * Checks if this form input's data is in the request data |
|
1080 | + * |
|
1081 | + * @param array $req_data like $_POST |
|
1082 | + * @return boolean |
|
1083 | + * @throws \EE_Error |
|
1084 | + */ |
|
1085 | + public function form_data_present_in($req_data = null) |
|
1086 | + { |
|
1087 | + if ($req_data === null) { |
|
1088 | + $req_data = $_POST; |
|
1089 | + } |
|
1090 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1091 | + if ($checked_value !== null) { |
|
1092 | + return true; |
|
1093 | + } else { |
|
1094 | + return false; |
|
1095 | + } |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Overrides parent to add js data from validation and display strategies |
|
1102 | + * |
|
1103 | + * @param array $form_other_js_data |
|
1104 | + * @return array |
|
1105 | + */ |
|
1106 | + public function get_other_js_data($form_other_js_data = array()) |
|
1107 | + { |
|
1108 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1109 | + return $form_other_js_data; |
|
1110 | + } |
|
1111 | + |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * Gets other JS data for localization from this input's strategies, like |
|
1116 | + * the validation strategies and the display strategy |
|
1117 | + * |
|
1118 | + * @param array $form_other_js_data |
|
1119 | + * @return array |
|
1120 | + */ |
|
1121 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1122 | + { |
|
1123 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1124 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1125 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1126 | + } |
|
1127 | + return $form_other_js_data; |
|
1128 | + } |
|
1129 | + |
|
1130 | + |
|
1131 | + |
|
1132 | + /** |
|
1133 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1134 | + * |
|
1135 | + * @return void |
|
1136 | + */ |
|
1137 | + public function enqueue_js() |
|
1138 | + { |
|
1139 | + //ask our display strategy and validation strategies if they have js to enqueue |
|
1140 | + $this->enqueue_js_from_strategies(); |
|
1141 | + } |
|
1142 | + |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * Tells strategies when its ok to enqueue their js and css |
|
1147 | + * |
|
1148 | + * @return void |
|
1149 | + */ |
|
1150 | + public function enqueue_js_from_strategies() |
|
1151 | + { |
|
1152 | + $this->get_display_strategy()->enqueue_js(); |
|
1153 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1154 | + $validation_strategy->enqueue_js(); |
|
1155 | + } |
|
1156 | + } |
|
1157 | 1157 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function __construct($input_args = array()) |
181 | 181 | { |
182 | - $input_args = (array)apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
182 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
183 | 183 | // the following properties must be cast as arrays |
184 | 184 | if (isset($input_args['validation_strategies'])) { |
185 | - foreach ((array)$input_args['validation_strategies'] as $validation_strategy) { |
|
185 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
186 | 186 | if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
187 | 187 | $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
188 | 188 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | // loop thru incoming options |
193 | 193 | foreach ($input_args as $key => $value) { |
194 | 194 | // add underscore to $key to match property names |
195 | - $_key = '_' . $key; |
|
195 | + $_key = '_'.$key; |
|
196 | 196 | if (property_exists($this, $_key)) { |
197 | 197 | $this->{$_key} = $value; |
198 | 198 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | foreach ($this->_validation_strategies as $validation_strategy) { |
209 | 209 | $validation_strategy->_construct_finalize($this); |
210 | 210 | } |
211 | - if (! $this->_normalization_strategy) { |
|
211 | + if ( ! $this->_normalization_strategy) { |
|
212 | 212 | $this->_normalization_strategy = new EE_Text_Normalization(); |
213 | 213 | } |
214 | 214 | $this->_normalization_strategy->_construct_finalize($this); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | if (isset($input_args['default'])) { |
217 | 217 | $this->set_default($input_args['default']); |
218 | 218 | } |
219 | - if (! $this->_sensitive_data_removal_strategy) { |
|
219 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
220 | 220 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
221 | 221 | } |
222 | 222 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
@@ -233,10 +233,10 @@ discard block |
||
233 | 233 | */ |
234 | 234 | protected function _set_default_html_name_if_empty() |
235 | 235 | { |
236 | - if (! $this->_html_name) { |
|
236 | + if ( ! $this->_html_name) { |
|
237 | 237 | $this->_html_name = $this->name(); |
238 | 238 | if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
239 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
239 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | protected function _get_display_strategy() |
269 | 269 | { |
270 | 270 | $this->ensure_construct_finalized_called(); |
271 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
271 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
272 | 272 | throw new EE_Error( |
273 | 273 | sprintf( |
274 | 274 | __( |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | */ |
502 | 502 | public function html_other_attributes() |
503 | 503 | { |
504 | - return ! empty($this->_html_other_attributes) ? ' ' . $this->_html_other_attributes : ''; |
|
504 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | */ |
646 | 646 | public function html_label_id() |
647 | 647 | { |
648 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
648 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl'; |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | $validation_strategy->get_jquery_validation_rule_array() |
796 | 796 | ); |
797 | 797 | } |
798 | - if (! empty($jquery_validation_rules)) { |
|
798 | + if ( ! empty($jquery_validation_rules)) { |
|
799 | 799 | foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
800 | 800 | $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules; |
801 | 801 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | public function html_class($add_required = false) |
919 | 919 | { |
920 | 920 | return $add_required && $this->required() |
921 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
921 | + ? $this->required_css_class().' '.$this->_html_class |
|
922 | 922 | : $this->_html_class; |
923 | 923 | } |
924 | 924 | |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | $button_css_attributes .= ''; |
993 | 993 | } |
994 | 994 | $this->_button_css_attributes .= ! empty($other_attributes) |
995 | - ? $button_css_attributes . ' ' . $other_attributes |
|
995 | + ? $button_css_attributes.' '.$other_attributes |
|
996 | 996 | : $button_css_attributes; |
997 | 997 | } |
998 | 998 |
@@ -13,386 +13,386 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * Creates the array for the tips |
|
18 | - */ |
|
19 | - protected function _set_tips_array() |
|
20 | - { |
|
21 | - $this->_qtipsa = array( |
|
22 | - 2 => array( |
|
23 | - 'content_id' => 'dtt-evt-name-label', |
|
24 | - 'target' => '.DTT_name_label', |
|
25 | - 'content' => $this->_get_event_name_label_info(), |
|
26 | - ), |
|
27 | - 3 => array( |
|
28 | - 'content_id' => 'dtt-evt-start-label', |
|
29 | - 'target' => '.DTT_EVT_start_label', |
|
30 | - 'content' => $this->_get_event_start_label_info(), |
|
31 | - ), |
|
32 | - 5 => array( |
|
33 | - 'content_id' => 'dtt-evt-end-label', |
|
34 | - 'target' => '.DTT_EVT_end_label', |
|
35 | - 'content' => $this->_get_event_end_label_info(), |
|
36 | - ), |
|
37 | - 10 => array( |
|
38 | - 'content_id' => 'dtt-reg-limit-label', |
|
39 | - 'target' => '.DTT_reg_limit_label', |
|
40 | - 'content' => $this->_get_event_datetime_DTT_reg_limit_label_info(), |
|
41 | - ), |
|
42 | - 15 => array( |
|
43 | - 'content_id' => 'dtt-sold-label', |
|
44 | - 'target' => '.DTT_sold_label', |
|
45 | - 'content' => $this->_get_event_datetime_DTT_sold_label_info(), |
|
46 | - ), |
|
47 | - 17 => array( |
|
48 | - 'content_id' => 'dtt-reserved-label', |
|
49 | - 'target' => '.DTT_reserved_label', |
|
50 | - 'content' => $this->_get_event_datetime_DTT_reserved_label_info(), |
|
51 | - ), |
|
52 | - 20 => array( |
|
53 | - 'content_id' => 'tkt-name-label', |
|
54 | - 'target' => '.TKT_name_label', |
|
55 | - 'content' => $this->_get_event_ticket_TKT_name_label_info(), |
|
56 | - ), |
|
57 | - 25 => array( |
|
58 | - 'content_id' => 'tkt-goes-on-sale-label', |
|
59 | - 'target' => '.TKT_goes_on_sale_label', |
|
60 | - 'content' => $this->_get_event_ticket_TKT_goes_on_sale_label_info(), |
|
61 | - ), |
|
62 | - 30 => array( |
|
63 | - 'content_id' => 'tkt-sell-until-label', |
|
64 | - 'target' => '.TKT_sell_until_label', |
|
65 | - 'content' => $this->_get_event_ticket_TKT_sell_until_label_info(), |
|
66 | - ), |
|
67 | - 35 => array( |
|
68 | - 'content_id' => 'tkt-price-label', |
|
69 | - 'target' => '.TKT_price_label', |
|
70 | - 'content' => $this->_get_event_ticket_TKT_price_label_info(), |
|
71 | - ), |
|
72 | - 40 => array( |
|
73 | - 'content_id' => 'tkt-qty-label', |
|
74 | - 'target' => '.TKT_qty_label', |
|
75 | - 'content' => $this->_get_event_ticket_TKT_qty_label_info(), |
|
76 | - ), |
|
77 | - 45 => array( |
|
78 | - 'content_id' => 'tkt-sold-label', |
|
79 | - 'target' => '.TKT_sold_label', |
|
80 | - 'content' => $this->_get_event_ticket_TKT_sold_label_info(), |
|
81 | - ), |
|
82 | - 47 => array( |
|
83 | - 'content_id' => 'tkt-reserved-label', |
|
84 | - 'target' => '.TKT_reserved_label', |
|
85 | - 'content' => $this->_get_event_ticket_TKT_reserved_label_info(), |
|
86 | - ), |
|
87 | - 50 => array( |
|
88 | - 'content_id' => 'tkt-regs-label', |
|
89 | - 'target' => '.TKT_regs_label', |
|
90 | - 'content' => $this->_get_event_ticket_TKT_regs_label_info(), |
|
91 | - ), |
|
92 | - 55 => array( |
|
93 | - 'content_id' => 'ant-tkt-name-label', |
|
94 | - 'target' => '.ANT_TKT_name_label', |
|
95 | - 'content' => $this->_get_event_ticket_ANT_TKT_name_label_info(), |
|
96 | - ), |
|
97 | - 60 => array( |
|
98 | - 'content_id' => 'ant-tkt-goes-on-sale-label', |
|
99 | - 'target' => '.ANT_TKT_goes_on_sale_label', |
|
100 | - 'content' => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(), |
|
101 | - ), |
|
102 | - 65 => array( |
|
103 | - 'content_id' => 'ant-tkt-sell-until-label', |
|
104 | - 'target' => '.ANT_TKT_sell_until_label', |
|
105 | - 'content' => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(), |
|
106 | - ), |
|
107 | - 70 => array( |
|
108 | - 'content_id' => 'ant-tkt-price-label', |
|
109 | - 'target' => '.ANT_TKT_price_label', |
|
110 | - 'content' => $this->_get_event_ticket_ANT_TKT_price_label_info(), |
|
111 | - ), |
|
112 | - 75 => array( |
|
113 | - 'content_id' => 'ant-tkt-qty-label', |
|
114 | - 'target' => '.ANT_TKT_qty_label', |
|
115 | - 'content' => $this->_get_event_ticket_ANT_TKT_qty_label_info(), |
|
116 | - ), |
|
117 | - 80 => array( |
|
118 | - 'content_id' => 'ane-dtt-evt-start-label', |
|
119 | - 'target' => '.add-new-event-datetime-DTT_EVT_start_label', |
|
120 | - 'content' => $this->_get_add_new_event_start_label_info(), |
|
121 | - ), |
|
122 | - 85 => array( |
|
123 | - 'content_id' => 'ane-dtt-evt-end-label', |
|
124 | - 'target' => '.add-new-event-datetime-DTT_EVT_end_label', |
|
125 | - 'content' => $this->_get_add_new_event_end_label_info(), |
|
126 | - ), |
|
127 | - 90 => array( |
|
128 | - 'content_id' => 'ane_dtt-reg-limit-label', |
|
129 | - 'target' => '.add-new-event-datetime-DTT_reg_limit_label', |
|
130 | - 'content' => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(), |
|
131 | - ), |
|
132 | - 100 => array( |
|
133 | - 'content_id' => 'td-tkt-number-datetimes-label', |
|
134 | - 'target' => '.TD_TKT_number_datetimes_label', |
|
135 | - 'content' => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(), |
|
136 | - ), |
|
137 | - 110 => array( |
|
138 | - 'content_id' => 'td-tkt-min-qty-label', |
|
139 | - 'target' => '.TD_TKT_min_qty_label', |
|
140 | - 'content' => $this->_get_event_ticket_TD_TKT_min_qty_label_info(), |
|
141 | - ), |
|
142 | - 120 => array( |
|
143 | - 'content_id' => 'td-tkt-max-qty-label', |
|
144 | - 'target' => '.TD_TKT_max_qty_label', |
|
145 | - 'content' => $this->_get_event_ticket_TD_TKT_max_qty_label_info(), |
|
146 | - ), |
|
147 | - 130 => array( |
|
148 | - 'content_id' => 'ticket-lock-icon', |
|
149 | - 'target' => '.ticket-archived .ee-lock-icon', |
|
150 | - 'content' => esc_html__( |
|
151 | - 'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).', |
|
152 | - 'event_espresso' |
|
153 | - ), |
|
154 | - ), |
|
155 | - 135 => array( |
|
156 | - 'content_id' => 'ticket-lock-icon-event-editor', |
|
157 | - 'target' => '.ee-lock-icon', |
|
158 | - 'content' => esc_html__( |
|
159 | - 'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - ), |
|
163 | - ); |
|
164 | - } |
|
16 | + /** |
|
17 | + * Creates the array for the tips |
|
18 | + */ |
|
19 | + protected function _set_tips_array() |
|
20 | + { |
|
21 | + $this->_qtipsa = array( |
|
22 | + 2 => array( |
|
23 | + 'content_id' => 'dtt-evt-name-label', |
|
24 | + 'target' => '.DTT_name_label', |
|
25 | + 'content' => $this->_get_event_name_label_info(), |
|
26 | + ), |
|
27 | + 3 => array( |
|
28 | + 'content_id' => 'dtt-evt-start-label', |
|
29 | + 'target' => '.DTT_EVT_start_label', |
|
30 | + 'content' => $this->_get_event_start_label_info(), |
|
31 | + ), |
|
32 | + 5 => array( |
|
33 | + 'content_id' => 'dtt-evt-end-label', |
|
34 | + 'target' => '.DTT_EVT_end_label', |
|
35 | + 'content' => $this->_get_event_end_label_info(), |
|
36 | + ), |
|
37 | + 10 => array( |
|
38 | + 'content_id' => 'dtt-reg-limit-label', |
|
39 | + 'target' => '.DTT_reg_limit_label', |
|
40 | + 'content' => $this->_get_event_datetime_DTT_reg_limit_label_info(), |
|
41 | + ), |
|
42 | + 15 => array( |
|
43 | + 'content_id' => 'dtt-sold-label', |
|
44 | + 'target' => '.DTT_sold_label', |
|
45 | + 'content' => $this->_get_event_datetime_DTT_sold_label_info(), |
|
46 | + ), |
|
47 | + 17 => array( |
|
48 | + 'content_id' => 'dtt-reserved-label', |
|
49 | + 'target' => '.DTT_reserved_label', |
|
50 | + 'content' => $this->_get_event_datetime_DTT_reserved_label_info(), |
|
51 | + ), |
|
52 | + 20 => array( |
|
53 | + 'content_id' => 'tkt-name-label', |
|
54 | + 'target' => '.TKT_name_label', |
|
55 | + 'content' => $this->_get_event_ticket_TKT_name_label_info(), |
|
56 | + ), |
|
57 | + 25 => array( |
|
58 | + 'content_id' => 'tkt-goes-on-sale-label', |
|
59 | + 'target' => '.TKT_goes_on_sale_label', |
|
60 | + 'content' => $this->_get_event_ticket_TKT_goes_on_sale_label_info(), |
|
61 | + ), |
|
62 | + 30 => array( |
|
63 | + 'content_id' => 'tkt-sell-until-label', |
|
64 | + 'target' => '.TKT_sell_until_label', |
|
65 | + 'content' => $this->_get_event_ticket_TKT_sell_until_label_info(), |
|
66 | + ), |
|
67 | + 35 => array( |
|
68 | + 'content_id' => 'tkt-price-label', |
|
69 | + 'target' => '.TKT_price_label', |
|
70 | + 'content' => $this->_get_event_ticket_TKT_price_label_info(), |
|
71 | + ), |
|
72 | + 40 => array( |
|
73 | + 'content_id' => 'tkt-qty-label', |
|
74 | + 'target' => '.TKT_qty_label', |
|
75 | + 'content' => $this->_get_event_ticket_TKT_qty_label_info(), |
|
76 | + ), |
|
77 | + 45 => array( |
|
78 | + 'content_id' => 'tkt-sold-label', |
|
79 | + 'target' => '.TKT_sold_label', |
|
80 | + 'content' => $this->_get_event_ticket_TKT_sold_label_info(), |
|
81 | + ), |
|
82 | + 47 => array( |
|
83 | + 'content_id' => 'tkt-reserved-label', |
|
84 | + 'target' => '.TKT_reserved_label', |
|
85 | + 'content' => $this->_get_event_ticket_TKT_reserved_label_info(), |
|
86 | + ), |
|
87 | + 50 => array( |
|
88 | + 'content_id' => 'tkt-regs-label', |
|
89 | + 'target' => '.TKT_regs_label', |
|
90 | + 'content' => $this->_get_event_ticket_TKT_regs_label_info(), |
|
91 | + ), |
|
92 | + 55 => array( |
|
93 | + 'content_id' => 'ant-tkt-name-label', |
|
94 | + 'target' => '.ANT_TKT_name_label', |
|
95 | + 'content' => $this->_get_event_ticket_ANT_TKT_name_label_info(), |
|
96 | + ), |
|
97 | + 60 => array( |
|
98 | + 'content_id' => 'ant-tkt-goes-on-sale-label', |
|
99 | + 'target' => '.ANT_TKT_goes_on_sale_label', |
|
100 | + 'content' => $this->_get_event_ticket_ANT_TKT_goes_on_sale_label_info(), |
|
101 | + ), |
|
102 | + 65 => array( |
|
103 | + 'content_id' => 'ant-tkt-sell-until-label', |
|
104 | + 'target' => '.ANT_TKT_sell_until_label', |
|
105 | + 'content' => $this->_get_event_ticket_ANT_TKT_sell_until_label_info(), |
|
106 | + ), |
|
107 | + 70 => array( |
|
108 | + 'content_id' => 'ant-tkt-price-label', |
|
109 | + 'target' => '.ANT_TKT_price_label', |
|
110 | + 'content' => $this->_get_event_ticket_ANT_TKT_price_label_info(), |
|
111 | + ), |
|
112 | + 75 => array( |
|
113 | + 'content_id' => 'ant-tkt-qty-label', |
|
114 | + 'target' => '.ANT_TKT_qty_label', |
|
115 | + 'content' => $this->_get_event_ticket_ANT_TKT_qty_label_info(), |
|
116 | + ), |
|
117 | + 80 => array( |
|
118 | + 'content_id' => 'ane-dtt-evt-start-label', |
|
119 | + 'target' => '.add-new-event-datetime-DTT_EVT_start_label', |
|
120 | + 'content' => $this->_get_add_new_event_start_label_info(), |
|
121 | + ), |
|
122 | + 85 => array( |
|
123 | + 'content_id' => 'ane-dtt-evt-end-label', |
|
124 | + 'target' => '.add-new-event-datetime-DTT_EVT_end_label', |
|
125 | + 'content' => $this->_get_add_new_event_end_label_info(), |
|
126 | + ), |
|
127 | + 90 => array( |
|
128 | + 'content_id' => 'ane_dtt-reg-limit-label', |
|
129 | + 'target' => '.add-new-event-datetime-DTT_reg_limit_label', |
|
130 | + 'content' => $this->_get_add_new_event_datetime_DTT_reg_limit_label_info(), |
|
131 | + ), |
|
132 | + 100 => array( |
|
133 | + 'content_id' => 'td-tkt-number-datetimes-label', |
|
134 | + 'target' => '.TD_TKT_number_datetimes_label', |
|
135 | + 'content' => $this->_get_event_ticket_TD_TKT_number_datetimes_label_info(), |
|
136 | + ), |
|
137 | + 110 => array( |
|
138 | + 'content_id' => 'td-tkt-min-qty-label', |
|
139 | + 'target' => '.TD_TKT_min_qty_label', |
|
140 | + 'content' => $this->_get_event_ticket_TD_TKT_min_qty_label_info(), |
|
141 | + ), |
|
142 | + 120 => array( |
|
143 | + 'content_id' => 'td-tkt-max-qty-label', |
|
144 | + 'target' => '.TD_TKT_max_qty_label', |
|
145 | + 'content' => $this->_get_event_ticket_TD_TKT_max_qty_label_info(), |
|
146 | + ), |
|
147 | + 130 => array( |
|
148 | + 'content_id' => 'ticket-lock-icon', |
|
149 | + 'target' => '.ticket-archived .ee-lock-icon', |
|
150 | + 'content' => esc_html__( |
|
151 | + 'This ticket was automatically locked and archived because it has a sold quantity and the price was modified. Existing ticket holders will still be verified using these ticket details. However, Event Espresso has automatically created a new active ticket with the modified price for new registrants. This lock is meant to prevent accidental trashing of this ticket. Certain details of this ticket can still be edited (non disabled inputs).', |
|
152 | + 'event_espresso' |
|
153 | + ), |
|
154 | + ), |
|
155 | + 135 => array( |
|
156 | + 'content_id' => 'ticket-lock-icon-event-editor', |
|
157 | + 'target' => '.ee-lock-icon', |
|
158 | + 'content' => esc_html__( |
|
159 | + 'This datetime can no longer be duplicated or deleted because tickets associated with this datetime have already been sold.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + ), |
|
163 | + ); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - private function _get_event_name_label_info() |
|
170 | - { |
|
171 | - return esc_html__( |
|
172 | - 'This is the name or title for an event datetime.', |
|
173 | - 'event_espresso' |
|
174 | - ); |
|
175 | - } |
|
166 | + /** |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + private function _get_event_name_label_info() |
|
170 | + { |
|
171 | + return esc_html__( |
|
172 | + 'This is the name or title for an event datetime.', |
|
173 | + 'event_espresso' |
|
174 | + ); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - private function _get_event_start_label_info() |
|
181 | - { |
|
182 | - return esc_html__( |
|
183 | - 'This shows when this event datetime starts.', |
|
184 | - 'event_espresso' |
|
185 | - ); |
|
186 | - } |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + private function _get_event_start_label_info() |
|
181 | + { |
|
182 | + return esc_html__( |
|
183 | + 'This shows when this event datetime starts.', |
|
184 | + 'event_espresso' |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - private function _get_event_end_label_info() |
|
192 | - { |
|
193 | - return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
194 | - } |
|
188 | + /** |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + private function _get_event_end_label_info() |
|
192 | + { |
|
193 | + return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
194 | + } |
|
195 | 195 | |
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - private function _get_event_datetime_DTT_reg_limit_label_info() |
|
200 | - { |
|
201 | - return esc_html__( |
|
202 | - 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
203 | - 'event_espresso' |
|
204 | - ); |
|
205 | - } |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + private function _get_event_datetime_DTT_reg_limit_label_info() |
|
200 | + { |
|
201 | + return esc_html__( |
|
202 | + 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
203 | + 'event_espresso' |
|
204 | + ); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - private function _get_event_datetime_DTT_sold_label_info() |
|
211 | - { |
|
212 | - return esc_html__( |
|
213 | - 'This shows the number of tickets that have been sold that have access to this event datetime.', |
|
214 | - 'event_espresso' |
|
215 | - ); |
|
216 | - } |
|
207 | + /** |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + private function _get_event_datetime_DTT_sold_label_info() |
|
211 | + { |
|
212 | + return esc_html__( |
|
213 | + 'This shows the number of tickets that have been sold that have access to this event datetime.', |
|
214 | + 'event_espresso' |
|
215 | + ); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function _get_event_datetime_DTT_reserved_label_info() |
|
222 | - { |
|
223 | - return esc_html__( |
|
224 | - 'This shows the number of reserved tickets that have access to this event datetime.', |
|
225 | - 'event_espresso' |
|
226 | - ); |
|
227 | - } |
|
218 | + /** |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function _get_event_datetime_DTT_reserved_label_info() |
|
222 | + { |
|
223 | + return esc_html__( |
|
224 | + 'This shows the number of reserved tickets that have access to this event datetime.', |
|
225 | + 'event_espresso' |
|
226 | + ); |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - private function _get_event_ticket_TKT_name_label_info() |
|
233 | - { |
|
234 | - return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
235 | - } |
|
229 | + /** |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + private function _get_event_ticket_TKT_name_label_info() |
|
233 | + { |
|
234 | + return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - private function _get_event_ticket_TKT_goes_on_sale_label_info() |
|
241 | - { |
|
242 | - return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
243 | - } |
|
237 | + /** |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + private function _get_event_ticket_TKT_goes_on_sale_label_info() |
|
241 | + { |
|
242 | + return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
243 | + } |
|
244 | 244 | |
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - private function _get_event_ticket_TKT_sell_until_label_info() |
|
249 | - { |
|
250 | - return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
251 | - } |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + private function _get_event_ticket_TKT_sell_until_label_info() |
|
249 | + { |
|
250 | + return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - private function _get_event_ticket_TKT_price_label_info() |
|
257 | - { |
|
258 | - return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
259 | - } |
|
253 | + /** |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + private function _get_event_ticket_TKT_price_label_info() |
|
257 | + { |
|
258 | + return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - private function _get_event_ticket_TKT_qty_label_info() |
|
265 | - { |
|
266 | - return esc_html__( |
|
267 | - 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
268 | - 'event_espresso' |
|
269 | - ); |
|
270 | - } |
|
261 | + /** |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + private function _get_event_ticket_TKT_qty_label_info() |
|
265 | + { |
|
266 | + return esc_html__( |
|
267 | + 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
268 | + 'event_espresso' |
|
269 | + ); |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - private function _get_event_ticket_TKT_sold_label_info() |
|
276 | - { |
|
277 | - return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso'); |
|
278 | - } |
|
272 | + /** |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + private function _get_event_ticket_TKT_sold_label_info() |
|
276 | + { |
|
277 | + return esc_html__('This shows the number of tickets that have been sold for this ticket.', 'event_espresso'); |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function _get_event_ticket_TKT_reserved_label_info() |
|
284 | - { |
|
285 | - return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso'); |
|
286 | - } |
|
280 | + /** |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + private function _get_event_ticket_TKT_reserved_label_info() |
|
284 | + { |
|
285 | + return esc_html__('This shows the number of tickets that are reserved for this ticket.', 'event_espresso'); |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - private function _get_event_ticket_TKT_regs_label_info() |
|
292 | - { |
|
293 | - return esc_html__( |
|
294 | - 'This shows the number of registrations that have occurred from ticket sales.', |
|
295 | - 'event_espresso' |
|
296 | - ); |
|
297 | - } |
|
288 | + /** |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + private function _get_event_ticket_TKT_regs_label_info() |
|
292 | + { |
|
293 | + return esc_html__( |
|
294 | + 'This shows the number of registrations that have occurred from ticket sales.', |
|
295 | + 'event_espresso' |
|
296 | + ); |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - private function _get_event_ticket_ANT_TKT_name_label_info() |
|
303 | - { |
|
304 | - return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
305 | - } |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + private function _get_event_ticket_ANT_TKT_name_label_info() |
|
303 | + { |
|
304 | + return esc_html__('This is the name of this ticket option.', 'event_espresso'); |
|
305 | + } |
|
306 | 306 | |
307 | - /** |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info() |
|
311 | - { |
|
312 | - return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
313 | - } |
|
307 | + /** |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + private function _get_event_ticket_ANT_TKT_goes_on_sale_label_info() |
|
311 | + { |
|
312 | + return esc_html__('This shows when the first ticket is available for sale.', 'event_espresso'); |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * @return string |
|
317 | - */ |
|
318 | - private function _get_event_ticket_ANT_TKT_sell_until_label_info() |
|
319 | - { |
|
320 | - return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
321 | - } |
|
315 | + /** |
|
316 | + * @return string |
|
317 | + */ |
|
318 | + private function _get_event_ticket_ANT_TKT_sell_until_label_info() |
|
319 | + { |
|
320 | + return esc_html__('This shows the date that ticket sales end for this ticket.', 'event_espresso'); |
|
321 | + } |
|
322 | 322 | |
323 | - /** |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - private function _get_event_ticket_ANT_TKT_price_label_info() |
|
327 | - { |
|
328 | - return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
329 | - } |
|
323 | + /** |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + private function _get_event_ticket_ANT_TKT_price_label_info() |
|
327 | + { |
|
328 | + return esc_html__('This is the price for this ticket.', 'event_espresso'); |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - private function _get_event_ticket_ANT_TKT_qty_label_info() |
|
335 | - { |
|
336 | - return esc_html__( |
|
337 | - 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
338 | - 'event_espresso' |
|
339 | - ); |
|
340 | - } |
|
331 | + /** |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + private function _get_event_ticket_ANT_TKT_qty_label_info() |
|
335 | + { |
|
336 | + return esc_html__( |
|
337 | + 'This field shows the quantity of tickets that are available for this type of ticket.', |
|
338 | + 'event_espresso' |
|
339 | + ); |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - private function _get_add_new_event_start_label_info() |
|
346 | - { |
|
347 | - return esc_html__('This shows when this event datetime starts.', 'event_espresso'); |
|
348 | - } |
|
342 | + /** |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + private function _get_add_new_event_start_label_info() |
|
346 | + { |
|
347 | + return esc_html__('This shows when this event datetime starts.', 'event_espresso'); |
|
348 | + } |
|
349 | 349 | |
350 | - /** |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - private function _get_add_new_event_end_label_info() |
|
354 | - { |
|
355 | - return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
356 | - } |
|
350 | + /** |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + private function _get_add_new_event_end_label_info() |
|
354 | + { |
|
355 | + return esc_html__('This shows when this event datetime ends.', 'event_espresso'); |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - private function _get_add_new_event_datetime_DTT_reg_limit_label_info() |
|
362 | - { |
|
363 | - return esc_html__( |
|
364 | - 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
365 | - 'event_espresso' |
|
366 | - ); |
|
367 | - } |
|
358 | + /** |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + private function _get_add_new_event_datetime_DTT_reg_limit_label_info() |
|
362 | + { |
|
363 | + return esc_html__( |
|
364 | + 'This field allows you to set a maximum number of tickets that you want to make available for an event datetime.', |
|
365 | + 'event_espresso' |
|
366 | + ); |
|
367 | + } |
|
368 | 368 | |
369 | - /** |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - private function _get_event_ticket_TD_TKT_number_datetimes_label_info() |
|
373 | - { |
|
374 | - return esc_html__( |
|
375 | - 'This field allows you to set the number of datetimes that a ticket should have access to.', |
|
376 | - 'event_espresso' |
|
377 | - ); |
|
378 | - } |
|
369 | + /** |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + private function _get_event_ticket_TD_TKT_number_datetimes_label_info() |
|
373 | + { |
|
374 | + return esc_html__( |
|
375 | + 'This field allows you to set the number of datetimes that a ticket should have access to.', |
|
376 | + 'event_espresso' |
|
377 | + ); |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - private function _get_event_ticket_TD_TKT_min_qty_label_info() |
|
384 | - { |
|
385 | - return esc_html__( |
|
386 | - 'This shows the minimum quantity that can be purchased for this ticket.', |
|
387 | - 'event_espresso' |
|
388 | - ); |
|
389 | - } |
|
380 | + /** |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + private function _get_event_ticket_TD_TKT_min_qty_label_info() |
|
384 | + { |
|
385 | + return esc_html__( |
|
386 | + 'This shows the minimum quantity that can be purchased for this ticket.', |
|
387 | + 'event_espresso' |
|
388 | + ); |
|
389 | + } |
|
390 | 390 | |
391 | - /** |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - private function _get_event_ticket_TD_TKT_max_qty_label_info() |
|
395 | - { |
|
396 | - return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso'); |
|
397 | - } |
|
391 | + /** |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + private function _get_event_ticket_TD_TKT_max_qty_label_info() |
|
395 | + { |
|
396 | + return esc_html__('This shows the maximum quantity that can be purchased for this ticket.', 'event_espresso'); |
|
397 | + } |
|
398 | 398 | } |
399 | 399 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -17,2634 +17,2634 @@ discard block |
||
17 | 17 | class Events_Admin_Page extends EE_Admin_Page_CPT |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * This will hold the event object for event_details screen. |
|
22 | - * |
|
23 | - * @access protected |
|
24 | - * @var EE_Event $_event |
|
25 | - */ |
|
26 | - protected $_event; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * This will hold the category object for category_details screen. |
|
31 | - * |
|
32 | - * @var stdClass $_category |
|
33 | - */ |
|
34 | - protected $_category; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * This will hold the event model instance |
|
39 | - * |
|
40 | - * @var EEM_Event $_event_model |
|
41 | - */ |
|
42 | - protected $_event_model; |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EE_Event |
|
48 | - */ |
|
49 | - protected $_cpt_model_obj = false; |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - protected function _init_page_props() |
|
54 | - { |
|
55 | - $this->page_slug = EVENTS_PG_SLUG; |
|
56 | - $this->page_label = EVENTS_LABEL; |
|
57 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
58 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
59 | - $this->_cpt_model_names = array( |
|
60 | - 'create_new' => 'EEM_Event', |
|
61 | - 'edit' => 'EEM_Event', |
|
62 | - ); |
|
63 | - $this->_cpt_edit_routes = array( |
|
64 | - 'espresso_events' => 'edit', |
|
65 | - ); |
|
66 | - add_action( |
|
67 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
68 | - array($this, 'verify_event_edit') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - protected function _ajax_hooks() |
|
75 | - { |
|
76 | - //todo: all hooks for events ajax goes in here. |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - protected function _define_page_props() |
|
82 | - { |
|
83 | - $this->_admin_page_title = EVENTS_LABEL; |
|
84 | - $this->_labels = array( |
|
85 | - 'buttons' => array( |
|
86 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
87 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
88 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
89 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
90 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
91 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
92 | - ), |
|
93 | - 'editor_title' => array( |
|
94 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
95 | - ), |
|
96 | - 'publishbox' => array( |
|
97 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
98 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
99 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
100 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
101 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
102 | - ), |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - protected function _set_page_routes() |
|
109 | - { |
|
110 | - //load formatter helper |
|
111 | - //load field generator helper |
|
112 | - //is there a evt_id in the request? |
|
113 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
114 | - ? $this->_req_data['EVT_ID'] : 0; |
|
115 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
116 | - $this->_page_routes = array( |
|
117 | - 'default' => array( |
|
118 | - 'func' => '_events_overview_list_table', |
|
119 | - 'capability' => 'ee_read_events', |
|
120 | - ), |
|
121 | - 'create_new' => array( |
|
122 | - 'func' => '_create_new_cpt_item', |
|
123 | - 'capability' => 'ee_edit_events', |
|
124 | - ), |
|
125 | - 'edit' => array( |
|
126 | - 'func' => '_edit_cpt_item', |
|
127 | - 'capability' => 'ee_edit_event', |
|
128 | - 'obj_id' => $evt_id, |
|
129 | - ), |
|
130 | - 'copy_event' => array( |
|
131 | - 'func' => '_copy_events', |
|
132 | - 'capability' => 'ee_edit_event', |
|
133 | - 'obj_id' => $evt_id, |
|
134 | - 'noheader' => true, |
|
135 | - ), |
|
136 | - 'trash_event' => array( |
|
137 | - 'func' => '_trash_or_restore_event', |
|
138 | - 'args' => array('event_status' => 'trash'), |
|
139 | - 'capability' => 'ee_delete_event', |
|
140 | - 'obj_id' => $evt_id, |
|
141 | - 'noheader' => true, |
|
142 | - ), |
|
143 | - 'trash_events' => array( |
|
144 | - 'func' => '_trash_or_restore_events', |
|
145 | - 'args' => array('event_status' => 'trash'), |
|
146 | - 'capability' => 'ee_delete_events', |
|
147 | - 'noheader' => true, |
|
148 | - ), |
|
149 | - 'restore_event' => array( |
|
150 | - 'func' => '_trash_or_restore_event', |
|
151 | - 'args' => array('event_status' => 'draft'), |
|
152 | - 'capability' => 'ee_delete_event', |
|
153 | - 'obj_id' => $evt_id, |
|
154 | - 'noheader' => true, |
|
155 | - ), |
|
156 | - 'restore_events' => array( |
|
157 | - 'func' => '_trash_or_restore_events', |
|
158 | - 'args' => array('event_status' => 'draft'), |
|
159 | - 'capability' => 'ee_delete_events', |
|
160 | - 'noheader' => true, |
|
161 | - ), |
|
162 | - 'delete_event' => array( |
|
163 | - 'func' => '_delete_event', |
|
164 | - 'capability' => 'ee_delete_event', |
|
165 | - 'obj_id' => $evt_id, |
|
166 | - 'noheader' => true, |
|
167 | - ), |
|
168 | - 'delete_events' => array( |
|
169 | - 'func' => '_delete_events', |
|
170 | - 'capability' => 'ee_delete_events', |
|
171 | - 'noheader' => true, |
|
172 | - ), |
|
173 | - 'view_report' => array( |
|
174 | - 'func' => '_view_report', |
|
175 | - 'capablity' => 'ee_edit_events', |
|
176 | - ), |
|
177 | - 'default_event_settings' => array( |
|
178 | - 'func' => '_default_event_settings', |
|
179 | - 'capability' => 'manage_options', |
|
180 | - ), |
|
181 | - 'update_default_event_settings' => array( |
|
182 | - 'func' => '_update_default_event_settings', |
|
183 | - 'capability' => 'manage_options', |
|
184 | - 'noheader' => true, |
|
185 | - ), |
|
186 | - 'template_settings' => array( |
|
187 | - 'func' => '_template_settings', |
|
188 | - 'capability' => 'manage_options', |
|
189 | - ), |
|
190 | - //event category tab related |
|
191 | - 'add_category' => array( |
|
192 | - 'func' => '_category_details', |
|
193 | - 'capability' => 'ee_edit_event_category', |
|
194 | - 'args' => array('add'), |
|
195 | - ), |
|
196 | - 'edit_category' => array( |
|
197 | - 'func' => '_category_details', |
|
198 | - 'capability' => 'ee_edit_event_category', |
|
199 | - 'args' => array('edit'), |
|
200 | - ), |
|
201 | - 'delete_categories' => array( |
|
202 | - 'func' => '_delete_categories', |
|
203 | - 'capability' => 'ee_delete_event_category', |
|
204 | - 'noheader' => true, |
|
205 | - ), |
|
206 | - 'delete_category' => array( |
|
207 | - 'func' => '_delete_categories', |
|
208 | - 'capability' => 'ee_delete_event_category', |
|
209 | - 'noheader' => true, |
|
210 | - ), |
|
211 | - 'insert_category' => array( |
|
212 | - 'func' => '_insert_or_update_category', |
|
213 | - 'args' => array('new_category' => true), |
|
214 | - 'capability' => 'ee_edit_event_category', |
|
215 | - 'noheader' => true, |
|
216 | - ), |
|
217 | - 'update_category' => array( |
|
218 | - 'func' => '_insert_or_update_category', |
|
219 | - 'args' => array('new_category' => false), |
|
220 | - 'capability' => 'ee_edit_event_category', |
|
221 | - 'noheader' => true, |
|
222 | - ), |
|
223 | - 'category_list' => array( |
|
224 | - 'func' => '_category_list_table', |
|
225 | - 'capability' => 'ee_manage_event_categories', |
|
226 | - ), |
|
227 | - ); |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - |
|
232 | - protected function _set_page_config() |
|
233 | - { |
|
234 | - $this->_page_config = array( |
|
235 | - 'default' => array( |
|
236 | - 'nav' => array( |
|
237 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
238 | - 'order' => 10, |
|
239 | - ), |
|
240 | - 'list_table' => 'Events_Admin_List_Table', |
|
241 | - 'help_tabs' => array( |
|
242 | - 'events_overview_help_tab' => array( |
|
243 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
244 | - 'filename' => 'events_overview', |
|
245 | - ), |
|
246 | - 'events_overview_table_column_headings_help_tab' => array( |
|
247 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
248 | - 'filename' => 'events_overview_table_column_headings', |
|
249 | - ), |
|
250 | - 'events_overview_filters_help_tab' => array( |
|
251 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
252 | - 'filename' => 'events_overview_filters', |
|
253 | - ), |
|
254 | - 'events_overview_view_help_tab' => array( |
|
255 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
256 | - 'filename' => 'events_overview_views', |
|
257 | - ), |
|
258 | - 'events_overview_other_help_tab' => array( |
|
259 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
260 | - 'filename' => 'events_overview_other', |
|
261 | - ), |
|
262 | - ), |
|
263 | - 'help_tour' => array( |
|
264 | - 'Event_Overview_Help_Tour', |
|
265 | - //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
266 | - ), |
|
267 | - 'qtips' => array( |
|
268 | - 'EE_Event_List_Table_Tips', |
|
269 | - ), |
|
270 | - 'require_nonce' => false, |
|
271 | - ), |
|
272 | - 'create_new' => array( |
|
273 | - 'nav' => array( |
|
274 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
275 | - 'order' => 5, |
|
276 | - 'persistent' => false, |
|
277 | - ), |
|
278 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
279 | - 'help_tabs' => array( |
|
280 | - 'event_editor_help_tab' => array( |
|
281 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
282 | - 'filename' => 'event_editor', |
|
283 | - ), |
|
284 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
285 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
286 | - 'filename' => 'event_editor_title_richtexteditor', |
|
287 | - ), |
|
288 | - 'event_editor_venue_details_help_tab' => array( |
|
289 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
290 | - 'filename' => 'event_editor_venue_details', |
|
291 | - ), |
|
292 | - 'event_editor_event_datetimes_help_tab' => array( |
|
293 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
294 | - 'filename' => 'event_editor_event_datetimes', |
|
295 | - ), |
|
296 | - 'event_editor_event_tickets_help_tab' => array( |
|
297 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
298 | - 'filename' => 'event_editor_event_tickets', |
|
299 | - ), |
|
300 | - 'event_editor_event_registration_options_help_tab' => array( |
|
301 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
302 | - 'filename' => 'event_editor_event_registration_options', |
|
303 | - ), |
|
304 | - 'event_editor_tags_categories_help_tab' => array( |
|
305 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
306 | - 'filename' => 'event_editor_tags_categories', |
|
307 | - ), |
|
308 | - 'event_editor_questions_registrants_help_tab' => array( |
|
309 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
310 | - 'filename' => 'event_editor_questions_registrants', |
|
311 | - ), |
|
312 | - 'event_editor_save_new_event_help_tab' => array( |
|
313 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
314 | - 'filename' => 'event_editor_save_new_event', |
|
315 | - ), |
|
316 | - 'event_editor_other_help_tab' => array( |
|
317 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
318 | - 'filename' => 'event_editor_other', |
|
319 | - ), |
|
320 | - ), |
|
321 | - 'help_tour' => array( |
|
322 | - 'Event_Editor_Help_Tour', |
|
323 | - ), |
|
324 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
325 | - 'require_nonce' => false, |
|
326 | - ), |
|
327 | - 'edit' => array( |
|
328 | - 'nav' => array( |
|
329 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
330 | - 'order' => 5, |
|
331 | - 'persistent' => false, |
|
332 | - 'url' => isset($this->_req_data['post']) |
|
333 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
334 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
335 | - $this->_current_page_view_url |
|
336 | - ) |
|
337 | - : $this->_admin_base_url, |
|
338 | - ), |
|
339 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
340 | - 'help_tabs' => array( |
|
341 | - 'event_editor_help_tab' => array( |
|
342 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
343 | - 'filename' => 'event_editor', |
|
344 | - ), |
|
345 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
346 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
347 | - 'filename' => 'event_editor_title_richtexteditor', |
|
348 | - ), |
|
349 | - 'event_editor_venue_details_help_tab' => array( |
|
350 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
351 | - 'filename' => 'event_editor_venue_details', |
|
352 | - ), |
|
353 | - 'event_editor_event_datetimes_help_tab' => array( |
|
354 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
355 | - 'filename' => 'event_editor_event_datetimes', |
|
356 | - ), |
|
357 | - 'event_editor_event_tickets_help_tab' => array( |
|
358 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
359 | - 'filename' => 'event_editor_event_tickets', |
|
360 | - ), |
|
361 | - 'event_editor_event_registration_options_help_tab' => array( |
|
362 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
363 | - 'filename' => 'event_editor_event_registration_options', |
|
364 | - ), |
|
365 | - 'event_editor_tags_categories_help_tab' => array( |
|
366 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
367 | - 'filename' => 'event_editor_tags_categories', |
|
368 | - ), |
|
369 | - 'event_editor_questions_registrants_help_tab' => array( |
|
370 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
371 | - 'filename' => 'event_editor_questions_registrants', |
|
372 | - ), |
|
373 | - 'event_editor_save_new_event_help_tab' => array( |
|
374 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
375 | - 'filename' => 'event_editor_save_new_event', |
|
376 | - ), |
|
377 | - 'event_editor_other_help_tab' => array( |
|
378 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
379 | - 'filename' => 'event_editor_other', |
|
380 | - ), |
|
381 | - ), |
|
382 | - /*'help_tour' => array( |
|
20 | + /** |
|
21 | + * This will hold the event object for event_details screen. |
|
22 | + * |
|
23 | + * @access protected |
|
24 | + * @var EE_Event $_event |
|
25 | + */ |
|
26 | + protected $_event; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * This will hold the category object for category_details screen. |
|
31 | + * |
|
32 | + * @var stdClass $_category |
|
33 | + */ |
|
34 | + protected $_category; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * This will hold the event model instance |
|
39 | + * |
|
40 | + * @var EEM_Event $_event_model |
|
41 | + */ |
|
42 | + protected $_event_model; |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EE_Event |
|
48 | + */ |
|
49 | + protected $_cpt_model_obj = false; |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + protected function _init_page_props() |
|
54 | + { |
|
55 | + $this->page_slug = EVENTS_PG_SLUG; |
|
56 | + $this->page_label = EVENTS_LABEL; |
|
57 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
58 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
59 | + $this->_cpt_model_names = array( |
|
60 | + 'create_new' => 'EEM_Event', |
|
61 | + 'edit' => 'EEM_Event', |
|
62 | + ); |
|
63 | + $this->_cpt_edit_routes = array( |
|
64 | + 'espresso_events' => 'edit', |
|
65 | + ); |
|
66 | + add_action( |
|
67 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
68 | + array($this, 'verify_event_edit') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + protected function _ajax_hooks() |
|
75 | + { |
|
76 | + //todo: all hooks for events ajax goes in here. |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + protected function _define_page_props() |
|
82 | + { |
|
83 | + $this->_admin_page_title = EVENTS_LABEL; |
|
84 | + $this->_labels = array( |
|
85 | + 'buttons' => array( |
|
86 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
87 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
88 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
89 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
90 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
91 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
92 | + ), |
|
93 | + 'editor_title' => array( |
|
94 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
95 | + ), |
|
96 | + 'publishbox' => array( |
|
97 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
98 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
99 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
100 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
101 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
102 | + ), |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + protected function _set_page_routes() |
|
109 | + { |
|
110 | + //load formatter helper |
|
111 | + //load field generator helper |
|
112 | + //is there a evt_id in the request? |
|
113 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
114 | + ? $this->_req_data['EVT_ID'] : 0; |
|
115 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
116 | + $this->_page_routes = array( |
|
117 | + 'default' => array( |
|
118 | + 'func' => '_events_overview_list_table', |
|
119 | + 'capability' => 'ee_read_events', |
|
120 | + ), |
|
121 | + 'create_new' => array( |
|
122 | + 'func' => '_create_new_cpt_item', |
|
123 | + 'capability' => 'ee_edit_events', |
|
124 | + ), |
|
125 | + 'edit' => array( |
|
126 | + 'func' => '_edit_cpt_item', |
|
127 | + 'capability' => 'ee_edit_event', |
|
128 | + 'obj_id' => $evt_id, |
|
129 | + ), |
|
130 | + 'copy_event' => array( |
|
131 | + 'func' => '_copy_events', |
|
132 | + 'capability' => 'ee_edit_event', |
|
133 | + 'obj_id' => $evt_id, |
|
134 | + 'noheader' => true, |
|
135 | + ), |
|
136 | + 'trash_event' => array( |
|
137 | + 'func' => '_trash_or_restore_event', |
|
138 | + 'args' => array('event_status' => 'trash'), |
|
139 | + 'capability' => 'ee_delete_event', |
|
140 | + 'obj_id' => $evt_id, |
|
141 | + 'noheader' => true, |
|
142 | + ), |
|
143 | + 'trash_events' => array( |
|
144 | + 'func' => '_trash_or_restore_events', |
|
145 | + 'args' => array('event_status' => 'trash'), |
|
146 | + 'capability' => 'ee_delete_events', |
|
147 | + 'noheader' => true, |
|
148 | + ), |
|
149 | + 'restore_event' => array( |
|
150 | + 'func' => '_trash_or_restore_event', |
|
151 | + 'args' => array('event_status' => 'draft'), |
|
152 | + 'capability' => 'ee_delete_event', |
|
153 | + 'obj_id' => $evt_id, |
|
154 | + 'noheader' => true, |
|
155 | + ), |
|
156 | + 'restore_events' => array( |
|
157 | + 'func' => '_trash_or_restore_events', |
|
158 | + 'args' => array('event_status' => 'draft'), |
|
159 | + 'capability' => 'ee_delete_events', |
|
160 | + 'noheader' => true, |
|
161 | + ), |
|
162 | + 'delete_event' => array( |
|
163 | + 'func' => '_delete_event', |
|
164 | + 'capability' => 'ee_delete_event', |
|
165 | + 'obj_id' => $evt_id, |
|
166 | + 'noheader' => true, |
|
167 | + ), |
|
168 | + 'delete_events' => array( |
|
169 | + 'func' => '_delete_events', |
|
170 | + 'capability' => 'ee_delete_events', |
|
171 | + 'noheader' => true, |
|
172 | + ), |
|
173 | + 'view_report' => array( |
|
174 | + 'func' => '_view_report', |
|
175 | + 'capablity' => 'ee_edit_events', |
|
176 | + ), |
|
177 | + 'default_event_settings' => array( |
|
178 | + 'func' => '_default_event_settings', |
|
179 | + 'capability' => 'manage_options', |
|
180 | + ), |
|
181 | + 'update_default_event_settings' => array( |
|
182 | + 'func' => '_update_default_event_settings', |
|
183 | + 'capability' => 'manage_options', |
|
184 | + 'noheader' => true, |
|
185 | + ), |
|
186 | + 'template_settings' => array( |
|
187 | + 'func' => '_template_settings', |
|
188 | + 'capability' => 'manage_options', |
|
189 | + ), |
|
190 | + //event category tab related |
|
191 | + 'add_category' => array( |
|
192 | + 'func' => '_category_details', |
|
193 | + 'capability' => 'ee_edit_event_category', |
|
194 | + 'args' => array('add'), |
|
195 | + ), |
|
196 | + 'edit_category' => array( |
|
197 | + 'func' => '_category_details', |
|
198 | + 'capability' => 'ee_edit_event_category', |
|
199 | + 'args' => array('edit'), |
|
200 | + ), |
|
201 | + 'delete_categories' => array( |
|
202 | + 'func' => '_delete_categories', |
|
203 | + 'capability' => 'ee_delete_event_category', |
|
204 | + 'noheader' => true, |
|
205 | + ), |
|
206 | + 'delete_category' => array( |
|
207 | + 'func' => '_delete_categories', |
|
208 | + 'capability' => 'ee_delete_event_category', |
|
209 | + 'noheader' => true, |
|
210 | + ), |
|
211 | + 'insert_category' => array( |
|
212 | + 'func' => '_insert_or_update_category', |
|
213 | + 'args' => array('new_category' => true), |
|
214 | + 'capability' => 'ee_edit_event_category', |
|
215 | + 'noheader' => true, |
|
216 | + ), |
|
217 | + 'update_category' => array( |
|
218 | + 'func' => '_insert_or_update_category', |
|
219 | + 'args' => array('new_category' => false), |
|
220 | + 'capability' => 'ee_edit_event_category', |
|
221 | + 'noheader' => true, |
|
222 | + ), |
|
223 | + 'category_list' => array( |
|
224 | + 'func' => '_category_list_table', |
|
225 | + 'capability' => 'ee_manage_event_categories', |
|
226 | + ), |
|
227 | + ); |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + |
|
232 | + protected function _set_page_config() |
|
233 | + { |
|
234 | + $this->_page_config = array( |
|
235 | + 'default' => array( |
|
236 | + 'nav' => array( |
|
237 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
238 | + 'order' => 10, |
|
239 | + ), |
|
240 | + 'list_table' => 'Events_Admin_List_Table', |
|
241 | + 'help_tabs' => array( |
|
242 | + 'events_overview_help_tab' => array( |
|
243 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
244 | + 'filename' => 'events_overview', |
|
245 | + ), |
|
246 | + 'events_overview_table_column_headings_help_tab' => array( |
|
247 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
248 | + 'filename' => 'events_overview_table_column_headings', |
|
249 | + ), |
|
250 | + 'events_overview_filters_help_tab' => array( |
|
251 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
252 | + 'filename' => 'events_overview_filters', |
|
253 | + ), |
|
254 | + 'events_overview_view_help_tab' => array( |
|
255 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
256 | + 'filename' => 'events_overview_views', |
|
257 | + ), |
|
258 | + 'events_overview_other_help_tab' => array( |
|
259 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
260 | + 'filename' => 'events_overview_other', |
|
261 | + ), |
|
262 | + ), |
|
263 | + 'help_tour' => array( |
|
264 | + 'Event_Overview_Help_Tour', |
|
265 | + //'New_Features_Test_Help_Tour' for testing multiple help tour |
|
266 | + ), |
|
267 | + 'qtips' => array( |
|
268 | + 'EE_Event_List_Table_Tips', |
|
269 | + ), |
|
270 | + 'require_nonce' => false, |
|
271 | + ), |
|
272 | + 'create_new' => array( |
|
273 | + 'nav' => array( |
|
274 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
275 | + 'order' => 5, |
|
276 | + 'persistent' => false, |
|
277 | + ), |
|
278 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
279 | + 'help_tabs' => array( |
|
280 | + 'event_editor_help_tab' => array( |
|
281 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
282 | + 'filename' => 'event_editor', |
|
283 | + ), |
|
284 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
285 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
286 | + 'filename' => 'event_editor_title_richtexteditor', |
|
287 | + ), |
|
288 | + 'event_editor_venue_details_help_tab' => array( |
|
289 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
290 | + 'filename' => 'event_editor_venue_details', |
|
291 | + ), |
|
292 | + 'event_editor_event_datetimes_help_tab' => array( |
|
293 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
294 | + 'filename' => 'event_editor_event_datetimes', |
|
295 | + ), |
|
296 | + 'event_editor_event_tickets_help_tab' => array( |
|
297 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
298 | + 'filename' => 'event_editor_event_tickets', |
|
299 | + ), |
|
300 | + 'event_editor_event_registration_options_help_tab' => array( |
|
301 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
302 | + 'filename' => 'event_editor_event_registration_options', |
|
303 | + ), |
|
304 | + 'event_editor_tags_categories_help_tab' => array( |
|
305 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
306 | + 'filename' => 'event_editor_tags_categories', |
|
307 | + ), |
|
308 | + 'event_editor_questions_registrants_help_tab' => array( |
|
309 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
310 | + 'filename' => 'event_editor_questions_registrants', |
|
311 | + ), |
|
312 | + 'event_editor_save_new_event_help_tab' => array( |
|
313 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
314 | + 'filename' => 'event_editor_save_new_event', |
|
315 | + ), |
|
316 | + 'event_editor_other_help_tab' => array( |
|
317 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
318 | + 'filename' => 'event_editor_other', |
|
319 | + ), |
|
320 | + ), |
|
321 | + 'help_tour' => array( |
|
322 | + 'Event_Editor_Help_Tour', |
|
323 | + ), |
|
324 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
325 | + 'require_nonce' => false, |
|
326 | + ), |
|
327 | + 'edit' => array( |
|
328 | + 'nav' => array( |
|
329 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
330 | + 'order' => 5, |
|
331 | + 'persistent' => false, |
|
332 | + 'url' => isset($this->_req_data['post']) |
|
333 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
334 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
335 | + $this->_current_page_view_url |
|
336 | + ) |
|
337 | + : $this->_admin_base_url, |
|
338 | + ), |
|
339 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
340 | + 'help_tabs' => array( |
|
341 | + 'event_editor_help_tab' => array( |
|
342 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
343 | + 'filename' => 'event_editor', |
|
344 | + ), |
|
345 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
346 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
347 | + 'filename' => 'event_editor_title_richtexteditor', |
|
348 | + ), |
|
349 | + 'event_editor_venue_details_help_tab' => array( |
|
350 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
351 | + 'filename' => 'event_editor_venue_details', |
|
352 | + ), |
|
353 | + 'event_editor_event_datetimes_help_tab' => array( |
|
354 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
355 | + 'filename' => 'event_editor_event_datetimes', |
|
356 | + ), |
|
357 | + 'event_editor_event_tickets_help_tab' => array( |
|
358 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
359 | + 'filename' => 'event_editor_event_tickets', |
|
360 | + ), |
|
361 | + 'event_editor_event_registration_options_help_tab' => array( |
|
362 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
363 | + 'filename' => 'event_editor_event_registration_options', |
|
364 | + ), |
|
365 | + 'event_editor_tags_categories_help_tab' => array( |
|
366 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
367 | + 'filename' => 'event_editor_tags_categories', |
|
368 | + ), |
|
369 | + 'event_editor_questions_registrants_help_tab' => array( |
|
370 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
371 | + 'filename' => 'event_editor_questions_registrants', |
|
372 | + ), |
|
373 | + 'event_editor_save_new_event_help_tab' => array( |
|
374 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
375 | + 'filename' => 'event_editor_save_new_event', |
|
376 | + ), |
|
377 | + 'event_editor_other_help_tab' => array( |
|
378 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
379 | + 'filename' => 'event_editor_other', |
|
380 | + ), |
|
381 | + ), |
|
382 | + /*'help_tour' => array( |
|
383 | 383 | 'Event_Edit_Help_Tour' |
384 | 384 | ),*/ |
385 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
386 | - 'require_nonce' => false, |
|
387 | - ), |
|
388 | - 'default_event_settings' => array( |
|
389 | - 'nav' => array( |
|
390 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
391 | - 'order' => 40, |
|
392 | - ), |
|
393 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
394 | - 'labels' => array( |
|
395 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
396 | - ), |
|
397 | - 'help_tabs' => array( |
|
398 | - 'default_settings_help_tab' => array( |
|
399 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
400 | - 'filename' => 'events_default_settings', |
|
401 | - ), |
|
402 | - 'default_settings_status_help_tab' => array( |
|
403 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
404 | - 'filename' => 'events_default_settings_status', |
|
405 | - ), |
|
406 | - 'default_maximum_tickets_help_tab' => array( |
|
407 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
408 | - 'filename' => 'events_default_settings_max_tickets', |
|
409 | - ) |
|
410 | - ), |
|
411 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
412 | - 'require_nonce' => false, |
|
413 | - ), |
|
414 | - //template settings |
|
415 | - 'template_settings' => array( |
|
416 | - 'nav' => array( |
|
417 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
418 | - 'order' => 30, |
|
419 | - ), |
|
420 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
421 | - 'help_tabs' => array( |
|
422 | - 'general_settings_templates_help_tab' => array( |
|
423 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
424 | - 'filename' => 'general_settings_templates', |
|
425 | - ), |
|
426 | - ), |
|
427 | - 'help_tour' => array('Templates_Help_Tour'), |
|
428 | - 'require_nonce' => false, |
|
429 | - ), |
|
430 | - //event category stuff |
|
431 | - 'add_category' => array( |
|
432 | - 'nav' => array( |
|
433 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
434 | - 'order' => 15, |
|
435 | - 'persistent' => false, |
|
436 | - ), |
|
437 | - 'help_tabs' => array( |
|
438 | - 'add_category_help_tab' => array( |
|
439 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
440 | - 'filename' => 'events_add_category', |
|
441 | - ), |
|
442 | - ), |
|
443 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
444 | - 'metaboxes' => array('_publish_post_box'), |
|
445 | - 'require_nonce' => false, |
|
446 | - ), |
|
447 | - 'edit_category' => array( |
|
448 | - 'nav' => array( |
|
449 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
450 | - 'order' => 15, |
|
451 | - 'persistent' => false, |
|
452 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
453 | - ? add_query_arg( |
|
454 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
455 | - $this->_current_page_view_url |
|
456 | - ) |
|
457 | - : $this->_admin_base_url, |
|
458 | - ), |
|
459 | - 'help_tabs' => array( |
|
460 | - 'edit_category_help_tab' => array( |
|
461 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
462 | - 'filename' => 'events_edit_category', |
|
463 | - ), |
|
464 | - ), |
|
465 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
466 | - 'metaboxes' => array('_publish_post_box'), |
|
467 | - 'require_nonce' => false, |
|
468 | - ), |
|
469 | - 'category_list' => array( |
|
470 | - 'nav' => array( |
|
471 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
472 | - 'order' => 20, |
|
473 | - ), |
|
474 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
475 | - 'help_tabs' => array( |
|
476 | - 'events_categories_help_tab' => array( |
|
477 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
478 | - 'filename' => 'events_categories', |
|
479 | - ), |
|
480 | - 'events_categories_table_column_headings_help_tab' => array( |
|
481 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
482 | - 'filename' => 'events_categories_table_column_headings', |
|
483 | - ), |
|
484 | - 'events_categories_view_help_tab' => array( |
|
485 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
486 | - 'filename' => 'events_categories_views', |
|
487 | - ), |
|
488 | - 'events_categories_other_help_tab' => array( |
|
489 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
490 | - 'filename' => 'events_categories_other', |
|
491 | - ), |
|
492 | - ), |
|
493 | - 'help_tour' => array( |
|
494 | - 'Event_Categories_Help_Tour', |
|
495 | - ), |
|
496 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
497 | - 'require_nonce' => false, |
|
498 | - ), |
|
499 | - ); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - protected function _add_screen_options() |
|
505 | - { |
|
506 | - //todo |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - protected function _add_screen_options_default() |
|
512 | - { |
|
513 | - $this->_per_page_screen_option(); |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - |
|
518 | - protected function _add_screen_options_category_list() |
|
519 | - { |
|
520 | - $page_title = $this->_admin_page_title; |
|
521 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
522 | - $this->_per_page_screen_option(); |
|
523 | - $this->_admin_page_title = $page_title; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - protected function _add_feature_pointers() |
|
529 | - { |
|
530 | - //todo |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - |
|
535 | - public function load_scripts_styles() |
|
536 | - { |
|
537 | - wp_register_style( |
|
538 | - 'events-admin-css', |
|
539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
540 | - array(), |
|
541 | - EVENT_ESPRESSO_VERSION |
|
542 | - ); |
|
543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
544 | - wp_enqueue_style('events-admin-css'); |
|
545 | - wp_enqueue_style('ee-cat-admin'); |
|
546 | - //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
547 | - //registers for all views |
|
548 | - //scripts |
|
549 | - wp_register_script( |
|
550 | - 'event_editor_js', |
|
551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
552 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
553 | - EVENT_ESPRESSO_VERSION, |
|
554 | - true |
|
555 | - ); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * enqueuing scripts and styles specific to this view |
|
562 | - * |
|
563 | - * @return void |
|
564 | - */ |
|
565 | - public function load_scripts_styles_create_new() |
|
566 | - { |
|
567 | - $this->load_scripts_styles_edit(); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * enqueuing scripts and styles specific to this view |
|
574 | - * |
|
575 | - * @return void |
|
576 | - */ |
|
577 | - public function load_scripts_styles_edit() |
|
578 | - { |
|
579 | - //styles |
|
580 | - wp_enqueue_style('espresso-ui-theme'); |
|
581 | - wp_register_style( |
|
582 | - 'event-editor-css', |
|
583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
584 | - array('ee-admin-css'), |
|
585 | - EVENT_ESPRESSO_VERSION |
|
586 | - ); |
|
587 | - wp_enqueue_style('event-editor-css'); |
|
588 | - //scripts |
|
589 | - wp_register_script( |
|
590 | - 'event-datetime-metabox', |
|
591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
592 | - array('event_editor_js', 'ee-datepicker'), |
|
593 | - EVENT_ESPRESSO_VERSION |
|
594 | - ); |
|
595 | - wp_enqueue_script('event-datetime-metabox'); |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - |
|
600 | - public function load_scripts_styles_add_category() |
|
601 | - { |
|
602 | - $this->load_scripts_styles_edit_category(); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - public function load_scripts_styles_edit_category() |
|
608 | - { |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - protected function _set_list_table_views_category_list() |
|
614 | - { |
|
615 | - $this->_views = array( |
|
616 | - 'all' => array( |
|
617 | - 'slug' => 'all', |
|
618 | - 'label' => esc_html__('All', 'event_espresso'), |
|
619 | - 'count' => 0, |
|
620 | - 'bulk_action' => array( |
|
621 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
622 | - ), |
|
623 | - ), |
|
624 | - ); |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - public function admin_init() |
|
630 | - { |
|
631 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
632 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
633 | - 'event_espresso' |
|
634 | - ); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - //nothing needed for events with these methods. |
|
640 | - public function admin_notices() |
|
641 | - { |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - |
|
646 | - public function admin_footer_scripts() |
|
647 | - { |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
654 | - * warning (via EE_Error::add_error()); |
|
655 | - * |
|
656 | - * @param EE_Event $event Event object |
|
657 | - * @access public |
|
658 | - * @return void |
|
659 | - */ |
|
660 | - public function verify_event_edit($event = null) |
|
661 | - { |
|
662 | - // no event? |
|
663 | - if (empty($event)) { |
|
664 | - // set event |
|
665 | - $event = $this->_cpt_model_obj; |
|
666 | - } |
|
667 | - // STILL no event? |
|
668 | - if (empty ($event)) { |
|
669 | - return; |
|
670 | - } |
|
671 | - $orig_status = $event->status(); |
|
672 | - // first check if event is active. |
|
673 | - if ( |
|
674 | - $orig_status === EEM_Event::cancelled |
|
675 | - || $orig_status === EEM_Event::postponed |
|
676 | - || $event->is_expired() |
|
677 | - || $event->is_inactive() |
|
678 | - ) { |
|
679 | - return; |
|
680 | - } |
|
681 | - //made it here so it IS active... next check that any of the tickets are sold. |
|
682 | - if ($event->is_sold_out(true)) { |
|
683 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
684 | - EE_Error::add_attention( |
|
685 | - sprintf( |
|
686 | - esc_html__( |
|
687 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
688 | - 'event_espresso' |
|
689 | - ), |
|
690 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
691 | - ) |
|
692 | - ); |
|
693 | - } |
|
694 | - return; |
|
695 | - } else if ($orig_status === EEM_Event::sold_out) { |
|
696 | - EE_Error::add_attention( |
|
697 | - sprintf( |
|
698 | - esc_html__( |
|
699 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
700 | - 'event_espresso' |
|
701 | - ), |
|
702 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
703 | - ) |
|
704 | - ); |
|
705 | - } |
|
706 | - //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
707 | - if ( ! $event->tickets_on_sale()) { |
|
708 | - return; |
|
709 | - } |
|
710 | - //made it here so show warning |
|
711 | - $this->_edit_event_warning(); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
718 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
719 | - * |
|
720 | - * @access protected |
|
721 | - * @return void |
|
722 | - */ |
|
723 | - protected function _edit_event_warning() |
|
724 | - { |
|
725 | - // we don't want to add warnings during these requests |
|
726 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
727 | - return; |
|
728 | - } |
|
729 | - EE_Error::add_attention( |
|
730 | - esc_html__( |
|
731 | - 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
732 | - 'event_espresso' |
|
733 | - ) |
|
734 | - ); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
741 | - * Otherwise, do the normal logic |
|
742 | - * |
|
743 | - * @return string |
|
744 | - * @throws \EE_Error |
|
745 | - */ |
|
746 | - protected function _create_new_cpt_item() |
|
747 | - { |
|
748 | - $gmt_offset = get_option('gmt_offset'); |
|
749 | - //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
750 | - if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
751 | - EE_Error::add_attention( |
|
752 | - sprintf( |
|
753 | - __( |
|
754 | - 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
755 | - 'event_espresso' |
|
756 | - ), |
|
757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
758 | - '</a>' |
|
759 | - ), |
|
760 | - __FILE__, |
|
761 | - __FUNCTION__, |
|
762 | - __LINE__ |
|
763 | - ); |
|
764 | - } |
|
765 | - return parent::_create_new_cpt_item(); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - |
|
770 | - protected function _set_list_table_views_default() |
|
771 | - { |
|
772 | - $this->_views = array( |
|
773 | - 'all' => array( |
|
774 | - 'slug' => 'all', |
|
775 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
776 | - 'count' => 0, |
|
777 | - 'bulk_action' => array( |
|
778 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
779 | - ), |
|
780 | - ), |
|
781 | - 'draft' => array( |
|
782 | - 'slug' => 'draft', |
|
783 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
784 | - 'count' => 0, |
|
785 | - 'bulk_action' => array( |
|
786 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
787 | - ), |
|
788 | - ), |
|
789 | - ); |
|
790 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
791 | - $this->_views['trash'] = array( |
|
792 | - 'slug' => 'trash', |
|
793 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
794 | - 'count' => 0, |
|
795 | - 'bulk_action' => array( |
|
796 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
797 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
798 | - ), |
|
799 | - ); |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * @return array |
|
807 | - */ |
|
808 | - protected function _event_legend_items() |
|
809 | - { |
|
810 | - $items = array( |
|
811 | - 'view_details' => array( |
|
812 | - 'class' => 'dashicons dashicons-search', |
|
813 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
814 | - ), |
|
815 | - 'edit_event' => array( |
|
816 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
817 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
818 | - ), |
|
819 | - 'view_attendees' => array( |
|
820 | - 'class' => 'dashicons dashicons-groups', |
|
821 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
822 | - ), |
|
823 | - ); |
|
824 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
825 | - $statuses = array( |
|
826 | - 'sold_out_status' => array( |
|
827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
828 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
829 | - ), |
|
830 | - 'active_status' => array( |
|
831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
832 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
833 | - ), |
|
834 | - 'upcoming_status' => array( |
|
835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
836 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
837 | - ), |
|
838 | - 'postponed_status' => array( |
|
839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
840 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
841 | - ), |
|
842 | - 'cancelled_status' => array( |
|
843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
844 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
845 | - ), |
|
846 | - 'expired_status' => array( |
|
847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
848 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
849 | - ), |
|
850 | - 'inactive_status' => array( |
|
851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
852 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
853 | - ), |
|
854 | - ); |
|
855 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
856 | - return array_merge($items, $statuses); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * _event_model |
|
863 | - * |
|
864 | - * @return EEM_Event |
|
865 | - */ |
|
866 | - private function _event_model() |
|
867 | - { |
|
868 | - if ( ! $this->_event_model instanceof EEM_Event) { |
|
869 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
870 | - } |
|
871 | - return $this->_event_model; |
|
872 | - } |
|
873 | - |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * Adds extra buttons to the WP CPT permalink field row. |
|
878 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
879 | - * |
|
880 | - * @param string $return the current html |
|
881 | - * @param int $id the post id for the page |
|
882 | - * @param string $new_title What the title is |
|
883 | - * @param string $new_slug what the slug is |
|
884 | - * @return string The new html string for the permalink area |
|
885 | - */ |
|
886 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
887 | - { |
|
888 | - //make sure this is only when editing |
|
889 | - if ( ! empty($id)) { |
|
890 | - $post = get_post($id); |
|
891 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
892 | - . esc_html__('Shortcode', 'event_espresso') |
|
893 | - . '</a> '; |
|
894 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
895 | - . $post->ID |
|
896 | - . ']">'; |
|
897 | - } |
|
898 | - return $return; |
|
899 | - } |
|
900 | - |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * _events_overview_list_table |
|
905 | - * This contains the logic for showing the events_overview list |
|
906 | - * |
|
907 | - * @access protected |
|
908 | - * @return void |
|
909 | - * @throws \EE_Error |
|
910 | - */ |
|
911 | - protected function _events_overview_list_table() |
|
912 | - { |
|
913 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
914 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
915 | - ? (array)$this->_template_args['after_list_table'] |
|
916 | - : array(); |
|
917 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
918 | - . EEH_Template::get_button_or_link( |
|
919 | - get_post_type_archive_link('espresso_events'), |
|
920 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
921 | - 'button' |
|
922 | - ); |
|
923 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
925 | - 'create_new', |
|
926 | - 'add', |
|
927 | - array(), |
|
928 | - 'add-new-h2' |
|
929 | - ); |
|
930 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * this allows for extra misc actions in the default WP publish box |
|
937 | - * |
|
938 | - * @return void |
|
939 | - */ |
|
940 | - public function extra_misc_actions_publish_box() |
|
941 | - { |
|
942 | - $this->_generate_publish_box_extra_content(); |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
949 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
950 | - * data. |
|
951 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
952 | - * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
953 | - * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
954 | - * you handle this accordingly. |
|
955 | - * |
|
956 | - * @access protected |
|
957 | - * @abstract |
|
958 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
959 | - * @param object $post The post object of the cpt that was saved. |
|
960 | - * @return void |
|
961 | - */ |
|
962 | - protected function _insert_update_cpt_item($post_id, $post) |
|
963 | - { |
|
964 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
965 | - //get out we're not processing an event save. |
|
966 | - return; |
|
967 | - } |
|
968 | - $event_values = array( |
|
969 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
970 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
971 | - 'EVT_additional_limit' => min( |
|
972 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
973 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
974 | - ), |
|
975 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
976 | - ? $this->_req_data['EVT_default_registration_status'] |
|
977 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
978 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
979 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
980 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
981 | - ? $this->_req_data['timezone_string'] : null, |
|
982 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
983 | - ? $this->_req_data['externalURL'] : null, |
|
984 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
985 | - ? $this->_req_data['event_phone'] : null, |
|
986 | - ); |
|
987 | - //update event |
|
988 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
989 | - //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
990 | - $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
991 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
992 | - //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
993 | - $event_update_callbacks = apply_filters( |
|
994 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
995 | - array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
996 | - ); |
|
997 | - $att_success = true; |
|
998 | - foreach ($event_update_callbacks as $e_callback) { |
|
999 | - $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
1000 | - $att_success = ! $att_success ? $att_success |
|
1001 | - : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
1002 | - } |
|
1003 | - //any errors? |
|
1004 | - if ($success && false === $att_success) { |
|
1005 | - EE_Error::add_error( |
|
1006 | - esc_html__( |
|
1007 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1008 | - 'event_espresso' |
|
1009 | - ), |
|
1010 | - __FILE__, |
|
1011 | - __FUNCTION__, |
|
1012 | - __LINE__ |
|
1013 | - ); |
|
1014 | - } else if ($success === false) { |
|
1015 | - EE_Error::add_error( |
|
1016 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1017 | - __FILE__, |
|
1018 | - __FUNCTION__, |
|
1019 | - __LINE__ |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * @see parent::restore_item() |
|
1028 | - * @param int $post_id |
|
1029 | - * @param int $revision_id |
|
1030 | - */ |
|
1031 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
1032 | - { |
|
1033 | - //copy existing event meta to new post |
|
1034 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1035 | - if ($post_evt instanceof EE_Event) { |
|
1036 | - //meta revision restore |
|
1037 | - $post_evt->restore_revision($revision_id); |
|
1038 | - //related objs restore |
|
1039 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1040 | - } |
|
1041 | - } |
|
1042 | - |
|
1043 | - |
|
1044 | - |
|
1045 | - /** |
|
1046 | - * Attach the venue to the Event |
|
1047 | - * |
|
1048 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
1049 | - * @param array $data The request data from the form |
|
1050 | - * @return bool Success or fail. |
|
1051 | - */ |
|
1052 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
1053 | - { |
|
1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1055 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1056 | - $rows_affected = null; |
|
1057 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1058 | - // very important. If we don't have a venue name... |
|
1059 | - // then we'll get out because not necessary to create empty venue |
|
1060 | - if (empty($data['venue_title'])) { |
|
1061 | - return false; |
|
1062 | - } |
|
1063 | - $venue_array = array( |
|
1064 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1065 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1066 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1067 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1068 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1069 | - : null, |
|
1070 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1071 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1072 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1073 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1074 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1075 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1076 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1077 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1078 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1079 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1080 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1081 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1082 | - 'status' => 'publish', |
|
1083 | - ); |
|
1084 | - //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1085 | - if ( ! empty($venue_id)) { |
|
1086 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1087 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1088 | - //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1089 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1090 | - return $rows_affected > 0 ? true : false; |
|
1091 | - } else { |
|
1092 | - //we insert the venue |
|
1093 | - $venue_id = $venue_model->insert($venue_array); |
|
1094 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1095 | - return ! empty($venue_id) ? true : false; |
|
1096 | - } |
|
1097 | - //when we have the ancestor come in it's already been handled by the revision save. |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1104 | - * |
|
1105 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
1106 | - * @param array $data The request data from the form |
|
1107 | - * @return array |
|
1108 | - */ |
|
1109 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1110 | - { |
|
1111 | - $success = true; |
|
1112 | - $saved_dtt = null; |
|
1113 | - $saved_tickets = array(); |
|
1114 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1115 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1116 | - //trim all values to ensure any excess whitespace is removed. |
|
1117 | - $dtt = array_map('trim', $dtt); |
|
1118 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1119 | - : $dtt['DTT_EVT_start']; |
|
1120 | - $datetime_values = array( |
|
1121 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1122 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1123 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1124 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1125 | - 'DTT_order' => $row, |
|
1126 | - ); |
|
1127 | - //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
1128 | - if ( ! empty($dtt['DTT_ID'])) { |
|
1129 | - $DTM = EE_Registry::instance() |
|
1130 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1131 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
1132 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
1133 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
1134 | - foreach ($datetime_values as $field => $value) { |
|
1135 | - $DTM->set($field, $value); |
|
1136 | - } |
|
1137 | - //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
1138 | - $saved_dtts[$DTM->ID()] = $DTM; |
|
1139 | - } else { |
|
1140 | - $DTM = EE_Registry::instance()->load_class( |
|
1141 | - 'Datetime', |
|
1142 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1143 | - false, |
|
1144 | - false |
|
1145 | - ); |
|
1146 | - foreach ($datetime_values as $field => $value) { |
|
1147 | - $DTM->set($field, $value); |
|
1148 | - } |
|
1149 | - } |
|
1150 | - $DTM->save(); |
|
1151 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1152 | - //load DTT helper |
|
1153 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1154 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1155 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1156 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1157 | - $DTT->save(); |
|
1158 | - } |
|
1159 | - //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
1160 | - $saved_dtt = $DTT; |
|
1161 | - $success = ! $success ? $success : $DTT; |
|
1162 | - //if ANY of these updates fail then we want the appropriate global error message. |
|
1163 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1164 | - } |
|
1165 | - //no dtts get deleted so we don't do any of that logic here. |
|
1166 | - //update tickets next |
|
1167 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1168 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1169 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1170 | - $update_prices = false; |
|
1171 | - $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
1172 | - ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1173 | - // trim inputs to ensure any excess whitespace is removed. |
|
1174 | - $tkt = array_map('trim', $tkt); |
|
1175 | - if (empty($tkt['TKT_start_date'])) { |
|
1176 | - //let's use now in the set timezone. |
|
1177 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1179 | - } |
|
1180 | - if (empty($tkt['TKT_end_date'])) { |
|
1181 | - //use the start date of the first datetime |
|
1182 | - $dtt = $evtobj->first_datetime(); |
|
1183 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1184 | - $incoming_date_formats[0], |
|
1185 | - $incoming_date_formats[1] |
|
1186 | - ); |
|
1187 | - } |
|
1188 | - $TKT_values = array( |
|
1189 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1190 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1191 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1192 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1193 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1194 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1195 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1196 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1197 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1198 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1199 | - 'TKT_row' => $row, |
|
1200 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1201 | - 'TKT_price' => $ticket_price, |
|
1202 | - ); |
|
1203 | - //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
1204 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1205 | - $TKT_values['TKT_ID'] = 0; |
|
1206 | - $TKT_values['TKT_is_default'] = 0; |
|
1207 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1208 | - $update_prices = true; |
|
1209 | - } |
|
1210 | - //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1211 | - //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
1212 | - //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1213 | - if ( ! empty($tkt['TKT_ID'])) { |
|
1214 | - $TKT = EE_Registry::instance() |
|
1215 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1216 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
1217 | - if ($TKT instanceof EE_Ticket) { |
|
1218 | - $ticket_sold = $TKT->count_related( |
|
1219 | - 'Registration', |
|
1220 | - array( |
|
1221 | - array( |
|
1222 | - 'STS_ID' => array( |
|
1223 | - 'NOT IN', |
|
1224 | - array(EEM_Registration::status_id_incomplete), |
|
1225 | - ), |
|
1226 | - ), |
|
1227 | - ) |
|
1228 | - ) > 0 ? true : false; |
|
1229 | - //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
1230 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
1231 | - && ! $TKT->get( |
|
1232 | - 'TKT_deleted' |
|
1233 | - ) ? true : false; |
|
1234 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1235 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1236 | - //set new values |
|
1237 | - foreach ($TKT_values as $field => $value) { |
|
1238 | - if ($field == 'TKT_qty') { |
|
1239 | - $TKT->set_qty($value); |
|
1240 | - } else { |
|
1241 | - $TKT->set($field, $value); |
|
1242 | - } |
|
1243 | - } |
|
1244 | - //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1245 | - if ($create_new_TKT) { |
|
1246 | - //archive the old ticket first |
|
1247 | - $TKT->set('TKT_deleted', 1); |
|
1248 | - $TKT->save(); |
|
1249 | - //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1250 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
1251 | - //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
1252 | - $TKT = clone $TKT; |
|
1253 | - $TKT->set('TKT_ID', 0); |
|
1254 | - $TKT->set('TKT_deleted', 0); |
|
1255 | - $TKT->set('TKT_price', $ticket_price); |
|
1256 | - $TKT->set('TKT_sold', 0); |
|
1257 | - //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1258 | - $update_prices = true; |
|
1259 | - } |
|
1260 | - //make sure price is set if it hasn't been already |
|
1261 | - $TKT->set('TKT_price', $ticket_price); |
|
1262 | - } |
|
1263 | - } else { |
|
1264 | - //no TKT_id so a new TKT |
|
1265 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1266 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1267 | - if ($TKT instanceof EE_Ticket) { |
|
1268 | - //need to reset values to properly account for the date formats |
|
1269 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1270 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1271 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
1272 | - //set new values |
|
1273 | - foreach ($TKT_values as $field => $value) { |
|
1274 | - if ($field == 'TKT_qty') { |
|
1275 | - $TKT->set_qty($value); |
|
1276 | - } else { |
|
1277 | - $TKT->set($field, $value); |
|
1278 | - } |
|
1279 | - } |
|
1280 | - $update_prices = true; |
|
1281 | - } |
|
1282 | - } |
|
1283 | - // cap ticket qty by datetime reg limits |
|
1284 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1285 | - //update ticket. |
|
1286 | - $TKT->save(); |
|
1287 | - //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1288 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1289 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1290 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1291 | - $TKT->save(); |
|
1292 | - } |
|
1293 | - //initially let's add the ticket to the dtt |
|
1294 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1295 | - $saved_tickets[$TKT->ID()] = $TKT; |
|
1296 | - //add prices to ticket |
|
1297 | - $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
1298 | - } |
|
1299 | - //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
1300 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1301 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1302 | - foreach ($tickets_removed as $id) { |
|
1303 | - $id = absint($id); |
|
1304 | - //get the ticket for this id |
|
1305 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1306 | - //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
1307 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1308 | - foreach ($dtts as $dtt) { |
|
1309 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1310 | - } |
|
1311 | - //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1312 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
1313 | - //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1314 | - $tkt_to_remove->delete_permanently(); |
|
1315 | - } |
|
1316 | - return array($saved_dtt, $saved_tickets); |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * This attaches a list of given prices to a ticket. |
|
1323 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1324 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1325 | - * price info and prices are automatically "archived" via the ticket. |
|
1326 | - * |
|
1327 | - * @access private |
|
1328 | - * @param array $prices Array of prices from the form. |
|
1329 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1330 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1331 | - * @return void |
|
1332 | - */ |
|
1333 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1334 | - { |
|
1335 | - foreach ($prices as $row => $prc) { |
|
1336 | - $PRC_values = array( |
|
1337 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1338 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1339 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1340 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1341 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1342 | - 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
1343 | - 'PRC_order' => $row, |
|
1344 | - ); |
|
1345 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1346 | - $PRC_values['PRC_ID'] = 0; |
|
1347 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1348 | - } else { |
|
1349 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1350 | - //update this price with new values |
|
1351 | - foreach ($PRC_values as $field => $newprc) { |
|
1352 | - $PRC->set($field, $newprc); |
|
1353 | - } |
|
1354 | - $PRC->save(); |
|
1355 | - } |
|
1356 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
1357 | - } |
|
1358 | - } |
|
1359 | - |
|
1360 | - |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Add in our autosave ajax handlers |
|
1364 | - * |
|
1365 | - * @return void |
|
1366 | - */ |
|
1367 | - protected function _ee_autosave_create_new() |
|
1368 | - { |
|
1369 | - // $this->_ee_autosave_edit(); |
|
1370 | - } |
|
1371 | - |
|
1372 | - |
|
1373 | - |
|
1374 | - protected function _ee_autosave_edit() |
|
1375 | - { |
|
1376 | - return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1377 | - } |
|
1378 | - |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * _generate_publish_box_extra_content |
|
1383 | - * |
|
1384 | - * @access private |
|
1385 | - * @return void |
|
1386 | - */ |
|
1387 | - private function _generate_publish_box_extra_content() |
|
1388 | - { |
|
1389 | - //load formatter helper |
|
1390 | - //args for getting related registrations |
|
1391 | - $approved_query_args = array( |
|
1392 | - array( |
|
1393 | - 'REG_deleted' => 0, |
|
1394 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1395 | - ), |
|
1396 | - ); |
|
1397 | - $not_approved_query_args = array( |
|
1398 | - array( |
|
1399 | - 'REG_deleted' => 0, |
|
1400 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1401 | - ), |
|
1402 | - ); |
|
1403 | - $pending_payment_query_args = array( |
|
1404 | - array( |
|
1405 | - 'REG_deleted' => 0, |
|
1406 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1407 | - ), |
|
1408 | - ); |
|
1409 | - // publish box |
|
1410 | - $publish_box_extra_args = array( |
|
1411 | - 'view_approved_reg_url' => add_query_arg( |
|
1412 | - array( |
|
1413 | - 'action' => 'default', |
|
1414 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1415 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1416 | - ), |
|
1417 | - REG_ADMIN_URL |
|
1418 | - ), |
|
1419 | - 'view_not_approved_reg_url' => add_query_arg( |
|
1420 | - array( |
|
1421 | - 'action' => 'default', |
|
1422 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1423 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1424 | - ), |
|
1425 | - REG_ADMIN_URL |
|
1426 | - ), |
|
1427 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
1428 | - array( |
|
1429 | - 'action' => 'default', |
|
1430 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1431 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1432 | - ), |
|
1433 | - REG_ADMIN_URL |
|
1434 | - ), |
|
1435 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1436 | - 'Registration', |
|
1437 | - $approved_query_args |
|
1438 | - ), |
|
1439 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1440 | - 'Registration', |
|
1441 | - $not_approved_query_args |
|
1442 | - ), |
|
1443 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1444 | - 'Registration', |
|
1445 | - $pending_payment_query_args |
|
1446 | - ), |
|
1447 | - 'misc_pub_section_class' => apply_filters( |
|
1448 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1449 | - 'misc-pub-section' |
|
1450 | - ), |
|
1451 | - //'email_attendees_url' => add_query_arg( |
|
1452 | - // array( |
|
1453 | - // 'event_admin_reports' => 'event_newsletter', |
|
1454 | - // 'event_id' => $this->_cpt_model_obj->id |
|
1455 | - // ), |
|
1456 | - // 'admin.php?page=espresso_registrations' |
|
1457 | - //), |
|
1458 | - ); |
|
1459 | - ob_start(); |
|
1460 | - do_action( |
|
1461 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1462 | - $this->_cpt_model_obj |
|
1463 | - ); |
|
1464 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1465 | - // load template |
|
1466 | - EEH_Template::display_template( |
|
1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1468 | - $publish_box_extra_args |
|
1469 | - ); |
|
1470 | - } |
|
1471 | - |
|
1472 | - |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * This just returns whatever is set as the _event object property |
|
1476 | - * //todo this will become obsolete once the models are in place |
|
1477 | - * |
|
1478 | - * @return object |
|
1479 | - */ |
|
1480 | - public function get_event_object() |
|
1481 | - { |
|
1482 | - return $this->_cpt_model_obj; |
|
1483 | - } |
|
1484 | - |
|
1485 | - |
|
1486 | - |
|
1487 | - |
|
1488 | - /** METABOXES * */ |
|
1489 | - /** |
|
1490 | - * _register_event_editor_meta_boxes |
|
1491 | - * add all metaboxes related to the event_editor |
|
1492 | - * |
|
1493 | - * @return void |
|
1494 | - */ |
|
1495 | - protected function _register_event_editor_meta_boxes() |
|
1496 | - { |
|
1497 | - $this->verify_cpt_object(); |
|
1498 | - add_meta_box( |
|
1499 | - 'espresso_event_editor_tickets', |
|
1500 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1501 | - array($this, 'ticket_metabox'), |
|
1502 | - $this->page_slug, |
|
1503 | - 'normal', |
|
1504 | - 'high' |
|
1505 | - ); |
|
1506 | - add_meta_box( |
|
1507 | - 'espresso_event_editor_event_options', |
|
1508 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
1509 | - array($this, 'registration_options_meta_box'), |
|
1510 | - $this->page_slug, |
|
1511 | - 'side', |
|
1512 | - 'default' |
|
1513 | - ); |
|
1514 | - // NOTE: if you're looking for other metaboxes in here, |
|
1515 | - // where a metabox has a related management page in the admin |
|
1516 | - // you will find it setup in the related management page's "_Hooks" file. |
|
1517 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1518 | - } |
|
1519 | - |
|
1520 | - |
|
1521 | - |
|
1522 | - public function ticket_metabox() |
|
1523 | - { |
|
1524 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1525 | - //defaults for template args |
|
1526 | - $template_args = array( |
|
1527 | - 'existing_datetime_ids' => '', |
|
1528 | - 'event_datetime_help_link' => '', |
|
1529 | - 'ticket_options_help_link' => '', |
|
1530 | - 'time' => null, |
|
1531 | - 'ticket_rows' => '', |
|
1532 | - 'existing_ticket_ids' => '', |
|
1533 | - 'total_ticket_rows' => 1, |
|
1534 | - 'ticket_js_structure' => '', |
|
1535 | - 'trash_icon' => 'ee-lock-icon', |
|
1536 | - 'disabled' => '', |
|
1537 | - ); |
|
1538 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1539 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1540 | - /** |
|
1541 | - * 1. Start with retrieving Datetimes |
|
1542 | - * 2. Fore each datetime get related tickets |
|
1543 | - * 3. For each ticket get related prices |
|
1544 | - */ |
|
1545 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1546 | - /** @type EE_Datetime $first_datetime */ |
|
1547 | - $first_datetime = reset($times); |
|
1548 | - //do we get related tickets? |
|
1549 | - if ($first_datetime instanceof EE_Datetime |
|
1550 | - && $first_datetime->ID() !== 0 |
|
1551 | - ) { |
|
1552 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1553 | - $template_args['time'] = $first_datetime; |
|
1554 | - $related_tickets = $first_datetime->tickets( |
|
1555 | - array( |
|
1556 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1557 | - 'default_where_conditions' => 'none', |
|
1558 | - ) |
|
1559 | - ); |
|
1560 | - if ( ! empty($related_tickets)) { |
|
1561 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
1562 | - $row = 0; |
|
1563 | - foreach ($related_tickets as $ticket) { |
|
1564 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1565 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1566 | - $row++; |
|
1567 | - } |
|
1568 | - } else { |
|
1569 | - $template_args['total_ticket_rows'] = 1; |
|
1570 | - /** @type EE_Ticket $ticket */ |
|
1571 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1572 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1573 | - } |
|
1574 | - } else { |
|
1575 | - $template_args['time'] = $times[0]; |
|
1576 | - /** @type EE_Ticket $ticket */ |
|
1577 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1578 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1579 | - // NOTE: we're just sending the first default row |
|
1580 | - // (decaf can't manage default tickets so this should be sufficient); |
|
1581 | - } |
|
1582 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1583 | - 'event_editor_event_datetimes_help_tab' |
|
1584 | - ); |
|
1585 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1586 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1587 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1588 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1589 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1590 | - true |
|
1591 | - ); |
|
1592 | - $template = apply_filters( |
|
1593 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1595 | - ); |
|
1596 | - EEH_Template::display_template($template, $template_args); |
|
1597 | - } |
|
1598 | - |
|
1599 | - |
|
1600 | - |
|
1601 | - /** |
|
1602 | - * Setup an individual ticket form for the decaf event editor page |
|
1603 | - * |
|
1604 | - * @access private |
|
1605 | - * @param EE_Ticket $ticket the ticket object |
|
1606 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1607 | - * @param int $row |
|
1608 | - * @return string generated html for the ticket row. |
|
1609 | - */ |
|
1610 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1611 | - { |
|
1612 | - $template_args = array( |
|
1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1614 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1615 | - : '', |
|
1616 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1617 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1618 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
1619 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1620 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1621 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1622 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1623 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1624 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1625 | - 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1626 | - && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1627 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1628 | - 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1629 | - : ' disabled=disabled', |
|
1630 | - ); |
|
1631 | - $price = $ticket->ID() !== 0 |
|
1632 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1633 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1634 | - $price_args = array( |
|
1635 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1636 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
1637 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
1638 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
1639 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1640 | - ); |
|
1641 | - //make sure we have default start and end dates if skeleton |
|
1642 | - //handle rows that should NOT be empty |
|
1643 | - if (empty($template_args['TKT_start_date'])) { |
|
1644 | - //if empty then the start date will be now. |
|
1645 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1646 | - } |
|
1647 | - if (empty($template_args['TKT_end_date'])) { |
|
1648 | - //get the earliest datetime (if present); |
|
1649 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1650 | - ? $this->_cpt_model_obj->get_first_related( |
|
1651 | - 'Datetime', |
|
1652 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1653 | - ) |
|
1654 | - : null; |
|
1655 | - if ( ! empty($earliest_dtt)) { |
|
1656 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1657 | - } else { |
|
1658 | - $template_args['TKT_end_date'] = date( |
|
1659 | - 'Y-m-d h:i a', |
|
1660 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
1661 | - ); |
|
1662 | - } |
|
1663 | - } |
|
1664 | - $template_args = array_merge($template_args, $price_args); |
|
1665 | - $template = apply_filters( |
|
1666 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1668 | - $ticket |
|
1669 | - ); |
|
1670 | - return EEH_Template::display_template($template, $template_args, true); |
|
1671 | - } |
|
1672 | - |
|
1673 | - |
|
1674 | - |
|
1675 | - public function registration_options_meta_box() |
|
1676 | - { |
|
1677 | - $yes_no_values = array( |
|
1678 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1679 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1680 | - ); |
|
1681 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1682 | - array( |
|
1683 | - EEM_Registration::status_id_cancelled, |
|
1684 | - EEM_Registration::status_id_declined, |
|
1685 | - EEM_Registration::status_id_incomplete, |
|
1686 | - ), |
|
1687 | - true |
|
1688 | - ); |
|
1689 | - //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1690 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
1691 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1692 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1693 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1694 | - 'default_reg_status', |
|
1695 | - $default_reg_status_values, |
|
1696 | - $this->_cpt_model_obj->default_registration_status() |
|
1697 | - ); |
|
1698 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1699 | - 'display_desc', |
|
1700 | - $yes_no_values, |
|
1701 | - $this->_cpt_model_obj->display_description() |
|
1702 | - ); |
|
1703 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1704 | - 'display_ticket_selector', |
|
1705 | - $yes_no_values, |
|
1706 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
1707 | - '', |
|
1708 | - '', |
|
1709 | - false |
|
1710 | - ); |
|
1711 | - $template_args['additional_registration_options'] = apply_filters( |
|
1712 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1713 | - '', |
|
1714 | - $template_args, |
|
1715 | - $yes_no_values, |
|
1716 | - $default_reg_status_values |
|
1717 | - ); |
|
1718 | - EEH_Template::display_template( |
|
1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1720 | - $template_args |
|
1721 | - ); |
|
1722 | - } |
|
1723 | - |
|
1724 | - |
|
1725 | - |
|
1726 | - /** |
|
1727 | - * _get_events() |
|
1728 | - * This method simply returns all the events (for the given _view and paging) |
|
1729 | - * |
|
1730 | - * @access public |
|
1731 | - * @param int $per_page count of items per page (20 default); |
|
1732 | - * @param int $current_page what is the current page being viewed. |
|
1733 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1734 | - * If FALSE then we return an array of event objects |
|
1735 | - * that match the given _view and paging parameters. |
|
1736 | - * @return array an array of event objects. |
|
1737 | - */ |
|
1738 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1739 | - { |
|
1740 | - $EEME = $this->_event_model(); |
|
1741 | - $offset = ($current_page - 1) * $per_page; |
|
1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1743 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1744 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
1745 | - if (isset($this->_req_data['month_range'])) { |
|
1746 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1747 | - //simulate the FIRST day of the month, that fixes issues for months like February |
|
1748 | - //where PHP doesn't know what to assume for date. |
|
1749 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1750 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1751 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1752 | - } |
|
1753 | - $where = array(); |
|
1754 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1755 | - //determine what post_status our condition will have for the query. |
|
1756 | - switch ($status) { |
|
1757 | - case 'month' : |
|
1758 | - case 'today' : |
|
1759 | - case null : |
|
1760 | - case 'all' : |
|
1761 | - break; |
|
1762 | - case 'draft' : |
|
1763 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1764 | - break; |
|
1765 | - default : |
|
1766 | - $where['status'] = $status; |
|
1767 | - } |
|
1768 | - //categories? |
|
1769 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1770 | - ? $this->_req_data['EVT_CAT'] : null; |
|
1771 | - if ( ! empty ($category)) { |
|
1772 | - $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1773 | - $where['Term_Taxonomy.term_id'] = $category; |
|
1774 | - } |
|
1775 | - //date where conditions |
|
1776 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1777 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
1778 | - $DateTime = new DateTime( |
|
1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1780 | - new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
1781 | - ); |
|
1782 | - $start = $DateTime->format(implode(' ', $start_formats)); |
|
1783 | - $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
1784 | - ->format('t'))->setTime(23, 59, 59) |
|
1785 | - ->format(implode(' ', $start_formats)); |
|
1786 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1787 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
1788 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1789 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1790 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1791 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1792 | - } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1793 | - $now = date('Y-m-01'); |
|
1794 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1795 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1796 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1797 | - ->setTime(23, 59, 59) |
|
1798 | - ->format(implode(' ', $start_formats)); |
|
1799 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1800 | - } |
|
1801 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1802 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1803 | - } else { |
|
1804 | - if ( ! isset($where['status'])) { |
|
1805 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1806 | - $where['OR'] = array( |
|
1807 | - 'status*restrict_private' => array('!=', 'private'), |
|
1808 | - 'AND' => array( |
|
1809 | - 'status*inclusive' => array('=', 'private'), |
|
1810 | - 'EVT_wp_user' => get_current_user_id(), |
|
1811 | - ), |
|
1812 | - ); |
|
1813 | - } |
|
1814 | - } |
|
1815 | - } |
|
1816 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
1817 | - if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
1818 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1819 | - ) { |
|
1820 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1821 | - } |
|
1822 | - } |
|
1823 | - //search query handling |
|
1824 | - if (isset($this->_req_data['s'])) { |
|
1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1826 | - $where['OR'] = array( |
|
1827 | - 'EVT_name' => array('LIKE', $search_string), |
|
1828 | - 'EVT_desc' => array('LIKE', $search_string), |
|
1829 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
1830 | - ); |
|
1831 | - } |
|
1832 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1833 | - $query_params = apply_filters( |
|
1834 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1835 | - array( |
|
1836 | - $where, |
|
1837 | - 'limit' => $limit, |
|
1838 | - 'order_by' => $orderby, |
|
1839 | - 'order' => $order, |
|
1840 | - 'group_by' => 'EVT_ID', |
|
1841 | - ), |
|
1842 | - $this->_req_data |
|
1843 | - ); |
|
1844 | - //let's first check if we have special requests coming in. |
|
1845 | - if (isset($this->_req_data['active_status'])) { |
|
1846 | - switch ($this->_req_data['active_status']) { |
|
1847 | - case 'upcoming' : |
|
1848 | - return $EEME->get_upcoming_events($query_params, $count); |
|
1849 | - break; |
|
1850 | - case 'expired' : |
|
1851 | - return $EEME->get_expired_events($query_params, $count); |
|
1852 | - break; |
|
1853 | - case 'active' : |
|
1854 | - return $EEME->get_active_events($query_params, $count); |
|
1855 | - break; |
|
1856 | - case 'inactive' : |
|
1857 | - return $EEME->get_inactive_events($query_params, $count); |
|
1858 | - break; |
|
1859 | - } |
|
1860 | - } |
|
1861 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1862 | - return $events; |
|
1863 | - } |
|
1864 | - |
|
1865 | - |
|
1866 | - |
|
1867 | - /** |
|
1868 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
1869 | - * |
|
1870 | - * @param string $post_id |
|
1871 | - */ |
|
1872 | - public function trash_cpt_item($post_id) |
|
1873 | - { |
|
1874 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1875 | - $this->_trash_or_restore_event('trash', false); |
|
1876 | - } |
|
1877 | - |
|
1878 | - |
|
1879 | - |
|
1880 | - /** |
|
1881 | - * @param string $post_id |
|
1882 | - */ |
|
1883 | - public function restore_cpt_item($post_id) |
|
1884 | - { |
|
1885 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1886 | - $this->_trash_or_restore_event('draft', false); |
|
1887 | - } |
|
1888 | - |
|
1889 | - |
|
1890 | - |
|
1891 | - /** |
|
1892 | - * @param string $post_id |
|
1893 | - */ |
|
1894 | - public function delete_cpt_item($post_id) |
|
1895 | - { |
|
1896 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1897 | - $this->_delete_event(false); |
|
1898 | - } |
|
1899 | - |
|
1900 | - |
|
1901 | - |
|
1902 | - /** |
|
1903 | - * _trash_or_restore_event |
|
1904 | - * |
|
1905 | - * @access protected |
|
1906 | - * @param string $event_status |
|
1907 | - * @param bool $redirect_after |
|
1908 | - */ |
|
1909 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
1910 | - { |
|
1911 | - //determine the event id and set to array. |
|
1912 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
1913 | - // loop thru events |
|
1914 | - if ($EVT_ID) { |
|
1915 | - // clean status |
|
1916 | - $event_status = sanitize_key($event_status); |
|
1917 | - // grab status |
|
1918 | - if ( ! empty($event_status)) { |
|
1919 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
1920 | - } else { |
|
1921 | - $success = false; |
|
1922 | - $msg = esc_html__( |
|
1923 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1924 | - 'event_espresso' |
|
1925 | - ); |
|
1926 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1927 | - } |
|
1928 | - } else { |
|
1929 | - $success = false; |
|
1930 | - $msg = esc_html__( |
|
1931 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
1932 | - 'event_espresso' |
|
1933 | - ); |
|
1934 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1935 | - } |
|
1936 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1937 | - if ($redirect_after) { |
|
1938 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
1939 | - } |
|
1940 | - } |
|
1941 | - |
|
1942 | - |
|
1943 | - |
|
1944 | - /** |
|
1945 | - * _trash_or_restore_events |
|
1946 | - * |
|
1947 | - * @access protected |
|
1948 | - * @param string $event_status |
|
1949 | - * @return void |
|
1950 | - */ |
|
1951 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
1952 | - { |
|
1953 | - // clean status |
|
1954 | - $event_status = sanitize_key($event_status); |
|
1955 | - // grab status |
|
1956 | - if ( ! empty($event_status)) { |
|
1957 | - $success = true; |
|
1958 | - //determine the event id and set to array. |
|
1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
1960 | - // loop thru events |
|
1961 | - foreach ($EVT_IDs as $EVT_ID) { |
|
1962 | - if ($EVT_ID = absint($EVT_ID)) { |
|
1963 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
1964 | - $success = $results !== false ? $success : false; |
|
1965 | - } else { |
|
1966 | - $msg = sprintf( |
|
1967 | - esc_html__( |
|
1968 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
1969 | - 'event_espresso' |
|
1970 | - ), |
|
1971 | - $EVT_ID |
|
1972 | - ); |
|
1973 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1974 | - $success = false; |
|
1975 | - } |
|
1976 | - } |
|
1977 | - } else { |
|
1978 | - $success = false; |
|
1979 | - $msg = esc_html__( |
|
1980 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1981 | - 'event_espresso' |
|
1982 | - ); |
|
1983 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1984 | - } |
|
1985 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
1986 | - $success = $success ? 2 : false; |
|
1987 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1988 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
1989 | - } |
|
1990 | - |
|
1991 | - |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * _trash_or_restore_events |
|
1995 | - * |
|
1996 | - * @access private |
|
1997 | - * @param int $EVT_ID |
|
1998 | - * @param string $event_status |
|
1999 | - * @return bool |
|
2000 | - */ |
|
2001 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2002 | - { |
|
2003 | - // grab event id |
|
2004 | - if ( ! $EVT_ID) { |
|
2005 | - $msg = esc_html__( |
|
2006 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2007 | - 'event_espresso' |
|
2008 | - ); |
|
2009 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2010 | - return false; |
|
2011 | - } |
|
2012 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2013 | - // clean status |
|
2014 | - $event_status = sanitize_key($event_status); |
|
2015 | - // grab status |
|
2016 | - if (empty($event_status)) { |
|
2017 | - $msg = esc_html__( |
|
2018 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2019 | - 'event_espresso' |
|
2020 | - ); |
|
2021 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2022 | - return false; |
|
2023 | - } |
|
2024 | - // was event trashed or restored ? |
|
2025 | - switch ($event_status) { |
|
2026 | - case 'draft' : |
|
2027 | - $action = 'restored from the trash'; |
|
2028 | - $hook = 'AHEE_event_restored_from_trash'; |
|
2029 | - break; |
|
2030 | - case 'trash' : |
|
2031 | - $action = 'moved to the trash'; |
|
2032 | - $hook = 'AHEE_event_moved_to_trash'; |
|
2033 | - break; |
|
2034 | - default : |
|
2035 | - $action = 'updated'; |
|
2036 | - $hook = false; |
|
2037 | - } |
|
2038 | - //use class to change status |
|
2039 | - $this->_cpt_model_obj->set_status($event_status); |
|
2040 | - $success = $this->_cpt_model_obj->save(); |
|
2041 | - if ($success === false) { |
|
2042 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2043 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2044 | - return false; |
|
2045 | - } |
|
2046 | - if ($hook) { |
|
2047 | - do_action($hook); |
|
2048 | - } |
|
2049 | - return true; |
|
2050 | - } |
|
2051 | - |
|
2052 | - |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * _delete_event |
|
2056 | - * |
|
2057 | - * @access protected |
|
2058 | - * @param bool $redirect_after |
|
2059 | - */ |
|
2060 | - protected function _delete_event($redirect_after = true) |
|
2061 | - { |
|
2062 | - //determine the event id and set to array. |
|
2063 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
2064 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
2065 | - // loop thru events |
|
2066 | - if ($EVT_ID) { |
|
2067 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
2068 | - // get list of events with no prices |
|
2069 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2070 | - // remove this event from the list of events with no prices |
|
2071 | - if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
2072 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2073 | - } |
|
2074 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2075 | - } else { |
|
2076 | - $success = false; |
|
2077 | - $msg = esc_html__( |
|
2078 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2079 | - 'event_espresso' |
|
2080 | - ); |
|
2081 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2082 | - } |
|
2083 | - if ($redirect_after) { |
|
2084 | - $this->_redirect_after_action( |
|
2085 | - $success, |
|
2086 | - 'Event', |
|
2087 | - 'deleted', |
|
2088 | - array('action' => 'default', 'status' => 'trash') |
|
2089 | - ); |
|
2090 | - } |
|
2091 | - } |
|
2092 | - |
|
2093 | - |
|
2094 | - |
|
2095 | - /** |
|
2096 | - * _delete_events |
|
2097 | - * |
|
2098 | - * @access protected |
|
2099 | - * @return void |
|
2100 | - */ |
|
2101 | - protected function _delete_events() |
|
2102 | - { |
|
2103 | - $success = true; |
|
2104 | - // get list of events with no prices |
|
2105 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2106 | - //determine the event id and set to array. |
|
2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
2108 | - // loop thru events |
|
2109 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2110 | - $EVT_ID = absint($EVT_ID); |
|
2111 | - if ($EVT_ID) { |
|
2112 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
2113 | - $success = $results !== false ? $success : false; |
|
2114 | - // remove this event from the list of events with no prices |
|
2115 | - unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2116 | - } else { |
|
2117 | - $success = false; |
|
2118 | - $msg = esc_html__( |
|
2119 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2120 | - 'event_espresso' |
|
2121 | - ); |
|
2122 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2123 | - } |
|
2124 | - } |
|
2125 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2126 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2127 | - $success = $success ? 2 : false; |
|
2128 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
2129 | - } |
|
2130 | - |
|
2131 | - |
|
2132 | - |
|
2133 | - /** |
|
2134 | - * _permanently_delete_event |
|
2135 | - * |
|
2136 | - * @access private |
|
2137 | - * @param int $EVT_ID |
|
2138 | - * @return bool |
|
2139 | - */ |
|
2140 | - private function _permanently_delete_event($EVT_ID = 0) |
|
2141 | - { |
|
2142 | - // grab event id |
|
2143 | - if ( ! $EVT_ID) { |
|
2144 | - $msg = esc_html__( |
|
2145 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2146 | - 'event_espresso' |
|
2147 | - ); |
|
2148 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2149 | - return false; |
|
2150 | - } |
|
2151 | - if ( |
|
2152 | - ! $this->_cpt_model_obj instanceof EE_Event |
|
2153 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
2154 | - ) { |
|
2155 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2156 | - } |
|
2157 | - if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
2158 | - return false; |
|
2159 | - } |
|
2160 | - //need to delete related tickets and prices first. |
|
2161 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
2162 | - foreach ($datetimes as $datetime) { |
|
2163 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
2164 | - $tickets = $datetime->get_many_related('Ticket'); |
|
2165 | - foreach ($tickets as $ticket) { |
|
2166 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
2167 | - $ticket->delete_related_permanently('Price'); |
|
2168 | - $ticket->delete_permanently(); |
|
2169 | - } |
|
2170 | - $datetime->delete(); |
|
2171 | - } |
|
2172 | - //what about related venues or terms? |
|
2173 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
2174 | - foreach ($venues as $venue) { |
|
2175 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
2176 | - } |
|
2177 | - //any attached question groups? |
|
2178 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
2179 | - if ( ! empty($question_groups)) { |
|
2180 | - foreach ($question_groups as $question_group) { |
|
2181 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
2182 | - } |
|
2183 | - } |
|
2184 | - //Message Template Groups |
|
2185 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
2186 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
2187 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
2188 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
2189 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
2190 | - } |
|
2191 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
2192 | - // did it all go as planned ? |
|
2193 | - if ($success) { |
|
2194 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
2195 | - EE_Error::add_success($msg); |
|
2196 | - } else { |
|
2197 | - $msg = sprintf( |
|
2198 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
2199 | - $EVT_ID |
|
2200 | - ); |
|
2201 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2202 | - return false; |
|
2203 | - } |
|
2204 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
2205 | - return true; |
|
2206 | - } |
|
2207 | - |
|
2208 | - |
|
2209 | - |
|
2210 | - /** |
|
2211 | - * get total number of events |
|
2212 | - * |
|
2213 | - * @access public |
|
2214 | - * @return int |
|
2215 | - */ |
|
2216 | - public function total_events() |
|
2217 | - { |
|
2218 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2219 | - return $count; |
|
2220 | - } |
|
2221 | - |
|
2222 | - |
|
2223 | - |
|
2224 | - /** |
|
2225 | - * get total number of draft events |
|
2226 | - * |
|
2227 | - * @access public |
|
2228 | - * @return int |
|
2229 | - */ |
|
2230 | - public function total_events_draft() |
|
2231 | - { |
|
2232 | - $where = array( |
|
2233 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
2234 | - ); |
|
2235 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2236 | - return $count; |
|
2237 | - } |
|
2238 | - |
|
2239 | - |
|
2240 | - |
|
2241 | - /** |
|
2242 | - * get total number of trashed events |
|
2243 | - * |
|
2244 | - * @access public |
|
2245 | - * @return int |
|
2246 | - */ |
|
2247 | - public function total_trashed_events() |
|
2248 | - { |
|
2249 | - $where = array( |
|
2250 | - 'status' => 'trash', |
|
2251 | - ); |
|
2252 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2253 | - return $count; |
|
2254 | - } |
|
2255 | - |
|
2256 | - |
|
2257 | - /** |
|
2258 | - * _default_event_settings |
|
2259 | - * This generates the Default Settings Tab |
|
2260 | - * |
|
2261 | - * @return void |
|
2262 | - * @throws \EE_Error |
|
2263 | - */ |
|
2264 | - protected function _default_event_settings() |
|
2265 | - { |
|
2266 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2267 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2268 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2269 | - $this->display_admin_page_with_sidebar(); |
|
2270 | - } |
|
2271 | - |
|
2272 | - |
|
2273 | - /** |
|
2274 | - * Return the form for event settings. |
|
2275 | - * @return \EE_Form_Section_Proper |
|
2276 | - */ |
|
2277 | - protected function _default_event_settings_form() |
|
2278 | - { |
|
2279 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2280 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2281 | - //exclude |
|
2282 | - array( |
|
2283 | - EEM_Registration::status_id_cancelled, |
|
2284 | - EEM_Registration::status_id_declined, |
|
2285 | - EEM_Registration::status_id_incomplete, |
|
2286 | - EEM_Registration::status_id_wait_list, |
|
2287 | - ), |
|
2288 | - true |
|
2289 | - ); |
|
2290 | - return new EE_Form_Section_Proper( |
|
2291 | - array( |
|
2292 | - 'name' => 'update_default_event_settings', |
|
2293 | - 'html_id' => 'update_default_event_settings', |
|
2294 | - 'html_class' => 'form-table', |
|
2295 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2296 | - 'subsections' => apply_filters( |
|
2297 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2298 | - array( |
|
2299 | - 'default_reg_status' => new EE_Select_Input( |
|
2300 | - $registration_stati_for_selection, |
|
2301 | - array( |
|
2302 | - 'default' => isset($registration_config->default_STS_ID) |
|
2303 | - && array_key_exists( |
|
2304 | - $registration_config->default_STS_ID, |
|
2305 | - $registration_stati_for_selection |
|
2306 | - ) |
|
2307 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
2308 | - : EEM_Registration::status_id_pending_payment, |
|
2309 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2310 | - . EEH_Template::get_help_tab_link( |
|
2311 | - 'default_settings_status_help_tab' |
|
2312 | - ), |
|
2313 | - 'html_help_text' => esc_html__( |
|
2314 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2315 | - 'event_espresso' |
|
2316 | - ) |
|
2317 | - ) |
|
2318 | - ), |
|
2319 | - 'default_max_tickets' => new EE_Integer_Input( |
|
2320 | - array( |
|
2321 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2322 | - ? $registration_config->default_maximum_number_of_tickets |
|
2323 | - : EEM_Event::get_default_additional_limit(), |
|
2324 | - 'html_label_text' => esc_html__( |
|
2325 | - 'Default Maximum Tickets Allowed Per Order:', |
|
2326 | - 'event_espresso' |
|
2327 | - ) . EEH_Template::get_help_tab_link( |
|
2328 | - 'default_maximum_tickets_help_tab"' |
|
2329 | - ), |
|
2330 | - 'html_help_text' => esc_html__( |
|
2331 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2332 | - 'event_espresso' |
|
2333 | - ) |
|
2334 | - ) |
|
2335 | - ) |
|
2336 | - ) |
|
2337 | - ) |
|
2338 | - ) |
|
2339 | - ); |
|
2340 | - } |
|
2341 | - |
|
2342 | - |
|
2343 | - /** |
|
2344 | - * _update_default_event_settings |
|
2345 | - * |
|
2346 | - * @access protected |
|
2347 | - * @return void |
|
2348 | - * @throws \EE_Error |
|
2349 | - */ |
|
2350 | - protected function _update_default_event_settings() |
|
2351 | - { |
|
2352 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2353 | - $form = $this->_default_event_settings_form(); |
|
2354 | - if ($form->was_submitted()) { |
|
2355 | - $form->receive_form_submission(); |
|
2356 | - if ($form->is_valid()) { |
|
2357 | - $valid_data = $form->valid_data(); |
|
2358 | - if (isset($valid_data['default_reg_status'])) { |
|
2359 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2360 | - } |
|
2361 | - if (isset($valid_data['default_max_tickets'])) { |
|
2362 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2363 | - } |
|
2364 | - //update because data was valid! |
|
2365 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
2366 | - EE_Error::overwrite_success(); |
|
2367 | - EE_Error::add_success( |
|
2368 | - __('Default Event Settings were updated', 'event_espresso') |
|
2369 | - ); |
|
2370 | - } |
|
2371 | - } |
|
2372 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2373 | - } |
|
2374 | - |
|
2375 | - |
|
2376 | - |
|
2377 | - /************* Templates *************/ |
|
2378 | - protected function _template_settings() |
|
2379 | - { |
|
2380 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2381 | - $this->_template_args['preview_img'] = '<img src="' |
|
2382 | - . EVENTS_ASSETS_URL |
|
2383 | - . DS |
|
2384 | - . 'images' |
|
2385 | - . DS |
|
2386 | - . 'caffeinated_template_features.jpg" alt="' |
|
2387 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2388 | - . '" />'; |
|
2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
2390 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2391 | - 'event_espresso' |
|
2392 | - ) . '</strong>'; |
|
2393 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2394 | - } |
|
2395 | - |
|
2396 | - |
|
2397 | - /** Event Category Stuff **/ |
|
2398 | - /** |
|
2399 | - * set the _category property with the category object for the loaded page. |
|
2400 | - * |
|
2401 | - * @access private |
|
2402 | - * @return void |
|
2403 | - */ |
|
2404 | - private function _set_category_object() |
|
2405 | - { |
|
2406 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2407 | - return; |
|
2408 | - } //already have the category object so get out. |
|
2409 | - //set default category object |
|
2410 | - $this->_set_empty_category_object(); |
|
2411 | - //only set if we've got an id |
|
2412 | - if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2413 | - return; |
|
2414 | - } |
|
2415 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2416 | - $term = get_term($category_id, 'espresso_event_categories'); |
|
2417 | - if ( ! empty($term)) { |
|
2418 | - $this->_category->category_name = $term->name; |
|
2419 | - $this->_category->category_identifier = $term->slug; |
|
2420 | - $this->_category->category_desc = $term->description; |
|
2421 | - $this->_category->id = $term->term_id; |
|
2422 | - $this->_category->parent = $term->parent; |
|
2423 | - } |
|
2424 | - } |
|
2425 | - |
|
2426 | - |
|
2427 | - |
|
2428 | - private function _set_empty_category_object() |
|
2429 | - { |
|
2430 | - $this->_category = new stdClass(); |
|
2431 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2432 | - $this->_category->id = $this->_category->parent = 0; |
|
2433 | - } |
|
2434 | - |
|
2435 | - |
|
2436 | - |
|
2437 | - protected function _category_list_table() |
|
2438 | - { |
|
2439 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2440 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2442 | - 'add_category', |
|
2443 | - 'add_category', |
|
2444 | - array(), |
|
2445 | - 'add-new-h2' |
|
2446 | - ); |
|
2447 | - $this->display_admin_list_table_page_with_sidebar(); |
|
2448 | - } |
|
2449 | - |
|
2450 | - |
|
2451 | - |
|
2452 | - /** |
|
2453 | - * @param $view |
|
2454 | - */ |
|
2455 | - protected function _category_details($view) |
|
2456 | - { |
|
2457 | - //load formatter helper |
|
2458 | - //load field generator helper |
|
2459 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2460 | - $this->_set_add_edit_form_tags($route); |
|
2461 | - $this->_set_category_object(); |
|
2462 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2463 | - $delete_action = 'delete_category'; |
|
2464 | - //custom redirect |
|
2465 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2466 | - array('action' => 'category_list'), |
|
2467 | - $this->_admin_base_url |
|
2468 | - ); |
|
2469 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2470 | - //take care of contents |
|
2471 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2472 | - $this->display_admin_page_with_sidebar(); |
|
2473 | - } |
|
2474 | - |
|
2475 | - |
|
2476 | - |
|
2477 | - /** |
|
2478 | - * @return mixed |
|
2479 | - */ |
|
2480 | - protected function _category_details_content() |
|
2481 | - { |
|
2482 | - $editor_args['category_desc'] = array( |
|
2483 | - 'type' => 'wp_editor', |
|
2484 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2485 | - 'class' => 'my_editor_custom', |
|
2486 | - 'wpeditor_args' => array('media_buttons' => false), |
|
2487 | - ); |
|
2488 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2489 | - $all_terms = get_terms( |
|
2490 | - array('espresso_event_categories'), |
|
2491 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2492 | - ); |
|
2493 | - //setup category select for term parents. |
|
2494 | - $category_select_values[] = array( |
|
2495 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2496 | - 'id' => 0, |
|
2497 | - ); |
|
2498 | - foreach ($all_terms as $term) { |
|
2499 | - $category_select_values[] = array( |
|
2500 | - 'text' => $term->name, |
|
2501 | - 'id' => $term->term_id, |
|
2502 | - ); |
|
2503 | - } |
|
2504 | - $category_select = EEH_Form_Fields::select_input( |
|
2505 | - 'category_parent', |
|
2506 | - $category_select_values, |
|
2507 | - $this->_category->parent |
|
2508 | - ); |
|
2509 | - $template_args = array( |
|
2510 | - 'category' => $this->_category, |
|
2511 | - 'category_select' => $category_select, |
|
2512 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2513 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2514 | - 'disable' => '', |
|
2515 | - 'disabled_message' => false, |
|
2516 | - ); |
|
2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2518 | - return EEH_Template::display_template($template, $template_args, true); |
|
2519 | - } |
|
2520 | - |
|
2521 | - |
|
2522 | - |
|
2523 | - protected function _delete_categories() |
|
2524 | - { |
|
2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
2526 | - : (array)$this->_req_data['category_id']; |
|
2527 | - foreach ($cat_ids as $cat_id) { |
|
2528 | - $this->_delete_category($cat_id); |
|
2529 | - } |
|
2530 | - //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2531 | - $query_args = array( |
|
2532 | - 'action' => 'category_list', |
|
2533 | - ); |
|
2534 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
2535 | - } |
|
2536 | - |
|
2537 | - |
|
2538 | - |
|
2539 | - /** |
|
2540 | - * @param $cat_id |
|
2541 | - */ |
|
2542 | - protected function _delete_category($cat_id) |
|
2543 | - { |
|
2544 | - $cat_id = absint($cat_id); |
|
2545 | - wp_delete_term($cat_id, 'espresso_event_categories'); |
|
2546 | - } |
|
2547 | - |
|
2548 | - |
|
2549 | - |
|
2550 | - /** |
|
2551 | - * @param $new_category |
|
2552 | - */ |
|
2553 | - protected function _insert_or_update_category($new_category) |
|
2554 | - { |
|
2555 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2556 | - $success = 0; //we already have a success message so lets not send another. |
|
2557 | - if ($cat_id) { |
|
2558 | - $query_args = array( |
|
2559 | - 'action' => 'edit_category', |
|
2560 | - 'EVT_CAT_ID' => $cat_id, |
|
2561 | - ); |
|
2562 | - } else { |
|
2563 | - $query_args = array('action' => 'add_category'); |
|
2564 | - } |
|
2565 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2566 | - } |
|
2567 | - |
|
2568 | - |
|
2569 | - |
|
2570 | - /** |
|
2571 | - * @param bool $update |
|
2572 | - * @return bool|mixed|string |
|
2573 | - */ |
|
2574 | - private function _insert_category($update = false) |
|
2575 | - { |
|
2576 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2577 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2578 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2579 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2580 | - if (empty($category_name)) { |
|
2581 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2582 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2583 | - return false; |
|
2584 | - } |
|
2585 | - $term_args = array( |
|
2586 | - 'name' => $category_name, |
|
2587 | - 'description' => $category_desc, |
|
2588 | - 'parent' => $category_parent, |
|
2589 | - ); |
|
2590 | - //was the category_identifier input disabled? |
|
2591 | - if (isset($this->_req_data['category_identifier'])) { |
|
2592 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2593 | - } |
|
2594 | - $insert_ids = $update |
|
2595 | - ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
2596 | - : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
2597 | - if ( ! is_array($insert_ids)) { |
|
2598 | - $msg = esc_html__( |
|
2599 | - 'An error occurred and the category has not been saved to the database.', |
|
2600 | - 'event_espresso' |
|
2601 | - ); |
|
2602 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2603 | - } else { |
|
2604 | - $cat_id = $insert_ids['term_id']; |
|
2605 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2606 | - EE_Error::add_success($msg); |
|
2607 | - } |
|
2608 | - return $cat_id; |
|
2609 | - } |
|
2610 | - |
|
2611 | - |
|
2612 | - |
|
2613 | - /** |
|
2614 | - * @param int $per_page |
|
2615 | - * @param int $current_page |
|
2616 | - * @param bool $count |
|
2617 | - * @return \EE_Base_Class[]|int |
|
2618 | - */ |
|
2619 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2620 | - { |
|
2621 | - //testing term stuff |
|
2622 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2623 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2624 | - $limit = ($current_page - 1) * $per_page; |
|
2625 | - $where = array('taxonomy' => 'espresso_event_categories'); |
|
2626 | - if (isset($this->_req_data['s'])) { |
|
2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2628 | - $where['OR'] = array( |
|
2629 | - 'Term.name' => array('LIKE', $sstr), |
|
2630 | - 'description' => array('LIKE', $sstr), |
|
2631 | - ); |
|
2632 | - } |
|
2633 | - $query_params = array( |
|
2634 | - $where, |
|
2635 | - 'order_by' => array($orderby => $order), |
|
2636 | - 'limit' => $limit . ',' . $per_page, |
|
2637 | - 'force_join' => array('Term'), |
|
2638 | - ); |
|
2639 | - $categories = $count |
|
2640 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2641 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2642 | - return $categories; |
|
2643 | - } |
|
2644 | - |
|
2645 | - |
|
2646 | - |
|
2647 | - /* end category stuff */ |
|
2648 | - /**************/ |
|
385 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
386 | + 'require_nonce' => false, |
|
387 | + ), |
|
388 | + 'default_event_settings' => array( |
|
389 | + 'nav' => array( |
|
390 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
391 | + 'order' => 40, |
|
392 | + ), |
|
393 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
394 | + 'labels' => array( |
|
395 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
396 | + ), |
|
397 | + 'help_tabs' => array( |
|
398 | + 'default_settings_help_tab' => array( |
|
399 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
400 | + 'filename' => 'events_default_settings', |
|
401 | + ), |
|
402 | + 'default_settings_status_help_tab' => array( |
|
403 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
404 | + 'filename' => 'events_default_settings_status', |
|
405 | + ), |
|
406 | + 'default_maximum_tickets_help_tab' => array( |
|
407 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
408 | + 'filename' => 'events_default_settings_max_tickets', |
|
409 | + ) |
|
410 | + ), |
|
411 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
412 | + 'require_nonce' => false, |
|
413 | + ), |
|
414 | + //template settings |
|
415 | + 'template_settings' => array( |
|
416 | + 'nav' => array( |
|
417 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
418 | + 'order' => 30, |
|
419 | + ), |
|
420 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
421 | + 'help_tabs' => array( |
|
422 | + 'general_settings_templates_help_tab' => array( |
|
423 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
424 | + 'filename' => 'general_settings_templates', |
|
425 | + ), |
|
426 | + ), |
|
427 | + 'help_tour' => array('Templates_Help_Tour'), |
|
428 | + 'require_nonce' => false, |
|
429 | + ), |
|
430 | + //event category stuff |
|
431 | + 'add_category' => array( |
|
432 | + 'nav' => array( |
|
433 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
434 | + 'order' => 15, |
|
435 | + 'persistent' => false, |
|
436 | + ), |
|
437 | + 'help_tabs' => array( |
|
438 | + 'add_category_help_tab' => array( |
|
439 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
440 | + 'filename' => 'events_add_category', |
|
441 | + ), |
|
442 | + ), |
|
443 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
444 | + 'metaboxes' => array('_publish_post_box'), |
|
445 | + 'require_nonce' => false, |
|
446 | + ), |
|
447 | + 'edit_category' => array( |
|
448 | + 'nav' => array( |
|
449 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
450 | + 'order' => 15, |
|
451 | + 'persistent' => false, |
|
452 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
453 | + ? add_query_arg( |
|
454 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
455 | + $this->_current_page_view_url |
|
456 | + ) |
|
457 | + : $this->_admin_base_url, |
|
458 | + ), |
|
459 | + 'help_tabs' => array( |
|
460 | + 'edit_category_help_tab' => array( |
|
461 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
462 | + 'filename' => 'events_edit_category', |
|
463 | + ), |
|
464 | + ), |
|
465 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
466 | + 'metaboxes' => array('_publish_post_box'), |
|
467 | + 'require_nonce' => false, |
|
468 | + ), |
|
469 | + 'category_list' => array( |
|
470 | + 'nav' => array( |
|
471 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
472 | + 'order' => 20, |
|
473 | + ), |
|
474 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
475 | + 'help_tabs' => array( |
|
476 | + 'events_categories_help_tab' => array( |
|
477 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
478 | + 'filename' => 'events_categories', |
|
479 | + ), |
|
480 | + 'events_categories_table_column_headings_help_tab' => array( |
|
481 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
482 | + 'filename' => 'events_categories_table_column_headings', |
|
483 | + ), |
|
484 | + 'events_categories_view_help_tab' => array( |
|
485 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
486 | + 'filename' => 'events_categories_views', |
|
487 | + ), |
|
488 | + 'events_categories_other_help_tab' => array( |
|
489 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
490 | + 'filename' => 'events_categories_other', |
|
491 | + ), |
|
492 | + ), |
|
493 | + 'help_tour' => array( |
|
494 | + 'Event_Categories_Help_Tour', |
|
495 | + ), |
|
496 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
497 | + 'require_nonce' => false, |
|
498 | + ), |
|
499 | + ); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + protected function _add_screen_options() |
|
505 | + { |
|
506 | + //todo |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + protected function _add_screen_options_default() |
|
512 | + { |
|
513 | + $this->_per_page_screen_option(); |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + |
|
518 | + protected function _add_screen_options_category_list() |
|
519 | + { |
|
520 | + $page_title = $this->_admin_page_title; |
|
521 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
522 | + $this->_per_page_screen_option(); |
|
523 | + $this->_admin_page_title = $page_title; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + protected function _add_feature_pointers() |
|
529 | + { |
|
530 | + //todo |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + |
|
535 | + public function load_scripts_styles() |
|
536 | + { |
|
537 | + wp_register_style( |
|
538 | + 'events-admin-css', |
|
539 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
540 | + array(), |
|
541 | + EVENT_ESPRESSO_VERSION |
|
542 | + ); |
|
543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
544 | + wp_enqueue_style('events-admin-css'); |
|
545 | + wp_enqueue_style('ee-cat-admin'); |
|
546 | + //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
547 | + //registers for all views |
|
548 | + //scripts |
|
549 | + wp_register_script( |
|
550 | + 'event_editor_js', |
|
551 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
552 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
553 | + EVENT_ESPRESSO_VERSION, |
|
554 | + true |
|
555 | + ); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * enqueuing scripts and styles specific to this view |
|
562 | + * |
|
563 | + * @return void |
|
564 | + */ |
|
565 | + public function load_scripts_styles_create_new() |
|
566 | + { |
|
567 | + $this->load_scripts_styles_edit(); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * enqueuing scripts and styles specific to this view |
|
574 | + * |
|
575 | + * @return void |
|
576 | + */ |
|
577 | + public function load_scripts_styles_edit() |
|
578 | + { |
|
579 | + //styles |
|
580 | + wp_enqueue_style('espresso-ui-theme'); |
|
581 | + wp_register_style( |
|
582 | + 'event-editor-css', |
|
583 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
584 | + array('ee-admin-css'), |
|
585 | + EVENT_ESPRESSO_VERSION |
|
586 | + ); |
|
587 | + wp_enqueue_style('event-editor-css'); |
|
588 | + //scripts |
|
589 | + wp_register_script( |
|
590 | + 'event-datetime-metabox', |
|
591 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
592 | + array('event_editor_js', 'ee-datepicker'), |
|
593 | + EVENT_ESPRESSO_VERSION |
|
594 | + ); |
|
595 | + wp_enqueue_script('event-datetime-metabox'); |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + |
|
600 | + public function load_scripts_styles_add_category() |
|
601 | + { |
|
602 | + $this->load_scripts_styles_edit_category(); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + public function load_scripts_styles_edit_category() |
|
608 | + { |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + protected function _set_list_table_views_category_list() |
|
614 | + { |
|
615 | + $this->_views = array( |
|
616 | + 'all' => array( |
|
617 | + 'slug' => 'all', |
|
618 | + 'label' => esc_html__('All', 'event_espresso'), |
|
619 | + 'count' => 0, |
|
620 | + 'bulk_action' => array( |
|
621 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
622 | + ), |
|
623 | + ), |
|
624 | + ); |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + public function admin_init() |
|
630 | + { |
|
631 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
632 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
633 | + 'event_espresso' |
|
634 | + ); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + //nothing needed for events with these methods. |
|
640 | + public function admin_notices() |
|
641 | + { |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + |
|
646 | + public function admin_footer_scripts() |
|
647 | + { |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
654 | + * warning (via EE_Error::add_error()); |
|
655 | + * |
|
656 | + * @param EE_Event $event Event object |
|
657 | + * @access public |
|
658 | + * @return void |
|
659 | + */ |
|
660 | + public function verify_event_edit($event = null) |
|
661 | + { |
|
662 | + // no event? |
|
663 | + if (empty($event)) { |
|
664 | + // set event |
|
665 | + $event = $this->_cpt_model_obj; |
|
666 | + } |
|
667 | + // STILL no event? |
|
668 | + if (empty ($event)) { |
|
669 | + return; |
|
670 | + } |
|
671 | + $orig_status = $event->status(); |
|
672 | + // first check if event is active. |
|
673 | + if ( |
|
674 | + $orig_status === EEM_Event::cancelled |
|
675 | + || $orig_status === EEM_Event::postponed |
|
676 | + || $event->is_expired() |
|
677 | + || $event->is_inactive() |
|
678 | + ) { |
|
679 | + return; |
|
680 | + } |
|
681 | + //made it here so it IS active... next check that any of the tickets are sold. |
|
682 | + if ($event->is_sold_out(true)) { |
|
683 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
684 | + EE_Error::add_attention( |
|
685 | + sprintf( |
|
686 | + esc_html__( |
|
687 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
688 | + 'event_espresso' |
|
689 | + ), |
|
690 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
691 | + ) |
|
692 | + ); |
|
693 | + } |
|
694 | + return; |
|
695 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
696 | + EE_Error::add_attention( |
|
697 | + sprintf( |
|
698 | + esc_html__( |
|
699 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
700 | + 'event_espresso' |
|
701 | + ), |
|
702 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
703 | + ) |
|
704 | + ); |
|
705 | + } |
|
706 | + //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
707 | + if ( ! $event->tickets_on_sale()) { |
|
708 | + return; |
|
709 | + } |
|
710 | + //made it here so show warning |
|
711 | + $this->_edit_event_warning(); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
718 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
719 | + * |
|
720 | + * @access protected |
|
721 | + * @return void |
|
722 | + */ |
|
723 | + protected function _edit_event_warning() |
|
724 | + { |
|
725 | + // we don't want to add warnings during these requests |
|
726 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
727 | + return; |
|
728 | + } |
|
729 | + EE_Error::add_attention( |
|
730 | + esc_html__( |
|
731 | + 'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.', |
|
732 | + 'event_espresso' |
|
733 | + ) |
|
734 | + ); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
741 | + * Otherwise, do the normal logic |
|
742 | + * |
|
743 | + * @return string |
|
744 | + * @throws \EE_Error |
|
745 | + */ |
|
746 | + protected function _create_new_cpt_item() |
|
747 | + { |
|
748 | + $gmt_offset = get_option('gmt_offset'); |
|
749 | + //only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
750 | + if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) { |
|
751 | + EE_Error::add_attention( |
|
752 | + sprintf( |
|
753 | + __( |
|
754 | + 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
|
755 | + 'event_espresso' |
|
756 | + ), |
|
757 | + '<a href="' . admin_url('options-general.php') . '">', |
|
758 | + '</a>' |
|
759 | + ), |
|
760 | + __FILE__, |
|
761 | + __FUNCTION__, |
|
762 | + __LINE__ |
|
763 | + ); |
|
764 | + } |
|
765 | + return parent::_create_new_cpt_item(); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + |
|
770 | + protected function _set_list_table_views_default() |
|
771 | + { |
|
772 | + $this->_views = array( |
|
773 | + 'all' => array( |
|
774 | + 'slug' => 'all', |
|
775 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
776 | + 'count' => 0, |
|
777 | + 'bulk_action' => array( |
|
778 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
779 | + ), |
|
780 | + ), |
|
781 | + 'draft' => array( |
|
782 | + 'slug' => 'draft', |
|
783 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
784 | + 'count' => 0, |
|
785 | + 'bulk_action' => array( |
|
786 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
787 | + ), |
|
788 | + ), |
|
789 | + ); |
|
790 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
791 | + $this->_views['trash'] = array( |
|
792 | + 'slug' => 'trash', |
|
793 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
794 | + 'count' => 0, |
|
795 | + 'bulk_action' => array( |
|
796 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
797 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
798 | + ), |
|
799 | + ); |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * @return array |
|
807 | + */ |
|
808 | + protected function _event_legend_items() |
|
809 | + { |
|
810 | + $items = array( |
|
811 | + 'view_details' => array( |
|
812 | + 'class' => 'dashicons dashicons-search', |
|
813 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
814 | + ), |
|
815 | + 'edit_event' => array( |
|
816 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
817 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
818 | + ), |
|
819 | + 'view_attendees' => array( |
|
820 | + 'class' => 'dashicons dashicons-groups', |
|
821 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
822 | + ), |
|
823 | + ); |
|
824 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
825 | + $statuses = array( |
|
826 | + 'sold_out_status' => array( |
|
827 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
828 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
829 | + ), |
|
830 | + 'active_status' => array( |
|
831 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
832 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
833 | + ), |
|
834 | + 'upcoming_status' => array( |
|
835 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
836 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
837 | + ), |
|
838 | + 'postponed_status' => array( |
|
839 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
840 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
841 | + ), |
|
842 | + 'cancelled_status' => array( |
|
843 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
844 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
845 | + ), |
|
846 | + 'expired_status' => array( |
|
847 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
848 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
849 | + ), |
|
850 | + 'inactive_status' => array( |
|
851 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
852 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
853 | + ), |
|
854 | + ); |
|
855 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
856 | + return array_merge($items, $statuses); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * _event_model |
|
863 | + * |
|
864 | + * @return EEM_Event |
|
865 | + */ |
|
866 | + private function _event_model() |
|
867 | + { |
|
868 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
869 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
870 | + } |
|
871 | + return $this->_event_model; |
|
872 | + } |
|
873 | + |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * Adds extra buttons to the WP CPT permalink field row. |
|
878 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
879 | + * |
|
880 | + * @param string $return the current html |
|
881 | + * @param int $id the post id for the page |
|
882 | + * @param string $new_title What the title is |
|
883 | + * @param string $new_slug what the slug is |
|
884 | + * @return string The new html string for the permalink area |
|
885 | + */ |
|
886 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
887 | + { |
|
888 | + //make sure this is only when editing |
|
889 | + if ( ! empty($id)) { |
|
890 | + $post = get_post($id); |
|
891 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
892 | + . esc_html__('Shortcode', 'event_espresso') |
|
893 | + . '</a> '; |
|
894 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
895 | + . $post->ID |
|
896 | + . ']">'; |
|
897 | + } |
|
898 | + return $return; |
|
899 | + } |
|
900 | + |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * _events_overview_list_table |
|
905 | + * This contains the logic for showing the events_overview list |
|
906 | + * |
|
907 | + * @access protected |
|
908 | + * @return void |
|
909 | + * @throws \EE_Error |
|
910 | + */ |
|
911 | + protected function _events_overview_list_table() |
|
912 | + { |
|
913 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
914 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
915 | + ? (array)$this->_template_args['after_list_table'] |
|
916 | + : array(); |
|
917 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
918 | + . EEH_Template::get_button_or_link( |
|
919 | + get_post_type_archive_link('espresso_events'), |
|
920 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
921 | + 'button' |
|
922 | + ); |
|
923 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
924 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
925 | + 'create_new', |
|
926 | + 'add', |
|
927 | + array(), |
|
928 | + 'add-new-h2' |
|
929 | + ); |
|
930 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * this allows for extra misc actions in the default WP publish box |
|
937 | + * |
|
938 | + * @return void |
|
939 | + */ |
|
940 | + public function extra_misc_actions_publish_box() |
|
941 | + { |
|
942 | + $this->_generate_publish_box_extra_content(); |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
949 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
950 | + * data. |
|
951 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
952 | + * ALSO very important. When a post transitions from scheduled to published, the save_post action is fired but you |
|
953 | + * will NOT have any _POST data containing any extra info you may have from other meta saves. So MAKE sure that |
|
954 | + * you handle this accordingly. |
|
955 | + * |
|
956 | + * @access protected |
|
957 | + * @abstract |
|
958 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
959 | + * @param object $post The post object of the cpt that was saved. |
|
960 | + * @return void |
|
961 | + */ |
|
962 | + protected function _insert_update_cpt_item($post_id, $post) |
|
963 | + { |
|
964 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
965 | + //get out we're not processing an event save. |
|
966 | + return; |
|
967 | + } |
|
968 | + $event_values = array( |
|
969 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
970 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
971 | + 'EVT_additional_limit' => min( |
|
972 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
973 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
974 | + ), |
|
975 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
976 | + ? $this->_req_data['EVT_default_registration_status'] |
|
977 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
978 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
979 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
980 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
981 | + ? $this->_req_data['timezone_string'] : null, |
|
982 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
983 | + ? $this->_req_data['externalURL'] : null, |
|
984 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
985 | + ? $this->_req_data['event_phone'] : null, |
|
986 | + ); |
|
987 | + //update event |
|
988 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
989 | + //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
990 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
991 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
992 | + //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
993 | + $event_update_callbacks = apply_filters( |
|
994 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
995 | + array(array($this, '_default_venue_update'), array($this, '_default_tickets_update')) |
|
996 | + ); |
|
997 | + $att_success = true; |
|
998 | + foreach ($event_update_callbacks as $e_callback) { |
|
999 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
1000 | + $att_success = ! $att_success ? $att_success |
|
1001 | + : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
1002 | + } |
|
1003 | + //any errors? |
|
1004 | + if ($success && false === $att_success) { |
|
1005 | + EE_Error::add_error( |
|
1006 | + esc_html__( |
|
1007 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1008 | + 'event_espresso' |
|
1009 | + ), |
|
1010 | + __FILE__, |
|
1011 | + __FUNCTION__, |
|
1012 | + __LINE__ |
|
1013 | + ); |
|
1014 | + } else if ($success === false) { |
|
1015 | + EE_Error::add_error( |
|
1016 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1017 | + __FILE__, |
|
1018 | + __FUNCTION__, |
|
1019 | + __LINE__ |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * @see parent::restore_item() |
|
1028 | + * @param int $post_id |
|
1029 | + * @param int $revision_id |
|
1030 | + */ |
|
1031 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
1032 | + { |
|
1033 | + //copy existing event meta to new post |
|
1034 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1035 | + if ($post_evt instanceof EE_Event) { |
|
1036 | + //meta revision restore |
|
1037 | + $post_evt->restore_revision($revision_id); |
|
1038 | + //related objs restore |
|
1039 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + |
|
1043 | + |
|
1044 | + |
|
1045 | + /** |
|
1046 | + * Attach the venue to the Event |
|
1047 | + * |
|
1048 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
1049 | + * @param array $data The request data from the form |
|
1050 | + * @return bool Success or fail. |
|
1051 | + */ |
|
1052 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
1053 | + { |
|
1054 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1055 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1056 | + $rows_affected = null; |
|
1057 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1058 | + // very important. If we don't have a venue name... |
|
1059 | + // then we'll get out because not necessary to create empty venue |
|
1060 | + if (empty($data['venue_title'])) { |
|
1061 | + return false; |
|
1062 | + } |
|
1063 | + $venue_array = array( |
|
1064 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1065 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1066 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1067 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1068 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1069 | + : null, |
|
1070 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1071 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1072 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1073 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1074 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1075 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1076 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1077 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1078 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1079 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1080 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1081 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1082 | + 'status' => 'publish', |
|
1083 | + ); |
|
1084 | + //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1085 | + if ( ! empty($venue_id)) { |
|
1086 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1087 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1088 | + //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1089 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1090 | + return $rows_affected > 0 ? true : false; |
|
1091 | + } else { |
|
1092 | + //we insert the venue |
|
1093 | + $venue_id = $venue_model->insert($venue_array); |
|
1094 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1095 | + return ! empty($venue_id) ? true : false; |
|
1096 | + } |
|
1097 | + //when we have the ancestor come in it's already been handled by the revision save. |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1104 | + * |
|
1105 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
1106 | + * @param array $data The request data from the form |
|
1107 | + * @return array |
|
1108 | + */ |
|
1109 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1110 | + { |
|
1111 | + $success = true; |
|
1112 | + $saved_dtt = null; |
|
1113 | + $saved_tickets = array(); |
|
1114 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1115 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1116 | + //trim all values to ensure any excess whitespace is removed. |
|
1117 | + $dtt = array_map('trim', $dtt); |
|
1118 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1119 | + : $dtt['DTT_EVT_start']; |
|
1120 | + $datetime_values = array( |
|
1121 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1122 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1123 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1124 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1125 | + 'DTT_order' => $row, |
|
1126 | + ); |
|
1127 | + //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
1128 | + if ( ! empty($dtt['DTT_ID'])) { |
|
1129 | + $DTM = EE_Registry::instance() |
|
1130 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1131 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
1132 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
1133 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
1134 | + foreach ($datetime_values as $field => $value) { |
|
1135 | + $DTM->set($field, $value); |
|
1136 | + } |
|
1137 | + //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
1138 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
1139 | + } else { |
|
1140 | + $DTM = EE_Registry::instance()->load_class( |
|
1141 | + 'Datetime', |
|
1142 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1143 | + false, |
|
1144 | + false |
|
1145 | + ); |
|
1146 | + foreach ($datetime_values as $field => $value) { |
|
1147 | + $DTM->set($field, $value); |
|
1148 | + } |
|
1149 | + } |
|
1150 | + $DTM->save(); |
|
1151 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1152 | + //load DTT helper |
|
1153 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1154 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1155 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1156 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1157 | + $DTT->save(); |
|
1158 | + } |
|
1159 | + //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
1160 | + $saved_dtt = $DTT; |
|
1161 | + $success = ! $success ? $success : $DTT; |
|
1162 | + //if ANY of these updates fail then we want the appropriate global error message. |
|
1163 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1164 | + } |
|
1165 | + //no dtts get deleted so we don't do any of that logic here. |
|
1166 | + //update tickets next |
|
1167 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1168 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1169 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1170 | + $update_prices = false; |
|
1171 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
1172 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1173 | + // trim inputs to ensure any excess whitespace is removed. |
|
1174 | + $tkt = array_map('trim', $tkt); |
|
1175 | + if (empty($tkt['TKT_start_date'])) { |
|
1176 | + //let's use now in the set timezone. |
|
1177 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1179 | + } |
|
1180 | + if (empty($tkt['TKT_end_date'])) { |
|
1181 | + //use the start date of the first datetime |
|
1182 | + $dtt = $evtobj->first_datetime(); |
|
1183 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1184 | + $incoming_date_formats[0], |
|
1185 | + $incoming_date_formats[1] |
|
1186 | + ); |
|
1187 | + } |
|
1188 | + $TKT_values = array( |
|
1189 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1190 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1191 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1192 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1193 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1194 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1195 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1196 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1197 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1198 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1199 | + 'TKT_row' => $row, |
|
1200 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1201 | + 'TKT_price' => $ticket_price, |
|
1202 | + ); |
|
1203 | + //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
1204 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1205 | + $TKT_values['TKT_ID'] = 0; |
|
1206 | + $TKT_values['TKT_is_default'] = 0; |
|
1207 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1208 | + $update_prices = true; |
|
1209 | + } |
|
1210 | + //if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1211 | + //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
1212 | + //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1213 | + if ( ! empty($tkt['TKT_ID'])) { |
|
1214 | + $TKT = EE_Registry::instance() |
|
1215 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1216 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
1217 | + if ($TKT instanceof EE_Ticket) { |
|
1218 | + $ticket_sold = $TKT->count_related( |
|
1219 | + 'Registration', |
|
1220 | + array( |
|
1221 | + array( |
|
1222 | + 'STS_ID' => array( |
|
1223 | + 'NOT IN', |
|
1224 | + array(EEM_Registration::status_id_incomplete), |
|
1225 | + ), |
|
1226 | + ), |
|
1227 | + ) |
|
1228 | + ) > 0 ? true : false; |
|
1229 | + //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
|
1230 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
1231 | + && ! $TKT->get( |
|
1232 | + 'TKT_deleted' |
|
1233 | + ) ? true : false; |
|
1234 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1235 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1236 | + //set new values |
|
1237 | + foreach ($TKT_values as $field => $value) { |
|
1238 | + if ($field == 'TKT_qty') { |
|
1239 | + $TKT->set_qty($value); |
|
1240 | + } else { |
|
1241 | + $TKT->set($field, $value); |
|
1242 | + } |
|
1243 | + } |
|
1244 | + //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1245 | + if ($create_new_TKT) { |
|
1246 | + //archive the old ticket first |
|
1247 | + $TKT->set('TKT_deleted', 1); |
|
1248 | + $TKT->save(); |
|
1249 | + //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1250 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1251 | + //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
1252 | + $TKT = clone $TKT; |
|
1253 | + $TKT->set('TKT_ID', 0); |
|
1254 | + $TKT->set('TKT_deleted', 0); |
|
1255 | + $TKT->set('TKT_price', $ticket_price); |
|
1256 | + $TKT->set('TKT_sold', 0); |
|
1257 | + //now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1258 | + $update_prices = true; |
|
1259 | + } |
|
1260 | + //make sure price is set if it hasn't been already |
|
1261 | + $TKT->set('TKT_price', $ticket_price); |
|
1262 | + } |
|
1263 | + } else { |
|
1264 | + //no TKT_id so a new TKT |
|
1265 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1266 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1267 | + if ($TKT instanceof EE_Ticket) { |
|
1268 | + //need to reset values to properly account for the date formats |
|
1269 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1270 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1271 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
1272 | + //set new values |
|
1273 | + foreach ($TKT_values as $field => $value) { |
|
1274 | + if ($field == 'TKT_qty') { |
|
1275 | + $TKT->set_qty($value); |
|
1276 | + } else { |
|
1277 | + $TKT->set($field, $value); |
|
1278 | + } |
|
1279 | + } |
|
1280 | + $update_prices = true; |
|
1281 | + } |
|
1282 | + } |
|
1283 | + // cap ticket qty by datetime reg limits |
|
1284 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1285 | + //update ticket. |
|
1286 | + $TKT->save(); |
|
1287 | + //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1288 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1289 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1290 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1291 | + $TKT->save(); |
|
1292 | + } |
|
1293 | + //initially let's add the ticket to the dtt |
|
1294 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1295 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1296 | + //add prices to ticket |
|
1297 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
1298 | + } |
|
1299 | + //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
1300 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1301 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1302 | + foreach ($tickets_removed as $id) { |
|
1303 | + $id = absint($id); |
|
1304 | + //get the ticket for this id |
|
1305 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1306 | + //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
1307 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1308 | + foreach ($dtts as $dtt) { |
|
1309 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1310 | + } |
|
1311 | + //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1312 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
1313 | + //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1314 | + $tkt_to_remove->delete_permanently(); |
|
1315 | + } |
|
1316 | + return array($saved_dtt, $saved_tickets); |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * This attaches a list of given prices to a ticket. |
|
1323 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1324 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1325 | + * price info and prices are automatically "archived" via the ticket. |
|
1326 | + * |
|
1327 | + * @access private |
|
1328 | + * @param array $prices Array of prices from the form. |
|
1329 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1330 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1331 | + * @return void |
|
1332 | + */ |
|
1333 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1334 | + { |
|
1335 | + foreach ($prices as $row => $prc) { |
|
1336 | + $PRC_values = array( |
|
1337 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1338 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1339 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1340 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1341 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1342 | + 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
|
1343 | + 'PRC_order' => $row, |
|
1344 | + ); |
|
1345 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1346 | + $PRC_values['PRC_ID'] = 0; |
|
1347 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1348 | + } else { |
|
1349 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1350 | + //update this price with new values |
|
1351 | + foreach ($PRC_values as $field => $newprc) { |
|
1352 | + $PRC->set($field, $newprc); |
|
1353 | + } |
|
1354 | + $PRC->save(); |
|
1355 | + } |
|
1356 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
1357 | + } |
|
1358 | + } |
|
1359 | + |
|
1360 | + |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Add in our autosave ajax handlers |
|
1364 | + * |
|
1365 | + * @return void |
|
1366 | + */ |
|
1367 | + protected function _ee_autosave_create_new() |
|
1368 | + { |
|
1369 | + // $this->_ee_autosave_edit(); |
|
1370 | + } |
|
1371 | + |
|
1372 | + |
|
1373 | + |
|
1374 | + protected function _ee_autosave_edit() |
|
1375 | + { |
|
1376 | + return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1377 | + } |
|
1378 | + |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * _generate_publish_box_extra_content |
|
1383 | + * |
|
1384 | + * @access private |
|
1385 | + * @return void |
|
1386 | + */ |
|
1387 | + private function _generate_publish_box_extra_content() |
|
1388 | + { |
|
1389 | + //load formatter helper |
|
1390 | + //args for getting related registrations |
|
1391 | + $approved_query_args = array( |
|
1392 | + array( |
|
1393 | + 'REG_deleted' => 0, |
|
1394 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1395 | + ), |
|
1396 | + ); |
|
1397 | + $not_approved_query_args = array( |
|
1398 | + array( |
|
1399 | + 'REG_deleted' => 0, |
|
1400 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1401 | + ), |
|
1402 | + ); |
|
1403 | + $pending_payment_query_args = array( |
|
1404 | + array( |
|
1405 | + 'REG_deleted' => 0, |
|
1406 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1407 | + ), |
|
1408 | + ); |
|
1409 | + // publish box |
|
1410 | + $publish_box_extra_args = array( |
|
1411 | + 'view_approved_reg_url' => add_query_arg( |
|
1412 | + array( |
|
1413 | + 'action' => 'default', |
|
1414 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1415 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1416 | + ), |
|
1417 | + REG_ADMIN_URL |
|
1418 | + ), |
|
1419 | + 'view_not_approved_reg_url' => add_query_arg( |
|
1420 | + array( |
|
1421 | + 'action' => 'default', |
|
1422 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1423 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1424 | + ), |
|
1425 | + REG_ADMIN_URL |
|
1426 | + ), |
|
1427 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
1428 | + array( |
|
1429 | + 'action' => 'default', |
|
1430 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1431 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1432 | + ), |
|
1433 | + REG_ADMIN_URL |
|
1434 | + ), |
|
1435 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1436 | + 'Registration', |
|
1437 | + $approved_query_args |
|
1438 | + ), |
|
1439 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1440 | + 'Registration', |
|
1441 | + $not_approved_query_args |
|
1442 | + ), |
|
1443 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1444 | + 'Registration', |
|
1445 | + $pending_payment_query_args |
|
1446 | + ), |
|
1447 | + 'misc_pub_section_class' => apply_filters( |
|
1448 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1449 | + 'misc-pub-section' |
|
1450 | + ), |
|
1451 | + //'email_attendees_url' => add_query_arg( |
|
1452 | + // array( |
|
1453 | + // 'event_admin_reports' => 'event_newsletter', |
|
1454 | + // 'event_id' => $this->_cpt_model_obj->id |
|
1455 | + // ), |
|
1456 | + // 'admin.php?page=espresso_registrations' |
|
1457 | + //), |
|
1458 | + ); |
|
1459 | + ob_start(); |
|
1460 | + do_action( |
|
1461 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1462 | + $this->_cpt_model_obj |
|
1463 | + ); |
|
1464 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1465 | + // load template |
|
1466 | + EEH_Template::display_template( |
|
1467 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1468 | + $publish_box_extra_args |
|
1469 | + ); |
|
1470 | + } |
|
1471 | + |
|
1472 | + |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * This just returns whatever is set as the _event object property |
|
1476 | + * //todo this will become obsolete once the models are in place |
|
1477 | + * |
|
1478 | + * @return object |
|
1479 | + */ |
|
1480 | + public function get_event_object() |
|
1481 | + { |
|
1482 | + return $this->_cpt_model_obj; |
|
1483 | + } |
|
1484 | + |
|
1485 | + |
|
1486 | + |
|
1487 | + |
|
1488 | + /** METABOXES * */ |
|
1489 | + /** |
|
1490 | + * _register_event_editor_meta_boxes |
|
1491 | + * add all metaboxes related to the event_editor |
|
1492 | + * |
|
1493 | + * @return void |
|
1494 | + */ |
|
1495 | + protected function _register_event_editor_meta_boxes() |
|
1496 | + { |
|
1497 | + $this->verify_cpt_object(); |
|
1498 | + add_meta_box( |
|
1499 | + 'espresso_event_editor_tickets', |
|
1500 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1501 | + array($this, 'ticket_metabox'), |
|
1502 | + $this->page_slug, |
|
1503 | + 'normal', |
|
1504 | + 'high' |
|
1505 | + ); |
|
1506 | + add_meta_box( |
|
1507 | + 'espresso_event_editor_event_options', |
|
1508 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
1509 | + array($this, 'registration_options_meta_box'), |
|
1510 | + $this->page_slug, |
|
1511 | + 'side', |
|
1512 | + 'default' |
|
1513 | + ); |
|
1514 | + // NOTE: if you're looking for other metaboxes in here, |
|
1515 | + // where a metabox has a related management page in the admin |
|
1516 | + // you will find it setup in the related management page's "_Hooks" file. |
|
1517 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1518 | + } |
|
1519 | + |
|
1520 | + |
|
1521 | + |
|
1522 | + public function ticket_metabox() |
|
1523 | + { |
|
1524 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1525 | + //defaults for template args |
|
1526 | + $template_args = array( |
|
1527 | + 'existing_datetime_ids' => '', |
|
1528 | + 'event_datetime_help_link' => '', |
|
1529 | + 'ticket_options_help_link' => '', |
|
1530 | + 'time' => null, |
|
1531 | + 'ticket_rows' => '', |
|
1532 | + 'existing_ticket_ids' => '', |
|
1533 | + 'total_ticket_rows' => 1, |
|
1534 | + 'ticket_js_structure' => '', |
|
1535 | + 'trash_icon' => 'ee-lock-icon', |
|
1536 | + 'disabled' => '', |
|
1537 | + ); |
|
1538 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1539 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1540 | + /** |
|
1541 | + * 1. Start with retrieving Datetimes |
|
1542 | + * 2. Fore each datetime get related tickets |
|
1543 | + * 3. For each ticket get related prices |
|
1544 | + */ |
|
1545 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1546 | + /** @type EE_Datetime $first_datetime */ |
|
1547 | + $first_datetime = reset($times); |
|
1548 | + //do we get related tickets? |
|
1549 | + if ($first_datetime instanceof EE_Datetime |
|
1550 | + && $first_datetime->ID() !== 0 |
|
1551 | + ) { |
|
1552 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1553 | + $template_args['time'] = $first_datetime; |
|
1554 | + $related_tickets = $first_datetime->tickets( |
|
1555 | + array( |
|
1556 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1557 | + 'default_where_conditions' => 'none', |
|
1558 | + ) |
|
1559 | + ); |
|
1560 | + if ( ! empty($related_tickets)) { |
|
1561 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
1562 | + $row = 0; |
|
1563 | + foreach ($related_tickets as $ticket) { |
|
1564 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1565 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1566 | + $row++; |
|
1567 | + } |
|
1568 | + } else { |
|
1569 | + $template_args['total_ticket_rows'] = 1; |
|
1570 | + /** @type EE_Ticket $ticket */ |
|
1571 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1572 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1573 | + } |
|
1574 | + } else { |
|
1575 | + $template_args['time'] = $times[0]; |
|
1576 | + /** @type EE_Ticket $ticket */ |
|
1577 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1578 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1579 | + // NOTE: we're just sending the first default row |
|
1580 | + // (decaf can't manage default tickets so this should be sufficient); |
|
1581 | + } |
|
1582 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1583 | + 'event_editor_event_datetimes_help_tab' |
|
1584 | + ); |
|
1585 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1586 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1587 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1588 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1589 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1590 | + true |
|
1591 | + ); |
|
1592 | + $template = apply_filters( |
|
1593 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1594 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1595 | + ); |
|
1596 | + EEH_Template::display_template($template, $template_args); |
|
1597 | + } |
|
1598 | + |
|
1599 | + |
|
1600 | + |
|
1601 | + /** |
|
1602 | + * Setup an individual ticket form for the decaf event editor page |
|
1603 | + * |
|
1604 | + * @access private |
|
1605 | + * @param EE_Ticket $ticket the ticket object |
|
1606 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1607 | + * @param int $row |
|
1608 | + * @return string generated html for the ticket row. |
|
1609 | + */ |
|
1610 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1611 | + { |
|
1612 | + $template_args = array( |
|
1613 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1614 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1615 | + : '', |
|
1616 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1617 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1618 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
1619 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1620 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1621 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1622 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1623 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1624 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1625 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1626 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1627 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1628 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1629 | + : ' disabled=disabled', |
|
1630 | + ); |
|
1631 | + $price = $ticket->ID() !== 0 |
|
1632 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1633 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1634 | + $price_args = array( |
|
1635 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1636 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
1637 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
1638 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
1639 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1640 | + ); |
|
1641 | + //make sure we have default start and end dates if skeleton |
|
1642 | + //handle rows that should NOT be empty |
|
1643 | + if (empty($template_args['TKT_start_date'])) { |
|
1644 | + //if empty then the start date will be now. |
|
1645 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1646 | + } |
|
1647 | + if (empty($template_args['TKT_end_date'])) { |
|
1648 | + //get the earliest datetime (if present); |
|
1649 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1650 | + ? $this->_cpt_model_obj->get_first_related( |
|
1651 | + 'Datetime', |
|
1652 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1653 | + ) |
|
1654 | + : null; |
|
1655 | + if ( ! empty($earliest_dtt)) { |
|
1656 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1657 | + } else { |
|
1658 | + $template_args['TKT_end_date'] = date( |
|
1659 | + 'Y-m-d h:i a', |
|
1660 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
1661 | + ); |
|
1662 | + } |
|
1663 | + } |
|
1664 | + $template_args = array_merge($template_args, $price_args); |
|
1665 | + $template = apply_filters( |
|
1666 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1667 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1668 | + $ticket |
|
1669 | + ); |
|
1670 | + return EEH_Template::display_template($template, $template_args, true); |
|
1671 | + } |
|
1672 | + |
|
1673 | + |
|
1674 | + |
|
1675 | + public function registration_options_meta_box() |
|
1676 | + { |
|
1677 | + $yes_no_values = array( |
|
1678 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1679 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1680 | + ); |
|
1681 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1682 | + array( |
|
1683 | + EEM_Registration::status_id_cancelled, |
|
1684 | + EEM_Registration::status_id_declined, |
|
1685 | + EEM_Registration::status_id_incomplete, |
|
1686 | + ), |
|
1687 | + true |
|
1688 | + ); |
|
1689 | + //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1690 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
1691 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1692 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1693 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1694 | + 'default_reg_status', |
|
1695 | + $default_reg_status_values, |
|
1696 | + $this->_cpt_model_obj->default_registration_status() |
|
1697 | + ); |
|
1698 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1699 | + 'display_desc', |
|
1700 | + $yes_no_values, |
|
1701 | + $this->_cpt_model_obj->display_description() |
|
1702 | + ); |
|
1703 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1704 | + 'display_ticket_selector', |
|
1705 | + $yes_no_values, |
|
1706 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
1707 | + '', |
|
1708 | + '', |
|
1709 | + false |
|
1710 | + ); |
|
1711 | + $template_args['additional_registration_options'] = apply_filters( |
|
1712 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1713 | + '', |
|
1714 | + $template_args, |
|
1715 | + $yes_no_values, |
|
1716 | + $default_reg_status_values |
|
1717 | + ); |
|
1718 | + EEH_Template::display_template( |
|
1719 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1720 | + $template_args |
|
1721 | + ); |
|
1722 | + } |
|
1723 | + |
|
1724 | + |
|
1725 | + |
|
1726 | + /** |
|
1727 | + * _get_events() |
|
1728 | + * This method simply returns all the events (for the given _view and paging) |
|
1729 | + * |
|
1730 | + * @access public |
|
1731 | + * @param int $per_page count of items per page (20 default); |
|
1732 | + * @param int $current_page what is the current page being viewed. |
|
1733 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1734 | + * If FALSE then we return an array of event objects |
|
1735 | + * that match the given _view and paging parameters. |
|
1736 | + * @return array an array of event objects. |
|
1737 | + */ |
|
1738 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1739 | + { |
|
1740 | + $EEME = $this->_event_model(); |
|
1741 | + $offset = ($current_page - 1) * $per_page; |
|
1742 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
1743 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1744 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
1745 | + if (isset($this->_req_data['month_range'])) { |
|
1746 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1747 | + //simulate the FIRST day of the month, that fixes issues for months like February |
|
1748 | + //where PHP doesn't know what to assume for date. |
|
1749 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1750 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1751 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1752 | + } |
|
1753 | + $where = array(); |
|
1754 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1755 | + //determine what post_status our condition will have for the query. |
|
1756 | + switch ($status) { |
|
1757 | + case 'month' : |
|
1758 | + case 'today' : |
|
1759 | + case null : |
|
1760 | + case 'all' : |
|
1761 | + break; |
|
1762 | + case 'draft' : |
|
1763 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1764 | + break; |
|
1765 | + default : |
|
1766 | + $where['status'] = $status; |
|
1767 | + } |
|
1768 | + //categories? |
|
1769 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1770 | + ? $this->_req_data['EVT_CAT'] : null; |
|
1771 | + if ( ! empty ($category)) { |
|
1772 | + $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1773 | + $where['Term_Taxonomy.term_id'] = $category; |
|
1774 | + } |
|
1775 | + //date where conditions |
|
1776 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1777 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
1778 | + $DateTime = new DateTime( |
|
1779 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
1780 | + new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
|
1781 | + ); |
|
1782 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
1783 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime |
|
1784 | + ->format('t'))->setTime(23, 59, 59) |
|
1785 | + ->format(implode(' ', $start_formats)); |
|
1786 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1787 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
1788 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1789 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1790 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1791 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1792 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1793 | + $now = date('Y-m-01'); |
|
1794 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1795 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1796 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1797 | + ->setTime(23, 59, 59) |
|
1798 | + ->format(implode(' ', $start_formats)); |
|
1799 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1800 | + } |
|
1801 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1802 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1803 | + } else { |
|
1804 | + if ( ! isset($where['status'])) { |
|
1805 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1806 | + $where['OR'] = array( |
|
1807 | + 'status*restrict_private' => array('!=', 'private'), |
|
1808 | + 'AND' => array( |
|
1809 | + 'status*inclusive' => array('=', 'private'), |
|
1810 | + 'EVT_wp_user' => get_current_user_id(), |
|
1811 | + ), |
|
1812 | + ); |
|
1813 | + } |
|
1814 | + } |
|
1815 | + } |
|
1816 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
1817 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
1818 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1819 | + ) { |
|
1820 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1821 | + } |
|
1822 | + } |
|
1823 | + //search query handling |
|
1824 | + if (isset($this->_req_data['s'])) { |
|
1825 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1826 | + $where['OR'] = array( |
|
1827 | + 'EVT_name' => array('LIKE', $search_string), |
|
1828 | + 'EVT_desc' => array('LIKE', $search_string), |
|
1829 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
1830 | + ); |
|
1831 | + } |
|
1832 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1833 | + $query_params = apply_filters( |
|
1834 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1835 | + array( |
|
1836 | + $where, |
|
1837 | + 'limit' => $limit, |
|
1838 | + 'order_by' => $orderby, |
|
1839 | + 'order' => $order, |
|
1840 | + 'group_by' => 'EVT_ID', |
|
1841 | + ), |
|
1842 | + $this->_req_data |
|
1843 | + ); |
|
1844 | + //let's first check if we have special requests coming in. |
|
1845 | + if (isset($this->_req_data['active_status'])) { |
|
1846 | + switch ($this->_req_data['active_status']) { |
|
1847 | + case 'upcoming' : |
|
1848 | + return $EEME->get_upcoming_events($query_params, $count); |
|
1849 | + break; |
|
1850 | + case 'expired' : |
|
1851 | + return $EEME->get_expired_events($query_params, $count); |
|
1852 | + break; |
|
1853 | + case 'active' : |
|
1854 | + return $EEME->get_active_events($query_params, $count); |
|
1855 | + break; |
|
1856 | + case 'inactive' : |
|
1857 | + return $EEME->get_inactive_events($query_params, $count); |
|
1858 | + break; |
|
1859 | + } |
|
1860 | + } |
|
1861 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1862 | + return $events; |
|
1863 | + } |
|
1864 | + |
|
1865 | + |
|
1866 | + |
|
1867 | + /** |
|
1868 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
1869 | + * |
|
1870 | + * @param string $post_id |
|
1871 | + */ |
|
1872 | + public function trash_cpt_item($post_id) |
|
1873 | + { |
|
1874 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1875 | + $this->_trash_or_restore_event('trash', false); |
|
1876 | + } |
|
1877 | + |
|
1878 | + |
|
1879 | + |
|
1880 | + /** |
|
1881 | + * @param string $post_id |
|
1882 | + */ |
|
1883 | + public function restore_cpt_item($post_id) |
|
1884 | + { |
|
1885 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1886 | + $this->_trash_or_restore_event('draft', false); |
|
1887 | + } |
|
1888 | + |
|
1889 | + |
|
1890 | + |
|
1891 | + /** |
|
1892 | + * @param string $post_id |
|
1893 | + */ |
|
1894 | + public function delete_cpt_item($post_id) |
|
1895 | + { |
|
1896 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1897 | + $this->_delete_event(false); |
|
1898 | + } |
|
1899 | + |
|
1900 | + |
|
1901 | + |
|
1902 | + /** |
|
1903 | + * _trash_or_restore_event |
|
1904 | + * |
|
1905 | + * @access protected |
|
1906 | + * @param string $event_status |
|
1907 | + * @param bool $redirect_after |
|
1908 | + */ |
|
1909 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
1910 | + { |
|
1911 | + //determine the event id and set to array. |
|
1912 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
1913 | + // loop thru events |
|
1914 | + if ($EVT_ID) { |
|
1915 | + // clean status |
|
1916 | + $event_status = sanitize_key($event_status); |
|
1917 | + // grab status |
|
1918 | + if ( ! empty($event_status)) { |
|
1919 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
1920 | + } else { |
|
1921 | + $success = false; |
|
1922 | + $msg = esc_html__( |
|
1923 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1924 | + 'event_espresso' |
|
1925 | + ); |
|
1926 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1927 | + } |
|
1928 | + } else { |
|
1929 | + $success = false; |
|
1930 | + $msg = esc_html__( |
|
1931 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
1932 | + 'event_espresso' |
|
1933 | + ); |
|
1934 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1935 | + } |
|
1936 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1937 | + if ($redirect_after) { |
|
1938 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
1939 | + } |
|
1940 | + } |
|
1941 | + |
|
1942 | + |
|
1943 | + |
|
1944 | + /** |
|
1945 | + * _trash_or_restore_events |
|
1946 | + * |
|
1947 | + * @access protected |
|
1948 | + * @param string $event_status |
|
1949 | + * @return void |
|
1950 | + */ |
|
1951 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
1952 | + { |
|
1953 | + // clean status |
|
1954 | + $event_status = sanitize_key($event_status); |
|
1955 | + // grab status |
|
1956 | + if ( ! empty($event_status)) { |
|
1957 | + $success = true; |
|
1958 | + //determine the event id and set to array. |
|
1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
1960 | + // loop thru events |
|
1961 | + foreach ($EVT_IDs as $EVT_ID) { |
|
1962 | + if ($EVT_ID = absint($EVT_ID)) { |
|
1963 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
1964 | + $success = $results !== false ? $success : false; |
|
1965 | + } else { |
|
1966 | + $msg = sprintf( |
|
1967 | + esc_html__( |
|
1968 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
1969 | + 'event_espresso' |
|
1970 | + ), |
|
1971 | + $EVT_ID |
|
1972 | + ); |
|
1973 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1974 | + $success = false; |
|
1975 | + } |
|
1976 | + } |
|
1977 | + } else { |
|
1978 | + $success = false; |
|
1979 | + $msg = esc_html__( |
|
1980 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1981 | + 'event_espresso' |
|
1982 | + ); |
|
1983 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1984 | + } |
|
1985 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
1986 | + $success = $success ? 2 : false; |
|
1987 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1988 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
1989 | + } |
|
1990 | + |
|
1991 | + |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * _trash_or_restore_events |
|
1995 | + * |
|
1996 | + * @access private |
|
1997 | + * @param int $EVT_ID |
|
1998 | + * @param string $event_status |
|
1999 | + * @return bool |
|
2000 | + */ |
|
2001 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2002 | + { |
|
2003 | + // grab event id |
|
2004 | + if ( ! $EVT_ID) { |
|
2005 | + $msg = esc_html__( |
|
2006 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2007 | + 'event_espresso' |
|
2008 | + ); |
|
2009 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2010 | + return false; |
|
2011 | + } |
|
2012 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2013 | + // clean status |
|
2014 | + $event_status = sanitize_key($event_status); |
|
2015 | + // grab status |
|
2016 | + if (empty($event_status)) { |
|
2017 | + $msg = esc_html__( |
|
2018 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2019 | + 'event_espresso' |
|
2020 | + ); |
|
2021 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2022 | + return false; |
|
2023 | + } |
|
2024 | + // was event trashed or restored ? |
|
2025 | + switch ($event_status) { |
|
2026 | + case 'draft' : |
|
2027 | + $action = 'restored from the trash'; |
|
2028 | + $hook = 'AHEE_event_restored_from_trash'; |
|
2029 | + break; |
|
2030 | + case 'trash' : |
|
2031 | + $action = 'moved to the trash'; |
|
2032 | + $hook = 'AHEE_event_moved_to_trash'; |
|
2033 | + break; |
|
2034 | + default : |
|
2035 | + $action = 'updated'; |
|
2036 | + $hook = false; |
|
2037 | + } |
|
2038 | + //use class to change status |
|
2039 | + $this->_cpt_model_obj->set_status($event_status); |
|
2040 | + $success = $this->_cpt_model_obj->save(); |
|
2041 | + if ($success === false) { |
|
2042 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2043 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2044 | + return false; |
|
2045 | + } |
|
2046 | + if ($hook) { |
|
2047 | + do_action($hook); |
|
2048 | + } |
|
2049 | + return true; |
|
2050 | + } |
|
2051 | + |
|
2052 | + |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * _delete_event |
|
2056 | + * |
|
2057 | + * @access protected |
|
2058 | + * @param bool $redirect_after |
|
2059 | + */ |
|
2060 | + protected function _delete_event($redirect_after = true) |
|
2061 | + { |
|
2062 | + //determine the event id and set to array. |
|
2063 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
2064 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
2065 | + // loop thru events |
|
2066 | + if ($EVT_ID) { |
|
2067 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
2068 | + // get list of events with no prices |
|
2069 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2070 | + // remove this event from the list of events with no prices |
|
2071 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
2072 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2073 | + } |
|
2074 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2075 | + } else { |
|
2076 | + $success = false; |
|
2077 | + $msg = esc_html__( |
|
2078 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2079 | + 'event_espresso' |
|
2080 | + ); |
|
2081 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2082 | + } |
|
2083 | + if ($redirect_after) { |
|
2084 | + $this->_redirect_after_action( |
|
2085 | + $success, |
|
2086 | + 'Event', |
|
2087 | + 'deleted', |
|
2088 | + array('action' => 'default', 'status' => 'trash') |
|
2089 | + ); |
|
2090 | + } |
|
2091 | + } |
|
2092 | + |
|
2093 | + |
|
2094 | + |
|
2095 | + /** |
|
2096 | + * _delete_events |
|
2097 | + * |
|
2098 | + * @access protected |
|
2099 | + * @return void |
|
2100 | + */ |
|
2101 | + protected function _delete_events() |
|
2102 | + { |
|
2103 | + $success = true; |
|
2104 | + // get list of events with no prices |
|
2105 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2106 | + //determine the event id and set to array. |
|
2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
2108 | + // loop thru events |
|
2109 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2110 | + $EVT_ID = absint($EVT_ID); |
|
2111 | + if ($EVT_ID) { |
|
2112 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
2113 | + $success = $results !== false ? $success : false; |
|
2114 | + // remove this event from the list of events with no prices |
|
2115 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2116 | + } else { |
|
2117 | + $success = false; |
|
2118 | + $msg = esc_html__( |
|
2119 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2120 | + 'event_espresso' |
|
2121 | + ); |
|
2122 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2123 | + } |
|
2124 | + } |
|
2125 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2126 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2127 | + $success = $success ? 2 : false; |
|
2128 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
2129 | + } |
|
2130 | + |
|
2131 | + |
|
2132 | + |
|
2133 | + /** |
|
2134 | + * _permanently_delete_event |
|
2135 | + * |
|
2136 | + * @access private |
|
2137 | + * @param int $EVT_ID |
|
2138 | + * @return bool |
|
2139 | + */ |
|
2140 | + private function _permanently_delete_event($EVT_ID = 0) |
|
2141 | + { |
|
2142 | + // grab event id |
|
2143 | + if ( ! $EVT_ID) { |
|
2144 | + $msg = esc_html__( |
|
2145 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2146 | + 'event_espresso' |
|
2147 | + ); |
|
2148 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2149 | + return false; |
|
2150 | + } |
|
2151 | + if ( |
|
2152 | + ! $this->_cpt_model_obj instanceof EE_Event |
|
2153 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
2154 | + ) { |
|
2155 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2156 | + } |
|
2157 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
2158 | + return false; |
|
2159 | + } |
|
2160 | + //need to delete related tickets and prices first. |
|
2161 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
2162 | + foreach ($datetimes as $datetime) { |
|
2163 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
2164 | + $tickets = $datetime->get_many_related('Ticket'); |
|
2165 | + foreach ($tickets as $ticket) { |
|
2166 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
2167 | + $ticket->delete_related_permanently('Price'); |
|
2168 | + $ticket->delete_permanently(); |
|
2169 | + } |
|
2170 | + $datetime->delete(); |
|
2171 | + } |
|
2172 | + //what about related venues or terms? |
|
2173 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
2174 | + foreach ($venues as $venue) { |
|
2175 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
2176 | + } |
|
2177 | + //any attached question groups? |
|
2178 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
2179 | + if ( ! empty($question_groups)) { |
|
2180 | + foreach ($question_groups as $question_group) { |
|
2181 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
2182 | + } |
|
2183 | + } |
|
2184 | + //Message Template Groups |
|
2185 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
2186 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
2187 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
2188 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
2189 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
2190 | + } |
|
2191 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
2192 | + // did it all go as planned ? |
|
2193 | + if ($success) { |
|
2194 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
2195 | + EE_Error::add_success($msg); |
|
2196 | + } else { |
|
2197 | + $msg = sprintf( |
|
2198 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
2199 | + $EVT_ID |
|
2200 | + ); |
|
2201 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2202 | + return false; |
|
2203 | + } |
|
2204 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
2205 | + return true; |
|
2206 | + } |
|
2207 | + |
|
2208 | + |
|
2209 | + |
|
2210 | + /** |
|
2211 | + * get total number of events |
|
2212 | + * |
|
2213 | + * @access public |
|
2214 | + * @return int |
|
2215 | + */ |
|
2216 | + public function total_events() |
|
2217 | + { |
|
2218 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2219 | + return $count; |
|
2220 | + } |
|
2221 | + |
|
2222 | + |
|
2223 | + |
|
2224 | + /** |
|
2225 | + * get total number of draft events |
|
2226 | + * |
|
2227 | + * @access public |
|
2228 | + * @return int |
|
2229 | + */ |
|
2230 | + public function total_events_draft() |
|
2231 | + { |
|
2232 | + $where = array( |
|
2233 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
2234 | + ); |
|
2235 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2236 | + return $count; |
|
2237 | + } |
|
2238 | + |
|
2239 | + |
|
2240 | + |
|
2241 | + /** |
|
2242 | + * get total number of trashed events |
|
2243 | + * |
|
2244 | + * @access public |
|
2245 | + * @return int |
|
2246 | + */ |
|
2247 | + public function total_trashed_events() |
|
2248 | + { |
|
2249 | + $where = array( |
|
2250 | + 'status' => 'trash', |
|
2251 | + ); |
|
2252 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2253 | + return $count; |
|
2254 | + } |
|
2255 | + |
|
2256 | + |
|
2257 | + /** |
|
2258 | + * _default_event_settings |
|
2259 | + * This generates the Default Settings Tab |
|
2260 | + * |
|
2261 | + * @return void |
|
2262 | + * @throws \EE_Error |
|
2263 | + */ |
|
2264 | + protected function _default_event_settings() |
|
2265 | + { |
|
2266 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2267 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2268 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2269 | + $this->display_admin_page_with_sidebar(); |
|
2270 | + } |
|
2271 | + |
|
2272 | + |
|
2273 | + /** |
|
2274 | + * Return the form for event settings. |
|
2275 | + * @return \EE_Form_Section_Proper |
|
2276 | + */ |
|
2277 | + protected function _default_event_settings_form() |
|
2278 | + { |
|
2279 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2280 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2281 | + //exclude |
|
2282 | + array( |
|
2283 | + EEM_Registration::status_id_cancelled, |
|
2284 | + EEM_Registration::status_id_declined, |
|
2285 | + EEM_Registration::status_id_incomplete, |
|
2286 | + EEM_Registration::status_id_wait_list, |
|
2287 | + ), |
|
2288 | + true |
|
2289 | + ); |
|
2290 | + return new EE_Form_Section_Proper( |
|
2291 | + array( |
|
2292 | + 'name' => 'update_default_event_settings', |
|
2293 | + 'html_id' => 'update_default_event_settings', |
|
2294 | + 'html_class' => 'form-table', |
|
2295 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2296 | + 'subsections' => apply_filters( |
|
2297 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2298 | + array( |
|
2299 | + 'default_reg_status' => new EE_Select_Input( |
|
2300 | + $registration_stati_for_selection, |
|
2301 | + array( |
|
2302 | + 'default' => isset($registration_config->default_STS_ID) |
|
2303 | + && array_key_exists( |
|
2304 | + $registration_config->default_STS_ID, |
|
2305 | + $registration_stati_for_selection |
|
2306 | + ) |
|
2307 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
2308 | + : EEM_Registration::status_id_pending_payment, |
|
2309 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2310 | + . EEH_Template::get_help_tab_link( |
|
2311 | + 'default_settings_status_help_tab' |
|
2312 | + ), |
|
2313 | + 'html_help_text' => esc_html__( |
|
2314 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2315 | + 'event_espresso' |
|
2316 | + ) |
|
2317 | + ) |
|
2318 | + ), |
|
2319 | + 'default_max_tickets' => new EE_Integer_Input( |
|
2320 | + array( |
|
2321 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2322 | + ? $registration_config->default_maximum_number_of_tickets |
|
2323 | + : EEM_Event::get_default_additional_limit(), |
|
2324 | + 'html_label_text' => esc_html__( |
|
2325 | + 'Default Maximum Tickets Allowed Per Order:', |
|
2326 | + 'event_espresso' |
|
2327 | + ) . EEH_Template::get_help_tab_link( |
|
2328 | + 'default_maximum_tickets_help_tab"' |
|
2329 | + ), |
|
2330 | + 'html_help_text' => esc_html__( |
|
2331 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2332 | + 'event_espresso' |
|
2333 | + ) |
|
2334 | + ) |
|
2335 | + ) |
|
2336 | + ) |
|
2337 | + ) |
|
2338 | + ) |
|
2339 | + ); |
|
2340 | + } |
|
2341 | + |
|
2342 | + |
|
2343 | + /** |
|
2344 | + * _update_default_event_settings |
|
2345 | + * |
|
2346 | + * @access protected |
|
2347 | + * @return void |
|
2348 | + * @throws \EE_Error |
|
2349 | + */ |
|
2350 | + protected function _update_default_event_settings() |
|
2351 | + { |
|
2352 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2353 | + $form = $this->_default_event_settings_form(); |
|
2354 | + if ($form->was_submitted()) { |
|
2355 | + $form->receive_form_submission(); |
|
2356 | + if ($form->is_valid()) { |
|
2357 | + $valid_data = $form->valid_data(); |
|
2358 | + if (isset($valid_data['default_reg_status'])) { |
|
2359 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2360 | + } |
|
2361 | + if (isset($valid_data['default_max_tickets'])) { |
|
2362 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2363 | + } |
|
2364 | + //update because data was valid! |
|
2365 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
2366 | + EE_Error::overwrite_success(); |
|
2367 | + EE_Error::add_success( |
|
2368 | + __('Default Event Settings were updated', 'event_espresso') |
|
2369 | + ); |
|
2370 | + } |
|
2371 | + } |
|
2372 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2373 | + } |
|
2374 | + |
|
2375 | + |
|
2376 | + |
|
2377 | + /************* Templates *************/ |
|
2378 | + protected function _template_settings() |
|
2379 | + { |
|
2380 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2381 | + $this->_template_args['preview_img'] = '<img src="' |
|
2382 | + . EVENTS_ASSETS_URL |
|
2383 | + . DS |
|
2384 | + . 'images' |
|
2385 | + . DS |
|
2386 | + . 'caffeinated_template_features.jpg" alt="' |
|
2387 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2388 | + . '" />'; |
|
2389 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
2390 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2391 | + 'event_espresso' |
|
2392 | + ) . '</strong>'; |
|
2393 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2394 | + } |
|
2395 | + |
|
2396 | + |
|
2397 | + /** Event Category Stuff **/ |
|
2398 | + /** |
|
2399 | + * set the _category property with the category object for the loaded page. |
|
2400 | + * |
|
2401 | + * @access private |
|
2402 | + * @return void |
|
2403 | + */ |
|
2404 | + private function _set_category_object() |
|
2405 | + { |
|
2406 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2407 | + return; |
|
2408 | + } //already have the category object so get out. |
|
2409 | + //set default category object |
|
2410 | + $this->_set_empty_category_object(); |
|
2411 | + //only set if we've got an id |
|
2412 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2413 | + return; |
|
2414 | + } |
|
2415 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2416 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
2417 | + if ( ! empty($term)) { |
|
2418 | + $this->_category->category_name = $term->name; |
|
2419 | + $this->_category->category_identifier = $term->slug; |
|
2420 | + $this->_category->category_desc = $term->description; |
|
2421 | + $this->_category->id = $term->term_id; |
|
2422 | + $this->_category->parent = $term->parent; |
|
2423 | + } |
|
2424 | + } |
|
2425 | + |
|
2426 | + |
|
2427 | + |
|
2428 | + private function _set_empty_category_object() |
|
2429 | + { |
|
2430 | + $this->_category = new stdClass(); |
|
2431 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2432 | + $this->_category->id = $this->_category->parent = 0; |
|
2433 | + } |
|
2434 | + |
|
2435 | + |
|
2436 | + |
|
2437 | + protected function _category_list_table() |
|
2438 | + { |
|
2439 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2440 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2441 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2442 | + 'add_category', |
|
2443 | + 'add_category', |
|
2444 | + array(), |
|
2445 | + 'add-new-h2' |
|
2446 | + ); |
|
2447 | + $this->display_admin_list_table_page_with_sidebar(); |
|
2448 | + } |
|
2449 | + |
|
2450 | + |
|
2451 | + |
|
2452 | + /** |
|
2453 | + * @param $view |
|
2454 | + */ |
|
2455 | + protected function _category_details($view) |
|
2456 | + { |
|
2457 | + //load formatter helper |
|
2458 | + //load field generator helper |
|
2459 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2460 | + $this->_set_add_edit_form_tags($route); |
|
2461 | + $this->_set_category_object(); |
|
2462 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2463 | + $delete_action = 'delete_category'; |
|
2464 | + //custom redirect |
|
2465 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2466 | + array('action' => 'category_list'), |
|
2467 | + $this->_admin_base_url |
|
2468 | + ); |
|
2469 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2470 | + //take care of contents |
|
2471 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2472 | + $this->display_admin_page_with_sidebar(); |
|
2473 | + } |
|
2474 | + |
|
2475 | + |
|
2476 | + |
|
2477 | + /** |
|
2478 | + * @return mixed |
|
2479 | + */ |
|
2480 | + protected function _category_details_content() |
|
2481 | + { |
|
2482 | + $editor_args['category_desc'] = array( |
|
2483 | + 'type' => 'wp_editor', |
|
2484 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2485 | + 'class' => 'my_editor_custom', |
|
2486 | + 'wpeditor_args' => array('media_buttons' => false), |
|
2487 | + ); |
|
2488 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2489 | + $all_terms = get_terms( |
|
2490 | + array('espresso_event_categories'), |
|
2491 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2492 | + ); |
|
2493 | + //setup category select for term parents. |
|
2494 | + $category_select_values[] = array( |
|
2495 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2496 | + 'id' => 0, |
|
2497 | + ); |
|
2498 | + foreach ($all_terms as $term) { |
|
2499 | + $category_select_values[] = array( |
|
2500 | + 'text' => $term->name, |
|
2501 | + 'id' => $term->term_id, |
|
2502 | + ); |
|
2503 | + } |
|
2504 | + $category_select = EEH_Form_Fields::select_input( |
|
2505 | + 'category_parent', |
|
2506 | + $category_select_values, |
|
2507 | + $this->_category->parent |
|
2508 | + ); |
|
2509 | + $template_args = array( |
|
2510 | + 'category' => $this->_category, |
|
2511 | + 'category_select' => $category_select, |
|
2512 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2513 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2514 | + 'disable' => '', |
|
2515 | + 'disabled_message' => false, |
|
2516 | + ); |
|
2517 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2518 | + return EEH_Template::display_template($template, $template_args, true); |
|
2519 | + } |
|
2520 | + |
|
2521 | + |
|
2522 | + |
|
2523 | + protected function _delete_categories() |
|
2524 | + { |
|
2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
2526 | + : (array)$this->_req_data['category_id']; |
|
2527 | + foreach ($cat_ids as $cat_id) { |
|
2528 | + $this->_delete_category($cat_id); |
|
2529 | + } |
|
2530 | + //doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2531 | + $query_args = array( |
|
2532 | + 'action' => 'category_list', |
|
2533 | + ); |
|
2534 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2535 | + } |
|
2536 | + |
|
2537 | + |
|
2538 | + |
|
2539 | + /** |
|
2540 | + * @param $cat_id |
|
2541 | + */ |
|
2542 | + protected function _delete_category($cat_id) |
|
2543 | + { |
|
2544 | + $cat_id = absint($cat_id); |
|
2545 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
2546 | + } |
|
2547 | + |
|
2548 | + |
|
2549 | + |
|
2550 | + /** |
|
2551 | + * @param $new_category |
|
2552 | + */ |
|
2553 | + protected function _insert_or_update_category($new_category) |
|
2554 | + { |
|
2555 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2556 | + $success = 0; //we already have a success message so lets not send another. |
|
2557 | + if ($cat_id) { |
|
2558 | + $query_args = array( |
|
2559 | + 'action' => 'edit_category', |
|
2560 | + 'EVT_CAT_ID' => $cat_id, |
|
2561 | + ); |
|
2562 | + } else { |
|
2563 | + $query_args = array('action' => 'add_category'); |
|
2564 | + } |
|
2565 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2566 | + } |
|
2567 | + |
|
2568 | + |
|
2569 | + |
|
2570 | + /** |
|
2571 | + * @param bool $update |
|
2572 | + * @return bool|mixed|string |
|
2573 | + */ |
|
2574 | + private function _insert_category($update = false) |
|
2575 | + { |
|
2576 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2577 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2578 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2579 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2580 | + if (empty($category_name)) { |
|
2581 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2582 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2583 | + return false; |
|
2584 | + } |
|
2585 | + $term_args = array( |
|
2586 | + 'name' => $category_name, |
|
2587 | + 'description' => $category_desc, |
|
2588 | + 'parent' => $category_parent, |
|
2589 | + ); |
|
2590 | + //was the category_identifier input disabled? |
|
2591 | + if (isset($this->_req_data['category_identifier'])) { |
|
2592 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2593 | + } |
|
2594 | + $insert_ids = $update |
|
2595 | + ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) |
|
2596 | + : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
2597 | + if ( ! is_array($insert_ids)) { |
|
2598 | + $msg = esc_html__( |
|
2599 | + 'An error occurred and the category has not been saved to the database.', |
|
2600 | + 'event_espresso' |
|
2601 | + ); |
|
2602 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2603 | + } else { |
|
2604 | + $cat_id = $insert_ids['term_id']; |
|
2605 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2606 | + EE_Error::add_success($msg); |
|
2607 | + } |
|
2608 | + return $cat_id; |
|
2609 | + } |
|
2610 | + |
|
2611 | + |
|
2612 | + |
|
2613 | + /** |
|
2614 | + * @param int $per_page |
|
2615 | + * @param int $current_page |
|
2616 | + * @param bool $count |
|
2617 | + * @return \EE_Base_Class[]|int |
|
2618 | + */ |
|
2619 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2620 | + { |
|
2621 | + //testing term stuff |
|
2622 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2623 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2624 | + $limit = ($current_page - 1) * $per_page; |
|
2625 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
2626 | + if (isset($this->_req_data['s'])) { |
|
2627 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2628 | + $where['OR'] = array( |
|
2629 | + 'Term.name' => array('LIKE', $sstr), |
|
2630 | + 'description' => array('LIKE', $sstr), |
|
2631 | + ); |
|
2632 | + } |
|
2633 | + $query_params = array( |
|
2634 | + $where, |
|
2635 | + 'order_by' => array($orderby => $order), |
|
2636 | + 'limit' => $limit . ',' . $per_page, |
|
2637 | + 'force_join' => array('Term'), |
|
2638 | + ); |
|
2639 | + $categories = $count |
|
2640 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2641 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2642 | + return $categories; |
|
2643 | + } |
|
2644 | + |
|
2645 | + |
|
2646 | + |
|
2647 | + /* end category stuff */ |
|
2648 | + /**************/ |
|
2649 | 2649 | } |
2650 | 2650 | //end class Events_Admin_Page |
@@ -536,11 +536,11 @@ discard block |
||
536 | 536 | { |
537 | 537 | wp_register_style( |
538 | 538 | 'events-admin-css', |
539 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
539 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
540 | 540 | array(), |
541 | 541 | EVENT_ESPRESSO_VERSION |
542 | 542 | ); |
543 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
543 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
544 | 544 | wp_enqueue_style('events-admin-css'); |
545 | 545 | wp_enqueue_style('ee-cat-admin'); |
546 | 546 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | //scripts |
549 | 549 | wp_register_script( |
550 | 550 | 'event_editor_js', |
551 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
551 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
552 | 552 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
553 | 553 | EVENT_ESPRESSO_VERSION, |
554 | 554 | true |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | wp_enqueue_style('espresso-ui-theme'); |
581 | 581 | wp_register_style( |
582 | 582 | 'event-editor-css', |
583 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
583 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
584 | 584 | array('ee-admin-css'), |
585 | 585 | EVENT_ESPRESSO_VERSION |
586 | 586 | ); |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | //scripts |
589 | 589 | wp_register_script( |
590 | 590 | 'event-datetime-metabox', |
591 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
591 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
592 | 592 | array('event_editor_js', 'ee-datepicker'), |
593 | 593 | EVENT_ESPRESSO_VERSION |
594 | 594 | ); |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | 'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.', |
755 | 755 | 'event_espresso' |
756 | 756 | ), |
757 | - '<a href="' . admin_url('options-general.php') . '">', |
|
757 | + '<a href="'.admin_url('options-general.php').'">', |
|
758 | 758 | '</a>' |
759 | 759 | ), |
760 | 760 | __FILE__, |
@@ -824,31 +824,31 @@ discard block |
||
824 | 824 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
825 | 825 | $statuses = array( |
826 | 826 | 'sold_out_status' => array( |
827 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
827 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
828 | 828 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
829 | 829 | ), |
830 | 830 | 'active_status' => array( |
831 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
831 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
832 | 832 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
833 | 833 | ), |
834 | 834 | 'upcoming_status' => array( |
835 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
835 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
836 | 836 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
837 | 837 | ), |
838 | 838 | 'postponed_status' => array( |
839 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
839 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
840 | 840 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
841 | 841 | ), |
842 | 842 | 'cancelled_status' => array( |
843 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
843 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
844 | 844 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
845 | 845 | ), |
846 | 846 | 'expired_status' => array( |
847 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
847 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
848 | 848 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
849 | 849 | ), |
850 | 850 | 'inactive_status' => array( |
851 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
851 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
852 | 852 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
853 | 853 | ), |
854 | 854 | ); |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | { |
913 | 913 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
914 | 914 | $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
915 | - ? (array)$this->_template_args['after_list_table'] |
|
915 | + ? (array) $this->_template_args['after_list_table'] |
|
916 | 916 | : array(); |
917 | 917 | $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
918 | 918 | . EEH_Template::get_button_or_link( |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | 'button' |
922 | 922 | ); |
923 | 923 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
924 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
924 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
925 | 925 | 'create_new', |
926 | 926 | 'add', |
927 | 927 | array(), |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | */ |
1052 | 1052 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
1053 | 1053 | { |
1054 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1054 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
1055 | 1055 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
1056 | 1056 | $rows_affected = null; |
1057 | 1057 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1175,7 +1175,7 @@ discard block |
||
1175 | 1175 | if (empty($tkt['TKT_start_date'])) { |
1176 | 1176 | //let's use now in the set timezone. |
1177 | 1177 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
1178 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1178 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
1179 | 1179 | } |
1180 | 1180 | if (empty($tkt['TKT_end_date'])) { |
1181 | 1181 | //use the start date of the first datetime |
@@ -1464,7 +1464,7 @@ discard block |
||
1464 | 1464 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
1465 | 1465 | // load template |
1466 | 1466 | EEH_Template::display_template( |
1467 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1467 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
1468 | 1468 | $publish_box_extra_args |
1469 | 1469 | ); |
1470 | 1470 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | ); |
1592 | 1592 | $template = apply_filters( |
1593 | 1593 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
1594 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1594 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
1595 | 1595 | ); |
1596 | 1596 | EEH_Template::display_template($template, $template_args); |
1597 | 1597 | } |
@@ -1610,7 +1610,7 @@ discard block |
||
1610 | 1610 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
1611 | 1611 | { |
1612 | 1612 | $template_args = array( |
1613 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1613 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
1614 | 1614 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
1615 | 1615 | : '', |
1616 | 1616 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1664,7 +1664,7 @@ discard block |
||
1664 | 1664 | $template_args = array_merge($template_args, $price_args); |
1665 | 1665 | $template = apply_filters( |
1666 | 1666 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
1667 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1667 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
1668 | 1668 | $ticket |
1669 | 1669 | ); |
1670 | 1670 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1716,7 +1716,7 @@ discard block |
||
1716 | 1716 | $default_reg_status_values |
1717 | 1717 | ); |
1718 | 1718 | EEH_Template::display_template( |
1719 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1719 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
1720 | 1720 | $template_args |
1721 | 1721 | ); |
1722 | 1722 | } |
@@ -1739,7 +1739,7 @@ discard block |
||
1739 | 1739 | { |
1740 | 1740 | $EEME = $this->_event_model(); |
1741 | 1741 | $offset = ($current_page - 1) * $per_page; |
1742 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1742 | + $limit = $count ? null : $offset.','.$per_page; |
|
1743 | 1743 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
1744 | 1744 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
1745 | 1745 | if (isset($this->_req_data['month_range'])) { |
@@ -1776,7 +1776,7 @@ discard block |
||
1776 | 1776 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
1777 | 1777 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
1778 | 1778 | $DateTime = new DateTime( |
1779 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1779 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
1780 | 1780 | new DateTimeZone(EEM_Datetime::instance()->get_timezone()) |
1781 | 1781 | ); |
1782 | 1782 | $start = $DateTime->format(implode(' ', $start_formats)); |
@@ -1822,7 +1822,7 @@ discard block |
||
1822 | 1822 | } |
1823 | 1823 | //search query handling |
1824 | 1824 | if (isset($this->_req_data['s'])) { |
1825 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1825 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1826 | 1826 | $where['OR'] = array( |
1827 | 1827 | 'EVT_name' => array('LIKE', $search_string), |
1828 | 1828 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1956,7 +1956,7 @@ discard block |
||
1956 | 1956 | if ( ! empty($event_status)) { |
1957 | 1957 | $success = true; |
1958 | 1958 | //determine the event id and set to array. |
1959 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
1959 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
1960 | 1960 | // loop thru events |
1961 | 1961 | foreach ($EVT_IDs as $EVT_ID) { |
1962 | 1962 | if ($EVT_ID = absint($EVT_ID)) { |
@@ -2104,7 +2104,7 @@ discard block |
||
2104 | 2104 | // get list of events with no prices |
2105 | 2105 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
2106 | 2106 | //determine the event id and set to array. |
2107 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array(); |
|
2107 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2108 | 2108 | // loop thru events |
2109 | 2109 | foreach ($EVT_IDs as $EVT_ID) { |
2110 | 2110 | $EVT_ID = absint($EVT_ID); |
@@ -2324,7 +2324,7 @@ discard block |
||
2324 | 2324 | 'html_label_text' => esc_html__( |
2325 | 2325 | 'Default Maximum Tickets Allowed Per Order:', |
2326 | 2326 | 'event_espresso' |
2327 | - ) . EEH_Template::get_help_tab_link( |
|
2327 | + ).EEH_Template::get_help_tab_link( |
|
2328 | 2328 | 'default_maximum_tickets_help_tab"' |
2329 | 2329 | ), |
2330 | 2330 | 'html_help_text' => esc_html__( |
@@ -2386,10 +2386,10 @@ discard block |
||
2386 | 2386 | . 'caffeinated_template_features.jpg" alt="' |
2387 | 2387 | . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
2388 | 2388 | . '" />'; |
2389 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__( |
|
2389 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__( |
|
2390 | 2390 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
2391 | 2391 | 'event_espresso' |
2392 | - ) . '</strong>'; |
|
2392 | + ).'</strong>'; |
|
2393 | 2393 | $this->display_admin_caf_preview_page('template_settings_tab'); |
2394 | 2394 | } |
2395 | 2395 | |
@@ -2438,7 +2438,7 @@ discard block |
||
2438 | 2438 | { |
2439 | 2439 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2440 | 2440 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
2441 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2441 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
2442 | 2442 | 'add_category', |
2443 | 2443 | 'add_category', |
2444 | 2444 | array(), |
@@ -2514,7 +2514,7 @@ discard block |
||
2514 | 2514 | 'disable' => '', |
2515 | 2515 | 'disabled_message' => false, |
2516 | 2516 | ); |
2517 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2517 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
2518 | 2518 | return EEH_Template::display_template($template, $template_args, true); |
2519 | 2519 | } |
2520 | 2520 | |
@@ -2522,8 +2522,8 @@ discard block |
||
2522 | 2522 | |
2523 | 2523 | protected function _delete_categories() |
2524 | 2524 | { |
2525 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID'] |
|
2526 | - : (array)$this->_req_data['category_id']; |
|
2525 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
2526 | + : (array) $this->_req_data['category_id']; |
|
2527 | 2527 | foreach ($cat_ids as $cat_id) { |
2528 | 2528 | $this->_delete_category($cat_id); |
2529 | 2529 | } |
@@ -2624,7 +2624,7 @@ discard block |
||
2624 | 2624 | $limit = ($current_page - 1) * $per_page; |
2625 | 2625 | $where = array('taxonomy' => 'espresso_event_categories'); |
2626 | 2626 | if (isset($this->_req_data['s'])) { |
2627 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2627 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
2628 | 2628 | $where['OR'] = array( |
2629 | 2629 | 'Term.name' => array('LIKE', $sstr), |
2630 | 2630 | 'description' => array('LIKE', $sstr), |
@@ -2633,7 +2633,7 @@ discard block |
||
2633 | 2633 | $query_params = array( |
2634 | 2634 | $where, |
2635 | 2635 | 'order_by' => array($orderby => $order), |
2636 | - 'limit' => $limit . ',' . $per_page, |
|
2636 | + 'limit' => $limit.','.$per_page, |
|
2637 | 2637 | 'force_join' => array('Term'), |
2638 | 2638 | ); |
2639 | 2639 | $categories = $count |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <p> |
2 | 2 | <?php esc_html_e( |
3 | - 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
4 | - 'event_espresso' |
|
5 | - ); ?> |
|
3 | + 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
4 | + 'event_espresso' |
|
5 | + ); ?> |
|
6 | 6 | </p> |
7 | 7 | \ No newline at end of file |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace EventEspresso\core\services\commands; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('No direct script access allowed'); |
7 | 7 | } |
8 | 8 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace EventEspresso\core\services\commands; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -16,22 +16,22 @@ discard block |
||
16 | 16 | interface CommandHandlerManagerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @param CommandHandlerInterface $command_handler |
|
21 | - * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
22 | - * @return void |
|
23 | - * @throws InvalidCommandHandlerException |
|
24 | - */ |
|
25 | - public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = ''); |
|
19 | + /** |
|
20 | + * @param CommandHandlerInterface $command_handler |
|
21 | + * @param string $fqcn_for_command Fully Qualified ClassName for Command |
|
22 | + * @return void |
|
23 | + * @throws InvalidCommandHandlerException |
|
24 | + */ |
|
25 | + public function addCommandHandler(CommandHandlerInterface $command_handler, $fqcn_for_command = ''); |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param CommandInterface $command |
|
31 | - * @param CommandBusInterface $command_bus |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null); |
|
29 | + /** |
|
30 | + * @param CommandInterface $command |
|
31 | + * @param CommandBusInterface $command_bus |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public function getCommandHandler(CommandInterface $command, CommandBusInterface $command_bus = null); |
|
35 | 35 | |
36 | 36 | } |
37 | 37 | // End of file CommandHandlerManagerInterface.php |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\commands\CommandInterface; |
6 | 6 | |
7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | interface CommandBusMiddlewareInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @param CommandInterface $command |
|
23 | - * @param Closure $next |
|
24 | - * @return mixed |
|
25 | - */ |
|
26 | - public function handle(CommandInterface $command, Closure $next); |
|
21 | + /** |
|
22 | + * @param CommandInterface $command |
|
23 | + * @param Closure $next |
|
24 | + * @return mixed |
|
25 | + */ |
|
26 | + public function handle(CommandInterface $command, Closure $next); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | // End of file CommandBusMiddlewareInterface.php |