@@ -13,93 +13,93 @@ |
||
| 13 | 13 | class EE_Has_Many_Relation extends EE_Model_Relation_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
| 18 | - * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
| 19 | - * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
| 20 | - * related models across the relation, and add-and-remove the relationships. |
|
| 21 | - * |
|
| 22 | - * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
| 23 | - * related models across this relation, block (prevent and add an |
|
| 24 | - * error) the deletion of this model |
|
| 25 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
| 26 | - * default |
|
| 27 | - */ |
|
| 28 | - public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
| 29 | - { |
|
| 30 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
| 31 | - } |
|
| 16 | + /** |
|
| 17 | + * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the |
|
| 18 | + * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but |
|
| 19 | + * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get |
|
| 20 | + * related models across the relation, and add-and-remove the relationships. |
|
| 21 | + * |
|
| 22 | + * @param boolean $block_deletes For this type of r elation, we block by default. If there are |
|
| 23 | + * related models across this relation, block (prevent and add an |
|
| 24 | + * error) the deletion of this model |
|
| 25 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
| 26 | + * default |
|
| 27 | + */ |
|
| 28 | + public function __construct($block_deletes = true, $blocking_delete_error_message = null) |
|
| 29 | + { |
|
| 30 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Gets the SQL string for performing the join between this model and the other model. |
|
| 36 | - * |
|
| 37 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
| 38 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
| 39 | - * other_model_primary_table.fk" etc |
|
| 40 | - * @throws \EE_Error |
|
| 41 | - */ |
|
| 42 | - public function get_join_statement($model_relation_chain) |
|
| 43 | - { |
|
| 44 | - //create the sql string like |
|
| 45 | - // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
| 46 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
| 47 | - $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 48 | - $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
| 49 | - $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
| 50 | - $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
| 51 | - $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
| 52 | - $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
| 34 | + /** |
|
| 35 | + * Gets the SQL string for performing the join between this model and the other model. |
|
| 36 | + * |
|
| 37 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
| 38 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
| 39 | + * other_model_primary_table.fk" etc |
|
| 40 | + * @throws \EE_Error |
|
| 41 | + */ |
|
| 42 | + public function get_join_statement($model_relation_chain) |
|
| 43 | + { |
|
| 44 | + //create the sql string like |
|
| 45 | + // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions |
|
| 46 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); |
|
| 47 | + $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 48 | + $pk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
| 49 | + $this->get_this_model()->get_this_model_name()) . $this_table_pk_field->get_table_alias(); |
|
| 50 | + $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, |
|
| 51 | + $this->get_other_model()->get_this_model_name()) . $other_table_fk_field->get_table_alias(); |
|
| 52 | + $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias); |
|
| 53 | 53 | |
| 54 | - return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
| 55 | - $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
| 56 | - } |
|
| 54 | + return $this->_left_join($fk_table, $fk_table_alias, $other_table_fk_field->get_table_column(), $pk_table_alias, |
|
| 55 | + $this_table_pk_field->get_table_column()) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
| 61 | - * you like. |
|
| 62 | - * |
|
| 63 | - * @param EE_Base_Class|int $this_obj_or_id |
|
| 64 | - * @param EE_Base_Class|int $other_obj_or_id |
|
| 65 | - * @param array $extra_join_model_fields_n_values |
|
| 66 | - * @return \EE_Base_Class |
|
| 67 | - * @throws \EE_Error |
|
| 68 | - */ |
|
| 69 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
| 70 | - { |
|
| 71 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 72 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 59 | + /** |
|
| 60 | + * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if |
|
| 61 | + * you like. |
|
| 62 | + * |
|
| 63 | + * @param EE_Base_Class|int $this_obj_or_id |
|
| 64 | + * @param EE_Base_Class|int $other_obj_or_id |
|
| 65 | + * @param array $extra_join_model_fields_n_values |
|
| 66 | + * @return \EE_Base_Class |
|
| 67 | + * @throws \EE_Error |
|
| 68 | + */ |
|
| 69 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
| 70 | + { |
|
| 71 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 72 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 73 | 73 | |
| 74 | - //find the field on the other model which is a foreign key to this model |
|
| 75 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 76 | - if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
| 77 | - //set that field on the other model to this model's ID |
|
| 78 | - $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
| 79 | - $other_model_obj->save(); |
|
| 80 | - } |
|
| 81 | - return $other_model_obj; |
|
| 82 | - } |
|
| 74 | + //find the field on the other model which is a foreign key to this model |
|
| 75 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 76 | + if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) { |
|
| 77 | + //set that field on the other model to this model's ID |
|
| 78 | + $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID()); |
|
| 79 | + $other_model_obj->save(); |
|
| 80 | + } |
|
| 81 | + return $other_model_obj; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
| 87 | - * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
| 88 | - * |
|
| 89 | - * @param EE_Base_Class|int $this_obj_or_id |
|
| 90 | - * @param EE_Base_Class|int $other_obj_or_id |
|
| 91 | - * @param array $where_query |
|
| 92 | - * @return \EE_Base_Class |
|
| 93 | - * @throws \EE_Error |
|
| 94 | - */ |
|
| 95 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
| 96 | - { |
|
| 97 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 98 | - //find the field on the other model which is a foreign key to this model |
|
| 99 | - $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 100 | - //set that field on the other model to this model's ID |
|
| 101 | - $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
| 102 | - $other_model_obj->save(); |
|
| 103 | - return $other_model_obj; |
|
| 104 | - } |
|
| 85 | + /** |
|
| 86 | + * Sets the other model object's foreign key to its default, instead of pointing to this model object. |
|
| 87 | + * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it |
|
| 88 | + * |
|
| 89 | + * @param EE_Base_Class|int $this_obj_or_id |
|
| 90 | + * @param EE_Base_Class|int $other_obj_or_id |
|
| 91 | + * @param array $where_query |
|
| 92 | + * @return \EE_Base_Class |
|
| 93 | + * @throws \EE_Error |
|
| 94 | + */ |
|
| 95 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
| 96 | + { |
|
| 97 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 98 | + //find the field on the other model which is a foreign key to this model |
|
| 99 | + $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
| 100 | + //set that field on the other model to this model's ID |
|
| 101 | + $other_model_obj->set($fk_field_on_other_model->get_name(), null, true); |
|
| 102 | + $other_model_obj->save(); |
|
| 103 | + return $other_model_obj; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * increments reserved by amount passed by $qty |
| 254 | 254 | * |
| 255 | 255 | * @param int $qty |
| 256 | - * @return boolean |
|
| 256 | + * @return boolean|null |
|
| 257 | 257 | */ |
| 258 | 258 | public function increase_reserved( $qty = 1 ) { |
| 259 | 259 | $reserved = $this->reserved() + absint( $qty ); |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | * decrements (subtracts) reserved by amount passed by $qty |
| 267 | 267 | * |
| 268 | 268 | * @param int $qty |
| 269 | - * @return boolean |
|
| 269 | + * @return boolean|null |
|
| 270 | 270 | */ |
| 271 | 271 | public function decrease_reserved( $qty = 1 ) { |
| 272 | 272 | $reserved = $this->reserved() - absint( $qty ); |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @param string $dt_frmt - string representation of date format defaults to WP settings |
| 412 | 412 | * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with |
| 413 | 413 | * the end date ie: Jan 01 "to" Dec 31 |
| 414 | - * @return mixed string on success, FALSE on fail |
|
| 414 | + * @return string string on success, FALSE on fail |
|
| 415 | 415 | * @throws \EE_Error |
| 416 | 416 | */ |
| 417 | 417 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * @param string $tm_format string representation of time format defaults to 'g:i a' |
| 484 | 484 | * @param string $conjunction conjunction junction what's your function ? |
| 485 | 485 | * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
| 486 | - * @return mixed string on success, FALSE on fail |
|
| 486 | + * @return string string on success, FALSE on fail |
|
| 487 | 487 | * @throws \EE_Error |
| 488 | 488 | */ |
| 489 | 489 | public function time_range( $tm_format = '', $conjunction = ' - ' ) { |
@@ -358,13 +358,13 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | |
| 361 | - /** |
|
| 362 | - * get event start date. Provide either the date format, or NULL to re-use the |
|
| 363 | - * last-used format, or '' to use the default date format |
|
| 364 | - * |
|
| 365 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 366 | - * @return mixed string on success, FALSE on fail |
|
| 367 | - */ |
|
| 361 | + /** |
|
| 362 | + * get event start date. Provide either the date format, or NULL to re-use the |
|
| 363 | + * last-used format, or '' to use the default date format |
|
| 364 | + * |
|
| 365 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 366 | + * @return mixed string on success, FALSE on fail |
|
| 367 | + */ |
|
| 368 | 368 | public function start_date( $dt_frmt = '' ) { |
| 369 | 369 | return $this->_show_datetime( 'D', 'start', $dt_frmt ); |
| 370 | 370 | } |
@@ -381,13 +381,13 @@ discard block |
||
| 381 | 381 | |
| 382 | 382 | |
| 383 | 383 | |
| 384 | - /** |
|
| 385 | - * get end date. Provide either the date format, or NULL to re-use the |
|
| 386 | - * last-used format, or '' to use the default date format |
|
| 387 | - * |
|
| 388 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 389 | - * @return mixed string on success, FALSE on fail |
|
| 390 | - */ |
|
| 384 | + /** |
|
| 385 | + * get end date. Provide either the date format, or NULL to re-use the |
|
| 386 | + * last-used format, or '' to use the default date format |
|
| 387 | + * |
|
| 388 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 389 | + * @return mixed string on success, FALSE on fail |
|
| 390 | + */ |
|
| 391 | 391 | public function end_date( $dt_frmt = '' ) { |
| 392 | 392 | return $this->_show_datetime( 'D', 'end', $dt_frmt ); |
| 393 | 393 | } |
@@ -509,23 +509,23 @@ discard block |
||
| 509 | 509 | /** |
| 510 | 510 | * This returns a range representation of the date and times. |
| 511 | 511 | * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
| 512 | - * Also, the return value is localized. |
|
| 513 | - * |
|
| 514 | - * @param string $dt_format |
|
| 512 | + * Also, the return value is localized. |
|
| 513 | + * |
|
| 514 | + * @param string $dt_format |
|
| 515 | 515 | * @param string $tm_format |
| 516 | 516 | * @param string $conjunction used between two different dates or times. |
| 517 | - * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 518 | - * @param string $separator used between the date and time formats. |
|
| 519 | - * ex: Dec 1, 2016{$separator}2pm |
|
| 517 | + * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 518 | + * @param string $separator used between the date and time formats. |
|
| 519 | + * ex: Dec 1, 2016{$separator}2pm |
|
| 520 | 520 | * @return string |
| 521 | 521 | * @throws \EE_Error |
| 522 | 522 | */ |
| 523 | 523 | public function date_and_time_range( |
| 524 | - $dt_format = '', |
|
| 525 | - $tm_format = '', |
|
| 526 | - $conjunction = ' - ' , |
|
| 527 | - $separator = ' ' |
|
| 528 | - ) { |
|
| 524 | + $dt_format = '', |
|
| 525 | + $tm_format = '', |
|
| 526 | + $conjunction = ' - ' , |
|
| 527 | + $separator = ' ' |
|
| 528 | + ) { |
|
| 529 | 529 | $dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt; |
| 530 | 530 | $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
| 531 | 531 | $full_format = $dt_format . $separator . $tm_format; |
@@ -539,14 +539,14 @@ discard block |
||
| 539 | 539 | //start and end date are the same but times are different |
| 540 | 540 | case ( $this->start_date() === $this->end_date() ) : |
| 541 | 541 | $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
| 542 | - . $conjunction |
|
| 543 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
| 542 | + . $conjunction |
|
| 543 | + . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
| 544 | 544 | break; |
| 545 | 545 | //all other conditions |
| 546 | 546 | default : |
| 547 | 547 | $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
| 548 | - . $conjunction |
|
| 549 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
| 548 | + . $conjunction |
|
| 549 | + . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
| 550 | 550 | break; |
| 551 | 551 | } |
| 552 | 552 | return $output; |
@@ -630,13 +630,13 @@ discard block |
||
| 630 | 630 | |
| 631 | 631 | |
| 632 | 632 | /** |
| 633 | - * get end date and time |
|
| 634 | - * |
|
| 635 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 636 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 637 | - * @return mixed string on success, FALSE on fail |
|
| 638 | - */ |
|
| 639 | - public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
| 633 | + * get end date and time |
|
| 634 | + * |
|
| 635 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 636 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 637 | + * @return mixed string on success, FALSE on fail |
|
| 638 | + */ |
|
| 639 | + public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
| 640 | 640 | return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format ); |
| 641 | 641 | } |
| 642 | 642 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | * date_format and the second value is the time format |
| 75 | 75 | * @return EE_Datetime |
| 76 | 76 | */ |
| 77 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 78 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 79 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 77 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 78 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 79 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * the website will be used. |
| 88 | 88 | * @return EE_Datetime |
| 89 | 89 | */ |
| 90 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 91 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 90 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 91 | + return new self($props_n_values, TRUE, $timezone); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | /** |
| 97 | 97 | * @param $name |
| 98 | 98 | */ |
| 99 | - public function set_name( $name ) { |
|
| 100 | - $this->set( 'DTT_name', $name ); |
|
| 99 | + public function set_name($name) { |
|
| 100 | + $this->set('DTT_name', $name); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | /** |
| 106 | 106 | * @param $description |
| 107 | 107 | */ |
| 108 | - public function set_description( $description ) { |
|
| 109 | - $this->set( 'DTT_description', $description ); |
|
| 108 | + public function set_description($description) { |
|
| 109 | + $this->set('DTT_description', $description); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
| 120 | 120 | */ |
| 121 | - public function set_start_date( $date ) { |
|
| 122 | - $this->_set_date_for( $date, 'DTT_EVT_start' ); |
|
| 121 | + public function set_start_date($date) { |
|
| 122 | + $this->_set_date_for($date, 'DTT_EVT_start'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | * |
| 132 | 132 | * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
| 133 | 133 | */ |
| 134 | - public function set_start_time( $time ) { |
|
| 135 | - $this->_set_time_for( $time, 'DTT_EVT_start' ); |
|
| 134 | + public function set_start_time($time) { |
|
| 135 | + $this->_set_time_for($time, 'DTT_EVT_start'); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -144,8 +144,8 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
| 146 | 146 | */ |
| 147 | - public function set_end_date( $date ) { |
|
| 148 | - $this->_set_date_for( $date, 'DTT_EVT_end' ); |
|
| 147 | + public function set_end_date($date) { |
|
| 148 | + $this->_set_date_for($date, 'DTT_EVT_end'); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
@@ -157,8 +157,8 @@ discard block |
||
| 157 | 157 | * |
| 158 | 158 | * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
| 159 | 159 | */ |
| 160 | - public function set_end_time( $time ) { |
|
| 161 | - $this->_set_time_for( $time, 'DTT_EVT_end' ); |
|
| 160 | + public function set_end_time($time) { |
|
| 161 | + $this->_set_time_for($time, 'DTT_EVT_end'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | * |
| 171 | 171 | * @param int $reg_limit |
| 172 | 172 | */ |
| 173 | - public function set_reg_limit( $reg_limit ) { |
|
| 174 | - $this->set( 'DTT_reg_limit', $reg_limit ); |
|
| 173 | + public function set_reg_limit($reg_limit) { |
|
| 174 | + $this->set('DTT_reg_limit', $reg_limit); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @return mixed int on success, FALSE on fail |
| 184 | 184 | */ |
| 185 | 185 | public function sold() { |
| 186 | - return $this->get_raw( 'DTT_sold' ); |
|
| 186 | + return $this->get_raw('DTT_sold'); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | * |
| 194 | 194 | * @param int $sold |
| 195 | 195 | */ |
| 196 | - public function set_sold( $sold ) { |
|
| 196 | + public function set_sold($sold) { |
|
| 197 | 197 | // sold can not go below zero |
| 198 | - $sold = max( 0, $sold ); |
|
| 199 | - $this->set( 'DTT_sold', $sold ); |
|
| 198 | + $sold = max(0, $sold); |
|
| 199 | + $this->set('DTT_sold', $sold); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | * increments sold by amount passed by $qty |
| 206 | 206 | * @param int $qty |
| 207 | 207 | */ |
| 208 | - public function increase_sold( $qty = 1 ) { |
|
| 208 | + public function increase_sold($qty = 1) { |
|
| 209 | 209 | $sold = $this->sold() + $qty; |
| 210 | 210 | // remove ticket reservation |
| 211 | - $this->decrease_reserved( $qty ); |
|
| 212 | - $this->set_sold( $sold ); |
|
| 211 | + $this->decrease_reserved($qty); |
|
| 212 | + $this->set_sold($sold); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * decrements (subtracts) sold amount passed by $qty |
| 219 | 219 | * @param int $qty |
| 220 | 220 | */ |
| 221 | - public function decrease_sold( $qty = 1 ) { |
|
| 221 | + public function decrease_sold($qty = 1) { |
|
| 222 | 222 | $sold = $this->sold() - $qty; |
| 223 | - $this->set_sold( $sold ); |
|
| 223 | + $this->set_sold($sold); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @return int |
| 232 | 232 | */ |
| 233 | 233 | public function reserved() { |
| 234 | - return $this->get_raw( 'DTT_reserved' ); |
|
| 234 | + return $this->get_raw('DTT_reserved'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @param int $reserved |
| 243 | 243 | */ |
| 244 | - public function set_reserved( $reserved ) { |
|
| 244 | + public function set_reserved($reserved) { |
|
| 245 | 245 | // reserved can not go below zero |
| 246 | - $reserved = max( 0, (int) $reserved ); |
|
| 247 | - $this->set( 'DTT_reserved', $reserved ); |
|
| 246 | + $reserved = max(0, (int) $reserved); |
|
| 247 | + $this->set('DTT_reserved', $reserved); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @param int $qty |
| 256 | 256 | * @return boolean |
| 257 | 257 | */ |
| 258 | - public function increase_reserved( $qty = 1 ) { |
|
| 259 | - $reserved = $this->reserved() + absint( $qty ); |
|
| 260 | - return $this->set_reserved( $reserved ); |
|
| 258 | + public function increase_reserved($qty = 1) { |
|
| 259 | + $reserved = $this->reserved() + absint($qty); |
|
| 260 | + return $this->set_reserved($reserved); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * @param int $qty |
| 269 | 269 | * @return boolean |
| 270 | 270 | */ |
| 271 | - public function decrease_reserved( $qty = 1 ) { |
|
| 272 | - $reserved = $this->reserved() - absint( $qty ); |
|
| 273 | - return $this->set_reserved( $reserved ); |
|
| 271 | + public function decrease_reserved($qty = 1) { |
|
| 272 | + $reserved = $this->reserved() - absint($qty); |
|
| 273 | + return $this->set_reserved($reserved); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | 293 | public function name() { |
| 294 | - return $this->get( 'DTT_name' ); |
|
| 294 | + return $this->get('DTT_name'); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @return string |
| 302 | 302 | */ |
| 303 | 303 | public function description() { |
| 304 | - return $this->get( 'DTT_description' ); |
|
| 304 | + return $this->get('DTT_description'); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * @return boolean TRUE if is primary, FALSE if not. |
| 312 | 312 | */ |
| 313 | 313 | public function is_primary() { |
| 314 | - return $this->get( 'DTT_is_primary' ); |
|
| 314 | + return $this->get('DTT_is_primary'); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @return int The order of the datetime for this event. |
| 322 | 322 | */ |
| 323 | 323 | public function order() { |
| 324 | - return $this->get( 'DTT_order' ); |
|
| 324 | + return $this->get('DTT_order'); |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @return int |
| 332 | 332 | */ |
| 333 | 333 | public function parent() { |
| 334 | - return $this->get( 'DTT_parent' ); |
|
| 334 | + return $this->get('DTT_parent'); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | |
@@ -347,10 +347,10 @@ discard block |
||
| 347 | 347 | * @param bool $echo - whether we echo or return (note echoing uses "pretty" formats, otherwise we use the standard formats) |
| 348 | 348 | * @return string|bool string on success, FALSE on fail |
| 349 | 349 | */ |
| 350 | - private function _show_datetime( $date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE ) { |
|
| 350 | + private function _show_datetime($date_or_time = NULL, $start_or_end = 'start', $dt_frmt = '', $tm_frmt = '', $echo = FALSE) { |
|
| 351 | 351 | $field_name = "DTT_EVT_{$start_or_end}"; |
| 352 | - $dtt = $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo ); |
|
| 353 | - if ( ! $echo ) { |
|
| 352 | + $dtt = $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, $date_or_time, $echo); |
|
| 353 | + if ( ! $echo) { |
|
| 354 | 354 | return $dtt; |
| 355 | 355 | } |
| 356 | 356 | return ''; |
@@ -365,8 +365,8 @@ discard block |
||
| 365 | 365 | * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
| 366 | 366 | * @return mixed string on success, FALSE on fail |
| 367 | 367 | */ |
| 368 | - public function start_date( $dt_frmt = '' ) { |
|
| 369 | - return $this->_show_datetime( 'D', 'start', $dt_frmt ); |
|
| 368 | + public function start_date($dt_frmt = '') { |
|
| 369 | + return $this->_show_datetime('D', 'start', $dt_frmt); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * Echoes start_date() |
| 376 | 376 | * @param string $dt_frmt |
| 377 | 377 | */ |
| 378 | - public function e_start_date( $dt_frmt = '' ) { |
|
| 379 | - $this->_show_datetime( 'D', 'start', $dt_frmt, NULL, TRUE ); |
|
| 378 | + public function e_start_date($dt_frmt = '') { |
|
| 379 | + $this->_show_datetime('D', 'start', $dt_frmt, NULL, TRUE); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
@@ -388,8 +388,8 @@ discard block |
||
| 388 | 388 | * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
| 389 | 389 | * @return mixed string on success, FALSE on fail |
| 390 | 390 | */ |
| 391 | - public function end_date( $dt_frmt = '' ) { |
|
| 392 | - return $this->_show_datetime( 'D', 'end', $dt_frmt ); |
|
| 391 | + public function end_date($dt_frmt = '') { |
|
| 392 | + return $this->_show_datetime('D', 'end', $dt_frmt); |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * Echoes the end date. See end_date() |
| 399 | 399 | * @param string $dt_frmt |
| 400 | 400 | */ |
| 401 | - public function e_end_date( $dt_frmt = '' ) { |
|
| 402 | - $this->_show_datetime( 'D', 'end', $dt_frmt, NULL, TRUE ); |
|
| 401 | + public function e_end_date($dt_frmt = '') { |
|
| 402 | + $this->_show_datetime('D', 'end', $dt_frmt, NULL, TRUE); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -414,11 +414,11 @@ discard block |
||
| 414 | 414 | * @return mixed string on success, FALSE on fail |
| 415 | 415 | * @throws \EE_Error |
| 416 | 416 | */ |
| 417 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
| 418 | - $dt_frmt = ! empty( $dt_frmt ) ? $dt_frmt : $this->_dt_frmt; |
|
| 419 | - $start = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_start', $dt_frmt ) ); |
|
| 420 | - $end = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_end', $dt_frmt ) ); |
|
| 421 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 417 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
| 418 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 419 | + $start = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt)); |
|
| 420 | + $end = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt)); |
|
| 421 | + return $start !== $end ? $start.$conjunction.$end : $start; |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | |
@@ -428,8 +428,8 @@ discard block |
||
| 428 | 428 | * @param string $conjunction |
| 429 | 429 | * @throws \EE_Error |
| 430 | 430 | */ |
| 431 | - public function e_date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
| 432 | - echo $this->date_range( $dt_frmt, $conjunction ); |
|
| 431 | + public function e_date_range($dt_frmt = '', $conjunction = ' - ') { |
|
| 432 | + echo $this->date_range($dt_frmt, $conjunction); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -440,8 +440,8 @@ discard block |
||
| 440 | 440 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
| 441 | 441 | * @return mixed string on success, FALSE on fail |
| 442 | 442 | */ |
| 443 | - public function start_time( $tm_format = '' ) { |
|
| 444 | - return $this->_show_datetime( 'T', 'start', NULL, $tm_format ); |
|
| 443 | + public function start_time($tm_format = '') { |
|
| 444 | + return $this->_show_datetime('T', 'start', NULL, $tm_format); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | /** |
| 450 | 450 | * @param string $tm_format |
| 451 | 451 | */ |
| 452 | - public function e_start_time( $tm_format = '' ) { |
|
| 453 | - $this->_show_datetime( 'T', 'start', NULL, $tm_format, TRUE ); |
|
| 452 | + public function e_start_time($tm_format = '') { |
|
| 453 | + $this->_show_datetime('T', 'start', NULL, $tm_format, TRUE); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -461,8 +461,8 @@ discard block |
||
| 461 | 461 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
| 462 | 462 | * @return mixed string on success, FALSE on fail |
| 463 | 463 | */ |
| 464 | - public function end_time( $tm_format = '' ) { |
|
| 465 | - return $this->_show_datetime( 'T', 'end', NULL, $tm_format ); |
|
| 464 | + public function end_time($tm_format = '') { |
|
| 465 | + return $this->_show_datetime('T', 'end', NULL, $tm_format); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | |
@@ -470,8 +470,8 @@ discard block |
||
| 470 | 470 | /** |
| 471 | 471 | * @param string $tm_format |
| 472 | 472 | */ |
| 473 | - public function e_end_time( $tm_format = '' ) { |
|
| 474 | - $this->_show_datetime( 'T', 'end', NULL, $tm_format, TRUE ); |
|
| 473 | + public function e_end_time($tm_format = '') { |
|
| 474 | + $this->_show_datetime('T', 'end', NULL, $tm_format, TRUE); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | |
@@ -486,11 +486,11 @@ discard block |
||
| 486 | 486 | * @return mixed string on success, FALSE on fail |
| 487 | 487 | * @throws \EE_Error |
| 488 | 488 | */ |
| 489 | - public function time_range( $tm_format = '', $conjunction = ' - ' ) { |
|
| 490 | - $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
|
| 491 | - $start = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_start', $tm_format ) ); |
|
| 492 | - $end = str_replace( ' ', ' ', $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ) ); |
|
| 493 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 489 | + public function time_range($tm_format = '', $conjunction = ' - ') { |
|
| 490 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 491 | + $start = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_start', $tm_format)); |
|
| 492 | + $end = str_replace(' ', ' ', $this->get_i18n_datetime('DTT_EVT_end', $tm_format)); |
|
| 493 | + return $start !== $end ? $start.$conjunction.$end : $start; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | * @param string $conjunction |
| 501 | 501 | * @throws \EE_Error |
| 502 | 502 | */ |
| 503 | - public function e_time_range( $tm_format = '', $conjunction = ' - ' ) { |
|
| 504 | - echo $this->time_range( $tm_format, $conjunction ); |
|
| 503 | + public function e_time_range($tm_format = '', $conjunction = ' - ') { |
|
| 504 | + echo $this->time_range($tm_format, $conjunction); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | |
@@ -523,30 +523,30 @@ discard block |
||
| 523 | 523 | public function date_and_time_range( |
| 524 | 524 | $dt_format = '', |
| 525 | 525 | $tm_format = '', |
| 526 | - $conjunction = ' - ' , |
|
| 526 | + $conjunction = ' - ', |
|
| 527 | 527 | $separator = ' ' |
| 528 | 528 | ) { |
| 529 | - $dt_format = ! empty( $dt_format ) ? $dt_format : $this->_dt_frmt; |
|
| 530 | - $tm_format = ! empty( $tm_format ) ? $tm_format : $this->_tm_frmt; |
|
| 531 | - $full_format = $dt_format . $separator . $tm_format; |
|
| 529 | + $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
| 530 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 531 | + $full_format = $dt_format.$separator.$tm_format; |
|
| 532 | 532 | |
| 533 | 533 | //the range output depends on various conditions |
| 534 | - switch ( true ) { |
|
| 534 | + switch (true) { |
|
| 535 | 535 | //start date timestamp and end date timestamp are the same. |
| 536 | - case ( $this->get_raw( 'DTT_EVT_start' ) === $this->get_raw( 'DTT_EVT_end' ) ) : |
|
| 537 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ); |
|
| 536 | + case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')) : |
|
| 537 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
| 538 | 538 | break; |
| 539 | 539 | //start and end date are the same but times are different |
| 540 | - case ( $this->start_date() === $this->end_date() ) : |
|
| 541 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
|
| 540 | + case ($this->start_date() === $this->end_date()) : |
|
| 541 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 542 | 542 | . $conjunction |
| 543 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $tm_format ); |
|
| 543 | + . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
| 544 | 544 | break; |
| 545 | 545 | //all other conditions |
| 546 | 546 | default : |
| 547 | - $output = $this->get_i18n_datetime( 'DTT_EVT_start', $full_format ) |
|
| 547 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 548 | 548 | . $conjunction |
| 549 | - . $this->get_i18n_datetime( 'DTT_EVT_end', $full_format ); |
|
| 549 | + . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
| 550 | 550 | break; |
| 551 | 551 | } |
| 552 | 552 | return $output; |
@@ -564,8 +564,8 @@ discard block |
||
| 564 | 564 | * @return void |
| 565 | 565 | * @throws \EE_Error |
| 566 | 566 | */ |
| 567 | - public function e_date_and_time_range( $dt_format = '', $tm_format = '', $conjunction = ' - ' ) { |
|
| 568 | - echo $this->date_and_time_range( $dt_format, $tm_format, $conjunction ); |
|
| 567 | + public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') { |
|
| 568 | + echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -577,8 +577,8 @@ discard block |
||
| 577 | 577 | * @param string $tm_format - string representation of time format defaults to 'g:i a' |
| 578 | 578 | * @return mixed string on success, FALSE on fail |
| 579 | 579 | */ |
| 580 | - public function start_date_and_time( $dt_format = '', $tm_format = '' ) { |
|
| 581 | - return $this->_show_datetime( '', 'start', $dt_format, $tm_format ); |
|
| 580 | + public function start_date_and_time($dt_format = '', $tm_format = '') { |
|
| 581 | + return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
@@ -587,8 +587,8 @@ discard block |
||
| 587 | 587 | * @param string $dt_frmt |
| 588 | 588 | * @param string $tm_format |
| 589 | 589 | */ |
| 590 | - public function e_start_date_and_time( $dt_frmt = '', $tm_format = '' ) { |
|
| 591 | - $this->_show_datetime( '', 'start', $dt_frmt, $tm_format, TRUE ); |
|
| 590 | + public function e_start_date_and_time($dt_frmt = '', $tm_format = '') { |
|
| 591 | + $this->_show_datetime('', 'start', $dt_frmt, $tm_format, TRUE); |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | |
@@ -602,11 +602,11 @@ discard block |
||
| 602 | 602 | * @param bool $round_up |
| 603 | 603 | * @return float|int|mixed |
| 604 | 604 | */ |
| 605 | - public function length( $units = 'seconds', $round_up = FALSE ) { |
|
| 606 | - $start = $this->get_raw( 'DTT_EVT_start' ); |
|
| 607 | - $end = $this->get_raw( 'DTT_EVT_end' ); |
|
| 605 | + public function length($units = 'seconds', $round_up = FALSE) { |
|
| 606 | + $start = $this->get_raw('DTT_EVT_start'); |
|
| 607 | + $end = $this->get_raw('DTT_EVT_end'); |
|
| 608 | 608 | $length_in_units = $end - $start; |
| 609 | - switch ( $units ) { |
|
| 609 | + switch ($units) { |
|
| 610 | 610 | //NOTE: We purposefully don't use "break;" in order to chain the divisions |
| 611 | 611 | /** @noinspection PhpMissingBreakStatementInspection */ |
| 612 | 612 | case 'days': |
@@ -619,10 +619,10 @@ discard block |
||
| 619 | 619 | $length_in_units /= 60; |
| 620 | 620 | case 'seconds': |
| 621 | 621 | default: |
| 622 | - $length_in_units = ceil( $length_in_units ); |
|
| 622 | + $length_in_units = ceil($length_in_units); |
|
| 623 | 623 | } |
| 624 | - if ( $round_up ) { |
|
| 625 | - $length_in_units = max( $length_in_units, 1 ); |
|
| 624 | + if ($round_up) { |
|
| 625 | + $length_in_units = max($length_in_units, 1); |
|
| 626 | 626 | } |
| 627 | 627 | return $length_in_units; |
| 628 | 628 | } |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | * @return mixed string on success, FALSE on fail |
| 638 | 638 | */ |
| 639 | 639 | public function end_date_and_time($dt_frmt = '', $tm_format = '') { |
| 640 | - return $this->_show_datetime( '', 'end', $dt_frmt, $tm_format ); |
|
| 640 | + return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | |
@@ -646,8 +646,8 @@ discard block |
||
| 646 | 646 | * @param string $dt_frmt |
| 647 | 647 | * @param string $tm_format |
| 648 | 648 | */ |
| 649 | - public function e_end_date_and_time( $dt_frmt = '', $tm_format = '' ) { |
|
| 650 | - $this->_show_datetime( '', 'end', $dt_frmt, $tm_format, TRUE ); |
|
| 649 | + public function e_end_date_and_time($dt_frmt = '', $tm_format = '') { |
|
| 650 | + $this->_show_datetime('', 'end', $dt_frmt, $tm_format, TRUE); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @return int |
| 659 | 659 | */ |
| 660 | 660 | public function start() { |
| 661 | - return $this->get_raw( 'DTT_EVT_start' ); |
|
| 661 | + return $this->get_raw('DTT_EVT_start'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -669,7 +669,7 @@ discard block |
||
| 669 | 669 | * @return int |
| 670 | 670 | */ |
| 671 | 671 | public function end() { |
| 672 | - return $this->get_raw( 'DTT_EVT_end' ); |
|
| 672 | + return $this->get_raw('DTT_EVT_end'); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | * @return mixed int on success, FALSE on fail |
| 681 | 681 | */ |
| 682 | 682 | public function reg_limit() { |
| 683 | - return $this->get_raw( 'DTT_reg_limit' ); |
|
| 683 | + return $this->get_raw('DTT_reg_limit'); |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | |
@@ -708,15 +708,15 @@ discard block |
||
| 708 | 708 | * the spaces remaining for this particular datetime, hence the flag. |
| 709 | 709 | * @return int |
| 710 | 710 | */ |
| 711 | - public function spaces_remaining( $consider_tickets = FALSE ) { |
|
| 711 | + public function spaces_remaining($consider_tickets = FALSE) { |
|
| 712 | 712 | // tickets remaining available for purchase |
| 713 | 713 | //no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
| 714 | 714 | $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
| 715 | - if ( ! $consider_tickets ) { |
|
| 715 | + if ( ! $consider_tickets) { |
|
| 716 | 716 | return $dtt_remaining; |
| 717 | 717 | } |
| 718 | 718 | $tickets_remaining = $this->tickets_remaining(); |
| 719 | - return min( $dtt_remaining, $tickets_remaining ); |
|
| 719 | + return min($dtt_remaining, $tickets_remaining); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -727,19 +727,19 @@ discard block |
||
| 727 | 727 | * @param array $query_params like EEM_Base::get_all's |
| 728 | 728 | * @return int |
| 729 | 729 | */ |
| 730 | - public function tickets_remaining( $query_params = array() ) { |
|
| 730 | + public function tickets_remaining($query_params = array()) { |
|
| 731 | 731 | $sum = 0; |
| 732 | - $tickets = $this->tickets( $query_params ); |
|
| 733 | - if ( ! empty( $tickets ) ) { |
|
| 734 | - foreach ( $tickets as $ticket ) { |
|
| 735 | - if ( $ticket instanceof EE_Ticket ) { |
|
| 732 | + $tickets = $this->tickets($query_params); |
|
| 733 | + if ( ! empty($tickets)) { |
|
| 734 | + foreach ($tickets as $ticket) { |
|
| 735 | + if ($ticket instanceof EE_Ticket) { |
|
| 736 | 736 | // get the actual amount of tickets that can be sold |
| 737 | - $qty = $ticket->qty( 'saleable' ); |
|
| 738 | - if ( $qty === EE_INF ) { |
|
| 737 | + $qty = $ticket->qty('saleable'); |
|
| 738 | + if ($qty === EE_INF) { |
|
| 739 | 739 | return EE_INF; |
| 740 | 740 | } |
| 741 | 741 | // no negative ticket quantities plz |
| 742 | - if ( $qty > 0 ) { |
|
| 742 | + if ($qty > 0) { |
|
| 743 | 743 | $sum += $qty; |
| 744 | 744 | } |
| 745 | 745 | } |
@@ -756,8 +756,8 @@ discard block |
||
| 756 | 756 | * @param array $query_params like EEM_Base::get_all's |
| 757 | 757 | * @return int |
| 758 | 758 | */ |
| 759 | - public function sum_tickets_initially_available( $query_params = array() ) { |
|
| 760 | - return $this->sum_related( 'Ticket', $query_params, 'TKT_qty' ); |
|
| 759 | + public function sum_tickets_initially_available($query_params = array()) { |
|
| 760 | + return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | * @return int |
| 770 | 770 | */ |
| 771 | 771 | public function total_tickets_available_at_this_datetime() { |
| 772 | - return $this->spaces_remaining( true ); |
|
| 772 | + return $this->spaces_remaining(true); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return boolean |
| 781 | 781 | */ |
| 782 | 782 | public function is_upcoming() { |
| 783 | - return ( $this->get_raw( 'DTT_EVT_start' ) > time() ); |
|
| 783 | + return ($this->get_raw('DTT_EVT_start') > time()); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | * @return boolean |
| 791 | 791 | */ |
| 792 | 792 | public function is_active() { |
| 793 | - return ( $this->get_raw( 'DTT_EVT_start' ) < time() && $this->get_raw( 'DTT_EVT_end' ) > time() ); |
|
| 793 | + return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | * @return boolean |
| 801 | 801 | */ |
| 802 | 802 | public function is_expired() { |
| 803 | - return ( $this->get_raw( 'DTT_EVT_end' ) < time() ); |
|
| 803 | + return ($this->get_raw('DTT_EVT_end') < time()); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | |
@@ -811,16 +811,16 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_active_status() { |
| 813 | 813 | $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
| 814 | - if ( $total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1 ) { |
|
| 814 | + if ($total_tickets_for_this_dtt !== FALSE && $total_tickets_for_this_dtt < 1) { |
|
| 815 | 815 | return EE_Datetime::sold_out; |
| 816 | 816 | } |
| 817 | - if ( $this->is_expired() ) { |
|
| 817 | + if ($this->is_expired()) { |
|
| 818 | 818 | return EE_Datetime::expired; |
| 819 | 819 | } |
| 820 | - if ( $this->is_upcoming() ) { |
|
| 820 | + if ($this->is_upcoming()) { |
|
| 821 | 821 | return EE_Datetime::upcoming; |
| 822 | 822 | } |
| 823 | - if ( $this->is_active() ) { |
|
| 823 | + if ($this->is_active()) { |
|
| 824 | 824 | return EE_Datetime::active; |
| 825 | 825 | } |
| 826 | 826 | return NULL; |
@@ -834,24 +834,24 @@ discard block |
||
| 834 | 834 | * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
| 835 | 835 | * @return string |
| 836 | 836 | */ |
| 837 | - public function get_dtt_display_name( $use_dtt_name = FALSE ) { |
|
| 838 | - if ( $use_dtt_name ) { |
|
| 837 | + public function get_dtt_display_name($use_dtt_name = FALSE) { |
|
| 838 | + if ($use_dtt_name) { |
|
| 839 | 839 | $dtt_name = $this->name(); |
| 840 | - if ( !empty( $dtt_name ) ) { |
|
| 840 | + if ( ! empty($dtt_name)) { |
|
| 841 | 841 | return $dtt_name; |
| 842 | 842 | } |
| 843 | 843 | } |
| 844 | 844 | //first condition is to see if the months are different |
| 845 | - if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) ) { |
|
| 846 | - $display_date = $this->start_date( 'M j\, Y g:i a' ) . ' - ' . $this->end_date( 'M j\, Y g:i a' ); |
|
| 845 | + if (date('m', $this->get_raw('DTT_EVT_start')) != date('m', $this->get_raw('DTT_EVT_end'))) { |
|
| 846 | + $display_date = $this->start_date('M j\, Y g:i a').' - '.$this->end_date('M j\, Y g:i a'); |
|
| 847 | 847 | //next condition is if its the same month but different day |
| 848 | 848 | } |
| 849 | 849 | else { |
| 850 | - if ( date( 'm', $this->get_raw( 'DTT_EVT_start' ) ) == date( 'm', $this->get_raw( 'DTT_EVT_end' ) ) && date( 'd', $this->get_raw( 'DTT_EVT_start' ) ) != date( 'd', $this->get_raw( 'DTT_EVT_end' ) ) ) { |
|
| 851 | - $display_date = $this->start_date( 'M j\, g:i a' ) . ' - ' . $this->end_date( 'M j\, g:i a Y' ); |
|
| 850 | + if (date('m', $this->get_raw('DTT_EVT_start')) == date('m', $this->get_raw('DTT_EVT_end')) && date('d', $this->get_raw('DTT_EVT_start')) != date('d', $this->get_raw('DTT_EVT_end'))) { |
|
| 851 | + $display_date = $this->start_date('M j\, g:i a').' - '.$this->end_date('M j\, g:i a Y'); |
|
| 852 | 852 | } |
| 853 | 853 | else { |
| 854 | - $display_date = $this->start_date( 'F j\, Y' ) . ' @ ' . $this->start_date( 'g:i a' ) . ' - ' . $this->end_date( 'g:i a' ); |
|
| 854 | + $display_date = $this->start_date('F j\, Y').' @ '.$this->start_date('g:i a').' - '.$this->end_date('g:i a'); |
|
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | return $display_date; |
@@ -865,8 +865,8 @@ discard block |
||
| 865 | 865 | *@param array $query_params see EEM_Base::get_all() |
| 866 | 866 | * @return EE_Ticket[] |
| 867 | 867 | */ |
| 868 | - public function tickets( $query_params = array() ) { |
|
| 869 | - return $this->get_many_related( 'Ticket', $query_params ); |
|
| 868 | + public function tickets($query_params = array()) { |
|
| 869 | + return $this->get_many_related('Ticket', $query_params); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | |
@@ -876,21 +876,21 @@ discard block |
||
| 876 | 876 | * @param array $query_params like EEM_Base::get_all's |
| 877 | 877 | * @return EE_Ticket[] |
| 878 | 878 | */ |
| 879 | - public function ticket_types_available_for_purchase( $query_params = array() ) { |
|
| 879 | + public function ticket_types_available_for_purchase($query_params = array()) { |
|
| 880 | 880 | // first check if datetime is valid |
| 881 | - if ( ! ( $this->is_upcoming() || $this->is_active() ) || $this->sold_out() ) { |
|
| 881 | + if ( ! ($this->is_upcoming() || $this->is_active()) || $this->sold_out()) { |
|
| 882 | 882 | return array(); |
| 883 | 883 | } |
| 884 | - if ( empty( $query_params ) ) { |
|
| 884 | + if (empty($query_params)) { |
|
| 885 | 885 | $query_params = array( |
| 886 | 886 | array( |
| 887 | - 'TKT_start_date' => array( '<=', EEM_Ticket::instance()->current_time_for_query( 'TKT_start_date' ) ), |
|
| 888 | - 'TKT_end_date' => array( '>=', EEM_Ticket::instance()->current_time_for_query( 'TKT_end_date' ) ), |
|
| 887 | + 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
| 888 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 889 | 889 | 'TKT_deleted' => false |
| 890 | 890 | ) |
| 891 | 891 | ); |
| 892 | 892 | } |
| 893 | - return $this->tickets( $query_params ); |
|
| 893 | + return $this->tickets($query_params); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | * @return EE_Event |
| 901 | 901 | */ |
| 902 | 902 | public function event() { |
| 903 | - return $this->get_first_related( 'Event' ); |
|
| 903 | + return $this->get_first_related('Event'); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -912,13 +912,13 @@ discard block |
||
| 912 | 912 | */ |
| 913 | 913 | public function update_sold() { |
| 914 | 914 | $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
| 915 | - array( array( |
|
| 915 | + array(array( |
|
| 916 | 916 | 'STS_ID' => EEM_Registration::status_id_approved, |
| 917 | 917 | 'REG_deleted' => 0, |
| 918 | 918 | 'Ticket.Datetime.DTT_ID' => $this->ID(), |
| 919 | - ) ) |
|
| 919 | + )) |
|
| 920 | 920 | ); |
| 921 | - $this->set( 'DTT_sold', $count_regs_for_this_datetime ); |
|
| 921 | + $this->set('DTT_sold', $count_regs_for_this_datetime); |
|
| 922 | 922 | $this->save(); |
| 923 | 923 | return $count_regs_for_this_datetime; |
| 924 | 924 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @access public |
| 40 | 40 | * @param int $EVT_ID |
| 41 | - * @return object |
|
| 41 | + * @return null|boolean |
|
| 42 | 42 | */ |
| 43 | 43 | public static function get_event( $EVT_ID = 0 ) { |
| 44 | 44 | $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint( $EVT_ID ); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @access public |
| 118 | 118 | * @param int $EVT_ID |
| 119 | - * @return string |
|
| 119 | + * @return boolean |
|
| 120 | 120 | */ |
| 121 | 121 | public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
| 122 | 122 | $event = EEH_Event_View::get_event( $EVT_ID ); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * event_active_status |
| 137 | 137 | * |
| 138 | 138 | * @access public |
| 139 | - * @param null $num_words |
|
| 139 | + * @param integer $num_words |
|
| 140 | 140 | * @param null $more |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | * |
| 429 | 429 | * @access public |
| 430 | 430 | * @param int $EVT_ID |
| 431 | - * @param null $include_expired |
|
| 431 | + * @param false|null $include_expired |
|
| 432 | 432 | * @param bool $include_deleted |
| 433 | 433 | * @param null $limit |
| 434 | 434 | * @return EE_Datetime[] |
@@ -148,11 +148,11 @@ discard block |
||
| 148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
| 149 | 149 | the_content(); |
| 150 | 150 | } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
| 151 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 151 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 152 | 152 | // AND an excerpt actually exists |
| 153 | 153 | the_excerpt(); |
| 154 | 154 | } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
| 155 | - // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 155 | + // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 156 | 156 | // but NO excerpt actually exists, so we need to create one |
| 157 | 157 | if ( ! empty( $num_words )) { |
| 158 | 158 | if ( empty( $more )) { |
@@ -161,32 +161,32 @@ discard block |
||
| 161 | 161 | $more .= ' class="more-link"'; |
| 162 | 162 | $more .= \EED_Events_Archive::link_target(); |
| 163 | 163 | $more .= '>' . $more_link_text . '</a>'; |
| 164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 164 | + $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 165 | 165 | } |
| 166 | 166 | $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
| 167 | 167 | |
| 168 | 168 | $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
| 169 | - } else { |
|
| 170 | - $content = get_the_content(); |
|
| 169 | + } else { |
|
| 170 | + $content = get_the_content(); |
|
| 171 | 171 | } |
| 172 | 172 | global $allowedtags; |
| 173 | 173 | // make sure links are allowed |
| 174 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
| 175 | - ? $allowedtags['a'] |
|
| 176 | - : array(); |
|
| 177 | - // as well as target attribute |
|
| 178 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 179 | - ? $allowedtags['a']['target'] |
|
| 180 | - : false; |
|
| 181 | - // but get previous value so we can reset it |
|
| 182 | - $prev_value = $allowedtags['a']['target']; |
|
| 183 | - $allowedtags['a']['target'] = true; |
|
| 174 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
| 175 | + ? $allowedtags['a'] |
|
| 176 | + : array(); |
|
| 177 | + // as well as target attribute |
|
| 178 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 179 | + ? $allowedtags['a']['target'] |
|
| 180 | + : false; |
|
| 181 | + // but get previous value so we can reset it |
|
| 182 | + $prev_value = $allowedtags['a']['target']; |
|
| 183 | + $allowedtags['a']['target'] = true; |
|
| 184 | 184 | $content = wp_kses( $content, $allowedtags ); |
| 185 | 185 | $content = strip_shortcodes( $content ); |
| 186 | 186 | echo apply_filters( 'the_content', $content ); |
| 187 | 187 | $allowedtags['a']['target'] = $prev_value; |
| 188 | - } else { |
|
| 189 | - // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 188 | + } else { |
|
| 189 | + // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
|
| 190 | 190 | echo apply_filters( 'the_content', '' ); |
| 191 | 191 | } |
| 192 | 192 | return ob_get_clean(); |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | $url = get_term_link( $term, 'espresso_venue_categories' ); |
| 235 | 235 | if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
| 236 | 236 | $category_links[] = '<a href="' . esc_url( $url ) |
| 237 | - . '" rel="tag"' |
|
| 238 | - . \EED_Events_Archive::link_target() |
|
| 239 | - .'>' |
|
| 240 | - . $term->name |
|
| 241 | - . '</a>'; |
|
| 237 | + . '" rel="tag"' |
|
| 238 | + . \EED_Events_Archive::link_target() |
|
| 239 | + .'>' |
|
| 240 | + . $term->name |
|
| 241 | + . '</a>'; |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -40,27 +40,27 @@ discard block |
||
| 40 | 40 | * @param int $EVT_ID |
| 41 | 41 | * @return object |
| 42 | 42 | */ |
| 43 | - public static function get_event( $EVT_ID = 0 ) { |
|
| 44 | - $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint( $EVT_ID ); |
|
| 43 | + public static function get_event($EVT_ID = 0) { |
|
| 44 | + $EVT_ID = $EVT_ID instanceof WP_Post ? $EVT_ID->ID : absint($EVT_ID); |
|
| 45 | 45 | // do we already have the Event you are looking for? |
| 46 | - if ( EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID ) { |
|
| 46 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
| 47 | 47 | return EEH_Event_View::$_event; |
| 48 | 48 | } |
| 49 | 49 | EEH_Event_View::$_event = NULL; |
| 50 | 50 | // international newspaper? |
| 51 | 51 | global $post; |
| 52 | 52 | // if this is being called from an EE_Event post, then we can just grab the attached EE_Event object |
| 53 | - if ( isset( $post->post_type ) && $post->post_type == 'espresso_events' || $EVT_ID ) { |
|
| 53 | + if (isset($post->post_type) && $post->post_type == 'espresso_events' || $EVT_ID) { |
|
| 54 | 54 | // d( $post ); |
| 55 | 55 | // grab the event we're looking for |
| 56 | - if ( isset( $post->EE_Event ) && ( $EVT_ID == 0 || ( $EVT_ID == $post->ID ))) { |
|
| 56 | + if (isset($post->EE_Event) && ($EVT_ID == 0 || ($EVT_ID == $post->ID))) { |
|
| 57 | 57 | EEH_Event_View::$_event = $post->EE_Event; |
| 58 | 58 | // d( EEH_Event_View::$_event ); |
| 59 | 59 | } |
| 60 | 60 | // now if we STILL do NOT have an EE_Event model object, BUT we have an Event ID... |
| 61 | - if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID ) { |
|
| 61 | + if ( ! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
| 62 | 62 | // sigh... pull it from the db |
| 63 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
| 63 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 64 | 64 | // d( EEH_Event_View::$_event ); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @param int $EVT_ID |
| 77 | 77 | * @return boolean |
| 78 | 78 | */ |
| 79 | - public static function display_ticket_selector( $EVT_ID = 0 ) { |
|
| 80 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 79 | + public static function display_ticket_selector($EVT_ID = 0) { |
|
| 80 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 81 | 81 | return $event instanceof EE_Event ? $event->display_ticket_selector() : FALSE; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | * @param int $EVT_ID |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public static function event_status( $EVT_ID = 0 ) { |
|
| 94 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 95 | - return $event instanceof EE_Event ? $event->pretty_active_status( FALSE ) : ''; |
|
| 93 | + public static function event_status($EVT_ID = 0) { |
|
| 94 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 95 | + return $event instanceof EE_Event ? $event->pretty_active_status(FALSE) : ''; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @param int $EVT_ID |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public static function event_active_status( $EVT_ID = 0 ) { |
|
| 108 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 107 | + public static function event_active_status($EVT_ID = 0) { |
|
| 108 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 109 | 109 | return $event instanceof EE_Event ? $event->pretty_active_status() : 'inactive'; |
| 110 | 110 | } |
| 111 | 111 | |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | * @param int $EVT_ID |
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | - public static function event_has_content_or_excerpt( $EVT_ID = 0 ) { |
|
| 122 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 121 | + public static function event_has_content_or_excerpt($EVT_ID = 0) { |
|
| 122 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 123 | 123 | $has_content_or_excerpt = FALSE; |
| 124 | - if ( $event instanceof EE_Event ) { |
|
| 125 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description( NULL, NULL, TRUE ) != '' ? TRUE : FALSE; |
|
| 124 | + if ($event instanceof EE_Event) { |
|
| 125 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(NULL, NULL, TRUE) != '' ? TRUE : FALSE; |
|
| 126 | 126 | } |
| 127 | - if ( is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
| 127 | + if (is_archive() && ! (espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list())) { |
|
| 128 | 128 | $has_content_or_excerpt = FALSE; |
| 129 | 129 | } |
| 130 | 130 | return $has_content_or_excerpt; |
@@ -140,34 +140,34 @@ discard block |
||
| 140 | 140 | * @param null $more |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public static function event_content_or_excerpt( $num_words = NULL, $more = NULL ) { |
|
| 143 | + public static function event_content_or_excerpt($num_words = NULL, $more = NULL) { |
|
| 144 | 144 | global $post; |
| 145 | 145 | |
| 146 | 146 | ob_start(); |
| 147 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
| 147 | + if ((is_single()) || (is_archive() && espresso_display_full_description_in_event_list())) { |
|
| 148 | 148 | // admin has chosen "full description" for the "Event Espresso - Events > Templates > Display Description" option |
| 149 | 149 | the_content(); |
| 150 | - } else if (( is_archive() && has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() ) ) { |
|
| 150 | + } else if ((is_archive() && has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
| 151 | 151 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
| 152 | 152 | // AND an excerpt actually exists |
| 153 | 153 | the_excerpt(); |
| 154 | - } else if (( is_archive() && ! has_excerpt( $post->ID ) && espresso_display_excerpt_in_event_list() )) { |
|
| 154 | + } else if ((is_archive() && ! has_excerpt($post->ID) && espresso_display_excerpt_in_event_list())) { |
|
| 155 | 155 | // admin has chosen "excerpt (short desc)" for the "Event Espresso - Events > Templates > Display Description" option |
| 156 | 156 | // but NO excerpt actually exists, so we need to create one |
| 157 | - if ( ! empty( $num_words )) { |
|
| 158 | - if ( empty( $more )) { |
|
| 159 | - $more_link_text = __( '(more…)' ); |
|
| 160 | - $more = ' <a href="' . get_permalink() . '"'; |
|
| 157 | + if ( ! empty($num_words)) { |
|
| 158 | + if (empty($more)) { |
|
| 159 | + $more_link_text = __('(more…)'); |
|
| 160 | + $more = ' <a href="'.get_permalink().'"'; |
|
| 161 | 161 | $more .= ' class="more-link"'; |
| 162 | 162 | $more .= \EED_Events_Archive::link_target(); |
| 163 | - $more .= '>' . $more_link_text . '</a>'; |
|
| 164 | - $more = apply_filters( 'the_content_more_link', $more, $more_link_text ); |
|
| 163 | + $more .= '>'.$more_link_text.'</a>'; |
|
| 164 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
| 165 | 165 | } |
| 166 | - $content = str_replace( 'NOMORELINK', '', get_the_content( 'NOMORELINK' )); |
|
| 166 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
| 167 | 167 | |
| 168 | - $content = wp_trim_words( $content, $num_words, ' ' ) . $more; |
|
| 168 | + $content = wp_trim_words($content, $num_words, ' ').$more; |
|
| 169 | 169 | } else { |
| 170 | - $content = get_the_content(); |
|
| 170 | + $content = get_the_content(); |
|
| 171 | 171 | } |
| 172 | 172 | global $allowedtags; |
| 173 | 173 | // make sure links are allowed |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | // but get previous value so we can reset it |
| 182 | 182 | $prev_value = $allowedtags['a']['target']; |
| 183 | 183 | $allowedtags['a']['target'] = true; |
| 184 | - $content = wp_kses( $content, $allowedtags ); |
|
| 185 | - $content = strip_shortcodes( $content ); |
|
| 186 | - echo apply_filters( 'the_content', $content ); |
|
| 184 | + $content = wp_kses($content, $allowedtags); |
|
| 185 | + $content = strip_shortcodes($content); |
|
| 186 | + echo apply_filters('the_content', $content); |
|
| 187 | 187 | $allowedtags['a']['target'] = $prev_value; |
| 188 | 188 | } else { |
| 189 | 189 | // admin has chosen "none" for the "Event Espresso - Events > Templates > Display Description" option |
| 190 | - echo apply_filters( 'the_content', '' ); |
|
| 190 | + echo apply_filters('the_content', ''); |
|
| 191 | 191 | } |
| 192 | 192 | return ob_get_clean(); |
| 193 | 193 | } |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | * @param int $EVT_ID |
| 202 | 202 | * @return EE_Ticket[] |
| 203 | 203 | */ |
| 204 | - public static function event_tickets_available( $EVT_ID = 0 ) { |
|
| 205 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 204 | + public static function event_tickets_available($EVT_ID = 0) { |
|
| 205 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 206 | 206 | $tickets_available_for_purchase = array(); |
| 207 | - if( $event instanceof EE_Event ) { |
|
| 208 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE ); |
|
| 209 | - foreach( $datetimes as $datetime ) { |
|
| 210 | - $tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() ); |
|
| 207 | + if ($event instanceof EE_Event) { |
|
| 208 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, FALSE); |
|
| 209 | + foreach ($datetimes as $datetime) { |
|
| 210 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | return $tickets_available_for_purchase; |
@@ -223,17 +223,17 @@ discard block |
||
| 223 | 223 | * @param bool $hide_uncategorized |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - public static function event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE ) { |
|
| 226 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = TRUE) { |
|
| 227 | 227 | $category_links = array(); |
| 228 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 229 | - if ( $event instanceof EE_Event ) { |
|
| 230 | - $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' ); |
|
| 231 | - if ( $event_categories ) { |
|
| 228 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 229 | + if ($event instanceof EE_Event) { |
|
| 230 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
| 231 | + if ($event_categories) { |
|
| 232 | 232 | // loop thru terms and create links |
| 233 | - foreach ( $event_categories as $term ) { |
|
| 234 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
| 235 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
| 236 | - $category_links[] = '<a href="' . esc_url( $url ) |
|
| 233 | + foreach ($event_categories as $term) { |
|
| 234 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 235 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
| 236 | + $category_links[] = '<a href="'.esc_url($url) |
|
| 237 | 237 | . '" rel="tag"' |
| 238 | 238 | . \EED_Events_Archive::link_target() |
| 239 | 239 | .'>' |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | - return implode( ', ', $category_links ); |
|
| 246 | + return implode(', ', $category_links); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | * @param int $EVT_ID |
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | - public static function the_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 261 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 262 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 263 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
| 260 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 261 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 262 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 263 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | |
@@ -274,10 +274,10 @@ discard block |
||
| 274 | 274 | * @param int $EVT_ID |
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | - public static function the_event_end_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 278 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
| 279 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 280 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
| 277 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 278 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 279 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 280 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | |
@@ -291,10 +291,10 @@ discard block |
||
| 291 | 291 | * @param int $EVT_ID |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - public static function the_earliest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 295 | - $datetime = EEH_Event_View::get_earliest_date_obj( $EVT_ID ); |
|
| 296 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 297 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_start', $format ) : ''; |
|
| 294 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 295 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
| 296 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 297 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -308,10 +308,10 @@ discard block |
||
| 308 | 308 | * @param int $EVT_ID |
| 309 | 309 | * @return string |
| 310 | 310 | */ |
| 311 | - public static function the_latest_event_date( $dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0 ) { |
|
| 312 | - $datetime = EEH_Event_View::get_last_date_obj( $EVT_ID ); |
|
| 313 | - $format = ! empty( $dt_frmt ) && ! empty( $tm_frmt ) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 314 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime( 'DTT_EVT_end', $format ) : ''; |
|
| 311 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) { |
|
| 312 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 313 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt.' '.$tm_frmt : $dt_frmt.$tm_frmt; |
|
| 314 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | |
@@ -323,13 +323,13 @@ discard block |
||
| 323 | 323 | * @param int $EVT_ID |
| 324 | 324 | * @return string |
| 325 | 325 | */ |
| 326 | - public static function event_date_as_calendar_page( $EVT_ID = 0 ) { |
|
| 327 | - $datetime = EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 328 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 326 | + public static function event_date_as_calendar_page($EVT_ID = 0) { |
|
| 327 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 328 | + if ($datetime instanceof EE_Datetime) { |
|
| 329 | 329 | ?> |
| 330 | 330 | <div class="event-date-calendar-page-dv"> |
| 331 | - <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime( 'DTT_EVT_start', 'M' );?></div> |
|
| 332 | - <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date( 'd' );?></div> |
|
| 331 | + <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M'); ?></div> |
|
| 332 | + <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d'); ?></div> |
|
| 333 | 333 | </div> |
| 334 | 334 | <?php |
| 335 | 335 | } |
@@ -344,17 +344,17 @@ discard block |
||
| 344 | 344 | * @param int $EVT_ID |
| 345 | 345 | * @return string |
| 346 | 346 | */ |
| 347 | - public static function get_primary_date_obj( $EVT_ID = 0 ) { |
|
| 348 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 349 | - if ( $event instanceof EE_Event ) { |
|
| 347 | + public static function get_primary_date_obj($EVT_ID = 0) { |
|
| 348 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 349 | + if ($event instanceof EE_Event) { |
|
| 350 | 350 | $datetimes = $event->get_many_related( |
| 351 | 351 | 'Datetime', |
| 352 | 352 | array( |
| 353 | 353 | 'limit' => 1, |
| 354 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
| 354 | + 'order_by' => array('DTT_order' => 'ASC') |
|
| 355 | 355 | ) |
| 356 | 356 | ); |
| 357 | - return reset( $datetimes ); |
|
| 357 | + return reset($datetimes); |
|
| 358 | 358 | } else { |
| 359 | 359 | return FALSE; |
| 360 | 360 | } |
@@ -369,17 +369,17 @@ discard block |
||
| 369 | 369 | * @param int $EVT_ID |
| 370 | 370 | * @return string |
| 371 | 371 | */ |
| 372 | - public static function get_last_date_obj( $EVT_ID = 0 ) { |
|
| 373 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 374 | - if ( $event instanceof EE_Event ) { |
|
| 372 | + public static function get_last_date_obj($EVT_ID = 0) { |
|
| 373 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 374 | + if ($event instanceof EE_Event) { |
|
| 375 | 375 | $datetimes = $event->get_many_related( |
| 376 | 376 | 'Datetime', |
| 377 | 377 | array( |
| 378 | 378 | 'limit' => 1, |
| 379 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
| 379 | + 'order_by' => array('DTT_order' => 'DESC') |
|
| 380 | 380 | ) |
| 381 | 381 | ); |
| 382 | - return end( $datetimes ); |
|
| 382 | + return end($datetimes); |
|
| 383 | 383 | } else { |
| 384 | 384 | return FALSE; |
| 385 | 385 | } |
@@ -394,17 +394,17 @@ discard block |
||
| 394 | 394 | * @param int $EVT_ID |
| 395 | 395 | * @return string |
| 396 | 396 | */ |
| 397 | - public static function get_earliest_date_obj( $EVT_ID = 0 ) { |
|
| 398 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 399 | - if ( $event instanceof EE_Event ) { |
|
| 397 | + public static function get_earliest_date_obj($EVT_ID = 0) { |
|
| 398 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 399 | + if ($event instanceof EE_Event) { |
|
| 400 | 400 | $datetimes = $event->get_many_related( |
| 401 | 401 | 'Datetime', |
| 402 | 402 | array( |
| 403 | 403 | 'limit' => 1, |
| 404 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
| 404 | + 'order_by' => array('DTT_EVT_start' => 'ASC') |
|
| 405 | 405 | ) |
| 406 | 406 | ); |
| 407 | - return reset( $datetimes ); |
|
| 407 | + return reset($datetimes); |
|
| 408 | 408 | } else { |
| 409 | 409 | return FALSE; |
| 410 | 410 | } |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @param int $EVT_ID |
| 420 | 420 | * @return string |
| 421 | 421 | */ |
| 422 | - public static function get_latest_date_obj( $EVT_ID = 0 ) { |
|
| 423 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 424 | - if ( $event instanceof EE_Event ) { |
|
| 422 | + public static function get_latest_date_obj($EVT_ID = 0) { |
|
| 423 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 424 | + if ($event instanceof EE_Event) { |
|
| 425 | 425 | $datetimes = $event->get_many_related( |
| 426 | 426 | 'Datetime', |
| 427 | 427 | array( |
| 428 | 428 | 'limit' => 1, |
| 429 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
| 429 | + 'order_by' => array('DTT_EVT_start' => 'DESC') |
|
| 430 | 430 | ) |
| 431 | 431 | ); |
| 432 | - return end( $datetimes ); |
|
| 432 | + return end($datetimes); |
|
| 433 | 433 | } else { |
| 434 | 434 | return FALSE; |
| 435 | 435 | } |
@@ -447,17 +447,17 @@ discard block |
||
| 447 | 447 | * @param null $limit |
| 448 | 448 | * @return EE_Datetime[] |
| 449 | 449 | */ |
| 450 | - public static function get_all_date_obj( $EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL ) { |
|
| 451 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 452 | - if($include_expired === null){ |
|
| 453 | - if($event instanceof EE_Event && $event->is_expired()){ |
|
| 450 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = NULL) { |
|
| 451 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 452 | + if ($include_expired === null) { |
|
| 453 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
| 454 | 454 | $include_expired = true; |
| 455 | - }else{ |
|
| 455 | + } else { |
|
| 456 | 456 | $include_expired = false; |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( $event instanceof EE_Event ) { |
|
| 460 | + if ($event instanceof EE_Event) { |
|
| 461 | 461 | return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
| 462 | 462 | } else { |
| 463 | 463 | return array(); |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | * @param int $EVT_ID |
| 474 | 474 | * @return string |
| 475 | 475 | */ |
| 476 | - public static function event_link_url( $EVT_ID = 0 ) { |
|
| 477 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 478 | - if ( $event instanceof EE_Event ) { |
|
| 479 | - $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink( $event->ID() ); |
|
| 480 | - return preg_match( "~^(?:f|ht)tps?://~i", $url ) ? $url : 'http://' . $url; |
|
| 476 | + public static function event_link_url($EVT_ID = 0) { |
|
| 477 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 478 | + if ($event instanceof EE_Event) { |
|
| 479 | + $url = $event->external_url() !== NULL && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
| 480 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://'.$url; |
|
| 481 | 481 | } |
| 482 | 482 | return NULL; |
| 483 | 483 | } |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | * @param int $EVT_ID |
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | - public static function event_phone( $EVT_ID = 0 ) { |
|
| 495 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 496 | - if ( $event instanceof EE_Event ) { |
|
| 497 | - return EEH_Schema::telephone( $event->phone() ); |
|
| 494 | + public static function event_phone($EVT_ID = 0) { |
|
| 495 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 496 | + if ($event instanceof EE_Event) { |
|
| 497 | + return EEH_Schema::telephone($event->phone()); |
|
| 498 | 498 | } |
| 499 | 499 | return NULL; |
| 500 | 500 | } |
@@ -511,26 +511,26 @@ discard block |
||
| 511 | 511 | * @param string $after |
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | - public static function edit_event_link( $EVT_ID = 0, $link = '', $before = '', $after = '' ) { |
|
| 515 | - $event = EEH_Event_View::get_event( $EVT_ID ); |
|
| 516 | - if ( $event instanceof EE_Event ) { |
|
| 514 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') { |
|
| 515 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 516 | + if ($event instanceof EE_Event) { |
|
| 517 | 517 | // can the user edit this post ? |
| 518 | - if ( current_user_can( 'edit_post', $event->ID() )) { |
|
| 518 | + if (current_user_can('edit_post', $event->ID())) { |
|
| 519 | 519 | // set link text |
| 520 | - $link_text = ! empty( $link ) ? $link : __('edit this event'); |
|
| 520 | + $link_text = ! empty($link) ? $link : __('edit this event'); |
|
| 521 | 521 | // generate nonce |
| 522 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
| 522 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 523 | 523 | // generate url to event editor for this event |
| 524 | - $url = add_query_arg( array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url() ); |
|
| 524 | + $url = add_query_arg(array('page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce), admin_url()); |
|
| 525 | 525 | // get edit CPT text |
| 526 | - $post_type_obj = get_post_type_object( 'espresso_events' ); |
|
| 526 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
| 527 | 527 | // build final link html |
| 528 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
| 529 | - $link .= ' title="' . esc_attr( $post_type_obj->labels->edit_item ) . '"'; |
|
| 528 | + $link = '<a class="post-edit-link" href="'.$url.'" '; |
|
| 529 | + $link .= ' title="'.esc_attr($post_type_obj->labels->edit_item).'"'; |
|
| 530 | 530 | $link .= \EED_Events_Archive::link_target(); |
| 531 | - $link .='>' . $link_text . '</a>'; |
|
| 531 | + $link .= '>'.$link_text.'</a>'; |
|
| 532 | 532 | // put it all together |
| 533 | - return $before . apply_filters( 'edit_post_link', $link, $event->ID() ) . $after; |
|
| 533 | + return $before.apply_filters('edit_post_link', $link, $event->ID()).$after; |
|
| 534 | 534 | } |
| 535 | 535 | } |
| 536 | 536 | return ''; |
@@ -61,15 +61,15 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param array $props_n_values incoming values |
|
| 66 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 67 | - * used.) |
|
| 68 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 69 | - * date_format and the second value is the time format |
|
| 70 | - * @return EE_Ticket |
|
| 71 | - * @throws \EE_Error |
|
| 72 | - */ |
|
| 64 | + /** |
|
| 65 | + * @param array $props_n_values incoming values |
|
| 66 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 67 | + * used.) |
|
| 68 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 69 | + * date_format and the second value is the time format |
|
| 70 | + * @return EE_Ticket |
|
| 71 | + * @throws \EE_Error |
|
| 72 | + */ |
|
| 73 | 73 | public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
| 74 | 74 | $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
| 75 | 75 | return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
@@ -77,36 +77,36 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param array $props_n_values incoming values from the database |
|
| 82 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 83 | - * the website will be used. |
|
| 84 | - * @return EE_Ticket |
|
| 85 | - * @throws \EE_Error |
|
| 86 | - */ |
|
| 80 | + /** |
|
| 81 | + * @param array $props_n_values incoming values from the database |
|
| 82 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 83 | + * the website will be used. |
|
| 84 | + * @return EE_Ticket |
|
| 85 | + * @throws \EE_Error |
|
| 86 | + */ |
|
| 87 | 87 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
| 88 | 88 | return new self( $props_n_values, TRUE, $timezone ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @return bool |
|
| 95 | - * @throws \EE_Error |
|
| 96 | - */ |
|
| 93 | + /** |
|
| 94 | + * @return bool |
|
| 95 | + * @throws \EE_Error |
|
| 96 | + */ |
|
| 97 | 97 | public function parent() { |
| 98 | 98 | return $this->get( 'TKT_parent' ); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * return if a ticket has quantities available for purchase |
|
| 105 | - * |
|
| 106 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 107 | - * @return boolean |
|
| 108 | - * @throws \EE_Error |
|
| 109 | - */ |
|
| 103 | + /** |
|
| 104 | + * return if a ticket has quantities available for purchase |
|
| 105 | + * |
|
| 106 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 107 | + * @return boolean |
|
| 108 | + * @throws \EE_Error |
|
| 109 | + */ |
|
| 110 | 110 | public function available( $DTT_ID = 0 ) { |
| 111 | 111 | // are we checking availability for a particular datetime ? |
| 112 | 112 | if ( $DTT_ID ) { |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 128 | - * |
|
| 129 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 130 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 131 | - * @return mixed status int if the display string isn't requested |
|
| 132 | - * @throws \EE_Error |
|
| 133 | - */ |
|
| 126 | + /** |
|
| 127 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 128 | + * |
|
| 129 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 130 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 131 | + * @return mixed status int if the display string isn't requested |
|
| 132 | + * @throws \EE_Error |
|
| 133 | + */ |
|
| 134 | 134 | public function ticket_status( $display = FALSE, $remaining = null ) { |
| 135 | 135 | $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
| 136 | 136 | if ( ! $remaining ) { |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
| 158 | - * |
|
| 159 | - * @access public |
|
| 160 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 161 | - * @return boolean true = tickets remaining, false not. |
|
| 162 | - * @throws \EE_Error |
|
| 163 | - */ |
|
| 156 | + /** |
|
| 157 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
| 158 | + * |
|
| 159 | + * @access public |
|
| 160 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 161 | + * @return boolean true = tickets remaining, false not. |
|
| 162 | + * @throws \EE_Error |
|
| 163 | + */ |
|
| 164 | 164 | public function is_remaining( $DTT_ID = 0 ) { |
| 165 | 165 | $num_remaining = $this->remaining( $DTT_ID ); |
| 166 | 166 | if ( $num_remaining === 0 ) { |
@@ -174,76 +174,76 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * return the total number of tickets available for purchase |
|
| 179 | - * |
|
| 180 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 181 | - * set to 0 for all related datetimes |
|
| 182 | - * @return int |
|
| 183 | - * @throws \EE_Error |
|
| 184 | - */ |
|
| 177 | + /** |
|
| 178 | + * return the total number of tickets available for purchase |
|
| 179 | + * |
|
| 180 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 181 | + * set to 0 for all related datetimes |
|
| 182 | + * @return int |
|
| 183 | + * @throws \EE_Error |
|
| 184 | + */ |
|
| 185 | 185 | public function remaining( $DTT_ID = 0 ) { |
| 186 | 186 | return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Gets min |
|
| 193 | - * |
|
| 194 | - * @return int |
|
| 195 | - * @throws \EE_Error |
|
| 196 | - */ |
|
| 191 | + /** |
|
| 192 | + * Gets min |
|
| 193 | + * |
|
| 194 | + * @return int |
|
| 195 | + * @throws \EE_Error |
|
| 196 | + */ |
|
| 197 | 197 | public function min() { |
| 198 | 198 | return $this->get( 'TKT_min' ); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 205 | - * |
|
| 206 | - * @return boolean |
|
| 207 | - * @throws \EE_Error |
|
| 208 | - */ |
|
| 203 | + /** |
|
| 204 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 205 | + * |
|
| 206 | + * @return boolean |
|
| 207 | + * @throws \EE_Error |
|
| 208 | + */ |
|
| 209 | 209 | public function is_expired() { |
| 210 | 210 | return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Return if a ticket is yet to go on sale or not |
|
| 217 | - * |
|
| 218 | - * @return boolean |
|
| 219 | - * @throws \EE_Error |
|
| 220 | - */ |
|
| 215 | + /** |
|
| 216 | + * Return if a ticket is yet to go on sale or not |
|
| 217 | + * |
|
| 218 | + * @return boolean |
|
| 219 | + * @throws \EE_Error |
|
| 220 | + */ |
|
| 221 | 221 | public function is_pending() { |
| 222 | 222 | return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Return if a ticket is on sale or not |
|
| 229 | - * |
|
| 230 | - * @return boolean |
|
| 231 | - * @throws \EE_Error |
|
| 232 | - */ |
|
| 227 | + /** |
|
| 228 | + * Return if a ticket is on sale or not |
|
| 229 | + * |
|
| 230 | + * @return boolean |
|
| 231 | + * @throws \EE_Error |
|
| 232 | + */ |
|
| 233 | 233 | public function is_on_sale() { |
| 234 | 234 | return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 241 | - * |
|
| 242 | - * @param string $dt_frmt |
|
| 243 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 244 | - * @return string |
|
| 245 | - * @throws \EE_Error |
|
| 246 | - */ |
|
| 239 | + /** |
|
| 240 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 241 | + * |
|
| 242 | + * @param string $dt_frmt |
|
| 243 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 244 | + * @return string |
|
| 245 | + * @throws \EE_Error |
|
| 246 | + */ |
|
| 247 | 247 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
| 248 | 248 | $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
| 249 | 249 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 258 | - * |
|
| 259 | - * @return EE_Datetime |
|
| 260 | - * @throws \EE_Error |
|
| 261 | - */ |
|
| 256 | + /** |
|
| 257 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 258 | + * |
|
| 259 | + * @return EE_Datetime |
|
| 260 | + * @throws \EE_Error |
|
| 261 | + */ |
|
| 262 | 262 | public function first_datetime() { |
| 263 | 263 | $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
| 264 | 264 | return reset( $datetimes ); |
@@ -266,14 +266,14 @@ discard block |
||
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 271 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 272 | - * |
|
| 273 | - * @param array $query_params see EEM_Base::get_all() |
|
| 274 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 275 | - * @throws \EE_Error |
|
| 276 | - */ |
|
| 269 | + /** |
|
| 270 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 271 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 272 | + * |
|
| 273 | + * @param array $query_params see EEM_Base::get_all() |
|
| 274 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 275 | + * @throws \EE_Error |
|
| 276 | + */ |
|
| 277 | 277 | public function datetimes( $query_params = array() ) { |
| 278 | 278 | if ( ! isset( $query_params[ 'order_by' ] ) ) { |
| 279 | 279 | $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
@@ -283,12 +283,12 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | |
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 288 | - * |
|
| 289 | - * @return EE_Datetime |
|
| 290 | - * @throws \EE_Error |
|
| 291 | - */ |
|
| 286 | + /** |
|
| 287 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 288 | + * |
|
| 289 | + * @return EE_Datetime |
|
| 290 | + * @throws \EE_Error |
|
| 291 | + */ |
|
| 292 | 292 | public function last_datetime() { |
| 293 | 293 | $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
| 294 | 294 | return end( $datetimes ); |
@@ -296,19 +296,19 @@ discard block |
||
| 296 | 296 | |
| 297 | 297 | |
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * This returns the total tickets sold depending on the given parameters. |
|
| 301 | - * |
|
| 302 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 303 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 304 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 305 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 306 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 307 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 308 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 309 | - * @return mixed (array|int) how many tickets have sold |
|
| 310 | - * @throws \EE_Error |
|
| 311 | - */ |
|
| 299 | + /** |
|
| 300 | + * This returns the total tickets sold depending on the given parameters. |
|
| 301 | + * |
|
| 302 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 303 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 304 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 305 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 306 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 307 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 308 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 309 | + * @return mixed (array|int) how many tickets have sold |
|
| 310 | + * @throws \EE_Error |
|
| 311 | + */ |
|
| 312 | 312 | public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
| 313 | 313 | $total = 0; |
| 314 | 314 | $tickets_sold = $this->_all_tickets_sold(); |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 338 | - * |
|
| 339 | - * @return EE_Ticket[] |
|
| 340 | - * @throws \EE_Error |
|
| 341 | - */ |
|
| 336 | + /** |
|
| 337 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 338 | + * |
|
| 339 | + * @return EE_Ticket[] |
|
| 340 | + * @throws \EE_Error |
|
| 341 | + */ |
|
| 342 | 342 | protected function _all_tickets_sold() { |
| 343 | 343 | $datetimes = $this->get_many_related( 'Datetime' ); |
| 344 | 344 | $tickets_sold = array(); |
@@ -354,29 +354,29 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * This returns the base price object for the ticket. |
|
| 359 | - * |
|
| 360 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 361 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 362 | - * @throws \EE_Error |
|
| 363 | - */ |
|
| 357 | + /** |
|
| 358 | + * This returns the base price object for the ticket. |
|
| 359 | + * |
|
| 360 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 361 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 362 | + * @throws \EE_Error |
|
| 363 | + */ |
|
| 364 | 364 | public function base_price( $return_array = FALSE ) { |
| 365 | 365 | $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
| 366 | 366 | return $return_array |
| 367 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 368 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 367 | + ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 368 | + : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
| 372 | 372 | |
| 373 | - /** |
|
| 374 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 375 | - * |
|
| 376 | - * @access public |
|
| 377 | - * @return EE_Price[] |
|
| 378 | - * @throws \EE_Error |
|
| 379 | - */ |
|
| 373 | + /** |
|
| 374 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 375 | + * |
|
| 376 | + * @access public |
|
| 377 | + * @return EE_Price[] |
|
| 378 | + * @throws \EE_Error |
|
| 379 | + */ |
|
| 380 | 380 | public function price_modifiers() { |
| 381 | 381 | $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
| 382 | 382 | return $this->prices( $query_params ); |
@@ -384,132 +384,132 @@ discard block |
||
| 384 | 384 | |
| 385 | 385 | |
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 389 | - * |
|
| 390 | - * @param array $query_params like EEM_Base::get_all |
|
| 391 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 392 | - * @throws \EE_Error |
|
| 393 | - */ |
|
| 387 | + /** |
|
| 388 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 389 | + * |
|
| 390 | + * @param array $query_params like EEM_Base::get_all |
|
| 391 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 392 | + * @throws \EE_Error |
|
| 393 | + */ |
|
| 394 | 394 | public function prices( $query_params = array() ) { |
| 395 | 395 | return $this->get_many_related( 'Price', $query_params ); |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
| 399 | 399 | |
| 400 | - /** |
|
| 401 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 402 | - * |
|
| 403 | - * @param array $query_params see EEM_Base::get_all() |
|
| 404 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 405 | - * @throws \EE_Error |
|
| 406 | - */ |
|
| 400 | + /** |
|
| 401 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 402 | + * |
|
| 403 | + * @param array $query_params see EEM_Base::get_all() |
|
| 404 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 405 | + * @throws \EE_Error |
|
| 406 | + */ |
|
| 407 | 407 | public function datetime_tickets( $query_params = array() ) { |
| 408 | 408 | return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
| 412 | 412 | |
| 413 | - /** |
|
| 414 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 415 | - * |
|
| 416 | - * @param boolean $show_expired |
|
| 417 | - * @param boolean $show_deleted |
|
| 418 | - * @return EE_Datetime[] |
|
| 419 | - * @throws \EE_Error |
|
| 420 | - */ |
|
| 413 | + /** |
|
| 414 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 415 | + * |
|
| 416 | + * @param boolean $show_expired |
|
| 417 | + * @param boolean $show_deleted |
|
| 418 | + * @return EE_Datetime[] |
|
| 419 | + * @throws \EE_Error |
|
| 420 | + */ |
|
| 421 | 421 | public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
| 422 | 422 | return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | |
| 427 | - /** |
|
| 428 | - * Gets ID |
|
| 429 | - * |
|
| 430 | - * @return string |
|
| 431 | - * @throws \EE_Error |
|
| 432 | - */ |
|
| 427 | + /** |
|
| 428 | + * Gets ID |
|
| 429 | + * |
|
| 430 | + * @return string |
|
| 431 | + * @throws \EE_Error |
|
| 432 | + */ |
|
| 433 | 433 | public function ID() { |
| 434 | 434 | return $this->get( 'TKT_ID' ); |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | |
| 438 | 438 | |
| 439 | - /** |
|
| 440 | - * get the author of the ticket. |
|
| 441 | - * |
|
| 442 | - * @since 4.5.0 |
|
| 443 | - * @return int |
|
| 444 | - * @throws \EE_Error |
|
| 445 | - */ |
|
| 439 | + /** |
|
| 440 | + * get the author of the ticket. |
|
| 441 | + * |
|
| 442 | + * @since 4.5.0 |
|
| 443 | + * @return int |
|
| 444 | + * @throws \EE_Error |
|
| 445 | + */ |
|
| 446 | 446 | public function wp_user() { |
| 447 | 447 | return $this->get('TKT_wp_user'); |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
| 451 | 451 | |
| 452 | - /** |
|
| 453 | - * Gets the template for the ticket |
|
| 454 | - * |
|
| 455 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 456 | - * @throws \EE_Error |
|
| 457 | - */ |
|
| 452 | + /** |
|
| 453 | + * Gets the template for the ticket |
|
| 454 | + * |
|
| 455 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 456 | + * @throws \EE_Error |
|
| 457 | + */ |
|
| 458 | 458 | public function template() { |
| 459 | 459 | return $this->get_first_related( 'Ticket_Template' ); |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 466 | - * |
|
| 467 | - * @return EE_Price[] |
|
| 468 | - * @throws \EE_Error |
|
| 469 | - */ |
|
| 464 | + /** |
|
| 465 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 466 | + * |
|
| 467 | + * @return EE_Price[] |
|
| 468 | + * @throws \EE_Error |
|
| 469 | + */ |
|
| 470 | 470 | public function get_ticket_taxes_for_admin() { |
| 471 | 471 | return EE_Taxes::get_taxes_for_admin(); |
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | |
| 475 | 475 | |
| 476 | - /** |
|
| 477 | - * @return float |
|
| 478 | - * @throws \EE_Error |
|
| 479 | - */ |
|
| 476 | + /** |
|
| 477 | + * @return float |
|
| 478 | + * @throws \EE_Error |
|
| 479 | + */ |
|
| 480 | 480 | public function ticket_price() { |
| 481 | 481 | return $this->get( 'TKT_price' ); |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
| 485 | 485 | |
| 486 | - /** |
|
| 487 | - * @return mixed |
|
| 488 | - * @throws \EE_Error |
|
| 489 | - */ |
|
| 486 | + /** |
|
| 487 | + * @return mixed |
|
| 488 | + * @throws \EE_Error |
|
| 489 | + */ |
|
| 490 | 490 | public function pretty_price() { |
| 491 | 491 | return $this->get_pretty( 'TKT_price' ); |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
| 495 | 495 | |
| 496 | - /** |
|
| 497 | - * @return bool |
|
| 498 | - * @throws \EE_Error |
|
| 499 | - */ |
|
| 496 | + /** |
|
| 497 | + * @return bool |
|
| 498 | + * @throws \EE_Error |
|
| 499 | + */ |
|
| 500 | 500 | public function is_free() { |
| 501 | 501 | return $this->get_ticket_total_with_taxes() === 0; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | |
| 505 | 505 | |
| 506 | - /** |
|
| 507 | - * get_ticket_total_with_taxes |
|
| 508 | - * |
|
| 509 | - * @param bool $no_cache |
|
| 510 | - * @return float |
|
| 511 | - * @throws \EE_Error |
|
| 512 | - */ |
|
| 506 | + /** |
|
| 507 | + * get_ticket_total_with_taxes |
|
| 508 | + * |
|
| 509 | + * @param bool $no_cache |
|
| 510 | + * @return float |
|
| 511 | + * @throws \EE_Error |
|
| 512 | + */ |
|
| 513 | 513 | public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
| 514 | 514 | if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
| 515 | 515 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
@@ -526,201 +526,201 @@ discard block |
||
| 526 | 526 | |
| 527 | 527 | |
| 528 | 528 | |
| 529 | - /** |
|
| 530 | - * @return float |
|
| 531 | - * @throws \EE_Error |
|
| 532 | - */ |
|
| 529 | + /** |
|
| 530 | + * @return float |
|
| 531 | + * @throws \EE_Error |
|
| 532 | + */ |
|
| 533 | 533 | public function get_ticket_subtotal() { |
| 534 | 534 | return EE_Taxes::get_subtotal_for_admin( $this ); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
| 538 | 538 | |
| 539 | - /** |
|
| 540 | - * Returns the total taxes applied to this ticket |
|
| 541 | - * |
|
| 542 | - * @return float |
|
| 543 | - * @throws \EE_Error |
|
| 544 | - */ |
|
| 539 | + /** |
|
| 540 | + * Returns the total taxes applied to this ticket |
|
| 541 | + * |
|
| 542 | + * @return float |
|
| 543 | + * @throws \EE_Error |
|
| 544 | + */ |
|
| 545 | 545 | public function get_ticket_taxes_total_for_admin() { |
| 546 | 546 | return EE_Taxes::get_total_taxes_for_admin( $this ); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
| 550 | 550 | |
| 551 | - /** |
|
| 552 | - * Sets name |
|
| 553 | - * |
|
| 554 | - * @param string $name |
|
| 555 | - * @throws \EE_Error |
|
| 556 | - */ |
|
| 551 | + /** |
|
| 552 | + * Sets name |
|
| 553 | + * |
|
| 554 | + * @param string $name |
|
| 555 | + * @throws \EE_Error |
|
| 556 | + */ |
|
| 557 | 557 | public function set_name( $name ) { |
| 558 | 558 | $this->set( 'TKT_name', $name ); |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | |
| 562 | 562 | |
| 563 | - /** |
|
| 564 | - * Gets description |
|
| 565 | - * |
|
| 566 | - * @return string |
|
| 567 | - * @throws \EE_Error |
|
| 568 | - */ |
|
| 563 | + /** |
|
| 564 | + * Gets description |
|
| 565 | + * |
|
| 566 | + * @return string |
|
| 567 | + * @throws \EE_Error |
|
| 568 | + */ |
|
| 569 | 569 | public function description() { |
| 570 | 570 | return $this->get( 'TKT_description' ); |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
| 574 | 574 | |
| 575 | - /** |
|
| 576 | - * Sets description |
|
| 577 | - * |
|
| 578 | - * @param string $description |
|
| 579 | - * @throws \EE_Error |
|
| 580 | - */ |
|
| 575 | + /** |
|
| 576 | + * Sets description |
|
| 577 | + * |
|
| 578 | + * @param string $description |
|
| 579 | + * @throws \EE_Error |
|
| 580 | + */ |
|
| 581 | 581 | public function set_description( $description ) { |
| 582 | 582 | $this->set( 'TKT_description', $description ); |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
| 586 | 586 | |
| 587 | - /** |
|
| 588 | - * Gets start_date |
|
| 589 | - * |
|
| 590 | - * @param string $dt_frmt |
|
| 591 | - * @param string $tm_frmt |
|
| 592 | - * @return string |
|
| 593 | - * @throws \EE_Error |
|
| 594 | - */ |
|
| 587 | + /** |
|
| 588 | + * Gets start_date |
|
| 589 | + * |
|
| 590 | + * @param string $dt_frmt |
|
| 591 | + * @param string $tm_frmt |
|
| 592 | + * @return string |
|
| 593 | + * @throws \EE_Error |
|
| 594 | + */ |
|
| 595 | 595 | public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 596 | 596 | return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
| 600 | 600 | |
| 601 | - /** |
|
| 602 | - * Sets start_date |
|
| 603 | - * |
|
| 604 | - * @param string $start_date |
|
| 605 | - * @return void |
|
| 606 | - * @throws \EE_Error |
|
| 607 | - */ |
|
| 601 | + /** |
|
| 602 | + * Sets start_date |
|
| 603 | + * |
|
| 604 | + * @param string $start_date |
|
| 605 | + * @return void |
|
| 606 | + * @throws \EE_Error |
|
| 607 | + */ |
|
| 608 | 608 | public function set_start_date( $start_date ) { |
| 609 | 609 | $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | |
| 613 | 613 | |
| 614 | - /** |
|
| 615 | - * Gets end_date |
|
| 616 | - * |
|
| 617 | - * @param string $dt_frmt |
|
| 618 | - * @param string $tm_frmt |
|
| 619 | - * @return string |
|
| 620 | - * @throws \EE_Error |
|
| 621 | - */ |
|
| 614 | + /** |
|
| 615 | + * Gets end_date |
|
| 616 | + * |
|
| 617 | + * @param string $dt_frmt |
|
| 618 | + * @param string $tm_frmt |
|
| 619 | + * @return string |
|
| 620 | + * @throws \EE_Error |
|
| 621 | + */ |
|
| 622 | 622 | public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 623 | 623 | return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
| 627 | 627 | |
| 628 | - /** |
|
| 629 | - * Sets end_date |
|
| 630 | - * |
|
| 631 | - * @param string $end_date |
|
| 632 | - * @return void |
|
| 633 | - * @throws \EE_Error |
|
| 634 | - */ |
|
| 628 | + /** |
|
| 629 | + * Sets end_date |
|
| 630 | + * |
|
| 631 | + * @param string $end_date |
|
| 632 | + * @return void |
|
| 633 | + * @throws \EE_Error |
|
| 634 | + */ |
|
| 635 | 635 | public function set_end_date( $end_date ) { |
| 636 | 636 | $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * Sets sell until time |
|
| 643 | - * |
|
| 644 | - * @since 4.5.0 |
|
| 645 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 646 | - * @throws \EE_Error |
|
| 647 | - */ |
|
| 641 | + /** |
|
| 642 | + * Sets sell until time |
|
| 643 | + * |
|
| 644 | + * @since 4.5.0 |
|
| 645 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 646 | + * @throws \EE_Error |
|
| 647 | + */ |
|
| 648 | 648 | public function set_end_time( $time ) { |
| 649 | 649 | $this->_set_time_for( $time, 'TKT_end_date' ); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
| 653 | 653 | |
| 654 | - /** |
|
| 655 | - * Sets min |
|
| 656 | - * |
|
| 657 | - * @param int $min |
|
| 658 | - * @return void |
|
| 659 | - * @throws \EE_Error |
|
| 660 | - */ |
|
| 654 | + /** |
|
| 655 | + * Sets min |
|
| 656 | + * |
|
| 657 | + * @param int $min |
|
| 658 | + * @return void |
|
| 659 | + * @throws \EE_Error |
|
| 660 | + */ |
|
| 661 | 661 | public function set_min( $min ) { |
| 662 | 662 | $this->set( 'TKT_min', $min ); |
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
| 666 | 666 | |
| 667 | - /** |
|
| 668 | - * Gets max |
|
| 669 | - * |
|
| 670 | - * @return int |
|
| 671 | - * @throws \EE_Error |
|
| 672 | - */ |
|
| 667 | + /** |
|
| 668 | + * Gets max |
|
| 669 | + * |
|
| 670 | + * @return int |
|
| 671 | + * @throws \EE_Error |
|
| 672 | + */ |
|
| 673 | 673 | public function max() { |
| 674 | 674 | return $this->get( 'TKT_max' ); |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | |
| 678 | 678 | |
| 679 | - /** |
|
| 680 | - * Sets max |
|
| 681 | - * |
|
| 682 | - * @param int $max |
|
| 683 | - * @return void |
|
| 684 | - * @throws \EE_Error |
|
| 685 | - */ |
|
| 679 | + /** |
|
| 680 | + * Sets max |
|
| 681 | + * |
|
| 682 | + * @param int $max |
|
| 683 | + * @return void |
|
| 684 | + * @throws \EE_Error |
|
| 685 | + */ |
|
| 686 | 686 | public function set_max( $max ) { |
| 687 | 687 | $this->set( 'TKT_max', $max ); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * Sets price |
|
| 694 | - * |
|
| 695 | - * @param float $price |
|
| 696 | - * @return void |
|
| 697 | - * @throws \EE_Error |
|
| 698 | - */ |
|
| 692 | + /** |
|
| 693 | + * Sets price |
|
| 694 | + * |
|
| 695 | + * @param float $price |
|
| 696 | + * @return void |
|
| 697 | + * @throws \EE_Error |
|
| 698 | + */ |
|
| 699 | 699 | public function set_price( $price ) { |
| 700 | 700 | $this->set( 'TKT_price', $price ); |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | |
| 704 | 704 | |
| 705 | - /** |
|
| 706 | - * Gets sold |
|
| 707 | - * |
|
| 708 | - * @return int |
|
| 709 | - * @throws \EE_Error |
|
| 710 | - */ |
|
| 705 | + /** |
|
| 706 | + * Gets sold |
|
| 707 | + * |
|
| 708 | + * @return int |
|
| 709 | + * @throws \EE_Error |
|
| 710 | + */ |
|
| 711 | 711 | public function sold() { |
| 712 | 712 | return $this->get_raw( 'TKT_sold' ); |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | |
| 716 | 716 | |
| 717 | - /** |
|
| 718 | - * Sets sold |
|
| 719 | - * |
|
| 720 | - * @param int $sold |
|
| 721 | - * @return void |
|
| 722 | - * @throws \EE_Error |
|
| 723 | - */ |
|
| 717 | + /** |
|
| 718 | + * Sets sold |
|
| 719 | + * |
|
| 720 | + * @param int $sold |
|
| 721 | + * @return void |
|
| 722 | + * @throws \EE_Error |
|
| 723 | + */ |
|
| 724 | 724 | public function set_sold( $sold ) { |
| 725 | 725 | // sold can not go below zero |
| 726 | 726 | $sold = max( 0, $sold ); |
@@ -729,13 +729,13 @@ discard block |
||
| 729 | 729 | |
| 730 | 730 | |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * increments sold by amount passed by $qty |
|
| 734 | - * |
|
| 735 | - * @param int $qty |
|
| 736 | - * @return void |
|
| 737 | - * @throws \EE_Error |
|
| 738 | - */ |
|
| 732 | + /** |
|
| 733 | + * increments sold by amount passed by $qty |
|
| 734 | + * |
|
| 735 | + * @param int $qty |
|
| 736 | + * @return void |
|
| 737 | + * @throws \EE_Error |
|
| 738 | + */ |
|
| 739 | 739 | public function increase_sold( $qty = 1 ) { |
| 740 | 740 | $sold = $this->sold() + $qty; |
| 741 | 741 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
@@ -747,13 +747,13 @@ discard block |
||
| 747 | 747 | |
| 748 | 748 | |
| 749 | 749 | |
| 750 | - /** |
|
| 751 | - * Increases sold on related datetimes |
|
| 752 | - * |
|
| 753 | - * @param int $qty |
|
| 754 | - * @return void |
|
| 755 | - * @throws \EE_Error |
|
| 756 | - */ |
|
| 750 | + /** |
|
| 751 | + * Increases sold on related datetimes |
|
| 752 | + * |
|
| 753 | + * @param int $qty |
|
| 754 | + * @return void |
|
| 755 | + * @throws \EE_Error |
|
| 756 | + */ |
|
| 757 | 757 | protected function _increase_sold_for_datetimes( $qty = 1 ) { |
| 758 | 758 | $datetimes = $this->datetimes(); |
| 759 | 759 | if ( is_array( $datetimes ) ) { |
@@ -768,13 +768,13 @@ discard block |
||
| 768 | 768 | |
| 769 | 769 | |
| 770 | 770 | |
| 771 | - /** |
|
| 772 | - * decrements (subtracts) sold by amount passed by $qty |
|
| 773 | - * |
|
| 774 | - * @param int $qty |
|
| 775 | - * @return void |
|
| 776 | - * @throws \EE_Error |
|
| 777 | - */ |
|
| 771 | + /** |
|
| 772 | + * decrements (subtracts) sold by amount passed by $qty |
|
| 773 | + * |
|
| 774 | + * @param int $qty |
|
| 775 | + * @return void |
|
| 776 | + * @throws \EE_Error |
|
| 777 | + */ |
|
| 778 | 778 | public function decrease_sold( $qty = 1 ) { |
| 779 | 779 | $sold = $this->sold() - $qty; |
| 780 | 780 | $this->_decrease_sold_for_datetimes( $qty ); |
@@ -783,13 +783,13 @@ discard block |
||
| 783 | 783 | |
| 784 | 784 | |
| 785 | 785 | |
| 786 | - /** |
|
| 787 | - * Decreases sold on related datetimes |
|
| 788 | - * |
|
| 789 | - * @param int $qty |
|
| 790 | - * @return void |
|
| 791 | - * @throws \EE_Error |
|
| 792 | - */ |
|
| 786 | + /** |
|
| 787 | + * Decreases sold on related datetimes |
|
| 788 | + * |
|
| 789 | + * @param int $qty |
|
| 790 | + * @return void |
|
| 791 | + * @throws \EE_Error |
|
| 792 | + */ |
|
| 793 | 793 | protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
| 794 | 794 | $datetimes = $this->datetimes(); |
| 795 | 795 | if ( is_array( $datetimes ) ) { |
@@ -804,25 +804,25 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | |
| 806 | 806 | |
| 807 | - /** |
|
| 808 | - * Gets qty of reserved tickets |
|
| 809 | - * |
|
| 810 | - * @return int |
|
| 811 | - * @throws \EE_Error |
|
| 812 | - */ |
|
| 807 | + /** |
|
| 808 | + * Gets qty of reserved tickets |
|
| 809 | + * |
|
| 810 | + * @return int |
|
| 811 | + * @throws \EE_Error |
|
| 812 | + */ |
|
| 813 | 813 | public function reserved() { |
| 814 | 814 | return $this->get_raw( 'TKT_reserved' ); |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
| 818 | 818 | |
| 819 | - /** |
|
| 820 | - * Sets reserved |
|
| 821 | - * |
|
| 822 | - * @param int $reserved |
|
| 823 | - * @return void |
|
| 824 | - * @throws \EE_Error |
|
| 825 | - */ |
|
| 819 | + /** |
|
| 820 | + * Sets reserved |
|
| 821 | + * |
|
| 822 | + * @param int $reserved |
|
| 823 | + * @return void |
|
| 824 | + * @throws \EE_Error |
|
| 825 | + */ |
|
| 826 | 826 | public function set_reserved( $reserved ) { |
| 827 | 827 | // reserved can not go below zero |
| 828 | 828 | $reserved = max( 0, (int) $reserved ); |
@@ -831,13 +831,13 @@ discard block |
||
| 831 | 831 | |
| 832 | 832 | |
| 833 | 833 | |
| 834 | - /** |
|
| 835 | - * increments reserved by amount passed by $qty |
|
| 836 | - * |
|
| 837 | - * @param int $qty |
|
| 838 | - * @return void |
|
| 839 | - * @throws \EE_Error |
|
| 840 | - */ |
|
| 834 | + /** |
|
| 835 | + * increments reserved by amount passed by $qty |
|
| 836 | + * |
|
| 837 | + * @param int $qty |
|
| 838 | + * @return void |
|
| 839 | + * @throws \EE_Error |
|
| 840 | + */ |
|
| 841 | 841 | public function increase_reserved( $qty = 1 ) { |
| 842 | 842 | $qty = absint( $qty ); |
| 843 | 843 | $reserved = $this->reserved() + $qty; |
@@ -847,13 +847,13 @@ discard block |
||
| 847 | 847 | |
| 848 | 848 | |
| 849 | 849 | |
| 850 | - /** |
|
| 851 | - * Increases sold on related datetimes |
|
| 852 | - * |
|
| 853 | - * @param int $qty |
|
| 854 | - * @return void |
|
| 855 | - * @throws \EE_Error |
|
| 856 | - */ |
|
| 850 | + /** |
|
| 851 | + * Increases sold on related datetimes |
|
| 852 | + * |
|
| 853 | + * @param int $qty |
|
| 854 | + * @return void |
|
| 855 | + * @throws \EE_Error |
|
| 856 | + */ |
|
| 857 | 857 | protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
| 858 | 858 | $datetimes = $this->datetimes(); |
| 859 | 859 | if ( is_array( $datetimes ) ) { |
@@ -868,14 +868,14 @@ discard block |
||
| 868 | 868 | |
| 869 | 869 | |
| 870 | 870 | |
| 871 | - /** |
|
| 872 | - * decrements (subtracts) reserved by amount passed by $qty |
|
| 873 | - * |
|
| 874 | - * @param int $qty |
|
| 875 | - * @param bool $adjust_datetimes |
|
| 876 | - * @return void |
|
| 877 | - * @throws \EE_Error |
|
| 878 | - */ |
|
| 871 | + /** |
|
| 872 | + * decrements (subtracts) reserved by amount passed by $qty |
|
| 873 | + * |
|
| 874 | + * @param int $qty |
|
| 875 | + * @param bool $adjust_datetimes |
|
| 876 | + * @return void |
|
| 877 | + * @throws \EE_Error |
|
| 878 | + */ |
|
| 879 | 879 | public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) { |
| 880 | 880 | $reserved = $this->reserved() - absint( $qty ); |
| 881 | 881 | if ( $adjust_datetimes ) { |
@@ -886,13 +886,13 @@ discard block |
||
| 886 | 886 | |
| 887 | 887 | |
| 888 | 888 | |
| 889 | - /** |
|
| 890 | - * Increases sold on related datetimes |
|
| 891 | - * |
|
| 892 | - * @param int $qty |
|
| 893 | - * @return void |
|
| 894 | - * @throws \EE_Error |
|
| 895 | - */ |
|
| 889 | + /** |
|
| 890 | + * Increases sold on related datetimes |
|
| 891 | + * |
|
| 892 | + * @param int $qty |
|
| 893 | + * @return void |
|
| 894 | + * @throws \EE_Error |
|
| 895 | + */ |
|
| 896 | 896 | protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
| 897 | 897 | $datetimes = $this->datetimes(); |
| 898 | 898 | if ( is_array( $datetimes ) ) { |
@@ -907,18 +907,18 @@ discard block |
||
| 907 | 907 | |
| 908 | 908 | |
| 909 | 909 | |
| 910 | - /** |
|
| 911 | - * Gets ticket quantity |
|
| 912 | - * |
|
| 913 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 914 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 915 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 916 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 917 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 918 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 919 | - * @return int |
|
| 920 | - * @throws \EE_Error |
|
| 921 | - */ |
|
| 910 | + /** |
|
| 911 | + * Gets ticket quantity |
|
| 912 | + * |
|
| 913 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 914 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 915 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 916 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 917 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 918 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 919 | + * @return int |
|
| 920 | + * @throws \EE_Error |
|
| 921 | + */ |
|
| 922 | 922 | public function qty( $context = '' ) { |
| 923 | 923 | switch ( $context ) { |
| 924 | 924 | case 'reg_limit' : |
@@ -932,19 +932,19 @@ discard block |
||
| 932 | 932 | |
| 933 | 933 | |
| 934 | 934 | |
| 935 | - /** |
|
| 936 | - * Gets ticket quantity |
|
| 937 | - * |
|
| 938 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 939 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 940 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 941 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 942 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 943 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 944 | - * set to 0 for all related datetimes |
|
| 945 | - * @return int |
|
| 946 | - * @throws \EE_Error |
|
| 947 | - */ |
|
| 935 | + /** |
|
| 936 | + * Gets ticket quantity |
|
| 937 | + * |
|
| 938 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 939 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 940 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 941 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 942 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 943 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 944 | + * set to 0 for all related datetimes |
|
| 945 | + * @return int |
|
| 946 | + * @throws \EE_Error |
|
| 947 | + */ |
|
| 948 | 948 | public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
| 949 | 949 | $raw = $this->get_raw( 'TKT_qty' ); |
| 950 | 950 | // return immediately if it's zero |
@@ -1027,212 +1027,212 @@ discard block |
||
| 1027 | 1027 | |
| 1028 | 1028 | |
| 1029 | 1029 | |
| 1030 | - /** |
|
| 1031 | - * Gets uses |
|
| 1032 | - * |
|
| 1033 | - * @return int |
|
| 1034 | - * @throws \EE_Error |
|
| 1035 | - */ |
|
| 1030 | + /** |
|
| 1031 | + * Gets uses |
|
| 1032 | + * |
|
| 1033 | + * @return int |
|
| 1034 | + * @throws \EE_Error |
|
| 1035 | + */ |
|
| 1036 | 1036 | public function uses() { |
| 1037 | 1037 | return $this->get( 'TKT_uses' ); |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | |
| 1041 | 1041 | |
| 1042 | - /** |
|
| 1043 | - * Sets uses |
|
| 1044 | - * |
|
| 1045 | - * @param int $uses |
|
| 1046 | - * @return void |
|
| 1047 | - * @throws \EE_Error |
|
| 1048 | - */ |
|
| 1042 | + /** |
|
| 1043 | + * Sets uses |
|
| 1044 | + * |
|
| 1045 | + * @param int $uses |
|
| 1046 | + * @return void |
|
| 1047 | + * @throws \EE_Error |
|
| 1048 | + */ |
|
| 1049 | 1049 | public function set_uses( $uses ) { |
| 1050 | 1050 | $this->set( 'TKT_uses', $uses ); |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | |
| 1054 | 1054 | |
| 1055 | - /** |
|
| 1056 | - * returns whether ticket is required or not. |
|
| 1057 | - * |
|
| 1058 | - * @return boolean |
|
| 1059 | - * @throws \EE_Error |
|
| 1060 | - */ |
|
| 1055 | + /** |
|
| 1056 | + * returns whether ticket is required or not. |
|
| 1057 | + * |
|
| 1058 | + * @return boolean |
|
| 1059 | + * @throws \EE_Error |
|
| 1060 | + */ |
|
| 1061 | 1061 | public function required() { |
| 1062 | 1062 | return $this->get( 'TKT_required' ); |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | |
| 1066 | 1066 | |
| 1067 | - /** |
|
| 1068 | - * sets the TKT_required property |
|
| 1069 | - * |
|
| 1070 | - * @param boolean $required |
|
| 1071 | - * @return void |
|
| 1072 | - * @throws \EE_Error |
|
| 1073 | - */ |
|
| 1067 | + /** |
|
| 1068 | + * sets the TKT_required property |
|
| 1069 | + * |
|
| 1070 | + * @param boolean $required |
|
| 1071 | + * @return void |
|
| 1072 | + * @throws \EE_Error |
|
| 1073 | + */ |
|
| 1074 | 1074 | public function set_required( $required ) { |
| 1075 | 1075 | $this->set( 'TKT_required', $required ); |
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | |
| 1079 | 1079 | |
| 1080 | - /** |
|
| 1081 | - * Gets taxable |
|
| 1082 | - * |
|
| 1083 | - * @return boolean |
|
| 1084 | - * @throws \EE_Error |
|
| 1085 | - */ |
|
| 1080 | + /** |
|
| 1081 | + * Gets taxable |
|
| 1082 | + * |
|
| 1083 | + * @return boolean |
|
| 1084 | + * @throws \EE_Error |
|
| 1085 | + */ |
|
| 1086 | 1086 | public function taxable() { |
| 1087 | 1087 | return $this->get( 'TKT_taxable' ); |
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | |
| 1091 | 1091 | |
| 1092 | - /** |
|
| 1093 | - * Sets taxable |
|
| 1094 | - * |
|
| 1095 | - * @param boolean $taxable |
|
| 1096 | - * @return void |
|
| 1097 | - * @throws \EE_Error |
|
| 1098 | - */ |
|
| 1092 | + /** |
|
| 1093 | + * Sets taxable |
|
| 1094 | + * |
|
| 1095 | + * @param boolean $taxable |
|
| 1096 | + * @return void |
|
| 1097 | + * @throws \EE_Error |
|
| 1098 | + */ |
|
| 1099 | 1099 | public function set_taxable( $taxable ) { |
| 1100 | 1100 | $this->set( 'TKT_taxable', $taxable ); |
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | |
| 1104 | 1104 | |
| 1105 | - /** |
|
| 1106 | - * Gets is_default |
|
| 1107 | - * |
|
| 1108 | - * @return boolean |
|
| 1109 | - * @throws \EE_Error |
|
| 1110 | - */ |
|
| 1105 | + /** |
|
| 1106 | + * Gets is_default |
|
| 1107 | + * |
|
| 1108 | + * @return boolean |
|
| 1109 | + * @throws \EE_Error |
|
| 1110 | + */ |
|
| 1111 | 1111 | public function is_default() { |
| 1112 | 1112 | return $this->get( 'TKT_is_default' ); |
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | |
| 1116 | 1116 | |
| 1117 | - /** |
|
| 1118 | - * Sets is_default |
|
| 1119 | - * |
|
| 1120 | - * @param boolean $is_default |
|
| 1121 | - * @return void |
|
| 1122 | - * @throws \EE_Error |
|
| 1123 | - */ |
|
| 1117 | + /** |
|
| 1118 | + * Sets is_default |
|
| 1119 | + * |
|
| 1120 | + * @param boolean $is_default |
|
| 1121 | + * @return void |
|
| 1122 | + * @throws \EE_Error |
|
| 1123 | + */ |
|
| 1124 | 1124 | public function set_is_default( $is_default ) { |
| 1125 | 1125 | $this->set( 'TKT_is_default', $is_default ); |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | |
| 1129 | 1129 | |
| 1130 | - /** |
|
| 1131 | - * Gets order |
|
| 1132 | - * |
|
| 1133 | - * @return int |
|
| 1134 | - * @throws \EE_Error |
|
| 1135 | - */ |
|
| 1130 | + /** |
|
| 1131 | + * Gets order |
|
| 1132 | + * |
|
| 1133 | + * @return int |
|
| 1134 | + * @throws \EE_Error |
|
| 1135 | + */ |
|
| 1136 | 1136 | public function order() { |
| 1137 | 1137 | return $this->get( 'TKT_order' ); |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | |
| 1141 | 1141 | |
| 1142 | - /** |
|
| 1143 | - * Sets order |
|
| 1144 | - * |
|
| 1145 | - * @param int $order |
|
| 1146 | - * @return void |
|
| 1147 | - * @throws \EE_Error |
|
| 1148 | - */ |
|
| 1142 | + /** |
|
| 1143 | + * Sets order |
|
| 1144 | + * |
|
| 1145 | + * @param int $order |
|
| 1146 | + * @return void |
|
| 1147 | + * @throws \EE_Error |
|
| 1148 | + */ |
|
| 1149 | 1149 | public function set_order( $order ) { |
| 1150 | 1150 | $this->set( 'TKT_order', $order ); |
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | |
| 1154 | 1154 | |
| 1155 | - /** |
|
| 1156 | - * Gets row |
|
| 1157 | - * |
|
| 1158 | - * @return int |
|
| 1159 | - * @throws \EE_Error |
|
| 1160 | - */ |
|
| 1155 | + /** |
|
| 1156 | + * Gets row |
|
| 1157 | + * |
|
| 1158 | + * @return int |
|
| 1159 | + * @throws \EE_Error |
|
| 1160 | + */ |
|
| 1161 | 1161 | public function row() { |
| 1162 | 1162 | return $this->get( 'TKT_row' ); |
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | |
| 1166 | 1166 | |
| 1167 | - /** |
|
| 1168 | - * Sets row |
|
| 1169 | - * |
|
| 1170 | - * @param int $row |
|
| 1171 | - * @return void |
|
| 1172 | - * @throws \EE_Error |
|
| 1173 | - */ |
|
| 1167 | + /** |
|
| 1168 | + * Sets row |
|
| 1169 | + * |
|
| 1170 | + * @param int $row |
|
| 1171 | + * @return void |
|
| 1172 | + * @throws \EE_Error |
|
| 1173 | + */ |
|
| 1174 | 1174 | public function set_row( $row ) { |
| 1175 | 1175 | $this->set( 'TKT_row', $row ); |
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | |
| 1179 | 1179 | |
| 1180 | - /** |
|
| 1181 | - * Gets deleted |
|
| 1182 | - * |
|
| 1183 | - * @return boolean |
|
| 1184 | - * @throws \EE_Error |
|
| 1185 | - */ |
|
| 1180 | + /** |
|
| 1181 | + * Gets deleted |
|
| 1182 | + * |
|
| 1183 | + * @return boolean |
|
| 1184 | + * @throws \EE_Error |
|
| 1185 | + */ |
|
| 1186 | 1186 | public function deleted() { |
| 1187 | 1187 | return $this->get( 'TKT_deleted' ); |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | |
| 1191 | 1191 | |
| 1192 | - /** |
|
| 1193 | - * Sets deleted |
|
| 1194 | - * |
|
| 1195 | - * @param boolean $deleted |
|
| 1196 | - * @return void |
|
| 1197 | - * @throws \EE_Error |
|
| 1198 | - */ |
|
| 1192 | + /** |
|
| 1193 | + * Sets deleted |
|
| 1194 | + * |
|
| 1195 | + * @param boolean $deleted |
|
| 1196 | + * @return void |
|
| 1197 | + * @throws \EE_Error |
|
| 1198 | + */ |
|
| 1199 | 1199 | public function set_deleted( $deleted ) { |
| 1200 | 1200 | $this->set( 'TKT_deleted', $deleted ); |
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | |
| 1204 | 1204 | |
| 1205 | - /** |
|
| 1206 | - * Gets parent |
|
| 1207 | - * |
|
| 1208 | - * @return int |
|
| 1209 | - * @throws \EE_Error |
|
| 1210 | - */ |
|
| 1205 | + /** |
|
| 1206 | + * Gets parent |
|
| 1207 | + * |
|
| 1208 | + * @return int |
|
| 1209 | + * @throws \EE_Error |
|
| 1210 | + */ |
|
| 1211 | 1211 | public function parent_ID() { |
| 1212 | 1212 | return $this->get( 'TKT_parent' ); |
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | |
| 1216 | 1216 | |
| 1217 | - /** |
|
| 1218 | - * Sets parent |
|
| 1219 | - * |
|
| 1220 | - * @param int $parent |
|
| 1221 | - * @return void |
|
| 1222 | - * @throws \EE_Error |
|
| 1223 | - */ |
|
| 1217 | + /** |
|
| 1218 | + * Sets parent |
|
| 1219 | + * |
|
| 1220 | + * @param int $parent |
|
| 1221 | + * @return void |
|
| 1222 | + * @throws \EE_Error |
|
| 1223 | + */ |
|
| 1224 | 1224 | public function set_parent_ID( $parent ) { |
| 1225 | 1225 | $this->set( 'TKT_parent', $parent ); |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | |
| 1229 | 1229 | |
| 1230 | - /** |
|
| 1231 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1232 | - * |
|
| 1233 | - * @return string |
|
| 1234 | - * @throws \EE_Error |
|
| 1235 | - */ |
|
| 1230 | + /** |
|
| 1231 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1232 | + * |
|
| 1233 | + * @return string |
|
| 1234 | + * @throws \EE_Error |
|
| 1235 | + */ |
|
| 1236 | 1236 | public function name_and_info() { |
| 1237 | 1237 | $times = array(); |
| 1238 | 1238 | foreach ( $this->datetimes() as $datetime ) { |
@@ -1243,50 +1243,50 @@ discard block |
||
| 1243 | 1243 | |
| 1244 | 1244 | |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * Gets name |
|
| 1248 | - * |
|
| 1249 | - * @return string |
|
| 1250 | - * @throws \EE_Error |
|
| 1251 | - */ |
|
| 1246 | + /** |
|
| 1247 | + * Gets name |
|
| 1248 | + * |
|
| 1249 | + * @return string |
|
| 1250 | + * @throws \EE_Error |
|
| 1251 | + */ |
|
| 1252 | 1252 | public function name() { |
| 1253 | 1253 | return $this->get( 'TKT_name' ); |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
| 1257 | 1257 | |
| 1258 | - /** |
|
| 1259 | - * Gets price |
|
| 1260 | - * |
|
| 1261 | - * @return float |
|
| 1262 | - * @throws \EE_Error |
|
| 1263 | - */ |
|
| 1258 | + /** |
|
| 1259 | + * Gets price |
|
| 1260 | + * |
|
| 1261 | + * @return float |
|
| 1262 | + * @throws \EE_Error |
|
| 1263 | + */ |
|
| 1264 | 1264 | public function price() { |
| 1265 | 1265 | return $this->get( 'TKT_price' ); |
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | |
| 1269 | 1269 | |
| 1270 | - /** |
|
| 1271 | - * Gets all the registrations for this ticket |
|
| 1272 | - * |
|
| 1273 | - * @param array $query_params like EEM_Base::get_all's |
|
| 1274 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1275 | - * @throws \EE_Error |
|
| 1276 | - */ |
|
| 1270 | + /** |
|
| 1271 | + * Gets all the registrations for this ticket |
|
| 1272 | + * |
|
| 1273 | + * @param array $query_params like EEM_Base::get_all's |
|
| 1274 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1275 | + * @throws \EE_Error |
|
| 1276 | + */ |
|
| 1277 | 1277 | public function registrations( $query_params = array() ) { |
| 1278 | 1278 | return $this->get_many_related( 'Registration', $query_params ); |
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | |
| 1282 | 1282 | |
| 1283 | - /** |
|
| 1284 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1285 | - * into account |
|
| 1286 | - * |
|
| 1287 | - * @return int |
|
| 1288 | - * @throws \EE_Error |
|
| 1289 | - */ |
|
| 1283 | + /** |
|
| 1284 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1285 | + * into account |
|
| 1286 | + * |
|
| 1287 | + * @return int |
|
| 1288 | + * @throws \EE_Error |
|
| 1289 | + */ |
|
| 1290 | 1290 | public function update_tickets_sold() { |
| 1291 | 1291 | $count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) ); |
| 1292 | 1292 | $this->set_sold( $count_regs_for_this_ticket ); |
@@ -1318,21 +1318,21 @@ discard block |
||
| 1318 | 1318 | |
| 1319 | 1319 | |
| 1320 | 1320 | |
| 1321 | - /** |
|
| 1322 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1323 | - * |
|
| 1324 | - * @see EEI_Event_Relation for comments |
|
| 1325 | - * @return EE_Event |
|
| 1326 | - * @throws \EE_Error |
|
| 1327 | - * @throws UnexpectedEntityException |
|
| 1328 | - */ |
|
| 1321 | + /** |
|
| 1322 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1323 | + * |
|
| 1324 | + * @see EEI_Event_Relation for comments |
|
| 1325 | + * @return EE_Event |
|
| 1326 | + * @throws \EE_Error |
|
| 1327 | + * @throws UnexpectedEntityException |
|
| 1328 | + */ |
|
| 1329 | 1329 | public function get_related_event() { |
| 1330 | 1330 | //get one datetime to use for getting the event |
| 1331 | 1331 | $datetime = $this->first_datetime(); |
| 1332 | 1332 | if ( ! $datetime instanceof \EE_Datetime ) { |
| 1333 | 1333 | throw new UnexpectedEntityException( |
| 1334 | 1334 | $datetime, |
| 1335 | - 'EE_Datetime', |
|
| 1335 | + 'EE_Datetime', |
|
| 1336 | 1336 | sprintf( |
| 1337 | 1337 | __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
| 1338 | 1338 | $datetime->name() |
@@ -1343,7 +1343,7 @@ discard block |
||
| 1343 | 1343 | if ( ! $event instanceof \EE_Event ) { |
| 1344 | 1344 | throw new UnexpectedEntityException( |
| 1345 | 1345 | $event, |
| 1346 | - 'EE_Event', |
|
| 1346 | + 'EE_Event', |
|
| 1347 | 1347 | sprintf( |
| 1348 | 1348 | __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
| 1349 | 1349 | $this->name() |
@@ -1355,14 +1355,14 @@ discard block |
||
| 1355 | 1355 | |
| 1356 | 1356 | |
| 1357 | 1357 | |
| 1358 | - /** |
|
| 1359 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1360 | - * |
|
| 1361 | - * @see EEI_Event_Relation for comments |
|
| 1362 | - * @return string |
|
| 1363 | - * @throws UnexpectedEntityException |
|
| 1364 | - * @throws \EE_Error |
|
| 1365 | - */ |
|
| 1358 | + /** |
|
| 1359 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1360 | + * |
|
| 1361 | + * @see EEI_Event_Relation for comments |
|
| 1362 | + * @return string |
|
| 1363 | + * @throws UnexpectedEntityException |
|
| 1364 | + * @throws \EE_Error |
|
| 1365 | + */ |
|
| 1366 | 1366 | public function get_event_name() { |
| 1367 | 1367 | $event = $this->get_related_event(); |
| 1368 | 1368 | return $event instanceof EE_Event ? $event->name() : ''; |
@@ -1370,14 +1370,14 @@ discard block |
||
| 1370 | 1370 | |
| 1371 | 1371 | |
| 1372 | 1372 | |
| 1373 | - /** |
|
| 1374 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1375 | - * |
|
| 1376 | - * @see EEI_Event_Relation for comments |
|
| 1377 | - * @return int |
|
| 1378 | - * @throws UnexpectedEntityException |
|
| 1379 | - * @throws \EE_Error |
|
| 1380 | - */ |
|
| 1373 | + /** |
|
| 1374 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1375 | + * |
|
| 1376 | + * @see EEI_Event_Relation for comments |
|
| 1377 | + * @return int |
|
| 1378 | + * @throws UnexpectedEntityException |
|
| 1379 | + * @throws \EE_Error |
|
| 1380 | + */ |
|
| 1381 | 1381 | public function get_event_ID() { |
| 1382 | 1382 | $event = $this->get_related_event(); |
| 1383 | 1383 | return $event instanceof EE_Event ? $event->ID() : 0; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 2 | 2 | |
| 3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | /** |
| 7 | 7 | * Event Espresso |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | * @return EE_Ticket |
| 71 | 71 | * @throws \EE_Error |
| 72 | 72 | */ |
| 73 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 74 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 75 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 73 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 74 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 75 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * @return EE_Ticket |
| 85 | 85 | * @throws \EE_Error |
| 86 | 86 | */ |
| 87 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 88 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 87 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 88 | + return new self($props_n_values, TRUE, $timezone); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @throws \EE_Error |
| 96 | 96 | */ |
| 97 | 97 | public function parent() { |
| 98 | - return $this->get( 'TKT_parent' ); |
|
| 98 | + return $this->get('TKT_parent'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | * @return boolean |
| 108 | 108 | * @throws \EE_Error |
| 109 | 109 | */ |
| 110 | - public function available( $DTT_ID = 0 ) { |
|
| 110 | + public function available($DTT_ID = 0) { |
|
| 111 | 111 | // are we checking availability for a particular datetime ? |
| 112 | - if ( $DTT_ID ) { |
|
| 112 | + if ($DTT_ID) { |
|
| 113 | 113 | // get that datetime object |
| 114 | - $datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
| 114 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
| 115 | 115 | // if ticket sales for this datetime have exceeded the reg limit... |
| 116 | - if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) { |
|
| 116 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 117 | 117 | return FALSE; |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -131,22 +131,22 @@ discard block |
||
| 131 | 131 | * @return mixed status int if the display string isn't requested |
| 132 | 132 | * @throws \EE_Error |
| 133 | 133 | */ |
| 134 | - public function ticket_status( $display = FALSE, $remaining = null ) { |
|
| 135 | - $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
|
| 136 | - if ( ! $remaining ) { |
|
| 137 | - return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out; |
|
| 134 | + public function ticket_status($display = FALSE, $remaining = null) { |
|
| 135 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 136 | + if ( ! $remaining) { |
|
| 137 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out; |
|
| 138 | 138 | } |
| 139 | - if ( $this->get( 'TKT_deleted' ) ) { |
|
| 140 | - return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived; |
|
| 139 | + if ($this->get('TKT_deleted')) { |
|
| 140 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived; |
|
| 141 | 141 | } |
| 142 | - if ( $this->is_expired() ) { |
|
| 143 | - return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired; |
|
| 142 | + if ($this->is_expired()) { |
|
| 143 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired; |
|
| 144 | 144 | } |
| 145 | - if ( $this->is_pending() ) { |
|
| 146 | - return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending; |
|
| 145 | + if ($this->is_pending()) { |
|
| 146 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending; |
|
| 147 | 147 | } |
| 148 | - if ( $this->is_on_sale() ) { |
|
| 149 | - return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale; |
|
| 148 | + if ($this->is_on_sale()) { |
|
| 149 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale; |
|
| 150 | 150 | } |
| 151 | 151 | return ''; |
| 152 | 152 | } |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | * @return boolean true = tickets remaining, false not. |
| 162 | 162 | * @throws \EE_Error |
| 163 | 163 | */ |
| 164 | - public function is_remaining( $DTT_ID = 0 ) { |
|
| 165 | - $num_remaining = $this->remaining( $DTT_ID ); |
|
| 166 | - if ( $num_remaining === 0 ) { |
|
| 164 | + public function is_remaining($DTT_ID = 0) { |
|
| 165 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 166 | + if ($num_remaining === 0) { |
|
| 167 | 167 | return FALSE; |
| 168 | 168 | } |
| 169 | - if ( $num_remaining > 0 && $num_remaining < $this->min() ) { |
|
| 169 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 170 | 170 | return FALSE; |
| 171 | 171 | } |
| 172 | 172 | return TRUE; |
@@ -182,8 +182,8 @@ discard block |
||
| 182 | 182 | * @return int |
| 183 | 183 | * @throws \EE_Error |
| 184 | 184 | */ |
| 185 | - public function remaining( $DTT_ID = 0 ) { |
|
| 186 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
|
| 185 | + public function remaining($DTT_ID = 0) { |
|
| 186 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | * @throws \EE_Error |
| 196 | 196 | */ |
| 197 | 197 | public function min() { |
| 198 | - return $this->get( 'TKT_min' ); |
|
| 198 | + return $this->get('TKT_min'); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * @throws \EE_Error |
| 208 | 208 | */ |
| 209 | 209 | public function is_expired() { |
| 210 | - return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
|
| 210 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @throws \EE_Error |
| 220 | 220 | */ |
| 221 | 221 | public function is_pending() { |
| 222 | - return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
|
| 222 | + return ($this->get_raw('TKT_start_date') > time()); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @throws \EE_Error |
| 232 | 232 | */ |
| 233 | 233 | public function is_on_sale() { |
| 234 | - return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
|
| 234 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | * @return string |
| 245 | 245 | * @throws \EE_Error |
| 246 | 246 | */ |
| 247 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
| 248 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
|
| 249 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
|
| 247 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
| 248 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : ''; |
|
| 249 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
| 250 | 250 | |
| 251 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 251 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | * @throws \EE_Error |
| 261 | 261 | */ |
| 262 | 262 | public function first_datetime() { |
| 263 | - $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
|
| 264 | - return reset( $datetimes ); |
|
| 263 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
| 264 | + return reset($datetimes); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | * @return EE_Datetime[]|EE_Base_Class[] |
| 275 | 275 | * @throws \EE_Error |
| 276 | 276 | */ |
| 277 | - public function datetimes( $query_params = array() ) { |
|
| 278 | - if ( ! isset( $query_params[ 'order_by' ] ) ) { |
|
| 279 | - $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
|
| 277 | + public function datetimes($query_params = array()) { |
|
| 278 | + if ( ! isset($query_params['order_by'])) { |
|
| 279 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 280 | 280 | } |
| 281 | - return $this->get_many_related( 'Datetime', $query_params ); |
|
| 281 | + return $this->get_many_related('Datetime', $query_params); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @throws \EE_Error |
| 291 | 291 | */ |
| 292 | 292 | public function last_datetime() { |
| 293 | - $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
|
| 294 | - return end( $datetimes ); |
|
| 293 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
| 294 | + return end($datetimes); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | |
@@ -309,22 +309,22 @@ discard block |
||
| 309 | 309 | * @return mixed (array|int) how many tickets have sold |
| 310 | 310 | * @throws \EE_Error |
| 311 | 311 | */ |
| 312 | - public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
|
| 312 | + public function tickets_sold($what = 'ticket', $dtt_id = NULL) { |
|
| 313 | 313 | $total = 0; |
| 314 | 314 | $tickets_sold = $this->_all_tickets_sold(); |
| 315 | - switch ( $what ) { |
|
| 315 | + switch ($what) { |
|
| 316 | 316 | case 'ticket' : |
| 317 | - return $tickets_sold[ 'ticket' ]; |
|
| 317 | + return $tickets_sold['ticket']; |
|
| 318 | 318 | break; |
| 319 | 319 | case 'datetime' : |
| 320 | - if ( empty( $tickets_sold[ 'datetime' ] ) ) { |
|
| 320 | + if (empty($tickets_sold['datetime'])) { |
|
| 321 | 321 | return $total; |
| 322 | 322 | } |
| 323 | - if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) { |
|
| 324 | - EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 323 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 324 | + EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 325 | 325 | return $total; |
| 326 | 326 | } |
| 327 | - return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ]; |
|
| 327 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 328 | 328 | break; |
| 329 | 329 | default: |
| 330 | 330 | return $total; |
@@ -340,15 +340,15 @@ discard block |
||
| 340 | 340 | * @throws \EE_Error |
| 341 | 341 | */ |
| 342 | 342 | protected function _all_tickets_sold() { |
| 343 | - $datetimes = $this->get_many_related( 'Datetime' ); |
|
| 343 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 344 | 344 | $tickets_sold = array(); |
| 345 | - if ( ! empty( $datetimes ) ) { |
|
| 346 | - foreach ( $datetimes as $datetime ) { |
|
| 347 | - $tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' ); |
|
| 345 | + if ( ! empty($datetimes)) { |
|
| 346 | + foreach ($datetimes as $datetime) { |
|
| 347 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | //Tickets sold |
| 351 | - $tickets_sold[ 'ticket' ] = $this->sold(); |
|
| 351 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 352 | 352 | return $tickets_sold; |
| 353 | 353 | } |
| 354 | 354 | |
@@ -361,11 +361,11 @@ discard block |
||
| 361 | 361 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
| 362 | 362 | * @throws \EE_Error |
| 363 | 363 | */ |
| 364 | - public function base_price( $return_array = FALSE ) { |
|
| 365 | - $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
|
| 364 | + public function base_price($return_array = FALSE) { |
|
| 365 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
| 366 | 366 | return $return_array |
| 367 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 368 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 367 | + ? $this->get_many_related('Price', array($_where)) |
|
| 368 | + : $this->get_first_related('Price', array($_where)); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * @throws \EE_Error |
| 379 | 379 | */ |
| 380 | 380 | public function price_modifiers() { |
| 381 | - $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
|
| 382 | - return $this->prices( $query_params ); |
|
| 381 | + $query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax)))); |
|
| 382 | + return $this->prices($query_params); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -391,8 +391,8 @@ discard block |
||
| 391 | 391 | * @return EE_Price[]|EE_Base_Class[] |
| 392 | 392 | * @throws \EE_Error |
| 393 | 393 | */ |
| 394 | - public function prices( $query_params = array() ) { |
|
| 395 | - return $this->get_many_related( 'Price', $query_params ); |
|
| 394 | + public function prices($query_params = array()) { |
|
| 395 | + return $this->get_many_related('Price', $query_params); |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
@@ -404,8 +404,8 @@ discard block |
||
| 404 | 404 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
| 405 | 405 | * @throws \EE_Error |
| 406 | 406 | */ |
| 407 | - public function datetime_tickets( $query_params = array() ) { |
|
| 408 | - return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
|
| 407 | + public function datetime_tickets($query_params = array()) { |
|
| 408 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
| 418 | 418 | * @return EE_Datetime[] |
| 419 | 419 | * @throws \EE_Error |
| 420 | 420 | */ |
| 421 | - public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
|
| 422 | - return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
|
| 421 | + public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) { |
|
| 422 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted); |
|
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | * @throws \EE_Error |
| 432 | 432 | */ |
| 433 | 433 | public function ID() { |
| 434 | - return $this->get( 'TKT_ID' ); |
|
| 434 | + return $this->get('TKT_ID'); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | * @throws \EE_Error |
| 457 | 457 | */ |
| 458 | 458 | public function template() { |
| 459 | - return $this->get_first_related( 'Ticket_Template' ); |
|
| 459 | + return $this->get_first_related('Ticket_Template'); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | * @throws \EE_Error |
| 479 | 479 | */ |
| 480 | 480 | public function ticket_price() { |
| 481 | - return $this->get( 'TKT_price' ); |
|
| 481 | + return $this->get('TKT_price'); |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | * @throws \EE_Error |
| 489 | 489 | */ |
| 490 | 490 | public function pretty_price() { |
| 491 | - return $this->get_pretty( 'TKT_price' ); |
|
| 491 | + return $this->get_pretty('TKT_price'); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -510,8 +510,8 @@ discard block |
||
| 510 | 510 | * @return float |
| 511 | 511 | * @throws \EE_Error |
| 512 | 512 | */ |
| 513 | - public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
|
| 514 | - if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
|
| 513 | + public function get_ticket_total_with_taxes($no_cache = FALSE) { |
|
| 514 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 515 | 515 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
| 516 | 516 | } |
| 517 | 517 | return (float) $this->_ticket_total_with_taxes; |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | |
| 521 | 521 | |
| 522 | 522 | public function ensure_TKT_Price_correct() { |
| 523 | - $this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) ); |
|
| 523 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 524 | 524 | $this->save(); |
| 525 | 525 | } |
| 526 | 526 | |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | * @throws \EE_Error |
| 532 | 532 | */ |
| 533 | 533 | public function get_ticket_subtotal() { |
| 534 | - return EE_Taxes::get_subtotal_for_admin( $this ); |
|
| 534 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | * @throws \EE_Error |
| 544 | 544 | */ |
| 545 | 545 | public function get_ticket_taxes_total_for_admin() { |
| 546 | - return EE_Taxes::get_total_taxes_for_admin( $this ); |
|
| 546 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | * @param string $name |
| 555 | 555 | * @throws \EE_Error |
| 556 | 556 | */ |
| 557 | - public function set_name( $name ) { |
|
| 558 | - $this->set( 'TKT_name', $name ); |
|
| 557 | + public function set_name($name) { |
|
| 558 | + $this->set('TKT_name', $name); |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | * @throws \EE_Error |
| 568 | 568 | */ |
| 569 | 569 | public function description() { |
| 570 | - return $this->get( 'TKT_description' ); |
|
| 570 | + return $this->get('TKT_description'); |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -578,8 +578,8 @@ discard block |
||
| 578 | 578 | * @param string $description |
| 579 | 579 | * @throws \EE_Error |
| 580 | 580 | */ |
| 581 | - public function set_description( $description ) { |
|
| 582 | - $this->set( 'TKT_description', $description ); |
|
| 581 | + public function set_description($description) { |
|
| 582 | + $this->set('TKT_description', $description); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -592,8 +592,8 @@ discard block |
||
| 592 | 592 | * @return string |
| 593 | 593 | * @throws \EE_Error |
| 594 | 594 | */ |
| 595 | - public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 596 | - return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
|
| 595 | + public function start_date($dt_frmt = '', $tm_frmt = '') { |
|
| 596 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | |
@@ -605,8 +605,8 @@ discard block |
||
| 605 | 605 | * @return void |
| 606 | 606 | * @throws \EE_Error |
| 607 | 607 | */ |
| 608 | - public function set_start_date( $start_date ) { |
|
| 609 | - $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
|
| 608 | + public function set_start_date($start_date) { |
|
| 609 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | |
@@ -619,8 +619,8 @@ discard block |
||
| 619 | 619 | * @return string |
| 620 | 620 | * @throws \EE_Error |
| 621 | 621 | */ |
| 622 | - public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 623 | - return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
|
| 622 | + public function end_date($dt_frmt = '', $tm_frmt = '') { |
|
| 623 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | * @return void |
| 633 | 633 | * @throws \EE_Error |
| 634 | 634 | */ |
| 635 | - public function set_end_date( $end_date ) { |
|
| 636 | - $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
|
| 635 | + public function set_end_date($end_date) { |
|
| 636 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
@@ -645,8 +645,8 @@ discard block |
||
| 645 | 645 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
| 646 | 646 | * @throws \EE_Error |
| 647 | 647 | */ |
| 648 | - public function set_end_time( $time ) { |
|
| 649 | - $this->_set_time_for( $time, 'TKT_end_date' ); |
|
| 648 | + public function set_end_time($time) { |
|
| 649 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
@@ -658,8 +658,8 @@ discard block |
||
| 658 | 658 | * @return void |
| 659 | 659 | * @throws \EE_Error |
| 660 | 660 | */ |
| 661 | - public function set_min( $min ) { |
|
| 662 | - $this->set( 'TKT_min', $min ); |
|
| 661 | + public function set_min($min) { |
|
| 662 | + $this->set('TKT_min', $min); |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | * @throws \EE_Error |
| 672 | 672 | */ |
| 673 | 673 | public function max() { |
| 674 | - return $this->get( 'TKT_max' ); |
|
| 674 | + return $this->get('TKT_max'); |
|
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | |
@@ -683,8 +683,8 @@ discard block |
||
| 683 | 683 | * @return void |
| 684 | 684 | * @throws \EE_Error |
| 685 | 685 | */ |
| 686 | - public function set_max( $max ) { |
|
| 687 | - $this->set( 'TKT_max', $max ); |
|
| 686 | + public function set_max($max) { |
|
| 687 | + $this->set('TKT_max', $max); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -696,8 +696,8 @@ discard block |
||
| 696 | 696 | * @return void |
| 697 | 697 | * @throws \EE_Error |
| 698 | 698 | */ |
| 699 | - public function set_price( $price ) { |
|
| 700 | - $this->set( 'TKT_price', $price ); |
|
| 699 | + public function set_price($price) { |
|
| 700 | + $this->set('TKT_price', $price); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | * @throws \EE_Error |
| 710 | 710 | */ |
| 711 | 711 | public function sold() { |
| 712 | - return $this->get_raw( 'TKT_sold' ); |
|
| 712 | + return $this->get_raw('TKT_sold'); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | |
@@ -721,10 +721,10 @@ discard block |
||
| 721 | 721 | * @return void |
| 722 | 722 | * @throws \EE_Error |
| 723 | 723 | */ |
| 724 | - public function set_sold( $sold ) { |
|
| 724 | + public function set_sold($sold) { |
|
| 725 | 725 | // sold can not go below zero |
| 726 | - $sold = max( 0, $sold ); |
|
| 727 | - $this->set( 'TKT_sold', $sold ); |
|
| 726 | + $sold = max(0, $sold); |
|
| 727 | + $this->set('TKT_sold', $sold); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | |
@@ -736,13 +736,13 @@ discard block |
||
| 736 | 736 | * @return void |
| 737 | 737 | * @throws \EE_Error |
| 738 | 738 | */ |
| 739 | - public function increase_sold( $qty = 1 ) { |
|
| 739 | + public function increase_sold($qty = 1) { |
|
| 740 | 740 | $sold = $this->sold() + $qty; |
| 741 | 741 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
| 742 | 742 | // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
| 743 | - $this->decrease_reserved( $qty, false ); |
|
| 744 | - $this->_increase_sold_for_datetimes( $qty ); |
|
| 745 | - $this->set_sold( $sold ); |
|
| 743 | + $this->decrease_reserved($qty, false); |
|
| 744 | + $this->_increase_sold_for_datetimes($qty); |
|
| 745 | + $this->set_sold($sold); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | |
@@ -754,12 +754,12 @@ discard block |
||
| 754 | 754 | * @return void |
| 755 | 755 | * @throws \EE_Error |
| 756 | 756 | */ |
| 757 | - protected function _increase_sold_for_datetimes( $qty = 1 ) { |
|
| 757 | + protected function _increase_sold_for_datetimes($qty = 1) { |
|
| 758 | 758 | $datetimes = $this->datetimes(); |
| 759 | - if ( is_array( $datetimes ) ) { |
|
| 760 | - foreach ( $datetimes as $datetime ) { |
|
| 761 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 762 | - $datetime->increase_sold( $qty ); |
|
| 759 | + if (is_array($datetimes)) { |
|
| 760 | + foreach ($datetimes as $datetime) { |
|
| 761 | + if ($datetime instanceof EE_Datetime) { |
|
| 762 | + $datetime->increase_sold($qty); |
|
| 763 | 763 | $datetime->save(); |
| 764 | 764 | } |
| 765 | 765 | } |
@@ -775,10 +775,10 @@ discard block |
||
| 775 | 775 | * @return void |
| 776 | 776 | * @throws \EE_Error |
| 777 | 777 | */ |
| 778 | - public function decrease_sold( $qty = 1 ) { |
|
| 778 | + public function decrease_sold($qty = 1) { |
|
| 779 | 779 | $sold = $this->sold() - $qty; |
| 780 | - $this->_decrease_sold_for_datetimes( $qty ); |
|
| 781 | - $this->set_sold( $sold ); |
|
| 780 | + $this->_decrease_sold_for_datetimes($qty); |
|
| 781 | + $this->set_sold($sold); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | |
@@ -790,12 +790,12 @@ discard block |
||
| 790 | 790 | * @return void |
| 791 | 791 | * @throws \EE_Error |
| 792 | 792 | */ |
| 793 | - protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
|
| 793 | + protected function _decrease_sold_for_datetimes($qty = 1) { |
|
| 794 | 794 | $datetimes = $this->datetimes(); |
| 795 | - if ( is_array( $datetimes ) ) { |
|
| 796 | - foreach ( $datetimes as $datetime ) { |
|
| 797 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 798 | - $datetime->decrease_sold( $qty ); |
|
| 795 | + if (is_array($datetimes)) { |
|
| 796 | + foreach ($datetimes as $datetime) { |
|
| 797 | + if ($datetime instanceof EE_Datetime) { |
|
| 798 | + $datetime->decrease_sold($qty); |
|
| 799 | 799 | $datetime->save(); |
| 800 | 800 | } |
| 801 | 801 | } |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | * @throws \EE_Error |
| 812 | 812 | */ |
| 813 | 813 | public function reserved() { |
| 814 | - return $this->get_raw( 'TKT_reserved' ); |
|
| 814 | + return $this->get_raw('TKT_reserved'); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
@@ -823,10 +823,10 @@ discard block |
||
| 823 | 823 | * @return void |
| 824 | 824 | * @throws \EE_Error |
| 825 | 825 | */ |
| 826 | - public function set_reserved( $reserved ) { |
|
| 826 | + public function set_reserved($reserved) { |
|
| 827 | 827 | // reserved can not go below zero |
| 828 | - $reserved = max( 0, (int) $reserved ); |
|
| 829 | - $this->set( 'TKT_reserved', $reserved ); |
|
| 828 | + $reserved = max(0, (int) $reserved); |
|
| 829 | + $this->set('TKT_reserved', $reserved); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | |
@@ -838,11 +838,11 @@ discard block |
||
| 838 | 838 | * @return void |
| 839 | 839 | * @throws \EE_Error |
| 840 | 840 | */ |
| 841 | - public function increase_reserved( $qty = 1 ) { |
|
| 842 | - $qty = absint( $qty ); |
|
| 841 | + public function increase_reserved($qty = 1) { |
|
| 842 | + $qty = absint($qty); |
|
| 843 | 843 | $reserved = $this->reserved() + $qty; |
| 844 | - $this->_increase_reserved_for_datetimes( $qty ); |
|
| 845 | - $this->set_reserved( $reserved ); |
|
| 844 | + $this->_increase_reserved_for_datetimes($qty); |
|
| 845 | + $this->set_reserved($reserved); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | |
@@ -854,12 +854,12 @@ discard block |
||
| 854 | 854 | * @return void |
| 855 | 855 | * @throws \EE_Error |
| 856 | 856 | */ |
| 857 | - protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
|
| 857 | + protected function _increase_reserved_for_datetimes($qty = 1) { |
|
| 858 | 858 | $datetimes = $this->datetimes(); |
| 859 | - if ( is_array( $datetimes ) ) { |
|
| 860 | - foreach ( $datetimes as $datetime ) { |
|
| 861 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 862 | - $datetime->increase_reserved( $qty ); |
|
| 859 | + if (is_array($datetimes)) { |
|
| 860 | + foreach ($datetimes as $datetime) { |
|
| 861 | + if ($datetime instanceof EE_Datetime) { |
|
| 862 | + $datetime->increase_reserved($qty); |
|
| 863 | 863 | $datetime->save(); |
| 864 | 864 | } |
| 865 | 865 | } |
@@ -876,12 +876,12 @@ discard block |
||
| 876 | 876 | * @return void |
| 877 | 877 | * @throws \EE_Error |
| 878 | 878 | */ |
| 879 | - public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) { |
|
| 880 | - $reserved = $this->reserved() - absint( $qty ); |
|
| 881 | - if ( $adjust_datetimes ) { |
|
| 882 | - $this->_decrease_reserved_for_datetimes( $qty ); |
|
| 879 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true) { |
|
| 880 | + $reserved = $this->reserved() - absint($qty); |
|
| 881 | + if ($adjust_datetimes) { |
|
| 882 | + $this->_decrease_reserved_for_datetimes($qty); |
|
| 883 | 883 | } |
| 884 | - $this->set_reserved( $reserved ); |
|
| 884 | + $this->set_reserved($reserved); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | |
@@ -893,12 +893,12 @@ discard block |
||
| 893 | 893 | * @return void |
| 894 | 894 | * @throws \EE_Error |
| 895 | 895 | */ |
| 896 | - protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
|
| 896 | + protected function _decrease_reserved_for_datetimes($qty = 1) { |
|
| 897 | 897 | $datetimes = $this->datetimes(); |
| 898 | - if ( is_array( $datetimes ) ) { |
|
| 899 | - foreach ( $datetimes as $datetime ) { |
|
| 900 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 901 | - $datetime->decrease_reserved( $qty ); |
|
| 898 | + if (is_array($datetimes)) { |
|
| 899 | + foreach ($datetimes as $datetime) { |
|
| 900 | + if ($datetime instanceof EE_Datetime) { |
|
| 901 | + $datetime->decrease_reserved($qty); |
|
| 902 | 902 | $datetime->save(); |
| 903 | 903 | } |
| 904 | 904 | } |
@@ -919,14 +919,14 @@ discard block |
||
| 919 | 919 | * @return int |
| 920 | 920 | * @throws \EE_Error |
| 921 | 921 | */ |
| 922 | - public function qty( $context = '' ) { |
|
| 923 | - switch ( $context ) { |
|
| 922 | + public function qty($context = '') { |
|
| 923 | + switch ($context) { |
|
| 924 | 924 | case 'reg_limit' : |
| 925 | 925 | return $this->real_quantity_on_ticket(); |
| 926 | 926 | case 'saleable' : |
| 927 | - return $this->real_quantity_on_ticket( 'saleable' ); |
|
| 927 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 928 | 928 | default: |
| 929 | - return $this->get_raw( 'TKT_qty' ); |
|
| 929 | + return $this->get_raw('TKT_qty'); |
|
| 930 | 930 | } |
| 931 | 931 | } |
| 932 | 932 | |
@@ -945,15 +945,15 @@ discard block |
||
| 945 | 945 | * @return int |
| 946 | 946 | * @throws \EE_Error |
| 947 | 947 | */ |
| 948 | - public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
|
| 949 | - $raw = $this->get_raw( 'TKT_qty' ); |
|
| 948 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) { |
|
| 949 | + $raw = $this->get_raw('TKT_qty'); |
|
| 950 | 950 | // return immediately if it's zero |
| 951 | - if ( $raw === 0 ) { |
|
| 951 | + if ($raw === 0) { |
|
| 952 | 952 | return $raw; |
| 953 | 953 | } |
| 954 | 954 | //echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
| 955 | 955 | // ensure qty doesn't exceed raw value for THIS ticket |
| 956 | - $qty = min( EE_INF, $raw ); |
|
| 956 | + $qty = min(EE_INF, $raw); |
|
| 957 | 957 | //echo "\n . qty: " . $qty . '<br />'; |
| 958 | 958 | // calculate this ticket's total sales and reservations |
| 959 | 959 | $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
@@ -962,23 +962,23 @@ discard block |
||
| 962 | 962 | //echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
| 963 | 963 | // first we need to calculate the maximum number of tickets available for the datetime |
| 964 | 964 | // do we want data for one datetime or all of them ? |
| 965 | - $query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array(); |
|
| 966 | - $datetimes = $this->datetimes( $query_params ); |
|
| 967 | - if ( is_array( $datetimes ) && ! empty( $datetimes ) ) { |
|
| 968 | - foreach ( $datetimes as $datetime ) { |
|
| 969 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 965 | + $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
| 966 | + $datetimes = $this->datetimes($query_params); |
|
| 967 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 968 | + foreach ($datetimes as $datetime) { |
|
| 969 | + if ($datetime instanceof EE_Datetime) { |
|
| 970 | 970 | $datetime->refresh_from_db(); |
| 971 | 971 | //echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
| 972 | 972 | //echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
| 973 | 973 | // initialize with no restrictions for each datetime |
| 974 | 974 | // but adjust datetime qty based on datetime reg limit |
| 975 | - $datetime_qty = min( EE_INF, $datetime->reg_limit() ); |
|
| 975 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 976 | 976 | //echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
| 977 | 977 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 978 | 978 | // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
| 979 | 979 | // and reservations for this datetime, that do NOT include sales and reservations |
| 980 | 980 | // for this ticket (so we add $this->sold() and $this->reserved() back in) |
| 981 | - if ( $context === 'saleable' ) { |
|
| 981 | + if ($context === 'saleable') { |
|
| 982 | 982 | $datetime_qty = max( |
| 983 | 983 | $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
| 984 | 984 | 0 |
@@ -990,16 +990,16 @@ discard block |
||
| 990 | 990 | $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
| 991 | 991 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 992 | 992 | } |
| 993 | - $qty = min( $datetime_qty, $qty ); |
|
| 993 | + $qty = min($datetime_qty, $qty); |
|
| 994 | 994 | //echo "\n . . qty: " . $qty . '<br />'; |
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | 997 | } |
| 998 | 998 | // NOW that we know the maximum number of tickets available for the datetime |
| 999 | 999 | // we can finally factor in the details for this specific ticket |
| 1000 | - if ( $qty > 0 && $context === 'saleable' ) { |
|
| 1000 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1001 | 1001 | // and subtract the sales for THIS ticket |
| 1002 | - $qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 ); |
|
| 1002 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1003 | 1003 | //echo "\n . qty: " . $qty . '<br />'; |
| 1004 | 1004 | } |
| 1005 | 1005 | //echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
@@ -1015,14 +1015,14 @@ discard block |
||
| 1015 | 1015 | * @return void |
| 1016 | 1016 | * @throws \EE_Error |
| 1017 | 1017 | */ |
| 1018 | - public function set_qty( $qty ) { |
|
| 1018 | + public function set_qty($qty) { |
|
| 1019 | 1019 | $datetimes = $this->datetimes(); |
| 1020 | - foreach ( $datetimes as $datetime ) { |
|
| 1021 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1022 | - $qty = min( $qty, $datetime->reg_limit() ); |
|
| 1020 | + foreach ($datetimes as $datetime) { |
|
| 1021 | + if ($datetime instanceof EE_Datetime) { |
|
| 1022 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1023 | 1023 | } |
| 1024 | 1024 | } |
| 1025 | - $this->set( 'TKT_qty', $qty ); |
|
| 1025 | + $this->set('TKT_qty', $qty); |
|
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | |
@@ -1034,7 +1034,7 @@ discard block |
||
| 1034 | 1034 | * @throws \EE_Error |
| 1035 | 1035 | */ |
| 1036 | 1036 | public function uses() { |
| 1037 | - return $this->get( 'TKT_uses' ); |
|
| 1037 | + return $this->get('TKT_uses'); |
|
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | |
@@ -1046,8 +1046,8 @@ discard block |
||
| 1046 | 1046 | * @return void |
| 1047 | 1047 | * @throws \EE_Error |
| 1048 | 1048 | */ |
| 1049 | - public function set_uses( $uses ) { |
|
| 1050 | - $this->set( 'TKT_uses', $uses ); |
|
| 1049 | + public function set_uses($uses) { |
|
| 1050 | + $this->set('TKT_uses', $uses); |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | * @throws \EE_Error |
| 1060 | 1060 | */ |
| 1061 | 1061 | public function required() { |
| 1062 | - return $this->get( 'TKT_required' ); |
|
| 1062 | + return $this->get('TKT_required'); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | * @return void |
| 1072 | 1072 | * @throws \EE_Error |
| 1073 | 1073 | */ |
| 1074 | - public function set_required( $required ) { |
|
| 1075 | - $this->set( 'TKT_required', $required ); |
|
| 1074 | + public function set_required($required) { |
|
| 1075 | + $this->set('TKT_required', $required); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | * @throws \EE_Error |
| 1085 | 1085 | */ |
| 1086 | 1086 | public function taxable() { |
| 1087 | - return $this->get( 'TKT_taxable' ); |
|
| 1087 | + return $this->get('TKT_taxable'); |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | |
@@ -1096,8 +1096,8 @@ discard block |
||
| 1096 | 1096 | * @return void |
| 1097 | 1097 | * @throws \EE_Error |
| 1098 | 1098 | */ |
| 1099 | - public function set_taxable( $taxable ) { |
|
| 1100 | - $this->set( 'TKT_taxable', $taxable ); |
|
| 1099 | + public function set_taxable($taxable) { |
|
| 1100 | + $this->set('TKT_taxable', $taxable); |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | * @throws \EE_Error |
| 1110 | 1110 | */ |
| 1111 | 1111 | public function is_default() { |
| 1112 | - return $this->get( 'TKT_is_default' ); |
|
| 1112 | + return $this->get('TKT_is_default'); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | |
@@ -1121,8 +1121,8 @@ discard block |
||
| 1121 | 1121 | * @return void |
| 1122 | 1122 | * @throws \EE_Error |
| 1123 | 1123 | */ |
| 1124 | - public function set_is_default( $is_default ) { |
|
| 1125 | - $this->set( 'TKT_is_default', $is_default ); |
|
| 1124 | + public function set_is_default($is_default) { |
|
| 1125 | + $this->set('TKT_is_default', $is_default); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | |
@@ -1134,7 +1134,7 @@ discard block |
||
| 1134 | 1134 | * @throws \EE_Error |
| 1135 | 1135 | */ |
| 1136 | 1136 | public function order() { |
| 1137 | - return $this->get( 'TKT_order' ); |
|
| 1137 | + return $this->get('TKT_order'); |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | |
@@ -1146,8 +1146,8 @@ discard block |
||
| 1146 | 1146 | * @return void |
| 1147 | 1147 | * @throws \EE_Error |
| 1148 | 1148 | */ |
| 1149 | - public function set_order( $order ) { |
|
| 1150 | - $this->set( 'TKT_order', $order ); |
|
| 1149 | + public function set_order($order) { |
|
| 1150 | + $this->set('TKT_order', $order); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | * @throws \EE_Error |
| 1160 | 1160 | */ |
| 1161 | 1161 | public function row() { |
| 1162 | - return $this->get( 'TKT_row' ); |
|
| 1162 | + return $this->get('TKT_row'); |
|
| 1163 | 1163 | } |
| 1164 | 1164 | |
| 1165 | 1165 | |
@@ -1171,8 +1171,8 @@ discard block |
||
| 1171 | 1171 | * @return void |
| 1172 | 1172 | * @throws \EE_Error |
| 1173 | 1173 | */ |
| 1174 | - public function set_row( $row ) { |
|
| 1175 | - $this->set( 'TKT_row', $row ); |
|
| 1174 | + public function set_row($row) { |
|
| 1175 | + $this->set('TKT_row', $row); |
|
| 1176 | 1176 | } |
| 1177 | 1177 | |
| 1178 | 1178 | |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | * @throws \EE_Error |
| 1185 | 1185 | */ |
| 1186 | 1186 | public function deleted() { |
| 1187 | - return $this->get( 'TKT_deleted' ); |
|
| 1187 | + return $this->get('TKT_deleted'); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | |
@@ -1196,8 +1196,8 @@ discard block |
||
| 1196 | 1196 | * @return void |
| 1197 | 1197 | * @throws \EE_Error |
| 1198 | 1198 | */ |
| 1199 | - public function set_deleted( $deleted ) { |
|
| 1200 | - $this->set( 'TKT_deleted', $deleted ); |
|
| 1199 | + public function set_deleted($deleted) { |
|
| 1200 | + $this->set('TKT_deleted', $deleted); |
|
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | 1203 | |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | * @throws \EE_Error |
| 1210 | 1210 | */ |
| 1211 | 1211 | public function parent_ID() { |
| 1212 | - return $this->get( 'TKT_parent' ); |
|
| 1212 | + return $this->get('TKT_parent'); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | |
@@ -1221,8 +1221,8 @@ discard block |
||
| 1221 | 1221 | * @return void |
| 1222 | 1222 | * @throws \EE_Error |
| 1223 | 1223 | */ |
| 1224 | - public function set_parent_ID( $parent ) { |
|
| 1225 | - $this->set( 'TKT_parent', $parent ); |
|
| 1224 | + public function set_parent_ID($parent) { |
|
| 1225 | + $this->set('TKT_parent', $parent); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | |
@@ -1235,10 +1235,10 @@ discard block |
||
| 1235 | 1235 | */ |
| 1236 | 1236 | public function name_and_info() { |
| 1237 | 1237 | $times = array(); |
| 1238 | - foreach ( $this->datetimes() as $datetime ) { |
|
| 1238 | + foreach ($this->datetimes() as $datetime) { |
|
| 1239 | 1239 | $times[] = $datetime->start_date_and_time(); |
| 1240 | 1240 | } |
| 1241 | - return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price(); |
|
| 1241 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | |
@@ -1250,7 +1250,7 @@ discard block |
||
| 1250 | 1250 | * @throws \EE_Error |
| 1251 | 1251 | */ |
| 1252 | 1252 | public function name() { |
| 1253 | - return $this->get( 'TKT_name' ); |
|
| 1253 | + return $this->get('TKT_name'); |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | * @throws \EE_Error |
| 1263 | 1263 | */ |
| 1264 | 1264 | public function price() { |
| 1265 | - return $this->get( 'TKT_price' ); |
|
| 1265 | + return $this->get('TKT_price'); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | |
@@ -1274,8 +1274,8 @@ discard block |
||
| 1274 | 1274 | * @return EE_Registration[]|EE_Base_Class[] |
| 1275 | 1275 | * @throws \EE_Error |
| 1276 | 1276 | */ |
| 1277 | - public function registrations( $query_params = array() ) { |
|
| 1278 | - return $this->get_many_related( 'Registration', $query_params ); |
|
| 1277 | + public function registrations($query_params = array()) { |
|
| 1278 | + return $this->get_many_related('Registration', $query_params); |
|
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | |
@@ -1288,8 +1288,8 @@ discard block |
||
| 1288 | 1288 | * @throws \EE_Error |
| 1289 | 1289 | */ |
| 1290 | 1290 | public function update_tickets_sold() { |
| 1291 | - $count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) ); |
|
| 1292 | - $this->set_sold( $count_regs_for_this_ticket ); |
|
| 1291 | + $count_regs_for_this_ticket = $this->count_registrations(array(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0))); |
|
| 1292 | + $this->set_sold($count_regs_for_this_ticket); |
|
| 1293 | 1293 | $this->save(); |
| 1294 | 1294 | return $count_regs_for_this_ticket; |
| 1295 | 1295 | } |
@@ -1301,7 +1301,7 @@ discard block |
||
| 1301 | 1301 | * @param array $query_params like EEM_Base::get_all's |
| 1302 | 1302 | * @return int |
| 1303 | 1303 | */ |
| 1304 | - public function count_registrations( $query_params = array() ) { |
|
| 1304 | + public function count_registrations($query_params = array()) { |
|
| 1305 | 1305 | return $this->count_related('Registration', $query_params); |
| 1306 | 1306 | } |
| 1307 | 1307 | |
@@ -1329,23 +1329,23 @@ discard block |
||
| 1329 | 1329 | public function get_related_event() { |
| 1330 | 1330 | //get one datetime to use for getting the event |
| 1331 | 1331 | $datetime = $this->first_datetime(); |
| 1332 | - if ( ! $datetime instanceof \EE_Datetime ) { |
|
| 1332 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 1333 | 1333 | throw new UnexpectedEntityException( |
| 1334 | 1334 | $datetime, |
| 1335 | 1335 | 'EE_Datetime', |
| 1336 | 1336 | sprintf( |
| 1337 | - __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1337 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1338 | 1338 | $datetime->name() |
| 1339 | 1339 | ) |
| 1340 | 1340 | ); |
| 1341 | 1341 | } |
| 1342 | 1342 | $event = $datetime->event(); |
| 1343 | - if ( ! $event instanceof \EE_Event ) { |
|
| 1343 | + if ( ! $event instanceof \EE_Event) { |
|
| 1344 | 1344 | throw new UnexpectedEntityException( |
| 1345 | 1345 | $event, |
| 1346 | 1346 | 'EE_Event', |
| 1347 | 1347 | sprintf( |
| 1348 | - __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1348 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1349 | 1349 | $this->name() |
| 1350 | 1350 | ) |
| 1351 | 1351 | ); |
@@ -128,7 +128,8 @@ |
||
| 128 | 128 | * |
| 129 | 129 | * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
| 130 | 130 | * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
| 131 | - * @return mixed status int if the display string isn't requested |
|
| 131 | + * @param boolean $remaining |
|
| 132 | + * @return string status int if the display string isn't requested |
|
| 132 | 133 | * @throws \EE_Error |
| 133 | 134 | */ |
| 134 | 135 | public function ticket_status( $display = FALSE, $remaining = null ) { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | $VNU_ID |
| 70 | 70 | ); |
| 71 | 71 | extract($template_args, EXTR_OVERWRITE); |
| 72 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 72 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param string $location |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - public static function location( $location = null ) { |
|
| 86 | - return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 85 | + public static function location($location = null) { |
|
| 86 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
| 87 | 87 | . $location |
| 88 | 88 | . '</div>' : ''; |
| 89 | 89 | } |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | * @param string $name |
| 99 | 99 | * @return string |
| 100 | 100 | */ |
| 101 | - public static function name( $name = null ) { |
|
| 102 | - return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
| 101 | + public static function name($name = null) { |
|
| 102 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | * @param EEI_Address $obj_with_address |
| 113 | 113 | * @return string |
| 114 | 114 | */ |
| 115 | - public static function streetAddress( EEI_Address $obj_with_address = null ) { |
|
| 115 | + public static function streetAddress(EEI_Address $obj_with_address = null) { |
|
| 116 | 116 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
| 117 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
| 117 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | * @param EEI_Address $obj_with_address |
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | - public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) { |
|
| 130 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) { |
|
| 131 | 131 | // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
| 132 | - if ( preg_match( |
|
| 132 | + if (preg_match( |
|
| 133 | 133 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
| 134 | 134 | $obj_with_address->address2() |
| 135 | - ) ) { |
|
| 135 | + )) { |
|
| 136 | 136 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
| 137 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
| 137 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
| 138 | 138 | } else { |
| 139 | 139 | return $obj_with_address->address2(); |
| 140 | 140 | } |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * @param EEI_Address $obj_with_address |
| 151 | 151 | * @return string |
| 152 | 152 | */ |
| 153 | - public static function addressLocality( EEI_Address $obj_with_address = null ) { |
|
| 153 | + public static function addressLocality(EEI_Address $obj_with_address = null) { |
|
| 154 | 154 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
| 155 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
| 155 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -165,10 +165,10 @@ discard block |
||
| 165 | 165 | * @param EEI_Address $obj_with_address |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | - public static function addressRegion( EEI_Address $obj_with_address = null ) { |
|
| 168 | + public static function addressRegion(EEI_Address $obj_with_address = null) { |
|
| 169 | 169 | $state = $obj_with_address->state_name(); |
| 170 | - if ( ! empty( $state ) ) { |
|
| 171 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
| 170 | + if ( ! empty($state)) { |
|
| 171 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
| 172 | 172 | } else { |
| 173 | 173 | return ''; |
| 174 | 174 | } |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @param EEI_Address $obj_with_address |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public static function addressCountry( EEI_Address $obj_with_address = null ) { |
|
| 187 | + public static function addressCountry(EEI_Address $obj_with_address = null) { |
|
| 188 | 188 | $country = $obj_with_address->country_name(); |
| 189 | - if ( ! empty( $country ) ) { |
|
| 190 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
| 189 | + if ( ! empty($country)) { |
|
| 190 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
| 191 | 191 | } else { |
| 192 | 192 | return ''; |
| 193 | 193 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param EEI_Address $obj_with_address |
| 204 | 204 | * @return string |
| 205 | 205 | */ |
| 206 | - public static function postalCode( EEI_Address $obj_with_address = null ) { |
|
| 206 | + public static function postalCode(EEI_Address $obj_with_address = null) { |
|
| 207 | 207 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
| 208 | 208 | . $obj_with_address->zip() |
| 209 | 209 | . '</span>' : ''; |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | * @param string $phone_nmbr |
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | - public static function telephone( $phone_nmbr = null ) { |
|
| 223 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
| 222 | + public static function telephone($phone_nmbr = null) { |
|
| 223 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
| 224 | 224 | : ''; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -236,13 +236,13 @@ discard block |
||
| 236 | 236 | * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
| 237 | 237 | * @return string (link) |
| 238 | 238 | */ |
| 239 | - public static function url( $url = null, $text = null, $attributes = array() ) { |
|
| 239 | + public static function url($url = null, $text = null, $attributes = array()) { |
|
| 240 | 240 | $atts = ''; |
| 241 | - foreach ( $attributes as $attribute => $value ) { |
|
| 242 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
| 241 | + foreach ($attributes as $attribute => $value) { |
|
| 242 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
| 243 | 243 | } |
| 244 | 244 | $text = $text !== null && $text !== '' ? $text : $url; |
| 245 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
| 245 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
| 246 | 246 | : ''; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -17,62 +17,62 @@ discard block |
||
| 17 | 17 | class EEH_Schema { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * generates JSON-based linked data for an event |
|
| 22 | - * |
|
| 23 | - * @param \EE_Event $event |
|
| 24 | - */ |
|
| 25 | - public static function add_json_linked_data_for_event(\EE_Event $event) |
|
| 26 | - { |
|
| 27 | - $template_args = array( |
|
| 28 | - 'event_permalink' => '', |
|
| 29 | - 'event_name' => '', |
|
| 30 | - 'event_description' => '', |
|
| 31 | - 'event_start' => '', |
|
| 32 | - 'event_end' => '', |
|
| 33 | - 'currency' => '', |
|
| 34 | - 'event_tickets' => array(), |
|
| 35 | - 'venue_name' => '', |
|
| 36 | - 'venue_url' => '', |
|
| 37 | - 'venue_locality' => '', |
|
| 38 | - 'venue_region' => '', |
|
| 39 | - 'event_image' => '', |
|
| 40 | - ); |
|
| 41 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
| 42 | - $template_args['event_name'] = $event->name(); |
|
| 43 | - $template_args['event_description'] = $event->description(); |
|
| 44 | - $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM); |
|
| 45 | - $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM); |
|
| 46 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 47 | - foreach ($event->tickets() as $ticket) { |
|
| 48 | - $ID = $ticket->ID(); |
|
| 49 | - $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 50 | - $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 51 | - $template_args['event_tickets'][$ID]['price'] = number_format( |
|
| 52 | - $ticket->price(), |
|
| 53 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 54 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 55 | - EE_Registry::instance()->CFG->currency->thsnds |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - $VNU_ID = espresso_venue_id(); |
|
| 59 | - if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 60 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 61 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 62 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 63 | - $template_args['venue_locality'] = $venue->city(); |
|
| 64 | - $template_args['venue_region'] = $venue->state_name(); |
|
| 65 | - } |
|
| 66 | - $template_args['event_image'] = $event->feature_image_url(); |
|
| 67 | - $template_args = apply_filters( |
|
| 68 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 69 | - $template_args, |
|
| 70 | - $event, |
|
| 71 | - $VNU_ID |
|
| 72 | - ); |
|
| 73 | - extract($template_args, EXTR_OVERWRITE); |
|
| 74 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 75 | - } |
|
| 20 | + /** |
|
| 21 | + * generates JSON-based linked data for an event |
|
| 22 | + * |
|
| 23 | + * @param \EE_Event $event |
|
| 24 | + */ |
|
| 25 | + public static function add_json_linked_data_for_event(\EE_Event $event) |
|
| 26 | + { |
|
| 27 | + $template_args = array( |
|
| 28 | + 'event_permalink' => '', |
|
| 29 | + 'event_name' => '', |
|
| 30 | + 'event_description' => '', |
|
| 31 | + 'event_start' => '', |
|
| 32 | + 'event_end' => '', |
|
| 33 | + 'currency' => '', |
|
| 34 | + 'event_tickets' => array(), |
|
| 35 | + 'venue_name' => '', |
|
| 36 | + 'venue_url' => '', |
|
| 37 | + 'venue_locality' => '', |
|
| 38 | + 'venue_region' => '', |
|
| 39 | + 'event_image' => '', |
|
| 40 | + ); |
|
| 41 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
| 42 | + $template_args['event_name'] = $event->name(); |
|
| 43 | + $template_args['event_description'] = $event->description(); |
|
| 44 | + $template_args['event_start'] = $event->primary_datetime()->start_date(DateTime::ATOM); |
|
| 45 | + $template_args['event_end'] = $event->primary_datetime()->end_date(DateTime::ATOM); |
|
| 46 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
| 47 | + foreach ($event->tickets() as $ticket) { |
|
| 48 | + $ID = $ticket->ID(); |
|
| 49 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
| 50 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
| 51 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
| 52 | + $ticket->price(), |
|
| 53 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
| 54 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
| 55 | + EE_Registry::instance()->CFG->currency->thsnds |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + $VNU_ID = espresso_venue_id(); |
|
| 59 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
| 60 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
| 61 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
| 62 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
| 63 | + $template_args['venue_locality'] = $venue->city(); |
|
| 64 | + $template_args['venue_region'] = $venue->state_name(); |
|
| 65 | + } |
|
| 66 | + $template_args['event_image'] = $event->feature_image_url(); |
|
| 67 | + $template_args = apply_filters( |
|
| 68 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
| 69 | + $template_args, |
|
| 70 | + $event, |
|
| 71 | + $VNU_ID |
|
| 72 | + ); |
|
| 73 | + extract($template_args, EXTR_OVERWRITE); |
|
| 74 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public static function location( $location = null ) { |
| 88 | 88 | return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
| 89 | - . $location |
|
| 90 | - . '</div>' : ''; |
|
| 89 | + . $location |
|
| 90 | + . '</div>' : ''; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public static function postalCode( EEI_Address $obj_with_address = null ) { |
| 209 | 209 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
| 210 | - . $obj_with_address->zip() |
|
| 211 | - . '</span>' : ''; |
|
| 210 | + . $obj_with_address->zip() |
|
| 211 | + . '</span>' : ''; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -22,686 +22,686 @@ discard block |
||
| 22 | 22 | final class EE_Front_Controller |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * $_template_path |
|
| 27 | - * @var string $_template_path |
|
| 28 | - * @access public |
|
| 29 | - */ |
|
| 30 | - private $_template_path; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * $_template |
|
| 34 | - * @var string $_template |
|
| 35 | - * @access public |
|
| 36 | - */ |
|
| 37 | - private $_template; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @type EE_Registry $Registry |
|
| 41 | - * @access protected |
|
| 42 | - */ |
|
| 43 | - protected $Registry; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @type EE_Request_Handler $Request_Handler |
|
| 47 | - * @access protected |
|
| 48 | - */ |
|
| 49 | - protected $Request_Handler; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
| 53 | - * @access protected |
|
| 54 | - */ |
|
| 55 | - protected $Module_Request_Router; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * class constructor |
|
| 60 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 61 | - * |
|
| 62 | - * @access public |
|
| 63 | - * @param \EE_Registry $Registry |
|
| 64 | - * @param \EE_Request_Handler $Request_Handler |
|
| 65 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 66 | - */ |
|
| 67 | - public function __construct( |
|
| 68 | - EE_Registry $Registry, |
|
| 69 | - EE_Request_Handler $Request_Handler, |
|
| 70 | - EE_Module_Request_Router $Module_Request_Router |
|
| 71 | - ) { |
|
| 72 | - $this->Registry = $Registry; |
|
| 73 | - $this->Request_Handler = $Request_Handler; |
|
| 74 | - $this->Module_Request_Router = $Module_Request_Router; |
|
| 75 | - // make sure template tags are loaded immediately so that themes don't break |
|
| 76 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10); |
|
| 77 | - // determine how to integrate WP_Query with the EE models |
|
| 78 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 79 | - // load other resources and begin to actually run shortcodes and modules |
|
| 80 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 81 | - // analyse the incoming WP request |
|
| 82 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 83 | - // process any content shortcodes |
|
| 84 | - add_action('parse_request', array($this, '_initialize_shortcodes'), 5); |
|
| 85 | - // process request with module factory |
|
| 86 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 87 | - // before headers sent |
|
| 88 | - add_action('wp', array($this, 'wp'), 5); |
|
| 89 | - // load css and js |
|
| 90 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1); |
|
| 91 | - // header |
|
| 92 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 93 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 94 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
| 95 | - // display errors |
|
| 96 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 97 | - // the content |
|
| 98 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 99 | - //exclude our private cpt comments |
|
| 100 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 101 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 102 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 103 | - // action hook EE |
|
| 104 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 105 | - // for checking that browser cookies are enabled |
|
| 106 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 107 | - setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/'); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return EE_Request_Handler |
|
| 114 | - */ |
|
| 115 | - public function Request_Handler() |
|
| 116 | - { |
|
| 117 | - return $this->Request_Handler; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return EE_Module_Request_Router |
|
| 123 | - */ |
|
| 124 | - public function Module_Request_Router() |
|
| 125 | - { |
|
| 126 | - return $this->Module_Request_Router; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 138 | - * load it's functions.php file ( if not already loaded ) |
|
| 139 | - * |
|
| 140 | - * @return void |
|
| 141 | - */ |
|
| 142 | - public function load_espresso_template_tags() |
|
| 143 | - { |
|
| 144 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 145 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * filter_wp_comments |
|
| 152 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 153 | - * widgets/queries done on frontend |
|
| 154 | - * |
|
| 155 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 156 | - * @return array array of comment clauses with modifications. |
|
| 157 | - */ |
|
| 158 | - public function filter_wp_comments($clauses) |
|
| 159 | - { |
|
| 160 | - global $wpdb; |
|
| 161 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 162 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 163 | - foreach ($cpts as $cpt => $details) { |
|
| 164 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return $clauses; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * employ_CPT_Strategy |
|
| 173 | - * |
|
| 174 | - * @access public |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - public function employ_CPT_Strategy() |
|
| 178 | - { |
|
| 179 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 180 | - $this->Registry->load_core('CPT_Strategy'); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 187 | - * |
|
| 188 | - * @param string $url incoming url |
|
| 189 | - * @return string final assembled url |
|
| 190 | - */ |
|
| 191 | - public function maybe_force_admin_ajax_ssl($url) |
|
| 192 | - { |
|
| 193 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 194 | - $url = str_replace('http://', 'https://', $url); |
|
| 195 | - } |
|
| 196 | - return $url; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 209 | - * default priority init phases have run |
|
| 210 | - * |
|
| 211 | - * @access public |
|
| 212 | - * @return void |
|
| 213 | - */ |
|
| 214 | - public function wp_loaded() |
|
| 215 | - { |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 223 | - /** |
|
| 224 | - * _get_request |
|
| 225 | - * |
|
| 226 | - * @access public |
|
| 227 | - * @param WP $WP |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function get_request(WP $WP) |
|
| 231 | - { |
|
| 232 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 233 | - $this->Request_Handler->parse_request($WP); |
|
| 234 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for |
|
| 240 | - * the currently requested page |
|
| 241 | - * |
|
| 242 | - * @access public |
|
| 243 | - * @param WP $WP |
|
| 244 | - * @return void |
|
| 245 | - */ |
|
| 246 | - public function _initialize_shortcodes(WP $WP) |
|
| 247 | - { |
|
| 248 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this); |
|
| 249 | - $this->Request_Handler->set_request_vars($WP); |
|
| 250 | - // grab post_name from request |
|
| 251 | - $current_post = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 252 | - $this->Request_Handler->get('post_name')); |
|
| 253 | - $show_on_front = get_option('show_on_front'); |
|
| 254 | - // if it's not set, then check if frontpage is blog |
|
| 255 | - if (empty($current_post)) { |
|
| 256 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 257 | - $current_post = 'posts'; |
|
| 258 | - // unless.. |
|
| 259 | - if ($show_on_front === 'page') { |
|
| 260 | - // some other page is set as the homepage |
|
| 261 | - $page_on_front = get_option('page_on_front'); |
|
| 262 | - if ($page_on_front) { |
|
| 263 | - // k now we need to find the post_name for this page |
|
| 264 | - global $wpdb; |
|
| 265 | - $page_on_front = $wpdb->get_var( |
|
| 266 | - $wpdb->prepare( |
|
| 267 | - "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
| 268 | - $page_on_front |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - // set the current post slug to what it actually is |
|
| 272 | - $current_post = $page_on_front ? $page_on_front : $current_post; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - // where are posts being displayed ? |
|
| 277 | - $page_for_posts = EE_Config::get_page_for_posts(); |
|
| 278 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 279 | - $current_post = basename($current_post); |
|
| 280 | - // are we on a category page? |
|
| 281 | - $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name', |
|
| 282 | - $WP->query_vars); |
|
| 283 | - // make sure shortcodes are set |
|
| 284 | - if (isset($this->Registry->CFG->core->post_shortcodes)) { |
|
| 285 | - if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) { |
|
| 286 | - $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array(); |
|
| 287 | - } |
|
| 288 | - // cycle thru all posts with shortcodes set |
|
| 289 | - foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
| 290 | - // filter shortcodes so |
|
| 291 | - $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', |
|
| 292 | - $post_shortcodes); |
|
| 293 | - // now cycle thru shortcodes |
|
| 294 | - foreach ($post_shortcodes as $shortcode_class => $post_id) { |
|
| 295 | - // are we on this page, or on the blog page, or an EE CPT category page ? |
|
| 296 | - if ($current_post === $post_name || $term_exists) { |
|
| 297 | - // maybe init the shortcode |
|
| 298 | - $this->initialize_shortcode_if_active_on_page( |
|
| 299 | - $shortcode_class, |
|
| 300 | - $current_post, |
|
| 301 | - $page_for_posts, |
|
| 302 | - $post_id, |
|
| 303 | - $term_exists, |
|
| 304 | - $WP |
|
| 305 | - ); |
|
| 306 | - // if this is NOT the "Posts page" and we have a valid entry |
|
| 307 | - // for the "Posts page" in our tracked post_shortcodes array |
|
| 308 | - // but the shortcode is not being tracked for this page |
|
| 309 | - } else if ( |
|
| 310 | - $post_name !== $page_for_posts |
|
| 311 | - && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts]) |
|
| 312 | - && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class]) |
|
| 313 | - ) { |
|
| 314 | - // then remove the "fallback" shortcode processor |
|
| 315 | - remove_shortcode($shortcode_class); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @param string $shortcode_class |
|
| 326 | - * @param string $current_post |
|
| 327 | - * @param string $page_for_posts |
|
| 328 | - * @param int $post_id |
|
| 329 | - * @param bool $term_exists |
|
| 330 | - * @param WP $WP |
|
| 331 | - */ |
|
| 332 | - protected function initialize_shortcode_if_active_on_page( |
|
| 333 | - $shortcode_class, |
|
| 334 | - $current_post, |
|
| 335 | - $page_for_posts, |
|
| 336 | - $post_id, |
|
| 337 | - $term_exists, |
|
| 338 | - $WP |
|
| 339 | - ) { |
|
| 340 | - // verify shortcode is in list of registered shortcodes |
|
| 341 | - if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) { |
|
| 342 | - if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) { |
|
| 343 | - EE_Error::add_error( |
|
| 344 | - sprintf( |
|
| 345 | - __( |
|
| 346 | - 'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', |
|
| 347 | - 'event_espresso' |
|
| 348 | - ), |
|
| 349 | - $shortcode_class |
|
| 350 | - ), |
|
| 351 | - __FILE__, |
|
| 352 | - __FUNCTION__, |
|
| 353 | - __LINE__ |
|
| 354 | - ); |
|
| 355 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 356 | - } |
|
| 357 | - add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor')); |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ? |
|
| 361 | - if ( |
|
| 362 | - $term_exists |
|
| 363 | - || $current_post === $page_for_posts |
|
| 364 | - || isset($this->Registry->CFG->core->post_shortcodes[$current_post]) |
|
| 365 | - ) { |
|
| 366 | - // let's pause to reflect on this... |
|
| 367 | - $sc_reflector = new ReflectionClass('EES_' . $shortcode_class); |
|
| 368 | - // ensure that class is actually a shortcode |
|
| 369 | - if ( |
|
| 370 | - defined('WP_DEBUG') |
|
| 371 | - && WP_DEBUG === true |
|
| 372 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 373 | - ) { |
|
| 374 | - EE_Error::add_error( |
|
| 375 | - sprintf( |
|
| 376 | - __( |
|
| 377 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 378 | - 'event_espresso' |
|
| 379 | - ), |
|
| 380 | - $shortcode_class |
|
| 381 | - ), |
|
| 382 | - __FILE__, |
|
| 383 | - __FUNCTION__, |
|
| 384 | - __LINE__ |
|
| 385 | - ); |
|
| 386 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 387 | - return; |
|
| 388 | - } |
|
| 389 | - // and pass the request object to the run method |
|
| 390 | - $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 391 | - // fire the shortcode class's run method, so that it can activate resources |
|
| 392 | - $this->Registry->shortcodes->{$shortcode_class}->run($WP); |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @param WP_Query $WP_Query |
|
| 402 | - * @return void |
|
| 403 | - */ |
|
| 404 | - public function pre_get_posts($WP_Query) |
|
| 405 | - { |
|
| 406 | - // only load Module_Request_Router if this is the main query |
|
| 407 | - if ( |
|
| 408 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 409 | - && $WP_Query->is_main_query() |
|
| 410 | - ) { |
|
| 411 | - // cycle thru module routes |
|
| 412 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 413 | - // determine module and method for route |
|
| 414 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 415 | - if ($module instanceof EED_Module) { |
|
| 416 | - // get registered view for route |
|
| 417 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 418 | - // grab module name |
|
| 419 | - $module_name = $module->module_name(); |
|
| 420 | - // map the module to the module objects |
|
| 421 | - $this->Registry->modules->{$module_name} = $module; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /*********************************************** WP HOOK ***********************************************/ |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * wp - basically last chance to do stuff before headers sent |
|
| 436 | - * |
|
| 437 | - * @access public |
|
| 438 | - * @return void |
|
| 439 | - */ |
|
| 440 | - public function wp() |
|
| 441 | - { |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /*********************************************** WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK ***********************************************/ |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * wp_enqueue_scripts |
|
| 451 | - * |
|
| 452 | - * @access public |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function wp_enqueue_scripts() |
|
| 456 | - { |
|
| 457 | - |
|
| 458 | - // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_css', '__return_false' ); |
|
| 459 | - if (apply_filters('FHEE_load_css', true)) { |
|
| 460 | - |
|
| 461 | - $this->Registry->CFG->template_settings->enable_default_style = true; |
|
| 462 | - //Load the ThemeRoller styles if enabled |
|
| 463 | - if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) { |
|
| 464 | - |
|
| 465 | - //Load custom style sheet if available |
|
| 466 | - if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) { |
|
| 467 | - wp_register_style('espresso_custom_css', |
|
| 468 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 469 | - EVENT_ESPRESSO_VERSION); |
|
| 470 | - wp_enqueue_style('espresso_custom_css'); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) { |
|
| 474 | - wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', |
|
| 475 | - array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 476 | - } else { |
|
| 477 | - wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 478 | - array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 479 | - } |
|
| 480 | - wp_enqueue_style('espresso_default'); |
|
| 481 | - |
|
| 482 | - if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) { |
|
| 483 | - wp_register_style('espresso_style', |
|
| 484 | - get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 485 | - array('dashicons', 'espresso_default')); |
|
| 486 | - } else { |
|
| 487 | - wp_register_style('espresso_style', |
|
| 488 | - EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 489 | - array('dashicons', 'espresso_default')); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_js', '__return_false' ); |
|
| 497 | - if (apply_filters('FHEE_load_js', true)) { |
|
| 498 | - |
|
| 499 | - wp_enqueue_script('jquery'); |
|
| 500 | - //let's make sure that all required scripts have been setup |
|
| 501 | - if (function_exists('wp_script_is') && ! wp_script_is('jquery')) { |
|
| 502 | - $msg = sprintf( |
|
| 503 | - __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', |
|
| 504 | - 'event_espresso'), |
|
| 505 | - '<em><br />', |
|
| 506 | - '</em>' |
|
| 507 | - ); |
|
| 508 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 509 | - } |
|
| 510 | - // load core js |
|
| 511 | - wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), |
|
| 512 | - EVENT_ESPRESSO_VERSION, true); |
|
| 513 | - wp_enqueue_script('espresso_core'); |
|
| 514 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 515 | - |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 519 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
| 520 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - //accounting.js library |
|
| 525 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 526 | - if (apply_filters('FHEE_load_accounting_js', false)) { |
|
| 527 | - $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
| 528 | - wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 529 | - array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 530 | - wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true); |
|
| 531 | - wp_enqueue_script('ee-accounting'); |
|
| 532 | - |
|
| 533 | - $currency_config = array( |
|
| 534 | - 'currency' => array( |
|
| 535 | - 'symbol' => $this->Registry->CFG->currency->sign, |
|
| 536 | - 'format' => array( |
|
| 537 | - 'pos' => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s', |
|
| 538 | - 'neg' => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 539 | - 'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s', |
|
| 540 | - ), |
|
| 541 | - 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 542 | - 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 543 | - 'precision' => $this->Registry->CFG->currency->dec_plc, |
|
| 544 | - ), |
|
| 545 | - 'number' => array( |
|
| 546 | - 'precision' => 0, |
|
| 547 | - 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 548 | - 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 549 | - ), |
|
| 550 | - ); |
|
| 551 | - wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ( ! function_exists('wp_head')) { |
|
| 555 | - $msg = sprintf( |
|
| 556 | - __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 557 | - 'event_espresso'), |
|
| 558 | - '<em><br />', |
|
| 559 | - '</em>' |
|
| 560 | - ); |
|
| 561 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 562 | - } |
|
| 563 | - if ( ! function_exists('wp_footer')) { |
|
| 564 | - $msg = sprintf( |
|
| 565 | - __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 566 | - 'event_espresso'), |
|
| 567 | - '<em><br />', |
|
| 568 | - '</em>' |
|
| 569 | - ); |
|
| 570 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - |
|
| 576 | - /** |
|
| 577 | - * header_meta_tag |
|
| 578 | - * |
|
| 579 | - * @access public |
|
| 580 | - * @return void |
|
| 581 | - */ |
|
| 582 | - public function header_meta_tag() |
|
| 583 | - { |
|
| 584 | - print( |
|
| 585 | - apply_filters( |
|
| 586 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 587 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 588 | - ); |
|
| 589 | - |
|
| 590 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 591 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 592 | - if ( |
|
| 593 | - is_tax('espresso_event_type') |
|
| 594 | - && get_option( 'blog_public' ) !== '0' |
|
| 595 | - ) { |
|
| 596 | - print( |
|
| 597 | - apply_filters( |
|
| 598 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 599 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 600 | - ) |
|
| 601 | - ); |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * wp_print_scripts |
|
| 609 | - * |
|
| 610 | - * @return void |
|
| 611 | - */ |
|
| 612 | - public function wp_print_scripts() |
|
| 613 | - { |
|
| 614 | - global $post; |
|
| 615 | - if (get_post_type() === 'espresso_events' && is_singular()) { |
|
| 616 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 617 | - } |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - |
|
| 622 | - /*********************************************** THE_CONTENT FILTER HOOK ***********************************************/ |
|
| 623 | - |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * the_content |
|
| 628 | - * |
|
| 629 | - * @access public |
|
| 630 | - * @param $the_content |
|
| 631 | - * @return string |
|
| 632 | - */ |
|
| 633 | - // public function the_content( $the_content ) { |
|
| 634 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 635 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 636 | - // } |
|
| 637 | - // return $the_content; |
|
| 638 | - // } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * display_errors |
|
| 646 | - * |
|
| 647 | - * @access public |
|
| 648 | - * @return string |
|
| 649 | - */ |
|
| 650 | - public function display_errors() |
|
| 651 | - { |
|
| 652 | - static $shown_already = false; |
|
| 653 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 654 | - if ( |
|
| 655 | - ! $shown_already |
|
| 656 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 657 | - && is_main_query() |
|
| 658 | - && ! is_feed() |
|
| 659 | - && in_the_loop() |
|
| 660 | - && $this->Request_Handler->is_espresso_page() |
|
| 661 | - ) { |
|
| 662 | - echo EE_Error::get_notices(); |
|
| 663 | - $shown_already = true; |
|
| 664 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 665 | - } |
|
| 666 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /*********************************************** UTILITIES ***********************************************/ |
|
| 674 | - /** |
|
| 675 | - * template_include |
|
| 676 | - * |
|
| 677 | - * @access public |
|
| 678 | - * @param string $template_include_path |
|
| 679 | - * @return string |
|
| 680 | - */ |
|
| 681 | - public function template_include($template_include_path = null) |
|
| 682 | - { |
|
| 683 | - if ($this->Request_Handler->is_espresso_page()) { |
|
| 684 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 685 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 686 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 687 | - $this->_template = basename($this->_template_path); |
|
| 688 | - return $this->_template_path; |
|
| 689 | - } |
|
| 690 | - return $template_include_path; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * get_selected_template |
|
| 696 | - * |
|
| 697 | - * @access public |
|
| 698 | - * @param bool $with_path |
|
| 699 | - * @return string |
|
| 700 | - */ |
|
| 701 | - public function get_selected_template($with_path = false) |
|
| 702 | - { |
|
| 703 | - return $with_path ? $this->_template_path : $this->_template; |
|
| 704 | - } |
|
| 25 | + /** |
|
| 26 | + * $_template_path |
|
| 27 | + * @var string $_template_path |
|
| 28 | + * @access public |
|
| 29 | + */ |
|
| 30 | + private $_template_path; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * $_template |
|
| 34 | + * @var string $_template |
|
| 35 | + * @access public |
|
| 36 | + */ |
|
| 37 | + private $_template; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @type EE_Registry $Registry |
|
| 41 | + * @access protected |
|
| 42 | + */ |
|
| 43 | + protected $Registry; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @type EE_Request_Handler $Request_Handler |
|
| 47 | + * @access protected |
|
| 48 | + */ |
|
| 49 | + protected $Request_Handler; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
| 53 | + * @access protected |
|
| 54 | + */ |
|
| 55 | + protected $Module_Request_Router; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * class constructor |
|
| 60 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
| 61 | + * |
|
| 62 | + * @access public |
|
| 63 | + * @param \EE_Registry $Registry |
|
| 64 | + * @param \EE_Request_Handler $Request_Handler |
|
| 65 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
| 66 | + */ |
|
| 67 | + public function __construct( |
|
| 68 | + EE_Registry $Registry, |
|
| 69 | + EE_Request_Handler $Request_Handler, |
|
| 70 | + EE_Module_Request_Router $Module_Request_Router |
|
| 71 | + ) { |
|
| 72 | + $this->Registry = $Registry; |
|
| 73 | + $this->Request_Handler = $Request_Handler; |
|
| 74 | + $this->Module_Request_Router = $Module_Request_Router; |
|
| 75 | + // make sure template tags are loaded immediately so that themes don't break |
|
| 76 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'load_espresso_template_tags'), 10); |
|
| 77 | + // determine how to integrate WP_Query with the EE models |
|
| 78 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
| 79 | + // load other resources and begin to actually run shortcodes and modules |
|
| 80 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
| 81 | + // analyse the incoming WP request |
|
| 82 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
| 83 | + // process any content shortcodes |
|
| 84 | + add_action('parse_request', array($this, '_initialize_shortcodes'), 5); |
|
| 85 | + // process request with module factory |
|
| 86 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
| 87 | + // before headers sent |
|
| 88 | + add_action('wp', array($this, 'wp'), 5); |
|
| 89 | + // load css and js |
|
| 90 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 1); |
|
| 91 | + // header |
|
| 92 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
| 93 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
| 94 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
| 95 | + // display errors |
|
| 96 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
| 97 | + // the content |
|
| 98 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
| 99 | + //exclude our private cpt comments |
|
| 100 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
| 101 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
| 102 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
| 103 | + // action hook EE |
|
| 104 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
| 105 | + // for checking that browser cookies are enabled |
|
| 106 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
| 107 | + setcookie('ee_cookie_test', uniqid(), time() + 24 * HOUR_IN_SECONDS, '/'); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return EE_Request_Handler |
|
| 114 | + */ |
|
| 115 | + public function Request_Handler() |
|
| 116 | + { |
|
| 117 | + return $this->Request_Handler; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return EE_Module_Request_Router |
|
| 123 | + */ |
|
| 124 | + public function Module_Request_Router() |
|
| 125 | + { |
|
| 126 | + return $this->Module_Request_Router; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * load_espresso_template_tags - if current theme is an espresso theme, or uses ee theme template parts, then |
|
| 138 | + * load it's functions.php file ( if not already loaded ) |
|
| 139 | + * |
|
| 140 | + * @return void |
|
| 141 | + */ |
|
| 142 | + public function load_espresso_template_tags() |
|
| 143 | + { |
|
| 144 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
| 145 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * filter_wp_comments |
|
| 152 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
| 153 | + * widgets/queries done on frontend |
|
| 154 | + * |
|
| 155 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
| 156 | + * @return array array of comment clauses with modifications. |
|
| 157 | + */ |
|
| 158 | + public function filter_wp_comments($clauses) |
|
| 159 | + { |
|
| 160 | + global $wpdb; |
|
| 161 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
| 162 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
| 163 | + foreach ($cpts as $cpt => $details) { |
|
| 164 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return $clauses; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * employ_CPT_Strategy |
|
| 173 | + * |
|
| 174 | + * @access public |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + public function employ_CPT_Strategy() |
|
| 178 | + { |
|
| 179 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
| 180 | + $this->Registry->load_core('CPT_Strategy'); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
| 187 | + * |
|
| 188 | + * @param string $url incoming url |
|
| 189 | + * @return string final assembled url |
|
| 190 | + */ |
|
| 191 | + public function maybe_force_admin_ajax_ssl($url) |
|
| 192 | + { |
|
| 193 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
| 194 | + $url = str_replace('http://', 'https://', $url); |
|
| 195 | + } |
|
| 196 | + return $url; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
| 209 | + * default priority init phases have run |
|
| 210 | + * |
|
| 211 | + * @access public |
|
| 212 | + * @return void |
|
| 213 | + */ |
|
| 214 | + public function wp_loaded() |
|
| 215 | + { |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
| 223 | + /** |
|
| 224 | + * _get_request |
|
| 225 | + * |
|
| 226 | + * @access public |
|
| 227 | + * @param WP $WP |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function get_request(WP $WP) |
|
| 231 | + { |
|
| 232 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
| 233 | + $this->Request_Handler->parse_request($WP); |
|
| 234 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * _initialize_shortcodes - calls init method on shortcodes that have been determined to be in the_content for |
|
| 240 | + * the currently requested page |
|
| 241 | + * |
|
| 242 | + * @access public |
|
| 243 | + * @param WP $WP |
|
| 244 | + * @return void |
|
| 245 | + */ |
|
| 246 | + public function _initialize_shortcodes(WP $WP) |
|
| 247 | + { |
|
| 248 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $WP, $this); |
|
| 249 | + $this->Request_Handler->set_request_vars($WP); |
|
| 250 | + // grab post_name from request |
|
| 251 | + $current_post = apply_filters('FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 252 | + $this->Request_Handler->get('post_name')); |
|
| 253 | + $show_on_front = get_option('show_on_front'); |
|
| 254 | + // if it's not set, then check if frontpage is blog |
|
| 255 | + if (empty($current_post)) { |
|
| 256 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 257 | + $current_post = 'posts'; |
|
| 258 | + // unless.. |
|
| 259 | + if ($show_on_front === 'page') { |
|
| 260 | + // some other page is set as the homepage |
|
| 261 | + $page_on_front = get_option('page_on_front'); |
|
| 262 | + if ($page_on_front) { |
|
| 263 | + // k now we need to find the post_name for this page |
|
| 264 | + global $wpdb; |
|
| 265 | + $page_on_front = $wpdb->get_var( |
|
| 266 | + $wpdb->prepare( |
|
| 267 | + "SELECT post_name from $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID=%d", |
|
| 268 | + $page_on_front |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + // set the current post slug to what it actually is |
|
| 272 | + $current_post = $page_on_front ? $page_on_front : $current_post; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + // where are posts being displayed ? |
|
| 277 | + $page_for_posts = EE_Config::get_page_for_posts(); |
|
| 278 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 279 | + $current_post = basename($current_post); |
|
| 280 | + // are we on a category page? |
|
| 281 | + $term_exists = is_array(term_exists($current_post, 'category')) || array_key_exists('category_name', |
|
| 282 | + $WP->query_vars); |
|
| 283 | + // make sure shortcodes are set |
|
| 284 | + if (isset($this->Registry->CFG->core->post_shortcodes)) { |
|
| 285 | + if ( ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts])) { |
|
| 286 | + $this->Registry->CFG->core->post_shortcodes[$page_for_posts] = array(); |
|
| 287 | + } |
|
| 288 | + // cycle thru all posts with shortcodes set |
|
| 289 | + foreach ($this->Registry->CFG->core->post_shortcodes as $post_name => $post_shortcodes) { |
|
| 290 | + // filter shortcodes so |
|
| 291 | + $post_shortcodes = apply_filters('FHEE__Front_Controller__initialize_shortcodes__post_shortcodes', |
|
| 292 | + $post_shortcodes); |
|
| 293 | + // now cycle thru shortcodes |
|
| 294 | + foreach ($post_shortcodes as $shortcode_class => $post_id) { |
|
| 295 | + // are we on this page, or on the blog page, or an EE CPT category page ? |
|
| 296 | + if ($current_post === $post_name || $term_exists) { |
|
| 297 | + // maybe init the shortcode |
|
| 298 | + $this->initialize_shortcode_if_active_on_page( |
|
| 299 | + $shortcode_class, |
|
| 300 | + $current_post, |
|
| 301 | + $page_for_posts, |
|
| 302 | + $post_id, |
|
| 303 | + $term_exists, |
|
| 304 | + $WP |
|
| 305 | + ); |
|
| 306 | + // if this is NOT the "Posts page" and we have a valid entry |
|
| 307 | + // for the "Posts page" in our tracked post_shortcodes array |
|
| 308 | + // but the shortcode is not being tracked for this page |
|
| 309 | + } else if ( |
|
| 310 | + $post_name !== $page_for_posts |
|
| 311 | + && isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts]) |
|
| 312 | + && ! isset($this->Registry->CFG->core->post_shortcodes[$page_for_posts][$shortcode_class]) |
|
| 313 | + ) { |
|
| 314 | + // then remove the "fallback" shortcode processor |
|
| 315 | + remove_shortcode($shortcode_class); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $this); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * @param string $shortcode_class |
|
| 326 | + * @param string $current_post |
|
| 327 | + * @param string $page_for_posts |
|
| 328 | + * @param int $post_id |
|
| 329 | + * @param bool $term_exists |
|
| 330 | + * @param WP $WP |
|
| 331 | + */ |
|
| 332 | + protected function initialize_shortcode_if_active_on_page( |
|
| 333 | + $shortcode_class, |
|
| 334 | + $current_post, |
|
| 335 | + $page_for_posts, |
|
| 336 | + $post_id, |
|
| 337 | + $term_exists, |
|
| 338 | + $WP |
|
| 339 | + ) { |
|
| 340 | + // verify shortcode is in list of registered shortcodes |
|
| 341 | + if ( ! isset($this->Registry->shortcodes->{$shortcode_class})) { |
|
| 342 | + if ($current_post !== $page_for_posts && current_user_can('edit_post', $post_id)) { |
|
| 343 | + EE_Error::add_error( |
|
| 344 | + sprintf( |
|
| 345 | + __( |
|
| 346 | + 'The [%s] shortcode has not been properly registered or the corresponding addon/module is not active for some reason. Either fix/remove the shortcode from the post, or activate the addon/module the shortcode is associated with.', |
|
| 347 | + 'event_espresso' |
|
| 348 | + ), |
|
| 349 | + $shortcode_class |
|
| 350 | + ), |
|
| 351 | + __FILE__, |
|
| 352 | + __FUNCTION__, |
|
| 353 | + __LINE__ |
|
| 354 | + ); |
|
| 355 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 356 | + } |
|
| 357 | + add_shortcode($shortcode_class, array('EES_Shortcode', 'invalid_shortcode_processor')); |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + // is this : a shortcodes set exclusively for this post, or for the home page, or a category, or a taxonomy ? |
|
| 361 | + if ( |
|
| 362 | + $term_exists |
|
| 363 | + || $current_post === $page_for_posts |
|
| 364 | + || isset($this->Registry->CFG->core->post_shortcodes[$current_post]) |
|
| 365 | + ) { |
|
| 366 | + // let's pause to reflect on this... |
|
| 367 | + $sc_reflector = new ReflectionClass('EES_' . $shortcode_class); |
|
| 368 | + // ensure that class is actually a shortcode |
|
| 369 | + if ( |
|
| 370 | + defined('WP_DEBUG') |
|
| 371 | + && WP_DEBUG === true |
|
| 372 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 373 | + ) { |
|
| 374 | + EE_Error::add_error( |
|
| 375 | + sprintf( |
|
| 376 | + __( |
|
| 377 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 378 | + 'event_espresso' |
|
| 379 | + ), |
|
| 380 | + $shortcode_class |
|
| 381 | + ), |
|
| 382 | + __FILE__, |
|
| 383 | + __FUNCTION__, |
|
| 384 | + __LINE__ |
|
| 385 | + ); |
|
| 386 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 387 | + return; |
|
| 388 | + } |
|
| 389 | + // and pass the request object to the run method |
|
| 390 | + $this->Registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 391 | + // fire the shortcode class's run method, so that it can activate resources |
|
| 392 | + $this->Registry->shortcodes->{$shortcode_class}->run($WP); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @param WP_Query $WP_Query |
|
| 402 | + * @return void |
|
| 403 | + */ |
|
| 404 | + public function pre_get_posts($WP_Query) |
|
| 405 | + { |
|
| 406 | + // only load Module_Request_Router if this is the main query |
|
| 407 | + if ( |
|
| 408 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
| 409 | + && $WP_Query->is_main_query() |
|
| 410 | + ) { |
|
| 411 | + // cycle thru module routes |
|
| 412 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
| 413 | + // determine module and method for route |
|
| 414 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
| 415 | + if ($module instanceof EED_Module) { |
|
| 416 | + // get registered view for route |
|
| 417 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
| 418 | + // grab module name |
|
| 419 | + $module_name = $module->module_name(); |
|
| 420 | + // map the module to the module objects |
|
| 421 | + $this->Registry->modules->{$module_name} = $module; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /*********************************************** WP HOOK ***********************************************/ |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * wp - basically last chance to do stuff before headers sent |
|
| 436 | + * |
|
| 437 | + * @access public |
|
| 438 | + * @return void |
|
| 439 | + */ |
|
| 440 | + public function wp() |
|
| 441 | + { |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /*********************************************** WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK ***********************************************/ |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * wp_enqueue_scripts |
|
| 451 | + * |
|
| 452 | + * @access public |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function wp_enqueue_scripts() |
|
| 456 | + { |
|
| 457 | + |
|
| 458 | + // css is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_css', '__return_false' ); |
|
| 459 | + if (apply_filters('FHEE_load_css', true)) { |
|
| 460 | + |
|
| 461 | + $this->Registry->CFG->template_settings->enable_default_style = true; |
|
| 462 | + //Load the ThemeRoller styles if enabled |
|
| 463 | + if (isset($this->Registry->CFG->template_settings->enable_default_style) && $this->Registry->CFG->template_settings->enable_default_style) { |
|
| 464 | + |
|
| 465 | + //Load custom style sheet if available |
|
| 466 | + if (isset($this->Registry->CFG->template_settings->custom_style_sheet)) { |
|
| 467 | + wp_register_style('espresso_custom_css', |
|
| 468 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->Registry->CFG->template_settings->custom_style_sheet, |
|
| 469 | + EVENT_ESPRESSO_VERSION); |
|
| 470 | + wp_enqueue_style('espresso_custom_css'); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + if (is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')) { |
|
| 474 | + wp_register_style('espresso_default', EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css', |
|
| 475 | + array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 476 | + } else { |
|
| 477 | + wp_register_style('espresso_default', EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
| 478 | + array('dashicons'), EVENT_ESPRESSO_VERSION); |
|
| 479 | + } |
|
| 480 | + wp_enqueue_style('espresso_default'); |
|
| 481 | + |
|
| 482 | + if (is_readable(get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'style.css')) { |
|
| 483 | + wp_register_style('espresso_style', |
|
| 484 | + get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 485 | + array('dashicons', 'espresso_default')); |
|
| 486 | + } else { |
|
| 487 | + wp_register_style('espresso_style', |
|
| 488 | + EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'style.css', |
|
| 489 | + array('dashicons', 'espresso_default')); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // js is turned ON by default, but prior to the wp_enqueue_scripts hook, can be turned OFF via: add_filter( 'FHEE_load_js', '__return_false' ); |
|
| 497 | + if (apply_filters('FHEE_load_js', true)) { |
|
| 498 | + |
|
| 499 | + wp_enqueue_script('jquery'); |
|
| 500 | + //let's make sure that all required scripts have been setup |
|
| 501 | + if (function_exists('wp_script_is') && ! wp_script_is('jquery')) { |
|
| 502 | + $msg = sprintf( |
|
| 503 | + __('%sJquery is not loaded!%sEvent Espresso is unable to load Jquery due to a conflict with your theme or another plugin.', |
|
| 504 | + 'event_espresso'), |
|
| 505 | + '<em><br />', |
|
| 506 | + '</em>' |
|
| 507 | + ); |
|
| 508 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 509 | + } |
|
| 510 | + // load core js |
|
| 511 | + wp_register_script('espresso_core', EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', array('jquery'), |
|
| 512 | + EVENT_ESPRESSO_VERSION, true); |
|
| 513 | + wp_enqueue_script('espresso_core'); |
|
| 514 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
| 515 | + |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + //qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 519 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
| 520 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + //accounting.js library |
|
| 525 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
| 526 | + if (apply_filters('FHEE_load_accounting_js', false)) { |
|
| 527 | + $acct_js = EE_THIRD_PARTY_URL . 'accounting/accounting.js'; |
|
| 528 | + wp_register_script('ee-accounting', EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
| 529 | + array('ee-accounting-core'), EVENT_ESPRESSO_VERSION, true); |
|
| 530 | + wp_register_script('ee-accounting-core', $acct_js, array('underscore'), '0.3.2', true); |
|
| 531 | + wp_enqueue_script('ee-accounting'); |
|
| 532 | + |
|
| 533 | + $currency_config = array( |
|
| 534 | + 'currency' => array( |
|
| 535 | + 'symbol' => $this->Registry->CFG->currency->sign, |
|
| 536 | + 'format' => array( |
|
| 537 | + 'pos' => $this->Registry->CFG->currency->sign_b4 ? '%s%v' : '%v%s', |
|
| 538 | + 'neg' => $this->Registry->CFG->currency->sign_b4 ? '- %s%v' : '- %v%s', |
|
| 539 | + 'zero' => $this->Registry->CFG->currency->sign_b4 ? '%s--' : '--%s', |
|
| 540 | + ), |
|
| 541 | + 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 542 | + 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 543 | + 'precision' => $this->Registry->CFG->currency->dec_plc, |
|
| 544 | + ), |
|
| 545 | + 'number' => array( |
|
| 546 | + 'precision' => 0, |
|
| 547 | + 'thousand' => $this->Registry->CFG->currency->thsnds, |
|
| 548 | + 'decimal' => $this->Registry->CFG->currency->dec_mrk, |
|
| 549 | + ), |
|
| 550 | + ); |
|
| 551 | + wp_localize_script('ee-accounting', 'EE_ACCOUNTING_CFG', $currency_config); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ( ! function_exists('wp_head')) { |
|
| 555 | + $msg = sprintf( |
|
| 556 | + __('%sMissing wp_head() function.%sThe WordPress function wp_head() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 557 | + 'event_espresso'), |
|
| 558 | + '<em><br />', |
|
| 559 | + '</em>' |
|
| 560 | + ); |
|
| 561 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 562 | + } |
|
| 563 | + if ( ! function_exists('wp_footer')) { |
|
| 564 | + $msg = sprintf( |
|
| 565 | + __('%sMissing wp_footer() function.%sThe WordPress function wp_footer() seems to be missing in your theme. Please contact the theme developer to make sure this is fixed before using Event Espresso.', |
|
| 566 | + 'event_espresso'), |
|
| 567 | + '<em><br />', |
|
| 568 | + '</em>' |
|
| 569 | + ); |
|
| 570 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + |
|
| 576 | + /** |
|
| 577 | + * header_meta_tag |
|
| 578 | + * |
|
| 579 | + * @access public |
|
| 580 | + * @return void |
|
| 581 | + */ |
|
| 582 | + public function header_meta_tag() |
|
| 583 | + { |
|
| 584 | + print( |
|
| 585 | + apply_filters( |
|
| 586 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
| 587 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
| 588 | + ); |
|
| 589 | + |
|
| 590 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
| 591 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
| 592 | + if ( |
|
| 593 | + is_tax('espresso_event_type') |
|
| 594 | + && get_option( 'blog_public' ) !== '0' |
|
| 595 | + ) { |
|
| 596 | + print( |
|
| 597 | + apply_filters( |
|
| 598 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
| 599 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
| 600 | + ) |
|
| 601 | + ); |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * wp_print_scripts |
|
| 609 | + * |
|
| 610 | + * @return void |
|
| 611 | + */ |
|
| 612 | + public function wp_print_scripts() |
|
| 613 | + { |
|
| 614 | + global $post; |
|
| 615 | + if (get_post_type() === 'espresso_events' && is_singular()) { |
|
| 616 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /*********************************************** THE_CONTENT FILTER HOOK ***********************************************/ |
|
| 623 | + |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * the_content |
|
| 628 | + * |
|
| 629 | + * @access public |
|
| 630 | + * @param $the_content |
|
| 631 | + * @return string |
|
| 632 | + */ |
|
| 633 | + // public function the_content( $the_content ) { |
|
| 634 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
| 635 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
| 636 | + // } |
|
| 637 | + // return $the_content; |
|
| 638 | + // } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * display_errors |
|
| 646 | + * |
|
| 647 | + * @access public |
|
| 648 | + * @return string |
|
| 649 | + */ |
|
| 650 | + public function display_errors() |
|
| 651 | + { |
|
| 652 | + static $shown_already = false; |
|
| 653 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
| 654 | + if ( |
|
| 655 | + ! $shown_already |
|
| 656 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
| 657 | + && is_main_query() |
|
| 658 | + && ! is_feed() |
|
| 659 | + && in_the_loop() |
|
| 660 | + && $this->Request_Handler->is_espresso_page() |
|
| 661 | + ) { |
|
| 662 | + echo EE_Error::get_notices(); |
|
| 663 | + $shown_already = true; |
|
| 664 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
| 665 | + } |
|
| 666 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /*********************************************** UTILITIES ***********************************************/ |
|
| 674 | + /** |
|
| 675 | + * template_include |
|
| 676 | + * |
|
| 677 | + * @access public |
|
| 678 | + * @param string $template_include_path |
|
| 679 | + * @return string |
|
| 680 | + */ |
|
| 681 | + public function template_include($template_include_path = null) |
|
| 682 | + { |
|
| 683 | + if ($this->Request_Handler->is_espresso_page()) { |
|
| 684 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
| 685 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
| 686 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
| 687 | + $this->_template = basename($this->_template_path); |
|
| 688 | + return $this->_template_path; |
|
| 689 | + } |
|
| 690 | + return $template_include_path; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * get_selected_template |
|
| 696 | + * |
|
| 697 | + * @access public |
|
| 698 | + * @param bool $with_path |
|
| 699 | + * @return string |
|
| 700 | + */ |
|
| 701 | + public function get_selected_template($with_path = false) |
|
| 702 | + { |
|
| 703 | + return $with_path ? $this->_template_path : $this->_template; |
|
| 704 | + } |
|
| 705 | 705 | |
| 706 | 706 | |
| 707 | 707 | } |
@@ -31,8 +31,8 @@ |
||
| 31 | 31 | "price": "<?php echo $ticket['price'] ?>", |
| 32 | 32 | "priceCurrency": "<?php echo $currency ?>" |
| 33 | 33 | }<?php if (is_array($event_tickets) && end($event_tickets) !== $ticket) { echo ','; } |
| 34 | - } |
|
| 35 | - ?> |
|
| 34 | + } |
|
| 35 | + ?> |
|
| 36 | 36 | ]<?php if ($venue_name) { ?>, |
| 37 | 37 | "location": { |
| 38 | 38 | "@type": "Place", |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * |
| 575 | 575 | * @param \EE_Datetime_Field $datetime_field |
| 576 | 576 | * @param bool $pretty |
| 577 | - * @param null $date_or_time |
|
| 577 | + * @param string|null $date_or_time |
|
| 578 | 578 | * @return void |
| 579 | 579 | * @throws \EE_Error |
| 580 | 580 | */ |
@@ -892,7 +892,7 @@ discard block |
||
| 892 | 892 | * |
| 893 | 893 | * @param null $field_to_order_by What field is being used as the reference point. |
| 894 | 894 | * @param array $query_params Any additional conditions on the query. |
| 895 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 895 | + * @param string $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 896 | 896 | * you can indicate just the columns you want returned |
| 897 | 897 | * @return array|EE_Base_Class |
| 898 | 898 | * @throws \EE_Error |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | * |
| 918 | 918 | * @param null $field_to_order_by What field is being used as the reference point. |
| 919 | 919 | * @param array $query_params Any additional conditions on the query. |
| 920 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 920 | + * @param string $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 921 | 921 | * you can indicate just the column you want returned |
| 922 | 922 | * @return array|EE_Base_Class |
| 923 | 923 | * @throws \EE_Error |
@@ -990,7 +990,7 @@ discard block |
||
| 990 | 990 | * This method simply returns the RAW unprocessed value for the given property in this class |
| 991 | 991 | * |
| 992 | 992 | * @param string $field_name A valid fieldname |
| 993 | - * @return mixed Whatever the raw value stored on the property is. |
|
| 993 | + * @return integer|null Whatever the raw value stored on the property is. |
|
| 994 | 994 | * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
| 995 | 995 | */ |
| 996 | 996 | public function get_raw($field_name) |
@@ -1256,7 +1256,7 @@ discard block |
||
| 1256 | 1256 | * sets the time on a datetime property |
| 1257 | 1257 | * |
| 1258 | 1258 | * @access protected |
| 1259 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1259 | + * @param string $time a valid time string for php datetime functions (or DateTime object) |
|
| 1260 | 1260 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
| 1261 | 1261 | * @throws \EE_Error |
| 1262 | 1262 | */ |
@@ -1271,7 +1271,7 @@ discard block |
||
| 1271 | 1271 | * sets the date on a datetime property |
| 1272 | 1272 | * |
| 1273 | 1273 | * @access protected |
| 1274 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1274 | + * @param string $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1275 | 1275 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
| 1276 | 1276 | * @throws \EE_Error |
| 1277 | 1277 | */ |
@@ -1329,6 +1329,7 @@ discard block |
||
| 1329 | 1329 | * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
| 1330 | 1330 | * @param string $prepend You can include something to prepend on the timestamp |
| 1331 | 1331 | * @param string $append You can include something to append on the timestamp |
| 1332 | + * @param string $args |
|
| 1332 | 1333 | * @throws EE_Error |
| 1333 | 1334 | * @return string timestamp |
| 1334 | 1335 | */ |
@@ -1699,7 +1700,7 @@ discard block |
||
| 1699 | 1700 | * |
| 1700 | 1701 | * @param array $props_n_values incoming array of properties and their values |
| 1701 | 1702 | * @param string $classname the classname of the child class |
| 1702 | - * @param null $timezone |
|
| 1703 | + * @param string|null $timezone |
|
| 1703 | 1704 | * @param array $date_formats incoming date_formats in an array where the first value is the |
| 1704 | 1705 | * date_format and the second value is the time format |
| 1705 | 1706 | * @return mixed (EE_Base_Class|bool) |
@@ -1777,7 +1778,7 @@ discard block |
||
| 1777 | 1778 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
| 1778 | 1779 | * |
| 1779 | 1780 | * @param string $model_classname |
| 1780 | - * @param null $timezone |
|
| 1781 | + * @param string|null $timezone |
|
| 1781 | 1782 | * @return EEM_Base |
| 1782 | 1783 | */ |
| 1783 | 1784 | protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
| 5 | 5 | |
@@ -25,2652 +25,2652 @@ discard block |
||
| 25 | 25 | abstract class EE_Base_Class |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * This is an array of the original properties and values provided during construction |
|
| 30 | - * of this model object. (keys are model field names, values are their values). |
|
| 31 | - * This list is important to remember so that when we are merging data from the db, we know |
|
| 32 | - * which values to override and which to not override. |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $_props_n_values_provided_in_constructor; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Timezone |
|
| 40 | - * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 41 | - * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 42 | - * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 43 | - * access to it. |
|
| 44 | - * |
|
| 45 | - * @var string |
|
| 46 | - */ |
|
| 47 | - protected $_timezone; |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * date format |
|
| 53 | - * pattern or format for displaying dates |
|
| 54 | - * |
|
| 55 | - * @var string $_dt_frmt |
|
| 56 | - */ |
|
| 57 | - protected $_dt_frmt; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * time format |
|
| 63 | - * pattern or format for displaying time |
|
| 64 | - * |
|
| 65 | - * @var string $_tm_frmt |
|
| 66 | - */ |
|
| 67 | - protected $_tm_frmt; |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 73 | - * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 74 | - * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 75 | - * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 76 | - * |
|
| 77 | - * @var array |
|
| 78 | - */ |
|
| 79 | - protected $_cached_properties = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 83 | - * single |
|
| 84 | - * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 85 | - * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 86 | - * all others have an array) |
|
| 87 | - * |
|
| 88 | - * @var array |
|
| 89 | - */ |
|
| 90 | - protected $_model_relations = array(); |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 94 | - * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 95 | - * |
|
| 96 | - * @var array |
|
| 97 | - */ |
|
| 98 | - protected $_fields = array(); |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 102 | - * For example, we might create model objects intended to only be used for the duration |
|
| 103 | - * of this request and to be thrown away, and if they were accidentally saved |
|
| 104 | - * it would be a bug. |
|
| 105 | - */ |
|
| 106 | - protected $_allow_persist = true; |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 112 | - * play nice |
|
| 113 | - * |
|
| 114 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 115 | - * layer of the model's _fields array, (eg, EVT_ID, |
|
| 116 | - * TXN_amount, QST_name, etc) and values are their values |
|
| 117 | - * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 118 | - * corresponding db model or not. |
|
| 119 | - * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 120 | - * be in when instantiating a EE_Base_Class object. |
|
| 121 | - * @param array $date_formats An array of date formats to set on construct where first |
|
| 122 | - * value is the date_format and second value is the time |
|
| 123 | - * format. |
|
| 124 | - * @throws EE_Error |
|
| 125 | - */ |
|
| 126 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
| 127 | - { |
|
| 128 | - $className = get_class($this); |
|
| 129 | - do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 130 | - $model = $this->get_model(); |
|
| 131 | - $model_fields = $model->field_settings(false); |
|
| 132 | - // ensure $fieldValues is an array |
|
| 133 | - $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 134 | - // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 135 | - // verify client code has not passed any invalid field names |
|
| 136 | - foreach ($fieldValues as $field_name => $field_value) { |
|
| 137 | - if ( ! isset($model_fields[$field_name])) { |
|
| 138 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 139 | - "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 143 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 144 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 145 | - list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 146 | - } else { |
|
| 147 | - //set default formats for date and time |
|
| 148 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 149 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 150 | - } |
|
| 151 | - //if db model is instantiating |
|
| 152 | - if ($bydb) { |
|
| 153 | - //client code has indicated these field values are from the database |
|
| 154 | - foreach ($model_fields as $fieldName => $field) { |
|
| 155 | - $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 156 | - } |
|
| 157 | - } else { |
|
| 158 | - //we're constructing a brand |
|
| 159 | - //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 160 | - foreach ($model_fields as $fieldName => $field) { |
|
| 161 | - $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - //remember what values were passed to this constructor |
|
| 165 | - $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 166 | - //remember in entity mapper |
|
| 167 | - if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 168 | - $model->add_to_entity_map($this); |
|
| 169 | - } |
|
| 170 | - //setup all the relations |
|
| 171 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 172 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 173 | - $this->_model_relations[$relation_name] = null; |
|
| 174 | - } else { |
|
| 175 | - $this->_model_relations[$relation_name] = array(); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - /** |
|
| 179 | - * Action done at the end of each model object construction |
|
| 180 | - * |
|
| 181 | - * @param EE_Base_Class $this the model object just created |
|
| 182 | - */ |
|
| 183 | - do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 190 | - * |
|
| 191 | - * @return boolean |
|
| 192 | - */ |
|
| 193 | - public function allow_persist() |
|
| 194 | - { |
|
| 195 | - return $this->_allow_persist; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 202 | - * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 203 | - * you got new information that somehow made you change your mind. |
|
| 204 | - * |
|
| 205 | - * @param boolean $allow_persist |
|
| 206 | - * @return boolean |
|
| 207 | - */ |
|
| 208 | - public function set_allow_persist($allow_persist) |
|
| 209 | - { |
|
| 210 | - return $this->_allow_persist = $allow_persist; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Gets the field's original value when this object was constructed during this request. |
|
| 217 | - * This can be helpful when determining if a model object has changed or not |
|
| 218 | - * |
|
| 219 | - * @param string $field_name |
|
| 220 | - * @return mixed|null |
|
| 221 | - * @throws \EE_Error |
|
| 222 | - */ |
|
| 223 | - public function get_original($field_name) |
|
| 224 | - { |
|
| 225 | - if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 226 | - && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 227 | - ) { |
|
| 228 | - return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 229 | - } else { |
|
| 230 | - return null; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param EE_Base_Class $obj |
|
| 238 | - * @return string |
|
| 239 | - */ |
|
| 240 | - public function get_class($obj) |
|
| 241 | - { |
|
| 242 | - return get_class($obj); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Overrides parent because parent expects old models. |
|
| 249 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 250 | - * |
|
| 251 | - * @param string $field_name |
|
| 252 | - * @param mixed $field_value |
|
| 253 | - * @param bool $use_default |
|
| 254 | - * @throws \EE_Error |
|
| 255 | - */ |
|
| 256 | - public function set($field_name, $field_value, $use_default = false) |
|
| 257 | - { |
|
| 258 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 259 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 260 | - // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 261 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 262 | - $field_obj->set_timezone($this->_timezone); |
|
| 263 | - $field_obj->set_date_format($this->_dt_frmt); |
|
| 264 | - $field_obj->set_time_format($this->_tm_frmt); |
|
| 265 | - } |
|
| 266 | - $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 267 | - //should the value be null? |
|
| 268 | - if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 269 | - $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 270 | - /** |
|
| 271 | - * To save having to refactor all the models, if a default value is used for a |
|
| 272 | - * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 273 | - * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 274 | - * object. |
|
| 275 | - * |
|
| 276 | - * @since 4.6.10+ |
|
| 277 | - */ |
|
| 278 | - if ( |
|
| 279 | - $field_obj instanceof EE_Datetime_Field |
|
| 280 | - && $this->_fields[$field_name] !== null |
|
| 281 | - && ! $this->_fields[$field_name] instanceof DateTime |
|
| 282 | - ) { |
|
| 283 | - empty($this->_fields[$field_name]) |
|
| 284 | - ? $this->set($field_name, time()) |
|
| 285 | - : $this->set($field_name, $this->_fields[$field_name]); |
|
| 286 | - } |
|
| 287 | - } else { |
|
| 288 | - $this->_fields[$field_name] = $holder_of_value; |
|
| 289 | - } |
|
| 290 | - //if we're not in the constructor... |
|
| 291 | - //now check if what we set was a primary key |
|
| 292 | - if ( |
|
| 293 | - //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 294 | - $this->_props_n_values_provided_in_constructor |
|
| 295 | - && $field_value |
|
| 296 | - && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 297 | - ) { |
|
| 298 | - //if so, we want all this object's fields to be filled either with |
|
| 299 | - //what we've explicitly set on this model |
|
| 300 | - //or what we have in the db |
|
| 301 | - // echo "setting primary key!"; |
|
| 302 | - $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 303 | - $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 304 | - foreach ($fields_on_model as $field_obj) { |
|
| 305 | - if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 306 | - && $field_obj->get_name() !== $field_name |
|
| 307 | - ) { |
|
| 308 | - $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - //oh this model object has an ID? well make sure its in the entity mapper |
|
| 312 | - $this->get_model()->add_to_entity_map($this); |
|
| 313 | - } |
|
| 314 | - //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 315 | - $this->_clear_cached_property($field_name); |
|
| 316 | - } else { |
|
| 317 | - throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 318 | - "event_espresso"), $field_name)); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * This sets the field value on the db column if it exists for the given $column_name or |
|
| 326 | - * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 327 | - * |
|
| 328 | - * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 329 | - * @param string $field_name Must be the exact column name. |
|
| 330 | - * @param mixed $field_value The value to set. |
|
| 331 | - * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 332 | - * @throws \EE_Error |
|
| 333 | - */ |
|
| 334 | - public function set_field_or_extra_meta($field_name, $field_value) |
|
| 335 | - { |
|
| 336 | - if ($this->get_model()->has_field($field_name)) { |
|
| 337 | - $this->set($field_name, $field_value); |
|
| 338 | - return true; |
|
| 339 | - } else { |
|
| 340 | - //ensure this object is saved first so that extra meta can be properly related. |
|
| 341 | - $this->save(); |
|
| 342 | - return $this->update_extra_meta($field_name, $field_value); |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * This retrieves the value of the db column set on this class or if that's not present |
|
| 350 | - * it will attempt to retrieve from extra_meta if found. |
|
| 351 | - * Example Usage: |
|
| 352 | - * Via EE_Message child class: |
|
| 353 | - * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 354 | - * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 355 | - * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 356 | - * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 357 | - * value for those extra fields dynamically via the EE_message object. |
|
| 358 | - * |
|
| 359 | - * @param string $field_name expecting the fully qualified field name. |
|
| 360 | - * @return mixed|null value for the field if found. null if not found. |
|
| 361 | - * @throws \EE_Error |
|
| 362 | - */ |
|
| 363 | - public function get_field_or_extra_meta($field_name) |
|
| 364 | - { |
|
| 365 | - if ($this->get_model()->has_field($field_name)) { |
|
| 366 | - $column_value = $this->get($field_name); |
|
| 367 | - } else { |
|
| 368 | - //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 369 | - $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 370 | - } |
|
| 371 | - return $column_value; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 378 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 379 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 380 | - * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 381 | - * |
|
| 382 | - * @access public |
|
| 383 | - * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 384 | - * @return void |
|
| 385 | - * @throws \EE_Error |
|
| 386 | - */ |
|
| 387 | - public function set_timezone($timezone = '') |
|
| 388 | - { |
|
| 389 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 390 | - //make sure we clear all cached properties because they won't be relevant now |
|
| 391 | - $this->_clear_cached_properties(); |
|
| 392 | - //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 393 | - $model_fields = $this->get_model()->field_settings(false); |
|
| 394 | - foreach ($model_fields as $field_name => $field_obj) { |
|
| 395 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 396 | - $field_obj->set_timezone($this->_timezone); |
|
| 397 | - if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 398 | - $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * This just returns whatever is set for the current timezone. |
|
| 408 | - * |
|
| 409 | - * @access public |
|
| 410 | - * @return string timezone string |
|
| 411 | - */ |
|
| 412 | - public function get_timezone() |
|
| 413 | - { |
|
| 414 | - return $this->_timezone; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 421 | - * internally instead of wp set date format options |
|
| 422 | - * |
|
| 423 | - * @since 4.6 |
|
| 424 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 425 | - */ |
|
| 426 | - public function set_date_format($format) |
|
| 427 | - { |
|
| 428 | - $this->_dt_frmt = $format; |
|
| 429 | - //clear cached_properties because they won't be relevant now. |
|
| 430 | - $this->_clear_cached_properties(); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 437 | - * class internally instead of wp set time format options. |
|
| 438 | - * |
|
| 439 | - * @since 4.6 |
|
| 440 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 441 | - */ |
|
| 442 | - public function set_time_format($format) |
|
| 443 | - { |
|
| 444 | - $this->_tm_frmt = $format; |
|
| 445 | - //clear cached_properties because they won't be relevant now. |
|
| 446 | - $this->_clear_cached_properties(); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * This returns the current internal set format for the date and time formats. |
|
| 453 | - * |
|
| 454 | - * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 455 | - * where the first value is the date format and the second value is the time format. |
|
| 456 | - * @return mixed string|array |
|
| 457 | - */ |
|
| 458 | - public function get_format($full = true) |
|
| 459 | - { |
|
| 460 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * cache |
|
| 467 | - * stores the passed model object on the current model object. |
|
| 468 | - * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 469 | - * |
|
| 470 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 471 | - * 'Registration' associated with this model object |
|
| 472 | - * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 473 | - * that could be a payment or a registration) |
|
| 474 | - * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 475 | - * items which will be stored in an array on this object |
|
| 476 | - * @throws EE_Error |
|
| 477 | - * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 478 | - * related thing, no array) |
|
| 479 | - */ |
|
| 480 | - public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 481 | - { |
|
| 482 | - // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 483 | - if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 484 | - return false; |
|
| 485 | - } |
|
| 486 | - // also get "how" the object is related, or throw an error |
|
| 487 | - if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 488 | - throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 489 | - $relationName, get_class($this))); |
|
| 490 | - } |
|
| 491 | - // how many things are related ? |
|
| 492 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 493 | - // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
|
| 494 | - // so for these model objects just set it to be cached |
|
| 495 | - $this->_model_relations[$relationName] = $object_to_cache; |
|
| 496 | - $return = true; |
|
| 497 | - } else { |
|
| 498 | - // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
|
| 499 | - // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 500 | - if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 501 | - // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 502 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 503 | - ? array($this->_model_relations[$relationName]) : array(); |
|
| 504 | - } |
|
| 505 | - // first check for a cache_id which is normally empty |
|
| 506 | - if ( ! empty($cache_id)) { |
|
| 507 | - // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
|
| 508 | - $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 509 | - $return = $cache_id; |
|
| 510 | - } elseif ($object_to_cache->ID()) { |
|
| 511 | - // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 512 | - $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 513 | - $return = $object_to_cache->ID(); |
|
| 514 | - } else { |
|
| 515 | - // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 516 | - $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 517 | - // move the internal pointer to the end of the array |
|
| 518 | - end($this->_model_relations[$relationName]); |
|
| 519 | - // and grab the key so that we can return it |
|
| 520 | - $return = key($this->_model_relations[$relationName]); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - return $return; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * For adding an item to the cached_properties property. |
|
| 530 | - * |
|
| 531 | - * @access protected |
|
| 532 | - * @param string $fieldname the property item the corresponding value is for. |
|
| 533 | - * @param mixed $value The value we are caching. |
|
| 534 | - * @param string|null $cache_type |
|
| 535 | - * @return void |
|
| 536 | - * @throws \EE_Error |
|
| 537 | - */ |
|
| 538 | - protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 539 | - { |
|
| 540 | - //first make sure this property exists |
|
| 541 | - $this->get_model()->field_settings_for($fieldname); |
|
| 542 | - $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 543 | - $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 550 | - * This also SETS the cache if we return the actual property! |
|
| 551 | - * |
|
| 552 | - * @param string $fieldname the name of the property we're trying to retrieve |
|
| 553 | - * @param bool $pretty |
|
| 554 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 555 | - * (in cases where the same property may be used for different outputs |
|
| 556 | - * - i.e. datetime, money etc.) |
|
| 557 | - * It can also accept certain pre-defined "schema" strings |
|
| 558 | - * to define how to output the property. |
|
| 559 | - * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 560 | - * @return mixed whatever the value for the property is we're retrieving |
|
| 561 | - * @throws \EE_Error |
|
| 562 | - */ |
|
| 563 | - protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 564 | - { |
|
| 565 | - //verify the field exists |
|
| 566 | - $this->get_model()->field_settings_for($fieldname); |
|
| 567 | - $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 568 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 569 | - if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 570 | - return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 571 | - } |
|
| 572 | - $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 573 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 574 | - // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 575 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 576 | - $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 577 | - } |
|
| 578 | - if ( ! isset($this->_fields[$fieldname])) { |
|
| 579 | - $this->_fields[$fieldname] = null; |
|
| 580 | - } |
|
| 581 | - $value = $pretty |
|
| 582 | - ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 583 | - : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 584 | - $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 585 | - return $value; |
|
| 586 | - } |
|
| 587 | - return null; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 594 | - * |
|
| 595 | - * @param \EE_Datetime_Field $datetime_field |
|
| 596 | - * @param bool $pretty |
|
| 597 | - * @param null $date_or_time |
|
| 598 | - * @return void |
|
| 599 | - * @throws \EE_Error |
|
| 600 | - */ |
|
| 601 | - protected function _prepare_datetime_field( |
|
| 602 | - EE_Datetime_Field $datetime_field, |
|
| 603 | - $pretty = false, |
|
| 604 | - $date_or_time = null |
|
| 605 | - ) { |
|
| 606 | - $datetime_field->set_timezone($this->_timezone); |
|
| 607 | - $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 608 | - $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 609 | - //set the output returned |
|
| 610 | - switch ($date_or_time) { |
|
| 611 | - case 'D' : |
|
| 612 | - $datetime_field->set_date_time_output('date'); |
|
| 613 | - break; |
|
| 614 | - case 'T' : |
|
| 615 | - $datetime_field->set_date_time_output('time'); |
|
| 616 | - break; |
|
| 617 | - default : |
|
| 618 | - $datetime_field->set_date_time_output(); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * This just takes care of clearing out the cached_properties |
|
| 626 | - * |
|
| 627 | - * @return void |
|
| 628 | - */ |
|
| 629 | - protected function _clear_cached_properties() |
|
| 630 | - { |
|
| 631 | - $this->_cached_properties = array(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - |
|
| 635 | - |
|
| 636 | - /** |
|
| 637 | - * This just clears out ONE property if it exists in the cache |
|
| 638 | - * |
|
| 639 | - * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 640 | - * @return void |
|
| 641 | - */ |
|
| 642 | - protected function _clear_cached_property($property_name) |
|
| 643 | - { |
|
| 644 | - if (isset($this->_cached_properties[$property_name])) { |
|
| 645 | - unset($this->_cached_properties[$property_name]); |
|
| 646 | - } |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * Ensures that this related thing is a model object. |
|
| 653 | - * |
|
| 654 | - * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 655 | - * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 656 | - * @return EE_Base_Class |
|
| 657 | - * @throws \EE_Error |
|
| 658 | - */ |
|
| 659 | - protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 660 | - { |
|
| 661 | - $other_model_instance = self::_get_model_instance_with_name( |
|
| 662 | - self::_get_model_classname($model_name), |
|
| 663 | - $this->_timezone |
|
| 664 | - ); |
|
| 665 | - return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 672 | - * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 673 | - * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 674 | - * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 675 | - * |
|
| 676 | - * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 677 | - * Eg 'Registration' |
|
| 678 | - * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 679 | - * if you intend to use $clear_all = TRUE, or the relation only |
|
| 680 | - * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 681 | - * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 682 | - * this is HasMany or HABTM. |
|
| 683 | - * @throws EE_Error |
|
| 684 | - * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 685 | - * relation from all |
|
| 686 | - */ |
|
| 687 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 688 | - { |
|
| 689 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 690 | - $index_in_cache = ''; |
|
| 691 | - if ( ! $relationship_to_model) { |
|
| 692 | - throw new EE_Error( |
|
| 693 | - sprintf( |
|
| 694 | - __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 695 | - $relationName, |
|
| 696 | - get_class($this) |
|
| 697 | - ) |
|
| 698 | - ); |
|
| 699 | - } |
|
| 700 | - if ($clear_all) { |
|
| 701 | - $obj_removed = true; |
|
| 702 | - $this->_model_relations[$relationName] = null; |
|
| 703 | - } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 704 | - $obj_removed = $this->_model_relations[$relationName]; |
|
| 705 | - $this->_model_relations[$relationName] = null; |
|
| 706 | - } else { |
|
| 707 | - if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 708 | - && $object_to_remove_or_index_into_array->ID() |
|
| 709 | - ) { |
|
| 710 | - $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 711 | - if (is_array($this->_model_relations[$relationName]) |
|
| 712 | - && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 713 | - ) { |
|
| 714 | - $index_found_at = null; |
|
| 715 | - //find this object in the array even though it has a different key |
|
| 716 | - foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 717 | - if ( |
|
| 718 | - $obj instanceof EE_Base_Class |
|
| 719 | - && ( |
|
| 720 | - $obj == $object_to_remove_or_index_into_array |
|
| 721 | - || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 722 | - ) |
|
| 723 | - ) { |
|
| 724 | - $index_found_at = $index; |
|
| 725 | - break; |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - if ($index_found_at) { |
|
| 729 | - $index_in_cache = $index_found_at; |
|
| 730 | - } else { |
|
| 731 | - //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 732 | - //if it wasn't in it to begin with. So we're done |
|
| 733 | - return $object_to_remove_or_index_into_array; |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 737 | - //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 738 | - foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 739 | - if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 740 | - $index_in_cache = $index; |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - } else { |
|
| 744 | - $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 745 | - } |
|
| 746 | - //supposedly we've found it. But it could just be that the client code |
|
| 747 | - //provided a bad index/object |
|
| 748 | - if ( |
|
| 749 | - isset( |
|
| 750 | - $this->_model_relations[$relationName], |
|
| 751 | - $this->_model_relations[$relationName][$index_in_cache] |
|
| 752 | - ) |
|
| 753 | - ) { |
|
| 754 | - $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 755 | - unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 756 | - } else { |
|
| 757 | - //that thing was never cached anyways. |
|
| 758 | - $obj_removed = null; |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $obj_removed; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * update_cache_after_object_save |
|
| 768 | - * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 769 | - * obtained after being saved to the db |
|
| 770 | - * |
|
| 771 | - * @param string $relationName - the type of object that is cached |
|
| 772 | - * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 773 | - * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 774 | - * @return boolean TRUE on success, FALSE on fail |
|
| 775 | - * @throws \EE_Error |
|
| 776 | - */ |
|
| 777 | - public function update_cache_after_object_save( |
|
| 778 | - $relationName, |
|
| 779 | - EE_Base_Class $newly_saved_object, |
|
| 780 | - $current_cache_id = '' |
|
| 781 | - ) { |
|
| 782 | - // verify that incoming object is of the correct type |
|
| 783 | - $obj_class = 'EE_' . $relationName; |
|
| 784 | - if ($newly_saved_object instanceof $obj_class) { |
|
| 785 | - /* @type EE_Base_Class $newly_saved_object */ |
|
| 786 | - // now get the type of relation |
|
| 787 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 788 | - // if this is a 1:1 relationship |
|
| 789 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 790 | - // then just replace the cached object with the newly saved object |
|
| 791 | - $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 792 | - return true; |
|
| 793 | - // or if it's some kind of sordid feral polyamorous relationship... |
|
| 794 | - } elseif (is_array($this->_model_relations[$relationName]) |
|
| 795 | - && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 796 | - ) { |
|
| 797 | - // then remove the current cached item |
|
| 798 | - unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 799 | - // and cache the newly saved object using it's new ID |
|
| 800 | - $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 801 | - return true; |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 811 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 812 | - * |
|
| 813 | - * @param string $relationName |
|
| 814 | - * @return EE_Base_Class |
|
| 815 | - */ |
|
| 816 | - public function get_one_from_cache($relationName) |
|
| 817 | - { |
|
| 818 | - $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 819 | - : null; |
|
| 820 | - if (is_array($cached_array_or_object)) { |
|
| 821 | - return array_shift($cached_array_or_object); |
|
| 822 | - } else { |
|
| 823 | - return $cached_array_or_object; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 831 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 832 | - * |
|
| 833 | - * @param string $relationName |
|
| 834 | - * @throws \EE_Error |
|
| 835 | - * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 836 | - */ |
|
| 837 | - public function get_all_from_cache($relationName) |
|
| 838 | - { |
|
| 839 | - $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 840 | - // if the result is not an array, but exists, make it an array |
|
| 841 | - $objects = is_array($objects) ? $objects : array($objects); |
|
| 842 | - //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 843 | - //basically, if this model object was stored in the session, and these cached model objects |
|
| 844 | - //already have IDs, let's make sure they're in their model's entity mapper |
|
| 845 | - //otherwise we will have duplicates next time we call |
|
| 846 | - // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 847 | - $model = EE_Registry::instance()->load_model($relationName); |
|
| 848 | - foreach ($objects as $model_object) { |
|
| 849 | - if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 850 | - //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 851 | - if ($model_object->ID()) { |
|
| 852 | - $model->add_to_entity_map($model_object); |
|
| 853 | - } |
|
| 854 | - } else { |
|
| 855 | - throw new EE_Error( |
|
| 856 | - sprintf( |
|
| 857 | - __( |
|
| 858 | - 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 859 | - 'event_espresso' |
|
| 860 | - ), |
|
| 861 | - $relationName, |
|
| 862 | - gettype($model_object) |
|
| 863 | - ) |
|
| 864 | - ); |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - return $objects; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 874 | - * matching the given query conditions. |
|
| 875 | - * |
|
| 876 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 877 | - * @param int $limit How many objects to return. |
|
| 878 | - * @param array $query_params Any additional conditions on the query. |
|
| 879 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 880 | - * you can indicate just the columns you want returned |
|
| 881 | - * @return array|EE_Base_Class[] |
|
| 882 | - * @throws \EE_Error |
|
| 883 | - */ |
|
| 884 | - public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 885 | - { |
|
| 886 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 887 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 888 | - : $field_to_order_by; |
|
| 889 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 890 | - if (empty($field) || empty($current_value)) { |
|
| 891 | - return array(); |
|
| 892 | - } |
|
| 893 | - return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /** |
|
| 899 | - * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 900 | - * matching the given query conditions. |
|
| 901 | - * |
|
| 902 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 903 | - * @param int $limit How many objects to return. |
|
| 904 | - * @param array $query_params Any additional conditions on the query. |
|
| 905 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 906 | - * you can indicate just the columns you want returned |
|
| 907 | - * @return array|EE_Base_Class[] |
|
| 908 | - * @throws \EE_Error |
|
| 909 | - */ |
|
| 910 | - public function previous_x( |
|
| 911 | - $field_to_order_by = null, |
|
| 912 | - $limit = 1, |
|
| 913 | - $query_params = array(), |
|
| 914 | - $columns_to_select = null |
|
| 915 | - ) { |
|
| 916 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 917 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 918 | - : $field_to_order_by; |
|
| 919 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 920 | - if (empty($field) || empty($current_value)) { |
|
| 921 | - return array(); |
|
| 922 | - } |
|
| 923 | - return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - /** |
|
| 929 | - * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 930 | - * matching the given query conditions. |
|
| 931 | - * |
|
| 932 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 933 | - * @param array $query_params Any additional conditions on the query. |
|
| 934 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 935 | - * you can indicate just the columns you want returned |
|
| 936 | - * @return array|EE_Base_Class |
|
| 937 | - * @throws \EE_Error |
|
| 938 | - */ |
|
| 939 | - public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 940 | - { |
|
| 941 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 942 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 943 | - : $field_to_order_by; |
|
| 944 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 945 | - if (empty($field) || empty($current_value)) { |
|
| 946 | - return array(); |
|
| 947 | - } |
|
| 948 | - return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 955 | - * matching the given query conditions. |
|
| 956 | - * |
|
| 957 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 958 | - * @param array $query_params Any additional conditions on the query. |
|
| 959 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 960 | - * you can indicate just the column you want returned |
|
| 961 | - * @return array|EE_Base_Class |
|
| 962 | - * @throws \EE_Error |
|
| 963 | - */ |
|
| 964 | - public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 965 | - { |
|
| 966 | - $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 967 | - ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 968 | - : $field_to_order_by; |
|
| 969 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 970 | - if (empty($field) || empty($current_value)) { |
|
| 971 | - return array(); |
|
| 972 | - } |
|
| 973 | - return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 974 | - } |
|
| 975 | - |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - /** |
|
| 979 | - * Overrides parent because parent expects old models. |
|
| 980 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 981 | - * |
|
| 982 | - * @param string $field_name |
|
| 983 | - * @param mixed $field_value_from_db |
|
| 984 | - * @throws \EE_Error |
|
| 985 | - */ |
|
| 986 | - public function set_from_db($field_name, $field_value_from_db) |
|
| 987 | - { |
|
| 988 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 989 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 990 | - //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 991 | - //eg, a CPT model object could have an entry in the posts table, but no |
|
| 992 | - //entry in the meta table. Meaning that all its columns in the meta table |
|
| 993 | - //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 994 | - if ($field_value_from_db === null) { |
|
| 995 | - if ($field_obj->is_nullable()) { |
|
| 996 | - //if the field allows nulls, then let it be null |
|
| 997 | - $field_value = null; |
|
| 998 | - } else { |
|
| 999 | - $field_value = $field_obj->get_default_value(); |
|
| 1000 | - } |
|
| 1001 | - } else { |
|
| 1002 | - $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1003 | - } |
|
| 1004 | - $this->_fields[$field_name] = $field_value; |
|
| 1005 | - $this->_clear_cached_property($field_name); |
|
| 1006 | - } |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * verifies that the specified field is of the correct type |
|
| 1013 | - * |
|
| 1014 | - * @param string $field_name |
|
| 1015 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1016 | - * (in cases where the same property may be used for different outputs |
|
| 1017 | - * - i.e. datetime, money etc.) |
|
| 1018 | - * @return mixed |
|
| 1019 | - * @throws \EE_Error |
|
| 1020 | - */ |
|
| 1021 | - public function get($field_name, $extra_cache_ref = null) |
|
| 1022 | - { |
|
| 1023 | - return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1030 | - * |
|
| 1031 | - * @param string $field_name A valid fieldname |
|
| 1032 | - * @return mixed Whatever the raw value stored on the property is. |
|
| 1033 | - * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1034 | - */ |
|
| 1035 | - public function get_raw($field_name) |
|
| 1036 | - { |
|
| 1037 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1038 | - return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
| 1039 | - ? $this->_fields[$field_name]->format('U') |
|
| 1040 | - : $this->_fields[$field_name]; |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * This is used to return the internal DateTime object used for a field that is a |
|
| 1047 | - * EE_Datetime_Field. |
|
| 1048 | - * |
|
| 1049 | - * @param string $field_name The field name retrieving the DateTime object. |
|
| 1050 | - * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1051 | - * @throws \EE_Error |
|
| 1052 | - * an error is set and false returned. If the field IS an |
|
| 1053 | - * EE_Datetime_Field and but the field value is null, then |
|
| 1054 | - * just null is returned (because that indicates that likely |
|
| 1055 | - * this field is nullable). |
|
| 1056 | - */ |
|
| 1057 | - public function get_DateTime_object($field_name) |
|
| 1058 | - { |
|
| 1059 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1060 | - if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1061 | - EE_Error::add_error( |
|
| 1062 | - sprintf( |
|
| 1063 | - __( |
|
| 1064 | - 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1065 | - 'event_espresso' |
|
| 1066 | - ), |
|
| 1067 | - $field_name |
|
| 1068 | - ), |
|
| 1069 | - __FILE__, |
|
| 1070 | - __FUNCTION__, |
|
| 1071 | - __LINE__ |
|
| 1072 | - ); |
|
| 1073 | - return false; |
|
| 1074 | - } |
|
| 1075 | - return $this->_fields[$field_name]; |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - |
|
| 1079 | - |
|
| 1080 | - /** |
|
| 1081 | - * To be used in template to immediately echo out the value, and format it for output. |
|
| 1082 | - * Eg, should call stripslashes and whatnot before echoing |
|
| 1083 | - * |
|
| 1084 | - * @param string $field_name the name of the field as it appears in the DB |
|
| 1085 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1086 | - * (in cases where the same property may be used for different outputs |
|
| 1087 | - * - i.e. datetime, money etc.) |
|
| 1088 | - * @return void |
|
| 1089 | - * @throws \EE_Error |
|
| 1090 | - */ |
|
| 1091 | - public function e($field_name, $extra_cache_ref = null) |
|
| 1092 | - { |
|
| 1093 | - echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - |
|
| 1097 | - |
|
| 1098 | - /** |
|
| 1099 | - * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1100 | - * can be easily used as the value of form input. |
|
| 1101 | - * |
|
| 1102 | - * @param string $field_name |
|
| 1103 | - * @return void |
|
| 1104 | - * @throws \EE_Error |
|
| 1105 | - */ |
|
| 1106 | - public function f($field_name) |
|
| 1107 | - { |
|
| 1108 | - $this->e($field_name, 'form_input'); |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - |
|
| 1113 | - /** |
|
| 1114 | - * @param string $field_name |
|
| 1115 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1116 | - * (in cases where the same property may be used for different outputs |
|
| 1117 | - * - i.e. datetime, money etc.) |
|
| 1118 | - * @return mixed |
|
| 1119 | - * @throws \EE_Error |
|
| 1120 | - */ |
|
| 1121 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1122 | - { |
|
| 1123 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - /** |
|
| 1129 | - * This simply returns the datetime for the given field name |
|
| 1130 | - * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1131 | - * (and the equivalent e_date, e_time, e_datetime). |
|
| 1132 | - * |
|
| 1133 | - * @access protected |
|
| 1134 | - * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1135 | - * @param string $dt_frmt valid datetime format used for date |
|
| 1136 | - * (if '' then we just use the default on the field, |
|
| 1137 | - * if NULL we use the last-used format) |
|
| 1138 | - * @param string $tm_frmt Same as above except this is for time format |
|
| 1139 | - * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1140 | - * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1141 | - * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1142 | - * if field is not a valid dtt field, or void if echoing |
|
| 1143 | - * @throws \EE_Error |
|
| 1144 | - */ |
|
| 1145 | - protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1146 | - { |
|
| 1147 | - // clear cached property |
|
| 1148 | - $this->_clear_cached_property($field_name); |
|
| 1149 | - //reset format properties because they are used in get() |
|
| 1150 | - $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1151 | - $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1152 | - if ($echo) { |
|
| 1153 | - $this->e($field_name, $date_or_time); |
|
| 1154 | - return ''; |
|
| 1155 | - } |
|
| 1156 | - return $this->get($field_name, $date_or_time); |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - |
|
| 1161 | - /** |
|
| 1162 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1163 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1164 | - * other echoes the pretty value for dtt) |
|
| 1165 | - * |
|
| 1166 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1167 | - * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1168 | - * @return string datetime value formatted |
|
| 1169 | - * @throws \EE_Error |
|
| 1170 | - */ |
|
| 1171 | - public function get_date($field_name, $format = '') |
|
| 1172 | - { |
|
| 1173 | - return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - |
|
| 1178 | - /** |
|
| 1179 | - * @param $field_name |
|
| 1180 | - * @param string $format |
|
| 1181 | - * @throws \EE_Error |
|
| 1182 | - */ |
|
| 1183 | - public function e_date($field_name, $format = '') |
|
| 1184 | - { |
|
| 1185 | - $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - |
|
| 1189 | - |
|
| 1190 | - /** |
|
| 1191 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1192 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1193 | - * other echoes the pretty value for dtt) |
|
| 1194 | - * |
|
| 1195 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1196 | - * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1197 | - * @return string datetime value formatted |
|
| 1198 | - * @throws \EE_Error |
|
| 1199 | - */ |
|
| 1200 | - public function get_time($field_name, $format = '') |
|
| 1201 | - { |
|
| 1202 | - return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - |
|
| 1207 | - /** |
|
| 1208 | - * @param $field_name |
|
| 1209 | - * @param string $format |
|
| 1210 | - * @throws \EE_Error |
|
| 1211 | - */ |
|
| 1212 | - public function e_time($field_name, $format = '') |
|
| 1213 | - { |
|
| 1214 | - $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - |
|
| 1218 | - |
|
| 1219 | - /** |
|
| 1220 | - * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1221 | - * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1222 | - * other echoes the pretty value for dtt) |
|
| 1223 | - * |
|
| 1224 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1225 | - * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1226 | - * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1227 | - * @return string datetime value formatted |
|
| 1228 | - * @throws \EE_Error |
|
| 1229 | - */ |
|
| 1230 | - public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1231 | - { |
|
| 1232 | - return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * @param string $field_name |
|
| 1239 | - * @param string $dt_frmt |
|
| 1240 | - * @param string $tm_frmt |
|
| 1241 | - * @throws \EE_Error |
|
| 1242 | - */ |
|
| 1243 | - public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1244 | - { |
|
| 1245 | - $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - |
|
| 1249 | - |
|
| 1250 | - /** |
|
| 1251 | - * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1252 | - * |
|
| 1253 | - * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1254 | - * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1255 | - * on the object will be used. |
|
| 1256 | - * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1257 | - * @throws \EE_Error |
|
| 1258 | - * field name. |
|
| 1259 | - */ |
|
| 1260 | - public function get_i18n_datetime($field_name, $format = '') |
|
| 1261 | - { |
|
| 1262 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1263 | - return date_i18n( |
|
| 1264 | - $format, |
|
| 1265 | - EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1266 | - ); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - |
|
| 1270 | - |
|
| 1271 | - /** |
|
| 1272 | - * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1273 | - * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1274 | - * thrown. |
|
| 1275 | - * |
|
| 1276 | - * @param string $field_name The field name being checked |
|
| 1277 | - * @throws EE_Error |
|
| 1278 | - * @return EE_Datetime_Field |
|
| 1279 | - */ |
|
| 1280 | - protected function _get_dtt_field_settings($field_name) |
|
| 1281 | - { |
|
| 1282 | - $field = $this->get_model()->field_settings_for($field_name); |
|
| 1283 | - //check if field is dtt |
|
| 1284 | - if ($field instanceof EE_Datetime_Field) { |
|
| 1285 | - return $field; |
|
| 1286 | - } else { |
|
| 1287 | - throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', |
|
| 1288 | - 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - |
|
| 1295 | - /** |
|
| 1296 | - * NOTE ABOUT BELOW: |
|
| 1297 | - * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1298 | - * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1299 | - * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1300 | - * method and make sure you send the entire datetime value for setting. |
|
| 1301 | - */ |
|
| 1302 | - /** |
|
| 1303 | - * sets the time on a datetime property |
|
| 1304 | - * |
|
| 1305 | - * @access protected |
|
| 1306 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1307 | - * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1308 | - * @throws \EE_Error |
|
| 1309 | - */ |
|
| 1310 | - protected function _set_time_for($time, $fieldname) |
|
| 1311 | - { |
|
| 1312 | - $this->_set_date_time('T', $time, $fieldname); |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * sets the date on a datetime property |
|
| 1319 | - * |
|
| 1320 | - * @access protected |
|
| 1321 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1322 | - * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1323 | - * @throws \EE_Error |
|
| 1324 | - */ |
|
| 1325 | - protected function _set_date_for($date, $fieldname) |
|
| 1326 | - { |
|
| 1327 | - $this->_set_date_time('D', $date, $fieldname); |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1334 | - * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1335 | - * |
|
| 1336 | - * @access protected |
|
| 1337 | - * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1338 | - * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1339 | - * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1340 | - * EE_Datetime_Field property) |
|
| 1341 | - * @throws \EE_Error |
|
| 1342 | - */ |
|
| 1343 | - protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1344 | - { |
|
| 1345 | - $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1346 | - $field->set_timezone($this->_timezone); |
|
| 1347 | - $field->set_date_format($this->_dt_frmt); |
|
| 1348 | - $field->set_time_format($this->_tm_frmt); |
|
| 1349 | - switch ($what) { |
|
| 1350 | - case 'T' : |
|
| 1351 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1352 | - $datetime_value, |
|
| 1353 | - $this->_fields[$fieldname] |
|
| 1354 | - ); |
|
| 1355 | - break; |
|
| 1356 | - case 'D' : |
|
| 1357 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1358 | - $datetime_value, |
|
| 1359 | - $this->_fields[$fieldname] |
|
| 1360 | - ); |
|
| 1361 | - break; |
|
| 1362 | - case 'B' : |
|
| 1363 | - $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1364 | - break; |
|
| 1365 | - } |
|
| 1366 | - $this->_clear_cached_property($fieldname); |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - |
|
| 1370 | - |
|
| 1371 | - /** |
|
| 1372 | - * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1373 | - * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1374 | - * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1375 | - * that could lead to some unexpected results! |
|
| 1376 | - * |
|
| 1377 | - * @access public |
|
| 1378 | - * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1379 | - * value being returned. |
|
| 1380 | - * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1381 | - * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1382 | - * @param string $prepend You can include something to prepend on the timestamp |
|
| 1383 | - * @param string $append You can include something to append on the timestamp |
|
| 1384 | - * @throws EE_Error |
|
| 1385 | - * @return string timestamp |
|
| 1386 | - */ |
|
| 1387 | - public function display_in_my_timezone( |
|
| 1388 | - $field_name, |
|
| 1389 | - $callback = 'get_datetime', |
|
| 1390 | - $args = null, |
|
| 1391 | - $prepend = '', |
|
| 1392 | - $append = '' |
|
| 1393 | - ) { |
|
| 1394 | - $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1395 | - if ($timezone === $this->_timezone) { |
|
| 1396 | - return ''; |
|
| 1397 | - } |
|
| 1398 | - $original_timezone = $this->_timezone; |
|
| 1399 | - $this->set_timezone($timezone); |
|
| 1400 | - $fn = (array)$field_name; |
|
| 1401 | - $args = array_merge($fn, (array)$args); |
|
| 1402 | - if ( ! method_exists($this, $callback)) { |
|
| 1403 | - throw new EE_Error( |
|
| 1404 | - sprintf( |
|
| 1405 | - __( |
|
| 1406 | - 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1407 | - 'event_espresso' |
|
| 1408 | - ), |
|
| 1409 | - $callback |
|
| 1410 | - ) |
|
| 1411 | - ); |
|
| 1412 | - } |
|
| 1413 | - $args = (array)$args; |
|
| 1414 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1415 | - $this->set_timezone($original_timezone); |
|
| 1416 | - return $return; |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * Deletes this model object. |
|
| 1423 | - * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1424 | - * override |
|
| 1425 | - * `EE_Base_Class::_delete` NOT this class. |
|
| 1426 | - * |
|
| 1427 | - * @return boolean | int |
|
| 1428 | - * @throws \EE_Error |
|
| 1429 | - */ |
|
| 1430 | - public function delete() |
|
| 1431 | - { |
|
| 1432 | - /** |
|
| 1433 | - * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1434 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1435 | - * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1436 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1437 | - * |
|
| 1438 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1439 | - */ |
|
| 1440 | - do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1441 | - $result = $this->_delete(); |
|
| 1442 | - /** |
|
| 1443 | - * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1444 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1445 | - * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1446 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1447 | - * |
|
| 1448 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1449 | - * @param boolean $result |
|
| 1450 | - */ |
|
| 1451 | - do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1452 | - return $result; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - |
|
| 1456 | - |
|
| 1457 | - /** |
|
| 1458 | - * Calls the specific delete method for the instantiated class. |
|
| 1459 | - * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1460 | - * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1461 | - * `EE_Base_Class::delete` |
|
| 1462 | - * |
|
| 1463 | - * @return bool|int |
|
| 1464 | - * @throws \EE_Error |
|
| 1465 | - */ |
|
| 1466 | - protected function _delete() |
|
| 1467 | - { |
|
| 1468 | - return $this->delete_permanently(); |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - |
|
| 1472 | - |
|
| 1473 | - /** |
|
| 1474 | - * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1475 | - * error) |
|
| 1476 | - * |
|
| 1477 | - * @return bool | int |
|
| 1478 | - * @throws \EE_Error |
|
| 1479 | - */ |
|
| 1480 | - public function delete_permanently() |
|
| 1481 | - { |
|
| 1482 | - /** |
|
| 1483 | - * Called just before HARD deleting a model object |
|
| 1484 | - * |
|
| 1485 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1486 | - */ |
|
| 1487 | - do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1488 | - $model = $this->get_model(); |
|
| 1489 | - $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1490 | - $this->refresh_cache_of_related_objects(); |
|
| 1491 | - /** |
|
| 1492 | - * Called just after HARD deleting a model object |
|
| 1493 | - * |
|
| 1494 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1495 | - * @param boolean $result |
|
| 1496 | - */ |
|
| 1497 | - do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1498 | - return $result; |
|
| 1499 | - } |
|
| 1500 | - |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1505 | - * related model objects |
|
| 1506 | - * |
|
| 1507 | - * @throws \EE_Error |
|
| 1508 | - */ |
|
| 1509 | - public function refresh_cache_of_related_objects() |
|
| 1510 | - { |
|
| 1511 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1512 | - if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1513 | - $related_objects = $this->_model_relations[$relation_name]; |
|
| 1514 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1515 | - //this relation only stores a single model object, not an array |
|
| 1516 | - //but let's make it consistent |
|
| 1517 | - $related_objects = array($related_objects); |
|
| 1518 | - } |
|
| 1519 | - foreach ($related_objects as $related_object) { |
|
| 1520 | - //only refresh their cache if they're in memory |
|
| 1521 | - if ($related_object instanceof EE_Base_Class) { |
|
| 1522 | - $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - } |
|
| 1526 | - } |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1533 | - * object just before saving. |
|
| 1534 | - * |
|
| 1535 | - * @access public |
|
| 1536 | - * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1537 | - * if provided during the save() method (often client code will change the fields' |
|
| 1538 | - * values before calling save) |
|
| 1539 | - * @throws \EE_Error |
|
| 1540 | - * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1541 | - * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1542 | - */ |
|
| 1543 | - public function save($set_cols_n_values = array()) |
|
| 1544 | - { |
|
| 1545 | - /** |
|
| 1546 | - * Filters the fields we're about to save on the model object |
|
| 1547 | - * |
|
| 1548 | - * @param array $set_cols_n_values |
|
| 1549 | - * @param EE_Base_Class $model_object |
|
| 1550 | - */ |
|
| 1551 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1552 | - $this); |
|
| 1553 | - //set attributes as provided in $set_cols_n_values |
|
| 1554 | - foreach ($set_cols_n_values as $column => $value) { |
|
| 1555 | - $this->set($column, $value); |
|
| 1556 | - } |
|
| 1557 | - /** |
|
| 1558 | - * Saving a model object. |
|
| 1559 | - * Before we perform a save, this action is fired. |
|
| 1560 | - * |
|
| 1561 | - * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1562 | - */ |
|
| 1563 | - do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1564 | - if ( ! $this->allow_persist()) { |
|
| 1565 | - return 0; |
|
| 1566 | - } |
|
| 1567 | - //now get current attribute values |
|
| 1568 | - $save_cols_n_values = $this->_fields; |
|
| 1569 | - //if the object already has an ID, update it. Otherwise, insert it |
|
| 1570 | - //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1571 | - $old_assumption_concerning_value_preparation = $this->get_model() |
|
| 1572 | - ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1573 | - $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
| 1574 | - //does this model have an autoincrement PK? |
|
| 1575 | - if ($this->get_model()->has_primary_key_field()) { |
|
| 1576 | - if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1577 | - //ok check if it's set, if so: update; if not, insert |
|
| 1578 | - if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1579 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1580 | - } else { |
|
| 1581 | - unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1582 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1583 | - if ($results) { |
|
| 1584 | - //if successful, set the primary key |
|
| 1585 | - //but don't use the normal SET method, because it will check if |
|
| 1586 | - //an item with the same ID exists in the mapper & db, then |
|
| 1587 | - //will find it in the db (because we just added it) and THAT object |
|
| 1588 | - //will get added to the mapper before we can add this one! |
|
| 1589 | - //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1590 | - $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1591 | - $this->_fields[$pk_field_name] = $results; |
|
| 1592 | - $this->_clear_cached_property($pk_field_name); |
|
| 1593 | - $this->get_model()->add_to_entity_map($this); |
|
| 1594 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1595 | - } |
|
| 1596 | - } |
|
| 1597 | - } else {//PK is NOT auto-increment |
|
| 1598 | - //so check if one like it already exists in the db |
|
| 1599 | - if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1600 | - if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1601 | - throw new EE_Error( |
|
| 1602 | - sprintf( |
|
| 1603 | - __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', |
|
| 1604 | - 'event_espresso'), |
|
| 1605 | - get_class($this), |
|
| 1606 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 1607 | - get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
| 1608 | - '<br />' |
|
| 1609 | - ) |
|
| 1610 | - ); |
|
| 1611 | - } |
|
| 1612 | - $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1613 | - } else { |
|
| 1614 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1615 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - } else {//there is NO primary key |
|
| 1619 | - $already_in_db = false; |
|
| 1620 | - foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1621 | - $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1622 | - if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1623 | - $already_in_db = true; |
|
| 1624 | - } |
|
| 1625 | - } |
|
| 1626 | - if ($already_in_db) { |
|
| 1627 | - $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1628 | - $this->get_model()->get_combined_primary_key_fields()); |
|
| 1629 | - $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1630 | - } else { |
|
| 1631 | - $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1632 | - } |
|
| 1633 | - } |
|
| 1634 | - //restore the old assumption about values being prepared by the model object |
|
| 1635 | - $this->get_model() |
|
| 1636 | - ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1637 | - /** |
|
| 1638 | - * After saving the model object this action is called |
|
| 1639 | - * |
|
| 1640 | - * @param EE_Base_Class $model_object which was just saved |
|
| 1641 | - * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1642 | - * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1643 | - */ |
|
| 1644 | - do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1645 | - return $results; |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - |
|
| 1649 | - |
|
| 1650 | - /** |
|
| 1651 | - * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1652 | - * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1653 | - * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1654 | - * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1655 | - * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the |
|
| 1656 | - * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1657 | - * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1658 | - * |
|
| 1659 | - * @return void |
|
| 1660 | - * @throws \EE_Error |
|
| 1661 | - */ |
|
| 1662 | - protected function _update_cached_related_model_objs_fks() |
|
| 1663 | - { |
|
| 1664 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1665 | - if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1666 | - foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1667 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1668 | - $this->get_model()->get_this_model_name() |
|
| 1669 | - ); |
|
| 1670 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1671 | - if ($related_model_obj_in_cache->ID()) { |
|
| 1672 | - $related_model_obj_in_cache->save(); |
|
| 1673 | - } |
|
| 1674 | - } |
|
| 1675 | - } |
|
| 1676 | - } |
|
| 1677 | - } |
|
| 1678 | - |
|
| 1679 | - |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * Saves this model object and its NEW cached relations to the database. |
|
| 1683 | - * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1684 | - * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1685 | - * because otherwise, there's a potential for infinite looping of saving |
|
| 1686 | - * Saves the cached related model objects, and ensures the relation between them |
|
| 1687 | - * and this object and properly setup |
|
| 1688 | - * |
|
| 1689 | - * @return int ID of new model object on save; 0 on failure+ |
|
| 1690 | - * @throws \EE_Error |
|
| 1691 | - */ |
|
| 1692 | - public function save_new_cached_related_model_objs() |
|
| 1693 | - { |
|
| 1694 | - //make sure this has been saved |
|
| 1695 | - if ( ! $this->ID()) { |
|
| 1696 | - $id = $this->save(); |
|
| 1697 | - } else { |
|
| 1698 | - $id = $this->ID(); |
|
| 1699 | - } |
|
| 1700 | - //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1701 | - foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1702 | - if ($this->_model_relations[$relationName]) { |
|
| 1703 | - //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1704 | - //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1705 | - if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1706 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1707 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1708 | - /* @var $related_model_obj EE_Base_Class */ |
|
| 1709 | - $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1710 | - // if( ! $related_model_obj->ID()){ |
|
| 1711 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1712 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1713 | - // } |
|
| 1714 | - } else { |
|
| 1715 | - foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1716 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1717 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1718 | - // if( ! $related_model_obj->ID()){ |
|
| 1719 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1720 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1721 | - // } |
|
| 1722 | - } |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1725 | - } |
|
| 1726 | - return $id; |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - |
|
| 1730 | - |
|
| 1731 | - /** |
|
| 1732 | - * for getting a model while instantiated. |
|
| 1733 | - * |
|
| 1734 | - * @return \EEM_Base | \EEM_CPT_Base |
|
| 1735 | - */ |
|
| 1736 | - public function get_model() |
|
| 1737 | - { |
|
| 1738 | - $modelName = self::_get_model_classname(get_class($this)); |
|
| 1739 | - return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * @param $props_n_values |
|
| 1746 | - * @param $classname |
|
| 1747 | - * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1748 | - * @throws \EE_Error |
|
| 1749 | - */ |
|
| 1750 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1751 | - { |
|
| 1752 | - //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1753 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1754 | - if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1755 | - $id = $props_n_values[$primary_id_ref]; |
|
| 1756 | - return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1757 | - } |
|
| 1758 | - return false; |
|
| 1759 | - } |
|
| 1760 | - |
|
| 1761 | - |
|
| 1762 | - |
|
| 1763 | - /** |
|
| 1764 | - * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1765 | - * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1766 | - * primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not |
|
| 1767 | - * we return false. |
|
| 1768 | - * |
|
| 1769 | - * @param array $props_n_values incoming array of properties and their values |
|
| 1770 | - * @param string $classname the classname of the child class |
|
| 1771 | - * @param null $timezone |
|
| 1772 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1773 | - * date_format and the second value is the time format |
|
| 1774 | - * @return mixed (EE_Base_Class|bool) |
|
| 1775 | - * @throws \EE_Error |
|
| 1776 | - */ |
|
| 1777 | - protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1778 | - { |
|
| 1779 | - $existing = null; |
|
| 1780 | - if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1781 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1782 | - if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1783 | - && ! empty($props_n_values[$primary_id_ref]) |
|
| 1784 | - ) { |
|
| 1785 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1786 | - $props_n_values[$primary_id_ref] |
|
| 1787 | - ); |
|
| 1788 | - } |
|
| 1789 | - } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1790 | - //no primary key on this model, but there's still a matching item in the DB |
|
| 1791 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1792 | - self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1793 | - ); |
|
| 1794 | - } |
|
| 1795 | - if ($existing) { |
|
| 1796 | - //set date formats if present before setting values |
|
| 1797 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1798 | - $existing->set_date_format($date_formats[0]); |
|
| 1799 | - $existing->set_time_format($date_formats[1]); |
|
| 1800 | - } else { |
|
| 1801 | - //set default formats for date and time |
|
| 1802 | - $existing->set_date_format(get_option('date_format')); |
|
| 1803 | - $existing->set_time_format(get_option('time_format')); |
|
| 1804 | - } |
|
| 1805 | - foreach ($props_n_values as $property => $field_value) { |
|
| 1806 | - $existing->set($property, $field_value); |
|
| 1807 | - } |
|
| 1808 | - return $existing; |
|
| 1809 | - } else { |
|
| 1810 | - return false; |
|
| 1811 | - } |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - |
|
| 1815 | - |
|
| 1816 | - /** |
|
| 1817 | - * Gets the EEM_*_Model for this class |
|
| 1818 | - * |
|
| 1819 | - * @access public now, as this is more convenient |
|
| 1820 | - * @param $classname |
|
| 1821 | - * @param null $timezone |
|
| 1822 | - * @throws EE_Error |
|
| 1823 | - * @return EEM_Base |
|
| 1824 | - */ |
|
| 1825 | - protected static function _get_model($classname, $timezone = null) |
|
| 1826 | - { |
|
| 1827 | - //find model for this class |
|
| 1828 | - if ( ! $classname) { |
|
| 1829 | - throw new EE_Error( |
|
| 1830 | - sprintf( |
|
| 1831 | - __( |
|
| 1832 | - "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1833 | - "event_espresso" |
|
| 1834 | - ), |
|
| 1835 | - $classname |
|
| 1836 | - ) |
|
| 1837 | - ); |
|
| 1838 | - } |
|
| 1839 | - $modelName = self::_get_model_classname($classname); |
|
| 1840 | - return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1847 | - * |
|
| 1848 | - * @param string $model_classname |
|
| 1849 | - * @param null $timezone |
|
| 1850 | - * @return EEM_Base |
|
| 1851 | - */ |
|
| 1852 | - protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1853 | - { |
|
| 1854 | - $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1855 | - $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1856 | - $model->set_timezone($timezone); |
|
| 1857 | - return $model; |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - |
|
| 1861 | - |
|
| 1862 | - /** |
|
| 1863 | - * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 1864 | - * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 1865 | - * |
|
| 1866 | - * @param null $model_name |
|
| 1867 | - * @return string like EEM_Attendee |
|
| 1868 | - */ |
|
| 1869 | - private static function _get_model_classname($model_name = null) |
|
| 1870 | - { |
|
| 1871 | - if (strpos($model_name, "EE_") === 0) { |
|
| 1872 | - $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1873 | - } else { |
|
| 1874 | - $model_classname = "EEM_" . $model_name; |
|
| 1875 | - } |
|
| 1876 | - return $model_classname; |
|
| 1877 | - } |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - |
|
| 1881 | - /** |
|
| 1882 | - * returns the name of the primary key attribute |
|
| 1883 | - * |
|
| 1884 | - * @param null $classname |
|
| 1885 | - * @throws EE_Error |
|
| 1886 | - * @return string |
|
| 1887 | - */ |
|
| 1888 | - protected static function _get_primary_key_name($classname = null) |
|
| 1889 | - { |
|
| 1890 | - if ( ! $classname) { |
|
| 1891 | - throw new EE_Error( |
|
| 1892 | - sprintf( |
|
| 1893 | - __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1894 | - $classname |
|
| 1895 | - ) |
|
| 1896 | - ); |
|
| 1897 | - } |
|
| 1898 | - return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - |
|
| 1903 | - /** |
|
| 1904 | - * Gets the value of the primary key. |
|
| 1905 | - * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 1906 | - * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 1907 | - * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 1908 | - * |
|
| 1909 | - * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 1910 | - * @throws \EE_Error |
|
| 1911 | - */ |
|
| 1912 | - public function ID() |
|
| 1913 | - { |
|
| 1914 | - //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 1915 | - if ($this->get_model()->has_primary_key_field()) { |
|
| 1916 | - return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1917 | - } else { |
|
| 1918 | - return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1919 | - } |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - |
|
| 1923 | - |
|
| 1924 | - /** |
|
| 1925 | - * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 1926 | - * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 1927 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 1928 | - * |
|
| 1929 | - * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 1930 | - * @param string $relationName eg 'Events','Question',etc. |
|
| 1931 | - * an attendee to a group, you also want to specify which role they |
|
| 1932 | - * will have in that group. So you would use this parameter to |
|
| 1933 | - * specify array('role-column-name'=>'role-id') |
|
| 1934 | - * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 1935 | - * allow you to further constrict the relation to being added. |
|
| 1936 | - * However, keep in mind that the columns (keys) given must match a |
|
| 1937 | - * column on the JOIN table and currently only the HABTM models |
|
| 1938 | - * accept these additional conditions. Also remember that if an |
|
| 1939 | - * exact match isn't found for these extra cols/val pairs, then a |
|
| 1940 | - * NEW row is created in the join table. |
|
| 1941 | - * @param null $cache_id |
|
| 1942 | - * @throws EE_Error |
|
| 1943 | - * @return EE_Base_Class the object the relation was added to |
|
| 1944 | - */ |
|
| 1945 | - public function _add_relation_to( |
|
| 1946 | - $otherObjectModelObjectOrID, |
|
| 1947 | - $relationName, |
|
| 1948 | - $extra_join_model_fields_n_values = array(), |
|
| 1949 | - $cache_id = null |
|
| 1950 | - ) { |
|
| 1951 | - //if this thing exists in the DB, save the relation to the DB |
|
| 1952 | - if ($this->ID()) { |
|
| 1953 | - $otherObject = $this->get_model() |
|
| 1954 | - ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 1955 | - $extra_join_model_fields_n_values); |
|
| 1956 | - //clear cache so future get_many_related and get_first_related() return new results. |
|
| 1957 | - $this->clear_cache($relationName, $otherObject, true); |
|
| 1958 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 1959 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1960 | - } |
|
| 1961 | - } else { |
|
| 1962 | - //this thing doesn't exist in the DB, so just cache it |
|
| 1963 | - if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1964 | - throw new EE_Error(sprintf( |
|
| 1965 | - __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', |
|
| 1966 | - 'event_espresso'), |
|
| 1967 | - $otherObjectModelObjectOrID, |
|
| 1968 | - get_class($this) |
|
| 1969 | - )); |
|
| 1970 | - } else { |
|
| 1971 | - $otherObject = $otherObjectModelObjectOrID; |
|
| 1972 | - } |
|
| 1973 | - $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1974 | - } |
|
| 1975 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 1976 | - //fix the reciprocal relation too |
|
| 1977 | - if ($otherObject->ID()) { |
|
| 1978 | - //its saved so assumed relations exist in the DB, so we can just |
|
| 1979 | - //clear the cache so future queries use the updated info in the DB |
|
| 1980 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1981 | - } else { |
|
| 1982 | - //it's not saved, so it caches relations like this |
|
| 1983 | - $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1984 | - } |
|
| 1985 | - } |
|
| 1986 | - return $otherObject; |
|
| 1987 | - } |
|
| 1988 | - |
|
| 1989 | - |
|
| 1990 | - |
|
| 1991 | - /** |
|
| 1992 | - * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 1993 | - * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 1994 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 1995 | - * from the cache |
|
| 1996 | - * |
|
| 1997 | - * @param mixed $otherObjectModelObjectOrID |
|
| 1998 | - * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 1999 | - * to the DB yet |
|
| 2000 | - * @param string $relationName |
|
| 2001 | - * @param array $where_query |
|
| 2002 | - * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2003 | - * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2004 | - * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2005 | - * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2006 | - * created in the join table. |
|
| 2007 | - * @return EE_Base_Class the relation was removed from |
|
| 2008 | - * @throws \EE_Error |
|
| 2009 | - */ |
|
| 2010 | - public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2011 | - { |
|
| 2012 | - if ($this->ID()) { |
|
| 2013 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2014 | - $otherObject = $this->get_model() |
|
| 2015 | - ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2016 | - $where_query); |
|
| 2017 | - $this->clear_cache($relationName, $otherObject); |
|
| 2018 | - } else { |
|
| 2019 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2020 | - $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2021 | - } |
|
| 2022 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 2023 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2024 | - } |
|
| 2025 | - return $otherObject; |
|
| 2026 | - } |
|
| 2027 | - |
|
| 2028 | - |
|
| 2029 | - |
|
| 2030 | - /** |
|
| 2031 | - * Removes ALL the related things for the $relationName. |
|
| 2032 | - * |
|
| 2033 | - * @param string $relationName |
|
| 2034 | - * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2035 | - * @return EE_Base_Class |
|
| 2036 | - * @throws \EE_Error |
|
| 2037 | - */ |
|
| 2038 | - public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2039 | - { |
|
| 2040 | - if ($this->ID()) { |
|
| 2041 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2042 | - $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2043 | - $this->clear_cache($relationName, null, true); |
|
| 2044 | - } else { |
|
| 2045 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2046 | - $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2047 | - } |
|
| 2048 | - if (is_array($otherObjects)) { |
|
| 2049 | - foreach ($otherObjects as $otherObject) { |
|
| 2050 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2051 | - } |
|
| 2052 | - } |
|
| 2053 | - return $otherObjects; |
|
| 2054 | - } |
|
| 2055 | - |
|
| 2056 | - |
|
| 2057 | - |
|
| 2058 | - /** |
|
| 2059 | - * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2060 | - * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2061 | - * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2062 | - * because we want to get even deleted items etc. |
|
| 2063 | - * |
|
| 2064 | - * @param string $relationName key in the model's _model_relations array |
|
| 2065 | - * @param array $query_params like EEM_Base::get_all |
|
| 2066 | - * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2067 | - * @throws \EE_Error |
|
| 2068 | - * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2069 | - * you want IDs |
|
| 2070 | - */ |
|
| 2071 | - public function get_many_related($relationName, $query_params = array()) |
|
| 2072 | - { |
|
| 2073 | - if ($this->ID()) { |
|
| 2074 | - //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2075 | - //if there are query parameters, forget about caching the related model objects. |
|
| 2076 | - if ($query_params) { |
|
| 2077 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2078 | - } else { |
|
| 2079 | - //did we already cache the result of this query? |
|
| 2080 | - $cached_results = $this->get_all_from_cache($relationName); |
|
| 2081 | - if ( ! $cached_results) { |
|
| 2082 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2083 | - //if no query parameters were passed, then we got all the related model objects |
|
| 2084 | - //for that relation. We can cache them then. |
|
| 2085 | - foreach ($related_model_objects as $related_model_object) { |
|
| 2086 | - $this->cache($relationName, $related_model_object); |
|
| 2087 | - } |
|
| 2088 | - } else { |
|
| 2089 | - $related_model_objects = $cached_results; |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - } else { |
|
| 2093 | - //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2094 | - $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2095 | - } |
|
| 2096 | - return $related_model_objects; |
|
| 2097 | - } |
|
| 2098 | - |
|
| 2099 | - |
|
| 2100 | - |
|
| 2101 | - /** |
|
| 2102 | - * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2103 | - * unless otherwise specified in the $query_params |
|
| 2104 | - * |
|
| 2105 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2106 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2107 | - * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2108 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2109 | - * that by the setting $distinct to TRUE; |
|
| 2110 | - * @return int |
|
| 2111 | - */ |
|
| 2112 | - public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2113 | - { |
|
| 2114 | - return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2115 | - } |
|
| 2116 | - |
|
| 2117 | - |
|
| 2118 | - |
|
| 2119 | - /** |
|
| 2120 | - * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2121 | - * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2122 | - * |
|
| 2123 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2124 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2125 | - * @param string $field_to_sum name of field to count by. |
|
| 2126 | - * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2127 | - * change it) |
|
| 2128 | - * @return int |
|
| 2129 | - */ |
|
| 2130 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2131 | - { |
|
| 2132 | - return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2133 | - } |
|
| 2134 | - |
|
| 2135 | - |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Gets the first (ie, one) related model object of the specified type. |
|
| 2139 | - * |
|
| 2140 | - * @param string $relationName key in the model's _model_relations array |
|
| 2141 | - * @param array $query_params like EEM_Base::get_all |
|
| 2142 | - * @return EE_Base_Class (not an array, a single object) |
|
| 2143 | - * @throws \EE_Error |
|
| 2144 | - */ |
|
| 2145 | - public function get_first_related($relationName, $query_params = array()) |
|
| 2146 | - { |
|
| 2147 | - if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2148 | - //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2149 | - //also make sure we're not caching the result of get_first_related |
|
| 2150 | - //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2151 | - if ($query_params |
|
| 2152 | - || ! $this->get_model()->related_settings_for($relationName) |
|
| 2153 | - instanceof |
|
| 2154 | - EE_Belongs_To_Relation |
|
| 2155 | - ) { |
|
| 2156 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2157 | - } else { |
|
| 2158 | - //first, check if we've already cached the result of this query |
|
| 2159 | - $cached_result = $this->get_one_from_cache($relationName); |
|
| 2160 | - if ( ! $cached_result) { |
|
| 2161 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2162 | - $this->cache($relationName, $related_model_object); |
|
| 2163 | - } else { |
|
| 2164 | - $related_model_object = $cached_result; |
|
| 2165 | - } |
|
| 2166 | - } |
|
| 2167 | - } else { |
|
| 2168 | - $related_model_object = null; |
|
| 2169 | - //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2170 | - if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2171 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2172 | - } |
|
| 2173 | - //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
|
| 2174 | - if ( ! $related_model_object) { |
|
| 2175 | - $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2176 | - } |
|
| 2177 | - } |
|
| 2178 | - return $related_model_object; |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - |
|
| 2182 | - |
|
| 2183 | - /** |
|
| 2184 | - * Does a delete on all related objects of type $relationName and removes |
|
| 2185 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2186 | - * of blocking related model objects) does nothing. If the related model objects are |
|
| 2187 | - * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2188 | - * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2189 | - * |
|
| 2190 | - * @param string $relationName |
|
| 2191 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2192 | - * @return int how many deleted |
|
| 2193 | - * @throws \EE_Error |
|
| 2194 | - */ |
|
| 2195 | - public function delete_related($relationName, $query_params = array()) |
|
| 2196 | - { |
|
| 2197 | - if ($this->ID()) { |
|
| 2198 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2199 | - } else { |
|
| 2200 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2201 | - $this->clear_cache($relationName, null, true); |
|
| 2202 | - } |
|
| 2203 | - return $count; |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - |
|
| 2207 | - |
|
| 2208 | - /** |
|
| 2209 | - * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2210 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2211 | - * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2212 | - * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2213 | - * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2214 | - * |
|
| 2215 | - * @param string $relationName |
|
| 2216 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2217 | - * @return int how many deleted (including those soft deleted) |
|
| 2218 | - * @throws \EE_Error |
|
| 2219 | - */ |
|
| 2220 | - public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2221 | - { |
|
| 2222 | - if ($this->ID()) { |
|
| 2223 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2224 | - } else { |
|
| 2225 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2226 | - } |
|
| 2227 | - $this->clear_cache($relationName, null, true); |
|
| 2228 | - return $count; |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * is_set |
|
| 2235 | - * Just a simple utility function children can use for checking if property exists |
|
| 2236 | - * |
|
| 2237 | - * @access public |
|
| 2238 | - * @param string $field_name property to check |
|
| 2239 | - * @return bool TRUE if existing,FALSE if not. |
|
| 2240 | - */ |
|
| 2241 | - public function is_set($field_name) |
|
| 2242 | - { |
|
| 2243 | - return isset($this->_fields[$field_name]); |
|
| 2244 | - } |
|
| 2245 | - |
|
| 2246 | - |
|
| 2247 | - |
|
| 2248 | - /** |
|
| 2249 | - * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2250 | - * EE_Error exception if they don't |
|
| 2251 | - * |
|
| 2252 | - * @param mixed (string|array) $properties properties to check |
|
| 2253 | - * @throws EE_Error |
|
| 2254 | - * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2255 | - */ |
|
| 2256 | - protected function _property_exists($properties) |
|
| 2257 | - { |
|
| 2258 | - foreach ((array)$properties as $property_name) { |
|
| 2259 | - //first make sure this property exists |
|
| 2260 | - if ( ! $this->_fields[$property_name]) { |
|
| 2261 | - throw new EE_Error( |
|
| 2262 | - sprintf( |
|
| 2263 | - __( |
|
| 2264 | - 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2265 | - 'event_espresso' |
|
| 2266 | - ), |
|
| 2267 | - $property_name |
|
| 2268 | - ) |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - } |
|
| 2272 | - return true; |
|
| 2273 | - } |
|
| 2274 | - |
|
| 2275 | - |
|
| 2276 | - |
|
| 2277 | - /** |
|
| 2278 | - * This simply returns an array of model fields for this object |
|
| 2279 | - * |
|
| 2280 | - * @return array |
|
| 2281 | - * @throws \EE_Error |
|
| 2282 | - */ |
|
| 2283 | - public function model_field_array() |
|
| 2284 | - { |
|
| 2285 | - $fields = $this->get_model()->field_settings(false); |
|
| 2286 | - $properties = array(); |
|
| 2287 | - //remove prepended underscore |
|
| 2288 | - foreach ($fields as $field_name => $settings) { |
|
| 2289 | - $properties[$field_name] = $this->get($field_name); |
|
| 2290 | - } |
|
| 2291 | - return $properties; |
|
| 2292 | - } |
|
| 2293 | - |
|
| 2294 | - |
|
| 2295 | - |
|
| 2296 | - /** |
|
| 2297 | - * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2298 | - * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2299 | - * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2300 | - * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2301 | - * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2302 | - * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2303 | - * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2304 | - * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2305 | - * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2306 | - * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2307 | - * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2308 | - * return $previousReturnValue.$returnString; |
|
| 2309 | - * } |
|
| 2310 | - * require('EE_Answer.class.php'); |
|
| 2311 | - * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2312 | - * echo $answer->my_callback('monkeys',100); |
|
| 2313 | - * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2314 | - * |
|
| 2315 | - * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2316 | - * @param array $args array of original arguments passed to the function |
|
| 2317 | - * @throws EE_Error |
|
| 2318 | - * @return mixed whatever the plugin which calls add_filter decides |
|
| 2319 | - */ |
|
| 2320 | - public function __call($methodName, $args) |
|
| 2321 | - { |
|
| 2322 | - $className = get_class($this); |
|
| 2323 | - $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2324 | - if ( ! has_filter($tagName)) { |
|
| 2325 | - throw new EE_Error( |
|
| 2326 | - sprintf( |
|
| 2327 | - __( |
|
| 2328 | - "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", |
|
| 2329 | - "event_espresso" |
|
| 2330 | - ), |
|
| 2331 | - $methodName, |
|
| 2332 | - $className, |
|
| 2333 | - $tagName |
|
| 2334 | - ) |
|
| 2335 | - ); |
|
| 2336 | - } |
|
| 2337 | - return apply_filters($tagName, null, $this, $args); |
|
| 2338 | - } |
|
| 2339 | - |
|
| 2340 | - |
|
| 2341 | - |
|
| 2342 | - /** |
|
| 2343 | - * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2344 | - * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2345 | - * |
|
| 2346 | - * @param string $meta_key |
|
| 2347 | - * @param string $meta_value |
|
| 2348 | - * @param string $previous_value |
|
| 2349 | - * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2350 | - * @throws \EE_Error |
|
| 2351 | - * NOTE: if the values haven't changed, returns 0 |
|
| 2352 | - */ |
|
| 2353 | - public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2354 | - { |
|
| 2355 | - $query_params = array( |
|
| 2356 | - array( |
|
| 2357 | - 'EXM_key' => $meta_key, |
|
| 2358 | - 'OBJ_ID' => $this->ID(), |
|
| 2359 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2360 | - ), |
|
| 2361 | - ); |
|
| 2362 | - if ($previous_value !== null) { |
|
| 2363 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2364 | - } |
|
| 2365 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2366 | - if ( ! $existing_rows_like_that) { |
|
| 2367 | - return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2368 | - } else { |
|
| 2369 | - foreach ($existing_rows_like_that as $existing_row) { |
|
| 2370 | - $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2371 | - } |
|
| 2372 | - return count($existing_rows_like_that); |
|
| 2373 | - } |
|
| 2374 | - } |
|
| 2375 | - |
|
| 2376 | - |
|
| 2377 | - |
|
| 2378 | - /** |
|
| 2379 | - * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2380 | - * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2381 | - * extra meta row was entered, false if not |
|
| 2382 | - * |
|
| 2383 | - * @param string $meta_key |
|
| 2384 | - * @param string $meta_value |
|
| 2385 | - * @param boolean $unique |
|
| 2386 | - * @return boolean |
|
| 2387 | - * @throws \EE_Error |
|
| 2388 | - */ |
|
| 2389 | - public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2390 | - { |
|
| 2391 | - if ($unique) { |
|
| 2392 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2393 | - array( |
|
| 2394 | - array( |
|
| 2395 | - 'EXM_key' => $meta_key, |
|
| 2396 | - 'OBJ_ID' => $this->ID(), |
|
| 2397 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2398 | - ), |
|
| 2399 | - ) |
|
| 2400 | - ); |
|
| 2401 | - if ($existing_extra_meta) { |
|
| 2402 | - return false; |
|
| 2403 | - } |
|
| 2404 | - } |
|
| 2405 | - $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2406 | - array( |
|
| 2407 | - 'EXM_key' => $meta_key, |
|
| 2408 | - 'EXM_value' => $meta_value, |
|
| 2409 | - 'OBJ_ID' => $this->ID(), |
|
| 2410 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2411 | - ) |
|
| 2412 | - ); |
|
| 2413 | - $new_extra_meta->save(); |
|
| 2414 | - return true; |
|
| 2415 | - } |
|
| 2416 | - |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2421 | - * is specified, only deletes extra meta records with that value. |
|
| 2422 | - * |
|
| 2423 | - * @param string $meta_key |
|
| 2424 | - * @param string $meta_value |
|
| 2425 | - * @return int number of extra meta rows deleted |
|
| 2426 | - * @throws \EE_Error |
|
| 2427 | - */ |
|
| 2428 | - public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2429 | - { |
|
| 2430 | - $query_params = array( |
|
| 2431 | - array( |
|
| 2432 | - 'EXM_key' => $meta_key, |
|
| 2433 | - 'OBJ_ID' => $this->ID(), |
|
| 2434 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2435 | - ), |
|
| 2436 | - ); |
|
| 2437 | - if ($meta_value !== null) { |
|
| 2438 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2439 | - } |
|
| 2440 | - return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - |
|
| 2444 | - |
|
| 2445 | - /** |
|
| 2446 | - * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2447 | - * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2448 | - * You can specify $default is case you haven't found the extra meta |
|
| 2449 | - * |
|
| 2450 | - * @param string $meta_key |
|
| 2451 | - * @param boolean $single |
|
| 2452 | - * @param mixed $default if we don't find anything, what should we return? |
|
| 2453 | - * @return mixed single value if $single; array if ! $single |
|
| 2454 | - * @throws \EE_Error |
|
| 2455 | - */ |
|
| 2456 | - public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2457 | - { |
|
| 2458 | - if ($single) { |
|
| 2459 | - $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2460 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2461 | - return $result->value(); |
|
| 2462 | - } else { |
|
| 2463 | - return $default; |
|
| 2464 | - } |
|
| 2465 | - } else { |
|
| 2466 | - $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2467 | - if ($results) { |
|
| 2468 | - $values = array(); |
|
| 2469 | - foreach ($results as $result) { |
|
| 2470 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2471 | - $values[$result->ID()] = $result->value(); |
|
| 2472 | - } |
|
| 2473 | - } |
|
| 2474 | - return $values; |
|
| 2475 | - } else { |
|
| 2476 | - return $default; |
|
| 2477 | - } |
|
| 2478 | - } |
|
| 2479 | - } |
|
| 2480 | - |
|
| 2481 | - |
|
| 2482 | - |
|
| 2483 | - /** |
|
| 2484 | - * Returns a simple array of all the extra meta associated with this model object. |
|
| 2485 | - * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2486 | - * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2487 | - * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2488 | - * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2489 | - * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2490 | - * finally the extra meta's value as each sub-value. (eg |
|
| 2491 | - * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2492 | - * |
|
| 2493 | - * @param boolean $one_of_each_key |
|
| 2494 | - * @return array |
|
| 2495 | - * @throws \EE_Error |
|
| 2496 | - */ |
|
| 2497 | - public function all_extra_meta_array($one_of_each_key = true) |
|
| 2498 | - { |
|
| 2499 | - $return_array = array(); |
|
| 2500 | - if ($one_of_each_key) { |
|
| 2501 | - $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2502 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2503 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2504 | - $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2505 | - } |
|
| 2506 | - } |
|
| 2507 | - } else { |
|
| 2508 | - $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2509 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2510 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2511 | - if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2512 | - $return_array[$extra_meta_obj->key()] = array(); |
|
| 2513 | - } |
|
| 2514 | - $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2515 | - } |
|
| 2516 | - } |
|
| 2517 | - } |
|
| 2518 | - return $return_array; |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - |
|
| 2522 | - |
|
| 2523 | - /** |
|
| 2524 | - * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2525 | - * |
|
| 2526 | - * @return string |
|
| 2527 | - * @throws \EE_Error |
|
| 2528 | - */ |
|
| 2529 | - public function name() |
|
| 2530 | - { |
|
| 2531 | - //find a field that's not a text field |
|
| 2532 | - $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2533 | - if ($field_we_can_use) { |
|
| 2534 | - return $this->get($field_we_can_use->get_name()); |
|
| 2535 | - } else { |
|
| 2536 | - $first_few_properties = $this->model_field_array(); |
|
| 2537 | - $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2538 | - $name_parts = array(); |
|
| 2539 | - foreach ($first_few_properties as $name => $value) { |
|
| 2540 | - $name_parts[] = "$name:$value"; |
|
| 2541 | - } |
|
| 2542 | - return implode(",", $name_parts); |
|
| 2543 | - } |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * in_entity_map |
|
| 2550 | - * Checks if this model object has been proven to already be in the entity map |
|
| 2551 | - * |
|
| 2552 | - * @return boolean |
|
| 2553 | - * @throws \EE_Error |
|
| 2554 | - */ |
|
| 2555 | - public function in_entity_map() |
|
| 2556 | - { |
|
| 2557 | - if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2558 | - //well, if we looked, did we find it in the entity map? |
|
| 2559 | - return true; |
|
| 2560 | - } else { |
|
| 2561 | - return false; |
|
| 2562 | - } |
|
| 2563 | - } |
|
| 2564 | - |
|
| 2565 | - |
|
| 2566 | - |
|
| 2567 | - /** |
|
| 2568 | - * refresh_from_db |
|
| 2569 | - * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2570 | - * |
|
| 2571 | - * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2572 | - * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2573 | - */ |
|
| 2574 | - public function refresh_from_db() |
|
| 2575 | - { |
|
| 2576 | - if ($this->ID() && $this->in_entity_map()) { |
|
| 2577 | - $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2578 | - } else { |
|
| 2579 | - //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2580 | - //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2581 | - //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2582 | - //absolutely nothing in it for this ID |
|
| 2583 | - if (WP_DEBUG) { |
|
| 2584 | - throw new EE_Error( |
|
| 2585 | - sprintf( |
|
| 2586 | - __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', |
|
| 2587 | - 'event_espresso'), |
|
| 2588 | - $this->ID(), |
|
| 2589 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2590 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2591 | - ) |
|
| 2592 | - ); |
|
| 2593 | - } |
|
| 2594 | - } |
|
| 2595 | - } |
|
| 2596 | - |
|
| 2597 | - |
|
| 2598 | - |
|
| 2599 | - /** |
|
| 2600 | - * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2601 | - * (probably a bad assumption they have made, oh well) |
|
| 2602 | - * |
|
| 2603 | - * @return string |
|
| 2604 | - */ |
|
| 2605 | - public function __toString() |
|
| 2606 | - { |
|
| 2607 | - try { |
|
| 2608 | - return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2609 | - } catch (Exception $e) { |
|
| 2610 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2611 | - return ''; |
|
| 2612 | - } |
|
| 2613 | - } |
|
| 2614 | - |
|
| 2615 | - |
|
| 2616 | - |
|
| 2617 | - /** |
|
| 2618 | - * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2619 | - * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2620 | - * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2621 | - * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2622 | - * Instead, those related model objects should be directly serialized and stored. |
|
| 2623 | - * Eg, the following won't work: |
|
| 2624 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2625 | - * $att = $reg->attendee(); |
|
| 2626 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2627 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2628 | - * //END REQUEST |
|
| 2629 | - * //START NEXT REQUEST |
|
| 2630 | - * $reg = get_option( 'my_option' ); |
|
| 2631 | - * $reg->attendee()->save(); |
|
| 2632 | - * And would need to be replace with: |
|
| 2633 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2634 | - * $att = $reg->attendee(); |
|
| 2635 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2636 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2637 | - * //END REQUEST |
|
| 2638 | - * //START NEXT REQUEST |
|
| 2639 | - * $att = get_option( 'my_option' ); |
|
| 2640 | - * $att->save(); |
|
| 2641 | - * |
|
| 2642 | - * @return array |
|
| 2643 | - * @throws \EE_Error |
|
| 2644 | - */ |
|
| 2645 | - public function __sleep() |
|
| 2646 | - { |
|
| 2647 | - foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2648 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2649 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2650 | - if ( |
|
| 2651 | - $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2652 | - && $this->get_one_from_cache($relation_name)->ID() |
|
| 2653 | - ) { |
|
| 2654 | - $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2655 | - } |
|
| 2656 | - } |
|
| 2657 | - } |
|
| 2658 | - $this->_props_n_values_provided_in_constructor = array(); |
|
| 2659 | - return array_keys(get_object_vars($this)); |
|
| 2660 | - } |
|
| 2661 | - |
|
| 2662 | - |
|
| 2663 | - |
|
| 2664 | - /** |
|
| 2665 | - * restore _props_n_values_provided_in_constructor |
|
| 2666 | - * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2667 | - * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2668 | - * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2669 | - */ |
|
| 2670 | - public function __wakeup() |
|
| 2671 | - { |
|
| 2672 | - $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2673 | - } |
|
| 28 | + /** |
|
| 29 | + * This is an array of the original properties and values provided during construction |
|
| 30 | + * of this model object. (keys are model field names, values are their values). |
|
| 31 | + * This list is important to remember so that when we are merging data from the db, we know |
|
| 32 | + * which values to override and which to not override. |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $_props_n_values_provided_in_constructor; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Timezone |
|
| 40 | + * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 41 | + * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 42 | + * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 43 | + * access to it. |
|
| 44 | + * |
|
| 45 | + * @var string |
|
| 46 | + */ |
|
| 47 | + protected $_timezone; |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * date format |
|
| 53 | + * pattern or format for displaying dates |
|
| 54 | + * |
|
| 55 | + * @var string $_dt_frmt |
|
| 56 | + */ |
|
| 57 | + protected $_dt_frmt; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * time format |
|
| 63 | + * pattern or format for displaying time |
|
| 64 | + * |
|
| 65 | + * @var string $_tm_frmt |
|
| 66 | + */ |
|
| 67 | + protected $_tm_frmt; |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 73 | + * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 74 | + * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 75 | + * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 76 | + * |
|
| 77 | + * @var array |
|
| 78 | + */ |
|
| 79 | + protected $_cached_properties = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 83 | + * single |
|
| 84 | + * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 85 | + * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 86 | + * all others have an array) |
|
| 87 | + * |
|
| 88 | + * @var array |
|
| 89 | + */ |
|
| 90 | + protected $_model_relations = array(); |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 94 | + * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 95 | + * |
|
| 96 | + * @var array |
|
| 97 | + */ |
|
| 98 | + protected $_fields = array(); |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 102 | + * For example, we might create model objects intended to only be used for the duration |
|
| 103 | + * of this request and to be thrown away, and if they were accidentally saved |
|
| 104 | + * it would be a bug. |
|
| 105 | + */ |
|
| 106 | + protected $_allow_persist = true; |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 112 | + * play nice |
|
| 113 | + * |
|
| 114 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 115 | + * layer of the model's _fields array, (eg, EVT_ID, |
|
| 116 | + * TXN_amount, QST_name, etc) and values are their values |
|
| 117 | + * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 118 | + * corresponding db model or not. |
|
| 119 | + * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 120 | + * be in when instantiating a EE_Base_Class object. |
|
| 121 | + * @param array $date_formats An array of date formats to set on construct where first |
|
| 122 | + * value is the date_format and second value is the time |
|
| 123 | + * format. |
|
| 124 | + * @throws EE_Error |
|
| 125 | + */ |
|
| 126 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '', $date_formats = array()) |
|
| 127 | + { |
|
| 128 | + $className = get_class($this); |
|
| 129 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 130 | + $model = $this->get_model(); |
|
| 131 | + $model_fields = $model->field_settings(false); |
|
| 132 | + // ensure $fieldValues is an array |
|
| 133 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 134 | + // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 135 | + // verify client code has not passed any invalid field names |
|
| 136 | + foreach ($fieldValues as $field_name => $field_value) { |
|
| 137 | + if ( ! isset($model_fields[$field_name])) { |
|
| 138 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 139 | + "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 143 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 144 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 145 | + list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 146 | + } else { |
|
| 147 | + //set default formats for date and time |
|
| 148 | + $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 149 | + $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 150 | + } |
|
| 151 | + //if db model is instantiating |
|
| 152 | + if ($bydb) { |
|
| 153 | + //client code has indicated these field values are from the database |
|
| 154 | + foreach ($model_fields as $fieldName => $field) { |
|
| 155 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 156 | + } |
|
| 157 | + } else { |
|
| 158 | + //we're constructing a brand |
|
| 159 | + //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 160 | + foreach ($model_fields as $fieldName => $field) { |
|
| 161 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + //remember what values were passed to this constructor |
|
| 165 | + $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 166 | + //remember in entity mapper |
|
| 167 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 168 | + $model->add_to_entity_map($this); |
|
| 169 | + } |
|
| 170 | + //setup all the relations |
|
| 171 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 172 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 173 | + $this->_model_relations[$relation_name] = null; |
|
| 174 | + } else { |
|
| 175 | + $this->_model_relations[$relation_name] = array(); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + /** |
|
| 179 | + * Action done at the end of each model object construction |
|
| 180 | + * |
|
| 181 | + * @param EE_Base_Class $this the model object just created |
|
| 182 | + */ |
|
| 183 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 190 | + * |
|
| 191 | + * @return boolean |
|
| 192 | + */ |
|
| 193 | + public function allow_persist() |
|
| 194 | + { |
|
| 195 | + return $this->_allow_persist; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 202 | + * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 203 | + * you got new information that somehow made you change your mind. |
|
| 204 | + * |
|
| 205 | + * @param boolean $allow_persist |
|
| 206 | + * @return boolean |
|
| 207 | + */ |
|
| 208 | + public function set_allow_persist($allow_persist) |
|
| 209 | + { |
|
| 210 | + return $this->_allow_persist = $allow_persist; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Gets the field's original value when this object was constructed during this request. |
|
| 217 | + * This can be helpful when determining if a model object has changed or not |
|
| 218 | + * |
|
| 219 | + * @param string $field_name |
|
| 220 | + * @return mixed|null |
|
| 221 | + * @throws \EE_Error |
|
| 222 | + */ |
|
| 223 | + public function get_original($field_name) |
|
| 224 | + { |
|
| 225 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 226 | + && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 227 | + ) { |
|
| 228 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 229 | + } else { |
|
| 230 | + return null; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param EE_Base_Class $obj |
|
| 238 | + * @return string |
|
| 239 | + */ |
|
| 240 | + public function get_class($obj) |
|
| 241 | + { |
|
| 242 | + return get_class($obj); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Overrides parent because parent expects old models. |
|
| 249 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 250 | + * |
|
| 251 | + * @param string $field_name |
|
| 252 | + * @param mixed $field_value |
|
| 253 | + * @param bool $use_default |
|
| 254 | + * @throws \EE_Error |
|
| 255 | + */ |
|
| 256 | + public function set($field_name, $field_value, $use_default = false) |
|
| 257 | + { |
|
| 258 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 259 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 260 | + // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 261 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 262 | + $field_obj->set_timezone($this->_timezone); |
|
| 263 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 264 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 265 | + } |
|
| 266 | + $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 267 | + //should the value be null? |
|
| 268 | + if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 269 | + $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 270 | + /** |
|
| 271 | + * To save having to refactor all the models, if a default value is used for a |
|
| 272 | + * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 273 | + * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 274 | + * object. |
|
| 275 | + * |
|
| 276 | + * @since 4.6.10+ |
|
| 277 | + */ |
|
| 278 | + if ( |
|
| 279 | + $field_obj instanceof EE_Datetime_Field |
|
| 280 | + && $this->_fields[$field_name] !== null |
|
| 281 | + && ! $this->_fields[$field_name] instanceof DateTime |
|
| 282 | + ) { |
|
| 283 | + empty($this->_fields[$field_name]) |
|
| 284 | + ? $this->set($field_name, time()) |
|
| 285 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
| 286 | + } |
|
| 287 | + } else { |
|
| 288 | + $this->_fields[$field_name] = $holder_of_value; |
|
| 289 | + } |
|
| 290 | + //if we're not in the constructor... |
|
| 291 | + //now check if what we set was a primary key |
|
| 292 | + if ( |
|
| 293 | + //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 294 | + $this->_props_n_values_provided_in_constructor |
|
| 295 | + && $field_value |
|
| 296 | + && $field_name === self::_get_primary_key_name(get_class($this)) |
|
| 297 | + ) { |
|
| 298 | + //if so, we want all this object's fields to be filled either with |
|
| 299 | + //what we've explicitly set on this model |
|
| 300 | + //or what we have in the db |
|
| 301 | + // echo "setting primary key!"; |
|
| 302 | + $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 303 | + $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 304 | + foreach ($fields_on_model as $field_obj) { |
|
| 305 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 306 | + && $field_obj->get_name() !== $field_name |
|
| 307 | + ) { |
|
| 308 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + //oh this model object has an ID? well make sure its in the entity mapper |
|
| 312 | + $this->get_model()->add_to_entity_map($this); |
|
| 313 | + } |
|
| 314 | + //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 315 | + $this->_clear_cached_property($field_name); |
|
| 316 | + } else { |
|
| 317 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 318 | + "event_espresso"), $field_name)); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * This sets the field value on the db column if it exists for the given $column_name or |
|
| 326 | + * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 327 | + * |
|
| 328 | + * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 329 | + * @param string $field_name Must be the exact column name. |
|
| 330 | + * @param mixed $field_value The value to set. |
|
| 331 | + * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 332 | + * @throws \EE_Error |
|
| 333 | + */ |
|
| 334 | + public function set_field_or_extra_meta($field_name, $field_value) |
|
| 335 | + { |
|
| 336 | + if ($this->get_model()->has_field($field_name)) { |
|
| 337 | + $this->set($field_name, $field_value); |
|
| 338 | + return true; |
|
| 339 | + } else { |
|
| 340 | + //ensure this object is saved first so that extra meta can be properly related. |
|
| 341 | + $this->save(); |
|
| 342 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * This retrieves the value of the db column set on this class or if that's not present |
|
| 350 | + * it will attempt to retrieve from extra_meta if found. |
|
| 351 | + * Example Usage: |
|
| 352 | + * Via EE_Message child class: |
|
| 353 | + * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 354 | + * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 355 | + * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 356 | + * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 357 | + * value for those extra fields dynamically via the EE_message object. |
|
| 358 | + * |
|
| 359 | + * @param string $field_name expecting the fully qualified field name. |
|
| 360 | + * @return mixed|null value for the field if found. null if not found. |
|
| 361 | + * @throws \EE_Error |
|
| 362 | + */ |
|
| 363 | + public function get_field_or_extra_meta($field_name) |
|
| 364 | + { |
|
| 365 | + if ($this->get_model()->has_field($field_name)) { |
|
| 366 | + $column_value = $this->get($field_name); |
|
| 367 | + } else { |
|
| 368 | + //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 369 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 370 | + } |
|
| 371 | + return $column_value; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 378 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 379 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 380 | + * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 381 | + * |
|
| 382 | + * @access public |
|
| 383 | + * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 384 | + * @return void |
|
| 385 | + * @throws \EE_Error |
|
| 386 | + */ |
|
| 387 | + public function set_timezone($timezone = '') |
|
| 388 | + { |
|
| 389 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 390 | + //make sure we clear all cached properties because they won't be relevant now |
|
| 391 | + $this->_clear_cached_properties(); |
|
| 392 | + //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 393 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 394 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 395 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 396 | + $field_obj->set_timezone($this->_timezone); |
|
| 397 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 398 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * This just returns whatever is set for the current timezone. |
|
| 408 | + * |
|
| 409 | + * @access public |
|
| 410 | + * @return string timezone string |
|
| 411 | + */ |
|
| 412 | + public function get_timezone() |
|
| 413 | + { |
|
| 414 | + return $this->_timezone; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 421 | + * internally instead of wp set date format options |
|
| 422 | + * |
|
| 423 | + * @since 4.6 |
|
| 424 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 425 | + */ |
|
| 426 | + public function set_date_format($format) |
|
| 427 | + { |
|
| 428 | + $this->_dt_frmt = $format; |
|
| 429 | + //clear cached_properties because they won't be relevant now. |
|
| 430 | + $this->_clear_cached_properties(); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 437 | + * class internally instead of wp set time format options. |
|
| 438 | + * |
|
| 439 | + * @since 4.6 |
|
| 440 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 441 | + */ |
|
| 442 | + public function set_time_format($format) |
|
| 443 | + { |
|
| 444 | + $this->_tm_frmt = $format; |
|
| 445 | + //clear cached_properties because they won't be relevant now. |
|
| 446 | + $this->_clear_cached_properties(); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * This returns the current internal set format for the date and time formats. |
|
| 453 | + * |
|
| 454 | + * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 455 | + * where the first value is the date format and the second value is the time format. |
|
| 456 | + * @return mixed string|array |
|
| 457 | + */ |
|
| 458 | + public function get_format($full = true) |
|
| 459 | + { |
|
| 460 | + return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * cache |
|
| 467 | + * stores the passed model object on the current model object. |
|
| 468 | + * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 469 | + * |
|
| 470 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 471 | + * 'Registration' associated with this model object |
|
| 472 | + * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 473 | + * that could be a payment or a registration) |
|
| 474 | + * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 475 | + * items which will be stored in an array on this object |
|
| 476 | + * @throws EE_Error |
|
| 477 | + * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 478 | + * related thing, no array) |
|
| 479 | + */ |
|
| 480 | + public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 481 | + { |
|
| 482 | + // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 483 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 484 | + return false; |
|
| 485 | + } |
|
| 486 | + // also get "how" the object is related, or throw an error |
|
| 487 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 488 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 489 | + $relationName, get_class($this))); |
|
| 490 | + } |
|
| 491 | + // how many things are related ? |
|
| 492 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 493 | + // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
|
| 494 | + // so for these model objects just set it to be cached |
|
| 495 | + $this->_model_relations[$relationName] = $object_to_cache; |
|
| 496 | + $return = true; |
|
| 497 | + } else { |
|
| 498 | + // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
|
| 499 | + // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 500 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 501 | + // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 502 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 503 | + ? array($this->_model_relations[$relationName]) : array(); |
|
| 504 | + } |
|
| 505 | + // first check for a cache_id which is normally empty |
|
| 506 | + if ( ! empty($cache_id)) { |
|
| 507 | + // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
|
| 508 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 509 | + $return = $cache_id; |
|
| 510 | + } elseif ($object_to_cache->ID()) { |
|
| 511 | + // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 512 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 513 | + $return = $object_to_cache->ID(); |
|
| 514 | + } else { |
|
| 515 | + // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 516 | + $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 517 | + // move the internal pointer to the end of the array |
|
| 518 | + end($this->_model_relations[$relationName]); |
|
| 519 | + // and grab the key so that we can return it |
|
| 520 | + $return = key($this->_model_relations[$relationName]); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + return $return; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * For adding an item to the cached_properties property. |
|
| 530 | + * |
|
| 531 | + * @access protected |
|
| 532 | + * @param string $fieldname the property item the corresponding value is for. |
|
| 533 | + * @param mixed $value The value we are caching. |
|
| 534 | + * @param string|null $cache_type |
|
| 535 | + * @return void |
|
| 536 | + * @throws \EE_Error |
|
| 537 | + */ |
|
| 538 | + protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 539 | + { |
|
| 540 | + //first make sure this property exists |
|
| 541 | + $this->get_model()->field_settings_for($fieldname); |
|
| 542 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 543 | + $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 550 | + * This also SETS the cache if we return the actual property! |
|
| 551 | + * |
|
| 552 | + * @param string $fieldname the name of the property we're trying to retrieve |
|
| 553 | + * @param bool $pretty |
|
| 554 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 555 | + * (in cases where the same property may be used for different outputs |
|
| 556 | + * - i.e. datetime, money etc.) |
|
| 557 | + * It can also accept certain pre-defined "schema" strings |
|
| 558 | + * to define how to output the property. |
|
| 559 | + * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 560 | + * @return mixed whatever the value for the property is we're retrieving |
|
| 561 | + * @throws \EE_Error |
|
| 562 | + */ |
|
| 563 | + protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 564 | + { |
|
| 565 | + //verify the field exists |
|
| 566 | + $this->get_model()->field_settings_for($fieldname); |
|
| 567 | + $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 568 | + $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 569 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 570 | + return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 571 | + } |
|
| 572 | + $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 573 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 574 | + // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 575 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 576 | + $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 577 | + } |
|
| 578 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 579 | + $this->_fields[$fieldname] = null; |
|
| 580 | + } |
|
| 581 | + $value = $pretty |
|
| 582 | + ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 583 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 584 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 585 | + return $value; |
|
| 586 | + } |
|
| 587 | + return null; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 594 | + * |
|
| 595 | + * @param \EE_Datetime_Field $datetime_field |
|
| 596 | + * @param bool $pretty |
|
| 597 | + * @param null $date_or_time |
|
| 598 | + * @return void |
|
| 599 | + * @throws \EE_Error |
|
| 600 | + */ |
|
| 601 | + protected function _prepare_datetime_field( |
|
| 602 | + EE_Datetime_Field $datetime_field, |
|
| 603 | + $pretty = false, |
|
| 604 | + $date_or_time = null |
|
| 605 | + ) { |
|
| 606 | + $datetime_field->set_timezone($this->_timezone); |
|
| 607 | + $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 608 | + $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 609 | + //set the output returned |
|
| 610 | + switch ($date_or_time) { |
|
| 611 | + case 'D' : |
|
| 612 | + $datetime_field->set_date_time_output('date'); |
|
| 613 | + break; |
|
| 614 | + case 'T' : |
|
| 615 | + $datetime_field->set_date_time_output('time'); |
|
| 616 | + break; |
|
| 617 | + default : |
|
| 618 | + $datetime_field->set_date_time_output(); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * This just takes care of clearing out the cached_properties |
|
| 626 | + * |
|
| 627 | + * @return void |
|
| 628 | + */ |
|
| 629 | + protected function _clear_cached_properties() |
|
| 630 | + { |
|
| 631 | + $this->_cached_properties = array(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + |
|
| 635 | + |
|
| 636 | + /** |
|
| 637 | + * This just clears out ONE property if it exists in the cache |
|
| 638 | + * |
|
| 639 | + * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 640 | + * @return void |
|
| 641 | + */ |
|
| 642 | + protected function _clear_cached_property($property_name) |
|
| 643 | + { |
|
| 644 | + if (isset($this->_cached_properties[$property_name])) { |
|
| 645 | + unset($this->_cached_properties[$property_name]); |
|
| 646 | + } |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * Ensures that this related thing is a model object. |
|
| 653 | + * |
|
| 654 | + * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 655 | + * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 656 | + * @return EE_Base_Class |
|
| 657 | + * @throws \EE_Error |
|
| 658 | + */ |
|
| 659 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 660 | + { |
|
| 661 | + $other_model_instance = self::_get_model_instance_with_name( |
|
| 662 | + self::_get_model_classname($model_name), |
|
| 663 | + $this->_timezone |
|
| 664 | + ); |
|
| 665 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 672 | + * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 673 | + * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 674 | + * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 675 | + * |
|
| 676 | + * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 677 | + * Eg 'Registration' |
|
| 678 | + * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 679 | + * if you intend to use $clear_all = TRUE, or the relation only |
|
| 680 | + * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 681 | + * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 682 | + * this is HasMany or HABTM. |
|
| 683 | + * @throws EE_Error |
|
| 684 | + * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 685 | + * relation from all |
|
| 686 | + */ |
|
| 687 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 688 | + { |
|
| 689 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 690 | + $index_in_cache = ''; |
|
| 691 | + if ( ! $relationship_to_model) { |
|
| 692 | + throw new EE_Error( |
|
| 693 | + sprintf( |
|
| 694 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 695 | + $relationName, |
|
| 696 | + get_class($this) |
|
| 697 | + ) |
|
| 698 | + ); |
|
| 699 | + } |
|
| 700 | + if ($clear_all) { |
|
| 701 | + $obj_removed = true; |
|
| 702 | + $this->_model_relations[$relationName] = null; |
|
| 703 | + } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 704 | + $obj_removed = $this->_model_relations[$relationName]; |
|
| 705 | + $this->_model_relations[$relationName] = null; |
|
| 706 | + } else { |
|
| 707 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 708 | + && $object_to_remove_or_index_into_array->ID() |
|
| 709 | + ) { |
|
| 710 | + $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 711 | + if (is_array($this->_model_relations[$relationName]) |
|
| 712 | + && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 713 | + ) { |
|
| 714 | + $index_found_at = null; |
|
| 715 | + //find this object in the array even though it has a different key |
|
| 716 | + foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 717 | + if ( |
|
| 718 | + $obj instanceof EE_Base_Class |
|
| 719 | + && ( |
|
| 720 | + $obj == $object_to_remove_or_index_into_array |
|
| 721 | + || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 722 | + ) |
|
| 723 | + ) { |
|
| 724 | + $index_found_at = $index; |
|
| 725 | + break; |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + if ($index_found_at) { |
|
| 729 | + $index_in_cache = $index_found_at; |
|
| 730 | + } else { |
|
| 731 | + //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 732 | + //if it wasn't in it to begin with. So we're done |
|
| 733 | + return $object_to_remove_or_index_into_array; |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 737 | + //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 738 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 739 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 740 | + $index_in_cache = $index; |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + } else { |
|
| 744 | + $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 745 | + } |
|
| 746 | + //supposedly we've found it. But it could just be that the client code |
|
| 747 | + //provided a bad index/object |
|
| 748 | + if ( |
|
| 749 | + isset( |
|
| 750 | + $this->_model_relations[$relationName], |
|
| 751 | + $this->_model_relations[$relationName][$index_in_cache] |
|
| 752 | + ) |
|
| 753 | + ) { |
|
| 754 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 755 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 756 | + } else { |
|
| 757 | + //that thing was never cached anyways. |
|
| 758 | + $obj_removed = null; |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $obj_removed; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * update_cache_after_object_save |
|
| 768 | + * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 769 | + * obtained after being saved to the db |
|
| 770 | + * |
|
| 771 | + * @param string $relationName - the type of object that is cached |
|
| 772 | + * @param \EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 773 | + * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 774 | + * @return boolean TRUE on success, FALSE on fail |
|
| 775 | + * @throws \EE_Error |
|
| 776 | + */ |
|
| 777 | + public function update_cache_after_object_save( |
|
| 778 | + $relationName, |
|
| 779 | + EE_Base_Class $newly_saved_object, |
|
| 780 | + $current_cache_id = '' |
|
| 781 | + ) { |
|
| 782 | + // verify that incoming object is of the correct type |
|
| 783 | + $obj_class = 'EE_' . $relationName; |
|
| 784 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 785 | + /* @type EE_Base_Class $newly_saved_object */ |
|
| 786 | + // now get the type of relation |
|
| 787 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 788 | + // if this is a 1:1 relationship |
|
| 789 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 790 | + // then just replace the cached object with the newly saved object |
|
| 791 | + $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 792 | + return true; |
|
| 793 | + // or if it's some kind of sordid feral polyamorous relationship... |
|
| 794 | + } elseif (is_array($this->_model_relations[$relationName]) |
|
| 795 | + && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 796 | + ) { |
|
| 797 | + // then remove the current cached item |
|
| 798 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 799 | + // and cache the newly saved object using it's new ID |
|
| 800 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 801 | + return true; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 811 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 812 | + * |
|
| 813 | + * @param string $relationName |
|
| 814 | + * @return EE_Base_Class |
|
| 815 | + */ |
|
| 816 | + public function get_one_from_cache($relationName) |
|
| 817 | + { |
|
| 818 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 819 | + : null; |
|
| 820 | + if (is_array($cached_array_or_object)) { |
|
| 821 | + return array_shift($cached_array_or_object); |
|
| 822 | + } else { |
|
| 823 | + return $cached_array_or_object; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 831 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 832 | + * |
|
| 833 | + * @param string $relationName |
|
| 834 | + * @throws \EE_Error |
|
| 835 | + * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 836 | + */ |
|
| 837 | + public function get_all_from_cache($relationName) |
|
| 838 | + { |
|
| 839 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 840 | + // if the result is not an array, but exists, make it an array |
|
| 841 | + $objects = is_array($objects) ? $objects : array($objects); |
|
| 842 | + //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 843 | + //basically, if this model object was stored in the session, and these cached model objects |
|
| 844 | + //already have IDs, let's make sure they're in their model's entity mapper |
|
| 845 | + //otherwise we will have duplicates next time we call |
|
| 846 | + // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 847 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 848 | + foreach ($objects as $model_object) { |
|
| 849 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 850 | + //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 851 | + if ($model_object->ID()) { |
|
| 852 | + $model->add_to_entity_map($model_object); |
|
| 853 | + } |
|
| 854 | + } else { |
|
| 855 | + throw new EE_Error( |
|
| 856 | + sprintf( |
|
| 857 | + __( |
|
| 858 | + 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 859 | + 'event_espresso' |
|
| 860 | + ), |
|
| 861 | + $relationName, |
|
| 862 | + gettype($model_object) |
|
| 863 | + ) |
|
| 864 | + ); |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + return $objects; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 874 | + * matching the given query conditions. |
|
| 875 | + * |
|
| 876 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 877 | + * @param int $limit How many objects to return. |
|
| 878 | + * @param array $query_params Any additional conditions on the query. |
|
| 879 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 880 | + * you can indicate just the columns you want returned |
|
| 881 | + * @return array|EE_Base_Class[] |
|
| 882 | + * @throws \EE_Error |
|
| 883 | + */ |
|
| 884 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 885 | + { |
|
| 886 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 887 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 888 | + : $field_to_order_by; |
|
| 889 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 890 | + if (empty($field) || empty($current_value)) { |
|
| 891 | + return array(); |
|
| 892 | + } |
|
| 893 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /** |
|
| 899 | + * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 900 | + * matching the given query conditions. |
|
| 901 | + * |
|
| 902 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 903 | + * @param int $limit How many objects to return. |
|
| 904 | + * @param array $query_params Any additional conditions on the query. |
|
| 905 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 906 | + * you can indicate just the columns you want returned |
|
| 907 | + * @return array|EE_Base_Class[] |
|
| 908 | + * @throws \EE_Error |
|
| 909 | + */ |
|
| 910 | + public function previous_x( |
|
| 911 | + $field_to_order_by = null, |
|
| 912 | + $limit = 1, |
|
| 913 | + $query_params = array(), |
|
| 914 | + $columns_to_select = null |
|
| 915 | + ) { |
|
| 916 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 917 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 918 | + : $field_to_order_by; |
|
| 919 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 920 | + if (empty($field) || empty($current_value)) { |
|
| 921 | + return array(); |
|
| 922 | + } |
|
| 923 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + /** |
|
| 929 | + * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 930 | + * matching the given query conditions. |
|
| 931 | + * |
|
| 932 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 933 | + * @param array $query_params Any additional conditions on the query. |
|
| 934 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 935 | + * you can indicate just the columns you want returned |
|
| 936 | + * @return array|EE_Base_Class |
|
| 937 | + * @throws \EE_Error |
|
| 938 | + */ |
|
| 939 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 940 | + { |
|
| 941 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 942 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 943 | + : $field_to_order_by; |
|
| 944 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 945 | + if (empty($field) || empty($current_value)) { |
|
| 946 | + return array(); |
|
| 947 | + } |
|
| 948 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 955 | + * matching the given query conditions. |
|
| 956 | + * |
|
| 957 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 958 | + * @param array $query_params Any additional conditions on the query. |
|
| 959 | + * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 960 | + * you can indicate just the column you want returned |
|
| 961 | + * @return array|EE_Base_Class |
|
| 962 | + * @throws \EE_Error |
|
| 963 | + */ |
|
| 964 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 965 | + { |
|
| 966 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() |
|
| 967 | + ? $this->get_model()->get_primary_key_field()->get_name() |
|
| 968 | + : $field_to_order_by; |
|
| 969 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 970 | + if (empty($field) || empty($current_value)) { |
|
| 971 | + return array(); |
|
| 972 | + } |
|
| 973 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 974 | + } |
|
| 975 | + |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + /** |
|
| 979 | + * Overrides parent because parent expects old models. |
|
| 980 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 981 | + * |
|
| 982 | + * @param string $field_name |
|
| 983 | + * @param mixed $field_value_from_db |
|
| 984 | + * @throws \EE_Error |
|
| 985 | + */ |
|
| 986 | + public function set_from_db($field_name, $field_value_from_db) |
|
| 987 | + { |
|
| 988 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 989 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 990 | + //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 991 | + //eg, a CPT model object could have an entry in the posts table, but no |
|
| 992 | + //entry in the meta table. Meaning that all its columns in the meta table |
|
| 993 | + //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 994 | + if ($field_value_from_db === null) { |
|
| 995 | + if ($field_obj->is_nullable()) { |
|
| 996 | + //if the field allows nulls, then let it be null |
|
| 997 | + $field_value = null; |
|
| 998 | + } else { |
|
| 999 | + $field_value = $field_obj->get_default_value(); |
|
| 1000 | + } |
|
| 1001 | + } else { |
|
| 1002 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1003 | + } |
|
| 1004 | + $this->_fields[$field_name] = $field_value; |
|
| 1005 | + $this->_clear_cached_property($field_name); |
|
| 1006 | + } |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * verifies that the specified field is of the correct type |
|
| 1013 | + * |
|
| 1014 | + * @param string $field_name |
|
| 1015 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1016 | + * (in cases where the same property may be used for different outputs |
|
| 1017 | + * - i.e. datetime, money etc.) |
|
| 1018 | + * @return mixed |
|
| 1019 | + * @throws \EE_Error |
|
| 1020 | + */ |
|
| 1021 | + public function get($field_name, $extra_cache_ref = null) |
|
| 1022 | + { |
|
| 1023 | + return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1030 | + * |
|
| 1031 | + * @param string $field_name A valid fieldname |
|
| 1032 | + * @return mixed Whatever the raw value stored on the property is. |
|
| 1033 | + * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1034 | + */ |
|
| 1035 | + public function get_raw($field_name) |
|
| 1036 | + { |
|
| 1037 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1038 | + return $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime |
|
| 1039 | + ? $this->_fields[$field_name]->format('U') |
|
| 1040 | + : $this->_fields[$field_name]; |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * This is used to return the internal DateTime object used for a field that is a |
|
| 1047 | + * EE_Datetime_Field. |
|
| 1048 | + * |
|
| 1049 | + * @param string $field_name The field name retrieving the DateTime object. |
|
| 1050 | + * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1051 | + * @throws \EE_Error |
|
| 1052 | + * an error is set and false returned. If the field IS an |
|
| 1053 | + * EE_Datetime_Field and but the field value is null, then |
|
| 1054 | + * just null is returned (because that indicates that likely |
|
| 1055 | + * this field is nullable). |
|
| 1056 | + */ |
|
| 1057 | + public function get_DateTime_object($field_name) |
|
| 1058 | + { |
|
| 1059 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1060 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1061 | + EE_Error::add_error( |
|
| 1062 | + sprintf( |
|
| 1063 | + __( |
|
| 1064 | + 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1065 | + 'event_espresso' |
|
| 1066 | + ), |
|
| 1067 | + $field_name |
|
| 1068 | + ), |
|
| 1069 | + __FILE__, |
|
| 1070 | + __FUNCTION__, |
|
| 1071 | + __LINE__ |
|
| 1072 | + ); |
|
| 1073 | + return false; |
|
| 1074 | + } |
|
| 1075 | + return $this->_fields[$field_name]; |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + |
|
| 1079 | + |
|
| 1080 | + /** |
|
| 1081 | + * To be used in template to immediately echo out the value, and format it for output. |
|
| 1082 | + * Eg, should call stripslashes and whatnot before echoing |
|
| 1083 | + * |
|
| 1084 | + * @param string $field_name the name of the field as it appears in the DB |
|
| 1085 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1086 | + * (in cases where the same property may be used for different outputs |
|
| 1087 | + * - i.e. datetime, money etc.) |
|
| 1088 | + * @return void |
|
| 1089 | + * @throws \EE_Error |
|
| 1090 | + */ |
|
| 1091 | + public function e($field_name, $extra_cache_ref = null) |
|
| 1092 | + { |
|
| 1093 | + echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + |
|
| 1097 | + |
|
| 1098 | + /** |
|
| 1099 | + * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1100 | + * can be easily used as the value of form input. |
|
| 1101 | + * |
|
| 1102 | + * @param string $field_name |
|
| 1103 | + * @return void |
|
| 1104 | + * @throws \EE_Error |
|
| 1105 | + */ |
|
| 1106 | + public function f($field_name) |
|
| 1107 | + { |
|
| 1108 | + $this->e($field_name, 'form_input'); |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + |
|
| 1113 | + /** |
|
| 1114 | + * @param string $field_name |
|
| 1115 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1116 | + * (in cases where the same property may be used for different outputs |
|
| 1117 | + * - i.e. datetime, money etc.) |
|
| 1118 | + * @return mixed |
|
| 1119 | + * @throws \EE_Error |
|
| 1120 | + */ |
|
| 1121 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1122 | + { |
|
| 1123 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + /** |
|
| 1129 | + * This simply returns the datetime for the given field name |
|
| 1130 | + * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1131 | + * (and the equivalent e_date, e_time, e_datetime). |
|
| 1132 | + * |
|
| 1133 | + * @access protected |
|
| 1134 | + * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1135 | + * @param string $dt_frmt valid datetime format used for date |
|
| 1136 | + * (if '' then we just use the default on the field, |
|
| 1137 | + * if NULL we use the last-used format) |
|
| 1138 | + * @param string $tm_frmt Same as above except this is for time format |
|
| 1139 | + * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1140 | + * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1141 | + * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1142 | + * if field is not a valid dtt field, or void if echoing |
|
| 1143 | + * @throws \EE_Error |
|
| 1144 | + */ |
|
| 1145 | + protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1146 | + { |
|
| 1147 | + // clear cached property |
|
| 1148 | + $this->_clear_cached_property($field_name); |
|
| 1149 | + //reset format properties because they are used in get() |
|
| 1150 | + $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1151 | + $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1152 | + if ($echo) { |
|
| 1153 | + $this->e($field_name, $date_or_time); |
|
| 1154 | + return ''; |
|
| 1155 | + } |
|
| 1156 | + return $this->get($field_name, $date_or_time); |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + |
|
| 1161 | + /** |
|
| 1162 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1163 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1164 | + * other echoes the pretty value for dtt) |
|
| 1165 | + * |
|
| 1166 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1167 | + * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1168 | + * @return string datetime value formatted |
|
| 1169 | + * @throws \EE_Error |
|
| 1170 | + */ |
|
| 1171 | + public function get_date($field_name, $format = '') |
|
| 1172 | + { |
|
| 1173 | + return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + |
|
| 1178 | + /** |
|
| 1179 | + * @param $field_name |
|
| 1180 | + * @param string $format |
|
| 1181 | + * @throws \EE_Error |
|
| 1182 | + */ |
|
| 1183 | + public function e_date($field_name, $format = '') |
|
| 1184 | + { |
|
| 1185 | + $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + |
|
| 1189 | + |
|
| 1190 | + /** |
|
| 1191 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1192 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1193 | + * other echoes the pretty value for dtt) |
|
| 1194 | + * |
|
| 1195 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1196 | + * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1197 | + * @return string datetime value formatted |
|
| 1198 | + * @throws \EE_Error |
|
| 1199 | + */ |
|
| 1200 | + public function get_time($field_name, $format = '') |
|
| 1201 | + { |
|
| 1202 | + return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + |
|
| 1207 | + /** |
|
| 1208 | + * @param $field_name |
|
| 1209 | + * @param string $format |
|
| 1210 | + * @throws \EE_Error |
|
| 1211 | + */ |
|
| 1212 | + public function e_time($field_name, $format = '') |
|
| 1213 | + { |
|
| 1214 | + $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + |
|
| 1218 | + |
|
| 1219 | + /** |
|
| 1220 | + * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1221 | + * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1222 | + * other echoes the pretty value for dtt) |
|
| 1223 | + * |
|
| 1224 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1225 | + * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1226 | + * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1227 | + * @return string datetime value formatted |
|
| 1228 | + * @throws \EE_Error |
|
| 1229 | + */ |
|
| 1230 | + public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1231 | + { |
|
| 1232 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * @param string $field_name |
|
| 1239 | + * @param string $dt_frmt |
|
| 1240 | + * @param string $tm_frmt |
|
| 1241 | + * @throws \EE_Error |
|
| 1242 | + */ |
|
| 1243 | + public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1244 | + { |
|
| 1245 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + |
|
| 1249 | + |
|
| 1250 | + /** |
|
| 1251 | + * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1252 | + * |
|
| 1253 | + * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1254 | + * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1255 | + * on the object will be used. |
|
| 1256 | + * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1257 | + * @throws \EE_Error |
|
| 1258 | + * field name. |
|
| 1259 | + */ |
|
| 1260 | + public function get_i18n_datetime($field_name, $format = '') |
|
| 1261 | + { |
|
| 1262 | + $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1263 | + return date_i18n( |
|
| 1264 | + $format, |
|
| 1265 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1266 | + ); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + |
|
| 1270 | + |
|
| 1271 | + /** |
|
| 1272 | + * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1273 | + * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1274 | + * thrown. |
|
| 1275 | + * |
|
| 1276 | + * @param string $field_name The field name being checked |
|
| 1277 | + * @throws EE_Error |
|
| 1278 | + * @return EE_Datetime_Field |
|
| 1279 | + */ |
|
| 1280 | + protected function _get_dtt_field_settings($field_name) |
|
| 1281 | + { |
|
| 1282 | + $field = $this->get_model()->field_settings_for($field_name); |
|
| 1283 | + //check if field is dtt |
|
| 1284 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1285 | + return $field; |
|
| 1286 | + } else { |
|
| 1287 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', |
|
| 1288 | + 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + |
|
| 1295 | + /** |
|
| 1296 | + * NOTE ABOUT BELOW: |
|
| 1297 | + * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1298 | + * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1299 | + * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1300 | + * method and make sure you send the entire datetime value for setting. |
|
| 1301 | + */ |
|
| 1302 | + /** |
|
| 1303 | + * sets the time on a datetime property |
|
| 1304 | + * |
|
| 1305 | + * @access protected |
|
| 1306 | + * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1307 | + * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1308 | + * @throws \EE_Error |
|
| 1309 | + */ |
|
| 1310 | + protected function _set_time_for($time, $fieldname) |
|
| 1311 | + { |
|
| 1312 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * sets the date on a datetime property |
|
| 1319 | + * |
|
| 1320 | + * @access protected |
|
| 1321 | + * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1322 | + * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1323 | + * @throws \EE_Error |
|
| 1324 | + */ |
|
| 1325 | + protected function _set_date_for($date, $fieldname) |
|
| 1326 | + { |
|
| 1327 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1334 | + * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1335 | + * |
|
| 1336 | + * @access protected |
|
| 1337 | + * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1338 | + * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1339 | + * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1340 | + * EE_Datetime_Field property) |
|
| 1341 | + * @throws \EE_Error |
|
| 1342 | + */ |
|
| 1343 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1344 | + { |
|
| 1345 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1346 | + $field->set_timezone($this->_timezone); |
|
| 1347 | + $field->set_date_format($this->_dt_frmt); |
|
| 1348 | + $field->set_time_format($this->_tm_frmt); |
|
| 1349 | + switch ($what) { |
|
| 1350 | + case 'T' : |
|
| 1351 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1352 | + $datetime_value, |
|
| 1353 | + $this->_fields[$fieldname] |
|
| 1354 | + ); |
|
| 1355 | + break; |
|
| 1356 | + case 'D' : |
|
| 1357 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1358 | + $datetime_value, |
|
| 1359 | + $this->_fields[$fieldname] |
|
| 1360 | + ); |
|
| 1361 | + break; |
|
| 1362 | + case 'B' : |
|
| 1363 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1364 | + break; |
|
| 1365 | + } |
|
| 1366 | + $this->_clear_cached_property($fieldname); |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + |
|
| 1370 | + |
|
| 1371 | + /** |
|
| 1372 | + * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1373 | + * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1374 | + * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1375 | + * that could lead to some unexpected results! |
|
| 1376 | + * |
|
| 1377 | + * @access public |
|
| 1378 | + * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1379 | + * value being returned. |
|
| 1380 | + * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1381 | + * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1382 | + * @param string $prepend You can include something to prepend on the timestamp |
|
| 1383 | + * @param string $append You can include something to append on the timestamp |
|
| 1384 | + * @throws EE_Error |
|
| 1385 | + * @return string timestamp |
|
| 1386 | + */ |
|
| 1387 | + public function display_in_my_timezone( |
|
| 1388 | + $field_name, |
|
| 1389 | + $callback = 'get_datetime', |
|
| 1390 | + $args = null, |
|
| 1391 | + $prepend = '', |
|
| 1392 | + $append = '' |
|
| 1393 | + ) { |
|
| 1394 | + $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1395 | + if ($timezone === $this->_timezone) { |
|
| 1396 | + return ''; |
|
| 1397 | + } |
|
| 1398 | + $original_timezone = $this->_timezone; |
|
| 1399 | + $this->set_timezone($timezone); |
|
| 1400 | + $fn = (array)$field_name; |
|
| 1401 | + $args = array_merge($fn, (array)$args); |
|
| 1402 | + if ( ! method_exists($this, $callback)) { |
|
| 1403 | + throw new EE_Error( |
|
| 1404 | + sprintf( |
|
| 1405 | + __( |
|
| 1406 | + 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1407 | + 'event_espresso' |
|
| 1408 | + ), |
|
| 1409 | + $callback |
|
| 1410 | + ) |
|
| 1411 | + ); |
|
| 1412 | + } |
|
| 1413 | + $args = (array)$args; |
|
| 1414 | + $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1415 | + $this->set_timezone($original_timezone); |
|
| 1416 | + return $return; |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * Deletes this model object. |
|
| 1423 | + * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1424 | + * override |
|
| 1425 | + * `EE_Base_Class::_delete` NOT this class. |
|
| 1426 | + * |
|
| 1427 | + * @return boolean | int |
|
| 1428 | + * @throws \EE_Error |
|
| 1429 | + */ |
|
| 1430 | + public function delete() |
|
| 1431 | + { |
|
| 1432 | + /** |
|
| 1433 | + * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1434 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1435 | + * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1436 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1437 | + * |
|
| 1438 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1439 | + */ |
|
| 1440 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1441 | + $result = $this->_delete(); |
|
| 1442 | + /** |
|
| 1443 | + * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1444 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1445 | + * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1446 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1447 | + * |
|
| 1448 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1449 | + * @param boolean $result |
|
| 1450 | + */ |
|
| 1451 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1452 | + return $result; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + |
|
| 1456 | + |
|
| 1457 | + /** |
|
| 1458 | + * Calls the specific delete method for the instantiated class. |
|
| 1459 | + * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1460 | + * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1461 | + * `EE_Base_Class::delete` |
|
| 1462 | + * |
|
| 1463 | + * @return bool|int |
|
| 1464 | + * @throws \EE_Error |
|
| 1465 | + */ |
|
| 1466 | + protected function _delete() |
|
| 1467 | + { |
|
| 1468 | + return $this->delete_permanently(); |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + |
|
| 1472 | + |
|
| 1473 | + /** |
|
| 1474 | + * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1475 | + * error) |
|
| 1476 | + * |
|
| 1477 | + * @return bool | int |
|
| 1478 | + * @throws \EE_Error |
|
| 1479 | + */ |
|
| 1480 | + public function delete_permanently() |
|
| 1481 | + { |
|
| 1482 | + /** |
|
| 1483 | + * Called just before HARD deleting a model object |
|
| 1484 | + * |
|
| 1485 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1486 | + */ |
|
| 1487 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1488 | + $model = $this->get_model(); |
|
| 1489 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1490 | + $this->refresh_cache_of_related_objects(); |
|
| 1491 | + /** |
|
| 1492 | + * Called just after HARD deleting a model object |
|
| 1493 | + * |
|
| 1494 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1495 | + * @param boolean $result |
|
| 1496 | + */ |
|
| 1497 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1498 | + return $result; |
|
| 1499 | + } |
|
| 1500 | + |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1505 | + * related model objects |
|
| 1506 | + * |
|
| 1507 | + * @throws \EE_Error |
|
| 1508 | + */ |
|
| 1509 | + public function refresh_cache_of_related_objects() |
|
| 1510 | + { |
|
| 1511 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1512 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1513 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1514 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1515 | + //this relation only stores a single model object, not an array |
|
| 1516 | + //but let's make it consistent |
|
| 1517 | + $related_objects = array($related_objects); |
|
| 1518 | + } |
|
| 1519 | + foreach ($related_objects as $related_object) { |
|
| 1520 | + //only refresh their cache if they're in memory |
|
| 1521 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1522 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + } |
|
| 1526 | + } |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1533 | + * object just before saving. |
|
| 1534 | + * |
|
| 1535 | + * @access public |
|
| 1536 | + * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1537 | + * if provided during the save() method (often client code will change the fields' |
|
| 1538 | + * values before calling save) |
|
| 1539 | + * @throws \EE_Error |
|
| 1540 | + * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1541 | + * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1542 | + */ |
|
| 1543 | + public function save($set_cols_n_values = array()) |
|
| 1544 | + { |
|
| 1545 | + /** |
|
| 1546 | + * Filters the fields we're about to save on the model object |
|
| 1547 | + * |
|
| 1548 | + * @param array $set_cols_n_values |
|
| 1549 | + * @param EE_Base_Class $model_object |
|
| 1550 | + */ |
|
| 1551 | + $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1552 | + $this); |
|
| 1553 | + //set attributes as provided in $set_cols_n_values |
|
| 1554 | + foreach ($set_cols_n_values as $column => $value) { |
|
| 1555 | + $this->set($column, $value); |
|
| 1556 | + } |
|
| 1557 | + /** |
|
| 1558 | + * Saving a model object. |
|
| 1559 | + * Before we perform a save, this action is fired. |
|
| 1560 | + * |
|
| 1561 | + * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1562 | + */ |
|
| 1563 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1564 | + if ( ! $this->allow_persist()) { |
|
| 1565 | + return 0; |
|
| 1566 | + } |
|
| 1567 | + //now get current attribute values |
|
| 1568 | + $save_cols_n_values = $this->_fields; |
|
| 1569 | + //if the object already has an ID, update it. Otherwise, insert it |
|
| 1570 | + //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1571 | + $old_assumption_concerning_value_preparation = $this->get_model() |
|
| 1572 | + ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1573 | + $this->get_model()->assume_values_already_prepared_by_model_object(true); |
|
| 1574 | + //does this model have an autoincrement PK? |
|
| 1575 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1576 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
| 1577 | + //ok check if it's set, if so: update; if not, insert |
|
| 1578 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
| 1579 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1580 | + } else { |
|
| 1581 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
| 1582 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1583 | + if ($results) { |
|
| 1584 | + //if successful, set the primary key |
|
| 1585 | + //but don't use the normal SET method, because it will check if |
|
| 1586 | + //an item with the same ID exists in the mapper & db, then |
|
| 1587 | + //will find it in the db (because we just added it) and THAT object |
|
| 1588 | + //will get added to the mapper before we can add this one! |
|
| 1589 | + //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1590 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
| 1591 | + $this->_fields[$pk_field_name] = $results; |
|
| 1592 | + $this->_clear_cached_property($pk_field_name); |
|
| 1593 | + $this->get_model()->add_to_entity_map($this); |
|
| 1594 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1595 | + } |
|
| 1596 | + } |
|
| 1597 | + } else {//PK is NOT auto-increment |
|
| 1598 | + //so check if one like it already exists in the db |
|
| 1599 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
| 1600 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1601 | + throw new EE_Error( |
|
| 1602 | + sprintf( |
|
| 1603 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', |
|
| 1604 | + 'event_espresso'), |
|
| 1605 | + get_class($this), |
|
| 1606 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 1607 | + get_class($this->get_model()) . '::instance()->get_one_by_ID()', |
|
| 1608 | + '<br />' |
|
| 1609 | + ) |
|
| 1610 | + ); |
|
| 1611 | + } |
|
| 1612 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1613 | + } else { |
|
| 1614 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1615 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1616 | + } |
|
| 1617 | + } |
|
| 1618 | + } else {//there is NO primary key |
|
| 1619 | + $already_in_db = false; |
|
| 1620 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
| 1621 | + $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1622 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
| 1623 | + $already_in_db = true; |
|
| 1624 | + } |
|
| 1625 | + } |
|
| 1626 | + if ($already_in_db) { |
|
| 1627 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1628 | + $this->get_model()->get_combined_primary_key_fields()); |
|
| 1629 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1630 | + } else { |
|
| 1631 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
| 1632 | + } |
|
| 1633 | + } |
|
| 1634 | + //restore the old assumption about values being prepared by the model object |
|
| 1635 | + $this->get_model() |
|
| 1636 | + ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1637 | + /** |
|
| 1638 | + * After saving the model object this action is called |
|
| 1639 | + * |
|
| 1640 | + * @param EE_Base_Class $model_object which was just saved |
|
| 1641 | + * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1642 | + * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1643 | + */ |
|
| 1644 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1645 | + return $results; |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + |
|
| 1649 | + |
|
| 1650 | + /** |
|
| 1651 | + * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1652 | + * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1653 | + * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1654 | + * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1655 | + * saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the |
|
| 1656 | + * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1657 | + * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1658 | + * |
|
| 1659 | + * @return void |
|
| 1660 | + * @throws \EE_Error |
|
| 1661 | + */ |
|
| 1662 | + protected function _update_cached_related_model_objs_fks() |
|
| 1663 | + { |
|
| 1664 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 1665 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1666 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1667 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1668 | + $this->get_model()->get_this_model_name() |
|
| 1669 | + ); |
|
| 1670 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1671 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1672 | + $related_model_obj_in_cache->save(); |
|
| 1673 | + } |
|
| 1674 | + } |
|
| 1675 | + } |
|
| 1676 | + } |
|
| 1677 | + } |
|
| 1678 | + |
|
| 1679 | + |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * Saves this model object and its NEW cached relations to the database. |
|
| 1683 | + * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1684 | + * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1685 | + * because otherwise, there's a potential for infinite looping of saving |
|
| 1686 | + * Saves the cached related model objects, and ensures the relation between them |
|
| 1687 | + * and this object and properly setup |
|
| 1688 | + * |
|
| 1689 | + * @return int ID of new model object on save; 0 on failure+ |
|
| 1690 | + * @throws \EE_Error |
|
| 1691 | + */ |
|
| 1692 | + public function save_new_cached_related_model_objs() |
|
| 1693 | + { |
|
| 1694 | + //make sure this has been saved |
|
| 1695 | + if ( ! $this->ID()) { |
|
| 1696 | + $id = $this->save(); |
|
| 1697 | + } else { |
|
| 1698 | + $id = $this->ID(); |
|
| 1699 | + } |
|
| 1700 | + //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1701 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1702 | + if ($this->_model_relations[$relationName]) { |
|
| 1703 | + //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1704 | + //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1705 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1706 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1707 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1708 | + /* @var $related_model_obj EE_Base_Class */ |
|
| 1709 | + $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1710 | + // if( ! $related_model_obj->ID()){ |
|
| 1711 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1712 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1713 | + // } |
|
| 1714 | + } else { |
|
| 1715 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1716 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1717 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1718 | + // if( ! $related_model_obj->ID()){ |
|
| 1719 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1720 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1721 | + // } |
|
| 1722 | + } |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } |
|
| 1726 | + return $id; |
|
| 1727 | + } |
|
| 1728 | + |
|
| 1729 | + |
|
| 1730 | + |
|
| 1731 | + /** |
|
| 1732 | + * for getting a model while instantiated. |
|
| 1733 | + * |
|
| 1734 | + * @return \EEM_Base | \EEM_CPT_Base |
|
| 1735 | + */ |
|
| 1736 | + public function get_model() |
|
| 1737 | + { |
|
| 1738 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1739 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * @param $props_n_values |
|
| 1746 | + * @param $classname |
|
| 1747 | + * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1748 | + * @throws \EE_Error |
|
| 1749 | + */ |
|
| 1750 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1751 | + { |
|
| 1752 | + //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1753 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1754 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1755 | + $id = $props_n_values[$primary_id_ref]; |
|
| 1756 | + return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1757 | + } |
|
| 1758 | + return false; |
|
| 1759 | + } |
|
| 1760 | + |
|
| 1761 | + |
|
| 1762 | + |
|
| 1763 | + /** |
|
| 1764 | + * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1765 | + * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1766 | + * primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not |
|
| 1767 | + * we return false. |
|
| 1768 | + * |
|
| 1769 | + * @param array $props_n_values incoming array of properties and their values |
|
| 1770 | + * @param string $classname the classname of the child class |
|
| 1771 | + * @param null $timezone |
|
| 1772 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1773 | + * date_format and the second value is the time format |
|
| 1774 | + * @return mixed (EE_Base_Class|bool) |
|
| 1775 | + * @throws \EE_Error |
|
| 1776 | + */ |
|
| 1777 | + protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1778 | + { |
|
| 1779 | + $existing = null; |
|
| 1780 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
| 1781 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1782 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1783 | + && ! empty($props_n_values[$primary_id_ref]) |
|
| 1784 | + ) { |
|
| 1785 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1786 | + $props_n_values[$primary_id_ref] |
|
| 1787 | + ); |
|
| 1788 | + } |
|
| 1789 | + } elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1790 | + //no primary key on this model, but there's still a matching item in the DB |
|
| 1791 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1792 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1793 | + ); |
|
| 1794 | + } |
|
| 1795 | + if ($existing) { |
|
| 1796 | + //set date formats if present before setting values |
|
| 1797 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1798 | + $existing->set_date_format($date_formats[0]); |
|
| 1799 | + $existing->set_time_format($date_formats[1]); |
|
| 1800 | + } else { |
|
| 1801 | + //set default formats for date and time |
|
| 1802 | + $existing->set_date_format(get_option('date_format')); |
|
| 1803 | + $existing->set_time_format(get_option('time_format')); |
|
| 1804 | + } |
|
| 1805 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1806 | + $existing->set($property, $field_value); |
|
| 1807 | + } |
|
| 1808 | + return $existing; |
|
| 1809 | + } else { |
|
| 1810 | + return false; |
|
| 1811 | + } |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + |
|
| 1815 | + |
|
| 1816 | + /** |
|
| 1817 | + * Gets the EEM_*_Model for this class |
|
| 1818 | + * |
|
| 1819 | + * @access public now, as this is more convenient |
|
| 1820 | + * @param $classname |
|
| 1821 | + * @param null $timezone |
|
| 1822 | + * @throws EE_Error |
|
| 1823 | + * @return EEM_Base |
|
| 1824 | + */ |
|
| 1825 | + protected static function _get_model($classname, $timezone = null) |
|
| 1826 | + { |
|
| 1827 | + //find model for this class |
|
| 1828 | + if ( ! $classname) { |
|
| 1829 | + throw new EE_Error( |
|
| 1830 | + sprintf( |
|
| 1831 | + __( |
|
| 1832 | + "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1833 | + "event_espresso" |
|
| 1834 | + ), |
|
| 1835 | + $classname |
|
| 1836 | + ) |
|
| 1837 | + ); |
|
| 1838 | + } |
|
| 1839 | + $modelName = self::_get_model_classname($classname); |
|
| 1840 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1847 | + * |
|
| 1848 | + * @param string $model_classname |
|
| 1849 | + * @param null $timezone |
|
| 1850 | + * @return EEM_Base |
|
| 1851 | + */ |
|
| 1852 | + protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1853 | + { |
|
| 1854 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1855 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 1856 | + $model->set_timezone($timezone); |
|
| 1857 | + return $model; |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + |
|
| 1861 | + |
|
| 1862 | + /** |
|
| 1863 | + * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 1864 | + * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 1865 | + * |
|
| 1866 | + * @param null $model_name |
|
| 1867 | + * @return string like EEM_Attendee |
|
| 1868 | + */ |
|
| 1869 | + private static function _get_model_classname($model_name = null) |
|
| 1870 | + { |
|
| 1871 | + if (strpos($model_name, "EE_") === 0) { |
|
| 1872 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 1873 | + } else { |
|
| 1874 | + $model_classname = "EEM_" . $model_name; |
|
| 1875 | + } |
|
| 1876 | + return $model_classname; |
|
| 1877 | + } |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + |
|
| 1881 | + /** |
|
| 1882 | + * returns the name of the primary key attribute |
|
| 1883 | + * |
|
| 1884 | + * @param null $classname |
|
| 1885 | + * @throws EE_Error |
|
| 1886 | + * @return string |
|
| 1887 | + */ |
|
| 1888 | + protected static function _get_primary_key_name($classname = null) |
|
| 1889 | + { |
|
| 1890 | + if ( ! $classname) { |
|
| 1891 | + throw new EE_Error( |
|
| 1892 | + sprintf( |
|
| 1893 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 1894 | + $classname |
|
| 1895 | + ) |
|
| 1896 | + ); |
|
| 1897 | + } |
|
| 1898 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + |
|
| 1903 | + /** |
|
| 1904 | + * Gets the value of the primary key. |
|
| 1905 | + * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 1906 | + * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 1907 | + * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 1908 | + * |
|
| 1909 | + * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 1910 | + * @throws \EE_Error |
|
| 1911 | + */ |
|
| 1912 | + public function ID() |
|
| 1913 | + { |
|
| 1914 | + //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 1915 | + if ($this->get_model()->has_primary_key_field()) { |
|
| 1916 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
| 1917 | + } else { |
|
| 1918 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
| 1919 | + } |
|
| 1920 | + } |
|
| 1921 | + |
|
| 1922 | + |
|
| 1923 | + |
|
| 1924 | + /** |
|
| 1925 | + * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 1926 | + * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 1927 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 1928 | + * |
|
| 1929 | + * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 1930 | + * @param string $relationName eg 'Events','Question',etc. |
|
| 1931 | + * an attendee to a group, you also want to specify which role they |
|
| 1932 | + * will have in that group. So you would use this parameter to |
|
| 1933 | + * specify array('role-column-name'=>'role-id') |
|
| 1934 | + * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 1935 | + * allow you to further constrict the relation to being added. |
|
| 1936 | + * However, keep in mind that the columns (keys) given must match a |
|
| 1937 | + * column on the JOIN table and currently only the HABTM models |
|
| 1938 | + * accept these additional conditions. Also remember that if an |
|
| 1939 | + * exact match isn't found for these extra cols/val pairs, then a |
|
| 1940 | + * NEW row is created in the join table. |
|
| 1941 | + * @param null $cache_id |
|
| 1942 | + * @throws EE_Error |
|
| 1943 | + * @return EE_Base_Class the object the relation was added to |
|
| 1944 | + */ |
|
| 1945 | + public function _add_relation_to( |
|
| 1946 | + $otherObjectModelObjectOrID, |
|
| 1947 | + $relationName, |
|
| 1948 | + $extra_join_model_fields_n_values = array(), |
|
| 1949 | + $cache_id = null |
|
| 1950 | + ) { |
|
| 1951 | + //if this thing exists in the DB, save the relation to the DB |
|
| 1952 | + if ($this->ID()) { |
|
| 1953 | + $otherObject = $this->get_model() |
|
| 1954 | + ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 1955 | + $extra_join_model_fields_n_values); |
|
| 1956 | + //clear cache so future get_many_related and get_first_related() return new results. |
|
| 1957 | + $this->clear_cache($relationName, $otherObject, true); |
|
| 1958 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1959 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 1960 | + } |
|
| 1961 | + } else { |
|
| 1962 | + //this thing doesn't exist in the DB, so just cache it |
|
| 1963 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 1964 | + throw new EE_Error(sprintf( |
|
| 1965 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', |
|
| 1966 | + 'event_espresso'), |
|
| 1967 | + $otherObjectModelObjectOrID, |
|
| 1968 | + get_class($this) |
|
| 1969 | + )); |
|
| 1970 | + } else { |
|
| 1971 | + $otherObject = $otherObjectModelObjectOrID; |
|
| 1972 | + } |
|
| 1973 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 1974 | + } |
|
| 1975 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 1976 | + //fix the reciprocal relation too |
|
| 1977 | + if ($otherObject->ID()) { |
|
| 1978 | + //its saved so assumed relations exist in the DB, so we can just |
|
| 1979 | + //clear the cache so future queries use the updated info in the DB |
|
| 1980 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
| 1981 | + } else { |
|
| 1982 | + //it's not saved, so it caches relations like this |
|
| 1983 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
| 1984 | + } |
|
| 1985 | + } |
|
| 1986 | + return $otherObject; |
|
| 1987 | + } |
|
| 1988 | + |
|
| 1989 | + |
|
| 1990 | + |
|
| 1991 | + /** |
|
| 1992 | + * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 1993 | + * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 1994 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 1995 | + * from the cache |
|
| 1996 | + * |
|
| 1997 | + * @param mixed $otherObjectModelObjectOrID |
|
| 1998 | + * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 1999 | + * to the DB yet |
|
| 2000 | + * @param string $relationName |
|
| 2001 | + * @param array $where_query |
|
| 2002 | + * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2003 | + * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2004 | + * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2005 | + * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2006 | + * created in the join table. |
|
| 2007 | + * @return EE_Base_Class the relation was removed from |
|
| 2008 | + * @throws \EE_Error |
|
| 2009 | + */ |
|
| 2010 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2011 | + { |
|
| 2012 | + if ($this->ID()) { |
|
| 2013 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2014 | + $otherObject = $this->get_model() |
|
| 2015 | + ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2016 | + $where_query); |
|
| 2017 | + $this->clear_cache($relationName, $otherObject); |
|
| 2018 | + } else { |
|
| 2019 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2020 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2021 | + } |
|
| 2022 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 2023 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2024 | + } |
|
| 2025 | + return $otherObject; |
|
| 2026 | + } |
|
| 2027 | + |
|
| 2028 | + |
|
| 2029 | + |
|
| 2030 | + /** |
|
| 2031 | + * Removes ALL the related things for the $relationName. |
|
| 2032 | + * |
|
| 2033 | + * @param string $relationName |
|
| 2034 | + * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2035 | + * @return EE_Base_Class |
|
| 2036 | + * @throws \EE_Error |
|
| 2037 | + */ |
|
| 2038 | + public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2039 | + { |
|
| 2040 | + if ($this->ID()) { |
|
| 2041 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2042 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2043 | + $this->clear_cache($relationName, null, true); |
|
| 2044 | + } else { |
|
| 2045 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2046 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2047 | + } |
|
| 2048 | + if (is_array($otherObjects)) { |
|
| 2049 | + foreach ($otherObjects as $otherObject) { |
|
| 2050 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2051 | + } |
|
| 2052 | + } |
|
| 2053 | + return $otherObjects; |
|
| 2054 | + } |
|
| 2055 | + |
|
| 2056 | + |
|
| 2057 | + |
|
| 2058 | + /** |
|
| 2059 | + * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2060 | + * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2061 | + * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2062 | + * because we want to get even deleted items etc. |
|
| 2063 | + * |
|
| 2064 | + * @param string $relationName key in the model's _model_relations array |
|
| 2065 | + * @param array $query_params like EEM_Base::get_all |
|
| 2066 | + * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2067 | + * @throws \EE_Error |
|
| 2068 | + * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2069 | + * you want IDs |
|
| 2070 | + */ |
|
| 2071 | + public function get_many_related($relationName, $query_params = array()) |
|
| 2072 | + { |
|
| 2073 | + if ($this->ID()) { |
|
| 2074 | + //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2075 | + //if there are query parameters, forget about caching the related model objects. |
|
| 2076 | + if ($query_params) { |
|
| 2077 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2078 | + } else { |
|
| 2079 | + //did we already cache the result of this query? |
|
| 2080 | + $cached_results = $this->get_all_from_cache($relationName); |
|
| 2081 | + if ( ! $cached_results) { |
|
| 2082 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2083 | + //if no query parameters were passed, then we got all the related model objects |
|
| 2084 | + //for that relation. We can cache them then. |
|
| 2085 | + foreach ($related_model_objects as $related_model_object) { |
|
| 2086 | + $this->cache($relationName, $related_model_object); |
|
| 2087 | + } |
|
| 2088 | + } else { |
|
| 2089 | + $related_model_objects = $cached_results; |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + } else { |
|
| 2093 | + //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2094 | + $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2095 | + } |
|
| 2096 | + return $related_model_objects; |
|
| 2097 | + } |
|
| 2098 | + |
|
| 2099 | + |
|
| 2100 | + |
|
| 2101 | + /** |
|
| 2102 | + * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2103 | + * unless otherwise specified in the $query_params |
|
| 2104 | + * |
|
| 2105 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2106 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2107 | + * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2108 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2109 | + * that by the setting $distinct to TRUE; |
|
| 2110 | + * @return int |
|
| 2111 | + */ |
|
| 2112 | + public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2113 | + { |
|
| 2114 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2115 | + } |
|
| 2116 | + |
|
| 2117 | + |
|
| 2118 | + |
|
| 2119 | + /** |
|
| 2120 | + * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2121 | + * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2122 | + * |
|
| 2123 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2124 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2125 | + * @param string $field_to_sum name of field to count by. |
|
| 2126 | + * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2127 | + * change it) |
|
| 2128 | + * @return int |
|
| 2129 | + */ |
|
| 2130 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2131 | + { |
|
| 2132 | + return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2133 | + } |
|
| 2134 | + |
|
| 2135 | + |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Gets the first (ie, one) related model object of the specified type. |
|
| 2139 | + * |
|
| 2140 | + * @param string $relationName key in the model's _model_relations array |
|
| 2141 | + * @param array $query_params like EEM_Base::get_all |
|
| 2142 | + * @return EE_Base_Class (not an array, a single object) |
|
| 2143 | + * @throws \EE_Error |
|
| 2144 | + */ |
|
| 2145 | + public function get_first_related($relationName, $query_params = array()) |
|
| 2146 | + { |
|
| 2147 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2148 | + //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2149 | + //also make sure we're not caching the result of get_first_related |
|
| 2150 | + //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2151 | + if ($query_params |
|
| 2152 | + || ! $this->get_model()->related_settings_for($relationName) |
|
| 2153 | + instanceof |
|
| 2154 | + EE_Belongs_To_Relation |
|
| 2155 | + ) { |
|
| 2156 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2157 | + } else { |
|
| 2158 | + //first, check if we've already cached the result of this query |
|
| 2159 | + $cached_result = $this->get_one_from_cache($relationName); |
|
| 2160 | + if ( ! $cached_result) { |
|
| 2161 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2162 | + $this->cache($relationName, $related_model_object); |
|
| 2163 | + } else { |
|
| 2164 | + $related_model_object = $cached_result; |
|
| 2165 | + } |
|
| 2166 | + } |
|
| 2167 | + } else { |
|
| 2168 | + $related_model_object = null; |
|
| 2169 | + //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2170 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2171 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
| 2172 | + } |
|
| 2173 | + //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
|
| 2174 | + if ( ! $related_model_object) { |
|
| 2175 | + $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2176 | + } |
|
| 2177 | + } |
|
| 2178 | + return $related_model_object; |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + |
|
| 2182 | + |
|
| 2183 | + /** |
|
| 2184 | + * Does a delete on all related objects of type $relationName and removes |
|
| 2185 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2186 | + * of blocking related model objects) does nothing. If the related model objects are |
|
| 2187 | + * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2188 | + * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2189 | + * |
|
| 2190 | + * @param string $relationName |
|
| 2191 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2192 | + * @return int how many deleted |
|
| 2193 | + * @throws \EE_Error |
|
| 2194 | + */ |
|
| 2195 | + public function delete_related($relationName, $query_params = array()) |
|
| 2196 | + { |
|
| 2197 | + if ($this->ID()) { |
|
| 2198 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2199 | + } else { |
|
| 2200 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2201 | + $this->clear_cache($relationName, null, true); |
|
| 2202 | + } |
|
| 2203 | + return $count; |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + |
|
| 2207 | + |
|
| 2208 | + /** |
|
| 2209 | + * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2210 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2211 | + * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2212 | + * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2213 | + * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2214 | + * |
|
| 2215 | + * @param string $relationName |
|
| 2216 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2217 | + * @return int how many deleted (including those soft deleted) |
|
| 2218 | + * @throws \EE_Error |
|
| 2219 | + */ |
|
| 2220 | + public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2221 | + { |
|
| 2222 | + if ($this->ID()) { |
|
| 2223 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2224 | + } else { |
|
| 2225 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2226 | + } |
|
| 2227 | + $this->clear_cache($relationName, null, true); |
|
| 2228 | + return $count; |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * is_set |
|
| 2235 | + * Just a simple utility function children can use for checking if property exists |
|
| 2236 | + * |
|
| 2237 | + * @access public |
|
| 2238 | + * @param string $field_name property to check |
|
| 2239 | + * @return bool TRUE if existing,FALSE if not. |
|
| 2240 | + */ |
|
| 2241 | + public function is_set($field_name) |
|
| 2242 | + { |
|
| 2243 | + return isset($this->_fields[$field_name]); |
|
| 2244 | + } |
|
| 2245 | + |
|
| 2246 | + |
|
| 2247 | + |
|
| 2248 | + /** |
|
| 2249 | + * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2250 | + * EE_Error exception if they don't |
|
| 2251 | + * |
|
| 2252 | + * @param mixed (string|array) $properties properties to check |
|
| 2253 | + * @throws EE_Error |
|
| 2254 | + * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2255 | + */ |
|
| 2256 | + protected function _property_exists($properties) |
|
| 2257 | + { |
|
| 2258 | + foreach ((array)$properties as $property_name) { |
|
| 2259 | + //first make sure this property exists |
|
| 2260 | + if ( ! $this->_fields[$property_name]) { |
|
| 2261 | + throw new EE_Error( |
|
| 2262 | + sprintf( |
|
| 2263 | + __( |
|
| 2264 | + 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2265 | + 'event_espresso' |
|
| 2266 | + ), |
|
| 2267 | + $property_name |
|
| 2268 | + ) |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + } |
|
| 2272 | + return true; |
|
| 2273 | + } |
|
| 2274 | + |
|
| 2275 | + |
|
| 2276 | + |
|
| 2277 | + /** |
|
| 2278 | + * This simply returns an array of model fields for this object |
|
| 2279 | + * |
|
| 2280 | + * @return array |
|
| 2281 | + * @throws \EE_Error |
|
| 2282 | + */ |
|
| 2283 | + public function model_field_array() |
|
| 2284 | + { |
|
| 2285 | + $fields = $this->get_model()->field_settings(false); |
|
| 2286 | + $properties = array(); |
|
| 2287 | + //remove prepended underscore |
|
| 2288 | + foreach ($fields as $field_name => $settings) { |
|
| 2289 | + $properties[$field_name] = $this->get($field_name); |
|
| 2290 | + } |
|
| 2291 | + return $properties; |
|
| 2292 | + } |
|
| 2293 | + |
|
| 2294 | + |
|
| 2295 | + |
|
| 2296 | + /** |
|
| 2297 | + * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2298 | + * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2299 | + * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2300 | + * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2301 | + * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2302 | + * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2303 | + * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2304 | + * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2305 | + * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2306 | + * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2307 | + * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2308 | + * return $previousReturnValue.$returnString; |
|
| 2309 | + * } |
|
| 2310 | + * require('EE_Answer.class.php'); |
|
| 2311 | + * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2312 | + * echo $answer->my_callback('monkeys',100); |
|
| 2313 | + * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2314 | + * |
|
| 2315 | + * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2316 | + * @param array $args array of original arguments passed to the function |
|
| 2317 | + * @throws EE_Error |
|
| 2318 | + * @return mixed whatever the plugin which calls add_filter decides |
|
| 2319 | + */ |
|
| 2320 | + public function __call($methodName, $args) |
|
| 2321 | + { |
|
| 2322 | + $className = get_class($this); |
|
| 2323 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2324 | + if ( ! has_filter($tagName)) { |
|
| 2325 | + throw new EE_Error( |
|
| 2326 | + sprintf( |
|
| 2327 | + __( |
|
| 2328 | + "Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", |
|
| 2329 | + "event_espresso" |
|
| 2330 | + ), |
|
| 2331 | + $methodName, |
|
| 2332 | + $className, |
|
| 2333 | + $tagName |
|
| 2334 | + ) |
|
| 2335 | + ); |
|
| 2336 | + } |
|
| 2337 | + return apply_filters($tagName, null, $this, $args); |
|
| 2338 | + } |
|
| 2339 | + |
|
| 2340 | + |
|
| 2341 | + |
|
| 2342 | + /** |
|
| 2343 | + * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2344 | + * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2345 | + * |
|
| 2346 | + * @param string $meta_key |
|
| 2347 | + * @param string $meta_value |
|
| 2348 | + * @param string $previous_value |
|
| 2349 | + * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2350 | + * @throws \EE_Error |
|
| 2351 | + * NOTE: if the values haven't changed, returns 0 |
|
| 2352 | + */ |
|
| 2353 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2354 | + { |
|
| 2355 | + $query_params = array( |
|
| 2356 | + array( |
|
| 2357 | + 'EXM_key' => $meta_key, |
|
| 2358 | + 'OBJ_ID' => $this->ID(), |
|
| 2359 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2360 | + ), |
|
| 2361 | + ); |
|
| 2362 | + if ($previous_value !== null) { |
|
| 2363 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2364 | + } |
|
| 2365 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2366 | + if ( ! $existing_rows_like_that) { |
|
| 2367 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2368 | + } else { |
|
| 2369 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2370 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2371 | + } |
|
| 2372 | + return count($existing_rows_like_that); |
|
| 2373 | + } |
|
| 2374 | + } |
|
| 2375 | + |
|
| 2376 | + |
|
| 2377 | + |
|
| 2378 | + /** |
|
| 2379 | + * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2380 | + * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2381 | + * extra meta row was entered, false if not |
|
| 2382 | + * |
|
| 2383 | + * @param string $meta_key |
|
| 2384 | + * @param string $meta_value |
|
| 2385 | + * @param boolean $unique |
|
| 2386 | + * @return boolean |
|
| 2387 | + * @throws \EE_Error |
|
| 2388 | + */ |
|
| 2389 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2390 | + { |
|
| 2391 | + if ($unique) { |
|
| 2392 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2393 | + array( |
|
| 2394 | + array( |
|
| 2395 | + 'EXM_key' => $meta_key, |
|
| 2396 | + 'OBJ_ID' => $this->ID(), |
|
| 2397 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2398 | + ), |
|
| 2399 | + ) |
|
| 2400 | + ); |
|
| 2401 | + if ($existing_extra_meta) { |
|
| 2402 | + return false; |
|
| 2403 | + } |
|
| 2404 | + } |
|
| 2405 | + $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2406 | + array( |
|
| 2407 | + 'EXM_key' => $meta_key, |
|
| 2408 | + 'EXM_value' => $meta_value, |
|
| 2409 | + 'OBJ_ID' => $this->ID(), |
|
| 2410 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2411 | + ) |
|
| 2412 | + ); |
|
| 2413 | + $new_extra_meta->save(); |
|
| 2414 | + return true; |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2421 | + * is specified, only deletes extra meta records with that value. |
|
| 2422 | + * |
|
| 2423 | + * @param string $meta_key |
|
| 2424 | + * @param string $meta_value |
|
| 2425 | + * @return int number of extra meta rows deleted |
|
| 2426 | + * @throws \EE_Error |
|
| 2427 | + */ |
|
| 2428 | + public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2429 | + { |
|
| 2430 | + $query_params = array( |
|
| 2431 | + array( |
|
| 2432 | + 'EXM_key' => $meta_key, |
|
| 2433 | + 'OBJ_ID' => $this->ID(), |
|
| 2434 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2435 | + ), |
|
| 2436 | + ); |
|
| 2437 | + if ($meta_value !== null) { |
|
| 2438 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2439 | + } |
|
| 2440 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + |
|
| 2444 | + |
|
| 2445 | + /** |
|
| 2446 | + * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2447 | + * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2448 | + * You can specify $default is case you haven't found the extra meta |
|
| 2449 | + * |
|
| 2450 | + * @param string $meta_key |
|
| 2451 | + * @param boolean $single |
|
| 2452 | + * @param mixed $default if we don't find anything, what should we return? |
|
| 2453 | + * @return mixed single value if $single; array if ! $single |
|
| 2454 | + * @throws \EE_Error |
|
| 2455 | + */ |
|
| 2456 | + public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2457 | + { |
|
| 2458 | + if ($single) { |
|
| 2459 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2460 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2461 | + return $result->value(); |
|
| 2462 | + } else { |
|
| 2463 | + return $default; |
|
| 2464 | + } |
|
| 2465 | + } else { |
|
| 2466 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2467 | + if ($results) { |
|
| 2468 | + $values = array(); |
|
| 2469 | + foreach ($results as $result) { |
|
| 2470 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2471 | + $values[$result->ID()] = $result->value(); |
|
| 2472 | + } |
|
| 2473 | + } |
|
| 2474 | + return $values; |
|
| 2475 | + } else { |
|
| 2476 | + return $default; |
|
| 2477 | + } |
|
| 2478 | + } |
|
| 2479 | + } |
|
| 2480 | + |
|
| 2481 | + |
|
| 2482 | + |
|
| 2483 | + /** |
|
| 2484 | + * Returns a simple array of all the extra meta associated with this model object. |
|
| 2485 | + * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2486 | + * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2487 | + * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2488 | + * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2489 | + * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2490 | + * finally the extra meta's value as each sub-value. (eg |
|
| 2491 | + * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2492 | + * |
|
| 2493 | + * @param boolean $one_of_each_key |
|
| 2494 | + * @return array |
|
| 2495 | + * @throws \EE_Error |
|
| 2496 | + */ |
|
| 2497 | + public function all_extra_meta_array($one_of_each_key = true) |
|
| 2498 | + { |
|
| 2499 | + $return_array = array(); |
|
| 2500 | + if ($one_of_each_key) { |
|
| 2501 | + $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2502 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2503 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2504 | + $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2505 | + } |
|
| 2506 | + } |
|
| 2507 | + } else { |
|
| 2508 | + $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2509 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2510 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2511 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2512 | + $return_array[$extra_meta_obj->key()] = array(); |
|
| 2513 | + } |
|
| 2514 | + $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2515 | + } |
|
| 2516 | + } |
|
| 2517 | + } |
|
| 2518 | + return $return_array; |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + |
|
| 2522 | + |
|
| 2523 | + /** |
|
| 2524 | + * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2525 | + * |
|
| 2526 | + * @return string |
|
| 2527 | + * @throws \EE_Error |
|
| 2528 | + */ |
|
| 2529 | + public function name() |
|
| 2530 | + { |
|
| 2531 | + //find a field that's not a text field |
|
| 2532 | + $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2533 | + if ($field_we_can_use) { |
|
| 2534 | + return $this->get($field_we_can_use->get_name()); |
|
| 2535 | + } else { |
|
| 2536 | + $first_few_properties = $this->model_field_array(); |
|
| 2537 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2538 | + $name_parts = array(); |
|
| 2539 | + foreach ($first_few_properties as $name => $value) { |
|
| 2540 | + $name_parts[] = "$name:$value"; |
|
| 2541 | + } |
|
| 2542 | + return implode(",", $name_parts); |
|
| 2543 | + } |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * in_entity_map |
|
| 2550 | + * Checks if this model object has been proven to already be in the entity map |
|
| 2551 | + * |
|
| 2552 | + * @return boolean |
|
| 2553 | + * @throws \EE_Error |
|
| 2554 | + */ |
|
| 2555 | + public function in_entity_map() |
|
| 2556 | + { |
|
| 2557 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2558 | + //well, if we looked, did we find it in the entity map? |
|
| 2559 | + return true; |
|
| 2560 | + } else { |
|
| 2561 | + return false; |
|
| 2562 | + } |
|
| 2563 | + } |
|
| 2564 | + |
|
| 2565 | + |
|
| 2566 | + |
|
| 2567 | + /** |
|
| 2568 | + * refresh_from_db |
|
| 2569 | + * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2570 | + * |
|
| 2571 | + * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2572 | + * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2573 | + */ |
|
| 2574 | + public function refresh_from_db() |
|
| 2575 | + { |
|
| 2576 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2577 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2578 | + } else { |
|
| 2579 | + //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2580 | + //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2581 | + //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2582 | + //absolutely nothing in it for this ID |
|
| 2583 | + if (WP_DEBUG) { |
|
| 2584 | + throw new EE_Error( |
|
| 2585 | + sprintf( |
|
| 2586 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', |
|
| 2587 | + 'event_espresso'), |
|
| 2588 | + $this->ID(), |
|
| 2589 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2590 | + get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2591 | + ) |
|
| 2592 | + ); |
|
| 2593 | + } |
|
| 2594 | + } |
|
| 2595 | + } |
|
| 2596 | + |
|
| 2597 | + |
|
| 2598 | + |
|
| 2599 | + /** |
|
| 2600 | + * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2601 | + * (probably a bad assumption they have made, oh well) |
|
| 2602 | + * |
|
| 2603 | + * @return string |
|
| 2604 | + */ |
|
| 2605 | + public function __toString() |
|
| 2606 | + { |
|
| 2607 | + try { |
|
| 2608 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2609 | + } catch (Exception $e) { |
|
| 2610 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2611 | + return ''; |
|
| 2612 | + } |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + |
|
| 2616 | + |
|
| 2617 | + /** |
|
| 2618 | + * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2619 | + * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2620 | + * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2621 | + * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2622 | + * Instead, those related model objects should be directly serialized and stored. |
|
| 2623 | + * Eg, the following won't work: |
|
| 2624 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2625 | + * $att = $reg->attendee(); |
|
| 2626 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2627 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2628 | + * //END REQUEST |
|
| 2629 | + * //START NEXT REQUEST |
|
| 2630 | + * $reg = get_option( 'my_option' ); |
|
| 2631 | + * $reg->attendee()->save(); |
|
| 2632 | + * And would need to be replace with: |
|
| 2633 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2634 | + * $att = $reg->attendee(); |
|
| 2635 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2636 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2637 | + * //END REQUEST |
|
| 2638 | + * //START NEXT REQUEST |
|
| 2639 | + * $att = get_option( 'my_option' ); |
|
| 2640 | + * $att->save(); |
|
| 2641 | + * |
|
| 2642 | + * @return array |
|
| 2643 | + * @throws \EE_Error |
|
| 2644 | + */ |
|
| 2645 | + public function __sleep() |
|
| 2646 | + { |
|
| 2647 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
| 2648 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2649 | + $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
| 2650 | + if ( |
|
| 2651 | + $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2652 | + && $this->get_one_from_cache($relation_name)->ID() |
|
| 2653 | + ) { |
|
| 2654 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2655 | + } |
|
| 2656 | + } |
|
| 2657 | + } |
|
| 2658 | + $this->_props_n_values_provided_in_constructor = array(); |
|
| 2659 | + return array_keys(get_object_vars($this)); |
|
| 2660 | + } |
|
| 2661 | + |
|
| 2662 | + |
|
| 2663 | + |
|
| 2664 | + /** |
|
| 2665 | + * restore _props_n_values_provided_in_constructor |
|
| 2666 | + * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2667 | + * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2668 | + * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2669 | + */ |
|
| 2670 | + public function __wakeup() |
|
| 2671 | + { |
|
| 2672 | + $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2673 | + } |
|
| 2674 | 2674 | |
| 2675 | 2675 | |
| 2676 | 2676 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -61,23 +61,23 @@ discard block |
||
| 61 | 61 | * @param string $min_core_version |
| 62 | 62 | * @return string always like '4.3.0.rc.000' |
| 63 | 63 | */ |
| 64 | - protected static function _effective_version( $min_core_version ) { |
|
| 64 | + protected static function _effective_version($min_core_version) { |
|
| 65 | 65 | // versions: 4 . 3 . 1 . p . 123 |
| 66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 67 | - $version_parts = explode( '.', $min_core_version ); |
|
| 67 | + $version_parts = explode('.', $min_core_version); |
|
| 68 | 68 | //check they specified the micro version (after 2nd period) |
| 69 | - if ( ! isset( $version_parts[2] ) ) { |
|
| 69 | + if ( ! isset($version_parts[2])) { |
|
| 70 | 70 | $version_parts[2] = '0'; |
| 71 | 71 | } |
| 72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 74 | - if ( ! isset( $version_parts[3] ) ) { |
|
| 74 | + if ( ! isset($version_parts[3])) { |
|
| 75 | 75 | $version_parts[3] = 'dev'; |
| 76 | 76 | } |
| 77 | - if ( ! isset( $version_parts[4] ) ) { |
|
| 77 | + if ( ! isset($version_parts[4])) { |
|
| 78 | 78 | $version_parts[4] = '000'; |
| 79 | 79 | } |
| 80 | - return implode( '.', $version_parts ); |
|
| 80 | + return implode('.', $version_parts); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | $actual_core_version = EVENT_ESPRESSO_VERSION |
| 95 | 95 | ) { |
| 96 | 96 | return version_compare( |
| 97 | - self::_effective_version( $actual_core_version ), |
|
| 98 | - self::_effective_version( $min_core_version ), |
|
| 97 | + self::_effective_version($actual_core_version), |
|
| 98 | + self::_effective_version($min_core_version), |
|
| 99 | 99 | '>=' |
| 100 | 100 | ); |
| 101 | 101 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * @throws EE_Error |
| 218 | 218 | * @return void |
| 219 | 219 | */ |
| 220 | - public static function register( $addon_name = '', $setup_args = array() ) { |
|
| 220 | + public static function register($addon_name = '', $setup_args = array()) { |
|
| 221 | 221 | // required fields MUST be present, so let's make sure they are. |
| 222 | 222 | \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
| 223 | 223 | // get class name for addon |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | // setup PUE |
| 228 | 228 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 229 | 229 | // does this addon work with this version of core or WordPress ? |
| 230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
| 230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 231 | 231 | return; |
| 232 | 232 | } |
| 233 | 233 | // register namespaces |
| 234 | 234 | \EE_Register_Addon::_setup_namespaces($addon_settings); |
| 235 | 235 | // check if this is an activation request |
| 236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 236 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 237 | 237 | // dont bother setting up the rest of the addon atm |
| 238 | 238 | return; |
| 239 | 239 | } |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | } else { |
| 327 | 327 | $class_name = $setup_args['class_name']; |
| 328 | 328 | } |
| 329 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 329 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,105 +344,105 @@ discard block |
||
| 344 | 344 | 'class_name' => $class_name, |
| 345 | 345 | // the addon slug for use in URLs, etc |
| 346 | 346 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
| 347 | - ? (string)$setup_args['plugin_slug'] |
|
| 347 | + ? (string) $setup_args['plugin_slug'] |
|
| 348 | 348 | : '', |
| 349 | 349 | // page slug to be used when generating the "Settings" link on the WP plugin page |
| 350 | 350 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
| 351 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 351 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 352 | 352 | : '', |
| 353 | 353 | // the "software" version for the addon |
| 354 | 354 | 'version' => isset($setup_args['version']) |
| 355 | - ? (string)$setup_args['version'] |
|
| 355 | + ? (string) $setup_args['version'] |
|
| 356 | 356 | : '', |
| 357 | 357 | // the minimum version of EE Core that the addon will work with |
| 358 | 358 | 'min_core_version' => isset($setup_args['min_core_version']) |
| 359 | - ? (string)$setup_args['min_core_version'] |
|
| 359 | + ? (string) $setup_args['min_core_version'] |
|
| 360 | 360 | : '', |
| 361 | 361 | // the minimum version of WordPress that the addon will work with |
| 362 | 362 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
| 363 | - ? (string)$setup_args['min_wp_version'] |
|
| 363 | + ? (string) $setup_args['min_wp_version'] |
|
| 364 | 364 | : EE_MIN_WP_VER_REQUIRED, |
| 365 | 365 | // full server path to main file (file loaded directly by WP) |
| 366 | 366 | 'main_file_path' => isset($setup_args['main_file_path']) |
| 367 | - ? (string)$setup_args['main_file_path'] |
|
| 367 | + ? (string) $setup_args['main_file_path'] |
|
| 368 | 368 | : '', |
| 369 | 369 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
| 370 | 370 | 'admin_path' => isset($setup_args['admin_path']) |
| 371 | - ? (string)$setup_args['admin_path'] : '', |
|
| 371 | + ? (string) $setup_args['admin_path'] : '', |
|
| 372 | 372 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
| 373 | 373 | 'admin_callback' => isset($setup_args['admin_callback']) |
| 374 | - ? (string)$setup_args['admin_callback'] |
|
| 374 | + ? (string) $setup_args['admin_callback'] |
|
| 375 | 375 | : '', |
| 376 | 376 | // the section name for this addon's configuration settings section (defaults to "addons") |
| 377 | 377 | 'config_section' => isset($setup_args['config_section']) |
| 378 | - ? (string)$setup_args['config_section'] |
|
| 378 | + ? (string) $setup_args['config_section'] |
|
| 379 | 379 | : 'addons', |
| 380 | 380 | // the class name for this addon's configuration settings object |
| 381 | 381 | 'config_class' => isset($setup_args['config_class']) |
| 382 | - ? (string)$setup_args['config_class'] : '', |
|
| 382 | + ? (string) $setup_args['config_class'] : '', |
|
| 383 | 383 | //the name given to the config for this addons' configuration settings object (optional) |
| 384 | 384 | 'config_name' => isset($setup_args['config_name']) |
| 385 | - ? (string)$setup_args['config_name'] : '', |
|
| 385 | + ? (string) $setup_args['config_name'] : '', |
|
| 386 | 386 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
| 387 | 387 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
| 388 | - ? (array)$setup_args['autoloader_paths'] |
|
| 388 | + ? (array) $setup_args['autoloader_paths'] |
|
| 389 | 389 | : array(), |
| 390 | 390 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
| 391 | 391 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
| 392 | - ? (array)$setup_args['autoloader_folders'] |
|
| 392 | + ? (array) $setup_args['autoloader_folders'] |
|
| 393 | 393 | : array(), |
| 394 | 394 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
| 395 | 395 | 'dms_paths' => isset($setup_args['dms_paths']) |
| 396 | - ? (array)$setup_args['dms_paths'] |
|
| 396 | + ? (array) $setup_args['dms_paths'] |
|
| 397 | 397 | : array(), |
| 398 | 398 | // array of full server paths to any EED_Modules used by the addon |
| 399 | 399 | 'module_paths' => isset($setup_args['module_paths']) |
| 400 | - ? (array)$setup_args['module_paths'] |
|
| 400 | + ? (array) $setup_args['module_paths'] |
|
| 401 | 401 | : array(), |
| 402 | 402 | // array of full server paths to any EES_Shortcodes used by the addon |
| 403 | 403 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
| 404 | - ? (array)$setup_args['shortcode_paths'] |
|
| 404 | + ? (array) $setup_args['shortcode_paths'] |
|
| 405 | 405 | : array(), |
| 406 | 406 | // array of full server paths to any WP_Widgets used by the addon |
| 407 | 407 | 'widget_paths' => isset($setup_args['widget_paths']) |
| 408 | - ? (array)$setup_args['widget_paths'] |
|
| 408 | + ? (array) $setup_args['widget_paths'] |
|
| 409 | 409 | : array(), |
| 410 | 410 | // array of PUE options used by the addon |
| 411 | 411 | 'pue_options' => isset($setup_args['pue_options']) |
| 412 | - ? (array)$setup_args['pue_options'] |
|
| 412 | + ? (array) $setup_args['pue_options'] |
|
| 413 | 413 | : array(), |
| 414 | 414 | 'message_types' => isset($setup_args['message_types']) |
| 415 | - ? (array)$setup_args['message_types'] |
|
| 415 | + ? (array) $setup_args['message_types'] |
|
| 416 | 416 | : array(), |
| 417 | 417 | 'capabilities' => isset($setup_args['capabilities']) |
| 418 | - ? (array)$setup_args['capabilities'] |
|
| 418 | + ? (array) $setup_args['capabilities'] |
|
| 419 | 419 | : array(), |
| 420 | 420 | 'capability_maps' => isset($setup_args['capability_maps']) |
| 421 | - ? (array)$setup_args['capability_maps'] |
|
| 421 | + ? (array) $setup_args['capability_maps'] |
|
| 422 | 422 | : array(), |
| 423 | 423 | 'model_paths' => isset($setup_args['model_paths']) |
| 424 | - ? (array)$setup_args['model_paths'] |
|
| 424 | + ? (array) $setup_args['model_paths'] |
|
| 425 | 425 | : array(), |
| 426 | 426 | 'class_paths' => isset($setup_args['class_paths']) |
| 427 | - ? (array)$setup_args['class_paths'] |
|
| 427 | + ? (array) $setup_args['class_paths'] |
|
| 428 | 428 | : array(), |
| 429 | 429 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
| 430 | - ? (array)$setup_args['model_extension_paths'] |
|
| 430 | + ? (array) $setup_args['model_extension_paths'] |
|
| 431 | 431 | : array(), |
| 432 | 432 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
| 433 | - ? (array)$setup_args['class_extension_paths'] |
|
| 433 | + ? (array) $setup_args['class_extension_paths'] |
|
| 434 | 434 | : array(), |
| 435 | 435 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
| 436 | - ? (array)$setup_args['custom_post_types'] |
|
| 436 | + ? (array) $setup_args['custom_post_types'] |
|
| 437 | 437 | : array(), |
| 438 | 438 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
| 439 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 439 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 440 | 440 | : array(), |
| 441 | 441 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
| 442 | - ? (array)$setup_args['payment_method_paths'] |
|
| 442 | + ? (array) $setup_args['payment_method_paths'] |
|
| 443 | 443 | : array(), |
| 444 | 444 | 'default_terms' => isset($setup_args['default_terms']) |
| 445 | - ? (array)$setup_args['default_terms'] |
|
| 445 | + ? (array) $setup_args['default_terms'] |
|
| 446 | 446 | : array(), |
| 447 | 447 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
| 448 | 448 | // that can be used for adding upgrading/marketing info |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $setup_args['namespace']['FQNS'], |
| 455 | 455 | $setup_args['namespace']['DIR'] |
| 456 | 456 | ) |
| 457 | - ? (array)$setup_args['namespace'] |
|
| 457 | + ? (array) $setup_args['namespace'] |
|
| 458 | 458 | : array(), |
| 459 | 459 | ); |
| 460 | 460 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @param array $addon_settings |
| 476 | 476 | * @return boolean |
| 477 | 477 | */ |
| 478 | - private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
|
| 478 | + private static function _addon_is_compatible($addon_name, array $addon_settings) { |
|
| 479 | 479 | global $wp_version; |
| 480 | 480 | $incompatibility_message = ''; |
| 481 | 481 | //check whether this addon version is compatible with EE core |
@@ -551,20 +551,20 @@ discard block |
||
| 551 | 551 | * @param array $setup_args |
| 552 | 552 | * @return void |
| 553 | 553 | */ |
| 554 | - private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
|
| 554 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) { |
|
| 555 | 555 | if ( ! empty($setup_args['pue_options'])) { |
| 556 | 556 | self::$_settings[$addon_name]['pue_options'] = array( |
| 557 | 557 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 558 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 559 | - : 'espresso_' . strtolower($class_name), |
|
| 558 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 559 | + : 'espresso_'.strtolower($class_name), |
|
| 560 | 560 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 561 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 561 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 562 | 562 | : plugin_basename($setup_args['main_file_path']), |
| 563 | 563 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
| 564 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 564 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 565 | 565 | : '24', |
| 566 | 566 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
| 567 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 567 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 568 | 568 | : false, |
| 569 | 569 | ); |
| 570 | 570 | add_action( |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | * @param array $addon_settings |
| 607 | 607 | * @return bool |
| 608 | 608 | */ |
| 609 | - private static function _addon_activation( $addon_name, array $addon_settings ) { |
|
| 609 | + private static function _addon_activation($addon_name, array $addon_settings) { |
|
| 610 | 610 | // this is an activation request |
| 611 | 611 | if (did_action('activate_plugin')) { |
| 612 | 612 | //to find if THIS is the addon that was activated, |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | } |
| 664 | 664 | // setup autoloaders for folders |
| 665 | 665 | if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
| 666 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 666 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 667 | 667 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 668 | 668 | } |
| 669 | 669 | } |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | * @return void |
| 679 | 679 | * @throws \EE_Error |
| 680 | 680 | */ |
| 681 | - private static function _register_models_and_extensions( $addon_name ) { |
|
| 681 | + private static function _register_models_and_extensions($addon_name) { |
|
| 682 | 682 | // register new models |
| 683 | 683 | if ( |
| 684 | 684 | ! empty(self::$_settings[$addon_name]['model_paths']) |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | * @return void |
| 715 | 715 | * @throws \EE_Error |
| 716 | 716 | */ |
| 717 | - private static function _register_data_migration_scripts( $addon_name ) { |
|
| 717 | + private static function _register_data_migration_scripts($addon_name) { |
|
| 718 | 718 | // setup DMS |
| 719 | 719 | if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
| 720 | 720 | EE_Register_Data_Migration_Scripts::register( |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | * @return void |
| 731 | 731 | * @throws \EE_Error |
| 732 | 732 | */ |
| 733 | - private static function _register_config( $addon_name ) { |
|
| 733 | + private static function _register_config($addon_name) { |
|
| 734 | 734 | // if config_class is present let's register config. |
| 735 | 735 | if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
| 736 | 736 | EE_Register_Config::register( |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @return void |
| 750 | 750 | * @throws \EE_Error |
| 751 | 751 | */ |
| 752 | - private static function _register_admin_pages( $addon_name ) { |
|
| 752 | + private static function _register_admin_pages($addon_name) { |
|
| 753 | 753 | if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
| 754 | 754 | EE_Register_Admin_Page::register( |
| 755 | 755 | $addon_name, |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * @return void |
| 765 | 765 | * @throws \EE_Error |
| 766 | 766 | */ |
| 767 | - private static function _register_modules( $addon_name ) { |
|
| 767 | + private static function _register_modules($addon_name) { |
|
| 768 | 768 | if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
| 769 | 769 | EE_Register_Module::register( |
| 770 | 770 | $addon_name, |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | * @return void |
| 780 | 780 | * @throws \EE_Error |
| 781 | 781 | */ |
| 782 | - private static function _register_shortcodes( $addon_name ) { |
|
| 782 | + private static function _register_shortcodes($addon_name) { |
|
| 783 | 783 | if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
| 784 | 784 | EE_Register_Shortcode::register( |
| 785 | 785 | $addon_name, |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | * @return void |
| 795 | 795 | * @throws \EE_Error |
| 796 | 796 | */ |
| 797 | - private static function _register_widgets( $addon_name ) { |
|
| 797 | + private static function _register_widgets($addon_name) { |
|
| 798 | 798 | if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
| 799 | 799 | EE_Register_Widget::register( |
| 800 | 800 | $addon_name, |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * @return void |
| 810 | 810 | * @throws \EE_Error |
| 811 | 811 | */ |
| 812 | - private static function _register_capabilities( $addon_name ) { |
|
| 812 | + private static function _register_capabilities($addon_name) { |
|
| 813 | 813 | if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
| 814 | 814 | EE_Register_Capabilities::register( |
| 815 | 815 | $addon_name, |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | * @return void |
| 828 | 828 | * @throws \EE_Error |
| 829 | 829 | */ |
| 830 | - private static function _register_message_types( $addon_name ) { |
|
| 830 | + private static function _register_message_types($addon_name) { |
|
| 831 | 831 | if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
| 832 | 832 | add_action( |
| 833 | 833 | 'EE_Brewing_Regular___messages_caf', |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | * @return void |
| 843 | 843 | * @throws \EE_Error |
| 844 | 844 | */ |
| 845 | - private static function _register_custom_post_types( $addon_name ) { |
|
| 845 | + private static function _register_custom_post_types($addon_name) { |
|
| 846 | 846 | if ( |
| 847 | 847 | ! empty(self::$_settings[$addon_name]['custom_post_types']) |
| 848 | 848 | || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | * @return void |
| 865 | 865 | * @throws \EE_Error |
| 866 | 866 | */ |
| 867 | - private static function _register_payment_methods( $addon_name ) { |
|
| 867 | + private static function _register_payment_methods($addon_name) { |
|
| 868 | 868 | if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
| 869 | 869 | EE_Register_Payment_Method::register( |
| 870 | 870 | $addon_name, |
@@ -881,25 +881,25 @@ discard block |
||
| 881 | 881 | * @param string $addon_name |
| 882 | 882 | * @return EE_Addon |
| 883 | 883 | */ |
| 884 | - private static function _load_and_init_addon_class( $addon_name ) { |
|
| 884 | + private static function _load_and_init_addon_class($addon_name) { |
|
| 885 | 885 | $addon = EE_Registry::instance()->load_addon( |
| 886 | - dirname( self::$_settings[ $addon_name ]['main_file_path'] ), |
|
| 887 | - self::$_settings[ $addon_name ]['class_name'] |
|
| 886 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 887 | + self::$_settings[$addon_name]['class_name'] |
|
| 888 | 888 | ); |
| 889 | - $addon->set_name( $addon_name ); |
|
| 890 | - $addon->set_plugin_slug( self::$_settings[ $addon_name ]['plugin_slug'] ); |
|
| 891 | - $addon->set_plugin_basename( self::$_settings[ $addon_name ]['plugin_basename'] ); |
|
| 892 | - $addon->set_main_plugin_file( self::$_settings[ $addon_name ]['main_file_path'] ); |
|
| 893 | - $addon->set_plugin_action_slug( self::$_settings[ $addon_name ]['plugin_action_slug'] ); |
|
| 894 | - $addon->set_plugins_page_row( self::$_settings[ $addon_name ]['plugins_page_row'] ); |
|
| 895 | - $addon->set_version( self::$_settings[ $addon_name ]['version'] ); |
|
| 896 | - $addon->set_min_core_version( self::_effective_version( self::$_settings[ $addon_name ]['min_core_version'] ) ); |
|
| 897 | - $addon->set_config_section( self::$_settings[ $addon_name ]['config_section'] ); |
|
| 898 | - $addon->set_config_class( self::$_settings[ $addon_name ]['config_class'] ); |
|
| 899 | - $addon->set_config_name( self::$_settings[ $addon_name ]['config_name'] ); |
|
| 889 | + $addon->set_name($addon_name); |
|
| 890 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 891 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 892 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 893 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 894 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 895 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 896 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 897 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 898 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 899 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 900 | 900 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 901 | 901 | //the plugin mainfile's path upon construction. |
| 902 | - register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
|
| 902 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 903 | 903 | // call any additional admin_callback functions during load_admin_controller hook |
| 904 | 904 | if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
| 905 | 905 | add_action( |
@@ -919,18 +919,18 @@ discard block |
||
| 919 | 919 | */ |
| 920 | 920 | public static function load_pue_update() { |
| 921 | 921 | // load PUE client |
| 922 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 922 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 923 | 923 | // cycle thru settings |
| 924 | - foreach ( self::$_settings as $settings ) { |
|
| 925 | - if ( ! empty( $settings['pue_options'] ) ) { |
|
| 924 | + foreach (self::$_settings as $settings) { |
|
| 925 | + if ( ! empty($settings['pue_options'])) { |
|
| 926 | 926 | // initiate the class and start the plugin update engine! |
| 927 | 927 | new PluginUpdateEngineChecker( |
| 928 | 928 | // host file URL |
| 929 | 929 | 'https://eventespresso.com', |
| 930 | 930 | // plugin slug(s) |
| 931 | 931 | array( |
| 932 | - 'premium' => array( 'p' => $settings['pue_options']['pue_plugin_slug'] ), |
|
| 933 | - 'prerelease' => array( 'beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr' ), |
|
| 932 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 933 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 934 | 934 | ), |
| 935 | 935 | // options |
| 936 | 936 | array( |
@@ -958,9 +958,9 @@ discard block |
||
| 958 | 958 | * @throws \EE_Error |
| 959 | 959 | */ |
| 960 | 960 | public static function register_message_types() { |
| 961 | - foreach ( self::$_settings as $addon_name => $settings ) { |
|
| 961 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 962 | 962 | if ( ! empty($settings['message_types'])) { |
| 963 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 963 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 964 | 964 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 965 | 965 | } |
| 966 | 966 | } |
@@ -977,73 +977,73 @@ discard block |
||
| 977 | 977 | * @throws EE_Error |
| 978 | 978 | * @return void |
| 979 | 979 | */ |
| 980 | - public static function deregister( $addon_name = null ) { |
|
| 981 | - if ( isset( self::$_settings[ $addon_name ] ) ) { |
|
| 982 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 983 | - if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
|
| 980 | + public static function deregister($addon_name = null) { |
|
| 981 | + if (isset(self::$_settings[$addon_name])) { |
|
| 982 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 983 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 984 | 984 | // setup DMS |
| 985 | - EE_Register_Data_Migration_Scripts::deregister( $addon_name ); |
|
| 985 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 986 | 986 | } |
| 987 | - if ( ! empty( self::$_settings[ $addon_name ]['admin_path'] ) ) { |
|
| 987 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 988 | 988 | // register admin page |
| 989 | - EE_Register_Admin_Page::deregister( $addon_name ); |
|
| 989 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 990 | 990 | } |
| 991 | - if ( ! empty( self::$_settings[ $addon_name ]['module_paths'] ) ) { |
|
| 991 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 992 | 992 | // add to list of modules to be registered |
| 993 | - EE_Register_Module::deregister( $addon_name ); |
|
| 993 | + EE_Register_Module::deregister($addon_name); |
|
| 994 | 994 | } |
| 995 | - if ( ! empty( self::$_settings[ $addon_name ]['shortcode_paths'] ) ) { |
|
| 995 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 996 | 996 | // add to list of shortcodes to be registered |
| 997 | - EE_Register_Shortcode::deregister( $addon_name ); |
|
| 997 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 998 | 998 | } |
| 999 | - if ( ! empty( self::$_settings[ $addon_name ]['config_class'] ) ) { |
|
| 999 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1000 | 1000 | // if config_class present let's register config. |
| 1001 | - EE_Register_Config::deregister( self::$_settings[ $addon_name ]['config_class'] ); |
|
| 1001 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1002 | 1002 | } |
| 1003 | - if ( ! empty( self::$_settings[ $addon_name ]['widget_paths'] ) ) { |
|
| 1003 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1004 | 1004 | // add to list of widgets to be registered |
| 1005 | - EE_Register_Widget::deregister( $addon_name ); |
|
| 1005 | + EE_Register_Widget::deregister($addon_name); |
|
| 1006 | 1006 | } |
| 1007 | - if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
|
| 1007 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1008 | 1008 | || |
| 1009 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
| 1009 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1010 | 1010 | ) { |
| 1011 | 1011 | // add to list of shortcodes to be registered |
| 1012 | - EE_Register_Model::deregister( $addon_name ); |
|
| 1012 | + EE_Register_Model::deregister($addon_name); |
|
| 1013 | 1013 | } |
| 1014 | - if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
|
| 1014 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1015 | 1015 | || |
| 1016 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
| 1016 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1017 | 1017 | ) { |
| 1018 | 1018 | // add to list of shortcodes to be registered |
| 1019 | - EE_Register_Model_Extensions::deregister( $addon_name ); |
|
| 1019 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1020 | 1020 | } |
| 1021 | - if ( ! empty( self::$_settings[ $addon_name ]['message_types'] ) ) { |
|
| 1022 | - foreach ((array)self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings ) |
|
| 1021 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1022 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) |
|
| 1023 | 1023 | { |
| 1024 | - EE_Register_Message_Type::deregister( $message_type ); |
|
| 1024 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1025 | 1025 | } |
| 1026 | 1026 | } |
| 1027 | 1027 | //deregister capabilities for addon |
| 1028 | 1028 | if ( |
| 1029 | - ! empty( self::$_settings[ $addon_name ]['capabilities'] ) |
|
| 1030 | - || ! empty( self::$_settings[ $addon_name ]['capability_maps'] ) |
|
| 1029 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1030 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1031 | 1031 | ) { |
| 1032 | - EE_Register_Capabilities::deregister( $addon_name ); |
|
| 1032 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1033 | 1033 | } |
| 1034 | 1034 | //deregister custom_post_types for addon |
| 1035 | - if ( ! empty( self::$_settings[ $addon_name ]['custom_post_types'] ) ) { |
|
| 1036 | - EE_Register_CPT::deregister( $addon_name ); |
|
| 1035 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1036 | + EE_Register_CPT::deregister($addon_name); |
|
| 1037 | 1037 | } |
| 1038 | 1038 | remove_action( |
| 1039 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1040 | - array( EE_Registry::instance()->addons->{$class_name}, 'deactivation' ) |
|
| 1039 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
| 1040 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
| 1041 | 1041 | ); |
| 1042 | 1042 | remove_action( |
| 1043 | 1043 | 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
| 1044 | - array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
|
| 1044 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
| 1045 | 1045 | ); |
| 1046 | - unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
|
| 1046 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | } |
| 1049 | 1049 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | protected static $_incompatible_addons = array( |
| 49 | 49 | 'Multi_Event_Registration' => '2.0.11.rc.002', |
| 50 | 50 | 'Promotions' => '1.0.0.rc.084', |
| 51 | - ); |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | |
@@ -219,660 +219,660 @@ discard block |
||
| 219 | 219 | */ |
| 220 | 220 | public static function register( $addon_name = '', $setup_args = array() ) { |
| 221 | 221 | // required fields MUST be present, so let's make sure they are. |
| 222 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 223 | - // get class name for addon |
|
| 222 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 223 | + // get class name for addon |
|
| 224 | 224 | $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
| 225 | 225 | //setup $_settings array from incoming values. |
| 226 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 227 | - // setup PUE |
|
| 228 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 229 | - // does this addon work with this version of core or WordPress ? |
|
| 230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
| 231 | - return; |
|
| 226 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 227 | + // setup PUE |
|
| 228 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 229 | + // does this addon work with this version of core or WordPress ? |
|
| 230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
| 231 | + return; |
|
| 232 | 232 | } |
| 233 | 233 | // register namespaces |
| 234 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 235 | - // check if this is an activation request |
|
| 236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 237 | - // dont bother setting up the rest of the addon atm |
|
| 238 | - return; |
|
| 239 | - } |
|
| 240 | - // we need cars |
|
| 241 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 242 | - // register new models and extensions |
|
| 243 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 244 | - // setup DMS |
|
| 245 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 246 | - // if config_class is present let's register config. |
|
| 247 | - \EE_Register_Addon::_register_config($addon_name); |
|
| 248 | - // register admin pages |
|
| 249 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 250 | - // add to list of modules to be registered |
|
| 251 | - \EE_Register_Addon::_register_modules($addon_name); |
|
| 252 | - // add to list of shortcodes to be registered |
|
| 253 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 254 | - // add to list of widgets to be registered |
|
| 255 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
| 256 | - // register capability related stuff. |
|
| 257 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 258 | - // any message type to register? |
|
| 259 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
| 234 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 235 | + // check if this is an activation request |
|
| 236 | + if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 237 | + // dont bother setting up the rest of the addon atm |
|
| 238 | + return; |
|
| 239 | + } |
|
| 240 | + // we need cars |
|
| 241 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 242 | + // register new models and extensions |
|
| 243 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 244 | + // setup DMS |
|
| 245 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 246 | + // if config_class is present let's register config. |
|
| 247 | + \EE_Register_Addon::_register_config($addon_name); |
|
| 248 | + // register admin pages |
|
| 249 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 250 | + // add to list of modules to be registered |
|
| 251 | + \EE_Register_Addon::_register_modules($addon_name); |
|
| 252 | + // add to list of shortcodes to be registered |
|
| 253 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 254 | + // add to list of widgets to be registered |
|
| 255 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
| 256 | + // register capability related stuff. |
|
| 257 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 258 | + // any message type to register? |
|
| 259 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
| 260 | 260 | // any custom post type/ custom capabilities or default terms to register |
| 261 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 262 | - // and any payment methods |
|
| 263 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 261 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 262 | + // and any payment methods |
|
| 263 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 264 | 264 | // load and instantiate main addon class |
| 265 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 266 | - $addon->after_registration(); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param string $addon_name |
|
| 273 | - * @param array $setup_args |
|
| 274 | - * @return void |
|
| 275 | - * @throws \EE_Error |
|
| 276 | - */ |
|
| 277 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 278 | - { |
|
| 279 | - // required fields MUST be present, so let's make sure they are. |
|
| 280 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 281 | - throw new EE_Error( |
|
| 282 | - __( |
|
| 283 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 284 | - 'event_espresso' |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 289 | - throw new EE_Error( |
|
| 290 | - sprintf( |
|
| 291 | - __( |
|
| 292 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 293 | - 'event_espresso' |
|
| 294 | - ), |
|
| 295 | - implode(',', array_keys($setup_args)) |
|
| 296 | - ) |
|
| 297 | - ); |
|
| 298 | - } |
|
| 299 | - // check that addon has not already been registered with that name |
|
| 300 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 301 | - throw new EE_Error( |
|
| 302 | - sprintf( |
|
| 303 | - __( |
|
| 304 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 305 | - 'event_espresso' |
|
| 306 | - ), |
|
| 307 | - $addon_name |
|
| 308 | - ) |
|
| 309 | - ); |
|
| 310 | - } |
|
| 265 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 266 | + $addon->after_registration(); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param string $addon_name |
|
| 273 | + * @param array $setup_args |
|
| 274 | + * @return void |
|
| 275 | + * @throws \EE_Error |
|
| 276 | + */ |
|
| 277 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 278 | + { |
|
| 279 | + // required fields MUST be present, so let's make sure they are. |
|
| 280 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 281 | + throw new EE_Error( |
|
| 282 | + __( |
|
| 283 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 284 | + 'event_espresso' |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 289 | + throw new EE_Error( |
|
| 290 | + sprintf( |
|
| 291 | + __( |
|
| 292 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 293 | + 'event_espresso' |
|
| 294 | + ), |
|
| 295 | + implode(',', array_keys($setup_args)) |
|
| 296 | + ) |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | + // check that addon has not already been registered with that name |
|
| 300 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 301 | + throw new EE_Error( |
|
| 302 | + sprintf( |
|
| 303 | + __( |
|
| 304 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 305 | + 'event_espresso' |
|
| 306 | + ), |
|
| 307 | + $addon_name |
|
| 308 | + ) |
|
| 309 | + ); |
|
| 310 | + } |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
| 314 | 314 | |
| 315 | - /** |
|
| 316 | - * @param string $addon_name |
|
| 317 | - * @param array $setup_args |
|
| 318 | - * @return string |
|
| 319 | - */ |
|
| 320 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 321 | - { |
|
| 322 | - if (empty($setup_args['class_name'])) { |
|
| 323 | - // generate one by first separating name with spaces |
|
| 324 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 325 | - //capitalize, then replace spaces with underscores |
|
| 326 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 327 | - } else { |
|
| 328 | - $class_name = $setup_args['class_name']; |
|
| 329 | - } |
|
| 330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param string $class_name |
|
| 337 | - * @param array $setup_args |
|
| 338 | - * @return array |
|
| 339 | - */ |
|
| 340 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 341 | - { |
|
| 342 | - //setup $_settings array from incoming values. |
|
| 343 | - $addon_settings = array( |
|
| 344 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 345 | - 'class_name' => $class_name, |
|
| 346 | - // the addon slug for use in URLs, etc |
|
| 347 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 348 | - ? (string)$setup_args['plugin_slug'] |
|
| 349 | - : '', |
|
| 350 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 351 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 352 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 353 | - : '', |
|
| 354 | - // the "software" version for the addon |
|
| 355 | - 'version' => isset($setup_args['version']) |
|
| 356 | - ? (string)$setup_args['version'] |
|
| 357 | - : '', |
|
| 358 | - // the minimum version of EE Core that the addon will work with |
|
| 359 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 360 | - ? (string)$setup_args['min_core_version'] |
|
| 361 | - : '', |
|
| 362 | - // the minimum version of WordPress that the addon will work with |
|
| 363 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 364 | - ? (string)$setup_args['min_wp_version'] |
|
| 365 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 366 | - // full server path to main file (file loaded directly by WP) |
|
| 367 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 368 | - ? (string)$setup_args['main_file_path'] |
|
| 369 | - : '', |
|
| 370 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 371 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 372 | - ? (string)$setup_args['admin_path'] : '', |
|
| 373 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 374 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 375 | - ? (string)$setup_args['admin_callback'] |
|
| 376 | - : '', |
|
| 377 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 378 | - 'config_section' => isset($setup_args['config_section']) |
|
| 379 | - ? (string)$setup_args['config_section'] |
|
| 380 | - : 'addons', |
|
| 381 | - // the class name for this addon's configuration settings object |
|
| 382 | - 'config_class' => isset($setup_args['config_class']) |
|
| 383 | - ? (string)$setup_args['config_class'] : '', |
|
| 384 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 385 | - 'config_name' => isset($setup_args['config_name']) |
|
| 386 | - ? (string)$setup_args['config_name'] : '', |
|
| 387 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 388 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 389 | - ? (array)$setup_args['autoloader_paths'] |
|
| 390 | - : array(), |
|
| 391 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 392 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 393 | - ? (array)$setup_args['autoloader_folders'] |
|
| 394 | - : array(), |
|
| 395 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 396 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 397 | - ? (array)$setup_args['dms_paths'] |
|
| 398 | - : array(), |
|
| 399 | - // array of full server paths to any EED_Modules used by the addon |
|
| 400 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 401 | - ? (array)$setup_args['module_paths'] |
|
| 402 | - : array(), |
|
| 403 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 404 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 405 | - ? (array)$setup_args['shortcode_paths'] |
|
| 406 | - : array(), |
|
| 407 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 408 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 409 | - ? (array)$setup_args['widget_paths'] |
|
| 410 | - : array(), |
|
| 411 | - // array of PUE options used by the addon |
|
| 412 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 413 | - ? (array)$setup_args['pue_options'] |
|
| 414 | - : array(), |
|
| 415 | - 'message_types' => isset($setup_args['message_types']) |
|
| 416 | - ? (array)$setup_args['message_types'] |
|
| 417 | - : array(), |
|
| 418 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 419 | - ? (array)$setup_args['capabilities'] |
|
| 420 | - : array(), |
|
| 421 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 422 | - ? (array)$setup_args['capability_maps'] |
|
| 423 | - : array(), |
|
| 424 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 425 | - ? (array)$setup_args['model_paths'] |
|
| 426 | - : array(), |
|
| 427 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 428 | - ? (array)$setup_args['class_paths'] |
|
| 429 | - : array(), |
|
| 430 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 431 | - ? (array)$setup_args['model_extension_paths'] |
|
| 432 | - : array(), |
|
| 433 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 434 | - ? (array)$setup_args['class_extension_paths'] |
|
| 435 | - : array(), |
|
| 436 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 437 | - ? (array)$setup_args['custom_post_types'] |
|
| 438 | - : array(), |
|
| 439 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 440 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 441 | - : array(), |
|
| 442 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 443 | - ? (array)$setup_args['payment_method_paths'] |
|
| 444 | - : array(), |
|
| 445 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 446 | - ? (array)$setup_args['default_terms'] |
|
| 447 | - : array(), |
|
| 448 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 449 | - // that can be used for adding upgrading/marketing info |
|
| 450 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 451 | - ? $setup_args['plugins_page_row'] |
|
| 452 | - : '', |
|
| 453 | - 'namespace' => isset( |
|
| 454 | - $setup_args['namespace'], |
|
| 455 | - $setup_args['namespace']['FQNS'], |
|
| 456 | - $setup_args['namespace']['DIR'] |
|
| 457 | - ) |
|
| 458 | - ? (array)$setup_args['namespace'] |
|
| 459 | - : array(), |
|
| 460 | - ); |
|
| 461 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 462 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 463 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 464 | - && ! empty($addon_settings['admin_path']) |
|
| 465 | - ? $addon_settings['plugin_slug'] |
|
| 466 | - : $addon_settings['plugin_action_slug']; |
|
| 467 | - // full server path to main file (file loaded directly by WP) |
|
| 468 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 469 | - return $addon_settings; |
|
| 315 | + /** |
|
| 316 | + * @param string $addon_name |
|
| 317 | + * @param array $setup_args |
|
| 318 | + * @return string |
|
| 319 | + */ |
|
| 320 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 321 | + { |
|
| 322 | + if (empty($setup_args['class_name'])) { |
|
| 323 | + // generate one by first separating name with spaces |
|
| 324 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 325 | + //capitalize, then replace spaces with underscores |
|
| 326 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 327 | + } else { |
|
| 328 | + $class_name = $setup_args['class_name']; |
|
| 329 | + } |
|
| 330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
| 470 | 331 | } |
| 471 | 332 | |
| 472 | 333 | |
| 473 | 334 | |
| 474 | - /** |
|
| 475 | - * @param string $addon_name |
|
| 476 | - * @param array $addon_settings |
|
| 477 | - * @return boolean |
|
| 478 | - */ |
|
| 335 | + /** |
|
| 336 | + * @param string $class_name |
|
| 337 | + * @param array $setup_args |
|
| 338 | + * @return array |
|
| 339 | + */ |
|
| 340 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 341 | + { |
|
| 342 | + //setup $_settings array from incoming values. |
|
| 343 | + $addon_settings = array( |
|
| 344 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 345 | + 'class_name' => $class_name, |
|
| 346 | + // the addon slug for use in URLs, etc |
|
| 347 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 348 | + ? (string)$setup_args['plugin_slug'] |
|
| 349 | + : '', |
|
| 350 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 351 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 352 | + ? (string)$setup_args['plugin_action_slug'] |
|
| 353 | + : '', |
|
| 354 | + // the "software" version for the addon |
|
| 355 | + 'version' => isset($setup_args['version']) |
|
| 356 | + ? (string)$setup_args['version'] |
|
| 357 | + : '', |
|
| 358 | + // the minimum version of EE Core that the addon will work with |
|
| 359 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 360 | + ? (string)$setup_args['min_core_version'] |
|
| 361 | + : '', |
|
| 362 | + // the minimum version of WordPress that the addon will work with |
|
| 363 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 364 | + ? (string)$setup_args['min_wp_version'] |
|
| 365 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 366 | + // full server path to main file (file loaded directly by WP) |
|
| 367 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 368 | + ? (string)$setup_args['main_file_path'] |
|
| 369 | + : '', |
|
| 370 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 371 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 372 | + ? (string)$setup_args['admin_path'] : '', |
|
| 373 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 374 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 375 | + ? (string)$setup_args['admin_callback'] |
|
| 376 | + : '', |
|
| 377 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 378 | + 'config_section' => isset($setup_args['config_section']) |
|
| 379 | + ? (string)$setup_args['config_section'] |
|
| 380 | + : 'addons', |
|
| 381 | + // the class name for this addon's configuration settings object |
|
| 382 | + 'config_class' => isset($setup_args['config_class']) |
|
| 383 | + ? (string)$setup_args['config_class'] : '', |
|
| 384 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 385 | + 'config_name' => isset($setup_args['config_name']) |
|
| 386 | + ? (string)$setup_args['config_name'] : '', |
|
| 387 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 388 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 389 | + ? (array)$setup_args['autoloader_paths'] |
|
| 390 | + : array(), |
|
| 391 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 392 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 393 | + ? (array)$setup_args['autoloader_folders'] |
|
| 394 | + : array(), |
|
| 395 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 396 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 397 | + ? (array)$setup_args['dms_paths'] |
|
| 398 | + : array(), |
|
| 399 | + // array of full server paths to any EED_Modules used by the addon |
|
| 400 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 401 | + ? (array)$setup_args['module_paths'] |
|
| 402 | + : array(), |
|
| 403 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 404 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 405 | + ? (array)$setup_args['shortcode_paths'] |
|
| 406 | + : array(), |
|
| 407 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 408 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 409 | + ? (array)$setup_args['widget_paths'] |
|
| 410 | + : array(), |
|
| 411 | + // array of PUE options used by the addon |
|
| 412 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 413 | + ? (array)$setup_args['pue_options'] |
|
| 414 | + : array(), |
|
| 415 | + 'message_types' => isset($setup_args['message_types']) |
|
| 416 | + ? (array)$setup_args['message_types'] |
|
| 417 | + : array(), |
|
| 418 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 419 | + ? (array)$setup_args['capabilities'] |
|
| 420 | + : array(), |
|
| 421 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 422 | + ? (array)$setup_args['capability_maps'] |
|
| 423 | + : array(), |
|
| 424 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 425 | + ? (array)$setup_args['model_paths'] |
|
| 426 | + : array(), |
|
| 427 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 428 | + ? (array)$setup_args['class_paths'] |
|
| 429 | + : array(), |
|
| 430 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 431 | + ? (array)$setup_args['model_extension_paths'] |
|
| 432 | + : array(), |
|
| 433 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 434 | + ? (array)$setup_args['class_extension_paths'] |
|
| 435 | + : array(), |
|
| 436 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 437 | + ? (array)$setup_args['custom_post_types'] |
|
| 438 | + : array(), |
|
| 439 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 440 | + ? (array)$setup_args['custom_taxonomies'] |
|
| 441 | + : array(), |
|
| 442 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 443 | + ? (array)$setup_args['payment_method_paths'] |
|
| 444 | + : array(), |
|
| 445 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 446 | + ? (array)$setup_args['default_terms'] |
|
| 447 | + : array(), |
|
| 448 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 449 | + // that can be used for adding upgrading/marketing info |
|
| 450 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 451 | + ? $setup_args['plugins_page_row'] |
|
| 452 | + : '', |
|
| 453 | + 'namespace' => isset( |
|
| 454 | + $setup_args['namespace'], |
|
| 455 | + $setup_args['namespace']['FQNS'], |
|
| 456 | + $setup_args['namespace']['DIR'] |
|
| 457 | + ) |
|
| 458 | + ? (array)$setup_args['namespace'] |
|
| 459 | + : array(), |
|
| 460 | + ); |
|
| 461 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 462 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 463 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 464 | + && ! empty($addon_settings['admin_path']) |
|
| 465 | + ? $addon_settings['plugin_slug'] |
|
| 466 | + : $addon_settings['plugin_action_slug']; |
|
| 467 | + // full server path to main file (file loaded directly by WP) |
|
| 468 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 469 | + return $addon_settings; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * @param string $addon_name |
|
| 476 | + * @param array $addon_settings |
|
| 477 | + * @return boolean |
|
| 478 | + */ |
|
| 479 | 479 | private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
| 480 | - global $wp_version; |
|
| 481 | - $incompatibility_message = ''; |
|
| 482 | - //check whether this addon version is compatible with EE core |
|
| 483 | - if ( |
|
| 484 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 485 | - && ! self::_meets_min_core_version_requirement( |
|
| 486 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 487 | - $addon_settings['version'] |
|
| 488 | - ) |
|
| 489 | - ) { |
|
| 490 | - $incompatibility_message = sprintf( |
|
| 491 | - __( |
|
| 492 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 493 | - ), |
|
| 494 | - $addon_name, |
|
| 495 | - '<br />', |
|
| 496 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 497 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 498 | - '</span><br />' |
|
| 499 | - ); |
|
| 500 | - } else if ( |
|
| 501 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 502 | - ) { |
|
| 503 | - $incompatibility_message = sprintf( |
|
| 504 | - __( |
|
| 505 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 506 | - 'event_espresso' |
|
| 507 | - ), |
|
| 508 | - $addon_name, |
|
| 509 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 510 | - self::_effective_version(espresso_version()), |
|
| 511 | - '<br />', |
|
| 512 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 513 | - '</span><br />' |
|
| 514 | - ); |
|
| 515 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 516 | - $incompatibility_message = sprintf( |
|
| 517 | - __( |
|
| 518 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 519 | - 'event_espresso' |
|
| 520 | - ), |
|
| 521 | - $addon_name, |
|
| 522 | - $addon_settings['min_wp_version'], |
|
| 523 | - '<br />', |
|
| 524 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 525 | - '</span><br />' |
|
| 526 | - ); |
|
| 527 | - } |
|
| 528 | - if ( ! empty($incompatibility_message)) { |
|
| 529 | - // remove 'activate' from the REQUEST |
|
| 530 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 531 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 532 | - if (current_user_can('activate_plugins')) { |
|
| 533 | - // show an error message indicating the plugin didn't activate properly |
|
| 534 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 535 | - } |
|
| 536 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 537 | - return false; |
|
| 538 | - } |
|
| 539 | - // addon IS compatible |
|
| 540 | - return true; |
|
| 480 | + global $wp_version; |
|
| 481 | + $incompatibility_message = ''; |
|
| 482 | + //check whether this addon version is compatible with EE core |
|
| 483 | + if ( |
|
| 484 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 485 | + && ! self::_meets_min_core_version_requirement( |
|
| 486 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 487 | + $addon_settings['version'] |
|
| 488 | + ) |
|
| 489 | + ) { |
|
| 490 | + $incompatibility_message = sprintf( |
|
| 491 | + __( |
|
| 492 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 493 | + ), |
|
| 494 | + $addon_name, |
|
| 495 | + '<br />', |
|
| 496 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 497 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 498 | + '</span><br />' |
|
| 499 | + ); |
|
| 500 | + } else if ( |
|
| 501 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 502 | + ) { |
|
| 503 | + $incompatibility_message = sprintf( |
|
| 504 | + __( |
|
| 505 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 506 | + 'event_espresso' |
|
| 507 | + ), |
|
| 508 | + $addon_name, |
|
| 509 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 510 | + self::_effective_version(espresso_version()), |
|
| 511 | + '<br />', |
|
| 512 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 513 | + '</span><br />' |
|
| 514 | + ); |
|
| 515 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 516 | + $incompatibility_message = sprintf( |
|
| 517 | + __( |
|
| 518 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 519 | + 'event_espresso' |
|
| 520 | + ), |
|
| 521 | + $addon_name, |
|
| 522 | + $addon_settings['min_wp_version'], |
|
| 523 | + '<br />', |
|
| 524 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 525 | + '</span><br />' |
|
| 526 | + ); |
|
| 527 | + } |
|
| 528 | + if ( ! empty($incompatibility_message)) { |
|
| 529 | + // remove 'activate' from the REQUEST |
|
| 530 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 531 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 532 | + if (current_user_can('activate_plugins')) { |
|
| 533 | + // show an error message indicating the plugin didn't activate properly |
|
| 534 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 535 | + } |
|
| 536 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 537 | + return false; |
|
| 538 | + } |
|
| 539 | + // addon IS compatible |
|
| 540 | + return true; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | |
| 544 | 544 | |
| 545 | - /** |
|
| 546 | - * if plugin update engine is being used for auto-updates, |
|
| 547 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 548 | - * (not needed if PUE is not being used) |
|
| 549 | - * |
|
| 550 | - * @param string $addon_name |
|
| 551 | - * @param string $class_name |
|
| 552 | - * @param array $setup_args |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 545 | + /** |
|
| 546 | + * if plugin update engine is being used for auto-updates, |
|
| 547 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 548 | + * (not needed if PUE is not being used) |
|
| 549 | + * |
|
| 550 | + * @param string $addon_name |
|
| 551 | + * @param string $class_name |
|
| 552 | + * @param array $setup_args |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | 555 | private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
| 556 | - if ( ! empty($setup_args['pue_options'])) { |
|
| 557 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
| 558 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 560 | - : 'espresso_' . strtolower($class_name), |
|
| 561 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 563 | - : plugin_basename($setup_args['main_file_path']), |
|
| 564 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 566 | - : '24', |
|
| 567 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 569 | - : false, |
|
| 570 | - ); |
|
| 571 | - add_action( |
|
| 572 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 573 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 574 | - ); |
|
| 575 | - } |
|
| 556 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 557 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 558 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 559 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 560 | + : 'espresso_' . strtolower($class_name), |
|
| 561 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 562 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 563 | + : plugin_basename($setup_args['main_file_path']), |
|
| 564 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 565 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 566 | + : '24', |
|
| 567 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 568 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 569 | + : false, |
|
| 570 | + ); |
|
| 571 | + add_action( |
|
| 572 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 573 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | |
| 580 | - /** |
|
| 581 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 582 | - * |
|
| 583 | - * @param array $addon_settings |
|
| 584 | - * @return void |
|
| 585 | - */ |
|
| 586 | - private static function _setup_namespaces(array $addon_settings) |
|
| 587 | - { |
|
| 588 | - // |
|
| 589 | - if ( |
|
| 590 | - isset( |
|
| 591 | - $addon_settings['namespace'], |
|
| 592 | - $addon_settings['namespace']['FQNS'], |
|
| 593 | - $addon_settings['namespace']['DIR'] |
|
| 594 | - ) |
|
| 595 | - ) { |
|
| 596 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 597 | - $addon_settings['namespace']['FQNS'], |
|
| 598 | - $addon_settings['namespace']['DIR'] |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - |
|
| 605 | - /** |
|
| 606 | - * @param string $addon_name |
|
| 607 | - * @param array $addon_settings |
|
| 608 | - * @return bool |
|
| 609 | - */ |
|
| 580 | + /** |
|
| 581 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 582 | + * |
|
| 583 | + * @param array $addon_settings |
|
| 584 | + * @return void |
|
| 585 | + */ |
|
| 586 | + private static function _setup_namespaces(array $addon_settings) |
|
| 587 | + { |
|
| 588 | + // |
|
| 589 | + if ( |
|
| 590 | + isset( |
|
| 591 | + $addon_settings['namespace'], |
|
| 592 | + $addon_settings['namespace']['FQNS'], |
|
| 593 | + $addon_settings['namespace']['DIR'] |
|
| 594 | + ) |
|
| 595 | + ) { |
|
| 596 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 597 | + $addon_settings['namespace']['FQNS'], |
|
| 598 | + $addon_settings['namespace']['DIR'] |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + |
|
| 605 | + /** |
|
| 606 | + * @param string $addon_name |
|
| 607 | + * @param array $addon_settings |
|
| 608 | + * @return bool |
|
| 609 | + */ |
|
| 610 | 610 | private static function _addon_activation( $addon_name, array $addon_settings ) { |
| 611 | - // this is an activation request |
|
| 612 | - if (did_action('activate_plugin')) { |
|
| 613 | - //to find if THIS is the addon that was activated, |
|
| 614 | - //just check if we have already registered it or not |
|
| 615 | - //(as the newly-activated addon wasn't around the first time addons were registered) |
|
| 616 | - if ( ! isset(self::$_settings[$addon_name])) { |
|
| 617 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 618 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 619 | - $addon->set_activation_indicator_option(); |
|
| 620 | - // dont bother setting up the rest of the addon. |
|
| 621 | - // we know it was just activated and the request will end soon |
|
| 622 | - } |
|
| 623 | - return true; |
|
| 624 | - } else { |
|
| 625 | - // make sure this was called in the right place! |
|
| 626 | - if ( |
|
| 627 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 628 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 629 | - ) { |
|
| 630 | - EE_Error::doing_it_wrong( |
|
| 631 | - __METHOD__, |
|
| 632 | - sprintf( |
|
| 633 | - __( |
|
| 634 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - $addon_name |
|
| 638 | - ), |
|
| 639 | - '4.3.0' |
|
| 640 | - ); |
|
| 641 | - } |
|
| 642 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 643 | - if (isset(self::$_settings[$addon_name])) { |
|
| 644 | - self::$_settings[$addon_name] += $addon_settings; |
|
| 645 | - } else { |
|
| 646 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - return false; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @param string $addon_name |
|
| 656 | - * @return void |
|
| 657 | - * @throws \EE_Error |
|
| 658 | - */ |
|
| 659 | - private static function _setup_autoloaders($addon_name) |
|
| 660 | - { |
|
| 661 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 662 | - // setup autoloader for single file |
|
| 663 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 664 | - } |
|
| 665 | - // setup autoloaders for folders |
|
| 666 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 668 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * register new models and extensions |
|
| 677 | - * |
|
| 678 | - * @param string $addon_name |
|
| 679 | - * @return void |
|
| 680 | - * @throws \EE_Error |
|
| 681 | - */ |
|
| 611 | + // this is an activation request |
|
| 612 | + if (did_action('activate_plugin')) { |
|
| 613 | + //to find if THIS is the addon that was activated, |
|
| 614 | + //just check if we have already registered it or not |
|
| 615 | + //(as the newly-activated addon wasn't around the first time addons were registered) |
|
| 616 | + if ( ! isset(self::$_settings[$addon_name])) { |
|
| 617 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 618 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 619 | + $addon->set_activation_indicator_option(); |
|
| 620 | + // dont bother setting up the rest of the addon. |
|
| 621 | + // we know it was just activated and the request will end soon |
|
| 622 | + } |
|
| 623 | + return true; |
|
| 624 | + } else { |
|
| 625 | + // make sure this was called in the right place! |
|
| 626 | + if ( |
|
| 627 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 628 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 629 | + ) { |
|
| 630 | + EE_Error::doing_it_wrong( |
|
| 631 | + __METHOD__, |
|
| 632 | + sprintf( |
|
| 633 | + __( |
|
| 634 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + $addon_name |
|
| 638 | + ), |
|
| 639 | + '4.3.0' |
|
| 640 | + ); |
|
| 641 | + } |
|
| 642 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 643 | + if (isset(self::$_settings[$addon_name])) { |
|
| 644 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 645 | + } else { |
|
| 646 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + return false; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @param string $addon_name |
|
| 656 | + * @return void |
|
| 657 | + * @throws \EE_Error |
|
| 658 | + */ |
|
| 659 | + private static function _setup_autoloaders($addon_name) |
|
| 660 | + { |
|
| 661 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 662 | + // setup autoloader for single file |
|
| 663 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 664 | + } |
|
| 665 | + // setup autoloaders for folders |
|
| 666 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 667 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 668 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * register new models and extensions |
|
| 677 | + * |
|
| 678 | + * @param string $addon_name |
|
| 679 | + * @return void |
|
| 680 | + * @throws \EE_Error |
|
| 681 | + */ |
|
| 682 | 682 | private static function _register_models_and_extensions( $addon_name ) { |
| 683 | - // register new models |
|
| 684 | - if ( |
|
| 685 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 686 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 687 | - ) { |
|
| 688 | - EE_Register_Model::register( |
|
| 689 | - $addon_name, |
|
| 690 | - array( |
|
| 691 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 692 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 693 | - ) |
|
| 694 | - ); |
|
| 695 | - } |
|
| 696 | - // register model extensions |
|
| 697 | - if ( |
|
| 698 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 699 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 700 | - ) { |
|
| 701 | - EE_Register_Model_Extensions::register( |
|
| 702 | - $addon_name, |
|
| 703 | - array( |
|
| 704 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 705 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 706 | - ) |
|
| 707 | - ); |
|
| 708 | - } |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * @param string $addon_name |
|
| 715 | - * @return void |
|
| 716 | - * @throws \EE_Error |
|
| 717 | - */ |
|
| 683 | + // register new models |
|
| 684 | + if ( |
|
| 685 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 686 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 687 | + ) { |
|
| 688 | + EE_Register_Model::register( |
|
| 689 | + $addon_name, |
|
| 690 | + array( |
|
| 691 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 692 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 693 | + ) |
|
| 694 | + ); |
|
| 695 | + } |
|
| 696 | + // register model extensions |
|
| 697 | + if ( |
|
| 698 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 699 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 700 | + ) { |
|
| 701 | + EE_Register_Model_Extensions::register( |
|
| 702 | + $addon_name, |
|
| 703 | + array( |
|
| 704 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 705 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 706 | + ) |
|
| 707 | + ); |
|
| 708 | + } |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * @param string $addon_name |
|
| 715 | + * @return void |
|
| 716 | + * @throws \EE_Error |
|
| 717 | + */ |
|
| 718 | 718 | private static function _register_data_migration_scripts( $addon_name ) { |
| 719 | - // setup DMS |
|
| 720 | - if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 721 | - EE_Register_Data_Migration_Scripts::register( |
|
| 722 | - $addon_name, |
|
| 723 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 724 | - ); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * @param string $addon_name |
|
| 731 | - * @return void |
|
| 732 | - * @throws \EE_Error |
|
| 733 | - */ |
|
| 719 | + // setup DMS |
|
| 720 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 721 | + EE_Register_Data_Migration_Scripts::register( |
|
| 722 | + $addon_name, |
|
| 723 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 724 | + ); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * @param string $addon_name |
|
| 731 | + * @return void |
|
| 732 | + * @throws \EE_Error |
|
| 733 | + */ |
|
| 734 | 734 | private static function _register_config( $addon_name ) { |
| 735 | - // if config_class is present let's register config. |
|
| 736 | - if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 737 | - EE_Register_Config::register( |
|
| 738 | - self::$_settings[$addon_name]['config_class'], |
|
| 739 | - array( |
|
| 740 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 741 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 742 | - ) |
|
| 743 | - ); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * @param string $addon_name |
|
| 750 | - * @return void |
|
| 751 | - * @throws \EE_Error |
|
| 752 | - */ |
|
| 735 | + // if config_class is present let's register config. |
|
| 736 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 737 | + EE_Register_Config::register( |
|
| 738 | + self::$_settings[$addon_name]['config_class'], |
|
| 739 | + array( |
|
| 740 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 741 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 742 | + ) |
|
| 743 | + ); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * @param string $addon_name |
|
| 750 | + * @return void |
|
| 751 | + * @throws \EE_Error |
|
| 752 | + */ |
|
| 753 | 753 | private static function _register_admin_pages( $addon_name ) { |
| 754 | - if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 755 | - EE_Register_Admin_Page::register( |
|
| 756 | - $addon_name, |
|
| 757 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - |
|
| 763 | - /** |
|
| 764 | - * @param string $addon_name |
|
| 765 | - * @return void |
|
| 766 | - * @throws \EE_Error |
|
| 767 | - */ |
|
| 754 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 755 | + EE_Register_Admin_Page::register( |
|
| 756 | + $addon_name, |
|
| 757 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + |
|
| 763 | + /** |
|
| 764 | + * @param string $addon_name |
|
| 765 | + * @return void |
|
| 766 | + * @throws \EE_Error |
|
| 767 | + */ |
|
| 768 | 768 | private static function _register_modules( $addon_name ) { |
| 769 | - if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 770 | - EE_Register_Module::register( |
|
| 771 | - $addon_name, |
|
| 772 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 773 | - ); |
|
| 774 | - } |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - /** |
|
| 779 | - * @param string $addon_name |
|
| 780 | - * @return void |
|
| 781 | - * @throws \EE_Error |
|
| 782 | - */ |
|
| 769 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 770 | + EE_Register_Module::register( |
|
| 771 | + $addon_name, |
|
| 772 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 773 | + ); |
|
| 774 | + } |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + /** |
|
| 779 | + * @param string $addon_name |
|
| 780 | + * @return void |
|
| 781 | + * @throws \EE_Error |
|
| 782 | + */ |
|
| 783 | 783 | private static function _register_shortcodes( $addon_name ) { |
| 784 | - if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 785 | - EE_Register_Shortcode::register( |
|
| 786 | - $addon_name, |
|
| 787 | - array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * @param string $addon_name |
|
| 795 | - * @return void |
|
| 796 | - * @throws \EE_Error |
|
| 797 | - */ |
|
| 784 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
| 785 | + EE_Register_Shortcode::register( |
|
| 786 | + $addon_name, |
|
| 787 | + array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * @param string $addon_name |
|
| 795 | + * @return void |
|
| 796 | + * @throws \EE_Error |
|
| 797 | + */ |
|
| 798 | 798 | private static function _register_widgets( $addon_name ) { |
| 799 | - if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 800 | - EE_Register_Widget::register( |
|
| 801 | - $addon_name, |
|
| 802 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 803 | - ); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - |
|
| 808 | - /** |
|
| 809 | - * @param string $addon_name |
|
| 810 | - * @return void |
|
| 811 | - * @throws \EE_Error |
|
| 812 | - */ |
|
| 799 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 800 | + EE_Register_Widget::register( |
|
| 801 | + $addon_name, |
|
| 802 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 803 | + ); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + |
|
| 808 | + /** |
|
| 809 | + * @param string $addon_name |
|
| 810 | + * @return void |
|
| 811 | + * @throws \EE_Error |
|
| 812 | + */ |
|
| 813 | 813 | private static function _register_capabilities( $addon_name ) { |
| 814 | - if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 815 | - EE_Register_Capabilities::register( |
|
| 816 | - $addon_name, |
|
| 817 | - array( |
|
| 818 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 819 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 820 | - ) |
|
| 821 | - ); |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * @param string $addon_name |
|
| 828 | - * @return void |
|
| 829 | - * @throws \EE_Error |
|
| 830 | - */ |
|
| 814 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 815 | + EE_Register_Capabilities::register( |
|
| 816 | + $addon_name, |
|
| 817 | + array( |
|
| 818 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 819 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 820 | + ) |
|
| 821 | + ); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * @param string $addon_name |
|
| 828 | + * @return void |
|
| 829 | + * @throws \EE_Error |
|
| 830 | + */ |
|
| 831 | 831 | private static function _register_message_types( $addon_name ) { |
| 832 | - if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 833 | - add_action( |
|
| 834 | - 'EE_Brewing_Regular___messages_caf', |
|
| 835 | - array('EE_Register_Addon', 'register_message_types') |
|
| 836 | - ); |
|
| 837 | - } |
|
| 838 | - } |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * @param string $addon_name |
|
| 843 | - * @return void |
|
| 844 | - * @throws \EE_Error |
|
| 845 | - */ |
|
| 832 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 833 | + add_action( |
|
| 834 | + 'EE_Brewing_Regular___messages_caf', |
|
| 835 | + array('EE_Register_Addon', 'register_message_types') |
|
| 836 | + ); |
|
| 837 | + } |
|
| 838 | + } |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * @param string $addon_name |
|
| 843 | + * @return void |
|
| 844 | + * @throws \EE_Error |
|
| 845 | + */ |
|
| 846 | 846 | private static function _register_custom_post_types( $addon_name ) { |
| 847 | - if ( |
|
| 848 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 849 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 850 | - ) { |
|
| 851 | - EE_Register_CPT::register( |
|
| 852 | - $addon_name, |
|
| 853 | - array( |
|
| 854 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 855 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 856 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 857 | - ) |
|
| 858 | - ); |
|
| 859 | - } |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * @param string $addon_name |
|
| 865 | - * @return void |
|
| 866 | - * @throws \EE_Error |
|
| 867 | - */ |
|
| 847 | + if ( |
|
| 848 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 849 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 850 | + ) { |
|
| 851 | + EE_Register_CPT::register( |
|
| 852 | + $addon_name, |
|
| 853 | + array( |
|
| 854 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 855 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 856 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 857 | + ) |
|
| 858 | + ); |
|
| 859 | + } |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * @param string $addon_name |
|
| 865 | + * @return void |
|
| 866 | + * @throws \EE_Error |
|
| 867 | + */ |
|
| 868 | 868 | private static function _register_payment_methods( $addon_name ) { |
| 869 | - if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 870 | - EE_Register_Payment_Method::register( |
|
| 871 | - $addon_name, |
|
| 872 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 873 | - ); |
|
| 874 | - } |
|
| 875 | - } |
|
| 869 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 870 | + EE_Register_Payment_Method::register( |
|
| 871 | + $addon_name, |
|
| 872 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 873 | + ); |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | 877 | |
| 878 | 878 | |
@@ -901,14 +901,14 @@ discard block |
||
| 901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 902 | 902 | //the plugin mainfile's path upon construction. |
| 903 | 903 | register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
| 904 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 905 | - if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 906 | - add_action( |
|
| 907 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 908 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 909 | - ); |
|
| 910 | - } |
|
| 911 | - return $addon; |
|
| 904 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 905 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 906 | + add_action( |
|
| 907 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 908 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 909 | + ); |
|
| 910 | + } |
|
| 911 | + return $addon; |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | // cycle thru settings |
| 925 | 925 | foreach ( self::$_settings as $settings ) { |
| 926 | 926 | if ( ! empty( $settings['pue_options'] ) ) { |
| 927 | - // initiate the class and start the plugin update engine! |
|
| 927 | + // initiate the class and start the plugin update engine! |
|
| 928 | 928 | new PluginUpdateEngineChecker( |
| 929 | 929 | // host file URL |
| 930 | 930 | 'https://eventespresso.com', |
@@ -960,11 +960,11 @@ discard block |
||
| 960 | 960 | */ |
| 961 | 961 | public static function register_message_types() { |
| 962 | 962 | foreach ( self::$_settings as $addon_name => $settings ) { |
| 963 | - if ( ! empty($settings['message_types'])) { |
|
| 964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 965 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 966 | - } |
|
| 967 | - } |
|
| 963 | + if ( ! empty($settings['message_types'])) { |
|
| 964 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 965 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 966 | + } |
|
| 967 | + } |
|
| 968 | 968 | } |
| 969 | 969 | } |
| 970 | 970 | |
@@ -1006,15 +1006,15 @@ discard block |
||
| 1006 | 1006 | EE_Register_Widget::deregister( $addon_name ); |
| 1007 | 1007 | } |
| 1008 | 1008 | if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
| 1009 | - || |
|
| 1010 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
| 1009 | + || |
|
| 1010 | + ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
| 1011 | 1011 | ) { |
| 1012 | 1012 | // add to list of shortcodes to be registered |
| 1013 | 1013 | EE_Register_Model::deregister( $addon_name ); |
| 1014 | 1014 | } |
| 1015 | 1015 | if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
| 1016 | - || |
|
| 1017 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
| 1016 | + || |
|
| 1017 | + ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
| 1018 | 1018 | ) { |
| 1019 | 1019 | // add to list of shortcodes to be registered |
| 1020 | 1020 | EE_Register_Model_Extensions::deregister( $addon_name ); |