@@ -16,595 +16,595 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
21 | - */ |
|
22 | - protected $_message_resource_manager; |
|
23 | - |
|
24 | - /** |
|
25 | - * @type EE_Messages_Queue |
|
26 | - */ |
|
27 | - protected $_queue; |
|
28 | - |
|
29 | - /** |
|
30 | - * @type EE_Messages_Generator |
|
31 | - */ |
|
32 | - protected $_generator; |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * constructor |
|
39 | - * |
|
40 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
41 | - */ |
|
42 | - public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
43 | - { |
|
44 | - $this->_message_resource_manager = $message_resource_manager; |
|
45 | - $this->_init_queue_and_generator(); |
|
46 | - } |
|
47 | - |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * This method sets (or resets) the various properties for use. |
|
53 | - * |
|
54 | - * - $_queue = holds the messages queue |
|
55 | - * - $_generator = holds the messages generator |
|
56 | - */ |
|
57 | - protected function _init_queue_and_generator() |
|
58 | - { |
|
59 | - $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
60 | - $this->_queue = $this->_generator->generation_queue(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * This returns the current set queue. |
|
68 | - * @return EE_Messages_Queue |
|
69 | - */ |
|
70 | - public function get_queue() |
|
71 | - { |
|
72 | - return $this->_queue; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
78 | - * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
79 | - * client code has already filtered those if necessary). |
|
80 | - * |
|
81 | - * @param EE_Messages_Queue $queue_to_process |
|
82 | - * @return bool true for success false for error. |
|
83 | - * @throws EE_Error |
|
84 | - * @throws EE_Error |
|
85 | - */ |
|
86 | - public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
87 | - { |
|
88 | - $success = false; |
|
89 | - $messages_to_send = array(); |
|
90 | - $messages_to_generate = array(); |
|
91 | - // loop through and setup the various messages from the queue so we know what is being processed |
|
92 | - $queue_to_process->get_message_repository()->rewind(); |
|
93 | - foreach ($queue_to_process->get_message_repository() as $message) { |
|
94 | - if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
95 | - $messages_to_generate[] = $message; |
|
96 | - continue; |
|
97 | - } |
|
98 | - |
|
99 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
100 | - $messages_to_send[] = $message; |
|
101 | - continue; |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // do generation/sends |
|
106 | - if ($messages_to_generate) { |
|
107 | - $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
108 | - } |
|
109 | - |
|
110 | - if ($messages_to_send) { |
|
111 | - $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
112 | - // if there was messages to generate and it failed, then we override any success value for the sending process |
|
113 | - // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
114 | - // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
115 | - // all messages processing on the same request. |
|
116 | - $success = $messages_to_generate && ! $success ? false : $sent; |
|
117 | - } |
|
118 | - return $success; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
124 | - * |
|
125 | - * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
126 | - * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
127 | - * |
|
128 | - * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
129 | - * generated messages. |
|
130 | - */ |
|
131 | - public function batch_generate_from_queue($messages = array(), $clear_queue = false) |
|
132 | - { |
|
133 | - if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
134 | - $new_queue = $this->_generator->generate(); |
|
135 | - if ($new_queue instanceof EE_Messages_Queue) { |
|
136 | - // unlock queue |
|
137 | - $this->_queue->unlock_queue(); |
|
138 | - $new_queue->initiate_request_by_priority('send'); |
|
139 | - return $new_queue; |
|
140 | - } |
|
141 | - } |
|
142 | - $this->_queue->unlock_queue(); |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This method preps a queue for generation. |
|
150 | - * |
|
151 | - * @since 4.9.0 |
|
152 | - * |
|
153 | - * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
154 | - * |
|
155 | - * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
156 | - * |
|
157 | - * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
158 | - */ |
|
159 | - protected function _build_queue_for_generation($messages = array(), $clear_queue = false) |
|
160 | - { |
|
161 | - |
|
162 | - if ($clear_queue) { |
|
163 | - $this->_init_queue_and_generator(); |
|
164 | - } |
|
165 | - |
|
166 | - if ($messages) { |
|
167 | - // if generation is locked then get out now because that means processing is already happening. |
|
168 | - if ($this->_queue->is_locked()) { |
|
169 | - return false; |
|
170 | - } |
|
171 | - |
|
172 | - $this->_queue->lock_queue(); |
|
173 | - $messages = is_array($messages) ? $messages : array( $messages ); |
|
174 | - foreach ($messages as $message) { |
|
175 | - if ($message instanceof EE_Message) { |
|
176 | - $data = $message->all_extra_meta_array(); |
|
177 | - $this->_queue->add($message, $data); |
|
178 | - } |
|
179 | - } |
|
180 | - return true; |
|
181 | - } else { |
|
182 | - return $this->_queue->get_batch_to_generate(); |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * This method preps a queue for sending. |
|
189 | - * |
|
190 | - * @param EE_Message[] $messages |
|
191 | - * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
192 | - * |
|
193 | - * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
194 | - */ |
|
195 | - protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
196 | - { |
|
197 | - // if sending is locked then get out now because that means processing is already happening. |
|
198 | - if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
199 | - return false; |
|
200 | - } |
|
201 | - |
|
202 | - $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
203 | - |
|
204 | - if ($clear_queue) { |
|
205 | - $this->_init_queue_and_generator(); |
|
206 | - } |
|
207 | - |
|
208 | - $messages = is_array($messages) ? $messages : array( $messages ); |
|
209 | - |
|
210 | - foreach ($messages as $message) { |
|
211 | - $this->_queue->add($message); |
|
212 | - } |
|
213 | - return true; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute() |
|
219 | - * to iterate and send unsent messages. |
|
220 | - * |
|
221 | - * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
222 | - * |
|
223 | - * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
224 | - * |
|
225 | - * @return EE_Messages_Queue |
|
226 | - */ |
|
227 | - public function batch_send_from_queue($messages = array(), $clear_queue = false) |
|
228 | - { |
|
229 | - |
|
230 | - if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
231 | - $this->_queue->execute(); |
|
232 | - $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
233 | - } else { |
|
234 | - // get messages to send and execute. |
|
235 | - $this->_queue->get_to_send_batch_and_send(); |
|
236 | - } |
|
237 | - // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
238 | - // messages in the queue and decide how to handle at that point. |
|
239 | - return $this->_queue; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
249 | - * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
250 | - * messages in the queue, leaving it up to the caller to do so. |
|
251 | - * |
|
252 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
253 | - * @return EE_Messages_Queue |
|
254 | - */ |
|
255 | - public function generate_and_return($messages_to_generate) |
|
256 | - { |
|
257 | - $this->_init_queue_and_generator(); |
|
258 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
259 | - return $this->_generator->generate(false); |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
267 | - * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
|
268 | - * @return EE_Messages_Queue |
|
269 | - */ |
|
270 | - public function generate_queue($persist = true) |
|
271 | - { |
|
272 | - return $this->_generator->generate($persist); |
|
273 | - } |
|
19 | + /** |
|
20 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
21 | + */ |
|
22 | + protected $_message_resource_manager; |
|
23 | + |
|
24 | + /** |
|
25 | + * @type EE_Messages_Queue |
|
26 | + */ |
|
27 | + protected $_queue; |
|
28 | + |
|
29 | + /** |
|
30 | + * @type EE_Messages_Generator |
|
31 | + */ |
|
32 | + protected $_generator; |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * constructor |
|
39 | + * |
|
40 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
41 | + */ |
|
42 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
43 | + { |
|
44 | + $this->_message_resource_manager = $message_resource_manager; |
|
45 | + $this->_init_queue_and_generator(); |
|
46 | + } |
|
47 | + |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * This method sets (or resets) the various properties for use. |
|
53 | + * |
|
54 | + * - $_queue = holds the messages queue |
|
55 | + * - $_generator = holds the messages generator |
|
56 | + */ |
|
57 | + protected function _init_queue_and_generator() |
|
58 | + { |
|
59 | + $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
60 | + $this->_queue = $this->_generator->generation_queue(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * This returns the current set queue. |
|
68 | + * @return EE_Messages_Queue |
|
69 | + */ |
|
70 | + public function get_queue() |
|
71 | + { |
|
72 | + return $this->_queue; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
78 | + * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
79 | + * client code has already filtered those if necessary). |
|
80 | + * |
|
81 | + * @param EE_Messages_Queue $queue_to_process |
|
82 | + * @return bool true for success false for error. |
|
83 | + * @throws EE_Error |
|
84 | + * @throws EE_Error |
|
85 | + */ |
|
86 | + public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
87 | + { |
|
88 | + $success = false; |
|
89 | + $messages_to_send = array(); |
|
90 | + $messages_to_generate = array(); |
|
91 | + // loop through and setup the various messages from the queue so we know what is being processed |
|
92 | + $queue_to_process->get_message_repository()->rewind(); |
|
93 | + foreach ($queue_to_process->get_message_repository() as $message) { |
|
94 | + if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
95 | + $messages_to_generate[] = $message; |
|
96 | + continue; |
|
97 | + } |
|
98 | + |
|
99 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
100 | + $messages_to_send[] = $message; |
|
101 | + continue; |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // do generation/sends |
|
106 | + if ($messages_to_generate) { |
|
107 | + $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
108 | + } |
|
109 | + |
|
110 | + if ($messages_to_send) { |
|
111 | + $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
112 | + // if there was messages to generate and it failed, then we override any success value for the sending process |
|
113 | + // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
114 | + // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
115 | + // all messages processing on the same request. |
|
116 | + $success = $messages_to_generate && ! $success ? false : $sent; |
|
117 | + } |
|
118 | + return $success; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
124 | + * |
|
125 | + * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
126 | + * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
127 | + * |
|
128 | + * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
129 | + * generated messages. |
|
130 | + */ |
|
131 | + public function batch_generate_from_queue($messages = array(), $clear_queue = false) |
|
132 | + { |
|
133 | + if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
134 | + $new_queue = $this->_generator->generate(); |
|
135 | + if ($new_queue instanceof EE_Messages_Queue) { |
|
136 | + // unlock queue |
|
137 | + $this->_queue->unlock_queue(); |
|
138 | + $new_queue->initiate_request_by_priority('send'); |
|
139 | + return $new_queue; |
|
140 | + } |
|
141 | + } |
|
142 | + $this->_queue->unlock_queue(); |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This method preps a queue for generation. |
|
150 | + * |
|
151 | + * @since 4.9.0 |
|
152 | + * |
|
153 | + * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
154 | + * |
|
155 | + * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
156 | + * |
|
157 | + * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
158 | + */ |
|
159 | + protected function _build_queue_for_generation($messages = array(), $clear_queue = false) |
|
160 | + { |
|
161 | + |
|
162 | + if ($clear_queue) { |
|
163 | + $this->_init_queue_and_generator(); |
|
164 | + } |
|
165 | + |
|
166 | + if ($messages) { |
|
167 | + // if generation is locked then get out now because that means processing is already happening. |
|
168 | + if ($this->_queue->is_locked()) { |
|
169 | + return false; |
|
170 | + } |
|
171 | + |
|
172 | + $this->_queue->lock_queue(); |
|
173 | + $messages = is_array($messages) ? $messages : array( $messages ); |
|
174 | + foreach ($messages as $message) { |
|
175 | + if ($message instanceof EE_Message) { |
|
176 | + $data = $message->all_extra_meta_array(); |
|
177 | + $this->_queue->add($message, $data); |
|
178 | + } |
|
179 | + } |
|
180 | + return true; |
|
181 | + } else { |
|
182 | + return $this->_queue->get_batch_to_generate(); |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * This method preps a queue for sending. |
|
189 | + * |
|
190 | + * @param EE_Message[] $messages |
|
191 | + * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
192 | + * |
|
193 | + * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
194 | + */ |
|
195 | + protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
196 | + { |
|
197 | + // if sending is locked then get out now because that means processing is already happening. |
|
198 | + if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
199 | + return false; |
|
200 | + } |
|
201 | + |
|
202 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
203 | + |
|
204 | + if ($clear_queue) { |
|
205 | + $this->_init_queue_and_generator(); |
|
206 | + } |
|
207 | + |
|
208 | + $messages = is_array($messages) ? $messages : array( $messages ); |
|
209 | + |
|
210 | + foreach ($messages as $message) { |
|
211 | + $this->_queue->add($message); |
|
212 | + } |
|
213 | + return true; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute() |
|
219 | + * to iterate and send unsent messages. |
|
220 | + * |
|
221 | + * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
222 | + * |
|
223 | + * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
224 | + * |
|
225 | + * @return EE_Messages_Queue |
|
226 | + */ |
|
227 | + public function batch_send_from_queue($messages = array(), $clear_queue = false) |
|
228 | + { |
|
229 | + |
|
230 | + if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
231 | + $this->_queue->execute(); |
|
232 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
233 | + } else { |
|
234 | + // get messages to send and execute. |
|
235 | + $this->_queue->get_to_send_batch_and_send(); |
|
236 | + } |
|
237 | + // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
238 | + // messages in the queue and decide how to handle at that point. |
|
239 | + return $this->_queue; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
249 | + * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
250 | + * messages in the queue, leaving it up to the caller to do so. |
|
251 | + * |
|
252 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
253 | + * @return EE_Messages_Queue |
|
254 | + */ |
|
255 | + public function generate_and_return($messages_to_generate) |
|
256 | + { |
|
257 | + $this->_init_queue_and_generator(); |
|
258 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
259 | + return $this->_generator->generate(false); |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
267 | + * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
|
268 | + * @return EE_Messages_Queue |
|
269 | + */ |
|
270 | + public function generate_queue($persist = true) |
|
271 | + { |
|
272 | + return $this->_generator->generate($persist); |
|
273 | + } |
|
274 | 274 | |
275 | 275 | |
276 | 276 | |
277 | 277 | |
278 | - /** |
|
279 | - * Queue for generation. Note this does NOT persist to the db. Client code should call get_message_repository()->save() if desire |
|
280 | - * to persist. This method is provided to client code to decide what it wants to do with queued messages for generation. |
|
281 | - * @param EE_Message_To_Generate $message_to_generate |
|
282 | - * @param bool $test_send Whether this item is for a test send or not. |
|
283 | - * @return EE_Messages_Queue |
|
284 | - */ |
|
285 | - public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
286 | - { |
|
287 | - if ($message_to_generate->valid()) { |
|
288 | - $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue |
|
300 | - * and then persists to storage. |
|
301 | - * |
|
302 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
303 | - */ |
|
304 | - public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
305 | - { |
|
306 | - $this->_init_queue_and_generator(); |
|
307 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
308 | - $this->_queue->save(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation |
|
318 | - * queue. Does NOT persist to storage (unless there is an error. |
|
319 | - * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue() |
|
320 | - * |
|
321 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
322 | - */ |
|
323 | - public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
324 | - { |
|
325 | - $this->_init_queue_and_generator(); |
|
326 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
334 | - * objects. |
|
335 | - * |
|
336 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
337 | - */ |
|
338 | - protected function _queue_for_generation_loop($messages_to_generate) |
|
339 | - { |
|
340 | - // make sure is in an array. |
|
341 | - if (! is_array($messages_to_generate)) { |
|
342 | - $messages_to_generate = array( $messages_to_generate ); |
|
343 | - } |
|
344 | - |
|
345 | - foreach ($messages_to_generate as $message_to_generate) { |
|
346 | - if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
347 | - $this->queue_for_generation($message_to_generate); |
|
348 | - } |
|
349 | - } |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
358 | - * queued for sending). |
|
359 | - * @param EE_Message_To_Generate[] |
|
360 | - * @return EE_Messages_Queue |
|
361 | - */ |
|
362 | - public function generate_and_queue_for_sending($messages_to_generate) |
|
363 | - { |
|
364 | - $this->_init_queue_and_generator(); |
|
365 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
366 | - return $this->_generator->generate(true); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Generate for preview and execute right away. |
|
375 | - * |
|
376 | - * @param EE_Message_To_Generate $message_to_generate |
|
377 | - * @param bool $test_send Whether this is a test send or not. |
|
378 | - * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
379 | - */ |
|
380 | - public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
381 | - { |
|
382 | - if (! $message_to_generate->valid()) { |
|
383 | - EE_Error::add_error( |
|
384 | - esc_html__('Unable to generate preview because of invalid data', 'event_espresso'), |
|
385 | - __FILE__, |
|
386 | - __FUNCTION__, |
|
387 | - __LINE__ |
|
388 | - ); |
|
389 | - return false; |
|
390 | - } |
|
391 | - // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
392 | - $message_to_generate->set_preview(true); |
|
393 | - $this->_init_queue_and_generator(); |
|
394 | - $this->queue_for_generation($message_to_generate, $test_send); |
|
395 | - $generated_queue = $this->_generator->generate(false); |
|
396 | - if ($generated_queue->execute(false)) { |
|
397 | - // the first queue item should be the preview |
|
398 | - $generated_queue->get_message_repository()->rewind(); |
|
399 | - if (! $generated_queue->get_message_repository()->valid()) { |
|
400 | - return $generated_queue; |
|
401 | - } |
|
402 | - return $generated_queue; |
|
403 | - } else { |
|
404 | - return false; |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * This queues for sending. |
|
411 | - * The messenger send now method is also verified to see if sending immediately is requested. |
|
412 | - * otherwise its just saved to the queue. |
|
413 | - * |
|
414 | - * @param EE_Message_To_Generate $message_to_generate |
|
415 | - * @return bool true or false for success. |
|
416 | - * @throws EE_Error |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
420 | - { |
|
421 | - if (! $message_to_generate->valid()) { |
|
422 | - return false; |
|
423 | - } |
|
424 | - $this->_init_queue_and_generator(); |
|
425 | - $message = $message_to_generate->get_EE_Message(); |
|
426 | - $this->_queue->add($message); |
|
427 | - if ($message->send_now()) { |
|
428 | - $this->_queue->execute(false); |
|
429 | - } else { |
|
430 | - $this->_queue->save(); |
|
431 | - } |
|
432 | - return true; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
438 | - * @param EE_Message_To_Generate $message_to_generate |
|
439 | - * @return EE_Messages_Queue | null |
|
440 | - */ |
|
441 | - public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
442 | - { |
|
443 | - if (! $message_to_generate->valid()) { |
|
444 | - return null; |
|
445 | - } |
|
446 | - // is there supposed to be a sending messenger for this message? |
|
447 | - if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
448 | - // make sure it's valid, but if it's not, |
|
449 | - // then set the value of $sending_messenger to an EE_Error object |
|
450 | - // so that downstream code can easily see that things went wrong. |
|
451 | - $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
452 | - ? $message_to_generate->sending_messenger() |
|
453 | - : new EE_Error( |
|
454 | - esc_html__( |
|
455 | - 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
456 | - 'event_espresso' |
|
457 | - ) |
|
458 | - ); |
|
459 | - } else { |
|
460 | - $sending_messenger = null; |
|
461 | - } |
|
462 | - |
|
463 | - if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
464 | - $this->_init_queue_and_generator(); |
|
465 | - $this->_queue->add($message_to_generate->get_EE_Message()); |
|
466 | - $this->_queue->execute(false, $sending_messenger); |
|
467 | - return $this->_queue; |
|
468 | - } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
469 | - $generated_queue = $this->generate_and_return(array( $message_to_generate )); |
|
470 | - $generated_queue->execute(false, $sending_messenger); |
|
471 | - return $generated_queue; |
|
472 | - } |
|
473 | - return null; |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Creates mtg objects for all active messengers and queues for generation. |
|
481 | - * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking |
|
482 | - * request to complete the action if the priority for the message requires immediate action. |
|
483 | - * @param string $message_type |
|
484 | - * @param mixed $data The data being used for generation. |
|
485 | - * @param bool $persist Whether to persist the queued messages to the db or not. |
|
486 | - */ |
|
487 | - public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
488 | - { |
|
489 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
490 | - if ($persist) { |
|
491 | - $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
492 | - $this->_queue->initiate_request_by_priority(); |
|
493 | - } else { |
|
494 | - $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
495 | - } |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * This simply loops through all active messengers and takes care of setting up the |
|
503 | - * EE_Message_To_Generate objects. |
|
504 | - * @param $message_type |
|
505 | - * @param $data |
|
506 | - * |
|
507 | - * @return EE_Message_To_Generate[] |
|
508 | - */ |
|
509 | - public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
510 | - { |
|
511 | - $messages_to_generate = array(); |
|
512 | - foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
513 | - $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
514 | - if ($message_to_generate->valid()) { |
|
515 | - $messages_to_generate[] = $message_to_generate; |
|
516 | - } |
|
517 | - } |
|
518 | - return $messages_to_generate; |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database |
|
524 | - * and send. |
|
525 | - * |
|
526 | - * @param array $message_ids |
|
527 | - * @throws EE_Error |
|
528 | - * @throws EE_Error |
|
529 | - */ |
|
530 | - public function setup_messages_from_ids_and_send($message_ids) |
|
531 | - { |
|
532 | - $this->_init_queue_and_generator(); |
|
533 | - $messages = EEM_Message::instance()->get_all(array( |
|
534 | - array( |
|
535 | - 'MSG_ID' => array( 'IN', $message_ids ), |
|
536 | - 'STS_ID' => array( |
|
537 | - 'IN', |
|
538 | - array_merge( |
|
539 | - EEM_Message::instance()->stati_indicating_sent(), |
|
540 | - array( EEM_Message::status_retry ) |
|
541 | - ), |
|
542 | - ), |
|
543 | - ), |
|
544 | - )); |
|
545 | - // set the Messages to resend. |
|
546 | - foreach ($messages as $message) { |
|
547 | - if ($message instanceof EE_Message) { |
|
548 | - $message->set_STS_ID(EEM_Message::status_resend); |
|
549 | - $this->_queue->add($message); |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - $this->_queue->initiate_request_by_priority('send'); |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
559 | - * objects from them, then returns the array of messages to generate objects. |
|
560 | - * Note, this sets up registrations for the registration family of message types. |
|
561 | - * |
|
562 | - * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
563 | - * |
|
564 | - * @return EE_Message_To_Generate[]|bool |
|
565 | - * @throws EE_Error |
|
566 | - */ |
|
567 | - public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
568 | - { |
|
569 | - /** @var RequestInterface $request */ |
|
570 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
571 | - $regs_to_send = array(); |
|
572 | - $regIDs = $request->getRequestParam($registration_ids_key, null, 'arrayOf|int'); |
|
573 | - if (empty($regIDs)) { |
|
574 | - EE_Error::add_error(esc_html__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
575 | - return false; |
|
576 | - } |
|
577 | - |
|
578 | - // make sure is an array |
|
579 | - $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs ); |
|
580 | - |
|
581 | - foreach ($regIDs as $regID) { |
|
582 | - $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
583 | - if (! $reg instanceof EE_Registration) { |
|
584 | - EE_Error::add_error(sprintf(esc_html__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
585 | - return false; |
|
586 | - } |
|
587 | - $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
588 | - } |
|
589 | - |
|
590 | - $messages_to_generate = array(); |
|
591 | - |
|
592 | - foreach ($regs_to_send as $status_group) { |
|
593 | - foreach ($status_group as $status_id => $registrations) { |
|
594 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
595 | - if (! $message_type) { |
|
596 | - continue; |
|
597 | - } |
|
598 | - $messages_to_generate = array_merge( |
|
599 | - $messages_to_generate, |
|
600 | - $this->setup_mtgs_for_all_active_messengers( |
|
601 | - $message_type, |
|
602 | - array( $registrations, $status_id ) |
|
603 | - ) |
|
604 | - ); |
|
605 | - } |
|
606 | - } |
|
607 | - |
|
608 | - return $messages_to_generate; |
|
609 | - } |
|
278 | + /** |
|
279 | + * Queue for generation. Note this does NOT persist to the db. Client code should call get_message_repository()->save() if desire |
|
280 | + * to persist. This method is provided to client code to decide what it wants to do with queued messages for generation. |
|
281 | + * @param EE_Message_To_Generate $message_to_generate |
|
282 | + * @param bool $test_send Whether this item is for a test send or not. |
|
283 | + * @return EE_Messages_Queue |
|
284 | + */ |
|
285 | + public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
286 | + { |
|
287 | + if ($message_to_generate->valid()) { |
|
288 | + $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue |
|
300 | + * and then persists to storage. |
|
301 | + * |
|
302 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
303 | + */ |
|
304 | + public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
305 | + { |
|
306 | + $this->_init_queue_and_generator(); |
|
307 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
308 | + $this->_queue->save(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation |
|
318 | + * queue. Does NOT persist to storage (unless there is an error. |
|
319 | + * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue() |
|
320 | + * |
|
321 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
322 | + */ |
|
323 | + public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
324 | + { |
|
325 | + $this->_init_queue_and_generator(); |
|
326 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
334 | + * objects. |
|
335 | + * |
|
336 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
337 | + */ |
|
338 | + protected function _queue_for_generation_loop($messages_to_generate) |
|
339 | + { |
|
340 | + // make sure is in an array. |
|
341 | + if (! is_array($messages_to_generate)) { |
|
342 | + $messages_to_generate = array( $messages_to_generate ); |
|
343 | + } |
|
344 | + |
|
345 | + foreach ($messages_to_generate as $message_to_generate) { |
|
346 | + if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
347 | + $this->queue_for_generation($message_to_generate); |
|
348 | + } |
|
349 | + } |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
358 | + * queued for sending). |
|
359 | + * @param EE_Message_To_Generate[] |
|
360 | + * @return EE_Messages_Queue |
|
361 | + */ |
|
362 | + public function generate_and_queue_for_sending($messages_to_generate) |
|
363 | + { |
|
364 | + $this->_init_queue_and_generator(); |
|
365 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
366 | + return $this->_generator->generate(true); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Generate for preview and execute right away. |
|
375 | + * |
|
376 | + * @param EE_Message_To_Generate $message_to_generate |
|
377 | + * @param bool $test_send Whether this is a test send or not. |
|
378 | + * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
379 | + */ |
|
380 | + public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
381 | + { |
|
382 | + if (! $message_to_generate->valid()) { |
|
383 | + EE_Error::add_error( |
|
384 | + esc_html__('Unable to generate preview because of invalid data', 'event_espresso'), |
|
385 | + __FILE__, |
|
386 | + __FUNCTION__, |
|
387 | + __LINE__ |
|
388 | + ); |
|
389 | + return false; |
|
390 | + } |
|
391 | + // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
392 | + $message_to_generate->set_preview(true); |
|
393 | + $this->_init_queue_and_generator(); |
|
394 | + $this->queue_for_generation($message_to_generate, $test_send); |
|
395 | + $generated_queue = $this->_generator->generate(false); |
|
396 | + if ($generated_queue->execute(false)) { |
|
397 | + // the first queue item should be the preview |
|
398 | + $generated_queue->get_message_repository()->rewind(); |
|
399 | + if (! $generated_queue->get_message_repository()->valid()) { |
|
400 | + return $generated_queue; |
|
401 | + } |
|
402 | + return $generated_queue; |
|
403 | + } else { |
|
404 | + return false; |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * This queues for sending. |
|
411 | + * The messenger send now method is also verified to see if sending immediately is requested. |
|
412 | + * otherwise its just saved to the queue. |
|
413 | + * |
|
414 | + * @param EE_Message_To_Generate $message_to_generate |
|
415 | + * @return bool true or false for success. |
|
416 | + * @throws EE_Error |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
420 | + { |
|
421 | + if (! $message_to_generate->valid()) { |
|
422 | + return false; |
|
423 | + } |
|
424 | + $this->_init_queue_and_generator(); |
|
425 | + $message = $message_to_generate->get_EE_Message(); |
|
426 | + $this->_queue->add($message); |
|
427 | + if ($message->send_now()) { |
|
428 | + $this->_queue->execute(false); |
|
429 | + } else { |
|
430 | + $this->_queue->save(); |
|
431 | + } |
|
432 | + return true; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
438 | + * @param EE_Message_To_Generate $message_to_generate |
|
439 | + * @return EE_Messages_Queue | null |
|
440 | + */ |
|
441 | + public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
442 | + { |
|
443 | + if (! $message_to_generate->valid()) { |
|
444 | + return null; |
|
445 | + } |
|
446 | + // is there supposed to be a sending messenger for this message? |
|
447 | + if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
448 | + // make sure it's valid, but if it's not, |
|
449 | + // then set the value of $sending_messenger to an EE_Error object |
|
450 | + // so that downstream code can easily see that things went wrong. |
|
451 | + $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
452 | + ? $message_to_generate->sending_messenger() |
|
453 | + : new EE_Error( |
|
454 | + esc_html__( |
|
455 | + 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
456 | + 'event_espresso' |
|
457 | + ) |
|
458 | + ); |
|
459 | + } else { |
|
460 | + $sending_messenger = null; |
|
461 | + } |
|
462 | + |
|
463 | + if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
464 | + $this->_init_queue_and_generator(); |
|
465 | + $this->_queue->add($message_to_generate->get_EE_Message()); |
|
466 | + $this->_queue->execute(false, $sending_messenger); |
|
467 | + return $this->_queue; |
|
468 | + } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
469 | + $generated_queue = $this->generate_and_return(array( $message_to_generate )); |
|
470 | + $generated_queue->execute(false, $sending_messenger); |
|
471 | + return $generated_queue; |
|
472 | + } |
|
473 | + return null; |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Creates mtg objects for all active messengers and queues for generation. |
|
481 | + * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking |
|
482 | + * request to complete the action if the priority for the message requires immediate action. |
|
483 | + * @param string $message_type |
|
484 | + * @param mixed $data The data being used for generation. |
|
485 | + * @param bool $persist Whether to persist the queued messages to the db or not. |
|
486 | + */ |
|
487 | + public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
488 | + { |
|
489 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
490 | + if ($persist) { |
|
491 | + $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
492 | + $this->_queue->initiate_request_by_priority(); |
|
493 | + } else { |
|
494 | + $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
495 | + } |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * This simply loops through all active messengers and takes care of setting up the |
|
503 | + * EE_Message_To_Generate objects. |
|
504 | + * @param $message_type |
|
505 | + * @param $data |
|
506 | + * |
|
507 | + * @return EE_Message_To_Generate[] |
|
508 | + */ |
|
509 | + public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
510 | + { |
|
511 | + $messages_to_generate = array(); |
|
512 | + foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
513 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
514 | + if ($message_to_generate->valid()) { |
|
515 | + $messages_to_generate[] = $message_to_generate; |
|
516 | + } |
|
517 | + } |
|
518 | + return $messages_to_generate; |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database |
|
524 | + * and send. |
|
525 | + * |
|
526 | + * @param array $message_ids |
|
527 | + * @throws EE_Error |
|
528 | + * @throws EE_Error |
|
529 | + */ |
|
530 | + public function setup_messages_from_ids_and_send($message_ids) |
|
531 | + { |
|
532 | + $this->_init_queue_and_generator(); |
|
533 | + $messages = EEM_Message::instance()->get_all(array( |
|
534 | + array( |
|
535 | + 'MSG_ID' => array( 'IN', $message_ids ), |
|
536 | + 'STS_ID' => array( |
|
537 | + 'IN', |
|
538 | + array_merge( |
|
539 | + EEM_Message::instance()->stati_indicating_sent(), |
|
540 | + array( EEM_Message::status_retry ) |
|
541 | + ), |
|
542 | + ), |
|
543 | + ), |
|
544 | + )); |
|
545 | + // set the Messages to resend. |
|
546 | + foreach ($messages as $message) { |
|
547 | + if ($message instanceof EE_Message) { |
|
548 | + $message->set_STS_ID(EEM_Message::status_resend); |
|
549 | + $this->_queue->add($message); |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + $this->_queue->initiate_request_by_priority('send'); |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
559 | + * objects from them, then returns the array of messages to generate objects. |
|
560 | + * Note, this sets up registrations for the registration family of message types. |
|
561 | + * |
|
562 | + * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
563 | + * |
|
564 | + * @return EE_Message_To_Generate[]|bool |
|
565 | + * @throws EE_Error |
|
566 | + */ |
|
567 | + public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
568 | + { |
|
569 | + /** @var RequestInterface $request */ |
|
570 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
571 | + $regs_to_send = array(); |
|
572 | + $regIDs = $request->getRequestParam($registration_ids_key, null, 'arrayOf|int'); |
|
573 | + if (empty($regIDs)) { |
|
574 | + EE_Error::add_error(esc_html__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
575 | + return false; |
|
576 | + } |
|
577 | + |
|
578 | + // make sure is an array |
|
579 | + $regIDs = is_array($regIDs) ? $regIDs : array( $regIDs ); |
|
580 | + |
|
581 | + foreach ($regIDs as $regID) { |
|
582 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
583 | + if (! $reg instanceof EE_Registration) { |
|
584 | + EE_Error::add_error(sprintf(esc_html__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
585 | + return false; |
|
586 | + } |
|
587 | + $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
588 | + } |
|
589 | + |
|
590 | + $messages_to_generate = array(); |
|
591 | + |
|
592 | + foreach ($regs_to_send as $status_group) { |
|
593 | + foreach ($status_group as $status_id => $registrations) { |
|
594 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
595 | + if (! $message_type) { |
|
596 | + continue; |
|
597 | + } |
|
598 | + $messages_to_generate = array_merge( |
|
599 | + $messages_to_generate, |
|
600 | + $this->setup_mtgs_for_all_active_messengers( |
|
601 | + $message_type, |
|
602 | + array( $registrations, $status_id ) |
|
603 | + ) |
|
604 | + ); |
|
605 | + } |
|
606 | + } |
|
607 | + |
|
608 | + return $messages_to_generate; |
|
609 | + } |
|
610 | 610 | } |
@@ -19,2652 +19,2652 @@ |
||
19 | 19 | class Events_Admin_Page extends EE_Admin_Page_CPT |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * This will hold the event object for event_details screen. |
|
24 | - * |
|
25 | - * @var EE_Event $_event |
|
26 | - */ |
|
27 | - protected $_event; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This will hold the category object for category_details screen. |
|
32 | - * |
|
33 | - * @var stdClass $_category |
|
34 | - */ |
|
35 | - protected $_category; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * This will hold the event model instance |
|
40 | - * |
|
41 | - * @var EEM_Event $_event_model |
|
42 | - */ |
|
43 | - protected $_event_model; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EE_Event |
|
48 | - */ |
|
49 | - protected $_cpt_model_obj = false; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @var NodeGroupDao |
|
54 | - */ |
|
55 | - protected $model_obj_node_group_persister; |
|
56 | - |
|
57 | - /** |
|
58 | - * Initialize page props for this admin page group. |
|
59 | - */ |
|
60 | - protected function _init_page_props() |
|
61 | - { |
|
62 | - $this->page_slug = EVENTS_PG_SLUG; |
|
63 | - $this->page_label = EVENTS_LABEL; |
|
64 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
65 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
66 | - $this->_cpt_model_names = array( |
|
67 | - 'create_new' => 'EEM_Event', |
|
68 | - 'edit' => 'EEM_Event', |
|
69 | - ); |
|
70 | - $this->_cpt_edit_routes = array( |
|
71 | - 'espresso_events' => 'edit', |
|
72 | - ); |
|
73 | - add_action( |
|
74 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
75 | - array($this, 'verify_event_edit'), |
|
76 | - 10, |
|
77 | - 2 |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Sets the ajax hooks used for this admin page group. |
|
84 | - */ |
|
85 | - protected function _ajax_hooks() |
|
86 | - { |
|
87 | - add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets the page properties for this admin page group. |
|
93 | - */ |
|
94 | - protected function _define_page_props() |
|
95 | - { |
|
96 | - $this->_admin_page_title = EVENTS_LABEL; |
|
97 | - $this->_labels = array( |
|
98 | - 'buttons' => array( |
|
99 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
100 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
101 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
102 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
103 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
104 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
105 | - ), |
|
106 | - 'editor_title' => array( |
|
107 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
108 | - ), |
|
109 | - 'publishbox' => array( |
|
110 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
111 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
112 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
113 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
114 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
115 | - ), |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Sets the page routes property for this admin page group. |
|
122 | - */ |
|
123 | - protected function _set_page_routes() |
|
124 | - { |
|
125 | - // load formatter helper |
|
126 | - // load field generator helper |
|
127 | - // is there a evt_id in the request? |
|
128 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
129 | - ? $this->_req_data['EVT_ID'] |
|
130 | - : 0; |
|
131 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
132 | - $this->_page_routes = array( |
|
133 | - 'default' => array( |
|
134 | - 'func' => '_events_overview_list_table', |
|
135 | - 'capability' => 'ee_read_events', |
|
136 | - ), |
|
137 | - 'create_new' => array( |
|
138 | - 'func' => '_create_new_cpt_item', |
|
139 | - 'capability' => 'ee_edit_events', |
|
140 | - ), |
|
141 | - 'edit' => array( |
|
142 | - 'func' => '_edit_cpt_item', |
|
143 | - 'capability' => 'ee_edit_event', |
|
144 | - 'obj_id' => $evt_id, |
|
145 | - ), |
|
146 | - 'copy_event' => array( |
|
147 | - 'func' => '_copy_events', |
|
148 | - 'capability' => 'ee_edit_event', |
|
149 | - 'obj_id' => $evt_id, |
|
150 | - 'noheader' => true, |
|
151 | - ), |
|
152 | - 'trash_event' => array( |
|
153 | - 'func' => '_trash_or_restore_event', |
|
154 | - 'args' => array('event_status' => 'trash'), |
|
155 | - 'capability' => 'ee_delete_event', |
|
156 | - 'obj_id' => $evt_id, |
|
157 | - 'noheader' => true, |
|
158 | - ), |
|
159 | - 'trash_events' => array( |
|
160 | - 'func' => '_trash_or_restore_events', |
|
161 | - 'args' => array('event_status' => 'trash'), |
|
162 | - 'capability' => 'ee_delete_events', |
|
163 | - 'noheader' => true, |
|
164 | - ), |
|
165 | - 'restore_event' => array( |
|
166 | - 'func' => '_trash_or_restore_event', |
|
167 | - 'args' => array('event_status' => 'draft'), |
|
168 | - 'capability' => 'ee_delete_event', |
|
169 | - 'obj_id' => $evt_id, |
|
170 | - 'noheader' => true, |
|
171 | - ), |
|
172 | - 'restore_events' => array( |
|
173 | - 'func' => '_trash_or_restore_events', |
|
174 | - 'args' => array('event_status' => 'draft'), |
|
175 | - 'capability' => 'ee_delete_events', |
|
176 | - 'noheader' => true, |
|
177 | - ), |
|
178 | - 'delete_event' => array( |
|
179 | - 'func' => '_delete_event', |
|
180 | - 'capability' => 'ee_delete_event', |
|
181 | - 'obj_id' => $evt_id, |
|
182 | - 'noheader' => true, |
|
183 | - ), |
|
184 | - 'delete_events' => array( |
|
185 | - 'func' => '_delete_events', |
|
186 | - 'capability' => 'ee_delete_events', |
|
187 | - 'noheader' => true, |
|
188 | - ), |
|
189 | - 'view_report' => array( |
|
190 | - 'func' => '_view_report', |
|
191 | - 'capablity' => 'ee_edit_events', |
|
192 | - ), |
|
193 | - 'default_event_settings' => array( |
|
194 | - 'func' => '_default_event_settings', |
|
195 | - 'capability' => 'manage_options', |
|
196 | - ), |
|
197 | - 'update_default_event_settings' => array( |
|
198 | - 'func' => '_update_default_event_settings', |
|
199 | - 'capability' => 'manage_options', |
|
200 | - 'noheader' => true, |
|
201 | - ), |
|
202 | - 'template_settings' => array( |
|
203 | - 'func' => '_template_settings', |
|
204 | - 'capability' => 'manage_options', |
|
205 | - ), |
|
206 | - // event category tab related |
|
207 | - 'add_category' => array( |
|
208 | - 'func' => '_category_details', |
|
209 | - 'capability' => 'ee_edit_event_category', |
|
210 | - 'args' => array('add'), |
|
211 | - ), |
|
212 | - 'edit_category' => array( |
|
213 | - 'func' => '_category_details', |
|
214 | - 'capability' => 'ee_edit_event_category', |
|
215 | - 'args' => array('edit'), |
|
216 | - ), |
|
217 | - 'delete_categories' => array( |
|
218 | - 'func' => '_delete_categories', |
|
219 | - 'capability' => 'ee_delete_event_category', |
|
220 | - 'noheader' => true, |
|
221 | - ), |
|
222 | - 'delete_category' => array( |
|
223 | - 'func' => '_delete_categories', |
|
224 | - 'capability' => 'ee_delete_event_category', |
|
225 | - 'noheader' => true, |
|
226 | - ), |
|
227 | - 'insert_category' => array( |
|
228 | - 'func' => '_insert_or_update_category', |
|
229 | - 'args' => array('new_category' => true), |
|
230 | - 'capability' => 'ee_edit_event_category', |
|
231 | - 'noheader' => true, |
|
232 | - ), |
|
233 | - 'update_category' => array( |
|
234 | - 'func' => '_insert_or_update_category', |
|
235 | - 'args' => array('new_category' => false), |
|
236 | - 'capability' => 'ee_edit_event_category', |
|
237 | - 'noheader' => true, |
|
238 | - ), |
|
239 | - 'category_list' => array( |
|
240 | - 'func' => '_category_list_table', |
|
241 | - 'capability' => 'ee_manage_event_categories', |
|
242 | - ), |
|
243 | - 'preview_deletion' => [ |
|
244 | - 'func' => 'previewDeletion', |
|
245 | - 'capability' => 'ee_delete_events', |
|
246 | - ], |
|
247 | - 'confirm_deletion' => [ |
|
248 | - 'func' => 'confirmDeletion', |
|
249 | - 'capability' => 'ee_delete_events', |
|
250 | - 'noheader' => true, |
|
251 | - ] |
|
252 | - ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Set the _page_config property for this admin page group. |
|
258 | - */ |
|
259 | - protected function _set_page_config() |
|
260 | - { |
|
261 | - $this->_page_config = array( |
|
262 | - 'default' => array( |
|
263 | - 'nav' => array( |
|
264 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
265 | - 'order' => 10, |
|
266 | - ), |
|
267 | - 'list_table' => 'Events_Admin_List_Table', |
|
268 | - 'help_tabs' => array( |
|
269 | - 'events_overview_help_tab' => array( |
|
270 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
271 | - 'filename' => 'events_overview', |
|
272 | - ), |
|
273 | - 'events_overview_table_column_headings_help_tab' => array( |
|
274 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
275 | - 'filename' => 'events_overview_table_column_headings', |
|
276 | - ), |
|
277 | - 'events_overview_filters_help_tab' => array( |
|
278 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
279 | - 'filename' => 'events_overview_filters', |
|
280 | - ), |
|
281 | - 'events_overview_view_help_tab' => array( |
|
282 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
283 | - 'filename' => 'events_overview_views', |
|
284 | - ), |
|
285 | - 'events_overview_other_help_tab' => array( |
|
286 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
287 | - 'filename' => 'events_overview_other', |
|
288 | - ), |
|
289 | - ), |
|
290 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
291 | - // 'help_tour' => array( |
|
292 | - // 'Event_Overview_Help_Tour', |
|
293 | - // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
294 | - // ), |
|
295 | - 'qtips' => array( |
|
296 | - 'EE_Event_List_Table_Tips', |
|
297 | - ), |
|
298 | - 'require_nonce' => false, |
|
299 | - ), |
|
300 | - 'create_new' => array( |
|
301 | - 'nav' => array( |
|
302 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
303 | - 'order' => 5, |
|
304 | - 'persistent' => false, |
|
305 | - ), |
|
306 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
307 | - 'help_tabs' => array( |
|
308 | - 'event_editor_help_tab' => array( |
|
309 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
310 | - 'filename' => 'event_editor', |
|
311 | - ), |
|
312 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
313 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
314 | - 'filename' => 'event_editor_title_richtexteditor', |
|
315 | - ), |
|
316 | - 'event_editor_venue_details_help_tab' => array( |
|
317 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
318 | - 'filename' => 'event_editor_venue_details', |
|
319 | - ), |
|
320 | - 'event_editor_event_datetimes_help_tab' => array( |
|
321 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
322 | - 'filename' => 'event_editor_event_datetimes', |
|
323 | - ), |
|
324 | - 'event_editor_event_tickets_help_tab' => array( |
|
325 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
326 | - 'filename' => 'event_editor_event_tickets', |
|
327 | - ), |
|
328 | - 'event_editor_event_registration_options_help_tab' => array( |
|
329 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
330 | - 'filename' => 'event_editor_event_registration_options', |
|
331 | - ), |
|
332 | - 'event_editor_tags_categories_help_tab' => array( |
|
333 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
334 | - 'filename' => 'event_editor_tags_categories', |
|
335 | - ), |
|
336 | - 'event_editor_questions_registrants_help_tab' => array( |
|
337 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
338 | - 'filename' => 'event_editor_questions_registrants', |
|
339 | - ), |
|
340 | - 'event_editor_save_new_event_help_tab' => array( |
|
341 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
342 | - 'filename' => 'event_editor_save_new_event', |
|
343 | - ), |
|
344 | - 'event_editor_other_help_tab' => array( |
|
345 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
346 | - 'filename' => 'event_editor_other', |
|
347 | - ), |
|
348 | - ), |
|
349 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
350 | - // 'help_tour' => array( |
|
351 | - // 'Event_Editor_Help_Tour', |
|
352 | - // ), |
|
353 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
354 | - 'require_nonce' => false, |
|
355 | - ), |
|
356 | - 'edit' => array( |
|
357 | - 'nav' => array( |
|
358 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
359 | - 'order' => 5, |
|
360 | - 'persistent' => false, |
|
361 | - 'url' => isset($this->_req_data['post']) |
|
362 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
363 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
364 | - $this->_current_page_view_url |
|
365 | - ) |
|
366 | - : $this->_admin_base_url, |
|
367 | - ), |
|
368 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
369 | - 'help_tabs' => array( |
|
370 | - 'event_editor_help_tab' => array( |
|
371 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
372 | - 'filename' => 'event_editor', |
|
373 | - ), |
|
374 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
375 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
376 | - 'filename' => 'event_editor_title_richtexteditor', |
|
377 | - ), |
|
378 | - 'event_editor_venue_details_help_tab' => array( |
|
379 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
380 | - 'filename' => 'event_editor_venue_details', |
|
381 | - ), |
|
382 | - 'event_editor_event_datetimes_help_tab' => array( |
|
383 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
384 | - 'filename' => 'event_editor_event_datetimes', |
|
385 | - ), |
|
386 | - 'event_editor_event_tickets_help_tab' => array( |
|
387 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
388 | - 'filename' => 'event_editor_event_tickets', |
|
389 | - ), |
|
390 | - 'event_editor_event_registration_options_help_tab' => array( |
|
391 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
392 | - 'filename' => 'event_editor_event_registration_options', |
|
393 | - ), |
|
394 | - 'event_editor_tags_categories_help_tab' => array( |
|
395 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
396 | - 'filename' => 'event_editor_tags_categories', |
|
397 | - ), |
|
398 | - 'event_editor_questions_registrants_help_tab' => array( |
|
399 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
400 | - 'filename' => 'event_editor_questions_registrants', |
|
401 | - ), |
|
402 | - 'event_editor_save_new_event_help_tab' => array( |
|
403 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
404 | - 'filename' => 'event_editor_save_new_event', |
|
405 | - ), |
|
406 | - 'event_editor_other_help_tab' => array( |
|
407 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
408 | - 'filename' => 'event_editor_other', |
|
409 | - ), |
|
410 | - ), |
|
411 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
412 | - 'require_nonce' => false, |
|
413 | - ), |
|
414 | - 'default_event_settings' => array( |
|
415 | - 'nav' => array( |
|
416 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
417 | - 'order' => 40, |
|
418 | - ), |
|
419 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
420 | - 'labels' => array( |
|
421 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
422 | - ), |
|
423 | - 'help_tabs' => array( |
|
424 | - 'default_settings_help_tab' => array( |
|
425 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
426 | - 'filename' => 'events_default_settings', |
|
427 | - ), |
|
428 | - 'default_settings_status_help_tab' => array( |
|
429 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
430 | - 'filename' => 'events_default_settings_status', |
|
431 | - ), |
|
432 | - 'default_maximum_tickets_help_tab' => array( |
|
433 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
434 | - 'filename' => 'events_default_settings_max_tickets', |
|
435 | - ), |
|
436 | - ), |
|
437 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
438 | - // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
439 | - 'require_nonce' => false, |
|
440 | - ), |
|
441 | - // template settings |
|
442 | - 'template_settings' => array( |
|
443 | - 'nav' => array( |
|
444 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
445 | - 'order' => 30, |
|
446 | - ), |
|
447 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
448 | - 'help_tabs' => array( |
|
449 | - 'general_settings_templates_help_tab' => array( |
|
450 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
451 | - 'filename' => 'general_settings_templates', |
|
452 | - ), |
|
453 | - ), |
|
454 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
455 | - // 'help_tour' => array('Templates_Help_Tour'), |
|
456 | - 'require_nonce' => false, |
|
457 | - ), |
|
458 | - // event category stuff |
|
459 | - 'add_category' => array( |
|
460 | - 'nav' => array( |
|
461 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
462 | - 'order' => 15, |
|
463 | - 'persistent' => false, |
|
464 | - ), |
|
465 | - 'help_tabs' => array( |
|
466 | - 'add_category_help_tab' => array( |
|
467 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
468 | - 'filename' => 'events_add_category', |
|
469 | - ), |
|
470 | - ), |
|
471 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
472 | - // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
473 | - 'metaboxes' => array('_publish_post_box'), |
|
474 | - 'require_nonce' => false, |
|
475 | - ), |
|
476 | - 'edit_category' => array( |
|
477 | - 'nav' => array( |
|
478 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
479 | - 'order' => 15, |
|
480 | - 'persistent' => false, |
|
481 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
482 | - ? add_query_arg( |
|
483 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
484 | - $this->_current_page_view_url |
|
485 | - ) |
|
486 | - : $this->_admin_base_url, |
|
487 | - ), |
|
488 | - 'help_tabs' => array( |
|
489 | - 'edit_category_help_tab' => array( |
|
490 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
491 | - 'filename' => 'events_edit_category', |
|
492 | - ), |
|
493 | - ), |
|
494 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
495 | - 'metaboxes' => array('_publish_post_box'), |
|
496 | - 'require_nonce' => false, |
|
497 | - ), |
|
498 | - 'category_list' => array( |
|
499 | - 'nav' => array( |
|
500 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
501 | - 'order' => 20, |
|
502 | - ), |
|
503 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
504 | - 'help_tabs' => array( |
|
505 | - 'events_categories_help_tab' => array( |
|
506 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
507 | - 'filename' => 'events_categories', |
|
508 | - ), |
|
509 | - 'events_categories_table_column_headings_help_tab' => array( |
|
510 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
511 | - 'filename' => 'events_categories_table_column_headings', |
|
512 | - ), |
|
513 | - 'events_categories_view_help_tab' => array( |
|
514 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
515 | - 'filename' => 'events_categories_views', |
|
516 | - ), |
|
517 | - 'events_categories_other_help_tab' => array( |
|
518 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
519 | - 'filename' => 'events_categories_other', |
|
520 | - ), |
|
521 | - ), |
|
522 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
523 | - // 'help_tour' => array( |
|
524 | - // 'Event_Categories_Help_Tour', |
|
525 | - // ), |
|
526 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
527 | - 'require_nonce' => false, |
|
528 | - ), |
|
529 | - 'preview_deletion' => array( |
|
530 | - 'nav' => array( |
|
531 | - 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
532 | - 'order' => 15, |
|
533 | - 'persistent' => false, |
|
534 | - 'url' => '', |
|
535 | - ), |
|
536 | - 'require_nonce' => false |
|
537 | - ) |
|
538 | - ); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
544 | - */ |
|
545 | - protected function _add_screen_options() |
|
546 | - { |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Implementing the screen options for the 'default' route. |
|
552 | - */ |
|
553 | - protected function _add_screen_options_default() |
|
554 | - { |
|
555 | - $this->_per_page_screen_option(); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Implementing screen options for the category list route. |
|
561 | - */ |
|
562 | - protected function _add_screen_options_category_list() |
|
563 | - { |
|
564 | - $page_title = $this->_admin_page_title; |
|
565 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
566 | - $this->_per_page_screen_option(); |
|
567 | - $this->_admin_page_title = $page_title; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Used to register any global feature pointers for the admin page group. |
|
573 | - */ |
|
574 | - protected function _add_feature_pointers() |
|
575 | - { |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
581 | - */ |
|
582 | - public function load_scripts_styles() |
|
583 | - { |
|
584 | - wp_register_style( |
|
585 | - 'events-admin-css', |
|
586 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
587 | - array(), |
|
588 | - EVENT_ESPRESSO_VERSION |
|
589 | - ); |
|
590 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
591 | - wp_enqueue_style('events-admin-css'); |
|
592 | - wp_enqueue_style('ee-cat-admin'); |
|
593 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
594 | - // registers for all views |
|
595 | - // scripts |
|
596 | - wp_register_script( |
|
597 | - 'event_editor_js', |
|
598 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
599 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
600 | - EVENT_ESPRESSO_VERSION, |
|
601 | - true |
|
602 | - ); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * Enqueuing scripts and styles specific to this view |
|
608 | - */ |
|
609 | - public function load_scripts_styles_create_new() |
|
610 | - { |
|
611 | - $this->load_scripts_styles_edit(); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Enqueuing scripts and styles specific to this view |
|
617 | - */ |
|
618 | - public function load_scripts_styles_edit() |
|
619 | - { |
|
620 | - // styles |
|
621 | - wp_enqueue_style('espresso-ui-theme'); |
|
622 | - wp_register_style( |
|
623 | - 'event-editor-css', |
|
624 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
625 | - array('ee-admin-css'), |
|
626 | - EVENT_ESPRESSO_VERSION |
|
627 | - ); |
|
628 | - wp_enqueue_style('event-editor-css'); |
|
629 | - // scripts |
|
630 | - wp_register_script( |
|
631 | - 'event-datetime-metabox', |
|
632 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
633 | - array('event_editor_js', 'ee-datepicker'), |
|
634 | - EVENT_ESPRESSO_VERSION |
|
635 | - ); |
|
636 | - wp_enqueue_script('event-datetime-metabox'); |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * Populating the _views property for the category list table view. |
|
642 | - */ |
|
643 | - protected function _set_list_table_views_category_list() |
|
644 | - { |
|
645 | - $this->_views = array( |
|
646 | - 'all' => array( |
|
647 | - 'slug' => 'all', |
|
648 | - 'label' => esc_html__('All', 'event_espresso'), |
|
649 | - 'count' => 0, |
|
650 | - 'bulk_action' => array( |
|
651 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
652 | - ), |
|
653 | - ), |
|
654 | - ); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
660 | - */ |
|
661 | - public function admin_init() |
|
662 | - { |
|
663 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
664 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
665 | - 'event_espresso' |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
672 | - * group. |
|
673 | - */ |
|
674 | - public function admin_notices() |
|
675 | - { |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
681 | - * this admin page group. |
|
682 | - */ |
|
683 | - public function admin_footer_scripts() |
|
684 | - { |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
690 | - * warning (via EE_Error::add_error()); |
|
691 | - * |
|
692 | - * @param EE_Event $event Event object |
|
693 | - * @param string $req_type |
|
694 | - * @return void |
|
695 | - * @throws EE_Error |
|
696 | - * @access public |
|
697 | - */ |
|
698 | - public function verify_event_edit($event = null, $req_type = '') |
|
699 | - { |
|
700 | - // don't need to do this when processing |
|
701 | - if (! empty($req_type)) { |
|
702 | - return; |
|
703 | - } |
|
704 | - // no event? |
|
705 | - if (empty($event)) { |
|
706 | - // set event |
|
707 | - $event = $this->_cpt_model_obj; |
|
708 | - } |
|
709 | - // STILL no event? |
|
710 | - if (! $event instanceof EE_Event) { |
|
711 | - return; |
|
712 | - } |
|
713 | - $orig_status = $event->status(); |
|
714 | - // first check if event is active. |
|
715 | - if ( |
|
716 | - $orig_status === EEM_Event::cancelled |
|
717 | - || $orig_status === EEM_Event::postponed |
|
718 | - || $event->is_expired() |
|
719 | - || $event->is_inactive() |
|
720 | - ) { |
|
721 | - return; |
|
722 | - } |
|
723 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
724 | - if ($event->is_sold_out(true)) { |
|
725 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
726 | - EE_Error::add_attention( |
|
727 | - sprintf( |
|
728 | - esc_html__( |
|
729 | - '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.', |
|
730 | - 'event_espresso' |
|
731 | - ), |
|
732 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
733 | - ) |
|
734 | - ); |
|
735 | - } |
|
736 | - return; |
|
737 | - } elseif ($orig_status === EEM_Event::sold_out) { |
|
738 | - EE_Error::add_attention( |
|
739 | - sprintf( |
|
740 | - esc_html__( |
|
741 | - '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.', |
|
742 | - 'event_espresso' |
|
743 | - ), |
|
744 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
745 | - ) |
|
746 | - ); |
|
747 | - } |
|
748 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
749 | - if (! $event->tickets_on_sale()) { |
|
750 | - return; |
|
751 | - } |
|
752 | - // made it here so show warning |
|
753 | - $this->_edit_event_warning(); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
759 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
760 | - * |
|
761 | - * @access protected |
|
762 | - * @return void |
|
763 | - */ |
|
764 | - protected function _edit_event_warning() |
|
765 | - { |
|
766 | - // we don't want to add warnings during these requests |
|
767 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
768 | - return; |
|
769 | - } |
|
770 | - EE_Error::add_attention( |
|
771 | - sprintf( |
|
772 | - esc_html__( |
|
773 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
774 | - 'event_espresso' |
|
775 | - ), |
|
776 | - '<a class="espresso-help-tab-lnk">', |
|
777 | - '</a>' |
|
778 | - ) |
|
779 | - ); |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
785 | - * Otherwise, do the normal logic |
|
786 | - * |
|
787 | - * @return string |
|
788 | - * @throws \EE_Error |
|
789 | - */ |
|
790 | - protected function _create_new_cpt_item() |
|
791 | - { |
|
792 | - $has_timezone_string = get_option('timezone_string'); |
|
793 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
794 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
795 | - EE_Error::add_attention( |
|
796 | - sprintf( |
|
797 | - esc_html__( |
|
798 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
799 | - 'event_espresso' |
|
800 | - ), |
|
801 | - '<br>', |
|
802 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
803 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
804 | - . '</select>', |
|
805 | - '<button class="button button-secondary timezone-submit">', |
|
806 | - '</button><span class="spinner"></span>' |
|
807 | - ), |
|
808 | - __FILE__, |
|
809 | - __FUNCTION__, |
|
810 | - __LINE__ |
|
811 | - ); |
|
812 | - } |
|
813 | - return parent::_create_new_cpt_item(); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - /** |
|
818 | - * Sets the _views property for the default route in this admin page group. |
|
819 | - */ |
|
820 | - protected function _set_list_table_views_default() |
|
821 | - { |
|
822 | - $this->_views = array( |
|
823 | - 'all' => array( |
|
824 | - 'slug' => 'all', |
|
825 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
826 | - 'count' => 0, |
|
827 | - 'bulk_action' => array( |
|
828 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
829 | - ), |
|
830 | - ), |
|
831 | - 'draft' => array( |
|
832 | - 'slug' => 'draft', |
|
833 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
834 | - 'count' => 0, |
|
835 | - 'bulk_action' => array( |
|
836 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
837 | - ), |
|
838 | - ), |
|
839 | - ); |
|
840 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
841 | - $this->_views['trash'] = array( |
|
842 | - 'slug' => 'trash', |
|
843 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
844 | - 'count' => 0, |
|
845 | - 'bulk_action' => array( |
|
846 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
847 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
848 | - ), |
|
849 | - ); |
|
850 | - } |
|
851 | - } |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * Provides the legend item array for the default list table view. |
|
856 | - * |
|
857 | - * @return array |
|
858 | - */ |
|
859 | - protected function _event_legend_items() |
|
860 | - { |
|
861 | - $items = array( |
|
862 | - 'view_details' => array( |
|
863 | - 'class' => 'dashicons dashicons-search', |
|
864 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
865 | - ), |
|
866 | - 'edit_event' => array( |
|
867 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
868 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
869 | - ), |
|
870 | - 'view_attendees' => array( |
|
871 | - 'class' => 'dashicons dashicons-groups', |
|
872 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
873 | - ), |
|
874 | - ); |
|
875 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
876 | - $statuses = array( |
|
877 | - 'sold_out_status' => array( |
|
878 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
879 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
880 | - ), |
|
881 | - 'active_status' => array( |
|
882 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
883 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
884 | - ), |
|
885 | - 'upcoming_status' => array( |
|
886 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
887 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
888 | - ), |
|
889 | - 'postponed_status' => array( |
|
890 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
891 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
892 | - ), |
|
893 | - 'cancelled_status' => array( |
|
894 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
895 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
896 | - ), |
|
897 | - 'expired_status' => array( |
|
898 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
899 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
900 | - ), |
|
901 | - 'inactive_status' => array( |
|
902 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
903 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
904 | - ), |
|
905 | - ); |
|
906 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
907 | - return array_merge($items, $statuses); |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - /** |
|
912 | - * @return EEM_Event |
|
913 | - */ |
|
914 | - private function _event_model() |
|
915 | - { |
|
916 | - if (! $this->_event_model instanceof EEM_Event) { |
|
917 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
918 | - } |
|
919 | - return $this->_event_model; |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * Adds extra buttons to the WP CPT permalink field row. |
|
925 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
926 | - * |
|
927 | - * @param string $return the current html |
|
928 | - * @param int $id the post id for the page |
|
929 | - * @param string $new_title What the title is |
|
930 | - * @param string $new_slug what the slug is |
|
931 | - * @return string The new html string for the permalink area |
|
932 | - */ |
|
933 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
934 | - { |
|
935 | - // make sure this is only when editing |
|
936 | - if (! empty($id)) { |
|
937 | - $post = get_post($id); |
|
938 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
939 | - . esc_html__('Shortcode', 'event_espresso') |
|
940 | - . '</a> '; |
|
941 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
942 | - . $post->ID |
|
943 | - . ']">'; |
|
944 | - } |
|
945 | - return $return; |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * _events_overview_list_table |
|
951 | - * This contains the logic for showing the events_overview list |
|
952 | - * |
|
953 | - * @access protected |
|
954 | - * @return void |
|
955 | - * @throws \EE_Error |
|
956 | - */ |
|
957 | - protected function _events_overview_list_table() |
|
958 | - { |
|
959 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
960 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
961 | - ? (array) $this->_template_args['after_list_table'] |
|
962 | - : array(); |
|
963 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
964 | - . EEH_Template::get_button_or_link( |
|
965 | - get_post_type_archive_link('espresso_events'), |
|
966 | - esc_html__("View Event Archive Page", "event_espresso"), |
|
967 | - 'button' |
|
968 | - ); |
|
969 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
970 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
971 | - 'create_new', |
|
972 | - 'add', |
|
973 | - array(), |
|
974 | - 'add-new-h2' |
|
975 | - ); |
|
976 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
977 | - } |
|
978 | - |
|
979 | - |
|
980 | - /** |
|
981 | - * this allows for extra misc actions in the default WP publish box |
|
982 | - * |
|
983 | - * @return void |
|
984 | - */ |
|
985 | - public function extra_misc_actions_publish_box() |
|
986 | - { |
|
987 | - $this->_generate_publish_box_extra_content(); |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - /** |
|
992 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
993 | - * saved. |
|
994 | - * Typically you would use this to save any additional data. |
|
995 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
996 | - * ALSO very important. When a post transitions from scheduled to published, |
|
997 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
998 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
999 | - * |
|
1000 | - * @access protected |
|
1001 | - * @abstract |
|
1002 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
1003 | - * @param object $post The post object of the cpt that was saved. |
|
1004 | - * @return void |
|
1005 | - * @throws \EE_Error |
|
1006 | - */ |
|
1007 | - protected function _insert_update_cpt_item($post_id, $post) |
|
1008 | - { |
|
1009 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1010 | - // get out we're not processing an event save. |
|
1011 | - return; |
|
1012 | - } |
|
1013 | - $event_values = array( |
|
1014 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
1015 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
1016 | - 'EVT_additional_limit' => min( |
|
1017 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1018 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
1019 | - ), |
|
1020 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
1021 | - ? $this->_req_data['EVT_default_registration_status'] |
|
1022 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
1023 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
1024 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
1025 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
1026 | - ? $this->_req_data['timezone_string'] : null, |
|
1027 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
1028 | - ? $this->_req_data['externalURL'] : null, |
|
1029 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
1030 | - ? $this->_req_data['event_phone'] : null, |
|
1031 | - ); |
|
1032 | - // update event |
|
1033 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1034 | - // 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! |
|
1035 | - $get_one_where = array( |
|
1036 | - $this->_event_model()->primary_key_name() => $post_id, |
|
1037 | - 'OR' => array( |
|
1038 | - 'status' => $post->post_status, |
|
1039 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1040 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
1041 | - 'status*1' => $this->_req_data['original_post_status'], |
|
1042 | - ), |
|
1043 | - ); |
|
1044 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
1045 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1046 | - $event_update_callbacks = apply_filters( |
|
1047 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1048 | - array( |
|
1049 | - array($this, '_default_venue_update'), |
|
1050 | - array($this, '_default_tickets_update'), |
|
1051 | - ) |
|
1052 | - ); |
|
1053 | - $att_success = true; |
|
1054 | - foreach ($event_update_callbacks as $e_callback) { |
|
1055 | - $_success = is_callable($e_callback) |
|
1056 | - ? call_user_func($e_callback, $event, $this->_req_data) |
|
1057 | - : false; |
|
1058 | - // if ANY of these updates fail then we want the appropriate global error message |
|
1059 | - $att_success = ! $att_success ? $att_success : $_success; |
|
1060 | - } |
|
1061 | - // any errors? |
|
1062 | - if ($success && false === $att_success) { |
|
1063 | - EE_Error::add_error( |
|
1064 | - esc_html__( |
|
1065 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1066 | - 'event_espresso' |
|
1067 | - ), |
|
1068 | - __FILE__, |
|
1069 | - __FUNCTION__, |
|
1070 | - __LINE__ |
|
1071 | - ); |
|
1072 | - } elseif ($success === false) { |
|
1073 | - EE_Error::add_error( |
|
1074 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1075 | - __FILE__, |
|
1076 | - __FUNCTION__, |
|
1077 | - __LINE__ |
|
1078 | - ); |
|
1079 | - } |
|
1080 | - } |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * @see parent::restore_item() |
|
1085 | - * @param int $post_id |
|
1086 | - * @param int $revision_id |
|
1087 | - */ |
|
1088 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
1089 | - { |
|
1090 | - // copy existing event meta to new post |
|
1091 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1092 | - if ($post_evt instanceof EE_Event) { |
|
1093 | - // meta revision restore |
|
1094 | - $post_evt->restore_revision($revision_id); |
|
1095 | - // related objs restore |
|
1096 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1097 | - } |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Attach the venue to the Event |
|
1103 | - * |
|
1104 | - * @param \EE_Event $evtobj Event Object to add the venue to |
|
1105 | - * @param array $data The request data from the form |
|
1106 | - * @return bool Success or fail. |
|
1107 | - */ |
|
1108 | - protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
1109 | - { |
|
1110 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1111 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1112 | - $rows_affected = null; |
|
1113 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1114 | - // very important. If we don't have a venue name... |
|
1115 | - // then we'll get out because not necessary to create empty venue |
|
1116 | - if (empty($data['venue_title'])) { |
|
1117 | - return false; |
|
1118 | - } |
|
1119 | - $venue_array = array( |
|
1120 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1121 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1122 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1123 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1124 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1125 | - : null, |
|
1126 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1127 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1128 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1129 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1130 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1131 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1132 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1133 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1134 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1135 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1136 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1137 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1138 | - 'status' => 'publish', |
|
1139 | - ); |
|
1140 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1141 | - if (! empty($venue_id)) { |
|
1142 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1143 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1144 | - // 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. |
|
1145 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1146 | - return $rows_affected > 0 ? true : false; |
|
1147 | - } else { |
|
1148 | - // we insert the venue |
|
1149 | - $venue_id = $venue_model->insert($venue_array); |
|
1150 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1151 | - return ! empty($venue_id) ? true : false; |
|
1152 | - } |
|
1153 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
1154 | - } |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1159 | - * |
|
1160 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
1161 | - * @param array $data The request data from the form |
|
1162 | - * @return array |
|
1163 | - */ |
|
1164 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1165 | - { |
|
1166 | - $success = true; |
|
1167 | - $saved_dtt = null; |
|
1168 | - $saved_tickets = array(); |
|
1169 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1170 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1171 | - // trim all values to ensure any excess whitespace is removed. |
|
1172 | - $dtt = array_map('trim', $dtt); |
|
1173 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1174 | - : $dtt['DTT_EVT_start']; |
|
1175 | - $datetime_values = array( |
|
1176 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1177 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1178 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1179 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1180 | - 'DTT_order' => $row, |
|
1181 | - ); |
|
1182 | - // 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. |
|
1183 | - if (! empty($dtt['DTT_ID'])) { |
|
1184 | - $DTM = EE_Registry::instance() |
|
1185 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1186 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
1187 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
1188 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
1189 | - foreach ($datetime_values as $field => $value) { |
|
1190 | - $DTM->set($field, $value); |
|
1191 | - } |
|
1192 | - // 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. |
|
1193 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1194 | - } else { |
|
1195 | - $DTM = EE_Registry::instance()->load_class( |
|
1196 | - 'Datetime', |
|
1197 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1198 | - false, |
|
1199 | - false |
|
1200 | - ); |
|
1201 | - foreach ($datetime_values as $field => $value) { |
|
1202 | - $DTM->set($field, $value); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - $DTM->save(); |
|
1206 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1207 | - // load DTT helper |
|
1208 | - // 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. |
|
1209 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1210 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1211 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1212 | - $DTT->save(); |
|
1213 | - } |
|
1214 | - // 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. |
|
1215 | - $saved_dtt = $DTT; |
|
1216 | - $success = ! $success ? $success : $DTT; |
|
1217 | - // if ANY of these updates fail then we want the appropriate global error message. |
|
1218 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1219 | - } |
|
1220 | - // no dtts get deleted so we don't do any of that logic here. |
|
1221 | - // update tickets next |
|
1222 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1223 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1224 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1225 | - $update_prices = false; |
|
1226 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1227 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1228 | - // trim inputs to ensure any excess whitespace is removed. |
|
1229 | - $tkt = array_map('trim', $tkt); |
|
1230 | - if (empty($tkt['TKT_start_date'])) { |
|
1231 | - // let's use now in the set timezone. |
|
1232 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1233 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1234 | - } |
|
1235 | - if (empty($tkt['TKT_end_date'])) { |
|
1236 | - // use the start date of the first datetime |
|
1237 | - $dtt = $evtobj->first_datetime(); |
|
1238 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1239 | - $incoming_date_formats[0], |
|
1240 | - $incoming_date_formats[1] |
|
1241 | - ); |
|
1242 | - } |
|
1243 | - $TKT_values = array( |
|
1244 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1245 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1246 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1247 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1248 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1249 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1250 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1251 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1252 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1253 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1254 | - 'TKT_row' => $row, |
|
1255 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1256 | - 'TKT_price' => $ticket_price, |
|
1257 | - ); |
|
1258 | - // 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. |
|
1259 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1260 | - $TKT_values['TKT_ID'] = 0; |
|
1261 | - $TKT_values['TKT_is_default'] = 0; |
|
1262 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1263 | - $update_prices = true; |
|
1264 | - } |
|
1265 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1266 | - // 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. |
|
1267 | - // 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. |
|
1268 | - if (! empty($tkt['TKT_ID'])) { |
|
1269 | - $TKT = EE_Registry::instance() |
|
1270 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1271 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
1272 | - if ($TKT instanceof EE_Ticket) { |
|
1273 | - $ticket_sold = $TKT->count_related( |
|
1274 | - 'Registration', |
|
1275 | - array( |
|
1276 | - array( |
|
1277 | - 'STS_ID' => array( |
|
1278 | - 'NOT IN', |
|
1279 | - array(EEM_Registration::status_id_incomplete), |
|
1280 | - ), |
|
1281 | - ), |
|
1282 | - ) |
|
1283 | - ) > 0 ? true : false; |
|
1284 | - // 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. |
|
1285 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
1286 | - && ! $TKT->get('TKT_deleted'); |
|
1287 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1288 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1289 | - // set new values |
|
1290 | - foreach ($TKT_values as $field => $value) { |
|
1291 | - if ($field == 'TKT_qty') { |
|
1292 | - $TKT->set_qty($value); |
|
1293 | - } else { |
|
1294 | - $TKT->set($field, $value); |
|
1295 | - } |
|
1296 | - } |
|
1297 | - // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1298 | - if ($create_new_TKT) { |
|
1299 | - // archive the old ticket first |
|
1300 | - $TKT->set('TKT_deleted', 1); |
|
1301 | - $TKT->save(); |
|
1302 | - // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1303 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1304 | - // 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. |
|
1305 | - $TKT = clone $TKT; |
|
1306 | - $TKT->set('TKT_ID', 0); |
|
1307 | - $TKT->set('TKT_deleted', 0); |
|
1308 | - $TKT->set('TKT_price', $ticket_price); |
|
1309 | - $TKT->set('TKT_sold', 0); |
|
1310 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1311 | - $update_prices = true; |
|
1312 | - } |
|
1313 | - // make sure price is set if it hasn't been already |
|
1314 | - $TKT->set('TKT_price', $ticket_price); |
|
1315 | - } |
|
1316 | - } else { |
|
1317 | - // no TKT_id so a new TKT |
|
1318 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1319 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1320 | - if ($TKT instanceof EE_Ticket) { |
|
1321 | - // need to reset values to properly account for the date formats |
|
1322 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1323 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1324 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
1325 | - // set new values |
|
1326 | - foreach ($TKT_values as $field => $value) { |
|
1327 | - if ($field == 'TKT_qty') { |
|
1328 | - $TKT->set_qty($value); |
|
1329 | - } else { |
|
1330 | - $TKT->set($field, $value); |
|
1331 | - } |
|
1332 | - } |
|
1333 | - $update_prices = true; |
|
1334 | - } |
|
1335 | - } |
|
1336 | - // cap ticket qty by datetime reg limits |
|
1337 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1338 | - // update ticket. |
|
1339 | - $TKT->save(); |
|
1340 | - // 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. |
|
1341 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1342 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1343 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1344 | - $TKT->save(); |
|
1345 | - } |
|
1346 | - // initially let's add the ticket to the dtt |
|
1347 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1348 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1349 | - // add prices to ticket |
|
1350 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1351 | - } |
|
1352 | - // 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. |
|
1353 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1354 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1355 | - foreach ($tickets_removed as $id) { |
|
1356 | - $id = absint($id); |
|
1357 | - // get the ticket for this id |
|
1358 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1359 | - if (! $tkt_to_remove instanceof EE_Ticket) { |
|
1360 | - continue; |
|
1361 | - } |
|
1362 | - |
|
1363 | - // 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) |
|
1364 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1365 | - foreach ($dtts as $dtt) { |
|
1366 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1367 | - } |
|
1368 | - // 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)) |
|
1369 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
1370 | - // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1371 | - $tkt_to_remove->delete_permanently(); |
|
1372 | - } |
|
1373 | - return array($saved_dtt, $saved_tickets); |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * This attaches a list of given prices to a ticket. |
|
1379 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1380 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1381 | - * price info and prices are automatically "archived" via the ticket. |
|
1382 | - * |
|
1383 | - * @access private |
|
1384 | - * @param array $prices Array of prices from the form. |
|
1385 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1386 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1387 | - * @return void |
|
1388 | - */ |
|
1389 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1390 | - { |
|
1391 | - foreach ($prices as $row => $prc) { |
|
1392 | - $PRC_values = array( |
|
1393 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1394 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1395 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1396 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1397 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1398 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1399 | - 'PRC_order' => $row, |
|
1400 | - ); |
|
1401 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1402 | - $PRC_values['PRC_ID'] = 0; |
|
1403 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1404 | - } else { |
|
1405 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1406 | - // update this price with new values |
|
1407 | - foreach ($PRC_values as $field => $newprc) { |
|
1408 | - $PRC->set($field, $newprc); |
|
1409 | - } |
|
1410 | - $PRC->save(); |
|
1411 | - } |
|
1412 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
1413 | - } |
|
1414 | - } |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * Add in our autosave ajax handlers |
|
1419 | - * |
|
1420 | - */ |
|
1421 | - protected function _ee_autosave_create_new() |
|
1422 | - { |
|
1423 | - } |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * More autosave handlers. |
|
1428 | - */ |
|
1429 | - protected function _ee_autosave_edit() |
|
1430 | - { |
|
1431 | - return; // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1432 | - } |
|
1433 | - |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * _generate_publish_box_extra_content |
|
1437 | - */ |
|
1438 | - private function _generate_publish_box_extra_content() |
|
1439 | - { |
|
1440 | - // load formatter helper |
|
1441 | - // args for getting related registrations |
|
1442 | - $approved_query_args = array( |
|
1443 | - array( |
|
1444 | - 'REG_deleted' => 0, |
|
1445 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1446 | - ), |
|
1447 | - ); |
|
1448 | - $not_approved_query_args = array( |
|
1449 | - array( |
|
1450 | - 'REG_deleted' => 0, |
|
1451 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1452 | - ), |
|
1453 | - ); |
|
1454 | - $pending_payment_query_args = array( |
|
1455 | - array( |
|
1456 | - 'REG_deleted' => 0, |
|
1457 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1458 | - ), |
|
1459 | - ); |
|
1460 | - // publish box |
|
1461 | - $publish_box_extra_args = array( |
|
1462 | - 'view_approved_reg_url' => add_query_arg( |
|
1463 | - array( |
|
1464 | - 'action' => 'default', |
|
1465 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1466 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1467 | - ), |
|
1468 | - REG_ADMIN_URL |
|
1469 | - ), |
|
1470 | - 'view_not_approved_reg_url' => add_query_arg( |
|
1471 | - array( |
|
1472 | - 'action' => 'default', |
|
1473 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1474 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1475 | - ), |
|
1476 | - REG_ADMIN_URL |
|
1477 | - ), |
|
1478 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
1479 | - array( |
|
1480 | - 'action' => 'default', |
|
1481 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1482 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1483 | - ), |
|
1484 | - REG_ADMIN_URL |
|
1485 | - ), |
|
1486 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1487 | - 'Registration', |
|
1488 | - $approved_query_args |
|
1489 | - ), |
|
1490 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1491 | - 'Registration', |
|
1492 | - $not_approved_query_args |
|
1493 | - ), |
|
1494 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1495 | - 'Registration', |
|
1496 | - $pending_payment_query_args |
|
1497 | - ), |
|
1498 | - 'misc_pub_section_class' => apply_filters( |
|
1499 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1500 | - 'misc-pub-section' |
|
1501 | - ), |
|
1502 | - ); |
|
1503 | - ob_start(); |
|
1504 | - do_action( |
|
1505 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1506 | - $this->_cpt_model_obj |
|
1507 | - ); |
|
1508 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1509 | - // load template |
|
1510 | - EEH_Template::display_template( |
|
1511 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1512 | - $publish_box_extra_args |
|
1513 | - ); |
|
1514 | - } |
|
1515 | - |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * @return EE_Event |
|
1519 | - */ |
|
1520 | - public function get_event_object() |
|
1521 | - { |
|
1522 | - return $this->_cpt_model_obj; |
|
1523 | - } |
|
1524 | - |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /** METABOXES * */ |
|
1529 | - /** |
|
1530 | - * _register_event_editor_meta_boxes |
|
1531 | - * add all metaboxes related to the event_editor |
|
1532 | - * |
|
1533 | - * @return void |
|
1534 | - */ |
|
1535 | - protected function _register_event_editor_meta_boxes() |
|
1536 | - { |
|
1537 | - $this->verify_cpt_object(); |
|
1538 | - add_meta_box( |
|
1539 | - 'espresso_event_editor_tickets', |
|
1540 | - esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1541 | - array($this, 'ticket_metabox'), |
|
1542 | - $this->page_slug, |
|
1543 | - 'normal', |
|
1544 | - 'high' |
|
1545 | - ); |
|
1546 | - add_meta_box( |
|
1547 | - 'espresso_event_editor_event_options', |
|
1548 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
1549 | - array($this, 'registration_options_meta_box'), |
|
1550 | - $this->page_slug, |
|
1551 | - 'side', |
|
1552 | - 'default' |
|
1553 | - ); |
|
1554 | - // NOTE: if you're looking for other metaboxes in here, |
|
1555 | - // where a metabox has a related management page in the admin |
|
1556 | - // you will find it setup in the related management page's "_Hooks" file. |
|
1557 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1558 | - } |
|
1559 | - |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * @throws DomainException |
|
1563 | - * @throws EE_Error |
|
1564 | - */ |
|
1565 | - public function ticket_metabox() |
|
1566 | - { |
|
1567 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1568 | - // defaults for template args |
|
1569 | - $template_args = array( |
|
1570 | - 'existing_datetime_ids' => '', |
|
1571 | - 'event_datetime_help_link' => '', |
|
1572 | - 'ticket_options_help_link' => '', |
|
1573 | - 'time' => null, |
|
1574 | - 'ticket_rows' => '', |
|
1575 | - 'existing_ticket_ids' => '', |
|
1576 | - 'total_ticket_rows' => 1, |
|
1577 | - 'ticket_js_structure' => '', |
|
1578 | - 'trash_icon' => 'ee-lock-icon', |
|
1579 | - 'disabled' => '', |
|
1580 | - ); |
|
1581 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1582 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1583 | - /** |
|
1584 | - * 1. Start with retrieving Datetimes |
|
1585 | - * 2. Fore each datetime get related tickets |
|
1586 | - * 3. For each ticket get related prices |
|
1587 | - */ |
|
1588 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1589 | - /** @type EE_Datetime $first_datetime */ |
|
1590 | - $first_datetime = reset($times); |
|
1591 | - // do we get related tickets? |
|
1592 | - if ( |
|
1593 | - $first_datetime instanceof EE_Datetime |
|
1594 | - && $first_datetime->ID() !== 0 |
|
1595 | - ) { |
|
1596 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1597 | - $template_args['time'] = $first_datetime; |
|
1598 | - $related_tickets = $first_datetime->tickets( |
|
1599 | - array( |
|
1600 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1601 | - 'default_where_conditions' => 'none', |
|
1602 | - ) |
|
1603 | - ); |
|
1604 | - if (! empty($related_tickets)) { |
|
1605 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
1606 | - $row = 0; |
|
1607 | - foreach ($related_tickets as $ticket) { |
|
1608 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1609 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1610 | - $row++; |
|
1611 | - } |
|
1612 | - } else { |
|
1613 | - $template_args['total_ticket_rows'] = 1; |
|
1614 | - /** @type EE_Ticket $ticket */ |
|
1615 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1616 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1617 | - } |
|
1618 | - } else { |
|
1619 | - $template_args['time'] = $times[0]; |
|
1620 | - /** @type EE_Ticket $ticket */ |
|
1621 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1622 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1623 | - // NOTE: we're just sending the first default row |
|
1624 | - // (decaf can't manage default tickets so this should be sufficient); |
|
1625 | - } |
|
1626 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1627 | - 'event_editor_event_datetimes_help_tab' |
|
1628 | - ); |
|
1629 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1630 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1631 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1632 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1633 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1634 | - true |
|
1635 | - ); |
|
1636 | - $template = apply_filters( |
|
1637 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1638 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1639 | - ); |
|
1640 | - EEH_Template::display_template($template, $template_args); |
|
1641 | - } |
|
1642 | - |
|
1643 | - |
|
1644 | - /** |
|
1645 | - * Setup an individual ticket form for the decaf event editor page |
|
1646 | - * |
|
1647 | - * @access private |
|
1648 | - * @param EE_Ticket $ticket the ticket object |
|
1649 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1650 | - * @param int $row |
|
1651 | - * @return string generated html for the ticket row. |
|
1652 | - */ |
|
1653 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1654 | - { |
|
1655 | - $template_args = array( |
|
1656 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1657 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1658 | - : '', |
|
1659 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1660 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1661 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
1662 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1663 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1664 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1665 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1666 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1667 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1668 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1669 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1670 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1671 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1672 | - : ' disabled=disabled', |
|
1673 | - ); |
|
1674 | - $price = $ticket->ID() !== 0 |
|
1675 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1676 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1677 | - $price_args = array( |
|
1678 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1679 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
1680 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
1681 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
1682 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1683 | - ); |
|
1684 | - // make sure we have default start and end dates if skeleton |
|
1685 | - // handle rows that should NOT be empty |
|
1686 | - if (empty($template_args['TKT_start_date'])) { |
|
1687 | - // if empty then the start date will be now. |
|
1688 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1689 | - } |
|
1690 | - if (empty($template_args['TKT_end_date'])) { |
|
1691 | - // get the earliest datetime (if present); |
|
1692 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1693 | - ? $this->_cpt_model_obj->get_first_related( |
|
1694 | - 'Datetime', |
|
1695 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1696 | - ) |
|
1697 | - : null; |
|
1698 | - if (! empty($earliest_dtt)) { |
|
1699 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1700 | - } else { |
|
1701 | - $template_args['TKT_end_date'] = date( |
|
1702 | - 'Y-m-d h:i a', |
|
1703 | - mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
1704 | - ); |
|
1705 | - } |
|
1706 | - } |
|
1707 | - $template_args = array_merge($template_args, $price_args); |
|
1708 | - $template = apply_filters( |
|
1709 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1710 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1711 | - $ticket |
|
1712 | - ); |
|
1713 | - return EEH_Template::display_template($template, $template_args, true); |
|
1714 | - } |
|
1715 | - |
|
1716 | - |
|
1717 | - /** |
|
1718 | - * @throws DomainException |
|
1719 | - */ |
|
1720 | - public function registration_options_meta_box() |
|
1721 | - { |
|
1722 | - $yes_no_values = array( |
|
1723 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1724 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1725 | - ); |
|
1726 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1727 | - array( |
|
1728 | - EEM_Registration::status_id_cancelled, |
|
1729 | - EEM_Registration::status_id_declined, |
|
1730 | - EEM_Registration::status_id_incomplete, |
|
1731 | - ), |
|
1732 | - true |
|
1733 | - ); |
|
1734 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1735 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
1736 | - $template_args['event'] = $this->_cpt_model_obj; |
|
1737 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1738 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1739 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1740 | - 'default_reg_status', |
|
1741 | - $default_reg_status_values, |
|
1742 | - $this->_cpt_model_obj->default_registration_status() |
|
1743 | - ); |
|
1744 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1745 | - 'display_desc', |
|
1746 | - $yes_no_values, |
|
1747 | - $this->_cpt_model_obj->display_description() |
|
1748 | - ); |
|
1749 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1750 | - 'display_ticket_selector', |
|
1751 | - $yes_no_values, |
|
1752 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
1753 | - '', |
|
1754 | - '', |
|
1755 | - false |
|
1756 | - ); |
|
1757 | - $template_args['additional_registration_options'] = apply_filters( |
|
1758 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1759 | - '', |
|
1760 | - $template_args, |
|
1761 | - $yes_no_values, |
|
1762 | - $default_reg_status_values |
|
1763 | - ); |
|
1764 | - EEH_Template::display_template( |
|
1765 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1766 | - $template_args |
|
1767 | - ); |
|
1768 | - } |
|
1769 | - |
|
1770 | - |
|
1771 | - /** |
|
1772 | - * _get_events() |
|
1773 | - * This method simply returns all the events (for the given _view and paging) |
|
1774 | - * |
|
1775 | - * @access public |
|
1776 | - * @param int $per_page count of items per page (20 default); |
|
1777 | - * @param int $current_page what is the current page being viewed. |
|
1778 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1779 | - * If FALSE then we return an array of event objects |
|
1780 | - * that match the given _view and paging parameters. |
|
1781 | - * @return array an array of event objects. |
|
1782 | - */ |
|
1783 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1784 | - { |
|
1785 | - $EEME = $this->_event_model(); |
|
1786 | - $offset = ($current_page - 1) * $per_page; |
|
1787 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1788 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1789 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
1790 | - if (isset($this->_req_data['month_range'])) { |
|
1791 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1792 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
1793 | - // where PHP doesn't know what to assume for date. |
|
1794 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1795 | - $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1796 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1797 | - } |
|
1798 | - $where = array(); |
|
1799 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1800 | - // determine what post_status our condition will have for the query. |
|
1801 | - switch ($status) { |
|
1802 | - case 'month': |
|
1803 | - case 'today': |
|
1804 | - case null: |
|
1805 | - case 'all': |
|
1806 | - break; |
|
1807 | - case 'draft': |
|
1808 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1809 | - break; |
|
1810 | - default: |
|
1811 | - $where['status'] = $status; |
|
1812 | - } |
|
1813 | - // categories? |
|
1814 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1815 | - ? $this->_req_data['EVT_CAT'] : null; |
|
1816 | - if (! empty($category)) { |
|
1817 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1818 | - $where['Term_Taxonomy.term_id'] = $category; |
|
1819 | - } |
|
1820 | - // date where conditions |
|
1821 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1822 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
1823 | - $DateTime = new DateTime( |
|
1824 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1825 | - new DateTimeZone('UTC') |
|
1826 | - ); |
|
1827 | - $start = $DateTime->getTimestamp(); |
|
1828 | - // set the datetime to be the end of the month |
|
1829 | - $DateTime->setDate( |
|
1830 | - $year_r, |
|
1831 | - $month_r, |
|
1832 | - $DateTime->format('t') |
|
1833 | - )->setTime(23, 59, 59); |
|
1834 | - $end = $DateTime->getTimestamp(); |
|
1835 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1836 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
1837 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1838 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1839 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1840 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1841 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1842 | - $now = date('Y-m-01'); |
|
1843 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1844 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1845 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1846 | - ->setTime(23, 59, 59) |
|
1847 | - ->format(implode(' ', $start_formats)); |
|
1848 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1849 | - } |
|
1850 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1851 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1852 | - } else { |
|
1853 | - if (! isset($where['status'])) { |
|
1854 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1855 | - $where['OR'] = array( |
|
1856 | - 'status*restrict_private' => array('!=', 'private'), |
|
1857 | - 'AND' => array( |
|
1858 | - 'status*inclusive' => array('=', 'private'), |
|
1859 | - 'EVT_wp_user' => get_current_user_id(), |
|
1860 | - ), |
|
1861 | - ); |
|
1862 | - } |
|
1863 | - } |
|
1864 | - } |
|
1865 | - if (isset($this->_req_data['EVT_wp_user'])) { |
|
1866 | - if ( |
|
1867 | - $this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
1868 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1869 | - ) { |
|
1870 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1871 | - } |
|
1872 | - } |
|
1873 | - // search query handling |
|
1874 | - if (isset($this->_req_data['s'])) { |
|
1875 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1876 | - $where['OR'] = array( |
|
1877 | - 'EVT_name' => array('LIKE', $search_string), |
|
1878 | - 'EVT_desc' => array('LIKE', $search_string), |
|
1879 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
1880 | - ); |
|
1881 | - } |
|
1882 | - // filter events by venue. |
|
1883 | - if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
1884 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
1885 | - } |
|
1886 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1887 | - $query_params = apply_filters( |
|
1888 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1889 | - array( |
|
1890 | - $where, |
|
1891 | - 'limit' => $limit, |
|
1892 | - 'order_by' => $orderby, |
|
1893 | - 'order' => $order, |
|
1894 | - 'group_by' => 'EVT_ID', |
|
1895 | - ), |
|
1896 | - $this->_req_data |
|
1897 | - ); |
|
1898 | - |
|
1899 | - // let's first check if we have special requests coming in. |
|
1900 | - if (isset($this->_req_data['active_status'])) { |
|
1901 | - switch ($this->_req_data['active_status']) { |
|
1902 | - case 'upcoming': |
|
1903 | - return $EEME->get_upcoming_events($query_params, $count); |
|
1904 | - break; |
|
1905 | - case 'expired': |
|
1906 | - return $EEME->get_expired_events($query_params, $count); |
|
1907 | - break; |
|
1908 | - case 'active': |
|
1909 | - return $EEME->get_active_events($query_params, $count); |
|
1910 | - break; |
|
1911 | - case 'inactive': |
|
1912 | - return $EEME->get_inactive_events($query_params, $count); |
|
1913 | - break; |
|
1914 | - } |
|
1915 | - } |
|
1916 | - |
|
1917 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1918 | - return $events; |
|
1919 | - } |
|
1920 | - |
|
1921 | - |
|
1922 | - /** |
|
1923 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
1924 | - * |
|
1925 | - * @param string $post_id |
|
1926 | - */ |
|
1927 | - public function trash_cpt_item($post_id) |
|
1928 | - { |
|
1929 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1930 | - $this->_trash_or_restore_event('trash', false); |
|
1931 | - } |
|
1932 | - |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * @param string $post_id |
|
1936 | - */ |
|
1937 | - public function restore_cpt_item($post_id) |
|
1938 | - { |
|
1939 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1940 | - $this->_trash_or_restore_event('draft', false); |
|
1941 | - } |
|
1942 | - |
|
1943 | - |
|
1944 | - /** |
|
1945 | - * @param string $post_id |
|
1946 | - */ |
|
1947 | - public function delete_cpt_item($post_id) |
|
1948 | - { |
|
1949 | - throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso')); |
|
1950 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1951 | - $this->_delete_event(); |
|
1952 | - } |
|
1953 | - |
|
1954 | - |
|
1955 | - /** |
|
1956 | - * _trash_or_restore_event |
|
1957 | - * |
|
1958 | - * @access protected |
|
1959 | - * @param string $event_status |
|
1960 | - * @param bool $redirect_after |
|
1961 | - */ |
|
1962 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
1963 | - { |
|
1964 | - // determine the event id and set to array. |
|
1965 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
1966 | - // loop thru events |
|
1967 | - if ($EVT_ID) { |
|
1968 | - // clean status |
|
1969 | - $event_status = sanitize_key($event_status); |
|
1970 | - // grab status |
|
1971 | - if (! empty($event_status)) { |
|
1972 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
1973 | - } else { |
|
1974 | - $success = false; |
|
1975 | - $msg = esc_html__( |
|
1976 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1977 | - 'event_espresso' |
|
1978 | - ); |
|
1979 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1980 | - } |
|
1981 | - } else { |
|
1982 | - $success = false; |
|
1983 | - $msg = esc_html__( |
|
1984 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
1985 | - 'event_espresso' |
|
1986 | - ); |
|
1987 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1988 | - } |
|
1989 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1990 | - if ($redirect_after) { |
|
1991 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
1992 | - } |
|
1993 | - } |
|
1994 | - |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * _trash_or_restore_events |
|
1998 | - * |
|
1999 | - * @access protected |
|
2000 | - * @param string $event_status |
|
2001 | - * @return void |
|
2002 | - */ |
|
2003 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
2004 | - { |
|
2005 | - // clean status |
|
2006 | - $event_status = sanitize_key($event_status); |
|
2007 | - // grab status |
|
2008 | - if (! empty($event_status)) { |
|
2009 | - $success = true; |
|
2010 | - // determine the event id and set to array. |
|
2011 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2012 | - // loop thru events |
|
2013 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2014 | - if ($EVT_ID = absint($EVT_ID)) { |
|
2015 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2016 | - $success = $results !== false ? $success : false; |
|
2017 | - } else { |
|
2018 | - $msg = sprintf( |
|
2019 | - esc_html__( |
|
2020 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2021 | - 'event_espresso' |
|
2022 | - ), |
|
2023 | - $EVT_ID |
|
2024 | - ); |
|
2025 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2026 | - $success = false; |
|
2027 | - } |
|
2028 | - } |
|
2029 | - } else { |
|
2030 | - $success = false; |
|
2031 | - $msg = esc_html__( |
|
2032 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2033 | - 'event_espresso' |
|
2034 | - ); |
|
2035 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2036 | - } |
|
2037 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2038 | - $success = $success ? 2 : false; |
|
2039 | - $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2040 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
2041 | - } |
|
2042 | - |
|
2043 | - |
|
2044 | - /** |
|
2045 | - * _trash_or_restore_events |
|
2046 | - * |
|
2047 | - * @access private |
|
2048 | - * @param int $EVT_ID |
|
2049 | - * @param string $event_status |
|
2050 | - * @return bool |
|
2051 | - */ |
|
2052 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2053 | - { |
|
2054 | - // grab event id |
|
2055 | - if (! $EVT_ID) { |
|
2056 | - $msg = esc_html__( |
|
2057 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2058 | - 'event_espresso' |
|
2059 | - ); |
|
2060 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2061 | - return false; |
|
2062 | - } |
|
2063 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2064 | - // clean status |
|
2065 | - $event_status = sanitize_key($event_status); |
|
2066 | - // grab status |
|
2067 | - if (empty($event_status)) { |
|
2068 | - $msg = esc_html__( |
|
2069 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2070 | - 'event_espresso' |
|
2071 | - ); |
|
2072 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2073 | - return false; |
|
2074 | - } |
|
2075 | - // was event trashed or restored ? |
|
2076 | - switch ($event_status) { |
|
2077 | - case 'draft': |
|
2078 | - $action = 'restored from the trash'; |
|
2079 | - $hook = 'AHEE_event_restored_from_trash'; |
|
2080 | - break; |
|
2081 | - case 'trash': |
|
2082 | - $action = 'moved to the trash'; |
|
2083 | - $hook = 'AHEE_event_moved_to_trash'; |
|
2084 | - break; |
|
2085 | - default: |
|
2086 | - $action = 'updated'; |
|
2087 | - $hook = false; |
|
2088 | - } |
|
2089 | - // use class to change status |
|
2090 | - $this->_cpt_model_obj->set_status($event_status); |
|
2091 | - $success = $this->_cpt_model_obj->save(); |
|
2092 | - if ($success === false) { |
|
2093 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2094 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2095 | - return false; |
|
2096 | - } |
|
2097 | - if ($hook) { |
|
2098 | - do_action($hook); |
|
2099 | - } |
|
2100 | - return true; |
|
2101 | - } |
|
2102 | - |
|
2103 | - |
|
2104 | - /** |
|
2105 | - * _delete_event |
|
2106 | - * |
|
2107 | - * @access protected |
|
2108 | - * @param bool $redirect_after |
|
2109 | - */ |
|
2110 | - protected function _delete_event() |
|
2111 | - { |
|
2112 | - $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array()); |
|
2113 | - } |
|
2114 | - |
|
2115 | - /** |
|
2116 | - * Gets the tree traversal batch persister. |
|
2117 | - * @since 4.10.12.p |
|
2118 | - * @return NodeGroupDao |
|
2119 | - * @throws InvalidArgumentException |
|
2120 | - * @throws InvalidDataTypeException |
|
2121 | - * @throws InvalidInterfaceException |
|
2122 | - */ |
|
2123 | - protected function getModelObjNodeGroupPersister() |
|
2124 | - { |
|
2125 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2126 | - $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2127 | - } |
|
2128 | - return $this->model_obj_node_group_persister; |
|
2129 | - } |
|
2130 | - |
|
2131 | - /** |
|
2132 | - * _delete_events |
|
2133 | - * |
|
2134 | - * @access protected |
|
2135 | - * @return void |
|
2136 | - */ |
|
2137 | - protected function _delete_events() |
|
2138 | - { |
|
2139 | - $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array()); |
|
2140 | - } |
|
2141 | - |
|
2142 | - protected function generateDeletionPreview($event_ids) |
|
2143 | - { |
|
2144 | - $event_ids = (array) $event_ids; |
|
2145 | - // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2146 | - $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2147 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2148 | - [ |
|
2149 | - 'action' => 'preview_deletion', |
|
2150 | - 'deletion_job_code' => $deletion_job_code, |
|
2151 | - ], |
|
2152 | - $this->_admin_base_url |
|
2153 | - ); |
|
2154 | - $event_ids = array_map( |
|
2155 | - 'intval', |
|
2156 | - $event_ids |
|
2157 | - ); |
|
2158 | - |
|
2159 | - EEH_URL::safeRedirectAndExit( |
|
2160 | - EE_Admin_Page::add_query_args_and_nonce( |
|
2161 | - array( |
|
2162 | - 'page' => 'espresso_batch', |
|
2163 | - 'batch' => EED_Batch::batch_job, |
|
2164 | - 'EVT_IDs' => $event_ids, |
|
2165 | - 'deletion_job_code' => $deletion_job_code, |
|
2166 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2167 | - 'return_url' => urlencode($return_url), |
|
2168 | - ), |
|
2169 | - admin_url() |
|
2170 | - ) |
|
2171 | - ); |
|
2172 | - } |
|
2173 | - |
|
2174 | - /** |
|
2175 | - * Checks for a POST submission |
|
2176 | - * @since 4.10.12.p |
|
2177 | - */ |
|
2178 | - protected function confirmDeletion() |
|
2179 | - { |
|
2180 | - $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
2181 | - $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2182 | - } |
|
2183 | - |
|
2184 | - /** |
|
2185 | - * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2186 | - * @since 4.10.12.p |
|
2187 | - * @throws EE_Error |
|
2188 | - */ |
|
2189 | - protected function previewDeletion() |
|
2190 | - { |
|
2191 | - $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
2192 | - $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2193 | - $this->display_admin_page_with_no_sidebar(); |
|
2194 | - } |
|
2195 | - |
|
2196 | - /** |
|
2197 | - * get total number of events |
|
2198 | - * |
|
2199 | - * @access public |
|
2200 | - * @return int |
|
2201 | - */ |
|
2202 | - public function total_events() |
|
2203 | - { |
|
2204 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2205 | - return $count; |
|
2206 | - } |
|
2207 | - |
|
2208 | - |
|
2209 | - /** |
|
2210 | - * get total number of draft events |
|
2211 | - * |
|
2212 | - * @access public |
|
2213 | - * @return int |
|
2214 | - */ |
|
2215 | - public function total_events_draft() |
|
2216 | - { |
|
2217 | - $where = array( |
|
2218 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
2219 | - ); |
|
2220 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2221 | - return $count; |
|
2222 | - } |
|
2223 | - |
|
2224 | - |
|
2225 | - /** |
|
2226 | - * get total number of trashed events |
|
2227 | - * |
|
2228 | - * @access public |
|
2229 | - * @return int |
|
2230 | - */ |
|
2231 | - public function total_trashed_events() |
|
2232 | - { |
|
2233 | - $where = array( |
|
2234 | - 'status' => 'trash', |
|
2235 | - ); |
|
2236 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2237 | - return $count; |
|
2238 | - } |
|
2239 | - |
|
2240 | - |
|
2241 | - /** |
|
2242 | - * _default_event_settings |
|
2243 | - * This generates the Default Settings Tab |
|
2244 | - * |
|
2245 | - * @return void |
|
2246 | - * @throws EE_Error |
|
2247 | - */ |
|
2248 | - protected function _default_event_settings() |
|
2249 | - { |
|
2250 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2251 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2252 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2253 | - $this->display_admin_page_with_sidebar(); |
|
2254 | - } |
|
2255 | - |
|
2256 | - |
|
2257 | - /** |
|
2258 | - * Return the form for event settings. |
|
2259 | - * |
|
2260 | - * @return EE_Form_Section_Proper |
|
2261 | - * @throws EE_Error |
|
2262 | - */ |
|
2263 | - protected function _default_event_settings_form() |
|
2264 | - { |
|
2265 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2266 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2267 | - // exclude |
|
2268 | - array( |
|
2269 | - EEM_Registration::status_id_cancelled, |
|
2270 | - EEM_Registration::status_id_declined, |
|
2271 | - EEM_Registration::status_id_incomplete, |
|
2272 | - EEM_Registration::status_id_wait_list, |
|
2273 | - ), |
|
2274 | - true |
|
2275 | - ); |
|
2276 | - return new EE_Form_Section_Proper( |
|
2277 | - array( |
|
2278 | - 'name' => 'update_default_event_settings', |
|
2279 | - 'html_id' => 'update_default_event_settings', |
|
2280 | - 'html_class' => 'form-table', |
|
2281 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2282 | - 'subsections' => apply_filters( |
|
2283 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2284 | - array( |
|
2285 | - 'default_reg_status' => new EE_Select_Input( |
|
2286 | - $registration_stati_for_selection, |
|
2287 | - array( |
|
2288 | - 'default' => isset($registration_config->default_STS_ID) |
|
2289 | - && array_key_exists( |
|
2290 | - $registration_config->default_STS_ID, |
|
2291 | - $registration_stati_for_selection |
|
2292 | - ) |
|
2293 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
2294 | - : EEM_Registration::status_id_pending_payment, |
|
2295 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2296 | - . EEH_Template::get_help_tab_link( |
|
2297 | - 'default_settings_status_help_tab' |
|
2298 | - ), |
|
2299 | - 'html_help_text' => esc_html__( |
|
2300 | - '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.', |
|
2301 | - 'event_espresso' |
|
2302 | - ), |
|
2303 | - ) |
|
2304 | - ), |
|
2305 | - 'default_max_tickets' => new EE_Integer_Input( |
|
2306 | - array( |
|
2307 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2308 | - ? $registration_config->default_maximum_number_of_tickets |
|
2309 | - : EEM_Event::get_default_additional_limit(), |
|
2310 | - 'html_label_text' => esc_html__( |
|
2311 | - 'Default Maximum Tickets Allowed Per Order:', |
|
2312 | - 'event_espresso' |
|
2313 | - ) |
|
2314 | - . EEH_Template::get_help_tab_link( |
|
2315 | - 'default_maximum_tickets_help_tab"' |
|
2316 | - ), |
|
2317 | - 'html_help_text' => esc_html__( |
|
2318 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2319 | - 'event_espresso' |
|
2320 | - ), |
|
2321 | - ) |
|
2322 | - ), |
|
2323 | - ) |
|
2324 | - ), |
|
2325 | - ) |
|
2326 | - ); |
|
2327 | - } |
|
2328 | - |
|
2329 | - |
|
2330 | - /** |
|
2331 | - * _update_default_event_settings |
|
2332 | - * |
|
2333 | - * @access protected |
|
2334 | - * @return void |
|
2335 | - * @throws EE_Error |
|
2336 | - */ |
|
2337 | - protected function _update_default_event_settings() |
|
2338 | - { |
|
2339 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2340 | - $form = $this->_default_event_settings_form(); |
|
2341 | - if ($form->was_submitted()) { |
|
2342 | - $form->receive_form_submission(); |
|
2343 | - if ($form->is_valid()) { |
|
2344 | - $valid_data = $form->valid_data(); |
|
2345 | - if (isset($valid_data['default_reg_status'])) { |
|
2346 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2347 | - } |
|
2348 | - if (isset($valid_data['default_max_tickets'])) { |
|
2349 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2350 | - } |
|
2351 | - // update because data was valid! |
|
2352 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
2353 | - EE_Error::overwrite_success(); |
|
2354 | - EE_Error::add_success( |
|
2355 | - esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2356 | - ); |
|
2357 | - } |
|
2358 | - } |
|
2359 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2360 | - } |
|
2361 | - |
|
2362 | - |
|
2363 | - /************* Templates *************/ |
|
2364 | - protected function _template_settings() |
|
2365 | - { |
|
2366 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2367 | - $this->_template_args['preview_img'] = '<img src="' |
|
2368 | - . EVENTS_ASSETS_URL |
|
2369 | - . '/images/' |
|
2370 | - . 'caffeinated_template_features.jpg" alt="' |
|
2371 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2372 | - . '" />'; |
|
2373 | - $this->_template_args['preview_text'] = '<strong>' |
|
2374 | - . esc_html__( |
|
2375 | - '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.', |
|
2376 | - 'event_espresso' |
|
2377 | - ) . '</strong>'; |
|
2378 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2379 | - } |
|
2380 | - |
|
2381 | - |
|
2382 | - /** Event Category Stuff **/ |
|
2383 | - /** |
|
2384 | - * set the _category property with the category object for the loaded page. |
|
2385 | - * |
|
2386 | - * @access private |
|
2387 | - * @return void |
|
2388 | - */ |
|
2389 | - private function _set_category_object() |
|
2390 | - { |
|
2391 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2392 | - return; |
|
2393 | - } //already have the category object so get out. |
|
2394 | - // set default category object |
|
2395 | - $this->_set_empty_category_object(); |
|
2396 | - // only set if we've got an id |
|
2397 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2398 | - return; |
|
2399 | - } |
|
2400 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2401 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2402 | - if (! empty($term)) { |
|
2403 | - $this->_category->category_name = $term->name; |
|
2404 | - $this->_category->category_identifier = $term->slug; |
|
2405 | - $this->_category->category_desc = $term->description; |
|
2406 | - $this->_category->id = $term->term_id; |
|
2407 | - $this->_category->parent = $term->parent; |
|
2408 | - } |
|
2409 | - } |
|
2410 | - |
|
2411 | - |
|
2412 | - /** |
|
2413 | - * Clears out category properties. |
|
2414 | - */ |
|
2415 | - private function _set_empty_category_object() |
|
2416 | - { |
|
2417 | - $this->_category = new stdClass(); |
|
2418 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2419 | - $this->_category->id = $this->_category->parent = 0; |
|
2420 | - } |
|
2421 | - |
|
2422 | - |
|
2423 | - /** |
|
2424 | - * @throws EE_Error |
|
2425 | - */ |
|
2426 | - protected function _category_list_table() |
|
2427 | - { |
|
2428 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2429 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2430 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2431 | - 'add_category', |
|
2432 | - 'add_category', |
|
2433 | - array(), |
|
2434 | - 'add-new-h2' |
|
2435 | - ); |
|
2436 | - $this->display_admin_list_table_page_with_sidebar(); |
|
2437 | - } |
|
2438 | - |
|
2439 | - |
|
2440 | - /** |
|
2441 | - * Output category details view. |
|
2442 | - */ |
|
2443 | - protected function _category_details($view) |
|
2444 | - { |
|
2445 | - // load formatter helper |
|
2446 | - // load field generator helper |
|
2447 | - $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2448 | - $this->_set_add_edit_form_tags($route); |
|
2449 | - $this->_set_category_object(); |
|
2450 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2451 | - $delete_action = 'delete_category'; |
|
2452 | - // custom redirect |
|
2453 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2454 | - array('action' => 'category_list'), |
|
2455 | - $this->_admin_base_url |
|
2456 | - ); |
|
2457 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2458 | - // take care of contents |
|
2459 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2460 | - $this->display_admin_page_with_sidebar(); |
|
2461 | - } |
|
2462 | - |
|
2463 | - |
|
2464 | - /** |
|
2465 | - * Output category details content. |
|
2466 | - */ |
|
2467 | - protected function _category_details_content() |
|
2468 | - { |
|
2469 | - $editor_args['category_desc'] = array( |
|
2470 | - 'type' => 'wp_editor', |
|
2471 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2472 | - 'class' => 'my_editor_custom', |
|
2473 | - 'wpeditor_args' => array('media_buttons' => false), |
|
2474 | - ); |
|
2475 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2476 | - $all_terms = get_terms( |
|
2477 | - array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
2478 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2479 | - ); |
|
2480 | - // setup category select for term parents. |
|
2481 | - $category_select_values[] = array( |
|
2482 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2483 | - 'id' => 0, |
|
2484 | - ); |
|
2485 | - foreach ($all_terms as $term) { |
|
2486 | - $category_select_values[] = array( |
|
2487 | - 'text' => $term->name, |
|
2488 | - 'id' => $term->term_id, |
|
2489 | - ); |
|
2490 | - } |
|
2491 | - $category_select = EEH_Form_Fields::select_input( |
|
2492 | - 'category_parent', |
|
2493 | - $category_select_values, |
|
2494 | - $this->_category->parent |
|
2495 | - ); |
|
2496 | - $template_args = array( |
|
2497 | - 'category' => $this->_category, |
|
2498 | - 'category_select' => $category_select, |
|
2499 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2500 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2501 | - 'disable' => '', |
|
2502 | - 'disabled_message' => false, |
|
2503 | - ); |
|
2504 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2505 | - return EEH_Template::display_template($template, $template_args, true); |
|
2506 | - } |
|
2507 | - |
|
2508 | - |
|
2509 | - /** |
|
2510 | - * Handles deleting categories. |
|
2511 | - */ |
|
2512 | - protected function _delete_categories() |
|
2513 | - { |
|
2514 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
2515 | - : (array) $this->_req_data['category_id']; |
|
2516 | - foreach ($cat_ids as $cat_id) { |
|
2517 | - $this->_delete_category($cat_id); |
|
2518 | - } |
|
2519 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2520 | - $query_args = array( |
|
2521 | - 'action' => 'category_list', |
|
2522 | - ); |
|
2523 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
2524 | - } |
|
2525 | - |
|
2526 | - |
|
2527 | - /** |
|
2528 | - * Handles deleting specific category. |
|
2529 | - * |
|
2530 | - * @param int $cat_id |
|
2531 | - */ |
|
2532 | - protected function _delete_category($cat_id) |
|
2533 | - { |
|
2534 | - $cat_id = absint($cat_id); |
|
2535 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2536 | - } |
|
2537 | - |
|
2538 | - |
|
2539 | - /** |
|
2540 | - * Handles triggering the update or insertion of a new category. |
|
2541 | - * |
|
2542 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
2543 | - */ |
|
2544 | - protected function _insert_or_update_category($new_category) |
|
2545 | - { |
|
2546 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2547 | - $success = 0; // we already have a success message so lets not send another. |
|
2548 | - if ($cat_id) { |
|
2549 | - $query_args = array( |
|
2550 | - 'action' => 'edit_category', |
|
2551 | - 'EVT_CAT_ID' => $cat_id, |
|
2552 | - ); |
|
2553 | - } else { |
|
2554 | - $query_args = array('action' => 'add_category'); |
|
2555 | - } |
|
2556 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2557 | - } |
|
2558 | - |
|
2559 | - |
|
2560 | - /** |
|
2561 | - * Inserts or updates category |
|
2562 | - * |
|
2563 | - * @param bool $update (true indicates we're updating a category). |
|
2564 | - * @return bool|mixed|string |
|
2565 | - */ |
|
2566 | - private function _insert_category($update = false) |
|
2567 | - { |
|
2568 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2569 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2570 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2571 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2572 | - if (empty($category_name)) { |
|
2573 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2574 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2575 | - return false; |
|
2576 | - } |
|
2577 | - $term_args = array( |
|
2578 | - 'name' => $category_name, |
|
2579 | - 'description' => $category_desc, |
|
2580 | - 'parent' => $category_parent, |
|
2581 | - ); |
|
2582 | - // was the category_identifier input disabled? |
|
2583 | - if (isset($this->_req_data['category_identifier'])) { |
|
2584 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2585 | - } |
|
2586 | - $insert_ids = $update |
|
2587 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2588 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2589 | - if (! is_array($insert_ids)) { |
|
2590 | - $msg = esc_html__( |
|
2591 | - 'An error occurred and the category has not been saved to the database.', |
|
2592 | - 'event_espresso' |
|
2593 | - ); |
|
2594 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2595 | - } else { |
|
2596 | - $cat_id = $insert_ids['term_id']; |
|
2597 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2598 | - EE_Error::add_success($msg); |
|
2599 | - } |
|
2600 | - return $cat_id; |
|
2601 | - } |
|
2602 | - |
|
2603 | - |
|
2604 | - /** |
|
2605 | - * Gets categories or count of categories matching the arguments in the request. |
|
2606 | - * |
|
2607 | - * @param int $per_page |
|
2608 | - * @param int $current_page |
|
2609 | - * @param bool $count |
|
2610 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
2611 | - */ |
|
2612 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2613 | - { |
|
2614 | - // testing term stuff |
|
2615 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2616 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2617 | - $limit = ($current_page - 1) * $per_page; |
|
2618 | - $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2619 | - if (isset($this->_req_data['s'])) { |
|
2620 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2621 | - $where['OR'] = array( |
|
2622 | - 'Term.name' => array('LIKE', $sstr), |
|
2623 | - 'description' => array('LIKE', $sstr), |
|
2624 | - ); |
|
2625 | - } |
|
2626 | - $query_params = array( |
|
2627 | - $where, |
|
2628 | - 'order_by' => array($orderby => $order), |
|
2629 | - 'limit' => $limit . ',' . $per_page, |
|
2630 | - 'force_join' => array('Term'), |
|
2631 | - ); |
|
2632 | - $categories = $count |
|
2633 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2634 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2635 | - return $categories; |
|
2636 | - } |
|
2637 | - |
|
2638 | - /* end category stuff */ |
|
2639 | - /**************/ |
|
2640 | - |
|
2641 | - |
|
2642 | - /** |
|
2643 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
2644 | - * |
|
2645 | - * @throws EE_Error |
|
2646 | - */ |
|
2647 | - public function save_timezonestring_setting() |
|
2648 | - { |
|
2649 | - $timezone_string = isset($this->_req_data['timezone_selected']) |
|
2650 | - ? $this->_req_data['timezone_selected'] |
|
2651 | - : ''; |
|
2652 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2653 | - EE_Error::add_error( |
|
2654 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2655 | - __FILE__, |
|
2656 | - __FUNCTION__, |
|
2657 | - __LINE__ |
|
2658 | - ); |
|
2659 | - $this->_template_args['error'] = true; |
|
2660 | - $this->_return_json(); |
|
2661 | - } |
|
2662 | - |
|
2663 | - update_option('timezone_string', $timezone_string); |
|
2664 | - EE_Error::add_success( |
|
2665 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2666 | - ); |
|
2667 | - $this->_template_args['success'] = true; |
|
2668 | - $this->_return_json(true, array('action' => 'create_new')); |
|
2669 | - } |
|
22 | + /** |
|
23 | + * This will hold the event object for event_details screen. |
|
24 | + * |
|
25 | + * @var EE_Event $_event |
|
26 | + */ |
|
27 | + protected $_event; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This will hold the category object for category_details screen. |
|
32 | + * |
|
33 | + * @var stdClass $_category |
|
34 | + */ |
|
35 | + protected $_category; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * This will hold the event model instance |
|
40 | + * |
|
41 | + * @var EEM_Event $_event_model |
|
42 | + */ |
|
43 | + protected $_event_model; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EE_Event |
|
48 | + */ |
|
49 | + protected $_cpt_model_obj = false; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @var NodeGroupDao |
|
54 | + */ |
|
55 | + protected $model_obj_node_group_persister; |
|
56 | + |
|
57 | + /** |
|
58 | + * Initialize page props for this admin page group. |
|
59 | + */ |
|
60 | + protected function _init_page_props() |
|
61 | + { |
|
62 | + $this->page_slug = EVENTS_PG_SLUG; |
|
63 | + $this->page_label = EVENTS_LABEL; |
|
64 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
65 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
66 | + $this->_cpt_model_names = array( |
|
67 | + 'create_new' => 'EEM_Event', |
|
68 | + 'edit' => 'EEM_Event', |
|
69 | + ); |
|
70 | + $this->_cpt_edit_routes = array( |
|
71 | + 'espresso_events' => 'edit', |
|
72 | + ); |
|
73 | + add_action( |
|
74 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
75 | + array($this, 'verify_event_edit'), |
|
76 | + 10, |
|
77 | + 2 |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Sets the ajax hooks used for this admin page group. |
|
84 | + */ |
|
85 | + protected function _ajax_hooks() |
|
86 | + { |
|
87 | + add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets the page properties for this admin page group. |
|
93 | + */ |
|
94 | + protected function _define_page_props() |
|
95 | + { |
|
96 | + $this->_admin_page_title = EVENTS_LABEL; |
|
97 | + $this->_labels = array( |
|
98 | + 'buttons' => array( |
|
99 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
100 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
101 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
102 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
103 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
104 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
105 | + ), |
|
106 | + 'editor_title' => array( |
|
107 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
108 | + ), |
|
109 | + 'publishbox' => array( |
|
110 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
111 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
112 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
113 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
114 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
115 | + ), |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Sets the page routes property for this admin page group. |
|
122 | + */ |
|
123 | + protected function _set_page_routes() |
|
124 | + { |
|
125 | + // load formatter helper |
|
126 | + // load field generator helper |
|
127 | + // is there a evt_id in the request? |
|
128 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
129 | + ? $this->_req_data['EVT_ID'] |
|
130 | + : 0; |
|
131 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
132 | + $this->_page_routes = array( |
|
133 | + 'default' => array( |
|
134 | + 'func' => '_events_overview_list_table', |
|
135 | + 'capability' => 'ee_read_events', |
|
136 | + ), |
|
137 | + 'create_new' => array( |
|
138 | + 'func' => '_create_new_cpt_item', |
|
139 | + 'capability' => 'ee_edit_events', |
|
140 | + ), |
|
141 | + 'edit' => array( |
|
142 | + 'func' => '_edit_cpt_item', |
|
143 | + 'capability' => 'ee_edit_event', |
|
144 | + 'obj_id' => $evt_id, |
|
145 | + ), |
|
146 | + 'copy_event' => array( |
|
147 | + 'func' => '_copy_events', |
|
148 | + 'capability' => 'ee_edit_event', |
|
149 | + 'obj_id' => $evt_id, |
|
150 | + 'noheader' => true, |
|
151 | + ), |
|
152 | + 'trash_event' => array( |
|
153 | + 'func' => '_trash_or_restore_event', |
|
154 | + 'args' => array('event_status' => 'trash'), |
|
155 | + 'capability' => 'ee_delete_event', |
|
156 | + 'obj_id' => $evt_id, |
|
157 | + 'noheader' => true, |
|
158 | + ), |
|
159 | + 'trash_events' => array( |
|
160 | + 'func' => '_trash_or_restore_events', |
|
161 | + 'args' => array('event_status' => 'trash'), |
|
162 | + 'capability' => 'ee_delete_events', |
|
163 | + 'noheader' => true, |
|
164 | + ), |
|
165 | + 'restore_event' => array( |
|
166 | + 'func' => '_trash_or_restore_event', |
|
167 | + 'args' => array('event_status' => 'draft'), |
|
168 | + 'capability' => 'ee_delete_event', |
|
169 | + 'obj_id' => $evt_id, |
|
170 | + 'noheader' => true, |
|
171 | + ), |
|
172 | + 'restore_events' => array( |
|
173 | + 'func' => '_trash_or_restore_events', |
|
174 | + 'args' => array('event_status' => 'draft'), |
|
175 | + 'capability' => 'ee_delete_events', |
|
176 | + 'noheader' => true, |
|
177 | + ), |
|
178 | + 'delete_event' => array( |
|
179 | + 'func' => '_delete_event', |
|
180 | + 'capability' => 'ee_delete_event', |
|
181 | + 'obj_id' => $evt_id, |
|
182 | + 'noheader' => true, |
|
183 | + ), |
|
184 | + 'delete_events' => array( |
|
185 | + 'func' => '_delete_events', |
|
186 | + 'capability' => 'ee_delete_events', |
|
187 | + 'noheader' => true, |
|
188 | + ), |
|
189 | + 'view_report' => array( |
|
190 | + 'func' => '_view_report', |
|
191 | + 'capablity' => 'ee_edit_events', |
|
192 | + ), |
|
193 | + 'default_event_settings' => array( |
|
194 | + 'func' => '_default_event_settings', |
|
195 | + 'capability' => 'manage_options', |
|
196 | + ), |
|
197 | + 'update_default_event_settings' => array( |
|
198 | + 'func' => '_update_default_event_settings', |
|
199 | + 'capability' => 'manage_options', |
|
200 | + 'noheader' => true, |
|
201 | + ), |
|
202 | + 'template_settings' => array( |
|
203 | + 'func' => '_template_settings', |
|
204 | + 'capability' => 'manage_options', |
|
205 | + ), |
|
206 | + // event category tab related |
|
207 | + 'add_category' => array( |
|
208 | + 'func' => '_category_details', |
|
209 | + 'capability' => 'ee_edit_event_category', |
|
210 | + 'args' => array('add'), |
|
211 | + ), |
|
212 | + 'edit_category' => array( |
|
213 | + 'func' => '_category_details', |
|
214 | + 'capability' => 'ee_edit_event_category', |
|
215 | + 'args' => array('edit'), |
|
216 | + ), |
|
217 | + 'delete_categories' => array( |
|
218 | + 'func' => '_delete_categories', |
|
219 | + 'capability' => 'ee_delete_event_category', |
|
220 | + 'noheader' => true, |
|
221 | + ), |
|
222 | + 'delete_category' => array( |
|
223 | + 'func' => '_delete_categories', |
|
224 | + 'capability' => 'ee_delete_event_category', |
|
225 | + 'noheader' => true, |
|
226 | + ), |
|
227 | + 'insert_category' => array( |
|
228 | + 'func' => '_insert_or_update_category', |
|
229 | + 'args' => array('new_category' => true), |
|
230 | + 'capability' => 'ee_edit_event_category', |
|
231 | + 'noheader' => true, |
|
232 | + ), |
|
233 | + 'update_category' => array( |
|
234 | + 'func' => '_insert_or_update_category', |
|
235 | + 'args' => array('new_category' => false), |
|
236 | + 'capability' => 'ee_edit_event_category', |
|
237 | + 'noheader' => true, |
|
238 | + ), |
|
239 | + 'category_list' => array( |
|
240 | + 'func' => '_category_list_table', |
|
241 | + 'capability' => 'ee_manage_event_categories', |
|
242 | + ), |
|
243 | + 'preview_deletion' => [ |
|
244 | + 'func' => 'previewDeletion', |
|
245 | + 'capability' => 'ee_delete_events', |
|
246 | + ], |
|
247 | + 'confirm_deletion' => [ |
|
248 | + 'func' => 'confirmDeletion', |
|
249 | + 'capability' => 'ee_delete_events', |
|
250 | + 'noheader' => true, |
|
251 | + ] |
|
252 | + ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Set the _page_config property for this admin page group. |
|
258 | + */ |
|
259 | + protected function _set_page_config() |
|
260 | + { |
|
261 | + $this->_page_config = array( |
|
262 | + 'default' => array( |
|
263 | + 'nav' => array( |
|
264 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
265 | + 'order' => 10, |
|
266 | + ), |
|
267 | + 'list_table' => 'Events_Admin_List_Table', |
|
268 | + 'help_tabs' => array( |
|
269 | + 'events_overview_help_tab' => array( |
|
270 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
271 | + 'filename' => 'events_overview', |
|
272 | + ), |
|
273 | + 'events_overview_table_column_headings_help_tab' => array( |
|
274 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
275 | + 'filename' => 'events_overview_table_column_headings', |
|
276 | + ), |
|
277 | + 'events_overview_filters_help_tab' => array( |
|
278 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
279 | + 'filename' => 'events_overview_filters', |
|
280 | + ), |
|
281 | + 'events_overview_view_help_tab' => array( |
|
282 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
283 | + 'filename' => 'events_overview_views', |
|
284 | + ), |
|
285 | + 'events_overview_other_help_tab' => array( |
|
286 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
287 | + 'filename' => 'events_overview_other', |
|
288 | + ), |
|
289 | + ), |
|
290 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
291 | + // 'help_tour' => array( |
|
292 | + // 'Event_Overview_Help_Tour', |
|
293 | + // // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
294 | + // ), |
|
295 | + 'qtips' => array( |
|
296 | + 'EE_Event_List_Table_Tips', |
|
297 | + ), |
|
298 | + 'require_nonce' => false, |
|
299 | + ), |
|
300 | + 'create_new' => array( |
|
301 | + 'nav' => array( |
|
302 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
303 | + 'order' => 5, |
|
304 | + 'persistent' => false, |
|
305 | + ), |
|
306 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
307 | + 'help_tabs' => array( |
|
308 | + 'event_editor_help_tab' => array( |
|
309 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
310 | + 'filename' => 'event_editor', |
|
311 | + ), |
|
312 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
313 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
314 | + 'filename' => 'event_editor_title_richtexteditor', |
|
315 | + ), |
|
316 | + 'event_editor_venue_details_help_tab' => array( |
|
317 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
318 | + 'filename' => 'event_editor_venue_details', |
|
319 | + ), |
|
320 | + 'event_editor_event_datetimes_help_tab' => array( |
|
321 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
322 | + 'filename' => 'event_editor_event_datetimes', |
|
323 | + ), |
|
324 | + 'event_editor_event_tickets_help_tab' => array( |
|
325 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
326 | + 'filename' => 'event_editor_event_tickets', |
|
327 | + ), |
|
328 | + 'event_editor_event_registration_options_help_tab' => array( |
|
329 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
330 | + 'filename' => 'event_editor_event_registration_options', |
|
331 | + ), |
|
332 | + 'event_editor_tags_categories_help_tab' => array( |
|
333 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
334 | + 'filename' => 'event_editor_tags_categories', |
|
335 | + ), |
|
336 | + 'event_editor_questions_registrants_help_tab' => array( |
|
337 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
338 | + 'filename' => 'event_editor_questions_registrants', |
|
339 | + ), |
|
340 | + 'event_editor_save_new_event_help_tab' => array( |
|
341 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
342 | + 'filename' => 'event_editor_save_new_event', |
|
343 | + ), |
|
344 | + 'event_editor_other_help_tab' => array( |
|
345 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
346 | + 'filename' => 'event_editor_other', |
|
347 | + ), |
|
348 | + ), |
|
349 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
350 | + // 'help_tour' => array( |
|
351 | + // 'Event_Editor_Help_Tour', |
|
352 | + // ), |
|
353 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
354 | + 'require_nonce' => false, |
|
355 | + ), |
|
356 | + 'edit' => array( |
|
357 | + 'nav' => array( |
|
358 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
359 | + 'order' => 5, |
|
360 | + 'persistent' => false, |
|
361 | + 'url' => isset($this->_req_data['post']) |
|
362 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
363 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
364 | + $this->_current_page_view_url |
|
365 | + ) |
|
366 | + : $this->_admin_base_url, |
|
367 | + ), |
|
368 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
369 | + 'help_tabs' => array( |
|
370 | + 'event_editor_help_tab' => array( |
|
371 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
372 | + 'filename' => 'event_editor', |
|
373 | + ), |
|
374 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
375 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
376 | + 'filename' => 'event_editor_title_richtexteditor', |
|
377 | + ), |
|
378 | + 'event_editor_venue_details_help_tab' => array( |
|
379 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
380 | + 'filename' => 'event_editor_venue_details', |
|
381 | + ), |
|
382 | + 'event_editor_event_datetimes_help_tab' => array( |
|
383 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
384 | + 'filename' => 'event_editor_event_datetimes', |
|
385 | + ), |
|
386 | + 'event_editor_event_tickets_help_tab' => array( |
|
387 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
388 | + 'filename' => 'event_editor_event_tickets', |
|
389 | + ), |
|
390 | + 'event_editor_event_registration_options_help_tab' => array( |
|
391 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
392 | + 'filename' => 'event_editor_event_registration_options', |
|
393 | + ), |
|
394 | + 'event_editor_tags_categories_help_tab' => array( |
|
395 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
396 | + 'filename' => 'event_editor_tags_categories', |
|
397 | + ), |
|
398 | + 'event_editor_questions_registrants_help_tab' => array( |
|
399 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
400 | + 'filename' => 'event_editor_questions_registrants', |
|
401 | + ), |
|
402 | + 'event_editor_save_new_event_help_tab' => array( |
|
403 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
404 | + 'filename' => 'event_editor_save_new_event', |
|
405 | + ), |
|
406 | + 'event_editor_other_help_tab' => array( |
|
407 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
408 | + 'filename' => 'event_editor_other', |
|
409 | + ), |
|
410 | + ), |
|
411 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
412 | + 'require_nonce' => false, |
|
413 | + ), |
|
414 | + 'default_event_settings' => array( |
|
415 | + 'nav' => array( |
|
416 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
417 | + 'order' => 40, |
|
418 | + ), |
|
419 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
420 | + 'labels' => array( |
|
421 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
422 | + ), |
|
423 | + 'help_tabs' => array( |
|
424 | + 'default_settings_help_tab' => array( |
|
425 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
426 | + 'filename' => 'events_default_settings', |
|
427 | + ), |
|
428 | + 'default_settings_status_help_tab' => array( |
|
429 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
430 | + 'filename' => 'events_default_settings_status', |
|
431 | + ), |
|
432 | + 'default_maximum_tickets_help_tab' => array( |
|
433 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
434 | + 'filename' => 'events_default_settings_max_tickets', |
|
435 | + ), |
|
436 | + ), |
|
437 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
438 | + // 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
439 | + 'require_nonce' => false, |
|
440 | + ), |
|
441 | + // template settings |
|
442 | + 'template_settings' => array( |
|
443 | + 'nav' => array( |
|
444 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
445 | + 'order' => 30, |
|
446 | + ), |
|
447 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
448 | + 'help_tabs' => array( |
|
449 | + 'general_settings_templates_help_tab' => array( |
|
450 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
451 | + 'filename' => 'general_settings_templates', |
|
452 | + ), |
|
453 | + ), |
|
454 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
455 | + // 'help_tour' => array('Templates_Help_Tour'), |
|
456 | + 'require_nonce' => false, |
|
457 | + ), |
|
458 | + // event category stuff |
|
459 | + 'add_category' => array( |
|
460 | + 'nav' => array( |
|
461 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
462 | + 'order' => 15, |
|
463 | + 'persistent' => false, |
|
464 | + ), |
|
465 | + 'help_tabs' => array( |
|
466 | + 'add_category_help_tab' => array( |
|
467 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
468 | + 'filename' => 'events_add_category', |
|
469 | + ), |
|
470 | + ), |
|
471 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
472 | + // 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
473 | + 'metaboxes' => array('_publish_post_box'), |
|
474 | + 'require_nonce' => false, |
|
475 | + ), |
|
476 | + 'edit_category' => array( |
|
477 | + 'nav' => array( |
|
478 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
479 | + 'order' => 15, |
|
480 | + 'persistent' => false, |
|
481 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
482 | + ? add_query_arg( |
|
483 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
484 | + $this->_current_page_view_url |
|
485 | + ) |
|
486 | + : $this->_admin_base_url, |
|
487 | + ), |
|
488 | + 'help_tabs' => array( |
|
489 | + 'edit_category_help_tab' => array( |
|
490 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
491 | + 'filename' => 'events_edit_category', |
|
492 | + ), |
|
493 | + ), |
|
494 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
495 | + 'metaboxes' => array('_publish_post_box'), |
|
496 | + 'require_nonce' => false, |
|
497 | + ), |
|
498 | + 'category_list' => array( |
|
499 | + 'nav' => array( |
|
500 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
501 | + 'order' => 20, |
|
502 | + ), |
|
503 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
504 | + 'help_tabs' => array( |
|
505 | + 'events_categories_help_tab' => array( |
|
506 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
507 | + 'filename' => 'events_categories', |
|
508 | + ), |
|
509 | + 'events_categories_table_column_headings_help_tab' => array( |
|
510 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
511 | + 'filename' => 'events_categories_table_column_headings', |
|
512 | + ), |
|
513 | + 'events_categories_view_help_tab' => array( |
|
514 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
515 | + 'filename' => 'events_categories_views', |
|
516 | + ), |
|
517 | + 'events_categories_other_help_tab' => array( |
|
518 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
519 | + 'filename' => 'events_categories_other', |
|
520 | + ), |
|
521 | + ), |
|
522 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
523 | + // 'help_tour' => array( |
|
524 | + // 'Event_Categories_Help_Tour', |
|
525 | + // ), |
|
526 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
527 | + 'require_nonce' => false, |
|
528 | + ), |
|
529 | + 'preview_deletion' => array( |
|
530 | + 'nav' => array( |
|
531 | + 'label' => esc_html__('Preview Deletion', 'event_espresso'), |
|
532 | + 'order' => 15, |
|
533 | + 'persistent' => false, |
|
534 | + 'url' => '', |
|
535 | + ), |
|
536 | + 'require_nonce' => false |
|
537 | + ) |
|
538 | + ); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
544 | + */ |
|
545 | + protected function _add_screen_options() |
|
546 | + { |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Implementing the screen options for the 'default' route. |
|
552 | + */ |
|
553 | + protected function _add_screen_options_default() |
|
554 | + { |
|
555 | + $this->_per_page_screen_option(); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Implementing screen options for the category list route. |
|
561 | + */ |
|
562 | + protected function _add_screen_options_category_list() |
|
563 | + { |
|
564 | + $page_title = $this->_admin_page_title; |
|
565 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
566 | + $this->_per_page_screen_option(); |
|
567 | + $this->_admin_page_title = $page_title; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Used to register any global feature pointers for the admin page group. |
|
573 | + */ |
|
574 | + protected function _add_feature_pointers() |
|
575 | + { |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
581 | + */ |
|
582 | + public function load_scripts_styles() |
|
583 | + { |
|
584 | + wp_register_style( |
|
585 | + 'events-admin-css', |
|
586 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
587 | + array(), |
|
588 | + EVENT_ESPRESSO_VERSION |
|
589 | + ); |
|
590 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
591 | + wp_enqueue_style('events-admin-css'); |
|
592 | + wp_enqueue_style('ee-cat-admin'); |
|
593 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
594 | + // registers for all views |
|
595 | + // scripts |
|
596 | + wp_register_script( |
|
597 | + 'event_editor_js', |
|
598 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
599 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
600 | + EVENT_ESPRESSO_VERSION, |
|
601 | + true |
|
602 | + ); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * Enqueuing scripts and styles specific to this view |
|
608 | + */ |
|
609 | + public function load_scripts_styles_create_new() |
|
610 | + { |
|
611 | + $this->load_scripts_styles_edit(); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Enqueuing scripts and styles specific to this view |
|
617 | + */ |
|
618 | + public function load_scripts_styles_edit() |
|
619 | + { |
|
620 | + // styles |
|
621 | + wp_enqueue_style('espresso-ui-theme'); |
|
622 | + wp_register_style( |
|
623 | + 'event-editor-css', |
|
624 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
625 | + array('ee-admin-css'), |
|
626 | + EVENT_ESPRESSO_VERSION |
|
627 | + ); |
|
628 | + wp_enqueue_style('event-editor-css'); |
|
629 | + // scripts |
|
630 | + wp_register_script( |
|
631 | + 'event-datetime-metabox', |
|
632 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
633 | + array('event_editor_js', 'ee-datepicker'), |
|
634 | + EVENT_ESPRESSO_VERSION |
|
635 | + ); |
|
636 | + wp_enqueue_script('event-datetime-metabox'); |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * Populating the _views property for the category list table view. |
|
642 | + */ |
|
643 | + protected function _set_list_table_views_category_list() |
|
644 | + { |
|
645 | + $this->_views = array( |
|
646 | + 'all' => array( |
|
647 | + 'slug' => 'all', |
|
648 | + 'label' => esc_html__('All', 'event_espresso'), |
|
649 | + 'count' => 0, |
|
650 | + 'bulk_action' => array( |
|
651 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
652 | + ), |
|
653 | + ), |
|
654 | + ); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
660 | + */ |
|
661 | + public function admin_init() |
|
662 | + { |
|
663 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
664 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
665 | + 'event_espresso' |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
672 | + * group. |
|
673 | + */ |
|
674 | + public function admin_notices() |
|
675 | + { |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
681 | + * this admin page group. |
|
682 | + */ |
|
683 | + public function admin_footer_scripts() |
|
684 | + { |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
690 | + * warning (via EE_Error::add_error()); |
|
691 | + * |
|
692 | + * @param EE_Event $event Event object |
|
693 | + * @param string $req_type |
|
694 | + * @return void |
|
695 | + * @throws EE_Error |
|
696 | + * @access public |
|
697 | + */ |
|
698 | + public function verify_event_edit($event = null, $req_type = '') |
|
699 | + { |
|
700 | + // don't need to do this when processing |
|
701 | + if (! empty($req_type)) { |
|
702 | + return; |
|
703 | + } |
|
704 | + // no event? |
|
705 | + if (empty($event)) { |
|
706 | + // set event |
|
707 | + $event = $this->_cpt_model_obj; |
|
708 | + } |
|
709 | + // STILL no event? |
|
710 | + if (! $event instanceof EE_Event) { |
|
711 | + return; |
|
712 | + } |
|
713 | + $orig_status = $event->status(); |
|
714 | + // first check if event is active. |
|
715 | + if ( |
|
716 | + $orig_status === EEM_Event::cancelled |
|
717 | + || $orig_status === EEM_Event::postponed |
|
718 | + || $event->is_expired() |
|
719 | + || $event->is_inactive() |
|
720 | + ) { |
|
721 | + return; |
|
722 | + } |
|
723 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
724 | + if ($event->is_sold_out(true)) { |
|
725 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
726 | + EE_Error::add_attention( |
|
727 | + sprintf( |
|
728 | + esc_html__( |
|
729 | + '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.', |
|
730 | + 'event_espresso' |
|
731 | + ), |
|
732 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
733 | + ) |
|
734 | + ); |
|
735 | + } |
|
736 | + return; |
|
737 | + } elseif ($orig_status === EEM_Event::sold_out) { |
|
738 | + EE_Error::add_attention( |
|
739 | + sprintf( |
|
740 | + esc_html__( |
|
741 | + '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.', |
|
742 | + 'event_espresso' |
|
743 | + ), |
|
744 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
745 | + ) |
|
746 | + ); |
|
747 | + } |
|
748 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
749 | + if (! $event->tickets_on_sale()) { |
|
750 | + return; |
|
751 | + } |
|
752 | + // made it here so show warning |
|
753 | + $this->_edit_event_warning(); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
759 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
760 | + * |
|
761 | + * @access protected |
|
762 | + * @return void |
|
763 | + */ |
|
764 | + protected function _edit_event_warning() |
|
765 | + { |
|
766 | + // we don't want to add warnings during these requests |
|
767 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
768 | + return; |
|
769 | + } |
|
770 | + EE_Error::add_attention( |
|
771 | + sprintf( |
|
772 | + esc_html__( |
|
773 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
774 | + 'event_espresso' |
|
775 | + ), |
|
776 | + '<a class="espresso-help-tab-lnk">', |
|
777 | + '</a>' |
|
778 | + ) |
|
779 | + ); |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
785 | + * Otherwise, do the normal logic |
|
786 | + * |
|
787 | + * @return string |
|
788 | + * @throws \EE_Error |
|
789 | + */ |
|
790 | + protected function _create_new_cpt_item() |
|
791 | + { |
|
792 | + $has_timezone_string = get_option('timezone_string'); |
|
793 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
794 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
795 | + EE_Error::add_attention( |
|
796 | + sprintf( |
|
797 | + esc_html__( |
|
798 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
799 | + 'event_espresso' |
|
800 | + ), |
|
801 | + '<br>', |
|
802 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
803 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
804 | + . '</select>', |
|
805 | + '<button class="button button-secondary timezone-submit">', |
|
806 | + '</button><span class="spinner"></span>' |
|
807 | + ), |
|
808 | + __FILE__, |
|
809 | + __FUNCTION__, |
|
810 | + __LINE__ |
|
811 | + ); |
|
812 | + } |
|
813 | + return parent::_create_new_cpt_item(); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + /** |
|
818 | + * Sets the _views property for the default route in this admin page group. |
|
819 | + */ |
|
820 | + protected function _set_list_table_views_default() |
|
821 | + { |
|
822 | + $this->_views = array( |
|
823 | + 'all' => array( |
|
824 | + 'slug' => 'all', |
|
825 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
826 | + 'count' => 0, |
|
827 | + 'bulk_action' => array( |
|
828 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
829 | + ), |
|
830 | + ), |
|
831 | + 'draft' => array( |
|
832 | + 'slug' => 'draft', |
|
833 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
834 | + 'count' => 0, |
|
835 | + 'bulk_action' => array( |
|
836 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
837 | + ), |
|
838 | + ), |
|
839 | + ); |
|
840 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
841 | + $this->_views['trash'] = array( |
|
842 | + 'slug' => 'trash', |
|
843 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
844 | + 'count' => 0, |
|
845 | + 'bulk_action' => array( |
|
846 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
847 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
848 | + ), |
|
849 | + ); |
|
850 | + } |
|
851 | + } |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * Provides the legend item array for the default list table view. |
|
856 | + * |
|
857 | + * @return array |
|
858 | + */ |
|
859 | + protected function _event_legend_items() |
|
860 | + { |
|
861 | + $items = array( |
|
862 | + 'view_details' => array( |
|
863 | + 'class' => 'dashicons dashicons-search', |
|
864 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
865 | + ), |
|
866 | + 'edit_event' => array( |
|
867 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
868 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
869 | + ), |
|
870 | + 'view_attendees' => array( |
|
871 | + 'class' => 'dashicons dashicons-groups', |
|
872 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
873 | + ), |
|
874 | + ); |
|
875 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
876 | + $statuses = array( |
|
877 | + 'sold_out_status' => array( |
|
878 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
879 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
880 | + ), |
|
881 | + 'active_status' => array( |
|
882 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
883 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
884 | + ), |
|
885 | + 'upcoming_status' => array( |
|
886 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
887 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
888 | + ), |
|
889 | + 'postponed_status' => array( |
|
890 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
891 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
892 | + ), |
|
893 | + 'cancelled_status' => array( |
|
894 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
895 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
896 | + ), |
|
897 | + 'expired_status' => array( |
|
898 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
899 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
900 | + ), |
|
901 | + 'inactive_status' => array( |
|
902 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
903 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
904 | + ), |
|
905 | + ); |
|
906 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
907 | + return array_merge($items, $statuses); |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + /** |
|
912 | + * @return EEM_Event |
|
913 | + */ |
|
914 | + private function _event_model() |
|
915 | + { |
|
916 | + if (! $this->_event_model instanceof EEM_Event) { |
|
917 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
918 | + } |
|
919 | + return $this->_event_model; |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * Adds extra buttons to the WP CPT permalink field row. |
|
925 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
926 | + * |
|
927 | + * @param string $return the current html |
|
928 | + * @param int $id the post id for the page |
|
929 | + * @param string $new_title What the title is |
|
930 | + * @param string $new_slug what the slug is |
|
931 | + * @return string The new html string for the permalink area |
|
932 | + */ |
|
933 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
934 | + { |
|
935 | + // make sure this is only when editing |
|
936 | + if (! empty($id)) { |
|
937 | + $post = get_post($id); |
|
938 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
939 | + . esc_html__('Shortcode', 'event_espresso') |
|
940 | + . '</a> '; |
|
941 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
942 | + . $post->ID |
|
943 | + . ']">'; |
|
944 | + } |
|
945 | + return $return; |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * _events_overview_list_table |
|
951 | + * This contains the logic for showing the events_overview list |
|
952 | + * |
|
953 | + * @access protected |
|
954 | + * @return void |
|
955 | + * @throws \EE_Error |
|
956 | + */ |
|
957 | + protected function _events_overview_list_table() |
|
958 | + { |
|
959 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
960 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
961 | + ? (array) $this->_template_args['after_list_table'] |
|
962 | + : array(); |
|
963 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
964 | + . EEH_Template::get_button_or_link( |
|
965 | + get_post_type_archive_link('espresso_events'), |
|
966 | + esc_html__("View Event Archive Page", "event_espresso"), |
|
967 | + 'button' |
|
968 | + ); |
|
969 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
970 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
971 | + 'create_new', |
|
972 | + 'add', |
|
973 | + array(), |
|
974 | + 'add-new-h2' |
|
975 | + ); |
|
976 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
977 | + } |
|
978 | + |
|
979 | + |
|
980 | + /** |
|
981 | + * this allows for extra misc actions in the default WP publish box |
|
982 | + * |
|
983 | + * @return void |
|
984 | + */ |
|
985 | + public function extra_misc_actions_publish_box() |
|
986 | + { |
|
987 | + $this->_generate_publish_box_extra_content(); |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + /** |
|
992 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
993 | + * saved. |
|
994 | + * Typically you would use this to save any additional data. |
|
995 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
996 | + * ALSO very important. When a post transitions from scheduled to published, |
|
997 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
998 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
999 | + * |
|
1000 | + * @access protected |
|
1001 | + * @abstract |
|
1002 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
1003 | + * @param object $post The post object of the cpt that was saved. |
|
1004 | + * @return void |
|
1005 | + * @throws \EE_Error |
|
1006 | + */ |
|
1007 | + protected function _insert_update_cpt_item($post_id, $post) |
|
1008 | + { |
|
1009 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1010 | + // get out we're not processing an event save. |
|
1011 | + return; |
|
1012 | + } |
|
1013 | + $event_values = array( |
|
1014 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
1015 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
1016 | + 'EVT_additional_limit' => min( |
|
1017 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1018 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
1019 | + ), |
|
1020 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
1021 | + ? $this->_req_data['EVT_default_registration_status'] |
|
1022 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
1023 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
1024 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
1025 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
1026 | + ? $this->_req_data['timezone_string'] : null, |
|
1027 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
1028 | + ? $this->_req_data['externalURL'] : null, |
|
1029 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
1030 | + ? $this->_req_data['event_phone'] : null, |
|
1031 | + ); |
|
1032 | + // update event |
|
1033 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1034 | + // 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! |
|
1035 | + $get_one_where = array( |
|
1036 | + $this->_event_model()->primary_key_name() => $post_id, |
|
1037 | + 'OR' => array( |
|
1038 | + 'status' => $post->post_status, |
|
1039 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1040 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
1041 | + 'status*1' => $this->_req_data['original_post_status'], |
|
1042 | + ), |
|
1043 | + ); |
|
1044 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
1045 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1046 | + $event_update_callbacks = apply_filters( |
|
1047 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1048 | + array( |
|
1049 | + array($this, '_default_venue_update'), |
|
1050 | + array($this, '_default_tickets_update'), |
|
1051 | + ) |
|
1052 | + ); |
|
1053 | + $att_success = true; |
|
1054 | + foreach ($event_update_callbacks as $e_callback) { |
|
1055 | + $_success = is_callable($e_callback) |
|
1056 | + ? call_user_func($e_callback, $event, $this->_req_data) |
|
1057 | + : false; |
|
1058 | + // if ANY of these updates fail then we want the appropriate global error message |
|
1059 | + $att_success = ! $att_success ? $att_success : $_success; |
|
1060 | + } |
|
1061 | + // any errors? |
|
1062 | + if ($success && false === $att_success) { |
|
1063 | + EE_Error::add_error( |
|
1064 | + esc_html__( |
|
1065 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1066 | + 'event_espresso' |
|
1067 | + ), |
|
1068 | + __FILE__, |
|
1069 | + __FUNCTION__, |
|
1070 | + __LINE__ |
|
1071 | + ); |
|
1072 | + } elseif ($success === false) { |
|
1073 | + EE_Error::add_error( |
|
1074 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1075 | + __FILE__, |
|
1076 | + __FUNCTION__, |
|
1077 | + __LINE__ |
|
1078 | + ); |
|
1079 | + } |
|
1080 | + } |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * @see parent::restore_item() |
|
1085 | + * @param int $post_id |
|
1086 | + * @param int $revision_id |
|
1087 | + */ |
|
1088 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
1089 | + { |
|
1090 | + // copy existing event meta to new post |
|
1091 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1092 | + if ($post_evt instanceof EE_Event) { |
|
1093 | + // meta revision restore |
|
1094 | + $post_evt->restore_revision($revision_id); |
|
1095 | + // related objs restore |
|
1096 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1097 | + } |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Attach the venue to the Event |
|
1103 | + * |
|
1104 | + * @param \EE_Event $evtobj Event Object to add the venue to |
|
1105 | + * @param array $data The request data from the form |
|
1106 | + * @return bool Success or fail. |
|
1107 | + */ |
|
1108 | + protected function _default_venue_update(\EE_Event $evtobj, $data) |
|
1109 | + { |
|
1110 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1111 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1112 | + $rows_affected = null; |
|
1113 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1114 | + // very important. If we don't have a venue name... |
|
1115 | + // then we'll get out because not necessary to create empty venue |
|
1116 | + if (empty($data['venue_title'])) { |
|
1117 | + return false; |
|
1118 | + } |
|
1119 | + $venue_array = array( |
|
1120 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1121 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1122 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1123 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1124 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1125 | + : null, |
|
1126 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1127 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1128 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1129 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1130 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1131 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1132 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1133 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1134 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1135 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1136 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1137 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1138 | + 'status' => 'publish', |
|
1139 | + ); |
|
1140 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1141 | + if (! empty($venue_id)) { |
|
1142 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1143 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1144 | + // 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. |
|
1145 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1146 | + return $rows_affected > 0 ? true : false; |
|
1147 | + } else { |
|
1148 | + // we insert the venue |
|
1149 | + $venue_id = $venue_model->insert($venue_array); |
|
1150 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1151 | + return ! empty($venue_id) ? true : false; |
|
1152 | + } |
|
1153 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
1154 | + } |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1159 | + * |
|
1160 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
1161 | + * @param array $data The request data from the form |
|
1162 | + * @return array |
|
1163 | + */ |
|
1164 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1165 | + { |
|
1166 | + $success = true; |
|
1167 | + $saved_dtt = null; |
|
1168 | + $saved_tickets = array(); |
|
1169 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1170 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1171 | + // trim all values to ensure any excess whitespace is removed. |
|
1172 | + $dtt = array_map('trim', $dtt); |
|
1173 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1174 | + : $dtt['DTT_EVT_start']; |
|
1175 | + $datetime_values = array( |
|
1176 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1177 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1178 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1179 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1180 | + 'DTT_order' => $row, |
|
1181 | + ); |
|
1182 | + // 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. |
|
1183 | + if (! empty($dtt['DTT_ID'])) { |
|
1184 | + $DTM = EE_Registry::instance() |
|
1185 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1186 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
1187 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
1188 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
1189 | + foreach ($datetime_values as $field => $value) { |
|
1190 | + $DTM->set($field, $value); |
|
1191 | + } |
|
1192 | + // 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. |
|
1193 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1194 | + } else { |
|
1195 | + $DTM = EE_Registry::instance()->load_class( |
|
1196 | + 'Datetime', |
|
1197 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1198 | + false, |
|
1199 | + false |
|
1200 | + ); |
|
1201 | + foreach ($datetime_values as $field => $value) { |
|
1202 | + $DTM->set($field, $value); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + $DTM->save(); |
|
1206 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1207 | + // load DTT helper |
|
1208 | + // 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. |
|
1209 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1210 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1211 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1212 | + $DTT->save(); |
|
1213 | + } |
|
1214 | + // 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. |
|
1215 | + $saved_dtt = $DTT; |
|
1216 | + $success = ! $success ? $success : $DTT; |
|
1217 | + // if ANY of these updates fail then we want the appropriate global error message. |
|
1218 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1219 | + } |
|
1220 | + // no dtts get deleted so we don't do any of that logic here. |
|
1221 | + // update tickets next |
|
1222 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1223 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1224 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1225 | + $update_prices = false; |
|
1226 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1227 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1228 | + // trim inputs to ensure any excess whitespace is removed. |
|
1229 | + $tkt = array_map('trim', $tkt); |
|
1230 | + if (empty($tkt['TKT_start_date'])) { |
|
1231 | + // let's use now in the set timezone. |
|
1232 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1233 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1234 | + } |
|
1235 | + if (empty($tkt['TKT_end_date'])) { |
|
1236 | + // use the start date of the first datetime |
|
1237 | + $dtt = $evtobj->first_datetime(); |
|
1238 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1239 | + $incoming_date_formats[0], |
|
1240 | + $incoming_date_formats[1] |
|
1241 | + ); |
|
1242 | + } |
|
1243 | + $TKT_values = array( |
|
1244 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1245 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1246 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1247 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1248 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1249 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1250 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1251 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1252 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1253 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1254 | + 'TKT_row' => $row, |
|
1255 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1256 | + 'TKT_price' => $ticket_price, |
|
1257 | + ); |
|
1258 | + // 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. |
|
1259 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1260 | + $TKT_values['TKT_ID'] = 0; |
|
1261 | + $TKT_values['TKT_is_default'] = 0; |
|
1262 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1263 | + $update_prices = true; |
|
1264 | + } |
|
1265 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1266 | + // 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. |
|
1267 | + // 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. |
|
1268 | + if (! empty($tkt['TKT_ID'])) { |
|
1269 | + $TKT = EE_Registry::instance() |
|
1270 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1271 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
1272 | + if ($TKT instanceof EE_Ticket) { |
|
1273 | + $ticket_sold = $TKT->count_related( |
|
1274 | + 'Registration', |
|
1275 | + array( |
|
1276 | + array( |
|
1277 | + 'STS_ID' => array( |
|
1278 | + 'NOT IN', |
|
1279 | + array(EEM_Registration::status_id_incomplete), |
|
1280 | + ), |
|
1281 | + ), |
|
1282 | + ) |
|
1283 | + ) > 0 ? true : false; |
|
1284 | + // 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. |
|
1285 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') |
|
1286 | + && ! $TKT->get('TKT_deleted'); |
|
1287 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1288 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1289 | + // set new values |
|
1290 | + foreach ($TKT_values as $field => $value) { |
|
1291 | + if ($field == 'TKT_qty') { |
|
1292 | + $TKT->set_qty($value); |
|
1293 | + } else { |
|
1294 | + $TKT->set($field, $value); |
|
1295 | + } |
|
1296 | + } |
|
1297 | + // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1298 | + if ($create_new_TKT) { |
|
1299 | + // archive the old ticket first |
|
1300 | + $TKT->set('TKT_deleted', 1); |
|
1301 | + $TKT->save(); |
|
1302 | + // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1303 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1304 | + // 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. |
|
1305 | + $TKT = clone $TKT; |
|
1306 | + $TKT->set('TKT_ID', 0); |
|
1307 | + $TKT->set('TKT_deleted', 0); |
|
1308 | + $TKT->set('TKT_price', $ticket_price); |
|
1309 | + $TKT->set('TKT_sold', 0); |
|
1310 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1311 | + $update_prices = true; |
|
1312 | + } |
|
1313 | + // make sure price is set if it hasn't been already |
|
1314 | + $TKT->set('TKT_price', $ticket_price); |
|
1315 | + } |
|
1316 | + } else { |
|
1317 | + // no TKT_id so a new TKT |
|
1318 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1319 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1320 | + if ($TKT instanceof EE_Ticket) { |
|
1321 | + // need to reset values to properly account for the date formats |
|
1322 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1323 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1324 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
1325 | + // set new values |
|
1326 | + foreach ($TKT_values as $field => $value) { |
|
1327 | + if ($field == 'TKT_qty') { |
|
1328 | + $TKT->set_qty($value); |
|
1329 | + } else { |
|
1330 | + $TKT->set($field, $value); |
|
1331 | + } |
|
1332 | + } |
|
1333 | + $update_prices = true; |
|
1334 | + } |
|
1335 | + } |
|
1336 | + // cap ticket qty by datetime reg limits |
|
1337 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1338 | + // update ticket. |
|
1339 | + $TKT->save(); |
|
1340 | + // 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. |
|
1341 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1342 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1343 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1344 | + $TKT->save(); |
|
1345 | + } |
|
1346 | + // initially let's add the ticket to the dtt |
|
1347 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1348 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1349 | + // add prices to ticket |
|
1350 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1351 | + } |
|
1352 | + // 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. |
|
1353 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1354 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1355 | + foreach ($tickets_removed as $id) { |
|
1356 | + $id = absint($id); |
|
1357 | + // get the ticket for this id |
|
1358 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1359 | + if (! $tkt_to_remove instanceof EE_Ticket) { |
|
1360 | + continue; |
|
1361 | + } |
|
1362 | + |
|
1363 | + // 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) |
|
1364 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1365 | + foreach ($dtts as $dtt) { |
|
1366 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1367 | + } |
|
1368 | + // 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)) |
|
1369 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
1370 | + // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1371 | + $tkt_to_remove->delete_permanently(); |
|
1372 | + } |
|
1373 | + return array($saved_dtt, $saved_tickets); |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * This attaches a list of given prices to a ticket. |
|
1379 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1380 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1381 | + * price info and prices are automatically "archived" via the ticket. |
|
1382 | + * |
|
1383 | + * @access private |
|
1384 | + * @param array $prices Array of prices from the form. |
|
1385 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1386 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1387 | + * @return void |
|
1388 | + */ |
|
1389 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1390 | + { |
|
1391 | + foreach ($prices as $row => $prc) { |
|
1392 | + $PRC_values = array( |
|
1393 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1394 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1395 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1396 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1397 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1398 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1399 | + 'PRC_order' => $row, |
|
1400 | + ); |
|
1401 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1402 | + $PRC_values['PRC_ID'] = 0; |
|
1403 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1404 | + } else { |
|
1405 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1406 | + // update this price with new values |
|
1407 | + foreach ($PRC_values as $field => $newprc) { |
|
1408 | + $PRC->set($field, $newprc); |
|
1409 | + } |
|
1410 | + $PRC->save(); |
|
1411 | + } |
|
1412 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
1413 | + } |
|
1414 | + } |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * Add in our autosave ajax handlers |
|
1419 | + * |
|
1420 | + */ |
|
1421 | + protected function _ee_autosave_create_new() |
|
1422 | + { |
|
1423 | + } |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * More autosave handlers. |
|
1428 | + */ |
|
1429 | + protected function _ee_autosave_edit() |
|
1430 | + { |
|
1431 | + return; // TEMPORARILY EXITING CAUSE THIS IS A TODO |
|
1432 | + } |
|
1433 | + |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * _generate_publish_box_extra_content |
|
1437 | + */ |
|
1438 | + private function _generate_publish_box_extra_content() |
|
1439 | + { |
|
1440 | + // load formatter helper |
|
1441 | + // args for getting related registrations |
|
1442 | + $approved_query_args = array( |
|
1443 | + array( |
|
1444 | + 'REG_deleted' => 0, |
|
1445 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1446 | + ), |
|
1447 | + ); |
|
1448 | + $not_approved_query_args = array( |
|
1449 | + array( |
|
1450 | + 'REG_deleted' => 0, |
|
1451 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1452 | + ), |
|
1453 | + ); |
|
1454 | + $pending_payment_query_args = array( |
|
1455 | + array( |
|
1456 | + 'REG_deleted' => 0, |
|
1457 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1458 | + ), |
|
1459 | + ); |
|
1460 | + // publish box |
|
1461 | + $publish_box_extra_args = array( |
|
1462 | + 'view_approved_reg_url' => add_query_arg( |
|
1463 | + array( |
|
1464 | + 'action' => 'default', |
|
1465 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1466 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1467 | + ), |
|
1468 | + REG_ADMIN_URL |
|
1469 | + ), |
|
1470 | + 'view_not_approved_reg_url' => add_query_arg( |
|
1471 | + array( |
|
1472 | + 'action' => 'default', |
|
1473 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1474 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1475 | + ), |
|
1476 | + REG_ADMIN_URL |
|
1477 | + ), |
|
1478 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
1479 | + array( |
|
1480 | + 'action' => 'default', |
|
1481 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1482 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1483 | + ), |
|
1484 | + REG_ADMIN_URL |
|
1485 | + ), |
|
1486 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1487 | + 'Registration', |
|
1488 | + $approved_query_args |
|
1489 | + ), |
|
1490 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1491 | + 'Registration', |
|
1492 | + $not_approved_query_args |
|
1493 | + ), |
|
1494 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1495 | + 'Registration', |
|
1496 | + $pending_payment_query_args |
|
1497 | + ), |
|
1498 | + 'misc_pub_section_class' => apply_filters( |
|
1499 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1500 | + 'misc-pub-section' |
|
1501 | + ), |
|
1502 | + ); |
|
1503 | + ob_start(); |
|
1504 | + do_action( |
|
1505 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1506 | + $this->_cpt_model_obj |
|
1507 | + ); |
|
1508 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1509 | + // load template |
|
1510 | + EEH_Template::display_template( |
|
1511 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1512 | + $publish_box_extra_args |
|
1513 | + ); |
|
1514 | + } |
|
1515 | + |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * @return EE_Event |
|
1519 | + */ |
|
1520 | + public function get_event_object() |
|
1521 | + { |
|
1522 | + return $this->_cpt_model_obj; |
|
1523 | + } |
|
1524 | + |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /** METABOXES * */ |
|
1529 | + /** |
|
1530 | + * _register_event_editor_meta_boxes |
|
1531 | + * add all metaboxes related to the event_editor |
|
1532 | + * |
|
1533 | + * @return void |
|
1534 | + */ |
|
1535 | + protected function _register_event_editor_meta_boxes() |
|
1536 | + { |
|
1537 | + $this->verify_cpt_object(); |
|
1538 | + add_meta_box( |
|
1539 | + 'espresso_event_editor_tickets', |
|
1540 | + esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1541 | + array($this, 'ticket_metabox'), |
|
1542 | + $this->page_slug, |
|
1543 | + 'normal', |
|
1544 | + 'high' |
|
1545 | + ); |
|
1546 | + add_meta_box( |
|
1547 | + 'espresso_event_editor_event_options', |
|
1548 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
1549 | + array($this, 'registration_options_meta_box'), |
|
1550 | + $this->page_slug, |
|
1551 | + 'side', |
|
1552 | + 'default' |
|
1553 | + ); |
|
1554 | + // NOTE: if you're looking for other metaboxes in here, |
|
1555 | + // where a metabox has a related management page in the admin |
|
1556 | + // you will find it setup in the related management page's "_Hooks" file. |
|
1557 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1558 | + } |
|
1559 | + |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * @throws DomainException |
|
1563 | + * @throws EE_Error |
|
1564 | + */ |
|
1565 | + public function ticket_metabox() |
|
1566 | + { |
|
1567 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1568 | + // defaults for template args |
|
1569 | + $template_args = array( |
|
1570 | + 'existing_datetime_ids' => '', |
|
1571 | + 'event_datetime_help_link' => '', |
|
1572 | + 'ticket_options_help_link' => '', |
|
1573 | + 'time' => null, |
|
1574 | + 'ticket_rows' => '', |
|
1575 | + 'existing_ticket_ids' => '', |
|
1576 | + 'total_ticket_rows' => 1, |
|
1577 | + 'ticket_js_structure' => '', |
|
1578 | + 'trash_icon' => 'ee-lock-icon', |
|
1579 | + 'disabled' => '', |
|
1580 | + ); |
|
1581 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1582 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1583 | + /** |
|
1584 | + * 1. Start with retrieving Datetimes |
|
1585 | + * 2. Fore each datetime get related tickets |
|
1586 | + * 3. For each ticket get related prices |
|
1587 | + */ |
|
1588 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1589 | + /** @type EE_Datetime $first_datetime */ |
|
1590 | + $first_datetime = reset($times); |
|
1591 | + // do we get related tickets? |
|
1592 | + if ( |
|
1593 | + $first_datetime instanceof EE_Datetime |
|
1594 | + && $first_datetime->ID() !== 0 |
|
1595 | + ) { |
|
1596 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1597 | + $template_args['time'] = $first_datetime; |
|
1598 | + $related_tickets = $first_datetime->tickets( |
|
1599 | + array( |
|
1600 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1601 | + 'default_where_conditions' => 'none', |
|
1602 | + ) |
|
1603 | + ); |
|
1604 | + if (! empty($related_tickets)) { |
|
1605 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
1606 | + $row = 0; |
|
1607 | + foreach ($related_tickets as $ticket) { |
|
1608 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1609 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1610 | + $row++; |
|
1611 | + } |
|
1612 | + } else { |
|
1613 | + $template_args['total_ticket_rows'] = 1; |
|
1614 | + /** @type EE_Ticket $ticket */ |
|
1615 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1616 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1617 | + } |
|
1618 | + } else { |
|
1619 | + $template_args['time'] = $times[0]; |
|
1620 | + /** @type EE_Ticket $ticket */ |
|
1621 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1622 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1623 | + // NOTE: we're just sending the first default row |
|
1624 | + // (decaf can't manage default tickets so this should be sufficient); |
|
1625 | + } |
|
1626 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1627 | + 'event_editor_event_datetimes_help_tab' |
|
1628 | + ); |
|
1629 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1630 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1631 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1632 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1633 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1634 | + true |
|
1635 | + ); |
|
1636 | + $template = apply_filters( |
|
1637 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1638 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1639 | + ); |
|
1640 | + EEH_Template::display_template($template, $template_args); |
|
1641 | + } |
|
1642 | + |
|
1643 | + |
|
1644 | + /** |
|
1645 | + * Setup an individual ticket form for the decaf event editor page |
|
1646 | + * |
|
1647 | + * @access private |
|
1648 | + * @param EE_Ticket $ticket the ticket object |
|
1649 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1650 | + * @param int $row |
|
1651 | + * @return string generated html for the ticket row. |
|
1652 | + */ |
|
1653 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1654 | + { |
|
1655 | + $template_args = array( |
|
1656 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1657 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1658 | + : '', |
|
1659 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1660 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1661 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
1662 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1663 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1664 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1665 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1666 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1667 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1668 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1669 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1670 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1671 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1672 | + : ' disabled=disabled', |
|
1673 | + ); |
|
1674 | + $price = $ticket->ID() !== 0 |
|
1675 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1676 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1677 | + $price_args = array( |
|
1678 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1679 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
1680 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
1681 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
1682 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1683 | + ); |
|
1684 | + // make sure we have default start and end dates if skeleton |
|
1685 | + // handle rows that should NOT be empty |
|
1686 | + if (empty($template_args['TKT_start_date'])) { |
|
1687 | + // if empty then the start date will be now. |
|
1688 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1689 | + } |
|
1690 | + if (empty($template_args['TKT_end_date'])) { |
|
1691 | + // get the earliest datetime (if present); |
|
1692 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1693 | + ? $this->_cpt_model_obj->get_first_related( |
|
1694 | + 'Datetime', |
|
1695 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1696 | + ) |
|
1697 | + : null; |
|
1698 | + if (! empty($earliest_dtt)) { |
|
1699 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1700 | + } else { |
|
1701 | + $template_args['TKT_end_date'] = date( |
|
1702 | + 'Y-m-d h:i a', |
|
1703 | + mktime(0, 0, 0, date("m"), date("d") + 7, date("Y")) |
|
1704 | + ); |
|
1705 | + } |
|
1706 | + } |
|
1707 | + $template_args = array_merge($template_args, $price_args); |
|
1708 | + $template = apply_filters( |
|
1709 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1710 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1711 | + $ticket |
|
1712 | + ); |
|
1713 | + return EEH_Template::display_template($template, $template_args, true); |
|
1714 | + } |
|
1715 | + |
|
1716 | + |
|
1717 | + /** |
|
1718 | + * @throws DomainException |
|
1719 | + */ |
|
1720 | + public function registration_options_meta_box() |
|
1721 | + { |
|
1722 | + $yes_no_values = array( |
|
1723 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1724 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1725 | + ); |
|
1726 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1727 | + array( |
|
1728 | + EEM_Registration::status_id_cancelled, |
|
1729 | + EEM_Registration::status_id_declined, |
|
1730 | + EEM_Registration::status_id_incomplete, |
|
1731 | + ), |
|
1732 | + true |
|
1733 | + ); |
|
1734 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1735 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
1736 | + $template_args['event'] = $this->_cpt_model_obj; |
|
1737 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1738 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1739 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1740 | + 'default_reg_status', |
|
1741 | + $default_reg_status_values, |
|
1742 | + $this->_cpt_model_obj->default_registration_status() |
|
1743 | + ); |
|
1744 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1745 | + 'display_desc', |
|
1746 | + $yes_no_values, |
|
1747 | + $this->_cpt_model_obj->display_description() |
|
1748 | + ); |
|
1749 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1750 | + 'display_ticket_selector', |
|
1751 | + $yes_no_values, |
|
1752 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
1753 | + '', |
|
1754 | + '', |
|
1755 | + false |
|
1756 | + ); |
|
1757 | + $template_args['additional_registration_options'] = apply_filters( |
|
1758 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1759 | + '', |
|
1760 | + $template_args, |
|
1761 | + $yes_no_values, |
|
1762 | + $default_reg_status_values |
|
1763 | + ); |
|
1764 | + EEH_Template::display_template( |
|
1765 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1766 | + $template_args |
|
1767 | + ); |
|
1768 | + } |
|
1769 | + |
|
1770 | + |
|
1771 | + /** |
|
1772 | + * _get_events() |
|
1773 | + * This method simply returns all the events (for the given _view and paging) |
|
1774 | + * |
|
1775 | + * @access public |
|
1776 | + * @param int $per_page count of items per page (20 default); |
|
1777 | + * @param int $current_page what is the current page being viewed. |
|
1778 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1779 | + * If FALSE then we return an array of event objects |
|
1780 | + * that match the given _view and paging parameters. |
|
1781 | + * @return array an array of event objects. |
|
1782 | + */ |
|
1783 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1784 | + { |
|
1785 | + $EEME = $this->_event_model(); |
|
1786 | + $offset = ($current_page - 1) * $per_page; |
|
1787 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
1788 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1789 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
|
1790 | + if (isset($this->_req_data['month_range'])) { |
|
1791 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1792 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
1793 | + // where PHP doesn't know what to assume for date. |
|
1794 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1795 | + $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1796 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1797 | + } |
|
1798 | + $where = array(); |
|
1799 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1800 | + // determine what post_status our condition will have for the query. |
|
1801 | + switch ($status) { |
|
1802 | + case 'month': |
|
1803 | + case 'today': |
|
1804 | + case null: |
|
1805 | + case 'all': |
|
1806 | + break; |
|
1807 | + case 'draft': |
|
1808 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1809 | + break; |
|
1810 | + default: |
|
1811 | + $where['status'] = $status; |
|
1812 | + } |
|
1813 | + // categories? |
|
1814 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1815 | + ? $this->_req_data['EVT_CAT'] : null; |
|
1816 | + if (! empty($category)) { |
|
1817 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1818 | + $where['Term_Taxonomy.term_id'] = $category; |
|
1819 | + } |
|
1820 | + // date where conditions |
|
1821 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1822 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
|
1823 | + $DateTime = new DateTime( |
|
1824 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
1825 | + new DateTimeZone('UTC') |
|
1826 | + ); |
|
1827 | + $start = $DateTime->getTimestamp(); |
|
1828 | + // set the datetime to be the end of the month |
|
1829 | + $DateTime->setDate( |
|
1830 | + $year_r, |
|
1831 | + $month_r, |
|
1832 | + $DateTime->format('t') |
|
1833 | + )->setTime(23, 59, 59); |
|
1834 | + $end = $DateTime->getTimestamp(); |
|
1835 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1836 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
|
1837 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1838 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1839 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1840 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1841 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1842 | + $now = date('Y-m-01'); |
|
1843 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1844 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1845 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1846 | + ->setTime(23, 59, 59) |
|
1847 | + ->format(implode(' ', $start_formats)); |
|
1848 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1849 | + } |
|
1850 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1851 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1852 | + } else { |
|
1853 | + if (! isset($where['status'])) { |
|
1854 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1855 | + $where['OR'] = array( |
|
1856 | + 'status*restrict_private' => array('!=', 'private'), |
|
1857 | + 'AND' => array( |
|
1858 | + 'status*inclusive' => array('=', 'private'), |
|
1859 | + 'EVT_wp_user' => get_current_user_id(), |
|
1860 | + ), |
|
1861 | + ); |
|
1862 | + } |
|
1863 | + } |
|
1864 | + } |
|
1865 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
1866 | + if ( |
|
1867 | + $this->_req_data['EVT_wp_user'] != get_current_user_id() |
|
1868 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1869 | + ) { |
|
1870 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1871 | + } |
|
1872 | + } |
|
1873 | + // search query handling |
|
1874 | + if (isset($this->_req_data['s'])) { |
|
1875 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1876 | + $where['OR'] = array( |
|
1877 | + 'EVT_name' => array('LIKE', $search_string), |
|
1878 | + 'EVT_desc' => array('LIKE', $search_string), |
|
1879 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
1880 | + ); |
|
1881 | + } |
|
1882 | + // filter events by venue. |
|
1883 | + if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
1884 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
1885 | + } |
|
1886 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1887 | + $query_params = apply_filters( |
|
1888 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1889 | + array( |
|
1890 | + $where, |
|
1891 | + 'limit' => $limit, |
|
1892 | + 'order_by' => $orderby, |
|
1893 | + 'order' => $order, |
|
1894 | + 'group_by' => 'EVT_ID', |
|
1895 | + ), |
|
1896 | + $this->_req_data |
|
1897 | + ); |
|
1898 | + |
|
1899 | + // let's first check if we have special requests coming in. |
|
1900 | + if (isset($this->_req_data['active_status'])) { |
|
1901 | + switch ($this->_req_data['active_status']) { |
|
1902 | + case 'upcoming': |
|
1903 | + return $EEME->get_upcoming_events($query_params, $count); |
|
1904 | + break; |
|
1905 | + case 'expired': |
|
1906 | + return $EEME->get_expired_events($query_params, $count); |
|
1907 | + break; |
|
1908 | + case 'active': |
|
1909 | + return $EEME->get_active_events($query_params, $count); |
|
1910 | + break; |
|
1911 | + case 'inactive': |
|
1912 | + return $EEME->get_inactive_events($query_params, $count); |
|
1913 | + break; |
|
1914 | + } |
|
1915 | + } |
|
1916 | + |
|
1917 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1918 | + return $events; |
|
1919 | + } |
|
1920 | + |
|
1921 | + |
|
1922 | + /** |
|
1923 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
1924 | + * |
|
1925 | + * @param string $post_id |
|
1926 | + */ |
|
1927 | + public function trash_cpt_item($post_id) |
|
1928 | + { |
|
1929 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1930 | + $this->_trash_or_restore_event('trash', false); |
|
1931 | + } |
|
1932 | + |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * @param string $post_id |
|
1936 | + */ |
|
1937 | + public function restore_cpt_item($post_id) |
|
1938 | + { |
|
1939 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1940 | + $this->_trash_or_restore_event('draft', false); |
|
1941 | + } |
|
1942 | + |
|
1943 | + |
|
1944 | + /** |
|
1945 | + * @param string $post_id |
|
1946 | + */ |
|
1947 | + public function delete_cpt_item($post_id) |
|
1948 | + { |
|
1949 | + throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of the steps taken to produce this error.', 'event_espresso')); |
|
1950 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1951 | + $this->_delete_event(); |
|
1952 | + } |
|
1953 | + |
|
1954 | + |
|
1955 | + /** |
|
1956 | + * _trash_or_restore_event |
|
1957 | + * |
|
1958 | + * @access protected |
|
1959 | + * @param string $event_status |
|
1960 | + * @param bool $redirect_after |
|
1961 | + */ |
|
1962 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
1963 | + { |
|
1964 | + // determine the event id and set to array. |
|
1965 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
1966 | + // loop thru events |
|
1967 | + if ($EVT_ID) { |
|
1968 | + // clean status |
|
1969 | + $event_status = sanitize_key($event_status); |
|
1970 | + // grab status |
|
1971 | + if (! empty($event_status)) { |
|
1972 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
1973 | + } else { |
|
1974 | + $success = false; |
|
1975 | + $msg = esc_html__( |
|
1976 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
1977 | + 'event_espresso' |
|
1978 | + ); |
|
1979 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1980 | + } |
|
1981 | + } else { |
|
1982 | + $success = false; |
|
1983 | + $msg = esc_html__( |
|
1984 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
1985 | + 'event_espresso' |
|
1986 | + ); |
|
1987 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1988 | + } |
|
1989 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
1990 | + if ($redirect_after) { |
|
1991 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
1992 | + } |
|
1993 | + } |
|
1994 | + |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * _trash_or_restore_events |
|
1998 | + * |
|
1999 | + * @access protected |
|
2000 | + * @param string $event_status |
|
2001 | + * @return void |
|
2002 | + */ |
|
2003 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
2004 | + { |
|
2005 | + // clean status |
|
2006 | + $event_status = sanitize_key($event_status); |
|
2007 | + // grab status |
|
2008 | + if (! empty($event_status)) { |
|
2009 | + $success = true; |
|
2010 | + // determine the event id and set to array. |
|
2011 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2012 | + // loop thru events |
|
2013 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2014 | + if ($EVT_ID = absint($EVT_ID)) { |
|
2015 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2016 | + $success = $results !== false ? $success : false; |
|
2017 | + } else { |
|
2018 | + $msg = sprintf( |
|
2019 | + esc_html__( |
|
2020 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2021 | + 'event_espresso' |
|
2022 | + ), |
|
2023 | + $EVT_ID |
|
2024 | + ); |
|
2025 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2026 | + $success = false; |
|
2027 | + } |
|
2028 | + } |
|
2029 | + } else { |
|
2030 | + $success = false; |
|
2031 | + $msg = esc_html__( |
|
2032 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2033 | + 'event_espresso' |
|
2034 | + ); |
|
2035 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2036 | + } |
|
2037 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2038 | + $success = $success ? 2 : false; |
|
2039 | + $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2040 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
2041 | + } |
|
2042 | + |
|
2043 | + |
|
2044 | + /** |
|
2045 | + * _trash_or_restore_events |
|
2046 | + * |
|
2047 | + * @access private |
|
2048 | + * @param int $EVT_ID |
|
2049 | + * @param string $event_status |
|
2050 | + * @return bool |
|
2051 | + */ |
|
2052 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2053 | + { |
|
2054 | + // grab event id |
|
2055 | + if (! $EVT_ID) { |
|
2056 | + $msg = esc_html__( |
|
2057 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2058 | + 'event_espresso' |
|
2059 | + ); |
|
2060 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2061 | + return false; |
|
2062 | + } |
|
2063 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2064 | + // clean status |
|
2065 | + $event_status = sanitize_key($event_status); |
|
2066 | + // grab status |
|
2067 | + if (empty($event_status)) { |
|
2068 | + $msg = esc_html__( |
|
2069 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2070 | + 'event_espresso' |
|
2071 | + ); |
|
2072 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2073 | + return false; |
|
2074 | + } |
|
2075 | + // was event trashed or restored ? |
|
2076 | + switch ($event_status) { |
|
2077 | + case 'draft': |
|
2078 | + $action = 'restored from the trash'; |
|
2079 | + $hook = 'AHEE_event_restored_from_trash'; |
|
2080 | + break; |
|
2081 | + case 'trash': |
|
2082 | + $action = 'moved to the trash'; |
|
2083 | + $hook = 'AHEE_event_moved_to_trash'; |
|
2084 | + break; |
|
2085 | + default: |
|
2086 | + $action = 'updated'; |
|
2087 | + $hook = false; |
|
2088 | + } |
|
2089 | + // use class to change status |
|
2090 | + $this->_cpt_model_obj->set_status($event_status); |
|
2091 | + $success = $this->_cpt_model_obj->save(); |
|
2092 | + if ($success === false) { |
|
2093 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2094 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2095 | + return false; |
|
2096 | + } |
|
2097 | + if ($hook) { |
|
2098 | + do_action($hook); |
|
2099 | + } |
|
2100 | + return true; |
|
2101 | + } |
|
2102 | + |
|
2103 | + |
|
2104 | + /** |
|
2105 | + * _delete_event |
|
2106 | + * |
|
2107 | + * @access protected |
|
2108 | + * @param bool $redirect_after |
|
2109 | + */ |
|
2110 | + protected function _delete_event() |
|
2111 | + { |
|
2112 | + $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : array()); |
|
2113 | + } |
|
2114 | + |
|
2115 | + /** |
|
2116 | + * Gets the tree traversal batch persister. |
|
2117 | + * @since 4.10.12.p |
|
2118 | + * @return NodeGroupDao |
|
2119 | + * @throws InvalidArgumentException |
|
2120 | + * @throws InvalidDataTypeException |
|
2121 | + * @throws InvalidInterfaceException |
|
2122 | + */ |
|
2123 | + protected function getModelObjNodeGroupPersister() |
|
2124 | + { |
|
2125 | + if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2126 | + $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
|
2127 | + } |
|
2128 | + return $this->model_obj_node_group_persister; |
|
2129 | + } |
|
2130 | + |
|
2131 | + /** |
|
2132 | + * _delete_events |
|
2133 | + * |
|
2134 | + * @access protected |
|
2135 | + * @return void |
|
2136 | + */ |
|
2137 | + protected function _delete_events() |
|
2138 | + { |
|
2139 | + $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array()); |
|
2140 | + } |
|
2141 | + |
|
2142 | + protected function generateDeletionPreview($event_ids) |
|
2143 | + { |
|
2144 | + $event_ids = (array) $event_ids; |
|
2145 | + // Set a code we can use to reference this deletion task in the batch jobs and preview page. |
|
2146 | + $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode(); |
|
2147 | + $return_url = EE_Admin_Page::add_query_args_and_nonce( |
|
2148 | + [ |
|
2149 | + 'action' => 'preview_deletion', |
|
2150 | + 'deletion_job_code' => $deletion_job_code, |
|
2151 | + ], |
|
2152 | + $this->_admin_base_url |
|
2153 | + ); |
|
2154 | + $event_ids = array_map( |
|
2155 | + 'intval', |
|
2156 | + $event_ids |
|
2157 | + ); |
|
2158 | + |
|
2159 | + EEH_URL::safeRedirectAndExit( |
|
2160 | + EE_Admin_Page::add_query_args_and_nonce( |
|
2161 | + array( |
|
2162 | + 'page' => 'espresso_batch', |
|
2163 | + 'batch' => EED_Batch::batch_job, |
|
2164 | + 'EVT_IDs' => $event_ids, |
|
2165 | + 'deletion_job_code' => $deletion_job_code, |
|
2166 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'), |
|
2167 | + 'return_url' => urlencode($return_url), |
|
2168 | + ), |
|
2169 | + admin_url() |
|
2170 | + ) |
|
2171 | + ); |
|
2172 | + } |
|
2173 | + |
|
2174 | + /** |
|
2175 | + * Checks for a POST submission |
|
2176 | + * @since 4.10.12.p |
|
2177 | + */ |
|
2178 | + protected function confirmDeletion() |
|
2179 | + { |
|
2180 | + $deletion_redirect_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion'); |
|
2181 | + $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url()); |
|
2182 | + } |
|
2183 | + |
|
2184 | + /** |
|
2185 | + * A page for users to preview what exactly will be deleted, and confirm they want to delete it. |
|
2186 | + * @since 4.10.12.p |
|
2187 | + * @throws EE_Error |
|
2188 | + */ |
|
2189 | + protected function previewDeletion() |
|
2190 | + { |
|
2191 | + $preview_deletion_logic = $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion'); |
|
2192 | + $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url())); |
|
2193 | + $this->display_admin_page_with_no_sidebar(); |
|
2194 | + } |
|
2195 | + |
|
2196 | + /** |
|
2197 | + * get total number of events |
|
2198 | + * |
|
2199 | + * @access public |
|
2200 | + * @return int |
|
2201 | + */ |
|
2202 | + public function total_events() |
|
2203 | + { |
|
2204 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2205 | + return $count; |
|
2206 | + } |
|
2207 | + |
|
2208 | + |
|
2209 | + /** |
|
2210 | + * get total number of draft events |
|
2211 | + * |
|
2212 | + * @access public |
|
2213 | + * @return int |
|
2214 | + */ |
|
2215 | + public function total_events_draft() |
|
2216 | + { |
|
2217 | + $where = array( |
|
2218 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
2219 | + ); |
|
2220 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2221 | + return $count; |
|
2222 | + } |
|
2223 | + |
|
2224 | + |
|
2225 | + /** |
|
2226 | + * get total number of trashed events |
|
2227 | + * |
|
2228 | + * @access public |
|
2229 | + * @return int |
|
2230 | + */ |
|
2231 | + public function total_trashed_events() |
|
2232 | + { |
|
2233 | + $where = array( |
|
2234 | + 'status' => 'trash', |
|
2235 | + ); |
|
2236 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2237 | + return $count; |
|
2238 | + } |
|
2239 | + |
|
2240 | + |
|
2241 | + /** |
|
2242 | + * _default_event_settings |
|
2243 | + * This generates the Default Settings Tab |
|
2244 | + * |
|
2245 | + * @return void |
|
2246 | + * @throws EE_Error |
|
2247 | + */ |
|
2248 | + protected function _default_event_settings() |
|
2249 | + { |
|
2250 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2251 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2252 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2253 | + $this->display_admin_page_with_sidebar(); |
|
2254 | + } |
|
2255 | + |
|
2256 | + |
|
2257 | + /** |
|
2258 | + * Return the form for event settings. |
|
2259 | + * |
|
2260 | + * @return EE_Form_Section_Proper |
|
2261 | + * @throws EE_Error |
|
2262 | + */ |
|
2263 | + protected function _default_event_settings_form() |
|
2264 | + { |
|
2265 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2266 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2267 | + // exclude |
|
2268 | + array( |
|
2269 | + EEM_Registration::status_id_cancelled, |
|
2270 | + EEM_Registration::status_id_declined, |
|
2271 | + EEM_Registration::status_id_incomplete, |
|
2272 | + EEM_Registration::status_id_wait_list, |
|
2273 | + ), |
|
2274 | + true |
|
2275 | + ); |
|
2276 | + return new EE_Form_Section_Proper( |
|
2277 | + array( |
|
2278 | + 'name' => 'update_default_event_settings', |
|
2279 | + 'html_id' => 'update_default_event_settings', |
|
2280 | + 'html_class' => 'form-table', |
|
2281 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2282 | + 'subsections' => apply_filters( |
|
2283 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2284 | + array( |
|
2285 | + 'default_reg_status' => new EE_Select_Input( |
|
2286 | + $registration_stati_for_selection, |
|
2287 | + array( |
|
2288 | + 'default' => isset($registration_config->default_STS_ID) |
|
2289 | + && array_key_exists( |
|
2290 | + $registration_config->default_STS_ID, |
|
2291 | + $registration_stati_for_selection |
|
2292 | + ) |
|
2293 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
2294 | + : EEM_Registration::status_id_pending_payment, |
|
2295 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2296 | + . EEH_Template::get_help_tab_link( |
|
2297 | + 'default_settings_status_help_tab' |
|
2298 | + ), |
|
2299 | + 'html_help_text' => esc_html__( |
|
2300 | + '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.', |
|
2301 | + 'event_espresso' |
|
2302 | + ), |
|
2303 | + ) |
|
2304 | + ), |
|
2305 | + 'default_max_tickets' => new EE_Integer_Input( |
|
2306 | + array( |
|
2307 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2308 | + ? $registration_config->default_maximum_number_of_tickets |
|
2309 | + : EEM_Event::get_default_additional_limit(), |
|
2310 | + 'html_label_text' => esc_html__( |
|
2311 | + 'Default Maximum Tickets Allowed Per Order:', |
|
2312 | + 'event_espresso' |
|
2313 | + ) |
|
2314 | + . EEH_Template::get_help_tab_link( |
|
2315 | + 'default_maximum_tickets_help_tab"' |
|
2316 | + ), |
|
2317 | + 'html_help_text' => esc_html__( |
|
2318 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2319 | + 'event_espresso' |
|
2320 | + ), |
|
2321 | + ) |
|
2322 | + ), |
|
2323 | + ) |
|
2324 | + ), |
|
2325 | + ) |
|
2326 | + ); |
|
2327 | + } |
|
2328 | + |
|
2329 | + |
|
2330 | + /** |
|
2331 | + * _update_default_event_settings |
|
2332 | + * |
|
2333 | + * @access protected |
|
2334 | + * @return void |
|
2335 | + * @throws EE_Error |
|
2336 | + */ |
|
2337 | + protected function _update_default_event_settings() |
|
2338 | + { |
|
2339 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2340 | + $form = $this->_default_event_settings_form(); |
|
2341 | + if ($form->was_submitted()) { |
|
2342 | + $form->receive_form_submission(); |
|
2343 | + if ($form->is_valid()) { |
|
2344 | + $valid_data = $form->valid_data(); |
|
2345 | + if (isset($valid_data['default_reg_status'])) { |
|
2346 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2347 | + } |
|
2348 | + if (isset($valid_data['default_max_tickets'])) { |
|
2349 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2350 | + } |
|
2351 | + // update because data was valid! |
|
2352 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
2353 | + EE_Error::overwrite_success(); |
|
2354 | + EE_Error::add_success( |
|
2355 | + esc_html__('Default Event Settings were updated', 'event_espresso') |
|
2356 | + ); |
|
2357 | + } |
|
2358 | + } |
|
2359 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2360 | + } |
|
2361 | + |
|
2362 | + |
|
2363 | + /************* Templates *************/ |
|
2364 | + protected function _template_settings() |
|
2365 | + { |
|
2366 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2367 | + $this->_template_args['preview_img'] = '<img src="' |
|
2368 | + . EVENTS_ASSETS_URL |
|
2369 | + . '/images/' |
|
2370 | + . 'caffeinated_template_features.jpg" alt="' |
|
2371 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2372 | + . '" />'; |
|
2373 | + $this->_template_args['preview_text'] = '<strong>' |
|
2374 | + . esc_html__( |
|
2375 | + '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.', |
|
2376 | + 'event_espresso' |
|
2377 | + ) . '</strong>'; |
|
2378 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2379 | + } |
|
2380 | + |
|
2381 | + |
|
2382 | + /** Event Category Stuff **/ |
|
2383 | + /** |
|
2384 | + * set the _category property with the category object for the loaded page. |
|
2385 | + * |
|
2386 | + * @access private |
|
2387 | + * @return void |
|
2388 | + */ |
|
2389 | + private function _set_category_object() |
|
2390 | + { |
|
2391 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2392 | + return; |
|
2393 | + } //already have the category object so get out. |
|
2394 | + // set default category object |
|
2395 | + $this->_set_empty_category_object(); |
|
2396 | + // only set if we've got an id |
|
2397 | + if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2398 | + return; |
|
2399 | + } |
|
2400 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2401 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2402 | + if (! empty($term)) { |
|
2403 | + $this->_category->category_name = $term->name; |
|
2404 | + $this->_category->category_identifier = $term->slug; |
|
2405 | + $this->_category->category_desc = $term->description; |
|
2406 | + $this->_category->id = $term->term_id; |
|
2407 | + $this->_category->parent = $term->parent; |
|
2408 | + } |
|
2409 | + } |
|
2410 | + |
|
2411 | + |
|
2412 | + /** |
|
2413 | + * Clears out category properties. |
|
2414 | + */ |
|
2415 | + private function _set_empty_category_object() |
|
2416 | + { |
|
2417 | + $this->_category = new stdClass(); |
|
2418 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2419 | + $this->_category->id = $this->_category->parent = 0; |
|
2420 | + } |
|
2421 | + |
|
2422 | + |
|
2423 | + /** |
|
2424 | + * @throws EE_Error |
|
2425 | + */ |
|
2426 | + protected function _category_list_table() |
|
2427 | + { |
|
2428 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2429 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2430 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2431 | + 'add_category', |
|
2432 | + 'add_category', |
|
2433 | + array(), |
|
2434 | + 'add-new-h2' |
|
2435 | + ); |
|
2436 | + $this->display_admin_list_table_page_with_sidebar(); |
|
2437 | + } |
|
2438 | + |
|
2439 | + |
|
2440 | + /** |
|
2441 | + * Output category details view. |
|
2442 | + */ |
|
2443 | + protected function _category_details($view) |
|
2444 | + { |
|
2445 | + // load formatter helper |
|
2446 | + // load field generator helper |
|
2447 | + $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
|
2448 | + $this->_set_add_edit_form_tags($route); |
|
2449 | + $this->_set_category_object(); |
|
2450 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2451 | + $delete_action = 'delete_category'; |
|
2452 | + // custom redirect |
|
2453 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2454 | + array('action' => 'category_list'), |
|
2455 | + $this->_admin_base_url |
|
2456 | + ); |
|
2457 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2458 | + // take care of contents |
|
2459 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2460 | + $this->display_admin_page_with_sidebar(); |
|
2461 | + } |
|
2462 | + |
|
2463 | + |
|
2464 | + /** |
|
2465 | + * Output category details content. |
|
2466 | + */ |
|
2467 | + protected function _category_details_content() |
|
2468 | + { |
|
2469 | + $editor_args['category_desc'] = array( |
|
2470 | + 'type' => 'wp_editor', |
|
2471 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2472 | + 'class' => 'my_editor_custom', |
|
2473 | + 'wpeditor_args' => array('media_buttons' => false), |
|
2474 | + ); |
|
2475 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2476 | + $all_terms = get_terms( |
|
2477 | + array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
2478 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2479 | + ); |
|
2480 | + // setup category select for term parents. |
|
2481 | + $category_select_values[] = array( |
|
2482 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2483 | + 'id' => 0, |
|
2484 | + ); |
|
2485 | + foreach ($all_terms as $term) { |
|
2486 | + $category_select_values[] = array( |
|
2487 | + 'text' => $term->name, |
|
2488 | + 'id' => $term->term_id, |
|
2489 | + ); |
|
2490 | + } |
|
2491 | + $category_select = EEH_Form_Fields::select_input( |
|
2492 | + 'category_parent', |
|
2493 | + $category_select_values, |
|
2494 | + $this->_category->parent |
|
2495 | + ); |
|
2496 | + $template_args = array( |
|
2497 | + 'category' => $this->_category, |
|
2498 | + 'category_select' => $category_select, |
|
2499 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2500 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2501 | + 'disable' => '', |
|
2502 | + 'disabled_message' => false, |
|
2503 | + ); |
|
2504 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2505 | + return EEH_Template::display_template($template, $template_args, true); |
|
2506 | + } |
|
2507 | + |
|
2508 | + |
|
2509 | + /** |
|
2510 | + * Handles deleting categories. |
|
2511 | + */ |
|
2512 | + protected function _delete_categories() |
|
2513 | + { |
|
2514 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
2515 | + : (array) $this->_req_data['category_id']; |
|
2516 | + foreach ($cat_ids as $cat_id) { |
|
2517 | + $this->_delete_category($cat_id); |
|
2518 | + } |
|
2519 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2520 | + $query_args = array( |
|
2521 | + 'action' => 'category_list', |
|
2522 | + ); |
|
2523 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2524 | + } |
|
2525 | + |
|
2526 | + |
|
2527 | + /** |
|
2528 | + * Handles deleting specific category. |
|
2529 | + * |
|
2530 | + * @param int $cat_id |
|
2531 | + */ |
|
2532 | + protected function _delete_category($cat_id) |
|
2533 | + { |
|
2534 | + $cat_id = absint($cat_id); |
|
2535 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2536 | + } |
|
2537 | + |
|
2538 | + |
|
2539 | + /** |
|
2540 | + * Handles triggering the update or insertion of a new category. |
|
2541 | + * |
|
2542 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
2543 | + */ |
|
2544 | + protected function _insert_or_update_category($new_category) |
|
2545 | + { |
|
2546 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2547 | + $success = 0; // we already have a success message so lets not send another. |
|
2548 | + if ($cat_id) { |
|
2549 | + $query_args = array( |
|
2550 | + 'action' => 'edit_category', |
|
2551 | + 'EVT_CAT_ID' => $cat_id, |
|
2552 | + ); |
|
2553 | + } else { |
|
2554 | + $query_args = array('action' => 'add_category'); |
|
2555 | + } |
|
2556 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2557 | + } |
|
2558 | + |
|
2559 | + |
|
2560 | + /** |
|
2561 | + * Inserts or updates category |
|
2562 | + * |
|
2563 | + * @param bool $update (true indicates we're updating a category). |
|
2564 | + * @return bool|mixed|string |
|
2565 | + */ |
|
2566 | + private function _insert_category($update = false) |
|
2567 | + { |
|
2568 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2569 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2570 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2571 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2572 | + if (empty($category_name)) { |
|
2573 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2574 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2575 | + return false; |
|
2576 | + } |
|
2577 | + $term_args = array( |
|
2578 | + 'name' => $category_name, |
|
2579 | + 'description' => $category_desc, |
|
2580 | + 'parent' => $category_parent, |
|
2581 | + ); |
|
2582 | + // was the category_identifier input disabled? |
|
2583 | + if (isset($this->_req_data['category_identifier'])) { |
|
2584 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2585 | + } |
|
2586 | + $insert_ids = $update |
|
2587 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2588 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2589 | + if (! is_array($insert_ids)) { |
|
2590 | + $msg = esc_html__( |
|
2591 | + 'An error occurred and the category has not been saved to the database.', |
|
2592 | + 'event_espresso' |
|
2593 | + ); |
|
2594 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2595 | + } else { |
|
2596 | + $cat_id = $insert_ids['term_id']; |
|
2597 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2598 | + EE_Error::add_success($msg); |
|
2599 | + } |
|
2600 | + return $cat_id; |
|
2601 | + } |
|
2602 | + |
|
2603 | + |
|
2604 | + /** |
|
2605 | + * Gets categories or count of categories matching the arguments in the request. |
|
2606 | + * |
|
2607 | + * @param int $per_page |
|
2608 | + * @param int $current_page |
|
2609 | + * @param bool $count |
|
2610 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
2611 | + */ |
|
2612 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2613 | + { |
|
2614 | + // testing term stuff |
|
2615 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2616 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2617 | + $limit = ($current_page - 1) * $per_page; |
|
2618 | + $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2619 | + if (isset($this->_req_data['s'])) { |
|
2620 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2621 | + $where['OR'] = array( |
|
2622 | + 'Term.name' => array('LIKE', $sstr), |
|
2623 | + 'description' => array('LIKE', $sstr), |
|
2624 | + ); |
|
2625 | + } |
|
2626 | + $query_params = array( |
|
2627 | + $where, |
|
2628 | + 'order_by' => array($orderby => $order), |
|
2629 | + 'limit' => $limit . ',' . $per_page, |
|
2630 | + 'force_join' => array('Term'), |
|
2631 | + ); |
|
2632 | + $categories = $count |
|
2633 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2634 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2635 | + return $categories; |
|
2636 | + } |
|
2637 | + |
|
2638 | + /* end category stuff */ |
|
2639 | + /**************/ |
|
2640 | + |
|
2641 | + |
|
2642 | + /** |
|
2643 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
2644 | + * |
|
2645 | + * @throws EE_Error |
|
2646 | + */ |
|
2647 | + public function save_timezonestring_setting() |
|
2648 | + { |
|
2649 | + $timezone_string = isset($this->_req_data['timezone_selected']) |
|
2650 | + ? $this->_req_data['timezone_selected'] |
|
2651 | + : ''; |
|
2652 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2653 | + EE_Error::add_error( |
|
2654 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2655 | + __FILE__, |
|
2656 | + __FUNCTION__, |
|
2657 | + __LINE__ |
|
2658 | + ); |
|
2659 | + $this->_template_args['error'] = true; |
|
2660 | + $this->_return_json(); |
|
2661 | + } |
|
2662 | + |
|
2663 | + update_option('timezone_string', $timezone_string); |
|
2664 | + EE_Error::add_success( |
|
2665 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2666 | + ); |
|
2667 | + $this->_template_args['success'] = true; |
|
2668 | + $this->_return_json(true, array('action' => 'create_new')); |
|
2669 | + } |
|
2670 | 2670 | } |
@@ -583,11 +583,11 @@ discard block |
||
583 | 583 | { |
584 | 584 | wp_register_style( |
585 | 585 | 'events-admin-css', |
586 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
586 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
587 | 587 | array(), |
588 | 588 | EVENT_ESPRESSO_VERSION |
589 | 589 | ); |
590 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
590 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
591 | 591 | wp_enqueue_style('events-admin-css'); |
592 | 592 | wp_enqueue_style('ee-cat-admin'); |
593 | 593 | // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | // scripts |
596 | 596 | wp_register_script( |
597 | 597 | 'event_editor_js', |
598 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
598 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
599 | 599 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
600 | 600 | EVENT_ESPRESSO_VERSION, |
601 | 601 | true |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | wp_enqueue_style('espresso-ui-theme'); |
622 | 622 | wp_register_style( |
623 | 623 | 'event-editor-css', |
624 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
624 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
625 | 625 | array('ee-admin-css'), |
626 | 626 | EVENT_ESPRESSO_VERSION |
627 | 627 | ); |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | // scripts |
630 | 630 | wp_register_script( |
631 | 631 | 'event-datetime-metabox', |
632 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
632 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
633 | 633 | array('event_editor_js', 'ee-datepicker'), |
634 | 634 | EVENT_ESPRESSO_VERSION |
635 | 635 | ); |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | public function verify_event_edit($event = null, $req_type = '') |
699 | 699 | { |
700 | 700 | // don't need to do this when processing |
701 | - if (! empty($req_type)) { |
|
701 | + if ( ! empty($req_type)) { |
|
702 | 702 | return; |
703 | 703 | } |
704 | 704 | // no event? |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $event = $this->_cpt_model_obj; |
708 | 708 | } |
709 | 709 | // STILL no event? |
710 | - if (! $event instanceof EE_Event) { |
|
710 | + if ( ! $event instanceof EE_Event) { |
|
711 | 711 | return; |
712 | 712 | } |
713 | 713 | $orig_status = $event->status(); |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | ); |
747 | 747 | } |
748 | 748 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
749 | - if (! $event->tickets_on_sale()) { |
|
749 | + if ( ! $event->tickets_on_sale()) { |
|
750 | 750 | return; |
751 | 751 | } |
752 | 752 | // made it here so show warning |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | { |
792 | 792 | $has_timezone_string = get_option('timezone_string'); |
793 | 793 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
794 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
794 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
795 | 795 | EE_Error::add_attention( |
796 | 796 | sprintf( |
797 | 797 | esc_html__( |
@@ -875,31 +875,31 @@ discard block |
||
875 | 875 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
876 | 876 | $statuses = array( |
877 | 877 | 'sold_out_status' => array( |
878 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
878 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
879 | 879 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
880 | 880 | ), |
881 | 881 | 'active_status' => array( |
882 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
882 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
883 | 883 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
884 | 884 | ), |
885 | 885 | 'upcoming_status' => array( |
886 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
886 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
887 | 887 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
888 | 888 | ), |
889 | 889 | 'postponed_status' => array( |
890 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
890 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
891 | 891 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
892 | 892 | ), |
893 | 893 | 'cancelled_status' => array( |
894 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
894 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
895 | 895 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
896 | 896 | ), |
897 | 897 | 'expired_status' => array( |
898 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
898 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
899 | 899 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
900 | 900 | ), |
901 | 901 | 'inactive_status' => array( |
902 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
902 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
903 | 903 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
904 | 904 | ), |
905 | 905 | ); |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | */ |
914 | 914 | private function _event_model() |
915 | 915 | { |
916 | - if (! $this->_event_model instanceof EEM_Event) { |
|
916 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
917 | 917 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
918 | 918 | } |
919 | 919 | return $this->_event_model; |
@@ -933,7 +933,7 @@ discard block |
||
933 | 933 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
934 | 934 | { |
935 | 935 | // make sure this is only when editing |
936 | - if (! empty($id)) { |
|
936 | + if ( ! empty($id)) { |
|
937 | 937 | $post = get_post($id); |
938 | 938 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
939 | 939 | . esc_html__('Shortcode', 'event_espresso') |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | 'button' |
968 | 968 | ); |
969 | 969 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
970 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
970 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
971 | 971 | 'create_new', |
972 | 972 | 'add', |
973 | 973 | array(), |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | */ |
1108 | 1108 | protected function _default_venue_update(\EE_Event $evtobj, $data) |
1109 | 1109 | { |
1110 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1110 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
1111 | 1111 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
1112 | 1112 | $rows_affected = null; |
1113 | 1113 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | 'status' => 'publish', |
1139 | 1139 | ); |
1140 | 1140 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
1141 | - if (! empty($venue_id)) { |
|
1141 | + if ( ! empty($venue_id)) { |
|
1142 | 1142 | $update_where = array($venue_model->primary_key_name() => $venue_id); |
1143 | 1143 | $rows_affected = $venue_model->update($venue_array, array($update_where)); |
1144 | 1144 | // 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. |
@@ -1180,7 +1180,7 @@ discard block |
||
1180 | 1180 | 'DTT_order' => $row, |
1181 | 1181 | ); |
1182 | 1182 | // 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. |
1183 | - if (! empty($dtt['DTT_ID'])) { |
|
1183 | + if ( ! empty($dtt['DTT_ID'])) { |
|
1184 | 1184 | $DTM = EE_Registry::instance() |
1185 | 1185 | ->load_model('Datetime', array($evtobj->get_timezone())) |
1186 | 1186 | ->get_one_by_ID($dtt['DTT_ID']); |
@@ -1190,7 +1190,7 @@ discard block |
||
1190 | 1190 | $DTM->set($field, $value); |
1191 | 1191 | } |
1192 | 1192 | // 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. |
1193 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1193 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
1194 | 1194 | } else { |
1195 | 1195 | $DTM = EE_Registry::instance()->load_class( |
1196 | 1196 | 'Datetime', |
@@ -1223,14 +1223,14 @@ discard block |
||
1223 | 1223 | foreach ($data['edit_tickets'] as $row => $tkt) { |
1224 | 1224 | $incoming_date_formats = array('Y-m-d', 'h:i a'); |
1225 | 1225 | $update_prices = false; |
1226 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1227 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1226 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
1227 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1228 | 1228 | // trim inputs to ensure any excess whitespace is removed. |
1229 | 1229 | $tkt = array_map('trim', $tkt); |
1230 | 1230 | if (empty($tkt['TKT_start_date'])) { |
1231 | 1231 | // let's use now in the set timezone. |
1232 | 1232 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
1233 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1233 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
1234 | 1234 | } |
1235 | 1235 | if (empty($tkt['TKT_end_date'])) { |
1236 | 1236 | // use the start date of the first datetime |
@@ -1265,7 +1265,7 @@ discard block |
||
1265 | 1265 | // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
1266 | 1266 | // 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. |
1267 | 1267 | // 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. |
1268 | - if (! empty($tkt['TKT_ID'])) { |
|
1268 | + if ( ! empty($tkt['TKT_ID'])) { |
|
1269 | 1269 | $TKT = EE_Registry::instance() |
1270 | 1270 | ->load_model('Ticket', array($evtobj->get_timezone())) |
1271 | 1271 | ->get_one_by_ID($tkt['TKT_ID']); |
@@ -1300,7 +1300,7 @@ discard block |
||
1300 | 1300 | $TKT->set('TKT_deleted', 1); |
1301 | 1301 | $TKT->save(); |
1302 | 1302 | // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
1303 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1303 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1304 | 1304 | // 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. |
1305 | 1305 | $TKT = clone $TKT; |
1306 | 1306 | $TKT->set('TKT_ID', 0); |
@@ -1345,9 +1345,9 @@ discard block |
||
1345 | 1345 | } |
1346 | 1346 | // initially let's add the ticket to the dtt |
1347 | 1347 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
1348 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1348 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1349 | 1349 | // add prices to ticket |
1350 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1350 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
1351 | 1351 | } |
1352 | 1352 | // 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. |
1353 | 1353 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | $id = absint($id); |
1357 | 1357 | // get the ticket for this id |
1358 | 1358 | $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
1359 | - if (! $tkt_to_remove instanceof EE_Ticket) { |
|
1359 | + if ( ! $tkt_to_remove instanceof EE_Ticket) { |
|
1360 | 1360 | continue; |
1361 | 1361 | } |
1362 | 1362 | |
@@ -1508,7 +1508,7 @@ discard block |
||
1508 | 1508 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
1509 | 1509 | // load template |
1510 | 1510 | EEH_Template::display_template( |
1511 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1511 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
1512 | 1512 | $publish_box_extra_args |
1513 | 1513 | ); |
1514 | 1514 | } |
@@ -1601,7 +1601,7 @@ discard block |
||
1601 | 1601 | 'default_where_conditions' => 'none', |
1602 | 1602 | ) |
1603 | 1603 | ); |
1604 | - if (! empty($related_tickets)) { |
|
1604 | + if ( ! empty($related_tickets)) { |
|
1605 | 1605 | $template_args['total_ticket_rows'] = count($related_tickets); |
1606 | 1606 | $row = 0; |
1607 | 1607 | foreach ($related_tickets as $ticket) { |
@@ -1635,7 +1635,7 @@ discard block |
||
1635 | 1635 | ); |
1636 | 1636 | $template = apply_filters( |
1637 | 1637 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
1638 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1638 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
1639 | 1639 | ); |
1640 | 1640 | EEH_Template::display_template($template, $template_args); |
1641 | 1641 | } |
@@ -1653,7 +1653,7 @@ discard block |
||
1653 | 1653 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
1654 | 1654 | { |
1655 | 1655 | $template_args = array( |
1656 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1656 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
1657 | 1657 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
1658 | 1658 | : '', |
1659 | 1659 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1665,10 +1665,10 @@ discard block |
||
1665 | 1665 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
1666 | 1666 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
1667 | 1667 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
1668 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1669 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1668 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1669 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1670 | 1670 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
1671 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1671 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1672 | 1672 | : ' disabled=disabled', |
1673 | 1673 | ); |
1674 | 1674 | $price = $ticket->ID() !== 0 |
@@ -1695,7 +1695,7 @@ discard block |
||
1695 | 1695 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1696 | 1696 | ) |
1697 | 1697 | : null; |
1698 | - if (! empty($earliest_dtt)) { |
|
1698 | + if ( ! empty($earliest_dtt)) { |
|
1699 | 1699 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
1700 | 1700 | } else { |
1701 | 1701 | $template_args['TKT_end_date'] = date( |
@@ -1707,7 +1707,7 @@ discard block |
||
1707 | 1707 | $template_args = array_merge($template_args, $price_args); |
1708 | 1708 | $template = apply_filters( |
1709 | 1709 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
1710 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1710 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
1711 | 1711 | $ticket |
1712 | 1712 | ); |
1713 | 1713 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1762,7 +1762,7 @@ discard block |
||
1762 | 1762 | $default_reg_status_values |
1763 | 1763 | ); |
1764 | 1764 | EEH_Template::display_template( |
1765 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1765 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
1766 | 1766 | $template_args |
1767 | 1767 | ); |
1768 | 1768 | } |
@@ -1784,7 +1784,7 @@ discard block |
||
1784 | 1784 | { |
1785 | 1785 | $EEME = $this->_event_model(); |
1786 | 1786 | $offset = ($current_page - 1) * $per_page; |
1787 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1787 | + $limit = $count ? null : $offset.','.$per_page; |
|
1788 | 1788 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
1789 | 1789 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
1790 | 1790 | if (isset($this->_req_data['month_range'])) { |
@@ -1813,7 +1813,7 @@ discard block |
||
1813 | 1813 | // categories? |
1814 | 1814 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
1815 | 1815 | ? $this->_req_data['EVT_CAT'] : null; |
1816 | - if (! empty($category)) { |
|
1816 | + if ( ! empty($category)) { |
|
1817 | 1817 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
1818 | 1818 | $where['Term_Taxonomy.term_id'] = $category; |
1819 | 1819 | } |
@@ -1821,7 +1821,7 @@ discard block |
||
1821 | 1821 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
1822 | 1822 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
1823 | 1823 | $DateTime = new DateTime( |
1824 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1824 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
1825 | 1825 | new DateTimeZone('UTC') |
1826 | 1826 | ); |
1827 | 1827 | $start = $DateTime->getTimestamp(); |
@@ -1847,11 +1847,11 @@ discard block |
||
1847 | 1847 | ->format(implode(' ', $start_formats)); |
1848 | 1848 | $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
1849 | 1849 | } |
1850 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1850 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1851 | 1851 | $where['EVT_wp_user'] = get_current_user_id(); |
1852 | 1852 | } else { |
1853 | - if (! isset($where['status'])) { |
|
1854 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1853 | + if ( ! isset($where['status'])) { |
|
1854 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1855 | 1855 | $where['OR'] = array( |
1856 | 1856 | 'status*restrict_private' => array('!=', 'private'), |
1857 | 1857 | 'AND' => array( |
@@ -1872,7 +1872,7 @@ discard block |
||
1872 | 1872 | } |
1873 | 1873 | // search query handling |
1874 | 1874 | if (isset($this->_req_data['s'])) { |
1875 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1875 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1876 | 1876 | $where['OR'] = array( |
1877 | 1877 | 'EVT_name' => array('LIKE', $search_string), |
1878 | 1878 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1968,7 +1968,7 @@ discard block |
||
1968 | 1968 | // clean status |
1969 | 1969 | $event_status = sanitize_key($event_status); |
1970 | 1970 | // grab status |
1971 | - if (! empty($event_status)) { |
|
1971 | + if ( ! empty($event_status)) { |
|
1972 | 1972 | $success = $this->_change_event_status($EVT_ID, $event_status); |
1973 | 1973 | } else { |
1974 | 1974 | $success = false; |
@@ -2005,7 +2005,7 @@ discard block |
||
2005 | 2005 | // clean status |
2006 | 2006 | $event_status = sanitize_key($event_status); |
2007 | 2007 | // grab status |
2008 | - if (! empty($event_status)) { |
|
2008 | + if ( ! empty($event_status)) { |
|
2009 | 2009 | $success = true; |
2010 | 2010 | // determine the event id and set to array. |
2011 | 2011 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
@@ -2052,7 +2052,7 @@ discard block |
||
2052 | 2052 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
2053 | 2053 | { |
2054 | 2054 | // grab event id |
2055 | - if (! $EVT_ID) { |
|
2055 | + if ( ! $EVT_ID) { |
|
2056 | 2056 | $msg = esc_html__( |
2057 | 2057 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
2058 | 2058 | 'event_espresso' |
@@ -2122,7 +2122,7 @@ discard block |
||
2122 | 2122 | */ |
2123 | 2123 | protected function getModelObjNodeGroupPersister() |
2124 | 2124 | { |
2125 | - if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2125 | + if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) { |
|
2126 | 2126 | $this->model_obj_node_group_persister = $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao'); |
2127 | 2127 | } |
2128 | 2128 | return $this->model_obj_node_group_persister; |
@@ -2374,7 +2374,7 @@ discard block |
||
2374 | 2374 | . esc_html__( |
2375 | 2375 | '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.', |
2376 | 2376 | 'event_espresso' |
2377 | - ) . '</strong>'; |
|
2377 | + ).'</strong>'; |
|
2378 | 2378 | $this->display_admin_caf_preview_page('template_settings_tab'); |
2379 | 2379 | } |
2380 | 2380 | |
@@ -2394,12 +2394,12 @@ discard block |
||
2394 | 2394 | // set default category object |
2395 | 2395 | $this->_set_empty_category_object(); |
2396 | 2396 | // only set if we've got an id |
2397 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2397 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2398 | 2398 | return; |
2399 | 2399 | } |
2400 | 2400 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
2401 | 2401 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
2402 | - if (! empty($term)) { |
|
2402 | + if ( ! empty($term)) { |
|
2403 | 2403 | $this->_category->category_name = $term->name; |
2404 | 2404 | $this->_category->category_identifier = $term->slug; |
2405 | 2405 | $this->_category->category_desc = $term->description; |
@@ -2427,7 +2427,7 @@ discard block |
||
2427 | 2427 | { |
2428 | 2428 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2429 | 2429 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
2430 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2430 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
2431 | 2431 | 'add_category', |
2432 | 2432 | 'add_category', |
2433 | 2433 | array(), |
@@ -2501,7 +2501,7 @@ discard block |
||
2501 | 2501 | 'disable' => '', |
2502 | 2502 | 'disabled_message' => false, |
2503 | 2503 | ); |
2504 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2504 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
2505 | 2505 | return EEH_Template::display_template($template, $template_args, true); |
2506 | 2506 | } |
2507 | 2507 | |
@@ -2586,7 +2586,7 @@ discard block |
||
2586 | 2586 | $insert_ids = $update |
2587 | 2587 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
2588 | 2588 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
2589 | - if (! is_array($insert_ids)) { |
|
2589 | + if ( ! is_array($insert_ids)) { |
|
2590 | 2590 | $msg = esc_html__( |
2591 | 2591 | 'An error occurred and the category has not been saved to the database.', |
2592 | 2592 | 'event_espresso' |
@@ -2617,7 +2617,7 @@ discard block |
||
2617 | 2617 | $limit = ($current_page - 1) * $per_page; |
2618 | 2618 | $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
2619 | 2619 | if (isset($this->_req_data['s'])) { |
2620 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2620 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
2621 | 2621 | $where['OR'] = array( |
2622 | 2622 | 'Term.name' => array('LIKE', $sstr), |
2623 | 2623 | 'description' => array('LIKE', $sstr), |
@@ -2626,7 +2626,7 @@ discard block |
||
2626 | 2626 | $query_params = array( |
2627 | 2627 | $where, |
2628 | 2628 | 'order_by' => array($orderby => $order), |
2629 | - 'limit' => $limit . ',' . $per_page, |
|
2629 | + 'limit' => $limit.','.$per_page, |
|
2630 | 2630 | 'force_join' => array('Term'), |
2631 | 2631 | ); |
2632 | 2632 | $categories = $count |