@@ -72,13 +72,13 @@ |
||
72 | 72 | private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
73 | 73 | { |
74 | 74 | $domain_fqcn = get_class($domain); |
75 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
75 | + if ( ! isset(BaristaFactory::$baristas[$domain_fqcn])) { |
|
76 | 76 | $barista = new Barista($asset_manifest); |
77 | 77 | // we still need to share this with the core loader to facilitate automatic dependency injection |
78 | 78 | $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
79 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
79 | + BaristaFactory::$baristas[$domain_fqcn] = $barista; |
|
80 | 80 | } |
81 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
81 | + return BaristaFactory::$baristas[$domain_fqcn]; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 |
@@ -11,114 +11,114 @@ |
||
11 | 11 | |
12 | 12 | class BaristaFactory implements FactoryInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * @var AssetManifestFactory |
|
16 | - */ |
|
17 | - private $manifest_factory; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var BaristaInterface[] |
|
21 | - */ |
|
22 | - private static $baristas = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var LoaderInterface $loader |
|
26 | - */ |
|
27 | - protected $loader; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * BaristaFactory constructor. |
|
32 | - * |
|
33 | - * @param AssetManifestFactory $manifest_factory |
|
34 | - * @param LoaderInterface $loader |
|
35 | - */ |
|
36 | - public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | - { |
|
38 | - $this->manifest_factory = $manifest_factory; |
|
39 | - $this->loader = $loader; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $domain_fqcn |
|
45 | - * @return BaristaInterface |
|
46 | - */ |
|
47 | - public function createFromDomainClass($domain_fqcn) |
|
48 | - { |
|
49 | - /** @var DomainInterface $domain */ |
|
50 | - $domain = $this->loader->getShared($domain_fqcn); |
|
51 | - return $this->createFromDomainObject($domain); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param DomainInterface $domain |
|
57 | - * @return BaristaInterface |
|
58 | - */ |
|
59 | - public function createFromDomainObject(DomainInterface $domain) |
|
60 | - { |
|
61 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
62 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
68 | - * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
69 | - * @return BaristaInterface |
|
70 | - */ |
|
71 | - public function create($domain_fqcn = '', array $domain_arguments = []) |
|
72 | - { |
|
73 | - $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
74 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
75 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param AssetManifestInterface $asset_manifest |
|
81 | - * @param DomainInterface $domain |
|
82 | - * @return BaristaInterface |
|
83 | - */ |
|
84 | - private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
85 | - { |
|
86 | - $domain_fqcn = get_class($domain); |
|
87 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
88 | - $barista = new Barista($asset_manifest); |
|
89 | - // we still need to share this with the core loader to facilitate automatic dependency injection |
|
90 | - $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
91 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
92 | - } |
|
93 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
99 | - * @param array $arguments |
|
100 | - * @return DomainInterface |
|
101 | - */ |
|
102 | - private function getDomain($domain_fqcn, array $arguments = []) |
|
103 | - { |
|
104 | - // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
105 | - // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
106 | - $domain = empty($domain_fqcn) |
|
107 | - ? DomainFactory::getEventEspressoCoreDomain() |
|
108 | - : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
109 | - if ($domain instanceof DomainInterface) { |
|
110 | - return $domain; |
|
111 | - } |
|
112 | - throw new DomainException( |
|
113 | - sprintf( |
|
114 | - esc_html__( |
|
115 | - 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
14 | + /** |
|
15 | + * @var AssetManifestFactory |
|
16 | + */ |
|
17 | + private $manifest_factory; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var BaristaInterface[] |
|
21 | + */ |
|
22 | + private static $baristas = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var LoaderInterface $loader |
|
26 | + */ |
|
27 | + protected $loader; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * BaristaFactory constructor. |
|
32 | + * |
|
33 | + * @param AssetManifestFactory $manifest_factory |
|
34 | + * @param LoaderInterface $loader |
|
35 | + */ |
|
36 | + public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | + { |
|
38 | + $this->manifest_factory = $manifest_factory; |
|
39 | + $this->loader = $loader; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $domain_fqcn |
|
45 | + * @return BaristaInterface |
|
46 | + */ |
|
47 | + public function createFromDomainClass($domain_fqcn) |
|
48 | + { |
|
49 | + /** @var DomainInterface $domain */ |
|
50 | + $domain = $this->loader->getShared($domain_fqcn); |
|
51 | + return $this->createFromDomainObject($domain); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param DomainInterface $domain |
|
57 | + * @return BaristaInterface |
|
58 | + */ |
|
59 | + public function createFromDomainObject(DomainInterface $domain) |
|
60 | + { |
|
61 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
62 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
68 | + * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
69 | + * @return BaristaInterface |
|
70 | + */ |
|
71 | + public function create($domain_fqcn = '', array $domain_arguments = []) |
|
72 | + { |
|
73 | + $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
74 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
75 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param AssetManifestInterface $asset_manifest |
|
81 | + * @param DomainInterface $domain |
|
82 | + * @return BaristaInterface |
|
83 | + */ |
|
84 | + private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
85 | + { |
|
86 | + $domain_fqcn = get_class($domain); |
|
87 | + if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
88 | + $barista = new Barista($asset_manifest); |
|
89 | + // we still need to share this with the core loader to facilitate automatic dependency injection |
|
90 | + $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
91 | + BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
92 | + } |
|
93 | + return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
99 | + * @param array $arguments |
|
100 | + * @return DomainInterface |
|
101 | + */ |
|
102 | + private function getDomain($domain_fqcn, array $arguments = []) |
|
103 | + { |
|
104 | + // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
105 | + // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
106 | + $domain = empty($domain_fqcn) |
|
107 | + ? DomainFactory::getEventEspressoCoreDomain() |
|
108 | + : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
109 | + if ($domain instanceof DomainInterface) { |
|
110 | + return $domain; |
|
111 | + } |
|
112 | + throw new DomainException( |
|
113 | + sprintf( |
|
114 | + esc_html__( |
|
115 | + 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
116 | 116 | %1$sThe supplied FQCN ("%2$s") is either invalid or the class is missing.', |
117 | - 'event_espresso' |
|
118 | - ), |
|
119 | - '<br />', |
|
120 | - $domain_fqcn |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
117 | + 'event_espresso' |
|
118 | + ), |
|
119 | + '<br />', |
|
120 | + $domain_fqcn |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | 124 | } |
@@ -15,676 +15,676 @@ |
||
15 | 15 | class EEH_Event_Query |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Start Date |
|
20 | - * |
|
21 | - * @var $_event_query_month |
|
22 | - */ |
|
23 | - protected static $_event_query_month; |
|
24 | - |
|
25 | - /** |
|
26 | - * Category |
|
27 | - * |
|
28 | - * @var $_event_query_category |
|
29 | - */ |
|
30 | - protected static $_event_query_category; |
|
31 | - |
|
32 | - /** |
|
33 | - * whether to display expired events in the event list |
|
34 | - * |
|
35 | - * @var bool $_show_expired |
|
36 | - */ |
|
37 | - protected static $_event_query_show_expired = false; |
|
38 | - |
|
39 | - /** |
|
40 | - * list of params for controlling how the query results are ordered |
|
41 | - * |
|
42 | - * @var array $_event_query_orderby |
|
43 | - */ |
|
44 | - protected static $_event_query_orderby = array(); |
|
45 | - |
|
46 | - /** |
|
47 | - * direction list is sorted |
|
48 | - * |
|
49 | - * @var string $_event_query_sort |
|
50 | - */ |
|
51 | - protected static $_event_query_sort; |
|
52 | - |
|
53 | - /** |
|
54 | - * list of params used to build the query's various clauses |
|
55 | - * |
|
56 | - * @var $_query_params |
|
57 | - */ |
|
58 | - protected static $_query_params = array(); |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public static function add_query_filters() |
|
66 | - { |
|
67 | - // add query filters |
|
68 | - add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param WP_Query $WP_Query |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public static function apply_query_filters(WP_Query $WP_Query) |
|
78 | - { |
|
79 | - return ( |
|
80 | - isset($WP_Query->query['post_type']) |
|
81 | - && $WP_Query->query['post_type'] === 'espresso_events' |
|
82 | - ) |
|
83 | - || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param WP_Query $WP_Query |
|
89 | - */ |
|
90 | - public static function filter_query_parts(WP_Query $WP_Query) |
|
91 | - { |
|
92 | - // ONLY add our filters if this isn't the main wp_query, |
|
93 | - // because if this is the main wp_query we already have |
|
94 | - // our cpt strategies take care of adding things in. |
|
95 | - if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
96 | - // build event list query |
|
97 | - add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
98 | - add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
99 | - add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
100 | - add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
101 | - add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $month |
|
109 | - * @param string $category |
|
110 | - * @param bool $show_expired |
|
111 | - * @param string $orderby |
|
112 | - * @param string $sort |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - public static function set_query_params( |
|
118 | - $month = '', |
|
119 | - $category = '', |
|
120 | - $show_expired = false, |
|
121 | - $orderby = 'start_date', |
|
122 | - $sort = 'ASC' |
|
123 | - ) { |
|
124 | - self::$_query_params = array(); |
|
125 | - EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
126 | - EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
127 | - EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
128 | - EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
129 | - EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * what month should the event list display events for? |
|
136 | - * |
|
137 | - * @param string $month |
|
138 | - * @return string |
|
139 | - * @throws InvalidArgumentException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - private static function _display_month($month = '') |
|
144 | - { |
|
145 | - return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param string $category |
|
152 | - * @return string |
|
153 | - * @throws InvalidArgumentException |
|
154 | - * @throws InvalidDataTypeException |
|
155 | - * @throws InvalidInterfaceException |
|
156 | - */ |
|
157 | - private static function _event_category_slug($category = '') |
|
158 | - { |
|
159 | - return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * @param bool $show_expired |
|
166 | - * @return bool |
|
167 | - * @throws InvalidArgumentException |
|
168 | - * @throws InvalidDataTypeException |
|
169 | - * @throws InvalidInterfaceException |
|
170 | - */ |
|
171 | - private static function _show_expired($show_expired = false) |
|
172 | - { |
|
173 | - // override default expired option if set via filter |
|
174 | - return filter_var( |
|
175 | - EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
176 | - FILTER_VALIDATE_BOOLEAN |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param string $orderby |
|
184 | - * @return array |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - private static function _orderby($orderby = 'start_date') |
|
190 | - { |
|
191 | - $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
|
192 | - $event_query_orderby = is_array($event_query_orderby) |
|
193 | - ? $event_query_orderby |
|
194 | - : explode(',', $event_query_orderby); |
|
195 | - $event_query_orderby = array_map('trim', $event_query_orderby); |
|
196 | - $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
197 | - return $event_query_orderby; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param string $sort |
|
204 | - * @return string |
|
205 | - * @throws InvalidArgumentException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - * @throws InvalidInterfaceException |
|
208 | - */ |
|
209 | - private static function _sort($sort = 'ASC') |
|
210 | - { |
|
211 | - $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
|
212 | - return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
213 | - ? strtoupper($sort) |
|
214 | - : 'ASC'; |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * Filters the clauses for the WP_Query object |
|
221 | - * |
|
222 | - * @param array $clauses array of clauses |
|
223 | - * @param WP_Query $wp_query |
|
224 | - * @return array array of clauses |
|
225 | - */ |
|
226 | - public static function posts_clauses($clauses, WP_Query $wp_query) |
|
227 | - { |
|
228 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
229 | - global $wpdb; |
|
230 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
231 | - } |
|
232 | - return $clauses; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string $SQL |
|
239 | - * @param WP_Query $wp_query |
|
240 | - * @return string |
|
241 | - * @throws EE_Error |
|
242 | - * @throws InvalidArgumentException |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - * @throws InvalidInterfaceException |
|
245 | - */ |
|
246 | - public static function posts_fields($SQL, WP_Query $wp_query) |
|
247 | - { |
|
248 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
249 | - // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
250 | - $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
251 | - } |
|
252 | - return $SQL; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param array $orderby_params |
|
259 | - * @return string |
|
260 | - * @throws EE_Error |
|
261 | - * @throws InvalidArgumentException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws InvalidInterfaceException |
|
264 | - */ |
|
265 | - public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
|
266 | - { |
|
267 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
268 | - foreach ($orderby_params as $orderby) { |
|
269 | - switch ($orderby) { |
|
270 | - case 'ticket_start': |
|
271 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
272 | - break; |
|
273 | - case 'ticket_end': |
|
274 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
275 | - break; |
|
276 | - case 'venue_title': |
|
277 | - $SQL .= ', Venue.post_title AS venue_title'; |
|
278 | - break; |
|
279 | - case 'city': |
|
280 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
281 | - break; |
|
282 | - case 'state': |
|
283 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
284 | - break; |
|
285 | - } |
|
286 | - } |
|
287 | - return $SQL; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * @param string $SQL |
|
294 | - * @param WP_Query $wp_query |
|
295 | - * @return string |
|
296 | - * @throws EE_Error |
|
297 | - * @throws InvalidArgumentException |
|
298 | - * @throws InvalidDataTypeException |
|
299 | - * @throws InvalidInterfaceException |
|
300 | - */ |
|
301 | - public static function posts_join($SQL = '', WP_Query $wp_query) |
|
302 | - { |
|
303 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
304 | - // Category |
|
305 | - $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
306 | - $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
307 | - $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
308 | - } |
|
309 | - return $SQL; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $SQL |
|
316 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
317 | - * @return string |
|
318 | - * @throws EE_Error |
|
319 | - * @throws InvalidArgumentException |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - * @throws InvalidInterfaceException |
|
322 | - */ |
|
323 | - public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
|
324 | - { |
|
325 | - if (! $show_expired) { |
|
326 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
328 | - // don't add if this is already in the SQL |
|
329 | - if (strpos($SQL, $join) === false) { |
|
330 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
331 | - } |
|
332 | - } |
|
333 | - return $SQL; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * @param string $SQL |
|
340 | - * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get |
|
341 | - * used for anything yet |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
|
345 | - { |
|
346 | - if (! empty($join_terms)) { |
|
347 | - global $wpdb; |
|
348 | - $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
|
349 | - $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
|
350 | - $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) "; |
|
351 | - } |
|
352 | - return $SQL; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
359 | - * |
|
360 | - * @param string $SQL |
|
361 | - * @param array $orderby_params |
|
362 | - * @return string |
|
363 | - * @throws EE_Error |
|
364 | - * @throws InvalidArgumentException |
|
365 | - * @throws InvalidDataTypeException |
|
366 | - * @throws InvalidInterfaceException |
|
367 | - */ |
|
368 | - public static function posts_join_for_orderby($SQL = '', array $orderby_params = array()) |
|
369 | - { |
|
370 | - foreach ($orderby_params as $orderby) { |
|
371 | - switch ($orderby) { |
|
372 | - case 'ticket_start': |
|
373 | - case 'ticket_end': |
|
374 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
|
375 | - $SQL, |
|
376 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
377 | - ); |
|
378 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
379 | - $SQL .= ' ON ('; |
|
380 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
381 | - $SQL .= ' = '; |
|
382 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
383 | - $SQL .= ' )'; |
|
384 | - break; |
|
385 | - case 'venue_title': |
|
386 | - case 'city': |
|
387 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
388 | - break; |
|
389 | - case 'state': |
|
390 | - $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
391 | - $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
392 | - break; |
|
393 | - case 'start_date': |
|
394 | - default: |
|
395 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
396 | - break; |
|
397 | - } |
|
398 | - } |
|
399 | - return $SQL; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * @param string $SQL |
|
406 | - * @param string $join |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - * @throws InvalidArgumentException |
|
410 | - * @throws InvalidDataTypeException |
|
411 | - * @throws InvalidInterfaceException |
|
412 | - */ |
|
413 | - protected static function _posts_join_for_datetime($SQL = '', $join = '') |
|
414 | - { |
|
415 | - if (! empty($join)) { |
|
416 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
417 | - if (strpos($SQL, $join) === false) { |
|
418 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
419 | - } |
|
420 | - } |
|
421 | - return ''; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * @param string $SQL |
|
428 | - * @return string |
|
429 | - * @throws EE_Error |
|
430 | - * @throws InvalidArgumentException |
|
431 | - * @throws InvalidDataTypeException |
|
432 | - * @throws InvalidInterfaceException |
|
433 | - */ |
|
434 | - protected static function _posts_join_for_event_venue($SQL = '') |
|
435 | - { |
|
436 | - // Event Venue table name |
|
437 | - $event_venue_table = EEM_Event_Venue::instance()->table(); |
|
438 | - // generate conditions for: Event <=> Event Venue JOIN clause |
|
439 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
441 | - // don't add joins if they have already been added |
|
442 | - if (strpos($SQL, $event_to_event_venue_join) === false) { |
|
443 | - // Venue table name |
|
444 | - $venue_table = EEM_Venue::instance()->table(); |
|
445 | - // Venue table pk |
|
446 | - $venue_table_pk = EEM_Venue::instance()->primary_key_name(); |
|
447 | - // Venue Meta table name |
|
448 | - $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
449 | - // generate JOIN clause for: Event <=> Event Venue |
|
450 | - $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )"; |
|
451 | - // generate JOIN clause for: Event Venue <=> Venue |
|
452 | - $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
|
453 | - // generate JOIN clause for: Venue <=> Venue Meta |
|
454 | - $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
|
455 | - unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
456 | - return $venue_SQL; |
|
457 | - } |
|
458 | - unset($event_venue_table, $event_to_event_venue_join); |
|
459 | - return ''; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * @param string $SQL |
|
466 | - * @return string |
|
467 | - * @throws EE_Error |
|
468 | - * @throws InvalidArgumentException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws InvalidInterfaceException |
|
471 | - */ |
|
472 | - protected static function _posts_join_for_venue_state($SQL = '') |
|
473 | - { |
|
474 | - // Venue Meta table name |
|
475 | - $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
476 | - // State table name |
|
477 | - $state_table = EEM_State::instance()->table(); |
|
478 | - // State table pk |
|
479 | - $state_table_pk = EEM_State::instance()->primary_key_name(); |
|
480 | - // verify vars |
|
481 | - if ($venue_meta_table && $state_table && $state_table_pk) { |
|
482 | - // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
|
483 | - $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
|
484 | - // don't add join if it has already been added |
|
485 | - if (strpos($SQL, $join) === false) { |
|
486 | - unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
487 | - return " LEFT JOIN $state_table ON ( $join )"; |
|
488 | - } |
|
489 | - } |
|
490 | - unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
491 | - return ''; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * @param string $SQL |
|
498 | - * @param WP_Query $wp_query |
|
499 | - * @return string |
|
500 | - * @throws EE_Error |
|
501 | - * @throws InvalidArgumentException |
|
502 | - * @throws InvalidDataTypeException |
|
503 | - * @throws InvalidInterfaceException |
|
504 | - */ |
|
505 | - public static function posts_where($SQL = '', WP_Query $wp_query) |
|
506 | - { |
|
507 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
508 | - // Show Expired ? |
|
509 | - $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
510 | - // Category |
|
511 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
512 | - // Start Date |
|
513 | - $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
514 | - } |
|
515 | - return $SQL; |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param boolean $show_expired if TRUE, then displayed past events |
|
522 | - * @return string |
|
523 | - * @throws EE_Error |
|
524 | - * @throws InvalidArgumentException |
|
525 | - * @throws InvalidDataTypeException |
|
526 | - * @throws InvalidInterfaceException |
|
527 | - */ |
|
528 | - public static function posts_where_sql_for_show_expired($show_expired = false) |
|
529 | - { |
|
530 | - return ! $show_expired |
|
531 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
532 | - : ''; |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @param boolean $event_category_slug |
|
539 | - * @return string |
|
540 | - */ |
|
541 | - public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
542 | - { |
|
543 | - global $wpdb; |
|
544 | - if (! empty($event_category_slug)) { |
|
545 | - $event_category_slugs_array = array_map('trim', explode(',', $event_category_slug)); |
|
546 | - $event_category_slugs_prepare = implode(', ', array_fill(0, count($event_category_slugs_array), '%s')); |
|
547 | - return $wpdb->prepare(" AND {$wpdb->terms}.slug IN ({$event_category_slugs_prepare}) ", $event_category_slugs_array); |
|
548 | - } |
|
549 | - return ''; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * @param boolean $month |
|
556 | - * @return string |
|
557 | - * @throws EE_Error |
|
558 | - * @throws InvalidArgumentException |
|
559 | - * @throws InvalidDataTypeException |
|
560 | - * @throws InvalidInterfaceException |
|
561 | - */ |
|
562 | - public static function posts_where_sql_for_event_list_month($month = null) |
|
563 | - { |
|
564 | - $SQL = ''; |
|
565 | - if (! empty($month)) { |
|
566 | - $datetime_table = EEM_Datetime::instance()->table(); |
|
567 | - // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
|
568 | - $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
|
569 | - $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
570 | - // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
|
571 | - $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
|
572 | - $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
573 | - } |
|
574 | - return $SQL; |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * @param string $SQL |
|
581 | - * @param WP_Query $wp_query |
|
582 | - * @return string |
|
583 | - * @throws EE_Error |
|
584 | - * @throws InvalidArgumentException |
|
585 | - * @throws InvalidDataTypeException |
|
586 | - * @throws InvalidInterfaceException |
|
587 | - */ |
|
588 | - public static function posts_orderby($SQL = '', WP_Query $wp_query) |
|
589 | - { |
|
590 | - if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
591 | - $SQL = EEH_Event_Query::posts_orderby_sql( |
|
592 | - EEH_Event_Query::$_event_query_orderby, |
|
593 | - EEH_Event_Query::$_event_query_sort |
|
594 | - ); |
|
595 | - } |
|
596 | - return $SQL; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * posts_orderby_sql |
|
603 | - * possible parameters: |
|
604 | - * ID |
|
605 | - * start_date |
|
606 | - * end_date |
|
607 | - * event_name |
|
608 | - * category_slug |
|
609 | - * ticket_start |
|
610 | - * ticket_end |
|
611 | - * venue_title |
|
612 | - * city |
|
613 | - * state |
|
614 | - * **IMPORTANT** |
|
615 | - * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
616 | - * or else some of the table references below will result in MySQL errors |
|
617 | - * |
|
618 | - * @param array $orderby_params |
|
619 | - * @param string $sort |
|
620 | - * @return string |
|
621 | - * @throws EE_Error |
|
622 | - * @throws InvalidArgumentException |
|
623 | - * @throws InvalidDataTypeException |
|
624 | - * @throws InvalidInterfaceException |
|
625 | - */ |
|
626 | - public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC') |
|
627 | - { |
|
628 | - global $wpdb; |
|
629 | - $SQL = ''; |
|
630 | - $counter = 0; |
|
631 | - $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
632 | - ? strtoupper($sort) |
|
633 | - : 'ASC'; |
|
634 | - // make sure 'orderby' is set in query params |
|
635 | - if (! isset(self::$_query_params['orderby'])) { |
|
636 | - self::$_query_params['orderby'] = array(); |
|
637 | - } |
|
638 | - // loop thru $orderby_params (type cast as array) |
|
639 | - foreach ($orderby_params as $orderby) { |
|
640 | - // check if we have already added this param |
|
641 | - if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
642 | - // if so then remove from the $orderby_params so that the count() method below is accurate |
|
643 | - unset($orderby_params[ $orderby ]); |
|
644 | - // then bump ahead to the next param |
|
645 | - continue; |
|
646 | - } |
|
647 | - // this will ad a comma depending on whether this is the first or last param |
|
648 | - $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
649 | - // ok what's we dealing with? |
|
650 | - switch ($orderby) { |
|
651 | - case 'id': |
|
652 | - case 'ID': |
|
653 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
654 | - break; |
|
655 | - case 'end_date': |
|
656 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
657 | - break; |
|
658 | - case 'event_name': |
|
659 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
660 | - break; |
|
661 | - case 'category_slug': |
|
662 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
663 | - break; |
|
664 | - case 'ticket_start': |
|
665 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
666 | - break; |
|
667 | - case 'ticket_end': |
|
668 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
669 | - break; |
|
670 | - case 'venue_title': |
|
671 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
672 | - break; |
|
673 | - case 'city': |
|
674 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
675 | - break; |
|
676 | - case 'state': |
|
677 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
678 | - break; |
|
679 | - case 'start_date': |
|
680 | - default: |
|
681 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
682 | - break; |
|
683 | - } |
|
684 | - // add to array of orderby params that have been added |
|
685 | - self::$_query_params['orderby'][ $orderby ] = true; |
|
686 | - $counter++; |
|
687 | - } |
|
688 | - return $SQL; |
|
689 | - } |
|
18 | + /** |
|
19 | + * Start Date |
|
20 | + * |
|
21 | + * @var $_event_query_month |
|
22 | + */ |
|
23 | + protected static $_event_query_month; |
|
24 | + |
|
25 | + /** |
|
26 | + * Category |
|
27 | + * |
|
28 | + * @var $_event_query_category |
|
29 | + */ |
|
30 | + protected static $_event_query_category; |
|
31 | + |
|
32 | + /** |
|
33 | + * whether to display expired events in the event list |
|
34 | + * |
|
35 | + * @var bool $_show_expired |
|
36 | + */ |
|
37 | + protected static $_event_query_show_expired = false; |
|
38 | + |
|
39 | + /** |
|
40 | + * list of params for controlling how the query results are ordered |
|
41 | + * |
|
42 | + * @var array $_event_query_orderby |
|
43 | + */ |
|
44 | + protected static $_event_query_orderby = array(); |
|
45 | + |
|
46 | + /** |
|
47 | + * direction list is sorted |
|
48 | + * |
|
49 | + * @var string $_event_query_sort |
|
50 | + */ |
|
51 | + protected static $_event_query_sort; |
|
52 | + |
|
53 | + /** |
|
54 | + * list of params used to build the query's various clauses |
|
55 | + * |
|
56 | + * @var $_query_params |
|
57 | + */ |
|
58 | + protected static $_query_params = array(); |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public static function add_query_filters() |
|
66 | + { |
|
67 | + // add query filters |
|
68 | + add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param WP_Query $WP_Query |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public static function apply_query_filters(WP_Query $WP_Query) |
|
78 | + { |
|
79 | + return ( |
|
80 | + isset($WP_Query->query['post_type']) |
|
81 | + && $WP_Query->query['post_type'] === 'espresso_events' |
|
82 | + ) |
|
83 | + || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param WP_Query $WP_Query |
|
89 | + */ |
|
90 | + public static function filter_query_parts(WP_Query $WP_Query) |
|
91 | + { |
|
92 | + // ONLY add our filters if this isn't the main wp_query, |
|
93 | + // because if this is the main wp_query we already have |
|
94 | + // our cpt strategies take care of adding things in. |
|
95 | + if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) { |
|
96 | + // build event list query |
|
97 | + add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2); |
|
98 | + add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2); |
|
99 | + add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2); |
|
100 | + add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2); |
|
101 | + add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $month |
|
109 | + * @param string $category |
|
110 | + * @param bool $show_expired |
|
111 | + * @param string $orderby |
|
112 | + * @param string $sort |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + public static function set_query_params( |
|
118 | + $month = '', |
|
119 | + $category = '', |
|
120 | + $show_expired = false, |
|
121 | + $orderby = 'start_date', |
|
122 | + $sort = 'ASC' |
|
123 | + ) { |
|
124 | + self::$_query_params = array(); |
|
125 | + EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month); |
|
126 | + EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category); |
|
127 | + EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired); |
|
128 | + EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby); |
|
129 | + EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * what month should the event list display events for? |
|
136 | + * |
|
137 | + * @param string $month |
|
138 | + * @return string |
|
139 | + * @throws InvalidArgumentException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + private static function _display_month($month = '') |
|
144 | + { |
|
145 | + return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month)); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param string $category |
|
152 | + * @return string |
|
153 | + * @throws InvalidArgumentException |
|
154 | + * @throws InvalidDataTypeException |
|
155 | + * @throws InvalidInterfaceException |
|
156 | + */ |
|
157 | + private static function _event_category_slug($category = '') |
|
158 | + { |
|
159 | + return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_category', $category)); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * @param bool $show_expired |
|
166 | + * @return bool |
|
167 | + * @throws InvalidArgumentException |
|
168 | + * @throws InvalidDataTypeException |
|
169 | + * @throws InvalidInterfaceException |
|
170 | + */ |
|
171 | + private static function _show_expired($show_expired = false) |
|
172 | + { |
|
173 | + // override default expired option if set via filter |
|
174 | + return filter_var( |
|
175 | + EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired), |
|
176 | + FILTER_VALIDATE_BOOLEAN |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param string $orderby |
|
184 | + * @return array |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + private static function _orderby($orderby = 'start_date') |
|
190 | + { |
|
191 | + $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby); |
|
192 | + $event_query_orderby = is_array($event_query_orderby) |
|
193 | + ? $event_query_orderby |
|
194 | + : explode(',', $event_query_orderby); |
|
195 | + $event_query_orderby = array_map('trim', $event_query_orderby); |
|
196 | + $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby); |
|
197 | + return $event_query_orderby; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param string $sort |
|
204 | + * @return string |
|
205 | + * @throws InvalidArgumentException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + * @throws InvalidInterfaceException |
|
208 | + */ |
|
209 | + private static function _sort($sort = 'ASC') |
|
210 | + { |
|
211 | + $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort); |
|
212 | + return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
213 | + ? strtoupper($sort) |
|
214 | + : 'ASC'; |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * Filters the clauses for the WP_Query object |
|
221 | + * |
|
222 | + * @param array $clauses array of clauses |
|
223 | + * @param WP_Query $wp_query |
|
224 | + * @return array array of clauses |
|
225 | + */ |
|
226 | + public static function posts_clauses($clauses, WP_Query $wp_query) |
|
227 | + { |
|
228 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
229 | + global $wpdb; |
|
230 | + $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
231 | + } |
|
232 | + return $clauses; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string $SQL |
|
239 | + * @param WP_Query $wp_query |
|
240 | + * @return string |
|
241 | + * @throws EE_Error |
|
242 | + * @throws InvalidArgumentException |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + * @throws InvalidInterfaceException |
|
245 | + */ |
|
246 | + public static function posts_fields($SQL, WP_Query $wp_query) |
|
247 | + { |
|
248 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
249 | + // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
250 | + $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby); |
|
251 | + } |
|
252 | + return $SQL; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param array $orderby_params |
|
259 | + * @return string |
|
260 | + * @throws EE_Error |
|
261 | + * @throws InvalidArgumentException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws InvalidInterfaceException |
|
264 | + */ |
|
265 | + public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
|
266 | + { |
|
267 | + $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
268 | + foreach ($orderby_params as $orderby) { |
|
269 | + switch ($orderby) { |
|
270 | + case 'ticket_start': |
|
271 | + $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
272 | + break; |
|
273 | + case 'ticket_end': |
|
274 | + $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
275 | + break; |
|
276 | + case 'venue_title': |
|
277 | + $SQL .= ', Venue.post_title AS venue_title'; |
|
278 | + break; |
|
279 | + case 'city': |
|
280 | + $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
281 | + break; |
|
282 | + case 'state': |
|
283 | + $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
284 | + break; |
|
285 | + } |
|
286 | + } |
|
287 | + return $SQL; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * @param string $SQL |
|
294 | + * @param WP_Query $wp_query |
|
295 | + * @return string |
|
296 | + * @throws EE_Error |
|
297 | + * @throws InvalidArgumentException |
|
298 | + * @throws InvalidDataTypeException |
|
299 | + * @throws InvalidInterfaceException |
|
300 | + */ |
|
301 | + public static function posts_join($SQL = '', WP_Query $wp_query) |
|
302 | + { |
|
303 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
304 | + // Category |
|
305 | + $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired); |
|
306 | + $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category); |
|
307 | + $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby); |
|
308 | + } |
|
309 | + return $SQL; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $SQL |
|
316 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
317 | + * @return string |
|
318 | + * @throws EE_Error |
|
319 | + * @throws InvalidArgumentException |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + * @throws InvalidInterfaceException |
|
322 | + */ |
|
323 | + public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
|
324 | + { |
|
325 | + if (! $show_expired) { |
|
326 | + $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | + $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
328 | + // don't add if this is already in the SQL |
|
329 | + if (strpos($SQL, $join) === false) { |
|
330 | + $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
331 | + } |
|
332 | + } |
|
333 | + return $SQL; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * @param string $SQL |
|
340 | + * @param string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get |
|
341 | + * used for anything yet |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
|
345 | + { |
|
346 | + if (! empty($join_terms)) { |
|
347 | + global $wpdb; |
|
348 | + $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
|
349 | + $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
|
350 | + $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) "; |
|
351 | + } |
|
352 | + return $SQL; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * usage: $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params ); |
|
359 | + * |
|
360 | + * @param string $SQL |
|
361 | + * @param array $orderby_params |
|
362 | + * @return string |
|
363 | + * @throws EE_Error |
|
364 | + * @throws InvalidArgumentException |
|
365 | + * @throws InvalidDataTypeException |
|
366 | + * @throws InvalidInterfaceException |
|
367 | + */ |
|
368 | + public static function posts_join_for_orderby($SQL = '', array $orderby_params = array()) |
|
369 | + { |
|
370 | + foreach ($orderby_params as $orderby) { |
|
371 | + switch ($orderby) { |
|
372 | + case 'ticket_start': |
|
373 | + case 'ticket_end': |
|
374 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
|
375 | + $SQL, |
|
376 | + EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
377 | + ); |
|
378 | + $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
379 | + $SQL .= ' ON ('; |
|
380 | + $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
381 | + $SQL .= ' = '; |
|
382 | + $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
383 | + $SQL .= ' )'; |
|
384 | + break; |
|
385 | + case 'venue_title': |
|
386 | + case 'city': |
|
387 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
388 | + break; |
|
389 | + case 'state': |
|
390 | + $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL); |
|
391 | + $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL); |
|
392 | + break; |
|
393 | + case 'start_date': |
|
394 | + default: |
|
395 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
396 | + break; |
|
397 | + } |
|
398 | + } |
|
399 | + return $SQL; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * @param string $SQL |
|
406 | + * @param string $join |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + * @throws InvalidArgumentException |
|
410 | + * @throws InvalidDataTypeException |
|
411 | + * @throws InvalidInterfaceException |
|
412 | + */ |
|
413 | + protected static function _posts_join_for_datetime($SQL = '', $join = '') |
|
414 | + { |
|
415 | + if (! empty($join)) { |
|
416 | + $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
417 | + if (strpos($SQL, $join) === false) { |
|
418 | + return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
419 | + } |
|
420 | + } |
|
421 | + return ''; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * @param string $SQL |
|
428 | + * @return string |
|
429 | + * @throws EE_Error |
|
430 | + * @throws InvalidArgumentException |
|
431 | + * @throws InvalidDataTypeException |
|
432 | + * @throws InvalidInterfaceException |
|
433 | + */ |
|
434 | + protected static function _posts_join_for_event_venue($SQL = '') |
|
435 | + { |
|
436 | + // Event Venue table name |
|
437 | + $event_venue_table = EEM_Event_Venue::instance()->table(); |
|
438 | + // generate conditions for: Event <=> Event Venue JOIN clause |
|
439 | + $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | + $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
441 | + // don't add joins if they have already been added |
|
442 | + if (strpos($SQL, $event_to_event_venue_join) === false) { |
|
443 | + // Venue table name |
|
444 | + $venue_table = EEM_Venue::instance()->table(); |
|
445 | + // Venue table pk |
|
446 | + $venue_table_pk = EEM_Venue::instance()->primary_key_name(); |
|
447 | + // Venue Meta table name |
|
448 | + $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
449 | + // generate JOIN clause for: Event <=> Event Venue |
|
450 | + $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )"; |
|
451 | + // generate JOIN clause for: Event Venue <=> Venue |
|
452 | + $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )"; |
|
453 | + // generate JOIN clause for: Venue <=> Venue Meta |
|
454 | + $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )"; |
|
455 | + unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table); |
|
456 | + return $venue_SQL; |
|
457 | + } |
|
458 | + unset($event_venue_table, $event_to_event_venue_join); |
|
459 | + return ''; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * @param string $SQL |
|
466 | + * @return string |
|
467 | + * @throws EE_Error |
|
468 | + * @throws InvalidArgumentException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws InvalidInterfaceException |
|
471 | + */ |
|
472 | + protected static function _posts_join_for_venue_state($SQL = '') |
|
473 | + { |
|
474 | + // Venue Meta table name |
|
475 | + $venue_meta_table = EEM_Venue::instance()->second_table(); |
|
476 | + // State table name |
|
477 | + $state_table = EEM_State::instance()->table(); |
|
478 | + // State table pk |
|
479 | + $state_table_pk = EEM_State::instance()->primary_key_name(); |
|
480 | + // verify vars |
|
481 | + if ($venue_meta_table && $state_table && $state_table_pk) { |
|
482 | + // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID |
|
483 | + $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk"; |
|
484 | + // don't add join if it has already been added |
|
485 | + if (strpos($SQL, $join) === false) { |
|
486 | + unset($state_table_pk, $venue_meta_table, $venue_table_pk); |
|
487 | + return " LEFT JOIN $state_table ON ( $join )"; |
|
488 | + } |
|
489 | + } |
|
490 | + unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk); |
|
491 | + return ''; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * @param string $SQL |
|
498 | + * @param WP_Query $wp_query |
|
499 | + * @return string |
|
500 | + * @throws EE_Error |
|
501 | + * @throws InvalidArgumentException |
|
502 | + * @throws InvalidDataTypeException |
|
503 | + * @throws InvalidInterfaceException |
|
504 | + */ |
|
505 | + public static function posts_where($SQL = '', WP_Query $wp_query) |
|
506 | + { |
|
507 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
508 | + // Show Expired ? |
|
509 | + $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired); |
|
510 | + // Category |
|
511 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category); |
|
512 | + // Start Date |
|
513 | + $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month); |
|
514 | + } |
|
515 | + return $SQL; |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param boolean $show_expired if TRUE, then displayed past events |
|
522 | + * @return string |
|
523 | + * @throws EE_Error |
|
524 | + * @throws InvalidArgumentException |
|
525 | + * @throws InvalidDataTypeException |
|
526 | + * @throws InvalidInterfaceException |
|
527 | + */ |
|
528 | + public static function posts_where_sql_for_show_expired($show_expired = false) |
|
529 | + { |
|
530 | + return ! $show_expired |
|
531 | + ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
532 | + : ''; |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @param boolean $event_category_slug |
|
539 | + * @return string |
|
540 | + */ |
|
541 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
|
542 | + { |
|
543 | + global $wpdb; |
|
544 | + if (! empty($event_category_slug)) { |
|
545 | + $event_category_slugs_array = array_map('trim', explode(',', $event_category_slug)); |
|
546 | + $event_category_slugs_prepare = implode(', ', array_fill(0, count($event_category_slugs_array), '%s')); |
|
547 | + return $wpdb->prepare(" AND {$wpdb->terms}.slug IN ({$event_category_slugs_prepare}) ", $event_category_slugs_array); |
|
548 | + } |
|
549 | + return ''; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * @param boolean $month |
|
556 | + * @return string |
|
557 | + * @throws EE_Error |
|
558 | + * @throws InvalidArgumentException |
|
559 | + * @throws InvalidDataTypeException |
|
560 | + * @throws InvalidInterfaceException |
|
561 | + */ |
|
562 | + public static function posts_where_sql_for_event_list_month($month = null) |
|
563 | + { |
|
564 | + $SQL = ''; |
|
565 | + if (! empty($month)) { |
|
566 | + $datetime_table = EEM_Datetime::instance()->table(); |
|
567 | + // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
|
568 | + $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
|
569 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
570 | + // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
|
571 | + $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
|
572 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
573 | + } |
|
574 | + return $SQL; |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * @param string $SQL |
|
581 | + * @param WP_Query $wp_query |
|
582 | + * @return string |
|
583 | + * @throws EE_Error |
|
584 | + * @throws InvalidArgumentException |
|
585 | + * @throws InvalidDataTypeException |
|
586 | + * @throws InvalidInterfaceException |
|
587 | + */ |
|
588 | + public static function posts_orderby($SQL = '', WP_Query $wp_query) |
|
589 | + { |
|
590 | + if (EEH_Event_Query::apply_query_filters($wp_query)) { |
|
591 | + $SQL = EEH_Event_Query::posts_orderby_sql( |
|
592 | + EEH_Event_Query::$_event_query_orderby, |
|
593 | + EEH_Event_Query::$_event_query_sort |
|
594 | + ); |
|
595 | + } |
|
596 | + return $SQL; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * posts_orderby_sql |
|
603 | + * possible parameters: |
|
604 | + * ID |
|
605 | + * start_date |
|
606 | + * end_date |
|
607 | + * event_name |
|
608 | + * category_slug |
|
609 | + * ticket_start |
|
610 | + * ticket_end |
|
611 | + * venue_title |
|
612 | + * city |
|
613 | + * state |
|
614 | + * **IMPORTANT** |
|
615 | + * make sure to also send the $orderby_params array to the posts_join_for_orderby() method |
|
616 | + * or else some of the table references below will result in MySQL errors |
|
617 | + * |
|
618 | + * @param array $orderby_params |
|
619 | + * @param string $sort |
|
620 | + * @return string |
|
621 | + * @throws EE_Error |
|
622 | + * @throws InvalidArgumentException |
|
623 | + * @throws InvalidDataTypeException |
|
624 | + * @throws InvalidInterfaceException |
|
625 | + */ |
|
626 | + public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC') |
|
627 | + { |
|
628 | + global $wpdb; |
|
629 | + $SQL = ''; |
|
630 | + $counter = 0; |
|
631 | + $sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true) |
|
632 | + ? strtoupper($sort) |
|
633 | + : 'ASC'; |
|
634 | + // make sure 'orderby' is set in query params |
|
635 | + if (! isset(self::$_query_params['orderby'])) { |
|
636 | + self::$_query_params['orderby'] = array(); |
|
637 | + } |
|
638 | + // loop thru $orderby_params (type cast as array) |
|
639 | + foreach ($orderby_params as $orderby) { |
|
640 | + // check if we have already added this param |
|
641 | + if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
642 | + // if so then remove from the $orderby_params so that the count() method below is accurate |
|
643 | + unset($orderby_params[ $orderby ]); |
|
644 | + // then bump ahead to the next param |
|
645 | + continue; |
|
646 | + } |
|
647 | + // this will ad a comma depending on whether this is the first or last param |
|
648 | + $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', '; |
|
649 | + // ok what's we dealing with? |
|
650 | + switch ($orderby) { |
|
651 | + case 'id': |
|
652 | + case 'ID': |
|
653 | + $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
654 | + break; |
|
655 | + case 'end_date': |
|
656 | + $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
657 | + break; |
|
658 | + case 'event_name': |
|
659 | + $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
660 | + break; |
|
661 | + case 'category_slug': |
|
662 | + $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
663 | + break; |
|
664 | + case 'ticket_start': |
|
665 | + $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
666 | + break; |
|
667 | + case 'ticket_end': |
|
668 | + $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
669 | + break; |
|
670 | + case 'venue_title': |
|
671 | + $SQL .= $glue . 'venue_title ' . $sort; |
|
672 | + break; |
|
673 | + case 'city': |
|
674 | + $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
675 | + break; |
|
676 | + case 'state': |
|
677 | + $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
678 | + break; |
|
679 | + case 'start_date': |
|
680 | + default: |
|
681 | + $SQL .= $glue . ' event_start_date ' . $sort; |
|
682 | + break; |
|
683 | + } |
|
684 | + // add to array of orderby params that have been added |
|
685 | + self::$_query_params['orderby'][ $orderby ] = true; |
|
686 | + $counter++; |
|
687 | + } |
|
688 | + return $SQL; |
|
689 | + } |
|
690 | 690 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | if (EEH_Event_Query::apply_query_filters($wp_query)) { |
229 | 229 | global $wpdb; |
230 | - $clauses['groupby'] = $wpdb->posts . '.ID '; |
|
230 | + $clauses['groupby'] = $wpdb->posts.'.ID '; |
|
231 | 231 | } |
232 | 232 | return $clauses; |
233 | 233 | } |
@@ -264,23 +264,23 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public static function posts_fields_sql_for_orderby(array $orderby_params = array()) |
266 | 266 | { |
267 | - $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
267 | + $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
268 | 268 | foreach ($orderby_params as $orderby) { |
269 | 269 | switch ($orderby) { |
270 | 270 | case 'ticket_start': |
271 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date'; |
|
271 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date'; |
|
272 | 272 | break; |
273 | 273 | case 'ticket_end': |
274 | - $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date'; |
|
274 | + $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date'; |
|
275 | 275 | break; |
276 | 276 | case 'venue_title': |
277 | 277 | $SQL .= ', Venue.post_title AS venue_title'; |
278 | 278 | break; |
279 | 279 | case 'city': |
280 | - $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city'; |
|
280 | + $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city'; |
|
281 | 281 | break; |
282 | 282 | case 'state': |
283 | - $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name'; |
|
283 | + $SQL .= ', '.EEM_State::instance()->table().'.STA_name'; |
|
284 | 284 | break; |
285 | 285 | } |
286 | 286 | } |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | */ |
323 | 323 | public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false) |
324 | 324 | { |
325 | - if (! $show_expired) { |
|
326 | - $join = EEM_Event::instance()->table() . '.ID = '; |
|
327 | - $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
325 | + if ( ! $show_expired) { |
|
326 | + $join = EEM_Event::instance()->table().'.ID = '; |
|
327 | + $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
328 | 328 | // don't add if this is already in the SQL |
329 | 329 | if (strpos($SQL, $join) === false) { |
330 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) '; |
|
330 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) '; |
|
331 | 331 | } |
332 | 332 | } |
333 | 333 | return $SQL; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') |
345 | 345 | { |
346 | - if (! empty($join_terms)) { |
|
346 | + if ( ! empty($join_terms)) { |
|
347 | 347 | global $wpdb; |
348 | 348 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
349 | 349 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -373,13 +373,13 @@ discard block |
||
373 | 373 | case 'ticket_end': |
374 | 374 | $SQL .= EEH_Event_Query::_posts_join_for_datetime( |
375 | 375 | $SQL, |
376 | - EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name() |
|
376 | + EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name() |
|
377 | 377 | ); |
378 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table(); |
|
378 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table(); |
|
379 | 379 | $SQL .= ' ON ('; |
380 | - $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
380 | + $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
381 | 381 | $SQL .= ' = '; |
382 | - $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name(); |
|
382 | + $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name(); |
|
383 | 383 | $SQL .= ' )'; |
384 | 384 | break; |
385 | 385 | case 'venue_title': |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | break; |
393 | 393 | case 'start_date': |
394 | 394 | default: |
395 | - $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID'); |
|
395 | + $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID'); |
|
396 | 396 | break; |
397 | 397 | } |
398 | 398 | } |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected static function _posts_join_for_datetime($SQL = '', $join = '') |
414 | 414 | { |
415 | - if (! empty($join)) { |
|
416 | - $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name(); |
|
415 | + if ( ! empty($join)) { |
|
416 | + $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name(); |
|
417 | 417 | if (strpos($SQL, $join) === false) { |
418 | - return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )'; |
|
418 | + return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )'; |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | return ''; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | // Event Venue table name |
437 | 437 | $event_venue_table = EEM_Event_Venue::instance()->table(); |
438 | 438 | // generate conditions for: Event <=> Event Venue JOIN clause |
439 | - $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = '; |
|
440 | - $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name(); |
|
439 | + $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = '; |
|
440 | + $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name(); |
|
441 | 441 | // don't add joins if they have already been added |
442 | 442 | if (strpos($SQL, $event_to_event_venue_join) === false) { |
443 | 443 | // Venue table name |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | public static function posts_where_sql_for_show_expired($show_expired = false) |
529 | 529 | { |
530 | 530 | return ! $show_expired |
531 | - ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' ' |
|
531 | + ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', true).'\' ' |
|
532 | 532 | : ''; |
533 | 533 | } |
534 | 534 | |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | public static function posts_where_sql_for_event_category_slug($event_category_slug = null) |
542 | 542 | { |
543 | 543 | global $wpdb; |
544 | - if (! empty($event_category_slug)) { |
|
544 | + if ( ! empty($event_category_slug)) { |
|
545 | 545 | $event_category_slugs_array = array_map('trim', explode(',', $event_category_slug)); |
546 | 546 | $event_category_slugs_prepare = implode(', ', array_fill(0, count($event_category_slugs_array), '%s')); |
547 | 547 | return $wpdb->prepare(" AND {$wpdb->terms}.slug IN ({$event_category_slugs_prepare}) ", $event_category_slugs_array); |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | public static function posts_where_sql_for_event_list_month($month = null) |
563 | 563 | { |
564 | 564 | $SQL = ''; |
565 | - if (! empty($month)) { |
|
565 | + if ( ! empty($month)) { |
|
566 | 566 | $datetime_table = EEM_Datetime::instance()->table(); |
567 | 567 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
568 | 568 | $SQL = " AND {$datetime_table}.DTT_EVT_start <= '"; |
569 | - $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'"; |
|
569 | + $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'"; |
|
570 | 570 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
571 | 571 | $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '"; |
572 | - $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' "; |
|
572 | + $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' "; |
|
573 | 573 | } |
574 | 574 | return $SQL; |
575 | 575 | } |
@@ -632,15 +632,15 @@ discard block |
||
632 | 632 | ? strtoupper($sort) |
633 | 633 | : 'ASC'; |
634 | 634 | // make sure 'orderby' is set in query params |
635 | - if (! isset(self::$_query_params['orderby'])) { |
|
635 | + if ( ! isset(self::$_query_params['orderby'])) { |
|
636 | 636 | self::$_query_params['orderby'] = array(); |
637 | 637 | } |
638 | 638 | // loop thru $orderby_params (type cast as array) |
639 | 639 | foreach ($orderby_params as $orderby) { |
640 | 640 | // check if we have already added this param |
641 | - if (isset(self::$_query_params['orderby'][ $orderby ])) { |
|
641 | + if (isset(self::$_query_params['orderby'][$orderby])) { |
|
642 | 642 | // if so then remove from the $orderby_params so that the count() method below is accurate |
643 | - unset($orderby_params[ $orderby ]); |
|
643 | + unset($orderby_params[$orderby]); |
|
644 | 644 | // then bump ahead to the next param |
645 | 645 | continue; |
646 | 646 | } |
@@ -650,39 +650,39 @@ discard block |
||
650 | 650 | switch ($orderby) { |
651 | 651 | case 'id': |
652 | 652 | case 'ID': |
653 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
653 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
654 | 654 | break; |
655 | 655 | case 'end_date': |
656 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
656 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
657 | 657 | break; |
658 | 658 | case 'event_name': |
659 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
659 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
660 | 660 | break; |
661 | 661 | case 'category_slug': |
662 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
662 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
663 | 663 | break; |
664 | 664 | case 'ticket_start': |
665 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
665 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
666 | 666 | break; |
667 | 667 | case 'ticket_end': |
668 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
668 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
669 | 669 | break; |
670 | 670 | case 'venue_title': |
671 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
671 | + $SQL .= $glue.'venue_title '.$sort; |
|
672 | 672 | break; |
673 | 673 | case 'city': |
674 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
674 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
675 | 675 | break; |
676 | 676 | case 'state': |
677 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
677 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
678 | 678 | break; |
679 | 679 | case 'start_date': |
680 | 680 | default: |
681 | - $SQL .= $glue . ' event_start_date ' . $sort; |
|
681 | + $SQL .= $glue.' event_start_date '.$sort; |
|
682 | 682 | break; |
683 | 683 | } |
684 | 684 | // add to array of orderby params that have been added |
685 | - self::$_query_params['orderby'][ $orderby ] = true; |
|
685 | + self::$_query_params['orderby'][$orderby] = true; |
|
686 | 686 | $counter++; |
687 | 687 | } |
688 | 688 | return $SQL; |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | $args['DTT_description'] = wp_kses_post($input['description']); |
41 | 41 | } |
42 | 42 | |
43 | - if (! empty($input['endDate'])) { |
|
43 | + if ( ! empty($input['endDate'])) { |
|
44 | 44 | $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
45 | 45 | } |
46 | 46 | |
47 | - if (! empty($input['eventId'])) { |
|
47 | + if ( ! empty($input['eventId'])) { |
|
48 | 48 | $args['EVT_ID'] = absint($input['eventId']); |
49 | - } elseif (! empty($input['event'])) { |
|
49 | + } elseif ( ! empty($input['event'])) { |
|
50 | 50 | $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
51 | - $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
51 | + $args['EVT_ID'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | if (array_key_exists('isPrimary', $input)) { |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | $args['DTT_order'] = (int) $input['order']; |
68 | 68 | } |
69 | 69 | |
70 | - if (! empty($input['parent'])) { |
|
70 | + if ( ! empty($input['parent'])) { |
|
71 | 71 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
72 | - $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
72 | + $args['DTT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | if (array_key_exists('reserved', $input)) { |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | $args['DTT_sold'] = (int) $input['sold']; |
81 | 81 | } |
82 | 82 | |
83 | - if (! empty($input['startDate'])) { |
|
83 | + if ( ! empty($input['startDate'])) { |
|
84 | 84 | $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
85 | 85 | } |
86 | 86 | |
87 | - if (! empty($input['tickets'])) { |
|
87 | + if ( ! empty($input['tickets'])) { |
|
88 | 88 | $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
89 | 89 | } |
90 | 90 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | |
116 | 116 | foreach ($tickets as $ID) { |
117 | 117 | $parts = Relay::fromGlobalId($ID); |
118 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
118 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
119 | 119 | $entity->_add_relation_to( |
120 | 120 | $parts['id'], |
121 | 121 | $relationName |
@@ -21,106 +21,106 @@ |
||
21 | 21 | class DatetimeMutation |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Maps the GraphQL input to a format that the model functions can use |
|
26 | - * |
|
27 | - * @param array $input Data coming from the GraphQL mutation query input |
|
28 | - * @return array |
|
29 | - * @throws Exception |
|
30 | - */ |
|
31 | - public static function prepareFields(array $input): array |
|
32 | - { |
|
33 | - $args = []; |
|
34 | - |
|
35 | - if (array_key_exists('capacity', $input)) { |
|
36 | - $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
37 | - } |
|
38 | - |
|
39 | - if (isset($input['description'])) { |
|
40 | - $args['DTT_description'] = wp_kses_post($input['description']); |
|
41 | - } |
|
42 | - |
|
43 | - if (! empty($input['endDate'])) { |
|
44 | - $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
45 | - } |
|
46 | - |
|
47 | - if (! empty($input['eventId'])) { |
|
48 | - $args['EVT_ID'] = absint($input['eventId']); |
|
49 | - } elseif (! empty($input['event'])) { |
|
50 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
51 | - $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | - } |
|
53 | - |
|
54 | - if (array_key_exists('isPrimary', $input)) { |
|
55 | - $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
56 | - } |
|
57 | - |
|
58 | - if (array_key_exists('isTrashed', $input)) { |
|
59 | - $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
60 | - } |
|
61 | - |
|
62 | - if (isset($input['name'])) { |
|
63 | - $args['DTT_name'] = sanitize_text_field($input['name']); |
|
64 | - } |
|
65 | - |
|
66 | - if (array_key_exists('order', $input)) { |
|
67 | - $args['DTT_order'] = (int) $input['order']; |
|
68 | - } |
|
69 | - |
|
70 | - if (! empty($input['parent'])) { |
|
71 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
72 | - $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | - } |
|
74 | - |
|
75 | - if (array_key_exists('reserved', $input)) { |
|
76 | - $args['DTT_reserved'] = (int) $input['reserved']; |
|
77 | - } |
|
78 | - |
|
79 | - if (array_key_exists('sold', $input)) { |
|
80 | - $args['DTT_sold'] = (int) $input['sold']; |
|
81 | - } |
|
82 | - |
|
83 | - if (! empty($input['startDate'])) { |
|
84 | - $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
85 | - } |
|
86 | - |
|
87 | - if (! empty($input['tickets'])) { |
|
88 | - $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
89 | - } |
|
90 | - |
|
91 | - return apply_filters( |
|
92 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args', |
|
93 | - $args, |
|
94 | - $input |
|
95 | - ); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Sets the related tickets for the given datetime. |
|
101 | - * |
|
102 | - * @param EE_Datetime $entity The datetime instance. |
|
103 | - * @param array $tickets Array of ticket IDs to relate. |
|
104 | - * @throws EE_Error |
|
105 | - * @throws InvalidDataTypeException |
|
106 | - * @throws InvalidInterfaceException |
|
107 | - * @throws InvalidArgumentException |
|
108 | - * @throws ReflectionException |
|
109 | - */ |
|
110 | - public static function setRelatedTickets(EE_Datetime $entity, array $tickets) |
|
111 | - { |
|
112 | - $relationName = 'Ticket'; |
|
113 | - // Remove all the existing related tickets |
|
114 | - $entity->_remove_relations($relationName); |
|
115 | - |
|
116 | - foreach ($tickets as $ID) { |
|
117 | - $parts = Relay::fromGlobalId($ID); |
|
118 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
119 | - $entity->_add_relation_to( |
|
120 | - $parts['id'], |
|
121 | - $relationName |
|
122 | - ); |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
24 | + /** |
|
25 | + * Maps the GraphQL input to a format that the model functions can use |
|
26 | + * |
|
27 | + * @param array $input Data coming from the GraphQL mutation query input |
|
28 | + * @return array |
|
29 | + * @throws Exception |
|
30 | + */ |
|
31 | + public static function prepareFields(array $input): array |
|
32 | + { |
|
33 | + $args = []; |
|
34 | + |
|
35 | + if (array_key_exists('capacity', $input)) { |
|
36 | + $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
37 | + } |
|
38 | + |
|
39 | + if (isset($input['description'])) { |
|
40 | + $args['DTT_description'] = wp_kses_post($input['description']); |
|
41 | + } |
|
42 | + |
|
43 | + if (! empty($input['endDate'])) { |
|
44 | + $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
45 | + } |
|
46 | + |
|
47 | + if (! empty($input['eventId'])) { |
|
48 | + $args['EVT_ID'] = absint($input['eventId']); |
|
49 | + } elseif (! empty($input['event'])) { |
|
50 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
51 | + $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | + } |
|
53 | + |
|
54 | + if (array_key_exists('isPrimary', $input)) { |
|
55 | + $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
56 | + } |
|
57 | + |
|
58 | + if (array_key_exists('isTrashed', $input)) { |
|
59 | + $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
60 | + } |
|
61 | + |
|
62 | + if (isset($input['name'])) { |
|
63 | + $args['DTT_name'] = sanitize_text_field($input['name']); |
|
64 | + } |
|
65 | + |
|
66 | + if (array_key_exists('order', $input)) { |
|
67 | + $args['DTT_order'] = (int) $input['order']; |
|
68 | + } |
|
69 | + |
|
70 | + if (! empty($input['parent'])) { |
|
71 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
72 | + $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | + } |
|
74 | + |
|
75 | + if (array_key_exists('reserved', $input)) { |
|
76 | + $args['DTT_reserved'] = (int) $input['reserved']; |
|
77 | + } |
|
78 | + |
|
79 | + if (array_key_exists('sold', $input)) { |
|
80 | + $args['DTT_sold'] = (int) $input['sold']; |
|
81 | + } |
|
82 | + |
|
83 | + if (! empty($input['startDate'])) { |
|
84 | + $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
85 | + } |
|
86 | + |
|
87 | + if (! empty($input['tickets'])) { |
|
88 | + $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
89 | + } |
|
90 | + |
|
91 | + return apply_filters( |
|
92 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__datetime_args', |
|
93 | + $args, |
|
94 | + $input |
|
95 | + ); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Sets the related tickets for the given datetime. |
|
101 | + * |
|
102 | + * @param EE_Datetime $entity The datetime instance. |
|
103 | + * @param array $tickets Array of ticket IDs to relate. |
|
104 | + * @throws EE_Error |
|
105 | + * @throws InvalidDataTypeException |
|
106 | + * @throws InvalidInterfaceException |
|
107 | + * @throws InvalidArgumentException |
|
108 | + * @throws ReflectionException |
|
109 | + */ |
|
110 | + public static function setRelatedTickets(EE_Datetime $entity, array $tickets) |
|
111 | + { |
|
112 | + $relationName = 'Ticket'; |
|
113 | + // Remove all the existing related tickets |
|
114 | + $entity->_remove_relations($relationName); |
|
115 | + |
|
116 | + foreach ($tickets as $ID) { |
|
117 | + $parts = Relay::fromGlobalId($ID); |
|
118 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
119 | + $entity->_add_relation_to( |
|
120 | + $parts['id'], |
|
121 | + $relationName |
|
122 | + ); |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | } |
83 | 83 | if ($child_node instanceof JsonDataNode) { |
84 | 84 | // feed data node back into this function |
85 | - $data[ $child_node_name ] = $this->initializeDataNodes($child_node, $depth); |
|
85 | + $data[$child_node_name] = $this->initializeDataNodes($child_node, $depth); |
|
86 | 86 | } else { |
87 | 87 | // or assign data directly |
88 | - $data[ $child_node_name ] = $child_node; |
|
88 | + $data[$child_node_name] = $child_node; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function printDataNode() |
101 | 101 | { |
102 | - if (!$this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
102 | + if ( ! $this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | // validate that the domain, node name, and target script are set |
106 | 106 | $domain = $this->primary_data_node->domain(); |
107 | 107 | $node_name = $this->primary_data_node->nodeName(); |
108 | - $data_valid = $this->validator->validateCriticalProperty($domain, 'domain route', false) |
|
108 | + $data_valid = $this->validator->validateCriticalProperty($domain, 'domain route', false) |
|
109 | 109 | && $this->validator->validateCriticalProperty($node_name, 'node name', false); |
110 | - if (! $data_valid) { |
|
110 | + if ( ! $data_valid) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | // initialize and parse data from primary data node |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $this->setPrimaryDataNode($data_node); |
138 | 138 | } |
139 | 139 | // and don't allow other nodes to be set until a primary is set |
140 | - if (! $this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
140 | + if ( ! $this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
141 | 141 | throw new DomainException( |
142 | 142 | esc_html__( |
143 | 143 | 'A PrimaryJsonDataNode needs to be set before data nodes can be added.', |
@@ -18,130 +18,130 @@ |
||
18 | 18 | class JsonDataNodeHandler |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var PrimaryJsonDataNode $primary_data_node |
|
23 | - */ |
|
24 | - private $primary_data_node; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var JsonDataNodeValidator $validator |
|
28 | - */ |
|
29 | - private $validator; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param JsonDataNodeValidator $validator |
|
34 | - */ |
|
35 | - public function __construct(JsonDataNodeValidator $validator) |
|
36 | - { |
|
37 | - $this->validator = $validator; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param JsonDataNode $data_node |
|
43 | - * @throws DomainException |
|
44 | - */ |
|
45 | - public function addDataNode(JsonDataNode $data_node) |
|
46 | - { |
|
47 | - if ($data_node->isNotInitialized()) { |
|
48 | - $this->validatePrimaryDataNode($data_node); |
|
49 | - $this->primary_data_node->addDataNode($data_node); |
|
50 | - } |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param PrimaryJsonDataNode $primary_data_node |
|
56 | - */ |
|
57 | - public function setPrimaryDataNode(PrimaryJsonDataNode $primary_data_node) |
|
58 | - { |
|
59 | - $this->primary_data_node = $primary_data_node; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param JsonDataNode $data_node |
|
65 | - * @param int $depth |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - private function initializeDataNodes(JsonDataNode $data_node, $depth = 0): array |
|
69 | - { |
|
70 | - $depth++; |
|
71 | - $data = []; |
|
72 | - // initialize the data node if not done already |
|
73 | - if ($data_node->isNotInitialized()) { |
|
74 | - $data_node->initialize(); |
|
75 | - // grab the data node's data array |
|
76 | - $data_node_data = $data_node->data(); |
|
77 | - foreach ($data_node_data as $child_node_name => $child_node) { |
|
78 | - // don't parse node if it's the primary, OR if depth has exceeded wp_json_encode() limit |
|
79 | - if ($child_node instanceof PrimaryJsonDataNode || $depth > 512) { |
|
80 | - continue; |
|
81 | - } |
|
82 | - if ($child_node instanceof JsonDataNode) { |
|
83 | - // feed data node back into this function |
|
84 | - $data[ $child_node_name ] = $this->initializeDataNodes($child_node, $depth); |
|
85 | - } else { |
|
86 | - // or assign data directly |
|
87 | - $data[ $child_node_name ] = $child_node; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - return $data; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws DomainException |
|
97 | - */ |
|
98 | - public function printDataNode() |
|
99 | - { |
|
100 | - if (!$this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
101 | - return; |
|
102 | - } |
|
103 | - // validate that the domain, node name, and target script are set |
|
104 | - $domain = $this->primary_data_node->domain(); |
|
105 | - $node_name = $this->primary_data_node->nodeName(); |
|
106 | - $data_valid = $this->validator->validateCriticalProperty($domain, 'domain route', false) |
|
107 | - && $this->validator->validateCriticalProperty($node_name, 'node name', false); |
|
108 | - if (! $data_valid) { |
|
109 | - return; |
|
110 | - } |
|
111 | - // initialize and parse data from primary data node |
|
112 | - $data = $this->initializeDataNodes($this->primary_data_node); |
|
113 | - // this prepends the current domain "use case" to the front of the array |
|
114 | - $data = ['domain' => $domain] + $data; |
|
115 | - // add legacy i18n strings |
|
116 | - $data['eei18n'] = EE_Registry::$i18n_js_strings; |
|
117 | - // and finally, print the JSON encoded data to the DOM |
|
118 | - printf( |
|
119 | - "<script type='text/javascript' id='%s'>\nvar %s = %s\n</script>\n", |
|
120 | - $node_name, |
|
121 | - $node_name, |
|
122 | - json_encode($data) |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param JsonDataNode $data_node |
|
129 | - * @throws DomainException |
|
130 | - */ |
|
131 | - private function validatePrimaryDataNode(JsonDataNode $data_node) |
|
132 | - { |
|
133 | - // set primary data node if that's what the incoming node is |
|
134 | - if ($data_node instanceof PrimaryJsonDataNode) { |
|
135 | - $this->setPrimaryDataNode($data_node); |
|
136 | - } |
|
137 | - // and don't allow other nodes to be set until a primary is set |
|
138 | - if (! $this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
139 | - throw new DomainException( |
|
140 | - esc_html__( |
|
141 | - 'A PrimaryJsonDataNode needs to be set before data nodes can be added.', |
|
142 | - 'event_espresso' |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
146 | - } |
|
21 | + /** |
|
22 | + * @var PrimaryJsonDataNode $primary_data_node |
|
23 | + */ |
|
24 | + private $primary_data_node; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var JsonDataNodeValidator $validator |
|
28 | + */ |
|
29 | + private $validator; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param JsonDataNodeValidator $validator |
|
34 | + */ |
|
35 | + public function __construct(JsonDataNodeValidator $validator) |
|
36 | + { |
|
37 | + $this->validator = $validator; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param JsonDataNode $data_node |
|
43 | + * @throws DomainException |
|
44 | + */ |
|
45 | + public function addDataNode(JsonDataNode $data_node) |
|
46 | + { |
|
47 | + if ($data_node->isNotInitialized()) { |
|
48 | + $this->validatePrimaryDataNode($data_node); |
|
49 | + $this->primary_data_node->addDataNode($data_node); |
|
50 | + } |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param PrimaryJsonDataNode $primary_data_node |
|
56 | + */ |
|
57 | + public function setPrimaryDataNode(PrimaryJsonDataNode $primary_data_node) |
|
58 | + { |
|
59 | + $this->primary_data_node = $primary_data_node; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param JsonDataNode $data_node |
|
65 | + * @param int $depth |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + private function initializeDataNodes(JsonDataNode $data_node, $depth = 0): array |
|
69 | + { |
|
70 | + $depth++; |
|
71 | + $data = []; |
|
72 | + // initialize the data node if not done already |
|
73 | + if ($data_node->isNotInitialized()) { |
|
74 | + $data_node->initialize(); |
|
75 | + // grab the data node's data array |
|
76 | + $data_node_data = $data_node->data(); |
|
77 | + foreach ($data_node_data as $child_node_name => $child_node) { |
|
78 | + // don't parse node if it's the primary, OR if depth has exceeded wp_json_encode() limit |
|
79 | + if ($child_node instanceof PrimaryJsonDataNode || $depth > 512) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + if ($child_node instanceof JsonDataNode) { |
|
83 | + // feed data node back into this function |
|
84 | + $data[ $child_node_name ] = $this->initializeDataNodes($child_node, $depth); |
|
85 | + } else { |
|
86 | + // or assign data directly |
|
87 | + $data[ $child_node_name ] = $child_node; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + return $data; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws DomainException |
|
97 | + */ |
|
98 | + public function printDataNode() |
|
99 | + { |
|
100 | + if (!$this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
101 | + return; |
|
102 | + } |
|
103 | + // validate that the domain, node name, and target script are set |
|
104 | + $domain = $this->primary_data_node->domain(); |
|
105 | + $node_name = $this->primary_data_node->nodeName(); |
|
106 | + $data_valid = $this->validator->validateCriticalProperty($domain, 'domain route', false) |
|
107 | + && $this->validator->validateCriticalProperty($node_name, 'node name', false); |
|
108 | + if (! $data_valid) { |
|
109 | + return; |
|
110 | + } |
|
111 | + // initialize and parse data from primary data node |
|
112 | + $data = $this->initializeDataNodes($this->primary_data_node); |
|
113 | + // this prepends the current domain "use case" to the front of the array |
|
114 | + $data = ['domain' => $domain] + $data; |
|
115 | + // add legacy i18n strings |
|
116 | + $data['eei18n'] = EE_Registry::$i18n_js_strings; |
|
117 | + // and finally, print the JSON encoded data to the DOM |
|
118 | + printf( |
|
119 | + "<script type='text/javascript' id='%s'>\nvar %s = %s\n</script>\n", |
|
120 | + $node_name, |
|
121 | + $node_name, |
|
122 | + json_encode($data) |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param JsonDataNode $data_node |
|
129 | + * @throws DomainException |
|
130 | + */ |
|
131 | + private function validatePrimaryDataNode(JsonDataNode $data_node) |
|
132 | + { |
|
133 | + // set primary data node if that's what the incoming node is |
|
134 | + if ($data_node instanceof PrimaryJsonDataNode) { |
|
135 | + $this->setPrimaryDataNode($data_node); |
|
136 | + } |
|
137 | + // and don't allow other nodes to be set until a primary is set |
|
138 | + if (! $this->primary_data_node instanceof PrimaryJsonDataNode) { |
|
139 | + throw new DomainException( |
|
140 | + esc_html__( |
|
141 | + 'A PrimaryJsonDataNode needs to be set before data nodes can be added.', |
|
142 | + 'event_espresso' |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | } |
@@ -15,35 +15,35 @@ |
||
15 | 15 | class JedLocaleData |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array $locales |
|
20 | - */ |
|
21 | - protected $locales = []; |
|
18 | + /** |
|
19 | + * @var array $locales |
|
20 | + */ |
|
21 | + protected $locales = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Returns Jed-formatted localization data. |
|
25 | - * |
|
26 | - * @param string $domain Translation domain. |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function getData($domain = Domain::TEXT_DOMAIN) |
|
30 | - { |
|
31 | - if (! isset($locales[ $domain ])) { |
|
32 | - $translations = get_translations_for_domain($domain); |
|
33 | - $locale = [ |
|
34 | - '' => [ |
|
35 | - 'domain' => $domain, |
|
36 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
37 | - ], |
|
38 | - ]; |
|
39 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
40 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
41 | - } |
|
42 | - foreach ($translations->entries as $id => $entry) { |
|
43 | - $locale[ $id ] = $entry->translations; |
|
44 | - } |
|
45 | - $locales[ $domain ] = $locale; |
|
46 | - } |
|
47 | - return $locales[ $domain ]; |
|
48 | - } |
|
23 | + /** |
|
24 | + * Returns Jed-formatted localization data. |
|
25 | + * |
|
26 | + * @param string $domain Translation domain. |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function getData($domain = Domain::TEXT_DOMAIN) |
|
30 | + { |
|
31 | + if (! isset($locales[ $domain ])) { |
|
32 | + $translations = get_translations_for_domain($domain); |
|
33 | + $locale = [ |
|
34 | + '' => [ |
|
35 | + 'domain' => $domain, |
|
36 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
37 | + ], |
|
38 | + ]; |
|
39 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
40 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
41 | + } |
|
42 | + foreach ($translations->entries as $id => $entry) { |
|
43 | + $locale[ $id ] = $entry->translations; |
|
44 | + } |
|
45 | + $locales[ $domain ] = $locale; |
|
46 | + } |
|
47 | + return $locales[ $domain ]; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getData($domain = Domain::TEXT_DOMAIN) |
30 | 30 | { |
31 | - if (! isset($locales[ $domain ])) { |
|
31 | + if ( ! isset($locales[$domain])) { |
|
32 | 32 | $translations = get_translations_for_domain($domain); |
33 | 33 | $locale = [ |
34 | 34 | '' => [ |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
37 | 37 | ], |
38 | 38 | ]; |
39 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
39 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
40 | 40 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
41 | 41 | } |
42 | 42 | foreach ($translations->entries as $id => $entry) { |
43 | - $locale[ $id ] = $entry->translations; |
|
43 | + $locale[$id] = $entry->translations; |
|
44 | 44 | } |
45 | - $locales[ $domain ] = $locale; |
|
45 | + $locales[$domain] = $locale; |
|
46 | 46 | } |
47 | - return $locales[ $domain ]; |
|
47 | + return $locales[$domain]; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -13,46 +13,46 @@ |
||
13 | 13 | */ |
14 | 14 | class I18nRegistry |
15 | 15 | { |
16 | - /** |
|
17 | - * @var DomainInterface |
|
18 | - */ |
|
19 | - private $domain; |
|
16 | + /** |
|
17 | + * @var DomainInterface |
|
18 | + */ |
|
19 | + private $domain; |
|
20 | 20 | |
21 | - /** |
|
22 | - * @var JedLocaleData $jed_locale |
|
23 | - */ |
|
24 | - private $jed_locale; |
|
21 | + /** |
|
22 | + * @var JedLocaleData $jed_locale |
|
23 | + */ |
|
24 | + private $jed_locale; |
|
25 | 25 | |
26 | - /** |
|
27 | - * I18nRegistry constructor. |
|
28 | - * |
|
29 | - * @param DomainInterface $domain |
|
30 | - * @param JedLocaleData $jed_locale |
|
31 | - * @param array() $i18n_map |
|
32 | - * @deprecated $VID:$ |
|
33 | - */ |
|
34 | - public function __construct(DomainInterface $domain, JedLocaleData $jed_locale, array $i18n_map = []) |
|
35 | - { |
|
36 | - $this->domain = $domain; |
|
37 | - $this->jed_locale = $jed_locale; |
|
38 | - } |
|
26 | + /** |
|
27 | + * I18nRegistry constructor. |
|
28 | + * |
|
29 | + * @param DomainInterface $domain |
|
30 | + * @param JedLocaleData $jed_locale |
|
31 | + * @param array() $i18n_map |
|
32 | + * @deprecated $VID:$ |
|
33 | + */ |
|
34 | + public function __construct(DomainInterface $domain, JedLocaleData $jed_locale, array $i18n_map = []) |
|
35 | + { |
|
36 | + $this->domain = $domain; |
|
37 | + $this->jed_locale = $jed_locale; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $handle The script handle reference. |
|
42 | - * @param string $domain The i18n domain for the strings. |
|
43 | - * @deprecated $VID:$ |
|
44 | - */ |
|
45 | - public function registerScriptI18n($handle, $domain = Domain::TEXT_DOMAIN) |
|
46 | - { |
|
47 | - } |
|
40 | + /** |
|
41 | + * @param string $handle The script handle reference. |
|
42 | + * @param string $domain The i18n domain for the strings. |
|
43 | + * @deprecated $VID:$ |
|
44 | + */ |
|
45 | + public function registerScriptI18n($handle, $domain = Domain::TEXT_DOMAIN) |
|
46 | + { |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param array $handles Array of registered script handles. |
|
51 | - * @return array |
|
52 | - * @deprecated $VID:$ |
|
53 | - */ |
|
54 | - public function queueI18n(array $handles) |
|
55 | - { |
|
56 | - return $handles; |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param array $handles Array of registered script handles. |
|
51 | + * @return array |
|
52 | + * @deprecated $VID:$ |
|
53 | + */ |
|
54 | + public function queueI18n(array $handles) |
|
55 | + { |
|
56 | + return $handles; |
|
57 | + } |
|
58 | 58 | } |
@@ -16,30 +16,30 @@ |
||
16 | 16 | */ |
17 | 17 | class CoreBlocksAssetManager extends BlockAssetManager |
18 | 18 | { |
19 | - const DOMAIN = 'blocks'; |
|
20 | - |
|
21 | - const ASSET_HANDLE_CORE_BLOCKS = Domain::ASSET_NAMESPACE . '-' . CoreBlocksAssetManager::DOMAIN; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @since $VID:$ |
|
26 | - * @throws DomainException |
|
27 | - */ |
|
28 | - public function enqueueEventEditor() |
|
29 | - { |
|
30 | - if ($this->verifyAssetIsRegistered(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS)) { |
|
31 | - wp_enqueue_script(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
32 | - wp_enqueue_style(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
33 | - } |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @since 4.9.71.p |
|
39 | - */ |
|
40 | - public function setAssetHandles() |
|
41 | - { |
|
42 | - $this->setEditorScriptHandle(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
43 | - $this->setScriptHandle(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
44 | - } |
|
19 | + const DOMAIN = 'blocks'; |
|
20 | + |
|
21 | + const ASSET_HANDLE_CORE_BLOCKS = Domain::ASSET_NAMESPACE . '-' . CoreBlocksAssetManager::DOMAIN; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @since $VID:$ |
|
26 | + * @throws DomainException |
|
27 | + */ |
|
28 | + public function enqueueEventEditor() |
|
29 | + { |
|
30 | + if ($this->verifyAssetIsRegistered(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS)) { |
|
31 | + wp_enqueue_script(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
32 | + wp_enqueue_style(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
33 | + } |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @since 4.9.71.p |
|
39 | + */ |
|
40 | + public function setAssetHandles() |
|
41 | + { |
|
42 | + $this->setEditorScriptHandle(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
43 | + $this->setScriptHandle(CoreBlocksAssetManager::ASSET_HANDLE_CORE_BLOCKS); |
|
44 | + } |
|
45 | 45 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | const DOMAIN = 'blocks'; |
20 | 20 | |
21 | - const ASSET_HANDLE_CORE_BLOCKS = Domain::ASSET_NAMESPACE . '-' . CoreBlocksAssetManager::DOMAIN; |
|
21 | + const ASSET_HANDLE_CORE_BLOCKS = Domain::ASSET_NAMESPACE.'-'.CoreBlocksAssetManager::DOMAIN; |
|
22 | 22 | |
23 | 23 | |
24 | 24 | /** |
@@ -21,49 +21,49 @@ |
||
21 | 21 | class EventEspressoData extends PrimaryJsonDataNode |
22 | 22 | { |
23 | 23 | |
24 | - const NODE_NAME = 'eventEspressoData'; |
|
24 | + const NODE_NAME = 'eventEspressoData'; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var Api $api |
|
28 | - */ |
|
29 | - private $api; |
|
26 | + /** |
|
27 | + * @var Api $api |
|
28 | + */ |
|
29 | + private $api; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var Config $config |
|
33 | - */ |
|
34 | - private $config; |
|
31 | + /** |
|
32 | + * @var Config $config |
|
33 | + */ |
|
34 | + private $config; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var JedLocaleData $jed_locale |
|
38 | - */ |
|
39 | - private $jed_locale; |
|
36 | + /** |
|
37 | + * @var JedLocaleData $jed_locale |
|
38 | + */ |
|
39 | + private $jed_locale; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @param Api $api |
|
44 | - * @param Config $config |
|
45 | - * @param JedLocaleData $jed_locale |
|
46 | - * @param JsonDataNodeValidator $validator |
|
47 | - */ |
|
48 | - public function __construct(Api $api, Config $config, JedLocaleData $jed_locale, JsonDataNodeValidator $validator) |
|
49 | - { |
|
50 | - parent::__construct($validator); |
|
51 | - $this->api = $api; |
|
52 | - $this->config = $config; |
|
53 | - $this->jed_locale = $jed_locale; |
|
54 | - $this->setNodeName(EventEspressoData::NODE_NAME); |
|
55 | - } |
|
42 | + /** |
|
43 | + * @param Api $api |
|
44 | + * @param Config $config |
|
45 | + * @param JedLocaleData $jed_locale |
|
46 | + * @param JsonDataNodeValidator $validator |
|
47 | + */ |
|
48 | + public function __construct(Api $api, Config $config, JedLocaleData $jed_locale, JsonDataNodeValidator $validator) |
|
49 | + { |
|
50 | + parent::__construct($validator); |
|
51 | + $this->api = $api; |
|
52 | + $this->config = $config; |
|
53 | + $this->jed_locale = $jed_locale; |
|
54 | + $this->setNodeName(EventEspressoData::NODE_NAME); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * @throws DomainException |
|
60 | - * @since $VID:$ |
|
61 | - */ |
|
62 | - public function initialize() |
|
63 | - { |
|
64 | - $this->addDataNode($this->api); |
|
65 | - $this->addDataNode($this->config); |
|
66 | - $this->addData('i18n', $this->jed_locale->getData(Domain::TEXT_DOMAIN)); |
|
67 | - $this->setInitialized(true); |
|
68 | - } |
|
58 | + /** |
|
59 | + * @throws DomainException |
|
60 | + * @since $VID:$ |
|
61 | + */ |
|
62 | + public function initialize() |
|
63 | + { |
|
64 | + $this->addDataNode($this->api); |
|
65 | + $this->addDataNode($this->config); |
|
66 | + $this->addData('i18n', $this->jed_locale->getData(Domain::TEXT_DOMAIN)); |
|
67 | + $this->setInitialized(true); |
|
68 | + } |
|
69 | 69 | } |
@@ -18,172 +18,172 @@ |
||
18 | 18 | class JavascriptAsset extends BrowserAsset |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var boolean $load_in_footer |
|
23 | - */ |
|
24 | - private $load_in_footer = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var boolean $requires_translation |
|
28 | - */ |
|
29 | - private $requires_translation = false; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var boolean $has_inline_data |
|
33 | - */ |
|
34 | - private $has_inline_data = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Closure $inline_data_callback |
|
38 | - */ |
|
39 | - private $inline_data_callback; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Asset constructor. |
|
44 | - * |
|
45 | - * @param string $handle |
|
46 | - * @param string $source |
|
47 | - * @param array $dependencies |
|
48 | - * @param bool $load_in_footer |
|
49 | - * @param DomainInterface $domain |
|
50 | - * @param string $version |
|
51 | - * @throws InvalidDataTypeException |
|
52 | - * @throws DomainException |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - $handle, |
|
56 | - $source, |
|
57 | - array $dependencies, |
|
58 | - $load_in_footer, |
|
59 | - DomainInterface $domain, |
|
60 | - $version = '' |
|
61 | - ) { |
|
62 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | - $this->setLoadInFooter($load_in_footer); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function loadInFooter() |
|
71 | - { |
|
72 | - return $this->load_in_footer; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param bool $load_in_footer |
|
78 | - */ |
|
79 | - private function setLoadInFooter($load_in_footer = true) |
|
80 | - { |
|
81 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function requiresTranslation() |
|
89 | - { |
|
90 | - return $this->requires_translation; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasInlineData() |
|
98 | - { |
|
99 | - return $this->has_inline_data; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param bool $has_inline_data |
|
105 | - * @return JavascriptAsset |
|
106 | - */ |
|
107 | - public function setHasInlineData($has_inline_data = true) |
|
108 | - { |
|
109 | - $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return Closure |
|
116 | - */ |
|
117 | - public function inlineDataCallback() |
|
118 | - { |
|
119 | - return $this->inline_data_callback; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function hasInlineDataCallback() |
|
127 | - { |
|
128 | - return $this->inline_data_callback instanceof Closure; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param Closure $inline_data_callback |
|
134 | - * @return JavascriptAsset |
|
135 | - */ |
|
136 | - public function setInlineDataCallback(Closure $inline_data_callback) |
|
137 | - { |
|
138 | - $this->inline_data_callback = $inline_data_callback; |
|
139 | - $this->setHasInlineData(); |
|
140 | - return $this; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @since 4.9.62.p |
|
146 | - */ |
|
147 | - public function enqueueAsset() |
|
148 | - { |
|
149 | - if ($this->source() === '') { |
|
150 | - return; |
|
151 | - } |
|
152 | - $attributes = $this->getAttributes(); |
|
153 | - if (!empty($attributes)) { |
|
154 | - add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | - } |
|
156 | - wp_enqueue_script($this->handle()); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function addAttributeTagsToScript($tag, $handle) |
|
161 | - { |
|
162 | - if ($handle === $this->handle()) { |
|
163 | - $attributes = $this->getAttributes(); |
|
164 | - $attributes_string = ''; |
|
165 | - foreach ($attributes as $key => $value) { |
|
166 | - if (is_int($key)) { |
|
167 | - $attributes_string .= " {$value}"; |
|
168 | - } else { |
|
169 | - $attributes_string .= " {$key}='{$value}'"; |
|
170 | - } |
|
171 | - } |
|
172 | - $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | - } |
|
174 | - |
|
175 | - return $tag; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @deprecated $VID:$ |
|
181 | - * @param bool $requires_translation |
|
182 | - * @return JavascriptAsset |
|
183 | - */ |
|
184 | - public function setRequiresTranslation($requires_translation = true) |
|
185 | - { |
|
186 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | - return $this; |
|
188 | - } |
|
21 | + /** |
|
22 | + * @var boolean $load_in_footer |
|
23 | + */ |
|
24 | + private $load_in_footer = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var boolean $requires_translation |
|
28 | + */ |
|
29 | + private $requires_translation = false; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var boolean $has_inline_data |
|
33 | + */ |
|
34 | + private $has_inline_data = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Closure $inline_data_callback |
|
38 | + */ |
|
39 | + private $inline_data_callback; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Asset constructor. |
|
44 | + * |
|
45 | + * @param string $handle |
|
46 | + * @param string $source |
|
47 | + * @param array $dependencies |
|
48 | + * @param bool $load_in_footer |
|
49 | + * @param DomainInterface $domain |
|
50 | + * @param string $version |
|
51 | + * @throws InvalidDataTypeException |
|
52 | + * @throws DomainException |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + $handle, |
|
56 | + $source, |
|
57 | + array $dependencies, |
|
58 | + $load_in_footer, |
|
59 | + DomainInterface $domain, |
|
60 | + $version = '' |
|
61 | + ) { |
|
62 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | + $this->setLoadInFooter($load_in_footer); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function loadInFooter() |
|
71 | + { |
|
72 | + return $this->load_in_footer; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param bool $load_in_footer |
|
78 | + */ |
|
79 | + private function setLoadInFooter($load_in_footer = true) |
|
80 | + { |
|
81 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function requiresTranslation() |
|
89 | + { |
|
90 | + return $this->requires_translation; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasInlineData() |
|
98 | + { |
|
99 | + return $this->has_inline_data; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param bool $has_inline_data |
|
105 | + * @return JavascriptAsset |
|
106 | + */ |
|
107 | + public function setHasInlineData($has_inline_data = true) |
|
108 | + { |
|
109 | + $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return Closure |
|
116 | + */ |
|
117 | + public function inlineDataCallback() |
|
118 | + { |
|
119 | + return $this->inline_data_callback; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function hasInlineDataCallback() |
|
127 | + { |
|
128 | + return $this->inline_data_callback instanceof Closure; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param Closure $inline_data_callback |
|
134 | + * @return JavascriptAsset |
|
135 | + */ |
|
136 | + public function setInlineDataCallback(Closure $inline_data_callback) |
|
137 | + { |
|
138 | + $this->inline_data_callback = $inline_data_callback; |
|
139 | + $this->setHasInlineData(); |
|
140 | + return $this; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @since 4.9.62.p |
|
146 | + */ |
|
147 | + public function enqueueAsset() |
|
148 | + { |
|
149 | + if ($this->source() === '') { |
|
150 | + return; |
|
151 | + } |
|
152 | + $attributes = $this->getAttributes(); |
|
153 | + if (!empty($attributes)) { |
|
154 | + add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | + } |
|
156 | + wp_enqueue_script($this->handle()); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function addAttributeTagsToScript($tag, $handle) |
|
161 | + { |
|
162 | + if ($handle === $this->handle()) { |
|
163 | + $attributes = $this->getAttributes(); |
|
164 | + $attributes_string = ''; |
|
165 | + foreach ($attributes as $key => $value) { |
|
166 | + if (is_int($key)) { |
|
167 | + $attributes_string .= " {$value}"; |
|
168 | + } else { |
|
169 | + $attributes_string .= " {$key}='{$value}'"; |
|
170 | + } |
|
171 | + } |
|
172 | + $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | + } |
|
174 | + |
|
175 | + return $tag; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @deprecated $VID:$ |
|
181 | + * @param bool $requires_translation |
|
182 | + * @return JavascriptAsset |
|
183 | + */ |
|
184 | + public function setRequiresTranslation($requires_translation = true) |
|
185 | + { |
|
186 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | + return $this; |
|
188 | + } |
|
189 | 189 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | return; |
151 | 151 | } |
152 | 152 | $attributes = $this->getAttributes(); |
153 | - if (!empty($attributes)) { |
|
153 | + if ( ! empty($attributes)) { |
|
154 | 154 | add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
155 | 155 | } |
156 | 156 | wp_enqueue_script($this->handle()); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $attributes_string .= " {$key}='{$value}'"; |
170 | 170 | } |
171 | 171 | } |
172 | - $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
172 | + $tag = str_replace('></script>', $attributes_string.'></script>', $tag); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $tag; |