@@ -30,132 +30,132 @@ |
||
30 | 30 | { |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * the actual shortcode tag that gets registered with WordPress |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function getTag() |
|
39 | - { |
|
40 | - return 'ESPRESSO_EVENTS'; |
|
41 | - } |
|
33 | + /** |
|
34 | + * the actual shortcode tag that gets registered with WordPress |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function getTag() |
|
39 | + { |
|
40 | + return 'ESPRESSO_EVENTS'; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * the time in seconds to cache the results of the processShortcode() method |
|
46 | - * 0 means the processShortcode() results will NOT be cached at all |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function cacheExpiration() |
|
51 | - { |
|
52 | - return 0; |
|
53 | - } |
|
44 | + /** |
|
45 | + * the time in seconds to cache the results of the processShortcode() method |
|
46 | + * 0 means the processShortcode() results will NOT be cached at all |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function cacheExpiration() |
|
51 | + { |
|
52 | + return 0; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
58 | - * this may be required for shortcodes that utilize a corresponding module, |
|
59 | - * and need to enqueue assets for that module |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function initializeShortcode() |
|
64 | - { |
|
65 | - EED_Events_Archive::instance()->event_list(); |
|
66 | - $this->shortcodeHasBeenInitialized(); |
|
67 | - } |
|
56 | + /** |
|
57 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
58 | + * this may be required for shortcodes that utilize a corresponding module, |
|
59 | + * and need to enqueue assets for that module |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function initializeShortcode() |
|
64 | + { |
|
65 | + EED_Events_Archive::instance()->event_list(); |
|
66 | + $this->shortcodeHasBeenInitialized(); |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * callback that runs when the shortcode is encountered in post content. |
|
72 | - * IMPORTANT !!! |
|
73 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
74 | - * |
|
75 | - * @param array $attributes |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function processShortcode($attributes = array()) |
|
79 | - { |
|
80 | - // grab attributes and merge with defaults |
|
81 | - $attributes = $this->getAttributes($attributes); |
|
82 | - // make sure we use the_excerpt() |
|
83 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
84 | - // apply query filters |
|
85 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
86 | - // run the query |
|
87 | - global $wp_query; |
|
88 | - // yes we have to overwrite the main wp query, but it's ok... |
|
89 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
90 | - $wp_query = new EventListQuery($attributes); |
|
91 | - // check what template is loaded and load filters accordingly |
|
92 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
93 | - // load our template |
|
94 | - $event_list = EEH_Template::locate_template( |
|
95 | - 'loop-espresso_events.php', |
|
96 | - array(), |
|
97 | - true, |
|
98 | - true |
|
99 | - ); |
|
100 | - // now reset the query and post data |
|
101 | - wp_reset_query(); |
|
102 | - wp_reset_postdata(); |
|
103 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
104 | - // remove query filters |
|
105 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
106 | - // pull our content from the output buffer and return it |
|
107 | - return $event_list; |
|
108 | - } |
|
70 | + /** |
|
71 | + * callback that runs when the shortcode is encountered in post content. |
|
72 | + * IMPORTANT !!! |
|
73 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
74 | + * |
|
75 | + * @param array $attributes |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function processShortcode($attributes = array()) |
|
79 | + { |
|
80 | + // grab attributes and merge with defaults |
|
81 | + $attributes = $this->getAttributes($attributes); |
|
82 | + // make sure we use the_excerpt() |
|
83 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
84 | + // apply query filters |
|
85 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
86 | + // run the query |
|
87 | + global $wp_query; |
|
88 | + // yes we have to overwrite the main wp query, but it's ok... |
|
89 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
90 | + $wp_query = new EventListQuery($attributes); |
|
91 | + // check what template is loaded and load filters accordingly |
|
92 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
93 | + // load our template |
|
94 | + $event_list = EEH_Template::locate_template( |
|
95 | + 'loop-espresso_events.php', |
|
96 | + array(), |
|
97 | + true, |
|
98 | + true |
|
99 | + ); |
|
100 | + // now reset the query and post data |
|
101 | + wp_reset_query(); |
|
102 | + wp_reset_postdata(); |
|
103 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
104 | + // remove query filters |
|
105 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
106 | + // pull our content from the output buffer and return it |
|
107 | + return $event_list; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * merge incoming attributes with filtered defaults |
|
113 | - * |
|
114 | - * @param array $attributes |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - private function getAttributes(array $attributes) |
|
118 | - { |
|
119 | - return array_merge( |
|
120 | - (array) apply_filters( |
|
121 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
122 | - array( |
|
123 | - 'title' => '', |
|
124 | - 'limit' => 10, |
|
125 | - 'css_class' => '', |
|
126 | - 'show_expired' => false, |
|
127 | - 'month' => '', |
|
128 | - 'category_slug' => '', |
|
129 | - 'order_by' => 'start_date', |
|
130 | - 'sort' => 'ASC', |
|
131 | - 'show_title' => true, |
|
132 | - ) |
|
133 | - ), |
|
134 | - $attributes |
|
135 | - ); |
|
136 | - } |
|
111 | + /** |
|
112 | + * merge incoming attributes with filtered defaults |
|
113 | + * |
|
114 | + * @param array $attributes |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + private function getAttributes(array $attributes) |
|
118 | + { |
|
119 | + return array_merge( |
|
120 | + (array) apply_filters( |
|
121 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
122 | + array( |
|
123 | + 'title' => '', |
|
124 | + 'limit' => 10, |
|
125 | + 'css_class' => '', |
|
126 | + 'show_expired' => false, |
|
127 | + 'month' => '', |
|
128 | + 'category_slug' => '', |
|
129 | + 'order_by' => 'start_date', |
|
130 | + 'sort' => 'ASC', |
|
131 | + 'show_title' => true, |
|
132 | + ) |
|
133 | + ), |
|
134 | + $attributes |
|
135 | + ); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * array for defining custom attribute sanitization callbacks, |
|
141 | - * where keys match keys in your attributes array, |
|
142 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
143 | - * So for example, if you had an integer attribute named "event_id" |
|
144 | - * that you wanted to be sanitized using absint(), |
|
145 | - * then you would pass the following for your $custom_sanitization array: |
|
146 | - * array('event_id' => 'absint') |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - protected function customAttributeSanitizationMap() |
|
151 | - { |
|
152 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
153 | - return array( |
|
154 | - 'category_slug' => 'skip_sanitization', |
|
155 | - 'show_expired' => 'skip_sanitization', |
|
156 | - 'order_by' => 'skip_sanitization', |
|
157 | - 'month' => 'skip_sanitization', |
|
158 | - 'sort' => 'skip_sanitization', |
|
159 | - ); |
|
160 | - } |
|
139 | + /** |
|
140 | + * array for defining custom attribute sanitization callbacks, |
|
141 | + * where keys match keys in your attributes array, |
|
142 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
143 | + * So for example, if you had an integer attribute named "event_id" |
|
144 | + * that you wanted to be sanitized using absint(), |
|
145 | + * then you would pass the following for your $custom_sanitization array: |
|
146 | + * array('event_id' => 'absint') |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + protected function customAttributeSanitizationMap() |
|
151 | + { |
|
152 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
153 | + return array( |
|
154 | + 'category_slug' => 'skip_sanitization', |
|
155 | + 'show_expired' => 'skip_sanitization', |
|
156 | + 'order_by' => 'skip_sanitization', |
|
157 | + 'month' => 'skip_sanitization', |
|
158 | + 'sort' => 'skip_sanitization', |
|
159 | + ); |
|
160 | + } |
|
161 | 161 | } |
@@ -20,78 +20,78 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * the actual shortcode tag that gets registered with WordPress |
|
25 | - * |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function getTag() |
|
29 | - { |
|
30 | - return 'ESPRESSO_CANCELLED'; |
|
31 | - } |
|
23 | + /** |
|
24 | + * the actual shortcode tag that gets registered with WordPress |
|
25 | + * |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function getTag() |
|
29 | + { |
|
30 | + return 'ESPRESSO_CANCELLED'; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * the time in seconds to cache the results of the processShortcode() method |
|
36 | - * 0 means the processShortcode() results will NOT be cached at all |
|
37 | - * |
|
38 | - * @return int |
|
39 | - */ |
|
40 | - public function cacheExpiration() |
|
41 | - { |
|
42 | - return 0; |
|
43 | - } |
|
34 | + /** |
|
35 | + * the time in seconds to cache the results of the processShortcode() method |
|
36 | + * 0 means the processShortcode() results will NOT be cached at all |
|
37 | + * |
|
38 | + * @return int |
|
39 | + */ |
|
40 | + public function cacheExpiration() |
|
41 | + { |
|
42 | + return 0; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
48 | - * this may be required for shortcodes that utilize a corresponding module, |
|
49 | - * and need to enqueue assets for that module |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function initializeShortcode() |
|
54 | - { |
|
55 | - $this->shortcodeHasBeenInitialized(); |
|
56 | - } |
|
46 | + /** |
|
47 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
48 | + * this may be required for shortcodes that utilize a corresponding module, |
|
49 | + * and need to enqueue assets for that module |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function initializeShortcode() |
|
54 | + { |
|
55 | + $this->shortcodeHasBeenInitialized(); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * callback that runs when the shortcode is encountered in post content. |
|
61 | - * IMPORTANT !!! |
|
62 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
63 | - * |
|
64 | - * @param array $attributes |
|
65 | - * @return string |
|
66 | - * @throws \EE_Error |
|
67 | - */ |
|
68 | - public function processShortcode($attributes = array()) |
|
69 | - { |
|
70 | - $transaction = EE_Registry::instance()->SSN->get_session_data('transaction'); |
|
71 | - if ($transaction instanceof EE_Transaction) { |
|
72 | - do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', $transaction); |
|
73 | - $registrations = $transaction->registrations(); |
|
74 | - foreach ($registrations as $registration) { |
|
75 | - if ($registration instanceof EE_Registration) { |
|
76 | - do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__registration', $registration); |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
80 | - do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__clear_session'); |
|
81 | - // remove all unwanted records from the db |
|
82 | - if (EE_Registry::instance()->CART instanceof EE_Cart) { |
|
83 | - EE_Registry::instance()->CART->delete_cart(); |
|
84 | - } |
|
85 | - // phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText |
|
86 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
87 | - return sprintf( |
|
88 | - __( |
|
89 | - '%sAll unsaved registration information entered during this session has been deleted.%s', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - '<p class="ee-registrations-cancelled-pg ee-attention">', |
|
93 | - '</p>' |
|
94 | - ); |
|
95 | - // phpcs:enable |
|
96 | - } |
|
59 | + /** |
|
60 | + * callback that runs when the shortcode is encountered in post content. |
|
61 | + * IMPORTANT !!! |
|
62 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
63 | + * |
|
64 | + * @param array $attributes |
|
65 | + * @return string |
|
66 | + * @throws \EE_Error |
|
67 | + */ |
|
68 | + public function processShortcode($attributes = array()) |
|
69 | + { |
|
70 | + $transaction = EE_Registry::instance()->SSN->get_session_data('transaction'); |
|
71 | + if ($transaction instanceof EE_Transaction) { |
|
72 | + do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', $transaction); |
|
73 | + $registrations = $transaction->registrations(); |
|
74 | + foreach ($registrations as $registration) { |
|
75 | + if ($registration instanceof EE_Registration) { |
|
76 | + do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__registration', $registration); |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | + do_action('AHEE__EES_Espresso_Cancelled__process_shortcode__clear_session'); |
|
81 | + // remove all unwanted records from the db |
|
82 | + if (EE_Registry::instance()->CART instanceof EE_Cart) { |
|
83 | + EE_Registry::instance()->CART->delete_cart(); |
|
84 | + } |
|
85 | + // phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText |
|
86 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
87 | + return sprintf( |
|
88 | + __( |
|
89 | + '%sAll unsaved registration information entered during this session has been deleted.%s', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + '<p class="ee-registrations-cancelled-pg ee-attention">', |
|
93 | + '</p>' |
|
94 | + ); |
|
95 | + // phpcs:enable |
|
96 | + } |
|
97 | 97 | } |
@@ -12,205 +12,205 @@ |
||
12 | 12 | */ |
13 | 13 | class GenericAddress implements \EEI_Address |
14 | 14 | { |
15 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
16 | - private $_address = ''; |
|
17 | - |
|
18 | - private $_address2 = ''; |
|
19 | - |
|
20 | - private $_city = ''; |
|
21 | - |
|
22 | - private $_state_ID = ''; |
|
23 | - |
|
24 | - private $_state_obj = ''; |
|
25 | - |
|
26 | - private $_zip = ''; |
|
27 | - |
|
28 | - private $_country_ID = ''; |
|
29 | - |
|
30 | - private $_country_obj = ''; |
|
31 | - // phpcs:enable |
|
32 | - |
|
33 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
34 | - /** |
|
35 | - * @param string $address |
|
36 | - * @param string $address2 |
|
37 | - * @param string $city |
|
38 | - * @param \EE_State | string $state |
|
39 | - * @param string $zip |
|
40 | - * @param \EE_Country | string $country |
|
41 | - * @return GenericAddress |
|
42 | - */ |
|
43 | - public function __construct($address, $address2, $city, $state, $zip, $country) |
|
44 | - { |
|
45 | - $this->_address = $address; |
|
46 | - $this->_address2 = $address2; |
|
47 | - $this->_city = $city; |
|
48 | - if ($state instanceof \EE_State) { |
|
49 | - $this->_state_obj = $state; |
|
50 | - } else { |
|
51 | - $this->_state_ID = $state; |
|
52 | - $this->_state_obj = $this->_get_state_obj(); |
|
53 | - } |
|
54 | - $this->_zip = $zip; |
|
55 | - if ($country instanceof \EE_Country) { |
|
56 | - $this->_country_obj = $country; |
|
57 | - } else { |
|
58 | - $this->_country_ID = $country; |
|
59 | - $this->_country_obj = $this->_get_country_obj(); |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function address() |
|
68 | - { |
|
69 | - return $this->_address; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function address2() |
|
77 | - { |
|
78 | - return $this->_address2; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function city() |
|
86 | - { |
|
87 | - return $this->_city; |
|
88 | - } |
|
89 | - |
|
90 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
91 | - |
|
92 | - /** |
|
93 | - * @return \EE_State |
|
94 | - */ |
|
95 | - private function _get_state_obj() |
|
96 | - { |
|
97 | - return $this->_state_obj instanceof \EE_State |
|
98 | - ? $this->_state_obj |
|
99 | - : \EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function state_ID() |
|
107 | - { |
|
108 | - return $this->_state_ID; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function state_abbrev() |
|
116 | - { |
|
117 | - return $this->state_obj() instanceof \EE_State |
|
118 | - ? $this->state_obj()->abbrev() |
|
119 | - : ''; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public function state_name() |
|
127 | - { |
|
128 | - return $this->state_obj() instanceof \EE_State |
|
129 | - ? $this->state_obj()->name() |
|
130 | - : ''; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @return \EE_State |
|
136 | - */ |
|
137 | - public function state_obj() |
|
138 | - { |
|
139 | - return $this->_state_obj; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function state() |
|
147 | - { |
|
148 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
149 | - return $this->state_obj()->abbrev(); |
|
150 | - } else { |
|
151 | - return $this->state_name(); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @return \EE_Country |
|
158 | - */ |
|
159 | - private function _get_country_obj() |
|
160 | - { |
|
161 | - return $this->_country_obj instanceof \EE_Country |
|
162 | - ? $this->_country_obj |
|
163 | - : \EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function country_ID() |
|
171 | - { |
|
172 | - return $this->_country_ID; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function country_name() |
|
180 | - { |
|
181 | - return $this->country_obj() instanceof \EE_Country |
|
182 | - ? $this->country_obj()->name() |
|
183 | - : ''; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return \EE_Country |
|
189 | - */ |
|
190 | - public function country_obj() |
|
191 | - { |
|
192 | - return $this->_country_obj; |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function country() |
|
200 | - { |
|
201 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
202 | - return $this->country_ID(); |
|
203 | - } else { |
|
204 | - return $this->country_name(); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function zip() |
|
213 | - { |
|
214 | - return $this->_zip; |
|
215 | - } |
|
15 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
16 | + private $_address = ''; |
|
17 | + |
|
18 | + private $_address2 = ''; |
|
19 | + |
|
20 | + private $_city = ''; |
|
21 | + |
|
22 | + private $_state_ID = ''; |
|
23 | + |
|
24 | + private $_state_obj = ''; |
|
25 | + |
|
26 | + private $_zip = ''; |
|
27 | + |
|
28 | + private $_country_ID = ''; |
|
29 | + |
|
30 | + private $_country_obj = ''; |
|
31 | + // phpcs:enable |
|
32 | + |
|
33 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
34 | + /** |
|
35 | + * @param string $address |
|
36 | + * @param string $address2 |
|
37 | + * @param string $city |
|
38 | + * @param \EE_State | string $state |
|
39 | + * @param string $zip |
|
40 | + * @param \EE_Country | string $country |
|
41 | + * @return GenericAddress |
|
42 | + */ |
|
43 | + public function __construct($address, $address2, $city, $state, $zip, $country) |
|
44 | + { |
|
45 | + $this->_address = $address; |
|
46 | + $this->_address2 = $address2; |
|
47 | + $this->_city = $city; |
|
48 | + if ($state instanceof \EE_State) { |
|
49 | + $this->_state_obj = $state; |
|
50 | + } else { |
|
51 | + $this->_state_ID = $state; |
|
52 | + $this->_state_obj = $this->_get_state_obj(); |
|
53 | + } |
|
54 | + $this->_zip = $zip; |
|
55 | + if ($country instanceof \EE_Country) { |
|
56 | + $this->_country_obj = $country; |
|
57 | + } else { |
|
58 | + $this->_country_ID = $country; |
|
59 | + $this->_country_obj = $this->_get_country_obj(); |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function address() |
|
68 | + { |
|
69 | + return $this->_address; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function address2() |
|
77 | + { |
|
78 | + return $this->_address2; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function city() |
|
86 | + { |
|
87 | + return $this->_city; |
|
88 | + } |
|
89 | + |
|
90 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
91 | + |
|
92 | + /** |
|
93 | + * @return \EE_State |
|
94 | + */ |
|
95 | + private function _get_state_obj() |
|
96 | + { |
|
97 | + return $this->_state_obj instanceof \EE_State |
|
98 | + ? $this->_state_obj |
|
99 | + : \EE_Registry::instance()->load_model('State')->get_one_by_ID($this->_state_ID); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function state_ID() |
|
107 | + { |
|
108 | + return $this->_state_ID; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function state_abbrev() |
|
116 | + { |
|
117 | + return $this->state_obj() instanceof \EE_State |
|
118 | + ? $this->state_obj()->abbrev() |
|
119 | + : ''; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public function state_name() |
|
127 | + { |
|
128 | + return $this->state_obj() instanceof \EE_State |
|
129 | + ? $this->state_obj()->name() |
|
130 | + : ''; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @return \EE_State |
|
136 | + */ |
|
137 | + public function state_obj() |
|
138 | + { |
|
139 | + return $this->_state_obj; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function state() |
|
147 | + { |
|
148 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
149 | + return $this->state_obj()->abbrev(); |
|
150 | + } else { |
|
151 | + return $this->state_name(); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @return \EE_Country |
|
158 | + */ |
|
159 | + private function _get_country_obj() |
|
160 | + { |
|
161 | + return $this->_country_obj instanceof \EE_Country |
|
162 | + ? $this->_country_obj |
|
163 | + : \EE_Registry::instance()->load_model('Country')->get_one_by_ID($this->_country_ID); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function country_ID() |
|
171 | + { |
|
172 | + return $this->_country_ID; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function country_name() |
|
180 | + { |
|
181 | + return $this->country_obj() instanceof \EE_Country |
|
182 | + ? $this->country_obj()->name() |
|
183 | + : ''; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return \EE_Country |
|
189 | + */ |
|
190 | + public function country_obj() |
|
191 | + { |
|
192 | + return $this->_country_obj; |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function country() |
|
200 | + { |
|
201 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
202 | + return $this->country_ID(); |
|
203 | + } else { |
|
204 | + return $this->country_name(); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function zip() |
|
213 | + { |
|
214 | + return $this->_zip; |
|
215 | + } |
|
216 | 216 | } |
@@ -16,198 +16,198 @@ |
||
16 | 16 | class EventListQuery extends WP_Query |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $title |
|
21 | - */ |
|
22 | - private $title; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var integer $limit |
|
26 | - */ |
|
27 | - private $limit = 10; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string $css_class |
|
31 | - */ |
|
32 | - private $css_class; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var boolean $show_expired |
|
36 | - */ |
|
37 | - private $show_expired = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string $month |
|
41 | - */ |
|
42 | - private $month; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $category_slug |
|
46 | - */ |
|
47 | - private $category_slug; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string $order_by |
|
51 | - */ |
|
52 | - private $order_by; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $sort |
|
56 | - */ |
|
57 | - private $sort; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var boolean $show_title |
|
61 | - */ |
|
62 | - private $show_title = true; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * EE_Event_List_Query Constructor * |
|
67 | - * |
|
68 | - * @param array $args |
|
69 | - */ |
|
70 | - public function __construct($args = array()) |
|
71 | - { |
|
72 | - $args = $this->parseArgs((array) $args); |
|
73 | - $this->setupEventQueryHelper(); |
|
74 | - $this->setupFilters(); |
|
75 | - $args = $this->getQueryArgs($args); |
|
76 | - // run the query |
|
77 | - parent::__construct($args); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param array $args |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - private function parseArgs(array $args) |
|
86 | - { |
|
87 | - // incoming args could be a mix of WP query args + EE shortcode args |
|
88 | - foreach ($args as $property => $value) { |
|
89 | - // if the arg is a property of this class, then it's an EE shortcode arg |
|
90 | - if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) { |
|
91 | - // set the property value |
|
92 | - $this->{$property} = $value; |
|
93 | - // then remove it from the array of args that will later be passed to WP_Query() |
|
94 | - unset($args[ $property ]); |
|
95 | - } |
|
96 | - } |
|
97 | - return $args; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - private function setupEventQueryHelper() |
|
102 | - { |
|
103 | - // add query filters |
|
104 | - EEH_Event_Query::add_query_filters(); |
|
105 | - // set params that will get used by the filters |
|
106 | - EEH_Event_Query::set_query_params( |
|
107 | - $this->month, |
|
108 | - $this->category_slug, |
|
109 | - $this->show_expired, |
|
110 | - $this->order_by, |
|
111 | - $this->sort |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - private function setupFilters() |
|
117 | - { |
|
118 | - // first off, let's remove any filters from previous queries |
|
119 | - remove_filter( |
|
120 | - 'FHEE__archive_espresso_events_template__show_header', |
|
121 | - array($this, 'show_event_list_title') |
|
122 | - ); |
|
123 | - remove_filter( |
|
124 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
125 | - array($this, 'event_list_title') |
|
126 | - ); |
|
127 | - remove_all_filters('FHEE__content_espresso_events__event_class'); |
|
128 | - // Event List Title ? |
|
129 | - add_filter( |
|
130 | - 'FHEE__archive_espresso_events_template__show_header', |
|
131 | - array($this, 'show_event_list_title') |
|
132 | - ); |
|
133 | - add_filter( |
|
134 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
135 | - array($this, 'event_list_title'), |
|
136 | - 10, |
|
137 | - 1 |
|
138 | - ); |
|
139 | - // add the css class |
|
140 | - add_filter( |
|
141 | - 'FHEE__content_espresso_events__event_class', |
|
142 | - array($this, 'event_list_css'), |
|
143 | - 10, |
|
144 | - 1 |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - private function getQueryArgs(array $args) |
|
150 | - { |
|
151 | - // the current "page" we are viewing |
|
152 | - $paged = max(1, get_query_var('paged')); |
|
153 | - // Force these args |
|
154 | - return array_merge( |
|
155 | - $args, |
|
156 | - array( |
|
157 | - 'post_type' => 'espresso_events', |
|
158 | - 'posts_per_page' => $this->limit, |
|
159 | - 'update_post_term_cache' => false, |
|
160 | - 'update_post_meta_cache' => false, |
|
161 | - 'paged' => $paged, |
|
162 | - 'offset' => ($paged - 1) * $this->limit, |
|
163 | - ) |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
168 | - |
|
169 | - /** |
|
170 | - * show_event_list_title |
|
171 | - * |
|
172 | - * @return boolean |
|
173 | - */ |
|
174 | - public function show_event_list_title() |
|
175 | - { |
|
176 | - return filter_var( |
|
177 | - $this->show_title, |
|
178 | - FILTER_VALIDATE_BOOLEAN |
|
179 | - ); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter |
|
185 | - * |
|
186 | - * @param string $event_list_title |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function event_list_title($event_list_title = '') |
|
190 | - { |
|
191 | - if (! empty($this->title)) { |
|
192 | - return $this->title; |
|
193 | - } |
|
194 | - return $event_list_title; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * callback for FHEE__content_espresso_events__event_class filter |
|
200 | - * |
|
201 | - * @param string $event_list_css |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function event_list_css($event_list_css = '') |
|
205 | - { |
|
206 | - $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
207 | - $event_list_css .= ! empty($this->css_class) ? $this->css_class : ''; |
|
208 | - $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
209 | - $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : ''; |
|
210 | - return $event_list_css; |
|
211 | - } |
|
212 | - // phpcs:enable |
|
19 | + /** |
|
20 | + * @var string $title |
|
21 | + */ |
|
22 | + private $title; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var integer $limit |
|
26 | + */ |
|
27 | + private $limit = 10; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string $css_class |
|
31 | + */ |
|
32 | + private $css_class; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var boolean $show_expired |
|
36 | + */ |
|
37 | + private $show_expired = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string $month |
|
41 | + */ |
|
42 | + private $month; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $category_slug |
|
46 | + */ |
|
47 | + private $category_slug; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string $order_by |
|
51 | + */ |
|
52 | + private $order_by; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $sort |
|
56 | + */ |
|
57 | + private $sort; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var boolean $show_title |
|
61 | + */ |
|
62 | + private $show_title = true; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * EE_Event_List_Query Constructor * |
|
67 | + * |
|
68 | + * @param array $args |
|
69 | + */ |
|
70 | + public function __construct($args = array()) |
|
71 | + { |
|
72 | + $args = $this->parseArgs((array) $args); |
|
73 | + $this->setupEventQueryHelper(); |
|
74 | + $this->setupFilters(); |
|
75 | + $args = $this->getQueryArgs($args); |
|
76 | + // run the query |
|
77 | + parent::__construct($args); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param array $args |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + private function parseArgs(array $args) |
|
86 | + { |
|
87 | + // incoming args could be a mix of WP query args + EE shortcode args |
|
88 | + foreach ($args as $property => $value) { |
|
89 | + // if the arg is a property of this class, then it's an EE shortcode arg |
|
90 | + if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) { |
|
91 | + // set the property value |
|
92 | + $this->{$property} = $value; |
|
93 | + // then remove it from the array of args that will later be passed to WP_Query() |
|
94 | + unset($args[ $property ]); |
|
95 | + } |
|
96 | + } |
|
97 | + return $args; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + private function setupEventQueryHelper() |
|
102 | + { |
|
103 | + // add query filters |
|
104 | + EEH_Event_Query::add_query_filters(); |
|
105 | + // set params that will get used by the filters |
|
106 | + EEH_Event_Query::set_query_params( |
|
107 | + $this->month, |
|
108 | + $this->category_slug, |
|
109 | + $this->show_expired, |
|
110 | + $this->order_by, |
|
111 | + $this->sort |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + private function setupFilters() |
|
117 | + { |
|
118 | + // first off, let's remove any filters from previous queries |
|
119 | + remove_filter( |
|
120 | + 'FHEE__archive_espresso_events_template__show_header', |
|
121 | + array($this, 'show_event_list_title') |
|
122 | + ); |
|
123 | + remove_filter( |
|
124 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
125 | + array($this, 'event_list_title') |
|
126 | + ); |
|
127 | + remove_all_filters('FHEE__content_espresso_events__event_class'); |
|
128 | + // Event List Title ? |
|
129 | + add_filter( |
|
130 | + 'FHEE__archive_espresso_events_template__show_header', |
|
131 | + array($this, 'show_event_list_title') |
|
132 | + ); |
|
133 | + add_filter( |
|
134 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
135 | + array($this, 'event_list_title'), |
|
136 | + 10, |
|
137 | + 1 |
|
138 | + ); |
|
139 | + // add the css class |
|
140 | + add_filter( |
|
141 | + 'FHEE__content_espresso_events__event_class', |
|
142 | + array($this, 'event_list_css'), |
|
143 | + 10, |
|
144 | + 1 |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + private function getQueryArgs(array $args) |
|
150 | + { |
|
151 | + // the current "page" we are viewing |
|
152 | + $paged = max(1, get_query_var('paged')); |
|
153 | + // Force these args |
|
154 | + return array_merge( |
|
155 | + $args, |
|
156 | + array( |
|
157 | + 'post_type' => 'espresso_events', |
|
158 | + 'posts_per_page' => $this->limit, |
|
159 | + 'update_post_term_cache' => false, |
|
160 | + 'update_post_meta_cache' => false, |
|
161 | + 'paged' => $paged, |
|
162 | + 'offset' => ($paged - 1) * $this->limit, |
|
163 | + ) |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
168 | + |
|
169 | + /** |
|
170 | + * show_event_list_title |
|
171 | + * |
|
172 | + * @return boolean |
|
173 | + */ |
|
174 | + public function show_event_list_title() |
|
175 | + { |
|
176 | + return filter_var( |
|
177 | + $this->show_title, |
|
178 | + FILTER_VALIDATE_BOOLEAN |
|
179 | + ); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter |
|
185 | + * |
|
186 | + * @param string $event_list_title |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function event_list_title($event_list_title = '') |
|
190 | + { |
|
191 | + if (! empty($this->title)) { |
|
192 | + return $this->title; |
|
193 | + } |
|
194 | + return $event_list_title; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * callback for FHEE__content_espresso_events__event_class filter |
|
200 | + * |
|
201 | + * @param string $event_list_css |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function event_list_css($event_list_css = '') |
|
205 | + { |
|
206 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
207 | + $event_list_css .= ! empty($this->css_class) ? $this->css_class : ''; |
|
208 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
209 | + $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : ''; |
|
210 | + return $event_list_css; |
|
211 | + } |
|
212 | + // phpcs:enable |
|
213 | 213 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // set the property value |
92 | 92 | $this->{$property} = $value; |
93 | 93 | // then remove it from the array of args that will later be passed to WP_Query() |
94 | - unset($args[ $property ]); |
|
94 | + unset($args[$property]); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | return $args; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function event_list_title($event_list_title = '') |
190 | 190 | { |
191 | - if (! empty($this->title)) { |
|
191 | + if ( ! empty($this->title)) { |
|
192 | 192 | return $this->title; |
193 | 193 | } |
194 | 194 | return $event_list_title; |
@@ -15,112 +15,112 @@ |
||
15 | 15 | class Basic implements EmailValidatorInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param string $email_address |
|
20 | - * @return bool |
|
21 | - * @throws EmailValidationException |
|
22 | - */ |
|
23 | - public function validate($email_address) |
|
24 | - { |
|
25 | - if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
26 | - // email not in correct {string}@{string} format |
|
27 | - throw new EmailValidationException( |
|
28 | - esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
29 | - ); |
|
30 | - } |
|
31 | - $atIndex = $this->getAtIndex($email_address); |
|
32 | - $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
33 | - $localLen = strlen($local); |
|
34 | - if ($localLen < 1) { |
|
35 | - // no local part |
|
36 | - throw new EmailValidationException( |
|
37 | - esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
38 | - ); |
|
39 | - } |
|
40 | - if ($localLen > 64) { |
|
41 | - // local part length exceeded |
|
42 | - throw new EmailValidationException( |
|
43 | - esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
44 | - ); |
|
45 | - } |
|
46 | - if ($local[0] === '.') { |
|
47 | - // local part starts with '.' |
|
48 | - throw new EmailValidationException( |
|
49 | - esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
50 | - ); |
|
51 | - } |
|
52 | - if ($local[ $localLen - 1 ] === '.') { |
|
53 | - // local part starts or ends with '.' |
|
54 | - throw new EmailValidationException( |
|
55 | - esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
56 | - ); |
|
57 | - } |
|
58 | - if (preg_match('/\\.\\./', $local)) { |
|
59 | - // local part has two consecutive dots |
|
60 | - throw new EmailValidationException( |
|
61 | - esc_html__( |
|
62 | - 'Email local-part (before the @) must not have two consecutive periods.', |
|
63 | - 'event_espresso' |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
68 | - $domainLen = strlen($domain); |
|
69 | - if ($domainLen < 1) { |
|
70 | - throw new EmailValidationException( |
|
71 | - esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
72 | - ); |
|
73 | - } |
|
74 | - if ($domainLen > 255) { |
|
75 | - // domain part length exceeded |
|
76 | - throw new EmailValidationException( |
|
77 | - esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
78 | - ); |
|
79 | - } |
|
80 | - if (preg_match('/\\.\\./', $domain)) { |
|
81 | - // domain part has two consecutive dots |
|
82 | - throw new EmailValidationException( |
|
83 | - esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
84 | - ); |
|
85 | - } |
|
86 | - return true; |
|
87 | - } |
|
18 | + /** |
|
19 | + * @param string $email_address |
|
20 | + * @return bool |
|
21 | + * @throws EmailValidationException |
|
22 | + */ |
|
23 | + public function validate($email_address) |
|
24 | + { |
|
25 | + if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
26 | + // email not in correct {string}@{string} format |
|
27 | + throw new EmailValidationException( |
|
28 | + esc_html__('Email does not have the required @ sign.', 'event_espresso') |
|
29 | + ); |
|
30 | + } |
|
31 | + $atIndex = $this->getAtIndex($email_address); |
|
32 | + $local = $this->getLocalPartOfEmail($email_address, $atIndex); |
|
33 | + $localLen = strlen($local); |
|
34 | + if ($localLen < 1) { |
|
35 | + // no local part |
|
36 | + throw new EmailValidationException( |
|
37 | + esc_html__('Email local-part (before the @) is required.', 'event_espresso') |
|
38 | + ); |
|
39 | + } |
|
40 | + if ($localLen > 64) { |
|
41 | + // local part length exceeded |
|
42 | + throw new EmailValidationException( |
|
43 | + esc_html__('Email local-part (before the @) is too long.', 'event_espresso') |
|
44 | + ); |
|
45 | + } |
|
46 | + if ($local[0] === '.') { |
|
47 | + // local part starts with '.' |
|
48 | + throw new EmailValidationException( |
|
49 | + esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
|
50 | + ); |
|
51 | + } |
|
52 | + if ($local[ $localLen - 1 ] === '.') { |
|
53 | + // local part starts or ends with '.' |
|
54 | + throw new EmailValidationException( |
|
55 | + esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
|
56 | + ); |
|
57 | + } |
|
58 | + if (preg_match('/\\.\\./', $local)) { |
|
59 | + // local part has two consecutive dots |
|
60 | + throw new EmailValidationException( |
|
61 | + esc_html__( |
|
62 | + 'Email local-part (before the @) must not have two consecutive periods.', |
|
63 | + 'event_espresso' |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + $domain = $this->getDomainPartOfEmail($email_address, $atIndex); |
|
68 | + $domainLen = strlen($domain); |
|
69 | + if ($domainLen < 1) { |
|
70 | + throw new EmailValidationException( |
|
71 | + esc_html__('Email domain (after the @) is required.', 'event_espresso') |
|
72 | + ); |
|
73 | + } |
|
74 | + if ($domainLen > 255) { |
|
75 | + // domain part length exceeded |
|
76 | + throw new EmailValidationException( |
|
77 | + esc_html__('Email domain (after the @) is too long.', 'event_espresso') |
|
78 | + ); |
|
79 | + } |
|
80 | + if (preg_match('/\\.\\./', $domain)) { |
|
81 | + // domain part has two consecutive dots |
|
82 | + throw new EmailValidationException( |
|
83 | + esc_html__('Email domain (after the @) must not have two consecutive periods.', 'event_espresso') |
|
84 | + ); |
|
85 | + } |
|
86 | + return true; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * returns the location of the @ symbol |
|
92 | - * |
|
93 | - * @param string $email_address |
|
94 | - * @return bool|string |
|
95 | - */ |
|
96 | - protected function getAtIndex($email_address) |
|
97 | - { |
|
98 | - return strrpos($email_address, '@'); |
|
99 | - } |
|
90 | + /** |
|
91 | + * returns the location of the @ symbol |
|
92 | + * |
|
93 | + * @param string $email_address |
|
94 | + * @return bool|string |
|
95 | + */ |
|
96 | + protected function getAtIndex($email_address) |
|
97 | + { |
|
98 | + return strrpos($email_address, '@'); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Gets the local part of the email |
|
104 | - * |
|
105 | - * @param string $email_address |
|
106 | - * @param bool|int $atIndex |
|
107 | - * @return bool|string |
|
108 | - */ |
|
109 | - protected function getLocalPartOfEmail($email_address, $atIndex) |
|
110 | - { |
|
111 | - return substr($email_address, 0, $atIndex); |
|
112 | - } |
|
102 | + /** |
|
103 | + * Gets the local part of the email |
|
104 | + * |
|
105 | + * @param string $email_address |
|
106 | + * @param bool|int $atIndex |
|
107 | + * @return bool|string |
|
108 | + */ |
|
109 | + protected function getLocalPartOfEmail($email_address, $atIndex) |
|
110 | + { |
|
111 | + return substr($email_address, 0, $atIndex); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | - /** |
|
116 | - * Gets the domain part of the email |
|
117 | - * |
|
118 | - * @param string $email_address |
|
119 | - * @param bool|int $atIndex |
|
120 | - * @return bool|string |
|
121 | - */ |
|
122 | - protected function getDomainPartOfEmail($email_address, $atIndex) |
|
123 | - { |
|
124 | - return substr($email_address, $atIndex + 1); |
|
125 | - } |
|
115 | + /** |
|
116 | + * Gets the domain part of the email |
|
117 | + * |
|
118 | + * @param string $email_address |
|
119 | + * @param bool|int $atIndex |
|
120 | + * @return bool|string |
|
121 | + */ |
|
122 | + protected function getDomainPartOfEmail($email_address, $atIndex) |
|
123 | + { |
|
124 | + return substr($email_address, $atIndex + 1); |
|
125 | + } |
|
126 | 126 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function validate($email_address) |
24 | 24 | { |
25 | - if (! preg_match('/^.+\@\S+$/', $email_address)) { |
|
25 | + if ( ! preg_match('/^.+\@\S+$/', $email_address)) { |
|
26 | 26 | // email not in correct {string}@{string} format |
27 | 27 | throw new EmailValidationException( |
28 | 28 | esc_html__('Email does not have the required @ sign.', 'event_espresso') |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | esc_html__('Email local-part (before the @) must not begin with a period.', 'event_espresso') |
50 | 50 | ); |
51 | 51 | } |
52 | - if ($local[ $localLen - 1 ] === '.') { |
|
52 | + if ($local[$localLen - 1] === '.') { |
|
53 | 53 | // local part starts or ends with '.' |
54 | 54 | throw new EmailValidationException( |
55 | 55 | esc_html__('Email local-part (before the @) must not end with a period.', 'event_espresso') |
@@ -29,102 +29,102 @@ |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @param EE_Event $event |
|
34 | - * @param EE_Transaction $transaction |
|
35 | - * @param EE_Ticket $ticket |
|
36 | - * @param EE_Line_Item $ticket_line_item |
|
37 | - * @param $reg_count |
|
38 | - * @param $reg_group_size |
|
39 | - * @param string $reg_status |
|
40 | - * @return EE_Registration |
|
41 | - * @throws OutOfRangeException |
|
42 | - * @throws EE_Error |
|
43 | - * @throws UnexpectedEntityException |
|
44 | - */ |
|
45 | - public function create( |
|
46 | - EE_Event $event, |
|
47 | - EE_Transaction $transaction, |
|
48 | - EE_Ticket $ticket, |
|
49 | - EE_Line_Item $ticket_line_item, |
|
50 | - $reg_count, |
|
51 | - $reg_group_size, |
|
52 | - $reg_status = EEM_Registration::status_id_incomplete |
|
53 | - ) { |
|
54 | - $registrations = $transaction->registrations(); |
|
55 | - $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
56 | - $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
57 | - $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
58 | - // generate new EE_Registration |
|
59 | - $registration = EE_Registration::new_instance( |
|
60 | - array( |
|
61 | - 'EVT_ID' => $event->ID(), |
|
62 | - 'TXN_ID' => $transaction->ID(), |
|
63 | - 'TKT_ID' => $ticket->ID(), |
|
64 | - 'STS_ID' => $reg_status, |
|
65 | - 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
66 | - 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
67 | - 'REG_count' => $reg_count, |
|
68 | - 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
69 | - 'REG_url_link' => $reg_url_link, |
|
70 | - 'REG_code' => $reg_code, |
|
71 | - ) |
|
72 | - ); |
|
73 | - if (! $registration instanceof EE_Registration) { |
|
74 | - throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
75 | - } |
|
76 | - // save registration so that we have an ID |
|
77 | - $registration->save(); |
|
78 | - // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
79 | - // because that is done as soon as the tickets are added/removed from the cart |
|
80 | - $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
81 | - $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
82 | - $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
83 | - $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
84 | - $registration->save(); |
|
85 | - return $registration; |
|
86 | - } |
|
32 | + /** |
|
33 | + * @param EE_Event $event |
|
34 | + * @param EE_Transaction $transaction |
|
35 | + * @param EE_Ticket $ticket |
|
36 | + * @param EE_Line_Item $ticket_line_item |
|
37 | + * @param $reg_count |
|
38 | + * @param $reg_group_size |
|
39 | + * @param string $reg_status |
|
40 | + * @return EE_Registration |
|
41 | + * @throws OutOfRangeException |
|
42 | + * @throws EE_Error |
|
43 | + * @throws UnexpectedEntityException |
|
44 | + */ |
|
45 | + public function create( |
|
46 | + EE_Event $event, |
|
47 | + EE_Transaction $transaction, |
|
48 | + EE_Ticket $ticket, |
|
49 | + EE_Line_Item $ticket_line_item, |
|
50 | + $reg_count, |
|
51 | + $reg_group_size, |
|
52 | + $reg_status = EEM_Registration::status_id_incomplete |
|
53 | + ) { |
|
54 | + $registrations = $transaction->registrations(); |
|
55 | + $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
56 | + $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
57 | + $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
58 | + // generate new EE_Registration |
|
59 | + $registration = EE_Registration::new_instance( |
|
60 | + array( |
|
61 | + 'EVT_ID' => $event->ID(), |
|
62 | + 'TXN_ID' => $transaction->ID(), |
|
63 | + 'TKT_ID' => $ticket->ID(), |
|
64 | + 'STS_ID' => $reg_status, |
|
65 | + 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
66 | + 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
67 | + 'REG_count' => $reg_count, |
|
68 | + 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
69 | + 'REG_url_link' => $reg_url_link, |
|
70 | + 'REG_code' => $reg_code, |
|
71 | + ) |
|
72 | + ); |
|
73 | + if (! $registration instanceof EE_Registration) { |
|
74 | + throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
75 | + } |
|
76 | + // save registration so that we have an ID |
|
77 | + $registration->save(); |
|
78 | + // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
79 | + // because that is done as soon as the tickets are added/removed from the cart |
|
80 | + $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
81 | + $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
82 | + $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
83 | + $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
84 | + $registration->save(); |
|
85 | + return $registration; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @param EE_Transaction $transaction |
|
91 | - * @param EE_Ticket $ticket |
|
92 | - * @param EE_Line_Item $ticket_line_item |
|
93 | - * @return float |
|
94 | - * @throws EE_Error |
|
95 | - * @throws OutOfRangeException |
|
96 | - */ |
|
97 | - protected function resolveFinalPrice( |
|
98 | - EE_Transaction $transaction, |
|
99 | - EE_Ticket $ticket, |
|
100 | - EE_Line_Item $ticket_line_item |
|
101 | - ) { |
|
102 | - $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | - $transaction->total_line_item(), |
|
104 | - $ticket_line_item |
|
105 | - ); |
|
106 | - $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | - return (float) $final_price; |
|
108 | - } |
|
89 | + /** |
|
90 | + * @param EE_Transaction $transaction |
|
91 | + * @param EE_Ticket $ticket |
|
92 | + * @param EE_Line_Item $ticket_line_item |
|
93 | + * @return float |
|
94 | + * @throws EE_Error |
|
95 | + * @throws OutOfRangeException |
|
96 | + */ |
|
97 | + protected function resolveFinalPrice( |
|
98 | + EE_Transaction $transaction, |
|
99 | + EE_Ticket $ticket, |
|
100 | + EE_Line_Item $ticket_line_item |
|
101 | + ) { |
|
102 | + $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
103 | + $transaction->total_line_item(), |
|
104 | + $ticket_line_item |
|
105 | + ); |
|
106 | + $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
107 | + return (float) $final_price; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * @param EE_Registration[] $registrations |
|
113 | - * @param boolean $update_existing_registrations |
|
114 | - * @return int |
|
115 | - * @throws EE_Error |
|
116 | - */ |
|
117 | - protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
118 | - { |
|
119 | - $new_reg_count = count($registrations) + 1; |
|
120 | - if ($update_existing_registrations) { |
|
121 | - foreach ($registrations as $registration) { |
|
122 | - if ($registration instanceof EE_Registration) { |
|
123 | - $registration->set_count($new_reg_count); |
|
124 | - $registration->save(); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - return $new_reg_count; |
|
129 | - } |
|
111 | + /** |
|
112 | + * @param EE_Registration[] $registrations |
|
113 | + * @param boolean $update_existing_registrations |
|
114 | + * @return int |
|
115 | + * @throws EE_Error |
|
116 | + */ |
|
117 | + protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
118 | + { |
|
119 | + $new_reg_count = count($registrations) + 1; |
|
120 | + if ($update_existing_registrations) { |
|
121 | + foreach ($registrations as $registration) { |
|
122 | + if ($registration instanceof EE_Registration) { |
|
123 | + $registration->set_count($new_reg_count); |
|
124 | + $registration->save(); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + return $new_reg_count; |
|
129 | + } |
|
130 | 130 | } |
@@ -70,14 +70,14 @@ |
||
70 | 70 | 'REG_code' => $reg_code, |
71 | 71 | ) |
72 | 72 | ); |
73 | - if (! $registration instanceof EE_Registration) { |
|
73 | + if ( ! $registration instanceof EE_Registration) { |
|
74 | 74 | throw new UnexpectedEntityException($registration, 'EE_Registration'); |
75 | 75 | } |
76 | 76 | // save registration so that we have an ID |
77 | 77 | $registration->save(); |
78 | 78 | // track reservation on reg but don't adjust ticket and datetime reserved counts |
79 | 79 | // because that is done as soon as the tickets are added/removed from the cart |
80 | - $registration->reserve_ticket(false, 'CreateRegistrationService:' . __LINE__); |
|
80 | + $registration->reserve_ticket(false, 'CreateRegistrationService:'.__LINE__); |
|
81 | 81 | $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
82 | 82 | $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
83 | 83 | $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
@@ -26,149 +26,149 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param EE_Registration $target_registration |
|
31 | - * @param EE_Registration $registration_to_copy |
|
32 | - * @return bool |
|
33 | - * @throws UnexpectedEntityException |
|
34 | - * @throws EntityNotFoundException |
|
35 | - * @throws RuntimeException |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - public function copyRegistrationDetails( |
|
39 | - EE_Registration $target_registration, |
|
40 | - EE_Registration $registration_to_copy |
|
41 | - ) { |
|
42 | - // copy attendee |
|
43 | - $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
44 | - $target_registration->updateStatusBasedOnTotalPaid(false); |
|
45 | - $target_registration->save(); |
|
46 | - // get answers to previous reg questions |
|
47 | - $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
48 | - // get questions to new event reg form |
|
49 | - $new_event = $target_registration->event(); |
|
50 | - $question_groups = $new_event->question_groups( |
|
51 | - array( |
|
52 | - array( |
|
53 | - 'Event.EVT_ID' => $new_event->ID(), |
|
54 | - 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
55 | - ), |
|
56 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
57 | - ) |
|
58 | - ); |
|
59 | - foreach ($question_groups as $question_group) { |
|
60 | - if ($question_group instanceof \EE_Question_Group) { |
|
61 | - foreach ($question_group->questions() as $question) { |
|
62 | - if ($question instanceof EE_Question) { |
|
63 | - $this->generateNewAnswer( |
|
64 | - $question, |
|
65 | - $target_registration, |
|
66 | - $answers |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - return true; |
|
73 | - } |
|
29 | + /** |
|
30 | + * @param EE_Registration $target_registration |
|
31 | + * @param EE_Registration $registration_to_copy |
|
32 | + * @return bool |
|
33 | + * @throws UnexpectedEntityException |
|
34 | + * @throws EntityNotFoundException |
|
35 | + * @throws RuntimeException |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + public function copyRegistrationDetails( |
|
39 | + EE_Registration $target_registration, |
|
40 | + EE_Registration $registration_to_copy |
|
41 | + ) { |
|
42 | + // copy attendee |
|
43 | + $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
44 | + $target_registration->updateStatusBasedOnTotalPaid(false); |
|
45 | + $target_registration->save(); |
|
46 | + // get answers to previous reg questions |
|
47 | + $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
48 | + // get questions to new event reg form |
|
49 | + $new_event = $target_registration->event(); |
|
50 | + $question_groups = $new_event->question_groups( |
|
51 | + array( |
|
52 | + array( |
|
53 | + 'Event.EVT_ID' => $new_event->ID(), |
|
54 | + 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
55 | + ), |
|
56 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
57 | + ) |
|
58 | + ); |
|
59 | + foreach ($question_groups as $question_group) { |
|
60 | + if ($question_group instanceof \EE_Question_Group) { |
|
61 | + foreach ($question_group->questions() as $question) { |
|
62 | + if ($question instanceof EE_Question) { |
|
63 | + $this->generateNewAnswer( |
|
64 | + $question, |
|
65 | + $target_registration, |
|
66 | + $answers |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + return true; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @param EE_Answer[] $answers |
|
78 | - * @return array |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - protected function reindexAnswersByQuestionId(array $answers) |
|
82 | - { |
|
83 | - $reindexed_answers = array(); |
|
84 | - foreach ($answers as $answer) { |
|
85 | - if ($answer instanceof EE_Answer) { |
|
86 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
87 | - } |
|
88 | - } |
|
89 | - return $reindexed_answers; |
|
90 | - } |
|
76 | + /** |
|
77 | + * @param EE_Answer[] $answers |
|
78 | + * @return array |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + protected function reindexAnswersByQuestionId(array $answers) |
|
82 | + { |
|
83 | + $reindexed_answers = array(); |
|
84 | + foreach ($answers as $answer) { |
|
85 | + if ($answer instanceof EE_Answer) { |
|
86 | + $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
87 | + } |
|
88 | + } |
|
89 | + return $reindexed_answers; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @param EE_Question $question |
|
95 | - * @param EE_Registration $registration |
|
96 | - * @param $previous_answers |
|
97 | - * @return EE_Answer |
|
98 | - * @throws UnexpectedEntityException |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - protected function generateNewAnswer( |
|
102 | - EE_Question $question, |
|
103 | - EE_Registration $registration, |
|
104 | - $previous_answers |
|
105 | - ) { |
|
106 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | - ? $previous_answers[ $question->ID() ] |
|
108 | - : ''; |
|
109 | - $new_answer = EE_Answer::new_instance( |
|
110 | - array( |
|
111 | - 'QST_ID' => $question->ID(), |
|
112 | - 'REG_ID' => $registration->ID(), |
|
113 | - 'ANS_value' => $old_answer_value, |
|
114 | - ) |
|
115 | - ); |
|
116 | - if (! $new_answer instanceof EE_Answer) { |
|
117 | - throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
118 | - } |
|
119 | - $new_answer->save(); |
|
120 | - return $new_answer; |
|
121 | - } |
|
93 | + /** |
|
94 | + * @param EE_Question $question |
|
95 | + * @param EE_Registration $registration |
|
96 | + * @param $previous_answers |
|
97 | + * @return EE_Answer |
|
98 | + * @throws UnexpectedEntityException |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + protected function generateNewAnswer( |
|
102 | + EE_Question $question, |
|
103 | + EE_Registration $registration, |
|
104 | + $previous_answers |
|
105 | + ) { |
|
106 | + $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | + ? $previous_answers[ $question->ID() ] |
|
108 | + : ''; |
|
109 | + $new_answer = EE_Answer::new_instance( |
|
110 | + array( |
|
111 | + 'QST_ID' => $question->ID(), |
|
112 | + 'REG_ID' => $registration->ID(), |
|
113 | + 'ANS_value' => $old_answer_value, |
|
114 | + ) |
|
115 | + ); |
|
116 | + if (! $new_answer instanceof EE_Answer) { |
|
117 | + throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
118 | + } |
|
119 | + $new_answer->save(); |
|
120 | + return $new_answer; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * @param EE_Registration $target_registration |
|
126 | - * @param EE_Registration $registration_to_copy |
|
127 | - * @return bool |
|
128 | - * @throws RuntimeException |
|
129 | - * @throws UnexpectedEntityException |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function copyPaymentDetails( |
|
133 | - EE_Registration $target_registration, |
|
134 | - EE_Registration $registration_to_copy |
|
135 | - ) { |
|
136 | - $save = false; |
|
137 | - $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
138 | - $new_registration_payment_total = 0; |
|
139 | - $registration_to_copy_total = $registration_to_copy->paid(); |
|
140 | - foreach ($previous_registration_payments as $previous_registration_payment) { |
|
141 | - if ($previous_registration_payment instanceof EE_Registration_Payment |
|
142 | - && $previous_registration_payment->payment() instanceof EE_Payment |
|
143 | - && $previous_registration_payment->payment()->is_approved() |
|
144 | - ) { |
|
145 | - $payment_amount = $previous_registration_payment->amount(); |
|
146 | - $new_registration_payment = EE_Registration_Payment::new_instance( |
|
147 | - array( |
|
148 | - 'REG_ID' => $target_registration->ID(), |
|
149 | - 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
150 | - 'RPY_amount' => $payment_amount, |
|
151 | - ) |
|
152 | - ); |
|
153 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | - throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
155 | - } |
|
156 | - $new_registration_payment->save(); |
|
157 | - // if new reg payment is good, then set old reg payment amount to zero |
|
158 | - $previous_registration_payment->set_amount(0); |
|
159 | - $previous_registration_payment->save(); |
|
160 | - // now increment/decrement payment amounts |
|
161 | - $new_registration_payment_total += $payment_amount; |
|
162 | - $registration_to_copy_total -= $payment_amount; |
|
163 | - $save = true; |
|
164 | - } |
|
165 | - } |
|
166 | - if ($save) { |
|
167 | - $target_registration->set_paid($new_registration_payment_total); |
|
168 | - $target_registration->save(); |
|
169 | - $registration_to_copy->set_paid($registration_to_copy_total); |
|
170 | - $registration_to_copy->save(); |
|
171 | - } |
|
172 | - return true; |
|
173 | - } |
|
124 | + /** |
|
125 | + * @param EE_Registration $target_registration |
|
126 | + * @param EE_Registration $registration_to_copy |
|
127 | + * @return bool |
|
128 | + * @throws RuntimeException |
|
129 | + * @throws UnexpectedEntityException |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function copyPaymentDetails( |
|
133 | + EE_Registration $target_registration, |
|
134 | + EE_Registration $registration_to_copy |
|
135 | + ) { |
|
136 | + $save = false; |
|
137 | + $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
138 | + $new_registration_payment_total = 0; |
|
139 | + $registration_to_copy_total = $registration_to_copy->paid(); |
|
140 | + foreach ($previous_registration_payments as $previous_registration_payment) { |
|
141 | + if ($previous_registration_payment instanceof EE_Registration_Payment |
|
142 | + && $previous_registration_payment->payment() instanceof EE_Payment |
|
143 | + && $previous_registration_payment->payment()->is_approved() |
|
144 | + ) { |
|
145 | + $payment_amount = $previous_registration_payment->amount(); |
|
146 | + $new_registration_payment = EE_Registration_Payment::new_instance( |
|
147 | + array( |
|
148 | + 'REG_ID' => $target_registration->ID(), |
|
149 | + 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
150 | + 'RPY_amount' => $payment_amount, |
|
151 | + ) |
|
152 | + ); |
|
153 | + if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | + throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
155 | + } |
|
156 | + $new_registration_payment->save(); |
|
157 | + // if new reg payment is good, then set old reg payment amount to zero |
|
158 | + $previous_registration_payment->set_amount(0); |
|
159 | + $previous_registration_payment->save(); |
|
160 | + // now increment/decrement payment amounts |
|
161 | + $new_registration_payment_total += $payment_amount; |
|
162 | + $registration_to_copy_total -= $payment_amount; |
|
163 | + $save = true; |
|
164 | + } |
|
165 | + } |
|
166 | + if ($save) { |
|
167 | + $target_registration->set_paid($new_registration_payment_total); |
|
168 | + $target_registration->save(); |
|
169 | + $registration_to_copy->set_paid($registration_to_copy_total); |
|
170 | + $registration_to_copy->save(); |
|
171 | + } |
|
172 | + return true; |
|
173 | + } |
|
174 | 174 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $reindexed_answers = array(); |
84 | 84 | foreach ($answers as $answer) { |
85 | 85 | if ($answer instanceof EE_Answer) { |
86 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
86 | + $reindexed_answers[$answer->question_ID()] = $answer->value(); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | return $reindexed_answers; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | EE_Registration $registration, |
104 | 104 | $previous_answers |
105 | 105 | ) { |
106 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | - ? $previous_answers[ $question->ID() ] |
|
106 | + $old_answer_value = isset($previous_answers[$question->ID()]) |
|
107 | + ? $previous_answers[$question->ID()] |
|
108 | 108 | : ''; |
109 | 109 | $new_answer = EE_Answer::new_instance( |
110 | 110 | array( |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | 'ANS_value' => $old_answer_value, |
114 | 114 | ) |
115 | 115 | ); |
116 | - if (! $new_answer instanceof EE_Answer) { |
|
116 | + if ( ! $new_answer instanceof EE_Answer) { |
|
117 | 117 | throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
118 | 118 | } |
119 | 119 | $new_answer->save(); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'RPY_amount' => $payment_amount, |
151 | 151 | ) |
152 | 152 | ); |
153 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
153 | + if ( ! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | 154 | throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
155 | 155 | } |
156 | 156 | $new_registration_payment->save(); |
@@ -26,702 +26,702 @@ |
||
26 | 26 | class EventSpacesCalculator |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Event $event |
|
31 | - */ |
|
32 | - private $event; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array $datetime_query_params |
|
36 | - */ |
|
37 | - private $datetime_query_params; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Ticket[] $active_tickets |
|
41 | - */ |
|
42 | - private $active_tickets = array(); |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EE_Datetime[] $datetimes |
|
46 | - */ |
|
47 | - private $datetimes = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * Array of Ticket IDs grouped by Datetime |
|
51 | - * |
|
52 | - * @var array $datetimes |
|
53 | - */ |
|
54 | - private $datetime_tickets = array(); |
|
55 | - |
|
56 | - /** |
|
57 | - * Max spaces for each Datetime (reg limit - previous sold) |
|
58 | - * |
|
59 | - * @var array $datetime_spaces |
|
60 | - */ |
|
61 | - private $datetime_spaces = array(); |
|
62 | - |
|
63 | - /** |
|
64 | - * Array of Datetime IDs grouped by Ticket |
|
65 | - * |
|
66 | - * @var array[] $ticket_datetimes |
|
67 | - */ |
|
68 | - private $ticket_datetimes = array(); |
|
69 | - |
|
70 | - /** |
|
71 | - * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
72 | - * |
|
73 | - * @var array $ticket_quantities |
|
74 | - */ |
|
75 | - private $ticket_quantities = array(); |
|
76 | - |
|
77 | - /** |
|
78 | - * total quantity of sold and reserved for each ticket |
|
79 | - * |
|
80 | - * @var array $tickets_sold |
|
81 | - */ |
|
82 | - private $tickets_sold = array(); |
|
83 | - |
|
84 | - /** |
|
85 | - * total spaces available across all datetimes |
|
86 | - * |
|
87 | - * @var array $total_spaces |
|
88 | - */ |
|
89 | - private $total_spaces = array(); |
|
90 | - |
|
91 | - /** |
|
92 | - * @var boolean $debug |
|
93 | - */ |
|
94 | - private $debug = false; // true false |
|
95 | - |
|
96 | - /** |
|
97 | - * @var null|int $spaces_remaining |
|
98 | - */ |
|
99 | - private $spaces_remaining; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var null|int $total_spaces_available |
|
103 | - */ |
|
104 | - private $total_spaces_available; |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * EventSpacesCalculator constructor. |
|
109 | - * |
|
110 | - * @param EE_Event $event |
|
111 | - * @param array $datetime_query_params |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
115 | - { |
|
116 | - $this->event = $event; |
|
117 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
118 | - $this->setHooks(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - private function setHooks() |
|
126 | - { |
|
127 | - add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
128 | - add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
129 | - add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
130 | - add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
131 | - add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
132 | - add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
133 | - add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
134 | - add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - public function clearResults() |
|
142 | - { |
|
143 | - $this->spaces_remaining = null; |
|
144 | - $this->total_spaces_available = null; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return EE_Ticket[] |
|
150 | - * @throws EE_Error |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - * @throws InvalidInterfaceException |
|
153 | - * @throws InvalidArgumentException |
|
154 | - */ |
|
155 | - public function getActiveTickets() |
|
156 | - { |
|
157 | - if (empty($this->active_tickets)) { |
|
158 | - $this->active_tickets = $this->event->tickets( |
|
159 | - array( |
|
160 | - array('TKT_deleted' => false), |
|
161 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
165 | - return $this->active_tickets; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param EE_Ticket[] $active_tickets |
|
171 | - * @throws EE_Error |
|
172 | - * @throws DomainException |
|
173 | - * @throws UnexpectedEntityException |
|
174 | - */ |
|
175 | - public function setActiveTickets(array $active_tickets = array()) |
|
176 | - { |
|
177 | - if (! empty($active_tickets)) { |
|
178 | - foreach ($active_tickets as $active_ticket) { |
|
179 | - $this->validateTicket($active_ticket); |
|
180 | - } |
|
181 | - // sort incoming array by ticket quantity (asc) |
|
182 | - usort( |
|
183 | - $active_tickets, |
|
184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
185 | - if ($a->qty() === $b->qty()) { |
|
186 | - return 0; |
|
187 | - } |
|
188 | - return ($a->qty() < $b->qty()) |
|
189 | - ? -1 |
|
190 | - : 1; |
|
191 | - } |
|
192 | - ); |
|
193 | - } |
|
194 | - $this->active_tickets = $active_tickets; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @param $ticket |
|
200 | - * @throws DomainException |
|
201 | - * @throws EE_Error |
|
202 | - * @throws UnexpectedEntityException |
|
203 | - */ |
|
204 | - private function validateTicket($ticket) |
|
205 | - { |
|
206 | - if (! $ticket instanceof EE_Ticket) { |
|
207 | - throw new DomainException( |
|
208 | - esc_html__( |
|
209 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
210 | - 'event_espresso' |
|
211 | - ) |
|
212 | - ); |
|
213 | - } |
|
214 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
215 | - throw new DomainException( |
|
216 | - sprintf( |
|
217 | - esc_html__( |
|
218 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
219 | - 'event_espresso' |
|
220 | - ), |
|
221 | - $ticket->get_event_ID(), |
|
222 | - $this->event->ID() |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @return EE_Datetime[] |
|
231 | - */ |
|
232 | - public function getDatetimes() |
|
233 | - { |
|
234 | - return $this->datetimes; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param EE_Datetime $datetime |
|
240 | - * @throws EE_Error |
|
241 | - * @throws DomainException |
|
242 | - */ |
|
243 | - public function setDatetime(EE_Datetime $datetime) |
|
244 | - { |
|
245 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
246 | - throw new DomainException( |
|
247 | - sprintf( |
|
248 | - esc_html__( |
|
249 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - $datetime->event()->ID(), |
|
253 | - $this->event->ID() |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * calculate spaces remaining based on "saleable" tickets |
|
263 | - * |
|
264 | - * @return float|int |
|
265 | - * @throws EE_Error |
|
266 | - * @throws DomainException |
|
267 | - * @throws UnexpectedEntityException |
|
268 | - * @throws InvalidDataTypeException |
|
269 | - * @throws InvalidInterfaceException |
|
270 | - * @throws InvalidArgumentException |
|
271 | - */ |
|
272 | - public function spacesRemaining() |
|
273 | - { |
|
274 | - if ($this->spaces_remaining === null) { |
|
275 | - $this->initialize(); |
|
276 | - $this->spaces_remaining = $this->calculate(); |
|
277 | - } |
|
278 | - return $this->spaces_remaining; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * calculates total available spaces for an event with no regard for sold tickets |
|
284 | - * |
|
285 | - * @return int|float |
|
286 | - * @throws EE_Error |
|
287 | - * @throws DomainException |
|
288 | - * @throws UnexpectedEntityException |
|
289 | - * @throws InvalidDataTypeException |
|
290 | - * @throws InvalidInterfaceException |
|
291 | - * @throws InvalidArgumentException |
|
292 | - */ |
|
293 | - public function totalSpacesAvailable() |
|
294 | - { |
|
295 | - if ($this->total_spaces_available === null) { |
|
296 | - $this->initialize(); |
|
297 | - $this->total_spaces_available = $this->calculate(false); |
|
298 | - } |
|
299 | - return $this->total_spaces_available; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Loops through the active tickets for the event |
|
305 | - * and builds a series of data arrays that will be used for calculating |
|
306 | - * the total maximum available spaces, as well as the spaces remaining. |
|
307 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
308 | - * we need to be constantly updating these data arrays as things change, |
|
309 | - * which is the entire reason for their existence. |
|
310 | - * |
|
311 | - * @throws EE_Error |
|
312 | - * @throws DomainException |
|
313 | - * @throws UnexpectedEntityException |
|
314 | - * @throws InvalidDataTypeException |
|
315 | - * @throws InvalidInterfaceException |
|
316 | - * @throws InvalidArgumentException |
|
317 | - */ |
|
318 | - private function initialize() |
|
319 | - { |
|
320 | - if ($this->debug) { |
|
321 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
322 | - } |
|
323 | - $this->datetime_tickets = array(); |
|
324 | - $this->datetime_spaces = array(); |
|
325 | - $this->ticket_datetimes = array(); |
|
326 | - $this->ticket_quantities = array(); |
|
327 | - $this->tickets_sold = array(); |
|
328 | - $this->total_spaces = array(); |
|
329 | - $active_tickets = $this->getActiveTickets(); |
|
330 | - if (! empty($active_tickets)) { |
|
331 | - foreach ($active_tickets as $ticket) { |
|
332 | - $this->validateTicket($ticket); |
|
333 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
334 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
335 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
336 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
337 | - // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
338 | - $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
339 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
340 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
341 | - foreach ($ticket_datetimes as $datetime) { |
|
342 | - // save all datetimes |
|
343 | - $this->setDatetime($datetime); |
|
344 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
345 | - $reg_limit = $datetime->reg_limit(); |
|
346 | - // ticket quantity can not exceed datetime reg limit |
|
347 | - $max_tickets = min($max_tickets, $reg_limit); |
|
348 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
349 | - // we are going to move all of our data into the following arrays: |
|
350 | - // datetime spaces initially represents the reg limit for each datetime, |
|
351 | - // but this will get adjusted as tickets are accounted for |
|
352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
353 | - // just an array of ticket IDs grouped by datetime |
|
354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
355 | - // and an array of datetime IDs grouped by ticket |
|
356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
357 | - } |
|
358 | - // total quantity of sold and reserved for each ticket |
|
359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
360 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
362 | - } |
|
363 | - } |
|
364 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
365 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
366 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
367 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
368 | - // but overwrite all of the data with that from datetime_tickets |
|
369 | - $this->datetime_tickets = array_merge( |
|
370 | - $this->datetime_spaces, |
|
371 | - $this->datetime_tickets |
|
372 | - ); |
|
373 | - if ($this->debug) { |
|
374 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
375 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
376 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * performs calculations on initialized data |
|
383 | - * |
|
384 | - * @param bool $consider_sold |
|
385 | - * @return int|float |
|
386 | - */ |
|
387 | - private function calculate($consider_sold = true) |
|
388 | - { |
|
389 | - if ($this->debug) { |
|
390 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
391 | - \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
392 | - } |
|
393 | - if ($consider_sold) { |
|
394 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
395 | - $this->adjustTicketQuantitiesDueToSales(); |
|
396 | - } |
|
397 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
398 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
399 | - } |
|
400 | - // total spaces available is just the sum of the spaces available for each datetime |
|
401 | - $spaces_remaining = array_sum($this->total_spaces); |
|
402 | - if ($this->debug) { |
|
403 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
404 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
405 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
406 | - } |
|
407 | - return $spaces_remaining; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
413 | - */ |
|
414 | - private function adjustTicketQuantitiesDueToSales() |
|
415 | - { |
|
416 | - if ($this->debug) { |
|
417 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
418 | - } |
|
419 | - foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
420 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
421 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
422 | - // don't let values go below zero |
|
423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
425 | - 0 |
|
426 | - ); |
|
427 | - if ($this->debug) { |
|
428 | - \EEH_Debug_Tools::printr( |
|
429 | - "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
430 | - 'subtracting', |
|
431 | - __FILE__, |
|
432 | - __LINE__ |
|
433 | - ); |
|
434 | - } |
|
435 | - } |
|
436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
438 | - ) { |
|
439 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
440 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
441 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
442 | - // don't let values go below zero |
|
443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
445 | - 0 |
|
446 | - ); |
|
447 | - if ($this->debug) { |
|
448 | - \EEH_Debug_Tools::printr( |
|
449 | - "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
450 | - 'subtracting', |
|
451 | - __FILE__, |
|
452 | - __LINE__ |
|
453 | - ); |
|
454 | - } |
|
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - /** |
|
463 | - * @param string $datetime_identifier |
|
464 | - * @param array $tickets |
|
465 | - */ |
|
466 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
467 | - { |
|
468 | - // make sure a reg limit is set for the datetime |
|
469 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
470 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
471 | - : 0; |
|
472 | - // and bail if it is not |
|
473 | - if (! $reg_limit) { |
|
474 | - if ($this->debug) { |
|
475 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
476 | - } |
|
477 | - return; |
|
478 | - } |
|
479 | - if ($this->debug) { |
|
480 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
481 | - \EEH_Debug_Tools::printr( |
|
482 | - "{$reg_limit}", |
|
483 | - 'REG LIMIT', |
|
484 | - __FILE__, |
|
485 | - __LINE__ |
|
486 | - ); |
|
487 | - } |
|
488 | - // number of allocated spaces always starts at zero |
|
489 | - $spaces_allocated = 0; |
|
490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
491 | - foreach ($tickets as $ticket_identifier) { |
|
492 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
493 | - $datetime_identifier, |
|
494 | - $reg_limit, |
|
495 | - $ticket_identifier, |
|
496 | - $spaces_allocated |
|
497 | - ); |
|
498 | - } |
|
499 | - // spaces can't be negative |
|
500 | - $spaces_allocated = max($spaces_allocated, 0); |
|
501 | - if ($spaces_allocated) { |
|
502 | - // track any non-zero values |
|
503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
504 | - if ($this->debug) { |
|
505 | - \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
506 | - } |
|
507 | - } else { |
|
508 | - if ($this->debug) { |
|
509 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
510 | - } |
|
511 | - } |
|
512 | - if ($this->debug) { |
|
513 | - \EEH_Debug_Tools::printr( |
|
514 | - $this->total_spaces[ $datetime_identifier ], |
|
515 | - '$total_spaces', |
|
516 | - __FILE__, |
|
517 | - __LINE__ |
|
518 | - ); |
|
519 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
520 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
521 | - } |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * @param string $datetime_identifier |
|
527 | - * @param int $reg_limit |
|
528 | - * @param string $ticket_identifier |
|
529 | - * @param int $spaces_allocated |
|
530 | - * @return int |
|
531 | - */ |
|
532 | - private function calculateAvailableSpacesForTicket( |
|
533 | - $datetime_identifier, |
|
534 | - $reg_limit, |
|
535 | - $ticket_identifier, |
|
536 | - $spaces_allocated |
|
537 | - ) { |
|
538 | - // make sure ticket quantity is set |
|
539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
541 | - : 0; |
|
542 | - if ($this->debug) { |
|
543 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
544 | - \EEH_Debug_Tools::printr( |
|
545 | - "{$ticket_quantity}", |
|
546 | - "ticket $ticket_identifier quantity: ", |
|
547 | - __FILE__, |
|
548 | - __LINE__, |
|
549 | - 2 |
|
550 | - ); |
|
551 | - } |
|
552 | - if ($ticket_quantity) { |
|
553 | - if ($this->debug) { |
|
554 | - \EEH_Debug_Tools::printr( |
|
555 | - ($spaces_allocated <= $reg_limit) |
|
556 | - ? 'true' |
|
557 | - : 'false', |
|
558 | - ' . spaces_allocated <= reg_limit = ', |
|
559 | - __FILE__, |
|
560 | - __LINE__ |
|
561 | - ); |
|
562 | - } |
|
563 | - // if the datetime is NOT at full capacity yet |
|
564 | - if ($spaces_allocated <= $reg_limit) { |
|
565 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
566 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
567 | - // or the maximum ticket quantity |
|
568 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
569 | - // adjust the available quantity in our tracking array |
|
570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
571 | - // and increment spaces allocated for this datetime |
|
572 | - $spaces_allocated += $ticket_quantity; |
|
573 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
574 | - if ($this->debug) { |
|
575 | - \EEH_Debug_Tools::printr( |
|
576 | - "{$ticket_quantity} {$ticket_identifier} tickets", |
|
577 | - ' > > allocate ', |
|
578 | - __FILE__, |
|
579 | - __LINE__, |
|
580 | - 3 |
|
581 | - ); |
|
582 | - if ($at_capacity) { |
|
583 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
584 | - } |
|
585 | - } |
|
586 | - // now adjust all other datetimes that allow access to this ticket |
|
587 | - $this->adjustDatetimes( |
|
588 | - $datetime_identifier, |
|
589 | - $ticket_identifier, |
|
590 | - $ticket_quantity, |
|
591 | - $at_capacity |
|
592 | - ); |
|
593 | - } |
|
594 | - } |
|
595 | - return $spaces_allocated; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * subtracts ticket amounts from all datetime reg limits |
|
601 | - * that allow access to the ticket specified, |
|
602 | - * because that ticket could be used |
|
603 | - * to attend any of the datetimes it has access to |
|
604 | - * |
|
605 | - * @param string $datetime_identifier |
|
606 | - * @param string $ticket_identifier |
|
607 | - * @param bool $at_capacity |
|
608 | - * @param int $ticket_quantity |
|
609 | - */ |
|
610 | - private function adjustDatetimes( |
|
611 | - $datetime_identifier, |
|
612 | - $ticket_identifier, |
|
613 | - $ticket_quantity, |
|
614 | - $at_capacity |
|
615 | - ) { |
|
616 | - /** @var array $datetime_tickets */ |
|
617 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
618 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
619 | - continue; |
|
620 | - } |
|
621 | - $adjusted = $this->adjustDatetimeSpaces( |
|
622 | - $datetime_ID, |
|
623 | - $ticket_identifier, |
|
624 | - $ticket_quantity |
|
625 | - ); |
|
626 | - // skip to next ticket if nothing changed |
|
627 | - if (! ($adjusted || $at_capacity)) { |
|
628 | - continue; |
|
629 | - } |
|
630 | - // then all of it's tickets are now unavailable |
|
631 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
632 | - if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
635 | - ) { |
|
636 | - if ($this->debug) { |
|
637 | - \EEH_Debug_Tools::printr( |
|
638 | - $datetime_ticket, |
|
639 | - ' . . . adjust ticket quantities for', |
|
640 | - __FILE__, |
|
641 | - __LINE__ |
|
642 | - ); |
|
643 | - } |
|
644 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
645 | - // otherwise just subtract the ticket quantity |
|
646 | - $new_quantity = $at_capacity |
|
647 | - ? 0 |
|
648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
649 | - // don't let ticket quantity go below zero |
|
650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
651 | - if ($this->debug) { |
|
652 | - \EEH_Debug_Tools::printr( |
|
653 | - $at_capacity |
|
654 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
656 | - " . . . . {$datetime_ticket} quantity set to ", |
|
657 | - __FILE__, |
|
658 | - __LINE__ |
|
659 | - ); |
|
660 | - } |
|
661 | - } |
|
662 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
663 | - if ($datetime_ticket === $ticket_identifier) { |
|
664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
666 | - ) { |
|
667 | - if ($this->debug) { |
|
668 | - \EEH_Debug_Tools::printr( |
|
669 | - $datetime_ticket, |
|
670 | - ' . . adjust other Datetimes for', |
|
671 | - __FILE__, |
|
672 | - __LINE__ |
|
673 | - ); |
|
674 | - } |
|
675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
676 | - // don't adjust the current datetime twice |
|
677 | - if ($datetime !== $datetime_identifier) { |
|
678 | - $this->adjustDatetimeSpaces( |
|
679 | - $datetime, |
|
680 | - $datetime_ticket, |
|
681 | - $ticket_quantity |
|
682 | - ); |
|
683 | - } |
|
684 | - } |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - } |
|
689 | - } |
|
690 | - |
|
691 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
692 | - { |
|
693 | - // does datetime have spaces available? |
|
694 | - // and does the supplied ticket have access to this datetime ? |
|
695 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
696 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
697 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
698 | - ) { |
|
699 | - if ($this->debug) { |
|
700 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
701 | - \EEH_Debug_Tools::printr( |
|
702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
703 | - " . . current {$datetime_identifier} spaces available", |
|
704 | - __FILE__, |
|
705 | - __LINE__ |
|
706 | - ); |
|
707 | - } |
|
708 | - // then decrement the available spaces for the datetime |
|
709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
710 | - // but don't let quantities go below zero |
|
711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
713 | - 0 |
|
714 | - ); |
|
715 | - if ($this->debug) { |
|
716 | - \EEH_Debug_Tools::printr( |
|
717 | - "{$ticket_quantity}", |
|
718 | - " . . . {$datetime_identifier} capacity reduced by", |
|
719 | - __FILE__, |
|
720 | - __LINE__ |
|
721 | - ); |
|
722 | - } |
|
723 | - return true; |
|
724 | - } |
|
725 | - return false; |
|
726 | - } |
|
29 | + /** |
|
30 | + * @var EE_Event $event |
|
31 | + */ |
|
32 | + private $event; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array $datetime_query_params |
|
36 | + */ |
|
37 | + private $datetime_query_params; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Ticket[] $active_tickets |
|
41 | + */ |
|
42 | + private $active_tickets = array(); |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EE_Datetime[] $datetimes |
|
46 | + */ |
|
47 | + private $datetimes = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * Array of Ticket IDs grouped by Datetime |
|
51 | + * |
|
52 | + * @var array $datetimes |
|
53 | + */ |
|
54 | + private $datetime_tickets = array(); |
|
55 | + |
|
56 | + /** |
|
57 | + * Max spaces for each Datetime (reg limit - previous sold) |
|
58 | + * |
|
59 | + * @var array $datetime_spaces |
|
60 | + */ |
|
61 | + private $datetime_spaces = array(); |
|
62 | + |
|
63 | + /** |
|
64 | + * Array of Datetime IDs grouped by Ticket |
|
65 | + * |
|
66 | + * @var array[] $ticket_datetimes |
|
67 | + */ |
|
68 | + private $ticket_datetimes = array(); |
|
69 | + |
|
70 | + /** |
|
71 | + * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
72 | + * |
|
73 | + * @var array $ticket_quantities |
|
74 | + */ |
|
75 | + private $ticket_quantities = array(); |
|
76 | + |
|
77 | + /** |
|
78 | + * total quantity of sold and reserved for each ticket |
|
79 | + * |
|
80 | + * @var array $tickets_sold |
|
81 | + */ |
|
82 | + private $tickets_sold = array(); |
|
83 | + |
|
84 | + /** |
|
85 | + * total spaces available across all datetimes |
|
86 | + * |
|
87 | + * @var array $total_spaces |
|
88 | + */ |
|
89 | + private $total_spaces = array(); |
|
90 | + |
|
91 | + /** |
|
92 | + * @var boolean $debug |
|
93 | + */ |
|
94 | + private $debug = false; // true false |
|
95 | + |
|
96 | + /** |
|
97 | + * @var null|int $spaces_remaining |
|
98 | + */ |
|
99 | + private $spaces_remaining; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var null|int $total_spaces_available |
|
103 | + */ |
|
104 | + private $total_spaces_available; |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * EventSpacesCalculator constructor. |
|
109 | + * |
|
110 | + * @param EE_Event $event |
|
111 | + * @param array $datetime_query_params |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
115 | + { |
|
116 | + $this->event = $event; |
|
117 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
118 | + $this->setHooks(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + private function setHooks() |
|
126 | + { |
|
127 | + add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
128 | + add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
129 | + add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
130 | + add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
131 | + add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
132 | + add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
133 | + add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
134 | + add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + public function clearResults() |
|
142 | + { |
|
143 | + $this->spaces_remaining = null; |
|
144 | + $this->total_spaces_available = null; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return EE_Ticket[] |
|
150 | + * @throws EE_Error |
|
151 | + * @throws InvalidDataTypeException |
|
152 | + * @throws InvalidInterfaceException |
|
153 | + * @throws InvalidArgumentException |
|
154 | + */ |
|
155 | + public function getActiveTickets() |
|
156 | + { |
|
157 | + if (empty($this->active_tickets)) { |
|
158 | + $this->active_tickets = $this->event->tickets( |
|
159 | + array( |
|
160 | + array('TKT_deleted' => false), |
|
161 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | + return $this->active_tickets; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param EE_Ticket[] $active_tickets |
|
171 | + * @throws EE_Error |
|
172 | + * @throws DomainException |
|
173 | + * @throws UnexpectedEntityException |
|
174 | + */ |
|
175 | + public function setActiveTickets(array $active_tickets = array()) |
|
176 | + { |
|
177 | + if (! empty($active_tickets)) { |
|
178 | + foreach ($active_tickets as $active_ticket) { |
|
179 | + $this->validateTicket($active_ticket); |
|
180 | + } |
|
181 | + // sort incoming array by ticket quantity (asc) |
|
182 | + usort( |
|
183 | + $active_tickets, |
|
184 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
185 | + if ($a->qty() === $b->qty()) { |
|
186 | + return 0; |
|
187 | + } |
|
188 | + return ($a->qty() < $b->qty()) |
|
189 | + ? -1 |
|
190 | + : 1; |
|
191 | + } |
|
192 | + ); |
|
193 | + } |
|
194 | + $this->active_tickets = $active_tickets; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @param $ticket |
|
200 | + * @throws DomainException |
|
201 | + * @throws EE_Error |
|
202 | + * @throws UnexpectedEntityException |
|
203 | + */ |
|
204 | + private function validateTicket($ticket) |
|
205 | + { |
|
206 | + if (! $ticket instanceof EE_Ticket) { |
|
207 | + throw new DomainException( |
|
208 | + esc_html__( |
|
209 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
210 | + 'event_espresso' |
|
211 | + ) |
|
212 | + ); |
|
213 | + } |
|
214 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
215 | + throw new DomainException( |
|
216 | + sprintf( |
|
217 | + esc_html__( |
|
218 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
219 | + 'event_espresso' |
|
220 | + ), |
|
221 | + $ticket->get_event_ID(), |
|
222 | + $this->event->ID() |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @return EE_Datetime[] |
|
231 | + */ |
|
232 | + public function getDatetimes() |
|
233 | + { |
|
234 | + return $this->datetimes; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param EE_Datetime $datetime |
|
240 | + * @throws EE_Error |
|
241 | + * @throws DomainException |
|
242 | + */ |
|
243 | + public function setDatetime(EE_Datetime $datetime) |
|
244 | + { |
|
245 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
246 | + throw new DomainException( |
|
247 | + sprintf( |
|
248 | + esc_html__( |
|
249 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + $datetime->event()->ID(), |
|
253 | + $this->event->ID() |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * calculate spaces remaining based on "saleable" tickets |
|
263 | + * |
|
264 | + * @return float|int |
|
265 | + * @throws EE_Error |
|
266 | + * @throws DomainException |
|
267 | + * @throws UnexpectedEntityException |
|
268 | + * @throws InvalidDataTypeException |
|
269 | + * @throws InvalidInterfaceException |
|
270 | + * @throws InvalidArgumentException |
|
271 | + */ |
|
272 | + public function spacesRemaining() |
|
273 | + { |
|
274 | + if ($this->spaces_remaining === null) { |
|
275 | + $this->initialize(); |
|
276 | + $this->spaces_remaining = $this->calculate(); |
|
277 | + } |
|
278 | + return $this->spaces_remaining; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * calculates total available spaces for an event with no regard for sold tickets |
|
284 | + * |
|
285 | + * @return int|float |
|
286 | + * @throws EE_Error |
|
287 | + * @throws DomainException |
|
288 | + * @throws UnexpectedEntityException |
|
289 | + * @throws InvalidDataTypeException |
|
290 | + * @throws InvalidInterfaceException |
|
291 | + * @throws InvalidArgumentException |
|
292 | + */ |
|
293 | + public function totalSpacesAvailable() |
|
294 | + { |
|
295 | + if ($this->total_spaces_available === null) { |
|
296 | + $this->initialize(); |
|
297 | + $this->total_spaces_available = $this->calculate(false); |
|
298 | + } |
|
299 | + return $this->total_spaces_available; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Loops through the active tickets for the event |
|
305 | + * and builds a series of data arrays that will be used for calculating |
|
306 | + * the total maximum available spaces, as well as the spaces remaining. |
|
307 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
308 | + * we need to be constantly updating these data arrays as things change, |
|
309 | + * which is the entire reason for their existence. |
|
310 | + * |
|
311 | + * @throws EE_Error |
|
312 | + * @throws DomainException |
|
313 | + * @throws UnexpectedEntityException |
|
314 | + * @throws InvalidDataTypeException |
|
315 | + * @throws InvalidInterfaceException |
|
316 | + * @throws InvalidArgumentException |
|
317 | + */ |
|
318 | + private function initialize() |
|
319 | + { |
|
320 | + if ($this->debug) { |
|
321 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
322 | + } |
|
323 | + $this->datetime_tickets = array(); |
|
324 | + $this->datetime_spaces = array(); |
|
325 | + $this->ticket_datetimes = array(); |
|
326 | + $this->ticket_quantities = array(); |
|
327 | + $this->tickets_sold = array(); |
|
328 | + $this->total_spaces = array(); |
|
329 | + $active_tickets = $this->getActiveTickets(); |
|
330 | + if (! empty($active_tickets)) { |
|
331 | + foreach ($active_tickets as $ticket) { |
|
332 | + $this->validateTicket($ticket); |
|
333 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
334 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
335 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
336 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
337 | + // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
338 | + $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
339 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
340 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
341 | + foreach ($ticket_datetimes as $datetime) { |
|
342 | + // save all datetimes |
|
343 | + $this->setDatetime($datetime); |
|
344 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
345 | + $reg_limit = $datetime->reg_limit(); |
|
346 | + // ticket quantity can not exceed datetime reg limit |
|
347 | + $max_tickets = min($max_tickets, $reg_limit); |
|
348 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
349 | + // we are going to move all of our data into the following arrays: |
|
350 | + // datetime spaces initially represents the reg limit for each datetime, |
|
351 | + // but this will get adjusted as tickets are accounted for |
|
352 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
353 | + // just an array of ticket IDs grouped by datetime |
|
354 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
355 | + // and an array of datetime IDs grouped by ticket |
|
356 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
357 | + } |
|
358 | + // total quantity of sold and reserved for each ticket |
|
359 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
360 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
361 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
362 | + } |
|
363 | + } |
|
364 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
365 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
366 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
367 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
368 | + // but overwrite all of the data with that from datetime_tickets |
|
369 | + $this->datetime_tickets = array_merge( |
|
370 | + $this->datetime_spaces, |
|
371 | + $this->datetime_tickets |
|
372 | + ); |
|
373 | + if ($this->debug) { |
|
374 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
375 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
376 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * performs calculations on initialized data |
|
383 | + * |
|
384 | + * @param bool $consider_sold |
|
385 | + * @return int|float |
|
386 | + */ |
|
387 | + private function calculate($consider_sold = true) |
|
388 | + { |
|
389 | + if ($this->debug) { |
|
390 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
391 | + \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
392 | + } |
|
393 | + if ($consider_sold) { |
|
394 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
395 | + $this->adjustTicketQuantitiesDueToSales(); |
|
396 | + } |
|
397 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
398 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
399 | + } |
|
400 | + // total spaces available is just the sum of the spaces available for each datetime |
|
401 | + $spaces_remaining = array_sum($this->total_spaces); |
|
402 | + if ($this->debug) { |
|
403 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
404 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
405 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
406 | + } |
|
407 | + return $spaces_remaining; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
413 | + */ |
|
414 | + private function adjustTicketQuantitiesDueToSales() |
|
415 | + { |
|
416 | + if ($this->debug) { |
|
417 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
418 | + } |
|
419 | + foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
420 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
421 | + $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
422 | + // don't let values go below zero |
|
423 | + $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | + $this->ticket_quantities[ $ticket_identifier ], |
|
425 | + 0 |
|
426 | + ); |
|
427 | + if ($this->debug) { |
|
428 | + \EEH_Debug_Tools::printr( |
|
429 | + "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
430 | + 'subtracting', |
|
431 | + __FILE__, |
|
432 | + __LINE__ |
|
433 | + ); |
|
434 | + } |
|
435 | + } |
|
436 | + if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
438 | + ) { |
|
439 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
440 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
441 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
442 | + // don't let values go below zero |
|
443 | + $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | + $this->datetime_spaces[ $ticket_datetime ], |
|
445 | + 0 |
|
446 | + ); |
|
447 | + if ($this->debug) { |
|
448 | + \EEH_Debug_Tools::printr( |
|
449 | + "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
450 | + 'subtracting', |
|
451 | + __FILE__, |
|
452 | + __LINE__ |
|
453 | + ); |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + /** |
|
463 | + * @param string $datetime_identifier |
|
464 | + * @param array $tickets |
|
465 | + */ |
|
466 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
467 | + { |
|
468 | + // make sure a reg limit is set for the datetime |
|
469 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
470 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
471 | + : 0; |
|
472 | + // and bail if it is not |
|
473 | + if (! $reg_limit) { |
|
474 | + if ($this->debug) { |
|
475 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
476 | + } |
|
477 | + return; |
|
478 | + } |
|
479 | + if ($this->debug) { |
|
480 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
481 | + \EEH_Debug_Tools::printr( |
|
482 | + "{$reg_limit}", |
|
483 | + 'REG LIMIT', |
|
484 | + __FILE__, |
|
485 | + __LINE__ |
|
486 | + ); |
|
487 | + } |
|
488 | + // number of allocated spaces always starts at zero |
|
489 | + $spaces_allocated = 0; |
|
490 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
491 | + foreach ($tickets as $ticket_identifier) { |
|
492 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
493 | + $datetime_identifier, |
|
494 | + $reg_limit, |
|
495 | + $ticket_identifier, |
|
496 | + $spaces_allocated |
|
497 | + ); |
|
498 | + } |
|
499 | + // spaces can't be negative |
|
500 | + $spaces_allocated = max($spaces_allocated, 0); |
|
501 | + if ($spaces_allocated) { |
|
502 | + // track any non-zero values |
|
503 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
504 | + if ($this->debug) { |
|
505 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
506 | + } |
|
507 | + } else { |
|
508 | + if ($this->debug) { |
|
509 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
510 | + } |
|
511 | + } |
|
512 | + if ($this->debug) { |
|
513 | + \EEH_Debug_Tools::printr( |
|
514 | + $this->total_spaces[ $datetime_identifier ], |
|
515 | + '$total_spaces', |
|
516 | + __FILE__, |
|
517 | + __LINE__ |
|
518 | + ); |
|
519 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
520 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
521 | + } |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * @param string $datetime_identifier |
|
527 | + * @param int $reg_limit |
|
528 | + * @param string $ticket_identifier |
|
529 | + * @param int $spaces_allocated |
|
530 | + * @return int |
|
531 | + */ |
|
532 | + private function calculateAvailableSpacesForTicket( |
|
533 | + $datetime_identifier, |
|
534 | + $reg_limit, |
|
535 | + $ticket_identifier, |
|
536 | + $spaces_allocated |
|
537 | + ) { |
|
538 | + // make sure ticket quantity is set |
|
539 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
541 | + : 0; |
|
542 | + if ($this->debug) { |
|
543 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
544 | + \EEH_Debug_Tools::printr( |
|
545 | + "{$ticket_quantity}", |
|
546 | + "ticket $ticket_identifier quantity: ", |
|
547 | + __FILE__, |
|
548 | + __LINE__, |
|
549 | + 2 |
|
550 | + ); |
|
551 | + } |
|
552 | + if ($ticket_quantity) { |
|
553 | + if ($this->debug) { |
|
554 | + \EEH_Debug_Tools::printr( |
|
555 | + ($spaces_allocated <= $reg_limit) |
|
556 | + ? 'true' |
|
557 | + : 'false', |
|
558 | + ' . spaces_allocated <= reg_limit = ', |
|
559 | + __FILE__, |
|
560 | + __LINE__ |
|
561 | + ); |
|
562 | + } |
|
563 | + // if the datetime is NOT at full capacity yet |
|
564 | + if ($spaces_allocated <= $reg_limit) { |
|
565 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
566 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
567 | + // or the maximum ticket quantity |
|
568 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
569 | + // adjust the available quantity in our tracking array |
|
570 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
571 | + // and increment spaces allocated for this datetime |
|
572 | + $spaces_allocated += $ticket_quantity; |
|
573 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
574 | + if ($this->debug) { |
|
575 | + \EEH_Debug_Tools::printr( |
|
576 | + "{$ticket_quantity} {$ticket_identifier} tickets", |
|
577 | + ' > > allocate ', |
|
578 | + __FILE__, |
|
579 | + __LINE__, |
|
580 | + 3 |
|
581 | + ); |
|
582 | + if ($at_capacity) { |
|
583 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
584 | + } |
|
585 | + } |
|
586 | + // now adjust all other datetimes that allow access to this ticket |
|
587 | + $this->adjustDatetimes( |
|
588 | + $datetime_identifier, |
|
589 | + $ticket_identifier, |
|
590 | + $ticket_quantity, |
|
591 | + $at_capacity |
|
592 | + ); |
|
593 | + } |
|
594 | + } |
|
595 | + return $spaces_allocated; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * subtracts ticket amounts from all datetime reg limits |
|
601 | + * that allow access to the ticket specified, |
|
602 | + * because that ticket could be used |
|
603 | + * to attend any of the datetimes it has access to |
|
604 | + * |
|
605 | + * @param string $datetime_identifier |
|
606 | + * @param string $ticket_identifier |
|
607 | + * @param bool $at_capacity |
|
608 | + * @param int $ticket_quantity |
|
609 | + */ |
|
610 | + private function adjustDatetimes( |
|
611 | + $datetime_identifier, |
|
612 | + $ticket_identifier, |
|
613 | + $ticket_quantity, |
|
614 | + $at_capacity |
|
615 | + ) { |
|
616 | + /** @var array $datetime_tickets */ |
|
617 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
618 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
619 | + continue; |
|
620 | + } |
|
621 | + $adjusted = $this->adjustDatetimeSpaces( |
|
622 | + $datetime_ID, |
|
623 | + $ticket_identifier, |
|
624 | + $ticket_quantity |
|
625 | + ); |
|
626 | + // skip to next ticket if nothing changed |
|
627 | + if (! ($adjusted || $at_capacity)) { |
|
628 | + continue; |
|
629 | + } |
|
630 | + // then all of it's tickets are now unavailable |
|
631 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
632 | + if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
633 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
635 | + ) { |
|
636 | + if ($this->debug) { |
|
637 | + \EEH_Debug_Tools::printr( |
|
638 | + $datetime_ticket, |
|
639 | + ' . . . adjust ticket quantities for', |
|
640 | + __FILE__, |
|
641 | + __LINE__ |
|
642 | + ); |
|
643 | + } |
|
644 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
645 | + // otherwise just subtract the ticket quantity |
|
646 | + $new_quantity = $at_capacity |
|
647 | + ? 0 |
|
648 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
649 | + // don't let ticket quantity go below zero |
|
650 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
651 | + if ($this->debug) { |
|
652 | + \EEH_Debug_Tools::printr( |
|
653 | + $at_capacity |
|
654 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
655 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
656 | + " . . . . {$datetime_ticket} quantity set to ", |
|
657 | + __FILE__, |
|
658 | + __LINE__ |
|
659 | + ); |
|
660 | + } |
|
661 | + } |
|
662 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
663 | + if ($datetime_ticket === $ticket_identifier) { |
|
664 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
666 | + ) { |
|
667 | + if ($this->debug) { |
|
668 | + \EEH_Debug_Tools::printr( |
|
669 | + $datetime_ticket, |
|
670 | + ' . . adjust other Datetimes for', |
|
671 | + __FILE__, |
|
672 | + __LINE__ |
|
673 | + ); |
|
674 | + } |
|
675 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
676 | + // don't adjust the current datetime twice |
|
677 | + if ($datetime !== $datetime_identifier) { |
|
678 | + $this->adjustDatetimeSpaces( |
|
679 | + $datetime, |
|
680 | + $datetime_ticket, |
|
681 | + $ticket_quantity |
|
682 | + ); |
|
683 | + } |
|
684 | + } |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + } |
|
689 | + } |
|
690 | + |
|
691 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
692 | + { |
|
693 | + // does datetime have spaces available? |
|
694 | + // and does the supplied ticket have access to this datetime ? |
|
695 | + if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
696 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
697 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
698 | + ) { |
|
699 | + if ($this->debug) { |
|
700 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
701 | + \EEH_Debug_Tools::printr( |
|
702 | + "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
703 | + " . . current {$datetime_identifier} spaces available", |
|
704 | + __FILE__, |
|
705 | + __LINE__ |
|
706 | + ); |
|
707 | + } |
|
708 | + // then decrement the available spaces for the datetime |
|
709 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
710 | + // but don't let quantities go below zero |
|
711 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | + $this->datetime_spaces[ $datetime_identifier ], |
|
713 | + 0 |
|
714 | + ); |
|
715 | + if ($this->debug) { |
|
716 | + \EEH_Debug_Tools::printr( |
|
717 | + "{$ticket_quantity}", |
|
718 | + " . . . {$datetime_identifier} capacity reduced by", |
|
719 | + __FILE__, |
|
720 | + __LINE__ |
|
721 | + ); |
|
722 | + } |
|
723 | + return true; |
|
724 | + } |
|
725 | + return false; |
|
726 | + } |
|
727 | 727 | } |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public function setActiveTickets(array $active_tickets = array()) |
176 | 176 | { |
177 | - if (! empty($active_tickets)) { |
|
177 | + if ( ! empty($active_tickets)) { |
|
178 | 178 | foreach ($active_tickets as $active_ticket) { |
179 | 179 | $this->validateTicket($active_ticket); |
180 | 180 | } |
181 | 181 | // sort incoming array by ticket quantity (asc) |
182 | 182 | usort( |
183 | 183 | $active_tickets, |
184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
184 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
185 | 185 | if ($a->qty() === $b->qty()) { |
186 | 186 | return 0; |
187 | 187 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | private function validateTicket($ticket) |
205 | 205 | { |
206 | - if (! $ticket instanceof EE_Ticket) { |
|
206 | + if ( ! $ticket instanceof EE_Ticket) { |
|
207 | 207 | throw new DomainException( |
208 | 208 | esc_html__( |
209 | 209 | 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | ) |
255 | 255 | ); |
256 | 256 | } |
257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
257 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | $this->tickets_sold = array(); |
328 | 328 | $this->total_spaces = array(); |
329 | 329 | $active_tickets = $this->getActiveTickets(); |
330 | - if (! empty($active_tickets)) { |
|
330 | + if ( ! empty($active_tickets)) { |
|
331 | 331 | foreach ($active_tickets as $ticket) { |
332 | 332 | $this->validateTicket($ticket); |
333 | 333 | // we need to index our data arrays using strings for the purpose of sorting, |
@@ -349,16 +349,16 @@ discard block |
||
349 | 349 | // we are going to move all of our data into the following arrays: |
350 | 350 | // datetime spaces initially represents the reg limit for each datetime, |
351 | 351 | // but this will get adjusted as tickets are accounted for |
352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
352 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
353 | 353 | // just an array of ticket IDs grouped by datetime |
354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
354 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
355 | 355 | // and an array of datetime IDs grouped by ticket |
356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
356 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
357 | 357 | } |
358 | 358 | // total quantity of sold and reserved for each ticket |
359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
359 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
360 | 360 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
361 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -417,11 +417,11 @@ discard block |
||
417 | 417 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
418 | 418 | } |
419 | 419 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
420 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
421 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
420 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
421 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
422 | 422 | // don't let values go below zero |
423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
423 | + $this->ticket_quantities[$ticket_identifier] = max( |
|
424 | + $this->ticket_quantities[$ticket_identifier], |
|
425 | 425 | 0 |
426 | 426 | ); |
427 | 427 | if ($this->debug) { |
@@ -433,15 +433,15 @@ discard block |
||
433 | 433 | ); |
434 | 434 | } |
435 | 435 | } |
436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
436 | + if (isset($this->ticket_datetimes[$ticket_identifier]) |
|
437 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
438 | 438 | ) { |
439 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
440 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
441 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
439 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
440 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
441 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
442 | 442 | // don't let values go below zero |
443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
443 | + $this->datetime_spaces[$ticket_datetime] = max( |
|
444 | + $this->datetime_spaces[$ticket_datetime], |
|
445 | 445 | 0 |
446 | 446 | ); |
447 | 447 | if ($this->debug) { |
@@ -466,11 +466,11 @@ discard block |
||
466 | 466 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
467 | 467 | { |
468 | 468 | // make sure a reg limit is set for the datetime |
469 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
470 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
469 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
470 | + ? $this->datetime_spaces[$datetime_identifier] |
|
471 | 471 | : 0; |
472 | 472 | // and bail if it is not |
473 | - if (! $reg_limit) { |
|
473 | + if ( ! $reg_limit) { |
|
474 | 474 | if ($this->debug) { |
475 | 475 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
476 | 476 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | } |
488 | 488 | // number of allocated spaces always starts at zero |
489 | 489 | $spaces_allocated = 0; |
490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
490 | + $this->total_spaces[$datetime_identifier] = 0; |
|
491 | 491 | foreach ($tickets as $ticket_identifier) { |
492 | 492 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
493 | 493 | $datetime_identifier, |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | $spaces_allocated = max($spaces_allocated, 0); |
501 | 501 | if ($spaces_allocated) { |
502 | 502 | // track any non-zero values |
503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
503 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
504 | 504 | if ($this->debug) { |
505 | 505 | \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
506 | 506 | } |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | } |
512 | 512 | if ($this->debug) { |
513 | 513 | \EEH_Debug_Tools::printr( |
514 | - $this->total_spaces[ $datetime_identifier ], |
|
514 | + $this->total_spaces[$datetime_identifier], |
|
515 | 515 | '$total_spaces', |
516 | 516 | __FILE__, |
517 | 517 | __LINE__ |
@@ -536,8 +536,8 @@ discard block |
||
536 | 536 | $spaces_allocated |
537 | 537 | ) { |
538 | 538 | // make sure ticket quantity is set |
539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
539 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
540 | + ? $this->ticket_quantities[$ticket_identifier] |
|
541 | 541 | : 0; |
542 | 542 | if ($this->debug) { |
543 | 543 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | // or the maximum ticket quantity |
568 | 568 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
569 | 569 | // adjust the available quantity in our tracking array |
570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
570 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
571 | 571 | // and increment spaces allocated for this datetime |
572 | 572 | $spaces_allocated += $ticket_quantity; |
573 | 573 | $at_capacity = $spaces_allocated >= $reg_limit; |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | $ticket_quantity |
625 | 625 | ); |
626 | 626 | // skip to next ticket if nothing changed |
627 | - if (! ($adjusted || $at_capacity)) { |
|
627 | + if ( ! ($adjusted || $at_capacity)) { |
|
628 | 628 | continue; |
629 | 629 | } |
630 | 630 | // then all of it's tickets are now unavailable |
631 | 631 | foreach ($datetime_tickets as $datetime_ticket) { |
632 | 632 | if (($ticket_identifier === $datetime_ticket || $at_capacity) |
633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
633 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
634 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
635 | 635 | ) { |
636 | 636 | if ($this->debug) { |
637 | 637 | \EEH_Debug_Tools::printr( |
@@ -645,14 +645,14 @@ discard block |
||
645 | 645 | // otherwise just subtract the ticket quantity |
646 | 646 | $new_quantity = $at_capacity |
647 | 647 | ? 0 |
648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
648 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
649 | 649 | // don't let ticket quantity go below zero |
650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
650 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
651 | 651 | if ($this->debug) { |
652 | 652 | \EEH_Debug_Tools::printr( |
653 | 653 | $at_capacity |
654 | 654 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
655 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
656 | 656 | " . . . . {$datetime_ticket} quantity set to ", |
657 | 657 | __FILE__, |
658 | 658 | __LINE__ |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | } |
662 | 662 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
663 | 663 | if ($datetime_ticket === $ticket_identifier) { |
664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
664 | + if (isset($this->ticket_datetimes[$datetime_ticket]) |
|
665 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
666 | 666 | ) { |
667 | 667 | if ($this->debug) { |
668 | 668 | \EEH_Debug_Tools::printr( |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | __LINE__ |
673 | 673 | ); |
674 | 674 | } |
675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
675 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
676 | 676 | // don't adjust the current datetime twice |
677 | 677 | if ($datetime !== $datetime_identifier) { |
678 | 678 | $this->adjustDatetimeSpaces( |
@@ -692,24 +692,24 @@ discard block |
||
692 | 692 | { |
693 | 693 | // does datetime have spaces available? |
694 | 694 | // and does the supplied ticket have access to this datetime ? |
695 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
696 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
697 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
695 | + if ($this->datetime_spaces[$datetime_identifier] > 0 |
|
696 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
697 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
698 | 698 | ) { |
699 | 699 | if ($this->debug) { |
700 | 700 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
701 | 701 | \EEH_Debug_Tools::printr( |
702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
702 | + "{$this->datetime_spaces[$datetime_identifier]}", |
|
703 | 703 | " . . current {$datetime_identifier} spaces available", |
704 | 704 | __FILE__, |
705 | 705 | __LINE__ |
706 | 706 | ); |
707 | 707 | } |
708 | 708 | // then decrement the available spaces for the datetime |
709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
709 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
710 | 710 | // but don't let quantities go below zero |
711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
711 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
712 | + $this->datetime_spaces[$datetime_identifier], |
|
713 | 713 | 0 |
714 | 714 | ); |
715 | 715 | if ($this->debug) { |
@@ -15,293 +15,293 @@ |
||
15 | 15 | class StatsGatherer |
16 | 16 | { |
17 | 17 | |
18 | - const COUNT_ALL_EVENTS = 'event'; |
|
19 | - const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
20 | - const COUNT_DATETIMES = 'datetime'; |
|
21 | - const COUNT_TICKETS = 'ticket'; |
|
22 | - const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
23 | - const COUNT_TICKETS_FREE = 'free_ticket'; |
|
24 | - const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
25 | - const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
26 | - const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
27 | - const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
28 | - const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
29 | - const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
30 | - const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
31 | - const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
32 | - const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
33 | - const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
34 | - const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
35 | - const INFO_SITE_CURRENCY = 'site_currency'; |
|
18 | + const COUNT_ALL_EVENTS = 'event'; |
|
19 | + const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
20 | + const COUNT_DATETIMES = 'datetime'; |
|
21 | + const COUNT_TICKETS = 'ticket'; |
|
22 | + const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
23 | + const COUNT_TICKETS_FREE = 'free_ticket'; |
|
24 | + const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
25 | + const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
26 | + const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
27 | + const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
28 | + const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
29 | + const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
30 | + const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
31 | + const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
32 | + const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
33 | + const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
34 | + const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
35 | + const INFO_SITE_CURRENCY = 'site_currency'; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @var EEM_Payment_Method |
|
40 | - */ |
|
41 | - private $payment_method_model; |
|
38 | + /** |
|
39 | + * @var EEM_Payment_Method |
|
40 | + */ |
|
41 | + private $payment_method_model; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @var EEM_Event |
|
46 | - */ |
|
47 | - private $event_model; |
|
44 | + /** |
|
45 | + * @var EEM_Event |
|
46 | + */ |
|
47 | + private $event_model; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EEM_Datetime |
|
51 | - */ |
|
52 | - private $datetime_model; |
|
49 | + /** |
|
50 | + * @var EEM_Datetime |
|
51 | + */ |
|
52 | + private $datetime_model; |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @var EEM_Ticket |
|
57 | - */ |
|
58 | - private $ticket_model; |
|
55 | + /** |
|
56 | + * @var EEM_Ticket |
|
57 | + */ |
|
58 | + private $ticket_model; |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @var EEM_Registration |
|
63 | - */ |
|
64 | - private $registration_model; |
|
61 | + /** |
|
62 | + * @var EEM_Registration |
|
63 | + */ |
|
64 | + private $registration_model; |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @var EEM_Transaction |
|
69 | - */ |
|
70 | - private $transaction_model; |
|
67 | + /** |
|
68 | + * @var EEM_Transaction |
|
69 | + */ |
|
70 | + private $transaction_model; |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * @var EE_Config |
|
75 | - */ |
|
76 | - private $config; |
|
73 | + /** |
|
74 | + * @var EE_Config |
|
75 | + */ |
|
76 | + private $config; |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * StatsGatherer constructor. |
|
81 | - * |
|
82 | - * @param EEM_Payment_Method $payment_method_model |
|
83 | - * @param EEM_Event $event_model |
|
84 | - * @param EEM_Datetime $datetime_model |
|
85 | - * @param EEM_Ticket $ticket_model |
|
86 | - * @param EEM_Registration $registration_model |
|
87 | - * @param EEM_Transaction $transaction_model |
|
88 | - * @param EE_Config $config |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - EEM_Payment_Method $payment_method_model, |
|
92 | - EEM_Event $event_model, |
|
93 | - EEM_Datetime $datetime_model, |
|
94 | - EEM_Ticket $ticket_model, |
|
95 | - EEM_Registration $registration_model, |
|
96 | - EEM_Transaction $transaction_model, |
|
97 | - EE_Config $config |
|
98 | - ) { |
|
99 | - $this->payment_method_model = $payment_method_model; |
|
100 | - $this->event_model = $event_model; |
|
101 | - $this->datetime_model = $datetime_model; |
|
102 | - $this->ticket_model = $ticket_model; |
|
103 | - $this->registration_model = $registration_model; |
|
104 | - $this->transaction_model = $transaction_model; |
|
105 | - $this->config = $config; |
|
106 | - } |
|
79 | + /** |
|
80 | + * StatsGatherer constructor. |
|
81 | + * |
|
82 | + * @param EEM_Payment_Method $payment_method_model |
|
83 | + * @param EEM_Event $event_model |
|
84 | + * @param EEM_Datetime $datetime_model |
|
85 | + * @param EEM_Ticket $ticket_model |
|
86 | + * @param EEM_Registration $registration_model |
|
87 | + * @param EEM_Transaction $transaction_model |
|
88 | + * @param EE_Config $config |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + EEM_Payment_Method $payment_method_model, |
|
92 | + EEM_Event $event_model, |
|
93 | + EEM_Datetime $datetime_model, |
|
94 | + EEM_Ticket $ticket_model, |
|
95 | + EEM_Registration $registration_model, |
|
96 | + EEM_Transaction $transaction_model, |
|
97 | + EE_Config $config |
|
98 | + ) { |
|
99 | + $this->payment_method_model = $payment_method_model; |
|
100 | + $this->event_model = $event_model; |
|
101 | + $this->datetime_model = $datetime_model; |
|
102 | + $this->ticket_model = $ticket_model; |
|
103 | + $this->registration_model = $registration_model; |
|
104 | + $this->transaction_model = $transaction_model; |
|
105 | + $this->config = $config; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Return the stats array for PUE UXIP stats. |
|
111 | - * |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function stats() |
|
115 | - { |
|
116 | - $stats = $this->paymentMethodStats(); |
|
117 | - // a-ok so let's setup our stats. |
|
118 | - $stats = array_merge($stats, array( |
|
119 | - 'is_multisite' => is_multisite() && is_main_site(), |
|
120 | - 'active_theme' => $this->getActiveThemeStat(), |
|
121 | - 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
122 | - 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
123 | - 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
124 | - 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
125 | - 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
126 | - 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
127 | - 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
128 | - 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
129 | - 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
130 | - 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
131 | - 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
132 | - 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
133 | - 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
134 | - 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
135 | - 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
136 | - 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
137 | - 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
138 | - self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
139 | - ? $this->config->currency->code |
|
140 | - : 'unknown', |
|
141 | - 'phpversion' => implode( |
|
142 | - '.', |
|
143 | - array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
144 | - ), |
|
145 | - )); |
|
146 | - // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
147 | - return array_filter($stats, function ($value) { |
|
148 | - return $value !== null; |
|
149 | - }); |
|
150 | - } |
|
109 | + /** |
|
110 | + * Return the stats array for PUE UXIP stats. |
|
111 | + * |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function stats() |
|
115 | + { |
|
116 | + $stats = $this->paymentMethodStats(); |
|
117 | + // a-ok so let's setup our stats. |
|
118 | + $stats = array_merge($stats, array( |
|
119 | + 'is_multisite' => is_multisite() && is_main_site(), |
|
120 | + 'active_theme' => $this->getActiveThemeStat(), |
|
121 | + 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
122 | + 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
123 | + 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
124 | + 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
125 | + 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
126 | + 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
127 | + 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
128 | + 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
129 | + 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
130 | + 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
131 | + 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
132 | + 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
133 | + 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
134 | + 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
135 | + 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
136 | + 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
137 | + 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
138 | + self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
139 | + ? $this->config->currency->code |
|
140 | + : 'unknown', |
|
141 | + 'phpversion' => implode( |
|
142 | + '.', |
|
143 | + array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
144 | + ), |
|
145 | + )); |
|
146 | + // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
147 | + return array_filter($stats, function ($value) { |
|
148 | + return $value !== null; |
|
149 | + }); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $which enum (@see constants prefixed with COUNT) |
|
154 | - * @return int|null |
|
155 | - */ |
|
156 | - private function getCountFor($which) |
|
157 | - { |
|
158 | - try { |
|
159 | - switch ($which) { |
|
160 | - case self::COUNT_ALL_EVENTS: |
|
161 | - $count = $this->event_model->count(); |
|
162 | - break; |
|
163 | - case self::COUNT_TICKETS: |
|
164 | - $count = $this->ticket_model->count(); |
|
165 | - break; |
|
166 | - case self::COUNT_DATETIMES: |
|
167 | - $count = $this->datetime_model->count(); |
|
168 | - break; |
|
169 | - case self::COUNT_ACTIVE_EVENTS: |
|
170 | - $count = $this->event_model->get_active_events(array(), true); |
|
171 | - break; |
|
172 | - case self::COUNT_DATETIMES_SOLD: |
|
173 | - $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
174 | - break; |
|
175 | - case self::COUNT_TICKETS_FREE: |
|
176 | - $count = $this->ticket_model->count(array( |
|
177 | - array( |
|
178 | - 'TKT_price' => 0, |
|
179 | - ), |
|
180 | - )); |
|
181 | - break; |
|
182 | - case self::COUNT_TICKETS_PAID: |
|
183 | - $count = $this->ticket_model->count(array( |
|
184 | - array( |
|
185 | - 'TKT_price' => array('>', 0), |
|
186 | - ), |
|
187 | - )); |
|
188 | - break; |
|
189 | - case self::COUNT_TICKETS_SOLD: |
|
190 | - $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
191 | - break; |
|
192 | - case self::COUNT_REGISTRATIONS_ALL: |
|
193 | - $count = $this->registration_model->count(); |
|
194 | - break; |
|
195 | - case self::COUNT_REGISTRATIONS_CANCELLED: |
|
196 | - $count = $this->registration_model->count( |
|
197 | - array( |
|
198 | - array( |
|
199 | - 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
200 | - ), |
|
201 | - ) |
|
202 | - ); |
|
203 | - break; |
|
204 | - case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
205 | - $count = $this->registration_model->count( |
|
206 | - array( |
|
207 | - array( |
|
208 | - 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
209 | - ), |
|
210 | - ) |
|
211 | - ); |
|
212 | - break; |
|
213 | - case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
214 | - $count = $this->registration_model->count( |
|
215 | - array( |
|
216 | - array( |
|
217 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
218 | - ), |
|
219 | - ) |
|
220 | - ); |
|
221 | - break; |
|
222 | - case self::COUNT_REGISTRATIONS_DECLINED: |
|
223 | - $count = $this->registration_model->count( |
|
224 | - array( |
|
225 | - array( |
|
226 | - 'STS_ID' => EEM_Registration::status_id_declined, |
|
227 | - ), |
|
228 | - ) |
|
229 | - ); |
|
230 | - break; |
|
231 | - case self::COUNT_REGISTRATIONS_PENDING: |
|
232 | - $count = $this->registration_model->count( |
|
233 | - array( |
|
234 | - array( |
|
235 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
236 | - ), |
|
237 | - ) |
|
238 | - ); |
|
239 | - break; |
|
240 | - case self::COUNT_REGISTRATIONS_APPROVED: |
|
241 | - $count = $this->registration_model->count( |
|
242 | - array( |
|
243 | - array( |
|
244 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
245 | - ), |
|
246 | - ) |
|
247 | - ); |
|
248 | - break; |
|
249 | - case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
250 | - $count = $this->transaction_model->sum( |
|
251 | - array( |
|
252 | - array( |
|
253 | - 'STS_ID' => EEM_Transaction::complete_status_code, |
|
254 | - ), |
|
255 | - ), |
|
256 | - 'TXN_total' |
|
257 | - ); |
|
258 | - break; |
|
259 | - case self::SUM_TRANSACTIONS_ALL_PAID: |
|
260 | - $count = $this->transaction_model->sum( |
|
261 | - array(), |
|
262 | - 'TXN_paid' |
|
263 | - ); |
|
264 | - break; |
|
265 | - default: |
|
266 | - $count = null; |
|
267 | - break; |
|
268 | - } |
|
269 | - } catch (Exception $e) { |
|
270 | - $count = null; |
|
271 | - } |
|
272 | - return $count; |
|
273 | - } |
|
152 | + /** |
|
153 | + * @param string $which enum (@see constants prefixed with COUNT) |
|
154 | + * @return int|null |
|
155 | + */ |
|
156 | + private function getCountFor($which) |
|
157 | + { |
|
158 | + try { |
|
159 | + switch ($which) { |
|
160 | + case self::COUNT_ALL_EVENTS: |
|
161 | + $count = $this->event_model->count(); |
|
162 | + break; |
|
163 | + case self::COUNT_TICKETS: |
|
164 | + $count = $this->ticket_model->count(); |
|
165 | + break; |
|
166 | + case self::COUNT_DATETIMES: |
|
167 | + $count = $this->datetime_model->count(); |
|
168 | + break; |
|
169 | + case self::COUNT_ACTIVE_EVENTS: |
|
170 | + $count = $this->event_model->get_active_events(array(), true); |
|
171 | + break; |
|
172 | + case self::COUNT_DATETIMES_SOLD: |
|
173 | + $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
174 | + break; |
|
175 | + case self::COUNT_TICKETS_FREE: |
|
176 | + $count = $this->ticket_model->count(array( |
|
177 | + array( |
|
178 | + 'TKT_price' => 0, |
|
179 | + ), |
|
180 | + )); |
|
181 | + break; |
|
182 | + case self::COUNT_TICKETS_PAID: |
|
183 | + $count = $this->ticket_model->count(array( |
|
184 | + array( |
|
185 | + 'TKT_price' => array('>', 0), |
|
186 | + ), |
|
187 | + )); |
|
188 | + break; |
|
189 | + case self::COUNT_TICKETS_SOLD: |
|
190 | + $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
191 | + break; |
|
192 | + case self::COUNT_REGISTRATIONS_ALL: |
|
193 | + $count = $this->registration_model->count(); |
|
194 | + break; |
|
195 | + case self::COUNT_REGISTRATIONS_CANCELLED: |
|
196 | + $count = $this->registration_model->count( |
|
197 | + array( |
|
198 | + array( |
|
199 | + 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
200 | + ), |
|
201 | + ) |
|
202 | + ); |
|
203 | + break; |
|
204 | + case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
205 | + $count = $this->registration_model->count( |
|
206 | + array( |
|
207 | + array( |
|
208 | + 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
209 | + ), |
|
210 | + ) |
|
211 | + ); |
|
212 | + break; |
|
213 | + case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
214 | + $count = $this->registration_model->count( |
|
215 | + array( |
|
216 | + array( |
|
217 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
218 | + ), |
|
219 | + ) |
|
220 | + ); |
|
221 | + break; |
|
222 | + case self::COUNT_REGISTRATIONS_DECLINED: |
|
223 | + $count = $this->registration_model->count( |
|
224 | + array( |
|
225 | + array( |
|
226 | + 'STS_ID' => EEM_Registration::status_id_declined, |
|
227 | + ), |
|
228 | + ) |
|
229 | + ); |
|
230 | + break; |
|
231 | + case self::COUNT_REGISTRATIONS_PENDING: |
|
232 | + $count = $this->registration_model->count( |
|
233 | + array( |
|
234 | + array( |
|
235 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
236 | + ), |
|
237 | + ) |
|
238 | + ); |
|
239 | + break; |
|
240 | + case self::COUNT_REGISTRATIONS_APPROVED: |
|
241 | + $count = $this->registration_model->count( |
|
242 | + array( |
|
243 | + array( |
|
244 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
245 | + ), |
|
246 | + ) |
|
247 | + ); |
|
248 | + break; |
|
249 | + case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
250 | + $count = $this->transaction_model->sum( |
|
251 | + array( |
|
252 | + array( |
|
253 | + 'STS_ID' => EEM_Transaction::complete_status_code, |
|
254 | + ), |
|
255 | + ), |
|
256 | + 'TXN_total' |
|
257 | + ); |
|
258 | + break; |
|
259 | + case self::SUM_TRANSACTIONS_ALL_PAID: |
|
260 | + $count = $this->transaction_model->sum( |
|
261 | + array(), |
|
262 | + 'TXN_paid' |
|
263 | + ); |
|
264 | + break; |
|
265 | + default: |
|
266 | + $count = null; |
|
267 | + break; |
|
268 | + } |
|
269 | + } catch (Exception $e) { |
|
270 | + $count = null; |
|
271 | + } |
|
272 | + return $count; |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * Return the active theme. |
|
277 | - * |
|
278 | - * @return false|string |
|
279 | - */ |
|
280 | - private function getActiveThemeStat() |
|
281 | - { |
|
282 | - $theme = wp_get_theme(); |
|
283 | - return $theme->get('Name'); |
|
284 | - } |
|
275 | + /** |
|
276 | + * Return the active theme. |
|
277 | + * |
|
278 | + * @return false|string |
|
279 | + */ |
|
280 | + private function getActiveThemeStat() |
|
281 | + { |
|
282 | + $theme = wp_get_theme(); |
|
283 | + return $theme->get('Name'); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * @return array |
|
288 | - */ |
|
289 | - private function paymentMethodStats() |
|
290 | - { |
|
291 | - $payment_method_stats = array(); |
|
292 | - try { |
|
293 | - $active_payment_methods = $this->payment_method_model->get_all_active( |
|
294 | - null, |
|
295 | - array('group_by' => 'PMD_type') |
|
296 | - ); |
|
297 | - if ($active_payment_methods) { |
|
298 | - foreach ($active_payment_methods as $payment_method) { |
|
299 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
300 | - } |
|
301 | - } |
|
302 | - } catch (Exception $e) { |
|
303 | - // do nothing just prevents fatals. |
|
304 | - } |
|
305 | - return $payment_method_stats; |
|
306 | - } |
|
286 | + /** |
|
287 | + * @return array |
|
288 | + */ |
|
289 | + private function paymentMethodStats() |
|
290 | + { |
|
291 | + $payment_method_stats = array(); |
|
292 | + try { |
|
293 | + $active_payment_methods = $this->payment_method_model->get_all_active( |
|
294 | + null, |
|
295 | + array('group_by' => 'PMD_type') |
|
296 | + ); |
|
297 | + if ($active_payment_methods) { |
|
298 | + foreach ($active_payment_methods as $payment_method) { |
|
299 | + $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
300 | + } |
|
301 | + } |
|
302 | + } catch (Exception $e) { |
|
303 | + // do nothing just prevents fatals. |
|
304 | + } |
|
305 | + return $payment_method_stats; |
|
306 | + } |
|
307 | 307 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | ), |
145 | 145 | )); |
146 | 146 | // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
147 | - return array_filter($stats, function ($value) { |
|
147 | + return array_filter($stats, function($value) { |
|
148 | 148 | return $value !== null; |
149 | 149 | }); |
150 | 150 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | ); |
297 | 297 | if ($active_payment_methods) { |
298 | 298 | foreach ($active_payment_methods as $payment_method) { |
299 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
299 | + $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1; |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | } catch (Exception $e) { |