@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | * @param EE_Message_Resource_Manager $message_resource_manager |
| 37 | 37 | */ |
| 38 | - public function __construct( EE_Message_Resource_Manager $message_resource_manager ) { |
|
| 38 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager) { |
|
| 39 | 39 | $this->_message_resource_manager = $message_resource_manager; |
| 40 | 40 | $this->_init_queue_and_generator(); |
| 41 | 41 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * - $_generator = holds the messages generator |
| 51 | 51 | */ |
| 52 | 52 | protected function _init_queue_and_generator() { |
| 53 | - $this->_generator = EE_Registry::factory( 'EE_Messages_Generator' ); |
|
| 53 | + $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
| 54 | 54 | $this->_queue = $this->_generator->generation_queue(); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -75,31 +75,31 @@ discard block |
||
| 75 | 75 | * @param EE_Messages_Queue $queue_to_process |
| 76 | 76 | * @return bool true for success false for error. |
| 77 | 77 | */ |
| 78 | - public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) { |
|
| 78 | + public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) { |
|
| 79 | 79 | $success = false; |
| 80 | 80 | $messages_to_send = array(); |
| 81 | 81 | $messages_to_generate = array(); |
| 82 | 82 | //loop through and setup the various messages from the queue so we know what is being processed |
| 83 | 83 | $queue_to_process->get_message_repository()->rewind(); |
| 84 | - foreach ( $queue_to_process->get_message_repository() as $message ) { |
|
| 85 | - if ( $message->STS_ID() === EEM_Message::status_incomplete ) { |
|
| 84 | + foreach ($queue_to_process->get_message_repository() as $message) { |
|
| 85 | + if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
| 86 | 86 | $messages_to_generate[] = $message; |
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) { |
|
| 90 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
| 91 | 91 | $messages_to_send[] = $message; |
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | //do generation/sends |
| 97 | - if ( $messages_to_generate ) { |
|
| 98 | - $success = $this->batch_generate_from_queue( $messages_to_generate, true ); |
|
| 97 | + if ($messages_to_generate) { |
|
| 98 | + $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - if ( $messages_to_send ) { |
|
| 102 | - $sent = $this->batch_send_from_queue( $messages_to_send, true ); |
|
| 101 | + if ($messages_to_send) { |
|
| 102 | + $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
| 103 | 103 | //if there was messages to generate and it failed, then we override any success value for the sending process |
| 104 | 104 | //otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
| 105 | 105 | //Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
| 120 | 120 | * generated messages. |
| 121 | 121 | */ |
| 122 | - public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) { |
|
| 123 | - if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) { |
|
| 122 | + public function batch_generate_from_queue($messages = array(), $clear_queue = false) { |
|
| 123 | + if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
| 124 | 124 | $new_queue = $this->_generator->generate(); |
| 125 | - if ( $new_queue instanceof EE_Messages_Queue ) { |
|
| 125 | + if ($new_queue instanceof EE_Messages_Queue) { |
|
| 126 | 126 | //unlock queue |
| 127 | 127 | $this->_queue->unlock_queue(); |
| 128 | - $new_queue->initiate_request_by_priority( 'send' ); |
|
| 128 | + $new_queue->initiate_request_by_priority('send'); |
|
| 129 | 129 | return $new_queue; |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -146,24 +146,24 @@ discard block |
||
| 146 | 146 | * |
| 147 | 147 | * @return bool true means queue prepped, false means there was a lock so no generation please. |
| 148 | 148 | */ |
| 149 | - protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) { |
|
| 149 | + protected function _build_queue_for_generation($messages = array(), $clear_queue = false) { |
|
| 150 | 150 | |
| 151 | - if ( $clear_queue ) { |
|
| 151 | + if ($clear_queue) { |
|
| 152 | 152 | $this->_init_queue_and_generator(); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if ( $messages ) { |
|
| 155 | + if ($messages) { |
|
| 156 | 156 | //if generation is locked then get out now because that means processing is already happening. |
| 157 | - if ( $this->_queue->is_locked() ) { |
|
| 157 | + if ($this->_queue->is_locked()) { |
|
| 158 | 158 | return false; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $this->_queue->lock_queue(); |
| 162 | - $messages = is_array( $messages ) ? $messages : array( $messages ); |
|
| 163 | - foreach ( $messages as $message ) { |
|
| 164 | - if ( $message instanceof EE_Message ) { |
|
| 162 | + $messages = is_array($messages) ? $messages : array($messages); |
|
| 163 | + foreach ($messages as $message) { |
|
| 164 | + if ($message instanceof EE_Message) { |
|
| 165 | 165 | $data = $message->all_extra_meta_array(); |
| 166 | - $this->_queue->add( $message, $data ); |
|
| 166 | + $this->_queue->add($message, $data); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | return true; |
@@ -181,22 +181,22 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
| 183 | 183 | */ |
| 184 | - protected function _build_queue_for_sending( $messages, $clear_queue = false ) { |
|
| 184 | + protected function _build_queue_for_sending($messages, $clear_queue = false) { |
|
| 185 | 185 | //if sending is locked then get out now because that means processing is already happening. |
| 186 | - if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) { |
|
| 186 | + if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
| 187 | 187 | return false; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - $this->_queue->lock_queue( EE_Messages_Queue::action_sending ); |
|
| 190 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
| 191 | 191 | |
| 192 | - if ( $clear_queue ) { |
|
| 192 | + if ($clear_queue) { |
|
| 193 | 193 | $this->_init_queue_and_generator(); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - $messages = is_array( $messages ) ? $messages : array( $messages ); |
|
| 196 | + $messages = is_array($messages) ? $messages : array($messages); |
|
| 197 | 197 | |
| 198 | - foreach ( $messages as $message ) { |
|
| 199 | - $this->_queue->add( $message ); |
|
| 198 | + foreach ($messages as $message) { |
|
| 199 | + $this->_queue->add($message); |
|
| 200 | 200 | } |
| 201 | 201 | return true; |
| 202 | 202 | } |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * |
| 213 | 213 | * @return EE_Messages_Queue |
| 214 | 214 | */ |
| 215 | - public function batch_send_from_queue( $messages = array(), $clear_queue = false ) { |
|
| 215 | + public function batch_send_from_queue($messages = array(), $clear_queue = false) { |
|
| 216 | 216 | |
| 217 | - if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) { |
|
| 217 | + if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
| 218 | 218 | $this->_queue->execute(); |
| 219 | - $this->_queue->unlock_queue( EE_Messages_Queue::action_sending ); |
|
| 219 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
| 220 | 220 | } else { |
| 221 | 221 | //get messages to send and execute. |
| 222 | 222 | $this->_queue->get_to_send_batch_and_send(); |
@@ -239,10 +239,10 @@ discard block |
||
| 239 | 239 | * @param EE_Message_To_Generate[] $messages_to_generate |
| 240 | 240 | * @return EE_Messages_Queue |
| 241 | 241 | */ |
| 242 | - public function generate_and_return( $messages_to_generate ) { |
|
| 242 | + public function generate_and_return($messages_to_generate) { |
|
| 243 | 243 | $this->_init_queue_and_generator(); |
| 244 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
| 245 | - return $this->_generator->generate( false ); |
|
| 244 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
| 245 | + return $this->_generator->generate(false); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not (false). |
| 254 | 254 | * @return EE_Messages_Queue |
| 255 | 255 | */ |
| 256 | - public function generate_queue( $persist = true ) { |
|
| 257 | - return $this->_generator->generate( $persist ); |
|
| 256 | + public function generate_queue($persist = true) { |
|
| 257 | + return $this->_generator->generate($persist); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * @param bool $test_send Whether this item is for a test send or not. |
| 268 | 268 | * @return EE_Messages_Queue |
| 269 | 269 | */ |
| 270 | - public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) { |
|
| 271 | - if ( $message_to_generate->valid() ) { |
|
| 272 | - $this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send ); |
|
| 270 | + public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) { |
|
| 271 | + if ($message_to_generate->valid()) { |
|
| 272 | + $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send); |
|
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @param EE_Message_To_Generate[] $messages_to_generate |
| 287 | 287 | */ |
| 288 | - public function batch_queue_for_generation_and_persist( $messages_to_generate ) { |
|
| 288 | + public function batch_queue_for_generation_and_persist($messages_to_generate) { |
|
| 289 | 289 | $this->_init_queue_and_generator(); |
| 290 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
| 290 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
| 291 | 291 | $this->_queue->save(); |
| 292 | 292 | } |
| 293 | 293 | |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | * |
| 304 | 304 | * @param EE_Message_To_Generate[] $messages_to_generate |
| 305 | 305 | */ |
| 306 | - public function batch_queue_for_generation_no_persist( $messages_to_generate ) { |
|
| 306 | + public function batch_queue_for_generation_no_persist($messages_to_generate) { |
|
| 307 | 307 | $this->_init_queue_and_generator(); |
| 308 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
| 308 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -317,15 +317,15 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | * @param EE_Message_To_Generate[] $messages_to_generate |
| 319 | 319 | */ |
| 320 | - protected function _queue_for_generation_loop( $messages_to_generate ) { |
|
| 320 | + protected function _queue_for_generation_loop($messages_to_generate) { |
|
| 321 | 321 | //make sure is in an array. |
| 322 | - if ( ! is_array( $messages_to_generate ) ) { |
|
| 323 | - $messages_to_generate = array( $messages_to_generate ); |
|
| 322 | + if ( ! is_array($messages_to_generate)) { |
|
| 323 | + $messages_to_generate = array($messages_to_generate); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - foreach ( $messages_to_generate as $message_to_generate ) { |
|
| 327 | - if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) { |
|
| 328 | - $this->queue_for_generation( $message_to_generate ); |
|
| 326 | + foreach ($messages_to_generate as $message_to_generate) { |
|
| 327 | + if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
| 328 | + $this->queue_for_generation($message_to_generate); |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | } |
@@ -340,10 +340,10 @@ discard block |
||
| 340 | 340 | * @param EE_Message_To_Generate[] |
| 341 | 341 | * @return EE_Messages_Queue |
| 342 | 342 | */ |
| 343 | - public function generate_and_queue_for_sending( $messages_to_generate ) { |
|
| 343 | + public function generate_and_queue_for_sending($messages_to_generate) { |
|
| 344 | 344 | $this->_init_queue_and_generator(); |
| 345 | - $this->_queue_for_generation_loop( $messages_to_generate ); |
|
| 346 | - return $this->_generator->generate( true ); |
|
| 345 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
| 346 | + return $this->_generator->generate(true); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | * @param bool $test_send Whether this is a test send or not. |
| 358 | 358 | * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
| 359 | 359 | */ |
| 360 | - public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) { |
|
| 361 | - if ( ! $message_to_generate->valid() ) { |
|
| 360 | + public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) { |
|
| 361 | + if ( ! $message_to_generate->valid()) { |
|
| 362 | 362 | EE_Error::add_error( |
| 363 | - __( 'Unable to generate preview because of invalid data', 'event_espresso' ), |
|
| 363 | + __('Unable to generate preview because of invalid data', 'event_espresso'), |
|
| 364 | 364 | __FILE__, |
| 365 | 365 | __FUNCTION__, |
| 366 | 366 | __LINE__ |
@@ -368,14 +368,14 @@ discard block |
||
| 368 | 368 | return false; |
| 369 | 369 | } |
| 370 | 370 | //just make sure preview is set on the $message_to_generate (in case client forgot) |
| 371 | - $message_to_generate->set_preview( true ); |
|
| 371 | + $message_to_generate->set_preview(true); |
|
| 372 | 372 | $this->_init_queue_and_generator(); |
| 373 | - $this->queue_for_generation( $message_to_generate, $test_send ); |
|
| 374 | - $generated_queue = $this->_generator->generate( false ); |
|
| 375 | - if ( $generated_queue->execute( false ) ) { |
|
| 373 | + $this->queue_for_generation($message_to_generate, $test_send); |
|
| 374 | + $generated_queue = $this->_generator->generate(false); |
|
| 375 | + if ($generated_queue->execute(false)) { |
|
| 376 | 376 | //the first queue item should be the preview |
| 377 | 377 | $generated_queue->get_message_repository()->rewind(); |
| 378 | - if ( ! $generated_queue->get_message_repository()->valid() ) { |
|
| 378 | + if ( ! $generated_queue->get_message_repository()->valid()) { |
|
| 379 | 379 | return $generated_queue; |
| 380 | 380 | } |
| 381 | 381 | return $generated_queue; |
@@ -392,15 +392,15 @@ discard block |
||
| 392 | 392 | * @param EE_Message_To_Generate $message_to_generate |
| 393 | 393 | * @return bool true or false for success. |
| 394 | 394 | */ |
| 395 | - public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) { |
|
| 396 | - if ( ! $message_to_generate->valid() ) { |
|
| 395 | + public function queue_for_sending(EE_Message_To_Generate $message_to_generate) { |
|
| 396 | + if ( ! $message_to_generate->valid()) { |
|
| 397 | 397 | return false; |
| 398 | 398 | } |
| 399 | 399 | $this->_init_queue_and_generator(); |
| 400 | 400 | $message = $message_to_generate->get_EE_Message(); |
| 401 | - $this->_queue->add( $message ); |
|
| 402 | - if ( $message->send_now() ) { |
|
| 403 | - $this->_queue->execute( false ); |
|
| 401 | + $this->_queue->add($message); |
|
| 402 | + if ($message->send_now()) { |
|
| 403 | + $this->_queue->execute(false); |
|
| 404 | 404 | } else { |
| 405 | 405 | $this->_queue->save(); |
| 406 | 406 | } |
@@ -413,12 +413,12 @@ discard block |
||
| 413 | 413 | * @param EE_Message_To_Generate $message_to_generate |
| 414 | 414 | * @return EE_Messages_Queue | null |
| 415 | 415 | */ |
| 416 | - public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) { |
|
| 417 | - if ( ! $message_to_generate->valid() ) { |
|
| 416 | + public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) { |
|
| 417 | + if ( ! $message_to_generate->valid()) { |
|
| 418 | 418 | return null; |
| 419 | 419 | } |
| 420 | 420 | // is there supposed to be a sending messenger for this message? |
| 421 | - if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) { |
|
| 421 | + if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
| 422 | 422 | // make sure it's valid, but if it's not, |
| 423 | 423 | // then set the value of $sending_messenger to an EE_Error object |
| 424 | 424 | // so that downstream code can easily see that things went wrong. |
@@ -434,14 +434,14 @@ discard block |
||
| 434 | 434 | $sending_messenger = null; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) { |
|
| 437 | + if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
| 438 | 438 | $this->_init_queue_and_generator(); |
| 439 | - $this->_queue->add( $message_to_generate->get_EE_Message() ); |
|
| 440 | - $this->_queue->execute( false, $sending_messenger ); |
|
| 439 | + $this->_queue->add($message_to_generate->get_EE_Message()); |
|
| 440 | + $this->_queue->execute(false, $sending_messenger); |
|
| 441 | 441 | return $this->_queue; |
| 442 | - } elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) { |
|
| 443 | - $generated_queue = $this->generate_and_return( array( $message_to_generate ) ); |
|
| 444 | - $generated_queue->execute( false, $sending_messenger ); |
|
| 442 | + } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
| 443 | + $generated_queue = $this->generate_and_return(array($message_to_generate)); |
|
| 444 | + $generated_queue->execute(false, $sending_messenger); |
|
| 445 | 445 | return $generated_queue; |
| 446 | 446 | } |
| 447 | 447 | return null; |
@@ -458,13 +458,13 @@ discard block |
||
| 458 | 458 | * @param mixed $data The data being used for generation. |
| 459 | 459 | * @param bool $persist Whether to persist the queued messages to the db or not. |
| 460 | 460 | */ |
| 461 | - public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) { |
|
| 462 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data ); |
|
| 463 | - if ( $persist ) { |
|
| 464 | - $this->batch_queue_for_generation_and_persist( $messages_to_generate ); |
|
| 461 | + public function generate_for_all_active_messengers($message_type, $data, $persist = true) { |
|
| 462 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
| 463 | + if ($persist) { |
|
| 464 | + $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
| 465 | 465 | $this->_queue->initiate_request_by_priority(); |
| 466 | 466 | } else { |
| 467 | - $this->batch_queue_for_generation_no_persist( $messages_to_generate ); |
|
| 467 | + $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
| 468 | 468 | } |
| 469 | 469 | } |
| 470 | 470 | |
@@ -479,11 +479,11 @@ discard block |
||
| 479 | 479 | * |
| 480 | 480 | * @return EE_Message_To_Generate[] |
| 481 | 481 | */ |
| 482 | - public function setup_mtgs_for_all_active_messengers( $message_type, $data ) { |
|
| 482 | + public function setup_mtgs_for_all_active_messengers($message_type, $data) { |
|
| 483 | 483 | $messages_to_generate = array(); |
| 484 | - foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object ) { |
|
| 485 | - $message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data ); |
|
| 486 | - if ( $message_to_generate->valid() ) { |
|
| 484 | + foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
| 485 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
| 486 | + if ($message_to_generate->valid()) { |
|
| 487 | 487 | $messages_to_generate[] = $message_to_generate; |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -498,29 +498,29 @@ discard block |
||
| 498 | 498 | * and send. |
| 499 | 499 | * @param array $message_ids |
| 500 | 500 | */ |
| 501 | - public function setup_messages_from_ids_and_send( $message_ids ) { |
|
| 501 | + public function setup_messages_from_ids_and_send($message_ids) { |
|
| 502 | 502 | $this->_init_queue_and_generator(); |
| 503 | - $messages = EEM_Message::instance()->get_all( array( |
|
| 503 | + $messages = EEM_Message::instance()->get_all(array( |
|
| 504 | 504 | array( |
| 505 | - 'MSG_ID' => array( 'IN', $message_ids ), |
|
| 505 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 506 | 506 | 'STS_ID' => array( |
| 507 | 507 | 'IN', |
| 508 | 508 | array_merge( |
| 509 | 509 | EEM_Message::instance()->stati_indicating_sent(), |
| 510 | - array( EEM_Message::status_retry ) |
|
| 510 | + array(EEM_Message::status_retry) |
|
| 511 | 511 | ), |
| 512 | 512 | ), |
| 513 | 513 | ), |
| 514 | 514 | )); |
| 515 | 515 | //set the Messages to resend. |
| 516 | - foreach ( $messages as $message ) { |
|
| 517 | - if ( $message instanceof EE_Message ) { |
|
| 518 | - $message->set_STS_ID( EEM_Message::status_resend ); |
|
| 519 | - $this->_queue->add( $message ); |
|
| 516 | + foreach ($messages as $message) { |
|
| 517 | + if ($message instanceof EE_Message) { |
|
| 518 | + $message->set_STS_ID(EEM_Message::status_resend); |
|
| 519 | + $this->_queue->add($message); |
|
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - $this->_queue->initiate_request_by_priority( 'send' ); |
|
| 523 | + $this->_queue->initiate_request_by_priority('send'); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
@@ -534,23 +534,23 @@ discard block |
||
| 534 | 534 | * |
| 535 | 535 | * @return EE_Message_To_Generate[] |
| 536 | 536 | */ |
| 537 | - public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) { |
|
| 538 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
| 539 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
| 537 | + public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') { |
|
| 538 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 539 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 540 | 540 | $regs_to_send = array(); |
| 541 | - $regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key ); |
|
| 542 | - if ( empty( $regIDs ) ) { |
|
| 543 | - EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 541 | + $regIDs = EE_Registry::instance()->REQ->get($registration_ids_key); |
|
| 542 | + if (empty($regIDs)) { |
|
| 543 | + EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 544 | 544 | return false; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | //make sure is an array |
| 548 | - $regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs ); |
|
| 548 | + $regIDs = is_array($regIDs) ? $regIDs : array($regIDs); |
|
| 549 | 549 | |
| 550 | - foreach( $regIDs as $regID ) { |
|
| 551 | - $reg = EEM_Registration::instance()->get_one_by_ID( $regID ); |
|
| 552 | - if ( ! $reg instanceof EE_Registration ) { |
|
| 553 | - EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) ); |
|
| 550 | + foreach ($regIDs as $regID) { |
|
| 551 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
| 552 | + if ( ! $reg instanceof EE_Registration) { |
|
| 553 | + EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID)); |
|
| 554 | 554 | return false; |
| 555 | 555 | } |
| 556 | 556 | $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg; |
@@ -558,13 +558,13 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | $messages_to_generate = array(); |
| 560 | 560 | |
| 561 | - foreach ( $regs_to_send as $status_group ) { |
|
| 562 | - foreach ( $status_group as $status_id => $registrations ) { |
|
| 561 | + foreach ($regs_to_send as $status_group) { |
|
| 562 | + foreach ($status_group as $status_id => $registrations) { |
|
| 563 | 563 | $messages_to_generate = array_merge( |
| 564 | 564 | $messages_to_generate, |
| 565 | 565 | $this->setup_mtgs_for_all_active_messengers( |
| 566 | - EEH_MSG_Template::convert_reg_status_to_message_type( $status_id ), |
|
| 567 | - array( $registrations, $status_id ) |
|
| 566 | + EEH_MSG_Template::convert_reg_status_to_message_type($status_id), |
|
| 567 | + array($registrations, $status_id) |
|
| 568 | 568 | ) |
| 569 | 569 | ); |
| 570 | 570 | } |
@@ -164,7 +164,7 @@ |
||
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $ticket |
|
| 167 | + * @param \EE_Base_Class $ticket |
|
| 168 | 168 | * @throws DomainException |
| 169 | 169 | * @throws EE_Error |
| 170 | 170 | * @throws UnexpectedEntityException |
@@ -31,620 +31,620 @@ |
||
| 31 | 31 | class EventSpacesCalculator |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var EE_Event $event |
|
| 36 | - */ |
|
| 37 | - private $event; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array $datetime_query_params |
|
| 41 | - */ |
|
| 42 | - private $datetime_query_params; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EE_Ticket[] $active_tickets |
|
| 46 | - */ |
|
| 47 | - private $active_tickets = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var EE_Datetime[] $datetimes |
|
| 51 | - */ |
|
| 52 | - private $datetimes = array(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Array of Ticket IDs grouped by Datetime |
|
| 56 | - * |
|
| 57 | - * @var array $datetimes |
|
| 58 | - */ |
|
| 59 | - private $datetime_tickets = array(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Max spaces for each Datetime (reg limit - previous sold) |
|
| 63 | - * |
|
| 64 | - * @var array $datetime_spaces |
|
| 65 | - */ |
|
| 66 | - private $datetime_spaces = array(); |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Array of Datetime IDs grouped by Ticket |
|
| 70 | - * |
|
| 71 | - * @var array $ticket_datetimes |
|
| 72 | - */ |
|
| 73 | - private $ticket_datetimes = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 77 | - * |
|
| 78 | - * @var array $ticket_quantities |
|
| 79 | - */ |
|
| 80 | - private $ticket_quantities = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * total quantity of sold and reserved for each ticket |
|
| 84 | - * |
|
| 85 | - * @var array $tickets_sold |
|
| 86 | - */ |
|
| 87 | - private $tickets_sold = array(); |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * total spaces available across all datetimes |
|
| 91 | - * |
|
| 92 | - * @var array $total_spaces |
|
| 93 | - */ |
|
| 94 | - private $total_spaces = array(); |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var boolean $debug |
|
| 98 | - */ |
|
| 99 | - private $debug = false; |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * EventSpacesCalculator constructor. |
|
| 105 | - * |
|
| 106 | - * @param EE_Event $event |
|
| 107 | - * @param array $datetime_query_params |
|
| 108 | - * @throws EE_Error |
|
| 109 | - */ |
|
| 110 | - public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 111 | - { |
|
| 112 | - $this->event = $event; |
|
| 113 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @return EE_Ticket[] |
|
| 120 | - * @throws EE_Error |
|
| 121 | - * @throws InvalidDataTypeException |
|
| 122 | - * @throws InvalidInterfaceException |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - */ |
|
| 125 | - public function getActiveTickets() |
|
| 126 | - { |
|
| 127 | - if (empty($this->active_tickets)) { |
|
| 128 | - $this->active_tickets = $this->event->tickets( |
|
| 129 | - array( |
|
| 130 | - array( |
|
| 131 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 132 | - 'TKT_deleted' => false, |
|
| 133 | - ), |
|
| 134 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - return $this->active_tickets; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param EE_Ticket[] $active_tickets |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws DomainException |
|
| 147 | - * @throws UnexpectedEntityException |
|
| 148 | - */ |
|
| 149 | - public function setActiveTickets(array $active_tickets = array()) |
|
| 150 | - { |
|
| 151 | - if ( ! empty($active_tickets)) { |
|
| 152 | - foreach ($active_tickets as $active_ticket) { |
|
| 153 | - $this->validateTicket($active_ticket); |
|
| 154 | - } |
|
| 155 | - // sort incoming array by ticket quantity (asc) |
|
| 156 | - usort( |
|
| 157 | - $active_tickets, |
|
| 158 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | - if ($a->qty() === $b->qty()) { |
|
| 160 | - return 0; |
|
| 161 | - } |
|
| 162 | - return ($a->qty() < $b->qty()) |
|
| 163 | - ? -1 |
|
| 164 | - : 1; |
|
| 165 | - } |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - $this->active_tickets = $active_tickets; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param $ticket |
|
| 175 | - * @throws DomainException |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws UnexpectedEntityException |
|
| 178 | - */ |
|
| 179 | - private function validateTicket($ticket) |
|
| 180 | - { |
|
| 181 | - if ( ! $ticket instanceof EE_Ticket) { |
|
| 182 | - throw new DomainException( |
|
| 183 | - esc_html__( |
|
| 184 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 185 | - 'event_espresso' |
|
| 186 | - ) |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 190 | - throw new DomainException( |
|
| 191 | - sprintf( |
|
| 192 | - esc_html__( |
|
| 193 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ), |
|
| 196 | - $ticket->get_event_ID(), |
|
| 197 | - $this->event->ID() |
|
| 198 | - ) |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @return EE_Datetime[] |
|
| 207 | - */ |
|
| 208 | - public function getDatetimes() |
|
| 209 | - { |
|
| 210 | - return $this->datetimes; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param EE_Datetime $datetime |
|
| 217 | - * @throws EE_Error |
|
| 218 | - * @throws DomainException |
|
| 219 | - */ |
|
| 220 | - public function setDatetime(EE_Datetime $datetime) |
|
| 221 | - { |
|
| 222 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 223 | - throw new DomainException( |
|
| 224 | - sprintf( |
|
| 225 | - esc_html__( |
|
| 226 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 227 | - 'event_espresso' |
|
| 228 | - ), |
|
| 229 | - $datetime->event()->ID(), |
|
| 230 | - $this->event->ID() |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - } |
|
| 234 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * calculate spaces remaining based on "saleable" tickets |
|
| 241 | - * |
|
| 242 | - * @return float|int |
|
| 243 | - * @throws EE_Error |
|
| 244 | - * @throws DomainException |
|
| 245 | - * @throws UnexpectedEntityException |
|
| 246 | - * @throws InvalidDataTypeException |
|
| 247 | - * @throws InvalidInterfaceException |
|
| 248 | - * @throws InvalidArgumentException |
|
| 249 | - */ |
|
| 250 | - public function spacesRemaining() |
|
| 251 | - { |
|
| 252 | - $this->initialize(); |
|
| 253 | - return $this->calculate(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * calculates total available spaces for an event with no regard for sold tickets |
|
| 260 | - * |
|
| 261 | - * @return int|float |
|
| 262 | - * @throws EE_Error |
|
| 263 | - * @throws DomainException |
|
| 264 | - * @throws UnexpectedEntityException |
|
| 265 | - * @throws InvalidDataTypeException |
|
| 266 | - * @throws InvalidInterfaceException |
|
| 267 | - * @throws InvalidArgumentException |
|
| 268 | - */ |
|
| 269 | - public function totalSpacesAvailable() |
|
| 270 | - { |
|
| 271 | - $this->initialize(); |
|
| 272 | - return $this->calculate(false); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Loops through the active tickets for the event |
|
| 279 | - * and builds a series of data arrays that will be used for calculating |
|
| 280 | - * the total maximum available spaces, as well as the spaces remaining. |
|
| 281 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
| 282 | - * we need to be constantly updating these data arrays as things change, |
|
| 283 | - * which is the entire reason for their existence. |
|
| 284 | - * |
|
| 285 | - * @throws EE_Error |
|
| 286 | - * @throws DomainException |
|
| 287 | - * @throws UnexpectedEntityException |
|
| 288 | - * @throws InvalidDataTypeException |
|
| 289 | - * @throws InvalidInterfaceException |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - */ |
|
| 292 | - private function initialize() |
|
| 293 | - { |
|
| 294 | - if ($this->debug) { |
|
| 295 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 296 | - } |
|
| 297 | - $this->datetime_tickets = array(); |
|
| 298 | - $this->datetime_spaces = array(); |
|
| 299 | - $this->ticket_datetimes = array(); |
|
| 300 | - $this->ticket_quantities = array(); |
|
| 301 | - $this->tickets_sold = array(); |
|
| 302 | - $this->total_spaces = array(); |
|
| 303 | - $active_tickets = $this->getActiveTickets(); |
|
| 304 | - if ( ! empty($active_tickets)) { |
|
| 305 | - foreach ($active_tickets as $ticket) { |
|
| 306 | - $this->validateTicket($ticket); |
|
| 307 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
| 308 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 309 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
| 310 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket |
|
| 311 | - $max_tickets = $ticket->qty(); |
|
| 312 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 313 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 314 | - foreach ($ticket_datetimes as $datetime) { |
|
| 315 | - // save all datetimes |
|
| 316 | - $this->setDatetime($datetime); |
|
| 317 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
| 318 | - $reg_limit = $datetime->reg_limit(); |
|
| 319 | - // ticket quantity can not exceed datetime reg limit |
|
| 320 | - $max_tickets = min($max_tickets, $reg_limit); |
|
| 321 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 322 | - // we are going to move all of our data into the following arrays: |
|
| 323 | - // datetime spaces initially represents the reg limit for each datetime, |
|
| 324 | - // but this will get adjusted as tickets are accounted for |
|
| 325 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 326 | - // just an array of ticket IDs grouped by datetime |
|
| 327 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 328 | - // and an array of datetime IDs grouped by ticket |
|
| 329 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 330 | - } |
|
| 331 | - // total quantity of sold and reserved for each ticket |
|
| 332 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 334 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 338 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 339 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 340 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 341 | - // but overwrite all of the data with that from datetime_tickets |
|
| 342 | - $this->datetime_tickets = array_merge( |
|
| 343 | - $this->datetime_spaces, |
|
| 344 | - $this->datetime_tickets |
|
| 345 | - ); |
|
| 346 | - if ($this->debug) { |
|
| 347 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 348 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 349 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * performs calculations on initialized data |
|
| 357 | - * |
|
| 358 | - * @param bool $consider_sold |
|
| 359 | - * @return int|float |
|
| 360 | - */ |
|
| 361 | - private function calculate($consider_sold = true) |
|
| 362 | - { |
|
| 363 | - if ($this->debug) { |
|
| 364 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 365 | - } |
|
| 366 | - if ($consider_sold) { |
|
| 367 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 368 | - $this->adjustTicketQuantitiesDueToSales(); |
|
| 369 | - } |
|
| 370 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 371 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 372 | - } |
|
| 373 | - // total spaces available is just the sum of the spaces available for each datetime |
|
| 374 | - $spaces_remaining = array_sum($this->total_spaces); |
|
| 375 | - if ($this->debug) { |
|
| 376 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 377 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 378 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 379 | - } |
|
| 380 | - return $spaces_remaining; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 386 | - */ |
|
| 387 | - private function adjustTicketQuantitiesDueToSales() |
|
| 388 | - { |
|
| 389 | - if ($this->debug) { |
|
| 390 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | - } |
|
| 392 | - foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 393 | - if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 395 | - if ($this->debug) { |
|
| 396 | - \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - if ( |
|
| 400 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | - ){ |
|
| 403 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 406 | - if ($this->debug) { |
|
| 407 | - \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 408 | - 'subtracting', __FILE__, __LINE__); |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @param string $datetime_identifier |
|
| 420 | - * @param array $tickets |
|
| 421 | - */ |
|
| 422 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 423 | - { |
|
| 424 | - // make sure a reg limit is set for the datetime |
|
| 425 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 427 | - : 0; |
|
| 428 | - // and bail if it is not |
|
| 429 | - if ( ! $reg_limit) { |
|
| 430 | - if ($this->debug) { |
|
| 431 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 432 | - } |
|
| 433 | - return; |
|
| 434 | - } |
|
| 435 | - if ($this->debug) { |
|
| 436 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 437 | - \EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__); |
|
| 438 | - } |
|
| 439 | - // number of allocated spaces always starts at zero |
|
| 440 | - $spaces_allocated = 0; |
|
| 441 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 442 | - foreach ($tickets as $ticket_identifier) { |
|
| 443 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 444 | - $datetime_identifier, |
|
| 445 | - $reg_limit, |
|
| 446 | - $ticket_identifier, |
|
| 447 | - $spaces_allocated |
|
| 448 | - ); |
|
| 449 | - } |
|
| 450 | - // spaces can't be negative |
|
| 451 | - $spaces_allocated = max($spaces_allocated, 0); |
|
| 452 | - if ($spaces_allocated) { |
|
| 453 | - // track any non-zero values |
|
| 454 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 455 | - if ($this->debug) { |
|
| 456 | - \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | - } |
|
| 458 | - } else { |
|
| 459 | - if ($this->debug) { |
|
| 460 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - if ($this->debug) { |
|
| 464 | - \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 465 | - __LINE__); |
|
| 466 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 467 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @param string $datetime_identifier |
|
| 475 | - * @param int $reg_limit |
|
| 476 | - * @param string $ticket_identifier |
|
| 477 | - * @param int $spaces_allocated |
|
| 478 | - * @return int |
|
| 479 | - */ |
|
| 480 | - private function calculateAvailableSpacesForTicket( |
|
| 481 | - $datetime_identifier, |
|
| 482 | - $reg_limit, |
|
| 483 | - $ticket_identifier, |
|
| 484 | - $spaces_allocated |
|
| 485 | - ) { |
|
| 486 | - // make sure ticket quantity is set |
|
| 487 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 489 | - : 0; |
|
| 490 | - if ($this->debug) { |
|
| 491 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 492 | - \EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ", |
|
| 493 | - __FILE__, __LINE__, 2); |
|
| 494 | - } |
|
| 495 | - if ($ticket_quantity) { |
|
| 496 | - if ($this->debug) { |
|
| 497 | - \EEH_Debug_Tools::printr( |
|
| 498 | - ($spaces_allocated <= $reg_limit) |
|
| 499 | - ? 'true' |
|
| 500 | - : 'false', |
|
| 501 | - ' . spaces_allocated <= reg_limit = ', |
|
| 502 | - __FILE__, __LINE__ |
|
| 503 | - ); |
|
| 504 | - } |
|
| 505 | - // if the datetime is NOT at full capacity yet |
|
| 506 | - if ($spaces_allocated <= $reg_limit) { |
|
| 507 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 508 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 509 | - // or the maximum ticket quantity |
|
| 510 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 511 | - // adjust the available quantity in our tracking array |
|
| 512 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 513 | - // and increment spaces allocated for this datetime |
|
| 514 | - $spaces_allocated += $ticket_quantity; |
|
| 515 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 516 | - if ($this->debug) { |
|
| 517 | - \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
|
| 518 | - __FILE__, __LINE__, 3); |
|
| 519 | - if ($at_capacity) { |
|
| 520 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - // now adjust all other datetimes that allow access to this ticket |
|
| 524 | - $this->adjustDatetimes( |
|
| 525 | - $datetime_identifier, |
|
| 526 | - $ticket_identifier, |
|
| 527 | - $ticket_quantity, |
|
| 528 | - $at_capacity |
|
| 529 | - ); |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - return $spaces_allocated; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * subtracts ticket amounts from all datetime reg limits |
|
| 539 | - * that allow access to the ticket specified, |
|
| 540 | - * because that ticket could be used |
|
| 541 | - * to attend any of the datetimes it has access to |
|
| 542 | - * |
|
| 543 | - * @param string $datetime_identifier |
|
| 544 | - * @param string $ticket_identifier |
|
| 545 | - * @param bool $at_capacity |
|
| 546 | - * @param int $ticket_quantity |
|
| 547 | - */ |
|
| 548 | - private function adjustDatetimes( |
|
| 549 | - $datetime_identifier, |
|
| 550 | - $ticket_identifier, |
|
| 551 | - $ticket_quantity, |
|
| 552 | - $at_capacity |
|
| 553 | - ) { |
|
| 554 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 555 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 556 | - continue; |
|
| 557 | - } |
|
| 558 | - $adjusted = $this->adjustDatetimeSpaces( |
|
| 559 | - $datetime_ID, |
|
| 560 | - $ticket_identifier, |
|
| 561 | - $ticket_quantity |
|
| 562 | - ); |
|
| 563 | - // skip to next ticket if nothing changed |
|
| 564 | - if (! ($adjusted || $at_capacity)) { |
|
| 565 | - continue; |
|
| 566 | - } |
|
| 567 | - // then all of it's tickets are now unavailable |
|
| 568 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
| 569 | - if ( |
|
| 570 | - ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 571 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 573 | - ) { |
|
| 574 | - if ($this->debug) { |
|
| 575 | - \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
|
| 576 | - __LINE__); |
|
| 577 | - } |
|
| 578 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 579 | - // otherwise just subtract the ticket quantity |
|
| 580 | - $new_quantity = $at_capacity |
|
| 581 | - ? 0 |
|
| 582 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 583 | - // don't let ticket quantity go below zero |
|
| 584 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 585 | - if ($this->debug) { |
|
| 586 | - \EEH_Debug_Tools::printr( |
|
| 587 | - $at_capacity |
|
| 588 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 589 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 590 | - " . . . . {$datetime_ticket} quantity set to ", |
|
| 591 | - __FILE__, __LINE__ |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 596 | - if ($datetime_ticket === $ticket_identifier) { |
|
| 597 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 599 | - ) { |
|
| 600 | - if ($this->debug) { |
|
| 601 | - \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
|
| 602 | - __LINE__); |
|
| 603 | - } |
|
| 604 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 605 | - // don't adjust the current datetime twice |
|
| 606 | - if ($datetime !== $datetime_identifier) { |
|
| 607 | - $this->adjustDatetimeSpaces( |
|
| 608 | - $datetime, |
|
| 609 | - $datetime_ticket, |
|
| 610 | - $ticket_quantity |
|
| 611 | - ); |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 621 | - { |
|
| 622 | - // does datetime have spaces available? |
|
| 623 | - // and does the supplied ticket have access to this datetime ? |
|
| 624 | - if ( |
|
| 625 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 628 | - ) { |
|
| 629 | - if ($this->debug) { |
|
| 630 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 631 | - \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | - } |
|
| 633 | - // then decrement the available spaces for the datetime |
|
| 634 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 635 | - // but don't let quantities go below zero |
|
| 636 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 638 | - 0 |
|
| 639 | - ); |
|
| 640 | - if ($this->debug) { |
|
| 641 | - \EEH_Debug_Tools::printr("{$ticket_quantity}", |
|
| 642 | - " . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__); |
|
| 643 | - } |
|
| 644 | - return true; |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 34 | + /** |
|
| 35 | + * @var EE_Event $event |
|
| 36 | + */ |
|
| 37 | + private $event; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array $datetime_query_params |
|
| 41 | + */ |
|
| 42 | + private $datetime_query_params; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EE_Ticket[] $active_tickets |
|
| 46 | + */ |
|
| 47 | + private $active_tickets = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var EE_Datetime[] $datetimes |
|
| 51 | + */ |
|
| 52 | + private $datetimes = array(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Array of Ticket IDs grouped by Datetime |
|
| 56 | + * |
|
| 57 | + * @var array $datetimes |
|
| 58 | + */ |
|
| 59 | + private $datetime_tickets = array(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Max spaces for each Datetime (reg limit - previous sold) |
|
| 63 | + * |
|
| 64 | + * @var array $datetime_spaces |
|
| 65 | + */ |
|
| 66 | + private $datetime_spaces = array(); |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Array of Datetime IDs grouped by Ticket |
|
| 70 | + * |
|
| 71 | + * @var array $ticket_datetimes |
|
| 72 | + */ |
|
| 73 | + private $ticket_datetimes = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 77 | + * |
|
| 78 | + * @var array $ticket_quantities |
|
| 79 | + */ |
|
| 80 | + private $ticket_quantities = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * total quantity of sold and reserved for each ticket |
|
| 84 | + * |
|
| 85 | + * @var array $tickets_sold |
|
| 86 | + */ |
|
| 87 | + private $tickets_sold = array(); |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * total spaces available across all datetimes |
|
| 91 | + * |
|
| 92 | + * @var array $total_spaces |
|
| 93 | + */ |
|
| 94 | + private $total_spaces = array(); |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var boolean $debug |
|
| 98 | + */ |
|
| 99 | + private $debug = false; |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * EventSpacesCalculator constructor. |
|
| 105 | + * |
|
| 106 | + * @param EE_Event $event |
|
| 107 | + * @param array $datetime_query_params |
|
| 108 | + * @throws EE_Error |
|
| 109 | + */ |
|
| 110 | + public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 111 | + { |
|
| 112 | + $this->event = $event; |
|
| 113 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @return EE_Ticket[] |
|
| 120 | + * @throws EE_Error |
|
| 121 | + * @throws InvalidDataTypeException |
|
| 122 | + * @throws InvalidInterfaceException |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + */ |
|
| 125 | + public function getActiveTickets() |
|
| 126 | + { |
|
| 127 | + if (empty($this->active_tickets)) { |
|
| 128 | + $this->active_tickets = $this->event->tickets( |
|
| 129 | + array( |
|
| 130 | + array( |
|
| 131 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 132 | + 'TKT_deleted' => false, |
|
| 133 | + ), |
|
| 134 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + return $this->active_tickets; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param EE_Ticket[] $active_tickets |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws DomainException |
|
| 147 | + * @throws UnexpectedEntityException |
|
| 148 | + */ |
|
| 149 | + public function setActiveTickets(array $active_tickets = array()) |
|
| 150 | + { |
|
| 151 | + if ( ! empty($active_tickets)) { |
|
| 152 | + foreach ($active_tickets as $active_ticket) { |
|
| 153 | + $this->validateTicket($active_ticket); |
|
| 154 | + } |
|
| 155 | + // sort incoming array by ticket quantity (asc) |
|
| 156 | + usort( |
|
| 157 | + $active_tickets, |
|
| 158 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | + if ($a->qty() === $b->qty()) { |
|
| 160 | + return 0; |
|
| 161 | + } |
|
| 162 | + return ($a->qty() < $b->qty()) |
|
| 163 | + ? -1 |
|
| 164 | + : 1; |
|
| 165 | + } |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + $this->active_tickets = $active_tickets; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param $ticket |
|
| 175 | + * @throws DomainException |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws UnexpectedEntityException |
|
| 178 | + */ |
|
| 179 | + private function validateTicket($ticket) |
|
| 180 | + { |
|
| 181 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 182 | + throw new DomainException( |
|
| 183 | + esc_html__( |
|
| 184 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 185 | + 'event_espresso' |
|
| 186 | + ) |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 190 | + throw new DomainException( |
|
| 191 | + sprintf( |
|
| 192 | + esc_html__( |
|
| 193 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ), |
|
| 196 | + $ticket->get_event_ID(), |
|
| 197 | + $this->event->ID() |
|
| 198 | + ) |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @return EE_Datetime[] |
|
| 207 | + */ |
|
| 208 | + public function getDatetimes() |
|
| 209 | + { |
|
| 210 | + return $this->datetimes; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param EE_Datetime $datetime |
|
| 217 | + * @throws EE_Error |
|
| 218 | + * @throws DomainException |
|
| 219 | + */ |
|
| 220 | + public function setDatetime(EE_Datetime $datetime) |
|
| 221 | + { |
|
| 222 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 223 | + throw new DomainException( |
|
| 224 | + sprintf( |
|
| 225 | + esc_html__( |
|
| 226 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 227 | + 'event_espresso' |
|
| 228 | + ), |
|
| 229 | + $datetime->event()->ID(), |
|
| 230 | + $this->event->ID() |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + } |
|
| 234 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * calculate spaces remaining based on "saleable" tickets |
|
| 241 | + * |
|
| 242 | + * @return float|int |
|
| 243 | + * @throws EE_Error |
|
| 244 | + * @throws DomainException |
|
| 245 | + * @throws UnexpectedEntityException |
|
| 246 | + * @throws InvalidDataTypeException |
|
| 247 | + * @throws InvalidInterfaceException |
|
| 248 | + * @throws InvalidArgumentException |
|
| 249 | + */ |
|
| 250 | + public function spacesRemaining() |
|
| 251 | + { |
|
| 252 | + $this->initialize(); |
|
| 253 | + return $this->calculate(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * calculates total available spaces for an event with no regard for sold tickets |
|
| 260 | + * |
|
| 261 | + * @return int|float |
|
| 262 | + * @throws EE_Error |
|
| 263 | + * @throws DomainException |
|
| 264 | + * @throws UnexpectedEntityException |
|
| 265 | + * @throws InvalidDataTypeException |
|
| 266 | + * @throws InvalidInterfaceException |
|
| 267 | + * @throws InvalidArgumentException |
|
| 268 | + */ |
|
| 269 | + public function totalSpacesAvailable() |
|
| 270 | + { |
|
| 271 | + $this->initialize(); |
|
| 272 | + return $this->calculate(false); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Loops through the active tickets for the event |
|
| 279 | + * and builds a series of data arrays that will be used for calculating |
|
| 280 | + * the total maximum available spaces, as well as the spaces remaining. |
|
| 281 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
| 282 | + * we need to be constantly updating these data arrays as things change, |
|
| 283 | + * which is the entire reason for their existence. |
|
| 284 | + * |
|
| 285 | + * @throws EE_Error |
|
| 286 | + * @throws DomainException |
|
| 287 | + * @throws UnexpectedEntityException |
|
| 288 | + * @throws InvalidDataTypeException |
|
| 289 | + * @throws InvalidInterfaceException |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + */ |
|
| 292 | + private function initialize() |
|
| 293 | + { |
|
| 294 | + if ($this->debug) { |
|
| 295 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 296 | + } |
|
| 297 | + $this->datetime_tickets = array(); |
|
| 298 | + $this->datetime_spaces = array(); |
|
| 299 | + $this->ticket_datetimes = array(); |
|
| 300 | + $this->ticket_quantities = array(); |
|
| 301 | + $this->tickets_sold = array(); |
|
| 302 | + $this->total_spaces = array(); |
|
| 303 | + $active_tickets = $this->getActiveTickets(); |
|
| 304 | + if ( ! empty($active_tickets)) { |
|
| 305 | + foreach ($active_tickets as $ticket) { |
|
| 306 | + $this->validateTicket($ticket); |
|
| 307 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
| 308 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 309 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
| 310 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket |
|
| 311 | + $max_tickets = $ticket->qty(); |
|
| 312 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 313 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 314 | + foreach ($ticket_datetimes as $datetime) { |
|
| 315 | + // save all datetimes |
|
| 316 | + $this->setDatetime($datetime); |
|
| 317 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
| 318 | + $reg_limit = $datetime->reg_limit(); |
|
| 319 | + // ticket quantity can not exceed datetime reg limit |
|
| 320 | + $max_tickets = min($max_tickets, $reg_limit); |
|
| 321 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 322 | + // we are going to move all of our data into the following arrays: |
|
| 323 | + // datetime spaces initially represents the reg limit for each datetime, |
|
| 324 | + // but this will get adjusted as tickets are accounted for |
|
| 325 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 326 | + // just an array of ticket IDs grouped by datetime |
|
| 327 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 328 | + // and an array of datetime IDs grouped by ticket |
|
| 329 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 330 | + } |
|
| 331 | + // total quantity of sold and reserved for each ticket |
|
| 332 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 334 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 338 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 339 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 340 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 341 | + // but overwrite all of the data with that from datetime_tickets |
|
| 342 | + $this->datetime_tickets = array_merge( |
|
| 343 | + $this->datetime_spaces, |
|
| 344 | + $this->datetime_tickets |
|
| 345 | + ); |
|
| 346 | + if ($this->debug) { |
|
| 347 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 348 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 349 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * performs calculations on initialized data |
|
| 357 | + * |
|
| 358 | + * @param bool $consider_sold |
|
| 359 | + * @return int|float |
|
| 360 | + */ |
|
| 361 | + private function calculate($consider_sold = true) |
|
| 362 | + { |
|
| 363 | + if ($this->debug) { |
|
| 364 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 365 | + } |
|
| 366 | + if ($consider_sold) { |
|
| 367 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 368 | + $this->adjustTicketQuantitiesDueToSales(); |
|
| 369 | + } |
|
| 370 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 371 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 372 | + } |
|
| 373 | + // total spaces available is just the sum of the spaces available for each datetime |
|
| 374 | + $spaces_remaining = array_sum($this->total_spaces); |
|
| 375 | + if ($this->debug) { |
|
| 376 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 377 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 378 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 379 | + } |
|
| 380 | + return $spaces_remaining; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 386 | + */ |
|
| 387 | + private function adjustTicketQuantitiesDueToSales() |
|
| 388 | + { |
|
| 389 | + if ($this->debug) { |
|
| 390 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | + } |
|
| 392 | + foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 393 | + if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | + $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 395 | + if ($this->debug) { |
|
| 396 | + \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + if ( |
|
| 400 | + isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | + ){ |
|
| 403 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 406 | + if ($this->debug) { |
|
| 407 | + \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 408 | + 'subtracting', __FILE__, __LINE__); |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @param string $datetime_identifier |
|
| 420 | + * @param array $tickets |
|
| 421 | + */ |
|
| 422 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 423 | + { |
|
| 424 | + // make sure a reg limit is set for the datetime |
|
| 425 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 427 | + : 0; |
|
| 428 | + // and bail if it is not |
|
| 429 | + if ( ! $reg_limit) { |
|
| 430 | + if ($this->debug) { |
|
| 431 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 432 | + } |
|
| 433 | + return; |
|
| 434 | + } |
|
| 435 | + if ($this->debug) { |
|
| 436 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 437 | + \EEH_Debug_Tools::printr("{$reg_limit}", 'REG LIMIT', __FILE__, __LINE__); |
|
| 438 | + } |
|
| 439 | + // number of allocated spaces always starts at zero |
|
| 440 | + $spaces_allocated = 0; |
|
| 441 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 442 | + foreach ($tickets as $ticket_identifier) { |
|
| 443 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 444 | + $datetime_identifier, |
|
| 445 | + $reg_limit, |
|
| 446 | + $ticket_identifier, |
|
| 447 | + $spaces_allocated |
|
| 448 | + ); |
|
| 449 | + } |
|
| 450 | + // spaces can't be negative |
|
| 451 | + $spaces_allocated = max($spaces_allocated, 0); |
|
| 452 | + if ($spaces_allocated) { |
|
| 453 | + // track any non-zero values |
|
| 454 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 455 | + if ($this->debug) { |
|
| 456 | + \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | + } |
|
| 458 | + } else { |
|
| 459 | + if ($this->debug) { |
|
| 460 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + if ($this->debug) { |
|
| 464 | + \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 465 | + __LINE__); |
|
| 466 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 467 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @param string $datetime_identifier |
|
| 475 | + * @param int $reg_limit |
|
| 476 | + * @param string $ticket_identifier |
|
| 477 | + * @param int $spaces_allocated |
|
| 478 | + * @return int |
|
| 479 | + */ |
|
| 480 | + private function calculateAvailableSpacesForTicket( |
|
| 481 | + $datetime_identifier, |
|
| 482 | + $reg_limit, |
|
| 483 | + $ticket_identifier, |
|
| 484 | + $spaces_allocated |
|
| 485 | + ) { |
|
| 486 | + // make sure ticket quantity is set |
|
| 487 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 489 | + : 0; |
|
| 490 | + if ($this->debug) { |
|
| 491 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 492 | + \EEH_Debug_Tools::printr("{$ticket_quantity}", "ticket $ticket_identifier quantity: ", |
|
| 493 | + __FILE__, __LINE__, 2); |
|
| 494 | + } |
|
| 495 | + if ($ticket_quantity) { |
|
| 496 | + if ($this->debug) { |
|
| 497 | + \EEH_Debug_Tools::printr( |
|
| 498 | + ($spaces_allocated <= $reg_limit) |
|
| 499 | + ? 'true' |
|
| 500 | + : 'false', |
|
| 501 | + ' . spaces_allocated <= reg_limit = ', |
|
| 502 | + __FILE__, __LINE__ |
|
| 503 | + ); |
|
| 504 | + } |
|
| 505 | + // if the datetime is NOT at full capacity yet |
|
| 506 | + if ($spaces_allocated <= $reg_limit) { |
|
| 507 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 508 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 509 | + // or the maximum ticket quantity |
|
| 510 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 511 | + // adjust the available quantity in our tracking array |
|
| 512 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 513 | + // and increment spaces allocated for this datetime |
|
| 514 | + $spaces_allocated += $ticket_quantity; |
|
| 515 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 516 | + if ($this->debug) { |
|
| 517 | + \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
|
| 518 | + __FILE__, __LINE__, 3); |
|
| 519 | + if ($at_capacity) { |
|
| 520 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + // now adjust all other datetimes that allow access to this ticket |
|
| 524 | + $this->adjustDatetimes( |
|
| 525 | + $datetime_identifier, |
|
| 526 | + $ticket_identifier, |
|
| 527 | + $ticket_quantity, |
|
| 528 | + $at_capacity |
|
| 529 | + ); |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + return $spaces_allocated; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * subtracts ticket amounts from all datetime reg limits |
|
| 539 | + * that allow access to the ticket specified, |
|
| 540 | + * because that ticket could be used |
|
| 541 | + * to attend any of the datetimes it has access to |
|
| 542 | + * |
|
| 543 | + * @param string $datetime_identifier |
|
| 544 | + * @param string $ticket_identifier |
|
| 545 | + * @param bool $at_capacity |
|
| 546 | + * @param int $ticket_quantity |
|
| 547 | + */ |
|
| 548 | + private function adjustDatetimes( |
|
| 549 | + $datetime_identifier, |
|
| 550 | + $ticket_identifier, |
|
| 551 | + $ticket_quantity, |
|
| 552 | + $at_capacity |
|
| 553 | + ) { |
|
| 554 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 555 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 556 | + continue; |
|
| 557 | + } |
|
| 558 | + $adjusted = $this->adjustDatetimeSpaces( |
|
| 559 | + $datetime_ID, |
|
| 560 | + $ticket_identifier, |
|
| 561 | + $ticket_quantity |
|
| 562 | + ); |
|
| 563 | + // skip to next ticket if nothing changed |
|
| 564 | + if (! ($adjusted || $at_capacity)) { |
|
| 565 | + continue; |
|
| 566 | + } |
|
| 567 | + // then all of it's tickets are now unavailable |
|
| 568 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
| 569 | + if ( |
|
| 570 | + ($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 571 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 573 | + ) { |
|
| 574 | + if ($this->debug) { |
|
| 575 | + \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
|
| 576 | + __LINE__); |
|
| 577 | + } |
|
| 578 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 579 | + // otherwise just subtract the ticket quantity |
|
| 580 | + $new_quantity = $at_capacity |
|
| 581 | + ? 0 |
|
| 582 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 583 | + // don't let ticket quantity go below zero |
|
| 584 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 585 | + if ($this->debug) { |
|
| 586 | + \EEH_Debug_Tools::printr( |
|
| 587 | + $at_capacity |
|
| 588 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 589 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 590 | + " . . . . {$datetime_ticket} quantity set to ", |
|
| 591 | + __FILE__, __LINE__ |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 596 | + if ($datetime_ticket === $ticket_identifier) { |
|
| 597 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 599 | + ) { |
|
| 600 | + if ($this->debug) { |
|
| 601 | + \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
|
| 602 | + __LINE__); |
|
| 603 | + } |
|
| 604 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 605 | + // don't adjust the current datetime twice |
|
| 606 | + if ($datetime !== $datetime_identifier) { |
|
| 607 | + $this->adjustDatetimeSpaces( |
|
| 608 | + $datetime, |
|
| 609 | + $datetime_ticket, |
|
| 610 | + $ticket_quantity |
|
| 611 | + ); |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 621 | + { |
|
| 622 | + // does datetime have spaces available? |
|
| 623 | + // and does the supplied ticket have access to this datetime ? |
|
| 624 | + if ( |
|
| 625 | + $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 628 | + ) { |
|
| 629 | + if ($this->debug) { |
|
| 630 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 631 | + \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | + } |
|
| 633 | + // then decrement the available spaces for the datetime |
|
| 634 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 635 | + // but don't let quantities go below zero |
|
| 636 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | + $this->datetime_spaces[ $datetime_identifier ], |
|
| 638 | + 0 |
|
| 639 | + ); |
|
| 640 | + if ($this->debug) { |
|
| 641 | + \EEH_Debug_Tools::printr("{$ticket_quantity}", |
|
| 642 | + " . . . {$datetime_identifier} capacity reduced by", __FILE__, __LINE__); |
|
| 643 | + } |
|
| 644 | + return true; |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | 648 | |
| 649 | 649 | } |
| 650 | 650 | // Location: EventSpacesCalculator.php |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | // sort incoming array by ticket quantity (asc) |
| 156 | 156 | usort( |
| 157 | 157 | $active_tickets, |
| 158 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 158 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 159 | 159 | if ($a->qty() === $b->qty()) { |
| 160 | 160 | return 0; |
| 161 | 161 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | ) |
| 232 | 232 | ); |
| 233 | 233 | } |
| 234 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 234 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -322,16 +322,16 @@ discard block |
||
| 322 | 322 | // we are going to move all of our data into the following arrays: |
| 323 | 323 | // datetime spaces initially represents the reg limit for each datetime, |
| 324 | 324 | // but this will get adjusted as tickets are accounted for |
| 325 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 325 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
| 326 | 326 | // just an array of ticket IDs grouped by datetime |
| 327 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 327 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
| 328 | 328 | // and an array of datetime IDs grouped by ticket |
| 329 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 329 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
| 330 | 330 | } |
| 331 | 331 | // total quantity of sold and reserved for each ticket |
| 332 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 332 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
| 333 | 333 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
| 334 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 334 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -390,19 +390,19 @@ discard block |
||
| 390 | 390 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
| 391 | 391 | } |
| 392 | 392 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
| 393 | - if (isset($this->ticket_quantities[ $ticket_identifier ])){ |
|
| 394 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 393 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 394 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
| 395 | 395 | if ($this->debug) { |
| 396 | 396 | \EEH_Debug_Tools::printr("{$tickets_sold} sales for ticket {$ticket_identifier} ", 'subtracting', __FILE__, __LINE__); |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | 399 | if ( |
| 400 | - isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 401 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 402 | - ){ |
|
| 403 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 404 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 405 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 400 | + isset($this->ticket_datetimes[$ticket_identifier]) |
|
| 401 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
| 402 | + ) { |
|
| 403 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
| 404 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 405 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
| 406 | 406 | if ($this->debug) { |
| 407 | 407 | \EEH_Debug_Tools::printr("{$tickets_sold} sales for datetime {$ticket_datetime} ", |
| 408 | 408 | 'subtracting', __FILE__, __LINE__); |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
| 423 | 423 | { |
| 424 | 424 | // make sure a reg limit is set for the datetime |
| 425 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 426 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 425 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
| 426 | + ? $this->datetime_spaces[$datetime_identifier] |
|
| 427 | 427 | : 0; |
| 428 | 428 | // and bail if it is not |
| 429 | 429 | if ( ! $reg_limit) { |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | } |
| 439 | 439 | // number of allocated spaces always starts at zero |
| 440 | 440 | $spaces_allocated = 0; |
| 441 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 441 | + $this->total_spaces[$datetime_identifier] = 0; |
|
| 442 | 442 | foreach ($tickets as $ticket_identifier) { |
| 443 | 443 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
| 444 | 444 | $datetime_identifier, |
@@ -451,9 +451,9 @@ discard block |
||
| 451 | 451 | $spaces_allocated = max($spaces_allocated, 0); |
| 452 | 452 | if ($spaces_allocated) { |
| 453 | 453 | // track any non-zero values |
| 454 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 454 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
| 455 | 455 | if ($this->debug) { |
| 456 | - \EEH_Debug_Tools::printr((string)$spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 456 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 457 | 457 | } |
| 458 | 458 | } else { |
| 459 | 459 | if ($this->debug) { |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | if ($this->debug) { |
| 464 | - \EEH_Debug_Tools::printr($this->total_spaces[ $datetime_identifier ], '$total_spaces', __FILE__, |
|
| 464 | + \EEH_Debug_Tools::printr($this->total_spaces[$datetime_identifier], '$total_spaces', __FILE__, |
|
| 465 | 465 | __LINE__); |
| 466 | 466 | \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
| 467 | 467 | \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | $spaces_allocated |
| 485 | 485 | ) { |
| 486 | 486 | // make sure ticket quantity is set |
| 487 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 488 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 487 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
| 488 | + ? $this->ticket_quantities[$ticket_identifier] |
|
| 489 | 489 | : 0; |
| 490 | 490 | if ($this->debug) { |
| 491 | 491 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -509,13 +509,13 @@ discard block |
||
| 509 | 509 | // or the maximum ticket quantity |
| 510 | 510 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
| 511 | 511 | // adjust the available quantity in our tracking array |
| 512 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 512 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
| 513 | 513 | // and increment spaces allocated for this datetime |
| 514 | 514 | $spaces_allocated += $ticket_quantity; |
| 515 | 515 | $at_capacity = $spaces_allocated >= $reg_limit; |
| 516 | 516 | if ($this->debug) { |
| 517 | 517 | \EEH_Debug_Tools::printr("{$ticket_quantity} {$ticket_identifier} tickets", ' > > allocate ', |
| 518 | - __FILE__, __LINE__, 3); |
|
| 518 | + __FILE__, __LINE__, 3); |
|
| 519 | 519 | if ($at_capacity) { |
| 520 | 520 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
| 521 | 521 | } |
@@ -561,15 +561,15 @@ discard block |
||
| 561 | 561 | $ticket_quantity |
| 562 | 562 | ); |
| 563 | 563 | // skip to next ticket if nothing changed |
| 564 | - if (! ($adjusted || $at_capacity)) { |
|
| 564 | + if ( ! ($adjusted || $at_capacity)) { |
|
| 565 | 565 | continue; |
| 566 | 566 | } |
| 567 | 567 | // then all of it's tickets are now unavailable |
| 568 | 568 | foreach ($datetime_tickets as $datetime_ticket) { |
| 569 | 569 | if ( |
| 570 | 570 | ($ticket_identifier === $datetime_ticket || $at_capacity) |
| 571 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 572 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 571 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
| 572 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
| 573 | 573 | ) { |
| 574 | 574 | if ($this->debug) { |
| 575 | 575 | \EEH_Debug_Tools::printr($datetime_ticket, ' . . . adjust ticket quantities for', __FILE__, |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | // otherwise just subtract the ticket quantity |
| 580 | 580 | $new_quantity = $at_capacity |
| 581 | 581 | ? 0 |
| 582 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 582 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
| 583 | 583 | // don't let ticket quantity go below zero |
| 584 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 584 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
| 585 | 585 | if ($this->debug) { |
| 586 | 586 | \EEH_Debug_Tools::printr( |
| 587 | 587 | $at_capacity |
| 588 | 588 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
| 589 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 589 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
| 590 | 590 | " . . . . {$datetime_ticket} quantity set to ", |
| 591 | 591 | __FILE__, __LINE__ |
| 592 | 592 | ); |
@@ -594,14 +594,14 @@ discard block |
||
| 594 | 594 | } |
| 595 | 595 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
| 596 | 596 | if ($datetime_ticket === $ticket_identifier) { |
| 597 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 598 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 597 | + if (isset($this->ticket_datetimes[$datetime_ticket]) |
|
| 598 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
| 599 | 599 | ) { |
| 600 | 600 | if ($this->debug) { |
| 601 | 601 | \EEH_Debug_Tools::printr($datetime_ticket, ' . . adjust other Datetimes for', __FILE__, |
| 602 | 602 | __LINE__); |
| 603 | 603 | } |
| 604 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 604 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
| 605 | 605 | // don't adjust the current datetime twice |
| 606 | 606 | if ($datetime !== $datetime_identifier) { |
| 607 | 607 | $this->adjustDatetimeSpaces( |
@@ -622,19 +622,19 @@ discard block |
||
| 622 | 622 | // does datetime have spaces available? |
| 623 | 623 | // and does the supplied ticket have access to this datetime ? |
| 624 | 624 | if ( |
| 625 | - $this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 626 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 627 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 625 | + $this->datetime_spaces[$datetime_identifier] > 0 |
|
| 626 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
| 627 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
| 628 | 628 | ) { |
| 629 | 629 | if ($this->debug) { |
| 630 | 630 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
| 631 | - \EEH_Debug_Tools::printr("{$this->datetime_spaces[ $datetime_identifier ]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 631 | + \EEH_Debug_Tools::printr("{$this->datetime_spaces[$datetime_identifier]}", " . . current {$datetime_identifier} spaces available", __FILE__, __LINE__); |
|
| 632 | 632 | } |
| 633 | 633 | // then decrement the available spaces for the datetime |
| 634 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 634 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
| 635 | 635 | // but don't let quantities go below zero |
| 636 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 637 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 636 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
| 637 | + $this->datetime_spaces[$datetime_identifier], |
|
| 638 | 638 | 0 |
| 639 | 639 | ); |
| 640 | 640 | if ($this->debug) { |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 5 | 5 | |
| 6 | 6 | if (!defined('EVENT_ESPRESSO_VERSION')) { |
| 7 | - exit('No direct script access allowed'); |
|
| 7 | + exit('No direct script access allowed'); |
|
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | |
@@ -18,1289 +18,1289 @@ discard block |
||
| 18 | 18 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * cached value for the the logical active status for the event |
|
| 23 | - * |
|
| 24 | - * @see get_active_status() |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_active_status = ''; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 31 | - * |
|
| 32 | - * @var EE_Datetime |
|
| 33 | - */ |
|
| 34 | - protected $_Primary_Datetime; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 38 | - */ |
|
| 39 | - protected $available_spaces_calculator; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param array $props_n_values incoming values |
|
| 44 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 45 | - * used.) |
|
| 46 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 47 | - * date_format and the second value is the time format |
|
| 48 | - * @return EE_Event |
|
| 49 | - * @throws EE_Error |
|
| 50 | - */ |
|
| 51 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 52 | - { |
|
| 53 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 54 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param array $props_n_values incoming values from the database |
|
| 60 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 61 | - * the website will be used. |
|
| 62 | - * @return EE_Event |
|
| 63 | - * @throws EE_Error |
|
| 64 | - */ |
|
| 65 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | - { |
|
| 67 | - return new self($props_n_values, true, $timezone); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @return EventSpacesCalculator |
|
| 74 | - * @throws \EE_Error |
|
| 75 | - */ |
|
| 76 | - public function getAvailableSpacesCalculator() |
|
| 77 | - { |
|
| 78 | - if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 79 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 80 | - } |
|
| 81 | - return $this->available_spaces_calculator; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 88 | - * |
|
| 89 | - * @param string $field_name |
|
| 90 | - * @param mixed $field_value |
|
| 91 | - * @param bool $use_default |
|
| 92 | - * @throws EE_Error |
|
| 93 | - */ |
|
| 94 | - public function set($field_name, $field_value, $use_default = false) |
|
| 95 | - { |
|
| 96 | - switch ($field_name) { |
|
| 97 | - case 'status' : |
|
| 98 | - $this->set_status($field_value, $use_default); |
|
| 99 | - break; |
|
| 100 | - default : |
|
| 101 | - parent::set($field_name, $field_value, $use_default); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * set_status |
|
| 108 | - * Checks if event status is being changed to SOLD OUT |
|
| 109 | - * and updates event meta data with previous event status |
|
| 110 | - * so that we can revert things if/when the event is no longer sold out |
|
| 111 | - * |
|
| 112 | - * @access public |
|
| 113 | - * @param string $new_status |
|
| 114 | - * @param bool $use_default |
|
| 115 | - * @return void |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_status($new_status = null, $use_default = false) |
|
| 119 | - { |
|
| 120 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | - if (empty($new_status) && !$use_default) { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 124 | - // get current Event status |
|
| 125 | - $old_status = $this->status(); |
|
| 126 | - // if status has changed |
|
| 127 | - if ($old_status !== $new_status) { |
|
| 128 | - // TO sold_out |
|
| 129 | - if ($new_status === EEM_Event::sold_out) { |
|
| 130 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | - // OR FROM sold_out |
|
| 134 | - } else if ($old_status === EEM_Event::sold_out) { |
|
| 135 | - $this->delete_post_meta('_previous_event_status'); |
|
| 136 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | - } |
|
| 138 | - // update status |
|
| 139 | - parent::set('status', $new_status, $use_default); |
|
| 140 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 141 | - return; |
|
| 142 | - } |
|
| 143 | - // even though the old value matches the new value, it's still good to |
|
| 144 | - // allow the parent set method to have a say |
|
| 145 | - parent::set('status', $new_status, $use_default); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Gets all the datetimes for this event |
|
| 151 | - * |
|
| 152 | - * @param array $query_params like EEM_Base::get_all |
|
| 153 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 154 | - * @throws EE_Error |
|
| 155 | - */ |
|
| 156 | - public function datetimes($query_params = array()) |
|
| 157 | - { |
|
| 158 | - return $this->get_many_related('Datetime', $query_params); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 164 | - * |
|
| 165 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 166 | - * @throws EE_Error |
|
| 167 | - */ |
|
| 168 | - public function datetimes_in_chronological_order() |
|
| 169 | - { |
|
| 170 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 176 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 177 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 178 | - * on EEM_Datetime for the rest of the request, no? |
|
| 179 | - * |
|
| 180 | - * @param boolean $show_expired whether or not to include expired events |
|
| 181 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 182 | - * @param null $limit |
|
| 183 | - * @return EE_Datetime[] |
|
| 184 | - * @throws EE_Error |
|
| 185 | - */ |
|
| 186 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 187 | - { |
|
| 188 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 189 | - $this->ID(), |
|
| 190 | - $show_expired, |
|
| 191 | - $show_deleted, |
|
| 192 | - $limit |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 199 | - * |
|
| 200 | - * @return EE_Base_Class|EE_Datetime |
|
| 201 | - * @throws EE_Error |
|
| 202 | - */ |
|
| 203 | - public function first_datetime() |
|
| 204 | - { |
|
| 205 | - return $this->get_first_related('Datetime'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Returns the 'primary' datetime for the event |
|
| 211 | - * |
|
| 212 | - * @param bool $try_to_exclude_expired |
|
| 213 | - * @param bool $try_to_exclude_deleted |
|
| 214 | - * @return EE_Datetime |
|
| 215 | - * @throws EE_Error |
|
| 216 | - */ |
|
| 217 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 218 | - { |
|
| 219 | - if (!empty ($this->_Primary_Datetime)) { |
|
| 220 | - return $this->_Primary_Datetime; |
|
| 221 | - } |
|
| 222 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 223 | - $this->ID(), |
|
| 224 | - $try_to_exclude_expired, |
|
| 225 | - $try_to_exclude_deleted |
|
| 226 | - ); |
|
| 227 | - return $this->_Primary_Datetime; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Gets all the tickets available for purchase of this event |
|
| 233 | - * |
|
| 234 | - * @param array $query_params like EEM_Base::get_all |
|
| 235 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 236 | - * @throws EE_Error |
|
| 237 | - */ |
|
| 238 | - public function tickets($query_params = array()) |
|
| 239 | - { |
|
| 240 | - //first get all datetimes |
|
| 241 | - $datetimes = $this->datetimes_ordered(); |
|
| 242 | - if (!$datetimes) { |
|
| 243 | - return array(); |
|
| 244 | - } |
|
| 245 | - $datetime_ids = array(); |
|
| 246 | - foreach ($datetimes as $datetime) { |
|
| 247 | - $datetime_ids[] = $datetime->ID(); |
|
| 248 | - } |
|
| 249 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 250 | - //if incoming $query_params has where conditions let's merge but not override existing. |
|
| 251 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 252 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 253 | - unset($query_params[0]); |
|
| 254 | - } |
|
| 255 | - //now add $where_params to $query_params |
|
| 256 | - $query_params[0] = $where_params; |
|
| 257 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * get all unexpired untrashed tickets |
|
| 263 | - * |
|
| 264 | - * @return EE_Ticket[] |
|
| 265 | - * @throws EE_Error |
|
| 266 | - */ |
|
| 267 | - public function active_tickets() |
|
| 268 | - { |
|
| 269 | - return $this->tickets(array( |
|
| 270 | - array( |
|
| 271 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 272 | - 'TKT_deleted' => false, |
|
| 273 | - ), |
|
| 274 | - )); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return bool |
|
| 280 | - * @throws EE_Error |
|
| 281 | - */ |
|
| 282 | - public function additional_limit() |
|
| 283 | - { |
|
| 284 | - return $this->get('EVT_additional_limit'); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @return bool |
|
| 290 | - * @throws EE_Error |
|
| 291 | - */ |
|
| 292 | - public function allow_overflow() |
|
| 293 | - { |
|
| 294 | - return $this->get('EVT_allow_overflow'); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return bool |
|
| 300 | - * @throws EE_Error |
|
| 301 | - */ |
|
| 302 | - public function created() |
|
| 303 | - { |
|
| 304 | - return $this->get('EVT_created'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * @return bool |
|
| 310 | - * @throws EE_Error |
|
| 311 | - */ |
|
| 312 | - public function description() |
|
| 313 | - { |
|
| 314 | - return $this->get('EVT_desc'); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Runs do_shortcode and wpautop on the description |
|
| 320 | - * |
|
| 321 | - * @return string of html |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function description_filtered() |
|
| 325 | - { |
|
| 326 | - return $this->get_pretty('EVT_desc'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return bool |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function display_description() |
|
| 335 | - { |
|
| 336 | - return $this->get('EVT_display_desc'); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * @return bool |
|
| 342 | - * @throws EE_Error |
|
| 343 | - */ |
|
| 344 | - public function display_ticket_selector() |
|
| 345 | - { |
|
| 346 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @return bool |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public function external_url() |
|
| 355 | - { |
|
| 356 | - return $this->get('EVT_external_URL'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @return bool |
|
| 362 | - * @throws EE_Error |
|
| 363 | - */ |
|
| 364 | - public function member_only() |
|
| 365 | - { |
|
| 366 | - return $this->get('EVT_member_only'); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * @return bool |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public function phone() |
|
| 375 | - { |
|
| 376 | - return $this->get('EVT_phone'); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @return bool |
|
| 382 | - * @throws EE_Error |
|
| 383 | - */ |
|
| 384 | - public function modified() |
|
| 385 | - { |
|
| 386 | - return $this->get('EVT_modified'); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * @return bool |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function name() |
|
| 395 | - { |
|
| 396 | - return $this->get('EVT_name'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return bool |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function order() |
|
| 405 | - { |
|
| 406 | - return $this->get('EVT_order'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @return bool|string |
|
| 412 | - * @throws EE_Error |
|
| 413 | - */ |
|
| 414 | - public function default_registration_status() |
|
| 415 | - { |
|
| 416 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | - return !empty($event_default_registration_status) |
|
| 418 | - ? $event_default_registration_status |
|
| 419 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * @param int $num_words |
|
| 425 | - * @param null $more |
|
| 426 | - * @param bool $not_full_desc |
|
| 427 | - * @return bool|string |
|
| 428 | - * @throws EE_Error |
|
| 429 | - */ |
|
| 430 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | - { |
|
| 432 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | - if (!empty($short_desc) || $not_full_desc) { |
|
| 434 | - return $short_desc; |
|
| 435 | - } |
|
| 436 | - $full_desc = $this->get('EVT_desc'); |
|
| 437 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * @return bool |
|
| 443 | - * @throws EE_Error |
|
| 444 | - */ |
|
| 445 | - public function slug() |
|
| 446 | - { |
|
| 447 | - return $this->get('EVT_slug'); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @return bool |
|
| 453 | - * @throws EE_Error |
|
| 454 | - */ |
|
| 455 | - public function timezone_string() |
|
| 456 | - { |
|
| 457 | - return $this->get('EVT_timezone_string'); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * @return bool |
|
| 463 | - * @throws EE_Error |
|
| 464 | - */ |
|
| 465 | - public function visible_on() |
|
| 466 | - { |
|
| 467 | - return $this->get('EVT_visible_on'); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @return int |
|
| 473 | - * @throws EE_Error |
|
| 474 | - */ |
|
| 475 | - public function wp_user() |
|
| 476 | - { |
|
| 477 | - return $this->get('EVT_wp_user'); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @return bool |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function donations() |
|
| 486 | - { |
|
| 487 | - return $this->get('EVT_donations'); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @param $limit |
|
| 493 | - * @throws EE_Error |
|
| 494 | - */ |
|
| 495 | - public function set_additional_limit($limit) |
|
| 496 | - { |
|
| 497 | - $this->set('EVT_additional_limit', $limit); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param $created |
|
| 503 | - * @throws EE_Error |
|
| 504 | - */ |
|
| 505 | - public function set_created($created) |
|
| 506 | - { |
|
| 507 | - $this->set('EVT_created', $created); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * @param $desc |
|
| 513 | - * @throws EE_Error |
|
| 514 | - */ |
|
| 515 | - public function set_description($desc) |
|
| 516 | - { |
|
| 517 | - $this->set('EVT_desc', $desc); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @param $display_desc |
|
| 523 | - * @throws EE_Error |
|
| 524 | - */ |
|
| 525 | - public function set_display_description($display_desc) |
|
| 526 | - { |
|
| 527 | - $this->set('EVT_display_desc', $display_desc); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @param $display_ticket_selector |
|
| 533 | - * @throws EE_Error |
|
| 534 | - */ |
|
| 535 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | - { |
|
| 537 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * @param $external_url |
|
| 543 | - * @throws EE_Error |
|
| 544 | - */ |
|
| 545 | - public function set_external_url($external_url) |
|
| 546 | - { |
|
| 547 | - $this->set('EVT_external_URL', $external_url); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * @param $member_only |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public function set_member_only($member_only) |
|
| 556 | - { |
|
| 557 | - $this->set('EVT_member_only', $member_only); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @param $event_phone |
|
| 563 | - * @throws EE_Error |
|
| 564 | - */ |
|
| 565 | - public function set_event_phone($event_phone) |
|
| 566 | - { |
|
| 567 | - $this->set('EVT_phone', $event_phone); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param $modified |
|
| 573 | - * @throws EE_Error |
|
| 574 | - */ |
|
| 575 | - public function set_modified($modified) |
|
| 576 | - { |
|
| 577 | - $this->set('EVT_modified', $modified); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @param $name |
|
| 583 | - * @throws EE_Error |
|
| 584 | - */ |
|
| 585 | - public function set_name($name) |
|
| 586 | - { |
|
| 587 | - $this->set('EVT_name', $name); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @param $order |
|
| 593 | - * @throws EE_Error |
|
| 594 | - */ |
|
| 595 | - public function set_order($order) |
|
| 596 | - { |
|
| 597 | - $this->set('EVT_order', $order); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @param $short_desc |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function set_short_description($short_desc) |
|
| 606 | - { |
|
| 607 | - $this->set('EVT_short_desc', $short_desc); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @param $slug |
|
| 613 | - * @throws EE_Error |
|
| 614 | - */ |
|
| 615 | - public function set_slug($slug) |
|
| 616 | - { |
|
| 617 | - $this->set('EVT_slug', $slug); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param $timezone_string |
|
| 623 | - * @throws EE_Error |
|
| 624 | - */ |
|
| 625 | - public function set_timezone_string($timezone_string) |
|
| 626 | - { |
|
| 627 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * @param $visible_on |
|
| 633 | - * @throws EE_Error |
|
| 634 | - */ |
|
| 635 | - public function set_visible_on($visible_on) |
|
| 636 | - { |
|
| 637 | - $this->set('EVT_visible_on', $visible_on); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @param $wp_user |
|
| 643 | - * @throws EE_Error |
|
| 644 | - */ |
|
| 645 | - public function set_wp_user($wp_user) |
|
| 646 | - { |
|
| 647 | - $this->set('EVT_wp_user', $wp_user); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @param $default_registration_status |
|
| 653 | - * @throws EE_Error |
|
| 654 | - */ |
|
| 655 | - public function set_default_registration_status($default_registration_status) |
|
| 656 | - { |
|
| 657 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param $donations |
|
| 663 | - * @throws EE_Error |
|
| 664 | - */ |
|
| 665 | - public function set_donations($donations) |
|
| 666 | - { |
|
| 667 | - $this->set('EVT_donations', $donations); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Adds a venue to this event |
|
| 673 | - * |
|
| 674 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 675 | - * @return EE_Base_Class|EE_Venue |
|
| 676 | - * @throws EE_Error |
|
| 677 | - */ |
|
| 678 | - public function add_venue($venue_id_or_obj) |
|
| 679 | - { |
|
| 680 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Removes a venue from the event |
|
| 686 | - * |
|
| 687 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 688 | - * @return EE_Base_Class|EE_Venue |
|
| 689 | - * @throws EE_Error |
|
| 690 | - */ |
|
| 691 | - public function remove_venue($venue_id_or_obj) |
|
| 692 | - { |
|
| 693 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 699 | - * |
|
| 700 | - * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 701 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 702 | - * @throws EE_Error |
|
| 703 | - */ |
|
| 704 | - public function venues($query_params = array()) |
|
| 705 | - { |
|
| 706 | - return $this->get_many_related('Venue', $query_params); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - |
|
| 710 | - /** |
|
| 711 | - * check if event id is present and if event is published |
|
| 712 | - * |
|
| 713 | - * @access public |
|
| 714 | - * @return boolean true yes, false no |
|
| 715 | - * @throws EE_Error |
|
| 716 | - */ |
|
| 717 | - private function _has_ID_and_is_published() |
|
| 718 | - { |
|
| 719 | - // first check if event id is present and not NULL, |
|
| 720 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 721 | - return |
|
| 722 | - $this->ID() && $this->ID() !== null |
|
| 723 | - && ( |
|
| 724 | - $this->status() === 'publish' |
|
| 725 | - || $this->status() === EEM_Event::sold_out |
|
| 726 | - || $this->status() === EEM_Event::postponed |
|
| 727 | - || $this->status() === EEM_Event::cancelled |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - |
|
| 732 | - /** |
|
| 733 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 734 | - * |
|
| 735 | - * @access public |
|
| 736 | - * @return boolean true yes, false no |
|
| 737 | - * @throws EE_Error |
|
| 738 | - */ |
|
| 739 | - public function is_upcoming() |
|
| 740 | - { |
|
| 741 | - // check if event id is present and if this event is published |
|
| 742 | - if ($this->is_inactive()) { |
|
| 743 | - return false; |
|
| 744 | - } |
|
| 745 | - // set initial value |
|
| 746 | - $upcoming = false; |
|
| 747 | - //next let's get all datetimes and loop through them |
|
| 748 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 749 | - foreach ($datetimes as $datetime) { |
|
| 750 | - if ($datetime instanceof EE_Datetime) { |
|
| 751 | - //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 752 | - if ($datetime->is_expired()) { |
|
| 753 | - continue; |
|
| 754 | - } |
|
| 755 | - //if this dtt is active then we return false. |
|
| 756 | - if ($datetime->is_active()) { |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 759 | - //otherwise let's check upcoming status |
|
| 760 | - $upcoming = $datetime->is_upcoming(); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - return $upcoming; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * @return bool |
|
| 769 | - * @throws EE_Error |
|
| 770 | - */ |
|
| 771 | - public function is_active() |
|
| 772 | - { |
|
| 773 | - // check if event id is present and if this event is published |
|
| 774 | - if ($this->is_inactive()) { |
|
| 775 | - return false; |
|
| 776 | - } |
|
| 777 | - // set initial value |
|
| 778 | - $active = false; |
|
| 779 | - //next let's get all datetimes and loop through them |
|
| 780 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | - foreach ($datetimes as $datetime) { |
|
| 782 | - if ($datetime instanceof EE_Datetime) { |
|
| 783 | - //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 784 | - if ($datetime->is_expired()) { |
|
| 785 | - continue; |
|
| 786 | - } |
|
| 787 | - //if this dtt is upcoming then we return false. |
|
| 788 | - if ($datetime->is_upcoming()) { |
|
| 789 | - return false; |
|
| 790 | - } |
|
| 791 | - //otherwise let's check active status |
|
| 792 | - $active = $datetime->is_active(); |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - return $active; |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * @return bool |
|
| 801 | - * @throws EE_Error |
|
| 802 | - */ |
|
| 803 | - public function is_expired() |
|
| 804 | - { |
|
| 805 | - // check if event id is present and if this event is published |
|
| 806 | - if ($this->is_inactive()) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - // set initial value |
|
| 810 | - $expired = false; |
|
| 811 | - //first let's get all datetimes and loop through them |
|
| 812 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | - foreach ($datetimes as $datetime) { |
|
| 814 | - if ($datetime instanceof EE_Datetime) { |
|
| 815 | - //if this dtt is upcoming or active then we return false. |
|
| 816 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 817 | - return false; |
|
| 818 | - } |
|
| 819 | - //otherwise let's check active status |
|
| 820 | - $expired = $datetime->is_expired(); |
|
| 821 | - } |
|
| 822 | - } |
|
| 823 | - return $expired; |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * @return bool |
|
| 829 | - * @throws EE_Error |
|
| 830 | - */ |
|
| 831 | - public function is_inactive() |
|
| 832 | - { |
|
| 833 | - // check if event id is present and if this event is published |
|
| 834 | - if ($this->_has_ID_and_is_published()) { |
|
| 835 | - return false; |
|
| 836 | - } |
|
| 837 | - return true; |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * calculate spaces remaining based on "saleable" tickets |
|
| 843 | - * |
|
| 844 | - * @param array $tickets |
|
| 845 | - * @param bool $filtered |
|
| 846 | - * @return int|float |
|
| 847 | - * @throws EE_Error |
|
| 848 | - * @throws DomainException |
|
| 849 | - * @throws UnexpectedEntityException |
|
| 850 | - */ |
|
| 851 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 852 | - { |
|
| 853 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 854 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 855 | - return $filtered |
|
| 856 | - ? apply_filters( |
|
| 857 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 858 | - $spaces_remaining, |
|
| 859 | - $this, |
|
| 860 | - $tickets |
|
| 861 | - ) |
|
| 862 | - : $spaces_remaining; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - |
|
| 866 | - /** |
|
| 867 | - * perform_sold_out_status_check |
|
| 868 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces available... |
|
| 869 | - * if NOT, then the event status will get toggled to 'sold_out' |
|
| 870 | - * |
|
| 871 | - * @return bool return the ACTUAL sold out state. |
|
| 872 | - * @throws EE_Error |
|
| 873 | - * @throws DomainException |
|
| 874 | - * @throws UnexpectedEntityException |
|
| 875 | - */ |
|
| 876 | - public function perform_sold_out_status_check() |
|
| 877 | - { |
|
| 878 | - // get all unexpired untrashed tickets |
|
| 879 | - $tickets = $this->active_tickets(); |
|
| 880 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 881 | - if (empty($tickets)) { |
|
| 882 | - return true; |
|
| 883 | - } |
|
| 884 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 885 | - if ($spaces_remaining < 1) { |
|
| 886 | - $this->set_status(EEM_Event::sold_out); |
|
| 887 | - $this->save(); |
|
| 888 | - $sold_out = true; |
|
| 889 | - } else { |
|
| 890 | - $sold_out = false; |
|
| 891 | - // was event previously marked as sold out ? |
|
| 892 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 893 | - // revert status to previous value, if it was set |
|
| 894 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 895 | - if ($previous_event_status) { |
|
| 896 | - $this->set_status($previous_event_status); |
|
| 897 | - $this->save(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 902 | - return $sold_out; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * This returns the total remaining spaces for sale on this event. |
|
| 909 | - * |
|
| 910 | - * @uses EE_Event::total_available_spaces() |
|
| 911 | - * @return float|int |
|
| 912 | - * @throws EE_Error |
|
| 913 | - * @throws DomainException |
|
| 914 | - * @throws UnexpectedEntityException |
|
| 915 | - */ |
|
| 916 | - public function spaces_remaining_for_sale() |
|
| 917 | - { |
|
| 918 | - return $this->total_available_spaces(true); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - |
|
| 922 | - |
|
| 923 | - /** |
|
| 924 | - * This returns the total spaces available for an event |
|
| 925 | - * while considering all the qtys on the tickets and the reg limits |
|
| 926 | - * on the datetimes attached to this event. |
|
| 927 | - * |
|
| 928 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 929 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 930 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 931 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 932 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 933 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 934 | - * sold out, the more accurate the "live" total is. |
|
| 935 | - * @return float|int |
|
| 936 | - * @throws EE_Error |
|
| 937 | - * @throws DomainException |
|
| 938 | - * @throws UnexpectedEntityException |
|
| 939 | - */ |
|
| 940 | - public function total_available_spaces($consider_sold = false) |
|
| 941 | - { |
|
| 942 | - $spaces_available = $consider_sold |
|
| 943 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 944 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 945 | - return apply_filters( |
|
| 946 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 947 | - $spaces_available, |
|
| 948 | - $this, |
|
| 949 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 950 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 951 | - ); |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * Checks if the event is set to sold out |
|
| 957 | - * |
|
| 958 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 959 | - * actual status but also to flip the status if necessary to sold |
|
| 960 | - * out If false, we just check the existing status of the event |
|
| 961 | - * @return boolean |
|
| 962 | - * @throws EE_Error |
|
| 963 | - */ |
|
| 964 | - public function is_sold_out($actual = false) |
|
| 965 | - { |
|
| 966 | - if (!$actual) { |
|
| 967 | - return $this->status() === EEM_Event::sold_out; |
|
| 968 | - } |
|
| 969 | - return $this->perform_sold_out_status_check(); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - /** |
|
| 974 | - * Checks if the event is marked as postponed |
|
| 975 | - * |
|
| 976 | - * @return boolean |
|
| 977 | - */ |
|
| 978 | - public function is_postponed() |
|
| 979 | - { |
|
| 980 | - return $this->status() === EEM_Event::postponed; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - /** |
|
| 985 | - * Checks if the event is marked as cancelled |
|
| 986 | - * |
|
| 987 | - * @return boolean |
|
| 988 | - */ |
|
| 989 | - public function is_cancelled() |
|
| 990 | - { |
|
| 991 | - return $this->status() === EEM_Event::cancelled; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 997 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 998 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 999 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1000 | - * the event is considered expired. |
|
| 1001 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a status |
|
| 1002 | - * set on the EVENT when it is not published and thus is done |
|
| 1003 | - * |
|
| 1004 | - * @param bool $reset |
|
| 1005 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1006 | - * @throws EE_Error |
|
| 1007 | - */ |
|
| 1008 | - public function get_active_status($reset = false) |
|
| 1009 | - { |
|
| 1010 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1011 | - if (!empty($this->_active_status) && !$reset) { |
|
| 1012 | - return $this->_active_status; |
|
| 1013 | - } |
|
| 1014 | - //first check if event id is present on this object |
|
| 1015 | - if (!$this->ID()) { |
|
| 1016 | - return false; |
|
| 1017 | - } |
|
| 1018 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1019 | - //if event is published: |
|
| 1020 | - if ($this->status() === 'publish') { |
|
| 1021 | - //active? |
|
| 1022 | - if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) { |
|
| 1023 | - $this->_active_status = EE_Datetime::active; |
|
| 1024 | - } else { |
|
| 1025 | - //upcoming? |
|
| 1026 | - if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) { |
|
| 1027 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1028 | - } else { |
|
| 1029 | - //expired? |
|
| 1030 | - if ( |
|
| 1031 | - EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
| 1032 | - ) { |
|
| 1033 | - $this->_active_status = EE_Datetime::expired; |
|
| 1034 | - } else { |
|
| 1035 | - //it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1036 | - //attached to the event. So in this case it will just be considered inactive. |
|
| 1037 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - } else { |
|
| 1042 | - //the event is not published, so let's just set it's active status according to its' post status |
|
| 1043 | - switch ($this->status()) { |
|
| 1044 | - case EEM_Event::sold_out : |
|
| 1045 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1046 | - break; |
|
| 1047 | - case EEM_Event::cancelled : |
|
| 1048 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1049 | - break; |
|
| 1050 | - case EEM_Event::postponed : |
|
| 1051 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1052 | - break; |
|
| 1053 | - default : |
|
| 1054 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - return $this->_active_status; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * pretty_active_status |
|
| 1063 | - * |
|
| 1064 | - * @access public |
|
| 1065 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1066 | - * @return mixed void|string |
|
| 1067 | - * @throws EE_Error |
|
| 1068 | - */ |
|
| 1069 | - public function pretty_active_status($echo = true) |
|
| 1070 | - { |
|
| 1071 | - $active_status = $this->get_active_status(); |
|
| 1072 | - $status = '<span class="ee-status event-active-status-' |
|
| 1073 | - . $active_status |
|
| 1074 | - . '">' |
|
| 1075 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1076 | - . '</span>'; |
|
| 1077 | - if ($echo) { |
|
| 1078 | - echo $status; |
|
| 1079 | - return ''; |
|
| 1080 | - } |
|
| 1081 | - return $status; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * @return bool|int |
|
| 1087 | - * @throws EE_Error |
|
| 1088 | - */ |
|
| 1089 | - public function get_number_of_tickets_sold() |
|
| 1090 | - { |
|
| 1091 | - $tkt_sold = 0; |
|
| 1092 | - if (!$this->ID()) { |
|
| 1093 | - return 0; |
|
| 1094 | - } |
|
| 1095 | - $datetimes = $this->datetimes(); |
|
| 1096 | - foreach ($datetimes as $datetime) { |
|
| 1097 | - if ($datetime instanceof EE_Datetime) { |
|
| 1098 | - $tkt_sold += $datetime->sold(); |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - return $tkt_sold; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * This just returns a count of all the registrations for this event |
|
| 1107 | - * |
|
| 1108 | - * @access public |
|
| 1109 | - * @return int |
|
| 1110 | - * @throws EE_Error |
|
| 1111 | - */ |
|
| 1112 | - public function get_count_of_all_registrations() |
|
| 1113 | - { |
|
| 1114 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * This returns the ticket with the earliest start time that is |
|
| 1120 | - * available for this event (across all datetimes attached to the event) |
|
| 1121 | - * |
|
| 1122 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1123 | - * @throws EE_Error |
|
| 1124 | - */ |
|
| 1125 | - public function get_ticket_with_earliest_start_time() |
|
| 1126 | - { |
|
| 1127 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1128 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1129 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * This returns the ticket with the latest end time that is available |
|
| 1135 | - * for this event (across all datetimes attached to the event) |
|
| 1136 | - * |
|
| 1137 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - */ |
|
| 1140 | - public function get_ticket_with_latest_end_time() |
|
| 1141 | - { |
|
| 1142 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1143 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1144 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - |
|
| 1148 | - /** |
|
| 1149 | - * This returns whether there are any tickets on sale for this event. |
|
| 1150 | - * |
|
| 1151 | - * @return bool true = YES tickets on sale. |
|
| 1152 | - * @throws EE_Error |
|
| 1153 | - */ |
|
| 1154 | - public function tickets_on_sale() |
|
| 1155 | - { |
|
| 1156 | - $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
| 1157 | - $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
| 1158 | - if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | - return false; |
|
| 1160 | - } |
|
| 1161 | - //check on sale for these two tickets. |
|
| 1162 | - if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
| 1163 | - return true; |
|
| 1164 | - } |
|
| 1165 | - return false; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1171 | - * to check for an external URL first |
|
| 1172 | - * |
|
| 1173 | - * @return string |
|
| 1174 | - * @throws EE_Error |
|
| 1175 | - */ |
|
| 1176 | - public function get_permalink() |
|
| 1177 | - { |
|
| 1178 | - if ($this->external_url()) { |
|
| 1179 | - return $this->external_url(); |
|
| 1180 | - } |
|
| 1181 | - return parent::get_permalink(); |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1187 | - * |
|
| 1188 | - * @param array $query_params like EEM_Base::get_all |
|
| 1189 | - * @return EE_Base_Class|EE_Term|null |
|
| 1190 | - * @throws EE_Error |
|
| 1191 | - */ |
|
| 1192 | - public function first_event_category($query_params = array()) |
|
| 1193 | - { |
|
| 1194 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1195 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1196 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - |
|
| 1200 | - /** |
|
| 1201 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1202 | - * |
|
| 1203 | - * @param array $query_params |
|
| 1204 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1205 | - * @throws EE_Error |
|
| 1206 | - */ |
|
| 1207 | - public function get_all_event_categories($query_params = array()) |
|
| 1208 | - { |
|
| 1209 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1210 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1211 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - |
|
| 1215 | - /** |
|
| 1216 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1217 | - * |
|
| 1218 | - * @param array $query_params @see EEM_Base::get_all |
|
| 1219 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1220 | - * @throws EE_Error |
|
| 1221 | - */ |
|
| 1222 | - public function question_groups($query_params = array()) |
|
| 1223 | - { |
|
| 1224 | - $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1231 | - * |
|
| 1232 | - * @see EEI_Visual_Representation for comments |
|
| 1233 | - * @return string |
|
| 1234 | - */ |
|
| 1235 | - public function get_icon() |
|
| 1236 | - { |
|
| 1237 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1238 | - } |
|
| 1239 | - |
|
| 1240 | - |
|
| 1241 | - /** |
|
| 1242 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1243 | - * |
|
| 1244 | - * @see EEI_Admin_Links for comments |
|
| 1245 | - * @return string |
|
| 1246 | - * @throws EE_Error |
|
| 1247 | - */ |
|
| 1248 | - public function get_admin_details_link() |
|
| 1249 | - { |
|
| 1250 | - return $this->get_admin_edit_link(); |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - |
|
| 1254 | - /** |
|
| 1255 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1256 | - * |
|
| 1257 | - * @see EEI_Admin_Links for comments |
|
| 1258 | - * @return string |
|
| 1259 | - * @throws EE_Error |
|
| 1260 | - */ |
|
| 1261 | - public function get_admin_edit_link() |
|
| 1262 | - { |
|
| 1263 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1264 | - 'page' => 'espresso_events', |
|
| 1265 | - 'action' => 'edit', |
|
| 1266 | - 'post' => $this->ID(), |
|
| 1267 | - ), |
|
| 1268 | - admin_url('admin.php') |
|
| 1269 | - ); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1275 | - * |
|
| 1276 | - * @see EEI_Admin_Links for comments |
|
| 1277 | - * @return string |
|
| 1278 | - */ |
|
| 1279 | - public function get_admin_settings_link() |
|
| 1280 | - { |
|
| 1281 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1282 | - 'page' => 'espresso_events', |
|
| 1283 | - 'action' => 'default_event_settings', |
|
| 1284 | - ), |
|
| 1285 | - admin_url('admin.php') |
|
| 1286 | - ); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1292 | - * |
|
| 1293 | - * @see EEI_Admin_Links for comments |
|
| 1294 | - * @return string |
|
| 1295 | - */ |
|
| 1296 | - public function get_admin_overview_link() |
|
| 1297 | - { |
|
| 1298 | - return EEH_URL::add_query_args_and_nonce(array( |
|
| 1299 | - 'page' => 'espresso_events', |
|
| 1300 | - 'action' => 'default', |
|
| 1301 | - ), |
|
| 1302 | - admin_url('admin.php') |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 21 | + /** |
|
| 22 | + * cached value for the the logical active status for the event |
|
| 23 | + * |
|
| 24 | + * @see get_active_status() |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_active_status = ''; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 31 | + * |
|
| 32 | + * @var EE_Datetime |
|
| 33 | + */ |
|
| 34 | + protected $_Primary_Datetime; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 38 | + */ |
|
| 39 | + protected $available_spaces_calculator; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param array $props_n_values incoming values |
|
| 44 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 45 | + * used.) |
|
| 46 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 47 | + * date_format and the second value is the time format |
|
| 48 | + * @return EE_Event |
|
| 49 | + * @throws EE_Error |
|
| 50 | + */ |
|
| 51 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 52 | + { |
|
| 53 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 54 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param array $props_n_values incoming values from the database |
|
| 60 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 61 | + * the website will be used. |
|
| 62 | + * @return EE_Event |
|
| 63 | + * @throws EE_Error |
|
| 64 | + */ |
|
| 65 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 66 | + { |
|
| 67 | + return new self($props_n_values, true, $timezone); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @return EventSpacesCalculator |
|
| 74 | + * @throws \EE_Error |
|
| 75 | + */ |
|
| 76 | + public function getAvailableSpacesCalculator() |
|
| 77 | + { |
|
| 78 | + if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 79 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 80 | + } |
|
| 81 | + return $this->available_spaces_calculator; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 88 | + * |
|
| 89 | + * @param string $field_name |
|
| 90 | + * @param mixed $field_value |
|
| 91 | + * @param bool $use_default |
|
| 92 | + * @throws EE_Error |
|
| 93 | + */ |
|
| 94 | + public function set($field_name, $field_value, $use_default = false) |
|
| 95 | + { |
|
| 96 | + switch ($field_name) { |
|
| 97 | + case 'status' : |
|
| 98 | + $this->set_status($field_value, $use_default); |
|
| 99 | + break; |
|
| 100 | + default : |
|
| 101 | + parent::set($field_name, $field_value, $use_default); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * set_status |
|
| 108 | + * Checks if event status is being changed to SOLD OUT |
|
| 109 | + * and updates event meta data with previous event status |
|
| 110 | + * so that we can revert things if/when the event is no longer sold out |
|
| 111 | + * |
|
| 112 | + * @access public |
|
| 113 | + * @param string $new_status |
|
| 114 | + * @param bool $use_default |
|
| 115 | + * @return void |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_status($new_status = null, $use_default = false) |
|
| 119 | + { |
|
| 120 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 121 | + if (empty($new_status) && !$use_default) { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | + // get current Event status |
|
| 125 | + $old_status = $this->status(); |
|
| 126 | + // if status has changed |
|
| 127 | + if ($old_status !== $new_status) { |
|
| 128 | + // TO sold_out |
|
| 129 | + if ($new_status === EEM_Event::sold_out) { |
|
| 130 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 131 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 132 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 133 | + // OR FROM sold_out |
|
| 134 | + } else if ($old_status === EEM_Event::sold_out) { |
|
| 135 | + $this->delete_post_meta('_previous_event_status'); |
|
| 136 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 137 | + } |
|
| 138 | + // update status |
|
| 139 | + parent::set('status', $new_status, $use_default); |
|
| 140 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 141 | + return; |
|
| 142 | + } |
|
| 143 | + // even though the old value matches the new value, it's still good to |
|
| 144 | + // allow the parent set method to have a say |
|
| 145 | + parent::set('status', $new_status, $use_default); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Gets all the datetimes for this event |
|
| 151 | + * |
|
| 152 | + * @param array $query_params like EEM_Base::get_all |
|
| 153 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 154 | + * @throws EE_Error |
|
| 155 | + */ |
|
| 156 | + public function datetimes($query_params = array()) |
|
| 157 | + { |
|
| 158 | + return $this->get_many_related('Datetime', $query_params); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 164 | + * |
|
| 165 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 166 | + * @throws EE_Error |
|
| 167 | + */ |
|
| 168 | + public function datetimes_in_chronological_order() |
|
| 169 | + { |
|
| 170 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 176 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 177 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 178 | + * on EEM_Datetime for the rest of the request, no? |
|
| 179 | + * |
|
| 180 | + * @param boolean $show_expired whether or not to include expired events |
|
| 181 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 182 | + * @param null $limit |
|
| 183 | + * @return EE_Datetime[] |
|
| 184 | + * @throws EE_Error |
|
| 185 | + */ |
|
| 186 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 187 | + { |
|
| 188 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 189 | + $this->ID(), |
|
| 190 | + $show_expired, |
|
| 191 | + $show_deleted, |
|
| 192 | + $limit |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 199 | + * |
|
| 200 | + * @return EE_Base_Class|EE_Datetime |
|
| 201 | + * @throws EE_Error |
|
| 202 | + */ |
|
| 203 | + public function first_datetime() |
|
| 204 | + { |
|
| 205 | + return $this->get_first_related('Datetime'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Returns the 'primary' datetime for the event |
|
| 211 | + * |
|
| 212 | + * @param bool $try_to_exclude_expired |
|
| 213 | + * @param bool $try_to_exclude_deleted |
|
| 214 | + * @return EE_Datetime |
|
| 215 | + * @throws EE_Error |
|
| 216 | + */ |
|
| 217 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 218 | + { |
|
| 219 | + if (!empty ($this->_Primary_Datetime)) { |
|
| 220 | + return $this->_Primary_Datetime; |
|
| 221 | + } |
|
| 222 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 223 | + $this->ID(), |
|
| 224 | + $try_to_exclude_expired, |
|
| 225 | + $try_to_exclude_deleted |
|
| 226 | + ); |
|
| 227 | + return $this->_Primary_Datetime; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Gets all the tickets available for purchase of this event |
|
| 233 | + * |
|
| 234 | + * @param array $query_params like EEM_Base::get_all |
|
| 235 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 236 | + * @throws EE_Error |
|
| 237 | + */ |
|
| 238 | + public function tickets($query_params = array()) |
|
| 239 | + { |
|
| 240 | + //first get all datetimes |
|
| 241 | + $datetimes = $this->datetimes_ordered(); |
|
| 242 | + if (!$datetimes) { |
|
| 243 | + return array(); |
|
| 244 | + } |
|
| 245 | + $datetime_ids = array(); |
|
| 246 | + foreach ($datetimes as $datetime) { |
|
| 247 | + $datetime_ids[] = $datetime->ID(); |
|
| 248 | + } |
|
| 249 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 250 | + //if incoming $query_params has where conditions let's merge but not override existing. |
|
| 251 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 252 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 253 | + unset($query_params[0]); |
|
| 254 | + } |
|
| 255 | + //now add $where_params to $query_params |
|
| 256 | + $query_params[0] = $where_params; |
|
| 257 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * get all unexpired untrashed tickets |
|
| 263 | + * |
|
| 264 | + * @return EE_Ticket[] |
|
| 265 | + * @throws EE_Error |
|
| 266 | + */ |
|
| 267 | + public function active_tickets() |
|
| 268 | + { |
|
| 269 | + return $this->tickets(array( |
|
| 270 | + array( |
|
| 271 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 272 | + 'TKT_deleted' => false, |
|
| 273 | + ), |
|
| 274 | + )); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return bool |
|
| 280 | + * @throws EE_Error |
|
| 281 | + */ |
|
| 282 | + public function additional_limit() |
|
| 283 | + { |
|
| 284 | + return $this->get('EVT_additional_limit'); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @return bool |
|
| 290 | + * @throws EE_Error |
|
| 291 | + */ |
|
| 292 | + public function allow_overflow() |
|
| 293 | + { |
|
| 294 | + return $this->get('EVT_allow_overflow'); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return bool |
|
| 300 | + * @throws EE_Error |
|
| 301 | + */ |
|
| 302 | + public function created() |
|
| 303 | + { |
|
| 304 | + return $this->get('EVT_created'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * @return bool |
|
| 310 | + * @throws EE_Error |
|
| 311 | + */ |
|
| 312 | + public function description() |
|
| 313 | + { |
|
| 314 | + return $this->get('EVT_desc'); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Runs do_shortcode and wpautop on the description |
|
| 320 | + * |
|
| 321 | + * @return string of html |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function description_filtered() |
|
| 325 | + { |
|
| 326 | + return $this->get_pretty('EVT_desc'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return bool |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function display_description() |
|
| 335 | + { |
|
| 336 | + return $this->get('EVT_display_desc'); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * @return bool |
|
| 342 | + * @throws EE_Error |
|
| 343 | + */ |
|
| 344 | + public function display_ticket_selector() |
|
| 345 | + { |
|
| 346 | + return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @return bool |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public function external_url() |
|
| 355 | + { |
|
| 356 | + return $this->get('EVT_external_URL'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @return bool |
|
| 362 | + * @throws EE_Error |
|
| 363 | + */ |
|
| 364 | + public function member_only() |
|
| 365 | + { |
|
| 366 | + return $this->get('EVT_member_only'); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * @return bool |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public function phone() |
|
| 375 | + { |
|
| 376 | + return $this->get('EVT_phone'); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @return bool |
|
| 382 | + * @throws EE_Error |
|
| 383 | + */ |
|
| 384 | + public function modified() |
|
| 385 | + { |
|
| 386 | + return $this->get('EVT_modified'); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * @return bool |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function name() |
|
| 395 | + { |
|
| 396 | + return $this->get('EVT_name'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return bool |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function order() |
|
| 405 | + { |
|
| 406 | + return $this->get('EVT_order'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @return bool|string |
|
| 412 | + * @throws EE_Error |
|
| 413 | + */ |
|
| 414 | + public function default_registration_status() |
|
| 415 | + { |
|
| 416 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 417 | + return !empty($event_default_registration_status) |
|
| 418 | + ? $event_default_registration_status |
|
| 419 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * @param int $num_words |
|
| 425 | + * @param null $more |
|
| 426 | + * @param bool $not_full_desc |
|
| 427 | + * @return bool|string |
|
| 428 | + * @throws EE_Error |
|
| 429 | + */ |
|
| 430 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 431 | + { |
|
| 432 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 433 | + if (!empty($short_desc) || $not_full_desc) { |
|
| 434 | + return $short_desc; |
|
| 435 | + } |
|
| 436 | + $full_desc = $this->get('EVT_desc'); |
|
| 437 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * @return bool |
|
| 443 | + * @throws EE_Error |
|
| 444 | + */ |
|
| 445 | + public function slug() |
|
| 446 | + { |
|
| 447 | + return $this->get('EVT_slug'); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @return bool |
|
| 453 | + * @throws EE_Error |
|
| 454 | + */ |
|
| 455 | + public function timezone_string() |
|
| 456 | + { |
|
| 457 | + return $this->get('EVT_timezone_string'); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @return bool |
|
| 463 | + * @throws EE_Error |
|
| 464 | + */ |
|
| 465 | + public function visible_on() |
|
| 466 | + { |
|
| 467 | + return $this->get('EVT_visible_on'); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @return int |
|
| 473 | + * @throws EE_Error |
|
| 474 | + */ |
|
| 475 | + public function wp_user() |
|
| 476 | + { |
|
| 477 | + return $this->get('EVT_wp_user'); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return bool |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function donations() |
|
| 486 | + { |
|
| 487 | + return $this->get('EVT_donations'); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @param $limit |
|
| 493 | + * @throws EE_Error |
|
| 494 | + */ |
|
| 495 | + public function set_additional_limit($limit) |
|
| 496 | + { |
|
| 497 | + $this->set('EVT_additional_limit', $limit); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param $created |
|
| 503 | + * @throws EE_Error |
|
| 504 | + */ |
|
| 505 | + public function set_created($created) |
|
| 506 | + { |
|
| 507 | + $this->set('EVT_created', $created); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * @param $desc |
|
| 513 | + * @throws EE_Error |
|
| 514 | + */ |
|
| 515 | + public function set_description($desc) |
|
| 516 | + { |
|
| 517 | + $this->set('EVT_desc', $desc); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @param $display_desc |
|
| 523 | + * @throws EE_Error |
|
| 524 | + */ |
|
| 525 | + public function set_display_description($display_desc) |
|
| 526 | + { |
|
| 527 | + $this->set('EVT_display_desc', $display_desc); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @param $display_ticket_selector |
|
| 533 | + * @throws EE_Error |
|
| 534 | + */ |
|
| 535 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 536 | + { |
|
| 537 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * @param $external_url |
|
| 543 | + * @throws EE_Error |
|
| 544 | + */ |
|
| 545 | + public function set_external_url($external_url) |
|
| 546 | + { |
|
| 547 | + $this->set('EVT_external_URL', $external_url); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * @param $member_only |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public function set_member_only($member_only) |
|
| 556 | + { |
|
| 557 | + $this->set('EVT_member_only', $member_only); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @param $event_phone |
|
| 563 | + * @throws EE_Error |
|
| 564 | + */ |
|
| 565 | + public function set_event_phone($event_phone) |
|
| 566 | + { |
|
| 567 | + $this->set('EVT_phone', $event_phone); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param $modified |
|
| 573 | + * @throws EE_Error |
|
| 574 | + */ |
|
| 575 | + public function set_modified($modified) |
|
| 576 | + { |
|
| 577 | + $this->set('EVT_modified', $modified); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @param $name |
|
| 583 | + * @throws EE_Error |
|
| 584 | + */ |
|
| 585 | + public function set_name($name) |
|
| 586 | + { |
|
| 587 | + $this->set('EVT_name', $name); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @param $order |
|
| 593 | + * @throws EE_Error |
|
| 594 | + */ |
|
| 595 | + public function set_order($order) |
|
| 596 | + { |
|
| 597 | + $this->set('EVT_order', $order); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @param $short_desc |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function set_short_description($short_desc) |
|
| 606 | + { |
|
| 607 | + $this->set('EVT_short_desc', $short_desc); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @param $slug |
|
| 613 | + * @throws EE_Error |
|
| 614 | + */ |
|
| 615 | + public function set_slug($slug) |
|
| 616 | + { |
|
| 617 | + $this->set('EVT_slug', $slug); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param $timezone_string |
|
| 623 | + * @throws EE_Error |
|
| 624 | + */ |
|
| 625 | + public function set_timezone_string($timezone_string) |
|
| 626 | + { |
|
| 627 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * @param $visible_on |
|
| 633 | + * @throws EE_Error |
|
| 634 | + */ |
|
| 635 | + public function set_visible_on($visible_on) |
|
| 636 | + { |
|
| 637 | + $this->set('EVT_visible_on', $visible_on); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @param $wp_user |
|
| 643 | + * @throws EE_Error |
|
| 644 | + */ |
|
| 645 | + public function set_wp_user($wp_user) |
|
| 646 | + { |
|
| 647 | + $this->set('EVT_wp_user', $wp_user); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @param $default_registration_status |
|
| 653 | + * @throws EE_Error |
|
| 654 | + */ |
|
| 655 | + public function set_default_registration_status($default_registration_status) |
|
| 656 | + { |
|
| 657 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param $donations |
|
| 663 | + * @throws EE_Error |
|
| 664 | + */ |
|
| 665 | + public function set_donations($donations) |
|
| 666 | + { |
|
| 667 | + $this->set('EVT_donations', $donations); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Adds a venue to this event |
|
| 673 | + * |
|
| 674 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 675 | + * @return EE_Base_Class|EE_Venue |
|
| 676 | + * @throws EE_Error |
|
| 677 | + */ |
|
| 678 | + public function add_venue($venue_id_or_obj) |
|
| 679 | + { |
|
| 680 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Removes a venue from the event |
|
| 686 | + * |
|
| 687 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 688 | + * @return EE_Base_Class|EE_Venue |
|
| 689 | + * @throws EE_Error |
|
| 690 | + */ |
|
| 691 | + public function remove_venue($venue_id_or_obj) |
|
| 692 | + { |
|
| 693 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 699 | + * |
|
| 700 | + * @param array $query_params like EEM_Base::get_all's $query_params |
|
| 701 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 702 | + * @throws EE_Error |
|
| 703 | + */ |
|
| 704 | + public function venues($query_params = array()) |
|
| 705 | + { |
|
| 706 | + return $this->get_many_related('Venue', $query_params); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + |
|
| 710 | + /** |
|
| 711 | + * check if event id is present and if event is published |
|
| 712 | + * |
|
| 713 | + * @access public |
|
| 714 | + * @return boolean true yes, false no |
|
| 715 | + * @throws EE_Error |
|
| 716 | + */ |
|
| 717 | + private function _has_ID_and_is_published() |
|
| 718 | + { |
|
| 719 | + // first check if event id is present and not NULL, |
|
| 720 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 721 | + return |
|
| 722 | + $this->ID() && $this->ID() !== null |
|
| 723 | + && ( |
|
| 724 | + $this->status() === 'publish' |
|
| 725 | + || $this->status() === EEM_Event::sold_out |
|
| 726 | + || $this->status() === EEM_Event::postponed |
|
| 727 | + || $this->status() === EEM_Event::cancelled |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + |
|
| 732 | + /** |
|
| 733 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 734 | + * |
|
| 735 | + * @access public |
|
| 736 | + * @return boolean true yes, false no |
|
| 737 | + * @throws EE_Error |
|
| 738 | + */ |
|
| 739 | + public function is_upcoming() |
|
| 740 | + { |
|
| 741 | + // check if event id is present and if this event is published |
|
| 742 | + if ($this->is_inactive()) { |
|
| 743 | + return false; |
|
| 744 | + } |
|
| 745 | + // set initial value |
|
| 746 | + $upcoming = false; |
|
| 747 | + //next let's get all datetimes and loop through them |
|
| 748 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 749 | + foreach ($datetimes as $datetime) { |
|
| 750 | + if ($datetime instanceof EE_Datetime) { |
|
| 751 | + //if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 752 | + if ($datetime->is_expired()) { |
|
| 753 | + continue; |
|
| 754 | + } |
|
| 755 | + //if this dtt is active then we return false. |
|
| 756 | + if ($datetime->is_active()) { |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | + //otherwise let's check upcoming status |
|
| 760 | + $upcoming = $datetime->is_upcoming(); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + return $upcoming; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * @return bool |
|
| 769 | + * @throws EE_Error |
|
| 770 | + */ |
|
| 771 | + public function is_active() |
|
| 772 | + { |
|
| 773 | + // check if event id is present and if this event is published |
|
| 774 | + if ($this->is_inactive()) { |
|
| 775 | + return false; |
|
| 776 | + } |
|
| 777 | + // set initial value |
|
| 778 | + $active = false; |
|
| 779 | + //next let's get all datetimes and loop through them |
|
| 780 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 781 | + foreach ($datetimes as $datetime) { |
|
| 782 | + if ($datetime instanceof EE_Datetime) { |
|
| 783 | + //if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 784 | + if ($datetime->is_expired()) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 787 | + //if this dtt is upcoming then we return false. |
|
| 788 | + if ($datetime->is_upcoming()) { |
|
| 789 | + return false; |
|
| 790 | + } |
|
| 791 | + //otherwise let's check active status |
|
| 792 | + $active = $datetime->is_active(); |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + return $active; |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * @return bool |
|
| 801 | + * @throws EE_Error |
|
| 802 | + */ |
|
| 803 | + public function is_expired() |
|
| 804 | + { |
|
| 805 | + // check if event id is present and if this event is published |
|
| 806 | + if ($this->is_inactive()) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + // set initial value |
|
| 810 | + $expired = false; |
|
| 811 | + //first let's get all datetimes and loop through them |
|
| 812 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 813 | + foreach ($datetimes as $datetime) { |
|
| 814 | + if ($datetime instanceof EE_Datetime) { |
|
| 815 | + //if this dtt is upcoming or active then we return false. |
|
| 816 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 819 | + //otherwise let's check active status |
|
| 820 | + $expired = $datetime->is_expired(); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | + return $expired; |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * @return bool |
|
| 829 | + * @throws EE_Error |
|
| 830 | + */ |
|
| 831 | + public function is_inactive() |
|
| 832 | + { |
|
| 833 | + // check if event id is present and if this event is published |
|
| 834 | + if ($this->_has_ID_and_is_published()) { |
|
| 835 | + return false; |
|
| 836 | + } |
|
| 837 | + return true; |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * calculate spaces remaining based on "saleable" tickets |
|
| 843 | + * |
|
| 844 | + * @param array $tickets |
|
| 845 | + * @param bool $filtered |
|
| 846 | + * @return int|float |
|
| 847 | + * @throws EE_Error |
|
| 848 | + * @throws DomainException |
|
| 849 | + * @throws UnexpectedEntityException |
|
| 850 | + */ |
|
| 851 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 852 | + { |
|
| 853 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 854 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 855 | + return $filtered |
|
| 856 | + ? apply_filters( |
|
| 857 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 858 | + $spaces_remaining, |
|
| 859 | + $this, |
|
| 860 | + $tickets |
|
| 861 | + ) |
|
| 862 | + : $spaces_remaining; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + |
|
| 866 | + /** |
|
| 867 | + * perform_sold_out_status_check |
|
| 868 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces available... |
|
| 869 | + * if NOT, then the event status will get toggled to 'sold_out' |
|
| 870 | + * |
|
| 871 | + * @return bool return the ACTUAL sold out state. |
|
| 872 | + * @throws EE_Error |
|
| 873 | + * @throws DomainException |
|
| 874 | + * @throws UnexpectedEntityException |
|
| 875 | + */ |
|
| 876 | + public function perform_sold_out_status_check() |
|
| 877 | + { |
|
| 878 | + // get all unexpired untrashed tickets |
|
| 879 | + $tickets = $this->active_tickets(); |
|
| 880 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 881 | + if (empty($tickets)) { |
|
| 882 | + return true; |
|
| 883 | + } |
|
| 884 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 885 | + if ($spaces_remaining < 1) { |
|
| 886 | + $this->set_status(EEM_Event::sold_out); |
|
| 887 | + $this->save(); |
|
| 888 | + $sold_out = true; |
|
| 889 | + } else { |
|
| 890 | + $sold_out = false; |
|
| 891 | + // was event previously marked as sold out ? |
|
| 892 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 893 | + // revert status to previous value, if it was set |
|
| 894 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 895 | + if ($previous_event_status) { |
|
| 896 | + $this->set_status($previous_event_status); |
|
| 897 | + $this->save(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 902 | + return $sold_out; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * This returns the total remaining spaces for sale on this event. |
|
| 909 | + * |
|
| 910 | + * @uses EE_Event::total_available_spaces() |
|
| 911 | + * @return float|int |
|
| 912 | + * @throws EE_Error |
|
| 913 | + * @throws DomainException |
|
| 914 | + * @throws UnexpectedEntityException |
|
| 915 | + */ |
|
| 916 | + public function spaces_remaining_for_sale() |
|
| 917 | + { |
|
| 918 | + return $this->total_available_spaces(true); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + |
|
| 922 | + |
|
| 923 | + /** |
|
| 924 | + * This returns the total spaces available for an event |
|
| 925 | + * while considering all the qtys on the tickets and the reg limits |
|
| 926 | + * on the datetimes attached to this event. |
|
| 927 | + * |
|
| 928 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 929 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 930 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 931 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 932 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 933 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 934 | + * sold out, the more accurate the "live" total is. |
|
| 935 | + * @return float|int |
|
| 936 | + * @throws EE_Error |
|
| 937 | + * @throws DomainException |
|
| 938 | + * @throws UnexpectedEntityException |
|
| 939 | + */ |
|
| 940 | + public function total_available_spaces($consider_sold = false) |
|
| 941 | + { |
|
| 942 | + $spaces_available = $consider_sold |
|
| 943 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 944 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 945 | + return apply_filters( |
|
| 946 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 947 | + $spaces_available, |
|
| 948 | + $this, |
|
| 949 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 950 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 951 | + ); |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * Checks if the event is set to sold out |
|
| 957 | + * |
|
| 958 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 959 | + * actual status but also to flip the status if necessary to sold |
|
| 960 | + * out If false, we just check the existing status of the event |
|
| 961 | + * @return boolean |
|
| 962 | + * @throws EE_Error |
|
| 963 | + */ |
|
| 964 | + public function is_sold_out($actual = false) |
|
| 965 | + { |
|
| 966 | + if (!$actual) { |
|
| 967 | + return $this->status() === EEM_Event::sold_out; |
|
| 968 | + } |
|
| 969 | + return $this->perform_sold_out_status_check(); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + /** |
|
| 974 | + * Checks if the event is marked as postponed |
|
| 975 | + * |
|
| 976 | + * @return boolean |
|
| 977 | + */ |
|
| 978 | + public function is_postponed() |
|
| 979 | + { |
|
| 980 | + return $this->status() === EEM_Event::postponed; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + /** |
|
| 985 | + * Checks if the event is marked as cancelled |
|
| 986 | + * |
|
| 987 | + * @return boolean |
|
| 988 | + */ |
|
| 989 | + public function is_cancelled() |
|
| 990 | + { |
|
| 991 | + return $this->status() === EEM_Event::cancelled; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 997 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 998 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 999 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1000 | + * the event is considered expired. |
|
| 1001 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a status |
|
| 1002 | + * set on the EVENT when it is not published and thus is done |
|
| 1003 | + * |
|
| 1004 | + * @param bool $reset |
|
| 1005 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1006 | + * @throws EE_Error |
|
| 1007 | + */ |
|
| 1008 | + public function get_active_status($reset = false) |
|
| 1009 | + { |
|
| 1010 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1011 | + if (!empty($this->_active_status) && !$reset) { |
|
| 1012 | + return $this->_active_status; |
|
| 1013 | + } |
|
| 1014 | + //first check if event id is present on this object |
|
| 1015 | + if (!$this->ID()) { |
|
| 1016 | + return false; |
|
| 1017 | + } |
|
| 1018 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1019 | + //if event is published: |
|
| 1020 | + if ($this->status() === 'publish') { |
|
| 1021 | + //active? |
|
| 1022 | + if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event) > 0) { |
|
| 1023 | + $this->_active_status = EE_Datetime::active; |
|
| 1024 | + } else { |
|
| 1025 | + //upcoming? |
|
| 1026 | + if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0) { |
|
| 1027 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1028 | + } else { |
|
| 1029 | + //expired? |
|
| 1030 | + if ( |
|
| 1031 | + EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0 |
|
| 1032 | + ) { |
|
| 1033 | + $this->_active_status = EE_Datetime::expired; |
|
| 1034 | + } else { |
|
| 1035 | + //it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1036 | + //attached to the event. So in this case it will just be considered inactive. |
|
| 1037 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + } else { |
|
| 1042 | + //the event is not published, so let's just set it's active status according to its' post status |
|
| 1043 | + switch ($this->status()) { |
|
| 1044 | + case EEM_Event::sold_out : |
|
| 1045 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1046 | + break; |
|
| 1047 | + case EEM_Event::cancelled : |
|
| 1048 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1049 | + break; |
|
| 1050 | + case EEM_Event::postponed : |
|
| 1051 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1052 | + break; |
|
| 1053 | + default : |
|
| 1054 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + return $this->_active_status; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * pretty_active_status |
|
| 1063 | + * |
|
| 1064 | + * @access public |
|
| 1065 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1066 | + * @return mixed void|string |
|
| 1067 | + * @throws EE_Error |
|
| 1068 | + */ |
|
| 1069 | + public function pretty_active_status($echo = true) |
|
| 1070 | + { |
|
| 1071 | + $active_status = $this->get_active_status(); |
|
| 1072 | + $status = '<span class="ee-status event-active-status-' |
|
| 1073 | + . $active_status |
|
| 1074 | + . '">' |
|
| 1075 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1076 | + . '</span>'; |
|
| 1077 | + if ($echo) { |
|
| 1078 | + echo $status; |
|
| 1079 | + return ''; |
|
| 1080 | + } |
|
| 1081 | + return $status; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * @return bool|int |
|
| 1087 | + * @throws EE_Error |
|
| 1088 | + */ |
|
| 1089 | + public function get_number_of_tickets_sold() |
|
| 1090 | + { |
|
| 1091 | + $tkt_sold = 0; |
|
| 1092 | + if (!$this->ID()) { |
|
| 1093 | + return 0; |
|
| 1094 | + } |
|
| 1095 | + $datetimes = $this->datetimes(); |
|
| 1096 | + foreach ($datetimes as $datetime) { |
|
| 1097 | + if ($datetime instanceof EE_Datetime) { |
|
| 1098 | + $tkt_sold += $datetime->sold(); |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + return $tkt_sold; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * This just returns a count of all the registrations for this event |
|
| 1107 | + * |
|
| 1108 | + * @access public |
|
| 1109 | + * @return int |
|
| 1110 | + * @throws EE_Error |
|
| 1111 | + */ |
|
| 1112 | + public function get_count_of_all_registrations() |
|
| 1113 | + { |
|
| 1114 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * This returns the ticket with the earliest start time that is |
|
| 1120 | + * available for this event (across all datetimes attached to the event) |
|
| 1121 | + * |
|
| 1122 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1123 | + * @throws EE_Error |
|
| 1124 | + */ |
|
| 1125 | + public function get_ticket_with_earliest_start_time() |
|
| 1126 | + { |
|
| 1127 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1128 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1129 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * This returns the ticket with the latest end time that is available |
|
| 1135 | + * for this event (across all datetimes attached to the event) |
|
| 1136 | + * |
|
| 1137 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + */ |
|
| 1140 | + public function get_ticket_with_latest_end_time() |
|
| 1141 | + { |
|
| 1142 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1143 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1144 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + |
|
| 1148 | + /** |
|
| 1149 | + * This returns whether there are any tickets on sale for this event. |
|
| 1150 | + * |
|
| 1151 | + * @return bool true = YES tickets on sale. |
|
| 1152 | + * @throws EE_Error |
|
| 1153 | + */ |
|
| 1154 | + public function tickets_on_sale() |
|
| 1155 | + { |
|
| 1156 | + $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
|
| 1157 | + $latest_ticket = $this->get_ticket_with_latest_end_time(); |
|
| 1158 | + if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | + return false; |
|
| 1160 | + } |
|
| 1161 | + //check on sale for these two tickets. |
|
| 1162 | + if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) { |
|
| 1163 | + return true; |
|
| 1164 | + } |
|
| 1165 | + return false; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1171 | + * to check for an external URL first |
|
| 1172 | + * |
|
| 1173 | + * @return string |
|
| 1174 | + * @throws EE_Error |
|
| 1175 | + */ |
|
| 1176 | + public function get_permalink() |
|
| 1177 | + { |
|
| 1178 | + if ($this->external_url()) { |
|
| 1179 | + return $this->external_url(); |
|
| 1180 | + } |
|
| 1181 | + return parent::get_permalink(); |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1187 | + * |
|
| 1188 | + * @param array $query_params like EEM_Base::get_all |
|
| 1189 | + * @return EE_Base_Class|EE_Term|null |
|
| 1190 | + * @throws EE_Error |
|
| 1191 | + */ |
|
| 1192 | + public function first_event_category($query_params = array()) |
|
| 1193 | + { |
|
| 1194 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1195 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1196 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + |
|
| 1200 | + /** |
|
| 1201 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1202 | + * |
|
| 1203 | + * @param array $query_params |
|
| 1204 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1205 | + * @throws EE_Error |
|
| 1206 | + */ |
|
| 1207 | + public function get_all_event_categories($query_params = array()) |
|
| 1208 | + { |
|
| 1209 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1210 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1211 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + |
|
| 1215 | + /** |
|
| 1216 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1217 | + * |
|
| 1218 | + * @param array $query_params @see EEM_Base::get_all |
|
| 1219 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1220 | + * @throws EE_Error |
|
| 1221 | + */ |
|
| 1222 | + public function question_groups($query_params = array()) |
|
| 1223 | + { |
|
| 1224 | + $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1231 | + * |
|
| 1232 | + * @see EEI_Visual_Representation for comments |
|
| 1233 | + * @return string |
|
| 1234 | + */ |
|
| 1235 | + public function get_icon() |
|
| 1236 | + { |
|
| 1237 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1238 | + } |
|
| 1239 | + |
|
| 1240 | + |
|
| 1241 | + /** |
|
| 1242 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1243 | + * |
|
| 1244 | + * @see EEI_Admin_Links for comments |
|
| 1245 | + * @return string |
|
| 1246 | + * @throws EE_Error |
|
| 1247 | + */ |
|
| 1248 | + public function get_admin_details_link() |
|
| 1249 | + { |
|
| 1250 | + return $this->get_admin_edit_link(); |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + |
|
| 1254 | + /** |
|
| 1255 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1256 | + * |
|
| 1257 | + * @see EEI_Admin_Links for comments |
|
| 1258 | + * @return string |
|
| 1259 | + * @throws EE_Error |
|
| 1260 | + */ |
|
| 1261 | + public function get_admin_edit_link() |
|
| 1262 | + { |
|
| 1263 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1264 | + 'page' => 'espresso_events', |
|
| 1265 | + 'action' => 'edit', |
|
| 1266 | + 'post' => $this->ID(), |
|
| 1267 | + ), |
|
| 1268 | + admin_url('admin.php') |
|
| 1269 | + ); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1275 | + * |
|
| 1276 | + * @see EEI_Admin_Links for comments |
|
| 1277 | + * @return string |
|
| 1278 | + */ |
|
| 1279 | + public function get_admin_settings_link() |
|
| 1280 | + { |
|
| 1281 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1282 | + 'page' => 'espresso_events', |
|
| 1283 | + 'action' => 'default_event_settings', |
|
| 1284 | + ), |
|
| 1285 | + admin_url('admin.php') |
|
| 1286 | + ); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1292 | + * |
|
| 1293 | + * @see EEI_Admin_Links for comments |
|
| 1294 | + * @return string |
|
| 1295 | + */ |
|
| 1296 | + public function get_admin_overview_link() |
|
| 1297 | + { |
|
| 1298 | + return EEH_URL::add_query_args_and_nonce(array( |
|
| 1299 | + 'page' => 'espresso_events', |
|
| 1300 | + 'action' => 'default', |
|
| 1301 | + ), |
|
| 1302 | + admin_url('admin.php') |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | 1305 | |
| 1306 | 1306 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | use EventEspresso\core\domain\services\event\EventSpacesCalculator; |
| 4 | 4 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 5 | 5 | |
| 6 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 7 | 7 | exit('No direct script access allowed'); |
| 8 | 8 | } |
| 9 | 9 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function getAvailableSpacesCalculator() |
| 77 | 77 | { |
| 78 | - if(! $this->available_spaces_calculator instanceof EventSpacesCalculator){ |
|
| 78 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 79 | 79 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
| 80 | 80 | } |
| 81 | 81 | return $this->available_spaces_calculator; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | public function set_status($new_status = null, $use_default = false) |
| 119 | 119 | { |
| 120 | 120 | // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
| 121 | - if (empty($new_status) && !$use_default) { |
|
| 121 | + if (empty($new_status) && ! $use_default) { |
|
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | 124 | // get current Event status |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
| 218 | 218 | { |
| 219 | - if (!empty ($this->_Primary_Datetime)) { |
|
| 219 | + if ( ! empty ($this->_Primary_Datetime)) { |
|
| 220 | 220 | return $this->_Primary_Datetime; |
| 221 | 221 | } |
| 222 | 222 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | { |
| 240 | 240 | //first get all datetimes |
| 241 | 241 | $datetimes = $this->datetimes_ordered(); |
| 242 | - if (!$datetimes) { |
|
| 242 | + if ( ! $datetimes) { |
|
| 243 | 243 | return array(); |
| 244 | 244 | } |
| 245 | 245 | $datetime_ids = array(); |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | */ |
| 344 | 344 | public function display_ticket_selector() |
| 345 | 345 | { |
| 346 | - return (bool)$this->get('EVT_display_ticket_selector'); |
|
| 346 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | public function default_registration_status() |
| 415 | 415 | { |
| 416 | 416 | $event_default_registration_status = $this->get('EVT_default_registration_status'); |
| 417 | - return !empty($event_default_registration_status) |
|
| 417 | + return ! empty($event_default_registration_status) |
|
| 418 | 418 | ? $event_default_registration_status |
| 419 | 419 | : EE_Registry::instance()->CFG->registration->default_STS_ID; |
| 420 | 420 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
| 431 | 431 | { |
| 432 | 432 | $short_desc = $this->get('EVT_short_desc'); |
| 433 | - if (!empty($short_desc) || $not_full_desc) { |
|
| 433 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
| 434 | 434 | return $short_desc; |
| 435 | 435 | } |
| 436 | 436 | $full_desc = $this->get('EVT_desc'); |
@@ -963,7 +963,7 @@ discard block |
||
| 963 | 963 | */ |
| 964 | 964 | public function is_sold_out($actual = false) |
| 965 | 965 | { |
| 966 | - if (!$actual) { |
|
| 966 | + if ( ! $actual) { |
|
| 967 | 967 | return $this->status() === EEM_Event::sold_out; |
| 968 | 968 | } |
| 969 | 969 | return $this->perform_sold_out_status_check(); |
@@ -1008,11 +1008,11 @@ discard block |
||
| 1008 | 1008 | public function get_active_status($reset = false) |
| 1009 | 1009 | { |
| 1010 | 1010 | // if the active status has already been set, then just use that value (unless we are resetting it) |
| 1011 | - if (!empty($this->_active_status) && !$reset) { |
|
| 1011 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
| 1012 | 1012 | return $this->_active_status; |
| 1013 | 1013 | } |
| 1014 | 1014 | //first check if event id is present on this object |
| 1015 | - if (!$this->ID()) { |
|
| 1015 | + if ( ! $this->ID()) { |
|
| 1016 | 1016 | return false; |
| 1017 | 1017 | } |
| 1018 | 1018 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | public function get_number_of_tickets_sold() |
| 1090 | 1090 | { |
| 1091 | 1091 | $tkt_sold = 0; |
| 1092 | - if (!$this->ID()) { |
|
| 1092 | + if ( ! $this->ID()) { |
|
| 1093 | 1093 | return 0; |
| 1094 | 1094 | } |
| 1095 | 1095 | $datetimes = $this->datetimes(); |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | { |
| 1156 | 1156 | $earliest_ticket = $this->get_ticket_with_earliest_start_time(); |
| 1157 | 1157 | $latest_ticket = $this->get_ticket_with_latest_end_time(); |
| 1158 | - if (!$latest_ticket instanceof EE_Ticket && !$earliest_ticket instanceof EE_Ticket) { |
|
| 1158 | + if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) { |
|
| 1159 | 1159 | return false; |
| 1160 | 1160 | } |
| 1161 | 1161 | //check on sale for these two tickets. |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | */ |
| 1222 | 1222 | public function question_groups($query_params = array()) |
| 1223 | 1223 | { |
| 1224 | - $query_params = !empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1224 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1225 | 1225 | return $this->get_many_related('Question_Group', $query_params); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | /** |
| 328 | 328 | * Get Timezone Transitions |
| 329 | 329 | * @param \DateTimeZone $date_time_zone |
| 330 | - * @param null $time |
|
| 330 | + * @param integer|null $time |
|
| 331 | 331 | * @param bool $first_only |
| 332 | 332 | * @return array|mixed |
| 333 | 333 | */ |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | /** |
| 344 | 344 | * Get Timezone Offset for given timezone object. |
| 345 | 345 | * @param \DateTimeZone $date_time_zone |
| 346 | - * @param null $time |
|
| 346 | + * @param integer|null $time |
|
| 347 | 347 | * @return mixed |
| 348 | 348 | * @throws \DomainException |
| 349 | 349 | */ |
@@ -1075,7 +1075,7 @@ discard block |
||
| 1075 | 1075 | * this method will add that "1" into your date regardless of the format. |
| 1076 | 1076 | * |
| 1077 | 1077 | * @param string $month |
| 1078 | - * @return string |
|
| 1078 | + * @return integer |
|
| 1079 | 1079 | */ |
| 1080 | 1080 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1081 | { |
@@ -1227,7 +1227,7 @@ discard block |
||
| 1227 | 1227 | /** |
| 1228 | 1228 | * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
| 1229 | 1229 | * |
| 1230 | - * @param int|WP_User $user_id |
|
| 1230 | + * @param integer $user_id |
|
| 1231 | 1231 | * @return string |
| 1232 | 1232 | */ |
| 1233 | 1233 | public static function get_user_locale($user_id = 0) |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 3 | - exit('NO direct script access allowed'); |
|
| 3 | + exit('NO direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -26,364 +26,364 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * return the timezone set for the WP install |
|
| 31 | - * |
|
| 32 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | - */ |
|
| 34 | - public static function get_timezone() |
|
| 35 | - { |
|
| 36 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * get_valid_timezone_string |
|
| 42 | - * ensures that a valid timezone string is returned |
|
| 43 | - * |
|
| 44 | - * @access protected |
|
| 45 | - * @param string $timezone_string |
|
| 46 | - * @return string |
|
| 47 | - * @throws \EE_Error |
|
| 48 | - */ |
|
| 49 | - public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | - { |
|
| 51 | - // if passed a value, then use that, else get WP option |
|
| 52 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | - // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | - EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | - return $timezone_string; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | - * |
|
| 63 | - * @static |
|
| 64 | - * @access public |
|
| 65 | - * @param string $timezone_string Timezone string to check |
|
| 66 | - * @param bool $throw_error |
|
| 67 | - * @return bool |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | - { |
|
| 72 | - // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 73 | - try { |
|
| 74 | - new DateTimeZone($timezone_string); |
|
| 75 | - } catch (Exception $e) { |
|
| 76 | - // sometimes we take exception to exceptions |
|
| 77 | - if (! $throw_error) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - throw new EE_Error( |
|
| 81 | - sprintf( |
|
| 82 | - __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | - 'event_espresso'), |
|
| 84 | - $timezone_string, |
|
| 85 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | - '</a>' |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - return true; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * _create_timezone_object_from_timezone_name |
|
| 96 | - * |
|
| 97 | - * @access protected |
|
| 98 | - * @param string $gmt_offset |
|
| 99 | - * @return string |
|
| 100 | - */ |
|
| 101 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | - { |
|
| 103 | - $timezone_string = 'UTC'; |
|
| 104 | - //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | - //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | - //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | - if ($gmt_offset === '') { |
|
| 108 | - //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | - if (get_option('timezone_string')) { |
|
| 110 | - return get_option('timezone_string'); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | - $gmt_offset = (float) $gmt_offset; |
|
| 115 | - |
|
| 116 | - //if $gmt_offset is 0, then just return UTC |
|
| 117 | - if ($gmt_offset === (float) 0) { |
|
| 118 | - return $timezone_string; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - if ($gmt_offset !== '') { |
|
| 123 | - // convert GMT offset to seconds |
|
| 124 | - $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | - // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | - $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | - //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | - try { |
|
| 129 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | - if ($offset !== $gmt_offset) { |
|
| 131 | - $timezone_string = false; |
|
| 132 | - } |
|
| 133 | - } catch (Exception $e) { |
|
| 134 | - $timezone_string = false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | - $timezone_string = $timezone_string !== false |
|
| 139 | - ? $timezone_string |
|
| 140 | - : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | - return $timezone_string; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Gets the site's GMT offset based on either the timezone string |
|
| 146 | - * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | - * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | - * |
|
| 149 | - * @return int seconds offset |
|
| 150 | - */ |
|
| 151 | - public static function get_site_timezone_gmt_offset() |
|
| 152 | - { |
|
| 153 | - $timezone_string = get_option('timezone_string'); |
|
| 154 | - if ($timezone_string) { |
|
| 155 | - try { |
|
| 156 | - $timezone = new DateTimeZone($timezone_string); |
|
| 157 | - return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | - } catch (Exception $e) { |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - $offset = get_option('gmt_offset'); |
|
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | - * timezone tables. |
|
| 169 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | - * |
|
| 171 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @param int $gmt_offset |
|
| 175 | - * @return int |
|
| 176 | - */ |
|
| 177 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | - { |
|
| 179 | - //make sure $gmt_offset is int |
|
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 181 | - switch ($gmt_offset) { |
|
| 182 | - //-12 |
|
| 183 | - case -43200: |
|
| 184 | - $gmt_offset = -39600; |
|
| 185 | - break; |
|
| 186 | - //-11.5 |
|
| 187 | - case -41400: |
|
| 188 | - $gmt_offset = -39600; |
|
| 189 | - break; |
|
| 190 | - //-10.5 |
|
| 191 | - case -37800: |
|
| 192 | - $gmt_offset = -39600; |
|
| 193 | - break; |
|
| 194 | - //-8.5 |
|
| 195 | - case -30600: |
|
| 196 | - $gmt_offset = -28800; |
|
| 197 | - break; |
|
| 198 | - //-7.5 |
|
| 199 | - case -27000: |
|
| 200 | - $gmt_offset = -25200; |
|
| 201 | - break; |
|
| 202 | - //-6.5 |
|
| 203 | - case -23400: |
|
| 204 | - $gmt_offset = -21600; |
|
| 205 | - break; |
|
| 206 | - //-5.5 |
|
| 207 | - case -19800: |
|
| 208 | - $gmt_offset = -18000; |
|
| 209 | - break; |
|
| 210 | - //-4.5 |
|
| 211 | - case -16200: |
|
| 212 | - $gmt_offset = -14400; |
|
| 213 | - break; |
|
| 214 | - //-3.5 |
|
| 215 | - case -12600: |
|
| 216 | - $gmt_offset = -10800; |
|
| 217 | - break; |
|
| 218 | - //-2.5 |
|
| 219 | - case -9000: |
|
| 220 | - $gmt_offset = -7200; |
|
| 221 | - break; |
|
| 222 | - //-1.5 |
|
| 223 | - case -5400: |
|
| 224 | - $gmt_offset = -3600; |
|
| 225 | - break; |
|
| 226 | - //-0.5 |
|
| 227 | - case -1800: |
|
| 228 | - $gmt_offset = 0; |
|
| 229 | - break; |
|
| 230 | - //.5 |
|
| 231 | - case 1800: |
|
| 232 | - $gmt_offset = 3600; |
|
| 233 | - break; |
|
| 234 | - //1.5 |
|
| 235 | - case 5400: |
|
| 236 | - $gmt_offset = 7200; |
|
| 237 | - break; |
|
| 238 | - //2.5 |
|
| 239 | - case 9000: |
|
| 240 | - $gmt_offset = 10800; |
|
| 241 | - break; |
|
| 242 | - //3.5 |
|
| 243 | - case 12600: |
|
| 244 | - $gmt_offset = 14400; |
|
| 245 | - break; |
|
| 246 | - |
|
| 247 | - //7.5 |
|
| 248 | - case 27000: |
|
| 249 | - $gmt_offset = 28800; |
|
| 250 | - break; |
|
| 251 | - //8.5 |
|
| 252 | - case 30600: |
|
| 253 | - $gmt_offset = 31500; |
|
| 254 | - break; |
|
| 255 | - //10.5 |
|
| 256 | - case 37800: |
|
| 257 | - $gmt_offset = 39600; |
|
| 258 | - break; |
|
| 259 | - //11.5 |
|
| 260 | - case 41400: |
|
| 261 | - $gmt_offset = 43200; |
|
| 262 | - break; |
|
| 263 | - //12.75 |
|
| 264 | - case 45900: |
|
| 265 | - $gmt_offset = 46800; |
|
| 266 | - break; |
|
| 267 | - //13.75 |
|
| 268 | - case 49500: |
|
| 269 | - $gmt_offset = 50400; |
|
| 270 | - break; |
|
| 271 | - } |
|
| 272 | - return $gmt_offset; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * get_timezone_string_from_abbreviations_list |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @param int $gmt_offset |
|
| 281 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | - * @return string |
|
| 283 | - * @throws \EE_Error |
|
| 284 | - */ |
|
| 285 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | - { |
|
| 287 | - $abbreviations = timezone_abbreviations_list(); |
|
| 288 | - foreach ($abbreviations as $abbreviation) { |
|
| 289 | - foreach ($abbreviation as $city) { |
|
| 290 | - if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | - try { |
|
| 292 | - $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | - if ($offset !== $gmt_offset) { |
|
| 294 | - continue; |
|
| 295 | - } else { |
|
| 296 | - return $city['timezone_id']; |
|
| 297 | - } |
|
| 298 | - } catch (Exception $e) { |
|
| 299 | - continue; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | - if ($coerce == true) { |
|
| 306 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | - false |
|
| 309 | - ); |
|
| 310 | - if ($timezone_string) { |
|
| 311 | - return $timezone_string; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - throw new EE_Error( |
|
| 315 | - sprintf( |
|
| 316 | - __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | - 'event_espresso'), |
|
| 318 | - $gmt_offset, |
|
| 319 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | - '</a>' |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Get Timezone Transitions |
|
| 329 | - * @param \DateTimeZone $date_time_zone |
|
| 330 | - * @param null $time |
|
| 331 | - * @param bool $first_only |
|
| 332 | - * @return array|mixed |
|
| 333 | - */ |
|
| 334 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | - { |
|
| 336 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | - $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get Timezone Offset for given timezone object. |
|
| 345 | - * @param \DateTimeZone $date_time_zone |
|
| 346 | - * @param null $time |
|
| 347 | - * @return mixed |
|
| 348 | - * @throws \DomainException |
|
| 349 | - */ |
|
| 350 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | - { |
|
| 352 | - $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | - if (! isset($transitions['offset'])) { |
|
| 354 | - throw new DomainException(); |
|
| 355 | - } |
|
| 356 | - return $transitions['offset']; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @access public |
|
| 362 | - * @param string $timezone_string |
|
| 363 | - */ |
|
| 364 | - public static function timezone_select_input($timezone_string = '') |
|
| 365 | - { |
|
| 366 | - // get WP date time format |
|
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | - // if passed a value, then use that, else get WP option |
|
| 369 | - $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | - // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | - $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | - $gmt_offset = get_option('gmt_offset'); |
|
| 373 | - |
|
| 374 | - $check_zone_info = true; |
|
| 375 | - if (empty($timezone_string)) { |
|
| 376 | - // Create a UTC+- zone if no timezone string exists |
|
| 377 | - $check_zone_info = false; |
|
| 378 | - if ($gmt_offset > 0) { |
|
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | - } elseif ($gmt_offset < 0) { |
|
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | - } else { |
|
| 383 | - $timezone_string = 'UTC'; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - ?> |
|
| 29 | + /** |
|
| 30 | + * return the timezone set for the WP install |
|
| 31 | + * |
|
| 32 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
| 33 | + */ |
|
| 34 | + public static function get_timezone() |
|
| 35 | + { |
|
| 36 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * get_valid_timezone_string |
|
| 42 | + * ensures that a valid timezone string is returned |
|
| 43 | + * |
|
| 44 | + * @access protected |
|
| 45 | + * @param string $timezone_string |
|
| 46 | + * @return string |
|
| 47 | + * @throws \EE_Error |
|
| 48 | + */ |
|
| 49 | + public static function get_valid_timezone_string($timezone_string = '') |
|
| 50 | + { |
|
| 51 | + // if passed a value, then use that, else get WP option |
|
| 52 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 53 | + // value from above exists, use that, else get timezone string from gmt_offset |
|
| 54 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : EEH_DTT_Helper::get_timezone_string_from_gmt_offset(); |
|
| 55 | + EEH_DTT_Helper::validate_timezone($timezone_string); |
|
| 56 | + return $timezone_string; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
| 62 | + * |
|
| 63 | + * @static |
|
| 64 | + * @access public |
|
| 65 | + * @param string $timezone_string Timezone string to check |
|
| 66 | + * @param bool $throw_error |
|
| 67 | + * @return bool |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
| 71 | + { |
|
| 72 | + // easiest way to test a timezone string is just see if it throws an error when you try to create a DateTimeZone object with it |
|
| 73 | + try { |
|
| 74 | + new DateTimeZone($timezone_string); |
|
| 75 | + } catch (Exception $e) { |
|
| 76 | + // sometimes we take exception to exceptions |
|
| 77 | + if (! $throw_error) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + throw new EE_Error( |
|
| 81 | + sprintf( |
|
| 82 | + __('The timezone given (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 83 | + 'event_espresso'), |
|
| 84 | + $timezone_string, |
|
| 85 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 86 | + '</a>' |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + return true; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * _create_timezone_object_from_timezone_name |
|
| 96 | + * |
|
| 97 | + * @access protected |
|
| 98 | + * @param string $gmt_offset |
|
| 99 | + * @return string |
|
| 100 | + */ |
|
| 101 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
| 102 | + { |
|
| 103 | + $timezone_string = 'UTC'; |
|
| 104 | + //if there is no incoming gmt_offset, then because WP hooks in on timezone_string, we need to see if that is |
|
| 105 | + //set because it will override `gmt_offset` via `pre_get_option` filter. If that's set, then let's just use |
|
| 106 | + //that! Otherwise we'll leave timezone_string at the default of 'UTC' before doing other logic. |
|
| 107 | + if ($gmt_offset === '') { |
|
| 108 | + //autoloaded so no need to set to a variable. There will not be multiple hits to the db. |
|
| 109 | + if (get_option('timezone_string')) { |
|
| 110 | + return get_option('timezone_string'); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $gmt_offset = $gmt_offset !== '' ? $gmt_offset : get_option('gmt_offset'); |
|
| 114 | + $gmt_offset = (float) $gmt_offset; |
|
| 115 | + |
|
| 116 | + //if $gmt_offset is 0, then just return UTC |
|
| 117 | + if ($gmt_offset === (float) 0) { |
|
| 118 | + return $timezone_string; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + if ($gmt_offset !== '') { |
|
| 123 | + // convert GMT offset to seconds |
|
| 124 | + $gmt_offset = $gmt_offset * HOUR_IN_SECONDS; |
|
| 125 | + // although we don't know the TZ abbreviation, we know the UTC offset |
|
| 126 | + $timezone_string = timezone_name_from_abbr(null, $gmt_offset); |
|
| 127 | + //only use this timezone_string IF it's current offset matches the given offset |
|
| 128 | + try { |
|
| 129 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone_string)); |
|
| 130 | + if ($offset !== $gmt_offset) { |
|
| 131 | + $timezone_string = false; |
|
| 132 | + } |
|
| 133 | + } catch (Exception $e) { |
|
| 134 | + $timezone_string = false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + // better have a valid timezone string by now, but if not, sigh... loop thru the timezone_abbreviations_list()... |
|
| 138 | + $timezone_string = $timezone_string !== false |
|
| 139 | + ? $timezone_string |
|
| 140 | + : EEH_DTT_Helper::get_timezone_string_from_abbreviations_list($gmt_offset); |
|
| 141 | + return $timezone_string; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Gets the site's GMT offset based on either the timezone string |
|
| 146 | + * (in which case teh gmt offset will vary depending on the location's |
|
| 147 | + * observance of daylight savings time) or the gmt_offset wp option |
|
| 148 | + * |
|
| 149 | + * @return int seconds offset |
|
| 150 | + */ |
|
| 151 | + public static function get_site_timezone_gmt_offset() |
|
| 152 | + { |
|
| 153 | + $timezone_string = get_option('timezone_string'); |
|
| 154 | + if ($timezone_string) { |
|
| 155 | + try { |
|
| 156 | + $timezone = new DateTimeZone($timezone_string); |
|
| 157 | + return $timezone->getOffset(new DateTime()); //in WordPress DateTime defaults to UTC |
|
| 158 | + } catch (Exception $e) { |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + $offset = get_option('gmt_offset'); |
|
| 162 | + return (int)($offset * HOUR_IN_SECONDS); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Depending on PHP version, there might not bevalid current timezone strings to match these gmt_offsets in its |
|
| 168 | + * timezone tables. |
|
| 169 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
| 170 | + * |
|
| 171 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @param int $gmt_offset |
|
| 175 | + * @return int |
|
| 176 | + */ |
|
| 177 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
| 178 | + { |
|
| 179 | + //make sure $gmt_offset is int |
|
| 180 | + $gmt_offset = (int)$gmt_offset; |
|
| 181 | + switch ($gmt_offset) { |
|
| 182 | + //-12 |
|
| 183 | + case -43200: |
|
| 184 | + $gmt_offset = -39600; |
|
| 185 | + break; |
|
| 186 | + //-11.5 |
|
| 187 | + case -41400: |
|
| 188 | + $gmt_offset = -39600; |
|
| 189 | + break; |
|
| 190 | + //-10.5 |
|
| 191 | + case -37800: |
|
| 192 | + $gmt_offset = -39600; |
|
| 193 | + break; |
|
| 194 | + //-8.5 |
|
| 195 | + case -30600: |
|
| 196 | + $gmt_offset = -28800; |
|
| 197 | + break; |
|
| 198 | + //-7.5 |
|
| 199 | + case -27000: |
|
| 200 | + $gmt_offset = -25200; |
|
| 201 | + break; |
|
| 202 | + //-6.5 |
|
| 203 | + case -23400: |
|
| 204 | + $gmt_offset = -21600; |
|
| 205 | + break; |
|
| 206 | + //-5.5 |
|
| 207 | + case -19800: |
|
| 208 | + $gmt_offset = -18000; |
|
| 209 | + break; |
|
| 210 | + //-4.5 |
|
| 211 | + case -16200: |
|
| 212 | + $gmt_offset = -14400; |
|
| 213 | + break; |
|
| 214 | + //-3.5 |
|
| 215 | + case -12600: |
|
| 216 | + $gmt_offset = -10800; |
|
| 217 | + break; |
|
| 218 | + //-2.5 |
|
| 219 | + case -9000: |
|
| 220 | + $gmt_offset = -7200; |
|
| 221 | + break; |
|
| 222 | + //-1.5 |
|
| 223 | + case -5400: |
|
| 224 | + $gmt_offset = -3600; |
|
| 225 | + break; |
|
| 226 | + //-0.5 |
|
| 227 | + case -1800: |
|
| 228 | + $gmt_offset = 0; |
|
| 229 | + break; |
|
| 230 | + //.5 |
|
| 231 | + case 1800: |
|
| 232 | + $gmt_offset = 3600; |
|
| 233 | + break; |
|
| 234 | + //1.5 |
|
| 235 | + case 5400: |
|
| 236 | + $gmt_offset = 7200; |
|
| 237 | + break; |
|
| 238 | + //2.5 |
|
| 239 | + case 9000: |
|
| 240 | + $gmt_offset = 10800; |
|
| 241 | + break; |
|
| 242 | + //3.5 |
|
| 243 | + case 12600: |
|
| 244 | + $gmt_offset = 14400; |
|
| 245 | + break; |
|
| 246 | + |
|
| 247 | + //7.5 |
|
| 248 | + case 27000: |
|
| 249 | + $gmt_offset = 28800; |
|
| 250 | + break; |
|
| 251 | + //8.5 |
|
| 252 | + case 30600: |
|
| 253 | + $gmt_offset = 31500; |
|
| 254 | + break; |
|
| 255 | + //10.5 |
|
| 256 | + case 37800: |
|
| 257 | + $gmt_offset = 39600; |
|
| 258 | + break; |
|
| 259 | + //11.5 |
|
| 260 | + case 41400: |
|
| 261 | + $gmt_offset = 43200; |
|
| 262 | + break; |
|
| 263 | + //12.75 |
|
| 264 | + case 45900: |
|
| 265 | + $gmt_offset = 46800; |
|
| 266 | + break; |
|
| 267 | + //13.75 |
|
| 268 | + case 49500: |
|
| 269 | + $gmt_offset = 50400; |
|
| 270 | + break; |
|
| 271 | + } |
|
| 272 | + return $gmt_offset; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * get_timezone_string_from_abbreviations_list |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @param int $gmt_offset |
|
| 281 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
| 282 | + * @return string |
|
| 283 | + * @throws \EE_Error |
|
| 284 | + */ |
|
| 285 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
| 286 | + { |
|
| 287 | + $abbreviations = timezone_abbreviations_list(); |
|
| 288 | + foreach ($abbreviations as $abbreviation) { |
|
| 289 | + foreach ($abbreviation as $city) { |
|
| 290 | + if ($city['offset'] === $gmt_offset && $city['dst'] === false) { |
|
| 291 | + try { |
|
| 292 | + $offset = self::get_timezone_offset(new DateTimeZone($city['timezone_id'])); |
|
| 293 | + if ($offset !== $gmt_offset) { |
|
| 294 | + continue; |
|
| 295 | + } else { |
|
| 296 | + return $city['timezone_id']; |
|
| 297 | + } |
|
| 298 | + } catch (Exception $e) { |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
| 305 | + if ($coerce == true) { |
|
| 306 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
| 307 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
| 308 | + false |
|
| 309 | + ); |
|
| 310 | + if ($timezone_string) { |
|
| 311 | + return $timezone_string; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + throw new EE_Error( |
|
| 315 | + sprintf( |
|
| 316 | + __('The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
| 317 | + 'event_espresso'), |
|
| 318 | + $gmt_offset, |
|
| 319 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
| 320 | + '</a>' |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Get Timezone Transitions |
|
| 329 | + * @param \DateTimeZone $date_time_zone |
|
| 330 | + * @param null $time |
|
| 331 | + * @param bool $first_only |
|
| 332 | + * @return array|mixed |
|
| 333 | + */ |
|
| 334 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
| 335 | + { |
|
| 336 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 337 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 338 | + $transitions = $date_time_zone->getTransitions($time); |
|
| 339 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get Timezone Offset for given timezone object. |
|
| 345 | + * @param \DateTimeZone $date_time_zone |
|
| 346 | + * @param null $time |
|
| 347 | + * @return mixed |
|
| 348 | + * @throws \DomainException |
|
| 349 | + */ |
|
| 350 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
| 351 | + { |
|
| 352 | + $transitions = self::get_timezone_transitions($date_time_zone, $time); |
|
| 353 | + if (! isset($transitions['offset'])) { |
|
| 354 | + throw new DomainException(); |
|
| 355 | + } |
|
| 356 | + return $transitions['offset']; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @access public |
|
| 362 | + * @param string $timezone_string |
|
| 363 | + */ |
|
| 364 | + public static function timezone_select_input($timezone_string = '') |
|
| 365 | + { |
|
| 366 | + // get WP date time format |
|
| 367 | + $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 368 | + // if passed a value, then use that, else get WP option |
|
| 369 | + $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
|
| 370 | + // check if the timezone is valid but don't throw any errors if it isn't |
|
| 371 | + $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); |
|
| 372 | + $gmt_offset = get_option('gmt_offset'); |
|
| 373 | + |
|
| 374 | + $check_zone_info = true; |
|
| 375 | + if (empty($timezone_string)) { |
|
| 376 | + // Create a UTC+- zone if no timezone string exists |
|
| 377 | + $check_zone_info = false; |
|
| 378 | + if ($gmt_offset > 0) { |
|
| 379 | + $timezone_string = 'UTC+' . $gmt_offset; |
|
| 380 | + } elseif ($gmt_offset < 0) { |
|
| 381 | + $timezone_string = 'UTC' . $gmt_offset; |
|
| 382 | + } else { |
|
| 383 | + $timezone_string = 'UTC'; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + ?> |
|
| 387 | 387 | |
| 388 | 388 | <p> |
| 389 | 389 | <label for="timezone_string"><?php _e('timezone'); ?></label> |
@@ -396,13 +396,13 @@ discard block |
||
| 396 | 396 | |
| 397 | 397 | <p> |
| 398 | 398 | <span><?php |
| 399 | - printf( |
|
| 400 | - __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | - '<abbr title="Coordinated Universal Time">', |
|
| 402 | - '</abbr>', |
|
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | - ); |
|
| 405 | - ?></span> |
|
| 399 | + printf( |
|
| 400 | + __('%1$sUTC%2$s time is %3$s'), |
|
| 401 | + '<abbr title="Coordinated Universal Time">', |
|
| 402 | + '</abbr>', |
|
| 403 | + '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 404 | + ); |
|
| 405 | + ?></span> |
|
| 406 | 406 | <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
| 407 | 407 | <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
| 408 | 408 | <?php endif; ?> |
@@ -411,693 +411,693 @@ discard block |
||
| 411 | 411 | <br/> |
| 412 | 412 | <span> |
| 413 | 413 | <?php |
| 414 | - // Set TZ so localtime works. |
|
| 415 | - date_default_timezone_set($timezone_string); |
|
| 416 | - $now = localtime(time(), true); |
|
| 417 | - if ($now['tm_isdst']) { |
|
| 418 | - _e('This timezone is currently in daylight saving time.'); |
|
| 419 | - } else { |
|
| 420 | - _e('This timezone is currently in standard time.'); |
|
| 421 | - } |
|
| 422 | - ?> |
|
| 414 | + // Set TZ so localtime works. |
|
| 415 | + date_default_timezone_set($timezone_string); |
|
| 416 | + $now = localtime(time(), true); |
|
| 417 | + if ($now['tm_isdst']) { |
|
| 418 | + _e('This timezone is currently in daylight saving time.'); |
|
| 419 | + } else { |
|
| 420 | + _e('This timezone is currently in standard time.'); |
|
| 421 | + } |
|
| 422 | + ?> |
|
| 423 | 423 | <br/> |
| 424 | 424 | <?php |
| 425 | - if (function_exists('timezone_transitions_get')) { |
|
| 426 | - $found = false; |
|
| 427 | - $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | - $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | - $right_now = time(); |
|
| 430 | - $tr['isdst'] = false; |
|
| 431 | - foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | - if ($tr['ts'] > $right_now) { |
|
| 433 | - $found = true; |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - if ($found) { |
|
| 439 | - $message = $tr['isdst'] ? |
|
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 442 | - // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | - printf($message, |
|
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | - } else { |
|
| 446 | - _e('This timezone does not observe daylight saving time.'); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - // Set back to UTC. |
|
| 450 | - date_default_timezone_set('UTC'); |
|
| 451 | - ?> |
|
| 425 | + if (function_exists('timezone_transitions_get')) { |
|
| 426 | + $found = false; |
|
| 427 | + $date_time_zone_selected = new DateTimeZone($timezone_string); |
|
| 428 | + $tz_offset = timezone_offset_get($date_time_zone_selected, date_create()); |
|
| 429 | + $right_now = time(); |
|
| 430 | + $tr['isdst'] = false; |
|
| 431 | + foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { |
|
| 432 | + if ($tr['ts'] > $right_now) { |
|
| 433 | + $found = true; |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + if ($found) { |
|
| 439 | + $message = $tr['isdst'] ? |
|
| 440 | + __(' Daylight saving time begins on: %s.') : |
|
| 441 | + __(' Standard time begins on: %s.'); |
|
| 442 | + // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
|
| 443 | + printf($message, |
|
| 444 | + '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 445 | + } else { |
|
| 446 | + _e('This timezone does not observe daylight saving time.'); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + // Set back to UTC. |
|
| 450 | + date_default_timezone_set('UTC'); |
|
| 451 | + ?> |
|
| 452 | 452 | </span></p> |
| 453 | 453 | <?php |
| 454 | - endif; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | - * the site is used. |
|
| 462 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | - * computed timestamp (i.e. date_i18n() ) |
|
| 464 | - * |
|
| 465 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | - * site will be used. |
|
| 468 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | - */ |
|
| 470 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | - { |
|
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | - $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | - $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | - |
|
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | - $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * _set_date_time_field |
|
| 484 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | - * |
|
| 486 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | - * @param DateTime $DateTime PHP DateTime object |
|
| 488 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | - * @return EE_Base_Class |
|
| 490 | - */ |
|
| 491 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | - { |
|
| 493 | - // grab current datetime format |
|
| 494 | - $current_format = $obj->get_format(); |
|
| 495 | - // set new full timestamp format |
|
| 496 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | - // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | - // reset datetime formats |
|
| 501 | - $obj->set_date_format($current_format[0]); |
|
| 502 | - $obj->set_time_format($current_format[1]); |
|
| 503 | - return $obj; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * date_time_add |
|
| 509 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | - * |
|
| 512 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | - * minutes, seconds) defaults to years |
|
| 516 | - * @param integer $value what you want to increment the time by |
|
| 517 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | - * (chaining) |
|
| 519 | - */ |
|
| 520 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | - { |
|
| 522 | - //get the raw UTC date. |
|
| 523 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * date_time_subtract |
|
| 531 | - * same as date_time_add except subtracting value instead of adding. |
|
| 532 | - * |
|
| 533 | - * @param \EE_Base_Class $obj |
|
| 534 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | - * @param string $period |
|
| 536 | - * @param int $value |
|
| 537 | - * @return \EE_Base_Class |
|
| 538 | - */ |
|
| 539 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | - { |
|
| 541 | - //get the raw UTC date |
|
| 542 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | - * |
|
| 551 | - * @param DateTime $DateTime DateTime object |
|
| 552 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | - * @param integer $value What you want to increment the date by |
|
| 555 | - * @param string $operand What operand you wish to use for the calculation |
|
| 556 | - * @return \DateTime return whatever type came in. |
|
| 557 | - * @throws \EE_Error |
|
| 558 | - */ |
|
| 559 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | - { |
|
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 562 | - throw new EE_Error( |
|
| 563 | - sprintf( |
|
| 564 | - __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | - print_r($DateTime, true) |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - } |
|
| 569 | - switch ($period) { |
|
| 570 | - case 'years' : |
|
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 572 | - break; |
|
| 573 | - case 'months' : |
|
| 574 | - $value = 'P' . $value . 'M'; |
|
| 575 | - break; |
|
| 576 | - case 'weeks' : |
|
| 577 | - $value = 'P' . $value . 'W'; |
|
| 578 | - break; |
|
| 579 | - case 'days' : |
|
| 580 | - $value = 'P' . $value . 'D'; |
|
| 581 | - break; |
|
| 582 | - case 'hours' : |
|
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 584 | - break; |
|
| 585 | - case 'minutes' : |
|
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 587 | - break; |
|
| 588 | - case 'seconds' : |
|
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 590 | - break; |
|
| 591 | - } |
|
| 592 | - switch ($operand) { |
|
| 593 | - case '+': |
|
| 594 | - $DateTime->add(new DateInterval($value)); |
|
| 595 | - break; |
|
| 596 | - case '-': |
|
| 597 | - $DateTime->sub(new DateInterval($value)); |
|
| 598 | - break; |
|
| 599 | - } |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | - * |
|
| 607 | - * @param int $timestamp Unix timestamp |
|
| 608 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | - * @param integer $value What you want to increment the date by |
|
| 611 | - * @param string $operand What operand you wish to use for the calculation |
|
| 612 | - * @return \DateTime return whatever type came in. |
|
| 613 | - * @throws \EE_Error |
|
| 614 | - */ |
|
| 615 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | - { |
|
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | - throw new EE_Error( |
|
| 619 | - sprintf( |
|
| 620 | - __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | - print_r($timestamp, true) |
|
| 622 | - ) |
|
| 623 | - ); |
|
| 624 | - } |
|
| 625 | - switch ($period) { |
|
| 626 | - case 'years' : |
|
| 627 | - $value = YEAR_IN_SECONDS * $value; |
|
| 628 | - break; |
|
| 629 | - case 'months' : |
|
| 630 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | - break; |
|
| 632 | - case 'weeks' : |
|
| 633 | - $value = WEEK_IN_SECONDS * $value; |
|
| 634 | - break; |
|
| 635 | - case 'days' : |
|
| 636 | - $value = DAY_IN_SECONDS * $value; |
|
| 637 | - break; |
|
| 638 | - case 'hours' : |
|
| 639 | - $value = HOUR_IN_SECONDS * $value; |
|
| 640 | - break; |
|
| 641 | - case 'minutes' : |
|
| 642 | - $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | - break; |
|
| 644 | - } |
|
| 645 | - switch ($operand) { |
|
| 646 | - case '+': |
|
| 647 | - $timestamp += $value; |
|
| 648 | - break; |
|
| 649 | - case '-': |
|
| 650 | - $timestamp -= $value; |
|
| 651 | - break; |
|
| 652 | - } |
|
| 653 | - return $timestamp; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | - * parameters and returns the new timestamp or DateTime. |
|
| 660 | - * |
|
| 661 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | - * @param string $period a value to indicate what interval is being used in the |
|
| 663 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | - * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | - * @param integer $value What you want to increment the date by |
|
| 666 | - * @param string $operand What operand you wish to use for the calculation |
|
| 667 | - * @return mixed string|DateTime return whatever type came in. |
|
| 668 | - */ |
|
| 669 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | - { |
|
| 671 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | - return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | - } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | - return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | - } else { |
|
| 676 | - //error |
|
| 677 | - return $DateTime_or_timestamp; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | - * and spit out the js and moment.js equivalent formats. |
|
| 685 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | - * time picker. |
|
| 688 | - * |
|
| 689 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | - * @param null $date_format_string |
|
| 691 | - * @param null $time_format_string |
|
| 692 | - * @return array |
|
| 693 | - * array( |
|
| 694 | - * 'js' => array ( |
|
| 695 | - * 'date' => //date format |
|
| 696 | - * 'time' => //time format |
|
| 697 | - * ), |
|
| 698 | - * 'moment' => //date and time format. |
|
| 699 | - * ) |
|
| 700 | - */ |
|
| 701 | - public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | - $date_format_string = null, |
|
| 703 | - $time_format_string = null |
|
| 704 | - ) { |
|
| 705 | - if ($date_format_string === null) { |
|
| 706 | - $date_format_string = get_option('date_format'); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if ($time_format_string === null) { |
|
| 710 | - $time_format_string = get_option('time_format'); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | - |
|
| 716 | - return array( |
|
| 717 | - 'js' => array( |
|
| 718 | - 'date' => $date_format['js'], |
|
| 719 | - 'time' => $time_format['js'], |
|
| 720 | - ), |
|
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | - ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * This converts incoming format string into js and moment variations. |
|
| 728 | - * |
|
| 729 | - * @param string $format_string incoming php format string |
|
| 730 | - * @return array js and moment formats. |
|
| 731 | - */ |
|
| 732 | - protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | - { |
|
| 734 | - /** |
|
| 735 | - * This is a map of symbols for formats. |
|
| 736 | - * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | - * |
|
| 738 | - * @var array |
|
| 739 | - */ |
|
| 740 | - $symbols_map = array( |
|
| 741 | - // Day |
|
| 742 | - //01 |
|
| 743 | - 'd' => array( |
|
| 744 | - 'js' => 'dd', |
|
| 745 | - 'moment' => 'DD', |
|
| 746 | - ), |
|
| 747 | - //Mon |
|
| 748 | - 'D' => array( |
|
| 749 | - 'js' => 'D', |
|
| 750 | - 'moment' => 'ddd', |
|
| 751 | - ), |
|
| 752 | - //1,2,...31 |
|
| 753 | - 'j' => array( |
|
| 754 | - 'js' => 'd', |
|
| 755 | - 'moment' => 'D', |
|
| 756 | - ), |
|
| 757 | - //Monday |
|
| 758 | - 'l' => array( |
|
| 759 | - 'js' => 'DD', |
|
| 760 | - 'moment' => 'dddd', |
|
| 761 | - ), |
|
| 762 | - //ISO numeric representation of the day of the week (1-6) |
|
| 763 | - 'N' => array( |
|
| 764 | - 'js' => '', |
|
| 765 | - 'moment' => 'E', |
|
| 766 | - ), |
|
| 767 | - //st,nd.rd |
|
| 768 | - 'S' => array( |
|
| 769 | - 'js' => '', |
|
| 770 | - 'moment' => 'o', |
|
| 771 | - ), |
|
| 772 | - //numeric representation of day of week (0-6) |
|
| 773 | - 'w' => array( |
|
| 774 | - 'js' => '', |
|
| 775 | - 'moment' => 'd', |
|
| 776 | - ), |
|
| 777 | - //day of year starting from 0 (0-365) |
|
| 778 | - 'z' => array( |
|
| 779 | - 'js' => 'o', |
|
| 780 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | - ), |
|
| 782 | - // Week |
|
| 783 | - //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | - 'W' => array( |
|
| 785 | - 'js' => '', |
|
| 786 | - 'moment' => 'w', |
|
| 787 | - ), |
|
| 788 | - // Month |
|
| 789 | - // January...December |
|
| 790 | - 'F' => array( |
|
| 791 | - 'js' => 'MM', |
|
| 792 | - 'moment' => 'MMMM', |
|
| 793 | - ), |
|
| 794 | - //01...12 |
|
| 795 | - 'm' => array( |
|
| 796 | - 'js' => 'mm', |
|
| 797 | - 'moment' => 'MM', |
|
| 798 | - ), |
|
| 799 | - //Jan...Dec |
|
| 800 | - 'M' => array( |
|
| 801 | - 'js' => 'M', |
|
| 802 | - 'moment' => 'MMM', |
|
| 803 | - ), |
|
| 804 | - //1-12 |
|
| 805 | - 'n' => array( |
|
| 806 | - 'js' => 'm', |
|
| 807 | - 'moment' => 'M', |
|
| 808 | - ), |
|
| 809 | - //number of days in given month |
|
| 810 | - 't' => array( |
|
| 811 | - 'js' => '', |
|
| 812 | - 'moment' => '', |
|
| 813 | - ), |
|
| 814 | - // Year |
|
| 815 | - //whether leap year or not 1/0 |
|
| 816 | - 'L' => array( |
|
| 817 | - 'js' => '', |
|
| 818 | - 'moment' => '', |
|
| 819 | - ), |
|
| 820 | - //ISO-8601 year number |
|
| 821 | - 'o' => array( |
|
| 822 | - 'js' => '', |
|
| 823 | - 'moment' => 'GGGG', |
|
| 824 | - ), |
|
| 825 | - //1999...2003 |
|
| 826 | - 'Y' => array( |
|
| 827 | - 'js' => 'yy', |
|
| 828 | - 'moment' => 'YYYY', |
|
| 829 | - ), |
|
| 830 | - //99...03 |
|
| 831 | - 'y' => array( |
|
| 832 | - 'js' => 'y', |
|
| 833 | - 'moment' => 'YY', |
|
| 834 | - ), |
|
| 835 | - // Time |
|
| 836 | - // am/pm |
|
| 837 | - 'a' => array( |
|
| 838 | - 'js' => 'tt', |
|
| 839 | - 'moment' => 'a', |
|
| 840 | - ), |
|
| 841 | - // AM/PM |
|
| 842 | - 'A' => array( |
|
| 843 | - 'js' => 'TT', |
|
| 844 | - 'moment' => 'A', |
|
| 845 | - ), |
|
| 846 | - // Swatch Internet Time?!? |
|
| 847 | - 'B' => array( |
|
| 848 | - 'js' => '', |
|
| 849 | - 'moment' => '', |
|
| 850 | - ), |
|
| 851 | - //1...12 |
|
| 852 | - 'g' => array( |
|
| 853 | - 'js' => 'h', |
|
| 854 | - 'moment' => 'h', |
|
| 855 | - ), |
|
| 856 | - //0...23 |
|
| 857 | - 'G' => array( |
|
| 858 | - 'js' => 'H', |
|
| 859 | - 'moment' => 'H', |
|
| 860 | - ), |
|
| 861 | - //01...12 |
|
| 862 | - 'h' => array( |
|
| 863 | - 'js' => 'hh', |
|
| 864 | - 'moment' => 'hh', |
|
| 865 | - ), |
|
| 866 | - //00...23 |
|
| 867 | - 'H' => array( |
|
| 868 | - 'js' => 'HH', |
|
| 869 | - 'moment' => 'HH', |
|
| 870 | - ), |
|
| 871 | - //00..59 |
|
| 872 | - 'i' => array( |
|
| 873 | - 'js' => 'mm', |
|
| 874 | - 'moment' => 'mm', |
|
| 875 | - ), |
|
| 876 | - //seconds... 00...59 |
|
| 877 | - 's' => array( |
|
| 878 | - 'js' => 'ss', |
|
| 879 | - 'moment' => 'ss', |
|
| 880 | - ), |
|
| 881 | - //microseconds |
|
| 882 | - 'u' => array( |
|
| 883 | - 'js' => '', |
|
| 884 | - 'moment' => '', |
|
| 885 | - ), |
|
| 886 | - ); |
|
| 887 | - $jquery_ui_format = ""; |
|
| 888 | - $moment_format = ""; |
|
| 889 | - $escaping = false; |
|
| 890 | - for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | - $char = $format_string[$i]; |
|
| 892 | - if ($char === '\\') { // PHP date format escaping character |
|
| 893 | - $i++; |
|
| 894 | - if ($escaping) { |
|
| 895 | - $jquery_ui_format .= $format_string[$i]; |
|
| 896 | - $moment_format .= $format_string[$i]; |
|
| 897 | - } else { |
|
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | - $moment_format .= $format_string[$i]; |
|
| 900 | - } |
|
| 901 | - $escaping = true; |
|
| 902 | - } else { |
|
| 903 | - if ($escaping) { |
|
| 904 | - $jquery_ui_format .= "'"; |
|
| 905 | - $moment_format .= "'"; |
|
| 906 | - $escaping = false; |
|
| 907 | - } |
|
| 908 | - if (isset($symbols_map[$char])) { |
|
| 909 | - $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | - $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | - } else { |
|
| 912 | - $jquery_ui_format .= $char; |
|
| 913 | - $moment_format .= $char; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - } |
|
| 917 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | - * |
|
| 924 | - * @param string $format_string Incoming format string for php date(). |
|
| 925 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | - * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | - * indicate failed validations. |
|
| 928 | - */ |
|
| 929 | - public static function validate_format_string($format_string) |
|
| 930 | - { |
|
| 931 | - $error_msg = array(); |
|
| 932 | - //time format checks |
|
| 933 | - switch (true) { |
|
| 934 | - case strpos($format_string, 'h') !== false : |
|
| 935 | - case strpos($format_string, 'g') !== false : |
|
| 936 | - /** |
|
| 937 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | - */ |
|
| 941 | - if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | - $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 943 | - 'event_espresso'); |
|
| 944 | - } |
|
| 945 | - break; |
|
| 946 | - |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - return empty($error_msg) ? true : $error_msg; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | - * very next day then this method will return true. |
|
| 956 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | - * |
|
| 960 | - * @param mixed $date_1 |
|
| 961 | - * @param mixed $date_2 |
|
| 962 | - * @return bool |
|
| 963 | - */ |
|
| 964 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | - { |
|
| 966 | - |
|
| 967 | - if ( |
|
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | - ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | - ) { |
|
| 971 | - return false; |
|
| 972 | - } |
|
| 973 | - return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | - * Functions. |
|
| 980 | - * |
|
| 981 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | - * @return string |
|
| 984 | - */ |
|
| 985 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | - { |
|
| 987 | - try { |
|
| 988 | - /** need to account for timezone offset on the selects */ |
|
| 989 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | - } catch (Exception $e) { |
|
| 991 | - $DateTimeZone = null; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | - */ |
|
| 998 | - $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | - $query_interval = $offset < 0 |
|
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | - return $query_interval; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - /** |
|
| 1006 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | - * (although note that we remove any HTML that may be added) |
|
| 1011 | - * |
|
| 1012 | - * @return string |
|
| 1013 | - */ |
|
| 1014 | - public static function get_timezone_string_for_display() |
|
| 1015 | - { |
|
| 1016 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1018 | - return esc_html($pretty_timezone); |
|
| 1019 | - } |
|
| 1020 | - $timezone_string = get_option('timezone_string'); |
|
| 1021 | - if ($timezone_string) { |
|
| 1022 | - static $mo_loaded = false; |
|
| 1023 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | - if (! $mo_loaded) { |
|
| 1025 | - $locale = get_locale(); |
|
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | - load_textdomain('continents-cities', $mofile); |
|
| 1028 | - $mo_loaded = true; |
|
| 1029 | - } |
|
| 1030 | - //well that was easy. |
|
| 1031 | - $parts = explode('/', $timezone_string); |
|
| 1032 | - //remove the continent |
|
| 1033 | - unset($parts[0]); |
|
| 1034 | - $t_parts = array(); |
|
| 1035 | - foreach ($parts as $part) { |
|
| 1036 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | - } |
|
| 1038 | - return implode(' - ', $t_parts); |
|
| 1039 | - } |
|
| 1040 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | - $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | - if (intval($gmt_offset) >= 0) { |
|
| 1043 | - $prefix = '+'; |
|
| 1044 | - } else { |
|
| 1045 | - $prefix = ''; |
|
| 1046 | - } |
|
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | - if (count($parts) === 1) { |
|
| 1049 | - $parts[1] = '00'; |
|
| 1050 | - } else { |
|
| 1051 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | - //to minutes, eg 30 or 15, respectively |
|
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | - } |
|
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | - * for a month using a string like "February" or "February 2017", |
|
| 1064 | - * and you don't specify a day as part of your string, |
|
| 1065 | - * then PHP will use whatever the current day of the month is. |
|
| 1066 | - * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | - * then PHP gets really confused by a date like February 30, |
|
| 1068 | - * so instead of saying |
|
| 1069 | - * "Hey February only has 28 days (this year)... |
|
| 1070 | - * ...you must have meant the last day of the month!" |
|
| 1071 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | - * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | - * The way around this is to always set the day to the first, |
|
| 1074 | - * so that the month will stay on the month you wanted. |
|
| 1075 | - * this method will add that "1" into your date regardless of the format. |
|
| 1076 | - * |
|
| 1077 | - * @param string $month |
|
| 1078 | - * @return string |
|
| 1079 | - */ |
|
| 1080 | - public static function first_of_month_timestamp($month = '') |
|
| 1081 | - { |
|
| 1082 | - $month = (string)$month; |
|
| 1083 | - $year = ''; |
|
| 1084 | - // check if the incoming string has a year in it or not |
|
| 1085 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | - $year = $matches[0]; |
|
| 1087 | - // ten remove that from the month string as well as any spaces |
|
| 1088 | - $month = trim(str_replace($year, '', $month)); |
|
| 1089 | - // add a space before the year |
|
| 1090 | - $year = " {$year}"; |
|
| 1091 | - } |
|
| 1092 | - // return timestamp for something like "February 1 2017" |
|
| 1093 | - return strtotime("{$month} 1{$year}"); |
|
| 1094 | - } |
|
| 454 | + endif; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
| 460 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
| 461 | + * the site is used. |
|
| 462 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
| 463 | + * computed timestamp (i.e. date_i18n() ) |
|
| 464 | + * |
|
| 465 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
| 466 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
| 467 | + * site will be used. |
|
| 468 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
| 469 | + */ |
|
| 470 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
| 471 | + { |
|
| 472 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 473 | + $timezone_string = self::get_valid_timezone_string($timezone_string); |
|
| 474 | + $TimeZone = new DateTimeZone($timezone_string); |
|
| 475 | + |
|
| 476 | + $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 477 | + $offset = timezone_offset_get($TimeZone, $DateTime); |
|
| 478 | + return (int)$DateTime->format('U') + (int)$offset; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * _set_date_time_field |
|
| 484 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
| 485 | + * |
|
| 486 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 487 | + * @param DateTime $DateTime PHP DateTime object |
|
| 488 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
| 489 | + * @return EE_Base_Class |
|
| 490 | + */ |
|
| 491 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
| 492 | + { |
|
| 493 | + // grab current datetime format |
|
| 494 | + $current_format = $obj->get_format(); |
|
| 495 | + // set new full timestamp format |
|
| 496 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
| 497 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
| 498 | + // set the new date value using a full timestamp format so that no data is lost |
|
| 499 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
| 500 | + // reset datetime formats |
|
| 501 | + $obj->set_date_format($current_format[0]); |
|
| 502 | + $obj->set_time_format($current_format[1]); |
|
| 503 | + return $obj; |
|
| 504 | + } |
|
| 505 | + |
|
| 1095 | 506 | |
| 1096 | 507 | /** |
| 1097 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | - */ |
|
| 1100 | - public static function tomorrow() |
|
| 508 | + * date_time_add |
|
| 509 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
| 510 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
| 511 | + * |
|
| 512 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
| 513 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 514 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
| 515 | + * minutes, seconds) defaults to years |
|
| 516 | + * @param integer $value what you want to increment the time by |
|
| 517 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
| 518 | + * (chaining) |
|
| 519 | + */ |
|
| 520 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 521 | + { |
|
| 522 | + //get the raw UTC date. |
|
| 523 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 524 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
| 525 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * date_time_subtract |
|
| 531 | + * same as date_time_add except subtracting value instead of adding. |
|
| 532 | + * |
|
| 533 | + * @param \EE_Base_Class $obj |
|
| 534 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
| 535 | + * @param string $period |
|
| 536 | + * @param int $value |
|
| 537 | + * @return \EE_Base_Class |
|
| 538 | + */ |
|
| 539 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
| 540 | + { |
|
| 541 | + //get the raw UTC date |
|
| 542 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
| 543 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
| 544 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
| 550 | + * |
|
| 551 | + * @param DateTime $DateTime DateTime object |
|
| 552 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 553 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 554 | + * @param integer $value What you want to increment the date by |
|
| 555 | + * @param string $operand What operand you wish to use for the calculation |
|
| 556 | + * @return \DateTime return whatever type came in. |
|
| 557 | + * @throws \EE_Error |
|
| 558 | + */ |
|
| 559 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
| 560 | + { |
|
| 561 | + if (! $DateTime instanceof DateTime) { |
|
| 562 | + throw new EE_Error( |
|
| 563 | + sprintf( |
|
| 564 | + __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
| 565 | + print_r($DateTime, true) |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + } |
|
| 569 | + switch ($period) { |
|
| 570 | + case 'years' : |
|
| 571 | + $value = 'P' . $value . 'Y'; |
|
| 572 | + break; |
|
| 573 | + case 'months' : |
|
| 574 | + $value = 'P' . $value . 'M'; |
|
| 575 | + break; |
|
| 576 | + case 'weeks' : |
|
| 577 | + $value = 'P' . $value . 'W'; |
|
| 578 | + break; |
|
| 579 | + case 'days' : |
|
| 580 | + $value = 'P' . $value . 'D'; |
|
| 581 | + break; |
|
| 582 | + case 'hours' : |
|
| 583 | + $value = 'PT' . $value . 'H'; |
|
| 584 | + break; |
|
| 585 | + case 'minutes' : |
|
| 586 | + $value = 'PT' . $value . 'M'; |
|
| 587 | + break; |
|
| 588 | + case 'seconds' : |
|
| 589 | + $value = 'PT' . $value . 'S'; |
|
| 590 | + break; |
|
| 591 | + } |
|
| 592 | + switch ($operand) { |
|
| 593 | + case '+': |
|
| 594 | + $DateTime->add(new DateInterval($value)); |
|
| 595 | + break; |
|
| 596 | + case '-': |
|
| 597 | + $DateTime->sub(new DateInterval($value)); |
|
| 598 | + break; |
|
| 599 | + } |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
| 606 | + * |
|
| 607 | + * @param int $timestamp Unix timestamp |
|
| 608 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
| 609 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
| 610 | + * @param integer $value What you want to increment the date by |
|
| 611 | + * @param string $operand What operand you wish to use for the calculation |
|
| 612 | + * @return \DateTime return whatever type came in. |
|
| 613 | + * @throws \EE_Error |
|
| 614 | + */ |
|
| 615 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 616 | + { |
|
| 617 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | + throw new EE_Error( |
|
| 619 | + sprintf( |
|
| 620 | + __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
| 621 | + print_r($timestamp, true) |
|
| 622 | + ) |
|
| 623 | + ); |
|
| 624 | + } |
|
| 625 | + switch ($period) { |
|
| 626 | + case 'years' : |
|
| 627 | + $value = YEAR_IN_SECONDS * $value; |
|
| 628 | + break; |
|
| 629 | + case 'months' : |
|
| 630 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
| 631 | + break; |
|
| 632 | + case 'weeks' : |
|
| 633 | + $value = WEEK_IN_SECONDS * $value; |
|
| 634 | + break; |
|
| 635 | + case 'days' : |
|
| 636 | + $value = DAY_IN_SECONDS * $value; |
|
| 637 | + break; |
|
| 638 | + case 'hours' : |
|
| 639 | + $value = HOUR_IN_SECONDS * $value; |
|
| 640 | + break; |
|
| 641 | + case 'minutes' : |
|
| 642 | + $value = MINUTE_IN_SECONDS * $value; |
|
| 643 | + break; |
|
| 644 | + } |
|
| 645 | + switch ($operand) { |
|
| 646 | + case '+': |
|
| 647 | + $timestamp += $value; |
|
| 648 | + break; |
|
| 649 | + case '-': |
|
| 650 | + $timestamp -= $value; |
|
| 651 | + break; |
|
| 652 | + } |
|
| 653 | + return $timestamp; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
| 659 | + * parameters and returns the new timestamp or DateTime. |
|
| 660 | + * |
|
| 661 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
| 662 | + * @param string $period a value to indicate what interval is being used in the |
|
| 663 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
| 664 | + * 'minutes', 'seconds'. Defaults to years. |
|
| 665 | + * @param integer $value What you want to increment the date by |
|
| 666 | + * @param string $operand What operand you wish to use for the calculation |
|
| 667 | + * @return mixed string|DateTime return whatever type came in. |
|
| 668 | + */ |
|
| 669 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
| 670 | + { |
|
| 671 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
| 672 | + return EEH_DTT_Helper::_modify_datetime_object($DateTime_or_timestamp, $period, $value, $operand); |
|
| 673 | + } else if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
| 674 | + return EEH_DTT_Helper::_modify_timestamp($DateTime_or_timestamp, $period, $value, $operand); |
|
| 675 | + } else { |
|
| 676 | + //error |
|
| 677 | + return $DateTime_or_timestamp; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
| 684 | + * and spit out the js and moment.js equivalent formats. |
|
| 685 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
| 686 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
| 687 | + * time picker. |
|
| 688 | + * |
|
| 689 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
| 690 | + * @param null $date_format_string |
|
| 691 | + * @param null $time_format_string |
|
| 692 | + * @return array |
|
| 693 | + * array( |
|
| 694 | + * 'js' => array ( |
|
| 695 | + * 'date' => //date format |
|
| 696 | + * 'time' => //time format |
|
| 697 | + * ), |
|
| 698 | + * 'moment' => //date and time format. |
|
| 699 | + * ) |
|
| 700 | + */ |
|
| 701 | + public static function convert_php_to_js_and_moment_date_formats( |
|
| 702 | + $date_format_string = null, |
|
| 703 | + $time_format_string = null |
|
| 704 | + ) { |
|
| 705 | + if ($date_format_string === null) { |
|
| 706 | + $date_format_string = get_option('date_format'); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if ($time_format_string === null) { |
|
| 710 | + $time_format_string = get_option('time_format'); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
| 714 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
| 715 | + |
|
| 716 | + return array( |
|
| 717 | + 'js' => array( |
|
| 718 | + 'date' => $date_format['js'], |
|
| 719 | + 'time' => $time_format['js'], |
|
| 720 | + ), |
|
| 721 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 722 | + ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * This converts incoming format string into js and moment variations. |
|
| 728 | + * |
|
| 729 | + * @param string $format_string incoming php format string |
|
| 730 | + * @return array js and moment formats. |
|
| 731 | + */ |
|
| 732 | + protected static function _php_to_js_moment_converter($format_string) |
|
| 733 | + { |
|
| 734 | + /** |
|
| 735 | + * This is a map of symbols for formats. |
|
| 736 | + * The index is the php symbol, the equivalent values are in the array. |
|
| 737 | + * |
|
| 738 | + * @var array |
|
| 739 | + */ |
|
| 740 | + $symbols_map = array( |
|
| 741 | + // Day |
|
| 742 | + //01 |
|
| 743 | + 'd' => array( |
|
| 744 | + 'js' => 'dd', |
|
| 745 | + 'moment' => 'DD', |
|
| 746 | + ), |
|
| 747 | + //Mon |
|
| 748 | + 'D' => array( |
|
| 749 | + 'js' => 'D', |
|
| 750 | + 'moment' => 'ddd', |
|
| 751 | + ), |
|
| 752 | + //1,2,...31 |
|
| 753 | + 'j' => array( |
|
| 754 | + 'js' => 'd', |
|
| 755 | + 'moment' => 'D', |
|
| 756 | + ), |
|
| 757 | + //Monday |
|
| 758 | + 'l' => array( |
|
| 759 | + 'js' => 'DD', |
|
| 760 | + 'moment' => 'dddd', |
|
| 761 | + ), |
|
| 762 | + //ISO numeric representation of the day of the week (1-6) |
|
| 763 | + 'N' => array( |
|
| 764 | + 'js' => '', |
|
| 765 | + 'moment' => 'E', |
|
| 766 | + ), |
|
| 767 | + //st,nd.rd |
|
| 768 | + 'S' => array( |
|
| 769 | + 'js' => '', |
|
| 770 | + 'moment' => 'o', |
|
| 771 | + ), |
|
| 772 | + //numeric representation of day of week (0-6) |
|
| 773 | + 'w' => array( |
|
| 774 | + 'js' => '', |
|
| 775 | + 'moment' => 'd', |
|
| 776 | + ), |
|
| 777 | + //day of year starting from 0 (0-365) |
|
| 778 | + 'z' => array( |
|
| 779 | + 'js' => 'o', |
|
| 780 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
| 781 | + ), |
|
| 782 | + // Week |
|
| 783 | + //ISO-8601 week number of year (weeks starting on monday) |
|
| 784 | + 'W' => array( |
|
| 785 | + 'js' => '', |
|
| 786 | + 'moment' => 'w', |
|
| 787 | + ), |
|
| 788 | + // Month |
|
| 789 | + // January...December |
|
| 790 | + 'F' => array( |
|
| 791 | + 'js' => 'MM', |
|
| 792 | + 'moment' => 'MMMM', |
|
| 793 | + ), |
|
| 794 | + //01...12 |
|
| 795 | + 'm' => array( |
|
| 796 | + 'js' => 'mm', |
|
| 797 | + 'moment' => 'MM', |
|
| 798 | + ), |
|
| 799 | + //Jan...Dec |
|
| 800 | + 'M' => array( |
|
| 801 | + 'js' => 'M', |
|
| 802 | + 'moment' => 'MMM', |
|
| 803 | + ), |
|
| 804 | + //1-12 |
|
| 805 | + 'n' => array( |
|
| 806 | + 'js' => 'm', |
|
| 807 | + 'moment' => 'M', |
|
| 808 | + ), |
|
| 809 | + //number of days in given month |
|
| 810 | + 't' => array( |
|
| 811 | + 'js' => '', |
|
| 812 | + 'moment' => '', |
|
| 813 | + ), |
|
| 814 | + // Year |
|
| 815 | + //whether leap year or not 1/0 |
|
| 816 | + 'L' => array( |
|
| 817 | + 'js' => '', |
|
| 818 | + 'moment' => '', |
|
| 819 | + ), |
|
| 820 | + //ISO-8601 year number |
|
| 821 | + 'o' => array( |
|
| 822 | + 'js' => '', |
|
| 823 | + 'moment' => 'GGGG', |
|
| 824 | + ), |
|
| 825 | + //1999...2003 |
|
| 826 | + 'Y' => array( |
|
| 827 | + 'js' => 'yy', |
|
| 828 | + 'moment' => 'YYYY', |
|
| 829 | + ), |
|
| 830 | + //99...03 |
|
| 831 | + 'y' => array( |
|
| 832 | + 'js' => 'y', |
|
| 833 | + 'moment' => 'YY', |
|
| 834 | + ), |
|
| 835 | + // Time |
|
| 836 | + // am/pm |
|
| 837 | + 'a' => array( |
|
| 838 | + 'js' => 'tt', |
|
| 839 | + 'moment' => 'a', |
|
| 840 | + ), |
|
| 841 | + // AM/PM |
|
| 842 | + 'A' => array( |
|
| 843 | + 'js' => 'TT', |
|
| 844 | + 'moment' => 'A', |
|
| 845 | + ), |
|
| 846 | + // Swatch Internet Time?!? |
|
| 847 | + 'B' => array( |
|
| 848 | + 'js' => '', |
|
| 849 | + 'moment' => '', |
|
| 850 | + ), |
|
| 851 | + //1...12 |
|
| 852 | + 'g' => array( |
|
| 853 | + 'js' => 'h', |
|
| 854 | + 'moment' => 'h', |
|
| 855 | + ), |
|
| 856 | + //0...23 |
|
| 857 | + 'G' => array( |
|
| 858 | + 'js' => 'H', |
|
| 859 | + 'moment' => 'H', |
|
| 860 | + ), |
|
| 861 | + //01...12 |
|
| 862 | + 'h' => array( |
|
| 863 | + 'js' => 'hh', |
|
| 864 | + 'moment' => 'hh', |
|
| 865 | + ), |
|
| 866 | + //00...23 |
|
| 867 | + 'H' => array( |
|
| 868 | + 'js' => 'HH', |
|
| 869 | + 'moment' => 'HH', |
|
| 870 | + ), |
|
| 871 | + //00..59 |
|
| 872 | + 'i' => array( |
|
| 873 | + 'js' => 'mm', |
|
| 874 | + 'moment' => 'mm', |
|
| 875 | + ), |
|
| 876 | + //seconds... 00...59 |
|
| 877 | + 's' => array( |
|
| 878 | + 'js' => 'ss', |
|
| 879 | + 'moment' => 'ss', |
|
| 880 | + ), |
|
| 881 | + //microseconds |
|
| 882 | + 'u' => array( |
|
| 883 | + 'js' => '', |
|
| 884 | + 'moment' => '', |
|
| 885 | + ), |
|
| 886 | + ); |
|
| 887 | + $jquery_ui_format = ""; |
|
| 888 | + $moment_format = ""; |
|
| 889 | + $escaping = false; |
|
| 890 | + for ($i = 0; $i < strlen($format_string); $i++) { |
|
| 891 | + $char = $format_string[$i]; |
|
| 892 | + if ($char === '\\') { // PHP date format escaping character |
|
| 893 | + $i++; |
|
| 894 | + if ($escaping) { |
|
| 895 | + $jquery_ui_format .= $format_string[$i]; |
|
| 896 | + $moment_format .= $format_string[$i]; |
|
| 897 | + } else { |
|
| 898 | + $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 899 | + $moment_format .= $format_string[$i]; |
|
| 900 | + } |
|
| 901 | + $escaping = true; |
|
| 902 | + } else { |
|
| 903 | + if ($escaping) { |
|
| 904 | + $jquery_ui_format .= "'"; |
|
| 905 | + $moment_format .= "'"; |
|
| 906 | + $escaping = false; |
|
| 907 | + } |
|
| 908 | + if (isset($symbols_map[$char])) { |
|
| 909 | + $jquery_ui_format .= $symbols_map[$char]['js']; |
|
| 910 | + $moment_format .= $symbols_map[$char]['moment']; |
|
| 911 | + } else { |
|
| 912 | + $jquery_ui_format .= $char; |
|
| 913 | + $moment_format .= $char; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + } |
|
| 917 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
| 923 | + * |
|
| 924 | + * @param string $format_string Incoming format string for php date(). |
|
| 925 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
| 926 | + * errors is returned. So for client code calling, check for is_array() to |
|
| 927 | + * indicate failed validations. |
|
| 928 | + */ |
|
| 929 | + public static function validate_format_string($format_string) |
|
| 930 | + { |
|
| 931 | + $error_msg = array(); |
|
| 932 | + //time format checks |
|
| 933 | + switch (true) { |
|
| 934 | + case strpos($format_string, 'h') !== false : |
|
| 935 | + case strpos($format_string, 'g') !== false : |
|
| 936 | + /** |
|
| 937 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
| 938 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
| 939 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
| 940 | + */ |
|
| 941 | + if (strpos(strtoupper($format_string), 'A') === false) { |
|
| 942 | + $error_msg[] = __('There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
| 943 | + 'event_espresso'); |
|
| 944 | + } |
|
| 945 | + break; |
|
| 946 | + |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + return empty($error_msg) ? true : $error_msg; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
| 955 | + * very next day then this method will return true. |
|
| 956 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
| 957 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
| 958 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
| 959 | + * |
|
| 960 | + * @param mixed $date_1 |
|
| 961 | + * @param mixed $date_2 |
|
| 962 | + * @return bool |
|
| 963 | + */ |
|
| 964 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
| 965 | + { |
|
| 966 | + |
|
| 967 | + if ( |
|
| 968 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | + ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
|
| 970 | + ) { |
|
| 971 | + return false; |
|
| 972 | + } |
|
| 973 | + return $date_2->format('U') - $date_1->format('U') == 86400 ? true : false; |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
| 979 | + * Functions. |
|
| 980 | + * |
|
| 981 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
| 982 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
| 983 | + * @return string |
|
| 984 | + */ |
|
| 985 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
| 986 | + { |
|
| 987 | + try { |
|
| 988 | + /** need to account for timezone offset on the selects */ |
|
| 989 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
| 990 | + } catch (Exception $e) { |
|
| 991 | + $DateTimeZone = null; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
| 996 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
| 997 | + */ |
|
| 998 | + $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
|
| 999 | + $query_interval = $offset < 0 |
|
| 1000 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 1002 | + return $query_interval; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + /** |
|
| 1006 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
| 1007 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
| 1008 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
| 1009 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
| 1010 | + * (although note that we remove any HTML that may be added) |
|
| 1011 | + * |
|
| 1012 | + * @return string |
|
| 1013 | + */ |
|
| 1014 | + public static function get_timezone_string_for_display() |
|
| 1015 | + { |
|
| 1016 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
| 1017 | + if (! empty($pretty_timezone)) { |
|
| 1018 | + return esc_html($pretty_timezone); |
|
| 1019 | + } |
|
| 1020 | + $timezone_string = get_option('timezone_string'); |
|
| 1021 | + if ($timezone_string) { |
|
| 1022 | + static $mo_loaded = false; |
|
| 1023 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
| 1024 | + if (! $mo_loaded) { |
|
| 1025 | + $locale = get_locale(); |
|
| 1026 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1027 | + load_textdomain('continents-cities', $mofile); |
|
| 1028 | + $mo_loaded = true; |
|
| 1029 | + } |
|
| 1030 | + //well that was easy. |
|
| 1031 | + $parts = explode('/', $timezone_string); |
|
| 1032 | + //remove the continent |
|
| 1033 | + unset($parts[0]); |
|
| 1034 | + $t_parts = array(); |
|
| 1035 | + foreach ($parts as $part) { |
|
| 1036 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
| 1037 | + } |
|
| 1038 | + return implode(' - ', $t_parts); |
|
| 1039 | + } |
|
| 1040 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
| 1041 | + $gmt_offset = get_option('gmt_offset'); |
|
| 1042 | + if (intval($gmt_offset) >= 0) { |
|
| 1043 | + $prefix = '+'; |
|
| 1044 | + } else { |
|
| 1045 | + $prefix = ''; |
|
| 1046 | + } |
|
| 1047 | + $parts = explode('.', (string)$gmt_offset); |
|
| 1048 | + if (count($parts) === 1) { |
|
| 1049 | + $parts[1] = '00'; |
|
| 1050 | + } else { |
|
| 1051 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
| 1052 | + //to minutes, eg 30 or 15, respectively |
|
| 1053 | + $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | + $parts[1] = (string)$hour_fraction * 60; |
|
| 1055 | + } |
|
| 1056 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
| 1063 | + * for a month using a string like "February" or "February 2017", |
|
| 1064 | + * and you don't specify a day as part of your string, |
|
| 1065 | + * then PHP will use whatever the current day of the month is. |
|
| 1066 | + * IF the current day of the month happens to be the 30th or 31st, |
|
| 1067 | + * then PHP gets really confused by a date like February 30, |
|
| 1068 | + * so instead of saying |
|
| 1069 | + * "Hey February only has 28 days (this year)... |
|
| 1070 | + * ...you must have meant the last day of the month!" |
|
| 1071 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
| 1072 | + * because someone requesting February 30th obviously meant March 1st! |
|
| 1073 | + * The way around this is to always set the day to the first, |
|
| 1074 | + * so that the month will stay on the month you wanted. |
|
| 1075 | + * this method will add that "1" into your date regardless of the format. |
|
| 1076 | + * |
|
| 1077 | + * @param string $month |
|
| 1078 | + * @return string |
|
| 1079 | + */ |
|
| 1080 | + public static function first_of_month_timestamp($month = '') |
|
| 1081 | + { |
|
| 1082 | + $month = (string)$month; |
|
| 1083 | + $year = ''; |
|
| 1084 | + // check if the incoming string has a year in it or not |
|
| 1085 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
| 1086 | + $year = $matches[0]; |
|
| 1087 | + // ten remove that from the month string as well as any spaces |
|
| 1088 | + $month = trim(str_replace($year, '', $month)); |
|
| 1089 | + // add a space before the year |
|
| 1090 | + $year = " {$year}"; |
|
| 1091 | + } |
|
| 1092 | + // return timestamp for something like "February 1 2017" |
|
| 1093 | + return strtotime("{$month} 1{$year}"); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + /** |
|
| 1097 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
| 1098 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
| 1099 | + */ |
|
| 1100 | + public static function tomorrow() |
|
| 1101 | 1101 | { |
| 1102 | 1102 | //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
| 1103 | 1103 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
@@ -1107,135 +1107,135 @@ discard block |
||
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | |
| 1110 | - /** |
|
| 1111 | - * ** |
|
| 1112 | - * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | - * |
|
| 1115 | - * @since 4.9.40.rc.008 |
|
| 1116 | - * @staticvar bool $mo_loaded |
|
| 1117 | - * @staticvar string $locale_loaded |
|
| 1118 | - * @param string $selected_zone Selected timezone. |
|
| 1119 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | - * @return string |
|
| 1121 | - */ |
|
| 1122 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | - { |
|
| 1124 | - static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | - |
|
| 1126 | - $continents = array( |
|
| 1127 | - 'Africa', |
|
| 1128 | - 'America', |
|
| 1129 | - 'Antarctica', |
|
| 1130 | - 'Arctic', |
|
| 1131 | - 'Asia', |
|
| 1132 | - 'Atlantic', |
|
| 1133 | - 'Australia', |
|
| 1134 | - 'Europe', |
|
| 1135 | - 'Indian', |
|
| 1136 | - 'Pacific', |
|
| 1137 | - ); |
|
| 1138 | - |
|
| 1139 | - // Load translations for continents and cities. |
|
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | - unload_textdomain('continents-cities'); |
|
| 1144 | - load_textdomain('continents-cities', $mofile); |
|
| 1145 | - $mo_loaded = true; |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - $zonen = array(); |
|
| 1149 | - foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | - $zone = explode('/', $zone); |
|
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1152 | - continue; |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | - $exists = array( |
|
| 1157 | - 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | - 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | - 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | - ); |
|
| 1161 | - $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | - $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | - $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | - |
|
| 1165 | - $zonen[] = array( |
|
| 1166 | - 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | - 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | - 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | - 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | - 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | - 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | - ); |
|
| 1173 | - } |
|
| 1174 | - usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | - |
|
| 1176 | - $structure = array(); |
|
| 1177 | - |
|
| 1178 | - if (empty($selected_zone)) { |
|
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - foreach ($zonen as $key => $zone) { |
|
| 1183 | - // Build value in an array to join later |
|
| 1184 | - $value = array($zone['continent']); |
|
| 1185 | - |
|
| 1186 | - if (empty($zone['city'])) { |
|
| 1187 | - // It's at the continent level (generally won't happen) |
|
| 1188 | - $display = $zone['t_continent']; |
|
| 1189 | - } else { |
|
| 1190 | - // It's inside a continent group |
|
| 1191 | - |
|
| 1192 | - // Continent optgroup |
|
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | - $label = $zone['t_continent']; |
|
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - // Add the city to the value |
|
| 1199 | - $value[] = $zone['city']; |
|
| 1200 | - |
|
| 1201 | - $display = $zone['t_city']; |
|
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1203 | - // Add the subcity to the value |
|
| 1204 | - $value[] = $zone['subcity']; |
|
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // Build the value |
|
| 1210 | - $value = join('/', $value); |
|
| 1211 | - $selected = ''; |
|
| 1212 | - if ($value === $selected_zone) { |
|
| 1213 | - $selected = 'selected="selected" '; |
|
| 1214 | - } |
|
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | - |
|
| 1217 | - // Close continent optgroup |
|
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | - $structure[] = '</optgroup>'; |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - |
|
| 1223 | - return join("\n", $structure); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - |
|
| 1227 | - /** |
|
| 1228 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | - * |
|
| 1230 | - * @param int|WP_User $user_id |
|
| 1231 | - * @return string |
|
| 1232 | - */ |
|
| 1233 | - public static function get_user_locale($user_id = 0) |
|
| 1234 | - { |
|
| 1235 | - if (function_exists('get_user_locale')) { |
|
| 1236 | - return get_user_locale($user_id); |
|
| 1237 | - } |
|
| 1238 | - return get_locale(); |
|
| 1239 | - } |
|
| 1110 | + /** |
|
| 1111 | + * ** |
|
| 1112 | + * Gives a nicely-formatted list of timezone strings. |
|
| 1113 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
| 1114 | + * |
|
| 1115 | + * @since 4.9.40.rc.008 |
|
| 1116 | + * @staticvar bool $mo_loaded |
|
| 1117 | + * @staticvar string $locale_loaded |
|
| 1118 | + * @param string $selected_zone Selected timezone. |
|
| 1119 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
| 1120 | + * @return string |
|
| 1121 | + */ |
|
| 1122 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
| 1123 | + { |
|
| 1124 | + static $mo_loaded = false, $locale_loaded = null; |
|
| 1125 | + |
|
| 1126 | + $continents = array( |
|
| 1127 | + 'Africa', |
|
| 1128 | + 'America', |
|
| 1129 | + 'Antarctica', |
|
| 1130 | + 'Arctic', |
|
| 1131 | + 'Asia', |
|
| 1132 | + 'Atlantic', |
|
| 1133 | + 'Australia', |
|
| 1134 | + 'Europe', |
|
| 1135 | + 'Indian', |
|
| 1136 | + 'Pacific', |
|
| 1137 | + ); |
|
| 1138 | + |
|
| 1139 | + // Load translations for continents and cities. |
|
| 1140 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
| 1142 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1143 | + unload_textdomain('continents-cities'); |
|
| 1144 | + load_textdomain('continents-cities', $mofile); |
|
| 1145 | + $mo_loaded = true; |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + $zonen = array(); |
|
| 1149 | + foreach (timezone_identifiers_list() as $zone) { |
|
| 1150 | + $zone = explode('/', $zone); |
|
| 1151 | + if (! in_array($zone[0], $continents)) { |
|
| 1152 | + continue; |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
| 1156 | + $exists = array( |
|
| 1157 | + 0 => (isset($zone[0]) && $zone[0]), |
|
| 1158 | + 1 => (isset($zone[1]) && $zone[1]), |
|
| 1159 | + 2 => (isset($zone[2]) && $zone[2]), |
|
| 1160 | + ); |
|
| 1161 | + $exists[3] = ($exists[0] && 'Etc' !== $zone[0]); |
|
| 1162 | + $exists[4] = ($exists[1] && $exists[3]); |
|
| 1163 | + $exists[5] = ($exists[2] && $exists[3]); |
|
| 1164 | + |
|
| 1165 | + $zonen[] = array( |
|
| 1166 | + 'continent' => ($exists[0] ? $zone[0] : ''), |
|
| 1167 | + 'city' => ($exists[1] ? $zone[1] : ''), |
|
| 1168 | + 'subcity' => ($exists[2] ? $zone[2] : ''), |
|
| 1169 | + 't_continent' => ($exists[3] ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') : ''), |
|
| 1170 | + 't_city' => ($exists[4] ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') : ''), |
|
| 1171 | + 't_subcity' => ($exists[5] ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') : ''), |
|
| 1172 | + ); |
|
| 1173 | + } |
|
| 1174 | + usort($zonen, '_wp_timezone_choice_usort_callback'); |
|
| 1175 | + |
|
| 1176 | + $structure = array(); |
|
| 1177 | + |
|
| 1178 | + if (empty($selected_zone)) { |
|
| 1179 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + foreach ($zonen as $key => $zone) { |
|
| 1183 | + // Build value in an array to join later |
|
| 1184 | + $value = array($zone['continent']); |
|
| 1185 | + |
|
| 1186 | + if (empty($zone['city'])) { |
|
| 1187 | + // It's at the continent level (generally won't happen) |
|
| 1188 | + $display = $zone['t_continent']; |
|
| 1189 | + } else { |
|
| 1190 | + // It's inside a continent group |
|
| 1191 | + |
|
| 1192 | + // Continent optgroup |
|
| 1193 | + if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | + $label = $zone['t_continent']; |
|
| 1195 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + // Add the city to the value |
|
| 1199 | + $value[] = $zone['city']; |
|
| 1200 | + |
|
| 1201 | + $display = $zone['t_city']; |
|
| 1202 | + if (! empty($zone['subcity'])) { |
|
| 1203 | + // Add the subcity to the value |
|
| 1204 | + $value[] = $zone['subcity']; |
|
| 1205 | + $display .= ' - ' . $zone['t_subcity']; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // Build the value |
|
| 1210 | + $value = join('/', $value); |
|
| 1211 | + $selected = ''; |
|
| 1212 | + if ($value === $selected_zone) { |
|
| 1213 | + $selected = 'selected="selected" '; |
|
| 1214 | + } |
|
| 1215 | + $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1216 | + |
|
| 1217 | + // Close continent optgroup |
|
| 1218 | + if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | + $structure[] = '</optgroup>'; |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + |
|
| 1223 | + return join("\n", $structure); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + |
|
| 1227 | + /** |
|
| 1228 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
| 1229 | + * |
|
| 1230 | + * @param int|WP_User $user_id |
|
| 1231 | + * @return string |
|
| 1232 | + */ |
|
| 1233 | + public static function get_user_locale($user_id = 0) |
|
| 1234 | + { |
|
| 1235 | + if (function_exists('get_user_locale')) { |
|
| 1236 | + return get_user_locale($user_id); |
|
| 1237 | + } |
|
| 1238 | + return get_locale(); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | }// end class EEH_DTT_Helper |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('NO direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | new DateTimeZone($timezone_string); |
| 75 | 75 | } catch (Exception $e) { |
| 76 | 76 | // sometimes we take exception to exceptions |
| 77 | - if (! $throw_error) { |
|
| 77 | + if ( ! $throw_error) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | throw new EE_Error( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | $offset = get_option('gmt_offset'); |
| 162 | - return (int)($offset * HOUR_IN_SECONDS); |
|
| 162 | + return (int) ($offset * HOUR_IN_SECONDS); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
| 178 | 178 | { |
| 179 | 179 | //make sure $gmt_offset is int |
| 180 | - $gmt_offset = (int)$gmt_offset; |
|
| 180 | + $gmt_offset = (int) $gmt_offset; |
|
| 181 | 181 | switch ($gmt_offset) { |
| 182 | 182 | //-12 |
| 183 | 183 | case -43200: |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
| 351 | 351 | { |
| 352 | 352 | $transitions = self::get_timezone_transitions($date_time_zone, $time); |
| 353 | - if (! isset($transitions['offset'])) { |
|
| 353 | + if ( ! isset($transitions['offset'])) { |
|
| 354 | 354 | throw new DomainException(); |
| 355 | 355 | } |
| 356 | 356 | return $transitions['offset']; |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | public static function timezone_select_input($timezone_string = '') |
| 365 | 365 | { |
| 366 | 366 | // get WP date time format |
| 367 | - $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); |
|
| 367 | + $datetime_format = get_option('date_format').' '.get_option('time_format'); |
|
| 368 | 368 | // if passed a value, then use that, else get WP option |
| 369 | 369 | $timezone_string = ! empty($timezone_string) ? $timezone_string : get_option('timezone_string'); |
| 370 | 370 | // check if the timezone is valid but don't throw any errors if it isn't |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | // Create a UTC+- zone if no timezone string exists |
| 377 | 377 | $check_zone_info = false; |
| 378 | 378 | if ($gmt_offset > 0) { |
| 379 | - $timezone_string = 'UTC+' . $gmt_offset; |
|
| 379 | + $timezone_string = 'UTC+'.$gmt_offset; |
|
| 380 | 380 | } elseif ($gmt_offset < 0) { |
| 381 | - $timezone_string = 'UTC' . $gmt_offset; |
|
| 381 | + $timezone_string = 'UTC'.$gmt_offset; |
|
| 382 | 382 | } else { |
| 383 | 383 | $timezone_string = 'UTC'; |
| 384 | 384 | } |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | __('%1$sUTC%2$s time is %3$s'), |
| 401 | 401 | '<abbr title="Coordinated Universal Time">', |
| 402 | 402 | '</abbr>', |
| 403 | - '<code>' . date_i18n($datetime_format, false, true) . '</code>' |
|
| 403 | + '<code>'.date_i18n($datetime_format, false, true).'</code>' |
|
| 404 | 404 | ); |
| 405 | 405 | ?></span> |
| 406 | - <?php if (! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | - <br/><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?></span> |
|
| 406 | + <?php if ( ! empty($timezone_string) || ! empty($gmt_offset)) : ?> |
|
| 407 | + <br/><span><?php printf(__('Local time is %1$s'), '<code>'.date_i18n($datetime_format).'</code>'); ?></span> |
|
| 408 | 408 | <?php endif; ?> |
| 409 | 409 | |
| 410 | 410 | <?php if ($check_zone_info && $timezone_string) : ?> |
@@ -437,11 +437,10 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | if ($found) { |
| 439 | 439 | $message = $tr['isdst'] ? |
| 440 | - __(' Daylight saving time begins on: %s.') : |
|
| 441 | - __(' Standard time begins on: %s.'); |
|
| 440 | + __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); |
|
| 442 | 441 | // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). |
| 443 | 442 | printf($message, |
| 444 | - '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); |
|
| 443 | + '<code >'.date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])).'</code >'); |
|
| 445 | 444 | } else { |
| 446 | 445 | _e('This timezone does not observe daylight saving time.'); |
| 447 | 446 | } |
@@ -469,13 +468,13 @@ discard block |
||
| 469 | 468 | */ |
| 470 | 469 | public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
| 471 | 470 | { |
| 472 | - $unix_timestamp = $unix_timestamp === 0 ? time() : (int)$unix_timestamp; |
|
| 471 | + $unix_timestamp = $unix_timestamp === 0 ? time() : (int) $unix_timestamp; |
|
| 473 | 472 | $timezone_string = self::get_valid_timezone_string($timezone_string); |
| 474 | 473 | $TimeZone = new DateTimeZone($timezone_string); |
| 475 | 474 | |
| 476 | - $DateTime = new DateTime('@' . $unix_timestamp, $TimeZone); |
|
| 475 | + $DateTime = new DateTime('@'.$unix_timestamp, $TimeZone); |
|
| 477 | 476 | $offset = timezone_offset_get($TimeZone, $DateTime); |
| 478 | - return (int)$DateTime->format('U') + (int)$offset; |
|
| 477 | + return (int) $DateTime->format('U') + (int) $offset; |
|
| 479 | 478 | } |
| 480 | 479 | |
| 481 | 480 | |
@@ -558,7 +557,7 @@ discard block |
||
| 558 | 557 | */ |
| 559 | 558 | protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
| 560 | 559 | { |
| 561 | - if (! $DateTime instanceof DateTime) { |
|
| 560 | + if ( ! $DateTime instanceof DateTime) { |
|
| 562 | 561 | throw new EE_Error( |
| 563 | 562 | sprintf( |
| 564 | 563 | __('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
@@ -568,25 +567,25 @@ discard block |
||
| 568 | 567 | } |
| 569 | 568 | switch ($period) { |
| 570 | 569 | case 'years' : |
| 571 | - $value = 'P' . $value . 'Y'; |
|
| 570 | + $value = 'P'.$value.'Y'; |
|
| 572 | 571 | break; |
| 573 | 572 | case 'months' : |
| 574 | - $value = 'P' . $value . 'M'; |
|
| 573 | + $value = 'P'.$value.'M'; |
|
| 575 | 574 | break; |
| 576 | 575 | case 'weeks' : |
| 577 | - $value = 'P' . $value . 'W'; |
|
| 576 | + $value = 'P'.$value.'W'; |
|
| 578 | 577 | break; |
| 579 | 578 | case 'days' : |
| 580 | - $value = 'P' . $value . 'D'; |
|
| 579 | + $value = 'P'.$value.'D'; |
|
| 581 | 580 | break; |
| 582 | 581 | case 'hours' : |
| 583 | - $value = 'PT' . $value . 'H'; |
|
| 582 | + $value = 'PT'.$value.'H'; |
|
| 584 | 583 | break; |
| 585 | 584 | case 'minutes' : |
| 586 | - $value = 'PT' . $value . 'M'; |
|
| 585 | + $value = 'PT'.$value.'M'; |
|
| 587 | 586 | break; |
| 588 | 587 | case 'seconds' : |
| 589 | - $value = 'PT' . $value . 'S'; |
|
| 588 | + $value = 'PT'.$value.'S'; |
|
| 590 | 589 | break; |
| 591 | 590 | } |
| 592 | 591 | switch ($operand) { |
@@ -614,7 +613,7 @@ discard block |
||
| 614 | 613 | */ |
| 615 | 614 | protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
| 616 | 615 | { |
| 617 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 616 | + if ( ! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
| 618 | 617 | throw new EE_Error( |
| 619 | 618 | sprintf( |
| 620 | 619 | __('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
@@ -718,7 +717,7 @@ discard block |
||
| 718 | 717 | 'date' => $date_format['js'], |
| 719 | 718 | 'time' => $time_format['js'], |
| 720 | 719 | ), |
| 721 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
| 720 | + 'moment' => $date_format['moment'].' '.$time_format['moment'], |
|
| 722 | 721 | ); |
| 723 | 722 | } |
| 724 | 723 | |
@@ -737,7 +736,7 @@ discard block |
||
| 737 | 736 | * |
| 738 | 737 | * @var array |
| 739 | 738 | */ |
| 740 | - $symbols_map = array( |
|
| 739 | + $symbols_map = array( |
|
| 741 | 740 | // Day |
| 742 | 741 | //01 |
| 743 | 742 | 'd' => array( |
@@ -895,7 +894,7 @@ discard block |
||
| 895 | 894 | $jquery_ui_format .= $format_string[$i]; |
| 896 | 895 | $moment_format .= $format_string[$i]; |
| 897 | 896 | } else { |
| 898 | - $jquery_ui_format .= '\'' . $format_string[$i]; |
|
| 897 | + $jquery_ui_format .= '\''.$format_string[$i]; |
|
| 899 | 898 | $moment_format .= $format_string[$i]; |
| 900 | 899 | } |
| 901 | 900 | $escaping = true; |
@@ -965,7 +964,7 @@ discard block |
||
| 965 | 964 | { |
| 966 | 965 | |
| 967 | 966 | if ( |
| 968 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 967 | + ( ! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) || |
|
| 969 | 968 | ($date_1->format(EE_Datetime_Field::mysql_time_format) != '00:00:00' || $date_2->format(EE_Datetime_Field::mysql_time_format) != '00:00:00') |
| 970 | 969 | ) { |
| 971 | 970 | return false; |
@@ -997,8 +996,8 @@ discard block |
||
| 997 | 996 | */ |
| 998 | 997 | $offset = $DateTimeZone instanceof DateTimeZone ? ($DateTimeZone->getOffset(new DateTime('now'))) / HOUR_IN_SECONDS : get_option('gmt_offset'); |
| 999 | 998 | $query_interval = $offset < 0 |
| 1000 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
| 1001 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
| 999 | + ? 'DATE_SUB('.$field_for_interval.', INTERVAL '.$offset * -1.' HOUR)' |
|
| 1000 | + : 'DATE_ADD('.$field_for_interval.', INTERVAL '.$offset.' HOUR)'; |
|
| 1002 | 1001 | return $query_interval; |
| 1003 | 1002 | } |
| 1004 | 1003 | |
@@ -1014,16 +1013,16 @@ discard block |
||
| 1014 | 1013 | public static function get_timezone_string_for_display() |
| 1015 | 1014 | { |
| 1016 | 1015 | $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
| 1017 | - if (! empty($pretty_timezone)) { |
|
| 1016 | + if ( ! empty($pretty_timezone)) { |
|
| 1018 | 1017 | return esc_html($pretty_timezone); |
| 1019 | 1018 | } |
| 1020 | 1019 | $timezone_string = get_option('timezone_string'); |
| 1021 | 1020 | if ($timezone_string) { |
| 1022 | 1021 | static $mo_loaded = false; |
| 1023 | 1022 | // Load translations for continents and cities just like wp_timezone_choice does |
| 1024 | - if (! $mo_loaded) { |
|
| 1023 | + if ( ! $mo_loaded) { |
|
| 1025 | 1024 | $locale = get_locale(); |
| 1026 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
| 1025 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale.'.mo'; |
|
| 1027 | 1026 | load_textdomain('continents-cities', $mofile); |
| 1028 | 1027 | $mo_loaded = true; |
| 1029 | 1028 | } |
@@ -1044,16 +1043,16 @@ discard block |
||
| 1044 | 1043 | } else { |
| 1045 | 1044 | $prefix = ''; |
| 1046 | 1045 | } |
| 1047 | - $parts = explode('.', (string)$gmt_offset); |
|
| 1046 | + $parts = explode('.', (string) $gmt_offset); |
|
| 1048 | 1047 | if (count($parts) === 1) { |
| 1049 | 1048 | $parts[1] = '00'; |
| 1050 | 1049 | } else { |
| 1051 | 1050 | //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
| 1052 | 1051 | //to minutes, eg 30 or 15, respectively |
| 1053 | - $hour_fraction = (float)('0.' . $parts[1]); |
|
| 1054 | - $parts[1] = (string)$hour_fraction * 60; |
|
| 1052 | + $hour_fraction = (float) ('0.'.$parts[1]); |
|
| 1053 | + $parts[1] = (string) $hour_fraction * 60; |
|
| 1055 | 1054 | } |
| 1056 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
| 1055 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix.implode(':', $parts)); |
|
| 1057 | 1056 | } |
| 1058 | 1057 | |
| 1059 | 1058 | |
@@ -1079,7 +1078,7 @@ discard block |
||
| 1079 | 1078 | */ |
| 1080 | 1079 | public static function first_of_month_timestamp($month = '') |
| 1081 | 1080 | { |
| 1082 | - $month = (string)$month; |
|
| 1081 | + $month = (string) $month; |
|
| 1083 | 1082 | $year = ''; |
| 1084 | 1083 | // check if the incoming string has a year in it or not |
| 1085 | 1084 | if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
@@ -1103,7 +1102,7 @@ discard block |
||
| 1103 | 1102 | //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
| 1104 | 1103 | //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
| 1105 | 1104 | //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
| 1106 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset()*-1); |
|
| 1105 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
| 1107 | 1106 | } |
| 1108 | 1107 | |
| 1109 | 1108 | |
@@ -1137,9 +1136,9 @@ discard block |
||
| 1137 | 1136 | ); |
| 1138 | 1137 | |
| 1139 | 1138 | // Load translations for continents and cities. |
| 1140 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1139 | + if ( ! $mo_loaded || $locale !== $locale_loaded) { |
|
| 1141 | 1140 | $locale_loaded = $locale ? $locale : get_locale(); |
| 1142 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
| 1141 | + $mofile = WP_LANG_DIR.'/continents-cities-'.$locale_loaded.'.mo'; |
|
| 1143 | 1142 | unload_textdomain('continents-cities'); |
| 1144 | 1143 | load_textdomain('continents-cities', $mofile); |
| 1145 | 1144 | $mo_loaded = true; |
@@ -1148,12 +1147,12 @@ discard block |
||
| 1148 | 1147 | $zonen = array(); |
| 1149 | 1148 | foreach (timezone_identifiers_list() as $zone) { |
| 1150 | 1149 | $zone = explode('/', $zone); |
| 1151 | - if (! in_array($zone[0], $continents)) { |
|
| 1150 | + if ( ! in_array($zone[0], $continents)) { |
|
| 1152 | 1151 | continue; |
| 1153 | 1152 | } |
| 1154 | 1153 | |
| 1155 | 1154 | // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
| 1156 | - $exists = array( |
|
| 1155 | + $exists = array( |
|
| 1157 | 1156 | 0 => (isset($zone[0]) && $zone[0]), |
| 1158 | 1157 | 1 => (isset($zone[1]) && $zone[1]), |
| 1159 | 1158 | 2 => (isset($zone[2]) && $zone[2]), |
@@ -1176,7 +1175,7 @@ discard block |
||
| 1176 | 1175 | $structure = array(); |
| 1177 | 1176 | |
| 1178 | 1177 | if (empty($selected_zone)) { |
| 1179 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
| 1178 | + $structure[] = '<option selected="selected" value="">'.__('Select a city').'</option>'; |
|
| 1180 | 1179 | } |
| 1181 | 1180 | |
| 1182 | 1181 | foreach ($zonen as $key => $zone) { |
@@ -1190,19 +1189,19 @@ discard block |
||
| 1190 | 1189 | // It's inside a continent group |
| 1191 | 1190 | |
| 1192 | 1191 | // Continent optgroup |
| 1193 | - if (! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1192 | + if ( ! isset($zonen[$key - 1]) || $zonen[$key - 1]['continent'] !== $zone['continent']) { |
|
| 1194 | 1193 | $label = $zone['t_continent']; |
| 1195 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
| 1194 | + $structure[] = '<optgroup label="'.esc_attr($label).'">'; |
|
| 1196 | 1195 | } |
| 1197 | 1196 | |
| 1198 | 1197 | // Add the city to the value |
| 1199 | 1198 | $value[] = $zone['city']; |
| 1200 | 1199 | |
| 1201 | 1200 | $display = $zone['t_city']; |
| 1202 | - if (! empty($zone['subcity'])) { |
|
| 1201 | + if ( ! empty($zone['subcity'])) { |
|
| 1203 | 1202 | // Add the subcity to the value |
| 1204 | 1203 | $value[] = $zone['subcity']; |
| 1205 | - $display .= ' - ' . $zone['t_subcity']; |
|
| 1204 | + $display .= ' - '.$zone['t_subcity']; |
|
| 1206 | 1205 | } |
| 1207 | 1206 | } |
| 1208 | 1207 | |
@@ -1212,10 +1211,10 @@ discard block |
||
| 1212 | 1211 | if ($value === $selected_zone) { |
| 1213 | 1212 | $selected = 'selected="selected" '; |
| 1214 | 1213 | } |
| 1215 | - $structure[] = '<option ' . $selected . 'value="' . esc_attr($value) . '">' . esc_html($display) . "</option>"; |
|
| 1214 | + $structure[] = '<option '.$selected.'value="'.esc_attr($value).'">'.esc_html($display)."</option>"; |
|
| 1216 | 1215 | |
| 1217 | 1216 | // Close continent optgroup |
| 1218 | - if (! empty($zone['city']) && (! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1217 | + if ( ! empty($zone['city']) && ( ! isset($zonen[$key + 1]) || (isset($zonen[$key + 1]) && $zonen[$key + 1]['continent'] !== $zone['continent']))) { |
|
| 1219 | 1218 | $structure[] = '</optgroup>'; |
| 1220 | 1219 | } |
| 1221 | 1220 | } |
@@ -17,413 +17,413 @@ |
||
| 17 | 17 | class EEM_Attendee extends EEM_CPT_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - // private instance of the Attendee object |
|
| 21 | - protected static $_instance = null; |
|
| 20 | + // private instance of the Attendee object |
|
| 21 | + protected static $_instance = null; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * QST_system for questions are strings not integers now, |
|
| 25 | - * so these constants are deprecated. |
|
| 26 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
| 27 | - * |
|
| 28 | - * @deprecated |
|
| 29 | - */ |
|
| 30 | - const fname_question_id = 1; |
|
| 23 | + /** |
|
| 24 | + * QST_system for questions are strings not integers now, |
|
| 25 | + * so these constants are deprecated. |
|
| 26 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
| 27 | + * |
|
| 28 | + * @deprecated |
|
| 29 | + */ |
|
| 30 | + const fname_question_id = 1; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @deprecated |
|
| 34 | - */ |
|
| 35 | - const lname_question_id = 2; |
|
| 32 | + /** |
|
| 33 | + * @deprecated |
|
| 34 | + */ |
|
| 35 | + const lname_question_id = 2; |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @deprecated |
|
| 40 | - */ |
|
| 41 | - const email_question_id = 3; |
|
| 38 | + /** |
|
| 39 | + * @deprecated |
|
| 40 | + */ |
|
| 41 | + const email_question_id = 3; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @deprecated |
|
| 46 | - */ |
|
| 47 | - const address_question_id = 4; |
|
| 44 | + /** |
|
| 45 | + * @deprecated |
|
| 46 | + */ |
|
| 47 | + const address_question_id = 4; |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @deprecated |
|
| 52 | - */ |
|
| 53 | - const address2_question_id = 5; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @deprecated |
|
| 58 | - */ |
|
| 59 | - const city_question_id = 6; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @deprecated |
|
| 64 | - */ |
|
| 65 | - const state_question_id = 7; |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @deprecated |
|
| 70 | - */ |
|
| 71 | - const country_question_id = 8; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @deprecated |
|
| 76 | - */ |
|
| 77 | - const zip_question_id = 9; |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @deprecated |
|
| 82 | - */ |
|
| 83 | - const phone_question_id = 10; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * When looking for questions that correspond to attendee fields, |
|
| 87 | - * look for the question with this QST_system value. |
|
| 88 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
| 89 | - */ |
|
| 90 | - const system_question_fname = 'fname'; |
|
| 91 | - |
|
| 92 | - const system_question_lname = 'lname'; |
|
| 93 | - |
|
| 94 | - const system_question_email = 'email'; |
|
| 95 | - |
|
| 96 | - const system_question_address = 'address'; |
|
| 97 | - |
|
| 98 | - const system_question_address2 = 'address2'; |
|
| 99 | - |
|
| 100 | - const system_question_city = 'city'; |
|
| 101 | - |
|
| 102 | - const system_question_state = 'state'; |
|
| 103 | - |
|
| 104 | - const system_question_country = 'country'; |
|
| 105 | - |
|
| 106 | - const system_question_zip = 'zip'; |
|
| 107 | - |
|
| 108 | - const system_question_phone = 'phone'; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 112 | - * also all the values of QST_system in the questions table, and values |
|
| 113 | - * are their corresponding Attendee field names |
|
| 114 | - * |
|
| 115 | - * @var array |
|
| 116 | - */ |
|
| 117 | - protected $_system_question_to_attendee_field_name = array( |
|
| 118 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 119 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 120 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
| 121 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
| 122 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 123 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
| 124 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
| 125 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 126 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 127 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * EEM_Attendee constructor. |
|
| 134 | - * |
|
| 135 | - * @param null $timezone |
|
| 136 | - * @param ModelFieldFactory $model_field_factory |
|
| 137 | - * @throws EE_Error |
|
| 138 | - * @throws InvalidArgumentException |
|
| 139 | - */ |
|
| 140 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
| 141 | - { |
|
| 142 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 143 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 144 | - $this->_tables = array( |
|
| 145 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 146 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 147 | - 'esp_attendee_meta', |
|
| 148 | - 'ATTM_ID', |
|
| 149 | - 'ATT_ID' |
|
| 150 | - ), |
|
| 151 | - ); |
|
| 152 | - $this->_fields = array( |
|
| 153 | - 'Attendee_CPT' => array( |
|
| 154 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 155 | - 'ID', |
|
| 156 | - esc_html__('Attendee ID', 'event_espresso') |
|
| 157 | - ), |
|
| 158 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 159 | - 'post_title', |
|
| 160 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 161 | - false, |
|
| 162 | - esc_html__('Unknown', 'event_espresso') |
|
| 163 | - ), |
|
| 164 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 165 | - 'post_content', |
|
| 166 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
| 167 | - false, |
|
| 168 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 169 | - ), |
|
| 170 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 171 | - 'post_name', |
|
| 172 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 173 | - ), |
|
| 174 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 175 | - 'post_date', |
|
| 176 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
| 177 | - ), |
|
| 178 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 179 | - 'post_excerpt', |
|
| 180 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 181 | - true, |
|
| 182 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 183 | - ), |
|
| 184 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 185 | - 'post_modified', |
|
| 186 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 187 | - ), |
|
| 188 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 189 | - 'post_author', |
|
| 190 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 191 | - false |
|
| 192 | - ), |
|
| 193 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 194 | - 'post_parent', |
|
| 195 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 196 | - false, |
|
| 197 | - 0 |
|
| 198 | - ), |
|
| 199 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 200 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
| 201 | - 'post_status', |
|
| 202 | - esc_html__('Attendee Status', 'event_espresso'), |
|
| 203 | - false, |
|
| 204 | - 'publish' |
|
| 205 | - ), |
|
| 206 | - ), |
|
| 207 | - 'Attendee_Meta' => array( |
|
| 208 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 209 | - 'ATTM_ID', |
|
| 210 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 211 | - false |
|
| 212 | - ), |
|
| 213 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 214 | - 'ATT_ID', |
|
| 215 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 216 | - false |
|
| 217 | - ), |
|
| 218 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 219 | - 'ATT_fname', |
|
| 220 | - esc_html__('First Name', 'event_espresso') |
|
| 221 | - ), |
|
| 222 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 223 | - 'ATT_lname', |
|
| 224 | - esc_html__('Last Name', 'event_espresso') |
|
| 225 | - ), |
|
| 226 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 227 | - 'ATT_address', |
|
| 228 | - esc_html__('Address Part 1', 'event_espresso') |
|
| 229 | - ), |
|
| 230 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 231 | - 'ATT_address2', |
|
| 232 | - esc_html__('Address Part 2', 'event_espresso') |
|
| 233 | - ), |
|
| 234 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 235 | - 'ATT_city', |
|
| 236 | - esc_html__('City', 'event_espresso') |
|
| 237 | - ), |
|
| 238 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 239 | - 'STA_ID', |
|
| 240 | - esc_html__('State', 'event_espresso'), |
|
| 241 | - true, |
|
| 242 | - 0, |
|
| 243 | - 'State' |
|
| 244 | - ), |
|
| 245 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 246 | - 'CNT_ISO', |
|
| 247 | - esc_html__('Country', 'event_espresso'), |
|
| 248 | - true, |
|
| 249 | - '', |
|
| 250 | - 'Country' |
|
| 251 | - ), |
|
| 252 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 253 | - 'ATT_zip', |
|
| 254 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 255 | - ), |
|
| 256 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
| 257 | - 'ATT_email', |
|
| 258 | - esc_html__('Email Address', 'event_espresso') |
|
| 259 | - ), |
|
| 260 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 261 | - 'ATT_phone', |
|
| 262 | - esc_html__('Phone', 'event_espresso') |
|
| 263 | - ), |
|
| 264 | - ), |
|
| 265 | - ); |
|
| 266 | - $this->_model_relations = array( |
|
| 267 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 268 | - 'State' => new EE_Belongs_To_Relation(), |
|
| 269 | - 'Country' => new EE_Belongs_To_Relation(), |
|
| 270 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 271 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 272 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 273 | - //allow deletion of attendees even if they have messages in the queue for them. |
|
| 274 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 275 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 276 | - ); |
|
| 277 | - $this->_caps_slug = 'contacts'; |
|
| 278 | - parent::__construct($timezone); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 285 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 286 | - * |
|
| 287 | - * @param string $system_question_string |
|
| 288 | - * @return string|null if not found |
|
| 289 | - */ |
|
| 290 | - public function get_attendee_field_for_system_question($system_question_string) |
|
| 291 | - { |
|
| 292 | - return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
| 293 | - ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
| 294 | - : null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 301 | - * |
|
| 302 | - * @return array |
|
| 303 | - */ |
|
| 304 | - public function system_question_to_attendee_field_mapping() |
|
| 305 | - { |
|
| 306 | - return $this->_system_question_to_attendee_field_name; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 313 | - * |
|
| 314 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 315 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 316 | - * @throws EE_Error |
|
| 317 | - */ |
|
| 318 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 319 | - { |
|
| 320 | - return $this->get_all( |
|
| 321 | - array( |
|
| 322 | - array( |
|
| 323 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 324 | - ? $transaction_id_or_obj->ID() |
|
| 325 | - : $transaction_id_or_obj, |
|
| 326 | - ), |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * retrieve a single attendee from db via their ID |
|
| 335 | - * |
|
| 336 | - * @param $ATT_ID |
|
| 337 | - * @return mixed array on success, FALSE on fail |
|
| 338 | - * @deprecated |
|
| 339 | - */ |
|
| 340 | - public function get_attendee_by_ID($ATT_ID = false) |
|
| 341 | - { |
|
| 342 | - // retrieve a particular EE_Attendee |
|
| 343 | - return $this->get_one_by_ID($ATT_ID); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * retrieve a single attendee from db via their ID |
|
| 350 | - * |
|
| 351 | - * @param array $where_cols_n_values |
|
| 352 | - * @return mixed array on success, FALSE on fail |
|
| 353 | - * @throws EE_Error |
|
| 354 | - */ |
|
| 355 | - public function get_attendee($where_cols_n_values = array()) |
|
| 356 | - { |
|
| 357 | - if (empty($where_cols_n_values)) { |
|
| 358 | - return false; |
|
| 359 | - } |
|
| 360 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 361 | - if (! empty($attendee)) { |
|
| 362 | - return array_shift($attendee); |
|
| 363 | - } |
|
| 364 | - return false; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Search for an existing Attendee record in the DB |
|
| 371 | - * |
|
| 372 | - * @param array $where_cols_n_values |
|
| 373 | - * @return bool|mixed |
|
| 374 | - * @throws EE_Error |
|
| 375 | - */ |
|
| 376 | - public function find_existing_attendee($where_cols_n_values = null) |
|
| 377 | - { |
|
| 378 | - // search by combo of first and last names plus the email address |
|
| 379 | - $attendee_data_keys = array( |
|
| 380 | - 'ATT_fname' => $this->_ATT_fname, |
|
| 381 | - 'ATT_lname' => $this->_ATT_lname, |
|
| 382 | - 'ATT_email' => $this->_ATT_email, |
|
| 383 | - ); |
|
| 384 | - // no search params means attendee object already exists. |
|
| 385 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 386 | - ? $where_cols_n_values |
|
| 387 | - : $attendee_data_keys; |
|
| 388 | - $valid_data = true; |
|
| 389 | - // check for required values |
|
| 390 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 391 | - ? $valid_data |
|
| 392 | - : false; |
|
| 393 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 394 | - ? $valid_data |
|
| 395 | - : false; |
|
| 396 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 397 | - ? $valid_data |
|
| 398 | - : false; |
|
| 399 | - if ($valid_data) { |
|
| 400 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
| 401 | - if ($attendee instanceof EE_Attendee) { |
|
| 402 | - return $attendee; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - return false; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Takes an incoming array of EE_Registration ids |
|
| 412 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 413 | - * |
|
| 414 | - * @since 4.3.0 |
|
| 415 | - * @param array $ids array of EE_Registration ids |
|
| 416 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 417 | - * @throws EE_Error |
|
| 418 | - */ |
|
| 419 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
| 420 | - { |
|
| 421 | - $ids = (array)$ids; |
|
| 422 | - $_where = array( |
|
| 423 | - 'Registration.REG_ID' => array('in', $ids), |
|
| 424 | - ); |
|
| 425 | - return $this->get_all(array($_where)); |
|
| 426 | - } |
|
| 50 | + /** |
|
| 51 | + * @deprecated |
|
| 52 | + */ |
|
| 53 | + const address2_question_id = 5; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @deprecated |
|
| 58 | + */ |
|
| 59 | + const city_question_id = 6; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @deprecated |
|
| 64 | + */ |
|
| 65 | + const state_question_id = 7; |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @deprecated |
|
| 70 | + */ |
|
| 71 | + const country_question_id = 8; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @deprecated |
|
| 76 | + */ |
|
| 77 | + const zip_question_id = 9; |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @deprecated |
|
| 82 | + */ |
|
| 83 | + const phone_question_id = 10; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * When looking for questions that correspond to attendee fields, |
|
| 87 | + * look for the question with this QST_system value. |
|
| 88 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
| 89 | + */ |
|
| 90 | + const system_question_fname = 'fname'; |
|
| 91 | + |
|
| 92 | + const system_question_lname = 'lname'; |
|
| 93 | + |
|
| 94 | + const system_question_email = 'email'; |
|
| 95 | + |
|
| 96 | + const system_question_address = 'address'; |
|
| 97 | + |
|
| 98 | + const system_question_address2 = 'address2'; |
|
| 99 | + |
|
| 100 | + const system_question_city = 'city'; |
|
| 101 | + |
|
| 102 | + const system_question_state = 'state'; |
|
| 103 | + |
|
| 104 | + const system_question_country = 'country'; |
|
| 105 | + |
|
| 106 | + const system_question_zip = 'zip'; |
|
| 107 | + |
|
| 108 | + const system_question_phone = 'phone'; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 112 | + * also all the values of QST_system in the questions table, and values |
|
| 113 | + * are their corresponding Attendee field names |
|
| 114 | + * |
|
| 115 | + * @var array |
|
| 116 | + */ |
|
| 117 | + protected $_system_question_to_attendee_field_name = array( |
|
| 118 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 119 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 120 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
| 121 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
| 122 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 123 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
| 124 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
| 125 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 126 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 127 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * EEM_Attendee constructor. |
|
| 134 | + * |
|
| 135 | + * @param null $timezone |
|
| 136 | + * @param ModelFieldFactory $model_field_factory |
|
| 137 | + * @throws EE_Error |
|
| 138 | + * @throws InvalidArgumentException |
|
| 139 | + */ |
|
| 140 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
| 141 | + { |
|
| 142 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 143 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 144 | + $this->_tables = array( |
|
| 145 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 146 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 147 | + 'esp_attendee_meta', |
|
| 148 | + 'ATTM_ID', |
|
| 149 | + 'ATT_ID' |
|
| 150 | + ), |
|
| 151 | + ); |
|
| 152 | + $this->_fields = array( |
|
| 153 | + 'Attendee_CPT' => array( |
|
| 154 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 155 | + 'ID', |
|
| 156 | + esc_html__('Attendee ID', 'event_espresso') |
|
| 157 | + ), |
|
| 158 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 159 | + 'post_title', |
|
| 160 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 161 | + false, |
|
| 162 | + esc_html__('Unknown', 'event_espresso') |
|
| 163 | + ), |
|
| 164 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 165 | + 'post_content', |
|
| 166 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
| 167 | + false, |
|
| 168 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 169 | + ), |
|
| 170 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 171 | + 'post_name', |
|
| 172 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 173 | + ), |
|
| 174 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 175 | + 'post_date', |
|
| 176 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
| 177 | + ), |
|
| 178 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 179 | + 'post_excerpt', |
|
| 180 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 181 | + true, |
|
| 182 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 183 | + ), |
|
| 184 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 185 | + 'post_modified', |
|
| 186 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 187 | + ), |
|
| 188 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 189 | + 'post_author', |
|
| 190 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 191 | + false |
|
| 192 | + ), |
|
| 193 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 194 | + 'post_parent', |
|
| 195 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 196 | + false, |
|
| 197 | + 0 |
|
| 198 | + ), |
|
| 199 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 200 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
| 201 | + 'post_status', |
|
| 202 | + esc_html__('Attendee Status', 'event_espresso'), |
|
| 203 | + false, |
|
| 204 | + 'publish' |
|
| 205 | + ), |
|
| 206 | + ), |
|
| 207 | + 'Attendee_Meta' => array( |
|
| 208 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 209 | + 'ATTM_ID', |
|
| 210 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 211 | + false |
|
| 212 | + ), |
|
| 213 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 214 | + 'ATT_ID', |
|
| 215 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 216 | + false |
|
| 217 | + ), |
|
| 218 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 219 | + 'ATT_fname', |
|
| 220 | + esc_html__('First Name', 'event_espresso') |
|
| 221 | + ), |
|
| 222 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 223 | + 'ATT_lname', |
|
| 224 | + esc_html__('Last Name', 'event_espresso') |
|
| 225 | + ), |
|
| 226 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 227 | + 'ATT_address', |
|
| 228 | + esc_html__('Address Part 1', 'event_espresso') |
|
| 229 | + ), |
|
| 230 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 231 | + 'ATT_address2', |
|
| 232 | + esc_html__('Address Part 2', 'event_espresso') |
|
| 233 | + ), |
|
| 234 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 235 | + 'ATT_city', |
|
| 236 | + esc_html__('City', 'event_espresso') |
|
| 237 | + ), |
|
| 238 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 239 | + 'STA_ID', |
|
| 240 | + esc_html__('State', 'event_espresso'), |
|
| 241 | + true, |
|
| 242 | + 0, |
|
| 243 | + 'State' |
|
| 244 | + ), |
|
| 245 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 246 | + 'CNT_ISO', |
|
| 247 | + esc_html__('Country', 'event_espresso'), |
|
| 248 | + true, |
|
| 249 | + '', |
|
| 250 | + 'Country' |
|
| 251 | + ), |
|
| 252 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 253 | + 'ATT_zip', |
|
| 254 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 255 | + ), |
|
| 256 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
| 257 | + 'ATT_email', |
|
| 258 | + esc_html__('Email Address', 'event_espresso') |
|
| 259 | + ), |
|
| 260 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 261 | + 'ATT_phone', |
|
| 262 | + esc_html__('Phone', 'event_espresso') |
|
| 263 | + ), |
|
| 264 | + ), |
|
| 265 | + ); |
|
| 266 | + $this->_model_relations = array( |
|
| 267 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 268 | + 'State' => new EE_Belongs_To_Relation(), |
|
| 269 | + 'Country' => new EE_Belongs_To_Relation(), |
|
| 270 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 271 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 272 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 273 | + //allow deletion of attendees even if they have messages in the queue for them. |
|
| 274 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 275 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 276 | + ); |
|
| 277 | + $this->_caps_slug = 'contacts'; |
|
| 278 | + parent::__construct($timezone); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 285 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 286 | + * |
|
| 287 | + * @param string $system_question_string |
|
| 288 | + * @return string|null if not found |
|
| 289 | + */ |
|
| 290 | + public function get_attendee_field_for_system_question($system_question_string) |
|
| 291 | + { |
|
| 292 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
| 293 | + ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
| 294 | + : null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 301 | + * |
|
| 302 | + * @return array |
|
| 303 | + */ |
|
| 304 | + public function system_question_to_attendee_field_mapping() |
|
| 305 | + { |
|
| 306 | + return $this->_system_question_to_attendee_field_name; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 313 | + * |
|
| 314 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 315 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 316 | + * @throws EE_Error |
|
| 317 | + */ |
|
| 318 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 319 | + { |
|
| 320 | + return $this->get_all( |
|
| 321 | + array( |
|
| 322 | + array( |
|
| 323 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 324 | + ? $transaction_id_or_obj->ID() |
|
| 325 | + : $transaction_id_or_obj, |
|
| 326 | + ), |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * retrieve a single attendee from db via their ID |
|
| 335 | + * |
|
| 336 | + * @param $ATT_ID |
|
| 337 | + * @return mixed array on success, FALSE on fail |
|
| 338 | + * @deprecated |
|
| 339 | + */ |
|
| 340 | + public function get_attendee_by_ID($ATT_ID = false) |
|
| 341 | + { |
|
| 342 | + // retrieve a particular EE_Attendee |
|
| 343 | + return $this->get_one_by_ID($ATT_ID); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * retrieve a single attendee from db via their ID |
|
| 350 | + * |
|
| 351 | + * @param array $where_cols_n_values |
|
| 352 | + * @return mixed array on success, FALSE on fail |
|
| 353 | + * @throws EE_Error |
|
| 354 | + */ |
|
| 355 | + public function get_attendee($where_cols_n_values = array()) |
|
| 356 | + { |
|
| 357 | + if (empty($where_cols_n_values)) { |
|
| 358 | + return false; |
|
| 359 | + } |
|
| 360 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 361 | + if (! empty($attendee)) { |
|
| 362 | + return array_shift($attendee); |
|
| 363 | + } |
|
| 364 | + return false; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Search for an existing Attendee record in the DB |
|
| 371 | + * |
|
| 372 | + * @param array $where_cols_n_values |
|
| 373 | + * @return bool|mixed |
|
| 374 | + * @throws EE_Error |
|
| 375 | + */ |
|
| 376 | + public function find_existing_attendee($where_cols_n_values = null) |
|
| 377 | + { |
|
| 378 | + // search by combo of first and last names plus the email address |
|
| 379 | + $attendee_data_keys = array( |
|
| 380 | + 'ATT_fname' => $this->_ATT_fname, |
|
| 381 | + 'ATT_lname' => $this->_ATT_lname, |
|
| 382 | + 'ATT_email' => $this->_ATT_email, |
|
| 383 | + ); |
|
| 384 | + // no search params means attendee object already exists. |
|
| 385 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 386 | + ? $where_cols_n_values |
|
| 387 | + : $attendee_data_keys; |
|
| 388 | + $valid_data = true; |
|
| 389 | + // check for required values |
|
| 390 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 391 | + ? $valid_data |
|
| 392 | + : false; |
|
| 393 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 394 | + ? $valid_data |
|
| 395 | + : false; |
|
| 396 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 397 | + ? $valid_data |
|
| 398 | + : false; |
|
| 399 | + if ($valid_data) { |
|
| 400 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
| 401 | + if ($attendee instanceof EE_Attendee) { |
|
| 402 | + return $attendee; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Takes an incoming array of EE_Registration ids |
|
| 412 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 413 | + * |
|
| 414 | + * @since 4.3.0 |
|
| 415 | + * @param array $ids array of EE_Registration ids |
|
| 416 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 417 | + * @throws EE_Error |
|
| 418 | + */ |
|
| 419 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
| 420 | + { |
|
| 421 | + $ids = (array)$ids; |
|
| 422 | + $_where = array( |
|
| 423 | + 'Registration.REG_ID' => array('in', $ids), |
|
| 424 | + ); |
|
| 425 | + return $this->get_all(array($_where)); |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | 428 | |
| 429 | 429 | } |
@@ -1,5 +1,4 @@ |
||
| 1 | 1 | <?php |
| 2 | -use EventEspresso\core\services\loaders\Loader; |
|
| 3 | 2 | use EventEspresso\core\services\orm\ModelFieldFactory; |
| 4 | 3 | |
| 5 | 4 | defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | return false; |
| 359 | 359 | } |
| 360 | 360 | $attendee = $this->get_all(array($where_cols_n_values)); |
| 361 | - if (! empty($attendee)) { |
|
| 361 | + if ( ! empty($attendee)) { |
|
| 362 | 362 | return array_shift($attendee); |
| 363 | 363 | } |
| 364 | 364 | return false; |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function get_array_of_contacts_from_reg_ids($ids) |
| 420 | 420 | { |
| 421 | - $ids = (array)$ids; |
|
| 421 | + $ids = (array) $ids; |
|
| 422 | 422 | $_where = array( |
| 423 | 423 | 'Registration.REG_ID' => array('in', $ids), |
| 424 | 424 | ); |
@@ -1,4 +1,4 @@ |
||
| 1 | -<?php use EventEspresso\core\services\orm\ModelFieldFactory; |
|
| 1 | +<?php |
|
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | 4 | exit('No direct script access allowed'); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
| 2 | 2 | |
| 3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 4 | - exit('No direct script access allowed'); |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
| 7 | 7 | |
@@ -18,789 +18,789 @@ discard block |
||
| 18 | 18 | class EEM_Event extends EEM_CPT_Base |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 23 | - * event |
|
| 24 | - */ |
|
| 25 | - const sold_out = 'sold_out'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 29 | - * date) |
|
| 30 | - */ |
|
| 31 | - const postponed = 'postponed'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * constant used by status(), indicating that the event will no longer occur |
|
| 35 | - */ |
|
| 36 | - const cancelled = 'cancelled'; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - protected static $_default_reg_status; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This is the default for the additional limit field. |
|
| 47 | - * @var int |
|
| 48 | - */ |
|
| 49 | - protected static $_default_additional_limit = 10; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * private instance of the Event object |
|
| 54 | - * |
|
| 55 | - * @var EEM_Event |
|
| 56 | - */ |
|
| 57 | - protected static $_instance; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 64 | - * |
|
| 65 | - * @param string $timezone |
|
| 66 | - * @throws \EE_Error |
|
| 67 | - */ |
|
| 68 | - protected function __construct($timezone = null) |
|
| 69 | - { |
|
| 70 | - EE_Registry::instance()->load_model('Registration'); |
|
| 71 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 72 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 73 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 74 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 75 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 76 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 77 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 78 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 79 | - $this->_custom_stati = apply_filters( |
|
| 80 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
| 81 | - array( |
|
| 82 | - EEM_Event::cancelled => array( |
|
| 83 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 84 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 85 | - ), |
|
| 86 | - EEM_Event::postponed => array( |
|
| 87 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 88 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 89 | - ), |
|
| 90 | - EEM_Event::sold_out => array( |
|
| 91 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 92 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 93 | - ), |
|
| 94 | - ) |
|
| 95 | - ); |
|
| 96 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 97 | - : self::$_default_reg_status; |
|
| 98 | - $this->_tables = array( |
|
| 99 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 100 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 101 | - ); |
|
| 102 | - $this->_fields = array( |
|
| 103 | - 'Event_CPT' => array( |
|
| 104 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
| 105 | - esc_html__('Post ID for Event', 'event_espresso')), |
|
| 106 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
| 107 | - false, |
|
| 108 | - ''), |
|
| 109 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
| 110 | - esc_html__('Event Description', 'event_espresso'), |
|
| 111 | - false, ''), |
|
| 112 | - 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
| 113 | - ''), |
|
| 114 | - 'EVT_created' => new EE_Datetime_Field('post_date', |
|
| 115 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 116 | - false, EE_Datetime_Field::now), |
|
| 117 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 118 | - esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
| 119 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 120 | - esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 121 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
| 122 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
| 123 | - false), |
|
| 124 | - 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
| 125 | - false, |
|
| 126 | - 0), |
|
| 127 | - 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
| 128 | - false, |
|
| 129 | - 1), |
|
| 130 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 131 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 132 | - 'status' => new EE_WP_Post_Status_Field('post_status', |
|
| 133 | - esc_html__('Event Status', 'event_espresso'), |
|
| 134 | - false, 'draft', $this->_custom_stati), |
|
| 135 | - ), |
|
| 136 | - 'Event_Meta' => array( |
|
| 137 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 138 | - esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
| 139 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 140 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 141 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 142 | - esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
| 143 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 144 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 145 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 146 | - esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 147 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 148 | - 'EVT_additional_limit', |
|
| 149 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 150 | - true, |
|
| 151 | - self::$_default_additional_limit |
|
| 152 | - ), |
|
| 153 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 154 | - 'EVT_default_registration_status', |
|
| 155 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 156 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 157 | - ), |
|
| 158 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 159 | - esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 160 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 162 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 163 | - esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 164 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 166 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 167 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 168 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 169 | - esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
| 170 | - ), |
|
| 171 | - ); |
|
| 172 | - $this->_model_relations = array( |
|
| 173 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 174 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
| 175 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 176 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 177 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 178 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 179 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 180 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 181 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 182 | - ); |
|
| 183 | - //this model is generally available for reading |
|
| 184 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 185 | - parent::__construct($timezone); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param string $default_reg_status |
|
| 192 | - */ |
|
| 193 | - public static function set_default_reg_status($default_reg_status) |
|
| 194 | - { |
|
| 195 | - self::$_default_reg_status = $default_reg_status; |
|
| 196 | - // if EEM_Event has already been instantiated, |
|
| 197 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 198 | - if (self::$_instance instanceof EEM_Event) { |
|
| 199 | - $default_reg_status = new EE_Enum_Text_Field( |
|
| 200 | - 'EVT_default_registration_status', |
|
| 201 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 202 | - false, |
|
| 203 | - $default_reg_status, |
|
| 204 | - EEM_Registration::reg_status_array() |
|
| 205 | - ); |
|
| 206 | - $default_reg_status->_construct_finalize( |
|
| 207 | - 'Event_Meta', |
|
| 208 | - 'EVT_default_registration_status', |
|
| 209 | - 'EEM_Event' |
|
| 210 | - ); |
|
| 211 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Used to override the default for the additional limit field. |
|
| 218 | - * @param $additional_limit |
|
| 219 | - */ |
|
| 220 | - public static function set_default_additional_limit($additional_limit) |
|
| 221 | - { |
|
| 222 | - self::$_default_additional_limit = (int) $additional_limit; |
|
| 223 | - if (self::$_instance instanceof EEM_Event) { |
|
| 224 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 225 | - 'EVT_additional_limit', |
|
| 226 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 227 | - true, |
|
| 228 | - self::$_default_additional_limit |
|
| 229 | - ); |
|
| 230 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 231 | - 'Event_Meta', |
|
| 232 | - 'EVT_additional_limit', |
|
| 233 | - 'EEM_Event' |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Return what is currently set as the default additional limit for the event. |
|
| 241 | - * @return int |
|
| 242 | - */ |
|
| 243 | - public static function get_default_additional_limit() |
|
| 244 | - { |
|
| 245 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * get_question_groups |
|
| 251 | - * |
|
| 252 | - * @return array |
|
| 253 | - * @throws \EE_Error |
|
| 254 | - */ |
|
| 255 | - public function get_all_question_groups() |
|
| 256 | - { |
|
| 257 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 258 | - array( |
|
| 259 | - array('QSG_deleted' => false), |
|
| 260 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * get_question_groups |
|
| 269 | - * |
|
| 270 | - * @param int $EVT_ID |
|
| 271 | - * @return array|bool |
|
| 272 | - * @throws \EE_Error |
|
| 273 | - */ |
|
| 274 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
| 275 | - { |
|
| 276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | - EE_Error::add_error( |
|
| 278 | - esc_html__( |
|
| 279 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 280 | - 'event_espresso' |
|
| 281 | - ), |
|
| 282 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 283 | - ); |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 287 | - array( |
|
| 288 | - array('EVT_ID' => $EVT_ID), |
|
| 289 | - ) |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * get_question_groups |
|
| 297 | - * |
|
| 298 | - * @param int $EVT_ID |
|
| 299 | - * @param boolean $for_primary_attendee |
|
| 300 | - * @return array|bool |
|
| 301 | - * @throws \EE_Error |
|
| 302 | - */ |
|
| 303 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 304 | - { |
|
| 305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | - EE_Error::add_error( |
|
| 307 | - esc_html__( |
|
| 308 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 309 | - 'event_espresso' |
|
| 310 | - ), |
|
| 311 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 312 | - ); |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 316 | - array( |
|
| 317 | - array( |
|
| 318 | - 'EVT_ID' => $EVT_ID, |
|
| 319 | - 'EQG_primary' => $for_primary_attendee, |
|
| 320 | - ), |
|
| 321 | - ) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * get_question_groups |
|
| 329 | - * |
|
| 330 | - * @param int $EVT_ID |
|
| 331 | - * @param EE_Registration $registration |
|
| 332 | - * @return array|bool |
|
| 333 | - * @throws \EE_Error |
|
| 334 | - */ |
|
| 335 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 336 | - { |
|
| 337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | - EE_Error::add_error( |
|
| 339 | - esc_html__( |
|
| 340 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 341 | - 'event_espresso' |
|
| 342 | - ), |
|
| 343 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 344 | - ); |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - $where_params = array( |
|
| 348 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 349 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 350 | - 'QSG_deleted' => false, |
|
| 351 | - ); |
|
| 352 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 353 | - array( |
|
| 354 | - $where_params, |
|
| 355 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 356 | - ) |
|
| 357 | - ); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * get_question_target_db_column |
|
| 364 | - * |
|
| 365 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
| 366 | - * @return array|bool |
|
| 367 | - * @throws \EE_Error |
|
| 368 | - */ |
|
| 369 | - public function get_questions_in_groups($QSG_IDs = '') |
|
| 370 | - { |
|
| 371 | - if (empty($QSG_IDs)) { |
|
| 372 | - EE_Error::add_error( |
|
| 373 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 374 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | - ); |
|
| 376 | - return false; |
|
| 377 | - } |
|
| 378 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 379 | - array( |
|
| 380 | - array( |
|
| 381 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 382 | - 'QST_deleted' => false, |
|
| 383 | - 'QST_admin_only' => is_admin(), |
|
| 384 | - ), |
|
| 385 | - 'order_by' => 'QST_order', |
|
| 386 | - ) |
|
| 387 | - ); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * get_options_for_question |
|
| 394 | - * |
|
| 395 | - * @param string $QST_IDs csv list of $QST IDs |
|
| 396 | - * @return array|bool |
|
| 397 | - * @throws \EE_Error |
|
| 398 | - */ |
|
| 399 | - public function get_options_for_question($QST_IDs) |
|
| 400 | - { |
|
| 401 | - if (empty($QST_IDs)) { |
|
| 402 | - EE_Error::add_error( |
|
| 403 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 404 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 405 | - ); |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 409 | - array( |
|
| 410 | - array( |
|
| 411 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 412 | - 'QSO_deleted' => false, |
|
| 413 | - ), |
|
| 414 | - 'order_by' => 'QSO_ID', |
|
| 415 | - ) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Gets all events that are published |
|
| 427 | - * and have event start time earlier than now and an event end time later than now |
|
| 428 | - * |
|
| 429 | - * @param array $query_params An array of query params to further filter on |
|
| 430 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 431 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 432 | - * @return EE_Event[]|int |
|
| 433 | - * @throws \EE_Error |
|
| 434 | - */ |
|
| 435 | - public function get_active_events($query_params, $count = false) |
|
| 436 | - { |
|
| 437 | - if (array_key_exists(0, $query_params)) { |
|
| 438 | - $where_params = $query_params[0]; |
|
| 439 | - unset($query_params[0]); |
|
| 440 | - } else { |
|
| 441 | - $where_params = array(); |
|
| 442 | - } |
|
| 443 | - // if we have count make sure we don't include group by |
|
| 444 | - if ($count && isset($query_params['group_by'])) { |
|
| 445 | - unset($query_params['group_by']); |
|
| 446 | - } |
|
| 447 | - // let's add specific query_params for active_events |
|
| 448 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 449 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 450 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 451 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 452 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 453 | - '<', |
|
| 454 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 455 | - ); |
|
| 456 | - } else { |
|
| 457 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 458 | - '<', |
|
| 459 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 460 | - ); |
|
| 461 | - } |
|
| 462 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 463 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 464 | - '>', |
|
| 465 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 466 | - ); |
|
| 467 | - } else { |
|
| 468 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 469 | - '>', |
|
| 470 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 471 | - ); |
|
| 472 | - } |
|
| 473 | - $query_params[0] = $where_params; |
|
| 474 | - // don't use $query_params with count() |
|
| 475 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 476 | - return $count |
|
| 477 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 478 | - : $this->get_all($query_params); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * get all events that are published and have an event start time later than now |
|
| 485 | - * |
|
| 486 | - * @param array $query_params An array of query params to further filter on |
|
| 487 | - * (Note that status and DTT_EVT_start will be overridden) |
|
| 488 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 489 | - * @return EE_Event[]|int |
|
| 490 | - * @throws \EE_Error |
|
| 491 | - */ |
|
| 492 | - public function get_upcoming_events($query_params, $count = false) |
|
| 493 | - { |
|
| 494 | - if (array_key_exists(0, $query_params)) { |
|
| 495 | - $where_params = $query_params[0]; |
|
| 496 | - unset($query_params[0]); |
|
| 497 | - } else { |
|
| 498 | - $where_params = array(); |
|
| 499 | - } |
|
| 500 | - // if we have count make sure we don't include group by |
|
| 501 | - if ($count && isset($query_params['group_by'])) { |
|
| 502 | - unset($query_params['group_by']); |
|
| 503 | - } |
|
| 504 | - // let's add specific query_params for active_events |
|
| 505 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 506 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 507 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 508 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 509 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 510 | - '>', |
|
| 511 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 512 | - ); |
|
| 513 | - } else { |
|
| 514 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 515 | - '>', |
|
| 516 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 517 | - ); |
|
| 518 | - } |
|
| 519 | - $query_params[0] = $where_params; |
|
| 520 | - // don't use $query_params with count() |
|
| 521 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 522 | - return $count |
|
| 523 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 524 | - : $this->get_all($query_params); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Gets all events that are published |
|
| 531 | - * and have an event end time later than now |
|
| 532 | - * |
|
| 533 | - * @param array $query_params An array of query params to further filter on |
|
| 534 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 535 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 536 | - * @return EE_Event[]|int |
|
| 537 | - * @throws \EE_Error |
|
| 538 | - */ |
|
| 539 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 540 | - { |
|
| 541 | - if (array_key_exists(0, $query_params)) { |
|
| 542 | - $where_params = $query_params[0]; |
|
| 543 | - unset($query_params[0]); |
|
| 544 | - } else { |
|
| 545 | - $where_params = array(); |
|
| 546 | - } |
|
| 547 | - // if we have count make sure we don't include group by |
|
| 548 | - if ($count && isset($query_params['group_by'])) { |
|
| 549 | - unset($query_params['group_by']); |
|
| 550 | - } |
|
| 551 | - // let's add specific query_params for active_events |
|
| 552 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 553 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 554 | - // add where params for DTT_EVT_end |
|
| 555 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 556 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 557 | - '>', |
|
| 558 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 559 | - ); |
|
| 560 | - } else { |
|
| 561 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 562 | - '>', |
|
| 563 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 564 | - ); |
|
| 565 | - } |
|
| 566 | - $query_params[0] = $where_params; |
|
| 567 | - // don't use $query_params with count() |
|
| 568 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 569 | - return $count |
|
| 570 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 571 | - : $this->get_all($query_params); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * This only returns events that are expired. |
|
| 578 | - * They may still be published but all their datetimes have expired. |
|
| 579 | - * |
|
| 580 | - * @param array $query_params An array of query params to further filter on |
|
| 581 | - * (note that status and DTT_EVT_end will be overridden) |
|
| 582 | - * @param bool $count whether to return the count or not (default FALSE) |
|
| 583 | - * @return EE_Event[]|int |
|
| 584 | - * @throws \EE_Error |
|
| 585 | - */ |
|
| 586 | - public function get_expired_events($query_params, $count = false) |
|
| 587 | - { |
|
| 588 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 589 | - // if we have count make sure we don't include group by |
|
| 590 | - if ($count && isset($query_params['group_by'])) { |
|
| 591 | - unset($query_params['group_by']); |
|
| 592 | - } |
|
| 593 | - // let's add specific query_params for active_events |
|
| 594 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
| 595 | - if (isset($where_params['status'])) { |
|
| 596 | - unset($where_params['status']); |
|
| 597 | - } |
|
| 598 | - $exclude_query = $query_params; |
|
| 599 | - if (isset($exclude_query[0])) { |
|
| 600 | - unset($exclude_query[0]); |
|
| 601 | - } |
|
| 602 | - $exclude_query[0] = array( |
|
| 603 | - 'Datetime.DTT_EVT_end' => array( |
|
| 604 | - '>', |
|
| 605 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 606 | - ), |
|
| 607 | - ); |
|
| 608 | - // first get all events that have datetimes where its not expired. |
|
| 609 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 610 | - $event_ids = array_keys($event_ids); |
|
| 611 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 612 | - $and_condition = array( |
|
| 613 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 614 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 615 | - ); |
|
| 616 | - if (isset($where_params['OR'])) { |
|
| 617 | - $and_condition['OR'] = $where_params['OR']; |
|
| 618 | - unset($where_params['OR']); |
|
| 619 | - } |
|
| 620 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 621 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 622 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 623 | - } |
|
| 624 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 625 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 626 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 627 | - } |
|
| 628 | - // merge remaining $where params with the and conditions. |
|
| 629 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 630 | - $query_params[0] = $where_params; |
|
| 631 | - // don't use $query_params with count() |
|
| 632 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 633 | - return $count |
|
| 634 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 635 | - : $this->get_all($query_params); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * This basically just returns the events that do not have the publish status. |
|
| 642 | - * |
|
| 643 | - * @param array $query_params An array of query params to further filter on |
|
| 644 | - * (note that status will be overwritten) |
|
| 645 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
| 646 | - * @return EE_Event[]|int |
|
| 647 | - * @throws \EE_Error |
|
| 648 | - */ |
|
| 649 | - public function get_inactive_events($query_params, $count = false) |
|
| 650 | - { |
|
| 651 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 652 | - // let's add in specific query_params for inactive events. |
|
| 653 | - if (isset($where_params['status'])) { |
|
| 654 | - unset($where_params['status']); |
|
| 655 | - } |
|
| 656 | - // if we have count make sure we don't include group by |
|
| 657 | - if ($count && isset($query_params['group_by'])) { |
|
| 658 | - unset($query_params['group_by']); |
|
| 659 | - } |
|
| 660 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 661 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 662 | - if (isset($where_params['OR'])) { |
|
| 663 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
| 664 | - unset($where_params['OR']); |
|
| 665 | - } |
|
| 666 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 667 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 668 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
| 669 | - } |
|
| 670 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 671 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 672 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
| 673 | - } |
|
| 674 | - $query_params[0] = $where_params; |
|
| 675 | - // don't use $query_params with count() |
|
| 676 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
| 677 | - return $count |
|
| 678 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 679 | - : $this->get_all($query_params); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 686 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 687 | - * attached to the event. See parent for param descriptions |
|
| 688 | - * |
|
| 689 | - * @param $id_or_obj |
|
| 690 | - * @param $other_model_id_or_obj |
|
| 691 | - * @param string $relationName |
|
| 692 | - * @param array $where_query |
|
| 693 | - * @return EE_Base_Class |
|
| 694 | - * @throws EE_Error |
|
| 695 | - */ |
|
| 696 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 697 | - { |
|
| 698 | - if ($relationName === 'Price') { |
|
| 699 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 700 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 701 | - //if EVT_ID = 0, then this is a default |
|
| 702 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 703 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 704 | - $prc_chk->set('PRC_ID', 0); |
|
| 705 | - } |
|
| 706 | - //run parent |
|
| 707 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 708 | - } |
|
| 709 | - //otherwise carry on as normal |
|
| 710 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /******************** DEPRECATED METHODS ********************/ |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * _get_question_target_db_column |
|
| 721 | - * |
|
| 722 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 723 | - * EE_Registration_Custom_Questions_Form located in |
|
| 724 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 725 | - * @access public |
|
| 726 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 727 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 728 | - * registration). |
|
| 729 | - * @throws EE_Error |
|
| 730 | - * @return array |
|
| 731 | - */ |
|
| 732 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 733 | - { |
|
| 734 | - if (empty($EVT_ID)) { |
|
| 735 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 736 | - 'event_espresso')); |
|
| 737 | - } |
|
| 738 | - $questions = array(); |
|
| 739 | - // get all question groups for event |
|
| 740 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 741 | - if (! empty($qgs)) { |
|
| 742 | - foreach ($qgs as $qg) { |
|
| 743 | - $qsts = $qg->questions(); |
|
| 744 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 745 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 746 | - foreach ($qsts as $qst) { |
|
| 747 | - if ($qst->is_system_question()) { |
|
| 748 | - continue; |
|
| 749 | - } |
|
| 750 | - $answer = EEM_Answer::instance()->get_one(array( |
|
| 751 | - array( |
|
| 752 | - 'QST_ID' => $qst->ID(), |
|
| 753 | - 'REG_ID' => $registration->ID(), |
|
| 754 | - ), |
|
| 755 | - )); |
|
| 756 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 757 | - $qst_name = $qstn_id = $qst->ID(); |
|
| 758 | - $ans_id = $answer->ID(); |
|
| 759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 760 | - $input_name = ''; |
|
| 761 | - $input_id = sanitize_key($qst->display_text()); |
|
| 762 | - $input_class = ''; |
|
| 763 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 764 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
| 765 | - . $input_name |
|
| 766 | - . $qst_name; |
|
| 767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 768 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 769 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 770 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 771 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 772 | - //leave responses as-is, don't convert stuff into html entities please! |
|
| 773 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 774 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 775 | - $QSOs = $qst->options(true, $answer->value()); |
|
| 776 | - if (is_array($QSOs)) { |
|
| 777 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 778 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - return $questions; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - /** |
|
| 790 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 791 | - * or an stdClass where each property is the name of a column, |
|
| 792 | - * @return EE_Base_Class |
|
| 793 | - * @throws \EE_Error |
|
| 794 | - */ |
|
| 795 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 796 | - { |
|
| 797 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 798 | - if($classInstance instanceof EE_Event) { |
|
| 799 | - //events have their timezone defined in the DB, so use it immediately |
|
| 800 | - $this->set_timezone($classInstance->get_timezone()); |
|
| 801 | - } |
|
| 802 | - return $classInstance; |
|
| 803 | - } |
|
| 21 | + /** |
|
| 22 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
| 23 | + * event |
|
| 24 | + */ |
|
| 25 | + const sold_out = 'sold_out'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
| 29 | + * date) |
|
| 30 | + */ |
|
| 31 | + const postponed = 'postponed'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * constant used by status(), indicating that the event will no longer occur |
|
| 35 | + */ |
|
| 36 | + const cancelled = 'cancelled'; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + protected static $_default_reg_status; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This is the default for the additional limit field. |
|
| 47 | + * @var int |
|
| 48 | + */ |
|
| 49 | + protected static $_default_additional_limit = 10; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * private instance of the Event object |
|
| 54 | + * |
|
| 55 | + * @var EEM_Event |
|
| 56 | + */ |
|
| 57 | + protected static $_instance; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
| 64 | + * |
|
| 65 | + * @param string $timezone |
|
| 66 | + * @throws \EE_Error |
|
| 67 | + */ |
|
| 68 | + protected function __construct($timezone = null) |
|
| 69 | + { |
|
| 70 | + EE_Registry::instance()->load_model('Registration'); |
|
| 71 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
| 72 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
| 73 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
| 74 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
| 75 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
| 76 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
| 77 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
| 78 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
| 79 | + $this->_custom_stati = apply_filters( |
|
| 80 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
| 81 | + array( |
|
| 82 | + EEM_Event::cancelled => array( |
|
| 83 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
| 84 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
| 85 | + ), |
|
| 86 | + EEM_Event::postponed => array( |
|
| 87 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
| 88 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
| 89 | + ), |
|
| 90 | + EEM_Event::sold_out => array( |
|
| 91 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
| 92 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
| 93 | + ), |
|
| 94 | + ) |
|
| 95 | + ); |
|
| 96 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
| 97 | + : self::$_default_reg_status; |
|
| 98 | + $this->_tables = array( |
|
| 99 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 100 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
| 101 | + ); |
|
| 102 | + $this->_fields = array( |
|
| 103 | + 'Event_CPT' => array( |
|
| 104 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
| 105 | + esc_html__('Post ID for Event', 'event_espresso')), |
|
| 106 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
| 107 | + false, |
|
| 108 | + ''), |
|
| 109 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
| 110 | + esc_html__('Event Description', 'event_espresso'), |
|
| 111 | + false, ''), |
|
| 112 | + 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
| 113 | + ''), |
|
| 114 | + 'EVT_created' => new EE_Datetime_Field('post_date', |
|
| 115 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
| 116 | + false, EE_Datetime_Field::now), |
|
| 117 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
| 118 | + esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
| 119 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
| 120 | + esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
| 121 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
| 122 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
| 123 | + false), |
|
| 124 | + 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
| 125 | + false, |
|
| 126 | + 0), |
|
| 127 | + 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
| 128 | + false, |
|
| 129 | + 1), |
|
| 130 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
| 131 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
| 132 | + 'status' => new EE_WP_Post_Status_Field('post_status', |
|
| 133 | + esc_html__('Event Status', 'event_espresso'), |
|
| 134 | + false, 'draft', $this->_custom_stati), |
|
| 135 | + ), |
|
| 136 | + 'Event_Meta' => array( |
|
| 137 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
| 138 | + esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
| 139 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
| 140 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
| 141 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
| 142 | + esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
| 143 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
| 144 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
| 145 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
| 146 | + esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
| 147 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
| 148 | + 'EVT_additional_limit', |
|
| 149 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 150 | + true, |
|
| 151 | + self::$_default_additional_limit |
|
| 152 | + ), |
|
| 153 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
| 154 | + 'EVT_default_registration_status', |
|
| 155 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
| 156 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
| 157 | + ), |
|
| 158 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
| 159 | + esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
| 160 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
| 161 | + esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 162 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
| 163 | + esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
| 164 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
| 165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 166 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
| 167 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
| 168 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
| 169 | + esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
| 170 | + ), |
|
| 171 | + ); |
|
| 172 | + $this->_model_relations = array( |
|
| 173 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 174 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
| 175 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
| 176 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
| 177 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 178 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 179 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
| 180 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
| 181 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 182 | + ); |
|
| 183 | + //this model is generally available for reading |
|
| 184 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 185 | + parent::__construct($timezone); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param string $default_reg_status |
|
| 192 | + */ |
|
| 193 | + public static function set_default_reg_status($default_reg_status) |
|
| 194 | + { |
|
| 195 | + self::$_default_reg_status = $default_reg_status; |
|
| 196 | + // if EEM_Event has already been instantiated, |
|
| 197 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
| 198 | + if (self::$_instance instanceof EEM_Event) { |
|
| 199 | + $default_reg_status = new EE_Enum_Text_Field( |
|
| 200 | + 'EVT_default_registration_status', |
|
| 201 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
| 202 | + false, |
|
| 203 | + $default_reg_status, |
|
| 204 | + EEM_Registration::reg_status_array() |
|
| 205 | + ); |
|
| 206 | + $default_reg_status->_construct_finalize( |
|
| 207 | + 'Event_Meta', |
|
| 208 | + 'EVT_default_registration_status', |
|
| 209 | + 'EEM_Event' |
|
| 210 | + ); |
|
| 211 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Used to override the default for the additional limit field. |
|
| 218 | + * @param $additional_limit |
|
| 219 | + */ |
|
| 220 | + public static function set_default_additional_limit($additional_limit) |
|
| 221 | + { |
|
| 222 | + self::$_default_additional_limit = (int) $additional_limit; |
|
| 223 | + if (self::$_instance instanceof EEM_Event) { |
|
| 224 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
| 225 | + 'EVT_additional_limit', |
|
| 226 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
| 227 | + true, |
|
| 228 | + self::$_default_additional_limit |
|
| 229 | + ); |
|
| 230 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
| 231 | + 'Event_Meta', |
|
| 232 | + 'EVT_additional_limit', |
|
| 233 | + 'EEM_Event' |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Return what is currently set as the default additional limit for the event. |
|
| 241 | + * @return int |
|
| 242 | + */ |
|
| 243 | + public static function get_default_additional_limit() |
|
| 244 | + { |
|
| 245 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * get_question_groups |
|
| 251 | + * |
|
| 252 | + * @return array |
|
| 253 | + * @throws \EE_Error |
|
| 254 | + */ |
|
| 255 | + public function get_all_question_groups() |
|
| 256 | + { |
|
| 257 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 258 | + array( |
|
| 259 | + array('QSG_deleted' => false), |
|
| 260 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * get_question_groups |
|
| 269 | + * |
|
| 270 | + * @param int $EVT_ID |
|
| 271 | + * @return array|bool |
|
| 272 | + * @throws \EE_Error |
|
| 273 | + */ |
|
| 274 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
| 275 | + { |
|
| 276 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | + EE_Error::add_error( |
|
| 278 | + esc_html__( |
|
| 279 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 280 | + 'event_espresso' |
|
| 281 | + ), |
|
| 282 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 283 | + ); |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 287 | + array( |
|
| 288 | + array('EVT_ID' => $EVT_ID), |
|
| 289 | + ) |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * get_question_groups |
|
| 297 | + * |
|
| 298 | + * @param int $EVT_ID |
|
| 299 | + * @param boolean $for_primary_attendee |
|
| 300 | + * @return array|bool |
|
| 301 | + * @throws \EE_Error |
|
| 302 | + */ |
|
| 303 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
| 304 | + { |
|
| 305 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | + EE_Error::add_error( |
|
| 307 | + esc_html__( |
|
| 308 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
| 309 | + 'event_espresso' |
|
| 310 | + ), |
|
| 311 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 312 | + ); |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
| 316 | + array( |
|
| 317 | + array( |
|
| 318 | + 'EVT_ID' => $EVT_ID, |
|
| 319 | + 'EQG_primary' => $for_primary_attendee, |
|
| 320 | + ), |
|
| 321 | + ) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * get_question_groups |
|
| 329 | + * |
|
| 330 | + * @param int $EVT_ID |
|
| 331 | + * @param EE_Registration $registration |
|
| 332 | + * @return array|bool |
|
| 333 | + * @throws \EE_Error |
|
| 334 | + */ |
|
| 335 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
| 336 | + { |
|
| 337 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | + EE_Error::add_error( |
|
| 339 | + esc_html__( |
|
| 340 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
| 341 | + 'event_espresso' |
|
| 342 | + ), |
|
| 343 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 344 | + ); |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + $where_params = array( |
|
| 348 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
| 349 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 350 | + 'QSG_deleted' => false, |
|
| 351 | + ); |
|
| 352 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
| 353 | + array( |
|
| 354 | + $where_params, |
|
| 355 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 356 | + ) |
|
| 357 | + ); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * get_question_target_db_column |
|
| 364 | + * |
|
| 365 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
| 366 | + * @return array|bool |
|
| 367 | + * @throws \EE_Error |
|
| 368 | + */ |
|
| 369 | + public function get_questions_in_groups($QSG_IDs = '') |
|
| 370 | + { |
|
| 371 | + if (empty($QSG_IDs)) { |
|
| 372 | + EE_Error::add_error( |
|
| 373 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
| 374 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 375 | + ); |
|
| 376 | + return false; |
|
| 377 | + } |
|
| 378 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
| 379 | + array( |
|
| 380 | + array( |
|
| 381 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
| 382 | + 'QST_deleted' => false, |
|
| 383 | + 'QST_admin_only' => is_admin(), |
|
| 384 | + ), |
|
| 385 | + 'order_by' => 'QST_order', |
|
| 386 | + ) |
|
| 387 | + ); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * get_options_for_question |
|
| 394 | + * |
|
| 395 | + * @param string $QST_IDs csv list of $QST IDs |
|
| 396 | + * @return array|bool |
|
| 397 | + * @throws \EE_Error |
|
| 398 | + */ |
|
| 399 | + public function get_options_for_question($QST_IDs) |
|
| 400 | + { |
|
| 401 | + if (empty($QST_IDs)) { |
|
| 402 | + EE_Error::add_error( |
|
| 403 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
| 404 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 405 | + ); |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
| 409 | + array( |
|
| 410 | + array( |
|
| 411 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
| 412 | + 'QSO_deleted' => false, |
|
| 413 | + ), |
|
| 414 | + 'order_by' => 'QSO_ID', |
|
| 415 | + ) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Gets all events that are published |
|
| 427 | + * and have event start time earlier than now and an event end time later than now |
|
| 428 | + * |
|
| 429 | + * @param array $query_params An array of query params to further filter on |
|
| 430 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
| 431 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 432 | + * @return EE_Event[]|int |
|
| 433 | + * @throws \EE_Error |
|
| 434 | + */ |
|
| 435 | + public function get_active_events($query_params, $count = false) |
|
| 436 | + { |
|
| 437 | + if (array_key_exists(0, $query_params)) { |
|
| 438 | + $where_params = $query_params[0]; |
|
| 439 | + unset($query_params[0]); |
|
| 440 | + } else { |
|
| 441 | + $where_params = array(); |
|
| 442 | + } |
|
| 443 | + // if we have count make sure we don't include group by |
|
| 444 | + if ($count && isset($query_params['group_by'])) { |
|
| 445 | + unset($query_params['group_by']); |
|
| 446 | + } |
|
| 447 | + // let's add specific query_params for active_events |
|
| 448 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 449 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 450 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
| 451 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 452 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
| 453 | + '<', |
|
| 454 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 455 | + ); |
|
| 456 | + } else { |
|
| 457 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 458 | + '<', |
|
| 459 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 460 | + ); |
|
| 461 | + } |
|
| 462 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 463 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 464 | + '>', |
|
| 465 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 466 | + ); |
|
| 467 | + } else { |
|
| 468 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 469 | + '>', |
|
| 470 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 471 | + ); |
|
| 472 | + } |
|
| 473 | + $query_params[0] = $where_params; |
|
| 474 | + // don't use $query_params with count() |
|
| 475 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 476 | + return $count |
|
| 477 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 478 | + : $this->get_all($query_params); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * get all events that are published and have an event start time later than now |
|
| 485 | + * |
|
| 486 | + * @param array $query_params An array of query params to further filter on |
|
| 487 | + * (Note that status and DTT_EVT_start will be overridden) |
|
| 488 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 489 | + * @return EE_Event[]|int |
|
| 490 | + * @throws \EE_Error |
|
| 491 | + */ |
|
| 492 | + public function get_upcoming_events($query_params, $count = false) |
|
| 493 | + { |
|
| 494 | + if (array_key_exists(0, $query_params)) { |
|
| 495 | + $where_params = $query_params[0]; |
|
| 496 | + unset($query_params[0]); |
|
| 497 | + } else { |
|
| 498 | + $where_params = array(); |
|
| 499 | + } |
|
| 500 | + // if we have count make sure we don't include group by |
|
| 501 | + if ($count && isset($query_params['group_by'])) { |
|
| 502 | + unset($query_params['group_by']); |
|
| 503 | + } |
|
| 504 | + // let's add specific query_params for active_events |
|
| 505 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 506 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 507 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
| 508 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 509 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
| 510 | + '>', |
|
| 511 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 512 | + ); |
|
| 513 | + } else { |
|
| 514 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
| 515 | + '>', |
|
| 516 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
| 517 | + ); |
|
| 518 | + } |
|
| 519 | + $query_params[0] = $where_params; |
|
| 520 | + // don't use $query_params with count() |
|
| 521 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 522 | + return $count |
|
| 523 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 524 | + : $this->get_all($query_params); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Gets all events that are published |
|
| 531 | + * and have an event end time later than now |
|
| 532 | + * |
|
| 533 | + * @param array $query_params An array of query params to further filter on |
|
| 534 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 535 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 536 | + * @return EE_Event[]|int |
|
| 537 | + * @throws \EE_Error |
|
| 538 | + */ |
|
| 539 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
| 540 | + { |
|
| 541 | + if (array_key_exists(0, $query_params)) { |
|
| 542 | + $where_params = $query_params[0]; |
|
| 543 | + unset($query_params[0]); |
|
| 544 | + } else { |
|
| 545 | + $where_params = array(); |
|
| 546 | + } |
|
| 547 | + // if we have count make sure we don't include group by |
|
| 548 | + if ($count && isset($query_params['group_by'])) { |
|
| 549 | + unset($query_params['group_by']); |
|
| 550 | + } |
|
| 551 | + // let's add specific query_params for active_events |
|
| 552 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 553 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
| 554 | + // add where params for DTT_EVT_end |
|
| 555 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 556 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
| 557 | + '>', |
|
| 558 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 559 | + ); |
|
| 560 | + } else { |
|
| 561 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
| 562 | + '>', |
|
| 563 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 564 | + ); |
|
| 565 | + } |
|
| 566 | + $query_params[0] = $where_params; |
|
| 567 | + // don't use $query_params with count() |
|
| 568 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 569 | + return $count |
|
| 570 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 571 | + : $this->get_all($query_params); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * This only returns events that are expired. |
|
| 578 | + * They may still be published but all their datetimes have expired. |
|
| 579 | + * |
|
| 580 | + * @param array $query_params An array of query params to further filter on |
|
| 581 | + * (note that status and DTT_EVT_end will be overridden) |
|
| 582 | + * @param bool $count whether to return the count or not (default FALSE) |
|
| 583 | + * @return EE_Event[]|int |
|
| 584 | + * @throws \EE_Error |
|
| 585 | + */ |
|
| 586 | + public function get_expired_events($query_params, $count = false) |
|
| 587 | + { |
|
| 588 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 589 | + // if we have count make sure we don't include group by |
|
| 590 | + if ($count && isset($query_params['group_by'])) { |
|
| 591 | + unset($query_params['group_by']); |
|
| 592 | + } |
|
| 593 | + // let's add specific query_params for active_events |
|
| 594 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
| 595 | + if (isset($where_params['status'])) { |
|
| 596 | + unset($where_params['status']); |
|
| 597 | + } |
|
| 598 | + $exclude_query = $query_params; |
|
| 599 | + if (isset($exclude_query[0])) { |
|
| 600 | + unset($exclude_query[0]); |
|
| 601 | + } |
|
| 602 | + $exclude_query[0] = array( |
|
| 603 | + 'Datetime.DTT_EVT_end' => array( |
|
| 604 | + '>', |
|
| 605 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 606 | + ), |
|
| 607 | + ); |
|
| 608 | + // first get all events that have datetimes where its not expired. |
|
| 609 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
| 610 | + $event_ids = array_keys($event_ids); |
|
| 611 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 612 | + $and_condition = array( |
|
| 613 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
| 614 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
| 615 | + ); |
|
| 616 | + if (isset($where_params['OR'])) { |
|
| 617 | + $and_condition['OR'] = $where_params['OR']; |
|
| 618 | + unset($where_params['OR']); |
|
| 619 | + } |
|
| 620 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 621 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 622 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 623 | + } |
|
| 624 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 625 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 626 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 627 | + } |
|
| 628 | + // merge remaining $where params with the and conditions. |
|
| 629 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
| 630 | + $query_params[0] = $where_params; |
|
| 631 | + // don't use $query_params with count() |
|
| 632 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 633 | + return $count |
|
| 634 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 635 | + : $this->get_all($query_params); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * This basically just returns the events that do not have the publish status. |
|
| 642 | + * |
|
| 643 | + * @param array $query_params An array of query params to further filter on |
|
| 644 | + * (note that status will be overwritten) |
|
| 645 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
| 646 | + * @return EE_Event[]|int |
|
| 647 | + * @throws \EE_Error |
|
| 648 | + */ |
|
| 649 | + public function get_inactive_events($query_params, $count = false) |
|
| 650 | + { |
|
| 651 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
| 652 | + // let's add in specific query_params for inactive events. |
|
| 653 | + if (isset($where_params['status'])) { |
|
| 654 | + unset($where_params['status']); |
|
| 655 | + } |
|
| 656 | + // if we have count make sure we don't include group by |
|
| 657 | + if ($count && isset($query_params['group_by'])) { |
|
| 658 | + unset($query_params['group_by']); |
|
| 659 | + } |
|
| 660 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
| 661 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
| 662 | + if (isset($where_params['OR'])) { |
|
| 663 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
| 664 | + unset($where_params['OR']); |
|
| 665 | + } |
|
| 666 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
| 667 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
| 668 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
| 669 | + } |
|
| 670 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
| 671 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
| 672 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
| 673 | + } |
|
| 674 | + $query_params[0] = $where_params; |
|
| 675 | + // don't use $query_params with count() |
|
| 676 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
| 677 | + return $count |
|
| 678 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
| 679 | + : $this->get_all($query_params); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
| 686 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
| 687 | + * attached to the event. See parent for param descriptions |
|
| 688 | + * |
|
| 689 | + * @param $id_or_obj |
|
| 690 | + * @param $other_model_id_or_obj |
|
| 691 | + * @param string $relationName |
|
| 692 | + * @param array $where_query |
|
| 693 | + * @return EE_Base_Class |
|
| 694 | + * @throws EE_Error |
|
| 695 | + */ |
|
| 696 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
| 697 | + { |
|
| 698 | + if ($relationName === 'Price') { |
|
| 699 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
| 700 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
| 701 | + //if EVT_ID = 0, then this is a default |
|
| 702 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
| 703 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
| 704 | + $prc_chk->set('PRC_ID', 0); |
|
| 705 | + } |
|
| 706 | + //run parent |
|
| 707 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
| 708 | + } |
|
| 709 | + //otherwise carry on as normal |
|
| 710 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /******************** DEPRECATED METHODS ********************/ |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * _get_question_target_db_column |
|
| 721 | + * |
|
| 722 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
| 723 | + * EE_Registration_Custom_Questions_Form located in |
|
| 724 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
| 725 | + * @access public |
|
| 726 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
| 727 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
| 728 | + * registration). |
|
| 729 | + * @throws EE_Error |
|
| 730 | + * @return array |
|
| 731 | + */ |
|
| 732 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
| 733 | + { |
|
| 734 | + if (empty($EVT_ID)) { |
|
| 735 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
| 736 | + 'event_espresso')); |
|
| 737 | + } |
|
| 738 | + $questions = array(); |
|
| 739 | + // get all question groups for event |
|
| 740 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
| 741 | + if (! empty($qgs)) { |
|
| 742 | + foreach ($qgs as $qg) { |
|
| 743 | + $qsts = $qg->questions(); |
|
| 744 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
| 745 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
| 746 | + foreach ($qsts as $qst) { |
|
| 747 | + if ($qst->is_system_question()) { |
|
| 748 | + continue; |
|
| 749 | + } |
|
| 750 | + $answer = EEM_Answer::instance()->get_one(array( |
|
| 751 | + array( |
|
| 752 | + 'QST_ID' => $qst->ID(), |
|
| 753 | + 'REG_ID' => $registration->ID(), |
|
| 754 | + ), |
|
| 755 | + )); |
|
| 756 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
| 757 | + $qst_name = $qstn_id = $qst->ID(); |
|
| 758 | + $ans_id = $answer->ID(); |
|
| 759 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 760 | + $input_name = ''; |
|
| 761 | + $input_id = sanitize_key($qst->display_text()); |
|
| 762 | + $input_class = ''; |
|
| 763 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
| 764 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
| 765 | + . $input_name |
|
| 766 | + . $qst_name; |
|
| 767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 768 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
| 769 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
| 770 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
| 771 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
| 772 | + //leave responses as-is, don't convert stuff into html entities please! |
|
| 773 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
| 774 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
| 775 | + $QSOs = $qst->options(true, $answer->value()); |
|
| 776 | + if (is_array($QSOs)) { |
|
| 777 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
| 778 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + return $questions; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + /** |
|
| 790 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
| 791 | + * or an stdClass where each property is the name of a column, |
|
| 792 | + * @return EE_Base_Class |
|
| 793 | + * @throws \EE_Error |
|
| 794 | + */ |
|
| 795 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
| 796 | + { |
|
| 797 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
| 798 | + if($classInstance instanceof EE_Event) { |
|
| 799 | + //events have their timezone defined in the DB, so use it immediately |
|
| 800 | + $this->set_timezone($classInstance->get_timezone()); |
|
| 801 | + } |
|
| 802 | + return $classInstance; |
|
| 803 | + } |
|
| 804 | 804 | } |
| 805 | 805 | // End of file EEM_Event.model.php |
| 806 | 806 | // Location: /includes/models/EEM_Event.model.php |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\services\orm\ModelFieldFactory; |
| 2 | 2 | |
| 3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | } |
| 6 | -require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
| 6 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
| 159 | 159 | esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
| 160 | 160 | 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
| 161 | - esc_html__('Event Phone Number', 'event_espresso'), false,''), |
|
| 161 | + esc_html__('Event Phone Number', 'event_espresso'), false, ''), |
|
| 162 | 162 | 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
| 163 | 163 | esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
| 164 | 164 | 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
| 165 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false,''), |
|
| 165 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false, ''), |
|
| 166 | 166 | 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
| 167 | 167 | esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
| 168 | 168 | 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | */ |
| 274 | 274 | public function get_all_event_question_groups($EVT_ID = 0) |
| 275 | 275 | { |
| 276 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 276 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 277 | 277 | EE_Error::add_error( |
| 278 | 278 | esc_html__( |
| 279 | 279 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
| 304 | 304 | { |
| 305 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 305 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 306 | 306 | EE_Error::add_error( |
| 307 | 307 | esc_html__( |
| 308 | 308 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | */ |
| 335 | 335 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
| 336 | 336 | { |
| 337 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 337 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
| 338 | 338 | EE_Error::add_error( |
| 339 | 339 | esc_html__( |
| 340 | 340 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | $questions = array(); |
| 739 | 739 | // get all question groups for event |
| 740 | 740 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
| 741 | - if (! empty($qgs)) { |
|
| 741 | + if ( ! empty($qgs)) { |
|
| 742 | 742 | foreach ($qgs as $qg) { |
| 743 | 743 | $qsts = $qg->questions(); |
| 744 | 744 | $questions[$qg->ID()] = $qg->model_field_array(); |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
| 757 | 757 | $qst_name = $qstn_id = $qst->ID(); |
| 758 | 758 | $ans_id = $answer->ID(); |
| 759 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
| 759 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
| 760 | 760 | $input_name = ''; |
| 761 | 761 | $input_id = sanitize_key($qst->display_text()); |
| 762 | 762 | $input_class = ''; |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
| 765 | 765 | . $input_name |
| 766 | 766 | . $qst_name; |
| 767 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
| 767 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
| 768 | 768 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
| 769 | 769 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
| 770 | 770 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
@@ -795,7 +795,7 @@ discard block |
||
| 795 | 795 | public function instantiate_class_from_array_or_object($cols_n_values) |
| 796 | 796 | { |
| 797 | 797 | $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
| 798 | - if($classInstance instanceof EE_Event) { |
|
| 798 | + if ($classInstance instanceof EE_Event) { |
|
| 799 | 799 | //events have their timezone defined in the DB, so use it immediately |
| 800 | 800 | $this->set_timezone($classInstance->get_timezone()); |
| 801 | 801 | } |
@@ -132,7 +132,6 @@ discard block |
||
| 132 | 132 | /** |
| 133 | 133 | * @param string $table_column |
| 134 | 134 | * @param string $nice_name |
| 135 | - * @param string $timezone_string |
|
| 136 | 135 | * @param bool $nullable |
| 137 | 136 | * @param string $default_value |
| 138 | 137 | * @throws EE_Error |
@@ -179,7 +178,7 @@ discard block |
||
| 179 | 178 | * @param string $table_column |
| 180 | 179 | * @param string $nice_name |
| 181 | 180 | * @param bool $nullable |
| 182 | - * @param null $default_value |
|
| 181 | + * @param integer $default_value |
|
| 183 | 182 | * @return EE_DB_Only_Int_Field |
| 184 | 183 | */ |
| 185 | 184 | public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
@@ -295,7 +294,7 @@ discard block |
||
| 295 | 294 | * @param string $table_column |
| 296 | 295 | * @param string $nice_name |
| 297 | 296 | * @param bool $nullable |
| 298 | - * @param null $default_value |
|
| 297 | + * @param integer $default_value |
|
| 299 | 298 | * @param string $model_name |
| 300 | 299 | * @return EE_Foreign_Key_Int_Field |
| 301 | 300 | */ |
@@ -313,7 +312,7 @@ discard block |
||
| 313 | 312 | * @param string $table_column |
| 314 | 313 | * @param string $nice_name |
| 315 | 314 | * @param bool $nullable |
| 316 | - * @param null $default_value |
|
| 315 | + * @param string $default_value |
|
| 317 | 316 | * @param string $model_name |
| 318 | 317 | * @return EE_Foreign_Key_String_Field |
| 319 | 318 | */ |
@@ -564,7 +563,7 @@ discard block |
||
| 564 | 563 | * @param string $table_column |
| 565 | 564 | * @param string $nice_name |
| 566 | 565 | * @param bool $nullable |
| 567 | - * @param mixed $default_value |
|
| 566 | + * @param string $default_value |
|
| 568 | 567 | * @param array $values If additional stati are to be used other than the default WP statuses, |
| 569 | 568 | * then they can be registered via this property. |
| 570 | 569 | * The format of the array should be as follows: |
@@ -33,9 +33,6 @@ |
||
| 33 | 33 | use EE_WP_Post_Status_Field; |
| 34 | 34 | use EE_WP_Post_Type_Field; |
| 35 | 35 | use EE_WP_User_Field; |
| 36 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
| 37 | -use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
| 38 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
| 39 | 36 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 40 | 37 | use InvalidArgumentException; |
| 41 | 38 | |
@@ -53,576 +53,576 @@ |
||
| 53 | 53 | class ModelFieldFactory |
| 54 | 54 | { |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var LoaderInterface $loader |
|
| 58 | - */ |
|
| 59 | - private $loader; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * ModelFieldFactory constructor. |
|
| 65 | - * |
|
| 66 | - * @param LoaderInterface $loader |
|
| 67 | - */ |
|
| 68 | - public function __construct(LoaderInterface $loader) |
|
| 69 | - { |
|
| 70 | - $this->loader = $loader; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $table_column |
|
| 77 | - * @param string $nice_name |
|
| 78 | - * @param bool $nullable |
|
| 79 | - * @param null $default_value |
|
| 80 | - * @return EE_All_Caps_Text_Field |
|
| 81 | - */ |
|
| 82 | - public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 83 | - { |
|
| 84 | - return $this->loader->getNew( |
|
| 85 | - 'EE_All_Caps_Text_Field', |
|
| 86 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $table_column |
|
| 94 | - * @param string $nice_name |
|
| 95 | - * @param bool $nullable |
|
| 96 | - * @param null $default_value |
|
| 97 | - * @param string $model_name |
|
| 98 | - * @return EE_Any_Foreign_Model_Name_Field |
|
| 99 | - */ |
|
| 100 | - public function createAnyForeignModelNameField( |
|
| 101 | - $table_column, |
|
| 102 | - $nice_name, |
|
| 103 | - $nullable, |
|
| 104 | - $default_value = null, |
|
| 105 | - $model_name |
|
| 106 | - ) { |
|
| 107 | - return $this->loader->getNew( |
|
| 108 | - 'EE_Any_Foreign_Model_Name_Field', |
|
| 109 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $table_column |
|
| 117 | - * @param string $nice_name |
|
| 118 | - * @param bool $nullable |
|
| 119 | - * @param null $default_value |
|
| 120 | - * @return EE_Boolean_Field |
|
| 121 | - */ |
|
| 122 | - public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 123 | - { |
|
| 124 | - return $this->loader->getNew( |
|
| 125 | - 'EE_Boolean_Field', |
|
| 126 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param string $table_column |
|
| 134 | - * @param string $nice_name |
|
| 135 | - * @param string $timezone_string |
|
| 136 | - * @param bool $nullable |
|
| 137 | - * @param string $default_value |
|
| 138 | - * @throws EE_Error |
|
| 139 | - * @throws InvalidArgumentException |
|
| 140 | - * @return EE_Datetime_Field |
|
| 141 | - */ |
|
| 142 | - public function createDatetimeField( |
|
| 143 | - $table_column, |
|
| 144 | - $nice_name, |
|
| 145 | - $nullable = false, |
|
| 146 | - $default_value = EE_Datetime_Field::now |
|
| 147 | - ) { |
|
| 148 | - return $this->loader->getNew( |
|
| 149 | - 'EE_Datetime_Field', |
|
| 150 | - array( |
|
| 151 | - $table_column, |
|
| 152 | - $nice_name, |
|
| 153 | - $nullable, |
|
| 154 | - $default_value |
|
| 155 | - ) |
|
| 156 | - ); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param string $table_column |
|
| 163 | - * @param string $nice_name |
|
| 164 | - * @param bool $nullable |
|
| 165 | - * @param null $default_value |
|
| 166 | - * @return EE_DB_Only_Float_Field |
|
| 167 | - */ |
|
| 168 | - public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 169 | - { |
|
| 170 | - return $this->loader->getNew( |
|
| 171 | - 'EE_DB_Only_Float_Field', |
|
| 172 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 173 | - ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param string $table_column |
|
| 180 | - * @param string $nice_name |
|
| 181 | - * @param bool $nullable |
|
| 182 | - * @param null $default_value |
|
| 183 | - * @return EE_DB_Only_Int_Field |
|
| 184 | - */ |
|
| 185 | - public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 186 | - { |
|
| 187 | - return $this->loader->getNew( |
|
| 188 | - 'EE_DB_Only_Int_Field', |
|
| 189 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $table_column |
|
| 197 | - * @param string $nice_name |
|
| 198 | - * @param bool $nullable |
|
| 199 | - * @param null $default_value |
|
| 200 | - * @return EE_DB_Only_Text_Field |
|
| 201 | - */ |
|
| 202 | - public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 203 | - { |
|
| 204 | - return $this->loader->getNew( |
|
| 205 | - 'EE_DB_Only_Text_Field', |
|
| 206 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @param string $table_column |
|
| 214 | - * @param string $nice_name |
|
| 215 | - * @param bool $nullable |
|
| 216 | - * @param string $default_value |
|
| 217 | - * @return EE_Email_Field |
|
| 218 | - */ |
|
| 219 | - public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 220 | - { |
|
| 221 | - return $this->loader->getNew( |
|
| 222 | - 'EE_Email_Field', |
|
| 223 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @param string $table_column |
|
| 231 | - * @param string $nice_name |
|
| 232 | - * @param bool $nullable |
|
| 233 | - * @param null $default_value |
|
| 234 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 235 | - * values are how they should be displayed |
|
| 236 | - * @return EE_Enum_Integer_Field |
|
| 237 | - */ |
|
| 238 | - public function createEnumIntegerField( |
|
| 239 | - $table_column, |
|
| 240 | - $nice_name, |
|
| 241 | - $nullable, |
|
| 242 | - $default_value = null, |
|
| 243 | - array $allowed_enum_values |
|
| 244 | - ) { |
|
| 245 | - return $this->loader->getNew( |
|
| 246 | - 'EE_Enum_Integer_Field', |
|
| 247 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @param string $table_column |
|
| 255 | - * @param string $nice_name |
|
| 256 | - * @param bool $nullable |
|
| 257 | - * @param null $default_value |
|
| 258 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 259 | - * values are how they should be displayed |
|
| 260 | - * @return EE_Enum_Text_Field |
|
| 261 | - */ |
|
| 262 | - public function createEnumTextField( |
|
| 263 | - $table_column, |
|
| 264 | - $nice_name, |
|
| 265 | - $nullable, |
|
| 266 | - $default_value, |
|
| 267 | - array $allowed_enum_values |
|
| 268 | - ) { |
|
| 269 | - return $this->loader->getNew( |
|
| 270 | - 'EE_Enum_Text_Field', |
|
| 271 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param string $table_column |
|
| 279 | - * @param string $nice_name |
|
| 280 | - * @param bool $nullable |
|
| 281 | - * @param null $default_value |
|
| 282 | - * @return EE_Float_Field |
|
| 283 | - */ |
|
| 284 | - public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 285 | - { |
|
| 286 | - return $this->loader->getNew( |
|
| 287 | - 'EE_Float_Field', |
|
| 288 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param string $table_column |
|
| 296 | - * @param string $nice_name |
|
| 297 | - * @param bool $nullable |
|
| 298 | - * @param null $default_value |
|
| 299 | - * @param string $model_name |
|
| 300 | - * @return EE_Foreign_Key_Int_Field |
|
| 301 | - */ |
|
| 302 | - public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 303 | - { |
|
| 304 | - return $this->loader->getNew( |
|
| 305 | - 'EE_Foreign_Key_Int_Field', |
|
| 306 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @param string $table_column |
|
| 314 | - * @param string $nice_name |
|
| 315 | - * @param bool $nullable |
|
| 316 | - * @param null $default_value |
|
| 317 | - * @param string $model_name |
|
| 318 | - * @return EE_Foreign_Key_String_Field |
|
| 319 | - */ |
|
| 320 | - public function createForeignKeyStringField( |
|
| 321 | - $table_column, |
|
| 322 | - $nice_name, |
|
| 323 | - $nullable, |
|
| 324 | - $default_value, |
|
| 325 | - $model_name |
|
| 326 | - ) { |
|
| 327 | - return $this->loader->getNew( |
|
| 328 | - 'EE_Foreign_Key_String_Field', |
|
| 329 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param string $table_column |
|
| 337 | - * @param string $nice_name |
|
| 338 | - * @param bool $nullable |
|
| 339 | - * @param null $default_value |
|
| 340 | - * @return EE_Full_HTML_Field |
|
| 341 | - */ |
|
| 342 | - public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 343 | - { |
|
| 344 | - return $this->loader->getNew( |
|
| 345 | - 'EE_Full_HTML_Field', |
|
| 346 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @param string $table_column |
|
| 354 | - * @param string $nice_name |
|
| 355 | - * @param bool $nullable |
|
| 356 | - * @param null $default_value |
|
| 357 | - * @return EE_Infinite_Integer_Field |
|
| 358 | - */ |
|
| 359 | - public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 360 | - { |
|
| 361 | - return $this->loader->getNew( |
|
| 362 | - 'EE_Infinite_Integer_Field', |
|
| 363 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 364 | - ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param string $table_column |
|
| 371 | - * @param string $nice_name |
|
| 372 | - * @param bool $nullable |
|
| 373 | - * @param integer $default_value |
|
| 374 | - * @return EE_Integer_Field |
|
| 375 | - */ |
|
| 376 | - public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
| 377 | - { |
|
| 378 | - return $this->loader->getNew( |
|
| 379 | - 'EE_Integer_Field', |
|
| 380 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @param string $table_column |
|
| 388 | - * @param string $nice_name |
|
| 389 | - * @param bool $nullable |
|
| 390 | - * @param null $default_value |
|
| 391 | - * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
| 392 | - */ |
|
| 393 | - public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 394 | - { |
|
| 395 | - return $this->loader->getNew( |
|
| 396 | - 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
| 397 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 398 | - ); |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * @param string $table_column |
|
| 405 | - * @param string $nice_name |
|
| 406 | - * @param bool $nullable |
|
| 407 | - * @param null $default_value |
|
| 408 | - * @return EE_Maybe_Serialized_Text_Field |
|
| 409 | - */ |
|
| 410 | - public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 411 | - { |
|
| 412 | - return $this->loader->getNew( |
|
| 413 | - 'EE_Maybe_Serialized_Text_Field', |
|
| 414 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @param string $table_column |
|
| 422 | - * @param string $nice_name |
|
| 423 | - * @param bool $nullable |
|
| 424 | - * @param null $default_value |
|
| 425 | - * @return EE_Money_Field |
|
| 426 | - */ |
|
| 427 | - public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 428 | - { |
|
| 429 | - return $this->loader->getNew( |
|
| 430 | - 'EE_Money_Field', |
|
| 431 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * @param string $table_column |
|
| 439 | - * @param string $nice_name |
|
| 440 | - * @param bool $nullable |
|
| 441 | - * @param string $default_value |
|
| 442 | - * @return EE_Plain_Text_Field |
|
| 443 | - */ |
|
| 444 | - public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 445 | - { |
|
| 446 | - return $this->loader->getNew( |
|
| 447 | - 'EE_Plain_Text_Field', |
|
| 448 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 449 | - ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @param string $table_column |
|
| 456 | - * @param string $nice_name |
|
| 457 | - * @param bool $nullable |
|
| 458 | - * @param null $default_value |
|
| 459 | - * @return EE_Post_Content_Field |
|
| 460 | - */ |
|
| 461 | - public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 462 | - { |
|
| 463 | - return $this->loader->getNew( |
|
| 464 | - 'EE_Post_Content_Field', |
|
| 465 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 466 | - ); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * @param string $table_column |
|
| 473 | - * @param string $nice_name |
|
| 474 | - * @return EE_Primary_Key_Int_Field |
|
| 475 | - */ |
|
| 476 | - public function createPrimaryKeyIntField($table_column, $nice_name) |
|
| 477 | - { |
|
| 478 | - return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * @param string $table_column |
|
| 485 | - * @param string $nice_name |
|
| 486 | - * @return EE_Primary_Key_String_Field |
|
| 487 | - */ |
|
| 488 | - public function createPrimaryKeyStringField($table_column, $nice_name) |
|
| 489 | - { |
|
| 490 | - return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * @param string $table_column |
|
| 497 | - * @param string $nice_name |
|
| 498 | - * @param bool $nullable |
|
| 499 | - * @param null $default_value |
|
| 500 | - * @return EE_Serialized_Text_Field |
|
| 501 | - */ |
|
| 502 | - public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 503 | - { |
|
| 504 | - return $this->loader->getNew( |
|
| 505 | - 'EE_Serialized_Text_Field', |
|
| 506 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 507 | - ); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @param string $table_column |
|
| 514 | - * @param string $nice_name |
|
| 515 | - * @param bool $nullable |
|
| 516 | - * @param null $default_value |
|
| 517 | - * @return EE_Simple_HTML_Field |
|
| 518 | - */ |
|
| 519 | - public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 520 | - { |
|
| 521 | - return $this->loader->getNew( |
|
| 522 | - 'EE_Simple_HTML_Field', |
|
| 523 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 524 | - ); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * @param string $table_column |
|
| 531 | - * @param string $nice_name |
|
| 532 | - * @param bool $nullable |
|
| 533 | - * @param null $default_value |
|
| 534 | - * @return EE_Slug_Field |
|
| 535 | - */ |
|
| 536 | - public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
| 537 | - { |
|
| 538 | - return $this->loader->getNew( |
|
| 539 | - 'EE_Slug_Field', |
|
| 540 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * @param string $table_column |
|
| 548 | - * @param string $nice_name |
|
| 549 | - * @param bool $nullable |
|
| 550 | - * @param null $default_value |
|
| 551 | - * @return EE_Trashed_Flag_Field |
|
| 552 | - */ |
|
| 553 | - public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 554 | - { |
|
| 555 | - return $this->loader->getNew( |
|
| 556 | - 'EE_Trashed_Flag_Field', |
|
| 557 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * @param string $table_column |
|
| 565 | - * @param string $nice_name |
|
| 566 | - * @param bool $nullable |
|
| 567 | - * @param mixed $default_value |
|
| 568 | - * @param array $values If additional stati are to be used other than the default WP statuses, |
|
| 569 | - * then they can be registered via this property. |
|
| 570 | - * The format of the array should be as follows: |
|
| 571 | - * array( |
|
| 572 | - * 'status_reference' => array( |
|
| 573 | - * 'label' => __('Status Reference Label', 'event_espresso'), |
|
| 574 | - * 'public' => true, // whether this status should be shown on the frontend of the site |
|
| 575 | - * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
|
| 576 | - * 'show_in_admin_all_list' => true, // whether this status is included in queries |
|
| 577 | - * for the admin "all" view in list table views. |
|
| 578 | - * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
|
| 579 | - * of the admin list tables (i.e. Status Reference(2) ) |
|
| 580 | - * 'label_count' => _n_noop( |
|
| 581 | - * 'Status Reference <span class="count">(%s)</span>', |
|
| 582 | - * 'Status References <span class="count">(%s)</span>' |
|
| 583 | - * ), // the text to display on the admin screen |
|
| 584 | - * ( or you won't see your status count ). |
|
| 585 | - * ) |
|
| 586 | - * ) |
|
| 587 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 588 | - * @return EE_WP_Post_Status_Field |
|
| 589 | - */ |
|
| 590 | - public function createWpPostStatusField( |
|
| 591 | - $table_column, |
|
| 592 | - $nice_name, |
|
| 593 | - $nullable, |
|
| 594 | - $default_value = null, |
|
| 595 | - array $values = array() |
|
| 596 | - ) { |
|
| 597 | - return $this->loader->getNew( |
|
| 598 | - 'EE_WP_Post_Status_Field', |
|
| 599 | - array($table_column, $nice_name, $nullable, $default_value, $values) |
|
| 600 | - ); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * @param string $post_type |
|
| 607 | - * @return EE_WP_Post_Type_Field |
|
| 608 | - */ |
|
| 609 | - public function createWpPostTypeField($post_type) |
|
| 610 | - { |
|
| 611 | - return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * @param string $table_column |
|
| 618 | - * @param string $nice_name |
|
| 619 | - * @param bool $nullable |
|
| 620 | - * @return EE_WP_User_Field |
|
| 621 | - */ |
|
| 622 | - public function createWpUserField($table_column, $nice_name, $nullable) |
|
| 623 | - { |
|
| 624 | - return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
| 625 | - } |
|
| 56 | + /** |
|
| 57 | + * @var LoaderInterface $loader |
|
| 58 | + */ |
|
| 59 | + private $loader; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * ModelFieldFactory constructor. |
|
| 65 | + * |
|
| 66 | + * @param LoaderInterface $loader |
|
| 67 | + */ |
|
| 68 | + public function __construct(LoaderInterface $loader) |
|
| 69 | + { |
|
| 70 | + $this->loader = $loader; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $table_column |
|
| 77 | + * @param string $nice_name |
|
| 78 | + * @param bool $nullable |
|
| 79 | + * @param null $default_value |
|
| 80 | + * @return EE_All_Caps_Text_Field |
|
| 81 | + */ |
|
| 82 | + public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 83 | + { |
|
| 84 | + return $this->loader->getNew( |
|
| 85 | + 'EE_All_Caps_Text_Field', |
|
| 86 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $table_column |
|
| 94 | + * @param string $nice_name |
|
| 95 | + * @param bool $nullable |
|
| 96 | + * @param null $default_value |
|
| 97 | + * @param string $model_name |
|
| 98 | + * @return EE_Any_Foreign_Model_Name_Field |
|
| 99 | + */ |
|
| 100 | + public function createAnyForeignModelNameField( |
|
| 101 | + $table_column, |
|
| 102 | + $nice_name, |
|
| 103 | + $nullable, |
|
| 104 | + $default_value = null, |
|
| 105 | + $model_name |
|
| 106 | + ) { |
|
| 107 | + return $this->loader->getNew( |
|
| 108 | + 'EE_Any_Foreign_Model_Name_Field', |
|
| 109 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $table_column |
|
| 117 | + * @param string $nice_name |
|
| 118 | + * @param bool $nullable |
|
| 119 | + * @param null $default_value |
|
| 120 | + * @return EE_Boolean_Field |
|
| 121 | + */ |
|
| 122 | + public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 123 | + { |
|
| 124 | + return $this->loader->getNew( |
|
| 125 | + 'EE_Boolean_Field', |
|
| 126 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param string $table_column |
|
| 134 | + * @param string $nice_name |
|
| 135 | + * @param string $timezone_string |
|
| 136 | + * @param bool $nullable |
|
| 137 | + * @param string $default_value |
|
| 138 | + * @throws EE_Error |
|
| 139 | + * @throws InvalidArgumentException |
|
| 140 | + * @return EE_Datetime_Field |
|
| 141 | + */ |
|
| 142 | + public function createDatetimeField( |
|
| 143 | + $table_column, |
|
| 144 | + $nice_name, |
|
| 145 | + $nullable = false, |
|
| 146 | + $default_value = EE_Datetime_Field::now |
|
| 147 | + ) { |
|
| 148 | + return $this->loader->getNew( |
|
| 149 | + 'EE_Datetime_Field', |
|
| 150 | + array( |
|
| 151 | + $table_column, |
|
| 152 | + $nice_name, |
|
| 153 | + $nullable, |
|
| 154 | + $default_value |
|
| 155 | + ) |
|
| 156 | + ); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param string $table_column |
|
| 163 | + * @param string $nice_name |
|
| 164 | + * @param bool $nullable |
|
| 165 | + * @param null $default_value |
|
| 166 | + * @return EE_DB_Only_Float_Field |
|
| 167 | + */ |
|
| 168 | + public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 169 | + { |
|
| 170 | + return $this->loader->getNew( |
|
| 171 | + 'EE_DB_Only_Float_Field', |
|
| 172 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 173 | + ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param string $table_column |
|
| 180 | + * @param string $nice_name |
|
| 181 | + * @param bool $nullable |
|
| 182 | + * @param null $default_value |
|
| 183 | + * @return EE_DB_Only_Int_Field |
|
| 184 | + */ |
|
| 185 | + public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 186 | + { |
|
| 187 | + return $this->loader->getNew( |
|
| 188 | + 'EE_DB_Only_Int_Field', |
|
| 189 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $table_column |
|
| 197 | + * @param string $nice_name |
|
| 198 | + * @param bool $nullable |
|
| 199 | + * @param null $default_value |
|
| 200 | + * @return EE_DB_Only_Text_Field |
|
| 201 | + */ |
|
| 202 | + public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 203 | + { |
|
| 204 | + return $this->loader->getNew( |
|
| 205 | + 'EE_DB_Only_Text_Field', |
|
| 206 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @param string $table_column |
|
| 214 | + * @param string $nice_name |
|
| 215 | + * @param bool $nullable |
|
| 216 | + * @param string $default_value |
|
| 217 | + * @return EE_Email_Field |
|
| 218 | + */ |
|
| 219 | + public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 220 | + { |
|
| 221 | + return $this->loader->getNew( |
|
| 222 | + 'EE_Email_Field', |
|
| 223 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @param string $table_column |
|
| 231 | + * @param string $nice_name |
|
| 232 | + * @param bool $nullable |
|
| 233 | + * @param null $default_value |
|
| 234 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 235 | + * values are how they should be displayed |
|
| 236 | + * @return EE_Enum_Integer_Field |
|
| 237 | + */ |
|
| 238 | + public function createEnumIntegerField( |
|
| 239 | + $table_column, |
|
| 240 | + $nice_name, |
|
| 241 | + $nullable, |
|
| 242 | + $default_value = null, |
|
| 243 | + array $allowed_enum_values |
|
| 244 | + ) { |
|
| 245 | + return $this->loader->getNew( |
|
| 246 | + 'EE_Enum_Integer_Field', |
|
| 247 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @param string $table_column |
|
| 255 | + * @param string $nice_name |
|
| 256 | + * @param bool $nullable |
|
| 257 | + * @param null $default_value |
|
| 258 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 259 | + * values are how they should be displayed |
|
| 260 | + * @return EE_Enum_Text_Field |
|
| 261 | + */ |
|
| 262 | + public function createEnumTextField( |
|
| 263 | + $table_column, |
|
| 264 | + $nice_name, |
|
| 265 | + $nullable, |
|
| 266 | + $default_value, |
|
| 267 | + array $allowed_enum_values |
|
| 268 | + ) { |
|
| 269 | + return $this->loader->getNew( |
|
| 270 | + 'EE_Enum_Text_Field', |
|
| 271 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param string $table_column |
|
| 279 | + * @param string $nice_name |
|
| 280 | + * @param bool $nullable |
|
| 281 | + * @param null $default_value |
|
| 282 | + * @return EE_Float_Field |
|
| 283 | + */ |
|
| 284 | + public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 285 | + { |
|
| 286 | + return $this->loader->getNew( |
|
| 287 | + 'EE_Float_Field', |
|
| 288 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param string $table_column |
|
| 296 | + * @param string $nice_name |
|
| 297 | + * @param bool $nullable |
|
| 298 | + * @param null $default_value |
|
| 299 | + * @param string $model_name |
|
| 300 | + * @return EE_Foreign_Key_Int_Field |
|
| 301 | + */ |
|
| 302 | + public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 303 | + { |
|
| 304 | + return $this->loader->getNew( |
|
| 305 | + 'EE_Foreign_Key_Int_Field', |
|
| 306 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @param string $table_column |
|
| 314 | + * @param string $nice_name |
|
| 315 | + * @param bool $nullable |
|
| 316 | + * @param null $default_value |
|
| 317 | + * @param string $model_name |
|
| 318 | + * @return EE_Foreign_Key_String_Field |
|
| 319 | + */ |
|
| 320 | + public function createForeignKeyStringField( |
|
| 321 | + $table_column, |
|
| 322 | + $nice_name, |
|
| 323 | + $nullable, |
|
| 324 | + $default_value, |
|
| 325 | + $model_name |
|
| 326 | + ) { |
|
| 327 | + return $this->loader->getNew( |
|
| 328 | + 'EE_Foreign_Key_String_Field', |
|
| 329 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param string $table_column |
|
| 337 | + * @param string $nice_name |
|
| 338 | + * @param bool $nullable |
|
| 339 | + * @param null $default_value |
|
| 340 | + * @return EE_Full_HTML_Field |
|
| 341 | + */ |
|
| 342 | + public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 343 | + { |
|
| 344 | + return $this->loader->getNew( |
|
| 345 | + 'EE_Full_HTML_Field', |
|
| 346 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @param string $table_column |
|
| 354 | + * @param string $nice_name |
|
| 355 | + * @param bool $nullable |
|
| 356 | + * @param null $default_value |
|
| 357 | + * @return EE_Infinite_Integer_Field |
|
| 358 | + */ |
|
| 359 | + public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 360 | + { |
|
| 361 | + return $this->loader->getNew( |
|
| 362 | + 'EE_Infinite_Integer_Field', |
|
| 363 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 364 | + ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param string $table_column |
|
| 371 | + * @param string $nice_name |
|
| 372 | + * @param bool $nullable |
|
| 373 | + * @param integer $default_value |
|
| 374 | + * @return EE_Integer_Field |
|
| 375 | + */ |
|
| 376 | + public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
| 377 | + { |
|
| 378 | + return $this->loader->getNew( |
|
| 379 | + 'EE_Integer_Field', |
|
| 380 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @param string $table_column |
|
| 388 | + * @param string $nice_name |
|
| 389 | + * @param bool $nullable |
|
| 390 | + * @param null $default_value |
|
| 391 | + * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
| 392 | + */ |
|
| 393 | + public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 394 | + { |
|
| 395 | + return $this->loader->getNew( |
|
| 396 | + 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
| 397 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 398 | + ); |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * @param string $table_column |
|
| 405 | + * @param string $nice_name |
|
| 406 | + * @param bool $nullable |
|
| 407 | + * @param null $default_value |
|
| 408 | + * @return EE_Maybe_Serialized_Text_Field |
|
| 409 | + */ |
|
| 410 | + public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 411 | + { |
|
| 412 | + return $this->loader->getNew( |
|
| 413 | + 'EE_Maybe_Serialized_Text_Field', |
|
| 414 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @param string $table_column |
|
| 422 | + * @param string $nice_name |
|
| 423 | + * @param bool $nullable |
|
| 424 | + * @param null $default_value |
|
| 425 | + * @return EE_Money_Field |
|
| 426 | + */ |
|
| 427 | + public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 428 | + { |
|
| 429 | + return $this->loader->getNew( |
|
| 430 | + 'EE_Money_Field', |
|
| 431 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @param string $table_column |
|
| 439 | + * @param string $nice_name |
|
| 440 | + * @param bool $nullable |
|
| 441 | + * @param string $default_value |
|
| 442 | + * @return EE_Plain_Text_Field |
|
| 443 | + */ |
|
| 444 | + public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 445 | + { |
|
| 446 | + return $this->loader->getNew( |
|
| 447 | + 'EE_Plain_Text_Field', |
|
| 448 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 449 | + ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @param string $table_column |
|
| 456 | + * @param string $nice_name |
|
| 457 | + * @param bool $nullable |
|
| 458 | + * @param null $default_value |
|
| 459 | + * @return EE_Post_Content_Field |
|
| 460 | + */ |
|
| 461 | + public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 462 | + { |
|
| 463 | + return $this->loader->getNew( |
|
| 464 | + 'EE_Post_Content_Field', |
|
| 465 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 466 | + ); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * @param string $table_column |
|
| 473 | + * @param string $nice_name |
|
| 474 | + * @return EE_Primary_Key_Int_Field |
|
| 475 | + */ |
|
| 476 | + public function createPrimaryKeyIntField($table_column, $nice_name) |
|
| 477 | + { |
|
| 478 | + return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * @param string $table_column |
|
| 485 | + * @param string $nice_name |
|
| 486 | + * @return EE_Primary_Key_String_Field |
|
| 487 | + */ |
|
| 488 | + public function createPrimaryKeyStringField($table_column, $nice_name) |
|
| 489 | + { |
|
| 490 | + return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param string $table_column |
|
| 497 | + * @param string $nice_name |
|
| 498 | + * @param bool $nullable |
|
| 499 | + * @param null $default_value |
|
| 500 | + * @return EE_Serialized_Text_Field |
|
| 501 | + */ |
|
| 502 | + public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 503 | + { |
|
| 504 | + return $this->loader->getNew( |
|
| 505 | + 'EE_Serialized_Text_Field', |
|
| 506 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 507 | + ); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @param string $table_column |
|
| 514 | + * @param string $nice_name |
|
| 515 | + * @param bool $nullable |
|
| 516 | + * @param null $default_value |
|
| 517 | + * @return EE_Simple_HTML_Field |
|
| 518 | + */ |
|
| 519 | + public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 520 | + { |
|
| 521 | + return $this->loader->getNew( |
|
| 522 | + 'EE_Simple_HTML_Field', |
|
| 523 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 524 | + ); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * @param string $table_column |
|
| 531 | + * @param string $nice_name |
|
| 532 | + * @param bool $nullable |
|
| 533 | + * @param null $default_value |
|
| 534 | + * @return EE_Slug_Field |
|
| 535 | + */ |
|
| 536 | + public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
| 537 | + { |
|
| 538 | + return $this->loader->getNew( |
|
| 539 | + 'EE_Slug_Field', |
|
| 540 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * @param string $table_column |
|
| 548 | + * @param string $nice_name |
|
| 549 | + * @param bool $nullable |
|
| 550 | + * @param null $default_value |
|
| 551 | + * @return EE_Trashed_Flag_Field |
|
| 552 | + */ |
|
| 553 | + public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 554 | + { |
|
| 555 | + return $this->loader->getNew( |
|
| 556 | + 'EE_Trashed_Flag_Field', |
|
| 557 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * @param string $table_column |
|
| 565 | + * @param string $nice_name |
|
| 566 | + * @param bool $nullable |
|
| 567 | + * @param mixed $default_value |
|
| 568 | + * @param array $values If additional stati are to be used other than the default WP statuses, |
|
| 569 | + * then they can be registered via this property. |
|
| 570 | + * The format of the array should be as follows: |
|
| 571 | + * array( |
|
| 572 | + * 'status_reference' => array( |
|
| 573 | + * 'label' => __('Status Reference Label', 'event_espresso'), |
|
| 574 | + * 'public' => true, // whether this status should be shown on the frontend of the site |
|
| 575 | + * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
|
| 576 | + * 'show_in_admin_all_list' => true, // whether this status is included in queries |
|
| 577 | + * for the admin "all" view in list table views. |
|
| 578 | + * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
|
| 579 | + * of the admin list tables (i.e. Status Reference(2) ) |
|
| 580 | + * 'label_count' => _n_noop( |
|
| 581 | + * 'Status Reference <span class="count">(%s)</span>', |
|
| 582 | + * 'Status References <span class="count">(%s)</span>' |
|
| 583 | + * ), // the text to display on the admin screen |
|
| 584 | + * ( or you won't see your status count ). |
|
| 585 | + * ) |
|
| 586 | + * ) |
|
| 587 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 588 | + * @return EE_WP_Post_Status_Field |
|
| 589 | + */ |
|
| 590 | + public function createWpPostStatusField( |
|
| 591 | + $table_column, |
|
| 592 | + $nice_name, |
|
| 593 | + $nullable, |
|
| 594 | + $default_value = null, |
|
| 595 | + array $values = array() |
|
| 596 | + ) { |
|
| 597 | + return $this->loader->getNew( |
|
| 598 | + 'EE_WP_Post_Status_Field', |
|
| 599 | + array($table_column, $nice_name, $nullable, $default_value, $values) |
|
| 600 | + ); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * @param string $post_type |
|
| 607 | + * @return EE_WP_Post_Type_Field |
|
| 608 | + */ |
|
| 609 | + public function createWpPostTypeField($post_type) |
|
| 610 | + { |
|
| 611 | + return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * @param string $table_column |
|
| 618 | + * @param string $nice_name |
|
| 619 | + * @param bool $nullable |
|
| 620 | + * @return EE_WP_User_Field |
|
| 621 | + */ |
|
| 622 | + public function createWpUserField($table_column, $nice_name, $nullable) |
|
| 623 | + { |
|
| 624 | + return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
| 625 | + } |
|
| 626 | 626 | |
| 627 | 627 | |
| 628 | 628 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | add_action( |
| 128 | 128 | 'shutdown', |
| 129 | - function () use ($formatted) { |
|
| 129 | + function() use ($formatted) { |
|
| 130 | 130 | Benchmark::displayResults(true, $formatted); |
| 131 | 131 | } |
| 132 | 132 | ); |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | add_action( |
| 148 | 148 | 'shutdown', |
| 149 | - function () use ($filepath, $formatted, $append) { |
|
| 149 | + function() use ($filepath, $formatted, $append) { |
|
| 150 | 150 | Benchmark::writeResultsToFile($filepath, $formatted, $append); |
| 151 | 151 | } |
| 152 | 152 | ); |
@@ -164,17 +164,17 @@ discard block |
||
| 164 | 164 | return ''; |
| 165 | 165 | } |
| 166 | 166 | $output = ''; |
| 167 | - if (! empty(Benchmark::$times)) { |
|
| 167 | + if ( ! empty(Benchmark::$times)) { |
|
| 168 | 168 | $total = 0; |
| 169 | 169 | $output .= $formatted |
| 170 | 170 | ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
| 171 | 171 | : ''; |
| 172 | 172 | foreach (Benchmark::$times as $timer_name => $total_time) { |
| 173 | 173 | $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
| 174 | - $output .= $formatted ? '<br />' : "\n"; |
|
| 174 | + $output .= $formatted ? '<br />' : "\n"; |
|
| 175 | 175 | $total += $total_time; |
| 176 | 176 | } |
| 177 | - if($formatted) { |
|
| 177 | + if ($formatted) { |
|
| 178 | 178 | $output .= '<br />'; |
| 179 | 179 | $output .= '<h4>TOTAL TIME</h4>'; |
| 180 | 180 | $output .= Benchmark::formatTime('', $total, $formatted); |
@@ -189,9 +189,9 @@ discard block |
||
| 189 | 189 | $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 192 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
| 193 | 193 | $output .= $formatted |
| 194 | - ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
| 194 | + ? '<h5>Memory</h5>'.implode('<br />', Benchmark::$memory_usage) |
|
| 195 | 195 | : implode("\n", Benchmark::$memory_usage); |
| 196 | 196 | } |
| 197 | 197 | if (empty($output)) { |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
| 240 | 240 | ? $filepath |
| 241 | 241 | : ''; |
| 242 | - if( empty($filepath)) { |
|
| 243 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 242 | + if (empty($filepath)) { |
|
| 243 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html'; |
|
| 244 | 244 | } |
| 245 | 245 | file_put_contents( |
| 246 | 246 | $filepath, |
| 247 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 247 | + "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted), |
|
| 248 | 248 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
| 249 | 249 | ); |
| 250 | 250 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | return round( |
| 264 | 264 | $size / pow(1024, $i = floor(log($size, 1024))), |
| 265 | 265 | 2 |
| 266 | - ) . ' ' . $unit[absint($i)]; |
|
| 266 | + ).' '.$unit[absint($i)]; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | |
@@ -17,303 +17,303 @@ |
||
| 17 | 17 | class Benchmark |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * array containing the start time for the timers |
|
| 22 | - */ |
|
| 23 | - private static $start_times; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * array containing all the timer'd times, which can be outputted via show_times() |
|
| 27 | - */ |
|
| 28 | - private static $times = array(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected static $memory_usage = array(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * whether to benchmark code or not |
|
| 39 | - */ |
|
| 40 | - public static function doNotRun() |
|
| 41 | - { |
|
| 42 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * resetTimes |
|
| 49 | - */ |
|
| 50 | - public static function resetTimes() |
|
| 51 | - { |
|
| 52 | - Benchmark::$times = array(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 59 | - * |
|
| 60 | - * @param null $timer_name |
|
| 61 | - */ |
|
| 62 | - public static function startTimer($timer_name = null) |
|
| 63 | - { |
|
| 64 | - if (Benchmark::doNotRun()) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 68 | - Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 75 | - * |
|
| 76 | - * @param string $timer_name |
|
| 77 | - */ |
|
| 78 | - public static function stopTimer($timer_name = '') |
|
| 79 | - { |
|
| 80 | - if (Benchmark::doNotRun()) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 84 | - if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 85 | - $start_time = Benchmark::$start_times[$timer_name]; |
|
| 86 | - unset(Benchmark::$start_times[$timer_name]); |
|
| 87 | - } else { |
|
| 88 | - $start_time = array_pop(Benchmark::$start_times); |
|
| 89 | - } |
|
| 90 | - Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Measure the memory usage by PHP so far. |
|
| 97 | - * |
|
| 98 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 99 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 100 | - * @param bool $formatted |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 104 | - { |
|
| 105 | - if (Benchmark::doNotRun()) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 109 | - Benchmark::$memory_usage[$label] = $memory_used; |
|
| 110 | - if ($output_now) { |
|
| 111 | - echo $formatted |
|
| 112 | - ? "<br>{$label} : {$memory_used}" |
|
| 113 | - : "\n {$label} : {$memory_used}"; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * will display the benchmarking results at shutdown |
|
| 121 | - * |
|
| 122 | - * @param bool $formatted |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public static function displayResultsAtShutdown($formatted = true) |
|
| 126 | - { |
|
| 127 | - add_action( |
|
| 128 | - 'shutdown', |
|
| 129 | - function () use ($formatted) { |
|
| 130 | - Benchmark::displayResults(true, $formatted); |
|
| 131 | - } |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * will display the benchmarking results at shutdown |
|
| 139 | - * |
|
| 140 | - * @param string $filepath |
|
| 141 | - * @param bool $formatted |
|
| 142 | - * @param bool $append |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 146 | - { |
|
| 147 | - add_action( |
|
| 148 | - 'shutdown', |
|
| 149 | - function () use ($filepath, $formatted, $append) { |
|
| 150 | - Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 151 | - } |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param bool $formatted |
|
| 159 | - * @return string |
|
| 160 | - */ |
|
| 161 | - private static function generateResults($formatted = true) |
|
| 162 | - { |
|
| 163 | - if (Benchmark::doNotRun()) { |
|
| 164 | - return ''; |
|
| 165 | - } |
|
| 166 | - $output = ''; |
|
| 167 | - if (! empty(Benchmark::$times)) { |
|
| 168 | - $total = 0; |
|
| 169 | - $output .= $formatted |
|
| 170 | - ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 171 | - : ''; |
|
| 172 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 173 | - $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 174 | - $output .= $formatted ? '<br />' : "\n"; |
|
| 175 | - $total += $total_time; |
|
| 176 | - } |
|
| 177 | - if($formatted) { |
|
| 178 | - $output .= '<br />'; |
|
| 179 | - $output .= '<h4>TOTAL TIME</h4>'; |
|
| 180 | - $output .= Benchmark::formatTime('', $total, $formatted); |
|
| 181 | - $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 182 | - $output .= '<br />'; |
|
| 183 | - $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 184 | - $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 185 | - $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 186 | - $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 187 | - $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 188 | - $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 189 | - $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - if (! empty(Benchmark::$memory_usage)) { |
|
| 193 | - $output .= $formatted |
|
| 194 | - ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
| 195 | - : implode("\n", Benchmark::$memory_usage); |
|
| 196 | - } |
|
| 197 | - if (empty($output)) { |
|
| 198 | - return ''; |
|
| 199 | - } |
|
| 200 | - $output = $formatted |
|
| 201 | - ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 202 | - . (is_admin() |
|
| 203 | - ? ' margin:2em 2em 2em 180px;' |
|
| 204 | - : ' margin:2em;') |
|
| 205 | - . ' padding:2em;">' |
|
| 206 | - . '<h4>BENCHMARKING</h4>' |
|
| 207 | - . $output |
|
| 208 | - . '</div>' |
|
| 209 | - : $output; |
|
| 210 | - return $output; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param bool $echo |
|
| 217 | - * @param bool $formatted |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public static function displayResults($echo = true, $formatted = true) |
|
| 221 | - { |
|
| 222 | - $results = Benchmark::generateResults($formatted); |
|
| 223 | - if ($echo) { |
|
| 224 | - echo $results; |
|
| 225 | - $results = ''; |
|
| 226 | - } |
|
| 227 | - return $results; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param string $filepath |
|
| 234 | - * @param bool $formatted |
|
| 235 | - * @param bool $append |
|
| 236 | - */ |
|
| 237 | - public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 238 | - { |
|
| 239 | - $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 240 | - ? $filepath |
|
| 241 | - : ''; |
|
| 242 | - if( empty($filepath)) { |
|
| 243 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 244 | - } |
|
| 245 | - file_put_contents( |
|
| 246 | - $filepath, |
|
| 247 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 248 | - $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 256 | - * |
|
| 257 | - * @param int $size |
|
| 258 | - * @return string |
|
| 259 | - */ |
|
| 260 | - public static function convert($size) |
|
| 261 | - { |
|
| 262 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 263 | - return round( |
|
| 264 | - $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 265 | - 2 |
|
| 266 | - ) . ' ' . $unit[absint($i)]; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param string $timer_name |
|
| 273 | - * @param float $total_time |
|
| 274 | - * @param bool $formatted |
|
| 275 | - * @return string |
|
| 276 | - */ |
|
| 277 | - public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 278 | - { |
|
| 279 | - $total_time *= 1000; |
|
| 280 | - switch ($total_time) { |
|
| 281 | - case $total_time > 12500 : |
|
| 282 | - $color = 'red'; |
|
| 283 | - $bold = 'bold'; |
|
| 284 | - break; |
|
| 285 | - case $total_time > 2500 : |
|
| 286 | - $color = 'darkorange'; |
|
| 287 | - $bold = 'bold'; |
|
| 288 | - break; |
|
| 289 | - case $total_time > 500 : |
|
| 290 | - $color = 'gold'; |
|
| 291 | - $bold = 'bold'; |
|
| 292 | - break; |
|
| 293 | - case $total_time > 100 : |
|
| 294 | - $color = 'limegreen'; |
|
| 295 | - $bold = 'normal'; |
|
| 296 | - break; |
|
| 297 | - case $total_time > 20 : |
|
| 298 | - $color = 'deepskyblue'; |
|
| 299 | - $bold = 'normal'; |
|
| 300 | - break; |
|
| 301 | - default : |
|
| 302 | - $color = 'mediumpurple'; |
|
| 303 | - $bold = 'normal'; |
|
| 304 | - break; |
|
| 305 | - } |
|
| 306 | - return $formatted |
|
| 307 | - ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 308 | - . $color |
|
| 309 | - . '; font-weight:' |
|
| 310 | - . $bold |
|
| 311 | - . '; font-size:1.2em;">' |
|
| 312 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 313 | - . '</span> ' |
|
| 314 | - . $timer_name |
|
| 315 | - : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 316 | - } |
|
| 20 | + /** |
|
| 21 | + * array containing the start time for the timers |
|
| 22 | + */ |
|
| 23 | + private static $start_times; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * array containing all the timer'd times, which can be outputted via show_times() |
|
| 27 | + */ |
|
| 28 | + private static $times = array(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected static $memory_usage = array(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * whether to benchmark code or not |
|
| 39 | + */ |
|
| 40 | + public static function doNotRun() |
|
| 41 | + { |
|
| 42 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * resetTimes |
|
| 49 | + */ |
|
| 50 | + public static function resetTimes() |
|
| 51 | + { |
|
| 52 | + Benchmark::$times = array(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
| 59 | + * |
|
| 60 | + * @param null $timer_name |
|
| 61 | + */ |
|
| 62 | + public static function startTimer($timer_name = null) |
|
| 63 | + { |
|
| 64 | + if (Benchmark::doNotRun()) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 68 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
| 75 | + * |
|
| 76 | + * @param string $timer_name |
|
| 77 | + */ |
|
| 78 | + public static function stopTimer($timer_name = '') |
|
| 79 | + { |
|
| 80 | + if (Benchmark::doNotRun()) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
| 84 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
| 85 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
| 86 | + unset(Benchmark::$start_times[$timer_name]); |
|
| 87 | + } else { |
|
| 88 | + $start_time = array_pop(Benchmark::$start_times); |
|
| 89 | + } |
|
| 90 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Measure the memory usage by PHP so far. |
|
| 97 | + * |
|
| 98 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
| 99 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
| 100 | + * @param bool $formatted |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
| 104 | + { |
|
| 105 | + if (Benchmark::doNotRun()) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
| 109 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
| 110 | + if ($output_now) { |
|
| 111 | + echo $formatted |
|
| 112 | + ? "<br>{$label} : {$memory_used}" |
|
| 113 | + : "\n {$label} : {$memory_used}"; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * will display the benchmarking results at shutdown |
|
| 121 | + * |
|
| 122 | + * @param bool $formatted |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public static function displayResultsAtShutdown($formatted = true) |
|
| 126 | + { |
|
| 127 | + add_action( |
|
| 128 | + 'shutdown', |
|
| 129 | + function () use ($formatted) { |
|
| 130 | + Benchmark::displayResults(true, $formatted); |
|
| 131 | + } |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * will display the benchmarking results at shutdown |
|
| 139 | + * |
|
| 140 | + * @param string $filepath |
|
| 141 | + * @param bool $formatted |
|
| 142 | + * @param bool $append |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
| 146 | + { |
|
| 147 | + add_action( |
|
| 148 | + 'shutdown', |
|
| 149 | + function () use ($filepath, $formatted, $append) { |
|
| 150 | + Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
| 151 | + } |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param bool $formatted |
|
| 159 | + * @return string |
|
| 160 | + */ |
|
| 161 | + private static function generateResults($formatted = true) |
|
| 162 | + { |
|
| 163 | + if (Benchmark::doNotRun()) { |
|
| 164 | + return ''; |
|
| 165 | + } |
|
| 166 | + $output = ''; |
|
| 167 | + if (! empty(Benchmark::$times)) { |
|
| 168 | + $total = 0; |
|
| 169 | + $output .= $formatted |
|
| 170 | + ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
| 171 | + : ''; |
|
| 172 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
| 173 | + $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
| 174 | + $output .= $formatted ? '<br />' : "\n"; |
|
| 175 | + $total += $total_time; |
|
| 176 | + } |
|
| 177 | + if($formatted) { |
|
| 178 | + $output .= '<br />'; |
|
| 179 | + $output .= '<h4>TOTAL TIME</h4>'; |
|
| 180 | + $output .= Benchmark::formatTime('', $total, $formatted); |
|
| 181 | + $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
| 182 | + $output .= '<br />'; |
|
| 183 | + $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
| 184 | + $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
| 185 | + $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
| 186 | + $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
| 187 | + $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
| 188 | + $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
| 189 | + $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + if (! empty(Benchmark::$memory_usage)) { |
|
| 193 | + $output .= $formatted |
|
| 194 | + ? '<h5>Memory</h5>' . implode('<br />', Benchmark::$memory_usage) |
|
| 195 | + : implode("\n", Benchmark::$memory_usage); |
|
| 196 | + } |
|
| 197 | + if (empty($output)) { |
|
| 198 | + return ''; |
|
| 199 | + } |
|
| 200 | + $output = $formatted |
|
| 201 | + ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
| 202 | + . (is_admin() |
|
| 203 | + ? ' margin:2em 2em 2em 180px;' |
|
| 204 | + : ' margin:2em;') |
|
| 205 | + . ' padding:2em;">' |
|
| 206 | + . '<h4>BENCHMARKING</h4>' |
|
| 207 | + . $output |
|
| 208 | + . '</div>' |
|
| 209 | + : $output; |
|
| 210 | + return $output; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param bool $echo |
|
| 217 | + * @param bool $formatted |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public static function displayResults($echo = true, $formatted = true) |
|
| 221 | + { |
|
| 222 | + $results = Benchmark::generateResults($formatted); |
|
| 223 | + if ($echo) { |
|
| 224 | + echo $results; |
|
| 225 | + $results = ''; |
|
| 226 | + } |
|
| 227 | + return $results; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param string $filepath |
|
| 234 | + * @param bool $formatted |
|
| 235 | + * @param bool $append |
|
| 236 | + */ |
|
| 237 | + public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
| 238 | + { |
|
| 239 | + $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
| 240 | + ? $filepath |
|
| 241 | + : ''; |
|
| 242 | + if( empty($filepath)) { |
|
| 243 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
| 244 | + } |
|
| 245 | + file_put_contents( |
|
| 246 | + $filepath, |
|
| 247 | + "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
| 248 | + $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
| 256 | + * |
|
| 257 | + * @param int $size |
|
| 258 | + * @return string |
|
| 259 | + */ |
|
| 260 | + public static function convert($size) |
|
| 261 | + { |
|
| 262 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
| 263 | + return round( |
|
| 264 | + $size / pow(1024, $i = floor(log($size, 1024))), |
|
| 265 | + 2 |
|
| 266 | + ) . ' ' . $unit[absint($i)]; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param string $timer_name |
|
| 273 | + * @param float $total_time |
|
| 274 | + * @param bool $formatted |
|
| 275 | + * @return string |
|
| 276 | + */ |
|
| 277 | + public static function formatTime($timer_name, $total_time, $formatted = true) |
|
| 278 | + { |
|
| 279 | + $total_time *= 1000; |
|
| 280 | + switch ($total_time) { |
|
| 281 | + case $total_time > 12500 : |
|
| 282 | + $color = 'red'; |
|
| 283 | + $bold = 'bold'; |
|
| 284 | + break; |
|
| 285 | + case $total_time > 2500 : |
|
| 286 | + $color = 'darkorange'; |
|
| 287 | + $bold = 'bold'; |
|
| 288 | + break; |
|
| 289 | + case $total_time > 500 : |
|
| 290 | + $color = 'gold'; |
|
| 291 | + $bold = 'bold'; |
|
| 292 | + break; |
|
| 293 | + case $total_time > 100 : |
|
| 294 | + $color = 'limegreen'; |
|
| 295 | + $bold = 'normal'; |
|
| 296 | + break; |
|
| 297 | + case $total_time > 20 : |
|
| 298 | + $color = 'deepskyblue'; |
|
| 299 | + $bold = 'normal'; |
|
| 300 | + break; |
|
| 301 | + default : |
|
| 302 | + $color = 'mediumpurple'; |
|
| 303 | + $bold = 'normal'; |
|
| 304 | + break; |
|
| 305 | + } |
|
| 306 | + return $formatted |
|
| 307 | + ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
| 308 | + . $color |
|
| 309 | + . '; font-weight:' |
|
| 310 | + . $bold |
|
| 311 | + . '; font-size:1.2em;">' |
|
| 312 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
| 313 | + . '</span> ' |
|
| 314 | + . $timer_name |
|
| 315 | + : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | |
@@ -15,395 +15,395 @@ discard block |
||
| 15 | 15 | final class EE_Admin implements InterminableInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @access private |
|
| 20 | - * @var EE_Admin $_instance |
|
| 21 | - */ |
|
| 22 | - private static $_instance; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - *@ singleton method used to instantiate class object |
|
| 27 | - *@ access public |
|
| 28 | - *@ return class instance |
|
| 29 | - * |
|
| 30 | - * @throws \EE_Error |
|
| 31 | - */ |
|
| 32 | - public static function instance() |
|
| 33 | - { |
|
| 34 | - // check if class object is instantiated |
|
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | - self::$_instance = new self(); |
|
| 37 | - } |
|
| 38 | - return self::$_instance; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return EE_Admin |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function reset() |
|
| 47 | - { |
|
| 48 | - self::$_instance = null; |
|
| 49 | - return self::instance(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * class constructor |
|
| 55 | - * |
|
| 56 | - * @throws \EE_Error |
|
| 57 | - */ |
|
| 58 | - protected function __construct() |
|
| 59 | - { |
|
| 60 | - // define global EE_Admin constants |
|
| 61 | - $this->_define_all_constants(); |
|
| 62 | - // set autoloaders for our admin page classes based on included path information |
|
| 63 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | - // admin hooks |
|
| 65 | - add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | - // load EE_Request_Handler early |
|
| 67 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | - add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | - add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | - add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | - add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | - add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | - add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | - add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | - add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | - |
|
| 78 | - //reset Environment config (we only do this on admin page loads); |
|
| 79 | - EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | - |
|
| 81 | - do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _define_all_constants |
|
| 87 | - * define constants that are set globally for all admin pages |
|
| 88 | - * |
|
| 89 | - * @access private |
|
| 90 | - * @return void |
|
| 91 | - */ |
|
| 92 | - private function _define_all_constants() |
|
| 93 | - { |
|
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | - define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | - * |
|
| 107 | - * @access public |
|
| 108 | - * @param array $links |
|
| 109 | - * @param string $plugin |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function filter_plugin_actions($links, $plugin) |
|
| 113 | - { |
|
| 114 | - // set $main_file in stone |
|
| 115 | - static $main_file; |
|
| 116 | - // if $main_file is not set yet |
|
| 117 | - if (! $main_file) { |
|
| 118 | - $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | - } |
|
| 120 | - if ($plugin === $main_file) { |
|
| 121 | - // compare current plugin to this one |
|
| 122 | - if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | - . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | - . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | - . '</a>'; |
|
| 127 | - array_unshift($links, $maintenance_link); |
|
| 128 | - } else { |
|
| 129 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | - . esc_html__('Settings', 'event_espresso') |
|
| 131 | - . '</a>'; |
|
| 132 | - $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | - . esc_html__('Events', 'event_espresso') |
|
| 134 | - . '</a>'; |
|
| 135 | - // add before other links |
|
| 136 | - array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return $links; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * _get_request |
|
| 145 | - * |
|
| 146 | - * @access public |
|
| 147 | - * @return void |
|
| 148 | - * @throws EE_Error |
|
| 149 | - * @throws ReflectionException |
|
| 150 | - */ |
|
| 151 | - public function get_request() |
|
| 152 | - { |
|
| 153 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | - EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * hide_admin_pages_except_maintenance_mode |
|
| 160 | - * |
|
| 161 | - * @access public |
|
| 162 | - * @param array $admin_page_folder_names |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | - { |
|
| 167 | - return array( |
|
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | - * EE_Front_Controller's init phases have run |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @return void |
|
| 181 | - * @throws EE_Error |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function init() |
|
| 185 | - { |
|
| 186 | - //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | - //ok so we want to enable the entire admin |
|
| 189 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | - add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | - add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | - //at a glance dashboard widget |
|
| 193 | - add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | - //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | - } |
|
| 197 | - // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | - try { |
|
| 200 | - //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | - EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | - } catch (EE_Error $e) { |
|
| 203 | - $e->get_error(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | - //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | - add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | - //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | - add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | - * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | - * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | - * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | - * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | - * |
|
| 222 | - * @param object $post_type WP post type object |
|
| 223 | - * @return object WP post type object |
|
| 224 | - */ |
|
| 225 | - public function remove_pages_from_nav_menu($post_type) |
|
| 226 | - { |
|
| 227 | - //if this isn't the "pages" post type let's get out |
|
| 228 | - if ($post_type->name !== 'page') { |
|
| 229 | - return $post_type; |
|
| 230 | - } |
|
| 231 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | - |
|
| 233 | - $post_type->_default_query = array( |
|
| 234 | - 'post__not_in' => $critical_pages, |
|
| 235 | - ); |
|
| 236 | - return $post_type; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | - * metaboxes get shown as well |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return void |
|
| 246 | - */ |
|
| 247 | - public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | - { |
|
| 249 | - global $wp_meta_boxes, $pagenow; |
|
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | - return; |
|
| 252 | - } |
|
| 253 | - $user = wp_get_current_user(); |
|
| 254 | - //has this been done yet? |
|
| 255 | - if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | - return; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | - $initial_meta_boxes = apply_filters( |
|
| 261 | - 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | - array( |
|
| 263 | - 'nav-menu-theme-locations', |
|
| 264 | - 'add-page', |
|
| 265 | - 'add-custom-links', |
|
| 266 | - 'add-category', |
|
| 267 | - 'add-espresso_events', |
|
| 268 | - 'add-espresso_venues', |
|
| 269 | - 'add-espresso_event_categories', |
|
| 270 | - 'add-espresso_venue_categories', |
|
| 271 | - 'add-post-type-post', |
|
| 272 | - 'add-post-type-page', |
|
| 273 | - ) |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - if (is_array($hidden_meta_boxes)) { |
|
| 277 | - foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | - if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | - unset($hidden_meta_boxes[$key]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | - update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | - * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | - * |
|
| 293 | - * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | - * addons etc. |
|
| 295 | - * @access public |
|
| 296 | - * @return void |
|
| 297 | - */ |
|
| 298 | - public function register_custom_nav_menu_boxes() |
|
| 299 | - { |
|
| 300 | - add_meta_box( |
|
| 301 | - 'add-extra-nav-menu-pages', |
|
| 302 | - esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | - array($this, 'ee_cpt_archive_pages'), |
|
| 304 | - 'nav-menus', |
|
| 305 | - 'side', |
|
| 306 | - 'core' |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | - * |
|
| 314 | - * @since 4.3.0 |
|
| 315 | - * @param string $link the original link generated by wp |
|
| 316 | - * @param int $id post id |
|
| 317 | - * @return string the (maybe) modified link |
|
| 318 | - */ |
|
| 319 | - public function modify_edit_post_link($link, $id) |
|
| 320 | - { |
|
| 321 | - if (! $post = get_post($id)) { |
|
| 322 | - return $link; |
|
| 323 | - } |
|
| 324 | - if ($post->post_type === 'espresso_attendees') { |
|
| 325 | - $query_args = array( |
|
| 326 | - 'action' => 'edit_attendee', |
|
| 327 | - 'post' => $id, |
|
| 328 | - ); |
|
| 329 | - return EEH_URL::add_query_args_and_nonce( |
|
| 330 | - $query_args, |
|
| 331 | - admin_url('admin.php?page=espresso_registrations') |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - return $link; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - |
|
| 338 | - public function ee_cpt_archive_pages() |
|
| 339 | - { |
|
| 340 | - global $nav_menu_selected_id; |
|
| 341 | - |
|
| 342 | - $db_fields = false; |
|
| 343 | - $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | - $current_tab = 'event-archives'; |
|
| 345 | - |
|
| 346 | - /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 18 | + /** |
|
| 19 | + * @access private |
|
| 20 | + * @var EE_Admin $_instance |
|
| 21 | + */ |
|
| 22 | + private static $_instance; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + *@ singleton method used to instantiate class object |
|
| 27 | + *@ access public |
|
| 28 | + *@ return class instance |
|
| 29 | + * |
|
| 30 | + * @throws \EE_Error |
|
| 31 | + */ |
|
| 32 | + public static function instance() |
|
| 33 | + { |
|
| 34 | + // check if class object is instantiated |
|
| 35 | + if (! self::$_instance instanceof EE_Admin) { |
|
| 36 | + self::$_instance = new self(); |
|
| 37 | + } |
|
| 38 | + return self::$_instance; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return EE_Admin |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function reset() |
|
| 47 | + { |
|
| 48 | + self::$_instance = null; |
|
| 49 | + return self::instance(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * class constructor |
|
| 55 | + * |
|
| 56 | + * @throws \EE_Error |
|
| 57 | + */ |
|
| 58 | + protected function __construct() |
|
| 59 | + { |
|
| 60 | + // define global EE_Admin constants |
|
| 61 | + $this->_define_all_constants(); |
|
| 62 | + // set autoloaders for our admin page classes based on included path information |
|
| 63 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
| 64 | + // admin hooks |
|
| 65 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
| 66 | + // load EE_Request_Handler early |
|
| 67 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
| 68 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
| 69 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
| 70 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
| 71 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
| 72 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
| 73 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 74 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
| 75 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
| 76 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
| 77 | + |
|
| 78 | + //reset Environment config (we only do this on admin page loads); |
|
| 79 | + EE_Registry::instance()->CFG->environment->recheck_values(); |
|
| 80 | + |
|
| 81 | + do_action('AHEE__EE_Admin__loaded'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _define_all_constants |
|
| 87 | + * define constants that are set globally for all admin pages |
|
| 88 | + * |
|
| 89 | + * @access private |
|
| 90 | + * @return void |
|
| 91 | + */ |
|
| 92 | + private function _define_all_constants() |
|
| 93 | + { |
|
| 94 | + if (! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 99 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * filter_plugin_actions - adds links to the Plugins page listing |
|
| 106 | + * |
|
| 107 | + * @access public |
|
| 108 | + * @param array $links |
|
| 109 | + * @param string $plugin |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function filter_plugin_actions($links, $plugin) |
|
| 113 | + { |
|
| 114 | + // set $main_file in stone |
|
| 115 | + static $main_file; |
|
| 116 | + // if $main_file is not set yet |
|
| 117 | + if (! $main_file) { |
|
| 118 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
| 119 | + } |
|
| 120 | + if ($plugin === $main_file) { |
|
| 121 | + // compare current plugin to this one |
|
| 122 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 123 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"' |
|
| 124 | + . ' title="Event Espresso is in maintenance mode. Click this link to learn why.">' |
|
| 125 | + . esc_html__('Maintenance Mode Active', 'event_espresso') |
|
| 126 | + . '</a>'; |
|
| 127 | + array_unshift($links, $maintenance_link); |
|
| 128 | + } else { |
|
| 129 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' |
|
| 130 | + . esc_html__('Settings', 'event_espresso') |
|
| 131 | + . '</a>'; |
|
| 132 | + $events_link = '<a href="admin.php?page=espresso_events">' |
|
| 133 | + . esc_html__('Events', 'event_espresso') |
|
| 134 | + . '</a>'; |
|
| 135 | + // add before other links |
|
| 136 | + array_unshift($links, $org_settings_link, $events_link); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return $links; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * _get_request |
|
| 145 | + * |
|
| 146 | + * @access public |
|
| 147 | + * @return void |
|
| 148 | + * @throws EE_Error |
|
| 149 | + * @throws ReflectionException |
|
| 150 | + */ |
|
| 151 | + public function get_request() |
|
| 152 | + { |
|
| 153 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 154 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * hide_admin_pages_except_maintenance_mode |
|
| 160 | + * |
|
| 161 | + * @access public |
|
| 162 | + * @param array $admin_page_folder_names |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
|
| 166 | + { |
|
| 167 | + return array( |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * init- should fire after shortcode, module, addon, other plugin (default priority), and even |
|
| 177 | + * EE_Front_Controller's init phases have run |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @return void |
|
| 181 | + * @throws EE_Error |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function init() |
|
| 185 | + { |
|
| 186 | + //only enable most of the EE_Admin IF we're not in full maintenance mode |
|
| 187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
| 188 | + //ok so we want to enable the entire admin |
|
| 189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
| 190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
| 192 | + //at a glance dashboard widget |
|
| 193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
| 194 | + //filter for get_edit_post_link used on comments for custom post types |
|
| 195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
| 196 | + } |
|
| 197 | + // run the admin page factory but ONLY if we are doing an ee admin ajax request |
|
| 198 | + if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | + try { |
|
| 200 | + //this loads the controller for the admin pages which will setup routing etc |
|
| 201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
| 202 | + } catch (EE_Error $e) { |
|
| 203 | + $e->get_error(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
| 207 | + //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
|
| 208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
| 209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
| 210 | + //exclude EE critical pages from all nav menus and wp_list_pages |
|
| 211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from |
|
| 217 | + * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in |
|
| 218 | + * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that |
|
| 219 | + * to override any queries found in the existing query for the given post type. Note that _default_query is not a |
|
| 220 | + * normal property on the post_type object. It's found ONLY in this particular context. |
|
| 221 | + * |
|
| 222 | + * @param object $post_type WP post type object |
|
| 223 | + * @return object WP post type object |
|
| 224 | + */ |
|
| 225 | + public function remove_pages_from_nav_menu($post_type) |
|
| 226 | + { |
|
| 227 | + //if this isn't the "pages" post type let's get out |
|
| 228 | + if ($post_type->name !== 'page') { |
|
| 229 | + return $post_type; |
|
| 230 | + } |
|
| 231 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 232 | + |
|
| 233 | + $post_type->_default_query = array( |
|
| 234 | + 'post__not_in' => $critical_pages, |
|
| 235 | + ); |
|
| 236 | + return $post_type; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * WP by default only shows three metaboxes in "nav-menus.php" for first times users. We want to make sure our |
|
| 242 | + * metaboxes get shown as well |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return void |
|
| 246 | + */ |
|
| 247 | + public function enable_hidden_ee_nav_menu_metaboxes() |
|
| 248 | + { |
|
| 249 | + global $wp_meta_boxes, $pagenow; |
|
| 250 | + if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | + return; |
|
| 252 | + } |
|
| 253 | + $user = wp_get_current_user(); |
|
| 254 | + //has this been done yet? |
|
| 255 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
| 260 | + $initial_meta_boxes = apply_filters( |
|
| 261 | + 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', |
|
| 262 | + array( |
|
| 263 | + 'nav-menu-theme-locations', |
|
| 264 | + 'add-page', |
|
| 265 | + 'add-custom-links', |
|
| 266 | + 'add-category', |
|
| 267 | + 'add-espresso_events', |
|
| 268 | + 'add-espresso_venues', |
|
| 269 | + 'add-espresso_event_categories', |
|
| 270 | + 'add-espresso_venue_categories', |
|
| 271 | + 'add-post-type-post', |
|
| 272 | + 'add-post-type-page', |
|
| 273 | + ) |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + if (is_array($hidden_meta_boxes)) { |
|
| 277 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
| 278 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
| 279 | + unset($hidden_meta_boxes[$key]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
| 285 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This method simply registers custom nav menu boxes for "nav_menus.php route" |
|
| 291 | + * Currently EE is using this to make sure there are menu options for our CPT archive page routes. |
|
| 292 | + * |
|
| 293 | + * @todo modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by |
|
| 294 | + * addons etc. |
|
| 295 | + * @access public |
|
| 296 | + * @return void |
|
| 297 | + */ |
|
| 298 | + public function register_custom_nav_menu_boxes() |
|
| 299 | + { |
|
| 300 | + add_meta_box( |
|
| 301 | + 'add-extra-nav-menu-pages', |
|
| 302 | + esc_html__('Event Espresso Pages', 'event_espresso'), |
|
| 303 | + array($this, 'ee_cpt_archive_pages'), |
|
| 304 | + 'nav-menus', |
|
| 305 | + 'side', |
|
| 306 | + 'core' |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Use this to edit the post link for our cpts so that the edit link points to the correct page. |
|
| 313 | + * |
|
| 314 | + * @since 4.3.0 |
|
| 315 | + * @param string $link the original link generated by wp |
|
| 316 | + * @param int $id post id |
|
| 317 | + * @return string the (maybe) modified link |
|
| 318 | + */ |
|
| 319 | + public function modify_edit_post_link($link, $id) |
|
| 320 | + { |
|
| 321 | + if (! $post = get_post($id)) { |
|
| 322 | + return $link; |
|
| 323 | + } |
|
| 324 | + if ($post->post_type === 'espresso_attendees') { |
|
| 325 | + $query_args = array( |
|
| 326 | + 'action' => 'edit_attendee', |
|
| 327 | + 'post' => $id, |
|
| 328 | + ); |
|
| 329 | + return EEH_URL::add_query_args_and_nonce( |
|
| 330 | + $query_args, |
|
| 331 | + admin_url('admin.php?page=espresso_registrations') |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + return $link; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + |
|
| 338 | + public function ee_cpt_archive_pages() |
|
| 339 | + { |
|
| 340 | + global $nav_menu_selected_id; |
|
| 341 | + |
|
| 342 | + $db_fields = false; |
|
| 343 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
| 344 | + $current_tab = 'event-archives'; |
|
| 345 | + |
|
| 346 | + /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
|
| 347 | 347 | $current_tab = 'search'; |
| 348 | 348 | }/**/ |
| 349 | 349 | |
| 350 | - $removed_args = array( |
|
| 351 | - 'action', |
|
| 352 | - 'customlink-tab', |
|
| 353 | - 'edit-menu-item', |
|
| 354 | - 'menu-item', |
|
| 355 | - 'page-tab', |
|
| 356 | - '_wpnonce', |
|
| 357 | - ); |
|
| 350 | + $removed_args = array( |
|
| 351 | + 'action', |
|
| 352 | + 'customlink-tab', |
|
| 353 | + 'edit-menu-item', |
|
| 354 | + 'menu-item', |
|
| 355 | + 'page-tab', |
|
| 356 | + '_wpnonce', |
|
| 357 | + ); |
|
| 358 | 358 | |
| 359 | - ?> |
|
| 359 | + ?> |
|
| 360 | 360 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
| 361 | 361 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 362 | 362 | <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
| 363 | 363 | <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" |
| 364 | 364 | href="<?php if ($nav_menu_selected_id) { |
| 365 | - echo esc_url( |
|
| 366 | - add_query_arg( |
|
| 367 | - 'extra-nav-menu-pages-tab', |
|
| 368 | - 'event-archives', |
|
| 369 | - remove_query_arg($removed_args) |
|
| 370 | - ) |
|
| 371 | - ); |
|
| 372 | - } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 365 | + echo esc_url( |
|
| 366 | + add_query_arg( |
|
| 367 | + 'extra-nav-menu-pages-tab', |
|
| 368 | + 'event-archives', |
|
| 369 | + remove_query_arg($removed_args) |
|
| 370 | + ) |
|
| 371 | + ); |
|
| 372 | + } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
| 373 | 373 | <?php _e('Event Archive Pages', 'event_espresso'); ?> |
| 374 | 374 | </a> |
| 375 | 375 | </li> |
| 376 | 376 | |
| 377 | 377 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
| 378 | - echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | - ?>"> |
|
| 378 | + echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
| 379 | + ?>"> |
|
| 380 | 380 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
| 381 | 381 | <?php |
| 382 | - $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | - $args['walker'] = $walker; |
|
| 384 | - echo walk_nav_menu_tree( |
|
| 385 | - array_map( |
|
| 386 | - array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | - $pages |
|
| 388 | - ), |
|
| 389 | - 0, |
|
| 390 | - (object) $args |
|
| 391 | - ); |
|
| 392 | - ?> |
|
| 382 | + $pages = $this->_get_extra_nav_menu_pages_items(); |
|
| 383 | + $args['walker'] = $walker; |
|
| 384 | + echo walk_nav_menu_tree( |
|
| 385 | + array_map( |
|
| 386 | + array($this, '_setup_extra_nav_menu_pages_items'), |
|
| 387 | + $pages |
|
| 388 | + ), |
|
| 389 | + 0, |
|
| 390 | + (object) $args |
|
| 391 | + ); |
|
| 392 | + ?> |
|
| 393 | 393 | </ul> |
| 394 | 394 | </div><!-- /.tabs-panel --> |
| 395 | 395 | |
| 396 | 396 | <p class="button-controls"> |
| 397 | 397 | <span class="list-controls"> |
| 398 | 398 | <a href="<?php |
| 399 | - echo esc_url(add_query_arg( |
|
| 400 | - array( |
|
| 401 | - 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | - 'selectall' => 1, |
|
| 403 | - ), |
|
| 404 | - remove_query_arg($removed_args) |
|
| 405 | - )); |
|
| 406 | - ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 399 | + echo esc_url(add_query_arg( |
|
| 400 | + array( |
|
| 401 | + 'extra-nav-menu-pages-tab' => 'event-archives', |
|
| 402 | + 'selectall' => 1, |
|
| 403 | + ), |
|
| 404 | + remove_query_arg($removed_args) |
|
| 405 | + )); |
|
| 406 | + ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
|
| 407 | 407 | </span> |
| 408 | 408 | <span class="add-to-menu"> |
| 409 | 409 | <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> |
@@ -416,491 +416,491 @@ discard block |
||
| 416 | 416 | |
| 417 | 417 | </div><!-- /.posttypediv --> |
| 418 | 418 | <?php |
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns an array of event archive nav items. |
|
| 424 | - * |
|
| 425 | - * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | - * method we use for getting the extra nav menu items |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - private function _get_extra_nav_menu_pages_items() |
|
| 430 | - { |
|
| 431 | - $menuitems[] = array( |
|
| 432 | - 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | - 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | - 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | - ); |
|
| 436 | - return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | - * the properties and converts it to the menu item object. |
|
| 443 | - * |
|
| 444 | - * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | - * @param $menu_item_values |
|
| 446 | - * @return stdClass |
|
| 447 | - */ |
|
| 448 | - private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | - { |
|
| 450 | - $menu_item = new stdClass(); |
|
| 451 | - $keys = array( |
|
| 452 | - 'ID' => 0, |
|
| 453 | - 'db_id' => 0, |
|
| 454 | - 'menu_item_parent' => 0, |
|
| 455 | - 'object_id' => -1, |
|
| 456 | - 'post_parent' => 0, |
|
| 457 | - 'type' => 'custom', |
|
| 458 | - 'object' => '', |
|
| 459 | - 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | - 'title' => '', |
|
| 461 | - 'url' => '', |
|
| 462 | - 'target' => '', |
|
| 463 | - 'attr_title' => '', |
|
| 464 | - 'description' => '', |
|
| 465 | - 'classes' => array(), |
|
| 466 | - 'xfn' => '', |
|
| 467 | - ); |
|
| 468 | - |
|
| 469 | - foreach ($keys as $key => $value) { |
|
| 470 | - $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | - } |
|
| 472 | - return $menu_item; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | - * EE_Admin_Page route is called. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function route_admin_request() |
|
| 483 | - { |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | - * |
|
| 490 | - * @return void |
|
| 491 | - */ |
|
| 492 | - public function wp_loaded() |
|
| 493 | - { |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * admin_init |
|
| 499 | - * |
|
| 500 | - * @access public |
|
| 501 | - * @return void |
|
| 502 | - * @throws EE_Error |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - */ |
|
| 505 | - public function admin_init() |
|
| 506 | - { |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | - * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | - * - check if doing post processing. |
|
| 512 | - * - check if doing post processing of one of EE CPTs |
|
| 513 | - * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | - */ |
|
| 515 | - if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | - EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | - * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | - * Pages" tab in the EE General Settings Admin page. |
|
| 525 | - * This is for user-proofing. |
|
| 526 | - */ |
|
| 527 | - add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | - * |
|
| 534 | - * @param string $output Current output. |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 537 | - public function modify_dropdown_pages($output) |
|
| 538 | - { |
|
| 539 | - //get critical pages |
|
| 540 | - $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | - |
|
| 542 | - //split current output by line break for easier parsing. |
|
| 543 | - $split_output = explode("\n", $output); |
|
| 544 | - |
|
| 545 | - //loop through to remove any critical pages from the array. |
|
| 546 | - foreach ($critical_pages as $page_id) { |
|
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 548 | - foreach ($split_output as $key => $haystack) { |
|
| 549 | - if (strpos($haystack, $needle) !== false) { |
|
| 550 | - unset($split_output[$key]); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - //replace output with the new contents |
|
| 556 | - return implode("\n", $split_output); |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | - * |
|
| 563 | - * @access public |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - public function enqueue_admin_scripts() |
|
| 567 | - { |
|
| 568 | - // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | - // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | - // calls. |
|
| 571 | - wp_enqueue_script( |
|
| 572 | - 'ee-inject-wp', |
|
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | - array('jquery'), |
|
| 575 | - EVENT_ESPRESSO_VERSION, |
|
| 576 | - true |
|
| 577 | - ); |
|
| 578 | - // register cookie script for future dependencies |
|
| 579 | - wp_register_script( |
|
| 580 | - 'jquery-cookie', |
|
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | - array('jquery'), |
|
| 583 | - '2.1', |
|
| 584 | - true |
|
| 585 | - ); |
|
| 586 | - //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | - // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | - if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | - //joyride style |
|
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | - wp_register_style( |
|
| 592 | - 'ee-joyride-css', |
|
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | - array('joyride-css'), |
|
| 595 | - EVENT_ESPRESSO_VERSION |
|
| 596 | - ); |
|
| 597 | - wp_register_script( |
|
| 598 | - 'joyride-modernizr', |
|
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | - array(), |
|
| 601 | - '2.1', |
|
| 602 | - true |
|
| 603 | - ); |
|
| 604 | - //joyride JS |
|
| 605 | - wp_register_script( |
|
| 606 | - 'jquery-joyride', |
|
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | - array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | - '2.1', |
|
| 610 | - true |
|
| 611 | - ); |
|
| 612 | - // wanna go for a joyride? |
|
| 613 | - wp_enqueue_style('ee-joyride-css'); |
|
| 614 | - wp_enqueue_script('jquery-joyride'); |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * display_admin_notices |
|
| 621 | - * |
|
| 622 | - * @access public |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function display_admin_notices() |
|
| 626 | - { |
|
| 627 | - echo EE_Error::get_notices(); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * get_persistent_admin_notices |
|
| 633 | - * |
|
| 634 | - * @access public |
|
| 635 | - * @return void |
|
| 636 | - */ |
|
| 637 | - public function get_persistent_admin_notices() |
|
| 638 | - { |
|
| 639 | - // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | - $args = array( |
|
| 641 | - 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | - ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | - : '', |
|
| 644 | - 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | - ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | - : '', |
|
| 647 | - ); |
|
| 648 | - $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | - //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | - //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | - //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | - //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | - if (! get_option('timezone_string')) { |
|
| 654 | - EE_Error::add_persistent_admin_notice( |
|
| 655 | - 'datetime_fix_notice', |
|
| 656 | - sprintf( |
|
| 657 | - esc_html__( |
|
| 658 | - '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | - 'event_espresso' |
|
| 660 | - ), |
|
| 661 | - '<strong>', |
|
| 662 | - '</strong>', |
|
| 663 | - '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | - '</a>', |
|
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | - array( |
|
| 667 | - 'page' => 'espresso_maintenance_settings', |
|
| 668 | - 'action' => 'datetime_tools' |
|
| 669 | - ), |
|
| 670 | - admin_url('admin.php') |
|
| 671 | - ) . '">' |
|
| 672 | - ) |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * dismiss_persistent_admin_notice |
|
| 681 | - * |
|
| 682 | - * @access public |
|
| 683 | - * @return void |
|
| 684 | - */ |
|
| 685 | - public function dismiss_ee_nag_notice_callback() |
|
| 686 | - { |
|
| 687 | - EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * @param array $elements |
|
| 693 | - * @return array |
|
| 694 | - * @throws \EE_Error |
|
| 695 | - */ |
|
| 696 | - public function dashboard_glance_items($elements) |
|
| 697 | - { |
|
| 698 | - $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | - $events = EEM_Event::instance()->count(); |
|
| 700 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | - array('page' => 'espresso_events'), |
|
| 702 | - admin_url('admin.php') |
|
| 703 | - ); |
|
| 704 | - $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | - $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | - $registrations = EEM_Registration::instance()->count( |
|
| 707 | - array( |
|
| 708 | - array( |
|
| 709 | - 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | - ), |
|
| 711 | - ) |
|
| 712 | - ); |
|
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | - array('page' => 'espresso_registrations'), |
|
| 715 | - admin_url('admin.php') |
|
| 716 | - ); |
|
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 718 | - _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | - number_format_i18n($registrations) |
|
| 720 | - ); |
|
| 721 | - $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | - |
|
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | - |
|
| 725 | - foreach ($items as $type => $item_properties) { |
|
| 726 | - $elements[] = sprintf( |
|
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | - $item_properties['url'], |
|
| 729 | - $item_properties['title'], |
|
| 730 | - $item_properties['text'] |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - return $elements; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * check_for_invalid_datetime_formats |
|
| 739 | - * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | - * their selected format can be parsed by PHP |
|
| 741 | - * |
|
| 742 | - * @access public |
|
| 743 | - * @param $value |
|
| 744 | - * @param $option |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @return string |
|
| 747 | - */ |
|
| 748 | - public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | - { |
|
| 750 | - // check for date_format or time_format |
|
| 751 | - switch ($option) { |
|
| 752 | - case 'date_format': |
|
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | - break; |
|
| 755 | - case 'time_format': |
|
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | - break; |
|
| 758 | - default: |
|
| 759 | - $date_time_format = false; |
|
| 760 | - } |
|
| 761 | - // do we have a date_time format to check ? |
|
| 762 | - if ($date_time_format) { |
|
| 763 | - $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | - |
|
| 765 | - if (is_array($error_msg)) { |
|
| 766 | - $msg = '<p>' |
|
| 767 | - . sprintf( |
|
| 768 | - esc_html__( |
|
| 769 | - 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - date($date_time_format), |
|
| 773 | - $date_time_format |
|
| 774 | - ) |
|
| 775 | - . '</p><p><ul>'; |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - foreach ($error_msg as $error) { |
|
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - $msg .= '</ul></p><p>' |
|
| 783 | - . sprintf( |
|
| 784 | - esc_html__( |
|
| 785 | - '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ), |
|
| 788 | - '<span style="color:#D54E21;">', |
|
| 789 | - '</span>' |
|
| 790 | - ) |
|
| 791 | - . '</p>'; |
|
| 792 | - |
|
| 793 | - // trigger WP settings error |
|
| 794 | - add_settings_error( |
|
| 795 | - 'date_format', |
|
| 796 | - 'date_format', |
|
| 797 | - $msg |
|
| 798 | - ); |
|
| 799 | - |
|
| 800 | - // set format to something valid |
|
| 801 | - switch ($option) { |
|
| 802 | - case 'date_format': |
|
| 803 | - $value = 'F j, Y'; |
|
| 804 | - break; |
|
| 805 | - case 'time_format': |
|
| 806 | - $value = 'g:i a'; |
|
| 807 | - break; |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - return $value; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | - * |
|
| 818 | - * @access public |
|
| 819 | - * @param $content |
|
| 820 | - * @return string |
|
| 821 | - */ |
|
| 822 | - public function its_eSpresso($content) |
|
| 823 | - { |
|
| 824 | - return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * espresso_admin_footer |
|
| 830 | - * |
|
| 831 | - * @access public |
|
| 832 | - * @return string |
|
| 833 | - */ |
|
| 834 | - public function espresso_admin_footer() |
|
| 835 | - { |
|
| 836 | - return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * static method for registering ee admin page. |
|
| 842 | - * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | - * |
|
| 844 | - * @since 4.3.0 |
|
| 845 | - * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | - * @see EE_Register_Admin_Page::register() |
|
| 847 | - * @param $page_basename |
|
| 848 | - * @param $page_path |
|
| 849 | - * @param array $config |
|
| 850 | - * @return void |
|
| 851 | - * @throws EE_Error |
|
| 852 | - */ |
|
| 853 | - public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | - { |
|
| 855 | - EE_Error::doing_it_wrong( |
|
| 856 | - __METHOD__, |
|
| 857 | - sprintf( |
|
| 858 | - esc_html__( |
|
| 859 | - 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | - 'event_espresso' |
|
| 861 | - ), |
|
| 862 | - $page_basename |
|
| 863 | - ), |
|
| 864 | - '4.3' |
|
| 865 | - ); |
|
| 866 | - if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | - $config['page_path'] = $page_path; |
|
| 868 | - } |
|
| 869 | - EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * @deprecated 4.8.41 |
|
| 875 | - * @access public |
|
| 876 | - * @param int $post_ID |
|
| 877 | - * @param \WP_Post $post |
|
| 878 | - * @return void |
|
| 879 | - */ |
|
| 880 | - public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | - { |
|
| 882 | - EE_Error::doing_it_wrong( |
|
| 883 | - __METHOD__, |
|
| 884 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | - '4.8.41' |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * @deprecated 4.8.41 |
|
| 892 | - * @access public |
|
| 893 | - * @param $option |
|
| 894 | - * @param $old_value |
|
| 895 | - * @param $value |
|
| 896 | - * @return void |
|
| 897 | - */ |
|
| 898 | - public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | - { |
|
| 900 | - EE_Error::doing_it_wrong( |
|
| 901 | - __METHOD__, |
|
| 902 | - esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | - '4.8.41' |
|
| 904 | - ); |
|
| 905 | - } |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns an array of event archive nav items. |
|
| 424 | + * |
|
| 425 | + * @todo for now this method is just in place so when it gets abstracted further we can substitute in whatever |
|
| 426 | + * method we use for getting the extra nav menu items |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + private function _get_extra_nav_menu_pages_items() |
|
| 430 | + { |
|
| 431 | + $menuitems[] = array( |
|
| 432 | + 'title' => esc_html__('Event List', 'event_espresso'), |
|
| 433 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
| 434 | + 'description' => esc_html__('Archive page for all events.', 'event_espresso'), |
|
| 435 | + ); |
|
| 436 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Setup nav menu walker item for usage in the event archive nav menu metabox. It receives a menu_item array with |
|
| 442 | + * the properties and converts it to the menu item object. |
|
| 443 | + * |
|
| 444 | + * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php |
|
| 445 | + * @param $menu_item_values |
|
| 446 | + * @return stdClass |
|
| 447 | + */ |
|
| 448 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) |
|
| 449 | + { |
|
| 450 | + $menu_item = new stdClass(); |
|
| 451 | + $keys = array( |
|
| 452 | + 'ID' => 0, |
|
| 453 | + 'db_id' => 0, |
|
| 454 | + 'menu_item_parent' => 0, |
|
| 455 | + 'object_id' => -1, |
|
| 456 | + 'post_parent' => 0, |
|
| 457 | + 'type' => 'custom', |
|
| 458 | + 'object' => '', |
|
| 459 | + 'type_label' => esc_html__('Extra Nav Menu Item', 'event_espresso'), |
|
| 460 | + 'title' => '', |
|
| 461 | + 'url' => '', |
|
| 462 | + 'target' => '', |
|
| 463 | + 'attr_title' => '', |
|
| 464 | + 'description' => '', |
|
| 465 | + 'classes' => array(), |
|
| 466 | + 'xfn' => '', |
|
| 467 | + ); |
|
| 468 | + |
|
| 469 | + foreach ($keys as $key => $value) { |
|
| 470 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
| 471 | + } |
|
| 472 | + return $menu_item; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an |
|
| 478 | + * EE_Admin_Page route is called. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function route_admin_request() |
|
| 483 | + { |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * wp_loaded should fire on the WordPress wp_loaded hook. This fires on a VERY late priority. |
|
| 489 | + * |
|
| 490 | + * @return void |
|
| 491 | + */ |
|
| 492 | + public function wp_loaded() |
|
| 493 | + { |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * admin_init |
|
| 499 | + * |
|
| 500 | + * @access public |
|
| 501 | + * @return void |
|
| 502 | + * @throws EE_Error |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + */ |
|
| 505 | + public function admin_init() |
|
| 506 | + { |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php), |
|
| 510 | + * so any hooking into core WP routes is taken care of. So in this next few lines of code: |
|
| 511 | + * - check if doing post processing. |
|
| 512 | + * - check if doing post processing of one of EE CPTs |
|
| 513 | + * - instantiate the corresponding EE CPT model for the post_type being processed. |
|
| 514 | + */ |
|
| 515 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
| 516 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 517 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting |
|
| 523 | + * critical pages. The only place critical pages need included in a generated dropdown is on the "Critical |
|
| 524 | + * Pages" tab in the EE General Settings Admin page. |
|
| 525 | + * This is for user-proofing. |
|
| 526 | + */ |
|
| 527 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection. |
|
| 533 | + * |
|
| 534 | + * @param string $output Current output. |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | + public function modify_dropdown_pages($output) |
|
| 538 | + { |
|
| 539 | + //get critical pages |
|
| 540 | + $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
|
| 541 | + |
|
| 542 | + //split current output by line break for easier parsing. |
|
| 543 | + $split_output = explode("\n", $output); |
|
| 544 | + |
|
| 545 | + //loop through to remove any critical pages from the array. |
|
| 546 | + foreach ($critical_pages as $page_id) { |
|
| 547 | + $needle = 'value="' . $page_id . '"'; |
|
| 548 | + foreach ($split_output as $key => $haystack) { |
|
| 549 | + if (strpos($haystack, $needle) !== false) { |
|
| 550 | + unset($split_output[$key]); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + //replace output with the new contents |
|
| 556 | + return implode("\n", $split_output); |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * enqueue all admin scripts that need loaded for admin pages |
|
| 562 | + * |
|
| 563 | + * @access public |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + public function enqueue_admin_scripts() |
|
| 567 | + { |
|
| 568 | + // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
|
| 569 | + // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script |
|
| 570 | + // calls. |
|
| 571 | + wp_enqueue_script( |
|
| 572 | + 'ee-inject-wp', |
|
| 573 | + EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 574 | + array('jquery'), |
|
| 575 | + EVENT_ESPRESSO_VERSION, |
|
| 576 | + true |
|
| 577 | + ); |
|
| 578 | + // register cookie script for future dependencies |
|
| 579 | + wp_register_script( |
|
| 580 | + 'jquery-cookie', |
|
| 581 | + EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 582 | + array('jquery'), |
|
| 583 | + '2.1', |
|
| 584 | + true |
|
| 585 | + ); |
|
| 586 | + //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again |
|
| 587 | + // via: add_filter('FHEE_load_joyride', '__return_true' ); |
|
| 588 | + if (apply_filters('FHEE_load_joyride', false)) { |
|
| 589 | + //joyride style |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | + wp_register_style( |
|
| 592 | + 'ee-joyride-css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 594 | + array('joyride-css'), |
|
| 595 | + EVENT_ESPRESSO_VERSION |
|
| 596 | + ); |
|
| 597 | + wp_register_script( |
|
| 598 | + 'joyride-modernizr', |
|
| 599 | + EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 600 | + array(), |
|
| 601 | + '2.1', |
|
| 602 | + true |
|
| 603 | + ); |
|
| 604 | + //joyride JS |
|
| 605 | + wp_register_script( |
|
| 606 | + 'jquery-joyride', |
|
| 607 | + EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 608 | + array('jquery-cookie', 'joyride-modernizr'), |
|
| 609 | + '2.1', |
|
| 610 | + true |
|
| 611 | + ); |
|
| 612 | + // wanna go for a joyride? |
|
| 613 | + wp_enqueue_style('ee-joyride-css'); |
|
| 614 | + wp_enqueue_script('jquery-joyride'); |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * display_admin_notices |
|
| 621 | + * |
|
| 622 | + * @access public |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function display_admin_notices() |
|
| 626 | + { |
|
| 627 | + echo EE_Error::get_notices(); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * get_persistent_admin_notices |
|
| 633 | + * |
|
| 634 | + * @access public |
|
| 635 | + * @return void |
|
| 636 | + */ |
|
| 637 | + public function get_persistent_admin_notices() |
|
| 638 | + { |
|
| 639 | + // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
|
| 640 | + $args = array( |
|
| 641 | + 'page' => EE_Registry::instance()->REQ->is_set('page') |
|
| 642 | + ? EE_Registry::instance()->REQ->get('page') |
|
| 643 | + : '', |
|
| 644 | + 'action' => EE_Registry::instance()->REQ->is_set('action') |
|
| 645 | + ? EE_Registry::instance()->REQ->get('action') |
|
| 646 | + : '', |
|
| 647 | + ); |
|
| 648 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, admin_url('admin.php')); |
|
| 649 | + //add dismissable notice for datetime changes. Only valid if site does not have a timezone_string set. |
|
| 650 | + //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
|
| 651 | + //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
|
| 652 | + //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
|
| 653 | + if (! get_option('timezone_string')) { |
|
| 654 | + EE_Error::add_persistent_admin_notice( |
|
| 655 | + 'datetime_fix_notice', |
|
| 656 | + sprintf( |
|
| 657 | + esc_html__( |
|
| 658 | + '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times. Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.', |
|
| 659 | + 'event_espresso' |
|
| 660 | + ), |
|
| 661 | + '<strong>', |
|
| 662 | + '</strong>', |
|
| 663 | + '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
|
| 664 | + '</a>', |
|
| 665 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | + array( |
|
| 667 | + 'page' => 'espresso_maintenance_settings', |
|
| 668 | + 'action' => 'datetime_tools' |
|
| 669 | + ), |
|
| 670 | + admin_url('admin.php') |
|
| 671 | + ) . '">' |
|
| 672 | + ) |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * dismiss_persistent_admin_notice |
|
| 681 | + * |
|
| 682 | + * @access public |
|
| 683 | + * @return void |
|
| 684 | + */ |
|
| 685 | + public function dismiss_ee_nag_notice_callback() |
|
| 686 | + { |
|
| 687 | + EE_Error::dismiss_persistent_admin_notice(); |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * @param array $elements |
|
| 693 | + * @return array |
|
| 694 | + * @throws \EE_Error |
|
| 695 | + */ |
|
| 696 | + public function dashboard_glance_items($elements) |
|
| 697 | + { |
|
| 698 | + $elements = is_array($elements) ? $elements : array($elements); |
|
| 699 | + $events = EEM_Event::instance()->count(); |
|
| 700 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 701 | + array('page' => 'espresso_events'), |
|
| 702 | + admin_url('admin.php') |
|
| 703 | + ); |
|
| 704 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
| 705 | + $items['events']['title'] = esc_html__('Click to view all Events', 'event_espresso'); |
|
| 706 | + $registrations = EEM_Registration::instance()->count( |
|
| 707 | + array( |
|
| 708 | + array( |
|
| 709 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete), |
|
| 710 | + ), |
|
| 711 | + ) |
|
| 712 | + ); |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | + array('page' => 'espresso_registrations'), |
|
| 715 | + admin_url('admin.php') |
|
| 716 | + ); |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | + _n('%s Registration', '%s Registrations', $registrations), |
|
| 719 | + number_format_i18n($registrations) |
|
| 720 | + ); |
|
| 721 | + $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
|
| 722 | + |
|
| 723 | + $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | + |
|
| 725 | + foreach ($items as $type => $item_properties) { |
|
| 726 | + $elements[] = sprintf( |
|
| 727 | + '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 728 | + $item_properties['url'], |
|
| 729 | + $item_properties['title'], |
|
| 730 | + $item_properties['text'] |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + return $elements; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * check_for_invalid_datetime_formats |
|
| 739 | + * if an admin changes their date or time format settings on the WP General Settings admin page, verify that |
|
| 740 | + * their selected format can be parsed by PHP |
|
| 741 | + * |
|
| 742 | + * @access public |
|
| 743 | + * @param $value |
|
| 744 | + * @param $option |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @return string |
|
| 747 | + */ |
|
| 748 | + public function check_for_invalid_datetime_formats($value, $option) |
|
| 749 | + { |
|
| 750 | + // check for date_format or time_format |
|
| 751 | + switch ($option) { |
|
| 752 | + case 'date_format': |
|
| 753 | + $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 754 | + break; |
|
| 755 | + case 'time_format': |
|
| 756 | + $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 757 | + break; |
|
| 758 | + default: |
|
| 759 | + $date_time_format = false; |
|
| 760 | + } |
|
| 761 | + // do we have a date_time format to check ? |
|
| 762 | + if ($date_time_format) { |
|
| 763 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
| 764 | + |
|
| 765 | + if (is_array($error_msg)) { |
|
| 766 | + $msg = '<p>' |
|
| 767 | + . sprintf( |
|
| 768 | + esc_html__( |
|
| 769 | + 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + date($date_time_format), |
|
| 773 | + $date_time_format |
|
| 774 | + ) |
|
| 775 | + . '</p><p><ul>'; |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + foreach ($error_msg as $error) { |
|
| 779 | + $msg .= '<li>' . $error . '</li>'; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + $msg .= '</ul></p><p>' |
|
| 783 | + . sprintf( |
|
| 784 | + esc_html__( |
|
| 785 | + '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ), |
|
| 788 | + '<span style="color:#D54E21;">', |
|
| 789 | + '</span>' |
|
| 790 | + ) |
|
| 791 | + . '</p>'; |
|
| 792 | + |
|
| 793 | + // trigger WP settings error |
|
| 794 | + add_settings_error( |
|
| 795 | + 'date_format', |
|
| 796 | + 'date_format', |
|
| 797 | + $msg |
|
| 798 | + ); |
|
| 799 | + |
|
| 800 | + // set format to something valid |
|
| 801 | + switch ($option) { |
|
| 802 | + case 'date_format': |
|
| 803 | + $value = 'F j, Y'; |
|
| 804 | + break; |
|
| 805 | + case 'time_format': |
|
| 806 | + $value = 'g:i a'; |
|
| 807 | + break; |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + return $value; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso" |
|
| 817 | + * |
|
| 818 | + * @access public |
|
| 819 | + * @param $content |
|
| 820 | + * @return string |
|
| 821 | + */ |
|
| 822 | + public function its_eSpresso($content) |
|
| 823 | + { |
|
| 824 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * espresso_admin_footer |
|
| 830 | + * |
|
| 831 | + * @access public |
|
| 832 | + * @return string |
|
| 833 | + */ |
|
| 834 | + public function espresso_admin_footer() |
|
| 835 | + { |
|
| 836 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * static method for registering ee admin page. |
|
| 842 | + * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register. |
|
| 843 | + * |
|
| 844 | + * @since 4.3.0 |
|
| 845 | + * @deprecated 4.3.0 Use EE_Register_Admin_Page::register() instead |
|
| 846 | + * @see EE_Register_Admin_Page::register() |
|
| 847 | + * @param $page_basename |
|
| 848 | + * @param $page_path |
|
| 849 | + * @param array $config |
|
| 850 | + * @return void |
|
| 851 | + * @throws EE_Error |
|
| 852 | + */ |
|
| 853 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) |
|
| 854 | + { |
|
| 855 | + EE_Error::doing_it_wrong( |
|
| 856 | + __METHOD__, |
|
| 857 | + sprintf( |
|
| 858 | + esc_html__( |
|
| 859 | + 'Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', |
|
| 860 | + 'event_espresso' |
|
| 861 | + ), |
|
| 862 | + $page_basename |
|
| 863 | + ), |
|
| 864 | + '4.3' |
|
| 865 | + ); |
|
| 866 | + if (class_exists('EE_Register_Admin_Page')) { |
|
| 867 | + $config['page_path'] = $page_path; |
|
| 868 | + } |
|
| 869 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * @deprecated 4.8.41 |
|
| 875 | + * @access public |
|
| 876 | + * @param int $post_ID |
|
| 877 | + * @param \WP_Post $post |
|
| 878 | + * @return void |
|
| 879 | + */ |
|
| 880 | + public static function parse_post_content_on_save($post_ID, $post) |
|
| 881 | + { |
|
| 882 | + EE_Error::doing_it_wrong( |
|
| 883 | + __METHOD__, |
|
| 884 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 885 | + '4.8.41' |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * @deprecated 4.8.41 |
|
| 892 | + * @access public |
|
| 893 | + * @param $option |
|
| 894 | + * @param $old_value |
|
| 895 | + * @param $value |
|
| 896 | + * @return void |
|
| 897 | + */ |
|
| 898 | + public function reset_page_for_posts_on_change($option, $old_value, $value) |
|
| 899 | + { |
|
| 900 | + EE_Error::doing_it_wrong( |
|
| 901 | + __METHOD__, |
|
| 902 | + esc_html__('Usage is deprecated', 'event_espresso'), |
|
| 903 | + '4.8.41' |
|
| 904 | + ); |
|
| 905 | + } |
|
| 906 | 906 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public static function instance() |
| 33 | 33 | { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if (! self::$_instance instanceof EE_Admin) { |
|
| 35 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | private function _define_all_constants() |
| 93 | 93 | { |
| 94 | - if (! defined('EE_ADMIN_URL')) { |
|
| 95 | - define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/'); |
|
| 96 | - define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/'); |
|
| 97 | - define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS); |
|
| 98 | - define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/'); |
|
| 94 | + if ( ! defined('EE_ADMIN_URL')) { |
|
| 95 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
| 96 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
| 97 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
| 98 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
| 99 | 99 | define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | // set $main_file in stone |
| 115 | 115 | static $main_file; |
| 116 | 116 | // if $main_file is not set yet |
| 117 | - if (! $main_file) { |
|
| 117 | + if ( ! $main_file) { |
|
| 118 | 118 | $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
| 119 | 119 | } |
| 120 | 120 | if ($plugin === $main_file) { |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) |
| 166 | 166 | { |
| 167 | 167 | return array( |
| 168 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
| 169 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
| 170 | - 'support' => EE_ADMIN_PAGES . 'support' . DS, |
|
| 168 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
| 169 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
| 170 | + 'support' => EE_ADMIN_PAGES.'support'.DS, |
|
| 171 | 171 | ); |
| 172 | 172 | } |
| 173 | 173 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
| 196 | 196 | } |
| 197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
| 198 | - if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
| 199 | 199 | try { |
| 200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
| 201 | 201 | EE_Registry::instance()->load_core('Admin_Page_Loader'); |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function enable_hidden_ee_nav_menu_metaboxes() |
| 248 | 248 | { |
| 249 | 249 | global $wp_meta_boxes, $pagenow; |
| 250 | - if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 250 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
| 251 | 251 | return; |
| 252 | 252 | } |
| 253 | 253 | $user = wp_get_current_user(); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | */ |
| 319 | 319 | public function modify_edit_post_link($link, $id) |
| 320 | 320 | { |
| 321 | - if (! $post = get_post($id)) { |
|
| 321 | + if ( ! $post = get_post($id)) { |
|
| 322 | 322 | return $link; |
| 323 | 323 | } |
| 324 | 324 | if ($post->post_type === 'espresso_attendees') { |
@@ -544,7 +544,7 @@ discard block |
||
| 544 | 544 | |
| 545 | 545 | //loop through to remove any critical pages from the array. |
| 546 | 546 | foreach ($critical_pages as $page_id) { |
| 547 | - $needle = 'value="' . $page_id . '"'; |
|
| 547 | + $needle = 'value="'.$page_id.'"'; |
|
| 548 | 548 | foreach ($split_output as $key => $haystack) { |
| 549 | 549 | if (strpos($haystack, $needle) !== false) { |
| 550 | 550 | unset($split_output[$key]); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | // calls. |
| 571 | 571 | wp_enqueue_script( |
| 572 | 572 | 'ee-inject-wp', |
| 573 | - EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', |
|
| 573 | + EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', |
|
| 574 | 574 | array('jquery'), |
| 575 | 575 | EVENT_ESPRESSO_VERSION, |
| 576 | 576 | true |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | // register cookie script for future dependencies |
| 579 | 579 | wp_register_script( |
| 580 | 580 | 'jquery-cookie', |
| 581 | - EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', |
|
| 581 | + EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', |
|
| 582 | 582 | array('jquery'), |
| 583 | 583 | '2.1', |
| 584 | 584 | true |
@@ -587,16 +587,16 @@ discard block |
||
| 587 | 587 | // via: add_filter('FHEE_load_joyride', '__return_true' ); |
| 588 | 588 | if (apply_filters('FHEE_load_joyride', false)) { |
| 589 | 589 | //joyride style |
| 590 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 590 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
| 591 | 591 | wp_register_style( |
| 592 | 592 | 'ee-joyride-css', |
| 593 | - EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', |
|
| 593 | + EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', |
|
| 594 | 594 | array('joyride-css'), |
| 595 | 595 | EVENT_ESPRESSO_VERSION |
| 596 | 596 | ); |
| 597 | 597 | wp_register_script( |
| 598 | 598 | 'joyride-modernizr', |
| 599 | - EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', |
|
| 599 | + EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', |
|
| 600 | 600 | array(), |
| 601 | 601 | '2.1', |
| 602 | 602 | true |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | //joyride JS |
| 605 | 605 | wp_register_script( |
| 606 | 606 | 'jquery-joyride', |
| 607 | - EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', |
|
| 607 | + EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', |
|
| 608 | 608 | array('jquery-cookie', 'joyride-modernizr'), |
| 609 | 609 | '2.1', |
| 610 | 610 | true |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | public function get_persistent_admin_notices() |
| 638 | 638 | { |
| 639 | 639 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
| 640 | - $args = array( |
|
| 640 | + $args = array( |
|
| 641 | 641 | 'page' => EE_Registry::instance()->REQ->is_set('page') |
| 642 | 642 | ? EE_Registry::instance()->REQ->get('page') |
| 643 | 643 | : '', |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version |
| 651 | 651 | //with this. But after enough time (indeterminate at this point) we can just remove this notice. |
| 652 | 652 | //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626 |
| 653 | - if (! get_option('timezone_string')) { |
|
| 653 | + if ( ! get_option('timezone_string')) { |
|
| 654 | 654 | EE_Error::add_persistent_admin_notice( |
| 655 | 655 | 'datetime_fix_notice', |
| 656 | 656 | sprintf( |
@@ -662,13 +662,13 @@ discard block |
||
| 662 | 662 | '</strong>', |
| 663 | 663 | '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">', |
| 664 | 664 | '</a>', |
| 665 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 665 | + '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
| 666 | 666 | array( |
| 667 | 667 | 'page' => 'espresso_maintenance_settings', |
| 668 | 668 | 'action' => 'datetime_tools' |
| 669 | 669 | ), |
| 670 | 670 | admin_url('admin.php') |
| 671 | - ) . '">' |
|
| 671 | + ).'">' |
|
| 672 | 672 | ) |
| 673 | 673 | ); |
| 674 | 674 | } |
@@ -710,21 +710,21 @@ discard block |
||
| 710 | 710 | ), |
| 711 | 711 | ) |
| 712 | 712 | ); |
| 713 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 713 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 714 | 714 | array('page' => 'espresso_registrations'), |
| 715 | 715 | admin_url('admin.php') |
| 716 | 716 | ); |
| 717 | - $items['registrations']['text'] = sprintf( |
|
| 717 | + $items['registrations']['text'] = sprintf( |
|
| 718 | 718 | _n('%s Registration', '%s Registrations', $registrations), |
| 719 | 719 | number_format_i18n($registrations) |
| 720 | 720 | ); |
| 721 | 721 | $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso'); |
| 722 | 722 | |
| 723 | - $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 723 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
| 724 | 724 | |
| 725 | 725 | foreach ($items as $type => $item_properties) { |
| 726 | 726 | $elements[] = sprintf( |
| 727 | - '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', |
|
| 727 | + '<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', |
|
| 728 | 728 | $item_properties['url'], |
| 729 | 729 | $item_properties['title'], |
| 730 | 730 | $item_properties['text'] |
@@ -750,10 +750,10 @@ discard block |
||
| 750 | 750 | // check for date_format or time_format |
| 751 | 751 | switch ($option) { |
| 752 | 752 | case 'date_format': |
| 753 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
| 753 | + $date_time_format = $value.' '.get_option('time_format'); |
|
| 754 | 754 | break; |
| 755 | 755 | case 'time_format': |
| 756 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
| 756 | + $date_time_format = get_option('date_format').' '.$value; |
|
| 757 | 757 | break; |
| 758 | 758 | default: |
| 759 | 759 | $date_time_format = false; |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | |
| 778 | 778 | foreach ($error_msg as $error) { |
| 779 | - $msg .= '<li>' . $error . '</li>'; |
|
| 779 | + $msg .= '<li>'.$error.'</li>'; |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | $msg .= '</ul></p><p>' |