@@ -20,216 +20,216 @@ |
||
20 | 20 | abstract class Block implements BlockInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * BlockAssetManager that this editor block uses for asset registration |
|
25 | - * |
|
26 | - * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | - */ |
|
28 | - protected $block_asset_manager; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array $attributes |
|
32 | - */ |
|
33 | - private $attributes; |
|
34 | - |
|
35 | - /** |
|
36 | - * If set to true, then the block will render its content client side |
|
37 | - * If false, then the block will render its content server side using the renderBlock() method |
|
38 | - * |
|
39 | - * @var bool $dynamic |
|
40 | - */ |
|
41 | - private $dynamic = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $editor_block_type |
|
45 | - */ |
|
46 | - private $editor_block_type; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $supported_post_types |
|
50 | - */ |
|
51 | - private $supported_post_types; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var WP_Block_Type $wp_block_type |
|
55 | - */ |
|
56 | - private $wp_block_type; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * BlockLoader constructor. |
|
61 | - * |
|
62 | - * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | - */ |
|
64 | - public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
65 | - { |
|
66 | - $this->block_asset_manager = $block_asset_manager; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function blockType() |
|
74 | - { |
|
75 | - return $this->editor_block_type; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function namespacedBlockType() |
|
83 | - { |
|
84 | - return self::NAME_SPACE . $this->editor_block_type; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param string $editor_block_type |
|
90 | - */ |
|
91 | - protected function setBlockType($editor_block_type) |
|
92 | - { |
|
93 | - $this->editor_block_type = $editor_block_type; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * BlockAssetManager that this editor block uses for asset registration |
|
99 | - * |
|
100 | - * @return BlockAssetManagerInterface |
|
101 | - */ |
|
102 | - public function assetManager() |
|
103 | - { |
|
104 | - return $this->block_asset_manager; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param WP_Block_Type $wp_block_type |
|
110 | - */ |
|
111 | - protected function setWpBlockType($wp_block_type) |
|
112 | - { |
|
113 | - $this->wp_block_type = $wp_block_type; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param array $supported_post_types |
|
119 | - */ |
|
120 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
121 | - { |
|
122 | - $this->supported_post_types = $supported_post_types; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function attributes() |
|
130 | - { |
|
131 | - return $this->attributes; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param array $attributes |
|
137 | - */ |
|
138 | - public function setAttributes(array $attributes) |
|
139 | - { |
|
140 | - $this->attributes = $attributes; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function isDynamic() |
|
148 | - { |
|
149 | - return $this->dynamic; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param bool $dynamic |
|
155 | - */ |
|
156 | - public function setDynamic($dynamic = true) |
|
157 | - { |
|
158 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Registers the Editor Block with WP core; |
|
164 | - * Returns the registered block type on success, or false on failure. |
|
165 | - * |
|
166 | - * @return WP_Block_Type|false |
|
167 | - */ |
|
168 | - public function registerBlock() |
|
169 | - { |
|
170 | - $args = array( |
|
171 | - 'attributes' => $this->attributes(), |
|
172 | - 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
173 | - 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
174 | - 'script' => $this->block_asset_manager->getScriptHandle(), |
|
175 | - 'style' => $this->block_asset_manager->getStyleHandle(), |
|
176 | - ); |
|
177 | - if (! $this->isDynamic()) { |
|
178 | - $args['render_callback'] = $this->renderBlock(); |
|
179 | - } |
|
180 | - $wp_block_type = register_block_type( |
|
181 | - new WP_Block_Type( |
|
182 | - $this->namespacedBlockType(), |
|
183 | - $args |
|
184 | - ) |
|
185 | - ); |
|
186 | - $this->setWpBlockType($wp_block_type); |
|
187 | - return $wp_block_type; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
193 | - */ |
|
194 | - public function unRegisterBlock() |
|
195 | - { |
|
196 | - return unregister_block_type($this->namespacedBlockType()); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * returns true if the block type applies for the supplied post type |
|
202 | - * and should be added to that post type's editor |
|
203 | - * |
|
204 | - * @param string $post_type |
|
205 | - * @return boolean |
|
206 | - */ |
|
207 | - public function appliesToPostType($post_type) |
|
208 | - { |
|
209 | - return in_array($post_type, $this->supported_post_types, true); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @return array |
|
215 | - */ |
|
216 | - public function getEditorContainer() |
|
217 | - { |
|
218 | - return array( |
|
219 | - $this->namespacedBlockType(), |
|
220 | - array(), |
|
221 | - ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * returns the rendered HTML for the block |
|
227 | - * |
|
228 | - * @param array $attributes |
|
229 | - * @return string |
|
230 | - */ |
|
231 | - public function renderBlock(array $attributes = array()) |
|
232 | - { |
|
233 | - return ''; |
|
234 | - } |
|
23 | + /** |
|
24 | + * BlockAssetManager that this editor block uses for asset registration |
|
25 | + * |
|
26 | + * @var BlockAssetManagerInterface $block_asset_manager |
|
27 | + */ |
|
28 | + protected $block_asset_manager; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array $attributes |
|
32 | + */ |
|
33 | + private $attributes; |
|
34 | + |
|
35 | + /** |
|
36 | + * If set to true, then the block will render its content client side |
|
37 | + * If false, then the block will render its content server side using the renderBlock() method |
|
38 | + * |
|
39 | + * @var bool $dynamic |
|
40 | + */ |
|
41 | + private $dynamic = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $editor_block_type |
|
45 | + */ |
|
46 | + private $editor_block_type; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $supported_post_types |
|
50 | + */ |
|
51 | + private $supported_post_types; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var WP_Block_Type $wp_block_type |
|
55 | + */ |
|
56 | + private $wp_block_type; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * BlockLoader constructor. |
|
61 | + * |
|
62 | + * @param BlockAssetManagerInterface $block_asset_manager |
|
63 | + */ |
|
64 | + public function __construct(BlockAssetManagerInterface $block_asset_manager) |
|
65 | + { |
|
66 | + $this->block_asset_manager = $block_asset_manager; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function blockType() |
|
74 | + { |
|
75 | + return $this->editor_block_type; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function namespacedBlockType() |
|
83 | + { |
|
84 | + return self::NAME_SPACE . $this->editor_block_type; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param string $editor_block_type |
|
90 | + */ |
|
91 | + protected function setBlockType($editor_block_type) |
|
92 | + { |
|
93 | + $this->editor_block_type = $editor_block_type; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * BlockAssetManager that this editor block uses for asset registration |
|
99 | + * |
|
100 | + * @return BlockAssetManagerInterface |
|
101 | + */ |
|
102 | + public function assetManager() |
|
103 | + { |
|
104 | + return $this->block_asset_manager; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param WP_Block_Type $wp_block_type |
|
110 | + */ |
|
111 | + protected function setWpBlockType($wp_block_type) |
|
112 | + { |
|
113 | + $this->wp_block_type = $wp_block_type; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param array $supported_post_types |
|
119 | + */ |
|
120 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
121 | + { |
|
122 | + $this->supported_post_types = $supported_post_types; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function attributes() |
|
130 | + { |
|
131 | + return $this->attributes; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param array $attributes |
|
137 | + */ |
|
138 | + public function setAttributes(array $attributes) |
|
139 | + { |
|
140 | + $this->attributes = $attributes; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function isDynamic() |
|
148 | + { |
|
149 | + return $this->dynamic; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param bool $dynamic |
|
155 | + */ |
|
156 | + public function setDynamic($dynamic = true) |
|
157 | + { |
|
158 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Registers the Editor Block with WP core; |
|
164 | + * Returns the registered block type on success, or false on failure. |
|
165 | + * |
|
166 | + * @return WP_Block_Type|false |
|
167 | + */ |
|
168 | + public function registerBlock() |
|
169 | + { |
|
170 | + $args = array( |
|
171 | + 'attributes' => $this->attributes(), |
|
172 | + 'editor_script' => $this->block_asset_manager->getEditorScriptHandle(), |
|
173 | + 'editor_style' => $this->block_asset_manager->getEditorStyleHandle(), |
|
174 | + 'script' => $this->block_asset_manager->getScriptHandle(), |
|
175 | + 'style' => $this->block_asset_manager->getStyleHandle(), |
|
176 | + ); |
|
177 | + if (! $this->isDynamic()) { |
|
178 | + $args['render_callback'] = $this->renderBlock(); |
|
179 | + } |
|
180 | + $wp_block_type = register_block_type( |
|
181 | + new WP_Block_Type( |
|
182 | + $this->namespacedBlockType(), |
|
183 | + $args |
|
184 | + ) |
|
185 | + ); |
|
186 | + $this->setWpBlockType($wp_block_type); |
|
187 | + return $wp_block_type; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
193 | + */ |
|
194 | + public function unRegisterBlock() |
|
195 | + { |
|
196 | + return unregister_block_type($this->namespacedBlockType()); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * returns true if the block type applies for the supplied post type |
|
202 | + * and should be added to that post type's editor |
|
203 | + * |
|
204 | + * @param string $post_type |
|
205 | + * @return boolean |
|
206 | + */ |
|
207 | + public function appliesToPostType($post_type) |
|
208 | + { |
|
209 | + return in_array($post_type, $this->supported_post_types, true); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @return array |
|
215 | + */ |
|
216 | + public function getEditorContainer() |
|
217 | + { |
|
218 | + return array( |
|
219 | + $this->namespacedBlockType(), |
|
220 | + array(), |
|
221 | + ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * returns the rendered HTML for the block |
|
227 | + * |
|
228 | + * @param array $attributes |
|
229 | + * @return string |
|
230 | + */ |
|
231 | + public function renderBlock(array $attributes = array()) |
|
232 | + { |
|
233 | + return ''; |
|
234 | + } |
|
235 | 235 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function namespacedBlockType() |
83 | 83 | { |
84 | - return self::NAME_SPACE . $this->editor_block_type; |
|
84 | + return self::NAME_SPACE.$this->editor_block_type; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | 'script' => $this->block_asset_manager->getScriptHandle(), |
175 | 175 | 'style' => $this->block_asset_manager->getStyleHandle(), |
176 | 176 | ); |
177 | - if (! $this->isDynamic()) { |
|
177 | + if ( ! $this->isDynamic()) { |
|
178 | 178 | $args['render_callback'] = $this->renderBlock(); |
179 | 179 | } |
180 | 180 | $wp_block_type = register_block_type( |
@@ -22,70 +22,70 @@ |
||
22 | 22 | interface BlockInterface |
23 | 23 | { |
24 | 24 | |
25 | - const NAME_SPACE = 'event-espresso/'; |
|
26 | - |
|
27 | - /** |
|
28 | - * Perform any early setup required by the block |
|
29 | - * including setting the block type and supported post types |
|
30 | - * |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function initialize(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function blockType(); |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * AssetRegister that this editor block uses for asset registration |
|
44 | - * |
|
45 | - * @return BlockAssetManagerInterface |
|
46 | - */ |
|
47 | - public function assetManager(); |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Registers the Editor Block with WP core; |
|
52 | - * Returns the registered block type on success, or false on failure. |
|
53 | - * |
|
54 | - * @return WP_Block_Type|false |
|
55 | - */ |
|
56 | - public function registerBlock(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Un-registers the Editor Block with WP core; |
|
61 | - * Returns the registered block type on success, or false on failure. |
|
62 | - * |
|
63 | - * @return WP_Block_Type|false |
|
64 | - */ |
|
65 | - public function unRegisterBlock(); |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * returns true if the block type applies for the supplied post type |
|
70 | - * and should be added to that post type's editor |
|
71 | - * |
|
72 | - * @param string $post_type |
|
73 | - * @return boolean |
|
74 | - */ |
|
75 | - public function appliesToPostType($post_type); |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function getEditorContainer(); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * returns the rendered HTML for the block |
|
86 | - * |
|
87 | - * @param array $attributes |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function renderBlock(array $attributes = array()); |
|
25 | + const NAME_SPACE = 'event-espresso/'; |
|
26 | + |
|
27 | + /** |
|
28 | + * Perform any early setup required by the block |
|
29 | + * including setting the block type and supported post types |
|
30 | + * |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function initialize(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function blockType(); |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * AssetRegister that this editor block uses for asset registration |
|
44 | + * |
|
45 | + * @return BlockAssetManagerInterface |
|
46 | + */ |
|
47 | + public function assetManager(); |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Registers the Editor Block with WP core; |
|
52 | + * Returns the registered block type on success, or false on failure. |
|
53 | + * |
|
54 | + * @return WP_Block_Type|false |
|
55 | + */ |
|
56 | + public function registerBlock(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Un-registers the Editor Block with WP core; |
|
61 | + * Returns the registered block type on success, or false on failure. |
|
62 | + * |
|
63 | + * @return WP_Block_Type|false |
|
64 | + */ |
|
65 | + public function unRegisterBlock(); |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * returns true if the block type applies for the supplied post type |
|
70 | + * and should be added to that post type's editor |
|
71 | + * |
|
72 | + * @param string $post_type |
|
73 | + * @return boolean |
|
74 | + */ |
|
75 | + public function appliesToPostType($post_type); |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function getEditorContainer(); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * returns the rendered HTML for the block |
|
86 | + * |
|
87 | + * @param array $attributes |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function renderBlock(array $attributes = array()); |
|
91 | 91 | } |
@@ -20,1048 +20,1048 @@ |
||
20 | 20 | class EED_Ticket_Sales_Monitor extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - const debug = false; |
|
24 | - |
|
25 | - private static $nl = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
29 | - * |
|
30 | - * @var array $ticket_selections |
|
31 | - */ |
|
32 | - protected $ticket_selections = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | - * according to how they are displayed in the actual Ticket_Selector |
|
37 | - * this tracks the current row being processed |
|
38 | - * |
|
39 | - * @var int $current_row |
|
40 | - */ |
|
41 | - protected $current_row = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * an array for tracking names of tickets that have sold out |
|
45 | - * |
|
46 | - * @var array $sold_out_tickets |
|
47 | - */ |
|
48 | - protected $sold_out_tickets = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
52 | - * |
|
53 | - * @var array $decremented_tickets |
|
54 | - */ |
|
55 | - protected $decremented_tickets = array(); |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public static function set_hooks() |
|
64 | - { |
|
65 | - self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
66 | - // release tickets for expired carts |
|
67 | - add_action( |
|
68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | - 1 |
|
71 | - ); |
|
72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | - 20, |
|
77 | - 3 |
|
78 | - ); |
|
79 | - // add notices for sold out tickets |
|
80 | - add_action( |
|
81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | - 10 |
|
84 | - ); |
|
85 | - |
|
86 | - // handle tickets deleted from cart |
|
87 | - add_action( |
|
88 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
89 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
90 | - 10, |
|
91 | - 2 |
|
92 | - ); |
|
93 | - // handle emptied carts |
|
94 | - add_action( |
|
95 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | - 10, |
|
98 | - 1 |
|
99 | - ); |
|
100 | - add_action( |
|
101 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | - 10, |
|
104 | - 1 |
|
105 | - ); |
|
106 | - // handle cancelled registrations |
|
107 | - add_action( |
|
108 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
109 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
110 | - 10, |
|
111 | - 1 |
|
112 | - ); |
|
113 | - // cron tasks |
|
114 | - add_action( |
|
115 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
116 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
117 | - 10, |
|
118 | - 1 |
|
119 | - ); |
|
120 | - add_action( |
|
121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | - 10, |
|
124 | - 1 |
|
125 | - ); |
|
126 | - add_action( |
|
127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
128 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
129 | - 10, |
|
130 | - 1 |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
137 | - * |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public static function set_hooks_admin() |
|
141 | - { |
|
142 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
148 | - */ |
|
149 | - public static function instance() |
|
150 | - { |
|
151 | - return parent::get_instance(__CLASS__); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param WP_Query $WP_Query |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function run($WP_Query) |
|
160 | - { |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Retrieves grand totals from the line items that have no TXN ID |
|
170 | - * and timestamps less than the current time minus the session lifespan. |
|
171 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
172 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
173 | - * |
|
174 | - * @return void |
|
175 | - * @throws DomainException |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - * @throws UnexpectedEntityException |
|
181 | - */ |
|
182 | - public static function release_tickets_for_expired_carts() |
|
183 | - { |
|
184 | - if (self::debug) { |
|
185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | - } |
|
187 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | - $expired_ticket_IDs = array(); |
|
189 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | - ); |
|
193 | - $timestamp = $session_lifespan->expiration(); |
|
194 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | - if (self::debug) { |
|
196 | - echo self::$nl . ' . time(): ' . time(); |
|
197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | - } |
|
203 | - if (! empty($expired_ticket_line_items)) { |
|
204 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | - if (self::debug) { |
|
210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | - . date( |
|
213 | - 'Y-m-d h:i a', |
|
214 | - $expired_ticket_line_item->timestamp(true) |
|
215 | - ); |
|
216 | - } |
|
217 | - } |
|
218 | - if (! empty($expired_ticket_IDs)) { |
|
219 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | - array(), |
|
222 | - __FUNCTION__ |
|
223 | - ); |
|
224 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | - } |
|
227 | - } |
|
228 | - do_action( |
|
229 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | - $expired_ticket_IDs, |
|
231 | - $expired_ticket_line_items |
|
232 | - ); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | - * |
|
243 | - * @param int $qty |
|
244 | - * @param EE_Ticket $ticket |
|
245 | - * @return bool |
|
246 | - * @throws UnexpectedEntityException |
|
247 | - * @throws EE_Error |
|
248 | - */ |
|
249 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | - { |
|
251 | - $qty = absint($qty); |
|
252 | - if ($qty > 0) { |
|
253 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | - } |
|
255 | - if (self::debug) { |
|
256 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
258 | - } |
|
259 | - return $qty; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
265 | - * |
|
266 | - * @param EE_Ticket $ticket |
|
267 | - * @param int $qty |
|
268 | - * @return int |
|
269 | - * @throws UnexpectedEntityException |
|
270 | - * @throws EE_Error |
|
271 | - */ |
|
272 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
273 | - { |
|
274 | - if (self::debug) { |
|
275 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
276 | - } |
|
277 | - if (! $ticket instanceof EE_Ticket) { |
|
278 | - return 0; |
|
279 | - } |
|
280 | - if (self::debug) { |
|
281 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
283 | - } |
|
284 | - $ticket->refresh_from_db(); |
|
285 | - // first let's determine the ticket availability based on sales |
|
286 | - $available = $ticket->qty('saleable'); |
|
287 | - if (self::debug) { |
|
288 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | - echo self::$nl . ' . . . available: ' . $available; |
|
293 | - } |
|
294 | - if ($available < 1) { |
|
295 | - $this->_ticket_sold_out($ticket); |
|
296 | - return 0; |
|
297 | - } |
|
298 | - if (self::debug) { |
|
299 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
300 | - } |
|
301 | - if ($available < $qty) { |
|
302 | - $qty = $available; |
|
303 | - if (self::debug) { |
|
304 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
305 | - } |
|
306 | - $this->_ticket_quantity_decremented($ticket); |
|
307 | - } |
|
308 | - $this->_reserve_ticket($ticket, $qty); |
|
309 | - return $qty; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * increments ticket reserved based on quantity passed |
|
315 | - * |
|
316 | - * @param EE_Ticket $ticket |
|
317 | - * @param int $quantity |
|
318 | - * @return bool |
|
319 | - * @throws EE_Error |
|
320 | - */ |
|
321 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
322 | - { |
|
323 | - if (self::debug) { |
|
324 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
325 | - } |
|
326 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
327 | - return $ticket->save(); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param EE_Ticket $ticket |
|
333 | - * @param int $quantity |
|
334 | - * @return bool |
|
335 | - * @throws EE_Error |
|
336 | - */ |
|
337 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
338 | - { |
|
339 | - if (self::debug) { |
|
340 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
341 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
342 | - } |
|
343 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
344 | - if (self::debug) { |
|
345 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
346 | - } |
|
347 | - return $ticket->save() ? 1 : 0; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - /** |
|
352 | - * removes quantities within the ticket selector based on zero ticket availability |
|
353 | - * |
|
354 | - * @param EE_Ticket $ticket |
|
355 | - * @return void |
|
356 | - * @throws UnexpectedEntityException |
|
357 | - * @throws EE_Error |
|
358 | - */ |
|
359 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
360 | - { |
|
361 | - if (self::debug) { |
|
362 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
363 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
364 | - } |
|
365 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
371 | - * |
|
372 | - * @param EE_Ticket $ticket |
|
373 | - * @return void |
|
374 | - * @throws UnexpectedEntityException |
|
375 | - * @throws EE_Error |
|
376 | - */ |
|
377 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
378 | - { |
|
379 | - if (self::debug) { |
|
380 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
381 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
382 | - } |
|
383 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * builds string out of ticket and event name |
|
389 | - * |
|
390 | - * @param EE_Ticket $ticket |
|
391 | - * @return string |
|
392 | - * @throws UnexpectedEntityException |
|
393 | - * @throws EE_Error |
|
394 | - */ |
|
395 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
396 | - { |
|
397 | - $event = $ticket->get_related_event(); |
|
398 | - if ($event instanceof EE_Event) { |
|
399 | - $ticket_name = sprintf( |
|
400 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
401 | - $ticket->name(), |
|
402 | - $event->name() |
|
403 | - ); |
|
404 | - } else { |
|
405 | - $ticket_name = $ticket->name(); |
|
406 | - } |
|
407 | - return $ticket_name; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /********************************** EVENT CART **********************************/ |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * releases or reserves ticket(s) based on quantity passed |
|
417 | - * |
|
418 | - * @param EE_Line_Item $line_item |
|
419 | - * @param int $quantity |
|
420 | - * @return void |
|
421 | - * @throws EE_Error |
|
422 | - * @throws InvalidArgumentException |
|
423 | - * @throws InvalidDataTypeException |
|
424 | - * @throws InvalidInterfaceException |
|
425 | - */ |
|
426 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
427 | - { |
|
428 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
429 | - if ($ticket instanceof EE_Ticket) { |
|
430 | - $ticket->add_extra_meta( |
|
431 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
432 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
433 | - ); |
|
434 | - if ($quantity > 0) { |
|
435 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
436 | - } else { |
|
437 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
438 | - } |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * releases reserved ticket(s) based on quantity passed |
|
445 | - * |
|
446 | - * @param EE_Ticket $ticket |
|
447 | - * @param int $quantity |
|
448 | - * @return void |
|
449 | - * @throws EE_Error |
|
450 | - */ |
|
451 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
452 | - { |
|
453 | - $ticket->add_extra_meta( |
|
454 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
455 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
456 | - ); |
|
457 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - |
|
462 | - /********************************** POST_NOTICES **********************************/ |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * @return void |
|
467 | - * @throws EE_Error |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws ReflectionException |
|
470 | - * @throws InvalidDataTypeException |
|
471 | - * @throws InvalidInterfaceException |
|
472 | - */ |
|
473 | - public static function post_notices() |
|
474 | - { |
|
475 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * @return void |
|
481 | - * @throws EE_Error |
|
482 | - * @throws InvalidArgumentException |
|
483 | - * @throws ReflectionException |
|
484 | - * @throws InvalidDataTypeException |
|
485 | - * @throws InvalidInterfaceException |
|
486 | - */ |
|
487 | - protected function _post_notices() |
|
488 | - { |
|
489 | - if (self::debug) { |
|
490 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
491 | - } |
|
492 | - $refresh_msg = ''; |
|
493 | - $none_added_msg = ''; |
|
494 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
495 | - $refresh_msg = __( |
|
496 | - 'Please refresh the page to view updated ticket quantities.', |
|
497 | - 'event_espresso' |
|
498 | - ); |
|
499 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
500 | - } |
|
501 | - if (! empty($this->sold_out_tickets)) { |
|
502 | - EE_Error::add_attention( |
|
503 | - sprintf( |
|
504 | - apply_filters( |
|
505 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
506 | - __( |
|
507 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
508 | - 'event_espresso' |
|
509 | - ) |
|
510 | - ), |
|
511 | - '<br />', |
|
512 | - implode('<br />', $this->sold_out_tickets), |
|
513 | - $none_added_msg, |
|
514 | - $refresh_msg |
|
515 | - ) |
|
516 | - ); |
|
517 | - // alter code flow in the Ticket Selector for better UX |
|
518 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
519 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
520 | - $this->sold_out_tickets = array(); |
|
521 | - // and reset the cart |
|
522 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
523 | - } |
|
524 | - if (! empty($this->decremented_tickets)) { |
|
525 | - EE_Error::add_attention( |
|
526 | - sprintf( |
|
527 | - apply_filters( |
|
528 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
529 | - __( |
|
530 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
531 | - 'event_espresso' |
|
532 | - ) |
|
533 | - ), |
|
534 | - '<br />', |
|
535 | - implode('<br />', $this->decremented_tickets), |
|
536 | - $none_added_msg, |
|
537 | - $refresh_msg |
|
538 | - ) |
|
539 | - ); |
|
540 | - $this->decremented_tickets = array(); |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
551 | - * by default, will NOT release tickets for finalized transactions |
|
552 | - * |
|
553 | - * @param EE_Transaction $transaction |
|
554 | - * @return int |
|
555 | - * @throws EE_Error |
|
556 | - * @throws InvalidSessionDataException |
|
557 | - */ |
|
558 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
559 | - { |
|
560 | - if (self::debug) { |
|
561 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
562 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
563 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
564 | - } |
|
565 | - // check if 'finalize_registration' step has been completed... |
|
566 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
567 | - if (self::debug) { |
|
568 | - // DEBUG LOG |
|
569 | - EEH_Debug_Tools::log( |
|
570 | - __CLASS__, |
|
571 | - __FUNCTION__, |
|
572 | - __LINE__, |
|
573 | - array('finalized' => $finalized), |
|
574 | - false, |
|
575 | - 'EE_Transaction: ' . $transaction->ID() |
|
576 | - ); |
|
577 | - } |
|
578 | - // how many tickets were released |
|
579 | - $count = 0; |
|
580 | - if (self::debug) { |
|
581 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
582 | - } |
|
583 | - $release_tickets_with_TXN_status = array( |
|
584 | - EEM_Transaction::failed_status_code, |
|
585 | - EEM_Transaction::abandoned_status_code, |
|
586 | - EEM_Transaction::incomplete_status_code, |
|
587 | - ); |
|
588 | - $events = array(); |
|
589 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
590 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
591 | - // cancel any reserved tickets for registrations that were not approved |
|
592 | - $registrations = $transaction->registrations(); |
|
593 | - if (self::debug) { |
|
594 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
595 | - $reg = reset($registrations); |
|
596 | - $ticket = $reg->ticket(); |
|
597 | - if ($ticket instanceof EE_Ticket) { |
|
598 | - $ticket->add_extra_meta( |
|
599 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
600 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
601 | - ); |
|
602 | - } |
|
603 | - } |
|
604 | - if (! empty($registrations)) { |
|
605 | - foreach ($registrations as $registration) { |
|
606 | - if ($registration instanceof EE_Registration |
|
607 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
608 | - ) { |
|
609 | - $count++; |
|
610 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
611 | - } |
|
612 | - } |
|
613 | - } |
|
614 | - } |
|
615 | - if ($events !== array()) { |
|
616 | - foreach ($events as $event) { |
|
617 | - /** @var EE_Event $event */ |
|
618 | - $event->perform_sold_out_status_check(); |
|
619 | - } |
|
620 | - } |
|
621 | - return $count; |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * releases reserved tickets for an EE_Registration |
|
627 | - * by default, will NOT release tickets for APPROVED registrations |
|
628 | - * |
|
629 | - * @param EE_Registration $registration |
|
630 | - * @param EE_Transaction $transaction |
|
631 | - * @return int |
|
632 | - * @throws EE_Error |
|
633 | - */ |
|
634 | - protected function _release_reserved_ticket_for_registration( |
|
635 | - EE_Registration $registration, |
|
636 | - EE_Transaction $transaction |
|
637 | - ) { |
|
638 | - $STS_ID = $transaction->status_ID(); |
|
639 | - if (self::debug) { |
|
640 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
641 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
642 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
643 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
644 | - } |
|
645 | - if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
646 | - $STS_ID === EEM_Transaction::failed_status_code |
|
647 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
648 | - || ( |
|
649 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
650 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
651 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
652 | - ) |
|
653 | - ) { |
|
654 | - if (self::debug) { |
|
655 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
656 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
657 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
658 | - var_dump($rsrvd); |
|
659 | - } |
|
660 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
661 | - return 1; |
|
662 | - } |
|
663 | - return 0; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - |
|
668 | - /********************************** SESSION_CART_RESET **********************************/ |
|
669 | - |
|
670 | - |
|
671 | - /** |
|
672 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
673 | - * |
|
674 | - * @param EE_Session $session |
|
675 | - * @return void |
|
676 | - * @throws EE_Error |
|
677 | - * @throws InvalidArgumentException |
|
678 | - * @throws ReflectionException |
|
679 | - * @throws InvalidDataTypeException |
|
680 | - * @throws InvalidInterfaceException |
|
681 | - */ |
|
682 | - public static function session_cart_reset(EE_Session $session) |
|
683 | - { |
|
684 | - // don't release tickets if checkout was already reset |
|
685 | - if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
686 | - return; |
|
687 | - } |
|
688 | - if (self::debug) { |
|
689 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
690 | - } |
|
691 | - // first check of the session has a valid Checkout object |
|
692 | - $checkout = $session->checkout(); |
|
693 | - if ($checkout instanceof EE_Checkout) { |
|
694 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
695 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
696 | - return; |
|
697 | - } |
|
698 | - $cart = $session->cart(); |
|
699 | - if ($cart instanceof EE_Cart) { |
|
700 | - if (self::debug) { |
|
701 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
702 | - } |
|
703 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
704 | - } else { |
|
705 | - if (self::debug) { |
|
706 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
707 | - var_export($cart, true); |
|
708 | - } |
|
709 | - } |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * releases reserved tickets in the EE_Cart |
|
715 | - * |
|
716 | - * @param EE_Cart $cart |
|
717 | - * @return void |
|
718 | - * @throws EE_Error |
|
719 | - * @throws InvalidArgumentException |
|
720 | - * @throws ReflectionException |
|
721 | - * @throws InvalidDataTypeException |
|
722 | - * @throws InvalidInterfaceException |
|
723 | - */ |
|
724 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
725 | - { |
|
726 | - if (self::debug) { |
|
727 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
728 | - } |
|
729 | - $ticket_line_items = $cart->get_tickets(); |
|
730 | - if (empty($ticket_line_items)) { |
|
731 | - return; |
|
732 | - } |
|
733 | - if (self::debug) { |
|
734 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
735 | - } |
|
736 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
737 | - if (self::debug) { |
|
738 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
739 | - } |
|
740 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
741 | - if (self::debug) { |
|
742 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
743 | - } |
|
744 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
745 | - if ($ticket instanceof EE_Ticket) { |
|
746 | - if (self::debug) { |
|
747 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
748 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
749 | - } |
|
750 | - $ticket->add_extra_meta( |
|
751 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
752 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
753 | - ); |
|
754 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
755 | - } |
|
756 | - } |
|
757 | - } |
|
758 | - if (self::debug) { |
|
759 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
760 | - } |
|
761 | - } |
|
762 | - |
|
763 | - |
|
764 | - |
|
765 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
770 | - * |
|
771 | - * @param EE_Session $session |
|
772 | - * @return void |
|
773 | - * @throws EE_Error |
|
774 | - * @throws InvalidSessionDataException |
|
775 | - */ |
|
776 | - public static function session_checkout_reset(EE_Session $session) |
|
777 | - { |
|
778 | - // don't release tickets if cart was already reset |
|
779 | - if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
780 | - return; |
|
781 | - } |
|
782 | - $checkout = $session->checkout(); |
|
783 | - if ($checkout instanceof EE_Checkout) { |
|
784 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
785 | - } |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * releases reserved tickets for the EE_Checkout->transaction |
|
791 | - * |
|
792 | - * @param EE_Checkout $checkout |
|
793 | - * @return void |
|
794 | - * @throws EE_Error |
|
795 | - * @throws InvalidSessionDataException |
|
796 | - */ |
|
797 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
798 | - { |
|
799 | - if (self::debug) { |
|
800 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
801 | - } |
|
802 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
803 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
804 | - return; |
|
805 | - } |
|
806 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - |
|
811 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @param EE_Session $session |
|
816 | - * @return void |
|
817 | - */ |
|
818 | - public static function session_expired_reset(EE_Session $session) |
|
819 | - { |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
829 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
830 | - * |
|
831 | - * @param EE_Transaction $transaction |
|
832 | - * @return void |
|
833 | - * @throws EE_Error |
|
834 | - * @throws InvalidSessionDataException |
|
835 | - */ |
|
836 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
837 | - { |
|
838 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
839 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
840 | - if (self::debug) { |
|
841 | - // DEBUG LOG |
|
842 | - EEH_Debug_Tools::log( |
|
843 | - __CLASS__, |
|
844 | - __FUNCTION__, |
|
845 | - __LINE__, |
|
846 | - array($transaction), |
|
847 | - false, |
|
848 | - 'EE_Transaction: ' . $transaction->ID() |
|
849 | - ); |
|
850 | - } |
|
851 | - return; |
|
852 | - } |
|
853 | - // have their been any successful payments made ? |
|
854 | - $payments = $transaction->payments(); |
|
855 | - foreach ($payments as $payment) { |
|
856 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
857 | - if (self::debug) { |
|
858 | - // DEBUG LOG |
|
859 | - EEH_Debug_Tools::log( |
|
860 | - __CLASS__, |
|
861 | - __FUNCTION__, |
|
862 | - __LINE__, |
|
863 | - array($payment), |
|
864 | - false, |
|
865 | - 'EE_Transaction: ' . $transaction->ID() |
|
866 | - ); |
|
867 | - } |
|
868 | - return; |
|
869 | - } |
|
870 | - } |
|
871 | - // since you haven't even attempted to pay for your ticket... |
|
872 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
878 | - |
|
879 | - |
|
880 | - /** |
|
881 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
882 | - * |
|
883 | - * @param EE_Transaction $transaction |
|
884 | - * @return void |
|
885 | - * @throws EE_Error |
|
886 | - * @throws InvalidSessionDataException |
|
887 | - */ |
|
888 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
889 | - { |
|
890 | - // since you haven't even attempted to pay for your ticket... |
|
891 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - |
|
896 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * Resets all ticket and datetime reserved counts to zero |
|
901 | - * Tickets that are currently associated with a Transaction that is in progress |
|
902 | - * |
|
903 | - * @throws EE_Error |
|
904 | - * @throws DomainException |
|
905 | - * @throws InvalidDataTypeException |
|
906 | - * @throws InvalidInterfaceException |
|
907 | - * @throws InvalidArgumentException |
|
908 | - * @throws UnexpectedEntityException |
|
909 | - */ |
|
910 | - public static function reset_reservation_counts() |
|
911 | - { |
|
912 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
913 | - $valid_reserved_tickets = array(); |
|
914 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
915 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
916 | - foreach ($transactions_not_in_progress as $transaction) { |
|
917 | - // if this TXN has been fully completed, then skip it |
|
918 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
919 | - continue; |
|
920 | - } |
|
921 | - $total_line_item = $transaction->total_line_item(); |
|
922 | - // $transaction_in_progress->line |
|
923 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
924 | - throw new DomainException( |
|
925 | - esc_html__( |
|
926 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
927 | - 'event_espresso' |
|
928 | - ) |
|
929 | - ); |
|
930 | - } |
|
931 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
932 | - $total_line_item |
|
933 | - ); |
|
934 | - } |
|
935 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
936 | - foreach ($total_line_items as $total_line_item) { |
|
937 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
938 | - $total_line_item |
|
939 | - ); |
|
940 | - } |
|
941 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
942 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
943 | - $tickets_with_reservations, |
|
944 | - $valid_reserved_tickets, |
|
945 | - __FUNCTION__ |
|
946 | - ); |
|
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - /** |
|
951 | - * @param EE_Line_Item $total_line_item |
|
952 | - * @return EE_Line_Item[] |
|
953 | - */ |
|
954 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
955 | - { |
|
956 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
957 | - $valid_reserved_tickets = array(); |
|
958 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
959 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
960 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
961 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
962 | - } |
|
963 | - } |
|
964 | - return $valid_reserved_tickets; |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * @param EE_Ticket[] $tickets_with_reservations |
|
970 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
971 | - * @return int |
|
972 | - * @throws UnexpectedEntityException |
|
973 | - * @throws DomainException |
|
974 | - * @throws EE_Error |
|
975 | - */ |
|
976 | - private static function release_reservations_for_tickets( |
|
977 | - array $tickets_with_reservations, |
|
978 | - array $valid_reserved_ticket_line_items = array(), |
|
979 | - $source |
|
980 | - ) { |
|
981 | - if (self::debug) { |
|
982 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
983 | - } |
|
984 | - $total_tickets_released = 0; |
|
985 | - $sold_out_events = array(); |
|
986 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
987 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
988 | - continue; |
|
989 | - } |
|
990 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
991 | - if (self::debug) { |
|
992 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
993 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
994 | - } |
|
995 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
996 | - if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
997 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
998 | - ) { |
|
999 | - if (self::debug) { |
|
1000 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' |
|
1001 | - . $valid_reserved_ticket_line_item->quantity(); |
|
1002 | - } |
|
1003 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
1004 | - } |
|
1005 | - } |
|
1006 | - if ($reserved_qty > 0) { |
|
1007 | - $ticket_with_reservations->add_extra_meta( |
|
1008 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1009 | - __LINE__ . ') ' . $source . '()' |
|
1010 | - ); |
|
1011 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:' . __LINE__); |
|
1012 | - $ticket_with_reservations->save(); |
|
1013 | - $total_tickets_released += $reserved_qty; |
|
1014 | - $event = $ticket_with_reservations->get_related_event(); |
|
1015 | - // track sold out events |
|
1016 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1017 | - $sold_out_events[] = $event; |
|
1018 | - } |
|
1019 | - } |
|
1020 | - } |
|
1021 | - if (self::debug) { |
|
1022 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
1023 | - } |
|
1024 | - // double check whether sold out events should remain sold out after releasing tickets |
|
1025 | - if ($sold_out_events !== array()) { |
|
1026 | - foreach ($sold_out_events as $sold_out_event) { |
|
1027 | - /** @var EE_Event $sold_out_event */ |
|
1028 | - $sold_out_event->perform_sold_out_status_check(); |
|
1029 | - } |
|
1030 | - } |
|
1031 | - return $total_tickets_released; |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - |
|
1036 | - /********************************** SHUTDOWN **********************************/ |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * @param int $timestamp |
|
1041 | - * @return false|int |
|
1042 | - * @throws EE_Error |
|
1043 | - * @throws InvalidArgumentException |
|
1044 | - * @throws InvalidDataTypeException |
|
1045 | - * @throws InvalidInterfaceException |
|
1046 | - */ |
|
1047 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1048 | - { |
|
1049 | - /** @type WPDB $wpdb */ |
|
1050 | - global $wpdb; |
|
1051 | - if (! absint($timestamp)) { |
|
1052 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1053 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1054 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1055 | - ); |
|
1056 | - $timestamp = $session_lifespan->expiration(); |
|
1057 | - } |
|
1058 | - return $wpdb->query( |
|
1059 | - $wpdb->prepare( |
|
1060 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
23 | + const debug = false; |
|
24 | + |
|
25 | + private static $nl = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
29 | + * |
|
30 | + * @var array $ticket_selections |
|
31 | + */ |
|
32 | + protected $ticket_selections = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | + * according to how they are displayed in the actual Ticket_Selector |
|
37 | + * this tracks the current row being processed |
|
38 | + * |
|
39 | + * @var int $current_row |
|
40 | + */ |
|
41 | + protected $current_row = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * an array for tracking names of tickets that have sold out |
|
45 | + * |
|
46 | + * @var array $sold_out_tickets |
|
47 | + */ |
|
48 | + protected $sold_out_tickets = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
52 | + * |
|
53 | + * @var array $decremented_tickets |
|
54 | + */ |
|
55 | + protected $decremented_tickets = array(); |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public static function set_hooks() |
|
64 | + { |
|
65 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
66 | + // release tickets for expired carts |
|
67 | + add_action( |
|
68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | + 1 |
|
71 | + ); |
|
72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | + 20, |
|
77 | + 3 |
|
78 | + ); |
|
79 | + // add notices for sold out tickets |
|
80 | + add_action( |
|
81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | + 10 |
|
84 | + ); |
|
85 | + |
|
86 | + // handle tickets deleted from cart |
|
87 | + add_action( |
|
88 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
89 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
90 | + 10, |
|
91 | + 2 |
|
92 | + ); |
|
93 | + // handle emptied carts |
|
94 | + add_action( |
|
95 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | + 10, |
|
98 | + 1 |
|
99 | + ); |
|
100 | + add_action( |
|
101 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | + 10, |
|
104 | + 1 |
|
105 | + ); |
|
106 | + // handle cancelled registrations |
|
107 | + add_action( |
|
108 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
109 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
110 | + 10, |
|
111 | + 1 |
|
112 | + ); |
|
113 | + // cron tasks |
|
114 | + add_action( |
|
115 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
116 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
117 | + 10, |
|
118 | + 1 |
|
119 | + ); |
|
120 | + add_action( |
|
121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | + 10, |
|
124 | + 1 |
|
125 | + ); |
|
126 | + add_action( |
|
127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
128 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
129 | + 10, |
|
130 | + 1 |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
137 | + * |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public static function set_hooks_admin() |
|
141 | + { |
|
142 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
148 | + */ |
|
149 | + public static function instance() |
|
150 | + { |
|
151 | + return parent::get_instance(__CLASS__); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param WP_Query $WP_Query |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function run($WP_Query) |
|
160 | + { |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Retrieves grand totals from the line items that have no TXN ID |
|
170 | + * and timestamps less than the current time minus the session lifespan. |
|
171 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
172 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
173 | + * |
|
174 | + * @return void |
|
175 | + * @throws DomainException |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + * @throws UnexpectedEntityException |
|
181 | + */ |
|
182 | + public static function release_tickets_for_expired_carts() |
|
183 | + { |
|
184 | + if (self::debug) { |
|
185 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | + } |
|
187 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | + $expired_ticket_IDs = array(); |
|
189 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | + ); |
|
193 | + $timestamp = $session_lifespan->expiration(); |
|
194 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | + if (self::debug) { |
|
196 | + echo self::$nl . ' . time(): ' . time(); |
|
197 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | + } |
|
203 | + if (! empty($expired_ticket_line_items)) { |
|
204 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | + if (self::debug) { |
|
210 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | + . date( |
|
213 | + 'Y-m-d h:i a', |
|
214 | + $expired_ticket_line_item->timestamp(true) |
|
215 | + ); |
|
216 | + } |
|
217 | + } |
|
218 | + if (! empty($expired_ticket_IDs)) { |
|
219 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | + array(), |
|
222 | + __FUNCTION__ |
|
223 | + ); |
|
224 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | + } |
|
227 | + } |
|
228 | + do_action( |
|
229 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | + $expired_ticket_IDs, |
|
231 | + $expired_ticket_line_items |
|
232 | + ); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | + * |
|
243 | + * @param int $qty |
|
244 | + * @param EE_Ticket $ticket |
|
245 | + * @return bool |
|
246 | + * @throws UnexpectedEntityException |
|
247 | + * @throws EE_Error |
|
248 | + */ |
|
249 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | + { |
|
251 | + $qty = absint($qty); |
|
252 | + if ($qty > 0) { |
|
253 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | + } |
|
255 | + if (self::debug) { |
|
256 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
258 | + } |
|
259 | + return $qty; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
265 | + * |
|
266 | + * @param EE_Ticket $ticket |
|
267 | + * @param int $qty |
|
268 | + * @return int |
|
269 | + * @throws UnexpectedEntityException |
|
270 | + * @throws EE_Error |
|
271 | + */ |
|
272 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
273 | + { |
|
274 | + if (self::debug) { |
|
275 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
276 | + } |
|
277 | + if (! $ticket instanceof EE_Ticket) { |
|
278 | + return 0; |
|
279 | + } |
|
280 | + if (self::debug) { |
|
281 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
283 | + } |
|
284 | + $ticket->refresh_from_db(); |
|
285 | + // first let's determine the ticket availability based on sales |
|
286 | + $available = $ticket->qty('saleable'); |
|
287 | + if (self::debug) { |
|
288 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | + echo self::$nl . ' . . . available: ' . $available; |
|
293 | + } |
|
294 | + if ($available < 1) { |
|
295 | + $this->_ticket_sold_out($ticket); |
|
296 | + return 0; |
|
297 | + } |
|
298 | + if (self::debug) { |
|
299 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
300 | + } |
|
301 | + if ($available < $qty) { |
|
302 | + $qty = $available; |
|
303 | + if (self::debug) { |
|
304 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
305 | + } |
|
306 | + $this->_ticket_quantity_decremented($ticket); |
|
307 | + } |
|
308 | + $this->_reserve_ticket($ticket, $qty); |
|
309 | + return $qty; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * increments ticket reserved based on quantity passed |
|
315 | + * |
|
316 | + * @param EE_Ticket $ticket |
|
317 | + * @param int $quantity |
|
318 | + * @return bool |
|
319 | + * @throws EE_Error |
|
320 | + */ |
|
321 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
322 | + { |
|
323 | + if (self::debug) { |
|
324 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
325 | + } |
|
326 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
327 | + return $ticket->save(); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param EE_Ticket $ticket |
|
333 | + * @param int $quantity |
|
334 | + * @return bool |
|
335 | + * @throws EE_Error |
|
336 | + */ |
|
337 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
338 | + { |
|
339 | + if (self::debug) { |
|
340 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
341 | + echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
342 | + } |
|
343 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
344 | + if (self::debug) { |
|
345 | + echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
346 | + } |
|
347 | + return $ticket->save() ? 1 : 0; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + /** |
|
352 | + * removes quantities within the ticket selector based on zero ticket availability |
|
353 | + * |
|
354 | + * @param EE_Ticket $ticket |
|
355 | + * @return void |
|
356 | + * @throws UnexpectedEntityException |
|
357 | + * @throws EE_Error |
|
358 | + */ |
|
359 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
360 | + { |
|
361 | + if (self::debug) { |
|
362 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
363 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
364 | + } |
|
365 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
371 | + * |
|
372 | + * @param EE_Ticket $ticket |
|
373 | + * @return void |
|
374 | + * @throws UnexpectedEntityException |
|
375 | + * @throws EE_Error |
|
376 | + */ |
|
377 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
378 | + { |
|
379 | + if (self::debug) { |
|
380 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
381 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
382 | + } |
|
383 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * builds string out of ticket and event name |
|
389 | + * |
|
390 | + * @param EE_Ticket $ticket |
|
391 | + * @return string |
|
392 | + * @throws UnexpectedEntityException |
|
393 | + * @throws EE_Error |
|
394 | + */ |
|
395 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
396 | + { |
|
397 | + $event = $ticket->get_related_event(); |
|
398 | + if ($event instanceof EE_Event) { |
|
399 | + $ticket_name = sprintf( |
|
400 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
401 | + $ticket->name(), |
|
402 | + $event->name() |
|
403 | + ); |
|
404 | + } else { |
|
405 | + $ticket_name = $ticket->name(); |
|
406 | + } |
|
407 | + return $ticket_name; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /********************************** EVENT CART **********************************/ |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * releases or reserves ticket(s) based on quantity passed |
|
417 | + * |
|
418 | + * @param EE_Line_Item $line_item |
|
419 | + * @param int $quantity |
|
420 | + * @return void |
|
421 | + * @throws EE_Error |
|
422 | + * @throws InvalidArgumentException |
|
423 | + * @throws InvalidDataTypeException |
|
424 | + * @throws InvalidInterfaceException |
|
425 | + */ |
|
426 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
427 | + { |
|
428 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
429 | + if ($ticket instanceof EE_Ticket) { |
|
430 | + $ticket->add_extra_meta( |
|
431 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
432 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
433 | + ); |
|
434 | + if ($quantity > 0) { |
|
435 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
436 | + } else { |
|
437 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
438 | + } |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * releases reserved ticket(s) based on quantity passed |
|
445 | + * |
|
446 | + * @param EE_Ticket $ticket |
|
447 | + * @param int $quantity |
|
448 | + * @return void |
|
449 | + * @throws EE_Error |
|
450 | + */ |
|
451 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
452 | + { |
|
453 | + $ticket->add_extra_meta( |
|
454 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
455 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
456 | + ); |
|
457 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + |
|
462 | + /********************************** POST_NOTICES **********************************/ |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * @return void |
|
467 | + * @throws EE_Error |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws ReflectionException |
|
470 | + * @throws InvalidDataTypeException |
|
471 | + * @throws InvalidInterfaceException |
|
472 | + */ |
|
473 | + public static function post_notices() |
|
474 | + { |
|
475 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * @return void |
|
481 | + * @throws EE_Error |
|
482 | + * @throws InvalidArgumentException |
|
483 | + * @throws ReflectionException |
|
484 | + * @throws InvalidDataTypeException |
|
485 | + * @throws InvalidInterfaceException |
|
486 | + */ |
|
487 | + protected function _post_notices() |
|
488 | + { |
|
489 | + if (self::debug) { |
|
490 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
491 | + } |
|
492 | + $refresh_msg = ''; |
|
493 | + $none_added_msg = ''; |
|
494 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
495 | + $refresh_msg = __( |
|
496 | + 'Please refresh the page to view updated ticket quantities.', |
|
497 | + 'event_espresso' |
|
498 | + ); |
|
499 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
500 | + } |
|
501 | + if (! empty($this->sold_out_tickets)) { |
|
502 | + EE_Error::add_attention( |
|
503 | + sprintf( |
|
504 | + apply_filters( |
|
505 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
506 | + __( |
|
507 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
508 | + 'event_espresso' |
|
509 | + ) |
|
510 | + ), |
|
511 | + '<br />', |
|
512 | + implode('<br />', $this->sold_out_tickets), |
|
513 | + $none_added_msg, |
|
514 | + $refresh_msg |
|
515 | + ) |
|
516 | + ); |
|
517 | + // alter code flow in the Ticket Selector for better UX |
|
518 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
519 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
520 | + $this->sold_out_tickets = array(); |
|
521 | + // and reset the cart |
|
522 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
523 | + } |
|
524 | + if (! empty($this->decremented_tickets)) { |
|
525 | + EE_Error::add_attention( |
|
526 | + sprintf( |
|
527 | + apply_filters( |
|
528 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
529 | + __( |
|
530 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
531 | + 'event_espresso' |
|
532 | + ) |
|
533 | + ), |
|
534 | + '<br />', |
|
535 | + implode('<br />', $this->decremented_tickets), |
|
536 | + $none_added_msg, |
|
537 | + $refresh_msg |
|
538 | + ) |
|
539 | + ); |
|
540 | + $this->decremented_tickets = array(); |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
551 | + * by default, will NOT release tickets for finalized transactions |
|
552 | + * |
|
553 | + * @param EE_Transaction $transaction |
|
554 | + * @return int |
|
555 | + * @throws EE_Error |
|
556 | + * @throws InvalidSessionDataException |
|
557 | + */ |
|
558 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
559 | + { |
|
560 | + if (self::debug) { |
|
561 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
562 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
563 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
564 | + } |
|
565 | + // check if 'finalize_registration' step has been completed... |
|
566 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
567 | + if (self::debug) { |
|
568 | + // DEBUG LOG |
|
569 | + EEH_Debug_Tools::log( |
|
570 | + __CLASS__, |
|
571 | + __FUNCTION__, |
|
572 | + __LINE__, |
|
573 | + array('finalized' => $finalized), |
|
574 | + false, |
|
575 | + 'EE_Transaction: ' . $transaction->ID() |
|
576 | + ); |
|
577 | + } |
|
578 | + // how many tickets were released |
|
579 | + $count = 0; |
|
580 | + if (self::debug) { |
|
581 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
582 | + } |
|
583 | + $release_tickets_with_TXN_status = array( |
|
584 | + EEM_Transaction::failed_status_code, |
|
585 | + EEM_Transaction::abandoned_status_code, |
|
586 | + EEM_Transaction::incomplete_status_code, |
|
587 | + ); |
|
588 | + $events = array(); |
|
589 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
590 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
591 | + // cancel any reserved tickets for registrations that were not approved |
|
592 | + $registrations = $transaction->registrations(); |
|
593 | + if (self::debug) { |
|
594 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
595 | + $reg = reset($registrations); |
|
596 | + $ticket = $reg->ticket(); |
|
597 | + if ($ticket instanceof EE_Ticket) { |
|
598 | + $ticket->add_extra_meta( |
|
599 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
600 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
601 | + ); |
|
602 | + } |
|
603 | + } |
|
604 | + if (! empty($registrations)) { |
|
605 | + foreach ($registrations as $registration) { |
|
606 | + if ($registration instanceof EE_Registration |
|
607 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
608 | + ) { |
|
609 | + $count++; |
|
610 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
611 | + } |
|
612 | + } |
|
613 | + } |
|
614 | + } |
|
615 | + if ($events !== array()) { |
|
616 | + foreach ($events as $event) { |
|
617 | + /** @var EE_Event $event */ |
|
618 | + $event->perform_sold_out_status_check(); |
|
619 | + } |
|
620 | + } |
|
621 | + return $count; |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * releases reserved tickets for an EE_Registration |
|
627 | + * by default, will NOT release tickets for APPROVED registrations |
|
628 | + * |
|
629 | + * @param EE_Registration $registration |
|
630 | + * @param EE_Transaction $transaction |
|
631 | + * @return int |
|
632 | + * @throws EE_Error |
|
633 | + */ |
|
634 | + protected function _release_reserved_ticket_for_registration( |
|
635 | + EE_Registration $registration, |
|
636 | + EE_Transaction $transaction |
|
637 | + ) { |
|
638 | + $STS_ID = $transaction->status_ID(); |
|
639 | + if (self::debug) { |
|
640 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
641 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
642 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
643 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
644 | + } |
|
645 | + if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
646 | + $STS_ID === EEM_Transaction::failed_status_code |
|
647 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
648 | + || ( |
|
649 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
650 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
651 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
652 | + ) |
|
653 | + ) { |
|
654 | + if (self::debug) { |
|
655 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
656 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
657 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
658 | + var_dump($rsrvd); |
|
659 | + } |
|
660 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
661 | + return 1; |
|
662 | + } |
|
663 | + return 0; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + |
|
668 | + /********************************** SESSION_CART_RESET **********************************/ |
|
669 | + |
|
670 | + |
|
671 | + /** |
|
672 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
673 | + * |
|
674 | + * @param EE_Session $session |
|
675 | + * @return void |
|
676 | + * @throws EE_Error |
|
677 | + * @throws InvalidArgumentException |
|
678 | + * @throws ReflectionException |
|
679 | + * @throws InvalidDataTypeException |
|
680 | + * @throws InvalidInterfaceException |
|
681 | + */ |
|
682 | + public static function session_cart_reset(EE_Session $session) |
|
683 | + { |
|
684 | + // don't release tickets if checkout was already reset |
|
685 | + if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
686 | + return; |
|
687 | + } |
|
688 | + if (self::debug) { |
|
689 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
690 | + } |
|
691 | + // first check of the session has a valid Checkout object |
|
692 | + $checkout = $session->checkout(); |
|
693 | + if ($checkout instanceof EE_Checkout) { |
|
694 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
695 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
696 | + return; |
|
697 | + } |
|
698 | + $cart = $session->cart(); |
|
699 | + if ($cart instanceof EE_Cart) { |
|
700 | + if (self::debug) { |
|
701 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
702 | + } |
|
703 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
704 | + } else { |
|
705 | + if (self::debug) { |
|
706 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
707 | + var_export($cart, true); |
|
708 | + } |
|
709 | + } |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * releases reserved tickets in the EE_Cart |
|
715 | + * |
|
716 | + * @param EE_Cart $cart |
|
717 | + * @return void |
|
718 | + * @throws EE_Error |
|
719 | + * @throws InvalidArgumentException |
|
720 | + * @throws ReflectionException |
|
721 | + * @throws InvalidDataTypeException |
|
722 | + * @throws InvalidInterfaceException |
|
723 | + */ |
|
724 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
725 | + { |
|
726 | + if (self::debug) { |
|
727 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
728 | + } |
|
729 | + $ticket_line_items = $cart->get_tickets(); |
|
730 | + if (empty($ticket_line_items)) { |
|
731 | + return; |
|
732 | + } |
|
733 | + if (self::debug) { |
|
734 | + echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
735 | + } |
|
736 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
737 | + if (self::debug) { |
|
738 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
739 | + } |
|
740 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
741 | + if (self::debug) { |
|
742 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
743 | + } |
|
744 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
745 | + if ($ticket instanceof EE_Ticket) { |
|
746 | + if (self::debug) { |
|
747 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
748 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
749 | + } |
|
750 | + $ticket->add_extra_meta( |
|
751 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
752 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
753 | + ); |
|
754 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
755 | + } |
|
756 | + } |
|
757 | + } |
|
758 | + if (self::debug) { |
|
759 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
760 | + } |
|
761 | + } |
|
762 | + |
|
763 | + |
|
764 | + |
|
765 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
770 | + * |
|
771 | + * @param EE_Session $session |
|
772 | + * @return void |
|
773 | + * @throws EE_Error |
|
774 | + * @throws InvalidSessionDataException |
|
775 | + */ |
|
776 | + public static function session_checkout_reset(EE_Session $session) |
|
777 | + { |
|
778 | + // don't release tickets if cart was already reset |
|
779 | + if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
780 | + return; |
|
781 | + } |
|
782 | + $checkout = $session->checkout(); |
|
783 | + if ($checkout instanceof EE_Checkout) { |
|
784 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
785 | + } |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * releases reserved tickets for the EE_Checkout->transaction |
|
791 | + * |
|
792 | + * @param EE_Checkout $checkout |
|
793 | + * @return void |
|
794 | + * @throws EE_Error |
|
795 | + * @throws InvalidSessionDataException |
|
796 | + */ |
|
797 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
798 | + { |
|
799 | + if (self::debug) { |
|
800 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
801 | + } |
|
802 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
803 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
804 | + return; |
|
805 | + } |
|
806 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + |
|
811 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @param EE_Session $session |
|
816 | + * @return void |
|
817 | + */ |
|
818 | + public static function session_expired_reset(EE_Session $session) |
|
819 | + { |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
829 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
830 | + * |
|
831 | + * @param EE_Transaction $transaction |
|
832 | + * @return void |
|
833 | + * @throws EE_Error |
|
834 | + * @throws InvalidSessionDataException |
|
835 | + */ |
|
836 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
837 | + { |
|
838 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
839 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
840 | + if (self::debug) { |
|
841 | + // DEBUG LOG |
|
842 | + EEH_Debug_Tools::log( |
|
843 | + __CLASS__, |
|
844 | + __FUNCTION__, |
|
845 | + __LINE__, |
|
846 | + array($transaction), |
|
847 | + false, |
|
848 | + 'EE_Transaction: ' . $transaction->ID() |
|
849 | + ); |
|
850 | + } |
|
851 | + return; |
|
852 | + } |
|
853 | + // have their been any successful payments made ? |
|
854 | + $payments = $transaction->payments(); |
|
855 | + foreach ($payments as $payment) { |
|
856 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
857 | + if (self::debug) { |
|
858 | + // DEBUG LOG |
|
859 | + EEH_Debug_Tools::log( |
|
860 | + __CLASS__, |
|
861 | + __FUNCTION__, |
|
862 | + __LINE__, |
|
863 | + array($payment), |
|
864 | + false, |
|
865 | + 'EE_Transaction: ' . $transaction->ID() |
|
866 | + ); |
|
867 | + } |
|
868 | + return; |
|
869 | + } |
|
870 | + } |
|
871 | + // since you haven't even attempted to pay for your ticket... |
|
872 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
878 | + |
|
879 | + |
|
880 | + /** |
|
881 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
882 | + * |
|
883 | + * @param EE_Transaction $transaction |
|
884 | + * @return void |
|
885 | + * @throws EE_Error |
|
886 | + * @throws InvalidSessionDataException |
|
887 | + */ |
|
888 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
889 | + { |
|
890 | + // since you haven't even attempted to pay for your ticket... |
|
891 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + |
|
896 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * Resets all ticket and datetime reserved counts to zero |
|
901 | + * Tickets that are currently associated with a Transaction that is in progress |
|
902 | + * |
|
903 | + * @throws EE_Error |
|
904 | + * @throws DomainException |
|
905 | + * @throws InvalidDataTypeException |
|
906 | + * @throws InvalidInterfaceException |
|
907 | + * @throws InvalidArgumentException |
|
908 | + * @throws UnexpectedEntityException |
|
909 | + */ |
|
910 | + public static function reset_reservation_counts() |
|
911 | + { |
|
912 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
913 | + $valid_reserved_tickets = array(); |
|
914 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
915 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
916 | + foreach ($transactions_not_in_progress as $transaction) { |
|
917 | + // if this TXN has been fully completed, then skip it |
|
918 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
919 | + continue; |
|
920 | + } |
|
921 | + $total_line_item = $transaction->total_line_item(); |
|
922 | + // $transaction_in_progress->line |
|
923 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
924 | + throw new DomainException( |
|
925 | + esc_html__( |
|
926 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
927 | + 'event_espresso' |
|
928 | + ) |
|
929 | + ); |
|
930 | + } |
|
931 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
932 | + $total_line_item |
|
933 | + ); |
|
934 | + } |
|
935 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
936 | + foreach ($total_line_items as $total_line_item) { |
|
937 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
938 | + $total_line_item |
|
939 | + ); |
|
940 | + } |
|
941 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
942 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
943 | + $tickets_with_reservations, |
|
944 | + $valid_reserved_tickets, |
|
945 | + __FUNCTION__ |
|
946 | + ); |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + /** |
|
951 | + * @param EE_Line_Item $total_line_item |
|
952 | + * @return EE_Line_Item[] |
|
953 | + */ |
|
954 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
955 | + { |
|
956 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
957 | + $valid_reserved_tickets = array(); |
|
958 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
959 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
960 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
961 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
962 | + } |
|
963 | + } |
|
964 | + return $valid_reserved_tickets; |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * @param EE_Ticket[] $tickets_with_reservations |
|
970 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
971 | + * @return int |
|
972 | + * @throws UnexpectedEntityException |
|
973 | + * @throws DomainException |
|
974 | + * @throws EE_Error |
|
975 | + */ |
|
976 | + private static function release_reservations_for_tickets( |
|
977 | + array $tickets_with_reservations, |
|
978 | + array $valid_reserved_ticket_line_items = array(), |
|
979 | + $source |
|
980 | + ) { |
|
981 | + if (self::debug) { |
|
982 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
983 | + } |
|
984 | + $total_tickets_released = 0; |
|
985 | + $sold_out_events = array(); |
|
986 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
987 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
988 | + continue; |
|
989 | + } |
|
990 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
991 | + if (self::debug) { |
|
992 | + echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
993 | + echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
994 | + } |
|
995 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
996 | + if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
997 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
998 | + ) { |
|
999 | + if (self::debug) { |
|
1000 | + echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' |
|
1001 | + . $valid_reserved_ticket_line_item->quantity(); |
|
1002 | + } |
|
1003 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
1004 | + } |
|
1005 | + } |
|
1006 | + if ($reserved_qty > 0) { |
|
1007 | + $ticket_with_reservations->add_extra_meta( |
|
1008 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1009 | + __LINE__ . ') ' . $source . '()' |
|
1010 | + ); |
|
1011 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:' . __LINE__); |
|
1012 | + $ticket_with_reservations->save(); |
|
1013 | + $total_tickets_released += $reserved_qty; |
|
1014 | + $event = $ticket_with_reservations->get_related_event(); |
|
1015 | + // track sold out events |
|
1016 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1017 | + $sold_out_events[] = $event; |
|
1018 | + } |
|
1019 | + } |
|
1020 | + } |
|
1021 | + if (self::debug) { |
|
1022 | + echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
1023 | + } |
|
1024 | + // double check whether sold out events should remain sold out after releasing tickets |
|
1025 | + if ($sold_out_events !== array()) { |
|
1026 | + foreach ($sold_out_events as $sold_out_event) { |
|
1027 | + /** @var EE_Event $sold_out_event */ |
|
1028 | + $sold_out_event->perform_sold_out_status_check(); |
|
1029 | + } |
|
1030 | + } |
|
1031 | + return $total_tickets_released; |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + |
|
1036 | + /********************************** SHUTDOWN **********************************/ |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * @param int $timestamp |
|
1041 | + * @return false|int |
|
1042 | + * @throws EE_Error |
|
1043 | + * @throws InvalidArgumentException |
|
1044 | + * @throws InvalidDataTypeException |
|
1045 | + * @throws InvalidInterfaceException |
|
1046 | + */ |
|
1047 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1048 | + { |
|
1049 | + /** @type WPDB $wpdb */ |
|
1050 | + global $wpdb; |
|
1051 | + if (! absint($timestamp)) { |
|
1052 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1053 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1054 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1055 | + ); |
|
1056 | + $timestamp = $session_lifespan->expiration(); |
|
1057 | + } |
|
1058 | + return $wpdb->query( |
|
1059 | + $wpdb->prepare( |
|
1060 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1061 | 1061 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1062 | - // use GMT time because that's what LIN_timestamps are in |
|
1063 | - date('Y-m-d H:i:s', $timestamp) |
|
1064 | - ) |
|
1065 | - ); |
|
1066 | - } |
|
1062 | + // use GMT time because that's what LIN_timestamps are in |
|
1063 | + date('Y-m-d H:i:s', $timestamp) |
|
1064 | + ) |
|
1065 | + ); |
|
1066 | + } |
|
1067 | 1067 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public static function release_tickets_for_expired_carts() |
183 | 183 | { |
184 | 184 | if (self::debug) { |
185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
185 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
186 | 186 | } |
187 | 187 | do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
188 | 188 | $expired_ticket_IDs = array(); |
@@ -193,29 +193,29 @@ discard block |
||
193 | 193 | $timestamp = $session_lifespan->expiration(); |
194 | 194 | $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
195 | 195 | if (self::debug) { |
196 | - echo self::$nl . ' . time(): ' . time(); |
|
197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
196 | + echo self::$nl.' . time(): '.time(); |
|
197 | + echo self::$nl.' . time() as date: '.date('Y-m-d H:i a'); |
|
198 | + echo self::$nl.' . session expiration: '.$session_lifespan->expiration(); |
|
199 | + echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | + echo self::$nl.' . timestamp: '.$timestamp; |
|
201 | + echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items); |
|
202 | 202 | } |
203 | - if (! empty($expired_ticket_line_items)) { |
|
203 | + if ( ! empty($expired_ticket_line_items)) { |
|
204 | 204 | foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
205 | + if ( ! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
208 | + $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | 209 | if (self::debug) { |
210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
210 | + echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID(); |
|
211 | + echo self::$nl.' . $expired_ticket_line_item->timestamp(): ' |
|
212 | 212 | . date( |
213 | 213 | 'Y-m-d h:i a', |
214 | 214 | $expired_ticket_line_item->timestamp(true) |
215 | 215 | ); |
216 | 216 | } |
217 | 217 | } |
218 | - if (! empty($expired_ticket_IDs)) { |
|
218 | + if ( ! empty($expired_ticket_IDs)) { |
|
219 | 219 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
220 | 220 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
221 | 221 | array(), |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
254 | 254 | } |
255 | 255 | if (self::debug) { |
256 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
256 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
257 | + echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>'; |
|
258 | 258 | } |
259 | 259 | return $qty; |
260 | 260 | } |
@@ -272,36 +272,36 @@ discard block |
||
272 | 272 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
273 | 273 | { |
274 | 274 | if (self::debug) { |
275 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
275 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
276 | 276 | } |
277 | - if (! $ticket instanceof EE_Ticket) { |
|
277 | + if ( ! $ticket instanceof EE_Ticket) { |
|
278 | 278 | return 0; |
279 | 279 | } |
280 | 280 | if (self::debug) { |
281 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
281 | + echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
282 | + echo self::$nl.' . original ticket->reserved: '.$ticket->reserved(); |
|
283 | 283 | } |
284 | 284 | $ticket->refresh_from_db(); |
285 | 285 | // first let's determine the ticket availability based on sales |
286 | 286 | $available = $ticket->qty('saleable'); |
287 | 287 | if (self::debug) { |
288 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | - echo self::$nl . ' . . . available: ' . $available; |
|
288 | + echo self::$nl.' . . . ticket->qty: '.$ticket->qty(); |
|
289 | + echo self::$nl.' . . . ticket->sold: '.$ticket->sold(); |
|
290 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
291 | + echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
292 | + echo self::$nl.' . . . available: '.$available; |
|
293 | 293 | } |
294 | 294 | if ($available < 1) { |
295 | 295 | $this->_ticket_sold_out($ticket); |
296 | 296 | return 0; |
297 | 297 | } |
298 | 298 | if (self::debug) { |
299 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
299 | + echo self::$nl.' . . . qty: '.$qty; |
|
300 | 300 | } |
301 | 301 | if ($available < $qty) { |
302 | 302 | $qty = $available; |
303 | 303 | if (self::debug) { |
304 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
304 | + echo self::$nl.' . . . QTY ADJUSTED: '.$qty; |
|
305 | 305 | } |
306 | 306 | $this->_ticket_quantity_decremented($ticket); |
307 | 307 | } |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
322 | 322 | { |
323 | 323 | if (self::debug) { |
324 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
324 | + echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity; |
|
325 | 325 | } |
326 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
326 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
327 | 327 | return $ticket->save(); |
328 | 328 | } |
329 | 329 | |
@@ -337,12 +337,12 @@ discard block |
||
337 | 337 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
338 | 338 | { |
339 | 339 | if (self::debug) { |
340 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
341 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
340 | + echo self::$nl.' . . . ticket->ID: '.$ticket->ID(); |
|
341 | + echo self::$nl.' . . . ticket->reserved before: '.$ticket->reserved(); |
|
342 | 342 | } |
343 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
343 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
344 | 344 | if (self::debug) { |
345 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
345 | + echo self::$nl.' . . . ticket->reserved after: '.$ticket->reserved(); |
|
346 | 346 | } |
347 | 347 | return $ticket->save() ? 1 : 0; |
348 | 348 | } |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | protected function _ticket_sold_out(EE_Ticket $ticket) |
360 | 360 | { |
361 | 361 | if (self::debug) { |
362 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
363 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
362 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
363 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
364 | 364 | } |
365 | 365 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
366 | 366 | } |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
378 | 378 | { |
379 | 379 | if (self::debug) { |
380 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
381 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
380 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
381 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
382 | 382 | } |
383 | 383 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
384 | 384 | } |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | if ($ticket instanceof EE_Ticket) { |
430 | 430 | $ticket->add_extra_meta( |
431 | 431 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
432 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
432 | + __LINE__.') '.__METHOD__.'()' |
|
433 | 433 | ); |
434 | 434 | if ($quantity > 0) { |
435 | 435 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | { |
453 | 453 | $ticket->add_extra_meta( |
454 | 454 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
455 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
455 | + __LINE__.') '.__METHOD__.'()' |
|
456 | 456 | ); |
457 | 457 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
458 | 458 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | protected function _post_notices() |
488 | 488 | { |
489 | 489 | if (self::debug) { |
490 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
490 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
491 | 491 | } |
492 | 492 | $refresh_msg = ''; |
493 | 493 | $none_added_msg = ''; |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | ); |
499 | 499 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
500 | 500 | } |
501 | - if (! empty($this->sold_out_tickets)) { |
|
501 | + if ( ! empty($this->sold_out_tickets)) { |
|
502 | 502 | EE_Error::add_attention( |
503 | 503 | sprintf( |
504 | 504 | apply_filters( |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | // and reset the cart |
522 | 522 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
523 | 523 | } |
524 | - if (! empty($this->decremented_tickets)) { |
|
524 | + if ( ! empty($this->decremented_tickets)) { |
|
525 | 525 | EE_Error::add_attention( |
526 | 526 | sprintf( |
527 | 527 | apply_filters( |
@@ -558,9 +558,9 @@ discard block |
||
558 | 558 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
559 | 559 | { |
560 | 560 | if (self::debug) { |
561 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
562 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
563 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
561 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
562 | + echo self::$nl.' . transaction->ID: '.$transaction->ID(); |
|
563 | + echo self::$nl.' . TXN status_ID: '.$transaction->status_ID(); |
|
564 | 564 | } |
565 | 565 | // check if 'finalize_registration' step has been completed... |
566 | 566 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -572,13 +572,13 @@ discard block |
||
572 | 572 | __LINE__, |
573 | 573 | array('finalized' => $finalized), |
574 | 574 | false, |
575 | - 'EE_Transaction: ' . $transaction->ID() |
|
575 | + 'EE_Transaction: '.$transaction->ID() |
|
576 | 576 | ); |
577 | 577 | } |
578 | 578 | // how many tickets were released |
579 | 579 | $count = 0; |
580 | 580 | if (self::debug) { |
581 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
581 | + echo self::$nl.' . . . TXN finalized: '.$finalized; |
|
582 | 582 | } |
583 | 583 | $release_tickets_with_TXN_status = array( |
584 | 584 | EEM_Transaction::failed_status_code, |
@@ -587,27 +587,27 @@ discard block |
||
587 | 587 | ); |
588 | 588 | $events = array(); |
589 | 589 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
590 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
590 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
591 | 591 | // cancel any reserved tickets for registrations that were not approved |
592 | 592 | $registrations = $transaction->registrations(); |
593 | 593 | if (self::debug) { |
594 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
594 | + echo self::$nl.' . . . # registrations: '.count($registrations); |
|
595 | 595 | $reg = reset($registrations); |
596 | 596 | $ticket = $reg->ticket(); |
597 | 597 | if ($ticket instanceof EE_Ticket) { |
598 | 598 | $ticket->add_extra_meta( |
599 | 599 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
600 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
600 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
601 | 601 | ); |
602 | 602 | } |
603 | 603 | } |
604 | - if (! empty($registrations)) { |
|
604 | + if ( ! empty($registrations)) { |
|
605 | 605 | foreach ($registrations as $registration) { |
606 | 606 | if ($registration instanceof EE_Registration |
607 | 607 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
608 | 608 | ) { |
609 | 609 | $count++; |
610 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
610 | + $events[$registration->event_ID()] = $registration->event(); |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | } |
@@ -637,10 +637,10 @@ discard block |
||
637 | 637 | ) { |
638 | 638 | $STS_ID = $transaction->status_ID(); |
639 | 639 | if (self::debug) { |
640 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
641 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
642 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
643 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
640 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
641 | + echo self::$nl.' . . registration->ID: '.$registration->ID(); |
|
642 | + echo self::$nl.' . . registration->status_ID: '.$registration->status_ID(); |
|
643 | + echo self::$nl.' . . transaction->status_ID(): '.$STS_ID; |
|
644 | 644 | } |
645 | 645 | if (// release Tickets for Failed Transactions and Abandoned Transactions |
646 | 646 | $STS_ID === EEM_Transaction::failed_status_code |
@@ -652,12 +652,12 @@ discard block |
||
652 | 652 | ) |
653 | 653 | ) { |
654 | 654 | if (self::debug) { |
655 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
655 | + echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET'; |
|
656 | 656 | $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
657 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
657 | + echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
658 | 658 | var_dump($rsrvd); |
659 | 659 | } |
660 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
660 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
661 | 661 | return 1; |
662 | 662 | } |
663 | 663 | return 0; |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | return; |
687 | 687 | } |
688 | 688 | if (self::debug) { |
689 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
689 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
690 | 690 | } |
691 | 691 | // first check of the session has a valid Checkout object |
692 | 692 | $checkout = $session->checkout(); |
@@ -698,12 +698,12 @@ discard block |
||
698 | 698 | $cart = $session->cart(); |
699 | 699 | if ($cart instanceof EE_Cart) { |
700 | 700 | if (self::debug) { |
701 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
701 | + echo self::$nl.self::$nl.' cart instance of EE_Cart: '; |
|
702 | 702 | } |
703 | 703 | EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
704 | 704 | } else { |
705 | 705 | if (self::debug) { |
706 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
706 | + echo self::$nl.self::$nl.' invalid EE_Cart: '; |
|
707 | 707 | var_export($cart, true); |
708 | 708 | } |
709 | 709 | } |
@@ -724,39 +724,39 @@ discard block |
||
724 | 724 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
725 | 725 | { |
726 | 726 | if (self::debug) { |
727 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
727 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
728 | 728 | } |
729 | 729 | $ticket_line_items = $cart->get_tickets(); |
730 | 730 | if (empty($ticket_line_items)) { |
731 | 731 | return; |
732 | 732 | } |
733 | 733 | if (self::debug) { |
734 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
734 | + echo '<br /> . ticket_line_item count: '.count($ticket_line_items); |
|
735 | 735 | } |
736 | 736 | foreach ($ticket_line_items as $ticket_line_item) { |
737 | 737 | if (self::debug) { |
738 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
738 | + echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
739 | 739 | } |
740 | 740 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
741 | 741 | if (self::debug) { |
742 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
742 | + echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
743 | 743 | } |
744 | 744 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
745 | 745 | if ($ticket instanceof EE_Ticket) { |
746 | 746 | if (self::debug) { |
747 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
748 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
747 | + echo self::$nl.' . . ticket->ID(): '.$ticket->ID(); |
|
748 | + echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
749 | 749 | } |
750 | 750 | $ticket->add_extra_meta( |
751 | 751 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
752 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
752 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
753 | 753 | ); |
754 | 754 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
755 | 755 | } |
756 | 756 | } |
757 | 757 | } |
758 | 758 | if (self::debug) { |
759 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
759 | + echo self::$nl.self::$nl.' RESET COMPLETED '; |
|
760 | 760 | } |
761 | 761 | } |
762 | 762 | |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | protected function _session_checkout_reset(EE_Checkout $checkout) |
798 | 798 | { |
799 | 799 | if (self::debug) { |
800 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
800 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
801 | 801 | } |
802 | 802 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
803 | 803 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | __LINE__, |
846 | 846 | array($transaction), |
847 | 847 | false, |
848 | - 'EE_Transaction: ' . $transaction->ID() |
|
848 | + 'EE_Transaction: '.$transaction->ID() |
|
849 | 849 | ); |
850 | 850 | } |
851 | 851 | return; |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | __LINE__, |
863 | 863 | array($payment), |
864 | 864 | false, |
865 | - 'EE_Transaction: ' . $transaction->ID() |
|
865 | + 'EE_Transaction: '.$transaction->ID() |
|
866 | 866 | ); |
867 | 867 | } |
868 | 868 | return; |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | } |
921 | 921 | $total_line_item = $transaction->total_line_item(); |
922 | 922 | // $transaction_in_progress->line |
923 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
923 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
924 | 924 | throw new DomainException( |
925 | 925 | esc_html__( |
926 | 926 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -979,25 +979,25 @@ discard block |
||
979 | 979 | $source |
980 | 980 | ) { |
981 | 981 | if (self::debug) { |
982 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
982 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
983 | 983 | } |
984 | 984 | $total_tickets_released = 0; |
985 | 985 | $sold_out_events = array(); |
986 | 986 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
987 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
987 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
988 | 988 | continue; |
989 | 989 | } |
990 | 990 | $reserved_qty = $ticket_with_reservations->reserved(); |
991 | 991 | if (self::debug) { |
992 | - echo self::$nl . ' . $ticket_with_reservations->ID(): ' . $ticket_with_reservations->ID(); |
|
993 | - echo self::$nl . ' . $reserved_qty: ' . $reserved_qty; |
|
992 | + echo self::$nl.' . $ticket_with_reservations->ID(): '.$ticket_with_reservations->ID(); |
|
993 | + echo self::$nl.' . $reserved_qty: '.$reserved_qty; |
|
994 | 994 | } |
995 | 995 | foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
996 | 996 | if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
997 | 997 | && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
998 | 998 | ) { |
999 | 999 | if (self::debug) { |
1000 | - echo self::$nl . ' . $valid_reserved_ticket_line_item->quantity(): ' |
|
1000 | + echo self::$nl.' . $valid_reserved_ticket_line_item->quantity(): ' |
|
1001 | 1001 | . $valid_reserved_ticket_line_item->quantity(); |
1002 | 1002 | } |
1003 | 1003 | $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
@@ -1006,9 +1006,9 @@ discard block |
||
1006 | 1006 | if ($reserved_qty > 0) { |
1007 | 1007 | $ticket_with_reservations->add_extra_meta( |
1008 | 1008 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
1009 | - __LINE__ . ') ' . $source . '()' |
|
1009 | + __LINE__.') '.$source.'()' |
|
1010 | 1010 | ); |
1011 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:' . __LINE__); |
|
1011 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__); |
|
1012 | 1012 | $ticket_with_reservations->save(); |
1013 | 1013 | $total_tickets_released += $reserved_qty; |
1014 | 1014 | $event = $ticket_with_reservations->get_related_event(); |
@@ -1019,7 +1019,7 @@ discard block |
||
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | if (self::debug) { |
1022 | - echo self::$nl . ' . $total_tickets_released: ' . $total_tickets_released; |
|
1022 | + echo self::$nl.' . $total_tickets_released: '.$total_tickets_released; |
|
1023 | 1023 | } |
1024 | 1024 | // double check whether sold out events should remain sold out after releasing tickets |
1025 | 1025 | if ($sold_out_events !== array()) { |
@@ -1048,7 +1048,7 @@ discard block |
||
1048 | 1048 | { |
1049 | 1049 | /** @type WPDB $wpdb */ |
1050 | 1050 | global $wpdb; |
1051 | - if (! absint($timestamp)) { |
|
1051 | + if ( ! absint($timestamp)) { |
|
1052 | 1052 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
1053 | 1053 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
1054 | 1054 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -1057,7 +1057,7 @@ discard block |
||
1057 | 1057 | } |
1058 | 1058 | return $wpdb->query( |
1059 | 1059 | $wpdb->prepare( |
1060 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1060 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
1061 | 1061 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1062 | 1062 | // use GMT time because that's what LIN_timestamps are in |
1063 | 1063 | date('Y-m-d H:i:s', $timestamp) |
@@ -21,181 +21,181 @@ |
||
21 | 21 | abstract class AssetManager implements AssetManagerInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var AssetCollection $assets |
|
26 | - */ |
|
27 | - protected $assets; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var DomainInterface |
|
31 | - */ |
|
32 | - protected $domain; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Registry $registry |
|
36 | - */ |
|
37 | - protected $registry; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * AssetRegister constructor. |
|
42 | - * |
|
43 | - * @param DomainInterface $domain |
|
44 | - * @param AssetCollection $assets |
|
45 | - * @param Registry $registry |
|
46 | - */ |
|
47 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | - { |
|
49 | - $this->domain = $domain; |
|
50 | - $this->assets = $assets; |
|
51 | - $this->registry = $registry; |
|
52 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @since $VID:$ |
|
61 | - */ |
|
62 | - abstract public function addAssets(); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @return void |
|
67 | - * @throws DuplicateCollectionIdentifierException |
|
68 | - * @throws InvalidDataTypeException |
|
69 | - * @throws InvalidEntityException |
|
70 | - * @since $VID:$ |
|
71 | - */ |
|
72 | - public function addManifestFile() |
|
73 | - { |
|
74 | - // if a manifest file has already been added for this domain, then just return that one |
|
75 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
76 | - return; |
|
77 | - } |
|
78 | - $asset = new ManifestFile($this->domain); |
|
79 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return ManifestFile[] |
|
85 | - * @since $VID:$ |
|
86 | - */ |
|
87 | - public function getManifestFile() |
|
88 | - { |
|
89 | - return $this->assets->getManifestFiles(); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param string $handle |
|
95 | - * @param string $source |
|
96 | - * @param array $dependencies |
|
97 | - * @param bool $load_in_footer |
|
98 | - * @return JavascriptAsset |
|
99 | - * @throws DuplicateCollectionIdentifierException |
|
100 | - * @throws InvalidDataTypeException |
|
101 | - * @throws InvalidEntityException |
|
102 | - * @since $VID:$ |
|
103 | - */ |
|
104 | - public function addJavascript( |
|
105 | - $handle, |
|
106 | - $source, |
|
107 | - array $dependencies = array(), |
|
108 | - $load_in_footer = true |
|
109 | - ) { |
|
110 | - $asset = new JavascriptAsset( |
|
111 | - $handle, |
|
112 | - $source, |
|
113 | - $dependencies, |
|
114 | - $load_in_footer, |
|
115 | - $this->domain |
|
116 | - ); |
|
117 | - $this->assets->add($asset, $handle); |
|
118 | - return $asset; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return JavascriptAsset[] |
|
124 | - * @since $VID:$ |
|
125 | - */ |
|
126 | - public function getJavascriptAssets() |
|
127 | - { |
|
128 | - return $this->assets->getJavascriptAssets(); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $handle |
|
134 | - * @param string $source |
|
135 | - * @param array $dependencies |
|
136 | - * @param string $media |
|
137 | - * @return StylesheetAsset |
|
138 | - * @throws DuplicateCollectionIdentifierException |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidEntityException |
|
141 | - * @since $VID:$ |
|
142 | - */ |
|
143 | - public function addStylesheet( |
|
144 | - $handle, |
|
145 | - $source, |
|
146 | - array $dependencies = array(), |
|
147 | - $media = 'all' |
|
148 | - ) { |
|
149 | - $asset = new StylesheetAsset( |
|
150 | - $handle, |
|
151 | - $source, |
|
152 | - $dependencies, |
|
153 | - $this->domain, |
|
154 | - $media |
|
155 | - ); |
|
156 | - $this->assets->add($asset, $handle); |
|
157 | - return $asset; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return StylesheetAsset[] |
|
163 | - * @since $VID:$ |
|
164 | - */ |
|
165 | - public function getStylesheetAssets() |
|
166 | - { |
|
167 | - return $this->assets->getStylesheetAssets(); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return void |
|
173 | - * @since $VID:$ |
|
174 | - */ |
|
175 | - public function enqueueJsAsset($handle) |
|
176 | - { |
|
177 | - if($this->assets->has($handle)){ |
|
178 | - /** @var JavascriptAsset $script */ |
|
179 | - $script = $this->assets->get($handle); |
|
180 | - if ($script->isRegistered()){ |
|
181 | - wp_enqueue_script($handle); |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @return void |
|
189 | - * @since $VID:$ |
|
190 | - */ |
|
191 | - public function enqueueCssSAsset($handle) |
|
192 | - { |
|
193 | - if ($this->assets->has($handle)) { |
|
194 | - /** @var StylesheetAsset $script */ |
|
195 | - $stylesheet = $this->assets->get($handle); |
|
196 | - if ($stylesheet->isRegistered()) { |
|
197 | - wp_enqueue_style($handle); |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
24 | + /** |
|
25 | + * @var AssetCollection $assets |
|
26 | + */ |
|
27 | + protected $assets; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var DomainInterface |
|
31 | + */ |
|
32 | + protected $domain; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Registry $registry |
|
36 | + */ |
|
37 | + protected $registry; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * AssetRegister constructor. |
|
42 | + * |
|
43 | + * @param DomainInterface $domain |
|
44 | + * @param AssetCollection $assets |
|
45 | + * @param Registry $registry |
|
46 | + */ |
|
47 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | + { |
|
49 | + $this->domain = $domain; |
|
50 | + $this->assets = $assets; |
|
51 | + $this->registry = $registry; |
|
52 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @since $VID:$ |
|
61 | + */ |
|
62 | + abstract public function addAssets(); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @return void |
|
67 | + * @throws DuplicateCollectionIdentifierException |
|
68 | + * @throws InvalidDataTypeException |
|
69 | + * @throws InvalidEntityException |
|
70 | + * @since $VID:$ |
|
71 | + */ |
|
72 | + public function addManifestFile() |
|
73 | + { |
|
74 | + // if a manifest file has already been added for this domain, then just return that one |
|
75 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
76 | + return; |
|
77 | + } |
|
78 | + $asset = new ManifestFile($this->domain); |
|
79 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return ManifestFile[] |
|
85 | + * @since $VID:$ |
|
86 | + */ |
|
87 | + public function getManifestFile() |
|
88 | + { |
|
89 | + return $this->assets->getManifestFiles(); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param string $handle |
|
95 | + * @param string $source |
|
96 | + * @param array $dependencies |
|
97 | + * @param bool $load_in_footer |
|
98 | + * @return JavascriptAsset |
|
99 | + * @throws DuplicateCollectionIdentifierException |
|
100 | + * @throws InvalidDataTypeException |
|
101 | + * @throws InvalidEntityException |
|
102 | + * @since $VID:$ |
|
103 | + */ |
|
104 | + public function addJavascript( |
|
105 | + $handle, |
|
106 | + $source, |
|
107 | + array $dependencies = array(), |
|
108 | + $load_in_footer = true |
|
109 | + ) { |
|
110 | + $asset = new JavascriptAsset( |
|
111 | + $handle, |
|
112 | + $source, |
|
113 | + $dependencies, |
|
114 | + $load_in_footer, |
|
115 | + $this->domain |
|
116 | + ); |
|
117 | + $this->assets->add($asset, $handle); |
|
118 | + return $asset; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return JavascriptAsset[] |
|
124 | + * @since $VID:$ |
|
125 | + */ |
|
126 | + public function getJavascriptAssets() |
|
127 | + { |
|
128 | + return $this->assets->getJavascriptAssets(); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $handle |
|
134 | + * @param string $source |
|
135 | + * @param array $dependencies |
|
136 | + * @param string $media |
|
137 | + * @return StylesheetAsset |
|
138 | + * @throws DuplicateCollectionIdentifierException |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidEntityException |
|
141 | + * @since $VID:$ |
|
142 | + */ |
|
143 | + public function addStylesheet( |
|
144 | + $handle, |
|
145 | + $source, |
|
146 | + array $dependencies = array(), |
|
147 | + $media = 'all' |
|
148 | + ) { |
|
149 | + $asset = new StylesheetAsset( |
|
150 | + $handle, |
|
151 | + $source, |
|
152 | + $dependencies, |
|
153 | + $this->domain, |
|
154 | + $media |
|
155 | + ); |
|
156 | + $this->assets->add($asset, $handle); |
|
157 | + return $asset; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return StylesheetAsset[] |
|
163 | + * @since $VID:$ |
|
164 | + */ |
|
165 | + public function getStylesheetAssets() |
|
166 | + { |
|
167 | + return $this->assets->getStylesheetAssets(); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return void |
|
173 | + * @since $VID:$ |
|
174 | + */ |
|
175 | + public function enqueueJsAsset($handle) |
|
176 | + { |
|
177 | + if($this->assets->has($handle)){ |
|
178 | + /** @var JavascriptAsset $script */ |
|
179 | + $script = $this->assets->get($handle); |
|
180 | + if ($script->isRegistered()){ |
|
181 | + wp_enqueue_script($handle); |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @return void |
|
189 | + * @since $VID:$ |
|
190 | + */ |
|
191 | + public function enqueueCssSAsset($handle) |
|
192 | + { |
|
193 | + if ($this->assets->has($handle)) { |
|
194 | + /** @var StylesheetAsset $script */ |
|
195 | + $stylesheet = $this->assets->get($handle); |
|
196 | + if ($stylesheet->isRegistered()) { |
|
197 | + wp_enqueue_style($handle); |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -174,10 +174,10 @@ |
||
174 | 174 | */ |
175 | 175 | public function enqueueJsAsset($handle) |
176 | 176 | { |
177 | - if($this->assets->has($handle)){ |
|
177 | + if ($this->assets->has($handle)) { |
|
178 | 178 | /** @var JavascriptAsset $script */ |
179 | 179 | $script = $this->assets->get($handle); |
180 | - if ($script->isRegistered()){ |
|
180 | + if ($script->isRegistered()) { |
|
181 | 181 | wp_enqueue_script($handle); |
182 | 182 | } |
183 | 183 | } |
@@ -17,142 +17,142 @@ |
||
17 | 17 | class JavascriptAsset extends BrowserAsset |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var boolean $load_in_footer |
|
22 | - */ |
|
23 | - private $load_in_footer = false; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var boolean $requires_translation |
|
27 | - */ |
|
28 | - private $requires_translation = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var boolean $has_localized_data |
|
32 | - */ |
|
33 | - private $has_localized_data = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Closure $localization_callback |
|
37 | - */ |
|
38 | - private $localization_callback; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Asset constructor. |
|
43 | - * |
|
44 | - * @param string $handle |
|
45 | - * @param string $source |
|
46 | - * @param array $dependencies |
|
47 | - * @param bool $load_in_footer |
|
48 | - * @param DomainInterface $domain |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - $handle, |
|
53 | - $source, |
|
54 | - array $dependencies, |
|
55 | - $load_in_footer, |
|
56 | - DomainInterface $domain |
|
57 | - ) { |
|
58 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
59 | - $this->setLoadInFooter($load_in_footer); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function loadInFooter() |
|
67 | - { |
|
68 | - return $this->load_in_footer; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param bool $load_in_footer |
|
74 | - */ |
|
75 | - private function setLoadInFooter($load_in_footer = true) |
|
76 | - { |
|
77 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function requiresTranslation() |
|
85 | - { |
|
86 | - return $this->requires_translation; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param bool $requires_translation |
|
92 | - * @return JavascriptAsset |
|
93 | - */ |
|
94 | - public function setRequiresTranslation($requires_translation = true) |
|
95 | - { |
|
96 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function hasLocalizedData() |
|
105 | - { |
|
106 | - return $this->has_localized_data; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @param bool $has_localized_data |
|
112 | - * @return JavascriptAsset |
|
113 | - */ |
|
114 | - public function setHasLocalizedData($has_localized_data = true) |
|
115 | - { |
|
116 | - $this->has_localized_data = filter_var($has_localized_data, FILTER_VALIDATE_BOOLEAN); |
|
117 | - return $this; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return Closure |
|
123 | - */ |
|
124 | - public function localizationCallback() |
|
125 | - { |
|
126 | - return $this->localization_callback; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function hasLocalizationCallback() |
|
134 | - { |
|
135 | - return $this->localization_callback instanceof Closure; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param Closure $localization_callback |
|
141 | - * @return JavascriptAsset |
|
142 | - */ |
|
143 | - public function setLocalizationCallback(Closure $localization_callback) |
|
144 | - { |
|
145 | - $this->localization_callback = $localization_callback; |
|
146 | - $this->setHasLocalizedData(); |
|
147 | - return $this; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @since $VID:$ |
|
153 | - */ |
|
154 | - public function enqueueAsset() |
|
155 | - { |
|
156 | - wp_enqueue_script($this->handle()); |
|
157 | - } |
|
20 | + /** |
|
21 | + * @var boolean $load_in_footer |
|
22 | + */ |
|
23 | + private $load_in_footer = false; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var boolean $requires_translation |
|
27 | + */ |
|
28 | + private $requires_translation = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var boolean $has_localized_data |
|
32 | + */ |
|
33 | + private $has_localized_data = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Closure $localization_callback |
|
37 | + */ |
|
38 | + private $localization_callback; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Asset constructor. |
|
43 | + * |
|
44 | + * @param string $handle |
|
45 | + * @param string $source |
|
46 | + * @param array $dependencies |
|
47 | + * @param bool $load_in_footer |
|
48 | + * @param DomainInterface $domain |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + $handle, |
|
53 | + $source, |
|
54 | + array $dependencies, |
|
55 | + $load_in_footer, |
|
56 | + DomainInterface $domain |
|
57 | + ) { |
|
58 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
59 | + $this->setLoadInFooter($load_in_footer); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function loadInFooter() |
|
67 | + { |
|
68 | + return $this->load_in_footer; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param bool $load_in_footer |
|
74 | + */ |
|
75 | + private function setLoadInFooter($load_in_footer = true) |
|
76 | + { |
|
77 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function requiresTranslation() |
|
85 | + { |
|
86 | + return $this->requires_translation; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param bool $requires_translation |
|
92 | + * @return JavascriptAsset |
|
93 | + */ |
|
94 | + public function setRequiresTranslation($requires_translation = true) |
|
95 | + { |
|
96 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function hasLocalizedData() |
|
105 | + { |
|
106 | + return $this->has_localized_data; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @param bool $has_localized_data |
|
112 | + * @return JavascriptAsset |
|
113 | + */ |
|
114 | + public function setHasLocalizedData($has_localized_data = true) |
|
115 | + { |
|
116 | + $this->has_localized_data = filter_var($has_localized_data, FILTER_VALIDATE_BOOLEAN); |
|
117 | + return $this; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return Closure |
|
123 | + */ |
|
124 | + public function localizationCallback() |
|
125 | + { |
|
126 | + return $this->localization_callback; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function hasLocalizationCallback() |
|
134 | + { |
|
135 | + return $this->localization_callback instanceof Closure; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param Closure $localization_callback |
|
141 | + * @return JavascriptAsset |
|
142 | + */ |
|
143 | + public function setLocalizationCallback(Closure $localization_callback) |
|
144 | + { |
|
145 | + $this->localization_callback = $localization_callback; |
|
146 | + $this->setHasLocalizedData(); |
|
147 | + return $this; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @since $VID:$ |
|
153 | + */ |
|
154 | + public function enqueueAsset() |
|
155 | + { |
|
156 | + wp_enqueue_script($this->handle()); |
|
157 | + } |
|
158 | 158 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.041'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.041'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -17,17 +17,17 @@ |
||
17 | 17 | */ |
18 | 18 | class CoreBlocksAssetManager extends BlockAssetManager |
19 | 19 | { |
20 | - const JS_HANDLE_CORE_BLOCKS = 'core-blocks'; |
|
21 | - const CSS_HANDLE_CORE_BLOCKS = 'core-blocks'; |
|
20 | + const JS_HANDLE_CORE_BLOCKS = 'core-blocks'; |
|
21 | + const CSS_HANDLE_CORE_BLOCKS = 'core-blocks'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @since $VID:$ |
|
25 | - */ |
|
26 | - public function setAssetHandles() |
|
27 | - { |
|
28 | - $this->setEditorScriptHandle(self::JS_HANDLE_CORE_BLOCKS); |
|
29 | - $this->setEditorStyleHandle(self::CSS_HANDLE_CORE_BLOCKS); |
|
30 | - $this->setScriptHandle(self::JS_HANDLE_CORE_BLOCKS); |
|
31 | - $this->setStyleHandle(self::CSS_HANDLE_CORE_BLOCKS); |
|
32 | - } |
|
23 | + /** |
|
24 | + * @since $VID:$ |
|
25 | + */ |
|
26 | + public function setAssetHandles() |
|
27 | + { |
|
28 | + $this->setEditorScriptHandle(self::JS_HANDLE_CORE_BLOCKS); |
|
29 | + $this->setEditorStyleHandle(self::CSS_HANDLE_CORE_BLOCKS); |
|
30 | + $this->setScriptHandle(self::JS_HANDLE_CORE_BLOCKS); |
|
31 | + $this->setStyleHandle(self::CSS_HANDLE_CORE_BLOCKS); |
|
32 | + } |
|
33 | 33 | } |
@@ -13,36 +13,36 @@ |
||
13 | 13 | interface BlockAssetManagerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @since $VID:$ |
|
18 | - * @return void |
|
19 | - */ |
|
20 | - public function setAssetHandles(); |
|
21 | - |
|
22 | - /** |
|
23 | - * @since $VID:$ |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getEditorScriptHandle(); |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @since $VID:$ |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function getEditorStyleHandle(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @since $VID:$ |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function getScriptHandle(); |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @since $VID:$ |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getStyleHandle(); |
|
16 | + /** |
|
17 | + * @since $VID:$ |
|
18 | + * @return void |
|
19 | + */ |
|
20 | + public function setAssetHandles(); |
|
21 | + |
|
22 | + /** |
|
23 | + * @since $VID:$ |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getEditorScriptHandle(); |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @since $VID:$ |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function getEditorStyleHandle(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @since $VID:$ |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function getScriptHandle(); |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @since $VID:$ |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getStyleHandle(); |
|
48 | 48 | } |
49 | 49 | \ No newline at end of file |
@@ -16,41 +16,41 @@ |
||
16 | 16 | class BlockAssetManagerCollection extends Collection |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Collection constructor |
|
21 | - * |
|
22 | - * @throws InvalidInterfaceException |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - parent::__construct('EventEspresso\core\services\assets\BlockAssetManager'); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @return void |
|
32 | - */ |
|
33 | - public function addAssets() |
|
34 | - { |
|
35 | - $this->rewind(); |
|
36 | - while ($this->valid()) { |
|
37 | - $this->current()->addAssets(); |
|
38 | - $this->next(); |
|
39 | - } |
|
40 | - $this->rewind(); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public function enqueueAssets() |
|
48 | - { |
|
49 | - $this->rewind(); |
|
50 | - while ($this->valid()) { |
|
51 | - $this->current()->enqueueAssets(); |
|
52 | - $this->next(); |
|
53 | - } |
|
54 | - $this->rewind(); |
|
55 | - } |
|
19 | + /** |
|
20 | + * Collection constructor |
|
21 | + * |
|
22 | + * @throws InvalidInterfaceException |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + parent::__construct('EventEspresso\core\services\assets\BlockAssetManager'); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @return void |
|
32 | + */ |
|
33 | + public function addAssets() |
|
34 | + { |
|
35 | + $this->rewind(); |
|
36 | + while ($this->valid()) { |
|
37 | + $this->current()->addAssets(); |
|
38 | + $this->next(); |
|
39 | + } |
|
40 | + $this->rewind(); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public function enqueueAssets() |
|
48 | + { |
|
49 | + $this->rewind(); |
|
50 | + while ($this->valid()) { |
|
51 | + $this->current()->enqueueAssets(); |
|
52 | + $this->next(); |
|
53 | + } |
|
54 | + $this->rewind(); |
|
55 | + } |
|
56 | 56 | } |