@@ -33,14 +33,14 @@ |
||
33 | 33 | * @return array |
34 | 34 | */ |
35 | 35 | function get_jquery_validation_rule_array(){ |
36 | - return array( |
|
37 | - 'number'=>true, |
|
38 | - 'step' => 1, |
|
39 | - 'messages' => array( |
|
40 | - 'number' => $this->get_validation_error_message(), |
|
41 | - 'step' => $this->get_validation_error_message() |
|
42 | - ) |
|
43 | - ); |
|
36 | + return array( |
|
37 | + 'number'=>true, |
|
38 | + 'step' => 1, |
|
39 | + 'messages' => array( |
|
40 | + 'number' => $this->get_validation_error_message(), |
|
41 | + 'step' => $this->get_validation_error_message() |
|
42 | + ) |
|
43 | + ); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | * @subpackage Expression package is undefined on line 19, column 19 in Templates/Scripting/PHPClass.php. |
7 | 7 | * @author Mike Nelson |
8 | 8 | */ |
9 | -class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base{ |
|
9 | +class EE_Int_Validation_Strategy extends EE_Validation_Strategy_Base { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @param null $validation_error_message |
13 | 13 | */ |
14 | - public function __construct( $validation_error_message = NULL ) { |
|
15 | - if( ! $validation_error_message ){ |
|
14 | + public function __construct($validation_error_message = NULL) { |
|
15 | + if ( ! $validation_error_message) { |
|
16 | 16 | $validation_error_message = __("Only digits are allowed.", "event_espresso"); |
17 | 17 | } |
18 | - parent::__construct( $validation_error_message ); |
|
18 | + parent::__construct($validation_error_message); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - function get_jquery_validation_rule_array(){ |
|
35 | + function get_jquery_validation_rule_array() { |
|
36 | 36 | return array( |
37 | 37 | 'number'=>true, |
38 | 38 | 'step' => 1, |
@@ -8,62 +8,62 @@ discard block |
||
8 | 8 | */ |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
10 | 10 | /** |
11 | - * |
|
12 | - * Money helper class. |
|
13 | - * This class has helper methods that help with money related conversions and calculations. |
|
14 | - * |
|
15 | - * @since %VER% |
|
16 | - * |
|
17 | - * @package Event Espresso |
|
18 | - * @subpackage helpers |
|
19 | - * @author Darren Ethier |
|
20 | - * |
|
21 | - * ------------------------------------------------------------------------ |
|
22 | - */ |
|
11 | + * |
|
12 | + * Money helper class. |
|
13 | + * This class has helper methods that help with money related conversions and calculations. |
|
14 | + * |
|
15 | + * @since %VER% |
|
16 | + * |
|
17 | + * @package Event Espresso |
|
18 | + * @subpackage helpers |
|
19 | + * @author Darren Ethier |
|
20 | + * |
|
21 | + * ------------------------------------------------------------------------ |
|
22 | + */ |
|
23 | 23 | class EEH_Money extends EEH_Base { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * This removes all localized money formatting from the incoming value |
|
28 | - * |
|
29 | - * @param int|float|string $money_value |
|
30 | - * @param string $CNT_ISO |
|
31 | - * @return float |
|
32 | - * @throws EE_Error |
|
33 | - */ |
|
26 | + /** |
|
27 | + * This removes all localized money formatting from the incoming value |
|
28 | + * |
|
29 | + * @param int|float|string $money_value |
|
30 | + * @param string $CNT_ISO |
|
31 | + * @return float |
|
32 | + * @throws EE_Error |
|
33 | + */ |
|
34 | 34 | public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') { |
35 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
36 | - $money_value = str_replace( |
|
37 | - array( |
|
38 | - $currency_config->thsnds, |
|
39 | - $currency_config->dec_mrk, |
|
40 | - ), |
|
41 | - array( |
|
42 | - '', // remove thousands separator |
|
43 | - '.', // convert decimal mark to what PHP expects |
|
44 | - ), |
|
45 | - $money_value |
|
46 | - ); |
|
47 | - $money_value = filter_var( |
|
48 | - $money_value, |
|
49 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
50 | - FILTER_FLAG_ALLOW_FRACTION |
|
51 | - ); |
|
52 | - return $money_value; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
59 | - * |
|
60 | - * @param int|string $money_value |
|
61 | - * @return float |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
35 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
36 | + $money_value = str_replace( |
|
37 | + array( |
|
38 | + $currency_config->thsnds, |
|
39 | + $currency_config->dec_mrk, |
|
40 | + ), |
|
41 | + array( |
|
42 | + '', // remove thousands separator |
|
43 | + '.', // convert decimal mark to what PHP expects |
|
44 | + ), |
|
45 | + $money_value |
|
46 | + ); |
|
47 | + $money_value = filter_var( |
|
48 | + $money_value, |
|
49 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
50 | + FILTER_FLAG_ALLOW_FRACTION |
|
51 | + ); |
|
52 | + return $money_value; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
59 | + * |
|
60 | + * @param int|string $money_value |
|
61 | + * @return float |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | 64 | public static function convert_to_float_from_localized_money($money_value ) { |
65 | 65 | //float it! and round to three decimal places |
66 | - return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
66 | + return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -151,19 +151,19 @@ discard block |
||
151 | 151 | |
152 | 152 | |
153 | 153 | |
154 | - /** |
|
155 | - * This returns a localized format string suitable for jQplot. |
|
156 | - * |
|
157 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
158 | - * Otherwise will use currency settings for current active country on site. |
|
159 | - * @return string |
|
160 | - * @throws EE_Error |
|
161 | - */ |
|
154 | + /** |
|
155 | + * This returns a localized format string suitable for jQplot. |
|
156 | + * |
|
157 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
158 | + * Otherwise will use currency settings for current active country on site. |
|
159 | + * @return string |
|
160 | + * @throws EE_Error |
|
161 | + */ |
|
162 | 162 | public static function get_format_for_jqplot( $CNT_ISO = '') { |
163 | 163 | //default format |
164 | 164 | $format = 'f'; |
165 | 165 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
166 | - //first get the decimal place and number of places |
|
166 | + //first get the decimal place and number of places |
|
167 | 167 | $format = "%'." . $currency_config->dec_plc . $format; |
168 | 168 | //currency symbol on right side. |
169 | 169 | $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | |
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
177 | - * |
|
178 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
179 | - * Otherwise will use currency settings for current active country on site. |
|
180 | - * Note: GoogleCharts uses ICU pattern set |
|
181 | - * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
182 | - * @return string |
|
183 | - * @throws EE_Error |
|
184 | - */ |
|
175 | + /** |
|
176 | + * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
177 | + * |
|
178 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
179 | + * Otherwise will use currency settings for current active country on site. |
|
180 | + * Note: GoogleCharts uses ICU pattern set |
|
181 | + * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
182 | + * @return string |
|
183 | + * @throws EE_Error |
|
184 | + */ |
|
185 | 185 | public static function get_format_for_google_charts( $CNT_ISO = '' ) { |
186 | 186 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
187 | 187 | $decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' ); |
@@ -208,24 +208,24 @@ discard block |
||
208 | 208 | |
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * @param string $CNT_ISO |
|
213 | - * @return EE_Currency_Config|null |
|
214 | - * @throws EE_Error |
|
215 | - */ |
|
216 | - public static function get_currency_config($CNT_ISO = '') |
|
217 | - { |
|
218 | - //if CNT_ISO passed lets try to get currency settings for it. |
|
219 | - $currency_config = $CNT_ISO !== '' |
|
220 | - ? new EE_Currency_Config($CNT_ISO) |
|
221 | - : null; |
|
222 | - //default currency settings for site if not set |
|
223 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
224 | - $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
225 | - ? EE_Registry::instance()->CFG->currency |
|
226 | - : new EE_Currency_Config(); |
|
227 | - } |
|
228 | - return $currency_config; |
|
229 | - } |
|
211 | + /** |
|
212 | + * @param string $CNT_ISO |
|
213 | + * @return EE_Currency_Config|null |
|
214 | + * @throws EE_Error |
|
215 | + */ |
|
216 | + public static function get_currency_config($CNT_ISO = '') |
|
217 | + { |
|
218 | + //if CNT_ISO passed lets try to get currency settings for it. |
|
219 | + $currency_config = $CNT_ISO !== '' |
|
220 | + ? new EE_Currency_Config($CNT_ISO) |
|
221 | + : null; |
|
222 | + //default currency settings for site if not set |
|
223 | + if (! $currency_config instanceof EE_Currency_Config) { |
|
224 | + $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
225 | + ? EE_Registry::instance()->CFG->currency |
|
226 | + : new EE_Currency_Config(); |
|
227 | + } |
|
228 | + return $currency_config; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | } //end class EEH_Money |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * ------------------------------------------------------------------------ |
22 | 22 | */ |
23 | -class EEH_Money extends EEH_Base { |
|
23 | +class EEH_Money extends EEH_Base { |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @return float |
62 | 62 | * @throws EE_Error |
63 | 63 | */ |
64 | - public static function convert_to_float_from_localized_money($money_value ) { |
|
64 | + public static function convert_to_float_from_localized_money($money_value) { |
|
65 | 65 | //float it! and round to three decimal places |
66 | - return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
66 | + return round((float) EEH_Money::strip_localized_money_formatting($money_value), 3); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | * @throws EE_Error |
83 | 83 | */ |
84 | 84 | |
85 | - public static function compare_floats( $float1, $float2, $operator='=' ) { |
|
85 | + public static function compare_floats($float1, $float2, $operator = '=') { |
|
86 | 86 | // Check numbers to 5 digits of precision |
87 | 87 | $epsilon = 0.00001; |
88 | 88 | |
89 | - $float1 = (float)$float1; |
|
90 | - $float2 = (float)$float2; |
|
89 | + $float1 = (float) $float1; |
|
90 | + $float2 = (float) $float2; |
|
91 | 91 | |
92 | 92 | switch ($operator) { |
93 | 93 | // equal |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | } |
144 | 144 | break; |
145 | 145 | default: |
146 | - throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) ); |
|
146 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso')); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return false; |
@@ -159,14 +159,14 @@ discard block |
||
159 | 159 | * @return string |
160 | 160 | * @throws EE_Error |
161 | 161 | */ |
162 | - public static function get_format_for_jqplot( $CNT_ISO = '') { |
|
162 | + public static function get_format_for_jqplot($CNT_ISO = '') { |
|
163 | 163 | //default format |
164 | 164 | $format = 'f'; |
165 | 165 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
166 | 166 | //first get the decimal place and number of places |
167 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
167 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
168 | 168 | //currency symbol on right side. |
169 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
169 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
170 | 170 | return $format; |
171 | 171 | } |
172 | 172 | |
@@ -182,20 +182,20 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | * @throws EE_Error |
184 | 184 | */ |
185 | - public static function get_format_for_google_charts( $CNT_ISO = '' ) { |
|
185 | + public static function get_format_for_google_charts($CNT_ISO = '') { |
|
186 | 186 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
187 | - $decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' ); |
|
187 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
188 | 188 | //first get the decimal place and number of places |
189 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
189 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
190 | 190 | |
191 | 191 | //currency symbol on right side. |
192 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
192 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
193 | 193 | $formatterObject = array( |
194 | 194 | 'decimalSymbol' => $currency_config->dec_mrk, |
195 | 195 | 'groupingSymbol' => $currency_config->thsnds, |
196 | 196 | 'fractionDigits' => $currency_config->dec_plc, |
197 | 197 | ); |
198 | - if ( $currency_config->sign_b4 ) { |
|
198 | + if ($currency_config->sign_b4) { |
|
199 | 199 | $formatterObject['prefix'] = $currency_config->sign; |
200 | 200 | } else { |
201 | 201 | $formatterObject['suffix'] = $currency_config->sign; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ? new EE_Currency_Config($CNT_ISO) |
221 | 221 | : null; |
222 | 222 | //default currency settings for site if not set |
223 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
223 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
224 | 224 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
225 | 225 | ? EE_Registry::instance()->CFG->currency |
226 | 226 | : new EE_Currency_Config(); |
@@ -217,7 +217,7 @@ |
||
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Used to override the default for the additional limit field. |
220 | - * @param $additional_limit |
|
220 | + * @param integer $additional_limit |
|
221 | 221 | */ |
222 | 222 | public static function set_default_additional_limit($additional_limit) |
223 | 223 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
5 | 5 | |
@@ -16,793 +16,793 @@ discard block |
||
16 | 16 | class EEM_Event extends EEM_CPT_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
21 | - * event |
|
22 | - */ |
|
23 | - const sold_out = 'sold_out'; |
|
24 | - |
|
25 | - /** |
|
26 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
27 | - * date) |
|
28 | - */ |
|
29 | - const postponed = 'postponed'; |
|
30 | - |
|
31 | - /** |
|
32 | - * constant used by status(), indicating that the event will no longer occur |
|
33 | - */ |
|
34 | - const cancelled = 'cancelled'; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected static $_default_reg_status; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This is the default for the additional limit field. |
|
45 | - * @var int |
|
46 | - */ |
|
47 | - protected static $_default_additional_limit = 10; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * private instance of the Event object |
|
52 | - * |
|
53 | - * @var EEM_Event |
|
54 | - */ |
|
55 | - protected static $_instance; |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * This function is a singleton method used to instantiate the EEM_Event object |
|
61 | - * |
|
62 | - * @param string $timezone |
|
63 | - * @return EEM_Event |
|
64 | - * @throws \EE_Error |
|
65 | - */ |
|
66 | - public static function instance($timezone = null) |
|
67 | - { |
|
68 | - // check if instance of EEM_Event already exists |
|
69 | - if (! self::$_instance instanceof EEM_Event) { |
|
70 | - // instantiate Espresso_model |
|
71 | - self::$_instance = new self($timezone); |
|
72 | - } |
|
73 | - //we might have a timezone set, let set_timezone decide what to do with it |
|
74 | - self::$_instance->set_timezone($timezone); |
|
75 | - // EEM_Event object |
|
76 | - return self::$_instance; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
83 | - * |
|
84 | - * @param string $timezone |
|
85 | - * @throws \EE_Error |
|
86 | - */ |
|
87 | - protected function __construct($timezone = null) |
|
88 | - { |
|
89 | - EE_Registry::instance()->load_model('Registration'); |
|
90 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
91 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
92 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
93 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
94 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
95 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
96 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
97 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
98 | - $this->_custom_stati = apply_filters( |
|
99 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
100 | - array( |
|
101 | - EEM_Event::cancelled => array( |
|
102 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
103 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
104 | - ), |
|
105 | - EEM_Event::postponed => array( |
|
106 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
107 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
108 | - ), |
|
109 | - EEM_Event::sold_out => array( |
|
110 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
111 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
112 | - ), |
|
113 | - ) |
|
114 | - ); |
|
115 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
116 | - : self::$_default_reg_status; |
|
117 | - $this->_tables = array( |
|
118 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
119 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
120 | - ); |
|
121 | - $this->_fields = array( |
|
122 | - 'Event_CPT' => array( |
|
123 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
124 | - esc_html__('Post ID for Event', 'event_espresso')), |
|
125 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
126 | - false, |
|
127 | - ''), |
|
128 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
129 | - esc_html__('Event Description', 'event_espresso'), |
|
130 | - false, ''), |
|
131 | - 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
132 | - ''), |
|
133 | - 'EVT_created' => new EE_Datetime_Field('post_date', |
|
134 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
135 | - false, EE_Datetime_Field::now), |
|
136 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
137 | - esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
138 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
139 | - esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
140 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
141 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | - false), |
|
143 | - 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
144 | - false, |
|
145 | - 0), |
|
146 | - 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
147 | - false, |
|
148 | - 1), |
|
149 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
150 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
151 | - 'status' => new EE_WP_Post_Status_Field('post_status', |
|
152 | - esc_html__('Event Status', 'event_espresso'), |
|
153 | - false, 'draft', $this->_custom_stati), |
|
154 | - ), |
|
155 | - 'Event_Meta' => array( |
|
156 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
157 | - esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
158 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
159 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
160 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
161 | - esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
162 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
163 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
164 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
165 | - esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
166 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
167 | - 'EVT_additional_limit', |
|
168 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
169 | - true, |
|
170 | - self::$_default_additional_limit |
|
171 | - ), |
|
172 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
173 | - 'EVT_default_registration_status', |
|
174 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
175 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
176 | - ), |
|
177 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
178 | - esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
179 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
180 | - esc_html__('Event Phone Number', 'event_espresso'), false), |
|
181 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
182 | - esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
183 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
184 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false), |
|
185 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
186 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
187 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
188 | - esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
189 | - ), |
|
190 | - ); |
|
191 | - $this->_model_relations = array( |
|
192 | - 'Registration' => new EE_Has_Many_Relation(), |
|
193 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
194 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
195 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
196 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
197 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
198 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
199 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
200 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
201 | - ); |
|
202 | - //this model is generally available for reading |
|
203 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
204 | - parent::__construct($timezone); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @param string $default_reg_status |
|
211 | - */ |
|
212 | - public static function set_default_reg_status($default_reg_status) |
|
213 | - { |
|
214 | - self::$_default_reg_status = $default_reg_status; |
|
215 | - // if EEM_Event has already been instantiated, |
|
216 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
217 | - if (self::$_instance instanceof EEM_Event) { |
|
218 | - $default_reg_status = new EE_Enum_Text_Field( |
|
219 | - 'EVT_default_registration_status', |
|
220 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
221 | - false, |
|
222 | - $default_reg_status, |
|
223 | - EEM_Registration::reg_status_array() |
|
224 | - ); |
|
225 | - $default_reg_status->_construct_finalize( |
|
226 | - 'Event_Meta', |
|
227 | - 'EVT_default_registration_status', |
|
228 | - 'EEM_Event' |
|
229 | - ); |
|
230 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Used to override the default for the additional limit field. |
|
237 | - * @param $additional_limit |
|
238 | - */ |
|
239 | - public static function set_default_additional_limit($additional_limit) |
|
240 | - { |
|
241 | - self::$_default_additional_limit = (int) $additional_limit; |
|
242 | - if (self::$_instance instanceof EEM_Event) { |
|
243 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
244 | - 'EVT_additional_limit', |
|
245 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
246 | - true, |
|
247 | - self::$_default_additional_limit |
|
248 | - ); |
|
249 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
250 | - 'Event_Meta', |
|
251 | - 'EVT_additional_limit', |
|
252 | - 'EEM_Event' |
|
253 | - ); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Return what is currently set as the default additional limit for the event. |
|
260 | - * @return int |
|
261 | - */ |
|
262 | - public static function get_default_additional_limit() |
|
263 | - { |
|
264 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * get_question_groups |
|
270 | - * |
|
271 | - * @return array |
|
272 | - * @throws \EE_Error |
|
273 | - */ |
|
274 | - public function get_all_question_groups() |
|
275 | - { |
|
276 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
277 | - array( |
|
278 | - array('QSG_deleted' => false), |
|
279 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * get_question_groups |
|
288 | - * |
|
289 | - * @param int $EVT_ID |
|
290 | - * @return array|bool |
|
291 | - * @throws \EE_Error |
|
292 | - */ |
|
293 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
294 | - { |
|
295 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
296 | - EE_Error::add_error( |
|
297 | - esc_html__( |
|
298 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - __FILE__, __FUNCTION__, __LINE__ |
|
302 | - ); |
|
303 | - return false; |
|
304 | - } |
|
305 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
306 | - array( |
|
307 | - array('EVT_ID' => $EVT_ID), |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * get_question_groups |
|
316 | - * |
|
317 | - * @param int $EVT_ID |
|
318 | - * @param boolean $for_primary_attendee |
|
319 | - * @return array|bool |
|
320 | - * @throws \EE_Error |
|
321 | - */ |
|
322 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
323 | - { |
|
324 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
325 | - EE_Error::add_error( |
|
326 | - esc_html__( |
|
327 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
328 | - 'event_espresso' |
|
329 | - ), |
|
330 | - __FILE__, __FUNCTION__, __LINE__ |
|
331 | - ); |
|
332 | - return false; |
|
333 | - } |
|
334 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
335 | - array( |
|
336 | - array( |
|
337 | - 'EVT_ID' => $EVT_ID, |
|
338 | - 'EQG_primary' => $for_primary_attendee, |
|
339 | - ), |
|
340 | - ) |
|
341 | - ); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * get_question_groups |
|
348 | - * |
|
349 | - * @param int $EVT_ID |
|
350 | - * @param EE_Registration $registration |
|
351 | - * @return array|bool |
|
352 | - * @throws \EE_Error |
|
353 | - */ |
|
354 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
355 | - { |
|
356 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
357 | - EE_Error::add_error( |
|
358 | - esc_html__( |
|
359 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - __FILE__, __FUNCTION__, __LINE__ |
|
363 | - ); |
|
364 | - return false; |
|
365 | - } |
|
366 | - $where_params = array( |
|
367 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
368 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
369 | - 'QSG_deleted' => false, |
|
370 | - ); |
|
371 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | - array( |
|
373 | - $where_params, |
|
374 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | - ) |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * get_question_target_db_column |
|
383 | - * |
|
384 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
385 | - * @return array|bool |
|
386 | - * @throws \EE_Error |
|
387 | - */ |
|
388 | - public function get_questions_in_groups($QSG_IDs = '') |
|
389 | - { |
|
390 | - if (empty($QSG_IDs)) { |
|
391 | - EE_Error::add_error( |
|
392 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
393 | - __FILE__, __FUNCTION__, __LINE__ |
|
394 | - ); |
|
395 | - return false; |
|
396 | - } |
|
397 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
398 | - array( |
|
399 | - array( |
|
400 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
401 | - 'QST_deleted' => false, |
|
402 | - 'QST_admin_only' => is_admin(), |
|
403 | - ), |
|
404 | - 'order_by' => 'QST_order', |
|
405 | - ) |
|
406 | - ); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * get_options_for_question |
|
413 | - * |
|
414 | - * @param string $QST_IDs csv list of $QST IDs |
|
415 | - * @return array|bool |
|
416 | - * @throws \EE_Error |
|
417 | - */ |
|
418 | - public function get_options_for_question($QST_IDs) |
|
419 | - { |
|
420 | - if (empty($QST_IDs)) { |
|
421 | - EE_Error::add_error( |
|
422 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
423 | - __FILE__, __FUNCTION__, __LINE__ |
|
424 | - ); |
|
425 | - return false; |
|
426 | - } |
|
427 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
428 | - array( |
|
429 | - array( |
|
430 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
431 | - 'QSO_deleted' => false, |
|
432 | - ), |
|
433 | - 'order_by' => 'QSO_ID', |
|
434 | - ) |
|
435 | - ); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets all events that are published |
|
446 | - * and have event start time earlier than now and an event end time later than now |
|
447 | - * |
|
448 | - * @param array $query_params An array of query params to further filter on |
|
449 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
450 | - * @param bool $count whether to return the count or not (default FALSE) |
|
451 | - * @return EE_Event[]|int |
|
452 | - * @throws \EE_Error |
|
453 | - */ |
|
454 | - public function get_active_events($query_params, $count = false) |
|
455 | - { |
|
456 | - if (array_key_exists(0, $query_params)) { |
|
457 | - $where_params = $query_params[0]; |
|
458 | - unset($query_params[0]); |
|
459 | - } else { |
|
460 | - $where_params = array(); |
|
461 | - } |
|
462 | - // if we have count make sure we don't include group by |
|
463 | - if ($count && isset($query_params['group_by'])) { |
|
464 | - unset($query_params['group_by']); |
|
465 | - } |
|
466 | - // let's add specific query_params for active_events |
|
467 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
468 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
469 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
470 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
471 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
472 | - '<', |
|
473 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
474 | - ); |
|
475 | - } else { |
|
476 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
477 | - '<', |
|
478 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
479 | - ); |
|
480 | - } |
|
481 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
482 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
483 | - '>', |
|
484 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
485 | - ); |
|
486 | - } else { |
|
487 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
488 | - '>', |
|
489 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
490 | - ); |
|
491 | - } |
|
492 | - $query_params[0] = $where_params; |
|
493 | - // don't use $query_params with count() |
|
494 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
495 | - return $count |
|
496 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
497 | - : $this->get_all($query_params); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * get all events that are published and have an event start time later than now |
|
504 | - * |
|
505 | - * @param array $query_params An array of query params to further filter on |
|
506 | - * (Note that status and DTT_EVT_start will be overridden) |
|
507 | - * @param bool $count whether to return the count or not (default FALSE) |
|
508 | - * @return EE_Event[]|int |
|
509 | - * @throws \EE_Error |
|
510 | - */ |
|
511 | - public function get_upcoming_events($query_params, $count = false) |
|
512 | - { |
|
513 | - if (array_key_exists(0, $query_params)) { |
|
514 | - $where_params = $query_params[0]; |
|
515 | - unset($query_params[0]); |
|
516 | - } else { |
|
517 | - $where_params = array(); |
|
518 | - } |
|
519 | - // if we have count make sure we don't include group by |
|
520 | - if ($count && isset($query_params['group_by'])) { |
|
521 | - unset($query_params['group_by']); |
|
522 | - } |
|
523 | - // let's add specific query_params for active_events |
|
524 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
525 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
526 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
527 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
528 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
529 | - '>', |
|
530 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
531 | - ); |
|
532 | - } else { |
|
533 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
534 | - '>', |
|
535 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
536 | - ); |
|
537 | - } |
|
538 | - $query_params[0] = $where_params; |
|
539 | - // don't use $query_params with count() |
|
540 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
541 | - return $count |
|
542 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
543 | - : $this->get_all($query_params); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * Gets all events that are published |
|
550 | - * and have an event end time later than now |
|
551 | - * |
|
552 | - * @param array $query_params An array of query params to further filter on |
|
553 | - * (note that status and DTT_EVT_end will be overridden) |
|
554 | - * @param bool $count whether to return the count or not (default FALSE) |
|
555 | - * @return EE_Event[]|int |
|
556 | - * @throws \EE_Error |
|
557 | - */ |
|
558 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
559 | - { |
|
560 | - if (array_key_exists(0, $query_params)) { |
|
561 | - $where_params = $query_params[0]; |
|
562 | - unset($query_params[0]); |
|
563 | - } else { |
|
564 | - $where_params = array(); |
|
565 | - } |
|
566 | - // if we have count make sure we don't include group by |
|
567 | - if ($count && isset($query_params['group_by'])) { |
|
568 | - unset($query_params['group_by']); |
|
569 | - } |
|
570 | - // let's add specific query_params for active_events |
|
571 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
572 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
573 | - // add where params for DTT_EVT_end |
|
574 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
575 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
576 | - '>', |
|
577 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
578 | - ); |
|
579 | - } else { |
|
580 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
581 | - '>', |
|
582 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | - ); |
|
584 | - } |
|
585 | - $query_params[0] = $where_params; |
|
586 | - // don't use $query_params with count() |
|
587 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
588 | - return $count |
|
589 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
590 | - : $this->get_all($query_params); |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * This only returns events that are expired. |
|
597 | - * They may still be published but all their datetimes have expired. |
|
598 | - * |
|
599 | - * @param array $query_params An array of query params to further filter on |
|
600 | - * (note that status and DTT_EVT_end will be overridden) |
|
601 | - * @param bool $count whether to return the count or not (default FALSE) |
|
602 | - * @return EE_Event[]|int |
|
603 | - * @throws \EE_Error |
|
604 | - */ |
|
605 | - public function get_expired_events($query_params, $count = false) |
|
606 | - { |
|
607 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
608 | - // if we have count make sure we don't include group by |
|
609 | - if ($count && isset($query_params['group_by'])) { |
|
610 | - unset($query_params['group_by']); |
|
611 | - } |
|
612 | - // let's add specific query_params for active_events |
|
613 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
614 | - if (isset($where_params['status'])) { |
|
615 | - unset($where_params['status']); |
|
616 | - } |
|
617 | - $exclude_query = $query_params; |
|
618 | - if (isset($exclude_query[0])) { |
|
619 | - unset($exclude_query[0]); |
|
620 | - } |
|
621 | - $exclude_query[0] = array( |
|
622 | - 'Datetime.DTT_EVT_end' => array( |
|
623 | - '>', |
|
624 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
625 | - ), |
|
626 | - ); |
|
627 | - // first get all events that have datetimes where its not expired. |
|
628 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
629 | - $event_ids = array_keys($event_ids); |
|
630 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
631 | - $and_condition = array( |
|
632 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
633 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
634 | - ); |
|
635 | - if (isset($where_params['OR'])) { |
|
636 | - $and_condition['OR'] = $where_params['OR']; |
|
637 | - unset($where_params['OR']); |
|
638 | - } |
|
639 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
640 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
641 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
642 | - } |
|
643 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
644 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
645 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
646 | - } |
|
647 | - // merge remaining $where params with the and conditions. |
|
648 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
649 | - $query_params[0] = $where_params; |
|
650 | - // don't use $query_params with count() |
|
651 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
652 | - return $count |
|
653 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
654 | - : $this->get_all($query_params); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * This basically just returns the events that do not have the publish status. |
|
661 | - * |
|
662 | - * @param array $query_params An array of query params to further filter on |
|
663 | - * (note that status will be overwritten) |
|
664 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
665 | - * @return EE_Event[]|int |
|
666 | - * @throws \EE_Error |
|
667 | - */ |
|
668 | - public function get_inactive_events($query_params, $count = false) |
|
669 | - { |
|
670 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
671 | - // let's add in specific query_params for inactive events. |
|
672 | - if (isset($where_params['status'])) { |
|
673 | - unset($where_params['status']); |
|
674 | - } |
|
675 | - // if we have count make sure we don't include group by |
|
676 | - if ($count && isset($query_params['group_by'])) { |
|
677 | - unset($query_params['group_by']); |
|
678 | - } |
|
679 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
680 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
681 | - if (isset($where_params['OR'])) { |
|
682 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
683 | - unset($where_params['OR']); |
|
684 | - } |
|
685 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
686 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
687 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
688 | - } |
|
689 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
690 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
691 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
692 | - } |
|
693 | - $query_params[0] = $where_params; |
|
694 | - // don't use $query_params with count() |
|
695 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
696 | - return $count |
|
697 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
698 | - : $this->get_all($query_params); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
705 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
706 | - * attached to the event. See parent for param descriptions |
|
707 | - * |
|
708 | - * @param $id_or_obj |
|
709 | - * @param $other_model_id_or_obj |
|
710 | - * @param string $relationName |
|
711 | - * @param array $where_query |
|
712 | - * @return EE_Base_Class |
|
713 | - * @throws EE_Error |
|
714 | - */ |
|
715 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
716 | - { |
|
717 | - if ($relationName === 'Price') { |
|
718 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
719 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
720 | - //if EVT_ID = 0, then this is a default |
|
721 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
722 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
723 | - $prc_chk->set('PRC_ID', 0); |
|
724 | - } |
|
725 | - //run parent |
|
726 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
727 | - } |
|
728 | - //otherwise carry on as normal |
|
729 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - |
|
734 | - /******************** DEPRECATED METHODS ********************/ |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * _get_question_target_db_column |
|
740 | - * |
|
741 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
742 | - * EE_Registration_Custom_Questions_Form located in |
|
743 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
744 | - * @access public |
|
745 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
746 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
747 | - * registration). |
|
748 | - * @throws EE_Error |
|
749 | - * @return array |
|
750 | - */ |
|
751 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
752 | - { |
|
753 | - if (empty($EVT_ID)) { |
|
754 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
755 | - 'event_espresso')); |
|
756 | - } |
|
757 | - $questions = array(); |
|
758 | - // get all question groups for event |
|
759 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
760 | - if (! empty($qgs)) { |
|
761 | - foreach ($qgs as $qg) { |
|
762 | - $qsts = $qg->questions(); |
|
763 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
764 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
765 | - foreach ($qsts as $qst) { |
|
766 | - if ($qst->is_system_question()) { |
|
767 | - continue; |
|
768 | - } |
|
769 | - $answer = EEM_Answer::instance()->get_one(array( |
|
770 | - array( |
|
771 | - 'QST_ID' => $qst->ID(), |
|
772 | - 'REG_ID' => $registration->ID(), |
|
773 | - ), |
|
774 | - )); |
|
775 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
776 | - $qst_name = $qstn_id = $qst->ID(); |
|
777 | - $ans_id = $answer->ID(); |
|
778 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
779 | - $input_name = ''; |
|
780 | - $input_id = sanitize_key($qst->display_text()); |
|
781 | - $input_class = ''; |
|
782 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
783 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
784 | - . $input_name |
|
785 | - . $qst_name; |
|
786 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
787 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
788 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
789 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
790 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
791 | - //leave responses as-is, don't convert stuff into html entities please! |
|
792 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
793 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
794 | - $QSOs = $qst->options(true, $answer->value()); |
|
795 | - if (is_array($QSOs)) { |
|
796 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
797 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
798 | - } |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - } |
|
804 | - return $questions; |
|
805 | - } |
|
19 | + /** |
|
20 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
21 | + * event |
|
22 | + */ |
|
23 | + const sold_out = 'sold_out'; |
|
24 | + |
|
25 | + /** |
|
26 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
27 | + * date) |
|
28 | + */ |
|
29 | + const postponed = 'postponed'; |
|
30 | + |
|
31 | + /** |
|
32 | + * constant used by status(), indicating that the event will no longer occur |
|
33 | + */ |
|
34 | + const cancelled = 'cancelled'; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected static $_default_reg_status; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This is the default for the additional limit field. |
|
45 | + * @var int |
|
46 | + */ |
|
47 | + protected static $_default_additional_limit = 10; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * private instance of the Event object |
|
52 | + * |
|
53 | + * @var EEM_Event |
|
54 | + */ |
|
55 | + protected static $_instance; |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * This function is a singleton method used to instantiate the EEM_Event object |
|
61 | + * |
|
62 | + * @param string $timezone |
|
63 | + * @return EEM_Event |
|
64 | + * @throws \EE_Error |
|
65 | + */ |
|
66 | + public static function instance($timezone = null) |
|
67 | + { |
|
68 | + // check if instance of EEM_Event already exists |
|
69 | + if (! self::$_instance instanceof EEM_Event) { |
|
70 | + // instantiate Espresso_model |
|
71 | + self::$_instance = new self($timezone); |
|
72 | + } |
|
73 | + //we might have a timezone set, let set_timezone decide what to do with it |
|
74 | + self::$_instance->set_timezone($timezone); |
|
75 | + // EEM_Event object |
|
76 | + return self::$_instance; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
83 | + * |
|
84 | + * @param string $timezone |
|
85 | + * @throws \EE_Error |
|
86 | + */ |
|
87 | + protected function __construct($timezone = null) |
|
88 | + { |
|
89 | + EE_Registry::instance()->load_model('Registration'); |
|
90 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
91 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
92 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
93 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
94 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
95 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
96 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
97 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
98 | + $this->_custom_stati = apply_filters( |
|
99 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
100 | + array( |
|
101 | + EEM_Event::cancelled => array( |
|
102 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
103 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
104 | + ), |
|
105 | + EEM_Event::postponed => array( |
|
106 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
107 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
108 | + ), |
|
109 | + EEM_Event::sold_out => array( |
|
110 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
111 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
112 | + ), |
|
113 | + ) |
|
114 | + ); |
|
115 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
116 | + : self::$_default_reg_status; |
|
117 | + $this->_tables = array( |
|
118 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
119 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
120 | + ); |
|
121 | + $this->_fields = array( |
|
122 | + 'Event_CPT' => array( |
|
123 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
124 | + esc_html__('Post ID for Event', 'event_espresso')), |
|
125 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
126 | + false, |
|
127 | + ''), |
|
128 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
129 | + esc_html__('Event Description', 'event_espresso'), |
|
130 | + false, ''), |
|
131 | + 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
132 | + ''), |
|
133 | + 'EVT_created' => new EE_Datetime_Field('post_date', |
|
134 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
135 | + false, EE_Datetime_Field::now), |
|
136 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
137 | + esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
138 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
139 | + esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
140 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
141 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | + false), |
|
143 | + 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
144 | + false, |
|
145 | + 0), |
|
146 | + 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
147 | + false, |
|
148 | + 1), |
|
149 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
150 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
151 | + 'status' => new EE_WP_Post_Status_Field('post_status', |
|
152 | + esc_html__('Event Status', 'event_espresso'), |
|
153 | + false, 'draft', $this->_custom_stati), |
|
154 | + ), |
|
155 | + 'Event_Meta' => array( |
|
156 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
157 | + esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
158 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
159 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
160 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
161 | + esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
162 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
163 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
164 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
165 | + esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
166 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
167 | + 'EVT_additional_limit', |
|
168 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
169 | + true, |
|
170 | + self::$_default_additional_limit |
|
171 | + ), |
|
172 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
173 | + 'EVT_default_registration_status', |
|
174 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
175 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
176 | + ), |
|
177 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
178 | + esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
179 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
180 | + esc_html__('Event Phone Number', 'event_espresso'), false), |
|
181 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
182 | + esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
183 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
184 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false), |
|
185 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
186 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
187 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
188 | + esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
189 | + ), |
|
190 | + ); |
|
191 | + $this->_model_relations = array( |
|
192 | + 'Registration' => new EE_Has_Many_Relation(), |
|
193 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
194 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
195 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
196 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
197 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
198 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
199 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
200 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
201 | + ); |
|
202 | + //this model is generally available for reading |
|
203 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
204 | + parent::__construct($timezone); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @param string $default_reg_status |
|
211 | + */ |
|
212 | + public static function set_default_reg_status($default_reg_status) |
|
213 | + { |
|
214 | + self::$_default_reg_status = $default_reg_status; |
|
215 | + // if EEM_Event has already been instantiated, |
|
216 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
217 | + if (self::$_instance instanceof EEM_Event) { |
|
218 | + $default_reg_status = new EE_Enum_Text_Field( |
|
219 | + 'EVT_default_registration_status', |
|
220 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
221 | + false, |
|
222 | + $default_reg_status, |
|
223 | + EEM_Registration::reg_status_array() |
|
224 | + ); |
|
225 | + $default_reg_status->_construct_finalize( |
|
226 | + 'Event_Meta', |
|
227 | + 'EVT_default_registration_status', |
|
228 | + 'EEM_Event' |
|
229 | + ); |
|
230 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Used to override the default for the additional limit field. |
|
237 | + * @param $additional_limit |
|
238 | + */ |
|
239 | + public static function set_default_additional_limit($additional_limit) |
|
240 | + { |
|
241 | + self::$_default_additional_limit = (int) $additional_limit; |
|
242 | + if (self::$_instance instanceof EEM_Event) { |
|
243 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
244 | + 'EVT_additional_limit', |
|
245 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
246 | + true, |
|
247 | + self::$_default_additional_limit |
|
248 | + ); |
|
249 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
250 | + 'Event_Meta', |
|
251 | + 'EVT_additional_limit', |
|
252 | + 'EEM_Event' |
|
253 | + ); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Return what is currently set as the default additional limit for the event. |
|
260 | + * @return int |
|
261 | + */ |
|
262 | + public static function get_default_additional_limit() |
|
263 | + { |
|
264 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * get_question_groups |
|
270 | + * |
|
271 | + * @return array |
|
272 | + * @throws \EE_Error |
|
273 | + */ |
|
274 | + public function get_all_question_groups() |
|
275 | + { |
|
276 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
277 | + array( |
|
278 | + array('QSG_deleted' => false), |
|
279 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * get_question_groups |
|
288 | + * |
|
289 | + * @param int $EVT_ID |
|
290 | + * @return array|bool |
|
291 | + * @throws \EE_Error |
|
292 | + */ |
|
293 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
294 | + { |
|
295 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
296 | + EE_Error::add_error( |
|
297 | + esc_html__( |
|
298 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + __FILE__, __FUNCTION__, __LINE__ |
|
302 | + ); |
|
303 | + return false; |
|
304 | + } |
|
305 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
306 | + array( |
|
307 | + array('EVT_ID' => $EVT_ID), |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * get_question_groups |
|
316 | + * |
|
317 | + * @param int $EVT_ID |
|
318 | + * @param boolean $for_primary_attendee |
|
319 | + * @return array|bool |
|
320 | + * @throws \EE_Error |
|
321 | + */ |
|
322 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
323 | + { |
|
324 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
325 | + EE_Error::add_error( |
|
326 | + esc_html__( |
|
327 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
328 | + 'event_espresso' |
|
329 | + ), |
|
330 | + __FILE__, __FUNCTION__, __LINE__ |
|
331 | + ); |
|
332 | + return false; |
|
333 | + } |
|
334 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
335 | + array( |
|
336 | + array( |
|
337 | + 'EVT_ID' => $EVT_ID, |
|
338 | + 'EQG_primary' => $for_primary_attendee, |
|
339 | + ), |
|
340 | + ) |
|
341 | + ); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * get_question_groups |
|
348 | + * |
|
349 | + * @param int $EVT_ID |
|
350 | + * @param EE_Registration $registration |
|
351 | + * @return array|bool |
|
352 | + * @throws \EE_Error |
|
353 | + */ |
|
354 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
355 | + { |
|
356 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
357 | + EE_Error::add_error( |
|
358 | + esc_html__( |
|
359 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + __FILE__, __FUNCTION__, __LINE__ |
|
363 | + ); |
|
364 | + return false; |
|
365 | + } |
|
366 | + $where_params = array( |
|
367 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
368 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
369 | + 'QSG_deleted' => false, |
|
370 | + ); |
|
371 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | + array( |
|
373 | + $where_params, |
|
374 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | + ) |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * get_question_target_db_column |
|
383 | + * |
|
384 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
385 | + * @return array|bool |
|
386 | + * @throws \EE_Error |
|
387 | + */ |
|
388 | + public function get_questions_in_groups($QSG_IDs = '') |
|
389 | + { |
|
390 | + if (empty($QSG_IDs)) { |
|
391 | + EE_Error::add_error( |
|
392 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
393 | + __FILE__, __FUNCTION__, __LINE__ |
|
394 | + ); |
|
395 | + return false; |
|
396 | + } |
|
397 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
398 | + array( |
|
399 | + array( |
|
400 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
401 | + 'QST_deleted' => false, |
|
402 | + 'QST_admin_only' => is_admin(), |
|
403 | + ), |
|
404 | + 'order_by' => 'QST_order', |
|
405 | + ) |
|
406 | + ); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * get_options_for_question |
|
413 | + * |
|
414 | + * @param string $QST_IDs csv list of $QST IDs |
|
415 | + * @return array|bool |
|
416 | + * @throws \EE_Error |
|
417 | + */ |
|
418 | + public function get_options_for_question($QST_IDs) |
|
419 | + { |
|
420 | + if (empty($QST_IDs)) { |
|
421 | + EE_Error::add_error( |
|
422 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
423 | + __FILE__, __FUNCTION__, __LINE__ |
|
424 | + ); |
|
425 | + return false; |
|
426 | + } |
|
427 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
428 | + array( |
|
429 | + array( |
|
430 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
431 | + 'QSO_deleted' => false, |
|
432 | + ), |
|
433 | + 'order_by' => 'QSO_ID', |
|
434 | + ) |
|
435 | + ); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets all events that are published |
|
446 | + * and have event start time earlier than now and an event end time later than now |
|
447 | + * |
|
448 | + * @param array $query_params An array of query params to further filter on |
|
449 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
450 | + * @param bool $count whether to return the count or not (default FALSE) |
|
451 | + * @return EE_Event[]|int |
|
452 | + * @throws \EE_Error |
|
453 | + */ |
|
454 | + public function get_active_events($query_params, $count = false) |
|
455 | + { |
|
456 | + if (array_key_exists(0, $query_params)) { |
|
457 | + $where_params = $query_params[0]; |
|
458 | + unset($query_params[0]); |
|
459 | + } else { |
|
460 | + $where_params = array(); |
|
461 | + } |
|
462 | + // if we have count make sure we don't include group by |
|
463 | + if ($count && isset($query_params['group_by'])) { |
|
464 | + unset($query_params['group_by']); |
|
465 | + } |
|
466 | + // let's add specific query_params for active_events |
|
467 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
468 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
469 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
470 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
471 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
472 | + '<', |
|
473 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
474 | + ); |
|
475 | + } else { |
|
476 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
477 | + '<', |
|
478 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
479 | + ); |
|
480 | + } |
|
481 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
482 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
483 | + '>', |
|
484 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
485 | + ); |
|
486 | + } else { |
|
487 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
488 | + '>', |
|
489 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
490 | + ); |
|
491 | + } |
|
492 | + $query_params[0] = $where_params; |
|
493 | + // don't use $query_params with count() |
|
494 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
495 | + return $count |
|
496 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
497 | + : $this->get_all($query_params); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * get all events that are published and have an event start time later than now |
|
504 | + * |
|
505 | + * @param array $query_params An array of query params to further filter on |
|
506 | + * (Note that status and DTT_EVT_start will be overridden) |
|
507 | + * @param bool $count whether to return the count or not (default FALSE) |
|
508 | + * @return EE_Event[]|int |
|
509 | + * @throws \EE_Error |
|
510 | + */ |
|
511 | + public function get_upcoming_events($query_params, $count = false) |
|
512 | + { |
|
513 | + if (array_key_exists(0, $query_params)) { |
|
514 | + $where_params = $query_params[0]; |
|
515 | + unset($query_params[0]); |
|
516 | + } else { |
|
517 | + $where_params = array(); |
|
518 | + } |
|
519 | + // if we have count make sure we don't include group by |
|
520 | + if ($count && isset($query_params['group_by'])) { |
|
521 | + unset($query_params['group_by']); |
|
522 | + } |
|
523 | + // let's add specific query_params for active_events |
|
524 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
525 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
526 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
527 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
528 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
529 | + '>', |
|
530 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
531 | + ); |
|
532 | + } else { |
|
533 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
534 | + '>', |
|
535 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
536 | + ); |
|
537 | + } |
|
538 | + $query_params[0] = $where_params; |
|
539 | + // don't use $query_params with count() |
|
540 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
541 | + return $count |
|
542 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
543 | + : $this->get_all($query_params); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * Gets all events that are published |
|
550 | + * and have an event end time later than now |
|
551 | + * |
|
552 | + * @param array $query_params An array of query params to further filter on |
|
553 | + * (note that status and DTT_EVT_end will be overridden) |
|
554 | + * @param bool $count whether to return the count or not (default FALSE) |
|
555 | + * @return EE_Event[]|int |
|
556 | + * @throws \EE_Error |
|
557 | + */ |
|
558 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
559 | + { |
|
560 | + if (array_key_exists(0, $query_params)) { |
|
561 | + $where_params = $query_params[0]; |
|
562 | + unset($query_params[0]); |
|
563 | + } else { |
|
564 | + $where_params = array(); |
|
565 | + } |
|
566 | + // if we have count make sure we don't include group by |
|
567 | + if ($count && isset($query_params['group_by'])) { |
|
568 | + unset($query_params['group_by']); |
|
569 | + } |
|
570 | + // let's add specific query_params for active_events |
|
571 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
572 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
573 | + // add where params for DTT_EVT_end |
|
574 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
575 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
576 | + '>', |
|
577 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
578 | + ); |
|
579 | + } else { |
|
580 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
581 | + '>', |
|
582 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | + ); |
|
584 | + } |
|
585 | + $query_params[0] = $where_params; |
|
586 | + // don't use $query_params with count() |
|
587 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
588 | + return $count |
|
589 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
590 | + : $this->get_all($query_params); |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * This only returns events that are expired. |
|
597 | + * They may still be published but all their datetimes have expired. |
|
598 | + * |
|
599 | + * @param array $query_params An array of query params to further filter on |
|
600 | + * (note that status and DTT_EVT_end will be overridden) |
|
601 | + * @param bool $count whether to return the count or not (default FALSE) |
|
602 | + * @return EE_Event[]|int |
|
603 | + * @throws \EE_Error |
|
604 | + */ |
|
605 | + public function get_expired_events($query_params, $count = false) |
|
606 | + { |
|
607 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
608 | + // if we have count make sure we don't include group by |
|
609 | + if ($count && isset($query_params['group_by'])) { |
|
610 | + unset($query_params['group_by']); |
|
611 | + } |
|
612 | + // let's add specific query_params for active_events |
|
613 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
614 | + if (isset($where_params['status'])) { |
|
615 | + unset($where_params['status']); |
|
616 | + } |
|
617 | + $exclude_query = $query_params; |
|
618 | + if (isset($exclude_query[0])) { |
|
619 | + unset($exclude_query[0]); |
|
620 | + } |
|
621 | + $exclude_query[0] = array( |
|
622 | + 'Datetime.DTT_EVT_end' => array( |
|
623 | + '>', |
|
624 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
625 | + ), |
|
626 | + ); |
|
627 | + // first get all events that have datetimes where its not expired. |
|
628 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
629 | + $event_ids = array_keys($event_ids); |
|
630 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
631 | + $and_condition = array( |
|
632 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
633 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
634 | + ); |
|
635 | + if (isset($where_params['OR'])) { |
|
636 | + $and_condition['OR'] = $where_params['OR']; |
|
637 | + unset($where_params['OR']); |
|
638 | + } |
|
639 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
640 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
641 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
642 | + } |
|
643 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
644 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
645 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
646 | + } |
|
647 | + // merge remaining $where params with the and conditions. |
|
648 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
649 | + $query_params[0] = $where_params; |
|
650 | + // don't use $query_params with count() |
|
651 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
652 | + return $count |
|
653 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
654 | + : $this->get_all($query_params); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * This basically just returns the events that do not have the publish status. |
|
661 | + * |
|
662 | + * @param array $query_params An array of query params to further filter on |
|
663 | + * (note that status will be overwritten) |
|
664 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
665 | + * @return EE_Event[]|int |
|
666 | + * @throws \EE_Error |
|
667 | + */ |
|
668 | + public function get_inactive_events($query_params, $count = false) |
|
669 | + { |
|
670 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
671 | + // let's add in specific query_params for inactive events. |
|
672 | + if (isset($where_params['status'])) { |
|
673 | + unset($where_params['status']); |
|
674 | + } |
|
675 | + // if we have count make sure we don't include group by |
|
676 | + if ($count && isset($query_params['group_by'])) { |
|
677 | + unset($query_params['group_by']); |
|
678 | + } |
|
679 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
680 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
681 | + if (isset($where_params['OR'])) { |
|
682 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
683 | + unset($where_params['OR']); |
|
684 | + } |
|
685 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
686 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
687 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
688 | + } |
|
689 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
690 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
691 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
692 | + } |
|
693 | + $query_params[0] = $where_params; |
|
694 | + // don't use $query_params with count() |
|
695 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
696 | + return $count |
|
697 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
698 | + : $this->get_all($query_params); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
705 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
706 | + * attached to the event. See parent for param descriptions |
|
707 | + * |
|
708 | + * @param $id_or_obj |
|
709 | + * @param $other_model_id_or_obj |
|
710 | + * @param string $relationName |
|
711 | + * @param array $where_query |
|
712 | + * @return EE_Base_Class |
|
713 | + * @throws EE_Error |
|
714 | + */ |
|
715 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
716 | + { |
|
717 | + if ($relationName === 'Price') { |
|
718 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
719 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
720 | + //if EVT_ID = 0, then this is a default |
|
721 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
722 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
723 | + $prc_chk->set('PRC_ID', 0); |
|
724 | + } |
|
725 | + //run parent |
|
726 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
727 | + } |
|
728 | + //otherwise carry on as normal |
|
729 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + |
|
734 | + /******************** DEPRECATED METHODS ********************/ |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * _get_question_target_db_column |
|
740 | + * |
|
741 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
742 | + * EE_Registration_Custom_Questions_Form located in |
|
743 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
744 | + * @access public |
|
745 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
746 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
747 | + * registration). |
|
748 | + * @throws EE_Error |
|
749 | + * @return array |
|
750 | + */ |
|
751 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
752 | + { |
|
753 | + if (empty($EVT_ID)) { |
|
754 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
755 | + 'event_espresso')); |
|
756 | + } |
|
757 | + $questions = array(); |
|
758 | + // get all question groups for event |
|
759 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
760 | + if (! empty($qgs)) { |
|
761 | + foreach ($qgs as $qg) { |
|
762 | + $qsts = $qg->questions(); |
|
763 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
764 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
765 | + foreach ($qsts as $qst) { |
|
766 | + if ($qst->is_system_question()) { |
|
767 | + continue; |
|
768 | + } |
|
769 | + $answer = EEM_Answer::instance()->get_one(array( |
|
770 | + array( |
|
771 | + 'QST_ID' => $qst->ID(), |
|
772 | + 'REG_ID' => $registration->ID(), |
|
773 | + ), |
|
774 | + )); |
|
775 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
776 | + $qst_name = $qstn_id = $qst->ID(); |
|
777 | + $ans_id = $answer->ID(); |
|
778 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
779 | + $input_name = ''; |
|
780 | + $input_id = sanitize_key($qst->display_text()); |
|
781 | + $input_class = ''; |
|
782 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
783 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
784 | + . $input_name |
|
785 | + . $qst_name; |
|
786 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
787 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
788 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
789 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
790 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
791 | + //leave responses as-is, don't convert stuff into html entities please! |
|
792 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
793 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
794 | + $QSOs = $qst->options(true, $answer->value()); |
|
795 | + if (is_array($QSOs)) { |
|
796 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
797 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
798 | + } |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + } |
|
803 | + } |
|
804 | + return $questions; |
|
805 | + } |
|
806 | 806 | |
807 | 807 | |
808 | 808 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | */ |
39 | 39 | public function __construct($generator) |
40 | 40 | { |
41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
41 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | 42 | throw new InvalidArgumentException( |
43 | 43 | esc_html__( |
44 | 44 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
@@ -33,7 +33,7 @@ |
||
33 | 33 | /** |
34 | 34 | * CoreLoader constructor. |
35 | 35 | * |
36 | - * @param EE_Registry|CoffeeShop $generator |
|
36 | + * @param EE_Registry $generator |
|
37 | 37 | * @throws InvalidArgumentException |
38 | 38 | */ |
39 | 39 | public function __construct($generator) |
@@ -23,58 +23,58 @@ |
||
23 | 23 | class CoreLoader implements LoaderInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry|CoffeeShop $generator |
|
28 | - */ |
|
29 | - private $generator; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * CoreLoader constructor. |
|
35 | - * |
|
36 | - * @param EE_Registry|CoffeeShop $generator |
|
37 | - * @throws InvalidArgumentException |
|
38 | - */ |
|
39 | - public function __construct($generator) |
|
40 | - { |
|
41 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | - throw new InvalidArgumentException( |
|
43 | - esc_html__( |
|
44 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | - 'event_espresso' |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
49 | - $this->generator = $generator; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $fqcn |
|
56 | - * @param array $arguments |
|
57 | - * @return mixed |
|
58 | - * @throws ServiceNotFoundException |
|
59 | - */ |
|
60 | - public function load($fqcn, $arguments = array()) |
|
61 | - { |
|
62 | - return $this->generator instanceof EE_Registry |
|
63 | - ? $this->generator->create($fqcn, $arguments) |
|
64 | - : $this->generator->brew($fqcn, $arguments); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * calls reset() on generator if method exists |
|
71 | - */ |
|
72 | - public function reset() |
|
73 | - { |
|
74 | - if (method_exists($this->generator, 'reset')) { |
|
75 | - $this->generator->reset(); |
|
76 | - } |
|
77 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry|CoffeeShop $generator |
|
28 | + */ |
|
29 | + private $generator; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * CoreLoader constructor. |
|
35 | + * |
|
36 | + * @param EE_Registry|CoffeeShop $generator |
|
37 | + * @throws InvalidArgumentException |
|
38 | + */ |
|
39 | + public function __construct($generator) |
|
40 | + { |
|
41 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
42 | + throw new InvalidArgumentException( |
|
43 | + esc_html__( |
|
44 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
45 | + 'event_espresso' |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | + $this->generator = $generator; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $fqcn |
|
56 | + * @param array $arguments |
|
57 | + * @return mixed |
|
58 | + * @throws ServiceNotFoundException |
|
59 | + */ |
|
60 | + public function load($fqcn, $arguments = array()) |
|
61 | + { |
|
62 | + return $this->generator instanceof EE_Registry |
|
63 | + ? $this->generator->create($fqcn, $arguments) |
|
64 | + : $this->generator->brew($fqcn, $arguments); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * calls reset() on generator if method exists |
|
71 | + */ |
|
72 | + public function reset() |
|
73 | + { |
|
74 | + if (method_exists($this->generator, 'reset')) { |
|
75 | + $this->generator->reset(); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | // End of file CoreLoader.php |
@@ -19,22 +19,22 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @var LoaderInterface $loader |
|
24 | - */ |
|
25 | - protected $loader; |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * LoaderDecorator constructor. |
|
31 | - * |
|
32 | - * @param LoaderInterface $loader |
|
33 | - */ |
|
34 | - public function __construct(LoaderInterface $loader) |
|
35 | - { |
|
36 | - $this->loader = $loader; |
|
37 | - } |
|
22 | + /** |
|
23 | + * @var LoaderInterface $loader |
|
24 | + */ |
|
25 | + protected $loader; |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * LoaderDecorator constructor. |
|
31 | + * |
|
32 | + * @param LoaderInterface $loader |
|
33 | + */ |
|
34 | + public function __construct(LoaderInterface $loader) |
|
35 | + { |
|
36 | + $this->loader = $loader; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\collections; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param mixed $identifier |
28 | 28 | * @return bool |
29 | 29 | */ |
30 | - public function add( $object, $identifier = null ); |
|
30 | + public function add($object, $identifier = null); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * setIdentifier |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param mixed $identifier |
40 | 40 | * @return bool |
41 | 41 | */ |
42 | - public function setIdentifier( $object, $identifier = null ); |
|
42 | + public function setIdentifier($object, $identifier = null); |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * get |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param mixed $identifier |
51 | 51 | * @return mixed |
52 | 52 | */ |
53 | - public function get( $identifier ); |
|
53 | + public function get($identifier); |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * has |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param mixed $identifier |
63 | 63 | * @return bool |
64 | 64 | */ |
65 | - public function has( $identifier ); |
|
65 | + public function has($identifier); |
|
66 | 66 | |
67 | 67 | /** |
68 | 68 | * hasObject |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @param $object |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public function hasObject( $object ); |
|
75 | + public function hasObject($object); |
|
76 | 76 | |
77 | 77 | /** |
78 | 78 | * remove |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param $object |
83 | 83 | * @return bool |
84 | 84 | */ |
85 | - public function remove( $object ); |
|
85 | + public function remove($object); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * setCurrent |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param mixed $identifier |
93 | 93 | * @return boolean |
94 | 94 | */ |
95 | - public function setCurrent( $identifier ) ; |
|
95 | + public function setCurrent($identifier); |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * setCurrentUsingObject |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @param $object |
103 | 103 | * @return boolean |
104 | 104 | */ |
105 | - public function setCurrentUsingObject( $object ); |
|
105 | + public function setCurrentUsingObject($object); |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * Returns the object occupying the index before the current object, |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @param $object |
120 | 120 | * @return boolean|int|string |
121 | 121 | */ |
122 | - public function indexOf( $object ); |
|
122 | + public function indexOf($object); |
|
123 | 123 | |
124 | 124 | |
125 | 125 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param $index |
130 | 130 | * @return mixed |
131 | 131 | */ |
132 | - public function objectAtIndex( $index ); |
|
132 | + public function objectAtIndex($index); |
|
133 | 133 | |
134 | 134 | /** |
135 | 135 | * Returns the sequence of objects as specified by the offset and length |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param int $length |
140 | 140 | * @return array |
141 | 141 | */ |
142 | - public function slice( $offset, $length ); |
|
142 | + public function slice($offset, $length); |
|
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Inserts an object (or an array of objects) at a certain point |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * @param mixed $objects A single object or an array of objects |
149 | 149 | * @param integer $index |
150 | 150 | */ |
151 | - public function insertAt( $objects, $index ); |
|
151 | + public function insertAt($objects, $index); |
|
152 | 152 | |
153 | 153 | /** |
154 | 154 | * Removes the object at the given index |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @see http://stackoverflow.com/a/8736013 |
157 | 157 | * @param integer $index |
158 | 158 | */ |
159 | - public function removeAt( $index ) ; |
|
159 | + public function removeAt($index); |
|
160 | 160 | |
161 | 161 | |
162 | 162 |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | public function previous(); |
114 | 114 | |
115 | 115 | /** |
116 | - * Returns the index of a given object, or false if not found |
|
117 | - * |
|
118 | - * @see http://stackoverflow.com/a/8736013 |
|
119 | - * @param $object |
|
120 | - * @return boolean|int|string |
|
121 | - */ |
|
116 | + * Returns the index of a given object, or false if not found |
|
117 | + * |
|
118 | + * @see http://stackoverflow.com/a/8736013 |
|
119 | + * @param $object |
|
120 | + * @return boolean|int|string |
|
121 | + */ |
|
122 | 122 | public function indexOf( $object ); |
123 | 123 | |
124 | 124 | |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * detaches ALL objects from the Collection |
|
165 | - */ |
|
166 | - public function detachAll(); |
|
163 | + /** |
|
164 | + * detaches ALL objects from the Collection |
|
165 | + */ |
|
166 | + public function detachAll(); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | // End of file CollectionInterface.php |
@@ -83,7 +83,6 @@ discard block |
||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * setIdentifier |
86 | - |
|
87 | 86 | * Sets the data associated with an object in the Collection |
88 | 87 | * if no $identifier is supplied, then the spl_object_hash() is used |
89 | 88 | * |
@@ -352,18 +351,18 @@ discard block |
||
352 | 351 | |
353 | 352 | |
354 | 353 | |
355 | - /** |
|
356 | - * detaches ALL objects from the Collection |
|
357 | - */ |
|
358 | - public function detachAll() |
|
359 | - { |
|
360 | - $this->rewind(); |
|
361 | - while ($this->valid()) { |
|
362 | - $object = $this->current(); |
|
363 | - $this->next(); |
|
364 | - $this->detach($object); |
|
365 | - } |
|
366 | - } |
|
354 | + /** |
|
355 | + * detaches ALL objects from the Collection |
|
356 | + */ |
|
357 | + public function detachAll() |
|
358 | + { |
|
359 | + $this->rewind(); |
|
360 | + while ($this->valid()) { |
|
361 | + $object = $this->current(); |
|
362 | + $this->next(); |
|
363 | + $this->detach($object); |
|
364 | + } |
|
365 | + } |
|
367 | 366 | |
368 | 367 | |
369 | 368 |
@@ -24,140 +24,140 @@ |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var LoaderInterface $new_loader |
|
29 | - */ |
|
30 | - private $new_loader; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $shared_loader |
|
35 | - */ |
|
36 | - private $shared_loader; |
|
37 | - |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * Loader constructor. |
|
42 | - * |
|
43 | - * @param LoaderInterface|null $new_loader |
|
44 | - * @param LoaderInterface|null $shared_loader |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - */ |
|
49 | - public function __construct(LoaderInterface $new_loader = null, LoaderInterface $shared_loader = null) |
|
50 | - { |
|
51 | - $this->new_loader = $this->setupNewLoader($new_loader); |
|
52 | - $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param LoaderInterface|null $new_loader |
|
59 | - * @return CoreLoader|LoaderInterface |
|
60 | - * @throws InvalidArgumentException |
|
61 | - */ |
|
62 | - private function setupNewLoader(LoaderInterface $new_loader = null) |
|
63 | - { |
|
64 | - // if not already generated, create a standard loader |
|
65 | - if (! $new_loader instanceof LoaderInterface) { |
|
66 | - $new_loader = new CoreLoader(EE_Registry::instance()); |
|
67 | - } |
|
68 | - return $new_loader; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param LoaderInterface|null $shared_loader |
|
75 | - * @return CoreLoader|LoaderInterface |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws InvalidArgumentException |
|
79 | - */ |
|
80 | - private function setupSharedLoader(LoaderInterface $shared_loader = null) |
|
81 | - { |
|
82 | - // if not already generated, create a caching loader |
|
83 | - if (! $shared_loader instanceof LoaderInterface) { |
|
84 | - $shared_loader = new CachingLoader( |
|
85 | - new CoreLoader(EE_Registry::instance()), |
|
86 | - new LooseCollection('') |
|
87 | - ); |
|
88 | - } |
|
89 | - return $shared_loader; |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return LoaderInterface |
|
96 | - */ |
|
97 | - public function getNewLoader() |
|
98 | - { |
|
99 | - return $this->new_loader; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return LoaderInterface |
|
106 | - */ |
|
107 | - public function getSharedLoader() |
|
108 | - { |
|
109 | - return $this->shared_loader; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $fqcn |
|
116 | - * @param array $arguments |
|
117 | - * @param bool $shared |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
121 | - { |
|
122 | - return $shared |
|
123 | - ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
124 | - : $this->getNewLoader()->load($fqcn, $arguments); |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $fqcn |
|
131 | - * @param array $arguments |
|
132 | - * @return mixed |
|
133 | - */ |
|
134 | - public function getNew($fqcn, $arguments = array()) |
|
135 | - { |
|
136 | - return $this->getNewLoader()->load($fqcn, $arguments); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $fqcn |
|
143 | - * @param array $arguments |
|
144 | - * @return mixed |
|
145 | - */ |
|
146 | - public function getShared($fqcn, $arguments = array()) |
|
147 | - { |
|
148 | - return $this->getSharedLoader()->load($fqcn, $arguments); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * calls reset() on loaders if that method exists |
|
155 | - */ |
|
156 | - public function reset() |
|
157 | - { |
|
158 | - $this->new_loader->reset(); |
|
159 | - $this->shared_loader->reset(); |
|
160 | - } |
|
27 | + /** |
|
28 | + * @var LoaderInterface $new_loader |
|
29 | + */ |
|
30 | + private $new_loader; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $shared_loader |
|
35 | + */ |
|
36 | + private $shared_loader; |
|
37 | + |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * Loader constructor. |
|
42 | + * |
|
43 | + * @param LoaderInterface|null $new_loader |
|
44 | + * @param LoaderInterface|null $shared_loader |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + */ |
|
49 | + public function __construct(LoaderInterface $new_loader = null, LoaderInterface $shared_loader = null) |
|
50 | + { |
|
51 | + $this->new_loader = $this->setupNewLoader($new_loader); |
|
52 | + $this->shared_loader = $this->setupSharedLoader($shared_loader); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param LoaderInterface|null $new_loader |
|
59 | + * @return CoreLoader|LoaderInterface |
|
60 | + * @throws InvalidArgumentException |
|
61 | + */ |
|
62 | + private function setupNewLoader(LoaderInterface $new_loader = null) |
|
63 | + { |
|
64 | + // if not already generated, create a standard loader |
|
65 | + if (! $new_loader instanceof LoaderInterface) { |
|
66 | + $new_loader = new CoreLoader(EE_Registry::instance()); |
|
67 | + } |
|
68 | + return $new_loader; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param LoaderInterface|null $shared_loader |
|
75 | + * @return CoreLoader|LoaderInterface |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws InvalidArgumentException |
|
79 | + */ |
|
80 | + private function setupSharedLoader(LoaderInterface $shared_loader = null) |
|
81 | + { |
|
82 | + // if not already generated, create a caching loader |
|
83 | + if (! $shared_loader instanceof LoaderInterface) { |
|
84 | + $shared_loader = new CachingLoader( |
|
85 | + new CoreLoader(EE_Registry::instance()), |
|
86 | + new LooseCollection('') |
|
87 | + ); |
|
88 | + } |
|
89 | + return $shared_loader; |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return LoaderInterface |
|
96 | + */ |
|
97 | + public function getNewLoader() |
|
98 | + { |
|
99 | + return $this->new_loader; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return LoaderInterface |
|
106 | + */ |
|
107 | + public function getSharedLoader() |
|
108 | + { |
|
109 | + return $this->shared_loader; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $fqcn |
|
116 | + * @param array $arguments |
|
117 | + * @param bool $shared |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
121 | + { |
|
122 | + return $shared |
|
123 | + ? $this->getSharedLoader()->load($fqcn, $arguments) |
|
124 | + : $this->getNewLoader()->load($fqcn, $arguments); |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $fqcn |
|
131 | + * @param array $arguments |
|
132 | + * @return mixed |
|
133 | + */ |
|
134 | + public function getNew($fqcn, $arguments = array()) |
|
135 | + { |
|
136 | + return $this->getNewLoader()->load($fqcn, $arguments); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $fqcn |
|
143 | + * @param array $arguments |
|
144 | + * @return mixed |
|
145 | + */ |
|
146 | + public function getShared($fqcn, $arguments = array()) |
|
147 | + { |
|
148 | + return $this->getSharedLoader()->load($fqcn, $arguments); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * calls reset() on loaders if that method exists |
|
155 | + */ |
|
156 | + public function reset() |
|
157 | + { |
|
158 | + $this->new_loader->reset(); |
|
159 | + $this->shared_loader->reset(); |
|
160 | + } |
|
161 | 161 | |
162 | 162 | } |
163 | 163 | // End of file Loader.php |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | private function setupNewLoader(LoaderInterface $new_loader = null) |
63 | 63 | { |
64 | 64 | // if not already generated, create a standard loader |
65 | - if (! $new_loader instanceof LoaderInterface) { |
|
65 | + if ( ! $new_loader instanceof LoaderInterface) { |
|
66 | 66 | $new_loader = new CoreLoader(EE_Registry::instance()); |
67 | 67 | } |
68 | 68 | return $new_loader; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | private function setupSharedLoader(LoaderInterface $shared_loader = null) |
81 | 81 | { |
82 | 82 | // if not already generated, create a caching loader |
83 | - if (! $shared_loader instanceof LoaderInterface) { |
|
83 | + if ( ! $shared_loader instanceof LoaderInterface) { |
|
84 | 84 | $shared_loader = new CachingLoader( |
85 | 85 | new CoreLoader(EE_Registry::instance()), |
86 | 86 | new LooseCollection('') |
@@ -102,17 +102,17 @@ |
||
102 | 102 | $fqcn = ltrim($fqcn, '\\'); |
103 | 103 | // caching can be turned off via the following code: |
104 | 104 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
105 | - if( |
|
105 | + if ( |
|
106 | 106 | apply_filters( |
107 | 107 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
108 | 108 | false, |
109 | 109 | $this |
110 | 110 | ) |
111 | - ){ |
|
111 | + ) { |
|
112 | 112 | return $this->loader->load($fqcn, $arguments); |
113 | 113 | } |
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
114 | + $identifier = md5($fqcn.serialize($arguments)); |
|
115 | + if ($this->cache->has($identifier)) { |
|
116 | 116 | return $this->cache->get($identifier); |
117 | 117 | } |
118 | 118 | $object = $this->loader->load($fqcn, $arguments); |
@@ -22,114 +22,114 @@ |
||
22 | 22 | class CachingLoader extends LoaderDecorator |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $identifier |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * CachingLoader constructor. |
|
39 | - * |
|
40 | - * @param LoaderInterface $loader |
|
41 | - * @param CollectionInterface $cache |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | - { |
|
47 | - parent::__construct($loader); |
|
48 | - $this->cache = $cache; |
|
49 | - $this->setIdentifier($identifier); |
|
50 | - if ($this->identifier !== '') { |
|
51 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | - // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | - // where "IDENTIFIER" = the string that was set during construction |
|
54 | - add_action( |
|
55 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | - array($this, 'reset') |
|
57 | - ); |
|
58 | - } |
|
59 | - // to clear ALL caches, simply do the following: |
|
60 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | - add_action( |
|
62 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | - array($this, 'reset') |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function identifier() |
|
73 | - { |
|
74 | - return $this->identifier; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $identifier |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - */ |
|
83 | - private function setIdentifier($identifier) |
|
84 | - { |
|
85 | - if ( ! is_string($identifier)) { |
|
86 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | - } |
|
88 | - $this->identifier = $identifier; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $fqcn |
|
95 | - * @param array $arguments |
|
96 | - * @return mixed |
|
97 | - * @throws InvalidEntityException |
|
98 | - * @throws ServiceNotFoundException |
|
99 | - */ |
|
100 | - public function load($fqcn, $arguments = array()) |
|
101 | - { |
|
102 | - $fqcn = ltrim($fqcn, '\\'); |
|
103 | - // caching can be turned off via the following code: |
|
104 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | - if( |
|
106 | - apply_filters( |
|
107 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | - false, |
|
109 | - $this |
|
110 | - ) |
|
111 | - ){ |
|
112 | - return $this->loader->load($fqcn, $arguments); |
|
113 | - } |
|
114 | - $identifier = md5($fqcn . serialize($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
116 | - return $this->cache->get($identifier); |
|
117 | - } |
|
118 | - $object = $this->loader->load($fqcn, $arguments); |
|
119 | - $this->cache->add($object, $identifier); |
|
120 | - return $object; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * empties cache and calls reset() on loader if method exists |
|
127 | - */ |
|
128 | - public function reset() |
|
129 | - { |
|
130 | - $this->cache->detachAll(); |
|
131 | - $this->loader->reset(); |
|
132 | - } |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $identifier |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * CachingLoader constructor. |
|
39 | + * |
|
40 | + * @param LoaderInterface $loader |
|
41 | + * @param CollectionInterface $cache |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct(LoaderInterface $loader, CollectionInterface $cache, $identifier = '') |
|
46 | + { |
|
47 | + parent::__construct($loader); |
|
48 | + $this->cache = $cache; |
|
49 | + $this->setIdentifier($identifier); |
|
50 | + if ($this->identifier !== '') { |
|
51 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
52 | + // do_action('AHEE__EventEspresso\core\services\loaders\CachingLoader__resetCache__IDENTIFIER'); |
|
53 | + // where "IDENTIFIER" = the string that was set during construction |
|
54 | + add_action( |
|
55 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
56 | + array($this, 'reset') |
|
57 | + ); |
|
58 | + } |
|
59 | + // to clear ALL caches, simply do the following: |
|
60 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
61 | + add_action( |
|
62 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
63 | + array($this, 'reset') |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function identifier() |
|
73 | + { |
|
74 | + return $this->identifier; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $identifier |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + */ |
|
83 | + private function setIdentifier($identifier) |
|
84 | + { |
|
85 | + if ( ! is_string($identifier)) { |
|
86 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
87 | + } |
|
88 | + $this->identifier = $identifier; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $fqcn |
|
95 | + * @param array $arguments |
|
96 | + * @return mixed |
|
97 | + * @throws InvalidEntityException |
|
98 | + * @throws ServiceNotFoundException |
|
99 | + */ |
|
100 | + public function load($fqcn, $arguments = array()) |
|
101 | + { |
|
102 | + $fqcn = ltrim($fqcn, '\\'); |
|
103 | + // caching can be turned off via the following code: |
|
104 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
105 | + if( |
|
106 | + apply_filters( |
|
107 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
108 | + false, |
|
109 | + $this |
|
110 | + ) |
|
111 | + ){ |
|
112 | + return $this->loader->load($fqcn, $arguments); |
|
113 | + } |
|
114 | + $identifier = md5($fqcn . serialize($arguments)); |
|
115 | + if($this->cache->has($identifier)){ |
|
116 | + return $this->cache->get($identifier); |
|
117 | + } |
|
118 | + $object = $this->loader->load($fqcn, $arguments); |
|
119 | + $this->cache->add($object, $identifier); |
|
120 | + return $object; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * empties cache and calls reset() on loader if method exists |
|
127 | + */ |
|
128 | + public function reset() |
|
129 | + { |
|
130 | + $this->cache->detachAll(); |
|
131 | + $this->loader->reset(); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | 135 | } |