@@ -11,131 +11,131 @@ |
||
| 11 | 11 | interface EEI_Payment extends EEI_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @return string indicating which the payment is approved, pending, cancelled or failed |
|
| 16 | - */ |
|
| 17 | - public function status(); |
|
| 14 | + /** |
|
| 15 | + * @return string indicating which the payment is approved, pending, cancelled or failed |
|
| 16 | + */ |
|
| 17 | + public function status(); |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @return float returns the amount the payment is for (whether or not its approved) |
|
| 23 | - */ |
|
| 24 | - public function amount(); |
|
| 21 | + /** |
|
| 22 | + * @return float returns the amount the payment is for (whether or not its approved) |
|
| 23 | + */ |
|
| 24 | + public function amount(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return string of the currency for this payment |
|
| 30 | - */ |
|
| 31 | - public function currency_code(); |
|
| 28 | + /** |
|
| 29 | + * @return string of the currency for this payment |
|
| 30 | + */ |
|
| 31 | + public function currency_code(); |
|
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * The gateway transaction's ID, usually assigned by the |
|
| 37 | - * payment provider |
|
| 38 | - * |
|
| 39 | - * @return string |
|
| 40 | - */ |
|
| 41 | - public function txn_id_chq_nmbr(); |
|
| 35 | + /** |
|
| 36 | + * The gateway transaction's ID, usually assigned by the |
|
| 37 | + * payment provider |
|
| 38 | + * |
|
| 39 | + * @return string |
|
| 40 | + */ |
|
| 41 | + public function txn_id_chq_nmbr(); |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $status |
|
| 47 | - */ |
|
| 48 | - public function set_status($status); |
|
| 45 | + /** |
|
| 46 | + * @param string $status |
|
| 47 | + */ |
|
| 48 | + public function set_status($status); |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Sets the response from the gateway, which is displayable to the user. |
|
| 54 | - * Eg, 'payment was approved', 'payment failed because invalid date', etc. |
|
| 55 | - * |
|
| 56 | - * @param string $response |
|
| 57 | - */ |
|
| 58 | - public function set_gateway_response($response); |
|
| 52 | + /** |
|
| 53 | + * Sets the response from the gateway, which is displayable to the user. |
|
| 54 | + * Eg, 'payment was approved', 'payment failed because invalid date', etc. |
|
| 55 | + * |
|
| 56 | + * @param string $response |
|
| 57 | + */ |
|
| 58 | + public function set_gateway_response($response); |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Sets the response details, usually the entire contents of an IPN request, |
|
| 64 | - * or data about the direct payment data sent |
|
| 65 | - * |
|
| 66 | - * @param mixed $response_details |
|
| 67 | - */ |
|
| 68 | - public function set_details($response_details); |
|
| 62 | + /** |
|
| 63 | + * Sets the response details, usually the entire contents of an IPN request, |
|
| 64 | + * or data about the direct payment data sent |
|
| 65 | + * |
|
| 66 | + * @param mixed $response_details |
|
| 67 | + */ |
|
| 68 | + public function set_details($response_details); |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns whatever the details were set to be, which could be an array, object, string, integer, whatever. |
|
| 74 | - * |
|
| 75 | - * @return mixed |
|
| 76 | - */ |
|
| 77 | - public function details(); |
|
| 72 | + /** |
|
| 73 | + * Returns whatever the details were set to be, which could be an array, object, string, integer, whatever. |
|
| 74 | + * |
|
| 75 | + * @return mixed |
|
| 76 | + */ |
|
| 77 | + public function details(); |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Sets the URl to redirect to, to process payment |
|
| 83 | - * |
|
| 84 | - * @param string $url |
|
| 85 | - */ |
|
| 86 | - public function set_redirect_url($url); |
|
| 81 | + /** |
|
| 82 | + * Sets the URl to redirect to, to process payment |
|
| 83 | + * |
|
| 84 | + * @param string $url |
|
| 85 | + */ |
|
| 86 | + public function set_redirect_url($url); |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Sets the argument which should be passed to the redirect url (ie, usually POST variables) |
|
| 92 | - * |
|
| 93 | - * @param array $args |
|
| 94 | - */ |
|
| 95 | - public function set_redirect_args($args); |
|
| 90 | + /** |
|
| 91 | + * Sets the argument which should be passed to the redirect url (ie, usually POST variables) |
|
| 92 | + * |
|
| 93 | + * @param array $args |
|
| 94 | + */ |
|
| 95 | + public function set_redirect_args($args); |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Gets redirect_args |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - public function redirect_args(); |
|
| 99 | + /** |
|
| 100 | + * Gets redirect_args |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + public function redirect_args(); |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @return EEI_Transaction |
|
| 110 | - */ |
|
| 111 | - public function transaction(); |
|
| 108 | + /** |
|
| 109 | + * @return EEI_Transaction |
|
| 110 | + */ |
|
| 111 | + public function transaction(); |
|
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Sets the amount for this payment |
|
| 117 | - * |
|
| 118 | - * @param float $amount |
|
| 119 | - */ |
|
| 120 | - public function set_amount($amount); |
|
| 115 | + /** |
|
| 116 | + * Sets the amount for this payment |
|
| 117 | + * |
|
| 118 | + * @param float $amount |
|
| 119 | + */ |
|
| 120 | + public function set_amount($amount); |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Sets the ID of the gateway transaction |
|
| 126 | - * |
|
| 127 | - * @param string $txn_id |
|
| 128 | - */ |
|
| 129 | - public function set_txn_id_chq_nmbr($txn_id); |
|
| 124 | + /** |
|
| 125 | + * Sets the ID of the gateway transaction |
|
| 126 | + * |
|
| 127 | + * @param string $txn_id |
|
| 128 | + */ |
|
| 129 | + public function set_txn_id_chq_nmbr($txn_id); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Sets a string for some extra accounting info |
|
| 135 | - * |
|
| 136 | - * @param string $extra_accounting_info |
|
| 137 | - */ |
|
| 138 | - public function set_extra_accntng($extra_accounting_info); |
|
| 133 | + /** |
|
| 134 | + * Sets a string for some extra accounting info |
|
| 135 | + * |
|
| 136 | + * @param string $extra_accounting_info |
|
| 137 | + */ |
|
| 138 | + public function set_extra_accntng($extra_accounting_info); |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | // End of file EEI_Payment.interface.php |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param array $props_n_values incoming values |
| 26 | 26 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
| 27 | 27 | * used.) |
| 28 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 28 | + * @param string[] $date_formats incoming date_formats in an array where the first value is the |
|
| 29 | 29 | * date_format and the second value is the time format |
| 30 | 30 | * @param MoneyFactory $money_factory |
| 31 | 31 | * @return EE_Payment |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | * Gets all the extra meta info on this payment |
| 672 | 672 | * |
| 673 | 673 | * @param array $query_params like EEM_Base::get_all |
| 674 | - * @return EE_Extra_Meta |
|
| 674 | + * @return EE_Base_Class[] |
|
| 675 | 675 | * @throws EE_Error |
| 676 | 676 | */ |
| 677 | 677 | public function extra_meta( $query_params = array() ) { |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | |
| 921 | 921 | /** |
| 922 | 922 | * Returns the payment's transaction's primary registration |
| 923 | - * @return EE_Registration|null |
|
| 923 | + * @return EE_Base_Class|null |
|
| 924 | 924 | * @throws EE_Error |
| 925 | 925 | */ |
| 926 | 926 | public function get_primary_registration() |
@@ -21,105 +21,105 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class EE_Payment extends EE_Base_Class implements EEI_Payment, UsesMoneyInterface { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param array $props_n_values incoming values |
|
| 26 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 27 | - * used.) |
|
| 28 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 29 | - * date_format and the second value is the time format |
|
| 30 | - * @param MoneyFactory $money_factory |
|
| 31 | - * @return EE_Payment |
|
| 32 | - * @throws InvalidArgumentException |
|
| 33 | - * @throws InvalidInterfaceException |
|
| 34 | - * @throws InvalidDataTypeException |
|
| 35 | - * @throws EE_Error |
|
| 36 | - */ |
|
| 37 | - public static function new_instance( |
|
| 38 | - $props_n_values = array(), |
|
| 39 | - $timezone = null, |
|
| 40 | - $date_formats = array(), |
|
| 41 | - MoneyFactory $money_factory = null |
|
| 42 | - ) { |
|
| 43 | - $has_object = parent::_check_for_object( |
|
| 44 | - $props_n_values, |
|
| 45 | - __CLASS__, |
|
| 46 | - $timezone, |
|
| 47 | - $date_formats |
|
| 48 | - ); |
|
| 49 | - return $has_object |
|
| 50 | - ? $has_object |
|
| 51 | - : new self( |
|
| 52 | - $props_n_values, |
|
| 53 | - false, |
|
| 54 | - $timezone, |
|
| 55 | - $date_formats, |
|
| 56 | - $money_factory |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param array $props_n_values incoming values from the database |
|
| 63 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 64 | - * the website will be used. |
|
| 65 | - * @param MoneyFactory $money_factory |
|
| 66 | - * @return EE_Payment |
|
| 67 | - * @throws InvalidArgumentException |
|
| 68 | - * @throws InvalidInterfaceException |
|
| 69 | - * @throws InvalidDataTypeException |
|
| 70 | - * @throws EE_Error |
|
| 71 | - */ |
|
| 72 | - public static function new_instance_from_db( |
|
| 73 | - $props_n_values = array(), |
|
| 74 | - $timezone = null, |
|
| 75 | - MoneyFactory $money_factory = null |
|
| 76 | - ) { |
|
| 77 | - return new self( |
|
| 78 | - $props_n_values, |
|
| 79 | - true, |
|
| 80 | - $timezone, |
|
| 81 | - array(), |
|
| 82 | - $money_factory |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 89 | - * play nice |
|
| 90 | - * |
|
| 91 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 92 | - * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 93 | - * values |
|
| 94 | - * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 95 | - * or not. |
|
| 96 | - * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 97 | - * instantiating |
|
| 98 | - * a EE_Base_Class object. |
|
| 99 | - * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 100 | - * date_format and second value is the time format. |
|
| 101 | - * @param MoneyFactory $money_factory |
|
| 102 | - * @throws InvalidArgumentException |
|
| 103 | - * @throws InvalidInterfaceException |
|
| 104 | - * @throws InvalidDataTypeException |
|
| 105 | - * @throws EE_Error |
|
| 106 | - */ |
|
| 107 | - protected function __construct( |
|
| 108 | - array $fieldValues = array(), |
|
| 109 | - $bydb = false, |
|
| 110 | - $timezone = '', |
|
| 111 | - array $date_formats = array(), |
|
| 112 | - MoneyFactory $money_factory = null |
|
| 113 | - ) { |
|
| 114 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 115 | - $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 116 | - } |
|
| 117 | - $this->money_factory = $money_factory; |
|
| 118 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 24 | + /** |
|
| 25 | + * @param array $props_n_values incoming values |
|
| 26 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 27 | + * used.) |
|
| 28 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 29 | + * date_format and the second value is the time format |
|
| 30 | + * @param MoneyFactory $money_factory |
|
| 31 | + * @return EE_Payment |
|
| 32 | + * @throws InvalidArgumentException |
|
| 33 | + * @throws InvalidInterfaceException |
|
| 34 | + * @throws InvalidDataTypeException |
|
| 35 | + * @throws EE_Error |
|
| 36 | + */ |
|
| 37 | + public static function new_instance( |
|
| 38 | + $props_n_values = array(), |
|
| 39 | + $timezone = null, |
|
| 40 | + $date_formats = array(), |
|
| 41 | + MoneyFactory $money_factory = null |
|
| 42 | + ) { |
|
| 43 | + $has_object = parent::_check_for_object( |
|
| 44 | + $props_n_values, |
|
| 45 | + __CLASS__, |
|
| 46 | + $timezone, |
|
| 47 | + $date_formats |
|
| 48 | + ); |
|
| 49 | + return $has_object |
|
| 50 | + ? $has_object |
|
| 51 | + : new self( |
|
| 52 | + $props_n_values, |
|
| 53 | + false, |
|
| 54 | + $timezone, |
|
| 55 | + $date_formats, |
|
| 56 | + $money_factory |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param array $props_n_values incoming values from the database |
|
| 63 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 64 | + * the website will be used. |
|
| 65 | + * @param MoneyFactory $money_factory |
|
| 66 | + * @return EE_Payment |
|
| 67 | + * @throws InvalidArgumentException |
|
| 68 | + * @throws InvalidInterfaceException |
|
| 69 | + * @throws InvalidDataTypeException |
|
| 70 | + * @throws EE_Error |
|
| 71 | + */ |
|
| 72 | + public static function new_instance_from_db( |
|
| 73 | + $props_n_values = array(), |
|
| 74 | + $timezone = null, |
|
| 75 | + MoneyFactory $money_factory = null |
|
| 76 | + ) { |
|
| 77 | + return new self( |
|
| 78 | + $props_n_values, |
|
| 79 | + true, |
|
| 80 | + $timezone, |
|
| 81 | + array(), |
|
| 82 | + $money_factory |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 89 | + * play nice |
|
| 90 | + * |
|
| 91 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 92 | + * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 93 | + * values |
|
| 94 | + * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 95 | + * or not. |
|
| 96 | + * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 97 | + * instantiating |
|
| 98 | + * a EE_Base_Class object. |
|
| 99 | + * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 100 | + * date_format and second value is the time format. |
|
| 101 | + * @param MoneyFactory $money_factory |
|
| 102 | + * @throws InvalidArgumentException |
|
| 103 | + * @throws InvalidInterfaceException |
|
| 104 | + * @throws InvalidDataTypeException |
|
| 105 | + * @throws EE_Error |
|
| 106 | + */ |
|
| 107 | + protected function __construct( |
|
| 108 | + array $fieldValues = array(), |
|
| 109 | + $bydb = false, |
|
| 110 | + $timezone = '', |
|
| 111 | + array $date_formats = array(), |
|
| 112 | + MoneyFactory $money_factory = null |
|
| 113 | + ) { |
|
| 114 | + if (! $money_factory instanceof MoneyFactory) { |
|
| 115 | + $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 116 | + } |
|
| 117 | + $this->money_factory = $money_factory; |
|
| 118 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | 123 | * Set Transaction ID |
| 124 | 124 | * |
| 125 | 125 | * @access public |
@@ -524,16 +524,16 @@ discard block |
||
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
| 527 | - /** |
|
| 528 | - * returns a pretty version of the status, good for displaying to users |
|
| 529 | - * |
|
| 530 | - * @param bool $show_icons |
|
| 531 | - * @return string |
|
| 532 | - * @throws InvalidArgumentException |
|
| 533 | - * @throws InvalidInterfaceException |
|
| 534 | - * @throws InvalidDataTypeException |
|
| 535 | - * @throws EE_Error |
|
| 536 | - */ |
|
| 527 | + /** |
|
| 528 | + * returns a pretty version of the status, good for displaying to users |
|
| 529 | + * |
|
| 530 | + * @param bool $show_icons |
|
| 531 | + * @return string |
|
| 532 | + * @throws InvalidArgumentException |
|
| 533 | + * @throws InvalidInterfaceException |
|
| 534 | + * @throws InvalidDataTypeException |
|
| 535 | + * @throws EE_Error |
|
| 536 | + */ |
|
| 537 | 537 | public function pretty_status( $show_icons = false ) { |
| 538 | 538 | $status = EEM_Status::instance()->localized_status( |
| 539 | 539 | array( $this->STS_ID() => __( 'unknown', 'event_espresso' ) ), |
@@ -742,11 +742,11 @@ discard block |
||
| 742 | 742 | $redirect_url = str_replace( '?' . $querystring, '', $redirect_url ); |
| 743 | 743 | } |
| 744 | 744 | $form = EEH_HTML::nl( 1 ) |
| 745 | - . '<form method="' |
|
| 746 | - . $method |
|
| 747 | - . '" name="gateway_form" action="' |
|
| 748 | - . $redirect_url |
|
| 749 | - . '">'; |
|
| 745 | + . '<form method="' |
|
| 746 | + . $method |
|
| 747 | + . '" name="gateway_form" action="' |
|
| 748 | + . $redirect_url |
|
| 749 | + . '">'; |
|
| 750 | 750 | $form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs(); |
| 751 | 751 | $form .= $inside_form_html; |
| 752 | 752 | $form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 ); |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | if ( $args !== null && is_array( $args ) ) { |
| 784 | 784 | foreach ( $args as $name => $value ) { |
| 785 | 785 | $html .= EEH_HTML::nl( 0 ) |
| 786 | - . '<input type="hidden" name="' |
|
| 787 | - . $name |
|
| 788 | - . '" value="' |
|
| 789 | - . esc_attr( $value ) |
|
| 790 | - . '"/>'; |
|
| 786 | + . '<input type="hidden" name="' |
|
| 787 | + . $name |
|
| 788 | + . '" value="' |
|
| 789 | + . esc_attr( $value ) |
|
| 790 | + . '"/>'; |
|
| 791 | 791 | } |
| 792 | 792 | } |
| 793 | 793 | return $html; |
@@ -886,99 +886,99 @@ discard block |
||
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | |
| 889 | - /** |
|
| 890 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 891 | - * |
|
| 892 | - * @return EE_Event|null |
|
| 893 | - * @throws EE_Error |
|
| 894 | - */ |
|
| 895 | - public function get_first_event() |
|
| 896 | - { |
|
| 897 | - $transaction = $this->transaction(); |
|
| 898 | - if ($transaction instanceof EE_Transaction) { |
|
| 899 | - $primary_registrant = $transaction->primary_registration(); |
|
| 900 | - if ($primary_registrant instanceof EE_Registration) { |
|
| 901 | - return $primary_registrant->event_obj(); |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - return null; |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * Gets the name of the first event for which is being paid |
|
| 910 | - * |
|
| 911 | - * @return string |
|
| 912 | - * @throws EE_Error |
|
| 913 | - */ |
|
| 914 | - public function get_first_event_name() |
|
| 915 | - { |
|
| 916 | - $event = $this->get_first_event(); |
|
| 917 | - return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * Returns the payment's transaction's primary registration |
|
| 923 | - * @return EE_Registration|null |
|
| 924 | - * @throws EE_Error |
|
| 925 | - */ |
|
| 926 | - public function get_primary_registration() |
|
| 927 | - { |
|
| 928 | - if ($this->transaction() instanceof EE_Transaction) { |
|
| 929 | - return $this->transaction()->primary_registration(); |
|
| 930 | - } |
|
| 931 | - return null; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - /** |
|
| 936 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
| 937 | - * @return EE_Attendee|null |
|
| 938 | - * @throws EE_Error |
|
| 939 | - */ |
|
| 940 | - public function get_primary_attendee() |
|
| 941 | - { |
|
| 942 | - $primary_reg = $this->get_primary_registration(); |
|
| 943 | - if( $primary_reg instanceof EE_Registration) { |
|
| 944 | - return $primary_reg->attendee(); |
|
| 945 | - } |
|
| 946 | - return null; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - |
|
| 950 | - /** |
|
| 951 | - * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 952 | - * in the currency's main units) |
|
| 953 | - * |
|
| 954 | - * @return int |
|
| 955 | - * @throws EE_Error |
|
| 956 | - * @throws InvalidEntityException |
|
| 957 | - * @throws DomainException |
|
| 958 | - */ |
|
| 959 | - public function amountInSubunits() |
|
| 960 | - { |
|
| 961 | - return $this->moneyInSubunits('PAY_amount'); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 967 | - * the amount is actually assumed to be in the currency's main units |
|
| 968 | - * |
|
| 969 | - * @param int $amount_in_subunits |
|
| 970 | - * @return void |
|
| 971 | - * @throws EE_Error |
|
| 972 | - * @throws InvalidArgumentException |
|
| 973 | - * @throws InvalidInterfaceException |
|
| 974 | - * @throws InvalidIdentifierException |
|
| 975 | - * @throws InvalidDataTypeException |
|
| 976 | - * @throws DomainException |
|
| 977 | - */ |
|
| 978 | - public function setAmountInSubunits($amount_in_subunits) |
|
| 979 | - { |
|
| 980 | - $this->setMoneySubunits('PAY_amount', $amount_in_subunits); |
|
| 981 | - } |
|
| 889 | + /** |
|
| 890 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
| 891 | + * |
|
| 892 | + * @return EE_Event|null |
|
| 893 | + * @throws EE_Error |
|
| 894 | + */ |
|
| 895 | + public function get_first_event() |
|
| 896 | + { |
|
| 897 | + $transaction = $this->transaction(); |
|
| 898 | + if ($transaction instanceof EE_Transaction) { |
|
| 899 | + $primary_registrant = $transaction->primary_registration(); |
|
| 900 | + if ($primary_registrant instanceof EE_Registration) { |
|
| 901 | + return $primary_registrant->event_obj(); |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + return null; |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * Gets the name of the first event for which is being paid |
|
| 910 | + * |
|
| 911 | + * @return string |
|
| 912 | + * @throws EE_Error |
|
| 913 | + */ |
|
| 914 | + public function get_first_event_name() |
|
| 915 | + { |
|
| 916 | + $event = $this->get_first_event(); |
|
| 917 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * Returns the payment's transaction's primary registration |
|
| 923 | + * @return EE_Registration|null |
|
| 924 | + * @throws EE_Error |
|
| 925 | + */ |
|
| 926 | + public function get_primary_registration() |
|
| 927 | + { |
|
| 928 | + if ($this->transaction() instanceof EE_Transaction) { |
|
| 929 | + return $this->transaction()->primary_registration(); |
|
| 930 | + } |
|
| 931 | + return null; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + /** |
|
| 936 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
| 937 | + * @return EE_Attendee|null |
|
| 938 | + * @throws EE_Error |
|
| 939 | + */ |
|
| 940 | + public function get_primary_attendee() |
|
| 941 | + { |
|
| 942 | + $primary_reg = $this->get_primary_registration(); |
|
| 943 | + if( $primary_reg instanceof EE_Registration) { |
|
| 944 | + return $primary_reg->attendee(); |
|
| 945 | + } |
|
| 946 | + return null; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + |
|
| 950 | + /** |
|
| 951 | + * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 952 | + * in the currency's main units) |
|
| 953 | + * |
|
| 954 | + * @return int |
|
| 955 | + * @throws EE_Error |
|
| 956 | + * @throws InvalidEntityException |
|
| 957 | + * @throws DomainException |
|
| 958 | + */ |
|
| 959 | + public function amountInSubunits() |
|
| 960 | + { |
|
| 961 | + return $this->moneyInSubunits('PAY_amount'); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 967 | + * the amount is actually assumed to be in the currency's main units |
|
| 968 | + * |
|
| 969 | + * @param int $amount_in_subunits |
|
| 970 | + * @return void |
|
| 971 | + * @throws EE_Error |
|
| 972 | + * @throws InvalidArgumentException |
|
| 973 | + * @throws InvalidInterfaceException |
|
| 974 | + * @throws InvalidIdentifierException |
|
| 975 | + * @throws InvalidDataTypeException |
|
| 976 | + * @throws DomainException |
|
| 977 | + */ |
|
| 978 | + public function setAmountInSubunits($amount_in_subunits) |
|
| 979 | + { |
|
| 980 | + $this->setMoneySubunits('PAY_amount', $amount_in_subunits); |
|
| 981 | + } |
|
| 982 | 982 | } |
| 983 | 983 | /* End of file EE_Payment.class.php */ |
| 984 | 984 | /* Location: /includes/classes/EE_Payment.class.php */ |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | use EventEspresso\core\services\currency\MoneyFactory; |
| 9 | 9 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 10 | 10 | |
| 11 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 12 | - exit( 'No direct script access allowed' ); |
|
| 11 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 12 | + exit('No direct script access allowed'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | array $date_formats = array(), |
| 112 | 112 | MoneyFactory $money_factory = null |
| 113 | 113 | ) { |
| 114 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 114 | + if ( ! $money_factory instanceof MoneyFactory) { |
|
| 115 | 115 | $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
| 116 | 116 | } |
| 117 | 117 | $this->money_factory = $money_factory; |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param int $TXN_ID |
| 127 | 127 | * @throws EE_Error |
| 128 | 128 | */ |
| 129 | - public function set_transaction_id( $TXN_ID = 0 ) { |
|
| 130 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
| 129 | + public function set_transaction_id($TXN_ID = 0) { |
|
| 130 | + $this->set('TXN_ID', $TXN_ID); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @throws EE_Error |
| 140 | 140 | */ |
| 141 | 141 | public function transaction() { |
| 142 | - return $this->get_first_related( 'Transaction' ); |
|
| 142 | + return $this->get_first_related('Transaction'); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @param string $STS_ID |
| 152 | 152 | * @throws EE_Error |
| 153 | 153 | */ |
| 154 | - public function set_status( $STS_ID = '' ) { |
|
| 155 | - $this->set( 'STS_ID', $STS_ID ); |
|
| 154 | + public function set_status($STS_ID = '') { |
|
| 155 | + $this->set('STS_ID', $STS_ID); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -164,8 +164,8 @@ discard block |
||
| 164 | 164 | * @param int $timestamp |
| 165 | 165 | * @throws EE_Error |
| 166 | 166 | */ |
| 167 | - public function set_timestamp( $timestamp = 0 ) { |
|
| 168 | - $this->set( 'PAY_timestamp', $timestamp ); |
|
| 167 | + public function set_timestamp($timestamp = 0) { |
|
| 168 | + $this->set('PAY_timestamp', $timestamp); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | |
@@ -177,8 +177,8 @@ discard block |
||
| 177 | 177 | * @param string $PAY_source |
| 178 | 178 | * @throws EE_Error |
| 179 | 179 | */ |
| 180 | - public function set_source( $PAY_source = '' ) { |
|
| 181 | - $this->set( 'PAY_source', $PAY_source ); |
|
| 180 | + public function set_source($PAY_source = '') { |
|
| 181 | + $this->set('PAY_source', $PAY_source); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param float $amount |
| 191 | 191 | * @throws EE_Error |
| 192 | 192 | */ |
| 193 | - public function set_amount( $amount = 0.00 ) { |
|
| 194 | - $this->set( 'PAY_amount', (float)$amount ); |
|
| 193 | + public function set_amount($amount = 0.00) { |
|
| 194 | + $this->set('PAY_amount', (float) $amount); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -203,8 +203,8 @@ discard block |
||
| 203 | 203 | * @param string $gateway_response |
| 204 | 204 | * @throws EE_Error |
| 205 | 205 | */ |
| 206 | - public function set_gateway_response( $gateway_response = '' ) { |
|
| 207 | - $this->set( 'PAY_gateway_response', $gateway_response ); |
|
| 206 | + public function set_gateway_response($gateway_response = '') { |
|
| 207 | + $this->set('PAY_gateway_response', $gateway_response); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | ), |
| 228 | 228 | '4.6.0' |
| 229 | 229 | ); |
| 230 | - return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' ); |
|
| 230 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @param string $txn_id_chq_nmbr |
| 240 | 240 | * @throws EE_Error |
| 241 | 241 | */ |
| 242 | - public function set_txn_id_chq_nmbr( $txn_id_chq_nmbr = '' ) { |
|
| 243 | - $this->set( 'PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr ); |
|
| 242 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') { |
|
| 243 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | * @param string $po_number |
| 253 | 253 | * @throws EE_Error |
| 254 | 254 | */ |
| 255 | - public function set_po_number( $po_number = '' ) { |
|
| 256 | - $this->set( 'PAY_po_number', $po_number ); |
|
| 255 | + public function set_po_number($po_number = '') { |
|
| 256 | + $this->set('PAY_po_number', $po_number); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | * @param string $extra_accntng |
| 266 | 266 | * @throws EE_Error |
| 267 | 267 | */ |
| 268 | - public function set_extra_accntng( $extra_accntng = '' ) { |
|
| 269 | - $this->set( 'PAY_extra_accntng', $extra_accntng ); |
|
| 268 | + public function set_extra_accntng($extra_accntng = '') { |
|
| 269 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | * @param bool $via_admin |
| 279 | 279 | * @throws EE_Error |
| 280 | 280 | */ |
| 281 | - public function set_payment_made_via_admin( $via_admin = false ) { |
|
| 282 | - if ( $via_admin ) { |
|
| 283 | - $this->set( 'PAY_source', EEM_Payment_Method::scope_admin ); |
|
| 281 | + public function set_payment_made_via_admin($via_admin = false) { |
|
| 282 | + if ($via_admin) { |
|
| 283 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
| 284 | 284 | } else { |
| 285 | - $this->set( 'PAY_source', EEM_Payment_Method::scope_cart ); |
|
| 285 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
@@ -295,13 +295,13 @@ discard block |
||
| 295 | 295 | * @param string|array $details |
| 296 | 296 | * @throws EE_Error |
| 297 | 297 | */ |
| 298 | - public function set_details( $details = '' ) { |
|
| 299 | - if ( is_array( $details ) ) { |
|
| 300 | - array_walk_recursive( $details, array( $this, '_strip_all_tags_within_array' ) ); |
|
| 298 | + public function set_details($details = '') { |
|
| 299 | + if (is_array($details)) { |
|
| 300 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
| 301 | 301 | } else { |
| 302 | - $details = wp_strip_all_tags( $details ); |
|
| 302 | + $details = wp_strip_all_tags($details); |
|
| 303 | 303 | } |
| 304 | - $this->set( 'PAY_details', $details ); |
|
| 304 | + $this->set('PAY_details', $details); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * @param string $redirect_url |
| 313 | 313 | * @throws EE_Error |
| 314 | 314 | */ |
| 315 | - public function set_redirect_url( $redirect_url ) { |
|
| 316 | - $this->set( 'PAY_redirect_url', $redirect_url ); |
|
| 315 | + public function set_redirect_url($redirect_url) { |
|
| 316 | + $this->set('PAY_redirect_url', $redirect_url); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | |
@@ -324,8 +324,8 @@ discard block |
||
| 324 | 324 | * @param array $redirect_args |
| 325 | 325 | * @throws EE_Error |
| 326 | 326 | */ |
| 327 | - public function set_redirect_args( $redirect_args ) { |
|
| 328 | - $this->set( 'PAY_redirect_args', $redirect_args ); |
|
| 327 | + public function set_redirect_args($redirect_args) { |
|
| 328 | + $this->set('PAY_redirect_args', $redirect_args); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | * @throws EE_Error |
| 338 | 338 | */ |
| 339 | 339 | public function TXN_ID() { |
| 340 | - return $this->get( 'TXN_ID' ); |
|
| 340 | + return $this->get('TXN_ID'); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * @throws EE_Error |
| 350 | 350 | */ |
| 351 | 351 | public function status() { |
| 352 | - return $this->get( 'STS_ID' ); |
|
| 352 | + return $this->get('STS_ID'); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @throws EE_Error |
| 362 | 362 | */ |
| 363 | 363 | public function STS_ID() { |
| 364 | - return $this->get( 'STS_ID' ); |
|
| 364 | + return $this->get('STS_ID'); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
@@ -375,8 +375,8 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | * @throws EE_Error |
| 377 | 377 | */ |
| 378 | - public function timestamp( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 379 | - return $this->get_i18n_datetime( 'PAY_timestamp', trim( $dt_frmt . ' ' . $tm_frmt) ); |
|
| 378 | + public function timestamp($dt_frmt = '', $tm_frmt = '') { |
|
| 379 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | * @throws EE_Error |
| 389 | 389 | */ |
| 390 | 390 | public function source() { |
| 391 | - return $this->get( 'PAY_source' ); |
|
| 391 | + return $this->get('PAY_source'); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | * @throws EE_Error |
| 402 | 402 | */ |
| 403 | 403 | public function amount() { |
| 404 | - return (float)$this->get( 'PAY_amount' ); |
|
| 404 | + return (float) $this->get('PAY_amount'); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | * @throws EE_Error |
| 412 | 412 | */ |
| 413 | 413 | public function amount_no_code() { |
| 414 | - return $this->get_pretty( 'PAY_amount', 'no_currency_code' ); |
|
| 414 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | * @throws EE_Error |
| 424 | 424 | */ |
| 425 | 425 | public function gateway_response() { |
| 426 | - return $this->get( 'PAY_gateway_response' ); |
|
| 426 | + return $this->get('PAY_gateway_response'); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | * @throws EE_Error |
| 436 | 436 | */ |
| 437 | 437 | public function txn_id_chq_nmbr() { |
| 438 | - return $this->get( 'PAY_txn_id_chq_nmbr' ); |
|
| 438 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | * @throws EE_Error |
| 448 | 448 | */ |
| 449 | 449 | public function po_number() { |
| 450 | - return $this->get( 'PAY_po_number' ); |
|
| 450 | + return $this->get('PAY_po_number'); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * @throws EE_Error |
| 460 | 460 | */ |
| 461 | 461 | public function extra_accntng() { |
| 462 | - return $this->get( 'PAY_extra_accntng' ); |
|
| 462 | + return $this->get('PAY_extra_accntng'); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @throws EE_Error |
| 472 | 472 | */ |
| 473 | 473 | public function payment_made_via_admin() { |
| 474 | - return ( $this->get( 'PAY_source' ) === EEM_Payment_Method::scope_admin ); |
|
| 474 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * @throws EE_Error |
| 484 | 484 | */ |
| 485 | 485 | public function details() { |
| 486 | - return $this->get( 'PAY_details' ); |
|
| 486 | + return $this->get('PAY_details'); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * @throws EE_Error |
| 496 | 496 | */ |
| 497 | 497 | public function redirect_url() { |
| 498 | - return $this->get( 'PAY_redirect_url' ); |
|
| 498 | + return $this->get('PAY_redirect_url'); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @throws EE_Error |
| 508 | 508 | */ |
| 509 | 509 | public function redirect_args() { |
| 510 | - return $this->get( 'PAY_redirect_args' ); |
|
| 510 | + return $this->get('PAY_redirect_args'); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @return void |
| 520 | 520 | * @throws EE_Error |
| 521 | 521 | */ |
| 522 | - public function e_pretty_status( $show_icons = false ) { |
|
| 523 | - echo $this->pretty_status( $show_icons ); |
|
| 522 | + public function e_pretty_status($show_icons = false) { |
|
| 523 | + echo $this->pretty_status($show_icons); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | |
@@ -534,14 +534,14 @@ discard block |
||
| 534 | 534 | * @throws InvalidDataTypeException |
| 535 | 535 | * @throws EE_Error |
| 536 | 536 | */ |
| 537 | - public function pretty_status( $show_icons = false ) { |
|
| 537 | + public function pretty_status($show_icons = false) { |
|
| 538 | 538 | $status = EEM_Status::instance()->localized_status( |
| 539 | - array( $this->STS_ID() => __( 'unknown', 'event_espresso' ) ), |
|
| 539 | + array($this->STS_ID() => __('unknown', 'event_espresso')), |
|
| 540 | 540 | false, |
| 541 | 541 | 'sentence' |
| 542 | 542 | ); |
| 543 | 543 | $icon = ''; |
| 544 | - switch ( $this->STS_ID() ) { |
|
| 544 | + switch ($this->STS_ID()) { |
|
| 545 | 545 | case EEM_Payment::status_id_approved: |
| 546 | 546 | $icon = $show_icons |
| 547 | 547 | ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | : ''; |
| 564 | 564 | break; |
| 565 | 565 | } |
| 566 | - return $icon . $status[ $this->STS_ID() ]; |
|
| 566 | + return $icon.$status[$this->STS_ID()]; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | * @throws EE_Error |
| 576 | 576 | */ |
| 577 | 577 | public function is_approved() { |
| 578 | - return $this->status_is( EEM_Payment::status_id_approved ); |
|
| 578 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return boolean whether the status of this payment equals the status id |
| 590 | 590 | * @throws EE_Error |
| 591 | 591 | */ |
| 592 | - protected function status_is( $STS_ID ) { |
|
| 592 | + protected function status_is($STS_ID) { |
|
| 593 | 593 | return $STS_ID === $this->STS_ID() ? true : false; |
| 594 | 594 | } |
| 595 | 595 | |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | * @throws EE_Error |
| 603 | 603 | */ |
| 604 | 604 | public function is_pending() { |
| 605 | - return $this->status_is( EEM_Payment::status_id_pending ); |
|
| 605 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @throws EE_Error |
| 615 | 615 | */ |
| 616 | 616 | public function is_cancelled() { |
| 617 | - return $this->status_is( EEM_Payment::status_id_cancelled ); |
|
| 617 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @throws EE_Error |
| 627 | 627 | */ |
| 628 | 628 | public function is_declined() { |
| 629 | - return $this->status_is( EEM_Payment::status_id_declined ); |
|
| 629 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | * @throws EE_Error |
| 639 | 639 | */ |
| 640 | 640 | public function is_failed() { |
| 641 | - return $this->status_is( EEM_Payment::status_id_failed ); |
|
| 641 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | * @throws EE_Error |
| 663 | 663 | */ |
| 664 | 664 | public function status_obj() { |
| 665 | - return $this->get_first_related( 'Status' ); |
|
| 665 | + return $this->get_first_related('Status'); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | |
@@ -674,8 +674,8 @@ discard block |
||
| 674 | 674 | * @return EE_Extra_Meta |
| 675 | 675 | * @throws EE_Error |
| 676 | 676 | */ |
| 677 | - public function extra_meta( $query_params = array() ) { |
|
| 678 | - return $this->get_many_related( 'Extra_Meta', $query_params ); |
|
| 677 | + public function extra_meta($query_params = array()) { |
|
| 678 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -689,7 +689,7 @@ discard block |
||
| 689 | 689 | * @throws EE_Error |
| 690 | 690 | */ |
| 691 | 691 | public function payment_method() { |
| 692 | - return $this->get_first_related( 'Payment_Method' ); |
|
| 692 | + return $this->get_first_related('Payment_Method'); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | |
@@ -707,18 +707,18 @@ discard block |
||
| 707 | 707 | * @return string html |
| 708 | 708 | * @throws EE_Error |
| 709 | 709 | */ |
| 710 | - public function redirect_form( $inside_form_html = null ) { |
|
| 710 | + public function redirect_form($inside_form_html = null) { |
|
| 711 | 711 | $redirect_url = $this->redirect_url(); |
| 712 | - if ( ! empty( $redirect_url ) ) { |
|
| 712 | + if ( ! empty($redirect_url)) { |
|
| 713 | 713 | // what ? no inner form content? |
| 714 | - if ( $inside_form_html === null ) { |
|
| 714 | + if ($inside_form_html === null) { |
|
| 715 | 715 | $inside_form_html = EEH_HTML::p( |
| 716 | 716 | sprintf( |
| 717 | 717 | __( |
| 718 | 718 | 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
| 719 | 719 | 'event_espresso' |
| 720 | 720 | ), |
| 721 | - EEH_HTML::br( 2 ), |
|
| 721 | + EEH_HTML::br(2), |
|
| 722 | 722 | '<input type="submit" value="', |
| 723 | 723 | '">' |
| 724 | 724 | ), |
@@ -734,22 +734,22 @@ discard block |
||
| 734 | 734 | ); |
| 735 | 735 | //if it's a GET request, we need to remove all the GET params in the querystring |
| 736 | 736 | //and put them into the form instead |
| 737 | - if ( $method === 'GET' ) { |
|
| 738 | - $querystring = parse_url( $redirect_url, PHP_URL_QUERY ); |
|
| 737 | + if ($method === 'GET') { |
|
| 738 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
| 739 | 739 | $get_params = null; |
| 740 | - parse_str( $querystring, $get_params ); |
|
| 741 | - $inside_form_html .= $this->_args_as_inputs( $get_params ); |
|
| 742 | - $redirect_url = str_replace( '?' . $querystring, '', $redirect_url ); |
|
| 740 | + parse_str($querystring, $get_params); |
|
| 741 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
| 742 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
| 743 | 743 | } |
| 744 | - $form = EEH_HTML::nl( 1 ) |
|
| 744 | + $form = EEH_HTML::nl(1) |
|
| 745 | 745 | . '<form method="' |
| 746 | 746 | . $method |
| 747 | 747 | . '" name="gateway_form" action="' |
| 748 | 748 | . $redirect_url |
| 749 | 749 | . '">'; |
| 750 | - $form .= EEH_HTML::nl( 1 ) . $this->redirect_args_as_inputs(); |
|
| 750 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
| 751 | 751 | $form .= $inside_form_html; |
| 752 | - $form .= EEH_HTML::nl( -1 ) . '</form>' . EEH_HTML::nl( -1 ); |
|
| 752 | + $form .= EEH_HTML::nl( -1 ).'</form>'.EEH_HTML::nl( -1 ); |
|
| 753 | 753 | return $form; |
| 754 | 754 | } else { |
| 755 | 755 | return null; |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * @throws EE_Error |
| 767 | 767 | */ |
| 768 | 768 | public function redirect_args_as_inputs() { |
| 769 | - return $this->_args_as_inputs( $this->redirect_args() ); |
|
| 769 | + return $this->_args_as_inputs($this->redirect_args()); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -778,15 +778,15 @@ discard block |
||
| 778 | 778 | * @param array $args key-value pairs |
| 779 | 779 | * @return string |
| 780 | 780 | */ |
| 781 | - protected function _args_as_inputs( $args ) { |
|
| 781 | + protected function _args_as_inputs($args) { |
|
| 782 | 782 | $html = ''; |
| 783 | - if ( $args !== null && is_array( $args ) ) { |
|
| 784 | - foreach ( $args as $name => $value ) { |
|
| 785 | - $html .= EEH_HTML::nl( 0 ) |
|
| 783 | + if ($args !== null && is_array($args)) { |
|
| 784 | + foreach ($args as $name => $value) { |
|
| 785 | + $html .= EEH_HTML::nl(0) |
|
| 786 | 786 | . '<input type="hidden" name="' |
| 787 | 787 | . $name |
| 788 | 788 | . '" value="' |
| 789 | - . esc_attr( $value ) |
|
| 789 | + . esc_attr($value) |
|
| 790 | 790 | . '"/>'; |
| 791 | 791 | } |
| 792 | 792 | } |
@@ -815,14 +815,14 @@ discard block |
||
| 815 | 815 | * @access private |
| 816 | 816 | * @param mixed $item |
| 817 | 817 | */ |
| 818 | - private function _strip_all_tags_within_array( &$item ) { |
|
| 819 | - if ( is_object( $item ) ) { |
|
| 820 | - $item = (array)$item; |
|
| 818 | + private function _strip_all_tags_within_array(&$item) { |
|
| 819 | + if (is_object($item)) { |
|
| 820 | + $item = (array) $item; |
|
| 821 | 821 | } |
| 822 | - if ( is_array( $item ) ) { |
|
| 823 | - array_walk_recursive( $item, array( $this, '_strip_all_tags_within_array' ) ); |
|
| 822 | + if (is_array($item)) { |
|
| 823 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
| 824 | 824 | } else { |
| 825 | - $item = wp_strip_all_tags( $item ); |
|
| 825 | + $item = wp_strip_all_tags($item); |
|
| 826 | 826 | } |
| 827 | 827 | } |
| 828 | 828 | |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | $original_status = EEH_Array::is_set( |
| 840 | 840 | $this->_props_n_values_provided_in_constructor, |
| 841 | 841 | 'STS_ID', |
| 842 | - $this->get_model()->field_settings_for( 'STS_ID' )->get_default_value() |
|
| 842 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
| 843 | 843 | ); |
| 844 | 844 | $current_status = $this->status(); |
| 845 | 845 | if ( |
@@ -865,11 +865,11 @@ discard block |
||
| 865 | 865 | * @return mixed |
| 866 | 866 | * @throws EE_Error |
| 867 | 867 | */ |
| 868 | - public function get_pretty( $field_name, $extra_cache_ref = null ) { |
|
| 869 | - if ( $field_name === 'PAY_gateway' ) { |
|
| 870 | - return $this->payment_method() ? $this->payment_method()->name() : __( 'Unknown', 'event_espresso' ); |
|
| 868 | + public function get_pretty($field_name, $extra_cache_ref = null) { |
|
| 869 | + if ($field_name === 'PAY_gateway') { |
|
| 870 | + return $this->payment_method() ? $this->payment_method()->name() : __('Unknown', 'event_espresso'); |
|
| 871 | 871 | } |
| 872 | - return $this->_get_cached_property( $field_name, true, $extra_cache_ref ); |
|
| 872 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | |
@@ -881,8 +881,8 @@ discard block |
||
| 881 | 881 | * @return EE_Registration_Payment[] |
| 882 | 882 | * @throws EE_Error |
| 883 | 883 | */ |
| 884 | - public function registration_payments( $query_params = array() ) { |
|
| 885 | - return $this->get_many_related( 'Registration_Payment', $query_params ); |
|
| 884 | + public function registration_payments($query_params = array()) { |
|
| 885 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | |
@@ -940,7 +940,7 @@ discard block |
||
| 940 | 940 | public function get_primary_attendee() |
| 941 | 941 | { |
| 942 | 942 | $primary_reg = $this->get_primary_registration(); |
| 943 | - if( $primary_reg instanceof EE_Registration) { |
|
| 943 | + if ($primary_reg instanceof EE_Registration) { |
|
| 944 | 944 | return $primary_reg->attendee(); |
| 945 | 945 | } |
| 946 | 946 | return null; |
@@ -20,2468 +20,2468 @@ discard block |
||
| 20 | 20 | final class EE_Config implements ResettableInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - const OPTION_NAME = 'ee_config'; |
|
| 23 | + const OPTION_NAME = 'ee_config'; |
|
| 24 | + |
|
| 25 | + const LOG_NAME = 'ee_config_log'; |
|
| 26 | + |
|
| 27 | + const LOG_LENGTH = 100; |
|
| 28 | + |
|
| 29 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * instance of the EE_Config object |
|
| 34 | + * |
|
| 35 | + * @var EE_Config $_instance |
|
| 36 | + * @access private |
|
| 37 | + */ |
|
| 38 | + private static $_instance; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var boolean $_logging_enabled |
|
| 42 | + */ |
|
| 43 | + private static $_logging_enabled = false; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 47 | + */ |
|
| 48 | + private $legacy_shortcodes_manager; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * An StdClass whose property names are addon slugs, |
|
| 52 | + * and values are their config classes |
|
| 53 | + * |
|
| 54 | + * @var StdClass |
|
| 55 | + */ |
|
| 56 | + public $addons; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var EE_Admin_Config |
|
| 60 | + */ |
|
| 61 | + public $admin; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var EE_Core_Config |
|
| 65 | + */ |
|
| 66 | + public $core; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var EE_Currency_Config |
|
| 70 | + */ |
|
| 71 | + public $currency; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var EE_Organization_Config |
|
| 75 | + */ |
|
| 76 | + public $organization; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var EE_Registration_Config |
|
| 80 | + */ |
|
| 81 | + public $registration; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var EE_Template_Config |
|
| 85 | + */ |
|
| 86 | + public $template_settings; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Holds EE environment values. |
|
| 90 | + * |
|
| 91 | + * @var EE_Environment_Config |
|
| 92 | + */ |
|
| 93 | + public $environment; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * settings pertaining to Google maps |
|
| 97 | + * |
|
| 98 | + * @var EE_Map_Config |
|
| 99 | + */ |
|
| 100 | + public $map_settings; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * settings pertaining to Taxes |
|
| 104 | + * |
|
| 105 | + * @var EE_Tax_Config |
|
| 106 | + */ |
|
| 107 | + public $tax_settings; |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Settings pertaining to global messages settings. |
|
| 112 | + * |
|
| 113 | + * @var EE_Messages_Config |
|
| 114 | + */ |
|
| 115 | + public $messages; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @deprecated |
|
| 119 | + * @var EE_Gateway_Config |
|
| 120 | + */ |
|
| 121 | + public $gateway; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var array $_addon_option_names |
|
| 125 | + * @access private |
|
| 126 | + */ |
|
| 127 | + private $_addon_option_names = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @var array $_module_route_map |
|
| 131 | + * @access private |
|
| 132 | + */ |
|
| 133 | + private static $_module_route_map = array(); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @var array $_module_forward_map |
|
| 137 | + * @access private |
|
| 138 | + */ |
|
| 139 | + private static $_module_forward_map = array(); |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @var array $_module_view_map |
|
| 143 | + * @access private |
|
| 144 | + */ |
|
| 145 | + private static $_module_view_map = array(); |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @singleton method used to instantiate class object |
|
| 151 | + * @access public |
|
| 152 | + * @return EE_Config instance |
|
| 153 | + */ |
|
| 154 | + public static function instance() |
|
| 155 | + { |
|
| 156 | + // check if class object is instantiated, and instantiated properly |
|
| 157 | + if (! self::$_instance instanceof EE_Config) { |
|
| 158 | + self::$_instance = new self(); |
|
| 159 | + } |
|
| 160 | + return self::$_instance; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Resets the config |
|
| 167 | + * |
|
| 168 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 169 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 170 | + * reflect its state in the database |
|
| 171 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 172 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 173 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 174 | + * site was put into maintenance mode) |
|
| 175 | + * @return EE_Config |
|
| 176 | + */ |
|
| 177 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 178 | + { |
|
| 179 | + if (self::$_instance instanceof EE_Config) { |
|
| 180 | + if ($hard_reset) { |
|
| 181 | + self::$_instance->legacy_shortcodes_manager = null; |
|
| 182 | + self::$_instance->_addon_option_names = array(); |
|
| 183 | + self::$_instance->_initialize_config(); |
|
| 184 | + self::$_instance->update_espresso_config(); |
|
| 185 | + } |
|
| 186 | + self::$_instance->update_addon_option_names(); |
|
| 187 | + } |
|
| 188 | + self::$_instance = null; |
|
| 189 | + //we don't need to reset the static properties imo because those should |
|
| 190 | + //only change when a module is added or removed. Currently we don't |
|
| 191 | + //support removing a module during a request when it previously existed |
|
| 192 | + if ($reinstantiate) { |
|
| 193 | + return self::instance(); |
|
| 194 | + } else { |
|
| 195 | + return null; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * class constructor |
|
| 203 | + * |
|
| 204 | + * @access private |
|
| 205 | + */ |
|
| 206 | + private function __construct() |
|
| 207 | + { |
|
| 208 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 209 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 210 | + // setup empty config classes |
|
| 211 | + $this->_initialize_config(); |
|
| 212 | + // load existing EE site settings |
|
| 213 | + $this->_load_core_config(); |
|
| 214 | + // confirm everything loaded correctly and set filtered defaults if not |
|
| 215 | + $this->_verify_config(); |
|
| 216 | + // register shortcodes and modules |
|
| 217 | + add_action( |
|
| 218 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 219 | + array($this, 'register_shortcodes_and_modules'), |
|
| 220 | + 999 |
|
| 221 | + ); |
|
| 222 | + // initialize shortcodes and modules |
|
| 223 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 224 | + // register widgets |
|
| 225 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 226 | + // shutdown |
|
| 227 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 228 | + // construct__end hook |
|
| 229 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
| 230 | + // hardcoded hack |
|
| 231 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @return boolean |
|
| 238 | + */ |
|
| 239 | + public static function logging_enabled() |
|
| 240 | + { |
|
| 241 | + return self::$_logging_enabled; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * use to get the current theme if needed from static context |
|
| 248 | + * |
|
| 249 | + * @return string current theme set. |
|
| 250 | + */ |
|
| 251 | + public static function get_current_theme() |
|
| 252 | + { |
|
| 253 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 254 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * _initialize_config |
|
| 261 | + * |
|
| 262 | + * @access private |
|
| 263 | + * @return void |
|
| 264 | + */ |
|
| 265 | + private function _initialize_config() |
|
| 266 | + { |
|
| 267 | + EE_Config::trim_log(); |
|
| 268 | + //set defaults |
|
| 269 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 270 | + $this->addons = new stdClass(); |
|
| 271 | + // set _module_route_map |
|
| 272 | + EE_Config::$_module_route_map = array(); |
|
| 273 | + // set _module_forward_map |
|
| 274 | + EE_Config::$_module_forward_map = array(); |
|
| 275 | + // set _module_view_map |
|
| 276 | + EE_Config::$_module_view_map = array(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * load core plugin configuration |
|
| 283 | + * |
|
| 284 | + * @access private |
|
| 285 | + * @return void |
|
| 286 | + */ |
|
| 287 | + private function _load_core_config() |
|
| 288 | + { |
|
| 289 | + // load_core_config__start hook |
|
| 290 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 291 | + $espresso_config = $this->get_espresso_config(); |
|
| 292 | + foreach ($espresso_config as $config => $settings) { |
|
| 293 | + // load_core_config__start hook |
|
| 294 | + $settings = apply_filters( |
|
| 295 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 296 | + $settings, |
|
| 297 | + $config, |
|
| 298 | + $this |
|
| 299 | + ); |
|
| 300 | + if (is_object($settings) && property_exists($this, $config)) { |
|
| 301 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 302 | + //call configs populate method to ensure any defaults are set for empty values. |
|
| 303 | + if (method_exists($settings, 'populate')) { |
|
| 304 | + $this->{$config}->populate(); |
|
| 305 | + } |
|
| 306 | + if (method_exists($settings, 'do_hooks')) { |
|
| 307 | + $this->{$config}->do_hooks(); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 312 | + $this->update_espresso_config(); |
|
| 313 | + } |
|
| 314 | + // load_core_config__end hook |
|
| 315 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * @return void |
|
| 321 | + * @throws ReflectionException |
|
| 322 | + * @throws InvalidArgumentException |
|
| 323 | + * @throws InvalidInterfaceException |
|
| 324 | + * @throws InvalidDataTypeException |
|
| 325 | + * @throws EE_Error |
|
| 326 | + */ |
|
| 327 | + protected function _verify_config() |
|
| 328 | + { |
|
| 329 | + $this->core = $this->core instanceof EE_Core_Config |
|
| 330 | + ? $this->core |
|
| 331 | + : new EE_Core_Config(); |
|
| 332 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 333 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 334 | + ? $this->organization |
|
| 335 | + : new EE_Organization_Config(); |
|
| 336 | + $this->organization = apply_filters( |
|
| 337 | + 'FHEE__EE_Config___initialize_config__organization', |
|
| 338 | + $this->organization |
|
| 339 | + ); |
|
| 340 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 341 | + ? $this->currency |
|
| 342 | + : new EE_Currency_Config($this->organization->CNT_ISO); |
|
| 343 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 344 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 345 | + ? $this->registration |
|
| 346 | + : new EE_Registration_Config(); |
|
| 347 | + $this->registration = apply_filters( |
|
| 348 | + 'FHEE__EE_Config___initialize_config__registration', |
|
| 349 | + $this->registration |
|
| 350 | + ); |
|
| 351 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 352 | + ? $this->admin |
|
| 353 | + : new EE_Admin_Config(); |
|
| 354 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 355 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 356 | + ? $this->template_settings |
|
| 357 | + : new EE_Template_Config(); |
|
| 358 | + $this->template_settings = apply_filters( |
|
| 359 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 360 | + $this->template_settings |
|
| 361 | + ); |
|
| 362 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 363 | + ? $this->map_settings |
|
| 364 | + : new EE_Map_Config(); |
|
| 365 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 366 | + $this->map_settings); |
|
| 367 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 368 | + ? $this->environment |
|
| 369 | + : new EE_Environment_Config(); |
|
| 370 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 371 | + $this->environment); |
|
| 372 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 373 | + ? $this->tax_settings |
|
| 374 | + : new EE_Tax_Config(); |
|
| 375 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 376 | + $this->tax_settings); |
|
| 377 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 378 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 379 | + ? $this->messages |
|
| 380 | + : new EE_Messages_Config(); |
|
| 381 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 382 | + ? $this->gateway |
|
| 383 | + : new EE_Gateway_Config(); |
|
| 384 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 385 | + $this->legacy_shortcodes_manager = null; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * get_espresso_config |
|
| 391 | + * |
|
| 392 | + * @access public |
|
| 393 | + * @return array of espresso config stuff |
|
| 394 | + */ |
|
| 395 | + public function get_espresso_config() |
|
| 396 | + { |
|
| 397 | + // grab espresso configuration |
|
| 398 | + return apply_filters( |
|
| 399 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 400 | + get_option(EE_Config::OPTION_NAME, array()) |
|
| 401 | + ); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * double_check_config_comparison |
|
| 408 | + * |
|
| 409 | + * @access public |
|
| 410 | + * @param string $option |
|
| 411 | + * @param $old_value |
|
| 412 | + * @param $value |
|
| 413 | + */ |
|
| 414 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 415 | + { |
|
| 416 | + // make sure we're checking the ee config |
|
| 417 | + if ($option === EE_Config::OPTION_NAME) { |
|
| 418 | + // run a loose comparison of the old value against the new value for type and properties, |
|
| 419 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 420 | + if ($value != $old_value) { |
|
| 421 | + // if they are NOT the same, then remove the hook, |
|
| 422 | + // which means the subsequent update results will be based solely on the update query results |
|
| 423 | + // the reason we do this is because, as stated above, |
|
| 424 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 425 | + // this happens PRIOR to serialization and any subsequent update. |
|
| 426 | + // If values are found to match their previous old value, |
|
| 427 | + // then WP bails before performing any update. |
|
| 428 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 429 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 430 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 431 | + // MySQL MAY ALSO NOT perform the update because |
|
| 432 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 433 | + // This results in the query returning an "affected rows" value of ZERO, |
|
| 434 | + // which gets returned immediately by WP update_option and looks like an error. |
|
| 435 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * update_espresso_config |
|
| 444 | + * |
|
| 445 | + * @access public |
|
| 446 | + */ |
|
| 447 | + protected function _reset_espresso_addon_config() |
|
| 448 | + { |
|
| 449 | + $this->_addon_option_names = array(); |
|
| 450 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 451 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 452 | + $config_class = get_class($addon_config_obj); |
|
| 453 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 454 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 455 | + } |
|
| 456 | + $this->addons->{$addon_name} = null; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * update_espresso_config |
|
| 464 | + * |
|
| 465 | + * @access public |
|
| 466 | + * @param bool $add_success |
|
| 467 | + * @param bool $add_error |
|
| 468 | + * @return bool |
|
| 469 | + */ |
|
| 470 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
| 471 | + { |
|
| 472 | + // don't allow config updates during WP heartbeats |
|
| 473 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 474 | + return false; |
|
| 475 | + } |
|
| 476 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 477 | + //$clone = clone( self::$_instance ); |
|
| 478 | + //self::$_instance = NULL; |
|
| 479 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 480 | + $this->_reset_espresso_addon_config(); |
|
| 481 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 482 | + // but BEFORE the actual update occurs |
|
| 483 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 484 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 485 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 486 | + $this->legacy_shortcodes_manager = null; |
|
| 487 | + // now update "ee_config" |
|
| 488 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 489 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 490 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
| 491 | + // if not saved... check if the hook we just added still exists; |
|
| 492 | + // if it does, it means one of two things: |
|
| 493 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 494 | + // or... |
|
| 495 | + // the db update query returned 0 rows affected |
|
| 496 | + // (probably because the data value was the same from it's perspective) |
|
| 497 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 498 | + // but just means no update occurred, so don't display an error to the user. |
|
| 499 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 500 | + // then it means that something truly went wrong |
|
| 501 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 502 | + // remove our action since we don't want it in the system anymore |
|
| 503 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 504 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 505 | + //self::$_instance = $clone; |
|
| 506 | + //unset( $clone ); |
|
| 507 | + // if config remains the same or was updated successfully |
|
| 508 | + if ($saved) { |
|
| 509 | + if ($add_success) { |
|
| 510 | + EE_Error::add_success( |
|
| 511 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 512 | + __FILE__, |
|
| 513 | + __FUNCTION__, |
|
| 514 | + __LINE__ |
|
| 515 | + ); |
|
| 516 | + } |
|
| 517 | + return true; |
|
| 518 | + } else { |
|
| 519 | + if ($add_error) { |
|
| 520 | + EE_Error::add_error( |
|
| 521 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 522 | + __FILE__, |
|
| 523 | + __FUNCTION__, |
|
| 524 | + __LINE__ |
|
| 525 | + ); |
|
| 526 | + } |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * _verify_config_params |
|
| 535 | + * |
|
| 536 | + * @access private |
|
| 537 | + * @param string $section |
|
| 538 | + * @param string $name |
|
| 539 | + * @param string $config_class |
|
| 540 | + * @param EE_Config_Base $config_obj |
|
| 541 | + * @param array $tests_to_run |
|
| 542 | + * @param bool $display_errors |
|
| 543 | + * @return bool TRUE on success, FALSE on fail |
|
| 544 | + */ |
|
| 545 | + private function _verify_config_params( |
|
| 546 | + $section = '', |
|
| 547 | + $name = '', |
|
| 548 | + $config_class = '', |
|
| 549 | + $config_obj = null, |
|
| 550 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 551 | + $display_errors = true |
|
| 552 | + ) { |
|
| 553 | + try { |
|
| 554 | + foreach ($tests_to_run as $test) { |
|
| 555 | + switch ($test) { |
|
| 556 | + // TEST #1 : check that section was set |
|
| 557 | + case 1 : |
|
| 558 | + if (empty($section)) { |
|
| 559 | + if ($display_errors) { |
|
| 560 | + throw new EE_Error( |
|
| 561 | + sprintf( |
|
| 562 | + __( |
|
| 563 | + 'No configuration section has been provided while attempting to save "%s".', |
|
| 564 | + 'event_espresso' |
|
| 565 | + ), |
|
| 566 | + $config_class |
|
| 567 | + ) |
|
| 568 | + ); |
|
| 569 | + } |
|
| 570 | + return false; |
|
| 571 | + } |
|
| 572 | + break; |
|
| 573 | + // TEST #2 : check that settings section exists |
|
| 574 | + case 2 : |
|
| 575 | + if (! isset($this->{$section})) { |
|
| 576 | + if ($display_errors) { |
|
| 577 | + throw new EE_Error( |
|
| 578 | + sprintf( |
|
| 579 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 580 | + $section |
|
| 581 | + ) |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + return false; |
|
| 585 | + } |
|
| 586 | + break; |
|
| 587 | + // TEST #3 : check that section is the proper format |
|
| 588 | + case 3 : |
|
| 589 | + if ( |
|
| 590 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 591 | + ) { |
|
| 592 | + if ($display_errors) { |
|
| 593 | + throw new EE_Error( |
|
| 594 | + sprintf( |
|
| 595 | + __( |
|
| 596 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
| 597 | + 'event_espresso' |
|
| 598 | + ), |
|
| 599 | + $section |
|
| 600 | + ) |
|
| 601 | + ); |
|
| 602 | + } |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + break; |
|
| 606 | + // TEST #4 : check that config section name has been set |
|
| 607 | + case 4 : |
|
| 608 | + if (empty($name)) { |
|
| 609 | + if ($display_errors) { |
|
| 610 | + throw new EE_Error( |
|
| 611 | + __( |
|
| 612 | + 'No name has been provided for the specific configuration section.', |
|
| 613 | + 'event_espresso' |
|
| 614 | + ) |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 619 | + break; |
|
| 620 | + // TEST #5 : check that a config class name has been set |
|
| 621 | + case 5 : |
|
| 622 | + if (empty($config_class)) { |
|
| 623 | + if ($display_errors) { |
|
| 624 | + throw new EE_Error( |
|
| 625 | + __( |
|
| 626 | + 'No class name has been provided for the specific configuration section.', |
|
| 627 | + 'event_espresso' |
|
| 628 | + ) |
|
| 629 | + ); |
|
| 630 | + } |
|
| 631 | + return false; |
|
| 632 | + } |
|
| 633 | + break; |
|
| 634 | + // TEST #6 : verify config class is accessible |
|
| 635 | + case 6 : |
|
| 636 | + if (! class_exists($config_class)) { |
|
| 637 | + if ($display_errors) { |
|
| 638 | + throw new EE_Error( |
|
| 639 | + sprintf( |
|
| 640 | + __( |
|
| 641 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 642 | + 'event_espresso' |
|
| 643 | + ), |
|
| 644 | + $config_class |
|
| 645 | + ) |
|
| 646 | + ); |
|
| 647 | + } |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 650 | + break; |
|
| 651 | + // TEST #7 : check that config has even been set |
|
| 652 | + case 7 : |
|
| 653 | + if (! isset($this->{$section}->{$name})) { |
|
| 654 | + if ($display_errors) { |
|
| 655 | + throw new EE_Error( |
|
| 656 | + sprintf( |
|
| 657 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 658 | + $section, |
|
| 659 | + $name |
|
| 660 | + ) |
|
| 661 | + ); |
|
| 662 | + } |
|
| 663 | + return false; |
|
| 664 | + } else { |
|
| 665 | + // and make sure it's not serialized |
|
| 666 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 667 | + } |
|
| 668 | + break; |
|
| 669 | + // TEST #8 : check that config is the requested type |
|
| 670 | + case 8 : |
|
| 671 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 672 | + if ($display_errors) { |
|
| 673 | + throw new EE_Error( |
|
| 674 | + sprintf( |
|
| 675 | + __( |
|
| 676 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 677 | + 'event_espresso' |
|
| 678 | + ), |
|
| 679 | + $section, |
|
| 680 | + $name, |
|
| 681 | + $config_class |
|
| 682 | + ) |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | + return false; |
|
| 686 | + } |
|
| 687 | + break; |
|
| 688 | + // TEST #9 : verify config object |
|
| 689 | + case 9 : |
|
| 690 | + if (! $config_obj instanceof EE_Config_Base) { |
|
| 691 | + if ($display_errors) { |
|
| 692 | + throw new EE_Error( |
|
| 693 | + sprintf( |
|
| 694 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 695 | + print_r($config_obj, true) |
|
| 696 | + ) |
|
| 697 | + ); |
|
| 698 | + } |
|
| 699 | + return false; |
|
| 700 | + } |
|
| 701 | + break; |
|
| 702 | + } |
|
| 703 | + } |
|
| 704 | + } catch (EE_Error $e) { |
|
| 705 | + $e->get_error(); |
|
| 706 | + } |
|
| 707 | + // you have successfully run the gauntlet |
|
| 708 | + return true; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * _generate_config_option_name |
|
| 715 | + * |
|
| 716 | + * @access protected |
|
| 717 | + * @param string $section |
|
| 718 | + * @param string $name |
|
| 719 | + * @return string |
|
| 720 | + */ |
|
| 721 | + private function _generate_config_option_name($section = '', $name = '') |
|
| 722 | + { |
|
| 723 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * _set_config_class |
|
| 730 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 731 | + * |
|
| 732 | + * @access private |
|
| 733 | + * @param string $config_class |
|
| 734 | + * @param string $name |
|
| 735 | + * @return string |
|
| 736 | + */ |
|
| 737 | + private function _set_config_class($config_class = '', $name = '') |
|
| 738 | + { |
|
| 739 | + return ! empty($config_class) |
|
| 740 | + ? $config_class |
|
| 741 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * set_config |
|
| 748 | + * |
|
| 749 | + * @access protected |
|
| 750 | + * @param string $section |
|
| 751 | + * @param string $name |
|
| 752 | + * @param string $config_class |
|
| 753 | + * @param EE_Config_Base $config_obj |
|
| 754 | + * @return EE_Config_Base |
|
| 755 | + */ |
|
| 756 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 757 | + { |
|
| 758 | + // ensure config class is set to something |
|
| 759 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 760 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 761 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 762 | + return null; |
|
| 763 | + } |
|
| 764 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 765 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 766 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 767 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 768 | + $this->update_addon_option_names(); |
|
| 769 | + } |
|
| 770 | + // verify the incoming config object but suppress errors |
|
| 771 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 772 | + $config_obj = new $config_class(); |
|
| 773 | + } |
|
| 774 | + if (get_option($config_option_name)) { |
|
| 775 | + EE_Config::log($config_option_name); |
|
| 776 | + update_option($config_option_name, $config_obj); |
|
| 777 | + $this->{$section}->{$name} = $config_obj; |
|
| 778 | + return $this->{$section}->{$name}; |
|
| 779 | + } else { |
|
| 780 | + // create a wp-option for this config |
|
| 781 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 782 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 783 | + return $this->{$section}->{$name}; |
|
| 784 | + } else { |
|
| 785 | + EE_Error::add_error( |
|
| 786 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 787 | + __FILE__, |
|
| 788 | + __FUNCTION__, |
|
| 789 | + __LINE__ |
|
| 790 | + ); |
|
| 791 | + return null; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * update_config |
|
| 800 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 801 | + * |
|
| 802 | + * @access public |
|
| 803 | + * @param string $section |
|
| 804 | + * @param string $name |
|
| 805 | + * @param EE_Config_Base|string $config_obj |
|
| 806 | + * @param bool $throw_errors |
|
| 807 | + * @return bool |
|
| 808 | + */ |
|
| 809 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 810 | + { |
|
| 811 | + // don't allow config updates during WP heartbeats |
|
| 812 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 813 | + return false; |
|
| 814 | + } |
|
| 815 | + $config_obj = maybe_unserialize($config_obj); |
|
| 816 | + // get class name of the incoming object |
|
| 817 | + $config_class = get_class($config_obj); |
|
| 818 | + // run tests 1-5 and 9 to verify config |
|
| 819 | + if (! $this->_verify_config_params( |
|
| 820 | + $section, |
|
| 821 | + $name, |
|
| 822 | + $config_class, |
|
| 823 | + $config_obj, |
|
| 824 | + array(1, 2, 3, 4, 7, 9) |
|
| 825 | + ) |
|
| 826 | + ) { |
|
| 827 | + return false; |
|
| 828 | + } |
|
| 829 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 830 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 831 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 832 | + // save new config to db |
|
| 833 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 834 | + return true; |
|
| 835 | + } |
|
| 836 | + } else { |
|
| 837 | + // first check if the record already exists |
|
| 838 | + $existing_config = get_option($config_option_name); |
|
| 839 | + $config_obj = serialize($config_obj); |
|
| 840 | + // just return if db record is already up to date (NOT type safe comparison) |
|
| 841 | + if ($existing_config == $config_obj) { |
|
| 842 | + $this->{$section}->{$name} = $config_obj; |
|
| 843 | + return true; |
|
| 844 | + } else if (update_option($config_option_name, $config_obj)) { |
|
| 845 | + EE_Config::log($config_option_name); |
|
| 846 | + // update wp-option for this config class |
|
| 847 | + $this->{$section}->{$name} = $config_obj; |
|
| 848 | + return true; |
|
| 849 | + } elseif ($throw_errors) { |
|
| 850 | + EE_Error::add_error( |
|
| 851 | + sprintf( |
|
| 852 | + __( |
|
| 853 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 854 | + 'event_espresso' |
|
| 855 | + ), |
|
| 856 | + $config_class, |
|
| 857 | + 'EE_Config->' . $section . '->' . $name |
|
| 858 | + ), |
|
| 859 | + __FILE__, |
|
| 860 | + __FUNCTION__, |
|
| 861 | + __LINE__ |
|
| 862 | + ); |
|
| 863 | + } |
|
| 864 | + } |
|
| 865 | + return false; |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * get_config |
|
| 872 | + * |
|
| 873 | + * @access public |
|
| 874 | + * @param string $section |
|
| 875 | + * @param string $name |
|
| 876 | + * @param string $config_class |
|
| 877 | + * @return mixed EE_Config_Base | NULL |
|
| 878 | + */ |
|
| 879 | + public function get_config($section = '', $name = '', $config_class = '') |
|
| 880 | + { |
|
| 881 | + // ensure config class is set to something |
|
| 882 | + $config_class = $this->_set_config_class($config_class, $name); |
|
| 883 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 884 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 885 | + return null; |
|
| 886 | + } |
|
| 887 | + // now test if the requested config object exists, but suppress errors |
|
| 888 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 889 | + // config already exists, so pass it back |
|
| 890 | + return $this->{$section}->{$name}; |
|
| 891 | + } |
|
| 892 | + // load config option from db if it exists |
|
| 893 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 894 | + // verify the newly retrieved config object, but suppress errors |
|
| 895 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 896 | + // config is good, so set it and pass it back |
|
| 897 | + $this->{$section}->{$name} = $config_obj; |
|
| 898 | + return $this->{$section}->{$name}; |
|
| 899 | + } |
|
| 900 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 901 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
| 902 | + // verify the newly created config object |
|
| 903 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 904 | + return $this->{$section}->{$name}; |
|
| 905 | + } else { |
|
| 906 | + EE_Error::add_error( |
|
| 907 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 908 | + __FILE__, |
|
| 909 | + __FUNCTION__, |
|
| 910 | + __LINE__ |
|
| 911 | + ); |
|
| 912 | + } |
|
| 913 | + return null; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * get_config_option |
|
| 920 | + * |
|
| 921 | + * @access public |
|
| 922 | + * @param string $config_option_name |
|
| 923 | + * @return mixed EE_Config_Base | FALSE |
|
| 924 | + */ |
|
| 925 | + public function get_config_option($config_option_name = '') |
|
| 926 | + { |
|
| 927 | + // retrieve the wp-option for this config class. |
|
| 928 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 929 | + if (empty($config_option)) { |
|
| 930 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 931 | + } |
|
| 932 | + return $config_option; |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + /** |
|
| 938 | + * log |
|
| 939 | + * |
|
| 940 | + * @param string $config_option_name |
|
| 941 | + */ |
|
| 942 | + public static function log($config_option_name = '') |
|
| 943 | + { |
|
| 944 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 945 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 946 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 947 | + $_request = $_REQUEST; |
|
| 948 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 949 | + $config_log[(string)microtime(true)] = array( |
|
| 950 | + 'config_name' => $config_option_name, |
|
| 951 | + 'request' => $_request, |
|
| 952 | + ); |
|
| 953 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 954 | + } |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * trim_log |
|
| 961 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 962 | + */ |
|
| 963 | + public static function trim_log() |
|
| 964 | + { |
|
| 965 | + if (! EE_Config::logging_enabled()) { |
|
| 966 | + return; |
|
| 967 | + } |
|
| 968 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 969 | + $log_length = count($config_log); |
|
| 970 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 971 | + ksort($config_log); |
|
| 972 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 973 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
| 974 | + } |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * get_page_for_posts |
|
| 981 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 982 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 983 | + * |
|
| 984 | + * @access public |
|
| 985 | + * @return string |
|
| 986 | + */ |
|
| 987 | + public static function get_page_for_posts() |
|
| 988 | + { |
|
| 989 | + $page_for_posts = get_option('page_for_posts'); |
|
| 990 | + if (! $page_for_posts) { |
|
| 991 | + return 'posts'; |
|
| 992 | + } |
|
| 993 | + /** @type WPDB $wpdb */ |
|
| 994 | + global $wpdb; |
|
| 995 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 996 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * register_shortcodes_and_modules. |
|
| 1003 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 1004 | + * In fact, this is where we give modules a chance to let core know they exist |
|
| 1005 | + * so they can help trigger maintenance mode if it's needed |
|
| 1006 | + * |
|
| 1007 | + * @access public |
|
| 1008 | + * @return void |
|
| 1009 | + */ |
|
| 1010 | + public function register_shortcodes_and_modules() |
|
| 1011 | + { |
|
| 1012 | + // allow modules to set hooks for the rest of the system |
|
| 1013 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * initialize_shortcodes_and_modules |
|
| 1020 | + * meaning they can start adding their hooks to get stuff done |
|
| 1021 | + * |
|
| 1022 | + * @access public |
|
| 1023 | + * @return void |
|
| 1024 | + */ |
|
| 1025 | + public function initialize_shortcodes_and_modules() |
|
| 1026 | + { |
|
| 1027 | + // allow modules to set hooks for the rest of the system |
|
| 1028 | + $this->_initialize_modules(); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * widgets_init |
|
| 1035 | + * |
|
| 1036 | + * @access private |
|
| 1037 | + * @return void |
|
| 1038 | + */ |
|
| 1039 | + public function widgets_init() |
|
| 1040 | + { |
|
| 1041 | + //only init widgets on admin pages when not in complete maintenance, and |
|
| 1042 | + //on frontend when not in any maintenance mode |
|
| 1043 | + if ( |
|
| 1044 | + ! EE_Maintenance_Mode::instance()->level() |
|
| 1045 | + || ( |
|
| 1046 | + is_admin() |
|
| 1047 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1048 | + ) |
|
| 1049 | + ) { |
|
| 1050 | + // grab list of installed widgets |
|
| 1051 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1052 | + // filter list of modules to register |
|
| 1053 | + $widgets_to_register = apply_filters( |
|
| 1054 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1055 | + $widgets_to_register |
|
| 1056 | + ); |
|
| 1057 | + if (! empty($widgets_to_register)) { |
|
| 1058 | + // cycle thru widget folders |
|
| 1059 | + foreach ($widgets_to_register as $widget_path) { |
|
| 1060 | + // add to list of installed widget modules |
|
| 1061 | + EE_Config::register_ee_widget($widget_path); |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + // filter list of installed modules |
|
| 1065 | + EE_Registry::instance()->widgets = apply_filters( |
|
| 1066 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1067 | + EE_Registry::instance()->widgets |
|
| 1068 | + ); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + |
|
| 1073 | + |
|
| 1074 | + /** |
|
| 1075 | + * register_ee_widget - makes core aware of this widget |
|
| 1076 | + * |
|
| 1077 | + * @access public |
|
| 1078 | + * @param string $widget_path - full path up to and including widget folder |
|
| 1079 | + * @return void |
|
| 1080 | + */ |
|
| 1081 | + public static function register_ee_widget($widget_path = null) |
|
| 1082 | + { |
|
| 1083 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1084 | + $widget_ext = '.widget.php'; |
|
| 1085 | + // make all separators match |
|
| 1086 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1087 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1088 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1089 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1090 | + $file_name = explode('.', basename($widget_path)); |
|
| 1091 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 1092 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1093 | + // sanitize shortcode directory name |
|
| 1094 | + $widget = sanitize_key($widget); |
|
| 1095 | + // now we need to rebuild the shortcode path |
|
| 1096 | + $widget_path = explode(DS, $widget_path); |
|
| 1097 | + // remove last segment |
|
| 1098 | + array_pop($widget_path); |
|
| 1099 | + // glue it back together |
|
| 1100 | + $widget_path = implode(DS, $widget_path); |
|
| 1101 | + } else { |
|
| 1102 | + // grab and sanitize widget directory name |
|
| 1103 | + $widget = sanitize_key(basename($widget_path)); |
|
| 1104 | + } |
|
| 1105 | + // create classname from widget directory name |
|
| 1106 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1107 | + // add class prefix |
|
| 1108 | + $widget_class = 'EEW_' . $widget; |
|
| 1109 | + // does the widget exist ? |
|
| 1110 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1111 | + $msg = sprintf( |
|
| 1112 | + __( |
|
| 1113 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1114 | + 'event_espresso' |
|
| 1115 | + ), |
|
| 1116 | + $widget_class, |
|
| 1117 | + $widget_path . DS . $widget_class . $widget_ext |
|
| 1118 | + ); |
|
| 1119 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1120 | + return; |
|
| 1121 | + } |
|
| 1122 | + // load the widget class file |
|
| 1123 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1124 | + // verify that class exists |
|
| 1125 | + if (! class_exists($widget_class)) { |
|
| 1126 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1127 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1128 | + return; |
|
| 1129 | + } |
|
| 1130 | + register_widget($widget_class); |
|
| 1131 | + // add to array of registered widgets |
|
| 1132 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * _register_modules |
|
| 1139 | + * |
|
| 1140 | + * @access private |
|
| 1141 | + * @return array |
|
| 1142 | + */ |
|
| 1143 | + private function _register_modules() |
|
| 1144 | + { |
|
| 1145 | + // grab list of installed modules |
|
| 1146 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1147 | + // filter list of modules to register |
|
| 1148 | + $modules_to_register = apply_filters( |
|
| 1149 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1150 | + $modules_to_register |
|
| 1151 | + ); |
|
| 1152 | + if (! empty($modules_to_register)) { |
|
| 1153 | + // loop through folders |
|
| 1154 | + foreach ($modules_to_register as $module_path) { |
|
| 1155 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1156 | + if ( |
|
| 1157 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1158 | + && $module_path !== EE_MODULES . 'gateways' |
|
| 1159 | + ) { |
|
| 1160 | + // add to list of installed modules |
|
| 1161 | + EE_Config::register_module($module_path); |
|
| 1162 | + } |
|
| 1163 | + } |
|
| 1164 | + } |
|
| 1165 | + // filter list of installed modules |
|
| 1166 | + return apply_filters( |
|
| 1167 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1168 | + EE_Registry::instance()->modules |
|
| 1169 | + ); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * register_module - makes core aware of this module |
|
| 1176 | + * |
|
| 1177 | + * @access public |
|
| 1178 | + * @param string $module_path - full path up to and including module folder |
|
| 1179 | + * @return bool |
|
| 1180 | + */ |
|
| 1181 | + public static function register_module($module_path = null) |
|
| 1182 | + { |
|
| 1183 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1184 | + $module_ext = '.module.php'; |
|
| 1185 | + // make all separators match |
|
| 1186 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1187 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1188 | + if (strpos($module_path, $module_ext) !== false) { |
|
| 1189 | + // grab and shortcode file name from directory name and break apart at dots |
|
| 1190 | + $module_file = explode('.', basename($module_path)); |
|
| 1191 | + // now we need to rebuild the shortcode path |
|
| 1192 | + $module_path = explode(DS, $module_path); |
|
| 1193 | + // remove last segment |
|
| 1194 | + array_pop($module_path); |
|
| 1195 | + // glue it back together |
|
| 1196 | + $module_path = implode(DS, $module_path) . DS; |
|
| 1197 | + // take first segment from file name pieces and sanitize it |
|
| 1198 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1199 | + // ensure class prefix is added |
|
| 1200 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1201 | + } else { |
|
| 1202 | + // we need to generate the filename based off of the folder name |
|
| 1203 | + // grab and sanitize module name |
|
| 1204 | + $module = strtolower(basename($module_path)); |
|
| 1205 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1206 | + // like trailingslashit() |
|
| 1207 | + $module_path = rtrim($module_path, DS) . DS; |
|
| 1208 | + // create classname from module directory name |
|
| 1209 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1210 | + // add class prefix |
|
| 1211 | + $module_class = 'EED_' . $module; |
|
| 1212 | + } |
|
| 1213 | + // does the module exist ? |
|
| 1214 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1215 | + $msg = sprintf( |
|
| 1216 | + __( |
|
| 1217 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1218 | + 'event_espresso' |
|
| 1219 | + ), |
|
| 1220 | + $module |
|
| 1221 | + ); |
|
| 1222 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1223 | + return false; |
|
| 1224 | + } |
|
| 1225 | + // load the module class file |
|
| 1226 | + require_once($module_path . $module_class . $module_ext); |
|
| 1227 | + // verify that class exists |
|
| 1228 | + if (! class_exists($module_class)) { |
|
| 1229 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1230 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | + return false; |
|
| 1232 | + } |
|
| 1233 | + // add to array of registered modules |
|
| 1234 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1235 | + do_action( |
|
| 1236 | + 'AHEE__EE_Config__register_module__complete', |
|
| 1237 | + $module_class, |
|
| 1238 | + EE_Registry::instance()->modules->{$module_class} |
|
| 1239 | + ); |
|
| 1240 | + return true; |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + |
|
| 1245 | + /** |
|
| 1246 | + * _initialize_modules |
|
| 1247 | + * allow modules to set hooks for the rest of the system |
|
| 1248 | + * |
|
| 1249 | + * @access private |
|
| 1250 | + * @return void |
|
| 1251 | + */ |
|
| 1252 | + private function _initialize_modules() |
|
| 1253 | + { |
|
| 1254 | + // cycle thru shortcode folders |
|
| 1255 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1256 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1257 | + // which set hooks ? |
|
| 1258 | + if (is_admin()) { |
|
| 1259 | + // fire immediately |
|
| 1260 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1261 | + } else { |
|
| 1262 | + // delay until other systems are online |
|
| 1263 | + add_action( |
|
| 1264 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1265 | + array($module_class, 'set_hooks') |
|
| 1266 | + ); |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * register_route - adds module method routes to route_map |
|
| 1275 | + * |
|
| 1276 | + * @access public |
|
| 1277 | + * @param string $route - "pretty" public alias for module method |
|
| 1278 | + * @param string $module - module name (classname without EED_ prefix) |
|
| 1279 | + * @param string $method_name - the actual module method to be routed to |
|
| 1280 | + * @param string $key - url param key indicating a route is being called |
|
| 1281 | + * @return bool |
|
| 1282 | + */ |
|
| 1283 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1284 | + { |
|
| 1285 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1286 | + $module = str_replace('EED_', '', $module); |
|
| 1287 | + $module_class = 'EED_' . $module; |
|
| 1288 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1289 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1290 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | + return false; |
|
| 1292 | + } |
|
| 1293 | + if (empty($route)) { |
|
| 1294 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1295 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1296 | + return false; |
|
| 1297 | + } |
|
| 1298 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1299 | + $msg = sprintf( |
|
| 1300 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1301 | + $route |
|
| 1302 | + ); |
|
| 1303 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1304 | + return false; |
|
| 1305 | + } |
|
| 1306 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1307 | + return true; |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + |
|
| 1311 | + |
|
| 1312 | + /** |
|
| 1313 | + * get_route - get module method route |
|
| 1314 | + * |
|
| 1315 | + * @access public |
|
| 1316 | + * @param string $route - "pretty" public alias for module method |
|
| 1317 | + * @param string $key - url param key indicating a route is being called |
|
| 1318 | + * @return string |
|
| 1319 | + */ |
|
| 1320 | + public static function get_route($route = null, $key = 'ee') |
|
| 1321 | + { |
|
| 1322 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1323 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1324 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1325 | + return EE_Config::$_module_route_map[$key][$route]; |
|
| 1326 | + } |
|
| 1327 | + return null; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + |
|
| 1331 | + |
|
| 1332 | + /** |
|
| 1333 | + * get_routes - get ALL module method routes |
|
| 1334 | + * |
|
| 1335 | + * @access public |
|
| 1336 | + * @return array |
|
| 1337 | + */ |
|
| 1338 | + public static function get_routes() |
|
| 1339 | + { |
|
| 1340 | + return EE_Config::$_module_route_map; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + |
|
| 1344 | + |
|
| 1345 | + /** |
|
| 1346 | + * register_forward - allows modules to forward request to another module for further processing |
|
| 1347 | + * |
|
| 1348 | + * @access public |
|
| 1349 | + * @param string $route - "pretty" public alias for module method |
|
| 1350 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1351 | + * class, allows different forwards to be served based on status |
|
| 1352 | + * @param array|string $forward - function name or array( class, method ) |
|
| 1353 | + * @param string $key - url param key indicating a route is being called |
|
| 1354 | + * @return bool |
|
| 1355 | + */ |
|
| 1356 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1357 | + { |
|
| 1358 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1359 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1360 | + $msg = sprintf( |
|
| 1361 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1362 | + $route |
|
| 1363 | + ); |
|
| 1364 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | + return false; |
|
| 1366 | + } |
|
| 1367 | + if (empty($forward)) { |
|
| 1368 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1369 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | + return false; |
|
| 1371 | + } |
|
| 1372 | + if (is_array($forward)) { |
|
| 1373 | + if (! isset($forward[1])) { |
|
| 1374 | + $msg = sprintf( |
|
| 1375 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1376 | + $route |
|
| 1377 | + ); |
|
| 1378 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | + return false; |
|
| 1380 | + } |
|
| 1381 | + if (! method_exists($forward[0], $forward[1])) { |
|
| 1382 | + $msg = sprintf( |
|
| 1383 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1384 | + $forward[1], |
|
| 1385 | + $route |
|
| 1386 | + ); |
|
| 1387 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | + return false; |
|
| 1389 | + } |
|
| 1390 | + } else if (! function_exists($forward)) { |
|
| 1391 | + $msg = sprintf( |
|
| 1392 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1393 | + $forward, |
|
| 1394 | + $route |
|
| 1395 | + ); |
|
| 1396 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1397 | + return false; |
|
| 1398 | + } |
|
| 1399 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1400 | + return true; |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + |
|
| 1404 | + |
|
| 1405 | + /** |
|
| 1406 | + * get_forward - get forwarding route |
|
| 1407 | + * |
|
| 1408 | + * @access public |
|
| 1409 | + * @param string $route - "pretty" public alias for module method |
|
| 1410 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1411 | + * allows different forwards to be served based on status |
|
| 1412 | + * @param string $key - url param key indicating a route is being called |
|
| 1413 | + * @return string |
|
| 1414 | + */ |
|
| 1415 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1416 | + { |
|
| 1417 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1418 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1419 | + return apply_filters( |
|
| 1420 | + 'FHEE__EE_Config__get_forward', |
|
| 1421 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1422 | + $route, |
|
| 1423 | + $status |
|
| 1424 | + ); |
|
| 1425 | + } |
|
| 1426 | + return null; |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + |
|
| 1430 | + |
|
| 1431 | + /** |
|
| 1432 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1433 | + * results |
|
| 1434 | + * |
|
| 1435 | + * @access public |
|
| 1436 | + * @param string $route - "pretty" public alias for module method |
|
| 1437 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1438 | + * allows different views to be served based on status |
|
| 1439 | + * @param string $view |
|
| 1440 | + * @param string $key - url param key indicating a route is being called |
|
| 1441 | + * @return bool |
|
| 1442 | + */ |
|
| 1443 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1444 | + { |
|
| 1445 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1446 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1447 | + $msg = sprintf( |
|
| 1448 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1449 | + $route |
|
| 1450 | + ); |
|
| 1451 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | + return false; |
|
| 1453 | + } |
|
| 1454 | + if (! is_readable($view)) { |
|
| 1455 | + $msg = sprintf( |
|
| 1456 | + __( |
|
| 1457 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1458 | + 'event_espresso' |
|
| 1459 | + ), |
|
| 1460 | + $view |
|
| 1461 | + ); |
|
| 1462 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1463 | + return false; |
|
| 1464 | + } |
|
| 1465 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1466 | + return true; |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + |
|
| 1470 | + |
|
| 1471 | + /** |
|
| 1472 | + * get_view - get view for route and status |
|
| 1473 | + * |
|
| 1474 | + * @access public |
|
| 1475 | + * @param string $route - "pretty" public alias for module method |
|
| 1476 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1477 | + * allows different views to be served based on status |
|
| 1478 | + * @param string $key - url param key indicating a route is being called |
|
| 1479 | + * @return string |
|
| 1480 | + */ |
|
| 1481 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1482 | + { |
|
| 1483 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1484 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1485 | + return apply_filters( |
|
| 1486 | + 'FHEE__EE_Config__get_view', |
|
| 1487 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1488 | + $route, |
|
| 1489 | + $status |
|
| 1490 | + ); |
|
| 1491 | + } |
|
| 1492 | + return null; |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + |
|
| 1496 | + |
|
| 1497 | + public function update_addon_option_names() |
|
| 1498 | + { |
|
| 1499 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + |
|
| 1504 | + public function shutdown() |
|
| 1505 | + { |
|
| 1506 | + $this->update_addon_option_names(); |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + |
|
| 1510 | + |
|
| 1511 | + /** |
|
| 1512 | + * @return LegacyShortcodesManager |
|
| 1513 | + */ |
|
| 1514 | + public static function getLegacyShortcodesManager() |
|
| 1515 | + { |
|
| 1516 | + |
|
| 1517 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1518 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1519 | + EE_Registry::instance() |
|
| 1520 | + ); |
|
| 1521 | + } |
|
| 1522 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1523 | + } |
|
| 1524 | + |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * register_shortcode - makes core aware of this shortcode |
|
| 1529 | + * |
|
| 1530 | + * @deprecated 4.9.26 |
|
| 1531 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1532 | + * @return bool |
|
| 1533 | + */ |
|
| 1534 | + public static function register_shortcode($shortcode_path = null) |
|
| 1535 | + { |
|
| 1536 | + EE_Error::doing_it_wrong( |
|
| 1537 | + __METHOD__, |
|
| 1538 | + __( |
|
| 1539 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1540 | + 'event_espresso' |
|
| 1541 | + ), |
|
| 1542 | + '4.9.26' |
|
| 1543 | + ); |
|
| 1544 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1545 | + } |
|
| 24 | 1546 | |
| 25 | - const LOG_NAME = 'ee_config_log'; |
|
| 26 | 1547 | |
| 27 | - const LOG_LENGTH = 100; |
|
| 28 | 1548 | |
| 29 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * instance of the EE_Config object |
|
| 34 | - * |
|
| 35 | - * @var EE_Config $_instance |
|
| 36 | - * @access private |
|
| 37 | - */ |
|
| 38 | - private static $_instance; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var boolean $_logging_enabled |
|
| 42 | - */ |
|
| 43 | - private static $_logging_enabled = false; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
| 47 | - */ |
|
| 48 | - private $legacy_shortcodes_manager; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * An StdClass whose property names are addon slugs, |
|
| 52 | - * and values are their config classes |
|
| 53 | - * |
|
| 54 | - * @var StdClass |
|
| 55 | - */ |
|
| 56 | - public $addons; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var EE_Admin_Config |
|
| 60 | - */ |
|
| 61 | - public $admin; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var EE_Core_Config |
|
| 65 | - */ |
|
| 66 | - public $core; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var EE_Currency_Config |
|
| 70 | - */ |
|
| 71 | - public $currency; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var EE_Organization_Config |
|
| 75 | - */ |
|
| 76 | - public $organization; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var EE_Registration_Config |
|
| 80 | - */ |
|
| 81 | - public $registration; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var EE_Template_Config |
|
| 85 | - */ |
|
| 86 | - public $template_settings; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Holds EE environment values. |
|
| 90 | - * |
|
| 91 | - * @var EE_Environment_Config |
|
| 92 | - */ |
|
| 93 | - public $environment; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * settings pertaining to Google maps |
|
| 97 | - * |
|
| 98 | - * @var EE_Map_Config |
|
| 99 | - */ |
|
| 100 | - public $map_settings; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * settings pertaining to Taxes |
|
| 104 | - * |
|
| 105 | - * @var EE_Tax_Config |
|
| 106 | - */ |
|
| 107 | - public $tax_settings; |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Settings pertaining to global messages settings. |
|
| 112 | - * |
|
| 113 | - * @var EE_Messages_Config |
|
| 114 | - */ |
|
| 115 | - public $messages; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @deprecated |
|
| 119 | - * @var EE_Gateway_Config |
|
| 120 | - */ |
|
| 121 | - public $gateway; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var array $_addon_option_names |
|
| 125 | - * @access private |
|
| 126 | - */ |
|
| 127 | - private $_addon_option_names = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @var array $_module_route_map |
|
| 131 | - * @access private |
|
| 132 | - */ |
|
| 133 | - private static $_module_route_map = array(); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var array $_module_forward_map |
|
| 137 | - * @access private |
|
| 138 | - */ |
|
| 139 | - private static $_module_forward_map = array(); |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @var array $_module_view_map |
|
| 143 | - * @access private |
|
| 144 | - */ |
|
| 145 | - private static $_module_view_map = array(); |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @singleton method used to instantiate class object |
|
| 151 | - * @access public |
|
| 152 | - * @return EE_Config instance |
|
| 153 | - */ |
|
| 154 | - public static function instance() |
|
| 155 | - { |
|
| 156 | - // check if class object is instantiated, and instantiated properly |
|
| 157 | - if (! self::$_instance instanceof EE_Config) { |
|
| 158 | - self::$_instance = new self(); |
|
| 159 | - } |
|
| 160 | - return self::$_instance; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Resets the config |
|
| 167 | - * |
|
| 168 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
| 169 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
| 170 | - * reflect its state in the database |
|
| 171 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
| 172 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
| 173 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
| 174 | - * site was put into maintenance mode) |
|
| 175 | - * @return EE_Config |
|
| 176 | - */ |
|
| 177 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
| 178 | - { |
|
| 179 | - if (self::$_instance instanceof EE_Config) { |
|
| 180 | - if ($hard_reset) { |
|
| 181 | - self::$_instance->legacy_shortcodes_manager = null; |
|
| 182 | - self::$_instance->_addon_option_names = array(); |
|
| 183 | - self::$_instance->_initialize_config(); |
|
| 184 | - self::$_instance->update_espresso_config(); |
|
| 185 | - } |
|
| 186 | - self::$_instance->update_addon_option_names(); |
|
| 187 | - } |
|
| 188 | - self::$_instance = null; |
|
| 189 | - //we don't need to reset the static properties imo because those should |
|
| 190 | - //only change when a module is added or removed. Currently we don't |
|
| 191 | - //support removing a module during a request when it previously existed |
|
| 192 | - if ($reinstantiate) { |
|
| 193 | - return self::instance(); |
|
| 194 | - } else { |
|
| 195 | - return null; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * class constructor |
|
| 203 | - * |
|
| 204 | - * @access private |
|
| 205 | - */ |
|
| 206 | - private function __construct() |
|
| 207 | - { |
|
| 208 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
| 209 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
| 210 | - // setup empty config classes |
|
| 211 | - $this->_initialize_config(); |
|
| 212 | - // load existing EE site settings |
|
| 213 | - $this->_load_core_config(); |
|
| 214 | - // confirm everything loaded correctly and set filtered defaults if not |
|
| 215 | - $this->_verify_config(); |
|
| 216 | - // register shortcodes and modules |
|
| 217 | - add_action( |
|
| 218 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
| 219 | - array($this, 'register_shortcodes_and_modules'), |
|
| 220 | - 999 |
|
| 221 | - ); |
|
| 222 | - // initialize shortcodes and modules |
|
| 223 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
| 224 | - // register widgets |
|
| 225 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
| 226 | - // shutdown |
|
| 227 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
| 228 | - // construct__end hook |
|
| 229 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
| 230 | - // hardcoded hack |
|
| 231 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @return boolean |
|
| 238 | - */ |
|
| 239 | - public static function logging_enabled() |
|
| 240 | - { |
|
| 241 | - return self::$_logging_enabled; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * use to get the current theme if needed from static context |
|
| 248 | - * |
|
| 249 | - * @return string current theme set. |
|
| 250 | - */ |
|
| 251 | - public static function get_current_theme() |
|
| 252 | - { |
|
| 253 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
| 254 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * _initialize_config |
|
| 261 | - * |
|
| 262 | - * @access private |
|
| 263 | - * @return void |
|
| 264 | - */ |
|
| 265 | - private function _initialize_config() |
|
| 266 | - { |
|
| 267 | - EE_Config::trim_log(); |
|
| 268 | - //set defaults |
|
| 269 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
| 270 | - $this->addons = new stdClass(); |
|
| 271 | - // set _module_route_map |
|
| 272 | - EE_Config::$_module_route_map = array(); |
|
| 273 | - // set _module_forward_map |
|
| 274 | - EE_Config::$_module_forward_map = array(); |
|
| 275 | - // set _module_view_map |
|
| 276 | - EE_Config::$_module_view_map = array(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * load core plugin configuration |
|
| 283 | - * |
|
| 284 | - * @access private |
|
| 285 | - * @return void |
|
| 286 | - */ |
|
| 287 | - private function _load_core_config() |
|
| 288 | - { |
|
| 289 | - // load_core_config__start hook |
|
| 290 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
| 291 | - $espresso_config = $this->get_espresso_config(); |
|
| 292 | - foreach ($espresso_config as $config => $settings) { |
|
| 293 | - // load_core_config__start hook |
|
| 294 | - $settings = apply_filters( |
|
| 295 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 296 | - $settings, |
|
| 297 | - $config, |
|
| 298 | - $this |
|
| 299 | - ); |
|
| 300 | - if (is_object($settings) && property_exists($this, $config)) { |
|
| 301 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 302 | - //call configs populate method to ensure any defaults are set for empty values. |
|
| 303 | - if (method_exists($settings, 'populate')) { |
|
| 304 | - $this->{$config}->populate(); |
|
| 305 | - } |
|
| 306 | - if (method_exists($settings, 'do_hooks')) { |
|
| 307 | - $this->{$config}->do_hooks(); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
| 312 | - $this->update_espresso_config(); |
|
| 313 | - } |
|
| 314 | - // load_core_config__end hook |
|
| 315 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @return void |
|
| 321 | - * @throws ReflectionException |
|
| 322 | - * @throws InvalidArgumentException |
|
| 323 | - * @throws InvalidInterfaceException |
|
| 324 | - * @throws InvalidDataTypeException |
|
| 325 | - * @throws EE_Error |
|
| 326 | - */ |
|
| 327 | - protected function _verify_config() |
|
| 328 | - { |
|
| 329 | - $this->core = $this->core instanceof EE_Core_Config |
|
| 330 | - ? $this->core |
|
| 331 | - : new EE_Core_Config(); |
|
| 332 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
| 333 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
| 334 | - ? $this->organization |
|
| 335 | - : new EE_Organization_Config(); |
|
| 336 | - $this->organization = apply_filters( |
|
| 337 | - 'FHEE__EE_Config___initialize_config__organization', |
|
| 338 | - $this->organization |
|
| 339 | - ); |
|
| 340 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
| 341 | - ? $this->currency |
|
| 342 | - : new EE_Currency_Config($this->organization->CNT_ISO); |
|
| 343 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
| 344 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
| 345 | - ? $this->registration |
|
| 346 | - : new EE_Registration_Config(); |
|
| 347 | - $this->registration = apply_filters( |
|
| 348 | - 'FHEE__EE_Config___initialize_config__registration', |
|
| 349 | - $this->registration |
|
| 350 | - ); |
|
| 351 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
| 352 | - ? $this->admin |
|
| 353 | - : new EE_Admin_Config(); |
|
| 354 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
| 355 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
| 356 | - ? $this->template_settings |
|
| 357 | - : new EE_Template_Config(); |
|
| 358 | - $this->template_settings = apply_filters( |
|
| 359 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
| 360 | - $this->template_settings |
|
| 361 | - ); |
|
| 362 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
| 363 | - ? $this->map_settings |
|
| 364 | - : new EE_Map_Config(); |
|
| 365 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
| 366 | - $this->map_settings); |
|
| 367 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
| 368 | - ? $this->environment |
|
| 369 | - : new EE_Environment_Config(); |
|
| 370 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
| 371 | - $this->environment); |
|
| 372 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
| 373 | - ? $this->tax_settings |
|
| 374 | - : new EE_Tax_Config(); |
|
| 375 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
| 376 | - $this->tax_settings); |
|
| 377 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
| 378 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
| 379 | - ? $this->messages |
|
| 380 | - : new EE_Messages_Config(); |
|
| 381 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
| 382 | - ? $this->gateway |
|
| 383 | - : new EE_Gateway_Config(); |
|
| 384 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
| 385 | - $this->legacy_shortcodes_manager = null; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * get_espresso_config |
|
| 391 | - * |
|
| 392 | - * @access public |
|
| 393 | - * @return array of espresso config stuff |
|
| 394 | - */ |
|
| 395 | - public function get_espresso_config() |
|
| 396 | - { |
|
| 397 | - // grab espresso configuration |
|
| 398 | - return apply_filters( |
|
| 399 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
| 400 | - get_option(EE_Config::OPTION_NAME, array()) |
|
| 401 | - ); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * double_check_config_comparison |
|
| 408 | - * |
|
| 409 | - * @access public |
|
| 410 | - * @param string $option |
|
| 411 | - * @param $old_value |
|
| 412 | - * @param $value |
|
| 413 | - */ |
|
| 414 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
| 415 | - { |
|
| 416 | - // make sure we're checking the ee config |
|
| 417 | - if ($option === EE_Config::OPTION_NAME) { |
|
| 418 | - // run a loose comparison of the old value against the new value for type and properties, |
|
| 419 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
| 420 | - if ($value != $old_value) { |
|
| 421 | - // if they are NOT the same, then remove the hook, |
|
| 422 | - // which means the subsequent update results will be based solely on the update query results |
|
| 423 | - // the reason we do this is because, as stated above, |
|
| 424 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
| 425 | - // this happens PRIOR to serialization and any subsequent update. |
|
| 426 | - // If values are found to match their previous old value, |
|
| 427 | - // then WP bails before performing any update. |
|
| 428 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
| 429 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
| 430 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
| 431 | - // MySQL MAY ALSO NOT perform the update because |
|
| 432 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
| 433 | - // This results in the query returning an "affected rows" value of ZERO, |
|
| 434 | - // which gets returned immediately by WP update_option and looks like an error. |
|
| 435 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * update_espresso_config |
|
| 444 | - * |
|
| 445 | - * @access public |
|
| 446 | - */ |
|
| 447 | - protected function _reset_espresso_addon_config() |
|
| 448 | - { |
|
| 449 | - $this->_addon_option_names = array(); |
|
| 450 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
| 451 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
| 452 | - $config_class = get_class($addon_config_obj); |
|
| 453 | - if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
| 454 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
| 455 | - } |
|
| 456 | - $this->addons->{$addon_name} = null; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * update_espresso_config |
|
| 464 | - * |
|
| 465 | - * @access public |
|
| 466 | - * @param bool $add_success |
|
| 467 | - * @param bool $add_error |
|
| 468 | - * @return bool |
|
| 469 | - */ |
|
| 470 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
| 471 | - { |
|
| 472 | - // don't allow config updates during WP heartbeats |
|
| 473 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 474 | - return false; |
|
| 475 | - } |
|
| 476 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
| 477 | - //$clone = clone( self::$_instance ); |
|
| 478 | - //self::$_instance = NULL; |
|
| 479 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
| 480 | - $this->_reset_espresso_addon_config(); |
|
| 481 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
| 482 | - // but BEFORE the actual update occurs |
|
| 483 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
| 484 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
| 485 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
| 486 | - $this->legacy_shortcodes_manager = null; |
|
| 487 | - // now update "ee_config" |
|
| 488 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
| 489 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
| 490 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
| 491 | - // if not saved... check if the hook we just added still exists; |
|
| 492 | - // if it does, it means one of two things: |
|
| 493 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
| 494 | - // or... |
|
| 495 | - // the db update query returned 0 rows affected |
|
| 496 | - // (probably because the data value was the same from it's perspective) |
|
| 497 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
| 498 | - // but just means no update occurred, so don't display an error to the user. |
|
| 499 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
| 500 | - // then it means that something truly went wrong |
|
| 501 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
| 502 | - // remove our action since we don't want it in the system anymore |
|
| 503 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
| 504 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
| 505 | - //self::$_instance = $clone; |
|
| 506 | - //unset( $clone ); |
|
| 507 | - // if config remains the same or was updated successfully |
|
| 508 | - if ($saved) { |
|
| 509 | - if ($add_success) { |
|
| 510 | - EE_Error::add_success( |
|
| 511 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
| 512 | - __FILE__, |
|
| 513 | - __FUNCTION__, |
|
| 514 | - __LINE__ |
|
| 515 | - ); |
|
| 516 | - } |
|
| 517 | - return true; |
|
| 518 | - } else { |
|
| 519 | - if ($add_error) { |
|
| 520 | - EE_Error::add_error( |
|
| 521 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
| 522 | - __FILE__, |
|
| 523 | - __FUNCTION__, |
|
| 524 | - __LINE__ |
|
| 525 | - ); |
|
| 526 | - } |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * _verify_config_params |
|
| 535 | - * |
|
| 536 | - * @access private |
|
| 537 | - * @param string $section |
|
| 538 | - * @param string $name |
|
| 539 | - * @param string $config_class |
|
| 540 | - * @param EE_Config_Base $config_obj |
|
| 541 | - * @param array $tests_to_run |
|
| 542 | - * @param bool $display_errors |
|
| 543 | - * @return bool TRUE on success, FALSE on fail |
|
| 544 | - */ |
|
| 545 | - private function _verify_config_params( |
|
| 546 | - $section = '', |
|
| 547 | - $name = '', |
|
| 548 | - $config_class = '', |
|
| 549 | - $config_obj = null, |
|
| 550 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
| 551 | - $display_errors = true |
|
| 552 | - ) { |
|
| 553 | - try { |
|
| 554 | - foreach ($tests_to_run as $test) { |
|
| 555 | - switch ($test) { |
|
| 556 | - // TEST #1 : check that section was set |
|
| 557 | - case 1 : |
|
| 558 | - if (empty($section)) { |
|
| 559 | - if ($display_errors) { |
|
| 560 | - throw new EE_Error( |
|
| 561 | - sprintf( |
|
| 562 | - __( |
|
| 563 | - 'No configuration section has been provided while attempting to save "%s".', |
|
| 564 | - 'event_espresso' |
|
| 565 | - ), |
|
| 566 | - $config_class |
|
| 567 | - ) |
|
| 568 | - ); |
|
| 569 | - } |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - break; |
|
| 573 | - // TEST #2 : check that settings section exists |
|
| 574 | - case 2 : |
|
| 575 | - if (! isset($this->{$section})) { |
|
| 576 | - if ($display_errors) { |
|
| 577 | - throw new EE_Error( |
|
| 578 | - sprintf( |
|
| 579 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
| 580 | - $section |
|
| 581 | - ) |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - return false; |
|
| 585 | - } |
|
| 586 | - break; |
|
| 587 | - // TEST #3 : check that section is the proper format |
|
| 588 | - case 3 : |
|
| 589 | - if ( |
|
| 590 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
| 591 | - ) { |
|
| 592 | - if ($display_errors) { |
|
| 593 | - throw new EE_Error( |
|
| 594 | - sprintf( |
|
| 595 | - __( |
|
| 596 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
| 597 | - 'event_espresso' |
|
| 598 | - ), |
|
| 599 | - $section |
|
| 600 | - ) |
|
| 601 | - ); |
|
| 602 | - } |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - break; |
|
| 606 | - // TEST #4 : check that config section name has been set |
|
| 607 | - case 4 : |
|
| 608 | - if (empty($name)) { |
|
| 609 | - if ($display_errors) { |
|
| 610 | - throw new EE_Error( |
|
| 611 | - __( |
|
| 612 | - 'No name has been provided for the specific configuration section.', |
|
| 613 | - 'event_espresso' |
|
| 614 | - ) |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - return false; |
|
| 618 | - } |
|
| 619 | - break; |
|
| 620 | - // TEST #5 : check that a config class name has been set |
|
| 621 | - case 5 : |
|
| 622 | - if (empty($config_class)) { |
|
| 623 | - if ($display_errors) { |
|
| 624 | - throw new EE_Error( |
|
| 625 | - __( |
|
| 626 | - 'No class name has been provided for the specific configuration section.', |
|
| 627 | - 'event_espresso' |
|
| 628 | - ) |
|
| 629 | - ); |
|
| 630 | - } |
|
| 631 | - return false; |
|
| 632 | - } |
|
| 633 | - break; |
|
| 634 | - // TEST #6 : verify config class is accessible |
|
| 635 | - case 6 : |
|
| 636 | - if (! class_exists($config_class)) { |
|
| 637 | - if ($display_errors) { |
|
| 638 | - throw new EE_Error( |
|
| 639 | - sprintf( |
|
| 640 | - __( |
|
| 641 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
| 642 | - 'event_espresso' |
|
| 643 | - ), |
|
| 644 | - $config_class |
|
| 645 | - ) |
|
| 646 | - ); |
|
| 647 | - } |
|
| 648 | - return false; |
|
| 649 | - } |
|
| 650 | - break; |
|
| 651 | - // TEST #7 : check that config has even been set |
|
| 652 | - case 7 : |
|
| 653 | - if (! isset($this->{$section}->{$name})) { |
|
| 654 | - if ($display_errors) { |
|
| 655 | - throw new EE_Error( |
|
| 656 | - sprintf( |
|
| 657 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
| 658 | - $section, |
|
| 659 | - $name |
|
| 660 | - ) |
|
| 661 | - ); |
|
| 662 | - } |
|
| 663 | - return false; |
|
| 664 | - } else { |
|
| 665 | - // and make sure it's not serialized |
|
| 666 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
| 667 | - } |
|
| 668 | - break; |
|
| 669 | - // TEST #8 : check that config is the requested type |
|
| 670 | - case 8 : |
|
| 671 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 672 | - if ($display_errors) { |
|
| 673 | - throw new EE_Error( |
|
| 674 | - sprintf( |
|
| 675 | - __( |
|
| 676 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
| 677 | - 'event_espresso' |
|
| 678 | - ), |
|
| 679 | - $section, |
|
| 680 | - $name, |
|
| 681 | - $config_class |
|
| 682 | - ) |
|
| 683 | - ); |
|
| 684 | - } |
|
| 685 | - return false; |
|
| 686 | - } |
|
| 687 | - break; |
|
| 688 | - // TEST #9 : verify config object |
|
| 689 | - case 9 : |
|
| 690 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 691 | - if ($display_errors) { |
|
| 692 | - throw new EE_Error( |
|
| 693 | - sprintf( |
|
| 694 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
| 695 | - print_r($config_obj, true) |
|
| 696 | - ) |
|
| 697 | - ); |
|
| 698 | - } |
|
| 699 | - return false; |
|
| 700 | - } |
|
| 701 | - break; |
|
| 702 | - } |
|
| 703 | - } |
|
| 704 | - } catch (EE_Error $e) { |
|
| 705 | - $e->get_error(); |
|
| 706 | - } |
|
| 707 | - // you have successfully run the gauntlet |
|
| 708 | - return true; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * _generate_config_option_name |
|
| 715 | - * |
|
| 716 | - * @access protected |
|
| 717 | - * @param string $section |
|
| 718 | - * @param string $name |
|
| 719 | - * @return string |
|
| 720 | - */ |
|
| 721 | - private function _generate_config_option_name($section = '', $name = '') |
|
| 722 | - { |
|
| 723 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * _set_config_class |
|
| 730 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
| 731 | - * |
|
| 732 | - * @access private |
|
| 733 | - * @param string $config_class |
|
| 734 | - * @param string $name |
|
| 735 | - * @return string |
|
| 736 | - */ |
|
| 737 | - private function _set_config_class($config_class = '', $name = '') |
|
| 738 | - { |
|
| 739 | - return ! empty($config_class) |
|
| 740 | - ? $config_class |
|
| 741 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * set_config |
|
| 748 | - * |
|
| 749 | - * @access protected |
|
| 750 | - * @param string $section |
|
| 751 | - * @param string $name |
|
| 752 | - * @param string $config_class |
|
| 753 | - * @param EE_Config_Base $config_obj |
|
| 754 | - * @return EE_Config_Base |
|
| 755 | - */ |
|
| 756 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
| 757 | - { |
|
| 758 | - // ensure config class is set to something |
|
| 759 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 760 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
| 761 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 762 | - return null; |
|
| 763 | - } |
|
| 764 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 765 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
| 766 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 767 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
| 768 | - $this->update_addon_option_names(); |
|
| 769 | - } |
|
| 770 | - // verify the incoming config object but suppress errors |
|
| 771 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 772 | - $config_obj = new $config_class(); |
|
| 773 | - } |
|
| 774 | - if (get_option($config_option_name)) { |
|
| 775 | - EE_Config::log($config_option_name); |
|
| 776 | - update_option($config_option_name, $config_obj); |
|
| 777 | - $this->{$section}->{$name} = $config_obj; |
|
| 778 | - return $this->{$section}->{$name}; |
|
| 779 | - } else { |
|
| 780 | - // create a wp-option for this config |
|
| 781 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
| 782 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
| 783 | - return $this->{$section}->{$name}; |
|
| 784 | - } else { |
|
| 785 | - EE_Error::add_error( |
|
| 786 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
| 787 | - __FILE__, |
|
| 788 | - __FUNCTION__, |
|
| 789 | - __LINE__ |
|
| 790 | - ); |
|
| 791 | - return null; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * update_config |
|
| 800 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
| 801 | - * |
|
| 802 | - * @access public |
|
| 803 | - * @param string $section |
|
| 804 | - * @param string $name |
|
| 805 | - * @param EE_Config_Base|string $config_obj |
|
| 806 | - * @param bool $throw_errors |
|
| 807 | - * @return bool |
|
| 808 | - */ |
|
| 809 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
| 810 | - { |
|
| 811 | - // don't allow config updates during WP heartbeats |
|
| 812 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
| 813 | - return false; |
|
| 814 | - } |
|
| 815 | - $config_obj = maybe_unserialize($config_obj); |
|
| 816 | - // get class name of the incoming object |
|
| 817 | - $config_class = get_class($config_obj); |
|
| 818 | - // run tests 1-5 and 9 to verify config |
|
| 819 | - if (! $this->_verify_config_params( |
|
| 820 | - $section, |
|
| 821 | - $name, |
|
| 822 | - $config_class, |
|
| 823 | - $config_obj, |
|
| 824 | - array(1, 2, 3, 4, 7, 9) |
|
| 825 | - ) |
|
| 826 | - ) { |
|
| 827 | - return false; |
|
| 828 | - } |
|
| 829 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
| 830 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
| 831 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 832 | - // save new config to db |
|
| 833 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
| 834 | - return true; |
|
| 835 | - } |
|
| 836 | - } else { |
|
| 837 | - // first check if the record already exists |
|
| 838 | - $existing_config = get_option($config_option_name); |
|
| 839 | - $config_obj = serialize($config_obj); |
|
| 840 | - // just return if db record is already up to date (NOT type safe comparison) |
|
| 841 | - if ($existing_config == $config_obj) { |
|
| 842 | - $this->{$section}->{$name} = $config_obj; |
|
| 843 | - return true; |
|
| 844 | - } else if (update_option($config_option_name, $config_obj)) { |
|
| 845 | - EE_Config::log($config_option_name); |
|
| 846 | - // update wp-option for this config class |
|
| 847 | - $this->{$section}->{$name} = $config_obj; |
|
| 848 | - return true; |
|
| 849 | - } elseif ($throw_errors) { |
|
| 850 | - EE_Error::add_error( |
|
| 851 | - sprintf( |
|
| 852 | - __( |
|
| 853 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
| 854 | - 'event_espresso' |
|
| 855 | - ), |
|
| 856 | - $config_class, |
|
| 857 | - 'EE_Config->' . $section . '->' . $name |
|
| 858 | - ), |
|
| 859 | - __FILE__, |
|
| 860 | - __FUNCTION__, |
|
| 861 | - __LINE__ |
|
| 862 | - ); |
|
| 863 | - } |
|
| 864 | - } |
|
| 865 | - return false; |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * get_config |
|
| 872 | - * |
|
| 873 | - * @access public |
|
| 874 | - * @param string $section |
|
| 875 | - * @param string $name |
|
| 876 | - * @param string $config_class |
|
| 877 | - * @return mixed EE_Config_Base | NULL |
|
| 878 | - */ |
|
| 879 | - public function get_config($section = '', $name = '', $config_class = '') |
|
| 880 | - { |
|
| 881 | - // ensure config class is set to something |
|
| 882 | - $config_class = $this->_set_config_class($config_class, $name); |
|
| 883 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
| 884 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 885 | - return null; |
|
| 886 | - } |
|
| 887 | - // now test if the requested config object exists, but suppress errors |
|
| 888 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
| 889 | - // config already exists, so pass it back |
|
| 890 | - return $this->{$section}->{$name}; |
|
| 891 | - } |
|
| 892 | - // load config option from db if it exists |
|
| 893 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
| 894 | - // verify the newly retrieved config object, but suppress errors |
|
| 895 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 896 | - // config is good, so set it and pass it back |
|
| 897 | - $this->{$section}->{$name} = $config_obj; |
|
| 898 | - return $this->{$section}->{$name}; |
|
| 899 | - } |
|
| 900 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
| 901 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
| 902 | - // verify the newly created config object |
|
| 903 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
| 904 | - return $this->{$section}->{$name}; |
|
| 905 | - } else { |
|
| 906 | - EE_Error::add_error( |
|
| 907 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
| 908 | - __FILE__, |
|
| 909 | - __FUNCTION__, |
|
| 910 | - __LINE__ |
|
| 911 | - ); |
|
| 912 | - } |
|
| 913 | - return null; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * get_config_option |
|
| 920 | - * |
|
| 921 | - * @access public |
|
| 922 | - * @param string $config_option_name |
|
| 923 | - * @return mixed EE_Config_Base | FALSE |
|
| 924 | - */ |
|
| 925 | - public function get_config_option($config_option_name = '') |
|
| 926 | - { |
|
| 927 | - // retrieve the wp-option for this config class. |
|
| 928 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
| 929 | - if (empty($config_option)) { |
|
| 930 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 931 | - } |
|
| 932 | - return $config_option; |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - /** |
|
| 938 | - * log |
|
| 939 | - * |
|
| 940 | - * @param string $config_option_name |
|
| 941 | - */ |
|
| 942 | - public static function log($config_option_name = '') |
|
| 943 | - { |
|
| 944 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
| 945 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
| 946 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
| 947 | - $_request = $_REQUEST; |
|
| 948 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
| 949 | - $config_log[(string)microtime(true)] = array( |
|
| 950 | - 'config_name' => $config_option_name, |
|
| 951 | - 'request' => $_request, |
|
| 952 | - ); |
|
| 953 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 954 | - } |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * trim_log |
|
| 961 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
| 962 | - */ |
|
| 963 | - public static function trim_log() |
|
| 964 | - { |
|
| 965 | - if (! EE_Config::logging_enabled()) { |
|
| 966 | - return; |
|
| 967 | - } |
|
| 968 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
| 969 | - $log_length = count($config_log); |
|
| 970 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
| 971 | - ksort($config_log); |
|
| 972 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
| 973 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
| 974 | - } |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * get_page_for_posts |
|
| 981 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
| 982 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
| 983 | - * |
|
| 984 | - * @access public |
|
| 985 | - * @return string |
|
| 986 | - */ |
|
| 987 | - public static function get_page_for_posts() |
|
| 988 | - { |
|
| 989 | - $page_for_posts = get_option('page_for_posts'); |
|
| 990 | - if (! $page_for_posts) { |
|
| 991 | - return 'posts'; |
|
| 992 | - } |
|
| 993 | - /** @type WPDB $wpdb */ |
|
| 994 | - global $wpdb; |
|
| 995 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
| 996 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * register_shortcodes_and_modules. |
|
| 1003 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
| 1004 | - * In fact, this is where we give modules a chance to let core know they exist |
|
| 1005 | - * so they can help trigger maintenance mode if it's needed |
|
| 1006 | - * |
|
| 1007 | - * @access public |
|
| 1008 | - * @return void |
|
| 1009 | - */ |
|
| 1010 | - public function register_shortcodes_and_modules() |
|
| 1011 | - { |
|
| 1012 | - // allow modules to set hooks for the rest of the system |
|
| 1013 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * initialize_shortcodes_and_modules |
|
| 1020 | - * meaning they can start adding their hooks to get stuff done |
|
| 1021 | - * |
|
| 1022 | - * @access public |
|
| 1023 | - * @return void |
|
| 1024 | - */ |
|
| 1025 | - public function initialize_shortcodes_and_modules() |
|
| 1026 | - { |
|
| 1027 | - // allow modules to set hooks for the rest of the system |
|
| 1028 | - $this->_initialize_modules(); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * widgets_init |
|
| 1035 | - * |
|
| 1036 | - * @access private |
|
| 1037 | - * @return void |
|
| 1038 | - */ |
|
| 1039 | - public function widgets_init() |
|
| 1040 | - { |
|
| 1041 | - //only init widgets on admin pages when not in complete maintenance, and |
|
| 1042 | - //on frontend when not in any maintenance mode |
|
| 1043 | - if ( |
|
| 1044 | - ! EE_Maintenance_Mode::instance()->level() |
|
| 1045 | - || ( |
|
| 1046 | - is_admin() |
|
| 1047 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
| 1048 | - ) |
|
| 1049 | - ) { |
|
| 1050 | - // grab list of installed widgets |
|
| 1051 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1052 | - // filter list of modules to register |
|
| 1053 | - $widgets_to_register = apply_filters( |
|
| 1054 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
| 1055 | - $widgets_to_register |
|
| 1056 | - ); |
|
| 1057 | - if (! empty($widgets_to_register)) { |
|
| 1058 | - // cycle thru widget folders |
|
| 1059 | - foreach ($widgets_to_register as $widget_path) { |
|
| 1060 | - // add to list of installed widget modules |
|
| 1061 | - EE_Config::register_ee_widget($widget_path); |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - // filter list of installed modules |
|
| 1065 | - EE_Registry::instance()->widgets = apply_filters( |
|
| 1066 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
| 1067 | - EE_Registry::instance()->widgets |
|
| 1068 | - ); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - |
|
| 1073 | - |
|
| 1074 | - /** |
|
| 1075 | - * register_ee_widget - makes core aware of this widget |
|
| 1076 | - * |
|
| 1077 | - * @access public |
|
| 1078 | - * @param string $widget_path - full path up to and including widget folder |
|
| 1079 | - * @return void |
|
| 1080 | - */ |
|
| 1081 | - public static function register_ee_widget($widget_path = null) |
|
| 1082 | - { |
|
| 1083 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
| 1084 | - $widget_ext = '.widget.php'; |
|
| 1085 | - // make all separators match |
|
| 1086 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
| 1087 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1088 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
| 1089 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1090 | - $file_name = explode('.', basename($widget_path)); |
|
| 1091 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 1092 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
| 1093 | - // sanitize shortcode directory name |
|
| 1094 | - $widget = sanitize_key($widget); |
|
| 1095 | - // now we need to rebuild the shortcode path |
|
| 1096 | - $widget_path = explode(DS, $widget_path); |
|
| 1097 | - // remove last segment |
|
| 1098 | - array_pop($widget_path); |
|
| 1099 | - // glue it back together |
|
| 1100 | - $widget_path = implode(DS, $widget_path); |
|
| 1101 | - } else { |
|
| 1102 | - // grab and sanitize widget directory name |
|
| 1103 | - $widget = sanitize_key(basename($widget_path)); |
|
| 1104 | - } |
|
| 1105 | - // create classname from widget directory name |
|
| 1106 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
| 1107 | - // add class prefix |
|
| 1108 | - $widget_class = 'EEW_' . $widget; |
|
| 1109 | - // does the widget exist ? |
|
| 1110 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1111 | - $msg = sprintf( |
|
| 1112 | - __( |
|
| 1113 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
| 1114 | - 'event_espresso' |
|
| 1115 | - ), |
|
| 1116 | - $widget_class, |
|
| 1117 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1118 | - ); |
|
| 1119 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1120 | - return; |
|
| 1121 | - } |
|
| 1122 | - // load the widget class file |
|
| 1123 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1124 | - // verify that class exists |
|
| 1125 | - if (! class_exists($widget_class)) { |
|
| 1126 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
| 1127 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1128 | - return; |
|
| 1129 | - } |
|
| 1130 | - register_widget($widget_class); |
|
| 1131 | - // add to array of registered widgets |
|
| 1132 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * _register_modules |
|
| 1139 | - * |
|
| 1140 | - * @access private |
|
| 1141 | - * @return array |
|
| 1142 | - */ |
|
| 1143 | - private function _register_modules() |
|
| 1144 | - { |
|
| 1145 | - // grab list of installed modules |
|
| 1146 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1147 | - // filter list of modules to register |
|
| 1148 | - $modules_to_register = apply_filters( |
|
| 1149 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
| 1150 | - $modules_to_register |
|
| 1151 | - ); |
|
| 1152 | - if (! empty($modules_to_register)) { |
|
| 1153 | - // loop through folders |
|
| 1154 | - foreach ($modules_to_register as $module_path) { |
|
| 1155 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
| 1156 | - if ( |
|
| 1157 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1158 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1159 | - ) { |
|
| 1160 | - // add to list of installed modules |
|
| 1161 | - EE_Config::register_module($module_path); |
|
| 1162 | - } |
|
| 1163 | - } |
|
| 1164 | - } |
|
| 1165 | - // filter list of installed modules |
|
| 1166 | - return apply_filters( |
|
| 1167 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
| 1168 | - EE_Registry::instance()->modules |
|
| 1169 | - ); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * register_module - makes core aware of this module |
|
| 1176 | - * |
|
| 1177 | - * @access public |
|
| 1178 | - * @param string $module_path - full path up to and including module folder |
|
| 1179 | - * @return bool |
|
| 1180 | - */ |
|
| 1181 | - public static function register_module($module_path = null) |
|
| 1182 | - { |
|
| 1183 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
| 1184 | - $module_ext = '.module.php'; |
|
| 1185 | - // make all separators match |
|
| 1186 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
| 1187 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 1188 | - if (strpos($module_path, $module_ext) !== false) { |
|
| 1189 | - // grab and shortcode file name from directory name and break apart at dots |
|
| 1190 | - $module_file = explode('.', basename($module_path)); |
|
| 1191 | - // now we need to rebuild the shortcode path |
|
| 1192 | - $module_path = explode(DS, $module_path); |
|
| 1193 | - // remove last segment |
|
| 1194 | - array_pop($module_path); |
|
| 1195 | - // glue it back together |
|
| 1196 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1197 | - // take first segment from file name pieces and sanitize it |
|
| 1198 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
| 1199 | - // ensure class prefix is added |
|
| 1200 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1201 | - } else { |
|
| 1202 | - // we need to generate the filename based off of the folder name |
|
| 1203 | - // grab and sanitize module name |
|
| 1204 | - $module = strtolower(basename($module_path)); |
|
| 1205 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
| 1206 | - // like trailingslashit() |
|
| 1207 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1208 | - // create classname from module directory name |
|
| 1209 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
| 1210 | - // add class prefix |
|
| 1211 | - $module_class = 'EED_' . $module; |
|
| 1212 | - } |
|
| 1213 | - // does the module exist ? |
|
| 1214 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1215 | - $msg = sprintf( |
|
| 1216 | - __( |
|
| 1217 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
| 1218 | - 'event_espresso' |
|
| 1219 | - ), |
|
| 1220 | - $module |
|
| 1221 | - ); |
|
| 1222 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1223 | - return false; |
|
| 1224 | - } |
|
| 1225 | - // load the module class file |
|
| 1226 | - require_once($module_path . $module_class . $module_ext); |
|
| 1227 | - // verify that class exists |
|
| 1228 | - if (! class_exists($module_class)) { |
|
| 1229 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
| 1230 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | - return false; |
|
| 1232 | - } |
|
| 1233 | - // add to array of registered modules |
|
| 1234 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1235 | - do_action( |
|
| 1236 | - 'AHEE__EE_Config__register_module__complete', |
|
| 1237 | - $module_class, |
|
| 1238 | - EE_Registry::instance()->modules->{$module_class} |
|
| 1239 | - ); |
|
| 1240 | - return true; |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - |
|
| 1245 | - /** |
|
| 1246 | - * _initialize_modules |
|
| 1247 | - * allow modules to set hooks for the rest of the system |
|
| 1248 | - * |
|
| 1249 | - * @access private |
|
| 1250 | - * @return void |
|
| 1251 | - */ |
|
| 1252 | - private function _initialize_modules() |
|
| 1253 | - { |
|
| 1254 | - // cycle thru shortcode folders |
|
| 1255 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
| 1256 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 1257 | - // which set hooks ? |
|
| 1258 | - if (is_admin()) { |
|
| 1259 | - // fire immediately |
|
| 1260 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
| 1261 | - } else { |
|
| 1262 | - // delay until other systems are online |
|
| 1263 | - add_action( |
|
| 1264 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 1265 | - array($module_class, 'set_hooks') |
|
| 1266 | - ); |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * register_route - adds module method routes to route_map |
|
| 1275 | - * |
|
| 1276 | - * @access public |
|
| 1277 | - * @param string $route - "pretty" public alias for module method |
|
| 1278 | - * @param string $module - module name (classname without EED_ prefix) |
|
| 1279 | - * @param string $method_name - the actual module method to be routed to |
|
| 1280 | - * @param string $key - url param key indicating a route is being called |
|
| 1281 | - * @return bool |
|
| 1282 | - */ |
|
| 1283 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
| 1284 | - { |
|
| 1285 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
| 1286 | - $module = str_replace('EED_', '', $module); |
|
| 1287 | - $module_class = 'EED_' . $module; |
|
| 1288 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1289 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
| 1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | - return false; |
|
| 1292 | - } |
|
| 1293 | - if (empty($route)) { |
|
| 1294 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
| 1295 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1296 | - return false; |
|
| 1297 | - } |
|
| 1298 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1299 | - $msg = sprintf( |
|
| 1300 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
| 1301 | - $route |
|
| 1302 | - ); |
|
| 1303 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1304 | - return false; |
|
| 1305 | - } |
|
| 1306 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1307 | - return true; |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - |
|
| 1311 | - |
|
| 1312 | - /** |
|
| 1313 | - * get_route - get module method route |
|
| 1314 | - * |
|
| 1315 | - * @access public |
|
| 1316 | - * @param string $route - "pretty" public alias for module method |
|
| 1317 | - * @param string $key - url param key indicating a route is being called |
|
| 1318 | - * @return string |
|
| 1319 | - */ |
|
| 1320 | - public static function get_route($route = null, $key = 'ee') |
|
| 1321 | - { |
|
| 1322 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
| 1323 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1324 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
| 1325 | - return EE_Config::$_module_route_map[$key][$route]; |
|
| 1326 | - } |
|
| 1327 | - return null; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - |
|
| 1331 | - |
|
| 1332 | - /** |
|
| 1333 | - * get_routes - get ALL module method routes |
|
| 1334 | - * |
|
| 1335 | - * @access public |
|
| 1336 | - * @return array |
|
| 1337 | - */ |
|
| 1338 | - public static function get_routes() |
|
| 1339 | - { |
|
| 1340 | - return EE_Config::$_module_route_map; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - |
|
| 1344 | - |
|
| 1345 | - /** |
|
| 1346 | - * register_forward - allows modules to forward request to another module for further processing |
|
| 1347 | - * |
|
| 1348 | - * @access public |
|
| 1349 | - * @param string $route - "pretty" public alias for module method |
|
| 1350 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
| 1351 | - * class, allows different forwards to be served based on status |
|
| 1352 | - * @param array|string $forward - function name or array( class, method ) |
|
| 1353 | - * @param string $key - url param key indicating a route is being called |
|
| 1354 | - * @return bool |
|
| 1355 | - */ |
|
| 1356 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
| 1357 | - { |
|
| 1358 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
| 1359 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1360 | - $msg = sprintf( |
|
| 1361 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
| 1362 | - $route |
|
| 1363 | - ); |
|
| 1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | - return false; |
|
| 1366 | - } |
|
| 1367 | - if (empty($forward)) { |
|
| 1368 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
| 1369 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | - return false; |
|
| 1371 | - } |
|
| 1372 | - if (is_array($forward)) { |
|
| 1373 | - if (! isset($forward[1])) { |
|
| 1374 | - $msg = sprintf( |
|
| 1375 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
| 1376 | - $route |
|
| 1377 | - ); |
|
| 1378 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | - return false; |
|
| 1380 | - } |
|
| 1381 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1382 | - $msg = sprintf( |
|
| 1383 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1384 | - $forward[1], |
|
| 1385 | - $route |
|
| 1386 | - ); |
|
| 1387 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | - return false; |
|
| 1389 | - } |
|
| 1390 | - } else if (! function_exists($forward)) { |
|
| 1391 | - $msg = sprintf( |
|
| 1392 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
| 1393 | - $forward, |
|
| 1394 | - $route |
|
| 1395 | - ); |
|
| 1396 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1397 | - return false; |
|
| 1398 | - } |
|
| 1399 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
| 1400 | - return true; |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - |
|
| 1404 | - |
|
| 1405 | - /** |
|
| 1406 | - * get_forward - get forwarding route |
|
| 1407 | - * |
|
| 1408 | - * @access public |
|
| 1409 | - * @param string $route - "pretty" public alias for module method |
|
| 1410 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1411 | - * allows different forwards to be served based on status |
|
| 1412 | - * @param string $key - url param key indicating a route is being called |
|
| 1413 | - * @return string |
|
| 1414 | - */ |
|
| 1415 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
| 1416 | - { |
|
| 1417 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
| 1418 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
| 1419 | - return apply_filters( |
|
| 1420 | - 'FHEE__EE_Config__get_forward', |
|
| 1421 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
| 1422 | - $route, |
|
| 1423 | - $status |
|
| 1424 | - ); |
|
| 1425 | - } |
|
| 1426 | - return null; |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - |
|
| 1430 | - |
|
| 1431 | - /** |
|
| 1432 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
| 1433 | - * results |
|
| 1434 | - * |
|
| 1435 | - * @access public |
|
| 1436 | - * @param string $route - "pretty" public alias for module method |
|
| 1437 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1438 | - * allows different views to be served based on status |
|
| 1439 | - * @param string $view |
|
| 1440 | - * @param string $key - url param key indicating a route is being called |
|
| 1441 | - * @return bool |
|
| 1442 | - */ |
|
| 1443 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
| 1444 | - { |
|
| 1445 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
| 1446 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1447 | - $msg = sprintf( |
|
| 1448 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
| 1449 | - $route |
|
| 1450 | - ); |
|
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | - return false; |
|
| 1453 | - } |
|
| 1454 | - if (! is_readable($view)) { |
|
| 1455 | - $msg = sprintf( |
|
| 1456 | - __( |
|
| 1457 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
| 1458 | - 'event_espresso' |
|
| 1459 | - ), |
|
| 1460 | - $view |
|
| 1461 | - ); |
|
| 1462 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1463 | - return false; |
|
| 1464 | - } |
|
| 1465 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
| 1466 | - return true; |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - |
|
| 1470 | - |
|
| 1471 | - /** |
|
| 1472 | - * get_view - get view for route and status |
|
| 1473 | - * |
|
| 1474 | - * @access public |
|
| 1475 | - * @param string $route - "pretty" public alias for module method |
|
| 1476 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
| 1477 | - * allows different views to be served based on status |
|
| 1478 | - * @param string $key - url param key indicating a route is being called |
|
| 1479 | - * @return string |
|
| 1480 | - */ |
|
| 1481 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
| 1482 | - { |
|
| 1483 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
| 1484 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
| 1485 | - return apply_filters( |
|
| 1486 | - 'FHEE__EE_Config__get_view', |
|
| 1487 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
| 1488 | - $route, |
|
| 1489 | - $status |
|
| 1490 | - ); |
|
| 1491 | - } |
|
| 1492 | - return null; |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - |
|
| 1496 | - |
|
| 1497 | - public function update_addon_option_names() |
|
| 1498 | - { |
|
| 1499 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - |
|
| 1504 | - public function shutdown() |
|
| 1505 | - { |
|
| 1506 | - $this->update_addon_option_names(); |
|
| 1507 | - } |
|
| 1508 | - |
|
| 1509 | - |
|
| 1510 | - |
|
| 1511 | - /** |
|
| 1512 | - * @return LegacyShortcodesManager |
|
| 1513 | - */ |
|
| 1514 | - public static function getLegacyShortcodesManager() |
|
| 1515 | - { |
|
| 1516 | - |
|
| 1517 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
| 1518 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
| 1519 | - EE_Registry::instance() |
|
| 1520 | - ); |
|
| 1521 | - } |
|
| 1522 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * register_shortcode - makes core aware of this shortcode |
|
| 1529 | - * |
|
| 1530 | - * @deprecated 4.9.26 |
|
| 1531 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 1532 | - * @return bool |
|
| 1533 | - */ |
|
| 1534 | - public static function register_shortcode($shortcode_path = null) |
|
| 1535 | - { |
|
| 1536 | - EE_Error::doing_it_wrong( |
|
| 1537 | - __METHOD__, |
|
| 1538 | - __( |
|
| 1539 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
| 1540 | - 'event_espresso' |
|
| 1541 | - ), |
|
| 1542 | - '4.9.26' |
|
| 1543 | - ); |
|
| 1544 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | - |
|
| 1549 | -} |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - |
|
| 1553 | -/** |
|
| 1554 | - * Base class used for config classes. These classes should generally not have |
|
| 1555 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1556 | - * basically, they should just be well-defined stdClasses |
|
| 1557 | - */ |
|
| 1558 | -class EE_Config_Base |
|
| 1559 | -{ |
|
| 1560 | - |
|
| 1561 | - /** |
|
| 1562 | - * Utility function for escaping the value of a property and returning. |
|
| 1563 | - * |
|
| 1564 | - * @param string $property property name (checks to see if exists). |
|
| 1565 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1566 | - * @throws EE_Error |
|
| 1567 | - */ |
|
| 1568 | - public function get_pretty($property) |
|
| 1569 | - { |
|
| 1570 | - if (! property_exists($this, $property)) { |
|
| 1571 | - throw new EE_Error( |
|
| 1572 | - sprintf( |
|
| 1573 | - __( |
|
| 1574 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1575 | - 'event_espresso' |
|
| 1576 | - ), |
|
| 1577 | - get_class($this), |
|
| 1578 | - $property |
|
| 1579 | - ) |
|
| 1580 | - ); |
|
| 1581 | - } |
|
| 1582 | - //just handling escaping of strings for now. |
|
| 1583 | - if (is_string($this->{$property})) { |
|
| 1584 | - return stripslashes($this->{$property}); |
|
| 1585 | - } |
|
| 1586 | - return $this->{$property}; |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - |
|
| 1590 | - |
|
| 1591 | - public function populate() |
|
| 1592 | - { |
|
| 1593 | - //grab defaults via a new instance of this class. |
|
| 1594 | - $class_name = get_class($this); |
|
| 1595 | - $defaults = new $class_name; |
|
| 1596 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1597 | - //default from our $defaults object. |
|
| 1598 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1599 | - if ($this->{$property} === null) { |
|
| 1600 | - $this->{$property} = $value; |
|
| 1601 | - } |
|
| 1602 | - } |
|
| 1603 | - //cleanup |
|
| 1604 | - unset($defaults); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - |
|
| 1609 | - /** |
|
| 1610 | - * __isset |
|
| 1611 | - * |
|
| 1612 | - * @param $a |
|
| 1613 | - * @return bool |
|
| 1614 | - */ |
|
| 1615 | - public function __isset($a) |
|
| 1616 | - { |
|
| 1617 | - return false; |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - |
|
| 1621 | - |
|
| 1622 | - /** |
|
| 1623 | - * __unset |
|
| 1624 | - * |
|
| 1625 | - * @param $a |
|
| 1626 | - * @return bool |
|
| 1627 | - */ |
|
| 1628 | - public function __unset($a) |
|
| 1629 | - { |
|
| 1630 | - return false; |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - |
|
| 1635 | - /** |
|
| 1636 | - * __clone |
|
| 1637 | - */ |
|
| 1638 | - public function __clone() |
|
| 1639 | - { |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - |
|
| 1643 | - |
|
| 1644 | - /** |
|
| 1645 | - * __wakeup |
|
| 1646 | - */ |
|
| 1647 | - public function __wakeup() |
|
| 1648 | - { |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - |
|
| 1652 | - |
|
| 1653 | - /** |
|
| 1654 | - * __destruct |
|
| 1655 | - */ |
|
| 1656 | - public function __destruct() |
|
| 1657 | - { |
|
| 1658 | - } |
|
| 1659 | -} |
|
| 1660 | - |
|
| 1661 | - |
|
| 1662 | - |
|
| 1663 | -/** |
|
| 1664 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 1665 | - */ |
|
| 1666 | -class EE_Core_Config extends EE_Config_Base |
|
| 1667 | -{ |
|
| 1668 | - |
|
| 1669 | - public $current_blog_id; |
|
| 1670 | - |
|
| 1671 | - public $ee_ueip_optin; |
|
| 1672 | - |
|
| 1673 | - public $ee_ueip_has_notified; |
|
| 1674 | - |
|
| 1675 | - /** |
|
| 1676 | - * Not to be confused with the 4 critical page variables (See |
|
| 1677 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1678 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1679 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1680 | - * |
|
| 1681 | - * @var array |
|
| 1682 | - */ |
|
| 1683 | - public $post_shortcodes; |
|
| 1684 | - |
|
| 1685 | - public $module_route_map; |
|
| 1686 | - |
|
| 1687 | - public $module_forward_map; |
|
| 1688 | - |
|
| 1689 | - public $module_view_map; |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * The next 4 vars are the IDs of critical EE pages. |
|
| 1693 | - * |
|
| 1694 | - * @var int |
|
| 1695 | - */ |
|
| 1696 | - public $reg_page_id; |
|
| 1697 | - |
|
| 1698 | - public $txn_page_id; |
|
| 1699 | - |
|
| 1700 | - public $thank_you_page_id; |
|
| 1701 | - |
|
| 1702 | - public $cancel_page_id; |
|
| 1703 | - |
|
| 1704 | - /** |
|
| 1705 | - * The next 4 vars are the URLs of critical EE pages. |
|
| 1706 | - * |
|
| 1707 | - * @var int |
|
| 1708 | - */ |
|
| 1709 | - public $reg_page_url; |
|
| 1710 | - |
|
| 1711 | - public $txn_page_url; |
|
| 1712 | - |
|
| 1713 | - public $thank_you_page_url; |
|
| 1714 | - |
|
| 1715 | - public $cancel_page_url; |
|
| 1716 | - |
|
| 1717 | - /** |
|
| 1718 | - * The next vars relate to the custom slugs for EE CPT routes |
|
| 1719 | - */ |
|
| 1720 | - public $event_cpt_slug; |
|
| 1721 | - |
|
| 1722 | - |
|
| 1723 | - /** |
|
| 1724 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1725 | - * request across blog switches in a multisite context. |
|
| 1726 | - * Avoids extra queries to the db for this option. |
|
| 1727 | - * |
|
| 1728 | - * @var bool |
|
| 1729 | - */ |
|
| 1730 | - public static $ee_ueip_option; |
|
| 1731 | - |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * class constructor |
|
| 1736 | - * |
|
| 1737 | - * @access public |
|
| 1738 | - */ |
|
| 1739 | - public function __construct() |
|
| 1740 | - { |
|
| 1741 | - // set default organization settings |
|
| 1742 | - $this->current_blog_id = get_current_blog_id(); |
|
| 1743 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1744 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1745 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1746 | - $this->post_shortcodes = array(); |
|
| 1747 | - $this->module_route_map = array(); |
|
| 1748 | - $this->module_forward_map = array(); |
|
| 1749 | - $this->module_view_map = array(); |
|
| 1750 | - // critical EE page IDs |
|
| 1751 | - $this->reg_page_id = 0; |
|
| 1752 | - $this->txn_page_id = 0; |
|
| 1753 | - $this->thank_you_page_id = 0; |
|
| 1754 | - $this->cancel_page_id = 0; |
|
| 1755 | - // critical EE page URLs |
|
| 1756 | - $this->reg_page_url = ''; |
|
| 1757 | - $this->txn_page_url = ''; |
|
| 1758 | - $this->thank_you_page_url = ''; |
|
| 1759 | - $this->cancel_page_url = ''; |
|
| 1760 | - //cpt slugs |
|
| 1761 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1762 | - //ueip constant check |
|
| 1763 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1764 | - $this->ee_ueip_optin = false; |
|
| 1765 | - $this->ee_ueip_has_notified = true; |
|
| 1766 | - } |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - |
|
| 1770 | - |
|
| 1771 | - /** |
|
| 1772 | - * @return array |
|
| 1773 | - */ |
|
| 1774 | - public function get_critical_pages_array() |
|
| 1775 | - { |
|
| 1776 | - return array( |
|
| 1777 | - $this->reg_page_id, |
|
| 1778 | - $this->txn_page_id, |
|
| 1779 | - $this->thank_you_page_id, |
|
| 1780 | - $this->cancel_page_id, |
|
| 1781 | - ); |
|
| 1782 | - } |
|
| 1783 | - |
|
| 1784 | - |
|
| 1785 | - |
|
| 1786 | - /** |
|
| 1787 | - * @return array |
|
| 1788 | - */ |
|
| 1789 | - public function get_critical_pages_shortcodes_array() |
|
| 1790 | - { |
|
| 1791 | - return array( |
|
| 1792 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1793 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1794 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1795 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1796 | - ); |
|
| 1797 | - } |
|
| 1798 | - |
|
| 1799 | - |
|
| 1800 | - |
|
| 1801 | - /** |
|
| 1802 | - * gets/returns URL for EE reg_page |
|
| 1803 | - * |
|
| 1804 | - * @access public |
|
| 1805 | - * @return string |
|
| 1806 | - */ |
|
| 1807 | - public function reg_page_url() |
|
| 1808 | - { |
|
| 1809 | - if (! $this->reg_page_url) { |
|
| 1810 | - $this->reg_page_url = add_query_arg( |
|
| 1811 | - array('uts' => time()), |
|
| 1812 | - get_permalink($this->reg_page_id) |
|
| 1813 | - ) . '#checkout'; |
|
| 1814 | - } |
|
| 1815 | - return $this->reg_page_url; |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - |
|
| 1819 | - |
|
| 1820 | - /** |
|
| 1821 | - * gets/returns URL for EE txn_page |
|
| 1822 | - * |
|
| 1823 | - * @param array $query_args like what gets passed to |
|
| 1824 | - * add_query_arg() as the first argument |
|
| 1825 | - * @access public |
|
| 1826 | - * @return string |
|
| 1827 | - */ |
|
| 1828 | - public function txn_page_url($query_args = array()) |
|
| 1829 | - { |
|
| 1830 | - if (! $this->txn_page_url) { |
|
| 1831 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1832 | - } |
|
| 1833 | - if ($query_args) { |
|
| 1834 | - return add_query_arg($query_args, $this->txn_page_url); |
|
| 1835 | - } else { |
|
| 1836 | - return $this->txn_page_url; |
|
| 1837 | - } |
|
| 1838 | - } |
|
| 1839 | - |
|
| 1840 | - |
|
| 1841 | - |
|
| 1842 | - /** |
|
| 1843 | - * gets/returns URL for EE thank_you_page |
|
| 1844 | - * |
|
| 1845 | - * @param array $query_args like what gets passed to |
|
| 1846 | - * add_query_arg() as the first argument |
|
| 1847 | - * @access public |
|
| 1848 | - * @return string |
|
| 1849 | - */ |
|
| 1850 | - public function thank_you_page_url($query_args = array()) |
|
| 1851 | - { |
|
| 1852 | - if (! $this->thank_you_page_url) { |
|
| 1853 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1854 | - } |
|
| 1855 | - if ($query_args) { |
|
| 1856 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1857 | - } else { |
|
| 1858 | - return $this->thank_you_page_url; |
|
| 1859 | - } |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - |
|
| 1864 | - /** |
|
| 1865 | - * gets/returns URL for EE cancel_page |
|
| 1866 | - * |
|
| 1867 | - * @access public |
|
| 1868 | - * @return string |
|
| 1869 | - */ |
|
| 1870 | - public function cancel_page_url() |
|
| 1871 | - { |
|
| 1872 | - if (! $this->cancel_page_url) { |
|
| 1873 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1874 | - } |
|
| 1875 | - return $this->cancel_page_url; |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - |
|
| 1879 | - |
|
| 1880 | - /** |
|
| 1881 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1882 | - * |
|
| 1883 | - * @since 4.7.5 |
|
| 1884 | - */ |
|
| 1885 | - protected function _reset_urls() |
|
| 1886 | - { |
|
| 1887 | - $this->reg_page_url = ''; |
|
| 1888 | - $this->txn_page_url = ''; |
|
| 1889 | - $this->cancel_page_url = ''; |
|
| 1890 | - $this->thank_you_page_url = ''; |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - |
|
| 1894 | - |
|
| 1895 | - /** |
|
| 1896 | - * Used to return what the opt-in value is set for the EE User Experience Program. |
|
| 1897 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1898 | - * on the main site only. |
|
| 1899 | - * |
|
| 1900 | - * @return mixed |
|
| 1901 | - */ |
|
| 1902 | - protected function _get_main_ee_ueip_optin() |
|
| 1903 | - { |
|
| 1904 | - //if this is the main site then we can just bypass our direct query. |
|
| 1905 | - if (is_main_site()) { |
|
| 1906 | - return get_option('ee_ueip_optin', false); |
|
| 1907 | - } |
|
| 1908 | - //is this already cached for this request? If so use it. |
|
| 1909 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1910 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1911 | - } |
|
| 1912 | - global $wpdb; |
|
| 1913 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1914 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1915 | - $option = 'ee_ueip_optin'; |
|
| 1916 | - //set correct table for query |
|
| 1917 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1918 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1919 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1920 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1921 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1922 | - //for the purpose of caching. |
|
| 1923 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1924 | - if (false !== $pre) { |
|
| 1925 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1926 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1927 | - } |
|
| 1928 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1929 | - $option)); |
|
| 1930 | - if (is_object($row)) { |
|
| 1931 | - $value = $row->option_value; |
|
| 1932 | - } else { //option does not exist so use default. |
|
| 1933 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1934 | - } |
|
| 1935 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1936 | - return EE_Core_Config::$ee_ueip_option; |
|
| 1937 | - } |
|
| 1938 | - |
|
| 1939 | - |
|
| 1940 | - |
|
| 1941 | - /** |
|
| 1942 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1943 | - * on the object. |
|
| 1944 | - * |
|
| 1945 | - * @return array |
|
| 1946 | - */ |
|
| 1947 | - public function __sleep() |
|
| 1948 | - { |
|
| 1949 | - //reset all url properties |
|
| 1950 | - $this->_reset_urls(); |
|
| 1951 | - //return what to save to db |
|
| 1952 | - return array_keys(get_object_vars($this)); |
|
| 1953 | - } |
|
| 1954 | - |
|
| 1955 | -} |
|
| 1956 | - |
|
| 1957 | - |
|
| 1958 | - |
|
| 1959 | -/** |
|
| 1960 | - * Config class for storing info on the Organization |
|
| 1961 | - */ |
|
| 1962 | -class EE_Organization_Config extends EE_Config_Base |
|
| 1963 | -{ |
|
| 1964 | - |
|
| 1965 | - /** |
|
| 1966 | - * @var string $name |
|
| 1967 | - * eg EE4.1 |
|
| 1968 | - */ |
|
| 1969 | - public $name; |
|
| 1970 | - |
|
| 1971 | - /** |
|
| 1972 | - * @var string $address_1 |
|
| 1973 | - * eg 123 Onna Road |
|
| 1974 | - */ |
|
| 1975 | - public $address_1; |
|
| 1976 | - |
|
| 1977 | - /** |
|
| 1978 | - * @var string $address_2 |
|
| 1979 | - * eg PO Box 123 |
|
| 1980 | - */ |
|
| 1981 | - public $address_2; |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * @var string $city |
|
| 1985 | - * eg Inna City |
|
| 1986 | - */ |
|
| 1987 | - public $city; |
|
| 1988 | - |
|
| 1989 | - /** |
|
| 1990 | - * @var int $STA_ID |
|
| 1991 | - * eg 4 |
|
| 1992 | - */ |
|
| 1993 | - public $STA_ID; |
|
| 1994 | - |
|
| 1995 | - /** |
|
| 1996 | - * @var string $CNT_ISO |
|
| 1997 | - * eg US |
|
| 1998 | - */ |
|
| 1999 | - public $CNT_ISO; |
|
| 2000 | - |
|
| 2001 | - /** |
|
| 2002 | - * @var string $zip |
|
| 2003 | - * eg 12345 or V1A 2B3 |
|
| 2004 | - */ |
|
| 2005 | - public $zip; |
|
| 2006 | - |
|
| 2007 | - /** |
|
| 2008 | - * @var string $email |
|
| 2009 | - * eg [email protected] |
|
| 2010 | - */ |
|
| 2011 | - public $email; |
|
| 2012 | - |
|
| 2013 | - |
|
| 2014 | - /** |
|
| 2015 | - * @var string $phone |
|
| 2016 | - * eg. 111-111-1111 |
|
| 2017 | - */ |
|
| 2018 | - public $phone; |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * @var string $vat |
|
| 2023 | - * VAT/Tax Number |
|
| 2024 | - */ |
|
| 2025 | - public $vat; |
|
| 2026 | - |
|
| 2027 | - /** |
|
| 2028 | - * @var string $logo_url |
|
| 2029 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2030 | - */ |
|
| 2031 | - public $logo_url; |
|
| 2032 | - |
|
| 2033 | - |
|
| 2034 | - /** |
|
| 2035 | - * The below are all various properties for holding links to organization social network profiles |
|
| 2036 | - * |
|
| 2037 | - * @var string |
|
| 2038 | - */ |
|
| 2039 | - /** |
|
| 2040 | - * facebook (facebook.com/profile.name) |
|
| 2041 | - * |
|
| 2042 | - * @var string |
|
| 2043 | - */ |
|
| 2044 | - public $facebook; |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - /** |
|
| 2048 | - * twitter (twitter.com/twitter_handle) |
|
| 2049 | - * |
|
| 2050 | - * @var string |
|
| 2051 | - */ |
|
| 2052 | - public $twitter; |
|
| 2053 | - |
|
| 2054 | - |
|
| 2055 | - /** |
|
| 2056 | - * linkedin (linkedin.com/in/profile_name) |
|
| 2057 | - * |
|
| 2058 | - * @var string |
|
| 2059 | - */ |
|
| 2060 | - public $linkedin; |
|
| 2061 | - |
|
| 2062 | - |
|
| 2063 | - /** |
|
| 2064 | - * pinterest (www.pinterest.com/profile_name) |
|
| 2065 | - * |
|
| 2066 | - * @var string |
|
| 2067 | - */ |
|
| 2068 | - public $pinterest; |
|
| 2069 | - |
|
| 2070 | - |
|
| 2071 | - /** |
|
| 2072 | - * google+ (google.com/+profileName) |
|
| 2073 | - * |
|
| 2074 | - * @var string |
|
| 2075 | - */ |
|
| 2076 | - public $google; |
|
| 2077 | - |
|
| 2078 | - |
|
| 2079 | - /** |
|
| 2080 | - * instagram (instagram.com/handle) |
|
| 2081 | - * |
|
| 2082 | - * @var string |
|
| 2083 | - */ |
|
| 2084 | - public $instagram; |
|
| 2085 | - |
|
| 2086 | - |
|
| 2087 | - |
|
| 2088 | - /** |
|
| 2089 | - * class constructor |
|
| 2090 | - * |
|
| 2091 | - * @access public |
|
| 2092 | - */ |
|
| 2093 | - public function __construct() |
|
| 2094 | - { |
|
| 2095 | - // set default organization settings |
|
| 2096 | - $this->name = get_bloginfo('name'); |
|
| 2097 | - $this->address_1 = '123 Onna Road'; |
|
| 2098 | - $this->address_2 = 'PO Box 123'; |
|
| 2099 | - $this->city = 'Inna City'; |
|
| 2100 | - $this->STA_ID = 4; |
|
| 2101 | - $this->CNT_ISO = 'US'; |
|
| 2102 | - $this->zip = '12345'; |
|
| 2103 | - $this->email = get_bloginfo('admin_email'); |
|
| 2104 | - $this->phone = ''; |
|
| 2105 | - $this->vat = '123456789'; |
|
| 2106 | - $this->logo_url = ''; |
|
| 2107 | - $this->facebook = ''; |
|
| 2108 | - $this->twitter = ''; |
|
| 2109 | - $this->linkedin = ''; |
|
| 2110 | - $this->pinterest = ''; |
|
| 2111 | - $this->google = ''; |
|
| 2112 | - $this->instagram = ''; |
|
| 2113 | - } |
|
| 2114 | - |
|
| 2115 | -} |
|
| 2116 | - |
|
| 2117 | - |
|
| 2118 | - |
|
| 2119 | -/** |
|
| 2120 | - * Class for defining what's in the EE_Config relating to currency |
|
| 2121 | - */ |
|
| 2122 | -class EE_Currency_Config extends EE_Config_Base |
|
| 2123 | -{ |
|
| 2124 | - |
|
| 2125 | - /** |
|
| 2126 | - * @var string $code |
|
| 2127 | - * eg 'US' |
|
| 2128 | - */ |
|
| 2129 | - public $code; |
|
| 2130 | - |
|
| 2131 | - /** |
|
| 2132 | - * @var string $name |
|
| 2133 | - * eg 'Dollar' |
|
| 2134 | - */ |
|
| 2135 | - public $name; |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * plural name |
|
| 2139 | - * |
|
| 2140 | - * @var string $plural |
|
| 2141 | - * eg 'Dollars' |
|
| 2142 | - */ |
|
| 2143 | - public $plural; |
|
| 2144 | - |
|
| 2145 | - /** |
|
| 2146 | - * currency sign |
|
| 2147 | - * |
|
| 2148 | - * @var string $sign |
|
| 2149 | - * eg '$' |
|
| 2150 | - */ |
|
| 2151 | - public $sign; |
|
| 2152 | - |
|
| 2153 | - /** |
|
| 2154 | - * Whether the currency sign should come before the number or not |
|
| 2155 | - * |
|
| 2156 | - * @var boolean $sign_b4 |
|
| 2157 | - */ |
|
| 2158 | - public $sign_b4; |
|
| 2159 | - |
|
| 2160 | - /** |
|
| 2161 | - * How many digits should come after the decimal place |
|
| 2162 | - * |
|
| 2163 | - * @var int $dec_plc |
|
| 2164 | - */ |
|
| 2165 | - public $dec_plc; |
|
| 2166 | - |
|
| 2167 | - /** |
|
| 2168 | - * Symbol to use for decimal mark |
|
| 2169 | - * |
|
| 2170 | - * @var string $dec_mrk |
|
| 2171 | - * eg '.' |
|
| 2172 | - */ |
|
| 2173 | - public $dec_mrk; |
|
| 2174 | - |
|
| 2175 | - /** |
|
| 2176 | - * Symbol to use for thousands |
|
| 2177 | - * |
|
| 2178 | - * @var string $thsnds |
|
| 2179 | - * eg ',' |
|
| 2180 | - */ |
|
| 2181 | - public $thsnds; |
|
| 2182 | - |
|
| 2183 | - |
|
| 2184 | - /** |
|
| 2185 | - * class constructor |
|
| 2186 | - * |
|
| 2187 | - * @access public |
|
| 2188 | - * @param string $CNT_ISO |
|
| 2189 | - * @param CountryCurrencyDao $country_currencies |
|
| 2190 | - * @throws EE_Error |
|
| 2191 | - * @throws InvalidArgumentException |
|
| 2192 | - * @throws ReflectionException |
|
| 2193 | - * @throws InvalidDataTypeException |
|
| 2194 | - * @throws InvalidInterfaceException |
|
| 2195 | - */ |
|
| 2196 | - public function __construct($CNT_ISO = '', CountryCurrencyDao $country_currencies = null) |
|
| 2197 | - { |
|
| 2198 | - if(! $country_currencies instanceof CountryCurrencyDao){ |
|
| 2199 | - $country_currencies = new CountryCurrencyDao(); |
|
| 2200 | - } |
|
| 2201 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2202 | - if (! empty($CNT_ISO)) { |
|
| 2203 | - // retrieve the country settings from the db, just in case they have been customized |
|
| 2204 | - $country_currency = $country_currencies->getCountryCurrencyByIsoCode($CNT_ISO); |
|
| 2205 | - $this->code = $country_currency['CurrencyCode']; // currency code: USD, CAD, EUR |
|
| 2206 | - $this->name = $country_currency['CurrencyNameSingle']; // Dollar |
|
| 2207 | - $this->plural = $country_currency['CurrencyNamePlural']; // Dollars |
|
| 2208 | - $this->sign = $country_currency['CurrencySign']; // currency sign: $ |
|
| 2209 | - $this->sign_b4 = $country_currency['CurrencySignB4']; // currency sign before or after: $TRUE or FALSE$ |
|
| 2210 | - $this->dec_plc = $country_currency['CurrencyDecimalPlaces']; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2211 | - $this->dec_mrk = $country_currency['CurrencyDecimalMark']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2212 | - $this->thsnds = $country_currency['CurrencyThousands']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2213 | - } |
|
| 2214 | - // fallback to hardcoded defaults, in case the above failed |
|
| 2215 | - if (empty($this->code)) { |
|
| 2216 | - // set default currency settings |
|
| 2217 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2218 | - $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar |
|
| 2219 | - $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars |
|
| 2220 | - $this->sign = '$'; // currency sign: $ |
|
| 2221 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2222 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2223 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2224 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2225 | - } |
|
| 2226 | - } |
|
| 2227 | - |
|
| 2228 | - |
|
| 2229 | - /** |
|
| 2230 | - * @param string $CNT_ISO |
|
| 2231 | - * @throws EE_Error |
|
| 2232 | - * @throws InvalidArgumentException |
|
| 2233 | - * @throws InvalidDataTypeException |
|
| 2234 | - * @throws InvalidInterfaceException |
|
| 2235 | - * @throws ReflectionException |
|
| 2236 | - */ |
|
| 2237 | - public function setFromCountryModel($CNT_ISO) |
|
| 2238 | - { |
|
| 2239 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2240 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2241 | - if ( |
|
| 2242 | - ! EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2243 | - || ! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2244 | - ) { |
|
| 2245 | - return; |
|
| 2246 | - } |
|
| 2247 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2248 | - if ($country instanceof EE_Country) { |
|
| 2249 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2250 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2251 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2252 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2253 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2254 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2255 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2256 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2257 | - } |
|
| 2258 | - } |
|
| 2259 | -} |
|
| 2260 | - |
|
| 2261 | - |
|
| 2262 | - |
|
| 2263 | -/** |
|
| 2264 | - * Class for defining what's in the EE_Config relating to registration settings |
|
| 2265 | - */ |
|
| 2266 | -class EE_Registration_Config extends EE_Config_Base |
|
| 2267 | -{ |
|
| 2268 | - |
|
| 2269 | - /** |
|
| 2270 | - * Default registration status |
|
| 2271 | - * |
|
| 2272 | - * @var string $default_STS_ID |
|
| 2273 | - * eg 'RPP' |
|
| 2274 | - */ |
|
| 2275 | - public $default_STS_ID; |
|
| 2276 | - |
|
| 2277 | - |
|
| 2278 | - /** |
|
| 2279 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2280 | - * registrations) |
|
| 2281 | - * @var int |
|
| 2282 | - */ |
|
| 2283 | - public $default_maximum_number_of_tickets; |
|
| 2284 | - |
|
| 2285 | - |
|
| 2286 | - /** |
|
| 2287 | - * level of validation to apply to email addresses |
|
| 2288 | - * |
|
| 2289 | - * @var string $email_validation_level |
|
| 2290 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2291 | - */ |
|
| 2292 | - public $email_validation_level; |
|
| 2293 | - |
|
| 2294 | - /** |
|
| 2295 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2296 | - * |
|
| 2297 | - * @var boolean $show_pending_payment_options |
|
| 2298 | - */ |
|
| 2299 | - public $show_pending_payment_options; |
|
| 2300 | - |
|
| 2301 | - /** |
|
| 2302 | - * Whether to skip the registration confirmation page |
|
| 2303 | - * |
|
| 2304 | - * @var boolean $skip_reg_confirmation |
|
| 2305 | - */ |
|
| 2306 | - public $skip_reg_confirmation; |
|
| 2307 | - |
|
| 2308 | - /** |
|
| 2309 | - * an array of SPCO reg steps where: |
|
| 2310 | - * the keys denotes the reg step order |
|
| 2311 | - * each element consists of an array with the following elements: |
|
| 2312 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2313 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2314 | - * "slug" => the URL param used to trigger the reg step |
|
| 2315 | - * |
|
| 2316 | - * @var array $reg_steps |
|
| 2317 | - */ |
|
| 2318 | - public $reg_steps; |
|
| 2319 | - |
|
| 2320 | - /** |
|
| 2321 | - * Whether registration confirmation should be the last page of SPCO |
|
| 2322 | - * |
|
| 2323 | - * @var boolean $reg_confirmation_last |
|
| 2324 | - */ |
|
| 2325 | - public $reg_confirmation_last; |
|
| 2326 | - |
|
| 2327 | - /** |
|
| 2328 | - * Whether or not to enable the EE Bot Trap |
|
| 2329 | - * |
|
| 2330 | - * @var boolean $use_bot_trap |
|
| 2331 | - */ |
|
| 2332 | - public $use_bot_trap; |
|
| 2333 | - |
|
| 2334 | - /** |
|
| 2335 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2336 | - * |
|
| 2337 | - * @var boolean $use_encryption |
|
| 2338 | - */ |
|
| 2339 | - public $use_encryption; |
|
| 1549 | +} |
|
| 2340 | 1550 | |
| 2341 | - /** |
|
| 2342 | - * Whether or not to use ReCaptcha |
|
| 2343 | - * |
|
| 2344 | - * @var boolean $use_captcha |
|
| 2345 | - */ |
|
| 2346 | - public $use_captcha; |
|
| 2347 | 1551 | |
| 2348 | - /** |
|
| 2349 | - * ReCaptcha Theme |
|
| 2350 | - * |
|
| 2351 | - * @var string $recaptcha_theme |
|
| 2352 | - * options: 'dark ', 'light' |
|
| 2353 | - */ |
|
| 2354 | - public $recaptcha_theme; |
|
| 2355 | 1552 | |
| 2356 | - /** |
|
| 2357 | - * ReCaptcha Type |
|
| 2358 | - * |
|
| 2359 | - * @var string $recaptcha_type |
|
| 2360 | - * options: 'audio', 'image' |
|
| 2361 | - */ |
|
| 2362 | - public $recaptcha_type; |
|
| 1553 | +/** |
|
| 1554 | + * Base class used for config classes. These classes should generally not have |
|
| 1555 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
| 1556 | + * basically, they should just be well-defined stdClasses |
|
| 1557 | + */ |
|
| 1558 | +class EE_Config_Base |
|
| 1559 | +{ |
|
| 2363 | 1560 | |
| 2364 | - /** |
|
| 2365 | - * ReCaptcha language |
|
| 2366 | - * |
|
| 2367 | - * @var string $recaptcha_language |
|
| 2368 | - * eg 'en' |
|
| 2369 | - */ |
|
| 2370 | - public $recaptcha_language; |
|
| 1561 | + /** |
|
| 1562 | + * Utility function for escaping the value of a property and returning. |
|
| 1563 | + * |
|
| 1564 | + * @param string $property property name (checks to see if exists). |
|
| 1565 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
| 1566 | + * @throws EE_Error |
|
| 1567 | + */ |
|
| 1568 | + public function get_pretty($property) |
|
| 1569 | + { |
|
| 1570 | + if (! property_exists($this, $property)) { |
|
| 1571 | + throw new EE_Error( |
|
| 1572 | + sprintf( |
|
| 1573 | + __( |
|
| 1574 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
| 1575 | + 'event_espresso' |
|
| 1576 | + ), |
|
| 1577 | + get_class($this), |
|
| 1578 | + $property |
|
| 1579 | + ) |
|
| 1580 | + ); |
|
| 1581 | + } |
|
| 1582 | + //just handling escaping of strings for now. |
|
| 1583 | + if (is_string($this->{$property})) { |
|
| 1584 | + return stripslashes($this->{$property}); |
|
| 1585 | + } |
|
| 1586 | + return $this->{$property}; |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + |
|
| 1590 | + |
|
| 1591 | + public function populate() |
|
| 1592 | + { |
|
| 1593 | + //grab defaults via a new instance of this class. |
|
| 1594 | + $class_name = get_class($this); |
|
| 1595 | + $defaults = new $class_name; |
|
| 1596 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
| 1597 | + //default from our $defaults object. |
|
| 1598 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
| 1599 | + if ($this->{$property} === null) { |
|
| 1600 | + $this->{$property} = $value; |
|
| 1601 | + } |
|
| 1602 | + } |
|
| 1603 | + //cleanup |
|
| 1604 | + unset($defaults); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + |
|
| 1609 | + /** |
|
| 1610 | + * __isset |
|
| 1611 | + * |
|
| 1612 | + * @param $a |
|
| 1613 | + * @return bool |
|
| 1614 | + */ |
|
| 1615 | + public function __isset($a) |
|
| 1616 | + { |
|
| 1617 | + return false; |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + |
|
| 1621 | + |
|
| 1622 | + /** |
|
| 1623 | + * __unset |
|
| 1624 | + * |
|
| 1625 | + * @param $a |
|
| 1626 | + * @return bool |
|
| 1627 | + */ |
|
| 1628 | + public function __unset($a) |
|
| 1629 | + { |
|
| 1630 | + return false; |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + |
|
| 1635 | + /** |
|
| 1636 | + * __clone |
|
| 1637 | + */ |
|
| 1638 | + public function __clone() |
|
| 1639 | + { |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + |
|
| 1643 | + |
|
| 1644 | + /** |
|
| 1645 | + * __wakeup |
|
| 1646 | + */ |
|
| 1647 | + public function __wakeup() |
|
| 1648 | + { |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + |
|
| 1652 | + |
|
| 1653 | + /** |
|
| 1654 | + * __destruct |
|
| 1655 | + */ |
|
| 1656 | + public function __destruct() |
|
| 1657 | + { |
|
| 1658 | + } |
|
| 1659 | +} |
|
| 2371 | 1660 | |
| 2372 | - /** |
|
| 2373 | - * ReCaptcha public key |
|
| 2374 | - * |
|
| 2375 | - * @var string $recaptcha_publickey |
|
| 2376 | - */ |
|
| 2377 | - public $recaptcha_publickey; |
|
| 2378 | 1661 | |
| 2379 | - /** |
|
| 2380 | - * ReCaptcha private key |
|
| 2381 | - * |
|
| 2382 | - * @var string $recaptcha_privatekey |
|
| 2383 | - */ |
|
| 2384 | - public $recaptcha_privatekey; |
|
| 2385 | 1662 | |
| 2386 | - /** |
|
| 2387 | - * ReCaptcha width |
|
| 2388 | - * |
|
| 2389 | - * @var int $recaptcha_width |
|
| 2390 | - * @deprecated |
|
| 2391 | - */ |
|
| 2392 | - public $recaptcha_width; |
|
| 1663 | +/** |
|
| 1664 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 1665 | + */ |
|
| 1666 | +class EE_Core_Config extends EE_Config_Base |
|
| 1667 | +{ |
|
| 2393 | 1668 | |
| 2394 | - /** |
|
| 2395 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2396 | - * |
|
| 2397 | - * @var boolean $track_invalid_checkout_access |
|
| 2398 | - */ |
|
| 2399 | - protected $track_invalid_checkout_access = true; |
|
| 1669 | + public $current_blog_id; |
|
| 1670 | + |
|
| 1671 | + public $ee_ueip_optin; |
|
| 1672 | + |
|
| 1673 | + public $ee_ueip_has_notified; |
|
| 1674 | + |
|
| 1675 | + /** |
|
| 1676 | + * Not to be confused with the 4 critical page variables (See |
|
| 1677 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
| 1678 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
| 1679 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
| 1680 | + * |
|
| 1681 | + * @var array |
|
| 1682 | + */ |
|
| 1683 | + public $post_shortcodes; |
|
| 1684 | + |
|
| 1685 | + public $module_route_map; |
|
| 1686 | + |
|
| 1687 | + public $module_forward_map; |
|
| 1688 | + |
|
| 1689 | + public $module_view_map; |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * The next 4 vars are the IDs of critical EE pages. |
|
| 1693 | + * |
|
| 1694 | + * @var int |
|
| 1695 | + */ |
|
| 1696 | + public $reg_page_id; |
|
| 1697 | + |
|
| 1698 | + public $txn_page_id; |
|
| 1699 | + |
|
| 1700 | + public $thank_you_page_id; |
|
| 1701 | + |
|
| 1702 | + public $cancel_page_id; |
|
| 1703 | + |
|
| 1704 | + /** |
|
| 1705 | + * The next 4 vars are the URLs of critical EE pages. |
|
| 1706 | + * |
|
| 1707 | + * @var int |
|
| 1708 | + */ |
|
| 1709 | + public $reg_page_url; |
|
| 1710 | + |
|
| 1711 | + public $txn_page_url; |
|
| 1712 | + |
|
| 1713 | + public $thank_you_page_url; |
|
| 1714 | + |
|
| 1715 | + public $cancel_page_url; |
|
| 1716 | + |
|
| 1717 | + /** |
|
| 1718 | + * The next vars relate to the custom slugs for EE CPT routes |
|
| 1719 | + */ |
|
| 1720 | + public $event_cpt_slug; |
|
| 1721 | + |
|
| 1722 | + |
|
| 1723 | + /** |
|
| 1724 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
| 1725 | + * request across blog switches in a multisite context. |
|
| 1726 | + * Avoids extra queries to the db for this option. |
|
| 1727 | + * |
|
| 1728 | + * @var bool |
|
| 1729 | + */ |
|
| 1730 | + public static $ee_ueip_option; |
|
| 1731 | + |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * class constructor |
|
| 1736 | + * |
|
| 1737 | + * @access public |
|
| 1738 | + */ |
|
| 1739 | + public function __construct() |
|
| 1740 | + { |
|
| 1741 | + // set default organization settings |
|
| 1742 | + $this->current_blog_id = get_current_blog_id(); |
|
| 1743 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
| 1744 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
| 1745 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
| 1746 | + $this->post_shortcodes = array(); |
|
| 1747 | + $this->module_route_map = array(); |
|
| 1748 | + $this->module_forward_map = array(); |
|
| 1749 | + $this->module_view_map = array(); |
|
| 1750 | + // critical EE page IDs |
|
| 1751 | + $this->reg_page_id = 0; |
|
| 1752 | + $this->txn_page_id = 0; |
|
| 1753 | + $this->thank_you_page_id = 0; |
|
| 1754 | + $this->cancel_page_id = 0; |
|
| 1755 | + // critical EE page URLs |
|
| 1756 | + $this->reg_page_url = ''; |
|
| 1757 | + $this->txn_page_url = ''; |
|
| 1758 | + $this->thank_you_page_url = ''; |
|
| 1759 | + $this->cancel_page_url = ''; |
|
| 1760 | + //cpt slugs |
|
| 1761 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
| 1762 | + //ueip constant check |
|
| 1763 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
| 1764 | + $this->ee_ueip_optin = false; |
|
| 1765 | + $this->ee_ueip_has_notified = true; |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + |
|
| 1770 | + |
|
| 1771 | + /** |
|
| 1772 | + * @return array |
|
| 1773 | + */ |
|
| 1774 | + public function get_critical_pages_array() |
|
| 1775 | + { |
|
| 1776 | + return array( |
|
| 1777 | + $this->reg_page_id, |
|
| 1778 | + $this->txn_page_id, |
|
| 1779 | + $this->thank_you_page_id, |
|
| 1780 | + $this->cancel_page_id, |
|
| 1781 | + ); |
|
| 1782 | + } |
|
| 1783 | + |
|
| 1784 | + |
|
| 1785 | + |
|
| 1786 | + /** |
|
| 1787 | + * @return array |
|
| 1788 | + */ |
|
| 1789 | + public function get_critical_pages_shortcodes_array() |
|
| 1790 | + { |
|
| 1791 | + return array( |
|
| 1792 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
| 1793 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
| 1794 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
| 1795 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
| 1796 | + ); |
|
| 1797 | + } |
|
| 1798 | + |
|
| 1799 | + |
|
| 1800 | + |
|
| 1801 | + /** |
|
| 1802 | + * gets/returns URL for EE reg_page |
|
| 1803 | + * |
|
| 1804 | + * @access public |
|
| 1805 | + * @return string |
|
| 1806 | + */ |
|
| 1807 | + public function reg_page_url() |
|
| 1808 | + { |
|
| 1809 | + if (! $this->reg_page_url) { |
|
| 1810 | + $this->reg_page_url = add_query_arg( |
|
| 1811 | + array('uts' => time()), |
|
| 1812 | + get_permalink($this->reg_page_id) |
|
| 1813 | + ) . '#checkout'; |
|
| 1814 | + } |
|
| 1815 | + return $this->reg_page_url; |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + |
|
| 1819 | + |
|
| 1820 | + /** |
|
| 1821 | + * gets/returns URL for EE txn_page |
|
| 1822 | + * |
|
| 1823 | + * @param array $query_args like what gets passed to |
|
| 1824 | + * add_query_arg() as the first argument |
|
| 1825 | + * @access public |
|
| 1826 | + * @return string |
|
| 1827 | + */ |
|
| 1828 | + public function txn_page_url($query_args = array()) |
|
| 1829 | + { |
|
| 1830 | + if (! $this->txn_page_url) { |
|
| 1831 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
| 1832 | + } |
|
| 1833 | + if ($query_args) { |
|
| 1834 | + return add_query_arg($query_args, $this->txn_page_url); |
|
| 1835 | + } else { |
|
| 1836 | + return $this->txn_page_url; |
|
| 1837 | + } |
|
| 1838 | + } |
|
| 1839 | + |
|
| 1840 | + |
|
| 1841 | + |
|
| 1842 | + /** |
|
| 1843 | + * gets/returns URL for EE thank_you_page |
|
| 1844 | + * |
|
| 1845 | + * @param array $query_args like what gets passed to |
|
| 1846 | + * add_query_arg() as the first argument |
|
| 1847 | + * @access public |
|
| 1848 | + * @return string |
|
| 1849 | + */ |
|
| 1850 | + public function thank_you_page_url($query_args = array()) |
|
| 1851 | + { |
|
| 1852 | + if (! $this->thank_you_page_url) { |
|
| 1853 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
| 1854 | + } |
|
| 1855 | + if ($query_args) { |
|
| 1856 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
| 1857 | + } else { |
|
| 1858 | + return $this->thank_you_page_url; |
|
| 1859 | + } |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + |
|
| 1864 | + /** |
|
| 1865 | + * gets/returns URL for EE cancel_page |
|
| 1866 | + * |
|
| 1867 | + * @access public |
|
| 1868 | + * @return string |
|
| 1869 | + */ |
|
| 1870 | + public function cancel_page_url() |
|
| 1871 | + { |
|
| 1872 | + if (! $this->cancel_page_url) { |
|
| 1873 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
| 1874 | + } |
|
| 1875 | + return $this->cancel_page_url; |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + |
|
| 1879 | + |
|
| 1880 | + /** |
|
| 1881 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
| 1882 | + * |
|
| 1883 | + * @since 4.7.5 |
|
| 1884 | + */ |
|
| 1885 | + protected function _reset_urls() |
|
| 1886 | + { |
|
| 1887 | + $this->reg_page_url = ''; |
|
| 1888 | + $this->txn_page_url = ''; |
|
| 1889 | + $this->cancel_page_url = ''; |
|
| 1890 | + $this->thank_you_page_url = ''; |
|
| 1891 | + } |
|
| 1892 | + |
|
| 1893 | + |
|
| 1894 | + |
|
| 1895 | + /** |
|
| 1896 | + * Used to return what the opt-in value is set for the EE User Experience Program. |
|
| 1897 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
| 1898 | + * on the main site only. |
|
| 1899 | + * |
|
| 1900 | + * @return mixed |
|
| 1901 | + */ |
|
| 1902 | + protected function _get_main_ee_ueip_optin() |
|
| 1903 | + { |
|
| 1904 | + //if this is the main site then we can just bypass our direct query. |
|
| 1905 | + if (is_main_site()) { |
|
| 1906 | + return get_option('ee_ueip_optin', false); |
|
| 1907 | + } |
|
| 1908 | + //is this already cached for this request? If so use it. |
|
| 1909 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
| 1910 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1911 | + } |
|
| 1912 | + global $wpdb; |
|
| 1913 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
| 1914 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
| 1915 | + $option = 'ee_ueip_optin'; |
|
| 1916 | + //set correct table for query |
|
| 1917 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1918 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
| 1919 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
| 1920 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
| 1921 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
| 1922 | + //for the purpose of caching. |
|
| 1923 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1924 | + if (false !== $pre) { |
|
| 1925 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
| 1926 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1927 | + } |
|
| 1928 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
| 1929 | + $option)); |
|
| 1930 | + if (is_object($row)) { |
|
| 1931 | + $value = $row->option_value; |
|
| 1932 | + } else { //option does not exist so use default. |
|
| 1933 | + return apply_filters('default_option_' . $option, false, $option); |
|
| 1934 | + } |
|
| 1935 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1936 | + return EE_Core_Config::$ee_ueip_option; |
|
| 1937 | + } |
|
| 1938 | + |
|
| 1939 | + |
|
| 1940 | + |
|
| 1941 | + /** |
|
| 1942 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
| 1943 | + * on the object. |
|
| 1944 | + * |
|
| 1945 | + * @return array |
|
| 1946 | + */ |
|
| 1947 | + public function __sleep() |
|
| 1948 | + { |
|
| 1949 | + //reset all url properties |
|
| 1950 | + $this->_reset_urls(); |
|
| 1951 | + //return what to save to db |
|
| 1952 | + return array_keys(get_object_vars($this)); |
|
| 1953 | + } |
|
| 2400 | 1954 | |
| 1955 | +} |
|
| 2401 | 1956 | |
| 2402 | 1957 | |
| 2403 | - /** |
|
| 2404 | - * class constructor |
|
| 2405 | - * |
|
| 2406 | - * @access public |
|
| 2407 | - */ |
|
| 2408 | - public function __construct() |
|
| 2409 | - { |
|
| 2410 | - // set default registration settings |
|
| 2411 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2412 | - $this->email_validation_level = 'wp_default'; |
|
| 2413 | - $this->show_pending_payment_options = true; |
|
| 2414 | - $this->skip_reg_confirmation = false; |
|
| 2415 | - $this->reg_steps = array(); |
|
| 2416 | - $this->reg_confirmation_last = false; |
|
| 2417 | - $this->use_bot_trap = true; |
|
| 2418 | - $this->use_encryption = true; |
|
| 2419 | - $this->use_captcha = false; |
|
| 2420 | - $this->recaptcha_theme = 'light'; |
|
| 2421 | - $this->recaptcha_type = 'image'; |
|
| 2422 | - $this->recaptcha_language = 'en'; |
|
| 2423 | - $this->recaptcha_publickey = null; |
|
| 2424 | - $this->recaptcha_privatekey = null; |
|
| 2425 | - $this->recaptcha_width = 500; |
|
| 2426 | - $this->default_maximum_number_of_tickets = 10; |
|
| 2427 | - } |
|
| 2428 | - |
|
| 2429 | - |
|
| 2430 | - |
|
| 2431 | - /** |
|
| 2432 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2433 | - * |
|
| 2434 | - * @since 4.8.8.rc.019 |
|
| 2435 | - */ |
|
| 2436 | - public function do_hooks() |
|
| 2437 | - { |
|
| 2438 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2439 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2440 | - } |
|
| 2441 | 1958 | |
| 1959 | +/** |
|
| 1960 | + * Config class for storing info on the Organization |
|
| 1961 | + */ |
|
| 1962 | +class EE_Organization_Config extends EE_Config_Base |
|
| 1963 | +{ |
|
| 2442 | 1964 | |
| 1965 | + /** |
|
| 1966 | + * @var string $name |
|
| 1967 | + * eg EE4.1 |
|
| 1968 | + */ |
|
| 1969 | + public $name; |
|
| 1970 | + |
|
| 1971 | + /** |
|
| 1972 | + * @var string $address_1 |
|
| 1973 | + * eg 123 Onna Road |
|
| 1974 | + */ |
|
| 1975 | + public $address_1; |
|
| 1976 | + |
|
| 1977 | + /** |
|
| 1978 | + * @var string $address_2 |
|
| 1979 | + * eg PO Box 123 |
|
| 1980 | + */ |
|
| 1981 | + public $address_2; |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * @var string $city |
|
| 1985 | + * eg Inna City |
|
| 1986 | + */ |
|
| 1987 | + public $city; |
|
| 1988 | + |
|
| 1989 | + /** |
|
| 1990 | + * @var int $STA_ID |
|
| 1991 | + * eg 4 |
|
| 1992 | + */ |
|
| 1993 | + public $STA_ID; |
|
| 1994 | + |
|
| 1995 | + /** |
|
| 1996 | + * @var string $CNT_ISO |
|
| 1997 | + * eg US |
|
| 1998 | + */ |
|
| 1999 | + public $CNT_ISO; |
|
| 2000 | + |
|
| 2001 | + /** |
|
| 2002 | + * @var string $zip |
|
| 2003 | + * eg 12345 or V1A 2B3 |
|
| 2004 | + */ |
|
| 2005 | + public $zip; |
|
| 2006 | + |
|
| 2007 | + /** |
|
| 2008 | + * @var string $email |
|
| 2009 | + * eg [email protected] |
|
| 2010 | + */ |
|
| 2011 | + public $email; |
|
| 2012 | + |
|
| 2013 | + |
|
| 2014 | + /** |
|
| 2015 | + * @var string $phone |
|
| 2016 | + * eg. 111-111-1111 |
|
| 2017 | + */ |
|
| 2018 | + public $phone; |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * @var string $vat |
|
| 2023 | + * VAT/Tax Number |
|
| 2024 | + */ |
|
| 2025 | + public $vat; |
|
| 2026 | + |
|
| 2027 | + /** |
|
| 2028 | + * @var string $logo_url |
|
| 2029 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
| 2030 | + */ |
|
| 2031 | + public $logo_url; |
|
| 2032 | + |
|
| 2033 | + |
|
| 2034 | + /** |
|
| 2035 | + * The below are all various properties for holding links to organization social network profiles |
|
| 2036 | + * |
|
| 2037 | + * @var string |
|
| 2038 | + */ |
|
| 2039 | + /** |
|
| 2040 | + * facebook (facebook.com/profile.name) |
|
| 2041 | + * |
|
| 2042 | + * @var string |
|
| 2043 | + */ |
|
| 2044 | + public $facebook; |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + /** |
|
| 2048 | + * twitter (twitter.com/twitter_handle) |
|
| 2049 | + * |
|
| 2050 | + * @var string |
|
| 2051 | + */ |
|
| 2052 | + public $twitter; |
|
| 2053 | + |
|
| 2054 | + |
|
| 2055 | + /** |
|
| 2056 | + * linkedin (linkedin.com/in/profile_name) |
|
| 2057 | + * |
|
| 2058 | + * @var string |
|
| 2059 | + */ |
|
| 2060 | + public $linkedin; |
|
| 2061 | + |
|
| 2062 | + |
|
| 2063 | + /** |
|
| 2064 | + * pinterest (www.pinterest.com/profile_name) |
|
| 2065 | + * |
|
| 2066 | + * @var string |
|
| 2067 | + */ |
|
| 2068 | + public $pinterest; |
|
| 2069 | + |
|
| 2070 | + |
|
| 2071 | + /** |
|
| 2072 | + * google+ (google.com/+profileName) |
|
| 2073 | + * |
|
| 2074 | + * @var string |
|
| 2075 | + */ |
|
| 2076 | + public $google; |
|
| 2077 | + |
|
| 2078 | + |
|
| 2079 | + /** |
|
| 2080 | + * instagram (instagram.com/handle) |
|
| 2081 | + * |
|
| 2082 | + * @var string |
|
| 2083 | + */ |
|
| 2084 | + public $instagram; |
|
| 2085 | + |
|
| 2086 | + |
|
| 2087 | + |
|
| 2088 | + /** |
|
| 2089 | + * class constructor |
|
| 2090 | + * |
|
| 2091 | + * @access public |
|
| 2092 | + */ |
|
| 2093 | + public function __construct() |
|
| 2094 | + { |
|
| 2095 | + // set default organization settings |
|
| 2096 | + $this->name = get_bloginfo('name'); |
|
| 2097 | + $this->address_1 = '123 Onna Road'; |
|
| 2098 | + $this->address_2 = 'PO Box 123'; |
|
| 2099 | + $this->city = 'Inna City'; |
|
| 2100 | + $this->STA_ID = 4; |
|
| 2101 | + $this->CNT_ISO = 'US'; |
|
| 2102 | + $this->zip = '12345'; |
|
| 2103 | + $this->email = get_bloginfo('admin_email'); |
|
| 2104 | + $this->phone = ''; |
|
| 2105 | + $this->vat = '123456789'; |
|
| 2106 | + $this->logo_url = ''; |
|
| 2107 | + $this->facebook = ''; |
|
| 2108 | + $this->twitter = ''; |
|
| 2109 | + $this->linkedin = ''; |
|
| 2110 | + $this->pinterest = ''; |
|
| 2111 | + $this->google = ''; |
|
| 2112 | + $this->instagram = ''; |
|
| 2113 | + } |
|
| 2443 | 2114 | |
| 2444 | - /** |
|
| 2445 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2446 | - * field matches the config setting for default_STS_ID. |
|
| 2447 | - */ |
|
| 2448 | - public function set_default_reg_status_on_EEM_Event() |
|
| 2449 | - { |
|
| 2450 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2451 | - } |
|
| 2115 | +} |
|
| 2452 | 2116 | |
| 2453 | 2117 | |
| 2454 | - /** |
|
| 2455 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2456 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2457 | - */ |
|
| 2458 | - public function set_default_max_ticket_on_EEM_Event() |
|
| 2459 | - { |
|
| 2460 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2461 | - } |
|
| 2462 | 2118 | |
| 2119 | +/** |
|
| 2120 | + * Class for defining what's in the EE_Config relating to currency |
|
| 2121 | + */ |
|
| 2122 | +class EE_Currency_Config extends EE_Config_Base |
|
| 2123 | +{ |
|
| 2463 | 2124 | |
| 2125 | + /** |
|
| 2126 | + * @var string $code |
|
| 2127 | + * eg 'US' |
|
| 2128 | + */ |
|
| 2129 | + public $code; |
|
| 2130 | + |
|
| 2131 | + /** |
|
| 2132 | + * @var string $name |
|
| 2133 | + * eg 'Dollar' |
|
| 2134 | + */ |
|
| 2135 | + public $name; |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * plural name |
|
| 2139 | + * |
|
| 2140 | + * @var string $plural |
|
| 2141 | + * eg 'Dollars' |
|
| 2142 | + */ |
|
| 2143 | + public $plural; |
|
| 2144 | + |
|
| 2145 | + /** |
|
| 2146 | + * currency sign |
|
| 2147 | + * |
|
| 2148 | + * @var string $sign |
|
| 2149 | + * eg '$' |
|
| 2150 | + */ |
|
| 2151 | + public $sign; |
|
| 2152 | + |
|
| 2153 | + /** |
|
| 2154 | + * Whether the currency sign should come before the number or not |
|
| 2155 | + * |
|
| 2156 | + * @var boolean $sign_b4 |
|
| 2157 | + */ |
|
| 2158 | + public $sign_b4; |
|
| 2159 | + |
|
| 2160 | + /** |
|
| 2161 | + * How many digits should come after the decimal place |
|
| 2162 | + * |
|
| 2163 | + * @var int $dec_plc |
|
| 2164 | + */ |
|
| 2165 | + public $dec_plc; |
|
| 2166 | + |
|
| 2167 | + /** |
|
| 2168 | + * Symbol to use for decimal mark |
|
| 2169 | + * |
|
| 2170 | + * @var string $dec_mrk |
|
| 2171 | + * eg '.' |
|
| 2172 | + */ |
|
| 2173 | + public $dec_mrk; |
|
| 2174 | + |
|
| 2175 | + /** |
|
| 2176 | + * Symbol to use for thousands |
|
| 2177 | + * |
|
| 2178 | + * @var string $thsnds |
|
| 2179 | + * eg ',' |
|
| 2180 | + */ |
|
| 2181 | + public $thsnds; |
|
| 2182 | + |
|
| 2183 | + |
|
| 2184 | + /** |
|
| 2185 | + * class constructor |
|
| 2186 | + * |
|
| 2187 | + * @access public |
|
| 2188 | + * @param string $CNT_ISO |
|
| 2189 | + * @param CountryCurrencyDao $country_currencies |
|
| 2190 | + * @throws EE_Error |
|
| 2191 | + * @throws InvalidArgumentException |
|
| 2192 | + * @throws ReflectionException |
|
| 2193 | + * @throws InvalidDataTypeException |
|
| 2194 | + * @throws InvalidInterfaceException |
|
| 2195 | + */ |
|
| 2196 | + public function __construct($CNT_ISO = '', CountryCurrencyDao $country_currencies = null) |
|
| 2197 | + { |
|
| 2198 | + if(! $country_currencies instanceof CountryCurrencyDao){ |
|
| 2199 | + $country_currencies = new CountryCurrencyDao(); |
|
| 2200 | + } |
|
| 2201 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
| 2202 | + if (! empty($CNT_ISO)) { |
|
| 2203 | + // retrieve the country settings from the db, just in case they have been customized |
|
| 2204 | + $country_currency = $country_currencies->getCountryCurrencyByIsoCode($CNT_ISO); |
|
| 2205 | + $this->code = $country_currency['CurrencyCode']; // currency code: USD, CAD, EUR |
|
| 2206 | + $this->name = $country_currency['CurrencyNameSingle']; // Dollar |
|
| 2207 | + $this->plural = $country_currency['CurrencyNamePlural']; // Dollars |
|
| 2208 | + $this->sign = $country_currency['CurrencySign']; // currency sign: $ |
|
| 2209 | + $this->sign_b4 = $country_currency['CurrencySignB4']; // currency sign before or after: $TRUE or FALSE$ |
|
| 2210 | + $this->dec_plc = $country_currency['CurrencyDecimalPlaces']; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2211 | + $this->dec_mrk = $country_currency['CurrencyDecimalMark']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2212 | + $this->thsnds = $country_currency['CurrencyThousands']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2213 | + } |
|
| 2214 | + // fallback to hardcoded defaults, in case the above failed |
|
| 2215 | + if (empty($this->code)) { |
|
| 2216 | + // set default currency settings |
|
| 2217 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2218 | + $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar |
|
| 2219 | + $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars |
|
| 2220 | + $this->sign = '$'; // currency sign: $ |
|
| 2221 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2222 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2223 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2224 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2225 | + } |
|
| 2226 | + } |
|
| 2227 | + |
|
| 2228 | + |
|
| 2229 | + /** |
|
| 2230 | + * @param string $CNT_ISO |
|
| 2231 | + * @throws EE_Error |
|
| 2232 | + * @throws InvalidArgumentException |
|
| 2233 | + * @throws InvalidDataTypeException |
|
| 2234 | + * @throws InvalidInterfaceException |
|
| 2235 | + * @throws ReflectionException |
|
| 2236 | + */ |
|
| 2237 | + public function setFromCountryModel($CNT_ISO) |
|
| 2238 | + { |
|
| 2239 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
| 2240 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 2241 | + if ( |
|
| 2242 | + ! EE_Maintenance_Mode::instance()->models_can_query() |
|
| 2243 | + || ! $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
| 2244 | + ) { |
|
| 2245 | + return; |
|
| 2246 | + } |
|
| 2247 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
| 2248 | + if ($country instanceof EE_Country) { |
|
| 2249 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2250 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2251 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2252 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2253 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2254 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2255 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2256 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2257 | + } |
|
| 2258 | + } |
|
| 2259 | +} |
|
| 2464 | 2260 | |
| 2465 | - /** |
|
| 2466 | - * @return boolean |
|
| 2467 | - */ |
|
| 2468 | - public function track_invalid_checkout_access() |
|
| 2469 | - { |
|
| 2470 | - return $this->track_invalid_checkout_access; |
|
| 2471 | - } |
|
| 2472 | 2261 | |
| 2473 | 2262 | |
| 2263 | +/** |
|
| 2264 | + * Class for defining what's in the EE_Config relating to registration settings |
|
| 2265 | + */ |
|
| 2266 | +class EE_Registration_Config extends EE_Config_Base |
|
| 2267 | +{ |
|
| 2474 | 2268 | |
| 2475 | - /** |
|
| 2476 | - * @param boolean $track_invalid_checkout_access |
|
| 2477 | - */ |
|
| 2478 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2479 | - { |
|
| 2480 | - $this->track_invalid_checkout_access = filter_var( |
|
| 2481 | - $track_invalid_checkout_access, |
|
| 2482 | - FILTER_VALIDATE_BOOLEAN |
|
| 2483 | - ); |
|
| 2484 | - } |
|
| 2269 | + /** |
|
| 2270 | + * Default registration status |
|
| 2271 | + * |
|
| 2272 | + * @var string $default_STS_ID |
|
| 2273 | + * eg 'RPP' |
|
| 2274 | + */ |
|
| 2275 | + public $default_STS_ID; |
|
| 2276 | + |
|
| 2277 | + |
|
| 2278 | + /** |
|
| 2279 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
| 2280 | + * registrations) |
|
| 2281 | + * @var int |
|
| 2282 | + */ |
|
| 2283 | + public $default_maximum_number_of_tickets; |
|
| 2284 | + |
|
| 2285 | + |
|
| 2286 | + /** |
|
| 2287 | + * level of validation to apply to email addresses |
|
| 2288 | + * |
|
| 2289 | + * @var string $email_validation_level |
|
| 2290 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
| 2291 | + */ |
|
| 2292 | + public $email_validation_level; |
|
| 2293 | + |
|
| 2294 | + /** |
|
| 2295 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
| 2296 | + * |
|
| 2297 | + * @var boolean $show_pending_payment_options |
|
| 2298 | + */ |
|
| 2299 | + public $show_pending_payment_options; |
|
| 2300 | + |
|
| 2301 | + /** |
|
| 2302 | + * Whether to skip the registration confirmation page |
|
| 2303 | + * |
|
| 2304 | + * @var boolean $skip_reg_confirmation |
|
| 2305 | + */ |
|
| 2306 | + public $skip_reg_confirmation; |
|
| 2307 | + |
|
| 2308 | + /** |
|
| 2309 | + * an array of SPCO reg steps where: |
|
| 2310 | + * the keys denotes the reg step order |
|
| 2311 | + * each element consists of an array with the following elements: |
|
| 2312 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
| 2313 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
| 2314 | + * "slug" => the URL param used to trigger the reg step |
|
| 2315 | + * |
|
| 2316 | + * @var array $reg_steps |
|
| 2317 | + */ |
|
| 2318 | + public $reg_steps; |
|
| 2319 | + |
|
| 2320 | + /** |
|
| 2321 | + * Whether registration confirmation should be the last page of SPCO |
|
| 2322 | + * |
|
| 2323 | + * @var boolean $reg_confirmation_last |
|
| 2324 | + */ |
|
| 2325 | + public $reg_confirmation_last; |
|
| 2326 | + |
|
| 2327 | + /** |
|
| 2328 | + * Whether or not to enable the EE Bot Trap |
|
| 2329 | + * |
|
| 2330 | + * @var boolean $use_bot_trap |
|
| 2331 | + */ |
|
| 2332 | + public $use_bot_trap; |
|
| 2333 | + |
|
| 2334 | + /** |
|
| 2335 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
| 2336 | + * |
|
| 2337 | + * @var boolean $use_encryption |
|
| 2338 | + */ |
|
| 2339 | + public $use_encryption; |
|
| 2340 | + |
|
| 2341 | + /** |
|
| 2342 | + * Whether or not to use ReCaptcha |
|
| 2343 | + * |
|
| 2344 | + * @var boolean $use_captcha |
|
| 2345 | + */ |
|
| 2346 | + public $use_captcha; |
|
| 2347 | + |
|
| 2348 | + /** |
|
| 2349 | + * ReCaptcha Theme |
|
| 2350 | + * |
|
| 2351 | + * @var string $recaptcha_theme |
|
| 2352 | + * options: 'dark ', 'light' |
|
| 2353 | + */ |
|
| 2354 | + public $recaptcha_theme; |
|
| 2355 | + |
|
| 2356 | + /** |
|
| 2357 | + * ReCaptcha Type |
|
| 2358 | + * |
|
| 2359 | + * @var string $recaptcha_type |
|
| 2360 | + * options: 'audio', 'image' |
|
| 2361 | + */ |
|
| 2362 | + public $recaptcha_type; |
|
| 2363 | + |
|
| 2364 | + /** |
|
| 2365 | + * ReCaptcha language |
|
| 2366 | + * |
|
| 2367 | + * @var string $recaptcha_language |
|
| 2368 | + * eg 'en' |
|
| 2369 | + */ |
|
| 2370 | + public $recaptcha_language; |
|
| 2371 | + |
|
| 2372 | + /** |
|
| 2373 | + * ReCaptcha public key |
|
| 2374 | + * |
|
| 2375 | + * @var string $recaptcha_publickey |
|
| 2376 | + */ |
|
| 2377 | + public $recaptcha_publickey; |
|
| 2378 | + |
|
| 2379 | + /** |
|
| 2380 | + * ReCaptcha private key |
|
| 2381 | + * |
|
| 2382 | + * @var string $recaptcha_privatekey |
|
| 2383 | + */ |
|
| 2384 | + public $recaptcha_privatekey; |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * ReCaptcha width |
|
| 2388 | + * |
|
| 2389 | + * @var int $recaptcha_width |
|
| 2390 | + * @deprecated |
|
| 2391 | + */ |
|
| 2392 | + public $recaptcha_width; |
|
| 2393 | + |
|
| 2394 | + /** |
|
| 2395 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
| 2396 | + * |
|
| 2397 | + * @var boolean $track_invalid_checkout_access |
|
| 2398 | + */ |
|
| 2399 | + protected $track_invalid_checkout_access = true; |
|
| 2400 | + |
|
| 2401 | + |
|
| 2402 | + |
|
| 2403 | + /** |
|
| 2404 | + * class constructor |
|
| 2405 | + * |
|
| 2406 | + * @access public |
|
| 2407 | + */ |
|
| 2408 | + public function __construct() |
|
| 2409 | + { |
|
| 2410 | + // set default registration settings |
|
| 2411 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
| 2412 | + $this->email_validation_level = 'wp_default'; |
|
| 2413 | + $this->show_pending_payment_options = true; |
|
| 2414 | + $this->skip_reg_confirmation = false; |
|
| 2415 | + $this->reg_steps = array(); |
|
| 2416 | + $this->reg_confirmation_last = false; |
|
| 2417 | + $this->use_bot_trap = true; |
|
| 2418 | + $this->use_encryption = true; |
|
| 2419 | + $this->use_captcha = false; |
|
| 2420 | + $this->recaptcha_theme = 'light'; |
|
| 2421 | + $this->recaptcha_type = 'image'; |
|
| 2422 | + $this->recaptcha_language = 'en'; |
|
| 2423 | + $this->recaptcha_publickey = null; |
|
| 2424 | + $this->recaptcha_privatekey = null; |
|
| 2425 | + $this->recaptcha_width = 500; |
|
| 2426 | + $this->default_maximum_number_of_tickets = 10; |
|
| 2427 | + } |
|
| 2428 | + |
|
| 2429 | + |
|
| 2430 | + |
|
| 2431 | + /** |
|
| 2432 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
| 2433 | + * |
|
| 2434 | + * @since 4.8.8.rc.019 |
|
| 2435 | + */ |
|
| 2436 | + public function do_hooks() |
|
| 2437 | + { |
|
| 2438 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
| 2439 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
| 2440 | + } |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + |
|
| 2444 | + /** |
|
| 2445 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
| 2446 | + * field matches the config setting for default_STS_ID. |
|
| 2447 | + */ |
|
| 2448 | + public function set_default_reg_status_on_EEM_Event() |
|
| 2449 | + { |
|
| 2450 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + |
|
| 2454 | + /** |
|
| 2455 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
| 2456 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
| 2457 | + */ |
|
| 2458 | + public function set_default_max_ticket_on_EEM_Event() |
|
| 2459 | + { |
|
| 2460 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
| 2461 | + } |
|
| 2462 | + |
|
| 2463 | + |
|
| 2464 | + |
|
| 2465 | + /** |
|
| 2466 | + * @return boolean |
|
| 2467 | + */ |
|
| 2468 | + public function track_invalid_checkout_access() |
|
| 2469 | + { |
|
| 2470 | + return $this->track_invalid_checkout_access; |
|
| 2471 | + } |
|
| 2472 | + |
|
| 2473 | + |
|
| 2474 | + |
|
| 2475 | + /** |
|
| 2476 | + * @param boolean $track_invalid_checkout_access |
|
| 2477 | + */ |
|
| 2478 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
| 2479 | + { |
|
| 2480 | + $this->track_invalid_checkout_access = filter_var( |
|
| 2481 | + $track_invalid_checkout_access, |
|
| 2482 | + FILTER_VALIDATE_BOOLEAN |
|
| 2483 | + ); |
|
| 2484 | + } |
|
| 2485 | 2485 | |
| 2486 | 2486 | |
| 2487 | 2487 | |
@@ -2495,160 +2495,160 @@ discard block |
||
| 2495 | 2495 | class EE_Admin_Config extends EE_Config_Base |
| 2496 | 2496 | { |
| 2497 | 2497 | |
| 2498 | - /** |
|
| 2499 | - * @var boolean $use_personnel_manager |
|
| 2500 | - */ |
|
| 2501 | - public $use_personnel_manager; |
|
| 2502 | - |
|
| 2503 | - /** |
|
| 2504 | - * @var boolean $use_dashboard_widget |
|
| 2505 | - */ |
|
| 2506 | - public $use_dashboard_widget; |
|
| 2507 | - |
|
| 2508 | - /** |
|
| 2509 | - * @var int $events_in_dashboard |
|
| 2510 | - */ |
|
| 2511 | - public $events_in_dashboard; |
|
| 2512 | - |
|
| 2513 | - /** |
|
| 2514 | - * @var boolean $use_event_timezones |
|
| 2515 | - */ |
|
| 2516 | - public $use_event_timezones; |
|
| 2517 | - |
|
| 2518 | - /** |
|
| 2519 | - * @var boolean $use_full_logging |
|
| 2520 | - */ |
|
| 2521 | - public $use_full_logging; |
|
| 2522 | - |
|
| 2523 | - /** |
|
| 2524 | - * @var string $log_file_name |
|
| 2525 | - */ |
|
| 2526 | - public $log_file_name; |
|
| 2527 | - |
|
| 2528 | - /** |
|
| 2529 | - * @var string $debug_file_name |
|
| 2530 | - */ |
|
| 2531 | - public $debug_file_name; |
|
| 2532 | - |
|
| 2533 | - /** |
|
| 2534 | - * @var boolean $use_remote_logging |
|
| 2535 | - */ |
|
| 2536 | - public $use_remote_logging; |
|
| 2537 | - |
|
| 2538 | - /** |
|
| 2539 | - * @var string $remote_logging_url |
|
| 2540 | - */ |
|
| 2541 | - public $remote_logging_url; |
|
| 2542 | - |
|
| 2543 | - /** |
|
| 2544 | - * @var boolean $show_reg_footer |
|
| 2545 | - */ |
|
| 2546 | - public $show_reg_footer; |
|
| 2547 | - |
|
| 2548 | - /** |
|
| 2549 | - * @var string $affiliate_id |
|
| 2550 | - */ |
|
| 2551 | - public $affiliate_id; |
|
| 2552 | - |
|
| 2553 | - /** |
|
| 2554 | - * help tours on or off (global setting) |
|
| 2555 | - * |
|
| 2556 | - * @var boolean |
|
| 2557 | - */ |
|
| 2558 | - public $help_tour_activation; |
|
| 2559 | - |
|
| 2560 | - /** |
|
| 2561 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2562 | - * but is incompatible with some server configuration errors |
|
| 2563 | - * if you get "500 internal server errors" during registration, try turning this on |
|
| 2564 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2565 | - * |
|
| 2566 | - * @var boolean $encode_session_data |
|
| 2567 | - */ |
|
| 2568 | - private $encode_session_data = false; |
|
| 2569 | - |
|
| 2570 | - |
|
| 2571 | - |
|
| 2572 | - /** |
|
| 2573 | - * class constructor |
|
| 2574 | - * |
|
| 2575 | - * @access public |
|
| 2576 | - */ |
|
| 2577 | - public function __construct() |
|
| 2578 | - { |
|
| 2579 | - // set default general admin settings |
|
| 2580 | - $this->use_personnel_manager = true; |
|
| 2581 | - $this->use_dashboard_widget = true; |
|
| 2582 | - $this->events_in_dashboard = 30; |
|
| 2583 | - $this->use_event_timezones = false; |
|
| 2584 | - $this->use_full_logging = false; |
|
| 2585 | - $this->use_remote_logging = false; |
|
| 2586 | - $this->remote_logging_url = null; |
|
| 2587 | - $this->show_reg_footer = true; |
|
| 2588 | - $this->affiliate_id = 'default'; |
|
| 2589 | - $this->help_tour_activation = true; |
|
| 2590 | - $this->encode_session_data = false; |
|
| 2591 | - } |
|
| 2592 | - |
|
| 2593 | - |
|
| 2594 | - |
|
| 2595 | - /** |
|
| 2596 | - * @param bool $reset |
|
| 2597 | - * @return string |
|
| 2598 | - */ |
|
| 2599 | - public function log_file_name($reset = false) |
|
| 2600 | - { |
|
| 2601 | - if (empty($this->log_file_name) || $reset) { |
|
| 2602 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2603 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2604 | - } |
|
| 2605 | - return $this->log_file_name; |
|
| 2606 | - } |
|
| 2607 | - |
|
| 2608 | - |
|
| 2609 | - |
|
| 2610 | - /** |
|
| 2611 | - * @param bool $reset |
|
| 2612 | - * @return string |
|
| 2613 | - */ |
|
| 2614 | - public function debug_file_name($reset = false) |
|
| 2615 | - { |
|
| 2616 | - if (empty($this->debug_file_name) || $reset) { |
|
| 2617 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2618 | - EE_Config::instance()->update_espresso_config(false, false); |
|
| 2619 | - } |
|
| 2620 | - return $this->debug_file_name; |
|
| 2621 | - } |
|
| 2622 | - |
|
| 2623 | - |
|
| 2624 | - |
|
| 2625 | - /** |
|
| 2626 | - * @return string |
|
| 2627 | - */ |
|
| 2628 | - public function affiliate_id() |
|
| 2629 | - { |
|
| 2630 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2631 | - } |
|
| 2632 | - |
|
| 2633 | - |
|
| 2634 | - |
|
| 2635 | - /** |
|
| 2636 | - * @return boolean |
|
| 2637 | - */ |
|
| 2638 | - public function encode_session_data() |
|
| 2639 | - { |
|
| 2640 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2641 | - } |
|
| 2642 | - |
|
| 2643 | - |
|
| 2644 | - |
|
| 2645 | - /** |
|
| 2646 | - * @param boolean $encode_session_data |
|
| 2647 | - */ |
|
| 2648 | - public function set_encode_session_data($encode_session_data) |
|
| 2649 | - { |
|
| 2650 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2651 | - } |
|
| 2498 | + /** |
|
| 2499 | + * @var boolean $use_personnel_manager |
|
| 2500 | + */ |
|
| 2501 | + public $use_personnel_manager; |
|
| 2502 | + |
|
| 2503 | + /** |
|
| 2504 | + * @var boolean $use_dashboard_widget |
|
| 2505 | + */ |
|
| 2506 | + public $use_dashboard_widget; |
|
| 2507 | + |
|
| 2508 | + /** |
|
| 2509 | + * @var int $events_in_dashboard |
|
| 2510 | + */ |
|
| 2511 | + public $events_in_dashboard; |
|
| 2512 | + |
|
| 2513 | + /** |
|
| 2514 | + * @var boolean $use_event_timezones |
|
| 2515 | + */ |
|
| 2516 | + public $use_event_timezones; |
|
| 2517 | + |
|
| 2518 | + /** |
|
| 2519 | + * @var boolean $use_full_logging |
|
| 2520 | + */ |
|
| 2521 | + public $use_full_logging; |
|
| 2522 | + |
|
| 2523 | + /** |
|
| 2524 | + * @var string $log_file_name |
|
| 2525 | + */ |
|
| 2526 | + public $log_file_name; |
|
| 2527 | + |
|
| 2528 | + /** |
|
| 2529 | + * @var string $debug_file_name |
|
| 2530 | + */ |
|
| 2531 | + public $debug_file_name; |
|
| 2532 | + |
|
| 2533 | + /** |
|
| 2534 | + * @var boolean $use_remote_logging |
|
| 2535 | + */ |
|
| 2536 | + public $use_remote_logging; |
|
| 2537 | + |
|
| 2538 | + /** |
|
| 2539 | + * @var string $remote_logging_url |
|
| 2540 | + */ |
|
| 2541 | + public $remote_logging_url; |
|
| 2542 | + |
|
| 2543 | + /** |
|
| 2544 | + * @var boolean $show_reg_footer |
|
| 2545 | + */ |
|
| 2546 | + public $show_reg_footer; |
|
| 2547 | + |
|
| 2548 | + /** |
|
| 2549 | + * @var string $affiliate_id |
|
| 2550 | + */ |
|
| 2551 | + public $affiliate_id; |
|
| 2552 | + |
|
| 2553 | + /** |
|
| 2554 | + * help tours on or off (global setting) |
|
| 2555 | + * |
|
| 2556 | + * @var boolean |
|
| 2557 | + */ |
|
| 2558 | + public $help_tour_activation; |
|
| 2559 | + |
|
| 2560 | + /** |
|
| 2561 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
| 2562 | + * but is incompatible with some server configuration errors |
|
| 2563 | + * if you get "500 internal server errors" during registration, try turning this on |
|
| 2564 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
| 2565 | + * |
|
| 2566 | + * @var boolean $encode_session_data |
|
| 2567 | + */ |
|
| 2568 | + private $encode_session_data = false; |
|
| 2569 | + |
|
| 2570 | + |
|
| 2571 | + |
|
| 2572 | + /** |
|
| 2573 | + * class constructor |
|
| 2574 | + * |
|
| 2575 | + * @access public |
|
| 2576 | + */ |
|
| 2577 | + public function __construct() |
|
| 2578 | + { |
|
| 2579 | + // set default general admin settings |
|
| 2580 | + $this->use_personnel_manager = true; |
|
| 2581 | + $this->use_dashboard_widget = true; |
|
| 2582 | + $this->events_in_dashboard = 30; |
|
| 2583 | + $this->use_event_timezones = false; |
|
| 2584 | + $this->use_full_logging = false; |
|
| 2585 | + $this->use_remote_logging = false; |
|
| 2586 | + $this->remote_logging_url = null; |
|
| 2587 | + $this->show_reg_footer = true; |
|
| 2588 | + $this->affiliate_id = 'default'; |
|
| 2589 | + $this->help_tour_activation = true; |
|
| 2590 | + $this->encode_session_data = false; |
|
| 2591 | + } |
|
| 2592 | + |
|
| 2593 | + |
|
| 2594 | + |
|
| 2595 | + /** |
|
| 2596 | + * @param bool $reset |
|
| 2597 | + * @return string |
|
| 2598 | + */ |
|
| 2599 | + public function log_file_name($reset = false) |
|
| 2600 | + { |
|
| 2601 | + if (empty($this->log_file_name) || $reset) { |
|
| 2602 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2603 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2604 | + } |
|
| 2605 | + return $this->log_file_name; |
|
| 2606 | + } |
|
| 2607 | + |
|
| 2608 | + |
|
| 2609 | + |
|
| 2610 | + /** |
|
| 2611 | + * @param bool $reset |
|
| 2612 | + * @return string |
|
| 2613 | + */ |
|
| 2614 | + public function debug_file_name($reset = false) |
|
| 2615 | + { |
|
| 2616 | + if (empty($this->debug_file_name) || $reset) { |
|
| 2617 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2618 | + EE_Config::instance()->update_espresso_config(false, false); |
|
| 2619 | + } |
|
| 2620 | + return $this->debug_file_name; |
|
| 2621 | + } |
|
| 2622 | + |
|
| 2623 | + |
|
| 2624 | + |
|
| 2625 | + /** |
|
| 2626 | + * @return string |
|
| 2627 | + */ |
|
| 2628 | + public function affiliate_id() |
|
| 2629 | + { |
|
| 2630 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + |
|
| 2634 | + |
|
| 2635 | + /** |
|
| 2636 | + * @return boolean |
|
| 2637 | + */ |
|
| 2638 | + public function encode_session_data() |
|
| 2639 | + { |
|
| 2640 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2641 | + } |
|
| 2642 | + |
|
| 2643 | + |
|
| 2644 | + |
|
| 2645 | + /** |
|
| 2646 | + * @param boolean $encode_session_data |
|
| 2647 | + */ |
|
| 2648 | + public function set_encode_session_data($encode_session_data) |
|
| 2649 | + { |
|
| 2650 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
| 2651 | + } |
|
| 2652 | 2652 | |
| 2653 | 2653 | |
| 2654 | 2654 | |
@@ -2662,71 +2662,71 @@ discard block |
||
| 2662 | 2662 | class EE_Template_Config extends EE_Config_Base |
| 2663 | 2663 | { |
| 2664 | 2664 | |
| 2665 | - /** |
|
| 2666 | - * @var boolean $enable_default_style |
|
| 2667 | - */ |
|
| 2668 | - public $enable_default_style; |
|
| 2669 | - |
|
| 2670 | - /** |
|
| 2671 | - * @var string $custom_style_sheet |
|
| 2672 | - */ |
|
| 2673 | - public $custom_style_sheet; |
|
| 2674 | - |
|
| 2675 | - /** |
|
| 2676 | - * @var boolean $display_address_in_regform |
|
| 2677 | - */ |
|
| 2678 | - public $display_address_in_regform; |
|
| 2679 | - |
|
| 2680 | - /** |
|
| 2681 | - * @var int $display_description_on_multi_reg_page |
|
| 2682 | - */ |
|
| 2683 | - public $display_description_on_multi_reg_page; |
|
| 2684 | - |
|
| 2685 | - /** |
|
| 2686 | - * @var boolean $use_custom_templates |
|
| 2687 | - */ |
|
| 2688 | - public $use_custom_templates; |
|
| 2689 | - |
|
| 2690 | - /** |
|
| 2691 | - * @var string $current_espresso_theme |
|
| 2692 | - */ |
|
| 2693 | - public $current_espresso_theme; |
|
| 2694 | - |
|
| 2695 | - /** |
|
| 2696 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2697 | - */ |
|
| 2698 | - public $EED_Ticket_Selector; |
|
| 2699 | - |
|
| 2700 | - /** |
|
| 2701 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2702 | - */ |
|
| 2703 | - public $EED_Event_Single; |
|
| 2704 | - |
|
| 2705 | - /** |
|
| 2706 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2707 | - */ |
|
| 2708 | - public $EED_Events_Archive; |
|
| 2709 | - |
|
| 2710 | - |
|
| 2711 | - |
|
| 2712 | - /** |
|
| 2713 | - * class constructor |
|
| 2714 | - * |
|
| 2715 | - * @access public |
|
| 2716 | - */ |
|
| 2717 | - public function __construct() |
|
| 2718 | - { |
|
| 2719 | - // set default template settings |
|
| 2720 | - $this->enable_default_style = true; |
|
| 2721 | - $this->custom_style_sheet = null; |
|
| 2722 | - $this->display_address_in_regform = true; |
|
| 2723 | - $this->display_description_on_multi_reg_page = false; |
|
| 2724 | - $this->use_custom_templates = false; |
|
| 2725 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2726 | - $this->EED_Event_Single = null; |
|
| 2727 | - $this->EED_Events_Archive = null; |
|
| 2728 | - $this->EED_Ticket_Selector = null; |
|
| 2729 | - } |
|
| 2665 | + /** |
|
| 2666 | + * @var boolean $enable_default_style |
|
| 2667 | + */ |
|
| 2668 | + public $enable_default_style; |
|
| 2669 | + |
|
| 2670 | + /** |
|
| 2671 | + * @var string $custom_style_sheet |
|
| 2672 | + */ |
|
| 2673 | + public $custom_style_sheet; |
|
| 2674 | + |
|
| 2675 | + /** |
|
| 2676 | + * @var boolean $display_address_in_regform |
|
| 2677 | + */ |
|
| 2678 | + public $display_address_in_regform; |
|
| 2679 | + |
|
| 2680 | + /** |
|
| 2681 | + * @var int $display_description_on_multi_reg_page |
|
| 2682 | + */ |
|
| 2683 | + public $display_description_on_multi_reg_page; |
|
| 2684 | + |
|
| 2685 | + /** |
|
| 2686 | + * @var boolean $use_custom_templates |
|
| 2687 | + */ |
|
| 2688 | + public $use_custom_templates; |
|
| 2689 | + |
|
| 2690 | + /** |
|
| 2691 | + * @var string $current_espresso_theme |
|
| 2692 | + */ |
|
| 2693 | + public $current_espresso_theme; |
|
| 2694 | + |
|
| 2695 | + /** |
|
| 2696 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
| 2697 | + */ |
|
| 2698 | + public $EED_Ticket_Selector; |
|
| 2699 | + |
|
| 2700 | + /** |
|
| 2701 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
| 2702 | + */ |
|
| 2703 | + public $EED_Event_Single; |
|
| 2704 | + |
|
| 2705 | + /** |
|
| 2706 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
| 2707 | + */ |
|
| 2708 | + public $EED_Events_Archive; |
|
| 2709 | + |
|
| 2710 | + |
|
| 2711 | + |
|
| 2712 | + /** |
|
| 2713 | + * class constructor |
|
| 2714 | + * |
|
| 2715 | + * @access public |
|
| 2716 | + */ |
|
| 2717 | + public function __construct() |
|
| 2718 | + { |
|
| 2719 | + // set default template settings |
|
| 2720 | + $this->enable_default_style = true; |
|
| 2721 | + $this->custom_style_sheet = null; |
|
| 2722 | + $this->display_address_in_regform = true; |
|
| 2723 | + $this->display_description_on_multi_reg_page = false; |
|
| 2724 | + $this->use_custom_templates = false; |
|
| 2725 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
| 2726 | + $this->EED_Event_Single = null; |
|
| 2727 | + $this->EED_Events_Archive = null; |
|
| 2728 | + $this->EED_Ticket_Selector = null; |
|
| 2729 | + } |
|
| 2730 | 2730 | |
| 2731 | 2731 | } |
| 2732 | 2732 | |
@@ -2738,115 +2738,115 @@ discard block |
||
| 2738 | 2738 | class EE_Map_Config extends EE_Config_Base |
| 2739 | 2739 | { |
| 2740 | 2740 | |
| 2741 | - /** |
|
| 2742 | - * @var boolean $use_google_maps |
|
| 2743 | - */ |
|
| 2744 | - public $use_google_maps; |
|
| 2745 | - |
|
| 2746 | - /** |
|
| 2747 | - * @var string $api_key |
|
| 2748 | - */ |
|
| 2749 | - public $google_map_api_key; |
|
| 2750 | - |
|
| 2751 | - /** |
|
| 2752 | - * @var int $event_details_map_width |
|
| 2753 | - */ |
|
| 2754 | - public $event_details_map_width; |
|
| 2755 | - |
|
| 2756 | - /** |
|
| 2757 | - * @var int $event_details_map_height |
|
| 2758 | - */ |
|
| 2759 | - public $event_details_map_height; |
|
| 2760 | - |
|
| 2761 | - /** |
|
| 2762 | - * @var int $event_details_map_zoom |
|
| 2763 | - */ |
|
| 2764 | - public $event_details_map_zoom; |
|
| 2765 | - |
|
| 2766 | - /** |
|
| 2767 | - * @var boolean $event_details_display_nav |
|
| 2768 | - */ |
|
| 2769 | - public $event_details_display_nav; |
|
| 2770 | - |
|
| 2771 | - /** |
|
| 2772 | - * @var boolean $event_details_nav_size |
|
| 2773 | - */ |
|
| 2774 | - public $event_details_nav_size; |
|
| 2775 | - |
|
| 2776 | - /** |
|
| 2777 | - * @var string $event_details_control_type |
|
| 2778 | - */ |
|
| 2779 | - public $event_details_control_type; |
|
| 2780 | - |
|
| 2781 | - /** |
|
| 2782 | - * @var string $event_details_map_align |
|
| 2783 | - */ |
|
| 2784 | - public $event_details_map_align; |
|
| 2785 | - |
|
| 2786 | - /** |
|
| 2787 | - * @var int $event_list_map_width |
|
| 2788 | - */ |
|
| 2789 | - public $event_list_map_width; |
|
| 2790 | - |
|
| 2791 | - /** |
|
| 2792 | - * @var int $event_list_map_height |
|
| 2793 | - */ |
|
| 2794 | - public $event_list_map_height; |
|
| 2795 | - |
|
| 2796 | - /** |
|
| 2797 | - * @var int $event_list_map_zoom |
|
| 2798 | - */ |
|
| 2799 | - public $event_list_map_zoom; |
|
| 2800 | - |
|
| 2801 | - /** |
|
| 2802 | - * @var boolean $event_list_display_nav |
|
| 2803 | - */ |
|
| 2804 | - public $event_list_display_nav; |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * @var boolean $event_list_nav_size |
|
| 2808 | - */ |
|
| 2809 | - public $event_list_nav_size; |
|
| 2810 | - |
|
| 2811 | - /** |
|
| 2812 | - * @var string $event_list_control_type |
|
| 2813 | - */ |
|
| 2814 | - public $event_list_control_type; |
|
| 2815 | - |
|
| 2816 | - /** |
|
| 2817 | - * @var string $event_list_map_align |
|
| 2818 | - */ |
|
| 2819 | - public $event_list_map_align; |
|
| 2820 | - |
|
| 2821 | - |
|
| 2822 | - |
|
| 2823 | - /** |
|
| 2824 | - * class constructor |
|
| 2825 | - * |
|
| 2826 | - * @access public |
|
| 2827 | - */ |
|
| 2828 | - public function __construct() |
|
| 2829 | - { |
|
| 2830 | - // set default map settings |
|
| 2831 | - $this->use_google_maps = true; |
|
| 2832 | - $this->google_map_api_key = ''; |
|
| 2833 | - // for event details pages (reg page) |
|
| 2834 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2835 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2836 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2837 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2838 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2839 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2840 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2841 | - // for event list pages |
|
| 2842 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2843 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2844 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2845 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2846 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2847 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2848 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2849 | - } |
|
| 2741 | + /** |
|
| 2742 | + * @var boolean $use_google_maps |
|
| 2743 | + */ |
|
| 2744 | + public $use_google_maps; |
|
| 2745 | + |
|
| 2746 | + /** |
|
| 2747 | + * @var string $api_key |
|
| 2748 | + */ |
|
| 2749 | + public $google_map_api_key; |
|
| 2750 | + |
|
| 2751 | + /** |
|
| 2752 | + * @var int $event_details_map_width |
|
| 2753 | + */ |
|
| 2754 | + public $event_details_map_width; |
|
| 2755 | + |
|
| 2756 | + /** |
|
| 2757 | + * @var int $event_details_map_height |
|
| 2758 | + */ |
|
| 2759 | + public $event_details_map_height; |
|
| 2760 | + |
|
| 2761 | + /** |
|
| 2762 | + * @var int $event_details_map_zoom |
|
| 2763 | + */ |
|
| 2764 | + public $event_details_map_zoom; |
|
| 2765 | + |
|
| 2766 | + /** |
|
| 2767 | + * @var boolean $event_details_display_nav |
|
| 2768 | + */ |
|
| 2769 | + public $event_details_display_nav; |
|
| 2770 | + |
|
| 2771 | + /** |
|
| 2772 | + * @var boolean $event_details_nav_size |
|
| 2773 | + */ |
|
| 2774 | + public $event_details_nav_size; |
|
| 2775 | + |
|
| 2776 | + /** |
|
| 2777 | + * @var string $event_details_control_type |
|
| 2778 | + */ |
|
| 2779 | + public $event_details_control_type; |
|
| 2780 | + |
|
| 2781 | + /** |
|
| 2782 | + * @var string $event_details_map_align |
|
| 2783 | + */ |
|
| 2784 | + public $event_details_map_align; |
|
| 2785 | + |
|
| 2786 | + /** |
|
| 2787 | + * @var int $event_list_map_width |
|
| 2788 | + */ |
|
| 2789 | + public $event_list_map_width; |
|
| 2790 | + |
|
| 2791 | + /** |
|
| 2792 | + * @var int $event_list_map_height |
|
| 2793 | + */ |
|
| 2794 | + public $event_list_map_height; |
|
| 2795 | + |
|
| 2796 | + /** |
|
| 2797 | + * @var int $event_list_map_zoom |
|
| 2798 | + */ |
|
| 2799 | + public $event_list_map_zoom; |
|
| 2800 | + |
|
| 2801 | + /** |
|
| 2802 | + * @var boolean $event_list_display_nav |
|
| 2803 | + */ |
|
| 2804 | + public $event_list_display_nav; |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * @var boolean $event_list_nav_size |
|
| 2808 | + */ |
|
| 2809 | + public $event_list_nav_size; |
|
| 2810 | + |
|
| 2811 | + /** |
|
| 2812 | + * @var string $event_list_control_type |
|
| 2813 | + */ |
|
| 2814 | + public $event_list_control_type; |
|
| 2815 | + |
|
| 2816 | + /** |
|
| 2817 | + * @var string $event_list_map_align |
|
| 2818 | + */ |
|
| 2819 | + public $event_list_map_align; |
|
| 2820 | + |
|
| 2821 | + |
|
| 2822 | + |
|
| 2823 | + /** |
|
| 2824 | + * class constructor |
|
| 2825 | + * |
|
| 2826 | + * @access public |
|
| 2827 | + */ |
|
| 2828 | + public function __construct() |
|
| 2829 | + { |
|
| 2830 | + // set default map settings |
|
| 2831 | + $this->use_google_maps = true; |
|
| 2832 | + $this->google_map_api_key = ''; |
|
| 2833 | + // for event details pages (reg page) |
|
| 2834 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2835 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2836 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2837 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2838 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2839 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2840 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2841 | + // for event list pages |
|
| 2842 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2843 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2844 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2845 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2846 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2847 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2848 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2849 | + } |
|
| 2850 | 2850 | |
| 2851 | 2851 | } |
| 2852 | 2852 | |
@@ -2858,47 +2858,47 @@ discard block |
||
| 2858 | 2858 | class EE_Events_Archive_Config extends EE_Config_Base |
| 2859 | 2859 | { |
| 2860 | 2860 | |
| 2861 | - public $display_status_banner; |
|
| 2861 | + public $display_status_banner; |
|
| 2862 | 2862 | |
| 2863 | - public $display_description; |
|
| 2863 | + public $display_description; |
|
| 2864 | 2864 | |
| 2865 | - public $display_ticket_selector; |
|
| 2865 | + public $display_ticket_selector; |
|
| 2866 | 2866 | |
| 2867 | - public $display_datetimes; |
|
| 2867 | + public $display_datetimes; |
|
| 2868 | 2868 | |
| 2869 | - public $display_venue; |
|
| 2869 | + public $display_venue; |
|
| 2870 | 2870 | |
| 2871 | - public $display_expired_events; |
|
| 2871 | + public $display_expired_events; |
|
| 2872 | 2872 | |
| 2873 | - public $use_sortable_display_order; |
|
| 2873 | + public $use_sortable_display_order; |
|
| 2874 | 2874 | |
| 2875 | - public $display_order_tickets; |
|
| 2875 | + public $display_order_tickets; |
|
| 2876 | 2876 | |
| 2877 | - public $display_order_datetimes; |
|
| 2877 | + public $display_order_datetimes; |
|
| 2878 | 2878 | |
| 2879 | - public $display_order_event; |
|
| 2879 | + public $display_order_event; |
|
| 2880 | 2880 | |
| 2881 | - public $display_order_venue; |
|
| 2881 | + public $display_order_venue; |
|
| 2882 | 2882 | |
| 2883 | 2883 | |
| 2884 | 2884 | |
| 2885 | - /** |
|
| 2886 | - * class constructor |
|
| 2887 | - */ |
|
| 2888 | - public function __construct() |
|
| 2889 | - { |
|
| 2890 | - $this->display_status_banner = 0; |
|
| 2891 | - $this->display_description = 1; |
|
| 2892 | - $this->display_ticket_selector = 0; |
|
| 2893 | - $this->display_datetimes = 1; |
|
| 2894 | - $this->display_venue = 0; |
|
| 2895 | - $this->display_expired_events = 0; |
|
| 2896 | - $this->use_sortable_display_order = false; |
|
| 2897 | - $this->display_order_tickets = 100; |
|
| 2898 | - $this->display_order_datetimes = 110; |
|
| 2899 | - $this->display_order_event = 120; |
|
| 2900 | - $this->display_order_venue = 130; |
|
| 2901 | - } |
|
| 2885 | + /** |
|
| 2886 | + * class constructor |
|
| 2887 | + */ |
|
| 2888 | + public function __construct() |
|
| 2889 | + { |
|
| 2890 | + $this->display_status_banner = 0; |
|
| 2891 | + $this->display_description = 1; |
|
| 2892 | + $this->display_ticket_selector = 0; |
|
| 2893 | + $this->display_datetimes = 1; |
|
| 2894 | + $this->display_venue = 0; |
|
| 2895 | + $this->display_expired_events = 0; |
|
| 2896 | + $this->use_sortable_display_order = false; |
|
| 2897 | + $this->display_order_tickets = 100; |
|
| 2898 | + $this->display_order_datetimes = 110; |
|
| 2899 | + $this->display_order_event = 120; |
|
| 2900 | + $this->display_order_venue = 130; |
|
| 2901 | + } |
|
| 2902 | 2902 | } |
| 2903 | 2903 | |
| 2904 | 2904 | |
@@ -2909,35 +2909,35 @@ discard block |
||
| 2909 | 2909 | class EE_Event_Single_Config extends EE_Config_Base |
| 2910 | 2910 | { |
| 2911 | 2911 | |
| 2912 | - public $display_status_banner_single; |
|
| 2912 | + public $display_status_banner_single; |
|
| 2913 | 2913 | |
| 2914 | - public $display_venue; |
|
| 2914 | + public $display_venue; |
|
| 2915 | 2915 | |
| 2916 | - public $use_sortable_display_order; |
|
| 2916 | + public $use_sortable_display_order; |
|
| 2917 | 2917 | |
| 2918 | - public $display_order_tickets; |
|
| 2918 | + public $display_order_tickets; |
|
| 2919 | 2919 | |
| 2920 | - public $display_order_datetimes; |
|
| 2920 | + public $display_order_datetimes; |
|
| 2921 | 2921 | |
| 2922 | - public $display_order_event; |
|
| 2922 | + public $display_order_event; |
|
| 2923 | 2923 | |
| 2924 | - public $display_order_venue; |
|
| 2924 | + public $display_order_venue; |
|
| 2925 | 2925 | |
| 2926 | 2926 | |
| 2927 | 2927 | |
| 2928 | - /** |
|
| 2929 | - * class constructor |
|
| 2930 | - */ |
|
| 2931 | - public function __construct() |
|
| 2932 | - { |
|
| 2933 | - $this->display_status_banner_single = 0; |
|
| 2934 | - $this->display_venue = 1; |
|
| 2935 | - $this->use_sortable_display_order = false; |
|
| 2936 | - $this->display_order_tickets = 100; |
|
| 2937 | - $this->display_order_datetimes = 110; |
|
| 2938 | - $this->display_order_event = 120; |
|
| 2939 | - $this->display_order_venue = 130; |
|
| 2940 | - } |
|
| 2928 | + /** |
|
| 2929 | + * class constructor |
|
| 2930 | + */ |
|
| 2931 | + public function __construct() |
|
| 2932 | + { |
|
| 2933 | + $this->display_status_banner_single = 0; |
|
| 2934 | + $this->display_venue = 1; |
|
| 2935 | + $this->use_sortable_display_order = false; |
|
| 2936 | + $this->display_order_tickets = 100; |
|
| 2937 | + $this->display_order_datetimes = 110; |
|
| 2938 | + $this->display_order_event = 120; |
|
| 2939 | + $this->display_order_venue = 130; |
|
| 2940 | + } |
|
| 2941 | 2941 | } |
| 2942 | 2942 | |
| 2943 | 2943 | |
@@ -2948,152 +2948,152 @@ discard block |
||
| 2948 | 2948 | class EE_Ticket_Selector_Config extends EE_Config_Base |
| 2949 | 2949 | { |
| 2950 | 2950 | |
| 2951 | - /** |
|
| 2952 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2953 | - */ |
|
| 2954 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2955 | - |
|
| 2956 | - /** |
|
| 2957 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2958 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2959 | - */ |
|
| 2960 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2961 | - |
|
| 2962 | - /** |
|
| 2963 | - * @var boolean $show_ticket_sale_columns |
|
| 2964 | - */ |
|
| 2965 | - public $show_ticket_sale_columns; |
|
| 2966 | - |
|
| 2967 | - /** |
|
| 2968 | - * @var boolean $show_ticket_details |
|
| 2969 | - */ |
|
| 2970 | - public $show_ticket_details; |
|
| 2971 | - |
|
| 2972 | - /** |
|
| 2973 | - * @var boolean $show_expired_tickets |
|
| 2974 | - */ |
|
| 2975 | - public $show_expired_tickets; |
|
| 2976 | - |
|
| 2977 | - /** |
|
| 2978 | - * whether or not to display a dropdown box populated with event datetimes |
|
| 2979 | - * that toggles which tickets are displayed for a ticket selector. |
|
| 2980 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2981 | - * |
|
| 2982 | - * @var string $show_datetime_selector |
|
| 2983 | - */ |
|
| 2984 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2985 | - |
|
| 2986 | - /** |
|
| 2987 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2988 | - * |
|
| 2989 | - * @var int $datetime_selector_threshold |
|
| 2990 | - */ |
|
| 2991 | - private $datetime_selector_threshold = 3; |
|
| 2992 | - |
|
| 2993 | - |
|
| 2994 | - |
|
| 2995 | - /** |
|
| 2996 | - * class constructor |
|
| 2997 | - */ |
|
| 2998 | - public function __construct() |
|
| 2999 | - { |
|
| 3000 | - $this->show_ticket_sale_columns = true; |
|
| 3001 | - $this->show_ticket_details = true; |
|
| 3002 | - $this->show_expired_tickets = true; |
|
| 3003 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3004 | - $this->datetime_selector_threshold = 3; |
|
| 3005 | - } |
|
| 3006 | - |
|
| 3007 | - |
|
| 3008 | - |
|
| 3009 | - /** |
|
| 3010 | - * returns true if a datetime selector should be displayed |
|
| 3011 | - * |
|
| 3012 | - * @param array $datetimes |
|
| 3013 | - * @return bool |
|
| 3014 | - */ |
|
| 3015 | - public function showDatetimeSelector(array $datetimes) |
|
| 3016 | - { |
|
| 3017 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3018 | - return ! ( |
|
| 3019 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3020 | - || ( |
|
| 3021 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3022 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3023 | - ) |
|
| 3024 | - ); |
|
| 3025 | - } |
|
| 3026 | - |
|
| 3027 | - |
|
| 3028 | - |
|
| 3029 | - /** |
|
| 3030 | - * @return string |
|
| 3031 | - */ |
|
| 3032 | - public function getShowDatetimeSelector() |
|
| 3033 | - { |
|
| 3034 | - return $this->show_datetime_selector; |
|
| 3035 | - } |
|
| 3036 | - |
|
| 3037 | - |
|
| 3038 | - |
|
| 3039 | - /** |
|
| 3040 | - * @param bool $keys_only |
|
| 3041 | - * @return array |
|
| 3042 | - */ |
|
| 3043 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3044 | - { |
|
| 3045 | - return $keys_only |
|
| 3046 | - ? array( |
|
| 3047 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3048 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3049 | - ) |
|
| 3050 | - : array( |
|
| 3051 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3052 | - 'Do not show date & time filter', 'event_espresso' |
|
| 3053 | - ), |
|
| 3054 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3055 | - 'Maybe show date & time filter', 'event_espresso' |
|
| 3056 | - ), |
|
| 3057 | - ); |
|
| 3058 | - } |
|
| 3059 | - |
|
| 3060 | - |
|
| 3061 | - |
|
| 3062 | - /** |
|
| 3063 | - * @param string $show_datetime_selector |
|
| 3064 | - */ |
|
| 3065 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3066 | - { |
|
| 3067 | - $this->show_datetime_selector = in_array( |
|
| 3068 | - $show_datetime_selector, |
|
| 3069 | - $this->getShowDatetimeSelectorOptions(), |
|
| 3070 | - true |
|
| 3071 | - ) |
|
| 3072 | - ? $show_datetime_selector |
|
| 3073 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3074 | - } |
|
| 3075 | - |
|
| 3076 | - |
|
| 3077 | - |
|
| 3078 | - /** |
|
| 3079 | - * @return int |
|
| 3080 | - */ |
|
| 3081 | - public function getDatetimeSelectorThreshold() |
|
| 3082 | - { |
|
| 3083 | - return $this->datetime_selector_threshold; |
|
| 3084 | - } |
|
| 3085 | - |
|
| 3086 | - |
|
| 3087 | - |
|
| 3088 | - |
|
| 3089 | - /** |
|
| 3090 | - * @param int $datetime_selector_threshold |
|
| 3091 | - */ |
|
| 3092 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3093 | - { |
|
| 3094 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3095 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3096 | - } |
|
| 2951 | + /** |
|
| 2952 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
| 2953 | + */ |
|
| 2954 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
| 2955 | + |
|
| 2956 | + /** |
|
| 2957 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
| 2958 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
| 2959 | + */ |
|
| 2960 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
| 2961 | + |
|
| 2962 | + /** |
|
| 2963 | + * @var boolean $show_ticket_sale_columns |
|
| 2964 | + */ |
|
| 2965 | + public $show_ticket_sale_columns; |
|
| 2966 | + |
|
| 2967 | + /** |
|
| 2968 | + * @var boolean $show_ticket_details |
|
| 2969 | + */ |
|
| 2970 | + public $show_ticket_details; |
|
| 2971 | + |
|
| 2972 | + /** |
|
| 2973 | + * @var boolean $show_expired_tickets |
|
| 2974 | + */ |
|
| 2975 | + public $show_expired_tickets; |
|
| 2976 | + |
|
| 2977 | + /** |
|
| 2978 | + * whether or not to display a dropdown box populated with event datetimes |
|
| 2979 | + * that toggles which tickets are displayed for a ticket selector. |
|
| 2980 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
| 2981 | + * |
|
| 2982 | + * @var string $show_datetime_selector |
|
| 2983 | + */ |
|
| 2984 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
| 2985 | + |
|
| 2986 | + /** |
|
| 2987 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
| 2988 | + * |
|
| 2989 | + * @var int $datetime_selector_threshold |
|
| 2990 | + */ |
|
| 2991 | + private $datetime_selector_threshold = 3; |
|
| 2992 | + |
|
| 2993 | + |
|
| 2994 | + |
|
| 2995 | + /** |
|
| 2996 | + * class constructor |
|
| 2997 | + */ |
|
| 2998 | + public function __construct() |
|
| 2999 | + { |
|
| 3000 | + $this->show_ticket_sale_columns = true; |
|
| 3001 | + $this->show_ticket_details = true; |
|
| 3002 | + $this->show_expired_tickets = true; |
|
| 3003 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3004 | + $this->datetime_selector_threshold = 3; |
|
| 3005 | + } |
|
| 3006 | + |
|
| 3007 | + |
|
| 3008 | + |
|
| 3009 | + /** |
|
| 3010 | + * returns true if a datetime selector should be displayed |
|
| 3011 | + * |
|
| 3012 | + * @param array $datetimes |
|
| 3013 | + * @return bool |
|
| 3014 | + */ |
|
| 3015 | + public function showDatetimeSelector(array $datetimes) |
|
| 3016 | + { |
|
| 3017 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
| 3018 | + return ! ( |
|
| 3019 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
| 3020 | + || ( |
|
| 3021 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
| 3022 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
| 3023 | + ) |
|
| 3024 | + ); |
|
| 3025 | + } |
|
| 3026 | + |
|
| 3027 | + |
|
| 3028 | + |
|
| 3029 | + /** |
|
| 3030 | + * @return string |
|
| 3031 | + */ |
|
| 3032 | + public function getShowDatetimeSelector() |
|
| 3033 | + { |
|
| 3034 | + return $this->show_datetime_selector; |
|
| 3035 | + } |
|
| 3036 | + |
|
| 3037 | + |
|
| 3038 | + |
|
| 3039 | + /** |
|
| 3040 | + * @param bool $keys_only |
|
| 3041 | + * @return array |
|
| 3042 | + */ |
|
| 3043 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
| 3044 | + { |
|
| 3045 | + return $keys_only |
|
| 3046 | + ? array( |
|
| 3047 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
| 3048 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
| 3049 | + ) |
|
| 3050 | + : array( |
|
| 3051 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3052 | + 'Do not show date & time filter', 'event_espresso' |
|
| 3053 | + ), |
|
| 3054 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
| 3055 | + 'Maybe show date & time filter', 'event_espresso' |
|
| 3056 | + ), |
|
| 3057 | + ); |
|
| 3058 | + } |
|
| 3059 | + |
|
| 3060 | + |
|
| 3061 | + |
|
| 3062 | + /** |
|
| 3063 | + * @param string $show_datetime_selector |
|
| 3064 | + */ |
|
| 3065 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
| 3066 | + { |
|
| 3067 | + $this->show_datetime_selector = in_array( |
|
| 3068 | + $show_datetime_selector, |
|
| 3069 | + $this->getShowDatetimeSelectorOptions(), |
|
| 3070 | + true |
|
| 3071 | + ) |
|
| 3072 | + ? $show_datetime_selector |
|
| 3073 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
| 3074 | + } |
|
| 3075 | + |
|
| 3076 | + |
|
| 3077 | + |
|
| 3078 | + /** |
|
| 3079 | + * @return int |
|
| 3080 | + */ |
|
| 3081 | + public function getDatetimeSelectorThreshold() |
|
| 3082 | + { |
|
| 3083 | + return $this->datetime_selector_threshold; |
|
| 3084 | + } |
|
| 3085 | + |
|
| 3086 | + |
|
| 3087 | + |
|
| 3088 | + |
|
| 3089 | + /** |
|
| 3090 | + * @param int $datetime_selector_threshold |
|
| 3091 | + */ |
|
| 3092 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
| 3093 | + { |
|
| 3094 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
| 3095 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
| 3096 | + } |
|
| 3097 | 3097 | |
| 3098 | 3098 | |
| 3099 | 3099 | |
@@ -3111,85 +3111,85 @@ discard block |
||
| 3111 | 3111 | class EE_Environment_Config extends EE_Config_Base |
| 3112 | 3112 | { |
| 3113 | 3113 | |
| 3114 | - /** |
|
| 3115 | - * Hold any php environment variables that we want to track. |
|
| 3116 | - * |
|
| 3117 | - * @var stdClass; |
|
| 3118 | - */ |
|
| 3119 | - public $php; |
|
| 3120 | - |
|
| 3121 | - |
|
| 3122 | - |
|
| 3123 | - /** |
|
| 3124 | - * constructor |
|
| 3125 | - */ |
|
| 3126 | - public function __construct() |
|
| 3127 | - { |
|
| 3128 | - $this->php = new stdClass(); |
|
| 3129 | - $this->_set_php_values(); |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - |
|
| 3133 | - |
|
| 3134 | - /** |
|
| 3135 | - * This sets the php environment variables. |
|
| 3136 | - * |
|
| 3137 | - * @since 4.4.0 |
|
| 3138 | - * @return void |
|
| 3139 | - */ |
|
| 3140 | - protected function _set_php_values() |
|
| 3141 | - { |
|
| 3142 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3143 | - $this->php->version = phpversion(); |
|
| 3144 | - } |
|
| 3145 | - |
|
| 3146 | - |
|
| 3147 | - |
|
| 3148 | - /** |
|
| 3149 | - * helper method for determining whether input_count is |
|
| 3150 | - * reaching the potential maximum the server can handle |
|
| 3151 | - * according to max_input_vars |
|
| 3152 | - * |
|
| 3153 | - * @param int $input_count the count of input vars. |
|
| 3154 | - * @return array { |
|
| 3155 | - * An array that represents whether available space and if no available space the error |
|
| 3156 | - * message. |
|
| 3157 | - * @type bool $has_space whether more inputs can be added. |
|
| 3158 | - * @type string $msg Any message to be displayed. |
|
| 3159 | - * } |
|
| 3160 | - */ |
|
| 3161 | - public function max_input_vars_limit_check($input_count = 0) |
|
| 3162 | - { |
|
| 3163 | - if (! empty($this->php->max_input_vars) |
|
| 3164 | - && ($input_count >= $this->php->max_input_vars) |
|
| 3165 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3166 | - ) { |
|
| 3167 | - return sprintf( |
|
| 3168 | - __( |
|
| 3169 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3170 | - 'event_espresso' |
|
| 3171 | - ), |
|
| 3172 | - '<br>', |
|
| 3173 | - $input_count, |
|
| 3174 | - $this->php->max_input_vars |
|
| 3175 | - ); |
|
| 3176 | - } else { |
|
| 3177 | - return ''; |
|
| 3178 | - } |
|
| 3179 | - } |
|
| 3180 | - |
|
| 3181 | - |
|
| 3182 | - |
|
| 3183 | - /** |
|
| 3184 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3185 | - * |
|
| 3186 | - * @since 4.4.1 |
|
| 3187 | - * @return void |
|
| 3188 | - */ |
|
| 3189 | - public function recheck_values() |
|
| 3190 | - { |
|
| 3191 | - $this->_set_php_values(); |
|
| 3192 | - } |
|
| 3114 | + /** |
|
| 3115 | + * Hold any php environment variables that we want to track. |
|
| 3116 | + * |
|
| 3117 | + * @var stdClass; |
|
| 3118 | + */ |
|
| 3119 | + public $php; |
|
| 3120 | + |
|
| 3121 | + |
|
| 3122 | + |
|
| 3123 | + /** |
|
| 3124 | + * constructor |
|
| 3125 | + */ |
|
| 3126 | + public function __construct() |
|
| 3127 | + { |
|
| 3128 | + $this->php = new stdClass(); |
|
| 3129 | + $this->_set_php_values(); |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + |
|
| 3133 | + |
|
| 3134 | + /** |
|
| 3135 | + * This sets the php environment variables. |
|
| 3136 | + * |
|
| 3137 | + * @since 4.4.0 |
|
| 3138 | + * @return void |
|
| 3139 | + */ |
|
| 3140 | + protected function _set_php_values() |
|
| 3141 | + { |
|
| 3142 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
| 3143 | + $this->php->version = phpversion(); |
|
| 3144 | + } |
|
| 3145 | + |
|
| 3146 | + |
|
| 3147 | + |
|
| 3148 | + /** |
|
| 3149 | + * helper method for determining whether input_count is |
|
| 3150 | + * reaching the potential maximum the server can handle |
|
| 3151 | + * according to max_input_vars |
|
| 3152 | + * |
|
| 3153 | + * @param int $input_count the count of input vars. |
|
| 3154 | + * @return array { |
|
| 3155 | + * An array that represents whether available space and if no available space the error |
|
| 3156 | + * message. |
|
| 3157 | + * @type bool $has_space whether more inputs can be added. |
|
| 3158 | + * @type string $msg Any message to be displayed. |
|
| 3159 | + * } |
|
| 3160 | + */ |
|
| 3161 | + public function max_input_vars_limit_check($input_count = 0) |
|
| 3162 | + { |
|
| 3163 | + if (! empty($this->php->max_input_vars) |
|
| 3164 | + && ($input_count >= $this->php->max_input_vars) |
|
| 3165 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
| 3166 | + ) { |
|
| 3167 | + return sprintf( |
|
| 3168 | + __( |
|
| 3169 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
| 3170 | + 'event_espresso' |
|
| 3171 | + ), |
|
| 3172 | + '<br>', |
|
| 3173 | + $input_count, |
|
| 3174 | + $this->php->max_input_vars |
|
| 3175 | + ); |
|
| 3176 | + } else { |
|
| 3177 | + return ''; |
|
| 3178 | + } |
|
| 3179 | + } |
|
| 3180 | + |
|
| 3181 | + |
|
| 3182 | + |
|
| 3183 | + /** |
|
| 3184 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
| 3185 | + * |
|
| 3186 | + * @since 4.4.1 |
|
| 3187 | + * @return void |
|
| 3188 | + */ |
|
| 3189 | + public function recheck_values() |
|
| 3190 | + { |
|
| 3191 | + $this->_set_php_values(); |
|
| 3192 | + } |
|
| 3193 | 3193 | |
| 3194 | 3194 | |
| 3195 | 3195 | |
@@ -3207,22 +3207,22 @@ discard block |
||
| 3207 | 3207 | class EE_Tax_Config extends EE_Config_Base |
| 3208 | 3208 | { |
| 3209 | 3209 | |
| 3210 | - /* |
|
| 3210 | + /* |
|
| 3211 | 3211 | * flag to indicate whether or not to display ticket prices with the taxes included |
| 3212 | 3212 | * |
| 3213 | 3213 | * @var boolean $prices_displayed_including_taxes |
| 3214 | 3214 | */ |
| 3215 | - public $prices_displayed_including_taxes; |
|
| 3215 | + public $prices_displayed_including_taxes; |
|
| 3216 | 3216 | |
| 3217 | 3217 | |
| 3218 | 3218 | |
| 3219 | - /** |
|
| 3220 | - * class constructor |
|
| 3221 | - */ |
|
| 3222 | - public function __construct() |
|
| 3223 | - { |
|
| 3224 | - $this->prices_displayed_including_taxes = true; |
|
| 3225 | - } |
|
| 3219 | + /** |
|
| 3220 | + * class constructor |
|
| 3221 | + */ |
|
| 3222 | + public function __construct() |
|
| 3223 | + { |
|
| 3224 | + $this->prices_displayed_including_taxes = true; |
|
| 3225 | + } |
|
| 3226 | 3226 | } |
| 3227 | 3227 | |
| 3228 | 3228 | |
@@ -3237,17 +3237,17 @@ discard block |
||
| 3237 | 3237 | class EE_Messages_Config extends EE_Config_Base |
| 3238 | 3238 | { |
| 3239 | 3239 | |
| 3240 | - /** |
|
| 3241 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3242 | - * A value of 0 represents never deleting. Default is 0. |
|
| 3243 | - * |
|
| 3244 | - * @var integer |
|
| 3245 | - */ |
|
| 3246 | - public $delete_threshold; |
|
| 3247 | - |
|
| 3248 | - public function __construct() { |
|
| 3249 | - $this->delete_threshold = 0; |
|
| 3250 | - } |
|
| 3240 | + /** |
|
| 3241 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
| 3242 | + * A value of 0 represents never deleting. Default is 0. |
|
| 3243 | + * |
|
| 3244 | + * @var integer |
|
| 3245 | + */ |
|
| 3246 | + public $delete_threshold; |
|
| 3247 | + |
|
| 3248 | + public function __construct() { |
|
| 3249 | + $this->delete_threshold = 0; |
|
| 3250 | + } |
|
| 3251 | 3251 | } |
| 3252 | 3252 | |
| 3253 | 3253 | |
@@ -3259,34 +3259,34 @@ discard block |
||
| 3259 | 3259 | class EE_Gateway_Config extends EE_Config_Base |
| 3260 | 3260 | { |
| 3261 | 3261 | |
| 3262 | - /** |
|
| 3263 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3264 | - * with any config info the gateway wants to store |
|
| 3265 | - * |
|
| 3266 | - * @var array |
|
| 3267 | - */ |
|
| 3268 | - public $payment_settings; |
|
| 3269 | - |
|
| 3270 | - /** |
|
| 3271 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3272 | - * the gateway is stored in the uploads directory |
|
| 3273 | - * |
|
| 3274 | - * @var array |
|
| 3275 | - */ |
|
| 3276 | - public $active_gateways; |
|
| 3277 | - |
|
| 3278 | - |
|
| 3279 | - |
|
| 3280 | - /** |
|
| 3281 | - * class constructor |
|
| 3282 | - * |
|
| 3283 | - * @deprecated |
|
| 3284 | - */ |
|
| 3285 | - public function __construct() |
|
| 3286 | - { |
|
| 3287 | - $this->payment_settings = array(); |
|
| 3288 | - $this->active_gateways = array('Invoice' => false); |
|
| 3289 | - } |
|
| 3262 | + /** |
|
| 3263 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
| 3264 | + * with any config info the gateway wants to store |
|
| 3265 | + * |
|
| 3266 | + * @var array |
|
| 3267 | + */ |
|
| 3268 | + public $payment_settings; |
|
| 3269 | + |
|
| 3270 | + /** |
|
| 3271 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
| 3272 | + * the gateway is stored in the uploads directory |
|
| 3273 | + * |
|
| 3274 | + * @var array |
|
| 3275 | + */ |
|
| 3276 | + public $active_gateways; |
|
| 3277 | + |
|
| 3278 | + |
|
| 3279 | + |
|
| 3280 | + /** |
|
| 3281 | + * class constructor |
|
| 3282 | + * |
|
| 3283 | + * @deprecated |
|
| 3284 | + */ |
|
| 3285 | + public function __construct() |
|
| 3286 | + { |
|
| 3287 | + $this->payment_settings = array(); |
|
| 3288 | + $this->active_gateways = array('Invoice' => false); |
|
| 3289 | + } |
|
| 3290 | 3290 | } |
| 3291 | 3291 | |
| 3292 | 3292 | // End of file EE_Config.core.php |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | public static function instance() |
| 155 | 155 | { |
| 156 | 156 | // check if class object is instantiated, and instantiated properly |
| 157 | - if (! self::$_instance instanceof EE_Config) { |
|
| 157 | + if ( ! self::$_instance instanceof EE_Config) { |
|
| 158 | 158 | self::$_instance = new self(); |
| 159 | 159 | } |
| 160 | 160 | return self::$_instance; |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $this |
| 299 | 299 | ); |
| 300 | 300 | if (is_object($settings) && property_exists($this, $config)) { |
| 301 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
| 301 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings); |
|
| 302 | 302 | //call configs populate method to ensure any defaults are set for empty values. |
| 303 | 303 | if (method_exists($settings, 'populate')) { |
| 304 | 304 | $this->{$config}->populate(); |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | break; |
| 573 | 573 | // TEST #2 : check that settings section exists |
| 574 | 574 | case 2 : |
| 575 | - if (! isset($this->{$section})) { |
|
| 575 | + if ( ! isset($this->{$section})) { |
|
| 576 | 576 | if ($display_errors) { |
| 577 | 577 | throw new EE_Error( |
| 578 | 578 | sprintf( |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | break; |
| 634 | 634 | // TEST #6 : verify config class is accessible |
| 635 | 635 | case 6 : |
| 636 | - if (! class_exists($config_class)) { |
|
| 636 | + if ( ! class_exists($config_class)) { |
|
| 637 | 637 | if ($display_errors) { |
| 638 | 638 | throw new EE_Error( |
| 639 | 639 | sprintf( |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | break; |
| 651 | 651 | // TEST #7 : check that config has even been set |
| 652 | 652 | case 7 : |
| 653 | - if (! isset($this->{$section}->{$name})) { |
|
| 653 | + if ( ! isset($this->{$section}->{$name})) { |
|
| 654 | 654 | if ($display_errors) { |
| 655 | 655 | throw new EE_Error( |
| 656 | 656 | sprintf( |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | break; |
| 669 | 669 | // TEST #8 : check that config is the requested type |
| 670 | 670 | case 8 : |
| 671 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
| 671 | + if ( ! $this->{$section}->{$name} instanceof $config_class) { |
|
| 672 | 672 | if ($display_errors) { |
| 673 | 673 | throw new EE_Error( |
| 674 | 674 | sprintf( |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | break; |
| 688 | 688 | // TEST #9 : verify config object |
| 689 | 689 | case 9 : |
| 690 | - if (! $config_obj instanceof EE_Config_Base) { |
|
| 690 | + if ( ! $config_obj instanceof EE_Config_Base) { |
|
| 691 | 691 | if ($display_errors) { |
| 692 | 692 | throw new EE_Error( |
| 693 | 693 | sprintf( |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | */ |
| 721 | 721 | private function _generate_config_option_name($section = '', $name = '') |
| 722 | 722 | { |
| 723 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 723 | + return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name)); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | { |
| 739 | 739 | return ! empty($config_class) |
| 740 | 740 | ? $config_class |
| 741 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
| 741 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config'; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
@@ -758,17 +758,17 @@ discard block |
||
| 758 | 758 | // ensure config class is set to something |
| 759 | 759 | $config_class = $this->_set_config_class($config_class, $name); |
| 760 | 760 | // run tests 1-4, 6, and 7 to verify all config params are set and valid |
| 761 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 761 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 762 | 762 | return null; |
| 763 | 763 | } |
| 764 | 764 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 765 | 765 | // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
| 766 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 766 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 767 | 767 | $this->_addon_option_names[$config_option_name] = $config_class; |
| 768 | 768 | $this->update_addon_option_names(); |
| 769 | 769 | } |
| 770 | 770 | // verify the incoming config object but suppress errors |
| 771 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 771 | + if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
| 772 | 772 | $config_obj = new $config_class(); |
| 773 | 773 | } |
| 774 | 774 | if (get_option($config_option_name)) { |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | // get class name of the incoming object |
| 817 | 817 | $config_class = get_class($config_obj); |
| 818 | 818 | // run tests 1-5 and 9 to verify config |
| 819 | - if (! $this->_verify_config_params( |
|
| 819 | + if ( ! $this->_verify_config_params( |
|
| 820 | 820 | $section, |
| 821 | 821 | $name, |
| 822 | 822 | $config_class, |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | } |
| 829 | 829 | $config_option_name = $this->_generate_config_option_name($section, $name); |
| 830 | 830 | // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
| 831 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
| 831 | + if ( ! isset($this->_addon_option_names[$config_option_name])) { |
|
| 832 | 832 | // save new config to db |
| 833 | 833 | if ($this->set_config($section, $name, $config_class, $config_obj)) { |
| 834 | 834 | return true; |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | 'event_espresso' |
| 855 | 855 | ), |
| 856 | 856 | $config_class, |
| 857 | - 'EE_Config->' . $section . '->' . $name |
|
| 857 | + 'EE_Config->'.$section.'->'.$name |
|
| 858 | 858 | ), |
| 859 | 859 | __FILE__, |
| 860 | 860 | __FUNCTION__, |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | // ensure config class is set to something |
| 882 | 882 | $config_class = $this->_set_config_class($config_class, $name); |
| 883 | 883 | // run tests 1-4, 6 and 7 to verify that all params have been set |
| 884 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 884 | + if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
| 885 | 885 | return null; |
| 886 | 886 | } |
| 887 | 887 | // now test if the requested config object exists, but suppress errors |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | // retrieve the wp-option for this config class. |
| 928 | 928 | $config_option = maybe_unserialize(get_option($config_option_name, array())); |
| 929 | 929 | if (empty($config_option)) { |
| 930 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
| 930 | + EE_Config::log($config_option_name.'-NOT-FOUND'); |
|
| 931 | 931 | } |
| 932 | 932 | return $config_option; |
| 933 | 933 | } |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | //copy incoming $_REQUEST and sanitize it so we can save it |
| 947 | 947 | $_request = $_REQUEST; |
| 948 | 948 | array_walk_recursive($_request, 'sanitize_text_field'); |
| 949 | - $config_log[(string)microtime(true)] = array( |
|
| 949 | + $config_log[(string) microtime(true)] = array( |
|
| 950 | 950 | 'config_name' => $config_option_name, |
| 951 | 951 | 'request' => $_request, |
| 952 | 952 | ); |
@@ -962,7 +962,7 @@ discard block |
||
| 962 | 962 | */ |
| 963 | 963 | public static function trim_log() |
| 964 | 964 | { |
| 965 | - if (! EE_Config::logging_enabled()) { |
|
| 965 | + if ( ! EE_Config::logging_enabled()) { |
|
| 966 | 966 | return; |
| 967 | 967 | } |
| 968 | 968 | $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
@@ -987,7 +987,7 @@ discard block |
||
| 987 | 987 | public static function get_page_for_posts() |
| 988 | 988 | { |
| 989 | 989 | $page_for_posts = get_option('page_for_posts'); |
| 990 | - if (! $page_for_posts) { |
|
| 990 | + if ( ! $page_for_posts) { |
|
| 991 | 991 | return 'posts'; |
| 992 | 992 | } |
| 993 | 993 | /** @type WPDB $wpdb */ |
@@ -1048,13 +1048,13 @@ discard block |
||
| 1048 | 1048 | ) |
| 1049 | 1049 | ) { |
| 1050 | 1050 | // grab list of installed widgets |
| 1051 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
| 1051 | + $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR); |
|
| 1052 | 1052 | // filter list of modules to register |
| 1053 | 1053 | $widgets_to_register = apply_filters( |
| 1054 | 1054 | 'FHEE__EE_Config__register_widgets__widgets_to_register', |
| 1055 | 1055 | $widgets_to_register |
| 1056 | 1056 | ); |
| 1057 | - if (! empty($widgets_to_register)) { |
|
| 1057 | + if ( ! empty($widgets_to_register)) { |
|
| 1058 | 1058 | // cycle thru widget folders |
| 1059 | 1059 | foreach ($widgets_to_register as $widget_path) { |
| 1060 | 1060 | // add to list of installed widget modules |
@@ -1105,31 +1105,31 @@ discard block |
||
| 1105 | 1105 | // create classname from widget directory name |
| 1106 | 1106 | $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
| 1107 | 1107 | // add class prefix |
| 1108 | - $widget_class = 'EEW_' . $widget; |
|
| 1108 | + $widget_class = 'EEW_'.$widget; |
|
| 1109 | 1109 | // does the widget exist ? |
| 1110 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
| 1110 | + if ( ! is_readable($widget_path.DS.$widget_class.$widget_ext)) { |
|
| 1111 | 1111 | $msg = sprintf( |
| 1112 | 1112 | __( |
| 1113 | 1113 | 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
| 1114 | 1114 | 'event_espresso' |
| 1115 | 1115 | ), |
| 1116 | 1116 | $widget_class, |
| 1117 | - $widget_path . DS . $widget_class . $widget_ext |
|
| 1117 | + $widget_path.DS.$widget_class.$widget_ext |
|
| 1118 | 1118 | ); |
| 1119 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1119 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1120 | 1120 | return; |
| 1121 | 1121 | } |
| 1122 | 1122 | // load the widget class file |
| 1123 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
| 1123 | + require_once($widget_path.DS.$widget_class.$widget_ext); |
|
| 1124 | 1124 | // verify that class exists |
| 1125 | - if (! class_exists($widget_class)) { |
|
| 1125 | + if ( ! class_exists($widget_class)) { |
|
| 1126 | 1126 | $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
| 1127 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1127 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1128 | 1128 | return; |
| 1129 | 1129 | } |
| 1130 | 1130 | register_widget($widget_class); |
| 1131 | 1131 | // add to array of registered widgets |
| 1132 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
| 1132 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path.DS.$widget_class.$widget_ext; |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | |
@@ -1143,19 +1143,19 @@ discard block |
||
| 1143 | 1143 | private function _register_modules() |
| 1144 | 1144 | { |
| 1145 | 1145 | // grab list of installed modules |
| 1146 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
| 1146 | + $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR); |
|
| 1147 | 1147 | // filter list of modules to register |
| 1148 | 1148 | $modules_to_register = apply_filters( |
| 1149 | 1149 | 'FHEE__EE_Config__register_modules__modules_to_register', |
| 1150 | 1150 | $modules_to_register |
| 1151 | 1151 | ); |
| 1152 | - if (! empty($modules_to_register)) { |
|
| 1152 | + if ( ! empty($modules_to_register)) { |
|
| 1153 | 1153 | // loop through folders |
| 1154 | 1154 | foreach ($modules_to_register as $module_path) { |
| 1155 | 1155 | /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
| 1156 | 1156 | if ( |
| 1157 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
| 1158 | - && $module_path !== EE_MODULES . 'gateways' |
|
| 1157 | + $module_path !== EE_MODULES.'zzz-copy-this-module-template' |
|
| 1158 | + && $module_path !== EE_MODULES.'gateways' |
|
| 1159 | 1159 | ) { |
| 1160 | 1160 | // add to list of installed modules |
| 1161 | 1161 | EE_Config::register_module($module_path); |
@@ -1193,25 +1193,25 @@ discard block |
||
| 1193 | 1193 | // remove last segment |
| 1194 | 1194 | array_pop($module_path); |
| 1195 | 1195 | // glue it back together |
| 1196 | - $module_path = implode(DS, $module_path) . DS; |
|
| 1196 | + $module_path = implode(DS, $module_path).DS; |
|
| 1197 | 1197 | // take first segment from file name pieces and sanitize it |
| 1198 | 1198 | $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
| 1199 | 1199 | // ensure class prefix is added |
| 1200 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
| 1200 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module; |
|
| 1201 | 1201 | } else { |
| 1202 | 1202 | // we need to generate the filename based off of the folder name |
| 1203 | 1203 | // grab and sanitize module name |
| 1204 | 1204 | $module = strtolower(basename($module_path)); |
| 1205 | 1205 | $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
| 1206 | 1206 | // like trailingslashit() |
| 1207 | - $module_path = rtrim($module_path, DS) . DS; |
|
| 1207 | + $module_path = rtrim($module_path, DS).DS; |
|
| 1208 | 1208 | // create classname from module directory name |
| 1209 | 1209 | $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
| 1210 | 1210 | // add class prefix |
| 1211 | - $module_class = 'EED_' . $module; |
|
| 1211 | + $module_class = 'EED_'.$module; |
|
| 1212 | 1212 | } |
| 1213 | 1213 | // does the module exist ? |
| 1214 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
| 1214 | + if ( ! is_readable($module_path.DS.$module_class.$module_ext)) { |
|
| 1215 | 1215 | $msg = sprintf( |
| 1216 | 1216 | __( |
| 1217 | 1217 | 'The requested %s module file could not be found or is not readable due to file permissions.', |
@@ -1219,19 +1219,19 @@ discard block |
||
| 1219 | 1219 | ), |
| 1220 | 1220 | $module |
| 1221 | 1221 | ); |
| 1222 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1222 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1223 | 1223 | return false; |
| 1224 | 1224 | } |
| 1225 | 1225 | // load the module class file |
| 1226 | - require_once($module_path . $module_class . $module_ext); |
|
| 1226 | + require_once($module_path.$module_class.$module_ext); |
|
| 1227 | 1227 | // verify that class exists |
| 1228 | - if (! class_exists($module_class)) { |
|
| 1228 | + if ( ! class_exists($module_class)) { |
|
| 1229 | 1229 | $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
| 1230 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1230 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1231 | 1231 | return false; |
| 1232 | 1232 | } |
| 1233 | 1233 | // add to array of registered modules |
| 1234 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
| 1234 | + EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext; |
|
| 1235 | 1235 | do_action( |
| 1236 | 1236 | 'AHEE__EE_Config__register_module__complete', |
| 1237 | 1237 | $module_class, |
@@ -1284,26 +1284,26 @@ discard block |
||
| 1284 | 1284 | { |
| 1285 | 1285 | do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
| 1286 | 1286 | $module = str_replace('EED_', '', $module); |
| 1287 | - $module_class = 'EED_' . $module; |
|
| 1288 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1287 | + $module_class = 'EED_'.$module; |
|
| 1288 | + if ( ! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
| 1289 | 1289 | $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
| 1290 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1290 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1291 | 1291 | return false; |
| 1292 | 1292 | } |
| 1293 | 1293 | if (empty($route)) { |
| 1294 | 1294 | $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
| 1295 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1295 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1296 | 1296 | return false; |
| 1297 | 1297 | } |
| 1298 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
| 1298 | + if ( ! method_exists('EED_'.$module, $method_name)) { |
|
| 1299 | 1299 | $msg = sprintf( |
| 1300 | 1300 | __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
| 1301 | 1301 | $route |
| 1302 | 1302 | ); |
| 1303 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1303 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1304 | 1304 | return false; |
| 1305 | 1305 | } |
| 1306 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
| 1306 | + EE_Config::$_module_route_map[$key][$route] = array('EED_'.$module, $method_name); |
|
| 1307 | 1307 | return true; |
| 1308 | 1308 | } |
| 1309 | 1309 | |
@@ -1320,7 +1320,7 @@ discard block |
||
| 1320 | 1320 | public static function get_route($route = null, $key = 'ee') |
| 1321 | 1321 | { |
| 1322 | 1322 | do_action('AHEE__EE_Config__get_route__begin', $route); |
| 1323 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1323 | + $route = (string) apply_filters('FHEE__EE_Config__get_route', $route); |
|
| 1324 | 1324 | if (isset(EE_Config::$_module_route_map[$key][$route])) { |
| 1325 | 1325 | return EE_Config::$_module_route_map[$key][$route]; |
| 1326 | 1326 | } |
@@ -1356,44 +1356,44 @@ discard block |
||
| 1356 | 1356 | public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
| 1357 | 1357 | { |
| 1358 | 1358 | do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
| 1359 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1359 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1360 | 1360 | $msg = sprintf( |
| 1361 | 1361 | __('The module route %s for this forward has not been registered.', 'event_espresso'), |
| 1362 | 1362 | $route |
| 1363 | 1363 | ); |
| 1364 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1364 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1365 | 1365 | return false; |
| 1366 | 1366 | } |
| 1367 | 1367 | if (empty($forward)) { |
| 1368 | 1368 | $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
| 1369 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1369 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1370 | 1370 | return false; |
| 1371 | 1371 | } |
| 1372 | 1372 | if (is_array($forward)) { |
| 1373 | - if (! isset($forward[1])) { |
|
| 1373 | + if ( ! isset($forward[1])) { |
|
| 1374 | 1374 | $msg = sprintf( |
| 1375 | 1375 | __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
| 1376 | 1376 | $route |
| 1377 | 1377 | ); |
| 1378 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1378 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1379 | 1379 | return false; |
| 1380 | 1380 | } |
| 1381 | - if (! method_exists($forward[0], $forward[1])) { |
|
| 1381 | + if ( ! method_exists($forward[0], $forward[1])) { |
|
| 1382 | 1382 | $msg = sprintf( |
| 1383 | 1383 | __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1384 | 1384 | $forward[1], |
| 1385 | 1385 | $route |
| 1386 | 1386 | ); |
| 1387 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1387 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1388 | 1388 | return false; |
| 1389 | 1389 | } |
| 1390 | - } else if (! function_exists($forward)) { |
|
| 1390 | + } else if ( ! function_exists($forward)) { |
|
| 1391 | 1391 | $msg = sprintf( |
| 1392 | 1392 | __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
| 1393 | 1393 | $forward, |
| 1394 | 1394 | $route |
| 1395 | 1395 | ); |
| 1396 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1396 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1397 | 1397 | return false; |
| 1398 | 1398 | } |
| 1399 | 1399 | EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
@@ -1443,15 +1443,15 @@ discard block |
||
| 1443 | 1443 | public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
| 1444 | 1444 | { |
| 1445 | 1445 | do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
| 1446 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1446 | + if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
| 1447 | 1447 | $msg = sprintf( |
| 1448 | 1448 | __('The module route %s for this view has not been registered.', 'event_espresso'), |
| 1449 | 1449 | $route |
| 1450 | 1450 | ); |
| 1451 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1451 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1452 | 1452 | return false; |
| 1453 | 1453 | } |
| 1454 | - if (! is_readable($view)) { |
|
| 1454 | + if ( ! is_readable($view)) { |
|
| 1455 | 1455 | $msg = sprintf( |
| 1456 | 1456 | __( |
| 1457 | 1457 | 'The %s view file could not be found or is not readable due to file permissions.', |
@@ -1459,7 +1459,7 @@ discard block |
||
| 1459 | 1459 | ), |
| 1460 | 1460 | $view |
| 1461 | 1461 | ); |
| 1462 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1462 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1463 | 1463 | return false; |
| 1464 | 1464 | } |
| 1465 | 1465 | EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
@@ -1567,7 +1567,7 @@ discard block |
||
| 1567 | 1567 | */ |
| 1568 | 1568 | public function get_pretty($property) |
| 1569 | 1569 | { |
| 1570 | - if (! property_exists($this, $property)) { |
|
| 1570 | + if ( ! property_exists($this, $property)) { |
|
| 1571 | 1571 | throw new EE_Error( |
| 1572 | 1572 | sprintf( |
| 1573 | 1573 | __( |
@@ -1806,11 +1806,11 @@ discard block |
||
| 1806 | 1806 | */ |
| 1807 | 1807 | public function reg_page_url() |
| 1808 | 1808 | { |
| 1809 | - if (! $this->reg_page_url) { |
|
| 1809 | + if ( ! $this->reg_page_url) { |
|
| 1810 | 1810 | $this->reg_page_url = add_query_arg( |
| 1811 | 1811 | array('uts' => time()), |
| 1812 | 1812 | get_permalink($this->reg_page_id) |
| 1813 | - ) . '#checkout'; |
|
| 1813 | + ).'#checkout'; |
|
| 1814 | 1814 | } |
| 1815 | 1815 | return $this->reg_page_url; |
| 1816 | 1816 | } |
@@ -1827,7 +1827,7 @@ discard block |
||
| 1827 | 1827 | */ |
| 1828 | 1828 | public function txn_page_url($query_args = array()) |
| 1829 | 1829 | { |
| 1830 | - if (! $this->txn_page_url) { |
|
| 1830 | + if ( ! $this->txn_page_url) { |
|
| 1831 | 1831 | $this->txn_page_url = get_permalink($this->txn_page_id); |
| 1832 | 1832 | } |
| 1833 | 1833 | if ($query_args) { |
@@ -1849,7 +1849,7 @@ discard block |
||
| 1849 | 1849 | */ |
| 1850 | 1850 | public function thank_you_page_url($query_args = array()) |
| 1851 | 1851 | { |
| 1852 | - if (! $this->thank_you_page_url) { |
|
| 1852 | + if ( ! $this->thank_you_page_url) { |
|
| 1853 | 1853 | $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
| 1854 | 1854 | } |
| 1855 | 1855 | if ($query_args) { |
@@ -1869,7 +1869,7 @@ discard block |
||
| 1869 | 1869 | */ |
| 1870 | 1870 | public function cancel_page_url() |
| 1871 | 1871 | { |
| 1872 | - if (! $this->cancel_page_url) { |
|
| 1872 | + if ( ! $this->cancel_page_url) { |
|
| 1873 | 1873 | $this->cancel_page_url = get_permalink($this->cancel_page_id); |
| 1874 | 1874 | } |
| 1875 | 1875 | return $this->cancel_page_url; |
@@ -1914,13 +1914,13 @@ discard block |
||
| 1914 | 1914 | $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
| 1915 | 1915 | $option = 'ee_ueip_optin'; |
| 1916 | 1916 | //set correct table for query |
| 1917 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
| 1917 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options'; |
|
| 1918 | 1918 | //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
| 1919 | 1919 | //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
| 1920 | 1920 | //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
| 1921 | 1921 | //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
| 1922 | 1922 | //for the purpose of caching. |
| 1923 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
| 1923 | + $pre = apply_filters('pre_option_'.$option, false, $option); |
|
| 1924 | 1924 | if (false !== $pre) { |
| 1925 | 1925 | EE_Core_Config::$ee_ueip_option = $pre; |
| 1926 | 1926 | return EE_Core_Config::$ee_ueip_option; |
@@ -1930,9 +1930,9 @@ discard block |
||
| 1930 | 1930 | if (is_object($row)) { |
| 1931 | 1931 | $value = $row->option_value; |
| 1932 | 1932 | } else { //option does not exist so use default. |
| 1933 | - return apply_filters('default_option_' . $option, false, $option); |
|
| 1933 | + return apply_filters('default_option_'.$option, false, $option); |
|
| 1934 | 1934 | } |
| 1935 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
| 1935 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option); |
|
| 1936 | 1936 | return EE_Core_Config::$ee_ueip_option; |
| 1937 | 1937 | } |
| 1938 | 1938 | |
@@ -2195,33 +2195,33 @@ discard block |
||
| 2195 | 2195 | */ |
| 2196 | 2196 | public function __construct($CNT_ISO = '', CountryCurrencyDao $country_currencies = null) |
| 2197 | 2197 | { |
| 2198 | - if(! $country_currencies instanceof CountryCurrencyDao){ |
|
| 2198 | + if ( ! $country_currencies instanceof CountryCurrencyDao) { |
|
| 2199 | 2199 | $country_currencies = new CountryCurrencyDao(); |
| 2200 | 2200 | } |
| 2201 | 2201 | // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
| 2202 | - if (! empty($CNT_ISO)) { |
|
| 2202 | + if ( ! empty($CNT_ISO)) { |
|
| 2203 | 2203 | // retrieve the country settings from the db, just in case they have been customized |
| 2204 | 2204 | $country_currency = $country_currencies->getCountryCurrencyByIsoCode($CNT_ISO); |
| 2205 | - $this->code = $country_currency['CurrencyCode']; // currency code: USD, CAD, EUR |
|
| 2206 | - $this->name = $country_currency['CurrencyNameSingle']; // Dollar |
|
| 2207 | - $this->plural = $country_currency['CurrencyNamePlural']; // Dollars |
|
| 2208 | - $this->sign = $country_currency['CurrencySign']; // currency sign: $ |
|
| 2209 | - $this->sign_b4 = $country_currency['CurrencySignB4']; // currency sign before or after: $TRUE or FALSE$ |
|
| 2210 | - $this->dec_plc = $country_currency['CurrencyDecimalPlaces']; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2211 | - $this->dec_mrk = $country_currency['CurrencyDecimalMark']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2212 | - $this->thsnds = $country_currency['CurrencyThousands']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2205 | + $this->code = $country_currency['CurrencyCode']; // currency code: USD, CAD, EUR |
|
| 2206 | + $this->name = $country_currency['CurrencyNameSingle']; // Dollar |
|
| 2207 | + $this->plural = $country_currency['CurrencyNamePlural']; // Dollars |
|
| 2208 | + $this->sign = $country_currency['CurrencySign']; // currency sign: $ |
|
| 2209 | + $this->sign_b4 = $country_currency['CurrencySignB4']; // currency sign before or after: $TRUE or FALSE$ |
|
| 2210 | + $this->dec_plc = $country_currency['CurrencyDecimalPlaces']; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2211 | + $this->dec_mrk = $country_currency['CurrencyDecimalMark']; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2212 | + $this->thsnds = $country_currency['CurrencyThousands']; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2213 | 2213 | } |
| 2214 | 2214 | // fallback to hardcoded defaults, in case the above failed |
| 2215 | 2215 | if (empty($this->code)) { |
| 2216 | 2216 | // set default currency settings |
| 2217 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2218 | - $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar |
|
| 2219 | - $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars |
|
| 2220 | - $this->sign = '$'; // currency sign: $ |
|
| 2221 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2222 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2223 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2224 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2217 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
| 2218 | + $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar |
|
| 2219 | + $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars |
|
| 2220 | + $this->sign = '$'; // currency sign: $ |
|
| 2221 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
| 2222 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2223 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2224 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2225 | 2225 | } |
| 2226 | 2226 | } |
| 2227 | 2227 | |
@@ -2246,14 +2246,14 @@ discard block |
||
| 2246 | 2246 | } |
| 2247 | 2247 | $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
| 2248 | 2248 | if ($country instanceof EE_Country) { |
| 2249 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2250 | - $this->name = $country->currency_name_single(); // Dollar |
|
| 2251 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2252 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2253 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2254 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2255 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2256 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2249 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
| 2250 | + $this->name = $country->currency_name_single(); // Dollar |
|
| 2251 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
| 2252 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
| 2253 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
| 2254 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
| 2255 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
| 2256 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
| 2257 | 2257 | } |
| 2258 | 2258 | } |
| 2259 | 2259 | } |
@@ -2599,7 +2599,7 @@ discard block |
||
| 2599 | 2599 | public function log_file_name($reset = false) |
| 2600 | 2600 | { |
| 2601 | 2601 | if (empty($this->log_file_name) || $reset) { |
| 2602 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
| 2602 | + $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt'; |
|
| 2603 | 2603 | EE_Config::instance()->update_espresso_config(false, false); |
| 2604 | 2604 | } |
| 2605 | 2605 | return $this->log_file_name; |
@@ -2614,7 +2614,7 @@ discard block |
||
| 2614 | 2614 | public function debug_file_name($reset = false) |
| 2615 | 2615 | { |
| 2616 | 2616 | if (empty($this->debug_file_name) || $reset) { |
| 2617 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
| 2617 | + $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt'; |
|
| 2618 | 2618 | EE_Config::instance()->update_espresso_config(false, false); |
| 2619 | 2619 | } |
| 2620 | 2620 | return $this->debug_file_name; |
@@ -2831,21 +2831,21 @@ discard block |
||
| 2831 | 2831 | $this->use_google_maps = true; |
| 2832 | 2832 | $this->google_map_api_key = ''; |
| 2833 | 2833 | // for event details pages (reg page) |
| 2834 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2835 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2836 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2837 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2838 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2839 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2840 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2834 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
| 2835 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
| 2836 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
| 2837 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
| 2838 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
| 2839 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
| 2840 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
| 2841 | 2841 | // for event list pages |
| 2842 | - $this->event_list_map_width = 300; // ee_map_width |
|
| 2843 | - $this->event_list_map_height = 185; // ee_map_height |
|
| 2844 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2845 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2846 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2847 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2848 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2842 | + $this->event_list_map_width = 300; // ee_map_width |
|
| 2843 | + $this->event_list_map_height = 185; // ee_map_height |
|
| 2844 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
| 2845 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
| 2846 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
| 2847 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
| 2848 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | } |
@@ -3160,7 +3160,7 @@ discard block |
||
| 3160 | 3160 | */ |
| 3161 | 3161 | public function max_input_vars_limit_check($input_count = 0) |
| 3162 | 3162 | { |
| 3163 | - if (! empty($this->php->max_input_vars) |
|
| 3163 | + if ( ! empty($this->php->max_input_vars) |
|
| 3164 | 3164 | && ($input_count >= $this->php->max_input_vars) |
| 3165 | 3165 | && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
| 3166 | 3166 | ) { |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 6 | 6 | |
| 7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -22,817 +22,817 @@ discard block |
||
| 22 | 22 | class EE_Dependency_Map |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * This means that the requested class dependency is not present in the dependency map |
|
| 27 | - */ |
|
| 28 | - const not_registered = 0; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | - */ |
|
| 33 | - const load_new_object = 1; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | - */ |
|
| 39 | - const load_from_cache = 2; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * When registering a dependency, |
|
| 43 | - * this indicates to keep any existing dependencies that already exist, |
|
| 44 | - * and simply discard any new dependencies declared in the incoming data |
|
| 45 | - */ |
|
| 46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * When registering a dependency, |
|
| 50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | - */ |
|
| 52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @type EE_Dependency_Map $_instance |
|
| 58 | - */ |
|
| 59 | - protected static $_instance; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @type EE_Request $request |
|
| 63 | - */ |
|
| 64 | - protected $_request; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @type EE_Response $response |
|
| 68 | - */ |
|
| 69 | - protected $_response; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @type LoaderInterface $loader |
|
| 73 | - */ |
|
| 74 | - protected $loader; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @type array $_dependency_map |
|
| 78 | - */ |
|
| 79 | - protected $_dependency_map = array(); |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @type array $_class_loaders |
|
| 83 | - */ |
|
| 84 | - protected $_class_loaders = array(); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @type array $_aliases |
|
| 88 | - */ |
|
| 89 | - protected $_aliases = array(); |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * EE_Dependency_Map constructor. |
|
| 95 | - * |
|
| 96 | - * @param EE_Request $request |
|
| 97 | - * @param EE_Response $response |
|
| 98 | - */ |
|
| 99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | - { |
|
| 101 | - $this->_request = $request; |
|
| 102 | - $this->_response = $response; |
|
| 103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | - do_action('EE_Dependency_Map____construct'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @throws InvalidDataTypeException |
|
| 111 | - * @throws InvalidInterfaceException |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - */ |
|
| 114 | - public function initialize() |
|
| 115 | - { |
|
| 116 | - $this->_register_core_dependencies(); |
|
| 117 | - $this->_register_core_class_loaders(); |
|
| 118 | - $this->_register_core_aliases(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @singleton method used to instantiate class object |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Request $request |
|
| 127 | - * @param EE_Response $response |
|
| 128 | - * @return EE_Dependency_Map |
|
| 129 | - */ |
|
| 130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | - { |
|
| 132 | - // check if class object is instantiated, and instantiated properly |
|
| 133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | - } |
|
| 136 | - return self::$_instance; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param LoaderInterface $loader |
|
| 143 | - */ |
|
| 144 | - public function setLoader(LoaderInterface $loader) |
|
| 145 | - { |
|
| 146 | - $this->loader = $loader; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $class |
|
| 153 | - * @param array $dependencies |
|
| 154 | - * @param int $overwrite |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public static function register_dependencies( |
|
| 158 | - $class, |
|
| 159 | - array $dependencies, |
|
| 160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | - ) { |
|
| 162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | - * to the class specified by the first parameter. |
|
| 170 | - * IMPORTANT !!! |
|
| 171 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | - * the order of the constructor parameters for the class in question. |
|
| 173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | - * |
|
| 176 | - * @param string $class |
|
| 177 | - * @param array $dependencies |
|
| 178 | - * @param int $overwrite |
|
| 179 | - * @return bool |
|
| 180 | - */ |
|
| 181 | - public function registerDependencies( |
|
| 182 | - $class, |
|
| 183 | - array $dependencies, |
|
| 184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | - ) { |
|
| 186 | - $class = trim($class, '\\'); |
|
| 187 | - $registered = false; |
|
| 188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | - } |
|
| 191 | - // we need to make sure that any aliases used when registering a dependency |
|
| 192 | - // get resolved to the correct class name |
|
| 193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | - $alias = self::$_instance->get_alias($dependency); |
|
| 195 | - if ( |
|
| 196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | - ) { |
|
| 199 | - unset($dependencies[$dependency]); |
|
| 200 | - $dependencies[$alias] = $load_source; |
|
| 201 | - $registered = true; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - // now add our two lists of dependencies together. |
|
| 205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | - // especially with numerically indexed arrays |
|
| 210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | - // now we need to ensure that the resulting dependencies |
|
| 212 | - // array only has the entries that are required for the class |
|
| 213 | - // so first count how many dependencies were originally registered for the class |
|
| 214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | - // then truncate the final array to match that count |
|
| 218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | - // otherwise just take the incoming array because nothing previously existed |
|
| 220 | - : $dependencies; |
|
| 221 | - return $registered; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $class_name |
|
| 228 | - * @param string $loader |
|
| 229 | - * @return bool |
|
| 230 | - * @throws DomainException |
|
| 231 | - */ |
|
| 232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | - { |
|
| 234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | - throw new DomainException( |
|
| 236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | - if ( |
|
| 241 | - ! is_callable($loader) |
|
| 242 | - && ( |
|
| 243 | - strpos($loader, 'load_') !== 0 |
|
| 244 | - || ! method_exists('EE_Registry', $loader) |
|
| 245 | - ) |
|
| 246 | - ) { |
|
| 247 | - throw new DomainException( |
|
| 248 | - sprintf( |
|
| 249 | - esc_html__( |
|
| 250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | - 'event_espresso' |
|
| 252 | - ), |
|
| 253 | - $loader |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | - return true; |
|
| 261 | - } |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - public function dependency_map() |
|
| 271 | - { |
|
| 272 | - return $this->_dependency_map; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | - * |
|
| 280 | - * @param string $class_name |
|
| 281 | - * @return boolean |
|
| 282 | - */ |
|
| 283 | - public function has($class_name = '') |
|
| 284 | - { |
|
| 285 | - // all legacy models have the same dependencies |
|
| 286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | - $class_name = 'LEGACY_MODELS'; |
|
| 288 | - } |
|
| 289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | - * |
|
| 297 | - * @param string $class_name |
|
| 298 | - * @param string $dependency |
|
| 299 | - * @return bool |
|
| 300 | - */ |
|
| 301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | - { |
|
| 303 | - // all legacy models have the same dependencies |
|
| 304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | - $class_name = 'LEGACY_MODELS'; |
|
| 306 | - } |
|
| 307 | - $dependency = $this->get_alias($dependency); |
|
| 308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | - ? true |
|
| 310 | - : false; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | - * |
|
| 318 | - * @param string $class_name |
|
| 319 | - * @param string $dependency |
|
| 320 | - * @return int |
|
| 321 | - */ |
|
| 322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | - { |
|
| 324 | - // all legacy models have the same dependencies |
|
| 325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | - $class_name = 'LEGACY_MODELS'; |
|
| 327 | - } |
|
| 328 | - $dependency = $this->get_alias($dependency); |
|
| 329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | - : EE_Dependency_Map::not_registered; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param string $class_name |
|
| 338 | - * @return string | Closure |
|
| 339 | - */ |
|
| 340 | - public function class_loader($class_name) |
|
| 341 | - { |
|
| 342 | - // all legacy models use load_model() |
|
| 343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | - return 'load_model'; |
|
| 345 | - } |
|
| 346 | - $class_name = $this->get_alias($class_name); |
|
| 347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @return array |
|
| 354 | - */ |
|
| 355 | - public function class_loaders() |
|
| 356 | - { |
|
| 357 | - return $this->_class_loaders; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * adds an alias for a classname |
|
| 364 | - * |
|
| 365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | - */ |
|
| 369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | - { |
|
| 371 | - if ($for_class !== '') { |
|
| 372 | - if (! isset($this->_aliases[$for_class])) { |
|
| 373 | - $this->_aliases[$for_class] = array(); |
|
| 374 | - } |
|
| 375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | - } |
|
| 377 | - $this->_aliases[$class_name] = $alias; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * returns TRUE if the provided class name has an alias |
|
| 384 | - * |
|
| 385 | - * @param string $class_name |
|
| 386 | - * @param string $for_class |
|
| 387 | - * @return bool |
|
| 388 | - */ |
|
| 389 | - public function has_alias($class_name = '', $for_class = '') |
|
| 390 | - { |
|
| 391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | - || ( |
|
| 393 | - isset($this->_aliases[$class_name]) |
|
| 394 | - && ! is_array($this->_aliases[$class_name]) |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | - * for example: |
|
| 404 | - * if the following two entries were added to the _aliases array: |
|
| 405 | - * array( |
|
| 406 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | - * ) |
|
| 409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | - * to load an instance of 'some\namespace\classname' |
|
| 411 | - * |
|
| 412 | - * @param string $class_name |
|
| 413 | - * @param string $for_class |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 416 | - public function get_alias($class_name = '', $for_class = '') |
|
| 417 | - { |
|
| 418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | - return $class_name; |
|
| 420 | - } |
|
| 421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | - } |
|
| 424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | - * This is done by using the following class constants: |
|
| 433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | - */ |
|
| 436 | - protected function _register_core_dependencies() |
|
| 437 | - { |
|
| 438 | - $this->_dependency_map = array( |
|
| 439 | - 'EE_Request_Handler' => array( |
|
| 440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | - ), |
|
| 442 | - 'EE_System' => array( |
|
| 443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | - ), |
|
| 449 | - 'EE_Session' => array( |
|
| 450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | - ), |
|
| 453 | - 'EE_Cart' => array( |
|
| 454 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | - ), |
|
| 456 | - 'EE_Front_Controller' => array( |
|
| 457 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - ), |
|
| 461 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | - ), |
|
| 464 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | - ), |
|
| 467 | - 'EE_Message_Resource_Manager' => array( |
|
| 468 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | - ), |
|
| 472 | - 'EE_Message_Factory' => array( |
|
| 473 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | - ), |
|
| 475 | - 'EE_messages' => array( |
|
| 476 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | - ), |
|
| 478 | - 'EE_Messages_Generator' => array( |
|
| 479 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - ), |
|
| 484 | - 'EE_Messages_Processor' => array( |
|
| 485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EE_Messages_Queue' => array( |
|
| 488 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | - ), |
|
| 490 | - 'EE_Messages_Template_Defaults' => array( |
|
| 491 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | - ), |
|
| 494 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | - ), |
|
| 498 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | - ), |
|
| 501 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | - ), |
|
| 505 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | - ), |
|
| 508 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | - ), |
|
| 512 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | - ), |
|
| 515 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | - ), |
|
| 518 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - ), |
|
| 536 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | - ), |
|
| 558 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | - ), |
|
| 562 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - ), |
|
| 566 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - ), |
|
| 570 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - ), |
|
| 574 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - ), |
|
| 578 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | - ), |
|
| 582 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - ), |
|
| 586 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | - ), |
|
| 590 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | - ), |
|
| 594 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - ), |
|
| 598 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | - ), |
|
| 601 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | - ), |
|
| 604 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - ), |
|
| 607 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | - ), |
|
| 610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | - ), |
|
| 613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ), |
|
| 616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - ), |
|
| 619 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - ), |
|
| 622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - ), |
|
| 625 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | - ), |
|
| 629 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | - null, |
|
| 631 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | - ), |
|
| 633 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | - ), |
|
| 636 | - 'LEGACY_MODELS' => array( |
|
| 637 | - null, |
|
| 638 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | - ), |
|
| 640 | - 'EE_Module_Request_Router' => array( |
|
| 641 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ), |
|
| 643 | - 'EE_Registration_Processor' => array( |
|
| 644 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 645 | - ), |
|
| 646 | - 'EventEspresso\core\services\currency\CurrencyFactory' => array( |
|
| 647 | - 'EventEspresso\core\services\currency\CountryCurrencyDao' => EE_Dependency_Map::load_from_cache, |
|
| 648 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
| 649 | - ), |
|
| 650 | - 'EventEspresso\core\services\currency\MoneyFactory' => array( |
|
| 651 | - 'EventEspresso\core\services\currency\CurrencyFactory' => EE_Dependency_Map::load_from_cache, |
|
| 652 | - 'EventEspresso\core\services\currency\Calculator' => EE_Dependency_Map::load_from_cache, |
|
| 653 | - ), |
|
| 654 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 655 | - null, |
|
| 656 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 657 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 658 | - ), |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - |
|
| 664 | - /** |
|
| 665 | - * Registers how core classes are loaded. |
|
| 666 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 667 | - * 'EE_Request_Handler' => 'load_core' |
|
| 668 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 669 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 670 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 671 | - * 'Some_Class' => function () { |
|
| 672 | - * return new Some_Class(); |
|
| 673 | - * }, |
|
| 674 | - * This is required for instantiating dependencies |
|
| 675 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 676 | - * 'Required_Interface' => function () { |
|
| 677 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 678 | - * }, |
|
| 679 | - * |
|
| 680 | - * @throws InvalidInterfaceException |
|
| 681 | - * @throws InvalidDataTypeException |
|
| 682 | - * @throws InvalidArgumentException |
|
| 683 | - */ |
|
| 684 | - protected function _register_core_class_loaders() |
|
| 685 | - { |
|
| 686 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 687 | - //be used in a closure. |
|
| 688 | - $request = &$this->_request; |
|
| 689 | - $response = &$this->_response; |
|
| 690 | - // $loader = &$this->loader; |
|
| 691 | - $this->_class_loaders = array( |
|
| 692 | - //load_core |
|
| 693 | - 'EE_Capabilities' => 'load_core', |
|
| 694 | - 'EE_Encryption' => 'load_core', |
|
| 695 | - 'EE_Front_Controller' => 'load_core', |
|
| 696 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 697 | - 'EE_Registry' => 'load_core', |
|
| 698 | - 'EE_Request' => function () use (&$request) { |
|
| 699 | - return $request; |
|
| 700 | - }, |
|
| 701 | - 'EE_Response' => function () use (&$response) { |
|
| 702 | - return $response; |
|
| 703 | - }, |
|
| 704 | - 'EE_Request_Handler' => 'load_core', |
|
| 705 | - 'EE_Session' => 'load_core', |
|
| 706 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 707 | - 'EE_System' => 'load_core', |
|
| 708 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 709 | - 'EE_Register_CPTs' => 'load_core', |
|
| 710 | - 'EE_Admin' => 'load_core', |
|
| 711 | - //load_lib |
|
| 712 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 713 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 714 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 715 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 716 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 717 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 718 | - 'EE_Message_Repository' => 'load_lib', |
|
| 719 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 720 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 721 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 722 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 723 | - 'EE_Messages_Generator' => function () { |
|
| 724 | - return EE_Registry::instance()->load_lib( |
|
| 725 | - 'Messages_Generator', |
|
| 726 | - array(), |
|
| 727 | - false, |
|
| 728 | - false |
|
| 729 | - ); |
|
| 730 | - }, |
|
| 731 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 732 | - return EE_Registry::instance()->load_lib( |
|
| 733 | - 'Messages_Template_Defaults', |
|
| 734 | - $arguments, |
|
| 735 | - false, |
|
| 736 | - false |
|
| 737 | - ); |
|
| 738 | - }, |
|
| 739 | - //load_model |
|
| 740 | - // 'EEM_Attendee' => 'load_model', |
|
| 741 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
| 742 | - // 'EEM_Message_Template' => 'load_model', |
|
| 743 | - //load_helper |
|
| 744 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 745 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 746 | - return new EEH_Parse_Shortcodes(); |
|
| 747 | - } |
|
| 748 | - return null; |
|
| 749 | - }, |
|
| 750 | - 'EE_Template_Config' => function () { |
|
| 751 | - return EE_Config::instance()->template_settings; |
|
| 752 | - }, |
|
| 753 | - 'EE_Currency_Config' => function () { |
|
| 754 | - return EE_Config::instance()->currency; |
|
| 755 | - }, |
|
| 756 | - 'EE_Registration_Config' => function () { |
|
| 757 | - return EE_Config::instance()->registration; |
|
| 758 | - }, |
|
| 759 | - 'EE_Organization_Config' => function () { |
|
| 760 | - return EE_Config::instance()->organization; |
|
| 761 | - }, |
|
| 762 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 763 | - return LoaderFactory::getLoader(); |
|
| 764 | - }, |
|
| 765 | - ); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * can be used for supplying alternate names for classes, |
|
| 772 | - * or for connecting interface names to instantiable classes |
|
| 773 | - */ |
|
| 774 | - protected function _register_core_aliases() |
|
| 775 | - { |
|
| 776 | - $this->_aliases = array( |
|
| 777 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 778 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 779 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 780 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 781 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 782 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 783 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 784 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 785 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 786 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 787 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 788 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 789 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 790 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 791 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 792 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 793 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 794 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 795 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 796 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 797 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 798 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 799 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 800 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 801 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 802 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 803 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 804 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 805 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 806 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 807 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 808 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 809 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 810 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 811 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 812 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 813 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 814 | - 'EventEspresso\core\services\currency\Calculator' => 'EventEspresso\core\services\currency\DefaultCalculator', |
|
| 815 | - ); |
|
| 816 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 817 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 825 | - * request Primarily used by unit tests. |
|
| 826 | - * |
|
| 827 | - * @throws InvalidDataTypeException |
|
| 828 | - * @throws InvalidInterfaceException |
|
| 829 | - * @throws InvalidArgumentException |
|
| 830 | - */ |
|
| 831 | - public function reset() |
|
| 832 | - { |
|
| 833 | - $this->_register_core_class_loaders(); |
|
| 834 | - $this->_register_core_dependencies(); |
|
| 835 | - } |
|
| 25 | + /** |
|
| 26 | + * This means that the requested class dependency is not present in the dependency map |
|
| 27 | + */ |
|
| 28 | + const not_registered = 0; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 32 | + */ |
|
| 33 | + const load_new_object = 1; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 38 | + */ |
|
| 39 | + const load_from_cache = 2; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * When registering a dependency, |
|
| 43 | + * this indicates to keep any existing dependencies that already exist, |
|
| 44 | + * and simply discard any new dependencies declared in the incoming data |
|
| 45 | + */ |
|
| 46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * When registering a dependency, |
|
| 50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 51 | + */ |
|
| 52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @type EE_Dependency_Map $_instance |
|
| 58 | + */ |
|
| 59 | + protected static $_instance; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @type EE_Request $request |
|
| 63 | + */ |
|
| 64 | + protected $_request; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @type EE_Response $response |
|
| 68 | + */ |
|
| 69 | + protected $_response; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @type LoaderInterface $loader |
|
| 73 | + */ |
|
| 74 | + protected $loader; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @type array $_dependency_map |
|
| 78 | + */ |
|
| 79 | + protected $_dependency_map = array(); |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @type array $_class_loaders |
|
| 83 | + */ |
|
| 84 | + protected $_class_loaders = array(); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @type array $_aliases |
|
| 88 | + */ |
|
| 89 | + protected $_aliases = array(); |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * EE_Dependency_Map constructor. |
|
| 95 | + * |
|
| 96 | + * @param EE_Request $request |
|
| 97 | + * @param EE_Response $response |
|
| 98 | + */ |
|
| 99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
| 100 | + { |
|
| 101 | + $this->_request = $request; |
|
| 102 | + $this->_response = $response; |
|
| 103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 104 | + do_action('EE_Dependency_Map____construct'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @throws InvalidDataTypeException |
|
| 111 | + * @throws InvalidInterfaceException |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + */ |
|
| 114 | + public function initialize() |
|
| 115 | + { |
|
| 116 | + $this->_register_core_dependencies(); |
|
| 117 | + $this->_register_core_class_loaders(); |
|
| 118 | + $this->_register_core_aliases(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @singleton method used to instantiate class object |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Request $request |
|
| 127 | + * @param EE_Response $response |
|
| 128 | + * @return EE_Dependency_Map |
|
| 129 | + */ |
|
| 130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
| 131 | + { |
|
| 132 | + // check if class object is instantiated, and instantiated properly |
|
| 133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
| 134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
| 135 | + } |
|
| 136 | + return self::$_instance; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param LoaderInterface $loader |
|
| 143 | + */ |
|
| 144 | + public function setLoader(LoaderInterface $loader) |
|
| 145 | + { |
|
| 146 | + $this->loader = $loader; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $class |
|
| 153 | + * @param array $dependencies |
|
| 154 | + * @param int $overwrite |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public static function register_dependencies( |
|
| 158 | + $class, |
|
| 159 | + array $dependencies, |
|
| 160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 161 | + ) { |
|
| 162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 169 | + * to the class specified by the first parameter. |
|
| 170 | + * IMPORTANT !!! |
|
| 171 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 172 | + * the order of the constructor parameters for the class in question. |
|
| 173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 175 | + * |
|
| 176 | + * @param string $class |
|
| 177 | + * @param array $dependencies |
|
| 178 | + * @param int $overwrite |
|
| 179 | + * @return bool |
|
| 180 | + */ |
|
| 181 | + public function registerDependencies( |
|
| 182 | + $class, |
|
| 183 | + array $dependencies, |
|
| 184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 185 | + ) { |
|
| 186 | + $class = trim($class, '\\'); |
|
| 187 | + $registered = false; |
|
| 188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 190 | + } |
|
| 191 | + // we need to make sure that any aliases used when registering a dependency |
|
| 192 | + // get resolved to the correct class name |
|
| 193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
| 194 | + $alias = self::$_instance->get_alias($dependency); |
|
| 195 | + if ( |
|
| 196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 198 | + ) { |
|
| 199 | + unset($dependencies[$dependency]); |
|
| 200 | + $dependencies[$alias] = $load_source; |
|
| 201 | + $registered = true; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + // now add our two lists of dependencies together. |
|
| 205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 206 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 208 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 209 | + // especially with numerically indexed arrays |
|
| 210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 211 | + // now we need to ensure that the resulting dependencies |
|
| 212 | + // array only has the entries that are required for the class |
|
| 213 | + // so first count how many dependencies were originally registered for the class |
|
| 214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 217 | + // then truncate the final array to match that count |
|
| 218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 219 | + // otherwise just take the incoming array because nothing previously existed |
|
| 220 | + : $dependencies; |
|
| 221 | + return $registered; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $class_name |
|
| 228 | + * @param string $loader |
|
| 229 | + * @return bool |
|
| 230 | + * @throws DomainException |
|
| 231 | + */ |
|
| 232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 233 | + { |
|
| 234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 235 | + throw new DomainException( |
|
| 236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 240 | + if ( |
|
| 241 | + ! is_callable($loader) |
|
| 242 | + && ( |
|
| 243 | + strpos($loader, 'load_') !== 0 |
|
| 244 | + || ! method_exists('EE_Registry', $loader) |
|
| 245 | + ) |
|
| 246 | + ) { |
|
| 247 | + throw new DomainException( |
|
| 248 | + sprintf( |
|
| 249 | + esc_html__( |
|
| 250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 251 | + 'event_espresso' |
|
| 252 | + ), |
|
| 253 | + $loader |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + $class_name = self::$_instance->get_alias($class_name); |
|
| 258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
| 259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
| 260 | + return true; |
|
| 261 | + } |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + public function dependency_map() |
|
| 271 | + { |
|
| 272 | + return $this->_dependency_map; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 279 | + * |
|
| 280 | + * @param string $class_name |
|
| 281 | + * @return boolean |
|
| 282 | + */ |
|
| 283 | + public function has($class_name = '') |
|
| 284 | + { |
|
| 285 | + // all legacy models have the same dependencies |
|
| 286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 287 | + $class_name = 'LEGACY_MODELS'; |
|
| 288 | + } |
|
| 289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 296 | + * |
|
| 297 | + * @param string $class_name |
|
| 298 | + * @param string $dependency |
|
| 299 | + * @return bool |
|
| 300 | + */ |
|
| 301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 302 | + { |
|
| 303 | + // all legacy models have the same dependencies |
|
| 304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 305 | + $class_name = 'LEGACY_MODELS'; |
|
| 306 | + } |
|
| 307 | + $dependency = $this->get_alias($dependency); |
|
| 308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
| 309 | + ? true |
|
| 310 | + : false; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 317 | + * |
|
| 318 | + * @param string $class_name |
|
| 319 | + * @param string $dependency |
|
| 320 | + * @return int |
|
| 321 | + */ |
|
| 322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 323 | + { |
|
| 324 | + // all legacy models have the same dependencies |
|
| 325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 326 | + $class_name = 'LEGACY_MODELS'; |
|
| 327 | + } |
|
| 328 | + $dependency = $this->get_alias($dependency); |
|
| 329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
| 331 | + : EE_Dependency_Map::not_registered; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param string $class_name |
|
| 338 | + * @return string | Closure |
|
| 339 | + */ |
|
| 340 | + public function class_loader($class_name) |
|
| 341 | + { |
|
| 342 | + // all legacy models use load_model() |
|
| 343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
| 344 | + return 'load_model'; |
|
| 345 | + } |
|
| 346 | + $class_name = $this->get_alias($class_name); |
|
| 347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @return array |
|
| 354 | + */ |
|
| 355 | + public function class_loaders() |
|
| 356 | + { |
|
| 357 | + return $this->_class_loaders; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * adds an alias for a classname |
|
| 364 | + * |
|
| 365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
| 366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 368 | + */ |
|
| 369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
| 370 | + { |
|
| 371 | + if ($for_class !== '') { |
|
| 372 | + if (! isset($this->_aliases[$for_class])) { |
|
| 373 | + $this->_aliases[$for_class] = array(); |
|
| 374 | + } |
|
| 375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
| 376 | + } |
|
| 377 | + $this->_aliases[$class_name] = $alias; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * returns TRUE if the provided class name has an alias |
|
| 384 | + * |
|
| 385 | + * @param string $class_name |
|
| 386 | + * @param string $for_class |
|
| 387 | + * @return bool |
|
| 388 | + */ |
|
| 389 | + public function has_alias($class_name = '', $for_class = '') |
|
| 390 | + { |
|
| 391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
| 392 | + || ( |
|
| 393 | + isset($this->_aliases[$class_name]) |
|
| 394 | + && ! is_array($this->_aliases[$class_name]) |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
| 402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
| 403 | + * for example: |
|
| 404 | + * if the following two entries were added to the _aliases array: |
|
| 405 | + * array( |
|
| 406 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 408 | + * ) |
|
| 409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 410 | + * to load an instance of 'some\namespace\classname' |
|
| 411 | + * |
|
| 412 | + * @param string $class_name |
|
| 413 | + * @param string $for_class |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | + public function get_alias($class_name = '', $for_class = '') |
|
| 417 | + { |
|
| 418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
| 419 | + return $class_name; |
|
| 420 | + } |
|
| 421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
| 422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
| 423 | + } |
|
| 424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 432 | + * This is done by using the following class constants: |
|
| 433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 435 | + */ |
|
| 436 | + protected function _register_core_dependencies() |
|
| 437 | + { |
|
| 438 | + $this->_dependency_map = array( |
|
| 439 | + 'EE_Request_Handler' => array( |
|
| 440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 441 | + ), |
|
| 442 | + 'EE_System' => array( |
|
| 443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 448 | + ), |
|
| 449 | + 'EE_Session' => array( |
|
| 450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 451 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 452 | + ), |
|
| 453 | + 'EE_Cart' => array( |
|
| 454 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 455 | + ), |
|
| 456 | + 'EE_Front_Controller' => array( |
|
| 457 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 458 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + ), |
|
| 461 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 462 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 463 | + ), |
|
| 464 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 465 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 466 | + ), |
|
| 467 | + 'EE_Message_Resource_Manager' => array( |
|
| 468 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 469 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 470 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 471 | + ), |
|
| 472 | + 'EE_Message_Factory' => array( |
|
| 473 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 474 | + ), |
|
| 475 | + 'EE_messages' => array( |
|
| 476 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 477 | + ), |
|
| 478 | + 'EE_Messages_Generator' => array( |
|
| 479 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 480 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 481 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 482 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + ), |
|
| 484 | + 'EE_Messages_Processor' => array( |
|
| 485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EE_Messages_Queue' => array( |
|
| 488 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 489 | + ), |
|
| 490 | + 'EE_Messages_Template_Defaults' => array( |
|
| 491 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 493 | + ), |
|
| 494 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 496 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 497 | + ), |
|
| 498 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 499 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 500 | + ), |
|
| 501 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 502 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 503 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 504 | + ), |
|
| 505 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 506 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 507 | + ), |
|
| 508 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 509 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 510 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 511 | + ), |
|
| 512 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 513 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 514 | + ), |
|
| 515 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 517 | + ), |
|
| 518 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 519 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 522 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 528 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 531 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 534 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + ), |
|
| 536 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 537 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 540 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 546 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 549 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 552 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 557 | + ), |
|
| 558 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 561 | + ), |
|
| 562 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + ), |
|
| 566 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + ), |
|
| 570 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + ), |
|
| 574 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + ), |
|
| 578 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 581 | + ), |
|
| 582 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + ), |
|
| 586 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 589 | + ), |
|
| 590 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 593 | + ), |
|
| 594 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 595 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 596 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + ), |
|
| 598 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 599 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 600 | + ), |
|
| 601 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 602 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 603 | + ), |
|
| 604 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + ), |
|
| 607 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 608 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 609 | + ), |
|
| 610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 612 | + ), |
|
| 613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ), |
|
| 616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + ), |
|
| 619 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 620 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + ), |
|
| 622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + ), |
|
| 625 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 626 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 628 | + ), |
|
| 629 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 630 | + null, |
|
| 631 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 632 | + ), |
|
| 633 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 635 | + ), |
|
| 636 | + 'LEGACY_MODELS' => array( |
|
| 637 | + null, |
|
| 638 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 639 | + ), |
|
| 640 | + 'EE_Module_Request_Router' => array( |
|
| 641 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ), |
|
| 643 | + 'EE_Registration_Processor' => array( |
|
| 644 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 645 | + ), |
|
| 646 | + 'EventEspresso\core\services\currency\CurrencyFactory' => array( |
|
| 647 | + 'EventEspresso\core\services\currency\CountryCurrencyDao' => EE_Dependency_Map::load_from_cache, |
|
| 648 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
| 649 | + ), |
|
| 650 | + 'EventEspresso\core\services\currency\MoneyFactory' => array( |
|
| 651 | + 'EventEspresso\core\services\currency\CurrencyFactory' => EE_Dependency_Map::load_from_cache, |
|
| 652 | + 'EventEspresso\core\services\currency\Calculator' => EE_Dependency_Map::load_from_cache, |
|
| 653 | + ), |
|
| 654 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 655 | + null, |
|
| 656 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 657 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 658 | + ), |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + |
|
| 664 | + /** |
|
| 665 | + * Registers how core classes are loaded. |
|
| 666 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 667 | + * 'EE_Request_Handler' => 'load_core' |
|
| 668 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 669 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 670 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 671 | + * 'Some_Class' => function () { |
|
| 672 | + * return new Some_Class(); |
|
| 673 | + * }, |
|
| 674 | + * This is required for instantiating dependencies |
|
| 675 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 676 | + * 'Required_Interface' => function () { |
|
| 677 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 678 | + * }, |
|
| 679 | + * |
|
| 680 | + * @throws InvalidInterfaceException |
|
| 681 | + * @throws InvalidDataTypeException |
|
| 682 | + * @throws InvalidArgumentException |
|
| 683 | + */ |
|
| 684 | + protected function _register_core_class_loaders() |
|
| 685 | + { |
|
| 686 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
| 687 | + //be used in a closure. |
|
| 688 | + $request = &$this->_request; |
|
| 689 | + $response = &$this->_response; |
|
| 690 | + // $loader = &$this->loader; |
|
| 691 | + $this->_class_loaders = array( |
|
| 692 | + //load_core |
|
| 693 | + 'EE_Capabilities' => 'load_core', |
|
| 694 | + 'EE_Encryption' => 'load_core', |
|
| 695 | + 'EE_Front_Controller' => 'load_core', |
|
| 696 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 697 | + 'EE_Registry' => 'load_core', |
|
| 698 | + 'EE_Request' => function () use (&$request) { |
|
| 699 | + return $request; |
|
| 700 | + }, |
|
| 701 | + 'EE_Response' => function () use (&$response) { |
|
| 702 | + return $response; |
|
| 703 | + }, |
|
| 704 | + 'EE_Request_Handler' => 'load_core', |
|
| 705 | + 'EE_Session' => 'load_core', |
|
| 706 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 707 | + 'EE_System' => 'load_core', |
|
| 708 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 709 | + 'EE_Register_CPTs' => 'load_core', |
|
| 710 | + 'EE_Admin' => 'load_core', |
|
| 711 | + //load_lib |
|
| 712 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 713 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 714 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 715 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 716 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 717 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 718 | + 'EE_Message_Repository' => 'load_lib', |
|
| 719 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 720 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 721 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 722 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 723 | + 'EE_Messages_Generator' => function () { |
|
| 724 | + return EE_Registry::instance()->load_lib( |
|
| 725 | + 'Messages_Generator', |
|
| 726 | + array(), |
|
| 727 | + false, |
|
| 728 | + false |
|
| 729 | + ); |
|
| 730 | + }, |
|
| 731 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 732 | + return EE_Registry::instance()->load_lib( |
|
| 733 | + 'Messages_Template_Defaults', |
|
| 734 | + $arguments, |
|
| 735 | + false, |
|
| 736 | + false |
|
| 737 | + ); |
|
| 738 | + }, |
|
| 739 | + //load_model |
|
| 740 | + // 'EEM_Attendee' => 'load_model', |
|
| 741 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
| 742 | + // 'EEM_Message_Template' => 'load_model', |
|
| 743 | + //load_helper |
|
| 744 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 745 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 746 | + return new EEH_Parse_Shortcodes(); |
|
| 747 | + } |
|
| 748 | + return null; |
|
| 749 | + }, |
|
| 750 | + 'EE_Template_Config' => function () { |
|
| 751 | + return EE_Config::instance()->template_settings; |
|
| 752 | + }, |
|
| 753 | + 'EE_Currency_Config' => function () { |
|
| 754 | + return EE_Config::instance()->currency; |
|
| 755 | + }, |
|
| 756 | + 'EE_Registration_Config' => function () { |
|
| 757 | + return EE_Config::instance()->registration; |
|
| 758 | + }, |
|
| 759 | + 'EE_Organization_Config' => function () { |
|
| 760 | + return EE_Config::instance()->organization; |
|
| 761 | + }, |
|
| 762 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 763 | + return LoaderFactory::getLoader(); |
|
| 764 | + }, |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * can be used for supplying alternate names for classes, |
|
| 772 | + * or for connecting interface names to instantiable classes |
|
| 773 | + */ |
|
| 774 | + protected function _register_core_aliases() |
|
| 775 | + { |
|
| 776 | + $this->_aliases = array( |
|
| 777 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 778 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 779 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 780 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 781 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 782 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 783 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 784 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 785 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 786 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 787 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
| 788 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
| 789 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 790 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 791 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 792 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 793 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 794 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 795 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 796 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 797 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 798 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 799 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 800 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 801 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 802 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 803 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 804 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 805 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 806 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 807 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
| 808 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 809 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 810 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 811 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 812 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 813 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 814 | + 'EventEspresso\core\services\currency\Calculator' => 'EventEspresso\core\services\currency\DefaultCalculator', |
|
| 815 | + ); |
|
| 816 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 817 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 825 | + * request Primarily used by unit tests. |
|
| 826 | + * |
|
| 827 | + * @throws InvalidDataTypeException |
|
| 828 | + * @throws InvalidInterfaceException |
|
| 829 | + * @throws InvalidArgumentException |
|
| 830 | + */ |
|
| 831 | + public function reset() |
|
| 832 | + { |
|
| 833 | + $this->_register_core_class_loaders(); |
|
| 834 | + $this->_register_core_dependencies(); |
|
| 835 | + } |
|
| 836 | 836 | |
| 837 | 837 | |
| 838 | 838 | } |
@@ -21,96 +21,96 @@ |
||
| 21 | 21 | class CountryCurrencyDao |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array[] $country_currency_data |
|
| 26 | - */ |
|
| 27 | - private $country_currency_data; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array[] $country_currencies_by_iso_code |
|
| 31 | - */ |
|
| 32 | - private $country_currencies_by_iso_code; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array[] $country_currencies_by_currency |
|
| 36 | - */ |
|
| 37 | - private $country_currencies_by_currency; |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return array[] |
|
| 42 | - * @throws EE_Error |
|
| 43 | - */ |
|
| 44 | - private function initializeCountryCurrencyData() |
|
| 45 | - { |
|
| 46 | - if ($this->country_currency_data === null) { |
|
| 47 | - $country_currency_data = json_decode( |
|
| 48 | - EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 49 | - true |
|
| 50 | - ); |
|
| 51 | - $this->parseCountryCurrencyData($country_currency_data); |
|
| 52 | - } |
|
| 53 | - return $this->country_currency_data; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array[] $country_currency_data |
|
| 59 | - */ |
|
| 60 | - private function parseCountryCurrencyData($country_currency_data) |
|
| 61 | - { |
|
| 62 | - foreach ($country_currency_data as $country_currency) { |
|
| 63 | - $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 64 | - $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 65 | - } |
|
| 66 | - $this->country_currency_data = $country_currency_data; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @param string $CNT_ISO |
|
| 72 | - * @return array |
|
| 73 | - * @throws EE_Error |
|
| 74 | - * @throws InvalidArgumentException |
|
| 75 | - */ |
|
| 76 | - public function getCountryCurrencyByIsoCode($CNT_ISO = '') |
|
| 77 | - { |
|
| 78 | - $this->initializeCountryCurrencyData(); |
|
| 79 | - if (! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 80 | - throw new InvalidArgumentException( |
|
| 81 | - sprintf( |
|
| 82 | - esc_html__( |
|
| 83 | - 'Valid country currency data could not be found for the "%1$s" country code;', |
|
| 84 | - 'event_espresso' |
|
| 85 | - ), |
|
| 86 | - $CNT_ISO |
|
| 87 | - ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 90 | - return $this->country_currencies_by_iso_code[ $CNT_ISO ]; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $code |
|
| 96 | - * @return array |
|
| 97 | - * @throws EE_Error |
|
| 98 | - * @throws InvalidArgumentException |
|
| 99 | - */ |
|
| 100 | - public function getCountryCurrencyByCurrencyCode($code = '') |
|
| 101 | - { |
|
| 102 | - $this->initializeCountryCurrencyData(); |
|
| 103 | - if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 104 | - throw new InvalidArgumentException( |
|
| 105 | - sprintf( |
|
| 106 | - esc_html__( |
|
| 107 | - 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 108 | - 'event_espresso' |
|
| 109 | - ), |
|
| 110 | - $code |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - return $this->country_currencies_by_currency[ $code ]; |
|
| 115 | - } |
|
| 24 | + /** |
|
| 25 | + * @var array[] $country_currency_data |
|
| 26 | + */ |
|
| 27 | + private $country_currency_data; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array[] $country_currencies_by_iso_code |
|
| 31 | + */ |
|
| 32 | + private $country_currencies_by_iso_code; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array[] $country_currencies_by_currency |
|
| 36 | + */ |
|
| 37 | + private $country_currencies_by_currency; |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return array[] |
|
| 42 | + * @throws EE_Error |
|
| 43 | + */ |
|
| 44 | + private function initializeCountryCurrencyData() |
|
| 45 | + { |
|
| 46 | + if ($this->country_currency_data === null) { |
|
| 47 | + $country_currency_data = json_decode( |
|
| 48 | + EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 49 | + true |
|
| 50 | + ); |
|
| 51 | + $this->parseCountryCurrencyData($country_currency_data); |
|
| 52 | + } |
|
| 53 | + return $this->country_currency_data; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array[] $country_currency_data |
|
| 59 | + */ |
|
| 60 | + private function parseCountryCurrencyData($country_currency_data) |
|
| 61 | + { |
|
| 62 | + foreach ($country_currency_data as $country_currency) { |
|
| 63 | + $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 64 | + $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 65 | + } |
|
| 66 | + $this->country_currency_data = $country_currency_data; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @param string $CNT_ISO |
|
| 72 | + * @return array |
|
| 73 | + * @throws EE_Error |
|
| 74 | + * @throws InvalidArgumentException |
|
| 75 | + */ |
|
| 76 | + public function getCountryCurrencyByIsoCode($CNT_ISO = '') |
|
| 77 | + { |
|
| 78 | + $this->initializeCountryCurrencyData(); |
|
| 79 | + if (! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 80 | + throw new InvalidArgumentException( |
|
| 81 | + sprintf( |
|
| 82 | + esc_html__( |
|
| 83 | + 'Valid country currency data could not be found for the "%1$s" country code;', |
|
| 84 | + 'event_espresso' |
|
| 85 | + ), |
|
| 86 | + $CNT_ISO |
|
| 87 | + ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | + return $this->country_currencies_by_iso_code[ $CNT_ISO ]; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $code |
|
| 96 | + * @return array |
|
| 97 | + * @throws EE_Error |
|
| 98 | + * @throws InvalidArgumentException |
|
| 99 | + */ |
|
| 100 | + public function getCountryCurrencyByCurrencyCode($code = '') |
|
| 101 | + { |
|
| 102 | + $this->initializeCountryCurrencyData(); |
|
| 103 | + if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 104 | + throw new InvalidArgumentException( |
|
| 105 | + sprintf( |
|
| 106 | + esc_html__( |
|
| 107 | + 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 108 | + 'event_espresso' |
|
| 109 | + ), |
|
| 110 | + $code |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + return $this->country_currencies_by_currency[ $code ]; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | if ($this->country_currency_data === null) { |
| 47 | 47 | $country_currency_data = json_decode( |
| 48 | - EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 48 | + EEH_File::get_file_contents(__DIR__.DS.'country-currencies.json'), |
|
| 49 | 49 | true |
| 50 | 50 | ); |
| 51 | 51 | $this->parseCountryCurrencyData($country_currency_data); |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | private function parseCountryCurrencyData($country_currency_data) |
| 61 | 61 | { |
| 62 | 62 | foreach ($country_currency_data as $country_currency) { |
| 63 | - $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 64 | - $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 63 | + $this->country_currencies_by_iso_code[$country_currency['CountryISO']] = $country_currency; |
|
| 64 | + $this->country_currencies_by_currency[$country_currency['CurrencyCode']] = $country_currency; |
|
| 65 | 65 | } |
| 66 | 66 | $this->country_currency_data = $country_currency_data; |
| 67 | 67 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | public function getCountryCurrencyByIsoCode($CNT_ISO = '') |
| 77 | 77 | { |
| 78 | 78 | $this->initializeCountryCurrencyData(); |
| 79 | - if (! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 79 | + if ( ! isset($this->country_currencies_by_iso_code[$CNT_ISO])) { |
|
| 80 | 80 | throw new InvalidArgumentException( |
| 81 | 81 | sprintf( |
| 82 | 82 | esc_html__( |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | ) |
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | - return $this->country_currencies_by_iso_code[ $CNT_ISO ]; |
|
| 90 | + return $this->country_currencies_by_iso_code[$CNT_ISO]; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | public function getCountryCurrencyByCurrencyCode($code = '') |
| 101 | 101 | { |
| 102 | 102 | $this->initializeCountryCurrencyData(); |
| 103 | - if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 103 | + if ( ! isset($this->country_currencies_by_currency[$code])) { |
|
| 104 | 104 | throw new InvalidArgumentException( |
| 105 | 105 | sprintf( |
| 106 | 106 | esc_html__( |
@@ -111,6 +111,6 @@ discard block |
||
| 111 | 111 | ) |
| 112 | 112 | ); |
| 113 | 113 | } |
| 114 | - return $this->country_currencies_by_currency[ $code ]; |
|
| 114 | + return $this->country_currencies_by_currency[$code]; |
|
| 115 | 115 | } |
| 116 | 116 | } |
@@ -23,84 +23,84 @@ |
||
| 23 | 23 | class CurrencyFactory |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string $site_country_iso |
|
| 28 | - */ |
|
| 29 | - private $site_country_iso; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var CountryCurrencyDao $country_currencies |
|
| 33 | - */ |
|
| 34 | - private $country_currencies; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * CurrencyFactory constructor. |
|
| 39 | - * |
|
| 40 | - * @param CountryCurrencyDao $country_currencies |
|
| 41 | - * @param EE_Organization_Config $organization_config |
|
| 42 | - */ |
|
| 43 | - public function __construct(CountryCurrencyDao $country_currencies, EE_Organization_Config $organization_config) |
|
| 44 | - { |
|
| 45 | - $this->country_currencies = $country_currencies; |
|
| 46 | - $this->site_country_iso = $organization_config->CNT_ISO; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param array $country_currency |
|
| 52 | - * @return Currency |
|
| 53 | - */ |
|
| 54 | - private function createCurrencyFromCountryCurrency(array $country_currency) |
|
| 55 | - { |
|
| 56 | - return new Currency( |
|
| 57 | - $country_currency['CurrencyCode'], |
|
| 58 | - new Label( |
|
| 59 | - $country_currency['CurrencyNameSingle'], |
|
| 60 | - $country_currency['CurrencyNamePlural'] |
|
| 61 | - ), |
|
| 62 | - $country_currency['CurrencySign'], |
|
| 63 | - $country_currency['CurrencySignB4'], |
|
| 64 | - $country_currency['CurrencyDecimalPlaces'], |
|
| 65 | - $country_currency['CurrencyDecimalMark'], |
|
| 66 | - $country_currency['CurrencyThousands'], |
|
| 67 | - $country_currency['CurrencySubunits'] |
|
| 68 | - ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * returns a Currency object for the supplied country code |
|
| 74 | - * |
|
| 75 | - * @param string $CNT_ISO |
|
| 76 | - * @return Currency |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - */ |
|
| 80 | - public function createFromCountryCode($CNT_ISO = null) |
|
| 81 | - { |
|
| 82 | - $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->site_country_iso; |
|
| 83 | - return $this->createCurrencyFromCountryCurrency( |
|
| 84 | - $this->country_currencies->getCountryCurrencyByIsoCode($CNT_ISO) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * returns a Currency object for the supplied currency code |
|
| 91 | - * PLZ NOTE: variations may exist between how different countries display the same currency, |
|
| 92 | - * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
|
| 93 | - * |
|
| 94 | - * @param string $code |
|
| 95 | - * @return Currency |
|
| 96 | - * @throws InvalidArgumentException |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function createFromCode($code) |
|
| 100 | - { |
|
| 101 | - return $this->createCurrencyFromCountryCurrency( |
|
| 102 | - $this->country_currencies->getCountryCurrencyByCurrencyCode($code) |
|
| 103 | - ); |
|
| 104 | - } |
|
| 26 | + /** |
|
| 27 | + * @var string $site_country_iso |
|
| 28 | + */ |
|
| 29 | + private $site_country_iso; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var CountryCurrencyDao $country_currencies |
|
| 33 | + */ |
|
| 34 | + private $country_currencies; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * CurrencyFactory constructor. |
|
| 39 | + * |
|
| 40 | + * @param CountryCurrencyDao $country_currencies |
|
| 41 | + * @param EE_Organization_Config $organization_config |
|
| 42 | + */ |
|
| 43 | + public function __construct(CountryCurrencyDao $country_currencies, EE_Organization_Config $organization_config) |
|
| 44 | + { |
|
| 45 | + $this->country_currencies = $country_currencies; |
|
| 46 | + $this->site_country_iso = $organization_config->CNT_ISO; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param array $country_currency |
|
| 52 | + * @return Currency |
|
| 53 | + */ |
|
| 54 | + private function createCurrencyFromCountryCurrency(array $country_currency) |
|
| 55 | + { |
|
| 56 | + return new Currency( |
|
| 57 | + $country_currency['CurrencyCode'], |
|
| 58 | + new Label( |
|
| 59 | + $country_currency['CurrencyNameSingle'], |
|
| 60 | + $country_currency['CurrencyNamePlural'] |
|
| 61 | + ), |
|
| 62 | + $country_currency['CurrencySign'], |
|
| 63 | + $country_currency['CurrencySignB4'], |
|
| 64 | + $country_currency['CurrencyDecimalPlaces'], |
|
| 65 | + $country_currency['CurrencyDecimalMark'], |
|
| 66 | + $country_currency['CurrencyThousands'], |
|
| 67 | + $country_currency['CurrencySubunits'] |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * returns a Currency object for the supplied country code |
|
| 74 | + * |
|
| 75 | + * @param string $CNT_ISO |
|
| 76 | + * @return Currency |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + */ |
|
| 80 | + public function createFromCountryCode($CNT_ISO = null) |
|
| 81 | + { |
|
| 82 | + $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->site_country_iso; |
|
| 83 | + return $this->createCurrencyFromCountryCurrency( |
|
| 84 | + $this->country_currencies->getCountryCurrencyByIsoCode($CNT_ISO) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * returns a Currency object for the supplied currency code |
|
| 91 | + * PLZ NOTE: variations may exist between how different countries display the same currency, |
|
| 92 | + * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
|
| 93 | + * |
|
| 94 | + * @param string $code |
|
| 95 | + * @return Currency |
|
| 96 | + * @throws InvalidArgumentException |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function createFromCode($code) |
|
| 100 | + { |
|
| 101 | + return $this->createCurrencyFromCountryCurrency( |
|
| 102 | + $this->country_currencies->getCountryCurrencyByCurrencyCode($code) |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | // Location: CreateCurrency.php |
@@ -21,105 +21,105 @@ discard block |
||
| 21 | 21 | class EE_Price extends EE_Soft_Delete_Base_Class implements UsesMoneyInterface |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param array $props_n_values incoming values |
|
| 26 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 27 | - * used.) |
|
| 28 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 29 | - * date_format and the second value is the time format |
|
| 30 | - * @param MoneyFactory $money_factory |
|
| 31 | - * @return EE_Price |
|
| 32 | - * @throws InvalidArgumentException |
|
| 33 | - * @throws InvalidInterfaceException |
|
| 34 | - * @throws InvalidDataTypeException |
|
| 35 | - * @throws EE_Error |
|
| 36 | - */ |
|
| 37 | - public static function new_instance( |
|
| 38 | - $props_n_values = array(), |
|
| 39 | - $timezone = null, |
|
| 40 | - $date_formats = array(), |
|
| 41 | - MoneyFactory $money_factory = null |
|
| 42 | - ) { |
|
| 43 | - $has_object = parent::_check_for_object( |
|
| 44 | - $props_n_values, |
|
| 45 | - __CLASS__, |
|
| 46 | - $timezone, |
|
| 47 | - $date_formats |
|
| 48 | - ); |
|
| 49 | - return $has_object |
|
| 50 | - ? $has_object |
|
| 51 | - : new self( |
|
| 52 | - $props_n_values, |
|
| 53 | - false, |
|
| 54 | - $timezone, |
|
| 55 | - $date_formats, |
|
| 56 | - $money_factory |
|
| 57 | - ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param array $props_n_values incoming values from the database |
|
| 63 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 64 | - * the website will be used. |
|
| 65 | - * @param MoneyFactory $money_factory |
|
| 66 | - * @return EE_Price |
|
| 67 | - * @throws InvalidArgumentException |
|
| 68 | - * @throws InvalidInterfaceException |
|
| 69 | - * @throws InvalidDataTypeException |
|
| 70 | - * @throws EE_Error |
|
| 71 | - */ |
|
| 72 | - public static function new_instance_from_db( |
|
| 73 | - $props_n_values = array(), |
|
| 74 | - $timezone = null, |
|
| 75 | - MoneyFactory $money_factory = null |
|
| 76 | - ) { |
|
| 77 | - return new self( |
|
| 78 | - $props_n_values, |
|
| 79 | - true, |
|
| 80 | - $timezone, |
|
| 81 | - array(), |
|
| 82 | - $money_factory |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 89 | - * play nice |
|
| 90 | - * |
|
| 91 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 92 | - * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 93 | - * values |
|
| 94 | - * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 95 | - * or not. |
|
| 96 | - * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 97 | - * instantiating |
|
| 98 | - * a EE_Base_Class object. |
|
| 99 | - * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 100 | - * date_format and second value is the time format. |
|
| 101 | - * @param MoneyFactory $money_factory |
|
| 102 | - * @throws InvalidArgumentException |
|
| 103 | - * @throws InvalidInterfaceException |
|
| 104 | - * @throws InvalidDataTypeException |
|
| 105 | - * @throws EE_Error |
|
| 106 | - */ |
|
| 107 | - protected function __construct( |
|
| 108 | - array $fieldValues = array(), |
|
| 109 | - $bydb = false, |
|
| 110 | - $timezone = '', |
|
| 111 | - array $date_formats = array(), |
|
| 112 | - MoneyFactory $money_factory = null |
|
| 113 | - ) { |
|
| 114 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 115 | - $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 116 | - } |
|
| 117 | - $this->money_factory = $money_factory; |
|
| 118 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 24 | + /** |
|
| 25 | + * @param array $props_n_values incoming values |
|
| 26 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 27 | + * used.) |
|
| 28 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 29 | + * date_format and the second value is the time format |
|
| 30 | + * @param MoneyFactory $money_factory |
|
| 31 | + * @return EE_Price |
|
| 32 | + * @throws InvalidArgumentException |
|
| 33 | + * @throws InvalidInterfaceException |
|
| 34 | + * @throws InvalidDataTypeException |
|
| 35 | + * @throws EE_Error |
|
| 36 | + */ |
|
| 37 | + public static function new_instance( |
|
| 38 | + $props_n_values = array(), |
|
| 39 | + $timezone = null, |
|
| 40 | + $date_formats = array(), |
|
| 41 | + MoneyFactory $money_factory = null |
|
| 42 | + ) { |
|
| 43 | + $has_object = parent::_check_for_object( |
|
| 44 | + $props_n_values, |
|
| 45 | + __CLASS__, |
|
| 46 | + $timezone, |
|
| 47 | + $date_formats |
|
| 48 | + ); |
|
| 49 | + return $has_object |
|
| 50 | + ? $has_object |
|
| 51 | + : new self( |
|
| 52 | + $props_n_values, |
|
| 53 | + false, |
|
| 54 | + $timezone, |
|
| 55 | + $date_formats, |
|
| 56 | + $money_factory |
|
| 57 | + ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param array $props_n_values incoming values from the database |
|
| 63 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 64 | + * the website will be used. |
|
| 65 | + * @param MoneyFactory $money_factory |
|
| 66 | + * @return EE_Price |
|
| 67 | + * @throws InvalidArgumentException |
|
| 68 | + * @throws InvalidInterfaceException |
|
| 69 | + * @throws InvalidDataTypeException |
|
| 70 | + * @throws EE_Error |
|
| 71 | + */ |
|
| 72 | + public static function new_instance_from_db( |
|
| 73 | + $props_n_values = array(), |
|
| 74 | + $timezone = null, |
|
| 75 | + MoneyFactory $money_factory = null |
|
| 76 | + ) { |
|
| 77 | + return new self( |
|
| 78 | + $props_n_values, |
|
| 79 | + true, |
|
| 80 | + $timezone, |
|
| 81 | + array(), |
|
| 82 | + $money_factory |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 89 | + * play nice |
|
| 90 | + * |
|
| 91 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 92 | + * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 93 | + * values |
|
| 94 | + * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 95 | + * or not. |
|
| 96 | + * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 97 | + * instantiating |
|
| 98 | + * a EE_Base_Class object. |
|
| 99 | + * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 100 | + * date_format and second value is the time format. |
|
| 101 | + * @param MoneyFactory $money_factory |
|
| 102 | + * @throws InvalidArgumentException |
|
| 103 | + * @throws InvalidInterfaceException |
|
| 104 | + * @throws InvalidDataTypeException |
|
| 105 | + * @throws EE_Error |
|
| 106 | + */ |
|
| 107 | + protected function __construct( |
|
| 108 | + array $fieldValues = array(), |
|
| 109 | + $bydb = false, |
|
| 110 | + $timezone = '', |
|
| 111 | + array $date_formats = array(), |
|
| 112 | + MoneyFactory $money_factory = null |
|
| 113 | + ) { |
|
| 114 | + if (! $money_factory instanceof MoneyFactory) { |
|
| 115 | + $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 116 | + } |
|
| 117 | + $this->money_factory = $money_factory; |
|
| 118 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | 123 | * Set Price type ID |
| 124 | 124 | * |
| 125 | 125 | * @access public |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | - * set is_default |
|
| 172 | - * |
|
| 173 | - * @access public |
|
| 174 | - * @param bool $PRC_is_default |
|
| 175 | - */ |
|
| 171 | + * set is_default |
|
| 172 | + * |
|
| 173 | + * @access public |
|
| 174 | + * @param bool $PRC_is_default |
|
| 175 | + */ |
|
| 176 | 176 | public function set_is_default( $PRC_is_default = FALSE ) { |
| 177 | 177 | $this->set( 'PRC_is_default', $PRC_is_default ); |
| 178 | 178 | } |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | - * set deleted |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @param bool $PRC_deleted |
|
| 187 | - */ |
|
| 183 | + * set deleted |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @param bool $PRC_deleted |
|
| 187 | + */ |
|
| 188 | 188 | public function set_deleted( $PRC_deleted = NULL ) { |
| 189 | 189 | $this->set( 'PRC_deleted', $PRC_deleted ); |
| 190 | 190 | } |
@@ -365,38 +365,38 @@ discard block |
||
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
| 368 | - /** |
|
| 369 | - * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 370 | - * in the currency's main units) |
|
| 371 | - * |
|
| 372 | - * @return int |
|
| 373 | - * @throws EE_Error |
|
| 374 | - * @throws InvalidEntityException |
|
| 375 | - * @throws DomainException |
|
| 376 | - */ |
|
| 377 | - public function amountInSubunits() |
|
| 378 | - { |
|
| 379 | - return $this->moneyInSubunits('PRC_amount'); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 385 | - * the amount is actually assumed to be in the currency's main units |
|
| 386 | - * |
|
| 387 | - * @param int $amount_in_subunits |
|
| 388 | - * @return void |
|
| 389 | - * @throws EE_Error |
|
| 390 | - * @throws InvalidArgumentException |
|
| 391 | - * @throws InvalidInterfaceException |
|
| 392 | - * @throws InvalidIdentifierException |
|
| 393 | - * @throws InvalidDataTypeException |
|
| 394 | - * @throws DomainException |
|
| 395 | - */ |
|
| 396 | - public function setAmountInSubunits($amount_in_subunits) |
|
| 397 | - { |
|
| 398 | - $this->setMoneySubunits('PRC_amount', $amount_in_subunits); |
|
| 399 | - } |
|
| 368 | + /** |
|
| 369 | + * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 370 | + * in the currency's main units) |
|
| 371 | + * |
|
| 372 | + * @return int |
|
| 373 | + * @throws EE_Error |
|
| 374 | + * @throws InvalidEntityException |
|
| 375 | + * @throws DomainException |
|
| 376 | + */ |
|
| 377 | + public function amountInSubunits() |
|
| 378 | + { |
|
| 379 | + return $this->moneyInSubunits('PRC_amount'); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 385 | + * the amount is actually assumed to be in the currency's main units |
|
| 386 | + * |
|
| 387 | + * @param int $amount_in_subunits |
|
| 388 | + * @return void |
|
| 389 | + * @throws EE_Error |
|
| 390 | + * @throws InvalidArgumentException |
|
| 391 | + * @throws InvalidInterfaceException |
|
| 392 | + * @throws InvalidIdentifierException |
|
| 393 | + * @throws InvalidDataTypeException |
|
| 394 | + * @throws DomainException |
|
| 395 | + */ |
|
| 396 | + public function setAmountInSubunits($amount_in_subunits) |
|
| 397 | + { |
|
| 398 | + $this->setMoneySubunits('PRC_amount', $amount_in_subunits); |
|
| 399 | + } |
|
| 400 | 400 | } |
| 401 | 401 | /* End of file EE_Price.class.php */ |
| 402 | 402 | /* Location: /includes/classes/EE_Price.class.php */ |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | array $date_formats = array(), |
| 112 | 112 | MoneyFactory $money_factory = null |
| 113 | 113 | ) { |
| 114 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 114 | + if ( ! $money_factory instanceof MoneyFactory) { |
|
| 115 | 115 | $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
| 116 | 116 | } |
| 117 | 117 | $this->money_factory = $money_factory; |
@@ -125,8 +125,8 @@ discard block |
||
| 125 | 125 | * @access public |
| 126 | 126 | * @param int $PRT_ID |
| 127 | 127 | */ |
| 128 | - public function set_type( $PRT_ID = 0 ) { |
|
| 129 | - $this->set( 'PRT_ID', $PRT_ID ); |
|
| 128 | + public function set_type($PRT_ID = 0) { |
|
| 129 | + $this->set('PRT_ID', $PRT_ID); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | * @access public |
| 138 | 138 | * @param float $PRC_amount |
| 139 | 139 | */ |
| 140 | - public function set_amount( $PRC_amount = 0.00 ) { |
|
| 141 | - $this->set( 'PRC_amount', $PRC_amount ); |
|
| 140 | + public function set_amount($PRC_amount = 0.00) { |
|
| 141 | + $this->set('PRC_amount', $PRC_amount); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | * @access public |
| 150 | 150 | * @param string $PRC_name |
| 151 | 151 | */ |
| 152 | - public function set_name( $PRC_name = '' ) { |
|
| 153 | - $this->set( 'PRC_name', $PRC_name ); |
|
| 152 | + public function set_name($PRC_name = '') { |
|
| 153 | + $this->set('PRC_name', $PRC_name); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | * @access public |
| 162 | 162 | * @param string $PRC_desc |
| 163 | 163 | */ |
| 164 | - public function set_description( $PRC_desc = '' ) { |
|
| 165 | - $this->Set( 'PRC_desc', $PRC_desc ); |
|
| 164 | + public function set_description($PRC_desc = '') { |
|
| 165 | + $this->Set('PRC_desc', $PRC_desc); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @access public |
| 174 | 174 | * @param bool $PRC_is_default |
| 175 | 175 | */ |
| 176 | - public function set_is_default( $PRC_is_default = FALSE ) { |
|
| 177 | - $this->set( 'PRC_is_default', $PRC_is_default ); |
|
| 176 | + public function set_is_default($PRC_is_default = FALSE) { |
|
| 177 | + $this->set('PRC_is_default', $PRC_is_default); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | * @access public |
| 186 | 186 | * @param bool $PRC_deleted |
| 187 | 187 | */ |
| 188 | - public function set_deleted( $PRC_deleted = NULL ) { |
|
| 189 | - $this->set( 'PRC_deleted', $PRC_deleted ); |
|
| 188 | + public function set_deleted($PRC_deleted = NULL) { |
|
| 189 | + $this->set('PRC_deleted', $PRC_deleted); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @return int |
| 198 | 198 | */ |
| 199 | 199 | public function type() { |
| 200 | - return $this->get( 'PRT_ID' ); |
|
| 200 | + return $this->get('PRT_ID'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return float |
| 209 | 209 | */ |
| 210 | 210 | public function amount() { |
| 211 | - return $this->get( 'PRC_amount' ); |
|
| 211 | + return $this->get('PRC_amount'); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | 221 | public function name() { |
| 222 | - return $this->get( 'PRC_name' ); |
|
| 222 | + return $this->get('PRC_name'); |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | * @return string |
| 231 | 231 | */ |
| 232 | 232 | public function desc() { |
| 233 | - return $this->get( 'PRC_desc' ); |
|
| 233 | + return $this->get('PRC_desc'); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @return int |
| 242 | 242 | */ |
| 243 | 243 | public function overrides() { |
| 244 | - return $this->get( 'PRC_overrides' ); |
|
| 244 | + return $this->get('PRC_overrides'); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @return int |
| 253 | 253 | */ |
| 254 | 254 | public function order() { |
| 255 | - return $this->get( 'PRC_order' ); |
|
| 255 | + return $this->get('PRC_order'); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | * @return bool |
| 277 | 277 | */ |
| 278 | 278 | public function is_default() { |
| 279 | - return $this->get( 'PRC_is_default' ); |
|
| 279 | + return $this->get('PRC_is_default'); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | * @return bool |
| 288 | 288 | */ |
| 289 | 289 | public function deleted() { |
| 290 | - return $this->get( 'PRC_deleted' ); |
|
| 290 | + return $this->get('PRC_deleted'); |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * @return bool |
| 297 | 297 | */ |
| 298 | 298 | public function parent() { |
| 299 | - return $this->get( 'PRC_parent' ); |
|
| 299 | + return $this->get('PRC_parent'); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return EE_Price_Type |
| 319 | 319 | */ |
| 320 | 320 | public function type_obj() { |
| 321 | - return $this->get_first_related( 'Price_Type' ); |
|
| 321 | + return $this->get_first_related('Price_Type'); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | public function is_percent() { |
| 342 | 342 | $price_type = $this->type_obj(); |
| 343 | - return $price_type->get( 'PRT_is_percent' ); |
|
| 343 | + return $price_type->get('PRT_is_percent'); |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | * @return string |
| 353 | 353 | */ |
| 354 | 354 | public function pretty_price() { |
| 355 | - return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%'; |
|
| 355 | + return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount').'%'; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @return mixed |
| 362 | 362 | */ |
| 363 | 363 | public function get_price_without_currency_symbol() { |
| 364 | - return str_replace( EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty( 'PRC_amount' ) ); |
|
| 364 | + return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount')); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * @author Darren Ethier |
| 35 | 35 | */ |
| 36 | 36 | class EE_Ticket |
| 37 | - extends EE_Soft_Delete_Base_Class |
|
| 38 | - implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon, UsesMoneyInterface |
|
| 37 | + extends EE_Soft_Delete_Base_Class |
|
| 38 | + implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon, UsesMoneyInterface |
|
| 39 | 39 | { |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -70,121 +70,121 @@ discard block |
||
| 70 | 70 | private $_ticket_total_with_taxes; |
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param array $props_n_values incoming values |
|
| 75 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 76 | - * used.) |
|
| 77 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 78 | - * date_format and the second value is the time format |
|
| 79 | - * @param MoneyFactory $money_factory |
|
| 80 | - * @return EE_Ticket |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws InvalidInterfaceException |
|
| 83 | - * @throws InvalidDataTypeException |
|
| 84 | - * @throws EE_Error |
|
| 85 | - */ |
|
| 86 | - public static function new_instance( |
|
| 87 | - $props_n_values = array(), |
|
| 88 | - $timezone = null, |
|
| 89 | - $date_formats = array(), |
|
| 90 | - MoneyFactory $money_factory = null |
|
| 91 | - ) { |
|
| 92 | - $has_object = parent::_check_for_object( |
|
| 93 | - $props_n_values, |
|
| 94 | - __CLASS__, |
|
| 95 | - $timezone, |
|
| 96 | - $date_formats |
|
| 97 | - ); |
|
| 98 | - return $has_object |
|
| 99 | - ? $has_object |
|
| 100 | - : new self( |
|
| 101 | - $props_n_values, |
|
| 102 | - false, |
|
| 103 | - $timezone, |
|
| 104 | - $date_formats, |
|
| 105 | - $money_factory |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param array $props_n_values incoming values from the database |
|
| 112 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 113 | - * the website will be used. |
|
| 114 | - * @param MoneyFactory $money_factory |
|
| 115 | - * @return EE_Ticket |
|
| 116 | - * @throws InvalidArgumentException |
|
| 117 | - * @throws InvalidInterfaceException |
|
| 118 | - * @throws InvalidDataTypeException |
|
| 119 | - * @throws EE_Error |
|
| 120 | - */ |
|
| 121 | - public static function new_instance_from_db( |
|
| 122 | - $props_n_values = array(), |
|
| 123 | - $timezone = null, |
|
| 124 | - MoneyFactory $money_factory = null |
|
| 125 | - ) { |
|
| 126 | - return new self( |
|
| 127 | - $props_n_values, |
|
| 128 | - true, |
|
| 129 | - $timezone, |
|
| 130 | - array(), |
|
| 131 | - $money_factory |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 138 | - * play nice |
|
| 139 | - * |
|
| 140 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 141 | - * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 142 | - * values |
|
| 143 | - * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 144 | - * or not. |
|
| 145 | - * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 146 | - * instantiating |
|
| 147 | - * a EE_Base_Class object. |
|
| 148 | - * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 149 | - * date_format and second value is the time format. |
|
| 150 | - * @param MoneyFactory $money_factory |
|
| 151 | - * @throws InvalidArgumentException |
|
| 152 | - * @throws InvalidInterfaceException |
|
| 153 | - * @throws InvalidDataTypeException |
|
| 154 | - * @throws EE_Error |
|
| 155 | - */ |
|
| 156 | - protected function __construct( |
|
| 157 | - array $fieldValues = array(), |
|
| 158 | - $bydb = false, |
|
| 159 | - $timezone = '', |
|
| 160 | - array $date_formats = array(), |
|
| 161 | - MoneyFactory $money_factory = null |
|
| 162 | - ) { |
|
| 163 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 164 | - $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 165 | - } |
|
| 166 | - $this->money_factory = $money_factory; |
|
| 167 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @return bool |
|
| 173 | - * @throws \EE_Error |
|
| 174 | - */ |
|
| 73 | + /** |
|
| 74 | + * @param array $props_n_values incoming values |
|
| 75 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 76 | + * used.) |
|
| 77 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 78 | + * date_format and the second value is the time format |
|
| 79 | + * @param MoneyFactory $money_factory |
|
| 80 | + * @return EE_Ticket |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws InvalidInterfaceException |
|
| 83 | + * @throws InvalidDataTypeException |
|
| 84 | + * @throws EE_Error |
|
| 85 | + */ |
|
| 86 | + public static function new_instance( |
|
| 87 | + $props_n_values = array(), |
|
| 88 | + $timezone = null, |
|
| 89 | + $date_formats = array(), |
|
| 90 | + MoneyFactory $money_factory = null |
|
| 91 | + ) { |
|
| 92 | + $has_object = parent::_check_for_object( |
|
| 93 | + $props_n_values, |
|
| 94 | + __CLASS__, |
|
| 95 | + $timezone, |
|
| 96 | + $date_formats |
|
| 97 | + ); |
|
| 98 | + return $has_object |
|
| 99 | + ? $has_object |
|
| 100 | + : new self( |
|
| 101 | + $props_n_values, |
|
| 102 | + false, |
|
| 103 | + $timezone, |
|
| 104 | + $date_formats, |
|
| 105 | + $money_factory |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param array $props_n_values incoming values from the database |
|
| 112 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 113 | + * the website will be used. |
|
| 114 | + * @param MoneyFactory $money_factory |
|
| 115 | + * @return EE_Ticket |
|
| 116 | + * @throws InvalidArgumentException |
|
| 117 | + * @throws InvalidInterfaceException |
|
| 118 | + * @throws InvalidDataTypeException |
|
| 119 | + * @throws EE_Error |
|
| 120 | + */ |
|
| 121 | + public static function new_instance_from_db( |
|
| 122 | + $props_n_values = array(), |
|
| 123 | + $timezone = null, |
|
| 124 | + MoneyFactory $money_factory = null |
|
| 125 | + ) { |
|
| 126 | + return new self( |
|
| 127 | + $props_n_values, |
|
| 128 | + true, |
|
| 129 | + $timezone, |
|
| 130 | + array(), |
|
| 131 | + $money_factory |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 138 | + * play nice |
|
| 139 | + * |
|
| 140 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd layer of the model's |
|
| 141 | + * _fields array, (eg, EVT_ID, TXN_amount, QST_name, etc) and values are their |
|
| 142 | + * values |
|
| 143 | + * @param boolean $bydb a flag for setting if the class is instantiated by the corresponding db model |
|
| 144 | + * or not. |
|
| 145 | + * @param string $timezone indicate what timezone you want any datetime fields to be in when |
|
| 146 | + * instantiating |
|
| 147 | + * a EE_Base_Class object. |
|
| 148 | + * @param array $date_formats An array of date formats to set on construct where first value is the |
|
| 149 | + * date_format and second value is the time format. |
|
| 150 | + * @param MoneyFactory $money_factory |
|
| 151 | + * @throws InvalidArgumentException |
|
| 152 | + * @throws InvalidInterfaceException |
|
| 153 | + * @throws InvalidDataTypeException |
|
| 154 | + * @throws EE_Error |
|
| 155 | + */ |
|
| 156 | + protected function __construct( |
|
| 157 | + array $fieldValues = array(), |
|
| 158 | + $bydb = false, |
|
| 159 | + $timezone = '', |
|
| 160 | + array $date_formats = array(), |
|
| 161 | + MoneyFactory $money_factory = null |
|
| 162 | + ) { |
|
| 163 | + if (! $money_factory instanceof MoneyFactory) { |
|
| 164 | + $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
|
| 165 | + } |
|
| 166 | + $this->money_factory = $money_factory; |
|
| 167 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @return bool |
|
| 173 | + * @throws \EE_Error |
|
| 174 | + */ |
|
| 175 | 175 | public function parent() { |
| 176 | 176 | return $this->get( 'TKT_parent' ); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * return if a ticket has quantities available for purchase |
|
| 183 | - * |
|
| 184 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 185 | - * @return boolean |
|
| 186 | - * @throws \EE_Error |
|
| 187 | - */ |
|
| 181 | + /** |
|
| 182 | + * return if a ticket has quantities available for purchase |
|
| 183 | + * |
|
| 184 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 185 | + * @return boolean |
|
| 186 | + * @throws \EE_Error |
|
| 187 | + */ |
|
| 188 | 188 | public function available( $DTT_ID = 0 ) { |
| 189 | 189 | // are we checking availability for a particular datetime ? |
| 190 | 190 | if ( $DTT_ID ) { |
@@ -201,14 +201,14 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 206 | - * |
|
| 207 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 208 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 209 | - * @return mixed status int if the display string isn't requested |
|
| 210 | - * @throws \EE_Error |
|
| 211 | - */ |
|
| 204 | + /** |
|
| 205 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 206 | + * |
|
| 207 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 208 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 209 | + * @return mixed status int if the display string isn't requested |
|
| 210 | + * @throws \EE_Error |
|
| 211 | + */ |
|
| 212 | 212 | public function ticket_status( $display = FALSE, $remaining = null ) { |
| 213 | 213 | $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
| 214 | 214 | if ( ! $remaining ) { |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * 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. |
|
| 236 | - * |
|
| 237 | - * @access public |
|
| 238 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 239 | - * @return boolean true = tickets remaining, false not. |
|
| 240 | - * @throws \EE_Error |
|
| 241 | - */ |
|
| 234 | + /** |
|
| 235 | + * 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. |
|
| 236 | + * |
|
| 237 | + * @access public |
|
| 238 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 239 | + * @return boolean true = tickets remaining, false not. |
|
| 240 | + * @throws \EE_Error |
|
| 241 | + */ |
|
| 242 | 242 | public function is_remaining( $DTT_ID = 0 ) { |
| 243 | 243 | $num_remaining = $this->remaining( $DTT_ID ); |
| 244 | 244 | if ( $num_remaining === 0 ) { |
@@ -252,76 +252,76 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * return the total number of tickets available for purchase |
|
| 257 | - * |
|
| 258 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 259 | - * set to 0 for all related datetimes |
|
| 260 | - * @return int |
|
| 261 | - * @throws \EE_Error |
|
| 262 | - */ |
|
| 255 | + /** |
|
| 256 | + * return the total number of tickets available for purchase |
|
| 257 | + * |
|
| 258 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 259 | + * set to 0 for all related datetimes |
|
| 260 | + * @return int |
|
| 261 | + * @throws \EE_Error |
|
| 262 | + */ |
|
| 263 | 263 | public function remaining( $DTT_ID = 0 ) { |
| 264 | 264 | return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Gets min |
|
| 271 | - * |
|
| 272 | - * @return int |
|
| 273 | - * @throws \EE_Error |
|
| 274 | - */ |
|
| 269 | + /** |
|
| 270 | + * Gets min |
|
| 271 | + * |
|
| 272 | + * @return int |
|
| 273 | + * @throws \EE_Error |
|
| 274 | + */ |
|
| 275 | 275 | public function min() { |
| 276 | 276 | return $this->get( 'TKT_min' ); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 283 | - * |
|
| 284 | - * @return boolean |
|
| 285 | - * @throws \EE_Error |
|
| 286 | - */ |
|
| 281 | + /** |
|
| 282 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 283 | + * |
|
| 284 | + * @return boolean |
|
| 285 | + * @throws \EE_Error |
|
| 286 | + */ |
|
| 287 | 287 | public function is_expired() { |
| 288 | 288 | return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Return if a ticket is yet to go on sale or not |
|
| 295 | - * |
|
| 296 | - * @return boolean |
|
| 297 | - * @throws \EE_Error |
|
| 298 | - */ |
|
| 293 | + /** |
|
| 294 | + * Return if a ticket is yet to go on sale or not |
|
| 295 | + * |
|
| 296 | + * @return boolean |
|
| 297 | + * @throws \EE_Error |
|
| 298 | + */ |
|
| 299 | 299 | public function is_pending() { |
| 300 | 300 | return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | |
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Return if a ticket is on sale or not |
|
| 307 | - * |
|
| 308 | - * @return boolean |
|
| 309 | - * @throws \EE_Error |
|
| 310 | - */ |
|
| 305 | + /** |
|
| 306 | + * Return if a ticket is on sale or not |
|
| 307 | + * |
|
| 308 | + * @return boolean |
|
| 309 | + * @throws \EE_Error |
|
| 310 | + */ |
|
| 311 | 311 | public function is_on_sale() { |
| 312 | 312 | return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
| 316 | 316 | |
| 317 | - /** |
|
| 318 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 319 | - * |
|
| 320 | - * @param string $dt_frmt |
|
| 321 | - * @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 |
|
| 322 | - * @return string |
|
| 323 | - * @throws \EE_Error |
|
| 324 | - */ |
|
| 317 | + /** |
|
| 318 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 319 | + * |
|
| 320 | + * @param string $dt_frmt |
|
| 321 | + * @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 |
|
| 322 | + * @return string |
|
| 323 | + * @throws \EE_Error |
|
| 324 | + */ |
|
| 325 | 325 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
| 326 | 326 | $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
| 327 | 327 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
@@ -331,12 +331,12 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | |
| 333 | 333 | |
| 334 | - /** |
|
| 335 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 336 | - * |
|
| 337 | - * @return EE_Datetime |
|
| 338 | - * @throws \EE_Error |
|
| 339 | - */ |
|
| 334 | + /** |
|
| 335 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 336 | + * |
|
| 337 | + * @return EE_Datetime |
|
| 338 | + * @throws \EE_Error |
|
| 339 | + */ |
|
| 340 | 340 | public function first_datetime() { |
| 341 | 341 | $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
| 342 | 342 | return reset( $datetimes ); |
@@ -344,14 +344,14 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | |
| 346 | 346 | |
| 347 | - /** |
|
| 348 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 349 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 350 | - * |
|
| 351 | - * @param array $query_params see EEM_Base::get_all() |
|
| 352 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 353 | - * @throws \EE_Error |
|
| 354 | - */ |
|
| 347 | + /** |
|
| 348 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 349 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 350 | + * |
|
| 351 | + * @param array $query_params see EEM_Base::get_all() |
|
| 352 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 353 | + * @throws \EE_Error |
|
| 354 | + */ |
|
| 355 | 355 | public function datetimes( $query_params = array() ) { |
| 356 | 356 | if ( ! isset( $query_params[ 'order_by' ] ) ) { |
| 357 | 357 | $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
@@ -361,12 +361,12 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 366 | - * |
|
| 367 | - * @return EE_Datetime |
|
| 368 | - * @throws \EE_Error |
|
| 369 | - */ |
|
| 364 | + /** |
|
| 365 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 366 | + * |
|
| 367 | + * @return EE_Datetime |
|
| 368 | + * @throws \EE_Error |
|
| 369 | + */ |
|
| 370 | 370 | public function last_datetime() { |
| 371 | 371 | $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
| 372 | 372 | return end( $datetimes ); |
@@ -374,19 +374,19 @@ discard block |
||
| 374 | 374 | |
| 375 | 375 | |
| 376 | 376 | |
| 377 | - /** |
|
| 378 | - * This returns the total tickets sold depending on the given parameters. |
|
| 379 | - * |
|
| 380 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 381 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 382 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 383 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 384 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 385 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 386 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 387 | - * @return mixed (array|int) how many tickets have sold |
|
| 388 | - * @throws \EE_Error |
|
| 389 | - */ |
|
| 377 | + /** |
|
| 378 | + * This returns the total tickets sold depending on the given parameters. |
|
| 379 | + * |
|
| 380 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 381 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 382 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 383 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 384 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 385 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 386 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 387 | + * @return mixed (array|int) how many tickets have sold |
|
| 388 | + * @throws \EE_Error |
|
| 389 | + */ |
|
| 390 | 390 | public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
| 391 | 391 | $total = 0; |
| 392 | 392 | $tickets_sold = $this->_all_tickets_sold(); |
@@ -411,12 +411,12 @@ discard block |
||
| 411 | 411 | |
| 412 | 412 | |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 416 | - * |
|
| 417 | - * @return EE_Ticket[] |
|
| 418 | - * @throws \EE_Error |
|
| 419 | - */ |
|
| 414 | + /** |
|
| 415 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 416 | + * |
|
| 417 | + * @return EE_Ticket[] |
|
| 418 | + * @throws \EE_Error |
|
| 419 | + */ |
|
| 420 | 420 | protected function _all_tickets_sold() { |
| 421 | 421 | $datetimes = $this->get_many_related( 'Datetime' ); |
| 422 | 422 | $tickets_sold = array(); |
@@ -432,29 +432,29 @@ discard block |
||
| 432 | 432 | |
| 433 | 433 | |
| 434 | 434 | |
| 435 | - /** |
|
| 436 | - * This returns the base price object for the ticket. |
|
| 437 | - * |
|
| 438 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 439 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 440 | - * @throws \EE_Error |
|
| 441 | - */ |
|
| 435 | + /** |
|
| 436 | + * This returns the base price object for the ticket. |
|
| 437 | + * |
|
| 438 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 439 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 440 | + * @throws \EE_Error |
|
| 441 | + */ |
|
| 442 | 442 | public function base_price( $return_array = FALSE ) { |
| 443 | 443 | $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
| 444 | 444 | return $return_array |
| 445 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 446 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 445 | + ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 446 | + : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
| 450 | 450 | |
| 451 | - /** |
|
| 452 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 453 | - * |
|
| 454 | - * @access public |
|
| 455 | - * @return EE_Price[] |
|
| 456 | - * @throws \EE_Error |
|
| 457 | - */ |
|
| 451 | + /** |
|
| 452 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 453 | + * |
|
| 454 | + * @access public |
|
| 455 | + * @return EE_Price[] |
|
| 456 | + * @throws \EE_Error |
|
| 457 | + */ |
|
| 458 | 458 | public function price_modifiers() { |
| 459 | 459 | $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 ) ) ) ); |
| 460 | 460 | return $this->prices( $query_params ); |
@@ -462,132 +462,132 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | |
| 464 | 464 | |
| 465 | - /** |
|
| 466 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 467 | - * |
|
| 468 | - * @param array $query_params like EEM_Base::get_all |
|
| 469 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 470 | - * @throws \EE_Error |
|
| 471 | - */ |
|
| 465 | + /** |
|
| 466 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 467 | + * |
|
| 468 | + * @param array $query_params like EEM_Base::get_all |
|
| 469 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 470 | + * @throws \EE_Error |
|
| 471 | + */ |
|
| 472 | 472 | public function prices( $query_params = array() ) { |
| 473 | 473 | return $this->get_many_related( 'Price', $query_params ); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | |
| 477 | 477 | |
| 478 | - /** |
|
| 479 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 480 | - * |
|
| 481 | - * @param array $query_params see EEM_Base::get_all() |
|
| 482 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 483 | - * @throws \EE_Error |
|
| 484 | - */ |
|
| 478 | + /** |
|
| 479 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 480 | + * |
|
| 481 | + * @param array $query_params see EEM_Base::get_all() |
|
| 482 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 483 | + * @throws \EE_Error |
|
| 484 | + */ |
|
| 485 | 485 | public function datetime_tickets( $query_params = array() ) { |
| 486 | 486 | return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
| 490 | 490 | |
| 491 | - /** |
|
| 492 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 493 | - * |
|
| 494 | - * @param boolean $show_expired |
|
| 495 | - * @param boolean $show_deleted |
|
| 496 | - * @return EE_Datetime[] |
|
| 497 | - * @throws \EE_Error |
|
| 498 | - */ |
|
| 491 | + /** |
|
| 492 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 493 | + * |
|
| 494 | + * @param boolean $show_expired |
|
| 495 | + * @param boolean $show_deleted |
|
| 496 | + * @return EE_Datetime[] |
|
| 497 | + * @throws \EE_Error |
|
| 498 | + */ |
|
| 499 | 499 | public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
| 500 | 500 | return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | |
| 504 | 504 | |
| 505 | - /** |
|
| 506 | - * Gets ID |
|
| 507 | - * |
|
| 508 | - * @return string |
|
| 509 | - * @throws \EE_Error |
|
| 510 | - */ |
|
| 505 | + /** |
|
| 506 | + * Gets ID |
|
| 507 | + * |
|
| 508 | + * @return string |
|
| 509 | + * @throws \EE_Error |
|
| 510 | + */ |
|
| 511 | 511 | public function ID() { |
| 512 | 512 | return $this->get( 'TKT_ID' ); |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * get the author of the ticket. |
|
| 519 | - * |
|
| 520 | - * @since 4.5.0 |
|
| 521 | - * @return int |
|
| 522 | - * @throws \EE_Error |
|
| 523 | - */ |
|
| 517 | + /** |
|
| 518 | + * get the author of the ticket. |
|
| 519 | + * |
|
| 520 | + * @since 4.5.0 |
|
| 521 | + * @return int |
|
| 522 | + * @throws \EE_Error |
|
| 523 | + */ |
|
| 524 | 524 | public function wp_user() { |
| 525 | 525 | return $this->get('TKT_wp_user'); |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | |
| 529 | 529 | |
| 530 | - /** |
|
| 531 | - * Gets the template for the ticket |
|
| 532 | - * |
|
| 533 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 534 | - * @throws \EE_Error |
|
| 535 | - */ |
|
| 530 | + /** |
|
| 531 | + * Gets the template for the ticket |
|
| 532 | + * |
|
| 533 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 534 | + * @throws \EE_Error |
|
| 535 | + */ |
|
| 536 | 536 | public function template() { |
| 537 | 537 | return $this->get_first_related( 'Ticket_Template' ); |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | |
| 541 | 541 | |
| 542 | - /** |
|
| 543 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 544 | - * |
|
| 545 | - * @return EE_Price[] |
|
| 546 | - * @throws \EE_Error |
|
| 547 | - */ |
|
| 542 | + /** |
|
| 543 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 544 | + * |
|
| 545 | + * @return EE_Price[] |
|
| 546 | + * @throws \EE_Error |
|
| 547 | + */ |
|
| 548 | 548 | public function get_ticket_taxes_for_admin() { |
| 549 | 549 | return EE_Taxes::get_taxes_for_admin(); |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
| 553 | 553 | |
| 554 | - /** |
|
| 555 | - * @return float |
|
| 556 | - * @throws \EE_Error |
|
| 557 | - */ |
|
| 554 | + /** |
|
| 555 | + * @return float |
|
| 556 | + * @throws \EE_Error |
|
| 557 | + */ |
|
| 558 | 558 | public function ticket_price() { |
| 559 | 559 | return $this->get( 'TKT_price' ); |
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | |
| 563 | 563 | |
| 564 | - /** |
|
| 565 | - * @return mixed |
|
| 566 | - * @throws \EE_Error |
|
| 567 | - */ |
|
| 564 | + /** |
|
| 565 | + * @return mixed |
|
| 566 | + * @throws \EE_Error |
|
| 567 | + */ |
|
| 568 | 568 | public function pretty_price() { |
| 569 | 569 | return $this->get_pretty( 'TKT_price' ); |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
| 573 | 573 | |
| 574 | - /** |
|
| 575 | - * @return bool |
|
| 576 | - * @throws \EE_Error |
|
| 577 | - */ |
|
| 574 | + /** |
|
| 575 | + * @return bool |
|
| 576 | + * @throws \EE_Error |
|
| 577 | + */ |
|
| 578 | 578 | public function is_free() { |
| 579 | 579 | return $this->get_ticket_total_with_taxes() === (float) 0; |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | |
| 583 | 583 | |
| 584 | - /** |
|
| 585 | - * get_ticket_total_with_taxes |
|
| 586 | - * |
|
| 587 | - * @param bool $no_cache |
|
| 588 | - * @return float |
|
| 589 | - * @throws \EE_Error |
|
| 590 | - */ |
|
| 584 | + /** |
|
| 585 | + * get_ticket_total_with_taxes |
|
| 586 | + * |
|
| 587 | + * @param bool $no_cache |
|
| 588 | + * @return float |
|
| 589 | + * @throws \EE_Error |
|
| 590 | + */ |
|
| 591 | 591 | public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
| 592 | 592 | if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
| 593 | 593 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
@@ -604,201 +604,201 @@ discard block |
||
| 604 | 604 | |
| 605 | 605 | |
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * @return float |
|
| 609 | - * @throws \EE_Error |
|
| 610 | - */ |
|
| 607 | + /** |
|
| 608 | + * @return float |
|
| 609 | + * @throws \EE_Error |
|
| 610 | + */ |
|
| 611 | 611 | public function get_ticket_subtotal() { |
| 612 | 612 | return EE_Taxes::get_subtotal_for_admin( $this ); |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * Returns the total taxes applied to this ticket |
|
| 619 | - * |
|
| 620 | - * @return float |
|
| 621 | - * @throws \EE_Error |
|
| 622 | - */ |
|
| 617 | + /** |
|
| 618 | + * Returns the total taxes applied to this ticket |
|
| 619 | + * |
|
| 620 | + * @return float |
|
| 621 | + * @throws \EE_Error |
|
| 622 | + */ |
|
| 623 | 623 | public function get_ticket_taxes_total_for_admin() { |
| 624 | 624 | return EE_Taxes::get_total_taxes_for_admin( $this ); |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | |
| 628 | 628 | |
| 629 | - /** |
|
| 630 | - * Sets name |
|
| 631 | - * |
|
| 632 | - * @param string $name |
|
| 633 | - * @throws \EE_Error |
|
| 634 | - */ |
|
| 629 | + /** |
|
| 630 | + * Sets name |
|
| 631 | + * |
|
| 632 | + * @param string $name |
|
| 633 | + * @throws \EE_Error |
|
| 634 | + */ |
|
| 635 | 635 | public function set_name( $name ) { |
| 636 | 636 | $this->set( 'TKT_name', $name ); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
| 640 | 640 | |
| 641 | - /** |
|
| 642 | - * Gets description |
|
| 643 | - * |
|
| 644 | - * @return string |
|
| 645 | - * @throws \EE_Error |
|
| 646 | - */ |
|
| 641 | + /** |
|
| 642 | + * Gets description |
|
| 643 | + * |
|
| 644 | + * @return string |
|
| 645 | + * @throws \EE_Error |
|
| 646 | + */ |
|
| 647 | 647 | public function description() { |
| 648 | 648 | return $this->get( 'TKT_description' ); |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
| 652 | 652 | |
| 653 | - /** |
|
| 654 | - * Sets description |
|
| 655 | - * |
|
| 656 | - * @param string $description |
|
| 657 | - * @throws \EE_Error |
|
| 658 | - */ |
|
| 653 | + /** |
|
| 654 | + * Sets description |
|
| 655 | + * |
|
| 656 | + * @param string $description |
|
| 657 | + * @throws \EE_Error |
|
| 658 | + */ |
|
| 659 | 659 | public function set_description( $description ) { |
| 660 | 660 | $this->set( 'TKT_description', $description ); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | |
| 664 | 664 | |
| 665 | - /** |
|
| 666 | - * Gets start_date |
|
| 667 | - * |
|
| 668 | - * @param string $dt_frmt |
|
| 669 | - * @param string $tm_frmt |
|
| 670 | - * @return string |
|
| 671 | - * @throws \EE_Error |
|
| 672 | - */ |
|
| 665 | + /** |
|
| 666 | + * Gets start_date |
|
| 667 | + * |
|
| 668 | + * @param string $dt_frmt |
|
| 669 | + * @param string $tm_frmt |
|
| 670 | + * @return string |
|
| 671 | + * @throws \EE_Error |
|
| 672 | + */ |
|
| 673 | 673 | public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 674 | 674 | return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | |
| 678 | 678 | |
| 679 | - /** |
|
| 680 | - * Sets start_date |
|
| 681 | - * |
|
| 682 | - * @param string $start_date |
|
| 683 | - * @return void |
|
| 684 | - * @throws \EE_Error |
|
| 685 | - */ |
|
| 679 | + /** |
|
| 680 | + * Sets start_date |
|
| 681 | + * |
|
| 682 | + * @param string $start_date |
|
| 683 | + * @return void |
|
| 684 | + * @throws \EE_Error |
|
| 685 | + */ |
|
| 686 | 686 | public function set_start_date( $start_date ) { |
| 687 | 687 | $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * Gets end_date |
|
| 694 | - * |
|
| 695 | - * @param string $dt_frmt |
|
| 696 | - * @param string $tm_frmt |
|
| 697 | - * @return string |
|
| 698 | - * @throws \EE_Error |
|
| 699 | - */ |
|
| 692 | + /** |
|
| 693 | + * Gets end_date |
|
| 694 | + * |
|
| 695 | + * @param string $dt_frmt |
|
| 696 | + * @param string $tm_frmt |
|
| 697 | + * @return string |
|
| 698 | + * @throws \EE_Error |
|
| 699 | + */ |
|
| 700 | 700 | public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 701 | 701 | return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
| 705 | 705 | |
| 706 | - /** |
|
| 707 | - * Sets end_date |
|
| 708 | - * |
|
| 709 | - * @param string $end_date |
|
| 710 | - * @return void |
|
| 711 | - * @throws \EE_Error |
|
| 712 | - */ |
|
| 706 | + /** |
|
| 707 | + * Sets end_date |
|
| 708 | + * |
|
| 709 | + * @param string $end_date |
|
| 710 | + * @return void |
|
| 711 | + * @throws \EE_Error |
|
| 712 | + */ |
|
| 713 | 713 | public function set_end_date( $end_date ) { |
| 714 | 714 | $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | |
| 718 | 718 | |
| 719 | - /** |
|
| 720 | - * Sets sell until time |
|
| 721 | - * |
|
| 722 | - * @since 4.5.0 |
|
| 723 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 724 | - * @throws \EE_Error |
|
| 725 | - */ |
|
| 719 | + /** |
|
| 720 | + * Sets sell until time |
|
| 721 | + * |
|
| 722 | + * @since 4.5.0 |
|
| 723 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 724 | + * @throws \EE_Error |
|
| 725 | + */ |
|
| 726 | 726 | public function set_end_time( $time ) { |
| 727 | 727 | $this->_set_time_for( $time, 'TKT_end_date' ); |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Sets min |
|
| 734 | - * |
|
| 735 | - * @param int $min |
|
| 736 | - * @return void |
|
| 737 | - * @throws \EE_Error |
|
| 738 | - */ |
|
| 732 | + /** |
|
| 733 | + * Sets min |
|
| 734 | + * |
|
| 735 | + * @param int $min |
|
| 736 | + * @return void |
|
| 737 | + * @throws \EE_Error |
|
| 738 | + */ |
|
| 739 | 739 | public function set_min( $min ) { |
| 740 | 740 | $this->set( 'TKT_min', $min ); |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Gets max |
|
| 747 | - * |
|
| 748 | - * @return int |
|
| 749 | - * @throws \EE_Error |
|
| 750 | - */ |
|
| 745 | + /** |
|
| 746 | + * Gets max |
|
| 747 | + * |
|
| 748 | + * @return int |
|
| 749 | + * @throws \EE_Error |
|
| 750 | + */ |
|
| 751 | 751 | public function max() { |
| 752 | 752 | return $this->get( 'TKT_max' ); |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
| 756 | 756 | |
| 757 | - /** |
|
| 758 | - * Sets max |
|
| 759 | - * |
|
| 760 | - * @param int $max |
|
| 761 | - * @return void |
|
| 762 | - * @throws \EE_Error |
|
| 763 | - */ |
|
| 757 | + /** |
|
| 758 | + * Sets max |
|
| 759 | + * |
|
| 760 | + * @param int $max |
|
| 761 | + * @return void |
|
| 762 | + * @throws \EE_Error |
|
| 763 | + */ |
|
| 764 | 764 | public function set_max( $max ) { |
| 765 | 765 | $this->set( 'TKT_max', $max ); |
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | |
| 769 | 769 | |
| 770 | - /** |
|
| 771 | - * Sets price |
|
| 772 | - * |
|
| 773 | - * @param float $price |
|
| 774 | - * @return void |
|
| 775 | - * @throws \EE_Error |
|
| 776 | - */ |
|
| 770 | + /** |
|
| 771 | + * Sets price |
|
| 772 | + * |
|
| 773 | + * @param float $price |
|
| 774 | + * @return void |
|
| 775 | + * @throws \EE_Error |
|
| 776 | + */ |
|
| 777 | 777 | public function set_price( $price ) { |
| 778 | 778 | $this->set( 'TKT_price', $price ); |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
| 782 | 782 | |
| 783 | - /** |
|
| 784 | - * Gets sold |
|
| 785 | - * |
|
| 786 | - * @return int |
|
| 787 | - * @throws \EE_Error |
|
| 788 | - */ |
|
| 783 | + /** |
|
| 784 | + * Gets sold |
|
| 785 | + * |
|
| 786 | + * @return int |
|
| 787 | + * @throws \EE_Error |
|
| 788 | + */ |
|
| 789 | 789 | public function sold() { |
| 790 | 790 | return $this->get_raw( 'TKT_sold' ); |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | |
| 794 | 794 | |
| 795 | - /** |
|
| 796 | - * Sets sold |
|
| 797 | - * |
|
| 798 | - * @param int $sold |
|
| 799 | - * @return void |
|
| 800 | - * @throws \EE_Error |
|
| 801 | - */ |
|
| 795 | + /** |
|
| 796 | + * Sets sold |
|
| 797 | + * |
|
| 798 | + * @param int $sold |
|
| 799 | + * @return void |
|
| 800 | + * @throws \EE_Error |
|
| 801 | + */ |
|
| 802 | 802 | public function set_sold( $sold ) { |
| 803 | 803 | // sold can not go below zero |
| 804 | 804 | $sold = max( 0, $sold ); |
@@ -807,13 +807,13 @@ discard block |
||
| 807 | 807 | |
| 808 | 808 | |
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * increments sold by amount passed by $qty |
|
| 812 | - * |
|
| 813 | - * @param int $qty |
|
| 814 | - * @return void |
|
| 815 | - * @throws \EE_Error |
|
| 816 | - */ |
|
| 810 | + /** |
|
| 811 | + * increments sold by amount passed by $qty |
|
| 812 | + * |
|
| 813 | + * @param int $qty |
|
| 814 | + * @return void |
|
| 815 | + * @throws \EE_Error |
|
| 816 | + */ |
|
| 817 | 817 | public function increase_sold( $qty = 1 ) { |
| 818 | 818 | $sold = $this->sold() + $qty; |
| 819 | 819 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
@@ -822,22 +822,22 @@ discard block |
||
| 822 | 822 | $this->_increase_sold_for_datetimes( $qty ); |
| 823 | 823 | $this->set_sold( $sold ); |
| 824 | 824 | do_action( |
| 825 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 826 | - $this, |
|
| 827 | - $qty, |
|
| 828 | - $sold |
|
| 829 | - ); |
|
| 825 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 826 | + $this, |
|
| 827 | + $qty, |
|
| 828 | + $sold |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | |
| 833 | 833 | |
| 834 | - /** |
|
| 835 | - * Increases sold on related datetimes |
|
| 836 | - * |
|
| 837 | - * @param int $qty |
|
| 838 | - * @return void |
|
| 839 | - * @throws \EE_Error |
|
| 840 | - */ |
|
| 834 | + /** |
|
| 835 | + * Increases sold on related datetimes |
|
| 836 | + * |
|
| 837 | + * @param int $qty |
|
| 838 | + * @return void |
|
| 839 | + * @throws \EE_Error |
|
| 840 | + */ |
|
| 841 | 841 | protected function _increase_sold_for_datetimes( $qty = 1 ) { |
| 842 | 842 | $datetimes = $this->datetimes(); |
| 843 | 843 | if ( is_array( $datetimes ) ) { |
@@ -852,34 +852,34 @@ discard block |
||
| 852 | 852 | |
| 853 | 853 | |
| 854 | 854 | |
| 855 | - /** |
|
| 856 | - * decrements (subtracts) sold by amount passed by $qty |
|
| 857 | - * |
|
| 858 | - * @param int $qty |
|
| 859 | - * @return void |
|
| 860 | - * @throws \EE_Error |
|
| 861 | - */ |
|
| 855 | + /** |
|
| 856 | + * decrements (subtracts) sold by amount passed by $qty |
|
| 857 | + * |
|
| 858 | + * @param int $qty |
|
| 859 | + * @return void |
|
| 860 | + * @throws \EE_Error |
|
| 861 | + */ |
|
| 862 | 862 | public function decrease_sold( $qty = 1 ) { |
| 863 | 863 | $sold = $this->sold() - $qty; |
| 864 | 864 | $this->_decrease_sold_for_datetimes( $qty ); |
| 865 | 865 | $this->set_sold( $sold ); |
| 866 | - do_action( |
|
| 867 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 868 | - $this, |
|
| 869 | - $qty, |
|
| 870 | - $sold |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - /** |
|
| 877 | - * Decreases sold on related datetimes |
|
| 878 | - * |
|
| 879 | - * @param int $qty |
|
| 880 | - * @return void |
|
| 881 | - * @throws \EE_Error |
|
| 882 | - */ |
|
| 866 | + do_action( |
|
| 867 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 868 | + $this, |
|
| 869 | + $qty, |
|
| 870 | + $sold |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + /** |
|
| 877 | + * Decreases sold on related datetimes |
|
| 878 | + * |
|
| 879 | + * @param int $qty |
|
| 880 | + * @return void |
|
| 881 | + * @throws \EE_Error |
|
| 882 | + */ |
|
| 883 | 883 | protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
| 884 | 884 | $datetimes = $this->datetimes(); |
| 885 | 885 | if ( is_array( $datetimes ) ) { |
@@ -894,25 +894,25 @@ discard block |
||
| 894 | 894 | |
| 895 | 895 | |
| 896 | 896 | |
| 897 | - /** |
|
| 898 | - * Gets qty of reserved tickets |
|
| 899 | - * |
|
| 900 | - * @return int |
|
| 901 | - * @throws \EE_Error |
|
| 902 | - */ |
|
| 897 | + /** |
|
| 898 | + * Gets qty of reserved tickets |
|
| 899 | + * |
|
| 900 | + * @return int |
|
| 901 | + * @throws \EE_Error |
|
| 902 | + */ |
|
| 903 | 903 | public function reserved() { |
| 904 | 904 | return $this->get_raw( 'TKT_reserved' ); |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | |
| 908 | 908 | |
| 909 | - /** |
|
| 910 | - * Sets reserved |
|
| 911 | - * |
|
| 912 | - * @param int $reserved |
|
| 913 | - * @return void |
|
| 914 | - * @throws \EE_Error |
|
| 915 | - */ |
|
| 909 | + /** |
|
| 910 | + * Sets reserved |
|
| 911 | + * |
|
| 912 | + * @param int $reserved |
|
| 913 | + * @return void |
|
| 914 | + * @throws \EE_Error |
|
| 915 | + */ |
|
| 916 | 916 | public function set_reserved( $reserved ) { |
| 917 | 917 | // reserved can not go below zero |
| 918 | 918 | $reserved = max( 0, (int) $reserved ); |
@@ -921,35 +921,35 @@ discard block |
||
| 921 | 921 | |
| 922 | 922 | |
| 923 | 923 | |
| 924 | - /** |
|
| 925 | - * increments reserved by amount passed by $qty |
|
| 926 | - * |
|
| 927 | - * @param int $qty |
|
| 928 | - * @return void |
|
| 929 | - * @throws \EE_Error |
|
| 930 | - */ |
|
| 924 | + /** |
|
| 925 | + * increments reserved by amount passed by $qty |
|
| 926 | + * |
|
| 927 | + * @param int $qty |
|
| 928 | + * @return void |
|
| 929 | + * @throws \EE_Error |
|
| 930 | + */ |
|
| 931 | 931 | public function increase_reserved( $qty = 1 ) { |
| 932 | 932 | $qty = absint( $qty ); |
| 933 | 933 | $reserved = $this->reserved() + $qty; |
| 934 | 934 | $this->_increase_reserved_for_datetimes( $qty ); |
| 935 | 935 | $this->set_reserved( $reserved ); |
| 936 | - do_action( |
|
| 937 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 938 | - $this, |
|
| 939 | - $qty, |
|
| 940 | - $reserved |
|
| 941 | - ); |
|
| 942 | - } |
|
| 943 | - |
|
| 944 | - |
|
| 945 | - |
|
| 946 | - /** |
|
| 947 | - * Increases sold on related datetimes |
|
| 948 | - * |
|
| 949 | - * @param int $qty |
|
| 950 | - * @return void |
|
| 951 | - * @throws \EE_Error |
|
| 952 | - */ |
|
| 936 | + do_action( |
|
| 937 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 938 | + $this, |
|
| 939 | + $qty, |
|
| 940 | + $reserved |
|
| 941 | + ); |
|
| 942 | + } |
|
| 943 | + |
|
| 944 | + |
|
| 945 | + |
|
| 946 | + /** |
|
| 947 | + * Increases sold on related datetimes |
|
| 948 | + * |
|
| 949 | + * @param int $qty |
|
| 950 | + * @return void |
|
| 951 | + * @throws \EE_Error |
|
| 952 | + */ |
|
| 953 | 953 | protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
| 954 | 954 | $datetimes = $this->datetimes(); |
| 955 | 955 | if ( is_array( $datetimes ) ) { |
@@ -964,37 +964,37 @@ discard block |
||
| 964 | 964 | |
| 965 | 965 | |
| 966 | 966 | |
| 967 | - /** |
|
| 968 | - * decrements (subtracts) reserved by amount passed by $qty |
|
| 969 | - * |
|
| 970 | - * @param int $qty |
|
| 971 | - * @param bool $adjust_datetimes |
|
| 972 | - * @return void |
|
| 973 | - * @throws \EE_Error |
|
| 974 | - */ |
|
| 967 | + /** |
|
| 968 | + * decrements (subtracts) reserved by amount passed by $qty |
|
| 969 | + * |
|
| 970 | + * @param int $qty |
|
| 971 | + * @param bool $adjust_datetimes |
|
| 972 | + * @return void |
|
| 973 | + * @throws \EE_Error |
|
| 974 | + */ |
|
| 975 | 975 | public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) { |
| 976 | 976 | $reserved = $this->reserved() - absint( $qty ); |
| 977 | 977 | if ( $adjust_datetimes ) { |
| 978 | 978 | $this->_decrease_reserved_for_datetimes( $qty ); |
| 979 | 979 | } |
| 980 | 980 | $this->set_reserved( $reserved ); |
| 981 | - do_action( |
|
| 982 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 983 | - $this, |
|
| 984 | - $qty, |
|
| 985 | - $reserved |
|
| 986 | - ); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - |
|
| 990 | - |
|
| 991 | - /** |
|
| 992 | - * Increases sold on related datetimes |
|
| 993 | - * |
|
| 994 | - * @param int $qty |
|
| 995 | - * @return void |
|
| 996 | - * @throws \EE_Error |
|
| 997 | - */ |
|
| 981 | + do_action( |
|
| 982 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 983 | + $this, |
|
| 984 | + $qty, |
|
| 985 | + $reserved |
|
| 986 | + ); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + |
|
| 990 | + |
|
| 991 | + /** |
|
| 992 | + * Increases sold on related datetimes |
|
| 993 | + * |
|
| 994 | + * @param int $qty |
|
| 995 | + * @return void |
|
| 996 | + * @throws \EE_Error |
|
| 997 | + */ |
|
| 998 | 998 | protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
| 999 | 999 | $datetimes = $this->datetimes(); |
| 1000 | 1000 | if ( is_array( $datetimes ) ) { |
@@ -1009,18 +1009,18 @@ discard block |
||
| 1009 | 1009 | |
| 1010 | 1010 | |
| 1011 | 1011 | |
| 1012 | - /** |
|
| 1013 | - * Gets ticket quantity |
|
| 1014 | - * |
|
| 1015 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1016 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1017 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1018 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1019 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1020 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1021 | - * @return int |
|
| 1022 | - * @throws \EE_Error |
|
| 1023 | - */ |
|
| 1012 | + /** |
|
| 1013 | + * Gets ticket quantity |
|
| 1014 | + * |
|
| 1015 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1016 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 1017 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 1018 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1019 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1020 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1021 | + * @return int |
|
| 1022 | + * @throws \EE_Error |
|
| 1023 | + */ |
|
| 1024 | 1024 | public function qty( $context = '' ) { |
| 1025 | 1025 | switch ( $context ) { |
| 1026 | 1026 | case 'reg_limit' : |
@@ -1034,19 +1034,19 @@ discard block |
||
| 1034 | 1034 | |
| 1035 | 1035 | |
| 1036 | 1036 | |
| 1037 | - /** |
|
| 1038 | - * Gets ticket quantity |
|
| 1039 | - * |
|
| 1040 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1041 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1042 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1043 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1044 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1045 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1046 | - * set to 0 for all related datetimes |
|
| 1047 | - * @return int |
|
| 1048 | - * @throws \EE_Error |
|
| 1049 | - */ |
|
| 1037 | + /** |
|
| 1038 | + * Gets ticket quantity |
|
| 1039 | + * |
|
| 1040 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 1041 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 1042 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 1043 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 1044 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 1045 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 1046 | + * set to 0 for all related datetimes |
|
| 1047 | + * @return int |
|
| 1048 | + * @throws \EE_Error |
|
| 1049 | + */ |
|
| 1050 | 1050 | public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
| 1051 | 1051 | $raw = $this->get_raw( 'TKT_qty' ); |
| 1052 | 1052 | // return immediately if it's zero |
@@ -1129,212 +1129,212 @@ discard block |
||
| 1129 | 1129 | |
| 1130 | 1130 | |
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * Gets uses |
|
| 1134 | - * |
|
| 1135 | - * @return int |
|
| 1136 | - * @throws \EE_Error |
|
| 1137 | - */ |
|
| 1132 | + /** |
|
| 1133 | + * Gets uses |
|
| 1134 | + * |
|
| 1135 | + * @return int |
|
| 1136 | + * @throws \EE_Error |
|
| 1137 | + */ |
|
| 1138 | 1138 | public function uses() { |
| 1139 | 1139 | return $this->get( 'TKT_uses' ); |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
| 1143 | 1143 | |
| 1144 | - /** |
|
| 1145 | - * Sets uses |
|
| 1146 | - * |
|
| 1147 | - * @param int $uses |
|
| 1148 | - * @return void |
|
| 1149 | - * @throws \EE_Error |
|
| 1150 | - */ |
|
| 1144 | + /** |
|
| 1145 | + * Sets uses |
|
| 1146 | + * |
|
| 1147 | + * @param int $uses |
|
| 1148 | + * @return void |
|
| 1149 | + * @throws \EE_Error |
|
| 1150 | + */ |
|
| 1151 | 1151 | public function set_uses( $uses ) { |
| 1152 | 1152 | $this->set( 'TKT_uses', $uses ); |
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | |
| 1156 | 1156 | |
| 1157 | - /** |
|
| 1158 | - * returns whether ticket is required or not. |
|
| 1159 | - * |
|
| 1160 | - * @return boolean |
|
| 1161 | - * @throws \EE_Error |
|
| 1162 | - */ |
|
| 1157 | + /** |
|
| 1158 | + * returns whether ticket is required or not. |
|
| 1159 | + * |
|
| 1160 | + * @return boolean |
|
| 1161 | + * @throws \EE_Error |
|
| 1162 | + */ |
|
| 1163 | 1163 | public function required() { |
| 1164 | 1164 | return $this->get( 'TKT_required' ); |
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | |
| 1168 | 1168 | |
| 1169 | - /** |
|
| 1170 | - * sets the TKT_required property |
|
| 1171 | - * |
|
| 1172 | - * @param boolean $required |
|
| 1173 | - * @return void |
|
| 1174 | - * @throws \EE_Error |
|
| 1175 | - */ |
|
| 1169 | + /** |
|
| 1170 | + * sets the TKT_required property |
|
| 1171 | + * |
|
| 1172 | + * @param boolean $required |
|
| 1173 | + * @return void |
|
| 1174 | + * @throws \EE_Error |
|
| 1175 | + */ |
|
| 1176 | 1176 | public function set_required( $required ) { |
| 1177 | 1177 | $this->set( 'TKT_required', $required ); |
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | |
| 1181 | 1181 | |
| 1182 | - /** |
|
| 1183 | - * Gets taxable |
|
| 1184 | - * |
|
| 1185 | - * @return boolean |
|
| 1186 | - * @throws \EE_Error |
|
| 1187 | - */ |
|
| 1182 | + /** |
|
| 1183 | + * Gets taxable |
|
| 1184 | + * |
|
| 1185 | + * @return boolean |
|
| 1186 | + * @throws \EE_Error |
|
| 1187 | + */ |
|
| 1188 | 1188 | public function taxable() { |
| 1189 | 1189 | return $this->get( 'TKT_taxable' ); |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | |
| 1193 | 1193 | |
| 1194 | - /** |
|
| 1195 | - * Sets taxable |
|
| 1196 | - * |
|
| 1197 | - * @param boolean $taxable |
|
| 1198 | - * @return void |
|
| 1199 | - * @throws \EE_Error |
|
| 1200 | - */ |
|
| 1194 | + /** |
|
| 1195 | + * Sets taxable |
|
| 1196 | + * |
|
| 1197 | + * @param boolean $taxable |
|
| 1198 | + * @return void |
|
| 1199 | + * @throws \EE_Error |
|
| 1200 | + */ |
|
| 1201 | 1201 | public function set_taxable( $taxable ) { |
| 1202 | 1202 | $this->set( 'TKT_taxable', $taxable ); |
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | |
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Gets is_default |
|
| 1209 | - * |
|
| 1210 | - * @return boolean |
|
| 1211 | - * @throws \EE_Error |
|
| 1212 | - */ |
|
| 1207 | + /** |
|
| 1208 | + * Gets is_default |
|
| 1209 | + * |
|
| 1210 | + * @return boolean |
|
| 1211 | + * @throws \EE_Error |
|
| 1212 | + */ |
|
| 1213 | 1213 | public function is_default() { |
| 1214 | 1214 | return $this->get( 'TKT_is_default' ); |
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | |
| 1218 | 1218 | |
| 1219 | - /** |
|
| 1220 | - * Sets is_default |
|
| 1221 | - * |
|
| 1222 | - * @param boolean $is_default |
|
| 1223 | - * @return void |
|
| 1224 | - * @throws \EE_Error |
|
| 1225 | - */ |
|
| 1219 | + /** |
|
| 1220 | + * Sets is_default |
|
| 1221 | + * |
|
| 1222 | + * @param boolean $is_default |
|
| 1223 | + * @return void |
|
| 1224 | + * @throws \EE_Error |
|
| 1225 | + */ |
|
| 1226 | 1226 | public function set_is_default( $is_default ) { |
| 1227 | 1227 | $this->set( 'TKT_is_default', $is_default ); |
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | |
| 1231 | 1231 | |
| 1232 | - /** |
|
| 1233 | - * Gets order |
|
| 1234 | - * |
|
| 1235 | - * @return int |
|
| 1236 | - * @throws \EE_Error |
|
| 1237 | - */ |
|
| 1232 | + /** |
|
| 1233 | + * Gets order |
|
| 1234 | + * |
|
| 1235 | + * @return int |
|
| 1236 | + * @throws \EE_Error |
|
| 1237 | + */ |
|
| 1238 | 1238 | public function order() { |
| 1239 | 1239 | return $this->get( 'TKT_order' ); |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | |
| 1243 | 1243 | |
| 1244 | - /** |
|
| 1245 | - * Sets order |
|
| 1246 | - * |
|
| 1247 | - * @param int $order |
|
| 1248 | - * @return void |
|
| 1249 | - * @throws \EE_Error |
|
| 1250 | - */ |
|
| 1244 | + /** |
|
| 1245 | + * Sets order |
|
| 1246 | + * |
|
| 1247 | + * @param int $order |
|
| 1248 | + * @return void |
|
| 1249 | + * @throws \EE_Error |
|
| 1250 | + */ |
|
| 1251 | 1251 | public function set_order( $order ) { |
| 1252 | 1252 | $this->set( 'TKT_order', $order ); |
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
| 1256 | 1256 | |
| 1257 | - /** |
|
| 1258 | - * Gets row |
|
| 1259 | - * |
|
| 1260 | - * @return int |
|
| 1261 | - * @throws \EE_Error |
|
| 1262 | - */ |
|
| 1257 | + /** |
|
| 1258 | + * Gets row |
|
| 1259 | + * |
|
| 1260 | + * @return int |
|
| 1261 | + * @throws \EE_Error |
|
| 1262 | + */ |
|
| 1263 | 1263 | public function row() { |
| 1264 | 1264 | return $this->get( 'TKT_row' ); |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | |
| 1268 | 1268 | |
| 1269 | - /** |
|
| 1270 | - * Sets row |
|
| 1271 | - * |
|
| 1272 | - * @param int $row |
|
| 1273 | - * @return void |
|
| 1274 | - * @throws \EE_Error |
|
| 1275 | - */ |
|
| 1269 | + /** |
|
| 1270 | + * Sets row |
|
| 1271 | + * |
|
| 1272 | + * @param int $row |
|
| 1273 | + * @return void |
|
| 1274 | + * @throws \EE_Error |
|
| 1275 | + */ |
|
| 1276 | 1276 | public function set_row( $row ) { |
| 1277 | 1277 | $this->set( 'TKT_row', $row ); |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | |
| 1281 | 1281 | |
| 1282 | - /** |
|
| 1283 | - * Gets deleted |
|
| 1284 | - * |
|
| 1285 | - * @return boolean |
|
| 1286 | - * @throws \EE_Error |
|
| 1287 | - */ |
|
| 1282 | + /** |
|
| 1283 | + * Gets deleted |
|
| 1284 | + * |
|
| 1285 | + * @return boolean |
|
| 1286 | + * @throws \EE_Error |
|
| 1287 | + */ |
|
| 1288 | 1288 | public function deleted() { |
| 1289 | 1289 | return $this->get( 'TKT_deleted' ); |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | |
| 1293 | 1293 | |
| 1294 | - /** |
|
| 1295 | - * Sets deleted |
|
| 1296 | - * |
|
| 1297 | - * @param boolean $deleted |
|
| 1298 | - * @return void |
|
| 1299 | - * @throws \EE_Error |
|
| 1300 | - */ |
|
| 1294 | + /** |
|
| 1295 | + * Sets deleted |
|
| 1296 | + * |
|
| 1297 | + * @param boolean $deleted |
|
| 1298 | + * @return void |
|
| 1299 | + * @throws \EE_Error |
|
| 1300 | + */ |
|
| 1301 | 1301 | public function set_deleted( $deleted ) { |
| 1302 | 1302 | $this->set( 'TKT_deleted', $deleted ); |
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | |
| 1306 | 1306 | |
| 1307 | - /** |
|
| 1308 | - * Gets parent |
|
| 1309 | - * |
|
| 1310 | - * @return int |
|
| 1311 | - * @throws \EE_Error |
|
| 1312 | - */ |
|
| 1307 | + /** |
|
| 1308 | + * Gets parent |
|
| 1309 | + * |
|
| 1310 | + * @return int |
|
| 1311 | + * @throws \EE_Error |
|
| 1312 | + */ |
|
| 1313 | 1313 | public function parent_ID() { |
| 1314 | 1314 | return $this->get( 'TKT_parent' ); |
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | |
| 1318 | 1318 | |
| 1319 | - /** |
|
| 1320 | - * Sets parent |
|
| 1321 | - * |
|
| 1322 | - * @param int $parent |
|
| 1323 | - * @return void |
|
| 1324 | - * @throws \EE_Error |
|
| 1325 | - */ |
|
| 1319 | + /** |
|
| 1320 | + * Sets parent |
|
| 1321 | + * |
|
| 1322 | + * @param int $parent |
|
| 1323 | + * @return void |
|
| 1324 | + * @throws \EE_Error |
|
| 1325 | + */ |
|
| 1326 | 1326 | public function set_parent_ID( $parent ) { |
| 1327 | 1327 | $this->set( 'TKT_parent', $parent ); |
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | |
| 1331 | 1331 | |
| 1332 | - /** |
|
| 1333 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1334 | - * |
|
| 1335 | - * @return string |
|
| 1336 | - * @throws \EE_Error |
|
| 1337 | - */ |
|
| 1332 | + /** |
|
| 1333 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1334 | + * |
|
| 1335 | + * @return string |
|
| 1336 | + * @throws \EE_Error |
|
| 1337 | + */ |
|
| 1338 | 1338 | public function name_and_info() { |
| 1339 | 1339 | $times = array(); |
| 1340 | 1340 | foreach ( $this->datetimes() as $datetime ) { |
@@ -1345,67 +1345,67 @@ discard block |
||
| 1345 | 1345 | |
| 1346 | 1346 | |
| 1347 | 1347 | |
| 1348 | - /** |
|
| 1349 | - * Gets name |
|
| 1350 | - * |
|
| 1351 | - * @return string |
|
| 1352 | - * @throws \EE_Error |
|
| 1353 | - */ |
|
| 1348 | + /** |
|
| 1349 | + * Gets name |
|
| 1350 | + * |
|
| 1351 | + * @return string |
|
| 1352 | + * @throws \EE_Error |
|
| 1353 | + */ |
|
| 1354 | 1354 | public function name() { |
| 1355 | 1355 | return $this->get( 'TKT_name' ); |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
| 1359 | 1359 | |
| 1360 | - /** |
|
| 1361 | - * Gets price |
|
| 1362 | - * |
|
| 1363 | - * @return float |
|
| 1364 | - * @throws \EE_Error |
|
| 1365 | - */ |
|
| 1360 | + /** |
|
| 1361 | + * Gets price |
|
| 1362 | + * |
|
| 1363 | + * @return float |
|
| 1364 | + * @throws \EE_Error |
|
| 1365 | + */ |
|
| 1366 | 1366 | public function price() { |
| 1367 | 1367 | return $this->get( 'TKT_price' ); |
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
| 1371 | 1371 | |
| 1372 | - /** |
|
| 1373 | - * Gets all the registrations for this ticket |
|
| 1374 | - * |
|
| 1375 | - * @param array $query_params like EEM_Base::get_all's |
|
| 1376 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1377 | - * @throws \EE_Error |
|
| 1378 | - */ |
|
| 1372 | + /** |
|
| 1373 | + * Gets all the registrations for this ticket |
|
| 1374 | + * |
|
| 1375 | + * @param array $query_params like EEM_Base::get_all's |
|
| 1376 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1377 | + * @throws \EE_Error |
|
| 1378 | + */ |
|
| 1379 | 1379 | public function registrations( $query_params = array() ) { |
| 1380 | 1380 | return $this->get_many_related( 'Registration', $query_params ); |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | |
| 1384 | 1384 | |
| 1385 | - /** |
|
| 1386 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1387 | - * into account |
|
| 1388 | - * |
|
| 1389 | - * @return int |
|
| 1390 | - * @throws \EE_Error |
|
| 1391 | - */ |
|
| 1385 | + /** |
|
| 1386 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1387 | + * into account |
|
| 1388 | + * |
|
| 1389 | + * @return int |
|
| 1390 | + * @throws \EE_Error |
|
| 1391 | + */ |
|
| 1392 | 1392 | public function update_tickets_sold() { |
| 1393 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1394 | - array( |
|
| 1395 | - array( |
|
| 1396 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1397 | - 'REG_deleted' => 0, |
|
| 1398 | - ), |
|
| 1399 | - ) |
|
| 1400 | - ); |
|
| 1401 | - $sold = $this->sold(); |
|
| 1402 | - if ($count_regs_for_this_ticket > $sold) { |
|
| 1403 | - $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1404 | - $this->save(); |
|
| 1405 | - } else if ($count_regs_for_this_ticket < $sold) { |
|
| 1406 | - $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1407 | - $this->save(); |
|
| 1408 | - } |
|
| 1393 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1394 | + array( |
|
| 1395 | + array( |
|
| 1396 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1397 | + 'REG_deleted' => 0, |
|
| 1398 | + ), |
|
| 1399 | + ) |
|
| 1400 | + ); |
|
| 1401 | + $sold = $this->sold(); |
|
| 1402 | + if ($count_regs_for_this_ticket > $sold) { |
|
| 1403 | + $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1404 | + $this->save(); |
|
| 1405 | + } else if ($count_regs_for_this_ticket < $sold) { |
|
| 1406 | + $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1407 | + $this->save(); |
|
| 1408 | + } |
|
| 1409 | 1409 | return $count_regs_for_this_ticket; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
@@ -1433,21 +1433,21 @@ discard block |
||
| 1433 | 1433 | |
| 1434 | 1434 | |
| 1435 | 1435 | |
| 1436 | - /** |
|
| 1437 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1438 | - * |
|
| 1439 | - * @see EEI_Event_Relation for comments |
|
| 1440 | - * @return EE_Event |
|
| 1441 | - * @throws \EE_Error |
|
| 1442 | - * @throws UnexpectedEntityException |
|
| 1443 | - */ |
|
| 1436 | + /** |
|
| 1437 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1438 | + * |
|
| 1439 | + * @see EEI_Event_Relation for comments |
|
| 1440 | + * @return EE_Event |
|
| 1441 | + * @throws \EE_Error |
|
| 1442 | + * @throws UnexpectedEntityException |
|
| 1443 | + */ |
|
| 1444 | 1444 | public function get_related_event() { |
| 1445 | 1445 | //get one datetime to use for getting the event |
| 1446 | 1446 | $datetime = $this->first_datetime(); |
| 1447 | 1447 | if ( ! $datetime instanceof \EE_Datetime ) { |
| 1448 | 1448 | throw new UnexpectedEntityException( |
| 1449 | 1449 | $datetime, |
| 1450 | - 'EE_Datetime', |
|
| 1450 | + 'EE_Datetime', |
|
| 1451 | 1451 | sprintf( |
| 1452 | 1452 | __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
| 1453 | 1453 | $this->name() |
@@ -1458,7 +1458,7 @@ discard block |
||
| 1458 | 1458 | if ( ! $event instanceof \EE_Event ) { |
| 1459 | 1459 | throw new UnexpectedEntityException( |
| 1460 | 1460 | $event, |
| 1461 | - 'EE_Event', |
|
| 1461 | + 'EE_Event', |
|
| 1462 | 1462 | sprintf( |
| 1463 | 1463 | __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
| 1464 | 1464 | $this->name() |
@@ -1470,14 +1470,14 @@ discard block |
||
| 1470 | 1470 | |
| 1471 | 1471 | |
| 1472 | 1472 | |
| 1473 | - /** |
|
| 1474 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1475 | - * |
|
| 1476 | - * @see EEI_Event_Relation for comments |
|
| 1477 | - * @return string |
|
| 1478 | - * @throws UnexpectedEntityException |
|
| 1479 | - * @throws \EE_Error |
|
| 1480 | - */ |
|
| 1473 | + /** |
|
| 1474 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1475 | + * |
|
| 1476 | + * @see EEI_Event_Relation for comments |
|
| 1477 | + * @return string |
|
| 1478 | + * @throws UnexpectedEntityException |
|
| 1479 | + * @throws \EE_Error |
|
| 1480 | + */ |
|
| 1481 | 1481 | public function get_event_name() { |
| 1482 | 1482 | $event = $this->get_related_event(); |
| 1483 | 1483 | return $event instanceof EE_Event ? $event->name() : ''; |
@@ -1485,62 +1485,62 @@ discard block |
||
| 1485 | 1485 | |
| 1486 | 1486 | |
| 1487 | 1487 | |
| 1488 | - /** |
|
| 1489 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1490 | - * |
|
| 1491 | - * @see EEI_Event_Relation for comments |
|
| 1492 | - * @return int |
|
| 1493 | - * @throws UnexpectedEntityException |
|
| 1494 | - * @throws \EE_Error |
|
| 1495 | - */ |
|
| 1488 | + /** |
|
| 1489 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1490 | + * |
|
| 1491 | + * @see EEI_Event_Relation for comments |
|
| 1492 | + * @return int |
|
| 1493 | + * @throws UnexpectedEntityException |
|
| 1494 | + * @throws \EE_Error |
|
| 1495 | + */ |
|
| 1496 | 1496 | public function get_event_ID() { |
| 1497 | 1497 | $event = $this->get_related_event(); |
| 1498 | 1498 | return $event instanceof EE_Event ? $event->ID() : 0; |
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | |
| 1502 | - /** |
|
| 1503 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1504 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1505 | - * If there are none then it can be permanently deleted. |
|
| 1506 | - * |
|
| 1507 | - * @return bool |
|
| 1508 | - */ |
|
| 1502 | + /** |
|
| 1503 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1504 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1505 | + * If there are none then it can be permanently deleted. |
|
| 1506 | + * |
|
| 1507 | + * @return bool |
|
| 1508 | + */ |
|
| 1509 | 1509 | public function is_permanently_deleteable() { |
| 1510 | - return $this->count_registrations() === 0; |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - |
|
| 1514 | - /** |
|
| 1515 | - * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 1516 | - * in the currency's main units) |
|
| 1517 | - * |
|
| 1518 | - * @return int |
|
| 1519 | - * @throws EE_Error |
|
| 1520 | - * @throws InvalidEntityException |
|
| 1521 | - * @throws DomainException |
|
| 1522 | - */ |
|
| 1523 | - public function amountInSubunits() |
|
| 1524 | - { |
|
| 1525 | - return $this->moneyInSubunits('TKT_price'); |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - |
|
| 1529 | - /** |
|
| 1530 | - * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 1531 | - * the amount is actually assumed to be in the currency's main units |
|
| 1532 | - * |
|
| 1533 | - * @param int $amount_in_subunits |
|
| 1534 | - * @return void |
|
| 1535 | - * @throws EE_Error |
|
| 1536 | - * @throws InvalidArgumentException |
|
| 1537 | - * @throws InvalidInterfaceException |
|
| 1538 | - * @throws InvalidIdentifierException |
|
| 1539 | - * @throws InvalidDataTypeException |
|
| 1540 | - * @throws DomainException |
|
| 1541 | - */ |
|
| 1542 | - public function setAmountInSubunits($amount_in_subunits) |
|
| 1543 | - { |
|
| 1544 | - $this->setMoneySubunits('TKT_price', $amount_in_subunits); |
|
| 1545 | - } |
|
| 1510 | + return $this->count_registrations() === 0; |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + |
|
| 1514 | + /** |
|
| 1515 | + * Returns the payment's amount in subunits (if the currency has subunits; otherwise this will actually be |
|
| 1516 | + * in the currency's main units) |
|
| 1517 | + * |
|
| 1518 | + * @return int |
|
| 1519 | + * @throws EE_Error |
|
| 1520 | + * @throws InvalidEntityException |
|
| 1521 | + * @throws DomainException |
|
| 1522 | + */ |
|
| 1523 | + public function amountInSubunits() |
|
| 1524 | + { |
|
| 1525 | + return $this->moneyInSubunits('TKT_price'); |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + |
|
| 1529 | + /** |
|
| 1530 | + * Sets the payment's amount based on the incoming monetary subunits (eg pennies). If the currency has no subunits, |
|
| 1531 | + * the amount is actually assumed to be in the currency's main units |
|
| 1532 | + * |
|
| 1533 | + * @param int $amount_in_subunits |
|
| 1534 | + * @return void |
|
| 1535 | + * @throws EE_Error |
|
| 1536 | + * @throws InvalidArgumentException |
|
| 1537 | + * @throws InvalidInterfaceException |
|
| 1538 | + * @throws InvalidIdentifierException |
|
| 1539 | + * @throws InvalidDataTypeException |
|
| 1540 | + * @throws DomainException |
|
| 1541 | + */ |
|
| 1542 | + public function setAmountInSubunits($amount_in_subunits) |
|
| 1543 | + { |
|
| 1544 | + $this->setMoneySubunits('TKT_price', $amount_in_subunits); |
|
| 1545 | + } |
|
| 1546 | 1546 | } //end EE_Ticket class |
@@ -7,8 +7,8 @@ discard block |
||
| 7 | 7 | use EventEspresso\core\services\currency\MoneyFactory; |
| 8 | 8 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 9 | 9 | |
| 10 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 11 | - exit( 'No direct script access allowed' ); |
|
| 10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | + exit('No direct script access allowed'); |
|
| 12 | 12 | } |
| 13 | 13 | /** |
| 14 | 14 | * Event Espresso |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | array $date_formats = array(), |
| 161 | 161 | MoneyFactory $money_factory = null |
| 162 | 162 | ) { |
| 163 | - if (! $money_factory instanceof MoneyFactory) { |
|
| 163 | + if ( ! $money_factory instanceof MoneyFactory) { |
|
| 164 | 164 | $money_factory = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\currency\MoneyFactory'); |
| 165 | 165 | } |
| 166 | 166 | $this->money_factory = $money_factory; |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @throws \EE_Error |
| 174 | 174 | */ |
| 175 | 175 | public function parent() { |
| 176 | - return $this->get( 'TKT_parent' ); |
|
| 176 | + return $this->get('TKT_parent'); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | * @return boolean |
| 186 | 186 | * @throws \EE_Error |
| 187 | 187 | */ |
| 188 | - public function available( $DTT_ID = 0 ) { |
|
| 188 | + public function available($DTT_ID = 0) { |
|
| 189 | 189 | // are we checking availability for a particular datetime ? |
| 190 | - if ( $DTT_ID ) { |
|
| 190 | + if ($DTT_ID) { |
|
| 191 | 191 | // get that datetime object |
| 192 | - $datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
| 192 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
| 193 | 193 | // if ticket sales for this datetime have exceeded the reg limit... |
| 194 | - if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) { |
|
| 194 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 195 | 195 | return FALSE; |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -209,22 +209,22 @@ discard block |
||
| 209 | 209 | * @return mixed status int if the display string isn't requested |
| 210 | 210 | * @throws \EE_Error |
| 211 | 211 | */ |
| 212 | - public function ticket_status( $display = FALSE, $remaining = null ) { |
|
| 213 | - $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
|
| 214 | - if ( ! $remaining ) { |
|
| 215 | - return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out; |
|
| 212 | + public function ticket_status($display = FALSE, $remaining = null) { |
|
| 213 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 214 | + if ( ! $remaining) { |
|
| 215 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out; |
|
| 216 | 216 | } |
| 217 | - if ( $this->get( 'TKT_deleted' ) ) { |
|
| 218 | - return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived; |
|
| 217 | + if ($this->get('TKT_deleted')) { |
|
| 218 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived; |
|
| 219 | 219 | } |
| 220 | - if ( $this->is_expired() ) { |
|
| 221 | - return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired; |
|
| 220 | + if ($this->is_expired()) { |
|
| 221 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired; |
|
| 222 | 222 | } |
| 223 | - if ( $this->is_pending() ) { |
|
| 224 | - return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending; |
|
| 223 | + if ($this->is_pending()) { |
|
| 224 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending; |
|
| 225 | 225 | } |
| 226 | - if ( $this->is_on_sale() ) { |
|
| 227 | - return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale; |
|
| 226 | + if ($this->is_on_sale()) { |
|
| 227 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale; |
|
| 228 | 228 | } |
| 229 | 229 | return ''; |
| 230 | 230 | } |
@@ -239,12 +239,12 @@ discard block |
||
| 239 | 239 | * @return boolean true = tickets remaining, false not. |
| 240 | 240 | * @throws \EE_Error |
| 241 | 241 | */ |
| 242 | - public function is_remaining( $DTT_ID = 0 ) { |
|
| 243 | - $num_remaining = $this->remaining( $DTT_ID ); |
|
| 244 | - if ( $num_remaining === 0 ) { |
|
| 242 | + public function is_remaining($DTT_ID = 0) { |
|
| 243 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 244 | + if ($num_remaining === 0) { |
|
| 245 | 245 | return FALSE; |
| 246 | 246 | } |
| 247 | - if ( $num_remaining > 0 && $num_remaining < $this->min() ) { |
|
| 247 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 248 | 248 | return FALSE; |
| 249 | 249 | } |
| 250 | 250 | return TRUE; |
@@ -260,8 +260,8 @@ discard block |
||
| 260 | 260 | * @return int |
| 261 | 261 | * @throws \EE_Error |
| 262 | 262 | */ |
| 263 | - public function remaining( $DTT_ID = 0 ) { |
|
| 264 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
|
| 263 | + public function remaining($DTT_ID = 0) { |
|
| 264 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @throws \EE_Error |
| 274 | 274 | */ |
| 275 | 275 | public function min() { |
| 276 | - return $this->get( 'TKT_min' ); |
|
| 276 | + return $this->get('TKT_min'); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @throws \EE_Error |
| 286 | 286 | */ |
| 287 | 287 | public function is_expired() { |
| 288 | - return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
|
| 288 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @throws \EE_Error |
| 298 | 298 | */ |
| 299 | 299 | public function is_pending() { |
| 300 | - return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
|
| 300 | + return ($this->get_raw('TKT_start_date') > time()); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @throws \EE_Error |
| 310 | 310 | */ |
| 311 | 311 | public function is_on_sale() { |
| 312 | - return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
|
| 312 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | |
@@ -322,11 +322,11 @@ discard block |
||
| 322 | 322 | * @return string |
| 323 | 323 | * @throws \EE_Error |
| 324 | 324 | */ |
| 325 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
| 326 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
|
| 327 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
|
| 325 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
| 326 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : ''; |
|
| 327 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
| 328 | 328 | |
| 329 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 329 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -338,8 +338,8 @@ discard block |
||
| 338 | 338 | * @throws \EE_Error |
| 339 | 339 | */ |
| 340 | 340 | public function first_datetime() { |
| 341 | - $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
|
| 342 | - return reset( $datetimes ); |
|
| 341 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
| 342 | + return reset($datetimes); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | * @return EE_Datetime[]|EE_Base_Class[] |
| 353 | 353 | * @throws \EE_Error |
| 354 | 354 | */ |
| 355 | - public function datetimes( $query_params = array() ) { |
|
| 356 | - if ( ! isset( $query_params[ 'order_by' ] ) ) { |
|
| 357 | - $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
|
| 355 | + public function datetimes($query_params = array()) { |
|
| 356 | + if ( ! isset($query_params['order_by'])) { |
|
| 357 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 358 | 358 | } |
| 359 | - return $this->get_many_related( 'Datetime', $query_params ); |
|
| 359 | + return $this->get_many_related('Datetime', $query_params); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | |
@@ -368,8 +368,8 @@ discard block |
||
| 368 | 368 | * @throws \EE_Error |
| 369 | 369 | */ |
| 370 | 370 | public function last_datetime() { |
| 371 | - $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
|
| 372 | - return end( $datetimes ); |
|
| 371 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
| 372 | + return end($datetimes); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | |
@@ -387,22 +387,22 @@ discard block |
||
| 387 | 387 | * @return mixed (array|int) how many tickets have sold |
| 388 | 388 | * @throws \EE_Error |
| 389 | 389 | */ |
| 390 | - public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
|
| 390 | + public function tickets_sold($what = 'ticket', $dtt_id = NULL) { |
|
| 391 | 391 | $total = 0; |
| 392 | 392 | $tickets_sold = $this->_all_tickets_sold(); |
| 393 | - switch ( $what ) { |
|
| 393 | + switch ($what) { |
|
| 394 | 394 | case 'ticket' : |
| 395 | - return $tickets_sold[ 'ticket' ]; |
|
| 395 | + return $tickets_sold['ticket']; |
|
| 396 | 396 | break; |
| 397 | 397 | case 'datetime' : |
| 398 | - if ( empty( $tickets_sold[ 'datetime' ] ) ) { |
|
| 398 | + if (empty($tickets_sold['datetime'])) { |
|
| 399 | 399 | return $total; |
| 400 | 400 | } |
| 401 | - if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) { |
|
| 402 | - 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__ ); |
|
| 401 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 402 | + 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__); |
|
| 403 | 403 | return $total; |
| 404 | 404 | } |
| 405 | - return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ]; |
|
| 405 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 406 | 406 | break; |
| 407 | 407 | default: |
| 408 | 408 | return $total; |
@@ -418,15 +418,15 @@ discard block |
||
| 418 | 418 | * @throws \EE_Error |
| 419 | 419 | */ |
| 420 | 420 | protected function _all_tickets_sold() { |
| 421 | - $datetimes = $this->get_many_related( 'Datetime' ); |
|
| 421 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 422 | 422 | $tickets_sold = array(); |
| 423 | - if ( ! empty( $datetimes ) ) { |
|
| 424 | - foreach ( $datetimes as $datetime ) { |
|
| 425 | - $tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' ); |
|
| 423 | + if ( ! empty($datetimes)) { |
|
| 424 | + foreach ($datetimes as $datetime) { |
|
| 425 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | //Tickets sold |
| 429 | - $tickets_sold[ 'ticket' ] = $this->sold(); |
|
| 429 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 430 | 430 | return $tickets_sold; |
| 431 | 431 | } |
| 432 | 432 | |
@@ -439,11 +439,11 @@ discard block |
||
| 439 | 439 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
| 440 | 440 | * @throws \EE_Error |
| 441 | 441 | */ |
| 442 | - public function base_price( $return_array = FALSE ) { |
|
| 443 | - $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
|
| 442 | + public function base_price($return_array = FALSE) { |
|
| 443 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
| 444 | 444 | return $return_array |
| 445 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 446 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 445 | + ? $this->get_many_related('Price', array($_where)) |
|
| 446 | + : $this->get_first_related('Price', array($_where)); |
|
| 447 | 447 | } |
| 448 | 448 | |
| 449 | 449 | |
@@ -456,8 +456,8 @@ discard block |
||
| 456 | 456 | * @throws \EE_Error |
| 457 | 457 | */ |
| 458 | 458 | public function price_modifiers() { |
| 459 | - $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 ) ) ) ); |
|
| 460 | - return $this->prices( $query_params ); |
|
| 459 | + $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)))); |
|
| 460 | + return $this->prices($query_params); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | |
@@ -469,8 +469,8 @@ discard block |
||
| 469 | 469 | * @return EE_Price[]|EE_Base_Class[] |
| 470 | 470 | * @throws \EE_Error |
| 471 | 471 | */ |
| 472 | - public function prices( $query_params = array() ) { |
|
| 473 | - return $this->get_many_related( 'Price', $query_params ); |
|
| 472 | + public function prices($query_params = array()) { |
|
| 473 | + return $this->get_many_related('Price', $query_params); |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
| 483 | 483 | * @throws \EE_Error |
| 484 | 484 | */ |
| 485 | - public function datetime_tickets( $query_params = array() ) { |
|
| 486 | - return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
|
| 485 | + public function datetime_tickets($query_params = array()) { |
|
| 486 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -496,8 +496,8 @@ discard block |
||
| 496 | 496 | * @return EE_Datetime[] |
| 497 | 497 | * @throws \EE_Error |
| 498 | 498 | */ |
| 499 | - public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
|
| 500 | - return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
|
| 499 | + public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) { |
|
| 500 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | * @throws \EE_Error |
| 510 | 510 | */ |
| 511 | 511 | public function ID() { |
| 512 | - return $this->get( 'TKT_ID' ); |
|
| 512 | + return $this->get('TKT_ID'); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
@@ -534,7 +534,7 @@ discard block |
||
| 534 | 534 | * @throws \EE_Error |
| 535 | 535 | */ |
| 536 | 536 | public function template() { |
| 537 | - return $this->get_first_related( 'Ticket_Template' ); |
|
| 537 | + return $this->get_first_related('Ticket_Template'); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | |
@@ -556,7 +556,7 @@ discard block |
||
| 556 | 556 | * @throws \EE_Error |
| 557 | 557 | */ |
| 558 | 558 | public function ticket_price() { |
| 559 | - return $this->get( 'TKT_price' ); |
|
| 559 | + return $this->get('TKT_price'); |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | * @throws \EE_Error |
| 567 | 567 | */ |
| 568 | 568 | public function pretty_price() { |
| 569 | - return $this->get_pretty( 'TKT_price' ); |
|
| 569 | + return $this->get_pretty('TKT_price'); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -588,8 +588,8 @@ discard block |
||
| 588 | 588 | * @return float |
| 589 | 589 | * @throws \EE_Error |
| 590 | 590 | */ |
| 591 | - public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
|
| 592 | - if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
|
| 591 | + public function get_ticket_total_with_taxes($no_cache = FALSE) { |
|
| 592 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 593 | 593 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
| 594 | 594 | } |
| 595 | 595 | return (float) $this->_ticket_total_with_taxes; |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | |
| 599 | 599 | |
| 600 | 600 | public function ensure_TKT_Price_correct() { |
| 601 | - $this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) ); |
|
| 601 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 602 | 602 | $this->save(); |
| 603 | 603 | } |
| 604 | 604 | |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | * @throws \EE_Error |
| 610 | 610 | */ |
| 611 | 611 | public function get_ticket_subtotal() { |
| 612 | - return EE_Taxes::get_subtotal_for_admin( $this ); |
|
| 612 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | * @throws \EE_Error |
| 622 | 622 | */ |
| 623 | 623 | public function get_ticket_taxes_total_for_admin() { |
| 624 | - return EE_Taxes::get_total_taxes_for_admin( $this ); |
|
| 624 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | |
@@ -632,8 +632,8 @@ discard block |
||
| 632 | 632 | * @param string $name |
| 633 | 633 | * @throws \EE_Error |
| 634 | 634 | */ |
| 635 | - public function set_name( $name ) { |
|
| 636 | - $this->set( 'TKT_name', $name ); |
|
| 635 | + public function set_name($name) { |
|
| 636 | + $this->set('TKT_name', $name); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | * @throws \EE_Error |
| 646 | 646 | */ |
| 647 | 647 | public function description() { |
| 648 | - return $this->get( 'TKT_description' ); |
|
| 648 | + return $this->get('TKT_description'); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | * @param string $description |
| 657 | 657 | * @throws \EE_Error |
| 658 | 658 | */ |
| 659 | - public function set_description( $description ) { |
|
| 660 | - $this->set( 'TKT_description', $description ); |
|
| 659 | + public function set_description($description) { |
|
| 660 | + $this->set('TKT_description', $description); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | |
@@ -670,8 +670,8 @@ discard block |
||
| 670 | 670 | * @return string |
| 671 | 671 | * @throws \EE_Error |
| 672 | 672 | */ |
| 673 | - public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 674 | - return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
|
| 673 | + public function start_date($dt_frmt = '', $tm_frmt = '') { |
|
| 674 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 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_start_date( $start_date ) { |
|
| 687 | - $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
|
| 686 | + public function set_start_date($start_date) { |
|
| 687 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | |
@@ -697,8 +697,8 @@ discard block |
||
| 697 | 697 | * @return string |
| 698 | 698 | * @throws \EE_Error |
| 699 | 699 | */ |
| 700 | - public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 701 | - return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
|
| 700 | + public function end_date($dt_frmt = '', $tm_frmt = '') { |
|
| 701 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | |
@@ -710,8 +710,8 @@ discard block |
||
| 710 | 710 | * @return void |
| 711 | 711 | * @throws \EE_Error |
| 712 | 712 | */ |
| 713 | - public function set_end_date( $end_date ) { |
|
| 714 | - $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
|
| 713 | + public function set_end_date($end_date) { |
|
| 714 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | |
@@ -723,8 +723,8 @@ discard block |
||
| 723 | 723 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
| 724 | 724 | * @throws \EE_Error |
| 725 | 725 | */ |
| 726 | - public function set_end_time( $time ) { |
|
| 727 | - $this->_set_time_for( $time, 'TKT_end_date' ); |
|
| 726 | + public function set_end_time($time) { |
|
| 727 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | |
@@ -736,8 +736,8 @@ discard block |
||
| 736 | 736 | * @return void |
| 737 | 737 | * @throws \EE_Error |
| 738 | 738 | */ |
| 739 | - public function set_min( $min ) { |
|
| 740 | - $this->set( 'TKT_min', $min ); |
|
| 739 | + public function set_min($min) { |
|
| 740 | + $this->set('TKT_min', $min); |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @throws \EE_Error |
| 750 | 750 | */ |
| 751 | 751 | public function max() { |
| 752 | - return $this->get( 'TKT_max' ); |
|
| 752 | + return $this->get('TKT_max'); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | |
@@ -761,8 +761,8 @@ discard block |
||
| 761 | 761 | * @return void |
| 762 | 762 | * @throws \EE_Error |
| 763 | 763 | */ |
| 764 | - public function set_max( $max ) { |
|
| 765 | - $this->set( 'TKT_max', $max ); |
|
| 764 | + public function set_max($max) { |
|
| 765 | + $this->set('TKT_max', $max); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | |
@@ -774,8 +774,8 @@ discard block |
||
| 774 | 774 | * @return void |
| 775 | 775 | * @throws \EE_Error |
| 776 | 776 | */ |
| 777 | - public function set_price( $price ) { |
|
| 778 | - $this->set( 'TKT_price', $price ); |
|
| 777 | + public function set_price($price) { |
|
| 778 | + $this->set('TKT_price', $price); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * @throws \EE_Error |
| 788 | 788 | */ |
| 789 | 789 | public function sold() { |
| 790 | - return $this->get_raw( 'TKT_sold' ); |
|
| 790 | + return $this->get_raw('TKT_sold'); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | |
@@ -799,10 +799,10 @@ discard block |
||
| 799 | 799 | * @return void |
| 800 | 800 | * @throws \EE_Error |
| 801 | 801 | */ |
| 802 | - public function set_sold( $sold ) { |
|
| 802 | + public function set_sold($sold) { |
|
| 803 | 803 | // sold can not go below zero |
| 804 | - $sold = max( 0, $sold ); |
|
| 805 | - $this->set( 'TKT_sold', $sold ); |
|
| 804 | + $sold = max(0, $sold); |
|
| 805 | + $this->set('TKT_sold', $sold); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | |
@@ -814,13 +814,13 @@ discard block |
||
| 814 | 814 | * @return void |
| 815 | 815 | * @throws \EE_Error |
| 816 | 816 | */ |
| 817 | - public function increase_sold( $qty = 1 ) { |
|
| 817 | + public function increase_sold($qty = 1) { |
|
| 818 | 818 | $sold = $this->sold() + $qty; |
| 819 | 819 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
| 820 | 820 | // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
| 821 | - $this->decrease_reserved( $qty, false ); |
|
| 822 | - $this->_increase_sold_for_datetimes( $qty ); |
|
| 823 | - $this->set_sold( $sold ); |
|
| 821 | + $this->decrease_reserved($qty, false); |
|
| 822 | + $this->_increase_sold_for_datetimes($qty); |
|
| 823 | + $this->set_sold($sold); |
|
| 824 | 824 | do_action( |
| 825 | 825 | 'AHEE__EE_Ticket__increase_sold', |
| 826 | 826 | $this, |
@@ -838,12 +838,12 @@ discard block |
||
| 838 | 838 | * @return void |
| 839 | 839 | * @throws \EE_Error |
| 840 | 840 | */ |
| 841 | - protected function _increase_sold_for_datetimes( $qty = 1 ) { |
|
| 841 | + protected function _increase_sold_for_datetimes($qty = 1) { |
|
| 842 | 842 | $datetimes = $this->datetimes(); |
| 843 | - if ( is_array( $datetimes ) ) { |
|
| 844 | - foreach ( $datetimes as $datetime ) { |
|
| 845 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 846 | - $datetime->increase_sold( $qty ); |
|
| 843 | + if (is_array($datetimes)) { |
|
| 844 | + foreach ($datetimes as $datetime) { |
|
| 845 | + if ($datetime instanceof EE_Datetime) { |
|
| 846 | + $datetime->increase_sold($qty); |
|
| 847 | 847 | $datetime->save(); |
| 848 | 848 | } |
| 849 | 849 | } |
@@ -859,10 +859,10 @@ discard block |
||
| 859 | 859 | * @return void |
| 860 | 860 | * @throws \EE_Error |
| 861 | 861 | */ |
| 862 | - public function decrease_sold( $qty = 1 ) { |
|
| 862 | + public function decrease_sold($qty = 1) { |
|
| 863 | 863 | $sold = $this->sold() - $qty; |
| 864 | - $this->_decrease_sold_for_datetimes( $qty ); |
|
| 865 | - $this->set_sold( $sold ); |
|
| 864 | + $this->_decrease_sold_for_datetimes($qty); |
|
| 865 | + $this->set_sold($sold); |
|
| 866 | 866 | do_action( |
| 867 | 867 | 'AHEE__EE_Ticket__decrease_sold', |
| 868 | 868 | $this, |
@@ -880,12 +880,12 @@ discard block |
||
| 880 | 880 | * @return void |
| 881 | 881 | * @throws \EE_Error |
| 882 | 882 | */ |
| 883 | - protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
|
| 883 | + protected function _decrease_sold_for_datetimes($qty = 1) { |
|
| 884 | 884 | $datetimes = $this->datetimes(); |
| 885 | - if ( is_array( $datetimes ) ) { |
|
| 886 | - foreach ( $datetimes as $datetime ) { |
|
| 887 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 888 | - $datetime->decrease_sold( $qty ); |
|
| 885 | + if (is_array($datetimes)) { |
|
| 886 | + foreach ($datetimes as $datetime) { |
|
| 887 | + if ($datetime instanceof EE_Datetime) { |
|
| 888 | + $datetime->decrease_sold($qty); |
|
| 889 | 889 | $datetime->save(); |
| 890 | 890 | } |
| 891 | 891 | } |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | * @throws \EE_Error |
| 902 | 902 | */ |
| 903 | 903 | public function reserved() { |
| 904 | - return $this->get_raw( 'TKT_reserved' ); |
|
| 904 | + return $this->get_raw('TKT_reserved'); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | |
@@ -913,10 +913,10 @@ discard block |
||
| 913 | 913 | * @return void |
| 914 | 914 | * @throws \EE_Error |
| 915 | 915 | */ |
| 916 | - public function set_reserved( $reserved ) { |
|
| 916 | + public function set_reserved($reserved) { |
|
| 917 | 917 | // reserved can not go below zero |
| 918 | - $reserved = max( 0, (int) $reserved ); |
|
| 919 | - $this->set( 'TKT_reserved', $reserved ); |
|
| 918 | + $reserved = max(0, (int) $reserved); |
|
| 919 | + $this->set('TKT_reserved', $reserved); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | |
@@ -928,11 +928,11 @@ discard block |
||
| 928 | 928 | * @return void |
| 929 | 929 | * @throws \EE_Error |
| 930 | 930 | */ |
| 931 | - public function increase_reserved( $qty = 1 ) { |
|
| 932 | - $qty = absint( $qty ); |
|
| 931 | + public function increase_reserved($qty = 1) { |
|
| 932 | + $qty = absint($qty); |
|
| 933 | 933 | $reserved = $this->reserved() + $qty; |
| 934 | - $this->_increase_reserved_for_datetimes( $qty ); |
|
| 935 | - $this->set_reserved( $reserved ); |
|
| 934 | + $this->_increase_reserved_for_datetimes($qty); |
|
| 935 | + $this->set_reserved($reserved); |
|
| 936 | 936 | do_action( |
| 937 | 937 | 'AHEE__EE_Ticket__increase_reserved', |
| 938 | 938 | $this, |
@@ -950,12 +950,12 @@ discard block |
||
| 950 | 950 | * @return void |
| 951 | 951 | * @throws \EE_Error |
| 952 | 952 | */ |
| 953 | - protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
|
| 953 | + protected function _increase_reserved_for_datetimes($qty = 1) { |
|
| 954 | 954 | $datetimes = $this->datetimes(); |
| 955 | - if ( is_array( $datetimes ) ) { |
|
| 956 | - foreach ( $datetimes as $datetime ) { |
|
| 957 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 958 | - $datetime->increase_reserved( $qty ); |
|
| 955 | + if (is_array($datetimes)) { |
|
| 956 | + foreach ($datetimes as $datetime) { |
|
| 957 | + if ($datetime instanceof EE_Datetime) { |
|
| 958 | + $datetime->increase_reserved($qty); |
|
| 959 | 959 | $datetime->save(); |
| 960 | 960 | } |
| 961 | 961 | } |
@@ -972,12 +972,12 @@ discard block |
||
| 972 | 972 | * @return void |
| 973 | 973 | * @throws \EE_Error |
| 974 | 974 | */ |
| 975 | - public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) { |
|
| 976 | - $reserved = $this->reserved() - absint( $qty ); |
|
| 977 | - if ( $adjust_datetimes ) { |
|
| 978 | - $this->_decrease_reserved_for_datetimes( $qty ); |
|
| 975 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true) { |
|
| 976 | + $reserved = $this->reserved() - absint($qty); |
|
| 977 | + if ($adjust_datetimes) { |
|
| 978 | + $this->_decrease_reserved_for_datetimes($qty); |
|
| 979 | 979 | } |
| 980 | - $this->set_reserved( $reserved ); |
|
| 980 | + $this->set_reserved($reserved); |
|
| 981 | 981 | do_action( |
| 982 | 982 | 'AHEE__EE_Ticket__decrease_reserved', |
| 983 | 983 | $this, |
@@ -995,12 +995,12 @@ discard block |
||
| 995 | 995 | * @return void |
| 996 | 996 | * @throws \EE_Error |
| 997 | 997 | */ |
| 998 | - protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
|
| 998 | + protected function _decrease_reserved_for_datetimes($qty = 1) { |
|
| 999 | 999 | $datetimes = $this->datetimes(); |
| 1000 | - if ( is_array( $datetimes ) ) { |
|
| 1001 | - foreach ( $datetimes as $datetime ) { |
|
| 1002 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1003 | - $datetime->decrease_reserved( $qty ); |
|
| 1000 | + if (is_array($datetimes)) { |
|
| 1001 | + foreach ($datetimes as $datetime) { |
|
| 1002 | + if ($datetime instanceof EE_Datetime) { |
|
| 1003 | + $datetime->decrease_reserved($qty); |
|
| 1004 | 1004 | $datetime->save(); |
| 1005 | 1005 | } |
| 1006 | 1006 | } |
@@ -1021,14 +1021,14 @@ discard block |
||
| 1021 | 1021 | * @return int |
| 1022 | 1022 | * @throws \EE_Error |
| 1023 | 1023 | */ |
| 1024 | - public function qty( $context = '' ) { |
|
| 1025 | - switch ( $context ) { |
|
| 1024 | + public function qty($context = '') { |
|
| 1025 | + switch ($context) { |
|
| 1026 | 1026 | case 'reg_limit' : |
| 1027 | 1027 | return $this->real_quantity_on_ticket(); |
| 1028 | 1028 | case 'saleable' : |
| 1029 | - return $this->real_quantity_on_ticket( 'saleable' ); |
|
| 1029 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 1030 | 1030 | default: |
| 1031 | - return $this->get_raw( 'TKT_qty' ); |
|
| 1031 | + return $this->get_raw('TKT_qty'); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | |
@@ -1047,15 +1047,15 @@ discard block |
||
| 1047 | 1047 | * @return int |
| 1048 | 1048 | * @throws \EE_Error |
| 1049 | 1049 | */ |
| 1050 | - public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
|
| 1051 | - $raw = $this->get_raw( 'TKT_qty' ); |
|
| 1050 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) { |
|
| 1051 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1052 | 1052 | // return immediately if it's zero |
| 1053 | - if ( $raw === 0 ) { |
|
| 1053 | + if ($raw === 0) { |
|
| 1054 | 1054 | return $raw; |
| 1055 | 1055 | } |
| 1056 | 1056 | //echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
| 1057 | 1057 | // ensure qty doesn't exceed raw value for THIS ticket |
| 1058 | - $qty = min( EE_INF, $raw ); |
|
| 1058 | + $qty = min(EE_INF, $raw); |
|
| 1059 | 1059 | //echo "\n . qty: " . $qty . '<br />'; |
| 1060 | 1060 | // calculate this ticket's total sales and reservations |
| 1061 | 1061 | $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
@@ -1064,23 +1064,23 @@ discard block |
||
| 1064 | 1064 | //echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
| 1065 | 1065 | // first we need to calculate the maximum number of tickets available for the datetime |
| 1066 | 1066 | // do we want data for one datetime or all of them ? |
| 1067 | - $query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array(); |
|
| 1068 | - $datetimes = $this->datetimes( $query_params ); |
|
| 1069 | - if ( is_array( $datetimes ) && ! empty( $datetimes ) ) { |
|
| 1070 | - foreach ( $datetimes as $datetime ) { |
|
| 1071 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1067 | + $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
| 1068 | + $datetimes = $this->datetimes($query_params); |
|
| 1069 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1070 | + foreach ($datetimes as $datetime) { |
|
| 1071 | + if ($datetime instanceof EE_Datetime) { |
|
| 1072 | 1072 | $datetime->refresh_from_db(); |
| 1073 | 1073 | //echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
| 1074 | 1074 | //echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
| 1075 | 1075 | // initialize with no restrictions for each datetime |
| 1076 | 1076 | // but adjust datetime qty based on datetime reg limit |
| 1077 | - $datetime_qty = min( EE_INF, $datetime->reg_limit() ); |
|
| 1077 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1078 | 1078 | //echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
| 1079 | 1079 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 1080 | 1080 | // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
| 1081 | 1081 | // and reservations for this datetime, that do NOT include sales and reservations |
| 1082 | 1082 | // for this ticket (so we add $this->sold() and $this->reserved() back in) |
| 1083 | - if ( $context === 'saleable' ) { |
|
| 1083 | + if ($context === 'saleable') { |
|
| 1084 | 1084 | $datetime_qty = max( |
| 1085 | 1085 | $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
| 1086 | 1086 | 0 |
@@ -1092,16 +1092,16 @@ discard block |
||
| 1092 | 1092 | $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
| 1093 | 1093 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 1094 | 1094 | } |
| 1095 | - $qty = min( $datetime_qty, $qty ); |
|
| 1095 | + $qty = min($datetime_qty, $qty); |
|
| 1096 | 1096 | //echo "\n . . qty: " . $qty . '<br />'; |
| 1097 | 1097 | } |
| 1098 | 1098 | } |
| 1099 | 1099 | } |
| 1100 | 1100 | // NOW that we know the maximum number of tickets available for the datetime |
| 1101 | 1101 | // we can finally factor in the details for this specific ticket |
| 1102 | - if ( $qty > 0 && $context === 'saleable' ) { |
|
| 1102 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1103 | 1103 | // and subtract the sales for THIS ticket |
| 1104 | - $qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 ); |
|
| 1104 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1105 | 1105 | //echo "\n . qty: " . $qty . '<br />'; |
| 1106 | 1106 | } |
| 1107 | 1107 | //echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
@@ -1117,14 +1117,14 @@ discard block |
||
| 1117 | 1117 | * @return void |
| 1118 | 1118 | * @throws \EE_Error |
| 1119 | 1119 | */ |
| 1120 | - public function set_qty( $qty ) { |
|
| 1120 | + public function set_qty($qty) { |
|
| 1121 | 1121 | $datetimes = $this->datetimes(); |
| 1122 | - foreach ( $datetimes as $datetime ) { |
|
| 1123 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1124 | - $qty = min( $qty, $datetime->reg_limit() ); |
|
| 1122 | + foreach ($datetimes as $datetime) { |
|
| 1123 | + if ($datetime instanceof EE_Datetime) { |
|
| 1124 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1125 | 1125 | } |
| 1126 | 1126 | } |
| 1127 | - $this->set( 'TKT_qty', $qty ); |
|
| 1127 | + $this->set('TKT_qty', $qty); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | * @throws \EE_Error |
| 1137 | 1137 | */ |
| 1138 | 1138 | public function uses() { |
| 1139 | - return $this->get( 'TKT_uses' ); |
|
| 1139 | + return $this->get('TKT_uses'); |
|
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | 1142 | |
@@ -1148,8 +1148,8 @@ discard block |
||
| 1148 | 1148 | * @return void |
| 1149 | 1149 | * @throws \EE_Error |
| 1150 | 1150 | */ |
| 1151 | - public function set_uses( $uses ) { |
|
| 1152 | - $this->set( 'TKT_uses', $uses ); |
|
| 1151 | + public function set_uses($uses) { |
|
| 1152 | + $this->set('TKT_uses', $uses); |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | * @throws \EE_Error |
| 1162 | 1162 | */ |
| 1163 | 1163 | public function required() { |
| 1164 | - return $this->get( 'TKT_required' ); |
|
| 1164 | + return $this->get('TKT_required'); |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | |
@@ -1173,8 +1173,8 @@ discard block |
||
| 1173 | 1173 | * @return void |
| 1174 | 1174 | * @throws \EE_Error |
| 1175 | 1175 | */ |
| 1176 | - public function set_required( $required ) { |
|
| 1177 | - $this->set( 'TKT_required', $required ); |
|
| 1176 | + public function set_required($required) { |
|
| 1177 | + $this->set('TKT_required', $required); |
|
| 1178 | 1178 | } |
| 1179 | 1179 | |
| 1180 | 1180 | |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | * @throws \EE_Error |
| 1187 | 1187 | */ |
| 1188 | 1188 | public function taxable() { |
| 1189 | - return $this->get( 'TKT_taxable' ); |
|
| 1189 | + return $this->get('TKT_taxable'); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | |
@@ -1198,8 +1198,8 @@ discard block |
||
| 1198 | 1198 | * @return void |
| 1199 | 1199 | * @throws \EE_Error |
| 1200 | 1200 | */ |
| 1201 | - public function set_taxable( $taxable ) { |
|
| 1202 | - $this->set( 'TKT_taxable', $taxable ); |
|
| 1201 | + public function set_taxable($taxable) { |
|
| 1202 | + $this->set('TKT_taxable', $taxable); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | |
@@ -1211,7 +1211,7 @@ discard block |
||
| 1211 | 1211 | * @throws \EE_Error |
| 1212 | 1212 | */ |
| 1213 | 1213 | public function is_default() { |
| 1214 | - return $this->get( 'TKT_is_default' ); |
|
| 1214 | + return $this->get('TKT_is_default'); |
|
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | |
@@ -1223,8 +1223,8 @@ discard block |
||
| 1223 | 1223 | * @return void |
| 1224 | 1224 | * @throws \EE_Error |
| 1225 | 1225 | */ |
| 1226 | - public function set_is_default( $is_default ) { |
|
| 1227 | - $this->set( 'TKT_is_default', $is_default ); |
|
| 1226 | + public function set_is_default($is_default) { |
|
| 1227 | + $this->set('TKT_is_default', $is_default); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | |
@@ -1236,7 +1236,7 @@ discard block |
||
| 1236 | 1236 | * @throws \EE_Error |
| 1237 | 1237 | */ |
| 1238 | 1238 | public function order() { |
| 1239 | - return $this->get( 'TKT_order' ); |
|
| 1239 | + return $this->get('TKT_order'); |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | |
@@ -1248,8 +1248,8 @@ discard block |
||
| 1248 | 1248 | * @return void |
| 1249 | 1249 | * @throws \EE_Error |
| 1250 | 1250 | */ |
| 1251 | - public function set_order( $order ) { |
|
| 1252 | - $this->set( 'TKT_order', $order ); |
|
| 1251 | + public function set_order($order) { |
|
| 1252 | + $this->set('TKT_order', $order); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | * @throws \EE_Error |
| 1262 | 1262 | */ |
| 1263 | 1263 | public function row() { |
| 1264 | - return $this->get( 'TKT_row' ); |
|
| 1264 | + return $this->get('TKT_row'); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | |
@@ -1273,8 +1273,8 @@ discard block |
||
| 1273 | 1273 | * @return void |
| 1274 | 1274 | * @throws \EE_Error |
| 1275 | 1275 | */ |
| 1276 | - public function set_row( $row ) { |
|
| 1277 | - $this->set( 'TKT_row', $row ); |
|
| 1276 | + public function set_row($row) { |
|
| 1277 | + $this->set('TKT_row', $row); |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | * @throws \EE_Error |
| 1287 | 1287 | */ |
| 1288 | 1288 | public function deleted() { |
| 1289 | - return $this->get( 'TKT_deleted' ); |
|
| 1289 | + return $this->get('TKT_deleted'); |
|
| 1290 | 1290 | } |
| 1291 | 1291 | |
| 1292 | 1292 | |
@@ -1298,8 +1298,8 @@ discard block |
||
| 1298 | 1298 | * @return void |
| 1299 | 1299 | * @throws \EE_Error |
| 1300 | 1300 | */ |
| 1301 | - public function set_deleted( $deleted ) { |
|
| 1302 | - $this->set( 'TKT_deleted', $deleted ); |
|
| 1301 | + public function set_deleted($deleted) { |
|
| 1302 | + $this->set('TKT_deleted', $deleted); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | |
@@ -1311,7 +1311,7 @@ discard block |
||
| 1311 | 1311 | * @throws \EE_Error |
| 1312 | 1312 | */ |
| 1313 | 1313 | public function parent_ID() { |
| 1314 | - return $this->get( 'TKT_parent' ); |
|
| 1314 | + return $this->get('TKT_parent'); |
|
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | |
@@ -1323,8 +1323,8 @@ discard block |
||
| 1323 | 1323 | * @return void |
| 1324 | 1324 | * @throws \EE_Error |
| 1325 | 1325 | */ |
| 1326 | - public function set_parent_ID( $parent ) { |
|
| 1327 | - $this->set( 'TKT_parent', $parent ); |
|
| 1326 | + public function set_parent_ID($parent) { |
|
| 1327 | + $this->set('TKT_parent', $parent); |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | |
@@ -1337,10 +1337,10 @@ discard block |
||
| 1337 | 1337 | */ |
| 1338 | 1338 | public function name_and_info() { |
| 1339 | 1339 | $times = array(); |
| 1340 | - foreach ( $this->datetimes() as $datetime ) { |
|
| 1340 | + foreach ($this->datetimes() as $datetime) { |
|
| 1341 | 1341 | $times[] = $datetime->start_date_and_time(); |
| 1342 | 1342 | } |
| 1343 | - return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price(); |
|
| 1343 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | * @throws \EE_Error |
| 1353 | 1353 | */ |
| 1354 | 1354 | public function name() { |
| 1355 | - return $this->get( 'TKT_name' ); |
|
| 1355 | + return $this->get('TKT_name'); |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
@@ -1364,7 +1364,7 @@ discard block |
||
| 1364 | 1364 | * @throws \EE_Error |
| 1365 | 1365 | */ |
| 1366 | 1366 | public function price() { |
| 1367 | - return $this->get( 'TKT_price' ); |
|
| 1367 | + return $this->get('TKT_price'); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1376,8 +1376,8 @@ discard block |
||
| 1376 | 1376 | * @return EE_Registration[]|EE_Base_Class[] |
| 1377 | 1377 | * @throws \EE_Error |
| 1378 | 1378 | */ |
| 1379 | - public function registrations( $query_params = array() ) { |
|
| 1380 | - return $this->get_many_related( 'Registration', $query_params ); |
|
| 1379 | + public function registrations($query_params = array()) { |
|
| 1380 | + return $this->get_many_related('Registration', $query_params); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | |
@@ -1416,7 +1416,7 @@ discard block |
||
| 1416 | 1416 | * @param array $query_params like EEM_Base::get_all's |
| 1417 | 1417 | * @return int |
| 1418 | 1418 | */ |
| 1419 | - public function count_registrations( $query_params = array() ) { |
|
| 1419 | + public function count_registrations($query_params = array()) { |
|
| 1420 | 1420 | return $this->count_related('Registration', $query_params); |
| 1421 | 1421 | } |
| 1422 | 1422 | |
@@ -1444,23 +1444,23 @@ discard block |
||
| 1444 | 1444 | public function get_related_event() { |
| 1445 | 1445 | //get one datetime to use for getting the event |
| 1446 | 1446 | $datetime = $this->first_datetime(); |
| 1447 | - if ( ! $datetime instanceof \EE_Datetime ) { |
|
| 1447 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 1448 | 1448 | throw new UnexpectedEntityException( |
| 1449 | 1449 | $datetime, |
| 1450 | 1450 | 'EE_Datetime', |
| 1451 | 1451 | sprintf( |
| 1452 | - __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1452 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1453 | 1453 | $this->name() |
| 1454 | 1454 | ) |
| 1455 | 1455 | ); |
| 1456 | 1456 | } |
| 1457 | 1457 | $event = $datetime->event(); |
| 1458 | - if ( ! $event instanceof \EE_Event ) { |
|
| 1458 | + if ( ! $event instanceof \EE_Event) { |
|
| 1459 | 1459 | throw new UnexpectedEntityException( |
| 1460 | 1460 | $event, |
| 1461 | 1461 | 'EE_Event', |
| 1462 | 1462 | sprintf( |
| 1463 | - __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1463 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1464 | 1464 | $this->name() |
| 1465 | 1465 | ) |
| 1466 | 1466 | ); |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | use EventEspresso\core\services\currency\MoneyFactory; |
| 11 | 11 | |
| 12 | 12 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 13 | - exit('No direct script access allowed'); |
|
| 13 | + exit('No direct script access allowed'); |
|
| 14 | 14 | } |
| 15 | 15 | do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
| 16 | 16 | |
@@ -26,2874 +26,2874 @@ discard block |
||
| 26 | 26 | abstract class EE_Base_Class |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * This is an array of the original properties and values provided during construction |
|
| 31 | - * of this model object. (keys are model field names, values are their values). |
|
| 32 | - * This list is important to remember so that when we are merging data from the db, we know |
|
| 33 | - * which values to override and which to not override. |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected $_props_n_values_provided_in_constructor; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Timezone |
|
| 41 | - * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 42 | - * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 43 | - * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 44 | - * access to it. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $_timezone; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * date format |
|
| 54 | - * pattern or format for displaying dates |
|
| 55 | - * |
|
| 56 | - * @var string $_dt_frmt |
|
| 57 | - */ |
|
| 58 | - protected $_dt_frmt; |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * time format |
|
| 64 | - * pattern or format for displaying time |
|
| 65 | - * |
|
| 66 | - * @var string $_tm_frmt |
|
| 67 | - */ |
|
| 68 | - protected $_tm_frmt; |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 74 | - * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 75 | - * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 76 | - * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 77 | - * |
|
| 78 | - * @var array |
|
| 79 | - */ |
|
| 80 | - protected $_cached_properties = array(); |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 84 | - * single |
|
| 85 | - * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 86 | - * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 87 | - * all others have an array) |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - protected $_model_relations = array(); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 95 | - * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 96 | - * |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - protected $_fields = array(); |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 103 | - * For example, we might create model objects intended to only be used for the duration |
|
| 104 | - * of this request and to be thrown away, and if they were accidentally saved |
|
| 105 | - * it would be a bug. |
|
| 106 | - */ |
|
| 107 | - protected $_allow_persist = true; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var boolean indicating whether or not this model object's properties have changed since construction |
|
| 111 | - */ |
|
| 112 | - protected $_has_changes = false; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @var EEM_Base |
|
| 116 | - */ |
|
| 117 | - protected $_model; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @var MoneyFactory |
|
| 121 | - */ |
|
| 122 | - protected $money_factory; |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 127 | - * play nice |
|
| 128 | - * |
|
| 129 | - * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 130 | - * layer of the model's _fields array, (eg, EVT_ID, |
|
| 131 | - * TXN_amount, QST_name, etc) and values are their values |
|
| 132 | - * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 133 | - * corresponding db model or not. |
|
| 134 | - * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 135 | - * be in when instantiating a EE_Base_Class object. |
|
| 136 | - * @param array $date_formats An array of date formats to set on construct where first |
|
| 137 | - * value is the date_format and second value is the time |
|
| 138 | - * format. |
|
| 139 | - * @throws InvalidArgumentException |
|
| 140 | - * @throws InvalidInterfaceException |
|
| 141 | - * @throws InvalidDataTypeException |
|
| 142 | - * @throws EE_Error |
|
| 143 | - */ |
|
| 144 | - protected function __construct( |
|
| 145 | - $fieldValues = array(), |
|
| 146 | - $bydb = false, |
|
| 147 | - $timezone = '', |
|
| 148 | - $date_formats = array() |
|
| 149 | - ) { |
|
| 150 | - $className = get_class($this); |
|
| 151 | - do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 152 | - $model = $this->get_model(); |
|
| 153 | - $model_fields = $model->field_settings(false); |
|
| 154 | - // ensure $fieldValues is an array |
|
| 155 | - $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 156 | - // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 157 | - // verify client code has not passed any invalid field names |
|
| 158 | - foreach ($fieldValues as $field_name => $field_value) { |
|
| 159 | - if ( ! isset($model_fields[$field_name])) { |
|
| 160 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 161 | - "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 165 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 166 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 167 | - list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 168 | - } else { |
|
| 169 | - //set default formats for date and time |
|
| 170 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 171 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 172 | - } |
|
| 173 | - //if db model is instantiating |
|
| 174 | - if ($bydb) { |
|
| 175 | - //client code has indicated these field values are from the database |
|
| 176 | - foreach ($model_fields as $fieldName => $field) { |
|
| 177 | - $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 178 | - } |
|
| 179 | - } else { |
|
| 180 | - //we're constructing a brand |
|
| 181 | - //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 182 | - foreach ($model_fields as $fieldName => $field) { |
|
| 183 | - $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - //remember what values were passed to this constructor |
|
| 187 | - $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 188 | - //remember in entity mapper |
|
| 189 | - if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 190 | - $model->add_to_entity_map($this); |
|
| 191 | - } |
|
| 192 | - //setup all the relations |
|
| 193 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 194 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 195 | - $this->_model_relations[$relation_name] = null; |
|
| 196 | - } else { |
|
| 197 | - $this->_model_relations[$relation_name] = array(); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - /** |
|
| 201 | - * Action done at the end of each model object construction |
|
| 202 | - * |
|
| 203 | - * @param EE_Base_Class $this the model object just created |
|
| 204 | - */ |
|
| 205 | - do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 212 | - * |
|
| 213 | - * @return boolean |
|
| 214 | - */ |
|
| 215 | - public function allow_persist() |
|
| 216 | - { |
|
| 217 | - return $this->_allow_persist; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 224 | - * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 225 | - * you got new information that somehow made you change your mind. |
|
| 226 | - * |
|
| 227 | - * @param boolean $allow_persist |
|
| 228 | - * @return boolean |
|
| 229 | - */ |
|
| 230 | - public function set_allow_persist($allow_persist) |
|
| 231 | - { |
|
| 232 | - return $this->_allow_persist = $allow_persist; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Gets the field's original value when this object was constructed during this request. |
|
| 239 | - * This can be helpful when determining if a model object has changed or not |
|
| 240 | - * |
|
| 241 | - * @param string $field_name |
|
| 242 | - * @return mixed|null |
|
| 243 | - * @throws EE_Error |
|
| 244 | - */ |
|
| 245 | - public function get_original($field_name) |
|
| 246 | - { |
|
| 247 | - if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 248 | - && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 249 | - ) { |
|
| 250 | - return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 251 | - } else { |
|
| 252 | - return null; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * @param EE_Base_Class $obj |
|
| 260 | - * @return string |
|
| 261 | - */ |
|
| 262 | - public function get_class($obj) |
|
| 263 | - { |
|
| 264 | - return get_class($obj); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Overrides parent because parent expects old models. |
|
| 270 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 271 | - * |
|
| 272 | - * @param string $field_name |
|
| 273 | - * @param mixed $field_value |
|
| 274 | - * @param bool $use_default |
|
| 275 | - * @throws InvalidArgumentException |
|
| 276 | - * @throws InvalidInterfaceException |
|
| 277 | - * @throws InvalidDataTypeException |
|
| 278 | - * @throws EE_Error |
|
| 279 | - */ |
|
| 280 | - public function set($field_name, $field_value, $use_default = false) |
|
| 281 | - { |
|
| 282 | - // if not using default and nothing has changed, and object has already been setup (has ID), |
|
| 283 | - // then don't do anything |
|
| 284 | - if ( |
|
| 285 | - ! $use_default |
|
| 286 | - && $this->_fields[$field_name] === $field_value |
|
| 287 | - && $this->ID() |
|
| 288 | - ) { |
|
| 289 | - return; |
|
| 290 | - } |
|
| 291 | - $model = $this->get_model(); |
|
| 292 | - $this->_has_changes = true; |
|
| 293 | - $field_obj = $model->field_settings_for($field_name); |
|
| 294 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 295 | - // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 296 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 297 | - $field_obj->set_timezone($this->_timezone); |
|
| 298 | - $field_obj->set_date_format($this->_dt_frmt); |
|
| 299 | - $field_obj->set_time_format($this->_tm_frmt); |
|
| 300 | - } |
|
| 301 | - $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 302 | - //should the value be null? |
|
| 303 | - if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 304 | - $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 305 | - /** |
|
| 306 | - * To save having to refactor all the models, if a default value is used for a |
|
| 307 | - * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 308 | - * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 309 | - * object. |
|
| 310 | - * |
|
| 311 | - * @since 4.6.10+ |
|
| 312 | - */ |
|
| 313 | - if ( |
|
| 314 | - $field_obj instanceof EE_Datetime_Field |
|
| 315 | - && $this->_fields[$field_name] !== null |
|
| 316 | - && ! $this->_fields[$field_name] instanceof DateTime |
|
| 317 | - ) { |
|
| 318 | - empty($this->_fields[$field_name]) |
|
| 319 | - ? $this->set($field_name, time()) |
|
| 320 | - : $this->set($field_name, $this->_fields[$field_name]); |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - $this->_fields[$field_name] = $holder_of_value; |
|
| 324 | - } |
|
| 325 | - //if we're not in the constructor... |
|
| 326 | - //now check if what we set was a primary key |
|
| 327 | - if ( |
|
| 328 | - //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 329 | - $this->_props_n_values_provided_in_constructor |
|
| 330 | - && $field_value |
|
| 331 | - && $field_name === $model->primary_key_name() |
|
| 332 | - ) { |
|
| 333 | - //if so, we want all this object's fields to be filled either with |
|
| 334 | - //what we've explicitly set on this model |
|
| 335 | - //or what we have in the db |
|
| 336 | - // echo "setting primary key!"; |
|
| 337 | - $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 338 | - $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 339 | - foreach ($fields_on_model as $field_obj) { |
|
| 340 | - if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 341 | - && $field_obj->get_name() !== $field_name |
|
| 342 | - ) { |
|
| 343 | - $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - //oh this model object has an ID? well make sure its in the entity mapper |
|
| 347 | - $model->add_to_entity_map($this); |
|
| 348 | - } |
|
| 349 | - //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 350 | - $this->_clear_cached_property($field_name); |
|
| 351 | - } else { |
|
| 352 | - throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 353 | - "event_espresso"), $field_name)); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * This sets the field value on the db column if it exists for the given $column_name or |
|
| 361 | - * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 362 | - * |
|
| 363 | - * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 364 | - * @param string $field_name Must be the exact column name. |
|
| 365 | - * @param mixed $field_value The value to set. |
|
| 366 | - * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 367 | - * @throws EE_Error |
|
| 368 | - */ |
|
| 369 | - public function set_field_or_extra_meta($field_name, $field_value) |
|
| 370 | - { |
|
| 371 | - if ($this->get_model()->has_field($field_name)) { |
|
| 372 | - $this->set($field_name, $field_value); |
|
| 373 | - return true; |
|
| 374 | - } else { |
|
| 375 | - //ensure this object is saved first so that extra meta can be properly related. |
|
| 376 | - $this->save(); |
|
| 377 | - return $this->update_extra_meta($field_name, $field_value); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * This retrieves the value of the db column set on this class or if that's not present |
|
| 385 | - * it will attempt to retrieve from extra_meta if found. |
|
| 386 | - * Example Usage: |
|
| 387 | - * Via EE_Message child class: |
|
| 388 | - * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 389 | - * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 390 | - * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 391 | - * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 392 | - * value for those extra fields dynamically via the EE_message object. |
|
| 393 | - * |
|
| 394 | - * @param string $field_name expecting the fully qualified field name. |
|
| 395 | - * @return mixed|null value for the field if found. null if not found. |
|
| 396 | - * @throws EE_Error |
|
| 397 | - */ |
|
| 398 | - public function get_field_or_extra_meta($field_name) |
|
| 399 | - { |
|
| 400 | - if ($this->get_model()->has_field($field_name)) { |
|
| 401 | - $column_value = $this->get($field_name); |
|
| 402 | - } else { |
|
| 403 | - //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 404 | - $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 405 | - } |
|
| 406 | - return $column_value; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 412 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 413 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 414 | - * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 415 | - * |
|
| 416 | - * @access public |
|
| 417 | - * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 418 | - * @return void |
|
| 419 | - * @throws InvalidArgumentException |
|
| 420 | - * @throws InvalidInterfaceException |
|
| 421 | - * @throws InvalidDataTypeException |
|
| 422 | - * @throws EE_Error |
|
| 423 | - */ |
|
| 424 | - public function set_timezone($timezone = '') |
|
| 425 | - { |
|
| 426 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 427 | - //make sure we clear all cached properties because they won't be relevant now |
|
| 428 | - $this->_clear_cached_properties(); |
|
| 429 | - //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 430 | - $model_fields = $this->get_model()->field_settings(false); |
|
| 431 | - foreach ($model_fields as $field_name => $field_obj) { |
|
| 432 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 433 | - $field_obj->set_timezone($this->_timezone); |
|
| 434 | - if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 435 | - $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * This just returns whatever is set for the current timezone. |
|
| 445 | - * |
|
| 446 | - * @access public |
|
| 447 | - * @return string timezone string |
|
| 448 | - */ |
|
| 449 | - public function get_timezone() |
|
| 450 | - { |
|
| 451 | - return $this->_timezone; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 458 | - * internally instead of wp set date format options |
|
| 459 | - * |
|
| 460 | - * @since 4.6 |
|
| 461 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 462 | - */ |
|
| 463 | - public function set_date_format($format) |
|
| 464 | - { |
|
| 465 | - $this->_dt_frmt = $format; |
|
| 466 | - //clear cached_properties because they won't be relevant now. |
|
| 467 | - $this->_clear_cached_properties(); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 474 | - * class internally instead of wp set time format options. |
|
| 475 | - * |
|
| 476 | - * @since 4.6 |
|
| 477 | - * @param string $format should be a format recognizable by PHP date() functions. |
|
| 478 | - */ |
|
| 479 | - public function set_time_format($format) |
|
| 480 | - { |
|
| 481 | - $this->_tm_frmt = $format; |
|
| 482 | - //clear cached_properties because they won't be relevant now. |
|
| 483 | - $this->_clear_cached_properties(); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * This returns the current internal set format for the date and time formats. |
|
| 490 | - * |
|
| 491 | - * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 492 | - * where the first value is the date format and the second value is the time format. |
|
| 493 | - * @return mixed string|array |
|
| 494 | - */ |
|
| 495 | - public function get_format($full = true) |
|
| 496 | - { |
|
| 497 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * cache |
|
| 504 | - * stores the passed model object on the current model object. |
|
| 505 | - * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 506 | - * |
|
| 507 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 508 | - * 'Registration' associated with this model object |
|
| 509 | - * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 510 | - * that could be a payment or a registration) |
|
| 511 | - * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 512 | - * items which will be stored in an array on this object |
|
| 513 | - * @throws EE_Error |
|
| 514 | - * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 515 | - * related thing, no array) |
|
| 516 | - */ |
|
| 517 | - public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 518 | - { |
|
| 519 | - // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 520 | - if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 521 | - return false; |
|
| 522 | - } |
|
| 523 | - // also get "how" the object is related, or throw an error |
|
| 524 | - if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 525 | - throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 526 | - $relationName, get_class($this))); |
|
| 527 | - } |
|
| 528 | - // how many things are related ? |
|
| 529 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 530 | - // 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 |
|
| 531 | - // so for these model objects just set it to be cached |
|
| 532 | - $this->_model_relations[$relationName] = $object_to_cache; |
|
| 533 | - $return = true; |
|
| 534 | - } else { |
|
| 535 | - // 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. |
|
| 536 | - // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 537 | - if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 538 | - // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 539 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 540 | - ? array($this->_model_relations[$relationName]) : array(); |
|
| 541 | - } |
|
| 542 | - // first check for a cache_id which is normally empty |
|
| 543 | - if ( ! empty($cache_id)) { |
|
| 544 | - // 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 |
|
| 545 | - $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 546 | - $return = $cache_id; |
|
| 547 | - } elseif ($object_to_cache->ID()) { |
|
| 548 | - // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 549 | - $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 550 | - $return = $object_to_cache->ID(); |
|
| 551 | - } else { |
|
| 552 | - // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 553 | - $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 554 | - // move the internal pointer to the end of the array |
|
| 555 | - end($this->_model_relations[$relationName]); |
|
| 556 | - // and grab the key so that we can return it |
|
| 557 | - $return = key($this->_model_relations[$relationName]); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - return $return; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * For adding an item to the cached_properties property. |
|
| 567 | - * |
|
| 568 | - * @access protected |
|
| 569 | - * @param string $fieldname the property item the corresponding value is for. |
|
| 570 | - * @param mixed $value The value we are caching. |
|
| 571 | - * @param string|null $cache_type |
|
| 572 | - * @return void |
|
| 573 | - * @throws EE_Error |
|
| 574 | - */ |
|
| 575 | - protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 576 | - { |
|
| 577 | - //first make sure this property exists |
|
| 578 | - $this->get_model()->field_settings_for($fieldname); |
|
| 579 | - $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 580 | - $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 587 | - * This also SETS the cache if we return the actual property! |
|
| 588 | - * |
|
| 589 | - * @param string $fieldname the name of the property we're trying to retrieve |
|
| 590 | - * @param bool $pretty |
|
| 591 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 592 | - * (in cases where the same property may be used for different outputs |
|
| 593 | - * - i.e. datetime, money etc.) |
|
| 594 | - * It can also accept certain pre-defined "schema" strings |
|
| 595 | - * to define how to output the property. |
|
| 596 | - * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 597 | - * @return mixed whatever the value for the property is we're retrieving |
|
| 598 | - * @throws EE_Error |
|
| 599 | - */ |
|
| 600 | - protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 601 | - { |
|
| 602 | - //verify the field exists |
|
| 603 | - $model = $this->get_model(); |
|
| 604 | - $model->field_settings_for($fieldname); |
|
| 605 | - $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 606 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 607 | - if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 608 | - return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 609 | - } |
|
| 610 | - $value = $this->_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 611 | - $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 612 | - return $value; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * If the cache didn't fetch the needed item, this fetches it. |
|
| 618 | - * @param string $fieldname |
|
| 619 | - * @param bool $pretty |
|
| 620 | - * @param string $extra_cache_ref |
|
| 621 | - * @return mixed |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 625 | - { |
|
| 626 | - $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 627 | - // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 628 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
| 629 | - $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 630 | - } |
|
| 631 | - if ( ! isset($this->_fields[$fieldname])) { |
|
| 632 | - $this->_fields[$fieldname] = null; |
|
| 633 | - } |
|
| 634 | - $value = $pretty |
|
| 635 | - ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 636 | - : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 637 | - return $value; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 643 | - * |
|
| 644 | - * @param \EE_Datetime_Field $datetime_field |
|
| 645 | - * @param bool $pretty |
|
| 646 | - * @param null $date_or_time |
|
| 647 | - * @return void |
|
| 648 | - * @throws InvalidArgumentException |
|
| 649 | - * @throws InvalidInterfaceException |
|
| 650 | - * @throws InvalidDataTypeException |
|
| 651 | - * @throws EE_Error |
|
| 652 | - */ |
|
| 653 | - protected function _prepare_datetime_field( |
|
| 654 | - EE_Datetime_Field $datetime_field, |
|
| 655 | - $pretty = false, |
|
| 656 | - $date_or_time = null |
|
| 657 | - ) { |
|
| 658 | - $datetime_field->set_timezone($this->_timezone); |
|
| 659 | - $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 660 | - $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 661 | - //set the output returned |
|
| 662 | - switch ($date_or_time) { |
|
| 663 | - case 'D' : |
|
| 664 | - $datetime_field->set_date_time_output('date'); |
|
| 665 | - break; |
|
| 666 | - case 'T' : |
|
| 667 | - $datetime_field->set_date_time_output('time'); |
|
| 668 | - break; |
|
| 669 | - default : |
|
| 670 | - $datetime_field->set_date_time_output(); |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * This just takes care of clearing out the cached_properties |
|
| 678 | - * |
|
| 679 | - * @return void |
|
| 680 | - */ |
|
| 681 | - protected function _clear_cached_properties() |
|
| 682 | - { |
|
| 683 | - $this->_cached_properties = array(); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * This just clears out ONE property if it exists in the cache |
|
| 690 | - * |
|
| 691 | - * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 692 | - * @return void |
|
| 693 | - */ |
|
| 694 | - protected function _clear_cached_property($property_name) |
|
| 695 | - { |
|
| 696 | - if (isset($this->_cached_properties[$property_name])) { |
|
| 697 | - unset($this->_cached_properties[$property_name]); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * Ensures that this related thing is a model object. |
|
| 705 | - * |
|
| 706 | - * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 707 | - * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 708 | - * @return EE_Base_Class |
|
| 709 | - * @throws EE_Error |
|
| 710 | - */ |
|
| 711 | - protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 712 | - { |
|
| 713 | - $other_model_instance = self::_get_model_instance_with_name( |
|
| 714 | - self::_get_model_classname($model_name), |
|
| 715 | - $this->_timezone |
|
| 716 | - ); |
|
| 717 | - return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 724 | - * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 725 | - * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 726 | - * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 727 | - * |
|
| 728 | - * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 729 | - * Eg 'Registration' |
|
| 730 | - * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 731 | - * if you intend to use $clear_all = TRUE, or the relation only |
|
| 732 | - * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 733 | - * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 734 | - * this is HasMany or HABTM. |
|
| 735 | - * @throws EE_Error |
|
| 736 | - * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 737 | - * relation from all |
|
| 738 | - */ |
|
| 739 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 740 | - { |
|
| 741 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 742 | - $index_in_cache = ''; |
|
| 743 | - if ( ! $relationship_to_model) { |
|
| 744 | - throw new EE_Error( |
|
| 745 | - sprintf( |
|
| 746 | - __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 747 | - $relationName, |
|
| 748 | - get_class($this) |
|
| 749 | - ) |
|
| 750 | - ); |
|
| 751 | - } |
|
| 752 | - if ($clear_all) { |
|
| 753 | - $obj_removed = true; |
|
| 754 | - $this->_model_relations[$relationName] = null; |
|
| 755 | - } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 756 | - $obj_removed = $this->_model_relations[$relationName]; |
|
| 757 | - $this->_model_relations[$relationName] = null; |
|
| 758 | - } else { |
|
| 759 | - if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 760 | - && $object_to_remove_or_index_into_array->ID() |
|
| 761 | - ) { |
|
| 762 | - $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 763 | - if (is_array($this->_model_relations[$relationName]) |
|
| 764 | - && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 765 | - ) { |
|
| 766 | - $index_found_at = null; |
|
| 767 | - //find this object in the array even though it has a different key |
|
| 768 | - foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 769 | - if ( |
|
| 770 | - $obj instanceof EE_Base_Class |
|
| 771 | - && ( |
|
| 772 | - $obj == $object_to_remove_or_index_into_array |
|
| 773 | - || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 774 | - ) |
|
| 775 | - ) { |
|
| 776 | - $index_found_at = $index; |
|
| 777 | - break; |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - if ($index_found_at) { |
|
| 781 | - $index_in_cache = $index_found_at; |
|
| 782 | - } else { |
|
| 783 | - //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 784 | - //if it wasn't in it to begin with. So we're done |
|
| 785 | - return $object_to_remove_or_index_into_array; |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 789 | - //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 790 | - foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 791 | - if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 792 | - $index_in_cache = $index; |
|
| 793 | - } |
|
| 794 | - } |
|
| 795 | - } else { |
|
| 796 | - $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 797 | - } |
|
| 798 | - //supposedly we've found it. But it could just be that the client code |
|
| 799 | - //provided a bad index/object |
|
| 800 | - if ( |
|
| 801 | - isset( |
|
| 802 | - $this->_model_relations[$relationName], |
|
| 803 | - $this->_model_relations[$relationName][$index_in_cache] |
|
| 804 | - ) |
|
| 805 | - ) { |
|
| 806 | - $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 807 | - unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 808 | - } else { |
|
| 809 | - //that thing was never cached anyways. |
|
| 810 | - $obj_removed = null; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - return $obj_removed; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - |
|
| 817 | - |
|
| 818 | - /** |
|
| 819 | - * update_cache_after_object_save |
|
| 820 | - * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 821 | - * obtained after being saved to the db |
|
| 822 | - * |
|
| 823 | - * @param string $relationName - the type of object that is cached |
|
| 824 | - * @param EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 825 | - * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 826 | - * @return boolean TRUE on success, FALSE on fail |
|
| 827 | - * @throws EE_Error |
|
| 828 | - */ |
|
| 829 | - public function update_cache_after_object_save( |
|
| 830 | - $relationName, |
|
| 831 | - EE_Base_Class $newly_saved_object, |
|
| 832 | - $current_cache_id = '' |
|
| 833 | - ) { |
|
| 834 | - // verify that incoming object is of the correct type |
|
| 835 | - $obj_class = 'EE_' . $relationName; |
|
| 836 | - if ($newly_saved_object instanceof $obj_class) { |
|
| 837 | - /* @type EE_Base_Class $newly_saved_object */ |
|
| 838 | - // now get the type of relation |
|
| 839 | - $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 840 | - // if this is a 1:1 relationship |
|
| 841 | - if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 842 | - // then just replace the cached object with the newly saved object |
|
| 843 | - $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 844 | - return true; |
|
| 845 | - // or if it's some kind of sordid feral polyamorous relationship... |
|
| 846 | - } elseif (is_array($this->_model_relations[$relationName]) |
|
| 847 | - && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 848 | - ) { |
|
| 849 | - // then remove the current cached item |
|
| 850 | - unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 851 | - // and cache the newly saved object using it's new ID |
|
| 852 | - $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 853 | - return true; |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - return false; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - |
|
| 861 | - /** |
|
| 862 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 863 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 864 | - * |
|
| 865 | - * @param string $relationName |
|
| 866 | - * @return EE_Base_Class |
|
| 867 | - */ |
|
| 868 | - public function get_one_from_cache($relationName) |
|
| 869 | - { |
|
| 870 | - $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 871 | - : null; |
|
| 872 | - if (is_array($cached_array_or_object)) { |
|
| 873 | - return array_shift($cached_array_or_object); |
|
| 874 | - } else { |
|
| 875 | - return $cached_array_or_object; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 882 | - * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 883 | - * |
|
| 884 | - * @param string $relationName |
|
| 885 | - * @throws \ReflectionException |
|
| 886 | - * @throws InvalidArgumentException |
|
| 887 | - * @throws InvalidInterfaceException |
|
| 888 | - * @throws InvalidDataTypeException |
|
| 889 | - * @throws EE_Error |
|
| 890 | - * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 891 | - */ |
|
| 892 | - public function get_all_from_cache($relationName) |
|
| 893 | - { |
|
| 894 | - $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 895 | - // if the result is not an array, but exists, make it an array |
|
| 896 | - $objects = is_array($objects) ? $objects : array($objects); |
|
| 897 | - //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 898 | - //basically, if this model object was stored in the session, and these cached model objects |
|
| 899 | - //already have IDs, let's make sure they're in their model's entity mapper |
|
| 900 | - //otherwise we will have duplicates next time we call |
|
| 901 | - // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 902 | - $model = EE_Registry::instance()->load_model($relationName); |
|
| 903 | - foreach ($objects as $model_object) { |
|
| 904 | - if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 905 | - //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 906 | - if ($model_object->ID()) { |
|
| 907 | - $model->add_to_entity_map($model_object); |
|
| 908 | - } |
|
| 909 | - } else { |
|
| 910 | - throw new EE_Error( |
|
| 911 | - sprintf( |
|
| 912 | - __( |
|
| 913 | - 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 914 | - 'event_espresso' |
|
| 915 | - ), |
|
| 916 | - $relationName, |
|
| 917 | - gettype($model_object) |
|
| 918 | - ) |
|
| 919 | - ); |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - return $objects; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 929 | - * matching the given query conditions. |
|
| 930 | - * |
|
| 931 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 932 | - * @param int $limit How many objects to return. |
|
| 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_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 940 | - { |
|
| 941 | - $model = $this->get_model(); |
|
| 942 | - $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 943 | - ? $model->get_primary_key_field()->get_name() |
|
| 944 | - : $field_to_order_by; |
|
| 945 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 946 | - if (empty($field) || empty($current_value)) { |
|
| 947 | - return array(); |
|
| 948 | - } |
|
| 949 | - return $model->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 956 | - * matching the given query conditions. |
|
| 957 | - * |
|
| 958 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 959 | - * @param int $limit How many objects to return. |
|
| 960 | - * @param array $query_params Any additional conditions on the query. |
|
| 961 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 962 | - * you can indicate just the columns you want returned |
|
| 963 | - * @return array|EE_Base_Class[] |
|
| 964 | - * @throws EE_Error |
|
| 965 | - */ |
|
| 966 | - public function previous_x( |
|
| 967 | - $field_to_order_by = null, |
|
| 968 | - $limit = 1, |
|
| 969 | - $query_params = array(), |
|
| 970 | - $columns_to_select = null |
|
| 971 | - ) { |
|
| 972 | - $model = $this->get_model(); |
|
| 973 | - $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 974 | - ? $model->get_primary_key_field()->get_name() |
|
| 975 | - : $field_to_order_by; |
|
| 976 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 977 | - if (empty($field) || empty($current_value)) { |
|
| 978 | - return array(); |
|
| 979 | - } |
|
| 980 | - return $model->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 987 | - * matching the given query conditions. |
|
| 988 | - * |
|
| 989 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 990 | - * @param array $query_params Any additional conditions on the query. |
|
| 991 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 992 | - * you can indicate just the columns you want returned |
|
| 993 | - * @return array|EE_Base_Class |
|
| 994 | - * @throws EE_Error |
|
| 995 | - */ |
|
| 996 | - public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 997 | - { |
|
| 998 | - $model = $this->get_model(); |
|
| 999 | - $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 1000 | - ? $model->get_primary_key_field()->get_name() |
|
| 1001 | - : $field_to_order_by; |
|
| 1002 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 1003 | - if (empty($field) || empty($current_value)) { |
|
| 1004 | - return array(); |
|
| 1005 | - } |
|
| 1006 | - return $model->next($current_value, $field, $query_params, $columns_to_select); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 1013 | - * matching the given query conditions. |
|
| 1014 | - * |
|
| 1015 | - * @param null $field_to_order_by What field is being used as the reference point. |
|
| 1016 | - * @param array $query_params Any additional conditions on the query. |
|
| 1017 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 1018 | - * you can indicate just the column you want returned |
|
| 1019 | - * @return array|EE_Base_Class |
|
| 1020 | - * @throws EE_Error |
|
| 1021 | - */ |
|
| 1022 | - public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 1023 | - { |
|
| 1024 | - $model = $this->get_model(); |
|
| 1025 | - $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 1026 | - ? $model->get_primary_key_field()->get_name() |
|
| 1027 | - : $field_to_order_by; |
|
| 1028 | - $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 1029 | - if (empty($field) || empty($current_value)) { |
|
| 1030 | - return array(); |
|
| 1031 | - } |
|
| 1032 | - return $model->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 1033 | - } |
|
| 1034 | - |
|
| 1035 | - |
|
| 1036 | - |
|
| 1037 | - /** |
|
| 1038 | - * Overrides parent because parent expects old models. |
|
| 1039 | - * This also doesn't do any validation, and won't work for serialized arrays |
|
| 1040 | - * |
|
| 1041 | - * @param string $field_name |
|
| 1042 | - * @param mixed $field_value_from_db |
|
| 1043 | - * @throws EE_Error |
|
| 1044 | - */ |
|
| 1045 | - public function set_from_db($field_name, $field_value_from_db) |
|
| 1046 | - { |
|
| 1047 | - $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 1048 | - if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 1049 | - //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 1050 | - //eg, a CPT model object could have an entry in the posts table, but no |
|
| 1051 | - //entry in the meta table. Meaning that all its columns in the meta table |
|
| 1052 | - //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 1053 | - if ($field_value_from_db === null) { |
|
| 1054 | - if ($field_obj->is_nullable()) { |
|
| 1055 | - //if the field allows nulls, then let it be null |
|
| 1056 | - $field_value = null; |
|
| 1057 | - } else { |
|
| 1058 | - $field_value = $field_obj->get_default_value(); |
|
| 1059 | - } |
|
| 1060 | - } else { |
|
| 1061 | - $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1062 | - } |
|
| 1063 | - $this->_fields[$field_name] = $field_value; |
|
| 1064 | - $this->_clear_cached_property($field_name); |
|
| 1065 | - } |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * verifies that the specified field is of the correct type |
|
| 1072 | - * |
|
| 1073 | - * @param string $field_name |
|
| 1074 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1075 | - * (in cases where the same property may be used for different outputs |
|
| 1076 | - * - i.e. datetime, money etc.) |
|
| 1077 | - * @return mixed |
|
| 1078 | - * @throws EE_Error |
|
| 1079 | - */ |
|
| 1080 | - public function get($field_name, $extra_cache_ref = null) |
|
| 1081 | - { |
|
| 1082 | - return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - |
|
| 1086 | - |
|
| 1087 | - /** |
|
| 1088 | - * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1089 | - * |
|
| 1090 | - * @param string $field_name A valid fieldname |
|
| 1091 | - * @return mixed Whatever the raw value stored on the property is. |
|
| 1092 | - * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1093 | - */ |
|
| 1094 | - public function get_raw($field_name) |
|
| 1095 | - { |
|
| 1096 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1097 | - switch(true){ |
|
| 1098 | - case $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime: |
|
| 1099 | - $value = $this->_fields[$field_name]->format('U'); |
|
| 1100 | - break; |
|
| 1101 | - case $field_settings instanceof EE_Money_Field && $this->_fields[$field_name] instanceof Money: |
|
| 1102 | - $value = $this->_fields[$field_name]->floatAmount(); |
|
| 1103 | - break; |
|
| 1104 | - default: |
|
| 1105 | - $value = $this->_fields[$field_name]; |
|
| 1106 | - } |
|
| 1107 | - return $value; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - /** |
|
| 1113 | - * This is used to return the internal DateTime object used for a field that is a |
|
| 1114 | - * EE_Datetime_Field. |
|
| 1115 | - * |
|
| 1116 | - * @param string $field_name The field name retrieving the DateTime object. |
|
| 1117 | - * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1118 | - * @throws EE_Error |
|
| 1119 | - * an error is set and false returned. If the field IS an |
|
| 1120 | - * EE_Datetime_Field and but the field value is null, then |
|
| 1121 | - * just null is returned (because that indicates that likely |
|
| 1122 | - * this field is nullable). |
|
| 1123 | - */ |
|
| 1124 | - public function get_DateTime_object($field_name) |
|
| 1125 | - { |
|
| 1126 | - $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1127 | - if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1128 | - EE_Error::add_error( |
|
| 1129 | - sprintf( |
|
| 1130 | - __( |
|
| 1131 | - 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1132 | - 'event_espresso' |
|
| 1133 | - ), |
|
| 1134 | - $field_name |
|
| 1135 | - ), |
|
| 1136 | - __FILE__, |
|
| 1137 | - __FUNCTION__, |
|
| 1138 | - __LINE__ |
|
| 1139 | - ); |
|
| 1140 | - return false; |
|
| 1141 | - } |
|
| 1142 | - return $this->_fields[$field_name]; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * Gets a Money object for the specified field. Please note that this should only be |
|
| 1148 | - * used for fields corresponding to EE_Money_Fields, and it will always return a money object, |
|
| 1149 | - * or else it will throw an exception. |
|
| 1150 | - * |
|
| 1151 | - * @param $field_name |
|
| 1152 | - * @return Money |
|
| 1153 | - * @throws InvalidEntityException |
|
| 1154 | - * @throws EE_Error |
|
| 1155 | - * @throws DomainException |
|
| 1156 | - */ |
|
| 1157 | - public function getMoneyObject($field_name) |
|
| 1158 | - { |
|
| 1159 | - $this->verifyUsesMoney(__FUNCTION__); |
|
| 1160 | - $field = $this->get_model()->field_settings_for($field_name); |
|
| 1161 | - $value = isset($this->_fields[$field_name]) ? $this->_fields[$field_name] : null; |
|
| 1162 | - if (! $field instanceof EE_Money_Field |
|
| 1163 | - || ! $value instanceof Money) { |
|
| 1164 | - throw new InvalidEntityException( |
|
| 1165 | - get_class($value), |
|
| 1166 | - 'Money', |
|
| 1167 | - sprintf( |
|
| 1168 | - esc_html__( |
|
| 1169 | - // @codingStandardsIgnoreStart |
|
| 1170 | - 'Tried to retrieve money value from %1$s with ID %2$s from field %3$s but no money object present.', |
|
| 1171 | - // @codingStandardsIgnoreEnd |
|
| 1172 | - 'event_espresso' |
|
| 1173 | - ), |
|
| 1174 | - get_class($this), |
|
| 1175 | - $this->ID(), |
|
| 1176 | - $field_name |
|
| 1177 | - ) |
|
| 1178 | - ); |
|
| 1179 | - } |
|
| 1180 | - return $value; |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - /** |
|
| 1186 | - * To be used in template to immediately echo out the value, and format it for output. |
|
| 1187 | - * Eg, should call stripslashes and whatnot before echoing |
|
| 1188 | - * |
|
| 1189 | - * @param string $field_name the name of the field as it appears in the DB |
|
| 1190 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1191 | - * (in cases where the same property may be used for different outputs |
|
| 1192 | - * - i.e. datetime, money etc.) |
|
| 1193 | - * @return void |
|
| 1194 | - * @throws EE_Error |
|
| 1195 | - */ |
|
| 1196 | - public function e($field_name, $extra_cache_ref = null) |
|
| 1197 | - { |
|
| 1198 | - echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - |
|
| 1202 | - |
|
| 1203 | - /** |
|
| 1204 | - * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1205 | - * can be easily used as the value of form input. |
|
| 1206 | - * |
|
| 1207 | - * @param string $field_name |
|
| 1208 | - * @return void |
|
| 1209 | - * @throws EE_Error |
|
| 1210 | - */ |
|
| 1211 | - public function f($field_name) |
|
| 1212 | - { |
|
| 1213 | - $this->e($field_name, 'form_input'); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * Same as `f()` but just returns the value instead of echoing it |
|
| 1218 | - * @param string $field_name |
|
| 1219 | - * @return string |
|
| 1220 | - * @throws EE_Error |
|
| 1221 | - */ |
|
| 1222 | - public function get_f($field_name) |
|
| 1223 | - { |
|
| 1224 | - return (string)$this->get_pretty($field_name,'form_input'); |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 1231 | - * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 1232 | - * to see what options are available. |
|
| 1233 | - * @param string $field_name |
|
| 1234 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1235 | - * (in cases where the same property may be used for different outputs |
|
| 1236 | - * - i.e. datetime, money etc.) |
|
| 1237 | - * @return mixed |
|
| 1238 | - * @throws EE_Error |
|
| 1239 | - */ |
|
| 1240 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1241 | - { |
|
| 1242 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * This simply returns the datetime for the given field name |
|
| 1249 | - * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1250 | - * (and the equivalent e_date, e_time, e_datetime). |
|
| 1251 | - * |
|
| 1252 | - * @access protected |
|
| 1253 | - * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1254 | - * @param string $dt_frmt valid datetime format used for date |
|
| 1255 | - * (if '' then we just use the default on the field, |
|
| 1256 | - * if NULL we use the last-used format) |
|
| 1257 | - * @param string $tm_frmt Same as above except this is for time format |
|
| 1258 | - * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1259 | - * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1260 | - * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1261 | - * if field is not a valid dtt field, or void if echoing |
|
| 1262 | - * @throws EE_Error |
|
| 1263 | - */ |
|
| 1264 | - protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1265 | - { |
|
| 1266 | - // clear cached property |
|
| 1267 | - $this->_clear_cached_property($field_name); |
|
| 1268 | - //reset format properties because they are used in get() |
|
| 1269 | - $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1270 | - $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1271 | - if ($echo) { |
|
| 1272 | - $this->e($field_name, $date_or_time); |
|
| 1273 | - return ''; |
|
| 1274 | - } |
|
| 1275 | - return $this->get($field_name, $date_or_time); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1282 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1283 | - * other echoes the pretty value for dtt) |
|
| 1284 | - * |
|
| 1285 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1286 | - * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1287 | - * @return string datetime value formatted |
|
| 1288 | - * @throws EE_Error |
|
| 1289 | - */ |
|
| 1290 | - public function get_date($field_name, $format = '') |
|
| 1291 | - { |
|
| 1292 | - return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - |
|
| 1296 | - |
|
| 1297 | - /** |
|
| 1298 | - * @param $field_name |
|
| 1299 | - * @param string $format |
|
| 1300 | - * @throws EE_Error |
|
| 1301 | - */ |
|
| 1302 | - public function e_date($field_name, $format = '') |
|
| 1303 | - { |
|
| 1304 | - $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1311 | - * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1312 | - * other echoes the pretty value for dtt) |
|
| 1313 | - * |
|
| 1314 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1315 | - * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1316 | - * @return string datetime value formatted |
|
| 1317 | - * @throws EE_Error |
|
| 1318 | - */ |
|
| 1319 | - public function get_time($field_name, $format = '') |
|
| 1320 | - { |
|
| 1321 | - return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - |
|
| 1326 | - /** |
|
| 1327 | - * @param $field_name |
|
| 1328 | - * @param string $format |
|
| 1329 | - * @throws EE_Error |
|
| 1330 | - */ |
|
| 1331 | - public function e_time($field_name, $format = '') |
|
| 1332 | - { |
|
| 1333 | - $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - |
|
| 1337 | - |
|
| 1338 | - /** |
|
| 1339 | - * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1340 | - * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1341 | - * other echoes the pretty value for dtt) |
|
| 1342 | - * |
|
| 1343 | - * @param string $field_name name of model object datetime field holding the value |
|
| 1344 | - * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1345 | - * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1346 | - * @return string datetime value formatted |
|
| 1347 | - * @throws EE_Error |
|
| 1348 | - */ |
|
| 1349 | - public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1350 | - { |
|
| 1351 | - return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1352 | - } |
|
| 1353 | - |
|
| 1354 | - |
|
| 1355 | - |
|
| 1356 | - /** |
|
| 1357 | - * @param string $field_name |
|
| 1358 | - * @param string $dt_frmt |
|
| 1359 | - * @param string $tm_frmt |
|
| 1360 | - * @throws EE_Error |
|
| 1361 | - */ |
|
| 1362 | - public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1363 | - { |
|
| 1364 | - $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1370 | - * |
|
| 1371 | - * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1372 | - * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1373 | - * on the object will be used. |
|
| 1374 | - * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1375 | - * @throws InvalidArgumentException |
|
| 1376 | - * @throws InvalidInterfaceException |
|
| 1377 | - * @throws InvalidDataTypeException |
|
| 1378 | - * @throws EE_Error |
|
| 1379 | - * field name. |
|
| 1380 | - */ |
|
| 1381 | - public function get_i18n_datetime($field_name, $format = '') |
|
| 1382 | - { |
|
| 1383 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1384 | - return date_i18n( |
|
| 1385 | - $format, |
|
| 1386 | - EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1387 | - ); |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - |
|
| 1391 | - |
|
| 1392 | - /** |
|
| 1393 | - * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1394 | - * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1395 | - * thrown. |
|
| 1396 | - * |
|
| 1397 | - * @param string $field_name The field name being checked |
|
| 1398 | - * @throws EE_Error |
|
| 1399 | - * @return EE_Datetime_Field |
|
| 1400 | - */ |
|
| 1401 | - protected function _get_dtt_field_settings($field_name) |
|
| 1402 | - { |
|
| 1403 | - $field = $this->get_model()->field_settings_for($field_name); |
|
| 1404 | - //check if field is dtt |
|
| 1405 | - if ($field instanceof EE_Datetime_Field) { |
|
| 1406 | - return $field; |
|
| 1407 | - } else { |
|
| 1408 | - 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', |
|
| 1409 | - 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1410 | - } |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - |
|
| 1414 | - |
|
| 1415 | - |
|
| 1416 | - /** |
|
| 1417 | - * NOTE ABOUT BELOW: |
|
| 1418 | - * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1419 | - * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1420 | - * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1421 | - * method and make sure you send the entire datetime value for setting. |
|
| 1422 | - */ |
|
| 1423 | - /** |
|
| 1424 | - * sets the time on a datetime property |
|
| 1425 | - * |
|
| 1426 | - * @access protected |
|
| 1427 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1428 | - * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1429 | - * @throws EE_Error |
|
| 1430 | - */ |
|
| 1431 | - protected function _set_time_for($time, $fieldname) |
|
| 1432 | - { |
|
| 1433 | - $this->_set_date_time('T', $time, $fieldname); |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * sets the date on a datetime property |
|
| 1440 | - * |
|
| 1441 | - * @access protected |
|
| 1442 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1443 | - * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1444 | - * @throws EE_Error |
|
| 1445 | - */ |
|
| 1446 | - protected function _set_date_for($date, $fieldname) |
|
| 1447 | - { |
|
| 1448 | - $this->_set_date_time('D', $date, $fieldname); |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - |
|
| 1452 | - /** |
|
| 1453 | - * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1454 | - * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1455 | - * |
|
| 1456 | - * @access protected |
|
| 1457 | - * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1458 | - * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1459 | - * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1460 | - * EE_Datetime_Field property) |
|
| 1461 | - * @throws InvalidArgumentException |
|
| 1462 | - * @throws InvalidInterfaceException |
|
| 1463 | - * @throws InvalidDataTypeException |
|
| 1464 | - * @throws EE_Error |
|
| 1465 | - */ |
|
| 1466 | - protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1467 | - { |
|
| 1468 | - $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1469 | - $field->set_timezone($this->_timezone); |
|
| 1470 | - $field->set_date_format($this->_dt_frmt); |
|
| 1471 | - $field->set_time_format($this->_tm_frmt); |
|
| 1472 | - switch ($what) { |
|
| 1473 | - case 'T' : |
|
| 1474 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1475 | - $datetime_value, |
|
| 1476 | - $this->_fields[$fieldname] |
|
| 1477 | - ); |
|
| 1478 | - break; |
|
| 1479 | - case 'D' : |
|
| 1480 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1481 | - $datetime_value, |
|
| 1482 | - $this->_fields[$fieldname] |
|
| 1483 | - ); |
|
| 1484 | - break; |
|
| 1485 | - case 'B' : |
|
| 1486 | - $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1487 | - break; |
|
| 1488 | - } |
|
| 1489 | - $this->_clear_cached_property($fieldname); |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1495 | - * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1496 | - * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1497 | - * that could lead to some unexpected results! |
|
| 1498 | - * |
|
| 1499 | - * @access public |
|
| 1500 | - * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1501 | - * value being returned. |
|
| 1502 | - * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1503 | - * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1504 | - * @param string $prepend You can include something to prepend on the timestamp |
|
| 1505 | - * @param string $append You can include something to append on the timestamp |
|
| 1506 | - * @throws InvalidArgumentException |
|
| 1507 | - * @throws InvalidInterfaceException |
|
| 1508 | - * @throws InvalidDataTypeException |
|
| 1509 | - * @throws EE_Error |
|
| 1510 | - * @return string timestamp |
|
| 1511 | - */ |
|
| 1512 | - public function display_in_my_timezone( |
|
| 1513 | - $field_name, |
|
| 1514 | - $callback = 'get_datetime', |
|
| 1515 | - $args = null, |
|
| 1516 | - $prepend = '', |
|
| 1517 | - $append = '' |
|
| 1518 | - ) { |
|
| 1519 | - $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1520 | - if ($timezone === $this->_timezone) { |
|
| 1521 | - return ''; |
|
| 1522 | - } |
|
| 1523 | - $original_timezone = $this->_timezone; |
|
| 1524 | - $this->set_timezone($timezone); |
|
| 1525 | - $fn = (array)$field_name; |
|
| 1526 | - $args = array_merge($fn, (array)$args); |
|
| 1527 | - if ( ! method_exists($this, $callback)) { |
|
| 1528 | - throw new EE_Error( |
|
| 1529 | - sprintf( |
|
| 1530 | - __( |
|
| 1531 | - 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1532 | - 'event_espresso' |
|
| 1533 | - ), |
|
| 1534 | - $callback |
|
| 1535 | - ) |
|
| 1536 | - ); |
|
| 1537 | - } |
|
| 1538 | - $args = (array)$args; |
|
| 1539 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1540 | - $this->set_timezone($original_timezone); |
|
| 1541 | - return $return; |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - |
|
| 1545 | - |
|
| 1546 | - /** |
|
| 1547 | - * Deletes this model object. |
|
| 1548 | - * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1549 | - * override |
|
| 1550 | - * `EE_Base_Class::_delete` NOT this class. |
|
| 1551 | - * |
|
| 1552 | - * @return boolean | int |
|
| 1553 | - * @throws EE_Error |
|
| 1554 | - */ |
|
| 1555 | - public function delete() |
|
| 1556 | - { |
|
| 1557 | - /** |
|
| 1558 | - * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1559 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1560 | - * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1561 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1562 | - * |
|
| 1563 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1564 | - */ |
|
| 1565 | - do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1566 | - $result = $this->_delete(); |
|
| 1567 | - /** |
|
| 1568 | - * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1569 | - * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1570 | - * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1571 | - * soft deletes (trash) the object and does not permanently delete it. |
|
| 1572 | - * |
|
| 1573 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1574 | - * @param boolean $result |
|
| 1575 | - */ |
|
| 1576 | - do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1577 | - return $result; |
|
| 1578 | - } |
|
| 1579 | - |
|
| 1580 | - |
|
| 1581 | - |
|
| 1582 | - /** |
|
| 1583 | - * Calls the specific delete method for the instantiated class. |
|
| 1584 | - * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1585 | - * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1586 | - * `EE_Base_Class::delete` |
|
| 1587 | - * |
|
| 1588 | - * @return bool|int |
|
| 1589 | - * @throws EE_Error |
|
| 1590 | - */ |
|
| 1591 | - protected function _delete() |
|
| 1592 | - { |
|
| 1593 | - return $this->delete_permanently(); |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - |
|
| 1597 | - |
|
| 1598 | - /** |
|
| 1599 | - * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1600 | - * error) |
|
| 1601 | - * |
|
| 1602 | - * @return bool | int |
|
| 1603 | - * @throws EE_Error |
|
| 1604 | - */ |
|
| 1605 | - public function delete_permanently() |
|
| 1606 | - { |
|
| 1607 | - /** |
|
| 1608 | - * Called just before HARD deleting a model object |
|
| 1609 | - * |
|
| 1610 | - * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1611 | - */ |
|
| 1612 | - do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1613 | - $model = $this->get_model(); |
|
| 1614 | - $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1615 | - $this->refresh_cache_of_related_objects(); |
|
| 1616 | - /** |
|
| 1617 | - * Called just after HARD deleting a model object |
|
| 1618 | - * |
|
| 1619 | - * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1620 | - * @param boolean $result |
|
| 1621 | - */ |
|
| 1622 | - do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1623 | - return $result; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - |
|
| 1627 | - |
|
| 1628 | - /** |
|
| 1629 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1630 | - * related model objects |
|
| 1631 | - * |
|
| 1632 | - * @throws EE_Error |
|
| 1633 | - */ |
|
| 1634 | - public function refresh_cache_of_related_objects() |
|
| 1635 | - { |
|
| 1636 | - $model = $this->get_model(); |
|
| 1637 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 1638 | - if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1639 | - $related_objects = $this->_model_relations[$relation_name]; |
|
| 1640 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1641 | - //this relation only stores a single model object, not an array |
|
| 1642 | - //but let's make it consistent |
|
| 1643 | - $related_objects = array($related_objects); |
|
| 1644 | - } |
|
| 1645 | - foreach ($related_objects as $related_object) { |
|
| 1646 | - //only refresh their cache if they're in memory |
|
| 1647 | - if ($related_object instanceof EE_Base_Class) { |
|
| 1648 | - $related_object->clear_cache($model->get_this_model_name(), $this); |
|
| 1649 | - } |
|
| 1650 | - } |
|
| 1651 | - } |
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - |
|
| 1655 | - |
|
| 1656 | - |
|
| 1657 | - /** |
|
| 1658 | - * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1659 | - * object just before saving. |
|
| 1660 | - * |
|
| 1661 | - * @access public |
|
| 1662 | - * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1663 | - * if provided during the save() method (often client code will change the fields' |
|
| 1664 | - * values before calling save) |
|
| 1665 | - * @throws EE_Error |
|
| 1666 | - * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1667 | - * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1668 | - */ |
|
| 1669 | - public function save($set_cols_n_values = array()) |
|
| 1670 | - { |
|
| 1671 | - $model = $this->get_model(); |
|
| 1672 | - /** |
|
| 1673 | - * Filters the fields we're about to save on the model object |
|
| 1674 | - * |
|
| 1675 | - * @param array $set_cols_n_values |
|
| 1676 | - * @param EE_Base_Class $model_object |
|
| 1677 | - */ |
|
| 1678 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1679 | - $this); |
|
| 1680 | - //set attributes as provided in $set_cols_n_values |
|
| 1681 | - foreach ($set_cols_n_values as $column => $value) { |
|
| 1682 | - $this->set($column, $value); |
|
| 1683 | - } |
|
| 1684 | - // no changes ? then don't do anything |
|
| 1685 | - if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 1686 | - return 0; |
|
| 1687 | - } |
|
| 1688 | - /** |
|
| 1689 | - * Saving a model object. |
|
| 1690 | - * Before we perform a save, this action is fired. |
|
| 1691 | - * |
|
| 1692 | - * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1693 | - */ |
|
| 1694 | - do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1695 | - if ( ! $this->allow_persist()) { |
|
| 1696 | - return 0; |
|
| 1697 | - } |
|
| 1698 | - //now get current attribute values |
|
| 1699 | - $save_cols_n_values = $this->_fields; |
|
| 1700 | - //if the object already has an ID, update it. Otherwise, insert it |
|
| 1701 | - //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1702 | - $old_assumption_concerning_value_preparation = $model |
|
| 1703 | - ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1704 | - $model->assume_values_already_prepared_by_model_object(true); |
|
| 1705 | - //does this model have an autoincrement PK? |
|
| 1706 | - if ($model->has_primary_key_field()) { |
|
| 1707 | - if ($model->get_primary_key_field()->is_auto_increment()) { |
|
| 1708 | - //ok check if it's set, if so: update; if not, insert |
|
| 1709 | - if ( ! empty($save_cols_n_values[$model->primary_key_name()])) { |
|
| 1710 | - $results = $model->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1711 | - } else { |
|
| 1712 | - unset($save_cols_n_values[$model->primary_key_name()]); |
|
| 1713 | - $results = $model->insert($save_cols_n_values); |
|
| 1714 | - if ($results) { |
|
| 1715 | - //if successful, set the primary key |
|
| 1716 | - //but don't use the normal SET method, because it will check if |
|
| 1717 | - //an item with the same ID exists in the mapper & db, then |
|
| 1718 | - //will find it in the db (because we just added it) and THAT object |
|
| 1719 | - //will get added to the mapper before we can add this one! |
|
| 1720 | - //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1721 | - $pk_field_name = $model->primary_key_name(); |
|
| 1722 | - $this->_fields[$pk_field_name] = $results; |
|
| 1723 | - $this->_clear_cached_property($pk_field_name); |
|
| 1724 | - $model->add_to_entity_map($this); |
|
| 1725 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - } else {//PK is NOT auto-increment |
|
| 1729 | - //so check if one like it already exists in the db |
|
| 1730 | - if ($model->exists_by_ID($this->ID())) { |
|
| 1731 | - if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1732 | - throw new EE_Error( |
|
| 1733 | - sprintf( |
|
| 1734 | - __('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', |
|
| 1735 | - 'event_espresso'), |
|
| 1736 | - get_class($this), |
|
| 1737 | - get_class($model) . '::instance()->add_to_entity_map()', |
|
| 1738 | - get_class($model) . '::instance()->get_one_by_ID()', |
|
| 1739 | - '<br />' |
|
| 1740 | - ) |
|
| 1741 | - ); |
|
| 1742 | - } |
|
| 1743 | - $results = $model->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1744 | - } else { |
|
| 1745 | - $results = $model->insert($save_cols_n_values); |
|
| 1746 | - $this->_update_cached_related_model_objs_fks(); |
|
| 1747 | - } |
|
| 1748 | - } |
|
| 1749 | - } else {//there is NO primary key |
|
| 1750 | - $already_in_db = false; |
|
| 1751 | - foreach ($model->unique_indexes() as $index) { |
|
| 1752 | - $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1753 | - if ($model->exists(array($uniqueness_where_params))) { |
|
| 1754 | - $already_in_db = true; |
|
| 1755 | - } |
|
| 1756 | - } |
|
| 1757 | - if ($already_in_db) { |
|
| 1758 | - $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1759 | - $model->get_combined_primary_key_fields()); |
|
| 1760 | - $results = $model->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1761 | - } else { |
|
| 1762 | - $results = $model->insert($save_cols_n_values); |
|
| 1763 | - } |
|
| 1764 | - } |
|
| 1765 | - //restore the old assumption about values being prepared by the model object |
|
| 1766 | - $model |
|
| 1767 | - ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1768 | - /** |
|
| 1769 | - * After saving the model object this action is called |
|
| 1770 | - * |
|
| 1771 | - * @param EE_Base_Class $model_object which was just saved |
|
| 1772 | - * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1773 | - * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1774 | - */ |
|
| 1775 | - do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1776 | - $this->_has_changes = false; |
|
| 1777 | - return $results; |
|
| 1778 | - } |
|
| 1779 | - |
|
| 1780 | - |
|
| 1781 | - |
|
| 1782 | - /** |
|
| 1783 | - * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1784 | - * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1785 | - * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1786 | - * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1787 | - * 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 |
|
| 1788 | - * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1789 | - * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1790 | - * |
|
| 1791 | - * @return void |
|
| 1792 | - * @throws EE_Error |
|
| 1793 | - */ |
|
| 1794 | - protected function _update_cached_related_model_objs_fks() |
|
| 1795 | - { |
|
| 1796 | - $model = $this->get_model(); |
|
| 1797 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 1798 | - if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1799 | - foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1800 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1801 | - $model->get_this_model_name() |
|
| 1802 | - ); |
|
| 1803 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1804 | - if ($related_model_obj_in_cache->ID()) { |
|
| 1805 | - $related_model_obj_in_cache->save(); |
|
| 1806 | - } |
|
| 1807 | - } |
|
| 1808 | - } |
|
| 1809 | - } |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - |
|
| 1813 | - |
|
| 1814 | - /** |
|
| 1815 | - * Saves this model object and its NEW cached relations to the database. |
|
| 1816 | - * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1817 | - * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1818 | - * because otherwise, there's a potential for infinite looping of saving |
|
| 1819 | - * Saves the cached related model objects, and ensures the relation between them |
|
| 1820 | - * and this object and properly setup |
|
| 1821 | - * |
|
| 1822 | - * @return int ID of new model object on save; 0 on failure+ |
|
| 1823 | - * @throws EE_Error |
|
| 1824 | - */ |
|
| 1825 | - public function save_new_cached_related_model_objs() |
|
| 1826 | - { |
|
| 1827 | - //make sure this has been saved |
|
| 1828 | - if ( ! $this->ID()) { |
|
| 1829 | - $id = $this->save(); |
|
| 1830 | - } else { |
|
| 1831 | - $id = $this->ID(); |
|
| 1832 | - } |
|
| 1833 | - //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1834 | - foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1835 | - if ($this->_model_relations[$relationName]) { |
|
| 1836 | - //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1837 | - //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1838 | - if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1839 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1840 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1841 | - /* @var $related_model_obj EE_Base_Class */ |
|
| 1842 | - $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1843 | - // if( ! $related_model_obj->ID()){ |
|
| 1844 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1845 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1846 | - // } |
|
| 1847 | - } else { |
|
| 1848 | - foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1849 | - //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1850 | - //but ONLY if it DOES NOT exist in the DB |
|
| 1851 | - // if( ! $related_model_obj->ID()){ |
|
| 1852 | - $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1853 | - $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1854 | - // } |
|
| 1855 | - } |
|
| 1856 | - } |
|
| 1857 | - } |
|
| 1858 | - } |
|
| 1859 | - return $id; |
|
| 1860 | - } |
|
| 1861 | - |
|
| 1862 | - |
|
| 1863 | - |
|
| 1864 | - /** |
|
| 1865 | - * for getting a model while instantiated. |
|
| 1866 | - * |
|
| 1867 | - * @return EEM_Base | EEM_CPT_Base |
|
| 1868 | - */ |
|
| 1869 | - public function get_model() |
|
| 1870 | - { |
|
| 1871 | - if( ! $this->_model){ |
|
| 1872 | - $modelName = self::_get_model_classname(get_class($this)); |
|
| 1873 | - $this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1874 | - } else { |
|
| 1875 | - $this->_model->set_timezone($this->_timezone); |
|
| 1876 | - } |
|
| 1877 | - |
|
| 1878 | - return $this->_model; |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * @param $props_n_values |
|
| 1885 | - * @param $classname |
|
| 1886 | - * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1887 | - * @throws EE_Error |
|
| 1888 | - */ |
|
| 1889 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1890 | - { |
|
| 1891 | - //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1892 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1893 | - if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1894 | - $id = $props_n_values[$primary_id_ref]; |
|
| 1895 | - return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1896 | - } |
|
| 1897 | - return false; |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1904 | - * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1905 | - * 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 |
|
| 1906 | - * we return false. |
|
| 1907 | - * |
|
| 1908 | - * @param array $props_n_values incoming array of properties and their values |
|
| 1909 | - * @param string $classname the classname of the child class |
|
| 1910 | - * @param null $timezone |
|
| 1911 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1912 | - * date_format and the second value is the time format |
|
| 1913 | - * @return mixed (EE_Base_Class|bool) |
|
| 1914 | - * @throws EE_Error |
|
| 1915 | - */ |
|
| 1916 | - protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1917 | - { |
|
| 1918 | - $existing = null; |
|
| 1919 | - $model = self::_get_model($classname, $timezone); |
|
| 1920 | - if ($model->has_primary_key_field()) { |
|
| 1921 | - $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1922 | - if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1923 | - && ! empty($props_n_values[$primary_id_ref]) |
|
| 1924 | - ) { |
|
| 1925 | - $existing = $model->get_one_by_ID( |
|
| 1926 | - $props_n_values[$primary_id_ref] |
|
| 1927 | - ); |
|
| 1928 | - } |
|
| 1929 | - } elseif ($model->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1930 | - //no primary key on this model, but there's still a matching item in the DB |
|
| 1931 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1932 | - self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1933 | - ); |
|
| 1934 | - } |
|
| 1935 | - if ($existing) { |
|
| 1936 | - //set date formats if present before setting values |
|
| 1937 | - if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1938 | - $existing->set_date_format($date_formats[0]); |
|
| 1939 | - $existing->set_time_format($date_formats[1]); |
|
| 1940 | - } else { |
|
| 1941 | - //set default formats for date and time |
|
| 1942 | - $existing->set_date_format(get_option('date_format')); |
|
| 1943 | - $existing->set_time_format(get_option('time_format')); |
|
| 1944 | - } |
|
| 1945 | - foreach ($props_n_values as $property => $field_value) { |
|
| 1946 | - $existing->set($property, $field_value); |
|
| 1947 | - } |
|
| 1948 | - return $existing; |
|
| 1949 | - } else { |
|
| 1950 | - return false; |
|
| 1951 | - } |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - |
|
| 1956 | - /** |
|
| 1957 | - * Gets the EEM_*_Model for this class |
|
| 1958 | - * |
|
| 1959 | - * @access public now, as this is more convenient |
|
| 1960 | - * @param $classname |
|
| 1961 | - * @param null $timezone |
|
| 1962 | - * @throws EE_Error |
|
| 1963 | - * @return EEM_Base |
|
| 1964 | - */ |
|
| 1965 | - protected static function _get_model($classname, $timezone = null) |
|
| 1966 | - { |
|
| 1967 | - //find model for this class |
|
| 1968 | - if ( ! $classname) { |
|
| 1969 | - throw new EE_Error( |
|
| 1970 | - sprintf( |
|
| 1971 | - __( |
|
| 1972 | - "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1973 | - "event_espresso" |
|
| 1974 | - ), |
|
| 1975 | - $classname |
|
| 1976 | - ) |
|
| 1977 | - ); |
|
| 1978 | - } |
|
| 1979 | - $modelName = self::_get_model_classname($classname); |
|
| 1980 | - return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - |
|
| 1984 | - /** |
|
| 1985 | - * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1986 | - * |
|
| 1987 | - * @param string $model_classname |
|
| 1988 | - * @param null $timezone |
|
| 1989 | - * @return EEM_Base |
|
| 1990 | - * @throws \ReflectionException |
|
| 1991 | - * @throws InvalidArgumentException |
|
| 1992 | - * @throws InvalidInterfaceException |
|
| 1993 | - * @throws InvalidDataTypeException |
|
| 1994 | - * @throws EE_Error |
|
| 1995 | - */ |
|
| 1996 | - protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1997 | - { |
|
| 1998 | - $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1999 | - $model = EE_Registry::instance()->load_model($model_classname); |
|
| 2000 | - $model->set_timezone($timezone); |
|
| 2001 | - return $model; |
|
| 2002 | - } |
|
| 2003 | - |
|
| 2004 | - |
|
| 2005 | - |
|
| 2006 | - /** |
|
| 2007 | - * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 2008 | - * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 2009 | - * |
|
| 2010 | - * @param null $model_name |
|
| 2011 | - * @return string like EEM_Attendee |
|
| 2012 | - */ |
|
| 2013 | - private static function _get_model_classname($model_name = null) |
|
| 2014 | - { |
|
| 2015 | - if (strpos($model_name, "EE_") === 0) { |
|
| 2016 | - $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 2017 | - } else { |
|
| 2018 | - $model_classname = "EEM_" . $model_name; |
|
| 2019 | - } |
|
| 2020 | - return $model_classname; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - |
|
| 2024 | - |
|
| 2025 | - /** |
|
| 2026 | - * returns the name of the primary key attribute |
|
| 2027 | - * |
|
| 2028 | - * @param null $classname |
|
| 2029 | - * @throws EE_Error |
|
| 2030 | - * @return string |
|
| 2031 | - */ |
|
| 2032 | - protected static function _get_primary_key_name($classname = null) |
|
| 2033 | - { |
|
| 2034 | - if ( ! $classname) { |
|
| 2035 | - throw new EE_Error( |
|
| 2036 | - sprintf( |
|
| 2037 | - __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 2038 | - $classname |
|
| 2039 | - ) |
|
| 2040 | - ); |
|
| 2041 | - } |
|
| 2042 | - return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 2043 | - } |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | - |
|
| 2047 | - /** |
|
| 2048 | - * Gets the value of the primary key. |
|
| 2049 | - * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 2050 | - * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 2051 | - * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 2052 | - * |
|
| 2053 | - * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 2054 | - * @throws EE_Error |
|
| 2055 | - */ |
|
| 2056 | - public function ID() |
|
| 2057 | - { |
|
| 2058 | - $model = $this->get_model(); |
|
| 2059 | - //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 2060 | - if ($model->has_primary_key_field()) { |
|
| 2061 | - return $this->_fields[$model->primary_key_name()]; |
|
| 2062 | - } else { |
|
| 2063 | - return $model->get_index_primary_key_string($this->_fields); |
|
| 2064 | - } |
|
| 2065 | - } |
|
| 2066 | - |
|
| 2067 | - |
|
| 2068 | - |
|
| 2069 | - /** |
|
| 2070 | - * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 2071 | - * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 2072 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 2073 | - * |
|
| 2074 | - * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 2075 | - * @param string $relationName eg 'Events','Question',etc. |
|
| 2076 | - * an attendee to a group, you also want to specify which role they |
|
| 2077 | - * will have in that group. So you would use this parameter to |
|
| 2078 | - * specify array('role-column-name'=>'role-id') |
|
| 2079 | - * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 2080 | - * allow you to further constrict the relation to being added. |
|
| 2081 | - * However, keep in mind that the columns (keys) given must match a |
|
| 2082 | - * column on the JOIN table and currently only the HABTM models |
|
| 2083 | - * accept these additional conditions. Also remember that if an |
|
| 2084 | - * exact match isn't found for these extra cols/val pairs, then a |
|
| 2085 | - * NEW row is created in the join table. |
|
| 2086 | - * @param null $cache_id |
|
| 2087 | - * @throws EE_Error |
|
| 2088 | - * @return EE_Base_Class the object the relation was added to |
|
| 2089 | - */ |
|
| 2090 | - public function _add_relation_to( |
|
| 2091 | - $otherObjectModelObjectOrID, |
|
| 2092 | - $relationName, |
|
| 2093 | - $extra_join_model_fields_n_values = array(), |
|
| 2094 | - $cache_id = null |
|
| 2095 | - ) { |
|
| 2096 | - $model = $this->get_model(); |
|
| 2097 | - //if this thing exists in the DB, save the relation to the DB |
|
| 2098 | - if ($this->ID()) { |
|
| 2099 | - $otherObject = $model |
|
| 2100 | - ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2101 | - $extra_join_model_fields_n_values); |
|
| 2102 | - //clear cache so future get_many_related and get_first_related() return new results. |
|
| 2103 | - $this->clear_cache($relationName, $otherObject, true); |
|
| 2104 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 2105 | - $otherObject->clear_cache($model->get_this_model_name(), $this); |
|
| 2106 | - } |
|
| 2107 | - } else { |
|
| 2108 | - //this thing doesn't exist in the DB, so just cache it |
|
| 2109 | - if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 2110 | - throw new EE_Error(sprintf( |
|
| 2111 | - __('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', |
|
| 2112 | - 'event_espresso'), |
|
| 2113 | - $otherObjectModelObjectOrID, |
|
| 2114 | - get_class($this) |
|
| 2115 | - )); |
|
| 2116 | - } else { |
|
| 2117 | - $otherObject = $otherObjectModelObjectOrID; |
|
| 2118 | - } |
|
| 2119 | - $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 2120 | - } |
|
| 2121 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 2122 | - //fix the reciprocal relation too |
|
| 2123 | - if ($otherObject->ID()) { |
|
| 2124 | - //its saved so assumed relations exist in the DB, so we can just |
|
| 2125 | - //clear the cache so future queries use the updated info in the DB |
|
| 2126 | - $otherObject->clear_cache($model->get_this_model_name(), null, true); |
|
| 2127 | - } else { |
|
| 2128 | - //it's not saved, so it caches relations like this |
|
| 2129 | - $otherObject->cache($model->get_this_model_name(), $this); |
|
| 2130 | - } |
|
| 2131 | - } |
|
| 2132 | - return $otherObject; |
|
| 2133 | - } |
|
| 2134 | - |
|
| 2135 | - |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 2139 | - * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 2140 | - * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 2141 | - * from the cache |
|
| 2142 | - * |
|
| 2143 | - * @param mixed $otherObjectModelObjectOrID |
|
| 2144 | - * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 2145 | - * to the DB yet |
|
| 2146 | - * @param string $relationName |
|
| 2147 | - * @param array $where_query |
|
| 2148 | - * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2149 | - * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2150 | - * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2151 | - * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2152 | - * created in the join table. |
|
| 2153 | - * @return EE_Base_Class the relation was removed from |
|
| 2154 | - * @throws EE_Error |
|
| 2155 | - */ |
|
| 2156 | - public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2157 | - { |
|
| 2158 | - if ($this->ID()) { |
|
| 2159 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2160 | - $otherObject = $this->get_model() |
|
| 2161 | - ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2162 | - $where_query); |
|
| 2163 | - $this->clear_cache($relationName, $otherObject); |
|
| 2164 | - } else { |
|
| 2165 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2166 | - $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2167 | - } |
|
| 2168 | - if ($otherObject instanceof EE_Base_Class) { |
|
| 2169 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2170 | - } |
|
| 2171 | - return $otherObject; |
|
| 2172 | - } |
|
| 2173 | - |
|
| 2174 | - |
|
| 2175 | - |
|
| 2176 | - /** |
|
| 2177 | - * Removes ALL the related things for the $relationName. |
|
| 2178 | - * |
|
| 2179 | - * @param string $relationName |
|
| 2180 | - * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2181 | - * @return EE_Base_Class |
|
| 2182 | - * @throws EE_Error |
|
| 2183 | - */ |
|
| 2184 | - public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2185 | - { |
|
| 2186 | - if ($this->ID()) { |
|
| 2187 | - //if this exists in the DB, save the relation change to the DB too |
|
| 2188 | - $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2189 | - $this->clear_cache($relationName, null, true); |
|
| 2190 | - } else { |
|
| 2191 | - //this doesn't exist in the DB, just remove it from the cache |
|
| 2192 | - $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2193 | - } |
|
| 2194 | - if (is_array($otherObjects)) { |
|
| 2195 | - foreach ($otherObjects as $otherObject) { |
|
| 2196 | - $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2197 | - } |
|
| 2198 | - } |
|
| 2199 | - return $otherObjects; |
|
| 2200 | - } |
|
| 2201 | - |
|
| 2202 | - |
|
| 2203 | - |
|
| 2204 | - /** |
|
| 2205 | - * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2206 | - * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2207 | - * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2208 | - * because we want to get even deleted items etc. |
|
| 2209 | - * |
|
| 2210 | - * @param string $relationName key in the model's _model_relations array |
|
| 2211 | - * @param array $query_params like EEM_Base::get_all |
|
| 2212 | - * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2213 | - * @throws EE_Error |
|
| 2214 | - * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2215 | - * you want IDs |
|
| 2216 | - */ |
|
| 2217 | - public function get_many_related($relationName, $query_params = array()) |
|
| 2218 | - { |
|
| 2219 | - if ($this->ID()) { |
|
| 2220 | - //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2221 | - //if there are query parameters, forget about caching the related model objects. |
|
| 2222 | - if ($query_params) { |
|
| 2223 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2224 | - } else { |
|
| 2225 | - //did we already cache the result of this query? |
|
| 2226 | - $cached_results = $this->get_all_from_cache($relationName); |
|
| 2227 | - if ( ! $cached_results) { |
|
| 2228 | - $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2229 | - //if no query parameters were passed, then we got all the related model objects |
|
| 2230 | - //for that relation. We can cache them then. |
|
| 2231 | - foreach ($related_model_objects as $related_model_object) { |
|
| 2232 | - $this->cache($relationName, $related_model_object); |
|
| 2233 | - } |
|
| 2234 | - } else { |
|
| 2235 | - $related_model_objects = $cached_results; |
|
| 2236 | - } |
|
| 2237 | - } |
|
| 2238 | - } else { |
|
| 2239 | - //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2240 | - $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2241 | - } |
|
| 2242 | - return $related_model_objects; |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - |
|
| 2246 | - /** |
|
| 2247 | - * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2248 | - * unless otherwise specified in the $query_params |
|
| 2249 | - * |
|
| 2250 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2251 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2252 | - * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2253 | - * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2254 | - * that by the setting $distinct to TRUE; |
|
| 2255 | - * @return int |
|
| 2256 | - * @throws EE_Error |
|
| 2257 | - */ |
|
| 2258 | - public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2259 | - { |
|
| 2260 | - return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - |
|
| 2264 | - /** |
|
| 2265 | - * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2266 | - * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2267 | - * |
|
| 2268 | - * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2269 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2270 | - * @param string $field_to_sum name of field to count by. |
|
| 2271 | - * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2272 | - * change it) |
|
| 2273 | - * @return int |
|
| 2274 | - * @throws EE_Error |
|
| 2275 | - */ |
|
| 2276 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2277 | - { |
|
| 2278 | - return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2279 | - } |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - |
|
| 2283 | - /** |
|
| 2284 | - * Gets the first (ie, one) related model object of the specified type. |
|
| 2285 | - * |
|
| 2286 | - * @param string $relationName key in the model's _model_relations array |
|
| 2287 | - * @param array $query_params like EEM_Base::get_all |
|
| 2288 | - * @return EE_Base_Class (not an array, a single object) |
|
| 2289 | - * @throws EE_Error |
|
| 2290 | - */ |
|
| 2291 | - public function get_first_related($relationName, $query_params = array()) |
|
| 2292 | - { |
|
| 2293 | - $model = $this->get_model(); |
|
| 2294 | - if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2295 | - //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2296 | - //also make sure we're not caching the result of get_first_related |
|
| 2297 | - //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2298 | - if ($query_params |
|
| 2299 | - || ! $model->related_settings_for($relationName) |
|
| 2300 | - instanceof |
|
| 2301 | - EE_Belongs_To_Relation |
|
| 2302 | - ) { |
|
| 2303 | - $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2304 | - } else { |
|
| 2305 | - //first, check if we've already cached the result of this query |
|
| 2306 | - $cached_result = $this->get_one_from_cache($relationName); |
|
| 2307 | - if ( ! $cached_result) { |
|
| 2308 | - $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2309 | - $this->cache($relationName, $related_model_object); |
|
| 2310 | - } else { |
|
| 2311 | - $related_model_object = $cached_result; |
|
| 2312 | - } |
|
| 2313 | - } |
|
| 2314 | - } else { |
|
| 2315 | - $related_model_object = null; |
|
| 2316 | - //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2317 | - if ($model->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2318 | - $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2319 | - } |
|
| 2320 | - //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 |
|
| 2321 | - if ( ! $related_model_object) { |
|
| 2322 | - $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2323 | - } |
|
| 2324 | - } |
|
| 2325 | - return $related_model_object; |
|
| 2326 | - } |
|
| 2327 | - |
|
| 2328 | - |
|
| 2329 | - |
|
| 2330 | - /** |
|
| 2331 | - * Does a delete on all related objects of type $relationName and removes |
|
| 2332 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2333 | - * of blocking related model objects) does nothing. If the related model objects are |
|
| 2334 | - * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2335 | - * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2336 | - * |
|
| 2337 | - * @param string $relationName |
|
| 2338 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2339 | - * @return int how many deleted |
|
| 2340 | - * @throws EE_Error |
|
| 2341 | - */ |
|
| 2342 | - public function delete_related($relationName, $query_params = array()) |
|
| 2343 | - { |
|
| 2344 | - if ($this->ID()) { |
|
| 2345 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2346 | - } else { |
|
| 2347 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2348 | - $this->clear_cache($relationName, null, true); |
|
| 2349 | - } |
|
| 2350 | - return $count; |
|
| 2351 | - } |
|
| 2352 | - |
|
| 2353 | - |
|
| 2354 | - |
|
| 2355 | - /** |
|
| 2356 | - * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2357 | - * the current model object's relation to them. If they can't be deleted (because |
|
| 2358 | - * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2359 | - * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2360 | - * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2361 | - * |
|
| 2362 | - * @param string $relationName |
|
| 2363 | - * @param array $query_params like EEM_Base::get_all's |
|
| 2364 | - * @return int how many deleted (including those soft deleted) |
|
| 2365 | - * @throws EE_Error |
|
| 2366 | - */ |
|
| 2367 | - public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2368 | - { |
|
| 2369 | - if ($this->ID()) { |
|
| 2370 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2371 | - } else { |
|
| 2372 | - $count = count($this->get_all_from_cache($relationName)); |
|
| 2373 | - } |
|
| 2374 | - $this->clear_cache($relationName, null, true); |
|
| 2375 | - return $count; |
|
| 2376 | - } |
|
| 2377 | - |
|
| 2378 | - |
|
| 2379 | - |
|
| 2380 | - /** |
|
| 2381 | - * is_set |
|
| 2382 | - * Just a simple utility function children can use for checking if property exists |
|
| 2383 | - * |
|
| 2384 | - * @access public |
|
| 2385 | - * @param string $field_name property to check |
|
| 2386 | - * @return bool TRUE if existing,FALSE if not. |
|
| 2387 | - */ |
|
| 2388 | - public function is_set($field_name) |
|
| 2389 | - { |
|
| 2390 | - return isset($this->_fields[$field_name]); |
|
| 2391 | - } |
|
| 2392 | - |
|
| 2393 | - |
|
| 2394 | - |
|
| 2395 | - /** |
|
| 2396 | - * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2397 | - * EE_Error exception if they don't |
|
| 2398 | - * |
|
| 2399 | - * @param mixed (string|array) $properties properties to check |
|
| 2400 | - * @throws EE_Error |
|
| 2401 | - * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2402 | - */ |
|
| 2403 | - protected function _property_exists($properties) |
|
| 2404 | - { |
|
| 2405 | - foreach ((array)$properties as $property_name) { |
|
| 2406 | - //first make sure this property exists |
|
| 2407 | - if ( ! $this->_fields[$property_name]) { |
|
| 2408 | - throw new EE_Error( |
|
| 2409 | - sprintf( |
|
| 2410 | - __( |
|
| 2411 | - 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2412 | - 'event_espresso' |
|
| 2413 | - ), |
|
| 2414 | - $property_name |
|
| 2415 | - ) |
|
| 2416 | - ); |
|
| 2417 | - } |
|
| 2418 | - } |
|
| 2419 | - return true; |
|
| 2420 | - } |
|
| 2421 | - |
|
| 2422 | - |
|
| 2423 | - |
|
| 2424 | - /** |
|
| 2425 | - * This simply returns an array of model fields for this object |
|
| 2426 | - * |
|
| 2427 | - * @return array |
|
| 2428 | - * @throws EE_Error |
|
| 2429 | - */ |
|
| 2430 | - public function model_field_array() |
|
| 2431 | - { |
|
| 2432 | - $fields = $this->get_model()->field_settings(false); |
|
| 2433 | - $properties = array(); |
|
| 2434 | - //remove prepended underscore |
|
| 2435 | - foreach ($fields as $field_name => $settings) { |
|
| 2436 | - $properties[$field_name] = $this->get($field_name); |
|
| 2437 | - } |
|
| 2438 | - return $properties; |
|
| 2439 | - } |
|
| 2440 | - |
|
| 2441 | - |
|
| 2442 | - |
|
| 2443 | - /** |
|
| 2444 | - * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2445 | - * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2446 | - * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2447 | - * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2448 | - * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2449 | - * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2450 | - * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2451 | - * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2452 | - * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2453 | - * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2454 | - * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2455 | - * return $previousReturnValue.$returnString; |
|
| 2456 | - * } |
|
| 2457 | - * require('EE_Answer.class.php'); |
|
| 2458 | - * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2459 | - * echo $answer->my_callback('monkeys',100); |
|
| 2460 | - * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2461 | - * |
|
| 2462 | - * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2463 | - * @param array $args array of original arguments passed to the function |
|
| 2464 | - * @throws EE_Error |
|
| 2465 | - * @return mixed whatever the plugin which calls add_filter decides |
|
| 2466 | - */ |
|
| 2467 | - public function __call($methodName, $args) |
|
| 2468 | - { |
|
| 2469 | - $className = get_class($this); |
|
| 2470 | - $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2471 | - if ( ! has_filter($tagName)) { |
|
| 2472 | - throw new EE_Error( |
|
| 2473 | - sprintf( |
|
| 2474 | - __( |
|
| 2475 | - "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;}", |
|
| 2476 | - "event_espresso" |
|
| 2477 | - ), |
|
| 2478 | - $methodName, |
|
| 2479 | - $className, |
|
| 2480 | - $tagName |
|
| 2481 | - ) |
|
| 2482 | - ); |
|
| 2483 | - } |
|
| 2484 | - return apply_filters($tagName, null, $this, $args); |
|
| 2485 | - } |
|
| 2486 | - |
|
| 2487 | - |
|
| 2488 | - /** |
|
| 2489 | - * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2490 | - * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2491 | - * |
|
| 2492 | - * @param string $meta_key |
|
| 2493 | - * @param mixed $meta_value |
|
| 2494 | - * @param mixed $previous_value |
|
| 2495 | - * @return bool|int # of records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2496 | - * @throws InvalidArgumentException |
|
| 2497 | - * @throws InvalidInterfaceException |
|
| 2498 | - * @throws InvalidDataTypeException |
|
| 2499 | - * @throws EE_Error |
|
| 2500 | - * NOTE: if the values haven't changed, returns 0 |
|
| 2501 | - */ |
|
| 2502 | - public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2503 | - { |
|
| 2504 | - $query_params = array( |
|
| 2505 | - array( |
|
| 2506 | - 'EXM_key' => $meta_key, |
|
| 2507 | - 'OBJ_ID' => $this->ID(), |
|
| 2508 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2509 | - ), |
|
| 2510 | - ); |
|
| 2511 | - if ($previous_value !== null) { |
|
| 2512 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2513 | - } |
|
| 2514 | - $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2515 | - if ( ! $existing_rows_like_that) { |
|
| 2516 | - return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2517 | - } |
|
| 2518 | - foreach ($existing_rows_like_that as $existing_row) { |
|
| 2519 | - $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2520 | - } |
|
| 2521 | - return count($existing_rows_like_that); |
|
| 2522 | - } |
|
| 2523 | - |
|
| 2524 | - |
|
| 2525 | - /** |
|
| 2526 | - * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2527 | - * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2528 | - * extra meta row was entered, false if not |
|
| 2529 | - * |
|
| 2530 | - * @param string $meta_key |
|
| 2531 | - * @param mixed $meta_value |
|
| 2532 | - * @param boolean $unique |
|
| 2533 | - * @return boolean |
|
| 2534 | - * @throws InvalidArgumentException |
|
| 2535 | - * @throws InvalidInterfaceException |
|
| 2536 | - * @throws InvalidDataTypeException |
|
| 2537 | - * @throws EE_Error |
|
| 2538 | - */ |
|
| 2539 | - public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2540 | - { |
|
| 2541 | - if ($unique) { |
|
| 2542 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2543 | - array( |
|
| 2544 | - array( |
|
| 2545 | - 'EXM_key' => $meta_key, |
|
| 2546 | - 'OBJ_ID' => $this->ID(), |
|
| 2547 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2548 | - ), |
|
| 2549 | - ) |
|
| 2550 | - ); |
|
| 2551 | - if ($existing_extra_meta) { |
|
| 2552 | - return false; |
|
| 2553 | - } |
|
| 2554 | - } |
|
| 2555 | - $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2556 | - array( |
|
| 2557 | - 'EXM_key' => $meta_key, |
|
| 2558 | - 'EXM_value' => $meta_value, |
|
| 2559 | - 'OBJ_ID' => $this->ID(), |
|
| 2560 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2561 | - ) |
|
| 2562 | - ); |
|
| 2563 | - $new_extra_meta->save(); |
|
| 2564 | - return true; |
|
| 2565 | - } |
|
| 2566 | - |
|
| 2567 | - |
|
| 2568 | - /** |
|
| 2569 | - * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2570 | - * is specified, only deletes extra meta records with that value. |
|
| 2571 | - * |
|
| 2572 | - * @param string $meta_key |
|
| 2573 | - * @param mixed $meta_value |
|
| 2574 | - * @return int number of extra meta rows deleted |
|
| 2575 | - * @throws InvalidArgumentException |
|
| 2576 | - * @throws InvalidInterfaceException |
|
| 2577 | - * @throws InvalidDataTypeException |
|
| 2578 | - * @throws EE_Error |
|
| 2579 | - */ |
|
| 2580 | - public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2581 | - { |
|
| 2582 | - $query_params = array( |
|
| 2583 | - array( |
|
| 2584 | - 'EXM_key' => $meta_key, |
|
| 2585 | - 'OBJ_ID' => $this->ID(), |
|
| 2586 | - 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2587 | - ), |
|
| 2588 | - ); |
|
| 2589 | - if ($meta_value !== null) { |
|
| 2590 | - $query_params[0]['EXM_value'] = $meta_value; |
|
| 2591 | - } |
|
| 2592 | - return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - |
|
| 2596 | - |
|
| 2597 | - /** |
|
| 2598 | - * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2599 | - * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2600 | - * You can specify $default is case you haven't found the extra meta |
|
| 2601 | - * |
|
| 2602 | - * @param string $meta_key |
|
| 2603 | - * @param boolean $single |
|
| 2604 | - * @param mixed $default if we don't find anything, what should we return? |
|
| 2605 | - * @return mixed single value if $single; array if ! $single |
|
| 2606 | - * @throws EE_Error |
|
| 2607 | - */ |
|
| 2608 | - public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2609 | - { |
|
| 2610 | - if ($single) { |
|
| 2611 | - $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2612 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2613 | - return $result->value(); |
|
| 2614 | - } |
|
| 2615 | - } else { |
|
| 2616 | - $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2617 | - if ($results) { |
|
| 2618 | - $values = array(); |
|
| 2619 | - foreach ($results as $result) { |
|
| 2620 | - if ($result instanceof EE_Extra_Meta) { |
|
| 2621 | - $values[$result->ID()] = $result->value(); |
|
| 2622 | - } |
|
| 2623 | - } |
|
| 2624 | - return $values; |
|
| 2625 | - } |
|
| 2626 | - } |
|
| 2627 | - //if nothing discovered yet return default. |
|
| 2628 | - return apply_filters( |
|
| 2629 | - 'FHEE__EE_Base_Class__get_extra_meta__default_value', |
|
| 2630 | - $default, |
|
| 2631 | - $meta_key, |
|
| 2632 | - $single, |
|
| 2633 | - $this |
|
| 2634 | - ); |
|
| 2635 | - } |
|
| 2636 | - |
|
| 2637 | - |
|
| 2638 | - |
|
| 2639 | - /** |
|
| 2640 | - * Returns a simple array of all the extra meta associated with this model object. |
|
| 2641 | - * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2642 | - * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2643 | - * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2644 | - * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2645 | - * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2646 | - * finally the extra meta's value as each sub-value. (eg |
|
| 2647 | - * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2648 | - * |
|
| 2649 | - * @param boolean $one_of_each_key |
|
| 2650 | - * @return array |
|
| 2651 | - * @throws EE_Error |
|
| 2652 | - */ |
|
| 2653 | - public function all_extra_meta_array($one_of_each_key = true) |
|
| 2654 | - { |
|
| 2655 | - $return_array = array(); |
|
| 2656 | - if ($one_of_each_key) { |
|
| 2657 | - $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2658 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2659 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2660 | - $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2661 | - } |
|
| 2662 | - } |
|
| 2663 | - } else { |
|
| 2664 | - $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2665 | - foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2666 | - if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2667 | - if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2668 | - $return_array[$extra_meta_obj->key()] = array(); |
|
| 2669 | - } |
|
| 2670 | - $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2671 | - } |
|
| 2672 | - } |
|
| 2673 | - } |
|
| 2674 | - return $return_array; |
|
| 2675 | - } |
|
| 2676 | - |
|
| 2677 | - |
|
| 2678 | - |
|
| 2679 | - /** |
|
| 2680 | - * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2681 | - * |
|
| 2682 | - * @return string |
|
| 2683 | - * @throws EE_Error |
|
| 2684 | - */ |
|
| 2685 | - public function name() |
|
| 2686 | - { |
|
| 2687 | - //find a field that's not a text field |
|
| 2688 | - $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2689 | - if ($field_we_can_use) { |
|
| 2690 | - return $this->get($field_we_can_use->get_name()); |
|
| 2691 | - } else { |
|
| 2692 | - $first_few_properties = $this->model_field_array(); |
|
| 2693 | - $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2694 | - $name_parts = array(); |
|
| 2695 | - foreach ($first_few_properties as $name => $value) { |
|
| 2696 | - $name_parts[] = "$name:$value"; |
|
| 2697 | - } |
|
| 2698 | - return implode(",", $name_parts); |
|
| 2699 | - } |
|
| 2700 | - } |
|
| 2701 | - |
|
| 2702 | - |
|
| 2703 | - |
|
| 2704 | - /** |
|
| 2705 | - * in_entity_map |
|
| 2706 | - * Checks if this model object has been proven to already be in the entity map |
|
| 2707 | - * |
|
| 2708 | - * @return boolean |
|
| 2709 | - * @throws EE_Error |
|
| 2710 | - */ |
|
| 2711 | - public function in_entity_map() |
|
| 2712 | - { |
|
| 2713 | - if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2714 | - //well, if we looked, did we find it in the entity map? |
|
| 2715 | - return true; |
|
| 2716 | - } else { |
|
| 2717 | - return false; |
|
| 2718 | - } |
|
| 2719 | - } |
|
| 2720 | - |
|
| 2721 | - |
|
| 2722 | - |
|
| 2723 | - /** |
|
| 2724 | - * refresh_from_db |
|
| 2725 | - * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2726 | - * |
|
| 2727 | - * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2728 | - * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2729 | - */ |
|
| 2730 | - public function refresh_from_db() |
|
| 2731 | - { |
|
| 2732 | - if ($this->ID() && $this->in_entity_map()) { |
|
| 2733 | - $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2734 | - } else { |
|
| 2735 | - //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2736 | - //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2737 | - //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2738 | - //absolutely nothing in it for this ID |
|
| 2739 | - if (WP_DEBUG) { |
|
| 2740 | - throw new EE_Error( |
|
| 2741 | - sprintf( |
|
| 2742 | - __('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.', |
|
| 2743 | - 'event_espresso'), |
|
| 2744 | - $this->ID(), |
|
| 2745 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2746 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2747 | - ) |
|
| 2748 | - ); |
|
| 2749 | - } |
|
| 2750 | - } |
|
| 2751 | - } |
|
| 2752 | - |
|
| 2753 | - |
|
| 2754 | - /** |
|
| 2755 | - * Gets the money field's amount in subunits (and if the currency has no subunits, gets it in the main units) |
|
| 2756 | - * |
|
| 2757 | - * @param string $money_field_name |
|
| 2758 | - * @return int |
|
| 2759 | - * @throws InvalidEntityException |
|
| 2760 | - * @throws EE_Error |
|
| 2761 | - * @throws DomainException |
|
| 2762 | - */ |
|
| 2763 | - public function moneyInSubunits($money_field_name) |
|
| 2764 | - { |
|
| 2765 | - $this->verifyUsesMoney(__FUNCTION__); |
|
| 2766 | - return $this->getMoneyObject($money_field_name)->amountInSubunits(); |
|
| 2767 | - } |
|
| 2768 | - |
|
| 2769 | - |
|
| 2770 | - /** |
|
| 2771 | - * Sets the money field's amount based on the incoming monetary subunits (eg pennies). If the currency has no |
|
| 2772 | - * subunits, the amount is actually assumed to be in the currency's main units |
|
| 2773 | - * |
|
| 2774 | - * @param string $money_field_name |
|
| 2775 | - * @param int $amount_in_subunits |
|
| 2776 | - * @throws InvalidArgumentException |
|
| 2777 | - * @throws InvalidInterfaceException |
|
| 2778 | - * @throws InvalidIdentifierException |
|
| 2779 | - * @throws InvalidDataTypeException |
|
| 2780 | - * @throws EE_Error |
|
| 2781 | - * @throws DomainException |
|
| 2782 | - */ |
|
| 2783 | - public function setMoneySubunits($money_field_name,$amount_in_subunits) |
|
| 2784 | - { |
|
| 2785 | - $this->verifyUsesMoney(__FUNCTION__); |
|
| 2786 | - $money = $this->money_factory->createFromSubUnits( |
|
| 2787 | - $amount_in_subunits, |
|
| 2788 | - EE_Config::instance()->currency->code |
|
| 2789 | - ); |
|
| 2790 | - $this->set($money_field_name, $money); |
|
| 2791 | - } |
|
| 2792 | - |
|
| 2793 | - |
|
| 2794 | - /** |
|
| 2795 | - * @param string $function |
|
| 2796 | - * @throws DomainException |
|
| 2797 | - * @throws EE_Error |
|
| 2798 | - */ |
|
| 2799 | - private function verifyUsesMoney($function) |
|
| 2800 | - { |
|
| 2801 | - if (! $this instanceof UsesMoneyInterface) { |
|
| 2802 | - throw new DomainException( |
|
| 2803 | - sprintf( |
|
| 2804 | - esc_html__( |
|
| 2805 | - '%1$s does not use an %2$s object for representing money values, therefore the %3$s method can not be called.', |
|
| 2806 | - 'event_espresso' |
|
| 2807 | - ), |
|
| 2808 | - $this->name(), |
|
| 2809 | - 'EventEspresso\core\domain\values\currency\Money', |
|
| 2810 | - "{$function}()" |
|
| 2811 | - ) |
|
| 2812 | - ); |
|
| 2813 | - } |
|
| 2814 | - } |
|
| 2815 | - |
|
| 2816 | - |
|
| 2817 | - |
|
| 2818 | - /** |
|
| 2819 | - * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2820 | - * (probably a bad assumption they have made, oh well) |
|
| 2821 | - * |
|
| 2822 | - * @return string |
|
| 2823 | - */ |
|
| 2824 | - public function __toString() |
|
| 2825 | - { |
|
| 2826 | - try { |
|
| 2827 | - return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2828 | - } catch (Exception $e) { |
|
| 2829 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2830 | - return ''; |
|
| 2831 | - } |
|
| 2832 | - } |
|
| 2833 | - |
|
| 2834 | - |
|
| 2835 | - |
|
| 2836 | - /** |
|
| 2837 | - * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2838 | - * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2839 | - * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2840 | - * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2841 | - * Instead, those related model objects should be directly serialized and stored. |
|
| 2842 | - * Eg, the following won't work: |
|
| 2843 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2844 | - * $att = $reg->attendee(); |
|
| 2845 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2846 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2847 | - * //END REQUEST |
|
| 2848 | - * //START NEXT REQUEST |
|
| 2849 | - * $reg = get_option( 'my_option' ); |
|
| 2850 | - * $reg->attendee()->save(); |
|
| 2851 | - * And would need to be replace with: |
|
| 2852 | - * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2853 | - * $att = $reg->attendee(); |
|
| 2854 | - * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2855 | - * update_option( 'my_option', serialize( $reg ) ); |
|
| 2856 | - * //END REQUEST |
|
| 2857 | - * //START NEXT REQUEST |
|
| 2858 | - * $att = get_option( 'my_option' ); |
|
| 2859 | - * $att->save(); |
|
| 2860 | - * |
|
| 2861 | - * @return array |
|
| 2862 | - * @throws EE_Error |
|
| 2863 | - */ |
|
| 2864 | - public function __sleep() |
|
| 2865 | - { |
|
| 2866 | - $model = $this->get_model(); |
|
| 2867 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 2868 | - if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2869 | - $classname = 'EE_' . $model->get_this_model_name(); |
|
| 2870 | - if ( |
|
| 2871 | - $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2872 | - && $this->get_one_from_cache($relation_name)->ID() |
|
| 2873 | - ) { |
|
| 2874 | - $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2875 | - } |
|
| 2876 | - } |
|
| 2877 | - } |
|
| 2878 | - $this->_props_n_values_provided_in_constructor = array(); |
|
| 2879 | - $properties_to_serialize = get_object_vars($this); |
|
| 2880 | - //don't serialize the model. It's big and that risks recursion |
|
| 2881 | - unset($properties_to_serialize['_model']); |
|
| 2882 | - return array_keys($properties_to_serialize); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - |
|
| 2886 | - |
|
| 2887 | - /** |
|
| 2888 | - * restore _props_n_values_provided_in_constructor |
|
| 2889 | - * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2890 | - * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2891 | - * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2892 | - */ |
|
| 2893 | - public function __wakeup() |
|
| 2894 | - { |
|
| 2895 | - $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2896 | - } |
|
| 29 | + /** |
|
| 30 | + * This is an array of the original properties and values provided during construction |
|
| 31 | + * of this model object. (keys are model field names, values are their values). |
|
| 32 | + * This list is important to remember so that when we are merging data from the db, we know |
|
| 33 | + * which values to override and which to not override. |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected $_props_n_values_provided_in_constructor; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Timezone |
|
| 41 | + * This gets set by the "set_timezone()" method so that we know what timezone incoming strings|timestamps are in. |
|
| 42 | + * This can also be used before a get to set what timezone you want strings coming out of the object to be in. NOT |
|
| 43 | + * all EE_Base_Class child classes use this property but any that use a EE_Datetime_Field data type will have |
|
| 44 | + * access to it. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $_timezone; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * date format |
|
| 54 | + * pattern or format for displaying dates |
|
| 55 | + * |
|
| 56 | + * @var string $_dt_frmt |
|
| 57 | + */ |
|
| 58 | + protected $_dt_frmt; |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * time format |
|
| 64 | + * pattern or format for displaying time |
|
| 65 | + * |
|
| 66 | + * @var string $_tm_frmt |
|
| 67 | + */ |
|
| 68 | + protected $_tm_frmt; |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * This property is for holding a cached array of object properties indexed by property name as the key. |
|
| 74 | + * The purpose of this is for setting a cache on properties that may have calculated values after a |
|
| 75 | + * prepare_for_get. That way the cache can be checked first and the calculated property returned instead of having |
|
| 76 | + * to recalculate. Used by _set_cached_property() and _get_cached_property() methods. |
|
| 77 | + * |
|
| 78 | + * @var array |
|
| 79 | + */ |
|
| 80 | + protected $_cached_properties = array(); |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * An array containing keys of the related model, and values are either an array of related mode objects or a |
|
| 84 | + * single |
|
| 85 | + * related model object. see the model's _model_relations. The keys should match those specified. And if the |
|
| 86 | + * relation is of type EE_Belongs_To (or one of its children), then there should only be ONE related model object, |
|
| 87 | + * all others have an array) |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + protected $_model_relations = array(); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Array where keys are field names (see the model's _fields property) and values are their values. To see what |
|
| 95 | + * their types should be, look at what that field object returns on its prepare_for_get and prepare_for_set methods) |
|
| 96 | + * |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + protected $_fields = array(); |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var boolean indicating whether or not this model object is intended to ever be saved |
|
| 103 | + * For example, we might create model objects intended to only be used for the duration |
|
| 104 | + * of this request and to be thrown away, and if they were accidentally saved |
|
| 105 | + * it would be a bug. |
|
| 106 | + */ |
|
| 107 | + protected $_allow_persist = true; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var boolean indicating whether or not this model object's properties have changed since construction |
|
| 111 | + */ |
|
| 112 | + protected $_has_changes = false; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @var EEM_Base |
|
| 116 | + */ |
|
| 117 | + protected $_model; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @var MoneyFactory |
|
| 121 | + */ |
|
| 122 | + protected $money_factory; |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * basic constructor for Event Espresso classes, performs any necessary initialization, and verifies it's children |
|
| 127 | + * play nice |
|
| 128 | + * |
|
| 129 | + * @param array $fieldValues where each key is a field (ie, array key in the 2nd |
|
| 130 | + * layer of the model's _fields array, (eg, EVT_ID, |
|
| 131 | + * TXN_amount, QST_name, etc) and values are their values |
|
| 132 | + * @param boolean $bydb a flag for setting if the class is instantiated by the |
|
| 133 | + * corresponding db model or not. |
|
| 134 | + * @param string $timezone indicate what timezone you want any datetime fields to |
|
| 135 | + * be in when instantiating a EE_Base_Class object. |
|
| 136 | + * @param array $date_formats An array of date formats to set on construct where first |
|
| 137 | + * value is the date_format and second value is the time |
|
| 138 | + * format. |
|
| 139 | + * @throws InvalidArgumentException |
|
| 140 | + * @throws InvalidInterfaceException |
|
| 141 | + * @throws InvalidDataTypeException |
|
| 142 | + * @throws EE_Error |
|
| 143 | + */ |
|
| 144 | + protected function __construct( |
|
| 145 | + $fieldValues = array(), |
|
| 146 | + $bydb = false, |
|
| 147 | + $timezone = '', |
|
| 148 | + $date_formats = array() |
|
| 149 | + ) { |
|
| 150 | + $className = get_class($this); |
|
| 151 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
| 152 | + $model = $this->get_model(); |
|
| 153 | + $model_fields = $model->field_settings(false); |
|
| 154 | + // ensure $fieldValues is an array |
|
| 155 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
| 156 | + // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 157 | + // verify client code has not passed any invalid field names |
|
| 158 | + foreach ($fieldValues as $field_name => $field_value) { |
|
| 159 | + if ( ! isset($model_fields[$field_name])) { |
|
| 160 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", |
|
| 161 | + "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 165 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 166 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 167 | + list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
|
| 168 | + } else { |
|
| 169 | + //set default formats for date and time |
|
| 170 | + $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 171 | + $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 172 | + } |
|
| 173 | + //if db model is instantiating |
|
| 174 | + if ($bydb) { |
|
| 175 | + //client code has indicated these field values are from the database |
|
| 176 | + foreach ($model_fields as $fieldName => $field) { |
|
| 177 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
| 178 | + } |
|
| 179 | + } else { |
|
| 180 | + //we're constructing a brand |
|
| 181 | + //new instance of the model object. Generally, this means we'll need to do more field validation |
|
| 182 | + foreach ($model_fields as $fieldName => $field) { |
|
| 183 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + //remember what values were passed to this constructor |
|
| 187 | + $this->_props_n_values_provided_in_constructor = $fieldValues; |
|
| 188 | + //remember in entity mapper |
|
| 189 | + if ( ! $bydb && $model->has_primary_key_field() && $this->ID()) { |
|
| 190 | + $model->add_to_entity_map($this); |
|
| 191 | + } |
|
| 192 | + //setup all the relations |
|
| 193 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 194 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 195 | + $this->_model_relations[$relation_name] = null; |
|
| 196 | + } else { |
|
| 197 | + $this->_model_relations[$relation_name] = array(); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + /** |
|
| 201 | + * Action done at the end of each model object construction |
|
| 202 | + * |
|
| 203 | + * @param EE_Base_Class $this the model object just created |
|
| 204 | + */ |
|
| 205 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Gets whether or not this model object is allowed to persist/be saved to the database. |
|
| 212 | + * |
|
| 213 | + * @return boolean |
|
| 214 | + */ |
|
| 215 | + public function allow_persist() |
|
| 216 | + { |
|
| 217 | + return $this->_allow_persist; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Sets whether or not this model object should be allowed to be saved to the DB. |
|
| 224 | + * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
| 225 | + * you got new information that somehow made you change your mind. |
|
| 226 | + * |
|
| 227 | + * @param boolean $allow_persist |
|
| 228 | + * @return boolean |
|
| 229 | + */ |
|
| 230 | + public function set_allow_persist($allow_persist) |
|
| 231 | + { |
|
| 232 | + return $this->_allow_persist = $allow_persist; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Gets the field's original value when this object was constructed during this request. |
|
| 239 | + * This can be helpful when determining if a model object has changed or not |
|
| 240 | + * |
|
| 241 | + * @param string $field_name |
|
| 242 | + * @return mixed|null |
|
| 243 | + * @throws EE_Error |
|
| 244 | + */ |
|
| 245 | + public function get_original($field_name) |
|
| 246 | + { |
|
| 247 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) |
|
| 248 | + && $field_settings = $this->get_model()->field_settings_for($field_name) |
|
| 249 | + ) { |
|
| 250 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
| 251 | + } else { |
|
| 252 | + return null; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * @param EE_Base_Class $obj |
|
| 260 | + * @return string |
|
| 261 | + */ |
|
| 262 | + public function get_class($obj) |
|
| 263 | + { |
|
| 264 | + return get_class($obj); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Overrides parent because parent expects old models. |
|
| 270 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 271 | + * |
|
| 272 | + * @param string $field_name |
|
| 273 | + * @param mixed $field_value |
|
| 274 | + * @param bool $use_default |
|
| 275 | + * @throws InvalidArgumentException |
|
| 276 | + * @throws InvalidInterfaceException |
|
| 277 | + * @throws InvalidDataTypeException |
|
| 278 | + * @throws EE_Error |
|
| 279 | + */ |
|
| 280 | + public function set($field_name, $field_value, $use_default = false) |
|
| 281 | + { |
|
| 282 | + // if not using default and nothing has changed, and object has already been setup (has ID), |
|
| 283 | + // then don't do anything |
|
| 284 | + if ( |
|
| 285 | + ! $use_default |
|
| 286 | + && $this->_fields[$field_name] === $field_value |
|
| 287 | + && $this->ID() |
|
| 288 | + ) { |
|
| 289 | + return; |
|
| 290 | + } |
|
| 291 | + $model = $this->get_model(); |
|
| 292 | + $this->_has_changes = true; |
|
| 293 | + $field_obj = $model->field_settings_for($field_name); |
|
| 294 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 295 | + // if ( method_exists( $field_obj, 'set_timezone' )) { |
|
| 296 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 297 | + $field_obj->set_timezone($this->_timezone); |
|
| 298 | + $field_obj->set_date_format($this->_dt_frmt); |
|
| 299 | + $field_obj->set_time_format($this->_tm_frmt); |
|
| 300 | + } |
|
| 301 | + $holder_of_value = $field_obj->prepare_for_set($field_value); |
|
| 302 | + //should the value be null? |
|
| 303 | + if (($field_value === null || $holder_of_value === null || $holder_of_value === '') && $use_default) { |
|
| 304 | + $this->_fields[$field_name] = $field_obj->get_default_value(); |
|
| 305 | + /** |
|
| 306 | + * To save having to refactor all the models, if a default value is used for a |
|
| 307 | + * EE_Datetime_Field, and that value is not null nor is it a DateTime |
|
| 308 | + * object. Then let's do a set again to ensure that it becomes a DateTime |
|
| 309 | + * object. |
|
| 310 | + * |
|
| 311 | + * @since 4.6.10+ |
|
| 312 | + */ |
|
| 313 | + if ( |
|
| 314 | + $field_obj instanceof EE_Datetime_Field |
|
| 315 | + && $this->_fields[$field_name] !== null |
|
| 316 | + && ! $this->_fields[$field_name] instanceof DateTime |
|
| 317 | + ) { |
|
| 318 | + empty($this->_fields[$field_name]) |
|
| 319 | + ? $this->set($field_name, time()) |
|
| 320 | + : $this->set($field_name, $this->_fields[$field_name]); |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + $this->_fields[$field_name] = $holder_of_value; |
|
| 324 | + } |
|
| 325 | + //if we're not in the constructor... |
|
| 326 | + //now check if what we set was a primary key |
|
| 327 | + if ( |
|
| 328 | + //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
| 329 | + $this->_props_n_values_provided_in_constructor |
|
| 330 | + && $field_value |
|
| 331 | + && $field_name === $model->primary_key_name() |
|
| 332 | + ) { |
|
| 333 | + //if so, we want all this object's fields to be filled either with |
|
| 334 | + //what we've explicitly set on this model |
|
| 335 | + //or what we have in the db |
|
| 336 | + // echo "setting primary key!"; |
|
| 337 | + $fields_on_model = self::_get_model(get_class($this))->field_settings(); |
|
| 338 | + $obj_in_db = self::_get_model(get_class($this))->get_one_by_ID($field_value); |
|
| 339 | + foreach ($fields_on_model as $field_obj) { |
|
| 340 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
| 341 | + && $field_obj->get_name() !== $field_name |
|
| 342 | + ) { |
|
| 343 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + //oh this model object has an ID? well make sure its in the entity mapper |
|
| 347 | + $model->add_to_entity_map($this); |
|
| 348 | + } |
|
| 349 | + //let's unset any cache for this field_name from the $_cached_properties property. |
|
| 350 | + $this->_clear_cached_property($field_name); |
|
| 351 | + } else { |
|
| 352 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", |
|
| 353 | + "event_espresso"), $field_name)); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * This sets the field value on the db column if it exists for the given $column_name or |
|
| 361 | + * saves it to EE_Extra_Meta if the given $column_name does not match a db column. |
|
| 362 | + * |
|
| 363 | + * @see EE_message::get_column_value for related documentation on the necessity of this method. |
|
| 364 | + * @param string $field_name Must be the exact column name. |
|
| 365 | + * @param mixed $field_value The value to set. |
|
| 366 | + * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
|
| 367 | + * @throws EE_Error |
|
| 368 | + */ |
|
| 369 | + public function set_field_or_extra_meta($field_name, $field_value) |
|
| 370 | + { |
|
| 371 | + if ($this->get_model()->has_field($field_name)) { |
|
| 372 | + $this->set($field_name, $field_value); |
|
| 373 | + return true; |
|
| 374 | + } else { |
|
| 375 | + //ensure this object is saved first so that extra meta can be properly related. |
|
| 376 | + $this->save(); |
|
| 377 | + return $this->update_extra_meta($field_name, $field_value); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * This retrieves the value of the db column set on this class or if that's not present |
|
| 385 | + * it will attempt to retrieve from extra_meta if found. |
|
| 386 | + * Example Usage: |
|
| 387 | + * Via EE_Message child class: |
|
| 388 | + * Due to the dynamic nature of the EE_messages system, EE_messengers will always have a "to", |
|
| 389 | + * "from", "subject", and "content" field (as represented in the EE_Message schema), however they may |
|
| 390 | + * also have additional main fields specific to the messenger. The system accommodates those extra |
|
| 391 | + * fields through the EE_Extra_Meta table. This method allows for EE_messengers to retrieve the |
|
| 392 | + * value for those extra fields dynamically via the EE_message object. |
|
| 393 | + * |
|
| 394 | + * @param string $field_name expecting the fully qualified field name. |
|
| 395 | + * @return mixed|null value for the field if found. null if not found. |
|
| 396 | + * @throws EE_Error |
|
| 397 | + */ |
|
| 398 | + public function get_field_or_extra_meta($field_name) |
|
| 399 | + { |
|
| 400 | + if ($this->get_model()->has_field($field_name)) { |
|
| 401 | + $column_value = $this->get($field_name); |
|
| 402 | + } else { |
|
| 403 | + //This isn't a column in the main table, let's see if it is in the extra meta. |
|
| 404 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
| 405 | + } |
|
| 406 | + return $column_value; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 412 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 413 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). This is |
|
| 414 | + * available to all child classes that may be using the EE_Datetime_Field for a field data type. |
|
| 415 | + * |
|
| 416 | + * @access public |
|
| 417 | + * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
|
| 418 | + * @return void |
|
| 419 | + * @throws InvalidArgumentException |
|
| 420 | + * @throws InvalidInterfaceException |
|
| 421 | + * @throws InvalidDataTypeException |
|
| 422 | + * @throws EE_Error |
|
| 423 | + */ |
|
| 424 | + public function set_timezone($timezone = '') |
|
| 425 | + { |
|
| 426 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
| 427 | + //make sure we clear all cached properties because they won't be relevant now |
|
| 428 | + $this->_clear_cached_properties(); |
|
| 429 | + //make sure we update field settings and the date for all EE_Datetime_Fields |
|
| 430 | + $model_fields = $this->get_model()->field_settings(false); |
|
| 431 | + foreach ($model_fields as $field_name => $field_obj) { |
|
| 432 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 433 | + $field_obj->set_timezone($this->_timezone); |
|
| 434 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
| 435 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * This just returns whatever is set for the current timezone. |
|
| 445 | + * |
|
| 446 | + * @access public |
|
| 447 | + * @return string timezone string |
|
| 448 | + */ |
|
| 449 | + public function get_timezone() |
|
| 450 | + { |
|
| 451 | + return $this->_timezone; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * This sets the internal date format to what is sent in to be used as the new default for the class |
|
| 458 | + * internally instead of wp set date format options |
|
| 459 | + * |
|
| 460 | + * @since 4.6 |
|
| 461 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 462 | + */ |
|
| 463 | + public function set_date_format($format) |
|
| 464 | + { |
|
| 465 | + $this->_dt_frmt = $format; |
|
| 466 | + //clear cached_properties because they won't be relevant now. |
|
| 467 | + $this->_clear_cached_properties(); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * This sets the internal time format string to what is sent in to be used as the new default for the |
|
| 474 | + * class internally instead of wp set time format options. |
|
| 475 | + * |
|
| 476 | + * @since 4.6 |
|
| 477 | + * @param string $format should be a format recognizable by PHP date() functions. |
|
| 478 | + */ |
|
| 479 | + public function set_time_format($format) |
|
| 480 | + { |
|
| 481 | + $this->_tm_frmt = $format; |
|
| 482 | + //clear cached_properties because they won't be relevant now. |
|
| 483 | + $this->_clear_cached_properties(); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * This returns the current internal set format for the date and time formats. |
|
| 490 | + * |
|
| 491 | + * @param bool $full if true (default), then return the full format. Otherwise will return an array |
|
| 492 | + * where the first value is the date format and the second value is the time format. |
|
| 493 | + * @return mixed string|array |
|
| 494 | + */ |
|
| 495 | + public function get_format($full = true) |
|
| 496 | + { |
|
| 497 | + return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * cache |
|
| 504 | + * stores the passed model object on the current model object. |
|
| 505 | + * In certain circumstances, we can use this cached model object instead of querying for another one entirely. |
|
| 506 | + * |
|
| 507 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg |
|
| 508 | + * 'Registration' associated with this model object |
|
| 509 | + * @param EE_Base_Class $object_to_cache that has a relation to this model object. (Eg, if this is a Transaction, |
|
| 510 | + * that could be a payment or a registration) |
|
| 511 | + * @param null $cache_id a string or number that will be used as the key for any Belongs_To_Many |
|
| 512 | + * items which will be stored in an array on this object |
|
| 513 | + * @throws EE_Error |
|
| 514 | + * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one |
|
| 515 | + * related thing, no array) |
|
| 516 | + */ |
|
| 517 | + public function cache($relationName = '', $object_to_cache = null, $cache_id = null) |
|
| 518 | + { |
|
| 519 | + // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
|
| 520 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
| 521 | + return false; |
|
| 522 | + } |
|
| 523 | + // also get "how" the object is related, or throw an error |
|
| 524 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
| 525 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), |
|
| 526 | + $relationName, get_class($this))); |
|
| 527 | + } |
|
| 528 | + // how many things are related ? |
|
| 529 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 530 | + // 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 |
|
| 531 | + // so for these model objects just set it to be cached |
|
| 532 | + $this->_model_relations[$relationName] = $object_to_cache; |
|
| 533 | + $return = true; |
|
| 534 | + } else { |
|
| 535 | + // 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. |
|
| 536 | + // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
|
| 537 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
| 538 | + // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
|
| 539 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class |
|
| 540 | + ? array($this->_model_relations[$relationName]) : array(); |
|
| 541 | + } |
|
| 542 | + // first check for a cache_id which is normally empty |
|
| 543 | + if ( ! empty($cache_id)) { |
|
| 544 | + // 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 |
|
| 545 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
| 546 | + $return = $cache_id; |
|
| 547 | + } elseif ($object_to_cache->ID()) { |
|
| 548 | + // OR the cached object originally came from the db, so let's just use it's PK for an ID |
|
| 549 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
| 550 | + $return = $object_to_cache->ID(); |
|
| 551 | + } else { |
|
| 552 | + // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
|
| 553 | + $this->_model_relations[$relationName][] = $object_to_cache; |
|
| 554 | + // move the internal pointer to the end of the array |
|
| 555 | + end($this->_model_relations[$relationName]); |
|
| 556 | + // and grab the key so that we can return it |
|
| 557 | + $return = key($this->_model_relations[$relationName]); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + return $return; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * For adding an item to the cached_properties property. |
|
| 567 | + * |
|
| 568 | + * @access protected |
|
| 569 | + * @param string $fieldname the property item the corresponding value is for. |
|
| 570 | + * @param mixed $value The value we are caching. |
|
| 571 | + * @param string|null $cache_type |
|
| 572 | + * @return void |
|
| 573 | + * @throws EE_Error |
|
| 574 | + */ |
|
| 575 | + protected function _set_cached_property($fieldname, $value, $cache_type = null) |
|
| 576 | + { |
|
| 577 | + //first make sure this property exists |
|
| 578 | + $this->get_model()->field_settings_for($fieldname); |
|
| 579 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
| 580 | + $this->_cached_properties[$fieldname][$cache_type] = $value; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * This returns the value cached property if it exists OR the actual property value if the cache doesn't exist. |
|
| 587 | + * This also SETS the cache if we return the actual property! |
|
| 588 | + * |
|
| 589 | + * @param string $fieldname the name of the property we're trying to retrieve |
|
| 590 | + * @param bool $pretty |
|
| 591 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 592 | + * (in cases where the same property may be used for different outputs |
|
| 593 | + * - i.e. datetime, money etc.) |
|
| 594 | + * It can also accept certain pre-defined "schema" strings |
|
| 595 | + * to define how to output the property. |
|
| 596 | + * see the field's prepare_for_pretty_echoing for what strings can be used |
|
| 597 | + * @return mixed whatever the value for the property is we're retrieving |
|
| 598 | + * @throws EE_Error |
|
| 599 | + */ |
|
| 600 | + protected function _get_cached_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 601 | + { |
|
| 602 | + //verify the field exists |
|
| 603 | + $model = $this->get_model(); |
|
| 604 | + $model->field_settings_for($fieldname); |
|
| 605 | + $cache_type = $pretty ? 'pretty' : 'standard'; |
|
| 606 | + $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 607 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
| 608 | + return $this->_cached_properties[$fieldname][$cache_type]; |
|
| 609 | + } |
|
| 610 | + $value = $this->_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
| 611 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
| 612 | + return $value; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * If the cache didn't fetch the needed item, this fetches it. |
|
| 618 | + * @param string $fieldname |
|
| 619 | + * @param bool $pretty |
|
| 620 | + * @param string $extra_cache_ref |
|
| 621 | + * @return mixed |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
| 625 | + { |
|
| 626 | + $field_obj = $this->get_model()->field_settings_for($fieldname); |
|
| 627 | + // If this is an EE_Datetime_Field we need to make sure timezone, formats, and output are correct |
|
| 628 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
| 629 | + $this->_prepare_datetime_field($field_obj, $pretty, $extra_cache_ref); |
|
| 630 | + } |
|
| 631 | + if ( ! isset($this->_fields[$fieldname])) { |
|
| 632 | + $this->_fields[$fieldname] = null; |
|
| 633 | + } |
|
| 634 | + $value = $pretty |
|
| 635 | + ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) |
|
| 636 | + : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
| 637 | + return $value; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * set timezone, formats, and output for EE_Datetime_Field objects |
|
| 643 | + * |
|
| 644 | + * @param \EE_Datetime_Field $datetime_field |
|
| 645 | + * @param bool $pretty |
|
| 646 | + * @param null $date_or_time |
|
| 647 | + * @return void |
|
| 648 | + * @throws InvalidArgumentException |
|
| 649 | + * @throws InvalidInterfaceException |
|
| 650 | + * @throws InvalidDataTypeException |
|
| 651 | + * @throws EE_Error |
|
| 652 | + */ |
|
| 653 | + protected function _prepare_datetime_field( |
|
| 654 | + EE_Datetime_Field $datetime_field, |
|
| 655 | + $pretty = false, |
|
| 656 | + $date_or_time = null |
|
| 657 | + ) { |
|
| 658 | + $datetime_field->set_timezone($this->_timezone); |
|
| 659 | + $datetime_field->set_date_format($this->_dt_frmt, $pretty); |
|
| 660 | + $datetime_field->set_time_format($this->_tm_frmt, $pretty); |
|
| 661 | + //set the output returned |
|
| 662 | + switch ($date_or_time) { |
|
| 663 | + case 'D' : |
|
| 664 | + $datetime_field->set_date_time_output('date'); |
|
| 665 | + break; |
|
| 666 | + case 'T' : |
|
| 667 | + $datetime_field->set_date_time_output('time'); |
|
| 668 | + break; |
|
| 669 | + default : |
|
| 670 | + $datetime_field->set_date_time_output(); |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * This just takes care of clearing out the cached_properties |
|
| 678 | + * |
|
| 679 | + * @return void |
|
| 680 | + */ |
|
| 681 | + protected function _clear_cached_properties() |
|
| 682 | + { |
|
| 683 | + $this->_cached_properties = array(); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * This just clears out ONE property if it exists in the cache |
|
| 690 | + * |
|
| 691 | + * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
|
| 692 | + * @return void |
|
| 693 | + */ |
|
| 694 | + protected function _clear_cached_property($property_name) |
|
| 695 | + { |
|
| 696 | + if (isset($this->_cached_properties[$property_name])) { |
|
| 697 | + unset($this->_cached_properties[$property_name]); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * Ensures that this related thing is a model object. |
|
| 705 | + * |
|
| 706 | + * @param mixed $object_or_id EE_base_Class/int/string either a related model object, or its ID |
|
| 707 | + * @param string $model_name name of the related thing, eg 'Attendee', |
|
| 708 | + * @return EE_Base_Class |
|
| 709 | + * @throws EE_Error |
|
| 710 | + */ |
|
| 711 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) |
|
| 712 | + { |
|
| 713 | + $other_model_instance = self::_get_model_instance_with_name( |
|
| 714 | + self::_get_model_classname($model_name), |
|
| 715 | + $this->_timezone |
|
| 716 | + ); |
|
| 717 | + return $other_model_instance->ensure_is_obj($object_or_id); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Forgets the cached model of the given relation Name. So the next time we request it, |
|
| 724 | + * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
| 725 | + * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
| 726 | + * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
| 727 | + * |
|
| 728 | + * @param string $relationName one of the keys in the _model_relations array on the model. |
|
| 729 | + * Eg 'Registration' |
|
| 730 | + * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
| 731 | + * if you intend to use $clear_all = TRUE, or the relation only |
|
| 732 | + * has 1 object anyways (ie, it's a BelongsToRelation) |
|
| 733 | + * @param bool $clear_all This flags clearing the entire cache relation property if |
|
| 734 | + * this is HasMany or HABTM. |
|
| 735 | + * @throws EE_Error |
|
| 736 | + * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a |
|
| 737 | + * relation from all |
|
| 738 | + */ |
|
| 739 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false) |
|
| 740 | + { |
|
| 741 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 742 | + $index_in_cache = ''; |
|
| 743 | + if ( ! $relationship_to_model) { |
|
| 744 | + throw new EE_Error( |
|
| 745 | + sprintf( |
|
| 746 | + __("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), |
|
| 747 | + $relationName, |
|
| 748 | + get_class($this) |
|
| 749 | + ) |
|
| 750 | + ); |
|
| 751 | + } |
|
| 752 | + if ($clear_all) { |
|
| 753 | + $obj_removed = true; |
|
| 754 | + $this->_model_relations[$relationName] = null; |
|
| 755 | + } elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 756 | + $obj_removed = $this->_model_relations[$relationName]; |
|
| 757 | + $this->_model_relations[$relationName] = null; |
|
| 758 | + } else { |
|
| 759 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class |
|
| 760 | + && $object_to_remove_or_index_into_array->ID() |
|
| 761 | + ) { |
|
| 762 | + $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
|
| 763 | + if (is_array($this->_model_relations[$relationName]) |
|
| 764 | + && ! isset($this->_model_relations[$relationName][$index_in_cache]) |
|
| 765 | + ) { |
|
| 766 | + $index_found_at = null; |
|
| 767 | + //find this object in the array even though it has a different key |
|
| 768 | + foreach ($this->_model_relations[$relationName] as $index => $obj) { |
|
| 769 | + if ( |
|
| 770 | + $obj instanceof EE_Base_Class |
|
| 771 | + && ( |
|
| 772 | + $obj == $object_to_remove_or_index_into_array |
|
| 773 | + || $obj->ID() === $object_to_remove_or_index_into_array->ID() |
|
| 774 | + ) |
|
| 775 | + ) { |
|
| 776 | + $index_found_at = $index; |
|
| 777 | + break; |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + if ($index_found_at) { |
|
| 781 | + $index_in_cache = $index_found_at; |
|
| 782 | + } else { |
|
| 783 | + //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
|
| 784 | + //if it wasn't in it to begin with. So we're done |
|
| 785 | + return $object_to_remove_or_index_into_array; |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + } elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
| 789 | + //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
|
| 790 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
| 791 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
| 792 | + $index_in_cache = $index; |
|
| 793 | + } |
|
| 794 | + } |
|
| 795 | + } else { |
|
| 796 | + $index_in_cache = $object_to_remove_or_index_into_array; |
|
| 797 | + } |
|
| 798 | + //supposedly we've found it. But it could just be that the client code |
|
| 799 | + //provided a bad index/object |
|
| 800 | + if ( |
|
| 801 | + isset( |
|
| 802 | + $this->_model_relations[$relationName], |
|
| 803 | + $this->_model_relations[$relationName][$index_in_cache] |
|
| 804 | + ) |
|
| 805 | + ) { |
|
| 806 | + $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
|
| 807 | + unset($this->_model_relations[$relationName][$index_in_cache]); |
|
| 808 | + } else { |
|
| 809 | + //that thing was never cached anyways. |
|
| 810 | + $obj_removed = null; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + return $obj_removed; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + |
|
| 817 | + |
|
| 818 | + /** |
|
| 819 | + * update_cache_after_object_save |
|
| 820 | + * Allows a cached item to have it's cache ID (within the array of cached items) reset using the new ID it has |
|
| 821 | + * obtained after being saved to the db |
|
| 822 | + * |
|
| 823 | + * @param string $relationName - the type of object that is cached |
|
| 824 | + * @param EE_Base_Class $newly_saved_object - the newly saved object to be re-cached |
|
| 825 | + * @param string $current_cache_id - the ID that was used when originally caching the object |
|
| 826 | + * @return boolean TRUE on success, FALSE on fail |
|
| 827 | + * @throws EE_Error |
|
| 828 | + */ |
|
| 829 | + public function update_cache_after_object_save( |
|
| 830 | + $relationName, |
|
| 831 | + EE_Base_Class $newly_saved_object, |
|
| 832 | + $current_cache_id = '' |
|
| 833 | + ) { |
|
| 834 | + // verify that incoming object is of the correct type |
|
| 835 | + $obj_class = 'EE_' . $relationName; |
|
| 836 | + if ($newly_saved_object instanceof $obj_class) { |
|
| 837 | + /* @type EE_Base_Class $newly_saved_object */ |
|
| 838 | + // now get the type of relation |
|
| 839 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
| 840 | + // if this is a 1:1 relationship |
|
| 841 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
| 842 | + // then just replace the cached object with the newly saved object |
|
| 843 | + $this->_model_relations[$relationName] = $newly_saved_object; |
|
| 844 | + return true; |
|
| 845 | + // or if it's some kind of sordid feral polyamorous relationship... |
|
| 846 | + } elseif (is_array($this->_model_relations[$relationName]) |
|
| 847 | + && isset($this->_model_relations[$relationName][$current_cache_id]) |
|
| 848 | + ) { |
|
| 849 | + // then remove the current cached item |
|
| 850 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
| 851 | + // and cache the newly saved object using it's new ID |
|
| 852 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
| 853 | + return true; |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + return false; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + |
|
| 861 | + /** |
|
| 862 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 863 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 864 | + * |
|
| 865 | + * @param string $relationName |
|
| 866 | + * @return EE_Base_Class |
|
| 867 | + */ |
|
| 868 | + public function get_one_from_cache($relationName) |
|
| 869 | + { |
|
| 870 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] |
|
| 871 | + : null; |
|
| 872 | + if (is_array($cached_array_or_object)) { |
|
| 873 | + return array_shift($cached_array_or_object); |
|
| 874 | + } else { |
|
| 875 | + return $cached_array_or_object; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Fetches a single EE_Base_Class on that relation. (If the relation is of type |
|
| 882 | + * BelongsTo, it will only ever have 1 object. However, other relations could have an array of objects) |
|
| 883 | + * |
|
| 884 | + * @param string $relationName |
|
| 885 | + * @throws \ReflectionException |
|
| 886 | + * @throws InvalidArgumentException |
|
| 887 | + * @throws InvalidInterfaceException |
|
| 888 | + * @throws InvalidDataTypeException |
|
| 889 | + * @throws EE_Error |
|
| 890 | + * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
|
| 891 | + */ |
|
| 892 | + public function get_all_from_cache($relationName) |
|
| 893 | + { |
|
| 894 | + $objects = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
| 895 | + // if the result is not an array, but exists, make it an array |
|
| 896 | + $objects = is_array($objects) ? $objects : array($objects); |
|
| 897 | + //bugfix for https://events.codebasehq.com/projects/event-espresso/tickets/7143 |
|
| 898 | + //basically, if this model object was stored in the session, and these cached model objects |
|
| 899 | + //already have IDs, let's make sure they're in their model's entity mapper |
|
| 900 | + //otherwise we will have duplicates next time we call |
|
| 901 | + // EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
|
| 902 | + $model = EE_Registry::instance()->load_model($relationName); |
|
| 903 | + foreach ($objects as $model_object) { |
|
| 904 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
| 905 | + //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
|
| 906 | + if ($model_object->ID()) { |
|
| 907 | + $model->add_to_entity_map($model_object); |
|
| 908 | + } |
|
| 909 | + } else { |
|
| 910 | + throw new EE_Error( |
|
| 911 | + sprintf( |
|
| 912 | + __( |
|
| 913 | + 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', |
|
| 914 | + 'event_espresso' |
|
| 915 | + ), |
|
| 916 | + $relationName, |
|
| 917 | + gettype($model_object) |
|
| 918 | + ) |
|
| 919 | + ); |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + return $objects; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Returns the next x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 929 | + * matching the given query conditions. |
|
| 930 | + * |
|
| 931 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 932 | + * @param int $limit How many objects to return. |
|
| 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_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) |
|
| 940 | + { |
|
| 941 | + $model = $this->get_model(); |
|
| 942 | + $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 943 | + ? $model->get_primary_key_field()->get_name() |
|
| 944 | + : $field_to_order_by; |
|
| 945 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 946 | + if (empty($field) || empty($current_value)) { |
|
| 947 | + return array(); |
|
| 948 | + } |
|
| 949 | + return $model->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * Returns the previous x number of EE_Base_Class objects in sequence from this object as found in the database |
|
| 956 | + * matching the given query conditions. |
|
| 957 | + * |
|
| 958 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 959 | + * @param int $limit How many objects to return. |
|
| 960 | + * @param array $query_params Any additional conditions on the query. |
|
| 961 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 962 | + * you can indicate just the columns you want returned |
|
| 963 | + * @return array|EE_Base_Class[] |
|
| 964 | + * @throws EE_Error |
|
| 965 | + */ |
|
| 966 | + public function previous_x( |
|
| 967 | + $field_to_order_by = null, |
|
| 968 | + $limit = 1, |
|
| 969 | + $query_params = array(), |
|
| 970 | + $columns_to_select = null |
|
| 971 | + ) { |
|
| 972 | + $model = $this->get_model(); |
|
| 973 | + $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 974 | + ? $model->get_primary_key_field()->get_name() |
|
| 975 | + : $field_to_order_by; |
|
| 976 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 977 | + if (empty($field) || empty($current_value)) { |
|
| 978 | + return array(); |
|
| 979 | + } |
|
| 980 | + return $model->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * Returns the next EE_Base_Class object in sequence from this object as found in the database |
|
| 987 | + * matching the given query conditions. |
|
| 988 | + * |
|
| 989 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 990 | + * @param array $query_params Any additional conditions on the query. |
|
| 991 | + * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
| 992 | + * you can indicate just the columns you want returned |
|
| 993 | + * @return array|EE_Base_Class |
|
| 994 | + * @throws EE_Error |
|
| 995 | + */ |
|
| 996 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 997 | + { |
|
| 998 | + $model = $this->get_model(); |
|
| 999 | + $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 1000 | + ? $model->get_primary_key_field()->get_name() |
|
| 1001 | + : $field_to_order_by; |
|
| 1002 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 1003 | + if (empty($field) || empty($current_value)) { |
|
| 1004 | + return array(); |
|
| 1005 | + } |
|
| 1006 | + return $model->next($current_value, $field, $query_params, $columns_to_select); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * Returns the previous EE_Base_Class object in sequence from this object as found in the database |
|
| 1013 | + * matching the given query conditions. |
|
| 1014 | + * |
|
| 1015 | + * @param null $field_to_order_by What field is being used as the reference point. |
|
| 1016 | + * @param array $query_params Any additional conditions on the query. |
|
| 1017 | + * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
| 1018 | + * you can indicate just the column you want returned |
|
| 1019 | + * @return array|EE_Base_Class |
|
| 1020 | + * @throws EE_Error |
|
| 1021 | + */ |
|
| 1022 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) |
|
| 1023 | + { |
|
| 1024 | + $model = $this->get_model(); |
|
| 1025 | + $field = empty($field_to_order_by) && $model->has_primary_key_field() |
|
| 1026 | + ? $model->get_primary_key_field()->get_name() |
|
| 1027 | + : $field_to_order_by; |
|
| 1028 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
| 1029 | + if (empty($field) || empty($current_value)) { |
|
| 1030 | + return array(); |
|
| 1031 | + } |
|
| 1032 | + return $model->previous($current_value, $field, $query_params, $columns_to_select); |
|
| 1033 | + } |
|
| 1034 | + |
|
| 1035 | + |
|
| 1036 | + |
|
| 1037 | + /** |
|
| 1038 | + * Overrides parent because parent expects old models. |
|
| 1039 | + * This also doesn't do any validation, and won't work for serialized arrays |
|
| 1040 | + * |
|
| 1041 | + * @param string $field_name |
|
| 1042 | + * @param mixed $field_value_from_db |
|
| 1043 | + * @throws EE_Error |
|
| 1044 | + */ |
|
| 1045 | + public function set_from_db($field_name, $field_value_from_db) |
|
| 1046 | + { |
|
| 1047 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
| 1048 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
| 1049 | + //you would think the DB has no NULLs for non-null label fields right? wrong! |
|
| 1050 | + //eg, a CPT model object could have an entry in the posts table, but no |
|
| 1051 | + //entry in the meta table. Meaning that all its columns in the meta table |
|
| 1052 | + //are null! yikes! so when we find one like that, use defaults for its meta columns |
|
| 1053 | + if ($field_value_from_db === null) { |
|
| 1054 | + if ($field_obj->is_nullable()) { |
|
| 1055 | + //if the field allows nulls, then let it be null |
|
| 1056 | + $field_value = null; |
|
| 1057 | + } else { |
|
| 1058 | + $field_value = $field_obj->get_default_value(); |
|
| 1059 | + } |
|
| 1060 | + } else { |
|
| 1061 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
| 1062 | + } |
|
| 1063 | + $this->_fields[$field_name] = $field_value; |
|
| 1064 | + $this->_clear_cached_property($field_name); |
|
| 1065 | + } |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * verifies that the specified field is of the correct type |
|
| 1072 | + * |
|
| 1073 | + * @param string $field_name |
|
| 1074 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1075 | + * (in cases where the same property may be used for different outputs |
|
| 1076 | + * - i.e. datetime, money etc.) |
|
| 1077 | + * @return mixed |
|
| 1078 | + * @throws EE_Error |
|
| 1079 | + */ |
|
| 1080 | + public function get($field_name, $extra_cache_ref = null) |
|
| 1081 | + { |
|
| 1082 | + return $this->_get_cached_property($field_name, false, $extra_cache_ref); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + |
|
| 1086 | + |
|
| 1087 | + /** |
|
| 1088 | + * This method simply returns the RAW unprocessed value for the given property in this class |
|
| 1089 | + * |
|
| 1090 | + * @param string $field_name A valid fieldname |
|
| 1091 | + * @return mixed Whatever the raw value stored on the property is. |
|
| 1092 | + * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
|
| 1093 | + */ |
|
| 1094 | + public function get_raw($field_name) |
|
| 1095 | + { |
|
| 1096 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1097 | + switch(true){ |
|
| 1098 | + case $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime: |
|
| 1099 | + $value = $this->_fields[$field_name]->format('U'); |
|
| 1100 | + break; |
|
| 1101 | + case $field_settings instanceof EE_Money_Field && $this->_fields[$field_name] instanceof Money: |
|
| 1102 | + $value = $this->_fields[$field_name]->floatAmount(); |
|
| 1103 | + break; |
|
| 1104 | + default: |
|
| 1105 | + $value = $this->_fields[$field_name]; |
|
| 1106 | + } |
|
| 1107 | + return $value; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + /** |
|
| 1113 | + * This is used to return the internal DateTime object used for a field that is a |
|
| 1114 | + * EE_Datetime_Field. |
|
| 1115 | + * |
|
| 1116 | + * @param string $field_name The field name retrieving the DateTime object. |
|
| 1117 | + * @return mixed null | false | DateTime If the requested field is NOT a EE_Datetime_Field then |
|
| 1118 | + * @throws EE_Error |
|
| 1119 | + * an error is set and false returned. If the field IS an |
|
| 1120 | + * EE_Datetime_Field and but the field value is null, then |
|
| 1121 | + * just null is returned (because that indicates that likely |
|
| 1122 | + * this field is nullable). |
|
| 1123 | + */ |
|
| 1124 | + public function get_DateTime_object($field_name) |
|
| 1125 | + { |
|
| 1126 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
| 1127 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
| 1128 | + EE_Error::add_error( |
|
| 1129 | + sprintf( |
|
| 1130 | + __( |
|
| 1131 | + 'The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', |
|
| 1132 | + 'event_espresso' |
|
| 1133 | + ), |
|
| 1134 | + $field_name |
|
| 1135 | + ), |
|
| 1136 | + __FILE__, |
|
| 1137 | + __FUNCTION__, |
|
| 1138 | + __LINE__ |
|
| 1139 | + ); |
|
| 1140 | + return false; |
|
| 1141 | + } |
|
| 1142 | + return $this->_fields[$field_name]; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * Gets a Money object for the specified field. Please note that this should only be |
|
| 1148 | + * used for fields corresponding to EE_Money_Fields, and it will always return a money object, |
|
| 1149 | + * or else it will throw an exception. |
|
| 1150 | + * |
|
| 1151 | + * @param $field_name |
|
| 1152 | + * @return Money |
|
| 1153 | + * @throws InvalidEntityException |
|
| 1154 | + * @throws EE_Error |
|
| 1155 | + * @throws DomainException |
|
| 1156 | + */ |
|
| 1157 | + public function getMoneyObject($field_name) |
|
| 1158 | + { |
|
| 1159 | + $this->verifyUsesMoney(__FUNCTION__); |
|
| 1160 | + $field = $this->get_model()->field_settings_for($field_name); |
|
| 1161 | + $value = isset($this->_fields[$field_name]) ? $this->_fields[$field_name] : null; |
|
| 1162 | + if (! $field instanceof EE_Money_Field |
|
| 1163 | + || ! $value instanceof Money) { |
|
| 1164 | + throw new InvalidEntityException( |
|
| 1165 | + get_class($value), |
|
| 1166 | + 'Money', |
|
| 1167 | + sprintf( |
|
| 1168 | + esc_html__( |
|
| 1169 | + // @codingStandardsIgnoreStart |
|
| 1170 | + 'Tried to retrieve money value from %1$s with ID %2$s from field %3$s but no money object present.', |
|
| 1171 | + // @codingStandardsIgnoreEnd |
|
| 1172 | + 'event_espresso' |
|
| 1173 | + ), |
|
| 1174 | + get_class($this), |
|
| 1175 | + $this->ID(), |
|
| 1176 | + $field_name |
|
| 1177 | + ) |
|
| 1178 | + ); |
|
| 1179 | + } |
|
| 1180 | + return $value; |
|
| 1181 | + } |
|
| 1182 | + |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + /** |
|
| 1186 | + * To be used in template to immediately echo out the value, and format it for output. |
|
| 1187 | + * Eg, should call stripslashes and whatnot before echoing |
|
| 1188 | + * |
|
| 1189 | + * @param string $field_name the name of the field as it appears in the DB |
|
| 1190 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1191 | + * (in cases where the same property may be used for different outputs |
|
| 1192 | + * - i.e. datetime, money etc.) |
|
| 1193 | + * @return void |
|
| 1194 | + * @throws EE_Error |
|
| 1195 | + */ |
|
| 1196 | + public function e($field_name, $extra_cache_ref = null) |
|
| 1197 | + { |
|
| 1198 | + echo $this->get_pretty($field_name, $extra_cache_ref); |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + |
|
| 1202 | + |
|
| 1203 | + /** |
|
| 1204 | + * Exactly like e(), echoes out the field, but sets its schema to 'form_input', so that it |
|
| 1205 | + * can be easily used as the value of form input. |
|
| 1206 | + * |
|
| 1207 | + * @param string $field_name |
|
| 1208 | + * @return void |
|
| 1209 | + * @throws EE_Error |
|
| 1210 | + */ |
|
| 1211 | + public function f($field_name) |
|
| 1212 | + { |
|
| 1213 | + $this->e($field_name, 'form_input'); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * Same as `f()` but just returns the value instead of echoing it |
|
| 1218 | + * @param string $field_name |
|
| 1219 | + * @return string |
|
| 1220 | + * @throws EE_Error |
|
| 1221 | + */ |
|
| 1222 | + public function get_f($field_name) |
|
| 1223 | + { |
|
| 1224 | + return (string)$this->get_pretty($field_name,'form_input'); |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Gets a pretty view of the field's value. $extra_cache_ref can specify different formats for this. |
|
| 1231 | + * The $extra_cache_ref will be passed to the model field's prepare_for_pretty_echoing, so consult the field's class |
|
| 1232 | + * to see what options are available. |
|
| 1233 | + * @param string $field_name |
|
| 1234 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
| 1235 | + * (in cases where the same property may be used for different outputs |
|
| 1236 | + * - i.e. datetime, money etc.) |
|
| 1237 | + * @return mixed |
|
| 1238 | + * @throws EE_Error |
|
| 1239 | + */ |
|
| 1240 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
| 1241 | + { |
|
| 1242 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * This simply returns the datetime for the given field name |
|
| 1249 | + * Note: this protected function is called by the wrapper get_date or get_time or get_datetime functions |
|
| 1250 | + * (and the equivalent e_date, e_time, e_datetime). |
|
| 1251 | + * |
|
| 1252 | + * @access protected |
|
| 1253 | + * @param string $field_name Field on the instantiated EE_Base_Class child object |
|
| 1254 | + * @param string $dt_frmt valid datetime format used for date |
|
| 1255 | + * (if '' then we just use the default on the field, |
|
| 1256 | + * if NULL we use the last-used format) |
|
| 1257 | + * @param string $tm_frmt Same as above except this is for time format |
|
| 1258 | + * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
|
| 1259 | + * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
|
| 1260 | + * @return string|bool|EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown |
|
| 1261 | + * if field is not a valid dtt field, or void if echoing |
|
| 1262 | + * @throws EE_Error |
|
| 1263 | + */ |
|
| 1264 | + protected function _get_datetime($field_name, $dt_frmt = '', $tm_frmt = '', $date_or_time = '', $echo = false) |
|
| 1265 | + { |
|
| 1266 | + // clear cached property |
|
| 1267 | + $this->_clear_cached_property($field_name); |
|
| 1268 | + //reset format properties because they are used in get() |
|
| 1269 | + $this->_dt_frmt = $dt_frmt !== '' ? $dt_frmt : $this->_dt_frmt; |
|
| 1270 | + $this->_tm_frmt = $tm_frmt !== '' ? $tm_frmt : $this->_tm_frmt; |
|
| 1271 | + if ($echo) { |
|
| 1272 | + $this->e($field_name, $date_or_time); |
|
| 1273 | + return ''; |
|
| 1274 | + } |
|
| 1275 | + return $this->get($field_name, $date_or_time); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the date |
|
| 1282 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1283 | + * other echoes the pretty value for dtt) |
|
| 1284 | + * |
|
| 1285 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1286 | + * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1287 | + * @return string datetime value formatted |
|
| 1288 | + * @throws EE_Error |
|
| 1289 | + */ |
|
| 1290 | + public function get_date($field_name, $format = '') |
|
| 1291 | + { |
|
| 1292 | + return $this->_get_datetime($field_name, $format, null, 'D'); |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + |
|
| 1296 | + |
|
| 1297 | + /** |
|
| 1298 | + * @param $field_name |
|
| 1299 | + * @param string $format |
|
| 1300 | + * @throws EE_Error |
|
| 1301 | + */ |
|
| 1302 | + public function e_date($field_name, $format = '') |
|
| 1303 | + { |
|
| 1304 | + $this->_get_datetime($field_name, $format, null, 'D', true); |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * below are wrapper functions for the various datetime outputs that can be obtained for JUST returning the time |
|
| 1311 | + * portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1312 | + * other echoes the pretty value for dtt) |
|
| 1313 | + * |
|
| 1314 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1315 | + * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
|
| 1316 | + * @return string datetime value formatted |
|
| 1317 | + * @throws EE_Error |
|
| 1318 | + */ |
|
| 1319 | + public function get_time($field_name, $format = '') |
|
| 1320 | + { |
|
| 1321 | + return $this->_get_datetime($field_name, null, $format, 'T'); |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + |
|
| 1326 | + /** |
|
| 1327 | + * @param $field_name |
|
| 1328 | + * @param string $format |
|
| 1329 | + * @throws EE_Error |
|
| 1330 | + */ |
|
| 1331 | + public function e_time($field_name, $format = '') |
|
| 1332 | + { |
|
| 1333 | + $this->_get_datetime($field_name, null, $format, 'T', true); |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + |
|
| 1337 | + |
|
| 1338 | + /** |
|
| 1339 | + * below are wrapper functions for the various datetime outputs that can be obtained for returning the date AND |
|
| 1340 | + * time portion of a datetime value. (note the only difference between get_ and e_ is one returns the value and the |
|
| 1341 | + * other echoes the pretty value for dtt) |
|
| 1342 | + * |
|
| 1343 | + * @param string $field_name name of model object datetime field holding the value |
|
| 1344 | + * @param string $dt_frmt format for the date returned (if NULL we use default in dt_frmt property) |
|
| 1345 | + * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
|
| 1346 | + * @return string datetime value formatted |
|
| 1347 | + * @throws EE_Error |
|
| 1348 | + */ |
|
| 1349 | + public function get_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1350 | + { |
|
| 1351 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
| 1352 | + } |
|
| 1353 | + |
|
| 1354 | + |
|
| 1355 | + |
|
| 1356 | + /** |
|
| 1357 | + * @param string $field_name |
|
| 1358 | + * @param string $dt_frmt |
|
| 1359 | + * @param string $tm_frmt |
|
| 1360 | + * @throws EE_Error |
|
| 1361 | + */ |
|
| 1362 | + public function e_datetime($field_name, $dt_frmt = '', $tm_frmt = '') |
|
| 1363 | + { |
|
| 1364 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, null, true); |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Get the i8ln value for a date using the WordPress @see date_i18n function. |
|
| 1370 | + * |
|
| 1371 | + * @param string $field_name The EE_Datetime_Field reference for the date being retrieved. |
|
| 1372 | + * @param string $format PHP valid date/time string format. If none is provided then the internal set format |
|
| 1373 | + * on the object will be used. |
|
| 1374 | + * @return string Date and time string in set locale or false if no field exists for the given |
|
| 1375 | + * @throws InvalidArgumentException |
|
| 1376 | + * @throws InvalidInterfaceException |
|
| 1377 | + * @throws InvalidDataTypeException |
|
| 1378 | + * @throws EE_Error |
|
| 1379 | + * field name. |
|
| 1380 | + */ |
|
| 1381 | + public function get_i18n_datetime($field_name, $format = '') |
|
| 1382 | + { |
|
| 1383 | + $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1384 | + return date_i18n( |
|
| 1385 | + $format, |
|
| 1386 | + EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
|
| 1387 | + ); |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + |
|
| 1391 | + |
|
| 1392 | + /** |
|
| 1393 | + * This method validates whether the given field name is a valid field on the model object as well as it is of a |
|
| 1394 | + * type EE_Datetime_Field. On success there will be returned the field settings. On fail an EE_Error exception is |
|
| 1395 | + * thrown. |
|
| 1396 | + * |
|
| 1397 | + * @param string $field_name The field name being checked |
|
| 1398 | + * @throws EE_Error |
|
| 1399 | + * @return EE_Datetime_Field |
|
| 1400 | + */ |
|
| 1401 | + protected function _get_dtt_field_settings($field_name) |
|
| 1402 | + { |
|
| 1403 | + $field = $this->get_model()->field_settings_for($field_name); |
|
| 1404 | + //check if field is dtt |
|
| 1405 | + if ($field instanceof EE_Datetime_Field) { |
|
| 1406 | + return $field; |
|
| 1407 | + } else { |
|
| 1408 | + 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', |
|
| 1409 | + 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
| 1410 | + } |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + |
|
| 1414 | + |
|
| 1415 | + |
|
| 1416 | + /** |
|
| 1417 | + * NOTE ABOUT BELOW: |
|
| 1418 | + * These convenience date and time setters are for setting date and time independently. In other words you might |
|
| 1419 | + * want to change the time on a datetime_field but leave the date the same (or vice versa). IF on the other hand |
|
| 1420 | + * you want to set both date and time at the same time, you can just use the models default set($fieldname,$value) |
|
| 1421 | + * method and make sure you send the entire datetime value for setting. |
|
| 1422 | + */ |
|
| 1423 | + /** |
|
| 1424 | + * sets the time on a datetime property |
|
| 1425 | + * |
|
| 1426 | + * @access protected |
|
| 1427 | + * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
| 1428 | + * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
|
| 1429 | + * @throws EE_Error |
|
| 1430 | + */ |
|
| 1431 | + protected function _set_time_for($time, $fieldname) |
|
| 1432 | + { |
|
| 1433 | + $this->_set_date_time('T', $time, $fieldname); |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * sets the date on a datetime property |
|
| 1440 | + * |
|
| 1441 | + * @access protected |
|
| 1442 | + * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
| 1443 | + * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
|
| 1444 | + * @throws EE_Error |
|
| 1445 | + */ |
|
| 1446 | + protected function _set_date_for($date, $fieldname) |
|
| 1447 | + { |
|
| 1448 | + $this->_set_date_time('D', $date, $fieldname); |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + |
|
| 1452 | + /** |
|
| 1453 | + * This takes care of setting a date or time independently on a given model object property. This method also |
|
| 1454 | + * verifies that the given fieldname matches a model object property and is for a EE_Datetime_Field field |
|
| 1455 | + * |
|
| 1456 | + * @access protected |
|
| 1457 | + * @param string $what "T" for time, 'B' for both, 'D' for Date. |
|
| 1458 | + * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
|
| 1459 | + * @param string $fieldname the name of the field the date OR time is being set on (must match a |
|
| 1460 | + * EE_Datetime_Field property) |
|
| 1461 | + * @throws InvalidArgumentException |
|
| 1462 | + * @throws InvalidInterfaceException |
|
| 1463 | + * @throws InvalidDataTypeException |
|
| 1464 | + * @throws EE_Error |
|
| 1465 | + */ |
|
| 1466 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) |
|
| 1467 | + { |
|
| 1468 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
| 1469 | + $field->set_timezone($this->_timezone); |
|
| 1470 | + $field->set_date_format($this->_dt_frmt); |
|
| 1471 | + $field->set_time_format($this->_tm_frmt); |
|
| 1472 | + switch ($what) { |
|
| 1473 | + case 'T' : |
|
| 1474 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( |
|
| 1475 | + $datetime_value, |
|
| 1476 | + $this->_fields[$fieldname] |
|
| 1477 | + ); |
|
| 1478 | + break; |
|
| 1479 | + case 'D' : |
|
| 1480 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( |
|
| 1481 | + $datetime_value, |
|
| 1482 | + $this->_fields[$fieldname] |
|
| 1483 | + ); |
|
| 1484 | + break; |
|
| 1485 | + case 'B' : |
|
| 1486 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
| 1487 | + break; |
|
| 1488 | + } |
|
| 1489 | + $this->_clear_cached_property($fieldname); |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * This will return a timestamp for the website timezone but ONLY when the current website timezone is different |
|
| 1495 | + * than the timezone set for the website. NOTE, this currently only works well with methods that return values. If |
|
| 1496 | + * you use it with methods that echo values the $_timestamp property may not get reset to its original value and |
|
| 1497 | + * that could lead to some unexpected results! |
|
| 1498 | + * |
|
| 1499 | + * @access public |
|
| 1500 | + * @param string $field_name This is the name of the field on the object that contains the date/time |
|
| 1501 | + * value being returned. |
|
| 1502 | + * @param string $callback must match a valid method in this class (defaults to get_datetime) |
|
| 1503 | + * @param mixed (array|string) $args This is the arguments that will be passed to the callback. |
|
| 1504 | + * @param string $prepend You can include something to prepend on the timestamp |
|
| 1505 | + * @param string $append You can include something to append on the timestamp |
|
| 1506 | + * @throws InvalidArgumentException |
|
| 1507 | + * @throws InvalidInterfaceException |
|
| 1508 | + * @throws InvalidDataTypeException |
|
| 1509 | + * @throws EE_Error |
|
| 1510 | + * @return string timestamp |
|
| 1511 | + */ |
|
| 1512 | + public function display_in_my_timezone( |
|
| 1513 | + $field_name, |
|
| 1514 | + $callback = 'get_datetime', |
|
| 1515 | + $args = null, |
|
| 1516 | + $prepend = '', |
|
| 1517 | + $append = '' |
|
| 1518 | + ) { |
|
| 1519 | + $timezone = EEH_DTT_Helper::get_timezone(); |
|
| 1520 | + if ($timezone === $this->_timezone) { |
|
| 1521 | + return ''; |
|
| 1522 | + } |
|
| 1523 | + $original_timezone = $this->_timezone; |
|
| 1524 | + $this->set_timezone($timezone); |
|
| 1525 | + $fn = (array)$field_name; |
|
| 1526 | + $args = array_merge($fn, (array)$args); |
|
| 1527 | + if ( ! method_exists($this, $callback)) { |
|
| 1528 | + throw new EE_Error( |
|
| 1529 | + sprintf( |
|
| 1530 | + __( |
|
| 1531 | + 'The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', |
|
| 1532 | + 'event_espresso' |
|
| 1533 | + ), |
|
| 1534 | + $callback |
|
| 1535 | + ) |
|
| 1536 | + ); |
|
| 1537 | + } |
|
| 1538 | + $args = (array)$args; |
|
| 1539 | + $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1540 | + $this->set_timezone($original_timezone); |
|
| 1541 | + return $return; |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + |
|
| 1545 | + |
|
| 1546 | + /** |
|
| 1547 | + * Deletes this model object. |
|
| 1548 | + * This calls the `EE_Base_Class::_delete` method. Child classes wishing to change default behaviour should |
|
| 1549 | + * override |
|
| 1550 | + * `EE_Base_Class::_delete` NOT this class. |
|
| 1551 | + * |
|
| 1552 | + * @return boolean | int |
|
| 1553 | + * @throws EE_Error |
|
| 1554 | + */ |
|
| 1555 | + public function delete() |
|
| 1556 | + { |
|
| 1557 | + /** |
|
| 1558 | + * Called just before the `EE_Base_Class::_delete` method call. |
|
| 1559 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1560 | + * should be aware that `_delete` may not always result in a permanent delete. For example, `EE_Soft_Delete_Base_Class::_delete` |
|
| 1561 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1562 | + * |
|
| 1563 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1564 | + */ |
|
| 1565 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
| 1566 | + $result = $this->_delete(); |
|
| 1567 | + /** |
|
| 1568 | + * Called just after the `EE_Base_Class::_delete` method call. |
|
| 1569 | + * Note: `EE_Base_Class::_delete` might be overridden by child classes so any client code hooking into these actions |
|
| 1570 | + * should be aware that `_delete` may not always result in a permanent delete. For example `EE_Soft_Base_Class::_delete` |
|
| 1571 | + * soft deletes (trash) the object and does not permanently delete it. |
|
| 1572 | + * |
|
| 1573 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1574 | + * @param boolean $result |
|
| 1575 | + */ |
|
| 1576 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
| 1577 | + return $result; |
|
| 1578 | + } |
|
| 1579 | + |
|
| 1580 | + |
|
| 1581 | + |
|
| 1582 | + /** |
|
| 1583 | + * Calls the specific delete method for the instantiated class. |
|
| 1584 | + * This method is called by the public `EE_Base_Class::delete` method. Any child classes desiring to override |
|
| 1585 | + * default functionality for "delete" (which is to call `permanently_delete`) should override this method NOT |
|
| 1586 | + * `EE_Base_Class::delete` |
|
| 1587 | + * |
|
| 1588 | + * @return bool|int |
|
| 1589 | + * @throws EE_Error |
|
| 1590 | + */ |
|
| 1591 | + protected function _delete() |
|
| 1592 | + { |
|
| 1593 | + return $this->delete_permanently(); |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + |
|
| 1597 | + |
|
| 1598 | + /** |
|
| 1599 | + * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an |
|
| 1600 | + * error) |
|
| 1601 | + * |
|
| 1602 | + * @return bool | int |
|
| 1603 | + * @throws EE_Error |
|
| 1604 | + */ |
|
| 1605 | + public function delete_permanently() |
|
| 1606 | + { |
|
| 1607 | + /** |
|
| 1608 | + * Called just before HARD deleting a model object |
|
| 1609 | + * |
|
| 1610 | + * @param EE_Base_Class $model_object about to be 'deleted' |
|
| 1611 | + */ |
|
| 1612 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
| 1613 | + $model = $this->get_model(); |
|
| 1614 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
| 1615 | + $this->refresh_cache_of_related_objects(); |
|
| 1616 | + /** |
|
| 1617 | + * Called just after HARD deleting a model object |
|
| 1618 | + * |
|
| 1619 | + * @param EE_Base_Class $model_object that was just 'deleted' |
|
| 1620 | + * @param boolean $result |
|
| 1621 | + */ |
|
| 1622 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
| 1623 | + return $result; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + |
|
| 1627 | + |
|
| 1628 | + /** |
|
| 1629 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
| 1630 | + * related model objects |
|
| 1631 | + * |
|
| 1632 | + * @throws EE_Error |
|
| 1633 | + */ |
|
| 1634 | + public function refresh_cache_of_related_objects() |
|
| 1635 | + { |
|
| 1636 | + $model = $this->get_model(); |
|
| 1637 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 1638 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
| 1639 | + $related_objects = $this->_model_relations[$relation_name]; |
|
| 1640 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 1641 | + //this relation only stores a single model object, not an array |
|
| 1642 | + //but let's make it consistent |
|
| 1643 | + $related_objects = array($related_objects); |
|
| 1644 | + } |
|
| 1645 | + foreach ($related_objects as $related_object) { |
|
| 1646 | + //only refresh their cache if they're in memory |
|
| 1647 | + if ($related_object instanceof EE_Base_Class) { |
|
| 1648 | + $related_object->clear_cache($model->get_this_model_name(), $this); |
|
| 1649 | + } |
|
| 1650 | + } |
|
| 1651 | + } |
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + |
|
| 1655 | + |
|
| 1656 | + |
|
| 1657 | + /** |
|
| 1658 | + * Saves this object to the database. An array may be supplied to set some values on this |
|
| 1659 | + * object just before saving. |
|
| 1660 | + * |
|
| 1661 | + * @access public |
|
| 1662 | + * @param array $set_cols_n_values keys are field names, values are their new values, |
|
| 1663 | + * if provided during the save() method (often client code will change the fields' |
|
| 1664 | + * values before calling save) |
|
| 1665 | + * @throws EE_Error |
|
| 1666 | + * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
|
| 1667 | + * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
|
| 1668 | + */ |
|
| 1669 | + public function save($set_cols_n_values = array()) |
|
| 1670 | + { |
|
| 1671 | + $model = $this->get_model(); |
|
| 1672 | + /** |
|
| 1673 | + * Filters the fields we're about to save on the model object |
|
| 1674 | + * |
|
| 1675 | + * @param array $set_cols_n_values |
|
| 1676 | + * @param EE_Base_Class $model_object |
|
| 1677 | + */ |
|
| 1678 | + $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1679 | + $this); |
|
| 1680 | + //set attributes as provided in $set_cols_n_values |
|
| 1681 | + foreach ($set_cols_n_values as $column => $value) { |
|
| 1682 | + $this->set($column, $value); |
|
| 1683 | + } |
|
| 1684 | + // no changes ? then don't do anything |
|
| 1685 | + if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 1686 | + return 0; |
|
| 1687 | + } |
|
| 1688 | + /** |
|
| 1689 | + * Saving a model object. |
|
| 1690 | + * Before we perform a save, this action is fired. |
|
| 1691 | + * |
|
| 1692 | + * @param EE_Base_Class $model_object the model object about to be saved. |
|
| 1693 | + */ |
|
| 1694 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
| 1695 | + if ( ! $this->allow_persist()) { |
|
| 1696 | + return 0; |
|
| 1697 | + } |
|
| 1698 | + //now get current attribute values |
|
| 1699 | + $save_cols_n_values = $this->_fields; |
|
| 1700 | + //if the object already has an ID, update it. Otherwise, insert it |
|
| 1701 | + //also: change the assumption about values passed to the model NOT being prepare dby the model object. They have been |
|
| 1702 | + $old_assumption_concerning_value_preparation = $model |
|
| 1703 | + ->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
| 1704 | + $model->assume_values_already_prepared_by_model_object(true); |
|
| 1705 | + //does this model have an autoincrement PK? |
|
| 1706 | + if ($model->has_primary_key_field()) { |
|
| 1707 | + if ($model->get_primary_key_field()->is_auto_increment()) { |
|
| 1708 | + //ok check if it's set, if so: update; if not, insert |
|
| 1709 | + if ( ! empty($save_cols_n_values[$model->primary_key_name()])) { |
|
| 1710 | + $results = $model->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1711 | + } else { |
|
| 1712 | + unset($save_cols_n_values[$model->primary_key_name()]); |
|
| 1713 | + $results = $model->insert($save_cols_n_values); |
|
| 1714 | + if ($results) { |
|
| 1715 | + //if successful, set the primary key |
|
| 1716 | + //but don't use the normal SET method, because it will check if |
|
| 1717 | + //an item with the same ID exists in the mapper & db, then |
|
| 1718 | + //will find it in the db (because we just added it) and THAT object |
|
| 1719 | + //will get added to the mapper before we can add this one! |
|
| 1720 | + //but if we just avoid using the SET method, all that headache can be avoided |
|
| 1721 | + $pk_field_name = $model->primary_key_name(); |
|
| 1722 | + $this->_fields[$pk_field_name] = $results; |
|
| 1723 | + $this->_clear_cached_property($pk_field_name); |
|
| 1724 | + $model->add_to_entity_map($this); |
|
| 1725 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1726 | + } |
|
| 1727 | + } |
|
| 1728 | + } else {//PK is NOT auto-increment |
|
| 1729 | + //so check if one like it already exists in the db |
|
| 1730 | + if ($model->exists_by_ID($this->ID())) { |
|
| 1731 | + if (WP_DEBUG && ! $this->in_entity_map()) { |
|
| 1732 | + throw new EE_Error( |
|
| 1733 | + sprintf( |
|
| 1734 | + __('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', |
|
| 1735 | + 'event_espresso'), |
|
| 1736 | + get_class($this), |
|
| 1737 | + get_class($model) . '::instance()->add_to_entity_map()', |
|
| 1738 | + get_class($model) . '::instance()->get_one_by_ID()', |
|
| 1739 | + '<br />' |
|
| 1740 | + ) |
|
| 1741 | + ); |
|
| 1742 | + } |
|
| 1743 | + $results = $model->update_by_ID($save_cols_n_values, $this->ID()); |
|
| 1744 | + } else { |
|
| 1745 | + $results = $model->insert($save_cols_n_values); |
|
| 1746 | + $this->_update_cached_related_model_objs_fks(); |
|
| 1747 | + } |
|
| 1748 | + } |
|
| 1749 | + } else {//there is NO primary key |
|
| 1750 | + $already_in_db = false; |
|
| 1751 | + foreach ($model->unique_indexes() as $index) { |
|
| 1752 | + $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
|
| 1753 | + if ($model->exists(array($uniqueness_where_params))) { |
|
| 1754 | + $already_in_db = true; |
|
| 1755 | + } |
|
| 1756 | + } |
|
| 1757 | + if ($already_in_db) { |
|
| 1758 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, |
|
| 1759 | + $model->get_combined_primary_key_fields()); |
|
| 1760 | + $results = $model->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
| 1761 | + } else { |
|
| 1762 | + $results = $model->insert($save_cols_n_values); |
|
| 1763 | + } |
|
| 1764 | + } |
|
| 1765 | + //restore the old assumption about values being prepared by the model object |
|
| 1766 | + $model |
|
| 1767 | + ->assume_values_already_prepared_by_model_object($old_assumption_concerning_value_preparation); |
|
| 1768 | + /** |
|
| 1769 | + * After saving the model object this action is called |
|
| 1770 | + * |
|
| 1771 | + * @param EE_Base_Class $model_object which was just saved |
|
| 1772 | + * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
|
| 1773 | + * the new ID (or 0 if an error occurred and it wasn't updated) |
|
| 1774 | + */ |
|
| 1775 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
| 1776 | + $this->_has_changes = false; |
|
| 1777 | + return $results; |
|
| 1778 | + } |
|
| 1779 | + |
|
| 1780 | + |
|
| 1781 | + |
|
| 1782 | + /** |
|
| 1783 | + * Updates the foreign key on related models objects pointing to this to have this model object's ID |
|
| 1784 | + * as their foreign key. If the cached related model objects already exist in the db, saves them (so that the DB |
|
| 1785 | + * is consistent) Especially useful in case we JUST added this model object ot the database and we want to let its |
|
| 1786 | + * cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't |
|
| 1787 | + * 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 |
|
| 1788 | + * transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether |
|
| 1789 | + * or not they exist in the DB (if they do, their DB records will be automatically updated) |
|
| 1790 | + * |
|
| 1791 | + * @return void |
|
| 1792 | + * @throws EE_Error |
|
| 1793 | + */ |
|
| 1794 | + protected function _update_cached_related_model_objs_fks() |
|
| 1795 | + { |
|
| 1796 | + $model = $this->get_model(); |
|
| 1797 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 1798 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 1799 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
| 1800 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( |
|
| 1801 | + $model->get_this_model_name() |
|
| 1802 | + ); |
|
| 1803 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
| 1804 | + if ($related_model_obj_in_cache->ID()) { |
|
| 1805 | + $related_model_obj_in_cache->save(); |
|
| 1806 | + } |
|
| 1807 | + } |
|
| 1808 | + } |
|
| 1809 | + } |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + |
|
| 1813 | + |
|
| 1814 | + /** |
|
| 1815 | + * Saves this model object and its NEW cached relations to the database. |
|
| 1816 | + * (Meaning, for now, IT DOES NOT WORK if the cached items already exist in the DB. |
|
| 1817 | + * In order for that to work, we would need to mark model objects as dirty/clean... |
|
| 1818 | + * because otherwise, there's a potential for infinite looping of saving |
|
| 1819 | + * Saves the cached related model objects, and ensures the relation between them |
|
| 1820 | + * and this object and properly setup |
|
| 1821 | + * |
|
| 1822 | + * @return int ID of new model object on save; 0 on failure+ |
|
| 1823 | + * @throws EE_Error |
|
| 1824 | + */ |
|
| 1825 | + public function save_new_cached_related_model_objs() |
|
| 1826 | + { |
|
| 1827 | + //make sure this has been saved |
|
| 1828 | + if ( ! $this->ID()) { |
|
| 1829 | + $id = $this->save(); |
|
| 1830 | + } else { |
|
| 1831 | + $id = $this->ID(); |
|
| 1832 | + } |
|
| 1833 | + //now save all the NEW cached model objects (ie they don't exist in the DB) |
|
| 1834 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
| 1835 | + if ($this->_model_relations[$relationName]) { |
|
| 1836 | + //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
|
| 1837 | + //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
|
| 1838 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
| 1839 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1840 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1841 | + /* @var $related_model_obj EE_Base_Class */ |
|
| 1842 | + $related_model_obj = $this->_model_relations[$relationName]; |
|
| 1843 | + // if( ! $related_model_obj->ID()){ |
|
| 1844 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1845 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1846 | + // } |
|
| 1847 | + } else { |
|
| 1848 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
| 1849 | + //add a relation to that relation type (which saves the appropriate thing in the process) |
|
| 1850 | + //but ONLY if it DOES NOT exist in the DB |
|
| 1851 | + // if( ! $related_model_obj->ID()){ |
|
| 1852 | + $this->_add_relation_to($related_model_obj, $relationName); |
|
| 1853 | + $related_model_obj->save_new_cached_related_model_objs(); |
|
| 1854 | + // } |
|
| 1855 | + } |
|
| 1856 | + } |
|
| 1857 | + } |
|
| 1858 | + } |
|
| 1859 | + return $id; |
|
| 1860 | + } |
|
| 1861 | + |
|
| 1862 | + |
|
| 1863 | + |
|
| 1864 | + /** |
|
| 1865 | + * for getting a model while instantiated. |
|
| 1866 | + * |
|
| 1867 | + * @return EEM_Base | EEM_CPT_Base |
|
| 1868 | + */ |
|
| 1869 | + public function get_model() |
|
| 1870 | + { |
|
| 1871 | + if( ! $this->_model){ |
|
| 1872 | + $modelName = self::_get_model_classname(get_class($this)); |
|
| 1873 | + $this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
| 1874 | + } else { |
|
| 1875 | + $this->_model->set_timezone($this->_timezone); |
|
| 1876 | + } |
|
| 1877 | + |
|
| 1878 | + return $this->_model; |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * @param $props_n_values |
|
| 1885 | + * @param $classname |
|
| 1886 | + * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
|
| 1887 | + * @throws EE_Error |
|
| 1888 | + */ |
|
| 1889 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) |
|
| 1890 | + { |
|
| 1891 | + //TODO: will not work for Term_Relationships because they have no PK! |
|
| 1892 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1893 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
| 1894 | + $id = $props_n_values[$primary_id_ref]; |
|
| 1895 | + return self::_get_model($classname)->get_from_entity_map($id); |
|
| 1896 | + } |
|
| 1897 | + return false; |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * This is called by child static "new_instance" method and we'll check to see if there is an existing db entry for |
|
| 1904 | + * the primary key (if present in incoming values). If there is a key in the incoming array that matches the |
|
| 1905 | + * 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 |
|
| 1906 | + * we return false. |
|
| 1907 | + * |
|
| 1908 | + * @param array $props_n_values incoming array of properties and their values |
|
| 1909 | + * @param string $classname the classname of the child class |
|
| 1910 | + * @param null $timezone |
|
| 1911 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 1912 | + * date_format and the second value is the time format |
|
| 1913 | + * @return mixed (EE_Base_Class|bool) |
|
| 1914 | + * @throws EE_Error |
|
| 1915 | + */ |
|
| 1916 | + protected static function _check_for_object($props_n_values, $classname, $timezone = null, $date_formats = array()) |
|
| 1917 | + { |
|
| 1918 | + $existing = null; |
|
| 1919 | + $model = self::_get_model($classname, $timezone); |
|
| 1920 | + if ($model->has_primary_key_field()) { |
|
| 1921 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
| 1922 | + if (array_key_exists($primary_id_ref, $props_n_values) |
|
| 1923 | + && ! empty($props_n_values[$primary_id_ref]) |
|
| 1924 | + ) { |
|
| 1925 | + $existing = $model->get_one_by_ID( |
|
| 1926 | + $props_n_values[$primary_id_ref] |
|
| 1927 | + ); |
|
| 1928 | + } |
|
| 1929 | + } elseif ($model->has_all_combined_primary_key_fields($props_n_values)) { |
|
| 1930 | + //no primary key on this model, but there's still a matching item in the DB |
|
| 1931 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID( |
|
| 1932 | + self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values) |
|
| 1933 | + ); |
|
| 1934 | + } |
|
| 1935 | + if ($existing) { |
|
| 1936 | + //set date formats if present before setting values |
|
| 1937 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
| 1938 | + $existing->set_date_format($date_formats[0]); |
|
| 1939 | + $existing->set_time_format($date_formats[1]); |
|
| 1940 | + } else { |
|
| 1941 | + //set default formats for date and time |
|
| 1942 | + $existing->set_date_format(get_option('date_format')); |
|
| 1943 | + $existing->set_time_format(get_option('time_format')); |
|
| 1944 | + } |
|
| 1945 | + foreach ($props_n_values as $property => $field_value) { |
|
| 1946 | + $existing->set($property, $field_value); |
|
| 1947 | + } |
|
| 1948 | + return $existing; |
|
| 1949 | + } else { |
|
| 1950 | + return false; |
|
| 1951 | + } |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + |
|
| 1956 | + /** |
|
| 1957 | + * Gets the EEM_*_Model for this class |
|
| 1958 | + * |
|
| 1959 | + * @access public now, as this is more convenient |
|
| 1960 | + * @param $classname |
|
| 1961 | + * @param null $timezone |
|
| 1962 | + * @throws EE_Error |
|
| 1963 | + * @return EEM_Base |
|
| 1964 | + */ |
|
| 1965 | + protected static function _get_model($classname, $timezone = null) |
|
| 1966 | + { |
|
| 1967 | + //find model for this class |
|
| 1968 | + if ( ! $classname) { |
|
| 1969 | + throw new EE_Error( |
|
| 1970 | + sprintf( |
|
| 1971 | + __( |
|
| 1972 | + "What were you thinking calling _get_model(%s)?? You need to specify the class name", |
|
| 1973 | + "event_espresso" |
|
| 1974 | + ), |
|
| 1975 | + $classname |
|
| 1976 | + ) |
|
| 1977 | + ); |
|
| 1978 | + } |
|
| 1979 | + $modelName = self::_get_model_classname($classname); |
|
| 1980 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + |
|
| 1984 | + /** |
|
| 1985 | + * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
|
| 1986 | + * |
|
| 1987 | + * @param string $model_classname |
|
| 1988 | + * @param null $timezone |
|
| 1989 | + * @return EEM_Base |
|
| 1990 | + * @throws \ReflectionException |
|
| 1991 | + * @throws InvalidArgumentException |
|
| 1992 | + * @throws InvalidInterfaceException |
|
| 1993 | + * @throws InvalidDataTypeException |
|
| 1994 | + * @throws EE_Error |
|
| 1995 | + */ |
|
| 1996 | + protected static function _get_model_instance_with_name($model_classname, $timezone = null) |
|
| 1997 | + { |
|
| 1998 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
| 1999 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
| 2000 | + $model->set_timezone($timezone); |
|
| 2001 | + return $model; |
|
| 2002 | + } |
|
| 2003 | + |
|
| 2004 | + |
|
| 2005 | + |
|
| 2006 | + /** |
|
| 2007 | + * If a model name is provided (eg Registration), gets the model classname for that model. |
|
| 2008 | + * Also works if a model class's classname is provided (eg EE_Registration). |
|
| 2009 | + * |
|
| 2010 | + * @param null $model_name |
|
| 2011 | + * @return string like EEM_Attendee |
|
| 2012 | + */ |
|
| 2013 | + private static function _get_model_classname($model_name = null) |
|
| 2014 | + { |
|
| 2015 | + if (strpos($model_name, "EE_") === 0) { |
|
| 2016 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
| 2017 | + } else { |
|
| 2018 | + $model_classname = "EEM_" . $model_name; |
|
| 2019 | + } |
|
| 2020 | + return $model_classname; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + |
|
| 2024 | + |
|
| 2025 | + /** |
|
| 2026 | + * returns the name of the primary key attribute |
|
| 2027 | + * |
|
| 2028 | + * @param null $classname |
|
| 2029 | + * @throws EE_Error |
|
| 2030 | + * @return string |
|
| 2031 | + */ |
|
| 2032 | + protected static function _get_primary_key_name($classname = null) |
|
| 2033 | + { |
|
| 2034 | + if ( ! $classname) { |
|
| 2035 | + throw new EE_Error( |
|
| 2036 | + sprintf( |
|
| 2037 | + __("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), |
|
| 2038 | + $classname |
|
| 2039 | + ) |
|
| 2040 | + ); |
|
| 2041 | + } |
|
| 2042 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + |
|
| 2046 | + |
|
| 2047 | + /** |
|
| 2048 | + * Gets the value of the primary key. |
|
| 2049 | + * If the object hasn't yet been saved, it should be whatever the model field's default was |
|
| 2050 | + * (eg, if this were the EE_Event class, look at the primary key field on EEM_Event and see what its default value |
|
| 2051 | + * is. Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
|
| 2052 | + * |
|
| 2053 | + * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
|
| 2054 | + * @throws EE_Error |
|
| 2055 | + */ |
|
| 2056 | + public function ID() |
|
| 2057 | + { |
|
| 2058 | + $model = $this->get_model(); |
|
| 2059 | + //now that we know the name of the variable, use a variable variable to get its value and return its |
|
| 2060 | + if ($model->has_primary_key_field()) { |
|
| 2061 | + return $this->_fields[$model->primary_key_name()]; |
|
| 2062 | + } else { |
|
| 2063 | + return $model->get_index_primary_key_string($this->_fields); |
|
| 2064 | + } |
|
| 2065 | + } |
|
| 2066 | + |
|
| 2067 | + |
|
| 2068 | + |
|
| 2069 | + /** |
|
| 2070 | + * Adds a relationship to the specified EE_Base_Class object, given the relationship's name. Eg, if the current |
|
| 2071 | + * model is related to a group of events, the $relationName should be 'Event', and should be a key in the EE |
|
| 2072 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just caches the related thing |
|
| 2073 | + * |
|
| 2074 | + * @param mixed $otherObjectModelObjectOrID EE_Base_Class or the ID of the other object |
|
| 2075 | + * @param string $relationName eg 'Events','Question',etc. |
|
| 2076 | + * an attendee to a group, you also want to specify which role they |
|
| 2077 | + * will have in that group. So you would use this parameter to |
|
| 2078 | + * specify array('role-column-name'=>'role-id') |
|
| 2079 | + * @param array $extra_join_model_fields_n_values You can optionally include an array of key=>value pairs that |
|
| 2080 | + * allow you to further constrict the relation to being added. |
|
| 2081 | + * However, keep in mind that the columns (keys) given must match a |
|
| 2082 | + * column on the JOIN table and currently only the HABTM models |
|
| 2083 | + * accept these additional conditions. Also remember that if an |
|
| 2084 | + * exact match isn't found for these extra cols/val pairs, then a |
|
| 2085 | + * NEW row is created in the join table. |
|
| 2086 | + * @param null $cache_id |
|
| 2087 | + * @throws EE_Error |
|
| 2088 | + * @return EE_Base_Class the object the relation was added to |
|
| 2089 | + */ |
|
| 2090 | + public function _add_relation_to( |
|
| 2091 | + $otherObjectModelObjectOrID, |
|
| 2092 | + $relationName, |
|
| 2093 | + $extra_join_model_fields_n_values = array(), |
|
| 2094 | + $cache_id = null |
|
| 2095 | + ) { |
|
| 2096 | + $model = $this->get_model(); |
|
| 2097 | + //if this thing exists in the DB, save the relation to the DB |
|
| 2098 | + if ($this->ID()) { |
|
| 2099 | + $otherObject = $model |
|
| 2100 | + ->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2101 | + $extra_join_model_fields_n_values); |
|
| 2102 | + //clear cache so future get_many_related and get_first_related() return new results. |
|
| 2103 | + $this->clear_cache($relationName, $otherObject, true); |
|
| 2104 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 2105 | + $otherObject->clear_cache($model->get_this_model_name(), $this); |
|
| 2106 | + } |
|
| 2107 | + } else { |
|
| 2108 | + //this thing doesn't exist in the DB, so just cache it |
|
| 2109 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
| 2110 | + throw new EE_Error(sprintf( |
|
| 2111 | + __('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', |
|
| 2112 | + 'event_espresso'), |
|
| 2113 | + $otherObjectModelObjectOrID, |
|
| 2114 | + get_class($this) |
|
| 2115 | + )); |
|
| 2116 | + } else { |
|
| 2117 | + $otherObject = $otherObjectModelObjectOrID; |
|
| 2118 | + } |
|
| 2119 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
| 2120 | + } |
|
| 2121 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 2122 | + //fix the reciprocal relation too |
|
| 2123 | + if ($otherObject->ID()) { |
|
| 2124 | + //its saved so assumed relations exist in the DB, so we can just |
|
| 2125 | + //clear the cache so future queries use the updated info in the DB |
|
| 2126 | + $otherObject->clear_cache($model->get_this_model_name(), null, true); |
|
| 2127 | + } else { |
|
| 2128 | + //it's not saved, so it caches relations like this |
|
| 2129 | + $otherObject->cache($model->get_this_model_name(), $this); |
|
| 2130 | + } |
|
| 2131 | + } |
|
| 2132 | + return $otherObject; |
|
| 2133 | + } |
|
| 2134 | + |
|
| 2135 | + |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * Removes a relationship to the specified EE_Base_Class object, given the relationships' name. Eg, if the current |
|
| 2139 | + * model is related to a group of events, the $relationName should be 'Events', and should be a key in the EE |
|
| 2140 | + * Model's $_model_relations array. If this model object doesn't exist in the DB, just removes the related thing |
|
| 2141 | + * from the cache |
|
| 2142 | + * |
|
| 2143 | + * @param mixed $otherObjectModelObjectOrID |
|
| 2144 | + * EE_Base_Class or the ID of the other object, OR an array key into the cache if this isn't saved |
|
| 2145 | + * to the DB yet |
|
| 2146 | + * @param string $relationName |
|
| 2147 | + * @param array $where_query |
|
| 2148 | + * You can optionally include an array of key=>value pairs that allow you to further constrict the |
|
| 2149 | + * relation to being added. However, keep in mind that the columns (keys) given must match a column |
|
| 2150 | + * on the JOIN table and currently only the HABTM models accept these additional conditions. Also |
|
| 2151 | + * remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is |
|
| 2152 | + * created in the join table. |
|
| 2153 | + * @return EE_Base_Class the relation was removed from |
|
| 2154 | + * @throws EE_Error |
|
| 2155 | + */ |
|
| 2156 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) |
|
| 2157 | + { |
|
| 2158 | + if ($this->ID()) { |
|
| 2159 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2160 | + $otherObject = $this->get_model() |
|
| 2161 | + ->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, |
|
| 2162 | + $where_query); |
|
| 2163 | + $this->clear_cache($relationName, $otherObject); |
|
| 2164 | + } else { |
|
| 2165 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2166 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
| 2167 | + } |
|
| 2168 | + if ($otherObject instanceof EE_Base_Class) { |
|
| 2169 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2170 | + } |
|
| 2171 | + return $otherObject; |
|
| 2172 | + } |
|
| 2173 | + |
|
| 2174 | + |
|
| 2175 | + |
|
| 2176 | + /** |
|
| 2177 | + * Removes ALL the related things for the $relationName. |
|
| 2178 | + * |
|
| 2179 | + * @param string $relationName |
|
| 2180 | + * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
|
| 2181 | + * @return EE_Base_Class |
|
| 2182 | + * @throws EE_Error |
|
| 2183 | + */ |
|
| 2184 | + public function _remove_relations($relationName, $where_query_params = array()) |
|
| 2185 | + { |
|
| 2186 | + if ($this->ID()) { |
|
| 2187 | + //if this exists in the DB, save the relation change to the DB too |
|
| 2188 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
| 2189 | + $this->clear_cache($relationName, null, true); |
|
| 2190 | + } else { |
|
| 2191 | + //this doesn't exist in the DB, just remove it from the cache |
|
| 2192 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
| 2193 | + } |
|
| 2194 | + if (is_array($otherObjects)) { |
|
| 2195 | + foreach ($otherObjects as $otherObject) { |
|
| 2196 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
| 2197 | + } |
|
| 2198 | + } |
|
| 2199 | + return $otherObjects; |
|
| 2200 | + } |
|
| 2201 | + |
|
| 2202 | + |
|
| 2203 | + |
|
| 2204 | + /** |
|
| 2205 | + * Gets all the related model objects of the specified type. Eg, if the current class if |
|
| 2206 | + * EE_Event, you could call $this->get_many_related('Registration') to get an array of all the |
|
| 2207 | + * EE_Registration objects which related to this event. Note: by default, we remove the "default query params" |
|
| 2208 | + * because we want to get even deleted items etc. |
|
| 2209 | + * |
|
| 2210 | + * @param string $relationName key in the model's _model_relations array |
|
| 2211 | + * @param array $query_params like EEM_Base::get_all |
|
| 2212 | + * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
|
| 2213 | + * @throws EE_Error |
|
| 2214 | + * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if |
|
| 2215 | + * you want IDs |
|
| 2216 | + */ |
|
| 2217 | + public function get_many_related($relationName, $query_params = array()) |
|
| 2218 | + { |
|
| 2219 | + if ($this->ID()) { |
|
| 2220 | + //this exists in the DB, so get the related things from either the cache or the DB |
|
| 2221 | + //if there are query parameters, forget about caching the related model objects. |
|
| 2222 | + if ($query_params) { |
|
| 2223 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2224 | + } else { |
|
| 2225 | + //did we already cache the result of this query? |
|
| 2226 | + $cached_results = $this->get_all_from_cache($relationName); |
|
| 2227 | + if ( ! $cached_results) { |
|
| 2228 | + $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
|
| 2229 | + //if no query parameters were passed, then we got all the related model objects |
|
| 2230 | + //for that relation. We can cache them then. |
|
| 2231 | + foreach ($related_model_objects as $related_model_object) { |
|
| 2232 | + $this->cache($relationName, $related_model_object); |
|
| 2233 | + } |
|
| 2234 | + } else { |
|
| 2235 | + $related_model_objects = $cached_results; |
|
| 2236 | + } |
|
| 2237 | + } |
|
| 2238 | + } else { |
|
| 2239 | + //this doesn't exist in the DB, so just get the related things from the cache |
|
| 2240 | + $related_model_objects = $this->get_all_from_cache($relationName); |
|
| 2241 | + } |
|
| 2242 | + return $related_model_objects; |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + |
|
| 2246 | + /** |
|
| 2247 | + * Instead of getting the related model objects, simply counts them. Ignores default_where_conditions by default, |
|
| 2248 | + * unless otherwise specified in the $query_params |
|
| 2249 | + * |
|
| 2250 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2251 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2252 | + * @param string $field_to_count name of field to count by. By default, uses primary key |
|
| 2253 | + * @param bool $distinct if we want to only count the distinct values for the column then you can trigger |
|
| 2254 | + * that by the setting $distinct to TRUE; |
|
| 2255 | + * @return int |
|
| 2256 | + * @throws EE_Error |
|
| 2257 | + */ |
|
| 2258 | + public function count_related($relation_name, $query_params = array(), $field_to_count = null, $distinct = false) |
|
| 2259 | + { |
|
| 2260 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + |
|
| 2264 | + /** |
|
| 2265 | + * Instead of getting the related model objects, simply sums up the values of the specified field. |
|
| 2266 | + * Note: ignores default_where_conditions by default, unless otherwise specified in the $query_params |
|
| 2267 | + * |
|
| 2268 | + * @param string $relation_name model_name like 'Event', or 'Registration' |
|
| 2269 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2270 | + * @param string $field_to_sum name of field to count by. |
|
| 2271 | + * By default, uses primary key (which doesn't make much sense, so you should probably |
|
| 2272 | + * change it) |
|
| 2273 | + * @return int |
|
| 2274 | + * @throws EE_Error |
|
| 2275 | + */ |
|
| 2276 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) |
|
| 2277 | + { |
|
| 2278 | + return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + |
|
| 2283 | + /** |
|
| 2284 | + * Gets the first (ie, one) related model object of the specified type. |
|
| 2285 | + * |
|
| 2286 | + * @param string $relationName key in the model's _model_relations array |
|
| 2287 | + * @param array $query_params like EEM_Base::get_all |
|
| 2288 | + * @return EE_Base_Class (not an array, a single object) |
|
| 2289 | + * @throws EE_Error |
|
| 2290 | + */ |
|
| 2291 | + public function get_first_related($relationName, $query_params = array()) |
|
| 2292 | + { |
|
| 2293 | + $model = $this->get_model(); |
|
| 2294 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
| 2295 | + //if they've provided some query parameters, don't bother trying to cache the result |
|
| 2296 | + //also make sure we're not caching the result of get_first_related |
|
| 2297 | + //on a relation which should have an array of objects (because the cache might have an array of objects) |
|
| 2298 | + if ($query_params |
|
| 2299 | + || ! $model->related_settings_for($relationName) |
|
| 2300 | + instanceof |
|
| 2301 | + EE_Belongs_To_Relation |
|
| 2302 | + ) { |
|
| 2303 | + $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2304 | + } else { |
|
| 2305 | + //first, check if we've already cached the result of this query |
|
| 2306 | + $cached_result = $this->get_one_from_cache($relationName); |
|
| 2307 | + if ( ! $cached_result) { |
|
| 2308 | + $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2309 | + $this->cache($relationName, $related_model_object); |
|
| 2310 | + } else { |
|
| 2311 | + $related_model_object = $cached_result; |
|
| 2312 | + } |
|
| 2313 | + } |
|
| 2314 | + } else { |
|
| 2315 | + $related_model_object = null; |
|
| 2316 | + //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
|
| 2317 | + if ($model->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
| 2318 | + $related_model_object = $model->get_first_related($this, $relationName, $query_params); |
|
| 2319 | + } |
|
| 2320 | + //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 |
|
| 2321 | + if ( ! $related_model_object) { |
|
| 2322 | + $related_model_object = $this->get_one_from_cache($relationName); |
|
| 2323 | + } |
|
| 2324 | + } |
|
| 2325 | + return $related_model_object; |
|
| 2326 | + } |
|
| 2327 | + |
|
| 2328 | + |
|
| 2329 | + |
|
| 2330 | + /** |
|
| 2331 | + * Does a delete on all related objects of type $relationName and removes |
|
| 2332 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2333 | + * of blocking related model objects) does nothing. If the related model objects are |
|
| 2334 | + * soft-deletable, they will be soft-deleted regardless of related blocking model objects. |
|
| 2335 | + * If this model object doesn't exist yet in the DB, just removes its related things |
|
| 2336 | + * |
|
| 2337 | + * @param string $relationName |
|
| 2338 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2339 | + * @return int how many deleted |
|
| 2340 | + * @throws EE_Error |
|
| 2341 | + */ |
|
| 2342 | + public function delete_related($relationName, $query_params = array()) |
|
| 2343 | + { |
|
| 2344 | + if ($this->ID()) { |
|
| 2345 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
| 2346 | + } else { |
|
| 2347 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2348 | + $this->clear_cache($relationName, null, true); |
|
| 2349 | + } |
|
| 2350 | + return $count; |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + |
|
| 2354 | + |
|
| 2355 | + /** |
|
| 2356 | + * Does a hard delete (ie, removes the DB row) on all related objects of type $relationName and removes |
|
| 2357 | + * the current model object's relation to them. If they can't be deleted (because |
|
| 2358 | + * of blocking related model objects) just does a soft delete on it instead, if possible. |
|
| 2359 | + * If the related thing isn't a soft-deletable model object, this function is identical |
|
| 2360 | + * to delete_related(). If this model object doesn't exist in the DB, just remove its related things |
|
| 2361 | + * |
|
| 2362 | + * @param string $relationName |
|
| 2363 | + * @param array $query_params like EEM_Base::get_all's |
|
| 2364 | + * @return int how many deleted (including those soft deleted) |
|
| 2365 | + * @throws EE_Error |
|
| 2366 | + */ |
|
| 2367 | + public function delete_related_permanently($relationName, $query_params = array()) |
|
| 2368 | + { |
|
| 2369 | + if ($this->ID()) { |
|
| 2370 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
| 2371 | + } else { |
|
| 2372 | + $count = count($this->get_all_from_cache($relationName)); |
|
| 2373 | + } |
|
| 2374 | + $this->clear_cache($relationName, null, true); |
|
| 2375 | + return $count; |
|
| 2376 | + } |
|
| 2377 | + |
|
| 2378 | + |
|
| 2379 | + |
|
| 2380 | + /** |
|
| 2381 | + * is_set |
|
| 2382 | + * Just a simple utility function children can use for checking if property exists |
|
| 2383 | + * |
|
| 2384 | + * @access public |
|
| 2385 | + * @param string $field_name property to check |
|
| 2386 | + * @return bool TRUE if existing,FALSE if not. |
|
| 2387 | + */ |
|
| 2388 | + public function is_set($field_name) |
|
| 2389 | + { |
|
| 2390 | + return isset($this->_fields[$field_name]); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + |
|
| 2394 | + |
|
| 2395 | + /** |
|
| 2396 | + * Just a simple utility function children can use for checking if property (or properties) exists and throwing an |
|
| 2397 | + * EE_Error exception if they don't |
|
| 2398 | + * |
|
| 2399 | + * @param mixed (string|array) $properties properties to check |
|
| 2400 | + * @throws EE_Error |
|
| 2401 | + * @return bool TRUE if existing, throw EE_Error if not. |
|
| 2402 | + */ |
|
| 2403 | + protected function _property_exists($properties) |
|
| 2404 | + { |
|
| 2405 | + foreach ((array)$properties as $property_name) { |
|
| 2406 | + //first make sure this property exists |
|
| 2407 | + if ( ! $this->_fields[$property_name]) { |
|
| 2408 | + throw new EE_Error( |
|
| 2409 | + sprintf( |
|
| 2410 | + __( |
|
| 2411 | + 'Trying to retrieve a non-existent property (%s). Double check the spelling please', |
|
| 2412 | + 'event_espresso' |
|
| 2413 | + ), |
|
| 2414 | + $property_name |
|
| 2415 | + ) |
|
| 2416 | + ); |
|
| 2417 | + } |
|
| 2418 | + } |
|
| 2419 | + return true; |
|
| 2420 | + } |
|
| 2421 | + |
|
| 2422 | + |
|
| 2423 | + |
|
| 2424 | + /** |
|
| 2425 | + * This simply returns an array of model fields for this object |
|
| 2426 | + * |
|
| 2427 | + * @return array |
|
| 2428 | + * @throws EE_Error |
|
| 2429 | + */ |
|
| 2430 | + public function model_field_array() |
|
| 2431 | + { |
|
| 2432 | + $fields = $this->get_model()->field_settings(false); |
|
| 2433 | + $properties = array(); |
|
| 2434 | + //remove prepended underscore |
|
| 2435 | + foreach ($fields as $field_name => $settings) { |
|
| 2436 | + $properties[$field_name] = $this->get($field_name); |
|
| 2437 | + } |
|
| 2438 | + return $properties; |
|
| 2439 | + } |
|
| 2440 | + |
|
| 2441 | + |
|
| 2442 | + |
|
| 2443 | + /** |
|
| 2444 | + * Very handy general function to allow for plugins to extend any child of EE_Base_Class. |
|
| 2445 | + * If a method is called on a child of EE_Base_Class that doesn't exist, this function is called |
|
| 2446 | + * (http://www.garfieldtech.com/blog/php-magic-call) and passed the method's name and arguments. Instead of |
|
| 2447 | + * requiring a plugin to extend the EE_Base_Class (which works fine is there's only 1 plugin, but when will that |
|
| 2448 | + * happen?) they can add a hook onto 'filters_hook_espresso__{className}__{methodName}' (eg, |
|
| 2449 | + * filters_hook_espresso__EE_Answer__my_great_function) and accepts 2 arguments: the object on which the function |
|
| 2450 | + * was called, and an array of the original arguments passed to the function. Whatever their callback function |
|
| 2451 | + * returns will be returned by this function. Example: in functions.php (or in a plugin): |
|
| 2452 | + * add_filter('FHEE__EE_Answer__my_callback','my_callback',10,3); function |
|
| 2453 | + * my_callback($previousReturnValue,EE_Base_Class $object,$argsArray){ |
|
| 2454 | + * $returnString= "you called my_callback! and passed args:".implode(",",$argsArray); |
|
| 2455 | + * return $previousReturnValue.$returnString; |
|
| 2456 | + * } |
|
| 2457 | + * require('EE_Answer.class.php'); |
|
| 2458 | + * $answer= EE_Answer::new_instance(array('REG_ID' => 2,'QST_ID' => 3,'ANS_value' => The answer is 42')); |
|
| 2459 | + * echo $answer->my_callback('monkeys',100); |
|
| 2460 | + * //will output "you called my_callback! and passed args:monkeys,100" |
|
| 2461 | + * |
|
| 2462 | + * @param string $methodName name of method which was called on a child of EE_Base_Class, but which |
|
| 2463 | + * @param array $args array of original arguments passed to the function |
|
| 2464 | + * @throws EE_Error |
|
| 2465 | + * @return mixed whatever the plugin which calls add_filter decides |
|
| 2466 | + */ |
|
| 2467 | + public function __call($methodName, $args) |
|
| 2468 | + { |
|
| 2469 | + $className = get_class($this); |
|
| 2470 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
| 2471 | + if ( ! has_filter($tagName)) { |
|
| 2472 | + throw new EE_Error( |
|
| 2473 | + sprintf( |
|
| 2474 | + __( |
|
| 2475 | + "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;}", |
|
| 2476 | + "event_espresso" |
|
| 2477 | + ), |
|
| 2478 | + $methodName, |
|
| 2479 | + $className, |
|
| 2480 | + $tagName |
|
| 2481 | + ) |
|
| 2482 | + ); |
|
| 2483 | + } |
|
| 2484 | + return apply_filters($tagName, null, $this, $args); |
|
| 2485 | + } |
|
| 2486 | + |
|
| 2487 | + |
|
| 2488 | + /** |
|
| 2489 | + * Similar to insert_post_meta, adds a record in the Extra_Meta model's table with the given key and value. |
|
| 2490 | + * A $previous_value can be specified in case there are many meta rows with the same key |
|
| 2491 | + * |
|
| 2492 | + * @param string $meta_key |
|
| 2493 | + * @param mixed $meta_value |
|
| 2494 | + * @param mixed $previous_value |
|
| 2495 | + * @return bool|int # of records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
|
| 2496 | + * @throws InvalidArgumentException |
|
| 2497 | + * @throws InvalidInterfaceException |
|
| 2498 | + * @throws InvalidDataTypeException |
|
| 2499 | + * @throws EE_Error |
|
| 2500 | + * NOTE: if the values haven't changed, returns 0 |
|
| 2501 | + */ |
|
| 2502 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = null) |
|
| 2503 | + { |
|
| 2504 | + $query_params = array( |
|
| 2505 | + array( |
|
| 2506 | + 'EXM_key' => $meta_key, |
|
| 2507 | + 'OBJ_ID' => $this->ID(), |
|
| 2508 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2509 | + ), |
|
| 2510 | + ); |
|
| 2511 | + if ($previous_value !== null) { |
|
| 2512 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2513 | + } |
|
| 2514 | + $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
|
| 2515 | + if ( ! $existing_rows_like_that) { |
|
| 2516 | + return $this->add_extra_meta($meta_key, $meta_value); |
|
| 2517 | + } |
|
| 2518 | + foreach ($existing_rows_like_that as $existing_row) { |
|
| 2519 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
| 2520 | + } |
|
| 2521 | + return count($existing_rows_like_that); |
|
| 2522 | + } |
|
| 2523 | + |
|
| 2524 | + |
|
| 2525 | + /** |
|
| 2526 | + * Adds a new extra meta record. If $unique is set to TRUE, we'll first double-check |
|
| 2527 | + * no other extra meta for this model object have the same key. Returns TRUE if the |
|
| 2528 | + * extra meta row was entered, false if not |
|
| 2529 | + * |
|
| 2530 | + * @param string $meta_key |
|
| 2531 | + * @param mixed $meta_value |
|
| 2532 | + * @param boolean $unique |
|
| 2533 | + * @return boolean |
|
| 2534 | + * @throws InvalidArgumentException |
|
| 2535 | + * @throws InvalidInterfaceException |
|
| 2536 | + * @throws InvalidDataTypeException |
|
| 2537 | + * @throws EE_Error |
|
| 2538 | + */ |
|
| 2539 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) |
|
| 2540 | + { |
|
| 2541 | + if ($unique) { |
|
| 2542 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one( |
|
| 2543 | + array( |
|
| 2544 | + array( |
|
| 2545 | + 'EXM_key' => $meta_key, |
|
| 2546 | + 'OBJ_ID' => $this->ID(), |
|
| 2547 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2548 | + ), |
|
| 2549 | + ) |
|
| 2550 | + ); |
|
| 2551 | + if ($existing_extra_meta) { |
|
| 2552 | + return false; |
|
| 2553 | + } |
|
| 2554 | + } |
|
| 2555 | + $new_extra_meta = EE_Extra_Meta::new_instance( |
|
| 2556 | + array( |
|
| 2557 | + 'EXM_key' => $meta_key, |
|
| 2558 | + 'EXM_value' => $meta_value, |
|
| 2559 | + 'OBJ_ID' => $this->ID(), |
|
| 2560 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2561 | + ) |
|
| 2562 | + ); |
|
| 2563 | + $new_extra_meta->save(); |
|
| 2564 | + return true; |
|
| 2565 | + } |
|
| 2566 | + |
|
| 2567 | + |
|
| 2568 | + /** |
|
| 2569 | + * Deletes all the extra meta rows for this record as specified by key. If $meta_value |
|
| 2570 | + * is specified, only deletes extra meta records with that value. |
|
| 2571 | + * |
|
| 2572 | + * @param string $meta_key |
|
| 2573 | + * @param mixed $meta_value |
|
| 2574 | + * @return int number of extra meta rows deleted |
|
| 2575 | + * @throws InvalidArgumentException |
|
| 2576 | + * @throws InvalidInterfaceException |
|
| 2577 | + * @throws InvalidDataTypeException |
|
| 2578 | + * @throws EE_Error |
|
| 2579 | + */ |
|
| 2580 | + public function delete_extra_meta($meta_key, $meta_value = null) |
|
| 2581 | + { |
|
| 2582 | + $query_params = array( |
|
| 2583 | + array( |
|
| 2584 | + 'EXM_key' => $meta_key, |
|
| 2585 | + 'OBJ_ID' => $this->ID(), |
|
| 2586 | + 'EXM_type' => $this->get_model()->get_this_model_name(), |
|
| 2587 | + ), |
|
| 2588 | + ); |
|
| 2589 | + if ($meta_value !== null) { |
|
| 2590 | + $query_params[0]['EXM_value'] = $meta_value; |
|
| 2591 | + } |
|
| 2592 | + return EEM_Extra_Meta::instance()->delete($query_params); |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + |
|
| 2596 | + |
|
| 2597 | + /** |
|
| 2598 | + * Gets the extra meta with the given meta key. If you specify "single" we just return 1, otherwise |
|
| 2599 | + * an array of everything found. Requires that this model actually have a relation of type EE_Has_Many_Any_Relation. |
|
| 2600 | + * You can specify $default is case you haven't found the extra meta |
|
| 2601 | + * |
|
| 2602 | + * @param string $meta_key |
|
| 2603 | + * @param boolean $single |
|
| 2604 | + * @param mixed $default if we don't find anything, what should we return? |
|
| 2605 | + * @return mixed single value if $single; array if ! $single |
|
| 2606 | + * @throws EE_Error |
|
| 2607 | + */ |
|
| 2608 | + public function get_extra_meta($meta_key, $single = false, $default = null) |
|
| 2609 | + { |
|
| 2610 | + if ($single) { |
|
| 2611 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2612 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2613 | + return $result->value(); |
|
| 2614 | + } |
|
| 2615 | + } else { |
|
| 2616 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key' => $meta_key))); |
|
| 2617 | + if ($results) { |
|
| 2618 | + $values = array(); |
|
| 2619 | + foreach ($results as $result) { |
|
| 2620 | + if ($result instanceof EE_Extra_Meta) { |
|
| 2621 | + $values[$result->ID()] = $result->value(); |
|
| 2622 | + } |
|
| 2623 | + } |
|
| 2624 | + return $values; |
|
| 2625 | + } |
|
| 2626 | + } |
|
| 2627 | + //if nothing discovered yet return default. |
|
| 2628 | + return apply_filters( |
|
| 2629 | + 'FHEE__EE_Base_Class__get_extra_meta__default_value', |
|
| 2630 | + $default, |
|
| 2631 | + $meta_key, |
|
| 2632 | + $single, |
|
| 2633 | + $this |
|
| 2634 | + ); |
|
| 2635 | + } |
|
| 2636 | + |
|
| 2637 | + |
|
| 2638 | + |
|
| 2639 | + /** |
|
| 2640 | + * Returns a simple array of all the extra meta associated with this model object. |
|
| 2641 | + * If $one_of_each_key is true (Default), it will be an array of simple key-value pairs, keys being the |
|
| 2642 | + * extra meta's key, and teh value being its value. However, if there are duplicate extra meta rows with |
|
| 2643 | + * the same key, only one will be used. (eg array('foo'=>'bar','monkey'=>123)) |
|
| 2644 | + * If $one_of_each_key is false, it will return an array with the top-level keys being |
|
| 2645 | + * the extra meta keys, but their values are also arrays, which have the extra-meta's ID as their sub-key, and |
|
| 2646 | + * finally the extra meta's value as each sub-value. (eg |
|
| 2647 | + * array('foo'=>array(1=>'bar',2=>'bill'),'monkey'=>array(3=>123))) |
|
| 2648 | + * |
|
| 2649 | + * @param boolean $one_of_each_key |
|
| 2650 | + * @return array |
|
| 2651 | + * @throws EE_Error |
|
| 2652 | + */ |
|
| 2653 | + public function all_extra_meta_array($one_of_each_key = true) |
|
| 2654 | + { |
|
| 2655 | + $return_array = array(); |
|
| 2656 | + if ($one_of_each_key) { |
|
| 2657 | + $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by' => 'EXM_key')); |
|
| 2658 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2659 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2660 | + $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
|
| 2661 | + } |
|
| 2662 | + } |
|
| 2663 | + } else { |
|
| 2664 | + $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
|
| 2665 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
| 2666 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
| 2667 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
| 2668 | + $return_array[$extra_meta_obj->key()] = array(); |
|
| 2669 | + } |
|
| 2670 | + $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
|
| 2671 | + } |
|
| 2672 | + } |
|
| 2673 | + } |
|
| 2674 | + return $return_array; |
|
| 2675 | + } |
|
| 2676 | + |
|
| 2677 | + |
|
| 2678 | + |
|
| 2679 | + /** |
|
| 2680 | + * Gets a pretty nice displayable nice for this model object. Often overridden |
|
| 2681 | + * |
|
| 2682 | + * @return string |
|
| 2683 | + * @throws EE_Error |
|
| 2684 | + */ |
|
| 2685 | + public function name() |
|
| 2686 | + { |
|
| 2687 | + //find a field that's not a text field |
|
| 2688 | + $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
|
| 2689 | + if ($field_we_can_use) { |
|
| 2690 | + return $this->get($field_we_can_use->get_name()); |
|
| 2691 | + } else { |
|
| 2692 | + $first_few_properties = $this->model_field_array(); |
|
| 2693 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
| 2694 | + $name_parts = array(); |
|
| 2695 | + foreach ($first_few_properties as $name => $value) { |
|
| 2696 | + $name_parts[] = "$name:$value"; |
|
| 2697 | + } |
|
| 2698 | + return implode(",", $name_parts); |
|
| 2699 | + } |
|
| 2700 | + } |
|
| 2701 | + |
|
| 2702 | + |
|
| 2703 | + |
|
| 2704 | + /** |
|
| 2705 | + * in_entity_map |
|
| 2706 | + * Checks if this model object has been proven to already be in the entity map |
|
| 2707 | + * |
|
| 2708 | + * @return boolean |
|
| 2709 | + * @throws EE_Error |
|
| 2710 | + */ |
|
| 2711 | + public function in_entity_map() |
|
| 2712 | + { |
|
| 2713 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
| 2714 | + //well, if we looked, did we find it in the entity map? |
|
| 2715 | + return true; |
|
| 2716 | + } else { |
|
| 2717 | + return false; |
|
| 2718 | + } |
|
| 2719 | + } |
|
| 2720 | + |
|
| 2721 | + |
|
| 2722 | + |
|
| 2723 | + /** |
|
| 2724 | + * refresh_from_db |
|
| 2725 | + * Makes sure the fields and values on this model object are in-sync with what's in the database. |
|
| 2726 | + * |
|
| 2727 | + * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
|
| 2728 | + * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
|
| 2729 | + */ |
|
| 2730 | + public function refresh_from_db() |
|
| 2731 | + { |
|
| 2732 | + if ($this->ID() && $this->in_entity_map()) { |
|
| 2733 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
| 2734 | + } else { |
|
| 2735 | + //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
|
| 2736 | + //if it has an ID but it's not in the map, and you're asking me to refresh it |
|
| 2737 | + //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
|
| 2738 | + //absolutely nothing in it for this ID |
|
| 2739 | + if (WP_DEBUG) { |
|
| 2740 | + throw new EE_Error( |
|
| 2741 | + sprintf( |
|
| 2742 | + __('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.', |
|
| 2743 | + 'event_espresso'), |
|
| 2744 | + $this->ID(), |
|
| 2745 | + get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2746 | + get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2747 | + ) |
|
| 2748 | + ); |
|
| 2749 | + } |
|
| 2750 | + } |
|
| 2751 | + } |
|
| 2752 | + |
|
| 2753 | + |
|
| 2754 | + /** |
|
| 2755 | + * Gets the money field's amount in subunits (and if the currency has no subunits, gets it in the main units) |
|
| 2756 | + * |
|
| 2757 | + * @param string $money_field_name |
|
| 2758 | + * @return int |
|
| 2759 | + * @throws InvalidEntityException |
|
| 2760 | + * @throws EE_Error |
|
| 2761 | + * @throws DomainException |
|
| 2762 | + */ |
|
| 2763 | + public function moneyInSubunits($money_field_name) |
|
| 2764 | + { |
|
| 2765 | + $this->verifyUsesMoney(__FUNCTION__); |
|
| 2766 | + return $this->getMoneyObject($money_field_name)->amountInSubunits(); |
|
| 2767 | + } |
|
| 2768 | + |
|
| 2769 | + |
|
| 2770 | + /** |
|
| 2771 | + * Sets the money field's amount based on the incoming monetary subunits (eg pennies). If the currency has no |
|
| 2772 | + * subunits, the amount is actually assumed to be in the currency's main units |
|
| 2773 | + * |
|
| 2774 | + * @param string $money_field_name |
|
| 2775 | + * @param int $amount_in_subunits |
|
| 2776 | + * @throws InvalidArgumentException |
|
| 2777 | + * @throws InvalidInterfaceException |
|
| 2778 | + * @throws InvalidIdentifierException |
|
| 2779 | + * @throws InvalidDataTypeException |
|
| 2780 | + * @throws EE_Error |
|
| 2781 | + * @throws DomainException |
|
| 2782 | + */ |
|
| 2783 | + public function setMoneySubunits($money_field_name,$amount_in_subunits) |
|
| 2784 | + { |
|
| 2785 | + $this->verifyUsesMoney(__FUNCTION__); |
|
| 2786 | + $money = $this->money_factory->createFromSubUnits( |
|
| 2787 | + $amount_in_subunits, |
|
| 2788 | + EE_Config::instance()->currency->code |
|
| 2789 | + ); |
|
| 2790 | + $this->set($money_field_name, $money); |
|
| 2791 | + } |
|
| 2792 | + |
|
| 2793 | + |
|
| 2794 | + /** |
|
| 2795 | + * @param string $function |
|
| 2796 | + * @throws DomainException |
|
| 2797 | + * @throws EE_Error |
|
| 2798 | + */ |
|
| 2799 | + private function verifyUsesMoney($function) |
|
| 2800 | + { |
|
| 2801 | + if (! $this instanceof UsesMoneyInterface) { |
|
| 2802 | + throw new DomainException( |
|
| 2803 | + sprintf( |
|
| 2804 | + esc_html__( |
|
| 2805 | + '%1$s does not use an %2$s object for representing money values, therefore the %3$s method can not be called.', |
|
| 2806 | + 'event_espresso' |
|
| 2807 | + ), |
|
| 2808 | + $this->name(), |
|
| 2809 | + 'EventEspresso\core\domain\values\currency\Money', |
|
| 2810 | + "{$function}()" |
|
| 2811 | + ) |
|
| 2812 | + ); |
|
| 2813 | + } |
|
| 2814 | + } |
|
| 2815 | + |
|
| 2816 | + |
|
| 2817 | + |
|
| 2818 | + /** |
|
| 2819 | + * Because some other plugins, like Advanced Cron Manager, expect all objects to have this method |
|
| 2820 | + * (probably a bad assumption they have made, oh well) |
|
| 2821 | + * |
|
| 2822 | + * @return string |
|
| 2823 | + */ |
|
| 2824 | + public function __toString() |
|
| 2825 | + { |
|
| 2826 | + try { |
|
| 2827 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
| 2828 | + } catch (Exception $e) { |
|
| 2829 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2830 | + return ''; |
|
| 2831 | + } |
|
| 2832 | + } |
|
| 2833 | + |
|
| 2834 | + |
|
| 2835 | + |
|
| 2836 | + /** |
|
| 2837 | + * Clear related model objects if they're already in the DB, because otherwise when we |
|
| 2838 | + * UN-serialize this model object we'll need to be careful to add them to the entity map. |
|
| 2839 | + * This means if we have made changes to those related model objects, and want to unserialize |
|
| 2840 | + * the this model object on a subsequent request, changes to those related model objects will be lost. |
|
| 2841 | + * Instead, those related model objects should be directly serialized and stored. |
|
| 2842 | + * Eg, the following won't work: |
|
| 2843 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2844 | + * $att = $reg->attendee(); |
|
| 2845 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2846 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2847 | + * //END REQUEST |
|
| 2848 | + * //START NEXT REQUEST |
|
| 2849 | + * $reg = get_option( 'my_option' ); |
|
| 2850 | + * $reg->attendee()->save(); |
|
| 2851 | + * And would need to be replace with: |
|
| 2852 | + * $reg = EEM_Registration::instance()->get_one_by_ID( 123 ); |
|
| 2853 | + * $att = $reg->attendee(); |
|
| 2854 | + * $att->set( 'ATT_fname', 'Dirk' ); |
|
| 2855 | + * update_option( 'my_option', serialize( $reg ) ); |
|
| 2856 | + * //END REQUEST |
|
| 2857 | + * //START NEXT REQUEST |
|
| 2858 | + * $att = get_option( 'my_option' ); |
|
| 2859 | + * $att->save(); |
|
| 2860 | + * |
|
| 2861 | + * @return array |
|
| 2862 | + * @throws EE_Error |
|
| 2863 | + */ |
|
| 2864 | + public function __sleep() |
|
| 2865 | + { |
|
| 2866 | + $model = $this->get_model(); |
|
| 2867 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
| 2868 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 2869 | + $classname = 'EE_' . $model->get_this_model_name(); |
|
| 2870 | + if ( |
|
| 2871 | + $this->get_one_from_cache($relation_name) instanceof $classname |
|
| 2872 | + && $this->get_one_from_cache($relation_name)->ID() |
|
| 2873 | + ) { |
|
| 2874 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
| 2875 | + } |
|
| 2876 | + } |
|
| 2877 | + } |
|
| 2878 | + $this->_props_n_values_provided_in_constructor = array(); |
|
| 2879 | + $properties_to_serialize = get_object_vars($this); |
|
| 2880 | + //don't serialize the model. It's big and that risks recursion |
|
| 2881 | + unset($properties_to_serialize['_model']); |
|
| 2882 | + return array_keys($properties_to_serialize); |
|
| 2883 | + } |
|
| 2884 | + |
|
| 2885 | + |
|
| 2886 | + |
|
| 2887 | + /** |
|
| 2888 | + * restore _props_n_values_provided_in_constructor |
|
| 2889 | + * PLZ NOTE: this will reset the array to whatever fields values were present prior to serialization, |
|
| 2890 | + * and therefore should NOT be used to determine if state change has occurred since initial construction. |
|
| 2891 | + * At best, you would only be able to detect if state change has occurred during THIS request. |
|
| 2892 | + */ |
|
| 2893 | + public function __wakeup() |
|
| 2894 | + { |
|
| 2895 | + $this->_props_n_values_provided_in_constructor = $this->_fields; |
|
| 2896 | + } |
|
| 2897 | 2897 | |
| 2898 | 2898 | |
| 2899 | 2899 | |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | list($this->_dt_frmt, $this->_tm_frmt) = $date_formats; |
| 168 | 168 | } else { |
| 169 | 169 | //set default formats for date and time |
| 170 | - $this->_dt_frmt = (string)get_option('date_format', 'Y-m-d'); |
|
| 171 | - $this->_tm_frmt = (string)get_option('time_format', 'g:i a'); |
|
| 170 | + $this->_dt_frmt = (string) get_option('date_format', 'Y-m-d'); |
|
| 171 | + $this->_tm_frmt = (string) get_option('time_format', 'g:i a'); |
|
| 172 | 172 | } |
| 173 | 173 | //if db model is instantiating |
| 174 | 174 | if ($bydb) { |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | */ |
| 495 | 495 | public function get_format($full = true) |
| 496 | 496 | { |
| 497 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 497 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -603,7 +603,7 @@ discard block |
||
| 603 | 603 | $model = $this->get_model(); |
| 604 | 604 | $model->field_settings_for($fieldname); |
| 605 | 605 | $cache_type = $pretty ? 'pretty' : 'standard'; |
| 606 | - $cache_type .= ! empty($extra_cache_ref) ? '_' . $extra_cache_ref : ''; |
|
| 606 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
| 607 | 607 | if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
| 608 | 608 | return $this->_cached_properties[$fieldname][$cache_type]; |
| 609 | 609 | } |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | $current_cache_id = '' |
| 833 | 833 | ) { |
| 834 | 834 | // verify that incoming object is of the correct type |
| 835 | - $obj_class = 'EE_' . $relationName; |
|
| 835 | + $obj_class = 'EE_'.$relationName; |
|
| 836 | 836 | if ($newly_saved_object instanceof $obj_class) { |
| 837 | 837 | /* @type EE_Base_Class $newly_saved_object */ |
| 838 | 838 | // now get the type of relation |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | public function get_raw($field_name) |
| 1095 | 1095 | { |
| 1096 | 1096 | $field_settings = $this->get_model()->field_settings_for($field_name); |
| 1097 | - switch(true){ |
|
| 1097 | + switch (true) { |
|
| 1098 | 1098 | case $field_settings instanceof EE_Datetime_Field && $this->_fields[$field_name] instanceof DateTime: |
| 1099 | 1099 | $value = $this->_fields[$field_name]->format('U'); |
| 1100 | 1100 | break; |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | $this->verifyUsesMoney(__FUNCTION__); |
| 1160 | 1160 | $field = $this->get_model()->field_settings_for($field_name); |
| 1161 | 1161 | $value = isset($this->_fields[$field_name]) ? $this->_fields[$field_name] : null; |
| 1162 | - if (! $field instanceof EE_Money_Field |
|
| 1162 | + if ( ! $field instanceof EE_Money_Field |
|
| 1163 | 1163 | || ! $value instanceof Money) { |
| 1164 | 1164 | throw new InvalidEntityException( |
| 1165 | 1165 | get_class($value), |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | */ |
| 1222 | 1222 | public function get_f($field_name) |
| 1223 | 1223 | { |
| 1224 | - return (string)$this->get_pretty($field_name,'form_input'); |
|
| 1224 | + return (string) $this->get_pretty($field_name, 'form_input'); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | 1227 | |
@@ -1380,7 +1380,7 @@ discard block |
||
| 1380 | 1380 | */ |
| 1381 | 1381 | public function get_i18n_datetime($field_name, $format = '') |
| 1382 | 1382 | { |
| 1383 | - $format = empty($format) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
| 1383 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
| 1384 | 1384 | return date_i18n( |
| 1385 | 1385 | $format, |
| 1386 | 1386 | EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone) |
@@ -1522,8 +1522,8 @@ discard block |
||
| 1522 | 1522 | } |
| 1523 | 1523 | $original_timezone = $this->_timezone; |
| 1524 | 1524 | $this->set_timezone($timezone); |
| 1525 | - $fn = (array)$field_name; |
|
| 1526 | - $args = array_merge($fn, (array)$args); |
|
| 1525 | + $fn = (array) $field_name; |
|
| 1526 | + $args = array_merge($fn, (array) $args); |
|
| 1527 | 1527 | if ( ! method_exists($this, $callback)) { |
| 1528 | 1528 | throw new EE_Error( |
| 1529 | 1529 | sprintf( |
@@ -1535,8 +1535,8 @@ discard block |
||
| 1535 | 1535 | ) |
| 1536 | 1536 | ); |
| 1537 | 1537 | } |
| 1538 | - $args = (array)$args; |
|
| 1539 | - $return = $prepend . call_user_func_array(array($this, $callback), $args) . $append; |
|
| 1538 | + $args = (array) $args; |
|
| 1539 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
| 1540 | 1540 | $this->set_timezone($original_timezone); |
| 1541 | 1541 | return $return; |
| 1542 | 1542 | } |
@@ -1675,14 +1675,14 @@ discard block |
||
| 1675 | 1675 | * @param array $set_cols_n_values |
| 1676 | 1676 | * @param EE_Base_Class $model_object |
| 1677 | 1677 | */ |
| 1678 | - $set_cols_n_values = (array)apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1678 | + $set_cols_n_values = (array) apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, |
|
| 1679 | 1679 | $this); |
| 1680 | 1680 | //set attributes as provided in $set_cols_n_values |
| 1681 | 1681 | foreach ($set_cols_n_values as $column => $value) { |
| 1682 | 1682 | $this->set($column, $value); |
| 1683 | 1683 | } |
| 1684 | 1684 | // no changes ? then don't do anything |
| 1685 | - if (! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 1685 | + if ( ! $this->_has_changes && $this->ID() && $model->get_primary_key_field()->is_auto_increment()) { |
|
| 1686 | 1686 | return 0; |
| 1687 | 1687 | } |
| 1688 | 1688 | /** |
@@ -1734,8 +1734,8 @@ discard block |
||
| 1734 | 1734 | __('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', |
| 1735 | 1735 | 'event_espresso'), |
| 1736 | 1736 | get_class($this), |
| 1737 | - get_class($model) . '::instance()->add_to_entity_map()', |
|
| 1738 | - get_class($model) . '::instance()->get_one_by_ID()', |
|
| 1737 | + get_class($model).'::instance()->add_to_entity_map()', |
|
| 1738 | + get_class($model).'::instance()->get_one_by_ID()', |
|
| 1739 | 1739 | '<br />' |
| 1740 | 1740 | ) |
| 1741 | 1741 | ); |
@@ -1868,7 +1868,7 @@ discard block |
||
| 1868 | 1868 | */ |
| 1869 | 1869 | public function get_model() |
| 1870 | 1870 | { |
| 1871 | - if( ! $this->_model){ |
|
| 1871 | + if ( ! $this->_model) { |
|
| 1872 | 1872 | $modelName = self::_get_model_classname(get_class($this)); |
| 1873 | 1873 | $this->_model = self::_get_model_instance_with_name($modelName, $this->_timezone); |
| 1874 | 1874 | } else { |
@@ -2015,7 +2015,7 @@ discard block |
||
| 2015 | 2015 | if (strpos($model_name, "EE_") === 0) { |
| 2016 | 2016 | $model_classname = str_replace("EE_", "EEM_", $model_name); |
| 2017 | 2017 | } else { |
| 2018 | - $model_classname = "EEM_" . $model_name; |
|
| 2018 | + $model_classname = "EEM_".$model_name; |
|
| 2019 | 2019 | } |
| 2020 | 2020 | return $model_classname; |
| 2021 | 2021 | } |
@@ -2402,7 +2402,7 @@ discard block |
||
| 2402 | 2402 | */ |
| 2403 | 2403 | protected function _property_exists($properties) |
| 2404 | 2404 | { |
| 2405 | - foreach ((array)$properties as $property_name) { |
|
| 2405 | + foreach ((array) $properties as $property_name) { |
|
| 2406 | 2406 | //first make sure this property exists |
| 2407 | 2407 | if ( ! $this->_fields[$property_name]) { |
| 2408 | 2408 | throw new EE_Error( |
@@ -2742,8 +2742,8 @@ discard block |
||
| 2742 | 2742 | __('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.', |
| 2743 | 2743 | 'event_espresso'), |
| 2744 | 2744 | $this->ID(), |
| 2745 | - get_class($this->get_model()) . '::instance()->add_to_entity_map()', |
|
| 2746 | - get_class($this->get_model()) . '::instance()->refresh_entity_map()' |
|
| 2745 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
| 2746 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
| 2747 | 2747 | ) |
| 2748 | 2748 | ); |
| 2749 | 2749 | } |
@@ -2780,7 +2780,7 @@ discard block |
||
| 2780 | 2780 | * @throws EE_Error |
| 2781 | 2781 | * @throws DomainException |
| 2782 | 2782 | */ |
| 2783 | - public function setMoneySubunits($money_field_name,$amount_in_subunits) |
|
| 2783 | + public function setMoneySubunits($money_field_name, $amount_in_subunits) |
|
| 2784 | 2784 | { |
| 2785 | 2785 | $this->verifyUsesMoney(__FUNCTION__); |
| 2786 | 2786 | $money = $this->money_factory->createFromSubUnits( |
@@ -2798,7 +2798,7 @@ discard block |
||
| 2798 | 2798 | */ |
| 2799 | 2799 | private function verifyUsesMoney($function) |
| 2800 | 2800 | { |
| 2801 | - if (! $this instanceof UsesMoneyInterface) { |
|
| 2801 | + if ( ! $this instanceof UsesMoneyInterface) { |
|
| 2802 | 2802 | throw new DomainException( |
| 2803 | 2803 | sprintf( |
| 2804 | 2804 | esc_html__( |
@@ -2866,7 +2866,7 @@ discard block |
||
| 2866 | 2866 | $model = $this->get_model(); |
| 2867 | 2867 | foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
| 2868 | 2868 | if ($relation_obj instanceof EE_Belongs_To_Relation) { |
| 2869 | - $classname = 'EE_' . $model->get_this_model_name(); |
|
| 2869 | + $classname = 'EE_'.$model->get_this_model_name(); |
|
| 2870 | 2870 | if ( |
| 2871 | 2871 | $this->get_one_from_cache($relation_name) instanceof $classname |
| 2872 | 2872 | && $this->get_one_from_cache($relation_name)->ID() |