Completed
Branch BUG-10375-migrations-not-repor... (1e9646)
by
unknown
62:53 queued 49:42
created
core/services/container/CoffeeShop.php 1 patch
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 use OutOfBoundsException;
14 14
 
15 15
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
16
-    exit('No direct script access allowed');
16
+	exit('No direct script access allowed');
17 17
 }
18 18
 
19 19
 
@@ -32,502 +32,502 @@  discard block
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * This was the best coffee related name I could think of to represent class name "aliases"
37
-     * So classes can be found via an alias identifier,
38
-     * that is revealed when it is run through... the filters... eh? get it?
39
-     *
40
-     * @var array $filters
41
-     */
42
-    private $filters = array();
43
-
44
-    /**
45
-     * These are the classes that will actually build the objects (to order of course)
46
-     *
47
-     * @var array $coffee_makers
48
-     */
49
-    private $coffee_makers = array();
50
-
51
-    /**
52
-     * where the instantiated "singleton" objects are stored
53
-     *
54
-     * @var CollectionInterface $carafe
55
-     */
56
-    private $carafe;
57
-
58
-    /**
59
-     * collection of Recipes that instruct us how to brew objects
60
-     *
61
-     * @var CollectionInterface $recipes
62
-     */
63
-    private $recipes;
64
-
65
-    /**
66
-     * collection of closures for brewing objects
67
-     *
68
-     * @var CollectionInterface $reservoir
69
-     */
70
-    private $reservoir;
71
-
72
-
73
-
74
-    /**
75
-     * CoffeeShop constructor
76
-     */
77
-    public function __construct()
78
-    {
79
-        // array for storing class aliases
80
-        $this->filters = array();
81
-        // create collection for storing shared services
82
-        $this->carafe = new LooseCollection( '' );
83
-        // create collection for storing recipes that tell how to build services and entities
84
-        $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
-        // create collection for storing closures for constructing new entities
86
-        $this->reservoir = new Collection('Closure');
87
-        // create collection for storing the generators that build our services and entity closures
88
-        $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Returns true if the container can return an entry for the given identifier.
95
-     * Returns false otherwise.
96
-     * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
-     * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
-     *
99
-     * @param string $identifier  Identifier of the entry to look for.
100
-     *                            Typically a Fully Qualified Class Name
101
-     * @return boolean
102
-     */
103
-    public function has($identifier)
104
-    {
105
-        $identifier = $this->filterIdentifier($identifier);
106
-        return $this->carafe->has($identifier);
107
-    }
108
-
109
-
110
-
111
-    /**
112
-     * finds a previously brewed (SHARED) service and returns it
113
-     *
114
-     * @param  string $identifier Identifier for the entity class to be constructed.
115
-     *                            Typically a Fully Qualified Class Name
116
-     * @return mixed
117
-     * @throws ServiceNotFoundException No service was found for this identifier.
118
-     */
119
-    public function get($identifier)
120
-    {
121
-        $identifier = $this->filterIdentifier($identifier);
122
-        if ($this->carafe->has($identifier)) {
123
-            return $this->carafe->get($identifier);
124
-        }
125
-        throw new ServiceNotFoundException($identifier);
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * returns an instance of the requested entity type using the supplied arguments.
132
-     * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
-     * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
-     * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
-     * then a new entity will be instantiated from the closure and returned.
136
-     * If a closure does not exist, then one will be built and added to the reservoir
137
-     * before instantiating the requested entity.
138
-     *
139
-     * @param  string $identifier Identifier for the entity class to be constructed.
140
-     *                            Typically a Fully Qualified Class Name
141
-     * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
-     * @param string  $type
143
-     * @return mixed
144
-     * @throws ServiceNotFoundException No service was found for this identifier.
145
-     */
146
-    public function brew($identifier, $arguments = array(), $type = '')
147
-    {
148
-        // resolve any class aliases that may exist
149
-        $identifier = $this->filterIdentifier($identifier);
150
-        try {
151
-            // is a shared service being requested?
152
-            if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
-                // if a shared service was requested and an instance is in the carafe, then return it
154
-                return $this->get($identifier);
155
-            }
156
-        } catch (ServiceNotFoundException $e) {
157
-            // if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
-            // and instead, attempt to build whatever was requested
159
-        }
160
-        $brewed = false;
161
-        // if the reservoir doesn't have a closure already for the requested identifier,
162
-        // then neither a shared service nor a closure for making entities has been built yet
163
-        if ( ! $this->reservoir->has($identifier)) {
164
-            // so let's brew something up and add it to the proper collection
165
-            $brewed = $this->makeCoffee($identifier, $arguments, $type);
166
-        }
167
-        // was the brewed item a callable factory function ?
168
-        if (is_callable($brewed)) {
169
-            // then instantiate a new entity from the cached closure
170
-            $entity = $brewed($arguments);
171
-        } else if ($brewed) {
172
-            // requested object was a shared entity, so attempt to get it from the carafe again
173
-            // because if it wasn't there before, then it should have just been brewed and added,
174
-            // but if it still isn't there, then this time
175
-            // the thrown ServiceNotFoundException will not be caught
176
-            $entity = $this->get($identifier);
177
-        } else {
178
-            // if identifier is for a non-shared entity,
179
-            // then either a cached closure already existed, or was just brewed
180
-            $closure = $this->reservoir->get($identifier);
181
-            $entity = $closure($arguments);
182
-        }
183
-        return $entity;
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param CoffeeMakerInterface $coffee_maker
190
-     * @param string               $type
191
-     * @return bool
192
-     */
193
-    public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
-    {
195
-        $type = CoffeeMaker::validateType($type);
196
-        return $this->coffee_makers->add($coffee_maker, $type);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * @param string   $identifier
203
-     * @param callable $closure
204
-     * @return callable|null
205
-     */
206
-    public function addClosure($identifier, $closure)
207
-    {
208
-        if ( ! is_callable($closure)) {
209
-            throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
-        }
211
-        $identifier = $this->processIdentifier($identifier);
212
-        if ($this->reservoir->add($closure, $identifier)) {
213
-            return $closure;
214
-        }
215
-        return null;
216
-    }
217
-
218
-
219
-
220
-    /**
221
-     * @param string   $identifier
222
-     * @return boolean
223
-     */
224
-    public function removeClosure($identifier)
225
-    {
226
-        $identifier = $this->processIdentifier($identifier);
227
-        if ($this->reservoir->has($identifier)) {
228
-            $this->reservoir->remove($this->reservoir->get($identifier));
229
-            if ( ! $this->reservoir->has($identifier)) {
230
-                return true;
231
-            }
232
-        }
233
-        return false;
234
-    }
235
-
236
-
237
-
238
-    /**
239
-     * @param  string $identifier Identifier for the entity class that the service applies to
240
-     *                            Typically a Fully Qualified Class Name
241
-     * @param mixed  $service
242
-     * @return bool
243
-     */
244
-    public function addService($identifier, $service)
245
-    {
246
-        $identifier = $this->processIdentifier($identifier);
247
-        $service = $this->validateService($identifier, $service);
248
-        return $this->carafe->add($service, $identifier);
249
-    }
250
-
251
-
252
-
253
-    /**
254
-     * @param string $identifier
255
-     * @return boolean
256
-     */
257
-    public function removeService($identifier)
258
-    {
259
-        $identifier = $this->processIdentifier($identifier);
260
-        if ($this->carafe->has($identifier)) {
261
-            $this->carafe->remove($this->carafe->get($identifier));
262
-            if ( ! $this->carafe->has($identifier)) {
263
-                return true;
264
-            }
265
-        }
266
-        return false;
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * Adds instructions on how to brew objects
273
-     *
274
-     * @param RecipeInterface $recipe
275
-     * @return mixed
276
-     */
277
-    public function addRecipe(RecipeInterface $recipe)
278
-    {
279
-        $this->addAliases($recipe->identifier(), $recipe->filters());
280
-        $identifier = $this->processIdentifier($recipe->identifier());
281
-        return $this->recipes->add($recipe, $identifier);
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param string $identifier The Recipe's identifier
288
-     * @return boolean
289
-     */
290
-    public function removeRecipe($identifier)
291
-    {
292
-        $identifier = $this->processIdentifier($identifier);
293
-        if ($this->recipes->has($identifier)) {
294
-            $this->recipes->remove(
295
-                $this->recipes->get($identifier)
296
-            );
297
-            if ( ! $this->recipes->has($identifier)) {
298
-                return true;
299
-            }
300
-        }
301
-        return false;
302
-    }
303
-
304
-
305
-
306
-    /**
307
-     * Get instructions on how to brew objects
308
-     *
309
-     * @param  string $identifier Identifier for the entity class that the recipe applies to
310
-     *                            Typically a Fully Qualified Class Name
311
-     * @param string $type
312
-     * @return RecipeInterface
313
-     */
314
-    public function getRecipe($identifier, $type = '')
315
-    {
316
-        $identifier = $this->processIdentifier($identifier);
317
-        if ($this->recipes->has($identifier)) {
318
-            return $this->recipes->get($identifier);
319
-        }
320
-        $default_recipes = $this->getDefaultRecipes();
321
-        $matches = array();
322
-        foreach ($default_recipes as $wildcard => $default_recipe) {
323
-            // is the wildcard recipe prefix in the identifier ?
324
-            if (strpos($identifier, $wildcard) !== false) {
325
-                // track matches and use the number of wildcard characters matched for the key
326
-                $matches[strlen($wildcard)] = $default_recipe;
327
-            }
328
-        }
329
-        if (count($matches) > 0) {
330
-            // sort our recipes by the number of wildcard characters matched
331
-            ksort($matches);
332
-            // then grab the last recipe form the list, since it had the most matching characters
333
-            $match = array_pop($matches);
334
-            // since we are using a default recipe, we need to set it's identifier and fqcn
335
-            return $this->copyDefaultRecipe($match, $identifier, $type);
336
-        }
337
-        if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
-            // since we are using a default recipe, we need to set it's identifier and fqcn
339
-            return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
-        }
341
-        throw new OutOfBoundsException(
342
-            sprintf(
343
-                __('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
-                $identifier
345
-            )
346
-        );
347
-    }
348
-
349
-
350
-
351
-    /**
352
-     * adds class name aliases to list of filters
353
-     *
354
-     * @param  string $identifier Identifier for the entity class that the alias applies to
355
-     *                            Typically a Fully Qualified Class Name
356
-     * @param  array  $aliases
357
-     * @return void
358
-     * @throws InvalidIdentifierException
359
-     */
360
-    public function addAliases($identifier, $aliases)
361
-    {
362
-        if (empty($aliases)) {
363
-            return;
364
-        }
365
-        $identifier = $this->processIdentifier($identifier);
366
-        foreach ((array)$aliases as $alias) {
367
-            $this->filters[$this->processIdentifier($alias)] = $identifier;
368
-        }
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Adds a service to one of the internal collections
375
-     *
376
-     * @param        $identifier
377
-     * @param array  $arguments
378
-     * @param string $type
379
-     * @return mixed
380
-     * @throws ServiceExistsException
381
-     */
382
-    private function makeCoffee($identifier, $arguments = array(), $type = '')
383
-    {
384
-        if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
-            throw new ServiceExistsException($identifier);
386
-        }
387
-        $identifier = $this->filterIdentifier($identifier);
388
-        $recipe = $this->getRecipe($identifier, $type);
389
-        $type = ! empty($type) ? $type : $recipe->type();
390
-        $coffee_maker = $this->getCoffeeMaker($type);
391
-        return $coffee_maker->brew($recipe, $arguments);
392
-    }
393
-
394
-
395
-
396
-    /**
397
-     * filters alias identifiers to find the real class name
398
-     *
399
-     * @param  string $identifier Identifier for the entity class that the filter applies to
400
-     *                            Typically a Fully Qualified Class Name
401
-     * @return string
402
-     * @throws InvalidIdentifierException
403
-     */
404
-    private function filterIdentifier($identifier)
405
-    {
406
-        $identifier = $this->processIdentifier($identifier);
407
-        return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
-            ? $this->filters[$identifier]
409
-            : $identifier;
410
-    }
411
-
412
-
413
-
414
-    /**
415
-     * verifies and standardizes identifiers
416
-     *
417
-     * @param  string $identifier Identifier for the entity class
418
-     *                            Typically a Fully Qualified Class Name
419
-     * @return string
420
-     * @throws InvalidIdentifierException
421
-     */
422
-    private function processIdentifier($identifier)
423
-    {
424
-        if ( ! is_string($identifier)) {
425
-            throw new InvalidIdentifierException(
426
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
-                '\Fully\Qualified\ClassName'
428
-            );
429
-        }
430
-        return ltrim($identifier, '\\');
431
-    }
432
-
433
-
434
-
435
-    /**
436
-     * @param string $type
437
-     * @return CoffeeMakerInterface
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidClassException
440
-     */
441
-    private function getCoffeeMaker($type)
442
-    {
443
-        if ( ! $this->coffee_makers->has($type)) {
444
-            throw new OutOfBoundsException(
445
-                __('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
-            );
447
-        }
448
-        return $this->coffee_makers->get($type);
449
-    }
450
-
451
-
452
-
453
-    /**
454
-     * Retrieves all recipes that use a wildcard "*" in their identifier
455
-     * This allows recipes to be set up for handling
456
-     * legacy classes that do not support PSR-4 autoloading.
457
-     * for example:
458
-     * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
-     *
460
-     * @return array
461
-     */
462
-    private function getDefaultRecipes()
463
-    {
464
-        $default_recipes = array();
465
-        $this->recipes->rewind();
466
-        while ($this->recipes->valid()) {
467
-            $identifier = $this->recipes->getInfo();
468
-            // does this recipe use a wildcard ? (but is NOT the global default)
469
-            if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
-                // strip the wildcard and use identifier as key
471
-                $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
-            }
473
-            $this->recipes->next();
474
-        }
475
-        return $default_recipes;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * clones a default recipe and then copies details
482
-     * from the incoming request to it so that it can be used
483
-     *
484
-     * @param RecipeInterface $default_recipe
485
-     * @param string          $identifier
486
-     * @param string          $type
487
-     * @return RecipeInterface
488
-     */
489
-    private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
-    {
491
-        $recipe = clone $default_recipe;
492
-        if ( ! empty($type)) {
493
-            $recipe->setType($type);
494
-        }
495
-        // is this the base default recipe ?
496
-        if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
-            $recipe->setIdentifier($identifier);
498
-            $recipe->setFqcn($identifier);
499
-            return $recipe;
500
-        }
501
-        $recipe->setIdentifier($identifier);
502
-        foreach ($default_recipe->paths() as $path) {
503
-            $path = str_replace('*', $identifier, $path);
504
-            if (is_readable($path)) {
505
-                $recipe->setPaths($path);
506
-            }
507
-        }
508
-        $recipe->setFqcn($identifier);
509
-        return $recipe;
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * @param  string $identifier Identifier for the entity class that the service applies to
516
-     *                            Typically a Fully Qualified Class Name
517
-     * @param mixed  $service
518
-     * @return object
519
-     * @throws InvalidServiceException
520
-     */
521
-    private function validateService($identifier, $service)
522
-    {
523
-        if ( ! is_object($service)) {
524
-            throw new InvalidServiceException(
525
-                $identifier,
526
-                $service
527
-            );
528
-        }
529
-        return $service;
530
-    }
35
+	/**
36
+	 * This was the best coffee related name I could think of to represent class name "aliases"
37
+	 * So classes can be found via an alias identifier,
38
+	 * that is revealed when it is run through... the filters... eh? get it?
39
+	 *
40
+	 * @var array $filters
41
+	 */
42
+	private $filters = array();
43
+
44
+	/**
45
+	 * These are the classes that will actually build the objects (to order of course)
46
+	 *
47
+	 * @var array $coffee_makers
48
+	 */
49
+	private $coffee_makers = array();
50
+
51
+	/**
52
+	 * where the instantiated "singleton" objects are stored
53
+	 *
54
+	 * @var CollectionInterface $carafe
55
+	 */
56
+	private $carafe;
57
+
58
+	/**
59
+	 * collection of Recipes that instruct us how to brew objects
60
+	 *
61
+	 * @var CollectionInterface $recipes
62
+	 */
63
+	private $recipes;
64
+
65
+	/**
66
+	 * collection of closures for brewing objects
67
+	 *
68
+	 * @var CollectionInterface $reservoir
69
+	 */
70
+	private $reservoir;
71
+
72
+
73
+
74
+	/**
75
+	 * CoffeeShop constructor
76
+	 */
77
+	public function __construct()
78
+	{
79
+		// array for storing class aliases
80
+		$this->filters = array();
81
+		// create collection for storing shared services
82
+		$this->carafe = new LooseCollection( '' );
83
+		// create collection for storing recipes that tell how to build services and entities
84
+		$this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
85
+		// create collection for storing closures for constructing new entities
86
+		$this->reservoir = new Collection('Closure');
87
+		// create collection for storing the generators that build our services and entity closures
88
+		$this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Returns true if the container can return an entry for the given identifier.
95
+	 * Returns false otherwise.
96
+	 * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
97
+	 * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
98
+	 *
99
+	 * @param string $identifier  Identifier of the entry to look for.
100
+	 *                            Typically a Fully Qualified Class Name
101
+	 * @return boolean
102
+	 */
103
+	public function has($identifier)
104
+	{
105
+		$identifier = $this->filterIdentifier($identifier);
106
+		return $this->carafe->has($identifier);
107
+	}
108
+
109
+
110
+
111
+	/**
112
+	 * finds a previously brewed (SHARED) service and returns it
113
+	 *
114
+	 * @param  string $identifier Identifier for the entity class to be constructed.
115
+	 *                            Typically a Fully Qualified Class Name
116
+	 * @return mixed
117
+	 * @throws ServiceNotFoundException No service was found for this identifier.
118
+	 */
119
+	public function get($identifier)
120
+	{
121
+		$identifier = $this->filterIdentifier($identifier);
122
+		if ($this->carafe->has($identifier)) {
123
+			return $this->carafe->get($identifier);
124
+		}
125
+		throw new ServiceNotFoundException($identifier);
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * returns an instance of the requested entity type using the supplied arguments.
132
+	 * If a shared service is requested and an instance is already in the carafe, then it will be returned.
133
+	 * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
134
+	 * If the request is for a new entity and a closure exists in the reservoir for creating it,
135
+	 * then a new entity will be instantiated from the closure and returned.
136
+	 * If a closure does not exist, then one will be built and added to the reservoir
137
+	 * before instantiating the requested entity.
138
+	 *
139
+	 * @param  string $identifier Identifier for the entity class to be constructed.
140
+	 *                            Typically a Fully Qualified Class Name
141
+	 * @param array   $arguments  an array of arguments to be passed to the entity constructor
142
+	 * @param string  $type
143
+	 * @return mixed
144
+	 * @throws ServiceNotFoundException No service was found for this identifier.
145
+	 */
146
+	public function brew($identifier, $arguments = array(), $type = '')
147
+	{
148
+		// resolve any class aliases that may exist
149
+		$identifier = $this->filterIdentifier($identifier);
150
+		try {
151
+			// is a shared service being requested?
152
+			if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
153
+				// if a shared service was requested and an instance is in the carafe, then return it
154
+				return $this->get($identifier);
155
+			}
156
+		} catch (ServiceNotFoundException $e) {
157
+			// if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
158
+			// and instead, attempt to build whatever was requested
159
+		}
160
+		$brewed = false;
161
+		// if the reservoir doesn't have a closure already for the requested identifier,
162
+		// then neither a shared service nor a closure for making entities has been built yet
163
+		if ( ! $this->reservoir->has($identifier)) {
164
+			// so let's brew something up and add it to the proper collection
165
+			$brewed = $this->makeCoffee($identifier, $arguments, $type);
166
+		}
167
+		// was the brewed item a callable factory function ?
168
+		if (is_callable($brewed)) {
169
+			// then instantiate a new entity from the cached closure
170
+			$entity = $brewed($arguments);
171
+		} else if ($brewed) {
172
+			// requested object was a shared entity, so attempt to get it from the carafe again
173
+			// because if it wasn't there before, then it should have just been brewed and added,
174
+			// but if it still isn't there, then this time
175
+			// the thrown ServiceNotFoundException will not be caught
176
+			$entity = $this->get($identifier);
177
+		} else {
178
+			// if identifier is for a non-shared entity,
179
+			// then either a cached closure already existed, or was just brewed
180
+			$closure = $this->reservoir->get($identifier);
181
+			$entity = $closure($arguments);
182
+		}
183
+		return $entity;
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param CoffeeMakerInterface $coffee_maker
190
+	 * @param string               $type
191
+	 * @return bool
192
+	 */
193
+	public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
194
+	{
195
+		$type = CoffeeMaker::validateType($type);
196
+		return $this->coffee_makers->add($coffee_maker, $type);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * @param string   $identifier
203
+	 * @param callable $closure
204
+	 * @return callable|null
205
+	 */
206
+	public function addClosure($identifier, $closure)
207
+	{
208
+		if ( ! is_callable($closure)) {
209
+			throw new InvalidDataTypeException('$closure', $closure, 'Closure');
210
+		}
211
+		$identifier = $this->processIdentifier($identifier);
212
+		if ($this->reservoir->add($closure, $identifier)) {
213
+			return $closure;
214
+		}
215
+		return null;
216
+	}
217
+
218
+
219
+
220
+	/**
221
+	 * @param string   $identifier
222
+	 * @return boolean
223
+	 */
224
+	public function removeClosure($identifier)
225
+	{
226
+		$identifier = $this->processIdentifier($identifier);
227
+		if ($this->reservoir->has($identifier)) {
228
+			$this->reservoir->remove($this->reservoir->get($identifier));
229
+			if ( ! $this->reservoir->has($identifier)) {
230
+				return true;
231
+			}
232
+		}
233
+		return false;
234
+	}
235
+
236
+
237
+
238
+	/**
239
+	 * @param  string $identifier Identifier for the entity class that the service applies to
240
+	 *                            Typically a Fully Qualified Class Name
241
+	 * @param mixed  $service
242
+	 * @return bool
243
+	 */
244
+	public function addService($identifier, $service)
245
+	{
246
+		$identifier = $this->processIdentifier($identifier);
247
+		$service = $this->validateService($identifier, $service);
248
+		return $this->carafe->add($service, $identifier);
249
+	}
250
+
251
+
252
+
253
+	/**
254
+	 * @param string $identifier
255
+	 * @return boolean
256
+	 */
257
+	public function removeService($identifier)
258
+	{
259
+		$identifier = $this->processIdentifier($identifier);
260
+		if ($this->carafe->has($identifier)) {
261
+			$this->carafe->remove($this->carafe->get($identifier));
262
+			if ( ! $this->carafe->has($identifier)) {
263
+				return true;
264
+			}
265
+		}
266
+		return false;
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * Adds instructions on how to brew objects
273
+	 *
274
+	 * @param RecipeInterface $recipe
275
+	 * @return mixed
276
+	 */
277
+	public function addRecipe(RecipeInterface $recipe)
278
+	{
279
+		$this->addAliases($recipe->identifier(), $recipe->filters());
280
+		$identifier = $this->processIdentifier($recipe->identifier());
281
+		return $this->recipes->add($recipe, $identifier);
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param string $identifier The Recipe's identifier
288
+	 * @return boolean
289
+	 */
290
+	public function removeRecipe($identifier)
291
+	{
292
+		$identifier = $this->processIdentifier($identifier);
293
+		if ($this->recipes->has($identifier)) {
294
+			$this->recipes->remove(
295
+				$this->recipes->get($identifier)
296
+			);
297
+			if ( ! $this->recipes->has($identifier)) {
298
+				return true;
299
+			}
300
+		}
301
+		return false;
302
+	}
303
+
304
+
305
+
306
+	/**
307
+	 * Get instructions on how to brew objects
308
+	 *
309
+	 * @param  string $identifier Identifier for the entity class that the recipe applies to
310
+	 *                            Typically a Fully Qualified Class Name
311
+	 * @param string $type
312
+	 * @return RecipeInterface
313
+	 */
314
+	public function getRecipe($identifier, $type = '')
315
+	{
316
+		$identifier = $this->processIdentifier($identifier);
317
+		if ($this->recipes->has($identifier)) {
318
+			return $this->recipes->get($identifier);
319
+		}
320
+		$default_recipes = $this->getDefaultRecipes();
321
+		$matches = array();
322
+		foreach ($default_recipes as $wildcard => $default_recipe) {
323
+			// is the wildcard recipe prefix in the identifier ?
324
+			if (strpos($identifier, $wildcard) !== false) {
325
+				// track matches and use the number of wildcard characters matched for the key
326
+				$matches[strlen($wildcard)] = $default_recipe;
327
+			}
328
+		}
329
+		if (count($matches) > 0) {
330
+			// sort our recipes by the number of wildcard characters matched
331
+			ksort($matches);
332
+			// then grab the last recipe form the list, since it had the most matching characters
333
+			$match = array_pop($matches);
334
+			// since we are using a default recipe, we need to set it's identifier and fqcn
335
+			return $this->copyDefaultRecipe($match, $identifier, $type);
336
+		}
337
+		if ($this->recipes->has(Recipe::DEFAULT_ID)) {
338
+			// since we are using a default recipe, we need to set it's identifier and fqcn
339
+			return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
340
+		}
341
+		throw new OutOfBoundsException(
342
+			sprintf(
343
+				__('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
344
+				$identifier
345
+			)
346
+		);
347
+	}
348
+
349
+
350
+
351
+	/**
352
+	 * adds class name aliases to list of filters
353
+	 *
354
+	 * @param  string $identifier Identifier for the entity class that the alias applies to
355
+	 *                            Typically a Fully Qualified Class Name
356
+	 * @param  array  $aliases
357
+	 * @return void
358
+	 * @throws InvalidIdentifierException
359
+	 */
360
+	public function addAliases($identifier, $aliases)
361
+	{
362
+		if (empty($aliases)) {
363
+			return;
364
+		}
365
+		$identifier = $this->processIdentifier($identifier);
366
+		foreach ((array)$aliases as $alias) {
367
+			$this->filters[$this->processIdentifier($alias)] = $identifier;
368
+		}
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Adds a service to one of the internal collections
375
+	 *
376
+	 * @param        $identifier
377
+	 * @param array  $arguments
378
+	 * @param string $type
379
+	 * @return mixed
380
+	 * @throws ServiceExistsException
381
+	 */
382
+	private function makeCoffee($identifier, $arguments = array(), $type = '')
383
+	{
384
+		if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
385
+			throw new ServiceExistsException($identifier);
386
+		}
387
+		$identifier = $this->filterIdentifier($identifier);
388
+		$recipe = $this->getRecipe($identifier, $type);
389
+		$type = ! empty($type) ? $type : $recipe->type();
390
+		$coffee_maker = $this->getCoffeeMaker($type);
391
+		return $coffee_maker->brew($recipe, $arguments);
392
+	}
393
+
394
+
395
+
396
+	/**
397
+	 * filters alias identifiers to find the real class name
398
+	 *
399
+	 * @param  string $identifier Identifier for the entity class that the filter applies to
400
+	 *                            Typically a Fully Qualified Class Name
401
+	 * @return string
402
+	 * @throws InvalidIdentifierException
403
+	 */
404
+	private function filterIdentifier($identifier)
405
+	{
406
+		$identifier = $this->processIdentifier($identifier);
407
+		return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
408
+			? $this->filters[$identifier]
409
+			: $identifier;
410
+	}
411
+
412
+
413
+
414
+	/**
415
+	 * verifies and standardizes identifiers
416
+	 *
417
+	 * @param  string $identifier Identifier for the entity class
418
+	 *                            Typically a Fully Qualified Class Name
419
+	 * @return string
420
+	 * @throws InvalidIdentifierException
421
+	 */
422
+	private function processIdentifier($identifier)
423
+	{
424
+		if ( ! is_string($identifier)) {
425
+			throw new InvalidIdentifierException(
426
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
427
+				'\Fully\Qualified\ClassName'
428
+			);
429
+		}
430
+		return ltrim($identifier, '\\');
431
+	}
432
+
433
+
434
+
435
+	/**
436
+	 * @param string $type
437
+	 * @return CoffeeMakerInterface
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidClassException
440
+	 */
441
+	private function getCoffeeMaker($type)
442
+	{
443
+		if ( ! $this->coffee_makers->has($type)) {
444
+			throw new OutOfBoundsException(
445
+				__('The requested coffee maker is either missing or invalid.', 'event_espresso')
446
+			);
447
+		}
448
+		return $this->coffee_makers->get($type);
449
+	}
450
+
451
+
452
+
453
+	/**
454
+	 * Retrieves all recipes that use a wildcard "*" in their identifier
455
+	 * This allows recipes to be set up for handling
456
+	 * legacy classes that do not support PSR-4 autoloading.
457
+	 * for example:
458
+	 * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
459
+	 *
460
+	 * @return array
461
+	 */
462
+	private function getDefaultRecipes()
463
+	{
464
+		$default_recipes = array();
465
+		$this->recipes->rewind();
466
+		while ($this->recipes->valid()) {
467
+			$identifier = $this->recipes->getInfo();
468
+			// does this recipe use a wildcard ? (but is NOT the global default)
469
+			if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
470
+				// strip the wildcard and use identifier as key
471
+				$default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
472
+			}
473
+			$this->recipes->next();
474
+		}
475
+		return $default_recipes;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * clones a default recipe and then copies details
482
+	 * from the incoming request to it so that it can be used
483
+	 *
484
+	 * @param RecipeInterface $default_recipe
485
+	 * @param string          $identifier
486
+	 * @param string          $type
487
+	 * @return RecipeInterface
488
+	 */
489
+	private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
490
+	{
491
+		$recipe = clone $default_recipe;
492
+		if ( ! empty($type)) {
493
+			$recipe->setType($type);
494
+		}
495
+		// is this the base default recipe ?
496
+		if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
497
+			$recipe->setIdentifier($identifier);
498
+			$recipe->setFqcn($identifier);
499
+			return $recipe;
500
+		}
501
+		$recipe->setIdentifier($identifier);
502
+		foreach ($default_recipe->paths() as $path) {
503
+			$path = str_replace('*', $identifier, $path);
504
+			if (is_readable($path)) {
505
+				$recipe->setPaths($path);
506
+			}
507
+		}
508
+		$recipe->setFqcn($identifier);
509
+		return $recipe;
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * @param  string $identifier Identifier for the entity class that the service applies to
516
+	 *                            Typically a Fully Qualified Class Name
517
+	 * @param mixed  $service
518
+	 * @return object
519
+	 * @throws InvalidServiceException
520
+	 */
521
+	private function validateService($identifier, $service)
522
+	{
523
+		if ( ! is_object($service)) {
524
+			throw new InvalidServiceException(
525
+				$identifier,
526
+				$service
527
+			);
528
+		}
529
+		return $service;
530
+	}
531 531
 
532 532
 }
533 533
 // End of file CoffeeShop.php
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +1406 added lines, -1406 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -31,1533 +31,1533 @@  discard block
 block discarded – undo
31 31
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
32 32
 {
33 33
     
34
-    /**
35
-     * This property is just used to hold the status of whether an event is currently being
36
-     * created (true) or edited (false)
37
-     * @access protected
38
-     * @var bool
39
-     */
40
-    protected $_is_creating_event;
34
+	/**
35
+	 * This property is just used to hold the status of whether an event is currently being
36
+	 * created (true) or edited (false)
37
+	 * @access protected
38
+	 * @var bool
39
+	 */
40
+	protected $_is_creating_event;
41 41
     
42 42
     
43
-    /**
44
-     * Used to contain the format strings for date and time that will be used for php date and
45
-     * time.
46
-     *
47
-     * Is set in the _set_hooks_properties() method.
48
-     *
49
-     * @var array
50
-     */
51
-    protected $_date_format_strings;
43
+	/**
44
+	 * Used to contain the format strings for date and time that will be used for php date and
45
+	 * time.
46
+	 *
47
+	 * Is set in the _set_hooks_properties() method.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	protected $_date_format_strings;
52 52
     
53 53
     
54
-    protected function _set_hooks_properties()
55
-    {
56
-        $this->_name = 'pricing';
57
-        
58
-        //capability check
59
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
-            'advanced_ticket_datetime_metabox')
61
-        ) {
62
-            return;
63
-        }
64
-        
65
-        
66
-        //if we were going to add our own metaboxes we'd use the below.
67
-        $this->_metaboxes = array(
68
-            0 => array(
69
-                'page_route' => array('edit', 'create_new'),
70
-                'func'       => 'pricing_metabox',
71
-                'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
-                'priority'   => 'high',
73
-                'context'    => 'normal'
74
-            ),
75
-        
76
-        );/**/
77
-        
78
-        $this->_remove_metaboxes = array(
79
-            0 => array(
80
-                'page_route' => array('edit', 'create_new'),
81
-                'id'         => 'espresso_event_editor_tickets',
82
-                'context'    => 'normal'
83
-            )
84
-        );
85
-        
86
-        /**
87
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
-         *
91
-         * @since 4.6.7
92
-         *
93
-         * @var array  Expected an array returned with 'date' and 'time' keys.
94
-         */
95
-        $this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
-            array(
97
-                'date' => 'Y-m-d',
98
-                'time' => 'h:i a'
99
-            ));
100
-        
101
-        //validate
102
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
-        
105
-        //validate format strings
106
-        $format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
-        if (is_array($format_validation)) {
108
-            $msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
-                    'event_espresso'),
110
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
-            foreach ($format_validation as $error) {
112
-                $msg .= '<li>' . $error . '</li>';
113
-            }
114
-            $msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
-                    'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
-            $this->_date_format_strings = array(
118
-                'date' => 'Y-m-d',
119
-                'time' => 'h:i a'
120
-            );
121
-        }
122
-        
123
-        
124
-        $this->_scripts_styles = array(
125
-            'registers'   => array(
126
-                'ee-tickets-datetimes-css' => array(
127
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
-                    'type' => 'css'
129
-                ),
130
-                'ee-dtt-ticket-metabox'    => array(
131
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
-                )
134
-            ),
135
-            'deregisters' => array(
136
-                'event-editor-css'       => array('type' => 'css'),
137
-                'event-datetime-metabox' => array('type' => 'js')
138
-            ),
139
-            'enqueues'    => array(
140
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
-            ),
143
-            'localize'    => array(
144
-                'ee-dtt-ticket-metabox' => array(
145
-                    'DTT_TRASH_BLOCK'       => array(
146
-                        'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
-                            'event_espresso'),
148
-                        'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
-                            'event_espresso'),
150
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
-                                'event_espresso') . '</button>',
152
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
-                                'event_espresso') . '</button>',
154
-                        'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
-                            'event_espresso'),
156
-                        'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
-                            'event_espresso'),
158
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
-                                'event_espresso') . '</button>'
160
-                    ),
161
-                    'DTT_ERROR_MSG'         => array(
162
-                        'no_ticket_name' => __('General Admission', 'event_espresso'),
163
-                        'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
-                                'event_espresso') . '</button></div>'
165
-                    ),
166
-                    'DTT_OVERSELL_WARNING'  => array(
167
-                        'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
-                            'event_espresso'),
169
-                        'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
-                            'event_espresso')
171
-                    ),
172
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
-                        $this->_date_format_strings['time']),
174
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
-                )
176
-            )
177
-        );
178
-        
179
-        
180
-        add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
-            array($this, 'autosave_handling'), 10);
182
-        add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
-            array($this, 'caf_updates'), 10);
184
-    }
54
+	protected function _set_hooks_properties()
55
+	{
56
+		$this->_name = 'pricing';
57
+        
58
+		//capability check
59
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_default_prices',
60
+			'advanced_ticket_datetime_metabox')
61
+		) {
62
+			return;
63
+		}
64
+        
65
+        
66
+		//if we were going to add our own metaboxes we'd use the below.
67
+		$this->_metaboxes = array(
68
+			0 => array(
69
+				'page_route' => array('edit', 'create_new'),
70
+				'func'       => 'pricing_metabox',
71
+				'label'      => __('Event Tickets & Datetimes', 'event_espresso'),
72
+				'priority'   => 'high',
73
+				'context'    => 'normal'
74
+			),
75
+        
76
+		);/**/
77
+        
78
+		$this->_remove_metaboxes = array(
79
+			0 => array(
80
+				'page_route' => array('edit', 'create_new'),
81
+				'id'         => 'espresso_event_editor_tickets',
82
+				'context'    => 'normal'
83
+			)
84
+		);
85
+        
86
+		/**
87
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
88
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
89
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
90
+		 *
91
+		 * @since 4.6.7
92
+		 *
93
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
94
+		 */
95
+		$this->_date_format_strings = apply_filters('FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
96
+			array(
97
+				'date' => 'Y-m-d',
98
+				'time' => 'h:i a'
99
+			));
100
+        
101
+		//validate
102
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) ? $this->_date_format_strings['date'] : null;
103
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) ? $this->_date_format_strings['time'] : null;
104
+        
105
+		//validate format strings
106
+		$format_validation = EEH_DTT_Helper::validate_format_string($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
107
+		if (is_array($format_validation)) {
108
+			$msg = '<p>' . sprintf(__('The format "%s" was likely added via a filter and is invalid for the following reasons:',
109
+					'event_espresso'),
110
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']) . '</p><ul>';
111
+			foreach ($format_validation as $error) {
112
+				$msg .= '<li>' . $error . '</li>';
113
+			}
114
+			$msg .= '</ul></p><p>' . sprintf(__('%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
115
+					'event_espresso'), '<span style="color:#D54E21;">', '</span>') . '</p>';
116
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
117
+			$this->_date_format_strings = array(
118
+				'date' => 'Y-m-d',
119
+				'time' => 'h:i a'
120
+			);
121
+		}
122
+        
123
+        
124
+		$this->_scripts_styles = array(
125
+			'registers'   => array(
126
+				'ee-tickets-datetimes-css' => array(
127
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
128
+					'type' => 'css'
129
+				),
130
+				'ee-dtt-ticket-metabox'    => array(
131
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
132
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore')
133
+				)
134
+			),
135
+			'deregisters' => array(
136
+				'event-editor-css'       => array('type' => 'css'),
137
+				'event-datetime-metabox' => array('type' => 'js')
138
+			),
139
+			'enqueues'    => array(
140
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
141
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new')
142
+			),
143
+			'localize'    => array(
144
+				'ee-dtt-ticket-metabox' => array(
145
+					'DTT_TRASH_BLOCK'       => array(
146
+						'main_warning'            => __('The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
147
+							'event_espresso'),
148
+						'after_warning'           => __('In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
149
+							'event_espresso'),
150
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">' . __('Cancel',
151
+								'event_espresso') . '</button>',
152
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">' . __('Close',
153
+								'event_espresso') . '</button>',
154
+						'single_warning_from_tkt' => __('The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
155
+							'event_espresso'),
156
+						'single_warning_from_dtt' => __('The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
157
+							'event_espresso'),
158
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">' . __('Dismiss',
159
+								'event_espresso') . '</button>'
160
+					),
161
+					'DTT_ERROR_MSG'         => array(
162
+						'no_ticket_name' => __('General Admission', 'event_espresso'),
163
+						'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' . __('Dismiss',
164
+								'event_espresso') . '</button></div>'
165
+					),
166
+					'DTT_OVERSELL_WARNING'  => array(
167
+						'datetime_ticket' => __('You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
168
+							'event_espresso'),
169
+						'ticket_datetime' => __('You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
170
+							'event_espresso')
171
+					),
172
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats($this->_date_format_strings['date'],
173
+						$this->_date_format_strings['time']),
174
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int)get_option('start_of_week'))
175
+				)
176
+			)
177
+		);
178
+        
179
+        
180
+		add_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
181
+			array($this, 'autosave_handling'), 10);
182
+		add_filter('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
183
+			array($this, 'caf_updates'), 10);
184
+	}
185 185
     
186 186
     
187
-    public function caf_updates($update_callbacks)
188
-    {
189
-        foreach ($update_callbacks as $key => $callback) {
190
-            if ($callback[1] == '_default_tickets_update') {
191
-                unset($update_callbacks[$key]);
192
-            }
193
-        }
194
-        
195
-        $update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
-        
197
-        return $update_callbacks;
198
-    }
187
+	public function caf_updates($update_callbacks)
188
+	{
189
+		foreach ($update_callbacks as $key => $callback) {
190
+			if ($callback[1] == '_default_tickets_update') {
191
+				unset($update_callbacks[$key]);
192
+			}
193
+		}
194
+        
195
+		$update_callbacks[] = array($this, 'dtt_and_tickets_caf_update');
196
+        
197
+		return $update_callbacks;
198
+	}
199 199
     
200 200
     
201
-    /**
202
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
-     *
204
-     * @param  EE_Event $evtobj The Event object we're attaching data to
205
-     * @param  array    $data   The request data from the form
206
-     *
207
-     * @return bool             success or fail
208
-     */
209
-    public function dtt_and_tickets_caf_update($evtobj, $data)
210
-    {
211
-        //first we need to start with datetimes cause they are the "root" items attached to events.
212
-        $saved_dtts = $this->_update_dtts($evtobj, $data);
213
-        //next tackle the tickets (and prices?)
214
-        $this->_update_tkts($evtobj, $saved_dtts, $data);
215
-    }
201
+	/**
202
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
203
+	 *
204
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
205
+	 * @param  array    $data   The request data from the form
206
+	 *
207
+	 * @return bool             success or fail
208
+	 */
209
+	public function dtt_and_tickets_caf_update($evtobj, $data)
210
+	{
211
+		//first we need to start with datetimes cause they are the "root" items attached to events.
212
+		$saved_dtts = $this->_update_dtts($evtobj, $data);
213
+		//next tackle the tickets (and prices?)
214
+		$this->_update_tkts($evtobj, $saved_dtts, $data);
215
+	}
216 216
     
217 217
     
218
-    /**
219
-     * update event_datetimes
220
-     *
221
-     * @param  EE_Event $evt_obj Event being updated
222
-     * @param  array    $data    the request data from the form
223
-     *
224
-     * @return EE_Datetime[]
225
-     */
226
-    protected function _update_dtts($evt_obj, $data)
227
-    {
228
-        $timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
-        $saved_dtt_ids  = array();
230
-        $saved_dtt_objs = array();
231
-        
232
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
-            //trim all values to ensure any excess whitespace is removed.
234
-            $dtt                = array_map(
235
-                function ($datetime_data) {
236
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
-                },
238
-                $dtt
239
-            );
240
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
-            $datetime_values    = array(
242
-                'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
-                'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
-                'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
-                'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
-                'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
-                'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
-                'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
-            );
218
+	/**
219
+	 * update event_datetimes
220
+	 *
221
+	 * @param  EE_Event $evt_obj Event being updated
222
+	 * @param  array    $data    the request data from the form
223
+	 *
224
+	 * @return EE_Datetime[]
225
+	 */
226
+	protected function _update_dtts($evt_obj, $data)
227
+	{
228
+		$timezone       = isset($data['timezone_string']) ? $data['timezone_string'] : null;
229
+		$saved_dtt_ids  = array();
230
+		$saved_dtt_objs = array();
231
+        
232
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
233
+			//trim all values to ensure any excess whitespace is removed.
234
+			$dtt                = array_map(
235
+				function ($datetime_data) {
236
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
237
+				},
238
+				$dtt
239
+			);
240
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start'];
241
+			$datetime_values    = array(
242
+				'DTT_ID'          => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
243
+				'DTT_name'        => ! empty($dtt['DTT_name']) ? $dtt['DTT_name'] : '',
244
+				'DTT_description' => ! empty($dtt['DTT_description']) ? $dtt['DTT_description'] : '',
245
+				'DTT_EVT_start'   => $dtt['DTT_EVT_start'],
246
+				'DTT_EVT_end'     => $dtt['DTT_EVT_end'],
247
+				'DTT_reg_limit'   => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
248
+				'DTT_order'       => ! isset($dtt['DTT_order']) ? $row : $dtt['DTT_order'],
249
+			);
250 250
             
251
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
251
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
252 252
             
253
-            if ( ! empty($dtt['DTT_ID'])) {
254
-                $DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
253
+			if ( ! empty($dtt['DTT_ID'])) {
254
+				$DTM = EE_Registry::instance()->load_model('Datetime', array($timezone))->get_one_by_ID($dtt['DTT_ID']);
255 255
                 
256
-                //set date and time format according to what is set in this class.
257
-                $DTM->set_date_format($this->_date_format_strings['date']);
258
-                $DTM->set_time_format($this->_date_format_strings['time']);
256
+				//set date and time format according to what is set in this class.
257
+				$DTM->set_date_format($this->_date_format_strings['date']);
258
+				$DTM->set_time_format($this->_date_format_strings['time']);
259 259
                 
260
-                foreach ($datetime_values as $field => $value) {
261
-                    $DTM->set($field, $value);
262
-                }
260
+				foreach ($datetime_values as $field => $value) {
261
+					$DTM->set($field, $value);
262
+				}
263 263
                 
264
-                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
-                // We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
-                $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
264
+				// make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.
265
+				// We need to do this so we dont' TRASH the parent DTT.(save the ID for both key and value to avoid duplications)
266
+				$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
267 267
                 
268
-            } else {
269
-                $DTM = EE_Registry::instance()->load_class(
270
-                    'Datetime',
271
-                    array(
272
-                        $datetime_values,
273
-                        $timezone,
274
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
-                    ),
276
-                    false,
277
-                    false
278
-                );
268
+			} else {
269
+				$DTM = EE_Registry::instance()->load_class(
270
+					'Datetime',
271
+					array(
272
+						$datetime_values,
273
+						$timezone,
274
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
275
+					),
276
+					false,
277
+					false
278
+				);
279 279
                 
280
-                foreach ($datetime_values as $field => $value) {
281
-                    $DTM->set($field, $value);
282
-                }
283
-            }
280
+				foreach ($datetime_values as $field => $value) {
281
+					$DTM->set($field, $value);
282
+				}
283
+			}
284 284
             
285 285
             
286
-            $DTM->save();
287
-            $DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
-            $evt_obj->save();
286
+			$DTM->save();
287
+			$DTM = $evt_obj->_add_relation_to($DTM, 'Datetime');
288
+			$evt_obj->save();
289 289
             
290
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
291
-            if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
-                $DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
-                $DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
-                $DTM->save();
295
-            }
290
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
291
+			if ($DTM->get_raw('DTT_EVT_start') > $DTM->get_raw('DTT_EVT_end')) {
292
+				$DTM->set('DTT_EVT_end', $DTM->get('DTT_EVT_start'));
293
+				$DTM = EEH_DTT_Helper::date_time_add($DTM, 'DTT_EVT_end', 'days');
294
+				$DTM->save();
295
+			}
296 296
             
297
-            //	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
-            // because it is possible there was a new one created for the autosave.
299
-            // (save the ID for both key and value to avoid duplications)
300
-            $saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
-            $saved_dtt_objs[$row]      = $DTM;
297
+			//	now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
298
+			// because it is possible there was a new one created for the autosave.
299
+			// (save the ID for both key and value to avoid duplications)
300
+			$saved_dtt_ids[$DTM->ID()] = $DTM->ID();
301
+			$saved_dtt_objs[$row]      = $DTM;
302 302
             
303
-            //todo if ANY of these updates fail then we want the appropriate global error message.
304
-        }
305
-        
306
-        //now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
-        $old_datetimes = explode(',', $data['datetime_IDs']);
308
-        $old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
-        
310
-        if (is_array($old_datetimes)) {
311
-            $dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
-            foreach ($dtts_to_delete as $id) {
313
-                $id = absint($id);
314
-                if (empty($id)) {
315
-                    continue;
316
-                }
303
+			//todo if ANY of these updates fail then we want the appropriate global error message.
304
+		}
305
+        
306
+		//now we need to REMOVE any dtts that got deleted.  Keep in mind that this process will only kick in for DTT's that don't have any DTT_sold on them. So its safe to permanently delete at this point.
307
+		$old_datetimes = explode(',', $data['datetime_IDs']);
308
+		$old_datetimes = $old_datetimes[0] == '' ? array() : $old_datetimes;
309
+        
310
+		if (is_array($old_datetimes)) {
311
+			$dtts_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
312
+			foreach ($dtts_to_delete as $id) {
313
+				$id = absint($id);
314
+				if (empty($id)) {
315
+					continue;
316
+				}
317 317
                 
318
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
318
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
319 319
                 
320
-                //remove tkt relationships.
321
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
-                foreach ($related_tickets as $tkt) {
323
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
-                }
320
+				//remove tkt relationships.
321
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
322
+				foreach ($related_tickets as $tkt) {
323
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
324
+				}
325 325
                 
326
-                $evt_obj->_remove_relation_to($id, 'Datetime');
327
-                $dtt_to_remove->refresh_cache_of_related_objects();
326
+				$evt_obj->_remove_relation_to($id, 'Datetime');
327
+				$dtt_to_remove->refresh_cache_of_related_objects();
328 328
                 
329
-            }
330
-        }
329
+			}
330
+		}
331 331
         
332
-        return $saved_dtt_objs;
333
-    }
332
+		return $saved_dtt_objs;
333
+	}
334 334
     
335 335
     
336
-    /**
337
-     * update tickets
338
-     *
339
-     * @param  EE_Event      $evtobj     Event object being updated
340
-     * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
-     * @param  array         $data       incoming request data
342
-     *
343
-     * @return EE_Ticket[]
344
-     */
345
-    protected function _update_tkts($evtobj, $saved_dtts, $data)
346
-    {
347
-        
348
-        $new_tkt     = null;
349
-        $new_default = null;
350
-        //stripslashes because WP filtered the $_POST ($data) array to add slashes
351
-        $data          = stripslashes_deep($data);
352
-        $timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
-        $saved_tickets = $dtts_on_existing = array();
354
-        $old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
-        
356
-        //load money helper
357
-        
358
-        foreach ($data['edit_tickets'] as $row => $tkt) {
336
+	/**
337
+	 * update tickets
338
+	 *
339
+	 * @param  EE_Event      $evtobj     Event object being updated
340
+	 * @param  EE_Datetime[] $saved_dtts an array of datetime ids being updated
341
+	 * @param  array         $data       incoming request data
342
+	 *
343
+	 * @return EE_Ticket[]
344
+	 */
345
+	protected function _update_tkts($evtobj, $saved_dtts, $data)
346
+	{
347
+        
348
+		$new_tkt     = null;
349
+		$new_default = null;
350
+		//stripslashes because WP filtered the $_POST ($data) array to add slashes
351
+		$data          = stripslashes_deep($data);
352
+		$timezone      = isset($data['timezone_string']) ? $data['timezone_string'] : null;
353
+		$saved_tickets = $dtts_on_existing = array();
354
+		$old_tickets   = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
355
+        
356
+		//load money helper
357
+        
358
+		foreach ($data['edit_tickets'] as $row => $tkt) {
359 359
             
360
-            $update_prices = $create_new_TKT = false;
360
+			$update_prices = $create_new_TKT = false;
361 361
             
362
-            //figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
362
+			//figure out what dtts were added to the ticket and what dtts were removed from the ticket in the session.
363 363
             
364
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
-            $tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
-            $dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
-            $dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
364
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]);
365
+			$tkt_dtt_rows          = explode(',', $data['ticket_datetime_rows'][$row]);
366
+			$dtts_added            = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
367
+			$dtts_removed          = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
368 368
             
369
-            // trim inputs to ensure any excess whitespace is removed.
370
-            $tkt = array_map(
371
-                function ($ticket_data) {
372
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
-                },
374
-                $tkt
375
-            );
369
+			// trim inputs to ensure any excess whitespace is removed.
370
+			$tkt = array_map(
371
+				function ($ticket_data) {
372
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
373
+				},
374
+				$tkt
375
+			);
376 376
             
377
-            //note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
-            //note incoming ['TKT_price'] value is already in standard notation (via js).
379
-            $ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
377
+			//note we are doing conversions to floats here instead of allowing EE_Money_Field to handle because we're doing calcs prior to using the models.
378
+			//note incoming ['TKT_price'] value is already in standard notation (via js).
379
+			$ticket_price = isset($tkt['TKT_price']) ? round((float)$tkt['TKT_price'], 3) : 0;
380 380
             
381
-            //note incoming base price needs converted from localized value.
382
-            $base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
-            //if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
-            $ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
-            $base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
381
+			//note incoming base price needs converted from localized value.
382
+			$base_price = isset($tkt['TKT_base_price']) ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) : 0;
383
+			//if ticket price == 0 and $base_price != 0 then ticket price == base_price
384
+			$ticket_price  = $ticket_price === 0 && $base_price !== 0 ? $base_price : $ticket_price;
385
+			$base_price_id = isset($tkt['TKT_base_price_ID']) ? $tkt['TKT_base_price_ID'] : 0;
386 386
             
387
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
387
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) ? $data['edit_prices'][$row] : array();
388 388
             
389
-            $now = null;
390
-            if (empty($tkt['TKT_start_date'])) {
391
-                //lets' use now in the set timezone.
392
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
-                $tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
-            }
389
+			$now = null;
390
+			if (empty($tkt['TKT_start_date'])) {
391
+				//lets' use now in the set timezone.
392
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
393
+				$tkt['TKT_start_date'] = $now->format($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
394
+			}
395 395
             
396
-            if (empty($tkt['TKT_end_date'])) {
397
-                /**
398
-                 * set the TKT_end_date to the first datetime attached to the ticket.
399
-                 */
400
-                $first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
-            }
396
+			if (empty($tkt['TKT_end_date'])) {
397
+				/**
398
+				 * set the TKT_end_date to the first datetime attached to the ticket.
399
+				 */
400
+				$first_dtt           = $saved_dtts[reset($tkt_dtt_rows)];
401
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_format_strings['date'] . ' ' . $this->_date_format_string['time']);
402
+			}
403 403
             
404
-            $TKT_values = array(
405
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
-                'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
-                    'event_espresso') ? $tkt['TKT_description'] : '',
410
-                'TKT_start_date'  => $tkt['TKT_start_date'],
411
-                'TKT_end_date'    => $tkt['TKT_end_date'],
412
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
-                'TKT_row'         => $row,
417
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
-                'TKT_price'       => $ticket_price
421
-            );
404
+			$TKT_values = array(
405
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
406
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
407
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
408
+				'TKT_description' => ! empty($tkt['TKT_description']) && $tkt['TKT_description'] != __('You can modify this description',
409
+					'event_espresso') ? $tkt['TKT_description'] : '',
410
+				'TKT_start_date'  => $tkt['TKT_start_date'],
411
+				'TKT_end_date'    => $tkt['TKT_end_date'],
412
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
413
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
414
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
415
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
416
+				'TKT_row'         => $row,
417
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
418
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
419
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
420
+				'TKT_price'       => $ticket_price
421
+			);
422 422
             
423 423
             
424
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
425
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
-                $TKT_values['TKT_ID']         = 0;
427
-                $TKT_values['TKT_is_default'] = 0;
428
-                $update_prices                = true;
429
-            }
424
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
425
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
426
+				$TKT_values['TKT_ID']         = 0;
427
+				$TKT_values['TKT_is_default'] = 0;
428
+				$update_prices                = true;
429
+			}
430 430
             
431
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
-            // we actually do our saves ahead of doing any add_relations to
433
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
-            // but DID have it's items modified.
435
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
436
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
-            if (absint($TKT_values['TKT_ID'])) {
438
-                $TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
-                if ($TKT instanceof EE_Ticket) {
431
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
432
+			// we actually do our saves ahead of doing any add_relations to
433
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
434
+			// but DID have it's items modified.
435
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
436
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
437
+			if (absint($TKT_values['TKT_ID'])) {
438
+				$TKT = EE_Registry::instance()->load_model('Ticket', array($timezone))->get_one_by_ID($tkt['TKT_ID']);
439
+				if ($TKT instanceof EE_Ticket) {
440 440
                     
441
-                    $TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
-                    // are there any registrations using this ticket ?
443
-                    $tickets_sold = $TKT->count_related(
444
-                        'Registration',
445
-                        array(
446
-                            array(
447
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
-                            )
449
-                        )
450
-                    );
451
-                    //set ticket formats
452
-                    $TKT->set_date_format($this->_date_format_strings['date']);
453
-                    $TKT->set_time_format($this->_date_format_strings['time']);
441
+					$TKT = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
442
+					// are there any registrations using this ticket ?
443
+					$tickets_sold = $TKT->count_related(
444
+						'Registration',
445
+						array(
446
+							array(
447
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))
448
+							)
449
+						)
450
+					);
451
+					//set ticket formats
452
+					$TKT->set_date_format($this->_date_format_strings['date']);
453
+					$TKT->set_time_format($this->_date_format_strings['time']);
454 454
                     
455
-                    // let's just check the total price for the existing ticket
456
-                    // and determine if it matches the new total price.
457
-                    // if they are different then we create a new ticket (if tkts sold)
458
-                    // if they aren't different then we go ahead and modify existing ticket.
459
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
-                        ? true : false;
455
+					// let's just check the total price for the existing ticket
456
+					// and determine if it matches the new total price.
457
+					// if they are different then we create a new ticket (if tkts sold)
458
+					// if they aren't different then we go ahead and modify existing ticket.
459
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price != $TKT->price() && ! $TKT->deleted()
460
+						? true : false;
461 461
                     
462
-                    //set new values
463
-                    foreach ($TKT_values as $field => $value) {
464
-                        if ($field === 'TKT_qty') {
465
-                            $TKT->set_qty($value);
466
-                        } else {
467
-                            $TKT->set($field, $value);
468
-                        }
469
-                    }
462
+					//set new values
463
+					foreach ($TKT_values as $field => $value) {
464
+						if ($field === 'TKT_qty') {
465
+							$TKT->set_qty($value);
466
+						} else {
467
+							$TKT->set($field, $value);
468
+						}
469
+					}
470 470
                     
471
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
-                    if ($create_new_TKT) {
473
-                        $new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
-                            $base_price_id);
475
-                    }
476
-                }
471
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
472
+					if ($create_new_TKT) {
473
+						$new_tkt = $this->_duplicate_ticket($TKT, $price_rows, $ticket_price, $base_price,
474
+							$base_price_id);
475
+					}
476
+				}
477 477
                 
478
-            } else {
479
-                // no TKT_id so a new TKT
480
-                $TKT = EE_Ticket::new_instance(
481
-                    $TKT_values,
482
-                    $timezone,
483
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
-                );
485
-                if ($TKT instanceof EE_Ticket) {
486
-                    // make sure ticket has an ID of setting relations won't work
487
-                    $TKT->save();
488
-                    $TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
-                    $update_prices = true;
490
-                }
491
-            }
492
-            //make sure any current values have been saved.
493
-            //$TKT->save();
478
+			} else {
479
+				// no TKT_id so a new TKT
480
+				$TKT = EE_Ticket::new_instance(
481
+					$TKT_values,
482
+					$timezone,
483
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
484
+				);
485
+				if ($TKT instanceof EE_Ticket) {
486
+					// make sure ticket has an ID of setting relations won't work
487
+					$TKT->save();
488
+					$TKT           = $this->_update_ticket_datetimes($TKT, $saved_dtts, $dtts_added, $dtts_removed);
489
+					$update_prices = true;
490
+				}
491
+			}
492
+			//make sure any current values have been saved.
493
+			//$TKT->save();
494 494
             
495
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
496
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
-            }
495
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
496
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
497
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
498
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
499
+			}
500 500
             
501
-            //let's make sure the base price is handled
502
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
-                $base_price_id) : $TKT;
501
+			//let's make sure the base price is handled
502
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $TKT, $update_prices, $base_price,
503
+				$base_price_id) : $TKT;
504 504
             
505
-            //add/update price_modifiers
506
-            $TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
505
+			//add/update price_modifiers
506
+			$TKT = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $TKT, $update_prices) : $TKT;
507 507
             
508
-            //need to make sue that the TKT_price is accurate after saving the prices.
509
-            $TKT->ensure_TKT_Price_correct();
508
+			//need to make sue that the TKT_price is accurate after saving the prices.
509
+			$TKT->ensure_TKT_Price_correct();
510 510
             
511
-            //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
-            if ( ! defined('DOING_AUTOSAVE')) {
513
-                if ( ! empty($tkt['TKT_is_default_selector'])) {
514
-                    $update_prices = true;
515
-                    $new_default   = clone $TKT;
516
-                    $new_default->set('TKT_ID', 0);
517
-                    $new_default->set('TKT_is_default', 1);
518
-                    $new_default->set('TKT_row', 1);
519
-                    $new_default->set('TKT_price', $ticket_price);
520
-                    //remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
-                    $new_default->_remove_relations('Datetime');
522
-                    //todo we need to add the current attached prices as new prices to the new default ticket.
523
-                    $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
-                    //don't forget the base price!
525
-                    $new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
-                        $base_price_id);
527
-                    $new_default->save();
528
-                    do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
-                        $row, $TKT, $data);
530
-                }
531
-            }
511
+			//handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
512
+			if ( ! defined('DOING_AUTOSAVE')) {
513
+				if ( ! empty($tkt['TKT_is_default_selector'])) {
514
+					$update_prices = true;
515
+					$new_default   = clone $TKT;
516
+					$new_default->set('TKT_ID', 0);
517
+					$new_default->set('TKT_is_default', 1);
518
+					$new_default->set('TKT_row', 1);
519
+					$new_default->set('TKT_price', $ticket_price);
520
+					//remove any dtt relations cause we DON'T want dtt relations attached (note this is just removing the cached relations in the object)
521
+					$new_default->_remove_relations('Datetime');
522
+					//todo we need to add the current attached prices as new prices to the new default ticket.
523
+					$new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices);
524
+					//don't forget the base price!
525
+					$new_default = $this->_add_prices_to_ticket(array(), $new_default, $update_prices, $base_price,
526
+						$base_price_id);
527
+					$new_default->save();
528
+					do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', $new_default,
529
+						$row, $TKT, $data);
530
+				}
531
+			}
532 532
             
533 533
             
534
-            //DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
534
+			//DO ALL dtt relationships for both current tickets and any archived tickets for the given dtt that are related to the current ticket. TODO... not sure exactly how we're going to do this considering we don't know what current ticket the archived tickets are related to (and TKT_parent is used for autosaves so that's not a field we can reliably use).
535 535
             
536 536
             
537
-            //let's assign any tickets that have been setup to the saved_tickets tracker
538
-            //save existing TKT
539
-            $TKT->save();
540
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
-                //save new TKT
542
-                $new_tkt->save();
543
-                //add new ticket to array
544
-                $saved_tickets[$new_tkt->ID()] = $new_tkt;
537
+			//let's assign any tickets that have been setup to the saved_tickets tracker
538
+			//save existing TKT
539
+			$TKT->save();
540
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
541
+				//save new TKT
542
+				$new_tkt->save();
543
+				//add new ticket to array
544
+				$saved_tickets[$new_tkt->ID()] = $new_tkt;
545 545
                 
546
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
546
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', $new_tkt, $row, $tkt, $data);
547 547
                 
548
-            } else {
549
-                //add tkt to saved tkts
550
-                $saved_tickets[$TKT->ID()] = $TKT;
548
+			} else {
549
+				//add tkt to saved tkts
550
+				$saved_tickets[$TKT->ID()] = $TKT;
551 551
                 
552
-                do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
-            }
552
+				do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', $TKT, $row, $tkt, $data);
553
+			}
554 554
             
555
-        }
556
-        
557
-        // now we need to handle tickets actually "deleted permanently".
558
-        // There are cases where we'd want this to happen
559
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
561
-        // No sense in keeping all the related data in the db!
562
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
-        
565
-        foreach ($tickets_removed as $id) {
566
-            $id = absint($id);
555
+		}
556
+        
557
+		// now we need to handle tickets actually "deleted permanently".
558
+		// There are cases where we'd want this to happen
559
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
560
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
561
+		// No sense in keeping all the related data in the db!
562
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
563
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
564
+        
565
+		foreach ($tickets_removed as $id) {
566
+			$id = absint($id);
567 567
             
568
-            //get the ticket for this id
569
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
568
+			//get the ticket for this id
569
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
570 570
             
571
-            //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
-            if ($tkt_to_remove->get('TKT_is_default')) {
573
-                continue;
574
-            }
571
+			//if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
572
+			if ($tkt_to_remove->get('TKT_is_default')) {
573
+				continue;
574
+			}
575 575
             
576
-            // if this tkt has any registrations attached so then we just ARCHIVE
577
-            // because we don't actually permanently delete these tickets.
578
-            if ($tkt_to_remove->count_related('Registration') > 0) {
579
-                $tkt_to_remove->delete();
580
-                continue;
581
-            }
576
+			// if this tkt has any registrations attached so then we just ARCHIVE
577
+			// because we don't actually permanently delete these tickets.
578
+			if ($tkt_to_remove->count_related('Registration') > 0) {
579
+				$tkt_to_remove->delete();
580
+				continue;
581
+			}
582 582
             
583
-            // need to get all the related datetimes on this ticket and remove from every single one of them
584
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
585
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
583
+			// need to get all the related datetimes on this ticket and remove from every single one of them
584
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
585
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
586 586
             
587
-            foreach ($dtts as $dtt) {
588
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
-            }
587
+			foreach ($dtts as $dtt) {
588
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
589
+			}
590 590
             
591
-            // need to do the same for prices (except these prices can also be deleted because again,
592
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
-            $tkt_to_remove->delete_related_permanently('Price');
591
+			// need to do the same for prices (except these prices can also be deleted because again,
592
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
593
+			$tkt_to_remove->delete_related_permanently('Price');
594 594
             
595
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
595
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
596 596
             
597
-            // finally let's delete this ticket
598
-            // (which should not be blocked at this point b/c we've removed all our relationships)
599
-            $tkt_to_remove->delete_permanently();
600
-        }
597
+			// finally let's delete this ticket
598
+			// (which should not be blocked at this point b/c we've removed all our relationships)
599
+			$tkt_to_remove->delete_permanently();
600
+		}
601 601
         
602
-        return $saved_tickets;
603
-    }
602
+		return $saved_tickets;
603
+	}
604 604
     
605 605
     
606
-    /**
607
-     *
608
-     * @access  protected
609
-     *
610
-     * @param \EE_Ticket     $ticket
611
-     * @param \EE_Datetime[] $saved_datetimes
612
-     * @param \EE_Datetime[] $added_datetimes
613
-     * @param \EE_Datetime[] $removed_datetimes
614
-     *
615
-     * @return \EE_Ticket
616
-     * @throws \EE_Error
617
-     */
618
-    protected function _update_ticket_datetimes(
619
-        EE_Ticket $ticket,
620
-        $saved_datetimes = array(),
621
-        $added_datetimes = array(),
622
-        $removed_datetimes = array()
623
-    ) {
624
-        
625
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
626
-        // and removing the ticket from datetimes it got removed from.
627
-        
628
-        // first let's add datetimes
629
-        if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
-            foreach ($added_datetimes as $row_id) {
631
-                $row_id = (int)$row_id;
632
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
-                    $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
-                    // Is this an existing ticket (has an ID) and does it have any sold?
635
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
636
-                    if ($ticket->ID() && $ticket->sold() > 0) {
637
-                        $saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
-                        $saved_datetimes[$row_id]->save();
639
-                    }
640
-                }
641
-            }
642
-        }
643
-        // then remove datetimes
644
-        if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
-            foreach ($removed_datetimes as $row_id) {
646
-                $row_id = (int)$row_id;
647
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
-                if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
-                    $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
-                    // Is this an existing ticket (has an ID) and does it have any sold?
652
-                    // If so, then we need to remove it's sold from the DTT_sold.
653
-                    if ($ticket->ID() && $ticket->sold() > 0) {
654
-                        $saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
-                        $saved_datetimes[$row_id]->save();
656
-                    }
657
-                }
658
-            }
659
-        }
660
-        // cap ticket qty by datetime reg limits
661
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
-        
663
-        return $ticket;
664
-    }
606
+	/**
607
+	 *
608
+	 * @access  protected
609
+	 *
610
+	 * @param \EE_Ticket     $ticket
611
+	 * @param \EE_Datetime[] $saved_datetimes
612
+	 * @param \EE_Datetime[] $added_datetimes
613
+	 * @param \EE_Datetime[] $removed_datetimes
614
+	 *
615
+	 * @return \EE_Ticket
616
+	 * @throws \EE_Error
617
+	 */
618
+	protected function _update_ticket_datetimes(
619
+		EE_Ticket $ticket,
620
+		$saved_datetimes = array(),
621
+		$added_datetimes = array(),
622
+		$removed_datetimes = array()
623
+	) {
624
+        
625
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
626
+		// and removing the ticket from datetimes it got removed from.
627
+        
628
+		// first let's add datetimes
629
+		if ( ! empty($added_datetimes) && is_array($added_datetimes)) {
630
+			foreach ($added_datetimes as $row_id) {
631
+				$row_id = (int)$row_id;
632
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
633
+					$ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime');
634
+					// Is this an existing ticket (has an ID) and does it have any sold?
635
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
636
+					if ($ticket->ID() && $ticket->sold() > 0) {
637
+						$saved_datetimes[$row_id]->increase_sold($ticket->sold());
638
+						$saved_datetimes[$row_id]->save();
639
+					}
640
+				}
641
+			}
642
+		}
643
+		// then remove datetimes
644
+		if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) {
645
+			foreach ($removed_datetimes as $row_id) {
646
+				$row_id = (int)$row_id;
647
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
648
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
649
+				if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) {
650
+					$ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime');
651
+					// Is this an existing ticket (has an ID) and does it have any sold?
652
+					// If so, then we need to remove it's sold from the DTT_sold.
653
+					if ($ticket->ID() && $ticket->sold() > 0) {
654
+						$saved_datetimes[$row_id]->decrease_sold($ticket->sold());
655
+						$saved_datetimes[$row_id]->save();
656
+					}
657
+				}
658
+			}
659
+		}
660
+		// cap ticket qty by datetime reg limits
661
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
662
+        
663
+		return $ticket;
664
+	}
665 665
     
666 666
     
667
-    /**
668
-     *
669
-     * @access  protected
670
-     *
671
-     * @param \EE_Ticket $ticket
672
-     * @param array      $price_rows
673
-     * @param int        $ticket_price
674
-     * @param int        $base_price
675
-     * @param int        $base_price_id
676
-     *
677
-     * @return \EE_Ticket
678
-     * @throws \EE_Error
679
-     */
680
-    protected function _duplicate_ticket(
681
-        EE_Ticket $ticket,
682
-        $price_rows = array(),
683
-        $ticket_price = 0,
684
-        $base_price = 0,
685
-        $base_price_id = 0
686
-    ) {
687
-        
688
-        // create new ticket that's a copy of the existing
689
-        // except a new id of course (and not archived)
690
-        // AND has the new TKT_price associated with it.
691
-        $new_ticket = clone $ticket;
692
-        $new_ticket->set('TKT_ID', 0);
693
-        $new_ticket->set('TKT_deleted', 0);
694
-        $new_ticket->set('TKT_price', $ticket_price);
695
-        $new_ticket->set('TKT_sold', 0);
696
-        // let's get a new ID for this ticket
697
-        $new_ticket->save();
698
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
-        $datetimes_on_existing = $ticket->get_many_related('Datetime');
700
-        $new_ticket            = $this->_update_ticket_datetimes(
701
-            $new_ticket,
702
-            $datetimes_on_existing,
703
-            array_keys($datetimes_on_existing)
704
-        );
705
-        
706
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
-        // available.
709
-        if ($ticket->sold() > 0) {
710
-            $new_qty = $ticket->qty() - $ticket->sold();
711
-            $new_ticket->set_qty($new_qty);
712
-        }
713
-        //now we update the prices just for this ticket
714
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
-        //and we update the base price
716
-        $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
-        
718
-        return $new_ticket;
719
-    }
667
+	/**
668
+	 *
669
+	 * @access  protected
670
+	 *
671
+	 * @param \EE_Ticket $ticket
672
+	 * @param array      $price_rows
673
+	 * @param int        $ticket_price
674
+	 * @param int        $base_price
675
+	 * @param int        $base_price_id
676
+	 *
677
+	 * @return \EE_Ticket
678
+	 * @throws \EE_Error
679
+	 */
680
+	protected function _duplicate_ticket(
681
+		EE_Ticket $ticket,
682
+		$price_rows = array(),
683
+		$ticket_price = 0,
684
+		$base_price = 0,
685
+		$base_price_id = 0
686
+	) {
687
+        
688
+		// create new ticket that's a copy of the existing
689
+		// except a new id of course (and not archived)
690
+		// AND has the new TKT_price associated with it.
691
+		$new_ticket = clone $ticket;
692
+		$new_ticket->set('TKT_ID', 0);
693
+		$new_ticket->set('TKT_deleted', 0);
694
+		$new_ticket->set('TKT_price', $ticket_price);
695
+		$new_ticket->set('TKT_sold', 0);
696
+		// let's get a new ID for this ticket
697
+		$new_ticket->save();
698
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
699
+		$datetimes_on_existing = $ticket->get_many_related('Datetime');
700
+		$new_ticket            = $this->_update_ticket_datetimes(
701
+			$new_ticket,
702
+			$datetimes_on_existing,
703
+			array_keys($datetimes_on_existing)
704
+		);
705
+        
706
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
707
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
708
+		// available.
709
+		if ($ticket->sold() > 0) {
710
+			$new_qty = $ticket->qty() - $ticket->sold();
711
+			$new_ticket->set_qty($new_qty);
712
+		}
713
+		//now we update the prices just for this ticket
714
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
715
+		//and we update the base price
716
+		$new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id);
717
+        
718
+		return $new_ticket;
719
+	}
720 720
     
721 721
     
722
-    /**
723
-     * This attaches a list of given prices to a ticket.
724
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
-     * price info and prices are automatically "archived" via the ticket.
727
-     *
728
-     * @access  private
729
-     *
730
-     * @param array     $prices        Array of prices from the form.
731
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
-     *
736
-     * @return EE_Ticket
737
-     */
738
-    protected function _add_prices_to_ticket(
739
-        $prices = array(),
740
-        EE_Ticket $ticket,
741
-        $new_prices = false,
742
-        $base_price = false,
743
-        $base_price_id = false
744
-    ) {
745
-        
746
-        //let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
-        $current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
-        
749
-        $updated_prices = array();
750
-        
751
-        // if $base_price ! FALSE then updating a base price.
752
-        if ($base_price !== false) {
753
-            $prices[1] = array(
754
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
-                'PRT_ID'     => 1,
756
-                'PRC_amount' => $base_price,
757
-                'PRC_name'   => $ticket->get('TKT_name'),
758
-                'PRC_desc'   => $ticket->get('TKT_description')
759
-            );
760
-        }
761
-        
762
-        //possibly need to save tkt
763
-        if ( ! $ticket->ID()) {
764
-            $ticket->save();
765
-        }
766
-        
767
-        foreach ($prices as $row => $prc) {
768
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
-            if (empty($prt_id)) {
770
-                continue;
771
-            } //prices MUST have a price type id.
772
-            $PRC_values = array(
773
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
-                'PRT_ID'         => $prt_id,
775
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
-                'PRC_is_default' => false,
779
-                //make sure we set PRC_is_default to false for all ticket saves from event_editor
780
-                'PRC_order'      => $row
781
-            );
782
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
-                $PRC_values['PRC_ID'] = 0;
784
-                $PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
-            } else {
786
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
-                //update this price with new values
788
-                foreach ($PRC_values as $field => $newprc) {
789
-                    $PRC->set($field, $newprc);
790
-                }
791
-            }
792
-            $PRC->save();
793
-            $prcid                  = $PRC->ID();
794
-            $updated_prices[$prcid] = $PRC;
795
-            $ticket->_add_relation_to($PRC, 'Price');
796
-        }
797
-        
798
-        //now let's remove any prices that got removed from the ticket
799
-        if ( ! empty ($current_prices_on_ticket)) {
800
-            $current          = array_keys($current_prices_on_ticket);
801
-            $updated          = array_keys($updated_prices);
802
-            $prices_to_remove = array_diff($current, $updated);
803
-            if ( ! empty($prices_to_remove)) {
804
-                foreach ($prices_to_remove as $prc_id) {
805
-                    $p = $current_prices_on_ticket[$prc_id];
806
-                    $ticket->_remove_relation_to($p, 'Price');
722
+	/**
723
+	 * This attaches a list of given prices to a ticket.
724
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
725
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
726
+	 * price info and prices are automatically "archived" via the ticket.
727
+	 *
728
+	 * @access  private
729
+	 *
730
+	 * @param array     $prices        Array of prices from the form.
731
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
732
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
733
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
734
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
735
+	 *
736
+	 * @return EE_Ticket
737
+	 */
738
+	protected function _add_prices_to_ticket(
739
+		$prices = array(),
740
+		EE_Ticket $ticket,
741
+		$new_prices = false,
742
+		$base_price = false,
743
+		$base_price_id = false
744
+	) {
745
+        
746
+		//let's just get any current prices that may exist on the given ticket so we can remove any prices that got trashed in this session.
747
+		$current_prices_on_ticket = $base_price !== false ? $ticket->base_price(true) : $ticket->price_modifiers();
748
+        
749
+		$updated_prices = array();
750
+        
751
+		// if $base_price ! FALSE then updating a base price.
752
+		if ($base_price !== false) {
753
+			$prices[1] = array(
754
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
755
+				'PRT_ID'     => 1,
756
+				'PRC_amount' => $base_price,
757
+				'PRC_name'   => $ticket->get('TKT_name'),
758
+				'PRC_desc'   => $ticket->get('TKT_description')
759
+			);
760
+		}
761
+        
762
+		//possibly need to save tkt
763
+		if ( ! $ticket->ID()) {
764
+			$ticket->save();
765
+		}
766
+        
767
+		foreach ($prices as $row => $prc) {
768
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
769
+			if (empty($prt_id)) {
770
+				continue;
771
+			} //prices MUST have a price type id.
772
+			$PRC_values = array(
773
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
774
+				'PRT_ID'         => $prt_id,
775
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
776
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
777
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
778
+				'PRC_is_default' => false,
779
+				//make sure we set PRC_is_default to false for all ticket saves from event_editor
780
+				'PRC_order'      => $row
781
+			);
782
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
783
+				$PRC_values['PRC_ID'] = 0;
784
+				$PRC                  = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
785
+			} else {
786
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
787
+				//update this price with new values
788
+				foreach ($PRC_values as $field => $newprc) {
789
+					$PRC->set($field, $newprc);
790
+				}
791
+			}
792
+			$PRC->save();
793
+			$prcid                  = $PRC->ID();
794
+			$updated_prices[$prcid] = $PRC;
795
+			$ticket->_add_relation_to($PRC, 'Price');
796
+		}
797
+        
798
+		//now let's remove any prices that got removed from the ticket
799
+		if ( ! empty ($current_prices_on_ticket)) {
800
+			$current          = array_keys($current_prices_on_ticket);
801
+			$updated          = array_keys($updated_prices);
802
+			$prices_to_remove = array_diff($current, $updated);
803
+			if ( ! empty($prices_to_remove)) {
804
+				foreach ($prices_to_remove as $prc_id) {
805
+					$p = $current_prices_on_ticket[$prc_id];
806
+					$ticket->_remove_relation_to($p, 'Price');
807 807
                     
808
-                    //delete permanently the price
809
-                    $p->delete_permanently();
810
-                }
811
-            }
812
-        }
813
-        
814
-        return $ticket;
815
-    }
808
+					//delete permanently the price
809
+					$p->delete_permanently();
810
+				}
811
+			}
812
+		}
813
+        
814
+		return $ticket;
815
+	}
816 816
     
817 817
     
818
-    public function autosave_handling($event_admin_obj)
819
-    {
820
-        return $event_admin_obj; //doing nothing for the moment.
821
-        //todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
-        
823
-        /**
824
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
-         *
826
-         * 1. TKT_is_default_selector (visible)
827
-         * 2. TKT_is_default (hidden)
828
-         *
829
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
-         *
831
-         * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
-         * On Autosave:
833
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
-         */
837
-    }
818
+	public function autosave_handling($event_admin_obj)
819
+	{
820
+		return $event_admin_obj; //doing nothing for the moment.
821
+		//todo when I get to this remember that I need to set the template args on the $event_admin_obj (use the set_template_args() method)
822
+        
823
+		/**
824
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
825
+		 *
826
+		 * 1. TKT_is_default_selector (visible)
827
+		 * 2. TKT_is_default (hidden)
828
+		 *
829
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want this ticket to be saved as a default.
830
+		 *
831
+		 * The tricky part is, on an initial display on create or edit (or after manually updating), the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true if this is a create.  However, after an autosave, users will want some sort of indicator that the TKT HAS been saved as a default.. in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
832
+		 * On Autosave:
833
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, then set the TKT_is_default to false.
834
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
835
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
836
+		 */
837
+	}
838 838
     
839 839
     
840
-    public function pricing_metabox()
841
-    {
842
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
-        
844
-        $evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
-        
846
-        //set is_creating_event property.
847
-        $evtID                    = $evtobj->ID();
848
-        $this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
-        
850
-        //default main template args
851
-        $main_template_args = array(
852
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
-            //todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
-            'existing_datetime_ids'    => '',
856
-            'total_dtt_rows'           => 1,
857
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
-            'datetime_rows'            => '',
861
-            'show_tickets_container'   => '',
862
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
-            'ticket_rows'              => '',
864
-            'existing_ticket_ids'      => '',
865
-            'total_ticket_rows'        => 1,
866
-            'ticket_js_structure'      => '',
867
-            'ee_collapsible_status'    => ' ee-collapsible-open'
868
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
-        );
870
-        
871
-        $timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
-        
873
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
-        
875
-        /**
876
-         * 1. Start with retrieving Datetimes
877
-         * 2. For each datetime get related tickets
878
-         * 3. For each ticket get related prices
879
-         */
880
-        
881
-        $DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
-        $times = $DTM->get_all_event_dates($evtID);
883
-        
884
-        
885
-        $main_template_args['total_dtt_rows'] = count($times);
886
-        
887
-        /** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
-        $dttrow = 1;
889
-        foreach ($times as $time) {
890
-            $dttid = $time->get('DTT_ID');
891
-            $time->set('DTT_order', $dttrow);
892
-            $existing_datetime_ids[] = $dttid;
840
+	public function pricing_metabox()
841
+	{
842
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
843
+        
844
+		$evtobj = $this->_adminpage_obj->get_cpt_model_obj();
845
+        
846
+		//set is_creating_event property.
847
+		$evtID                    = $evtobj->ID();
848
+		$this->_is_creating_event = absint($evtID) != 0 ? false : true;
849
+        
850
+		//default main template args
851
+		$main_template_args = array(
852
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link('event_editor_event_datetimes_help_tab',
853
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
854
+			//todo need to add a filter to the template for the help text in the Events_Admin_Page core file so we can add further help
855
+			'existing_datetime_ids'    => '',
856
+			'total_dtt_rows'           => 1,
857
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link('add_new_dtt_info',
858
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
859
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
860
+			'datetime_rows'            => '',
861
+			'show_tickets_container'   => '',
862
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
863
+			'ticket_rows'              => '',
864
+			'existing_ticket_ids'      => '',
865
+			'total_ticket_rows'        => 1,
866
+			'ticket_js_structure'      => '',
867
+			'ee_collapsible_status'    => ' ee-collapsible-open'
868
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
869
+		);
870
+        
871
+		$timezone = $evtobj instanceof EE_Event ? $evtobj->timezone_string() : null;
872
+        
873
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
874
+        
875
+		/**
876
+		 * 1. Start with retrieving Datetimes
877
+		 * 2. For each datetime get related tickets
878
+		 * 3. For each ticket get related prices
879
+		 */
880
+        
881
+		$DTM   = EE_Registry::instance()->load_model('Datetime', array($timezone));
882
+		$times = $DTM->get_all_event_dates($evtID);
883
+        
884
+        
885
+		$main_template_args['total_dtt_rows'] = count($times);
886
+        
887
+		/** @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 for why we are counting $dttrow and then setting that on the Datetime object */
888
+		$dttrow = 1;
889
+		foreach ($times as $time) {
890
+			$dttid = $time->get('DTT_ID');
891
+			$time->set('DTT_order', $dttrow);
892
+			$existing_datetime_ids[] = $dttid;
893 893
             
894
-            //tickets attached
895
-            $related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
-                array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
-                'default_where_conditions' => 'none',
898
-                'order_by'                 => array('TKT_order' => 'ASC')
899
-            )) : array();
894
+			//tickets attached
895
+			$related_tickets = $time->ID() > 0 ? $time->get_many_related('Ticket', array(
896
+				array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
897
+				'default_where_conditions' => 'none',
898
+				'order_by'                 => array('TKT_order' => 'ASC')
899
+			)) : array();
900 900
             
901
-            //if there are no related tickets this is likely a new event OR autodraft
902
-            // event so we need to generate the default tickets because dtts
903
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
-            // datetime on the event.
905
-            if (empty ($related_tickets) && count($times) < 2) {
906
-                $related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
901
+			//if there are no related tickets this is likely a new event OR autodraft
902
+			// event so we need to generate the default tickets because dtts
903
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
904
+			// datetime on the event.
905
+			if (empty ($related_tickets) && count($times) < 2) {
906
+				$related_tickets = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
907 907
                 
908
-                //this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
908
+				//this should be ordered by TKT_ID, so let's grab the first default ticket (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
909
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
910 910
                 
911
-                $main_default_ticket = reset($related_tickets);
912
-                if ($main_default_ticket instanceof EE_Ticket) {
913
-                    foreach ($default_prices as $default_price) {
914
-                        if ($default_price->is_base_price()) {
915
-                            continue;
916
-                        }
917
-                        $main_default_ticket->cache('Price', $default_price);
918
-                    }
919
-                }
920
-            }
911
+				$main_default_ticket = reset($related_tickets);
912
+				if ($main_default_ticket instanceof EE_Ticket) {
913
+					foreach ($default_prices as $default_price) {
914
+						if ($default_price->is_base_price()) {
915
+							continue;
916
+						}
917
+						$main_default_ticket->cache('Price', $default_price);
918
+					}
919
+				}
920
+			}
921 921
             
922 922
             
923
-            //we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
923
+			//we can't actually setup rows in this loop yet cause we don't know all the unique tickets for this event yet (tickets are linked through all datetimes). So we're going to temporarily cache some of that information.
924 924
             
925
-            //loop through and setup the ticket rows and make sure the order is set.
926
-            foreach ($related_tickets as $ticket) {
927
-                $tktid  = $ticket->get('TKT_ID');
928
-                $tktrow = $ticket->get('TKT_row');
929
-                //we only want unique tickets in our final display!!
930
-                if ( ! in_array($tktid, $existing_ticket_ids)) {
931
-                    $existing_ticket_ids[] = $tktid;
932
-                    $all_tickets[]         = $ticket;
933
-                }
925
+			//loop through and setup the ticket rows and make sure the order is set.
926
+			foreach ($related_tickets as $ticket) {
927
+				$tktid  = $ticket->get('TKT_ID');
928
+				$tktrow = $ticket->get('TKT_row');
929
+				//we only want unique tickets in our final display!!
930
+				if ( ! in_array($tktid, $existing_ticket_ids)) {
931
+					$existing_ticket_ids[] = $tktid;
932
+					$all_tickets[]         = $ticket;
933
+				}
934 934
                 
935
-                //temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
-                $datetime_tickets[$dttid][] = $tktrow;
935
+				//temporary cache of this ticket info for this datetime for later processing of datetime rows.
936
+				$datetime_tickets[$dttid][] = $tktrow;
937 937
                 
938
-                //temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
-                if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
-                    $ticket_datetimes[$tktid][] = $dttrow;
941
-                }
942
-            }
943
-            $dttrow++;
944
-        }
945
-        
946
-        $main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
-        $main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
-        
950
-        //sort $all_tickets by order
951
-        usort($all_tickets, function ($a, $b) {
952
-            $a_order = (int)$a->get('TKT_order');
953
-            $b_order = (int)$b->get('TKT_order');
954
-            if ($a_order == $b_order) {
955
-                return 0;
956
-            }
938
+				//temporary cache of this datetime info for this ticket for later processing of ticket rows.
939
+				if ( ! isset($ticket_datetimes[$tktid]) || ! in_array($dttrow, $ticket_datetimes[$tktid])) {
940
+					$ticket_datetimes[$tktid][] = $dttrow;
941
+				}
942
+			}
943
+			$dttrow++;
944
+		}
945
+        
946
+		$main_template_args['total_ticket_rows']     = count($existing_ticket_ids);
947
+		$main_template_args['existing_ticket_ids']   = implode(',', $existing_ticket_ids);
948
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
949
+        
950
+		//sort $all_tickets by order
951
+		usort($all_tickets, function ($a, $b) {
952
+			$a_order = (int)$a->get('TKT_order');
953
+			$b_order = (int)$b->get('TKT_order');
954
+			if ($a_order == $b_order) {
955
+				return 0;
956
+			}
957 957
             
958
-            return ($a_order < $b_order) ? -1 : 1;
959
-        });
960
-        
961
-        //k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
-        $dttrow = 1;
963
-        foreach ($times as $time) {
964
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
-                $all_tickets, false, $times);
966
-            $dttrow++;
967
-        }
968
-        
969
-        //then loop through all tickets for the ticket rows.
970
-        $tktrow = 1;
971
-        foreach ($all_tickets as $ticket) {
972
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
-                false, $all_tickets);
974
-            $tktrow++;
975
-        }
976
-        
977
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
-        $template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
-        EEH_Template::display_template($template, $main_template_args);
980
-        
981
-        return;
982
-    }
958
+			return ($a_order < $b_order) ? -1 : 1;
959
+		});
960
+        
961
+		//k NOW we have all the data we need for setting up the dtt rows and ticket rows so we start our dtt loop again.
962
+		$dttrow = 1;
963
+		foreach ($times as $time) {
964
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row($dttrow, $time, $datetime_tickets,
965
+				$all_tickets, false, $times);
966
+			$dttrow++;
967
+		}
968
+        
969
+		//then loop through all tickets for the ticket rows.
970
+		$tktrow = 1;
971
+		foreach ($all_tickets as $ticket) {
972
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row($tktrow, $ticket, $ticket_datetimes, $times,
973
+				false, $all_tickets);
974
+			$tktrow++;
975
+		}
976
+        
977
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($times, $all_tickets);
978
+		$template                                  = PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php';
979
+		EEH_Template::display_template($template, $main_template_args);
980
+        
981
+		return;
982
+	}
983 983
     
984 984
     
985
-    protected function _get_datetime_row(
986
-        $dttrow,
987
-        EE_Datetime $dtt,
988
-        $datetime_tickets,
989
-        $all_tickets,
990
-        $default = false,
991
-        $all_dtts = array()
992
-    ) {
993
-        
994
-        $dtt_display_template_args = array(
995
-            'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
-                $all_tickets, $default),
998
-            'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
-        );
1000
-        $template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
-        
1002
-        return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
-    }
985
+	protected function _get_datetime_row(
986
+		$dttrow,
987
+		EE_Datetime $dtt,
988
+		$datetime_tickets,
989
+		$all_tickets,
990
+		$default = false,
991
+		$all_dtts = array()
992
+	) {
993
+        
994
+		$dtt_display_template_args = array(
995
+			'dtt_edit_row'             => $this->_get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts),
996
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets,
997
+				$all_tickets, $default),
998
+			'dtt_row'                  => $default ? 'DTTNUM' : $dttrow
999
+		);
1000
+		$template                  = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php';
1001
+        
1002
+		return EEH_Template::display_template($template, $dtt_display_template_args, true);
1003
+	}
1004 1004
     
1005 1005
     
1006
-    /**
1007
-     * This method is used to generate a dtt fields  edit row.
1008
-     * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
-     * skeleton by the js.
1010
-     *
1011
-     * @param int           $dttrow                         The row number for the row being generated.
1012
-     * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
-     *                                                                       generated, this must be a EE_Datetime
1014
-     *                                                                       object.
1015
-     * @param bool          $default                        Whether a default row is being generated or not.
1016
-     * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
-     *
1018
-     * @return string Generated edit row.
1019
-     */
1020
-    protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
-    {
1022
-        
1023
-        // if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
-        $default = ! $dtt instanceof EE_Datetime ? true : false;
1025
-        
1026
-        $template_args = array(
1027
-            'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
-            'edit_dtt_expanded'    => '',
1030
-            //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
-            'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
-            'DTT_name'             => $default ? '' : $dtt->name(),
1033
-            'DTT_description'      => $default ? '' : $dtt->description(),
1034
-            'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
-            'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
-            'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
-            'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
-            'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
-            'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1040
-            'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1041
-            'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1042
-                ? ''
1043
-                : EE_Admin_Page::add_query_args_and_nonce(
1044
-                    array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1045
-                    REG_ADMIN_URL
1046
-                )
1047
-        );
1048
-        
1049
-        $template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1050
-        
1051
-        //allow filtering of template args at this point.
1052
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1053
-            $template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1054
-        
1055
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1056
-        
1057
-        return EEH_Template::display_template($template, $template_args, true);
1058
-    }
1006
+	/**
1007
+	 * This method is used to generate a dtt fields  edit row.
1008
+	 * The same row is used to generate a row with valid DTT objects and the default row that is used as the
1009
+	 * skeleton by the js.
1010
+	 *
1011
+	 * @param int           $dttrow                         The row number for the row being generated.
1012
+	 * @param               mixed                           EE_Datetime|null $dtt      If not default row being
1013
+	 *                                                                       generated, this must be a EE_Datetime
1014
+	 *                                                                       object.
1015
+	 * @param bool          $default                        Whether a default row is being generated or not.
1016
+	 * @param EE_Datetime[] $all_dtts                       This is the array of all datetimes used in the editor.
1017
+	 *
1018
+	 * @return string Generated edit row.
1019
+	 */
1020
+	protected function _get_dtt_edit_row($dttrow, $dtt, $default, $all_dtts)
1021
+	{
1022
+        
1023
+		// if the incoming $dtt object is NOT an instance of EE_Datetime then force default to true.
1024
+		$default = ! $dtt instanceof EE_Datetime ? true : false;
1025
+        
1026
+		$template_args = array(
1027
+			'dtt_row'              => $default ? 'DTTNUM' : $dttrow,
1028
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1029
+			'edit_dtt_expanded'    => '',
1030
+			//$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? '' : ' ee-edit-editing',
1031
+			'DTT_ID'               => $default ? '' : $dtt->ID(),
1032
+			'DTT_name'             => $default ? '' : $dtt->name(),
1033
+			'DTT_description'      => $default ? '' : $dtt->description(),
1034
+			'DTT_EVT_start'        => $default ? '' : $dtt->start_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1035
+			'DTT_EVT_end'          => $default ? '' : $dtt->end_date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1036
+			'DTT_reg_limit'        => $default ? '' : $dtt->get_pretty('DTT_reg_limit', 'input'),
1037
+			'DTT_order'            => $default ? 'DTTNUM' : $dttrow,
1038
+			'dtt_sold'             => $default ? '0' : $dtt->get('DTT_sold'),
1039
+			'clone_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? '' : 'clone-icon ee-icon ee-icon-clone clickable',
1040
+			'trash_icon'           => ! empty($dtt) && $dtt->get('DTT_sold') > 0 ? 'ee-lock-icon' : 'trash-icon dashicons dashicons-post-trash clickable',
1041
+			'reg_list_url'         => $default || ! $dtt->event() instanceof \EE_Event
1042
+				? ''
1043
+				: EE_Admin_Page::add_query_args_and_nonce(
1044
+					array('event_id' => $dtt->event()->ID(), 'datetime_id' => $dtt->ID()),
1045
+					REG_ADMIN_URL
1046
+				)
1047
+		);
1048
+        
1049
+		$template_args['show_trash'] = count($all_dtts) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' ? ' style="display:none"' : '';
1050
+        
1051
+		//allow filtering of template args at this point.
1052
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1053
+			$template_args, $dttrow, $dtt, $default, $all_dtts, $this->_is_creating_event);
1054
+        
1055
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php';
1056
+        
1057
+		return EEH_Template::display_template($template, $template_args, true);
1058
+	}
1059 1059
     
1060 1060
     
1061
-    protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1062
-    {
1063
-        
1064
-        $template_args = array(
1065
-            'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1066
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1067
-            'DTT_description'                   => $default ? '' : $dtt->description(),
1068
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1069
-            'show_tickets_row'                  => ' style="display:none;"',
1070
-            //$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1071
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1072
-                $this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1073
-            //todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1074
-            'DTT_ID'                            => $default ? '' : $dtt->ID()
1075
-        );
1076
-        
1077
-        //need to setup the list items (but only if this isnt' a default skeleton setup)
1078
-        if ( ! $default) {
1079
-            $tktrow = 1;
1080
-            foreach ($all_tickets as $ticket) {
1081
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1082
-                    $dtt, $ticket, $datetime_tickets, $default);
1083
-                $tktrow++;
1084
-            }
1085
-        }
1086
-        
1087
-        //filter template args at this point
1088
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1089
-            $template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1090
-        
1091
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1092
-        
1093
-        return EEH_Template::display_template($template, $template_args, true);
1094
-    }
1061
+	protected function _get_dtt_attached_tickets_row($dttrow, $dtt, $datetime_tickets, $all_tickets, $default)
1062
+	{
1063
+        
1064
+		$template_args = array(
1065
+			'dtt_row'                           => $default ? 'DTTNUM' : $dttrow,
1066
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1067
+			'DTT_description'                   => $default ? '' : $dtt->description(),
1068
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1069
+			'show_tickets_row'                  => ' style="display:none;"',
1070
+			//$default || $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' style="display:none;"' : '',
1071
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link('add_new_ticket_via_datetime',
1072
+				$this->_adminpage_obj->page_slug, $this->_adminpage_obj->get_req_action(), false, false),
1073
+			//todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1074
+			'DTT_ID'                            => $default ? '' : $dtt->ID()
1075
+		);
1076
+        
1077
+		//need to setup the list items (but only if this isnt' a default skeleton setup)
1078
+		if ( ! $default) {
1079
+			$tktrow = 1;
1080
+			foreach ($all_tickets as $ticket) {
1081
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item($dttrow, $tktrow,
1082
+					$dtt, $ticket, $datetime_tickets, $default);
1083
+				$tktrow++;
1084
+			}
1085
+		}
1086
+        
1087
+		//filter template args at this point
1088
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1089
+			$template_args, $dttrow, $dtt, $datetime_tickets, $all_tickets, $default, $this->_is_creating_event);
1090
+        
1091
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php';
1092
+        
1093
+		return EEH_Template::display_template($template, $template_args, true);
1094
+	}
1095 1095
     
1096 1096
     
1097
-    protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1098
-    {
1099
-        $tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1100
-        $dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1101
-        
1102
-        $displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1103
-        $template_args = array(
1104
-            'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1105
-            'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1106
-            'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1107
-            'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1108
-            'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1109
-            'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1110
-        );
1111
-        
1112
-        //filter template args
1113
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1114
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1115
-        
1116
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1117
-        
1118
-        return EEH_Template::display_template($template, $template_args, true);
1119
-    }
1097
+	protected function _get_datetime_tickets_list_item($dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default)
1098
+	{
1099
+		$tktid    = ! empty($ticket) ? $ticket->ID() : 0;
1100
+		$dtt_tkts = $dtt instanceof EE_Datetime && isset($datetime_tickets[$dtt->ID()]) ? $datetime_tickets[$dtt->ID()] : array();
1101
+        
1102
+		$displayrow    = ! empty($ticket) ? $ticket->get('TKT_row') : 0;
1103
+		$template_args = array(
1104
+			'dtt_row'                 => $default ? 'DTTNUM' : $dttrow,
1105
+			'tkt_row'                 => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1106
+			'datetime_ticket_checked' => in_array($displayrow, $dtt_tkts) ? ' checked="checked"' : '',
1107
+			'ticket_selected'         => in_array($displayrow, $dtt_tkts) ? ' ticket-selected' : '',
1108
+			'TKT_name'                => $default && empty($ticket) ? 'TKTNAME' : $ticket->get('TKT_name'),
1109
+			'tkt_status_class'        => ($default && empty($ticket)) || $this->_is_creating_event ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status(),
1110
+		);
1111
+        
1112
+		//filter template args
1113
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1114
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $datetime_tickets, $default, $this->_is_creating_event);
1115
+        
1116
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php';
1117
+        
1118
+		return EEH_Template::display_template($template, $template_args, true);
1119
+	}
1120 1120
     
1121 1121
     
1122
-    /**
1123
-     * This generates the ticket row for tickets.
1124
-     * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1125
-     * true)
1126
-     *
1127
-     * @param int           $tktrow                          Represents the row number being generated.
1128
-     * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1129
-     *                                                                      be null.
1130
-     * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1131
-     *                                                       each ticket or empty for  default
1132
-     * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1133
-     * @param bool          $default                         Whether default row being generated or not.
1134
-     * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1135
-     *                                                       empty in the case of defaults)
1136
-     *
1137
-     * @return [type] [description]
1138
-     */
1139
-    protected function _get_ticket_row(
1140
-        $tktrow,
1141
-        $ticket,
1142
-        $ticket_datetimes,
1143
-        $all_dtts,
1144
-        $default = false,
1145
-        $all_tickets = array()
1146
-    ) {
1147
-        
1148
-        //if $ticket is not an instance of EE_Ticket then force default to true.
1149
-        $default = ! $ticket instanceof EE_Ticket ? true : false;
1150
-        
1151
-        $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1152
-            array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1153
-        
1154
-        //if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1155
-        //the object.  This is done by not including any query_params.
1156
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1157
-            $prices = $ticket->get_many_related('Price');
1158
-        }
1159
-        
1160
-        // check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1161
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1162
-        
1163
-        $tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1164
-        
1165
-        $ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1166
-        $base_price       = $default ? null : $ticket->base_price();
1167
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1168
-        
1169
-        //breaking out complicated condition for ticket_status
1170
-        if ($default) {
1171
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1172
-        } else {
1173
-            $ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1174
-        }
1175
-        
1176
-        //breaking out complicated condition for TKT_taxable
1177
-        if ($default) {
1178
-            $TKT_taxable = '';
1179
-        } else {
1180
-            $TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1181
-        }
1122
+	/**
1123
+	 * This generates the ticket row for tickets.
1124
+	 * This same method is used to generate both the actual rows and the js skeleton row (when default ==
1125
+	 * true)
1126
+	 *
1127
+	 * @param int           $tktrow                          Represents the row number being generated.
1128
+	 * @param               mixed                            null|EE_Ticket $ticket           If default then this will
1129
+	 *                                                                      be null.
1130
+	 * @param EE_Datetime[] $ticket_datetimes                Either an array of all datetimes on all tickets indexed by
1131
+	 *                                                       each ticket or empty for  default
1132
+	 * @param EE_Datetime[] $all_dtts                        All Datetimes on the event or empty for default.
1133
+	 * @param bool          $default                         Whether default row being generated or not.
1134
+	 * @param EE_Ticket[]   $all_tickets                     This is an array of all tickets attached to the event (or
1135
+	 *                                                       empty in the case of defaults)
1136
+	 *
1137
+	 * @return [type] [description]
1138
+	 */
1139
+	protected function _get_ticket_row(
1140
+		$tktrow,
1141
+		$ticket,
1142
+		$ticket_datetimes,
1143
+		$all_dtts,
1144
+		$default = false,
1145
+		$all_tickets = array()
1146
+	) {
1147
+        
1148
+		//if $ticket is not an instance of EE_Ticket then force default to true.
1149
+		$default = ! $ticket instanceof EE_Ticket ? true : false;
1150
+        
1151
+		$prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price',
1152
+			array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array();
1153
+        
1154
+		//if there is only one price (which would be the base price) or NO prices and this ticket is a default ticket, let's just make sure there are no cached default prices on
1155
+		//the object.  This is done by not including any query_params.
1156
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1157
+			$prices = $ticket->get_many_related('Price');
1158
+		}
1159
+        
1160
+		// check if we're dealing with a default ticket in which case we don't want any starting_ticket_datetime_row values set (otherwise there won't be any new relationships created for tickets based off of the default ticket).  This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1161
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')) ? true : false;
1162
+        
1163
+		$tkt_dtts = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1164
+        
1165
+		$ticket_subtotal  = $default ? 0 : $ticket->get_ticket_subtotal();
1166
+		$base_price       = $default ? null : $ticket->base_price();
1167
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1168
+        
1169
+		//breaking out complicated condition for ticket_status
1170
+		if ($default) {
1171
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1172
+		} else {
1173
+			$ticket_status_class = $ticket->is_default() ? ' tkt-status-' . EE_Ticket::onsale : ' tkt-status-' . $ticket->ticket_status();
1174
+		}
1175
+        
1176
+		//breaking out complicated condition for TKT_taxable
1177
+		if ($default) {
1178
+			$TKT_taxable = '';
1179
+		} else {
1180
+			$TKT_taxable = $ticket->get('TKT_taxable') ? ' checked="checked"' : '';
1181
+		}
1182 1182
 
1183 1183
         
1184
-        $template_args = array(
1185
-            'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1186
-            'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1187
-            //on initial page load this will always be the correct order.
1188
-            'tkt_status_class'              => $ticket_status_class,
1189
-            'display_edit_tkt_row'          => ' style="display:none;"',
1190
-            'edit_tkt_expanded'             => '',
1191
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1192
-            'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1193
-            'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1194
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1195
-            'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1196
-                $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1197
-            'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1198
-                'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
-                'sentence') : $ticket->ticket_status(true),
1200
-            'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1201
-                false, false),
1202
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1203
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1204
-            'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1205
-            'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1206
-            'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1207
-            'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1208
-            'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1209
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1210
-            'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1211
-                array(
1212
-                    'STS_ID' => array(
1213
-                        '!=',
1214
-                        EEM_Registration::status_id_incomplete
1215
-                    )
1216
-                )
1217
-            )),
1218
-            'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1219
-            'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1220
-            'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1221
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1222
-            'TKT_is_default_selector'       => '',
1223
-            'ticket_price_rows'             => '',
1224
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1225
-                'localized_float'),
1226
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1227
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1228
-            'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1229
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1230
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1231
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1232
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1233
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1234
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1235
-            'TKT_taxable'                   => $TKT_taxable,
1236
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1237
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1238
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1239
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1240
-            'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1241
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1242
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1243
-            'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1244
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1245
-        );
1246
-        
1247
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1248
-        
1249
-        //handle rows that should NOT be empty
1250
-        if (empty($template_args['TKT_start_date'])) {
1251
-            //if empty then the start date will be now.
1252
-            $template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1253
-                current_time('timestamp'));
1254
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1255
-        }
1256
-        
1257
-        if (empty($template_args['TKT_end_date'])) {
1184
+		$template_args = array(
1185
+			'tkt_row'                       => $default ? 'TICKETNUM' : $tktrow,
1186
+			'TKT_order'                     => $default ? 'TICKETNUM' : $tktrow,
1187
+			//on initial page load this will always be the correct order.
1188
+			'tkt_status_class'              => $ticket_status_class,
1189
+			'display_edit_tkt_row'          => ' style="display:none;"',
1190
+			'edit_tkt_expanded'             => '',
1191
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1192
+			'TKT_name'                      => $default ? '' : $ticket->get('TKT_name'),
1193
+			'TKT_start_date'                => $default ? '' : $ticket->get_date('TKT_start_date',
1194
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1195
+			'TKT_end_date'                  => $default ? '' : $ticket->get_date('TKT_end_date',
1196
+				$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']),
1197
+			'TKT_status'                    => $default ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1198
+				'sentence') : $ticket->is_default() ? EEH_Template::pretty_status(EE_Ticket::onsale, false,
1199
+				'sentence') : $ticket->ticket_status(true),
1200
+			'TKT_price'                     => $default ? '' : EEH_Template::format_currency($ticket->get_ticket_total_with_taxes(),
1201
+				false, false),
1202
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1203
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1204
+			'TKT_qty'                       => $default ? '' : $ticket->get_pretty('TKT_qty', 'symbol'),
1205
+			'TKT_qty_for_input'             => $default ? '' : $ticket->get_pretty('TKT_qty', 'input'),
1206
+			'TKT_uses'                      => $default ? '' : $ticket->get_pretty('TKT_uses', 'input'),
1207
+			'TKT_min'                       => $default ? '' : ($ticket->get('TKT_min') === -1 || $ticket->get('TKT_min') === 0 ? '' : $ticket->get('TKT_min')),
1208
+			'TKT_max'                       => $default ? '' : $ticket->get_pretty('TKT_max', 'input'),
1209
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1210
+			'TKT_registrations'             => $default ? 0 : $ticket->count_registrations(array(
1211
+				array(
1212
+					'STS_ID' => array(
1213
+						'!=',
1214
+						EEM_Registration::status_id_incomplete
1215
+					)
1216
+				)
1217
+			)),
1218
+			'TKT_ID'                        => $default ? 0 : $ticket->get('TKT_ID'),
1219
+			'TKT_description'               => $default ? '' : $ticket->get('TKT_description'),
1220
+			'TKT_is_default'                => $default ? 0 : $ticket->get('TKT_is_default'),
1221
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1222
+			'TKT_is_default_selector'       => '',
1223
+			'ticket_price_rows'             => '',
1224
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price ? '' : $base_price->get_pretty('PRC_amount',
1225
+				'localized_float'),
1226
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1227
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0) ? '' : ' style="display:none;"',
1228
+			'show_price_mod_button'         => count($prices) > 1 || ($default && $count_price_mods > 0) || ( ! $default && $ticket->get('TKT_deleted')) ? ' style="display:none;"' : '',
1229
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1230
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1231
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_dtts),
1232
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_dtts),
1233
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1234
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1235
+			'TKT_taxable'                   => $TKT_taxable,
1236
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') ? '' : ' style="display:none"',
1237
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1238
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency($ticket_subtotal, false, false),
1239
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1240
+			'tax_rows'                      => $this->_get_tax_rows($tktrow, $ticket),
1241
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? true : false,
1242
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? ' ticket-archived' : '',
1243
+			'trash_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? 'ee-lock-icon ' : 'trash-icon dashicons dashicons-post-trash clickable',
1244
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') ? '' : 'clone-icon ee-icon ee-icon-clone clickable'
1245
+		);
1246
+        
1247
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] != 'ee-lock-icon' ? ' style="display:none"' : '';
1248
+        
1249
+		//handle rows that should NOT be empty
1250
+		if (empty($template_args['TKT_start_date'])) {
1251
+			//if empty then the start date will be now.
1252
+			$template_args['TKT_start_date']   = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1253
+				current_time('timestamp'));
1254
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1255
+		}
1256
+        
1257
+		if (empty($template_args['TKT_end_date'])) {
1258 1258
             
1259
-            //get the earliest datetime (if present);
1260
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1261
-                array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1259
+			//get the earliest datetime (if present);
1260
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related('Datetime',
1261
+				array('order_by' => array('DTT_EVT_start' => 'ASC'))) : null;
1262 1262
             
1263
-            if ( ! empty($earliest_dtt)) {
1264
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1265
-                    $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1266
-            } else {
1267
-                //default so let's just use what's been set for the default date-time which is 30 days from now.
1268
-                $template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1269
-                    mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1270
-            }
1271
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1272
-        }
1273
-        
1274
-        //generate ticket_datetime items
1275
-        if ( ! $default) {
1276
-            $dttrow = 1;
1277
-            foreach ($all_dtts as $dtt) {
1278
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1279
-                    $ticket, $ticket_datetimes, $default);
1280
-                $dttrow++;
1281
-            }
1282
-        }
1283
-        
1284
-        $prcrow = 1;
1285
-        foreach ($prices as $price) {
1286
-            if ($price->is_base_price()) {
1287
-                $prcrow++;
1288
-                continue;
1289
-            }
1290
-            $show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1291
-            $show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1292
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1293
-                $ticket, $show_trash, $show_create);
1294
-            $prcrow++;
1295
-        }
1296
-        
1297
-        //filter $template_args
1298
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1299
-            $template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1300
-            $this->_is_creating_event);
1301
-        
1302
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1303
-        
1304
-        return EEH_Template::display_template($template, $template_args, true);
1305
-    }
1263
+			if ( ! empty($earliest_dtt)) {
1264
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start',
1265
+					$this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']);
1266
+			} else {
1267
+				//default so let's just use what's been set for the default date-time which is 30 days from now.
1268
+				$template_args['TKT_end_date'] = date($this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time'],
1269
+					mktime(24, 0, 0, date("m"), date("d") + 29, date("Y")));
1270
+			}
1271
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1272
+		}
1273
+        
1274
+		//generate ticket_datetime items
1275
+		if ( ! $default) {
1276
+			$dttrow = 1;
1277
+			foreach ($all_dtts as $dtt) {
1278
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow, $tktrow, $dtt,
1279
+					$ticket, $ticket_datetimes, $default);
1280
+				$dttrow++;
1281
+			}
1282
+		}
1283
+        
1284
+		$prcrow = 1;
1285
+		foreach ($prices as $price) {
1286
+			if ($price->is_base_price()) {
1287
+				$prcrow++;
1288
+				continue;
1289
+			}
1290
+			$show_trash  = (count($prices) > 1 && $prcrow === 1) || count($prices) === 1 ? false : true;
1291
+			$show_create = count($prices) > 1 && count($prices) !== $prcrow ? false : true;
1292
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row($tktrow, $prcrow, $price, $default,
1293
+				$ticket, $show_trash, $show_create);
1294
+			$prcrow++;
1295
+		}
1296
+        
1297
+		//filter $template_args
1298
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1299
+			$template_args, $tktrow, $ticket, $ticket_datetimes, $all_dtts, $default, $all_tickets,
1300
+			$this->_is_creating_event);
1301
+        
1302
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php';
1303
+        
1304
+		return EEH_Template::display_template($template, $template_args, true);
1305
+	}
1306 1306
     
1307 1307
     
1308
-    protected function _get_tax_rows($tktrow, $ticket)
1309
-    {
1310
-        $tax_rows      = '';
1311
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1312
-        $template_args = array();
1313
-        $taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1314
-        foreach ($taxes as $tax) {
1315
-            $tax_added     = $this->_get_tax_added($tax, $ticket);
1316
-            $template_args = array(
1317
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1318
-                'tax_id'            => $tax->ID(),
1319
-                'tkt_row'           => $tktrow,
1320
-                'tax_label'         => $tax->get('PRC_name'),
1321
-                'tax_added'         => $tax_added,
1322
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1323
-                'tax_amount'        => $tax->get('PRC_amount')
1324
-            );
1325
-            $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1326
-                $template_args, $tktrow, $ticket, $this->_is_creating_event);
1327
-            $tax_rows .= EEH_Template::display_template($template, $template_args, true);
1328
-        }
1329
-        
1330
-        
1331
-        return $tax_rows;
1332
-    }
1308
+	protected function _get_tax_rows($tktrow, $ticket)
1309
+	{
1310
+		$tax_rows      = '';
1311
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php';
1312
+		$template_args = array();
1313
+		$taxes         = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1314
+		foreach ($taxes as $tax) {
1315
+			$tax_added     = $this->_get_tax_added($tax, $ticket);
1316
+			$template_args = array(
1317
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable') ? '' : ' style="display:none;"',
1318
+				'tax_id'            => $tax->ID(),
1319
+				'tkt_row'           => $tktrow,
1320
+				'tax_label'         => $tax->get('PRC_name'),
1321
+				'tax_added'         => $tax_added,
1322
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1323
+				'tax_amount'        => $tax->get('PRC_amount')
1324
+			);
1325
+			$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1326
+				$template_args, $tktrow, $ticket, $this->_is_creating_event);
1327
+			$tax_rows .= EEH_Template::display_template($template, $template_args, true);
1328
+		}
1329
+        
1330
+        
1331
+		return $tax_rows;
1332
+	}
1333 1333
     
1334 1334
     
1335
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1336
-    {
1337
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1335
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1336
+	{
1337
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1338 1338
         
1339
-        return $subtotal * $tax->get('PRC_amount') / 100;
1340
-    }
1339
+		return $subtotal * $tax->get('PRC_amount') / 100;
1340
+	}
1341 1341
     
1342 1342
     
1343
-    protected function _get_ticket_price_row(
1344
-        $tktrow,
1345
-        $prcrow,
1346
-        $price,
1347
-        $default,
1348
-        $ticket,
1349
-        $show_trash = true,
1350
-        $show_create = true
1351
-    ) {
1352
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1353
-        $template_args = array(
1354
-            'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1355
-            'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1356
-            'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1357
-            'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1358
-                $price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1359
-            'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1360
-            'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1361
-            'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1362
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1363
-            'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1364
-            'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1365
-            'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1366
-            'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1367
-            'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1368
-                'localized_float'),
1369
-            'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1370
-            'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1371
-            'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1372
-            'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1373
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1374
-        );
1375
-        
1376
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1377
-            $template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1378
-            $this->_is_creating_event);
1379
-        
1380
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1381
-        
1382
-        return EEH_Template::display_template($template, $template_args, true);
1383
-    }
1343
+	protected function _get_ticket_price_row(
1344
+		$tktrow,
1345
+		$prcrow,
1346
+		$price,
1347
+		$default,
1348
+		$ticket,
1349
+		$show_trash = true,
1350
+		$show_create = true
1351
+	) {
1352
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false;
1353
+		$template_args = array(
1354
+			'tkt_row'               => $default && empty($ticket) ? 'TICKETNUM' : $tktrow,
1355
+			'PRC_order'             => $default && empty($price) ? 'PRICENUM' : $prcrow,
1356
+			'edit_prices_name'      => $default && empty($price) ? 'PRICENAMEATTR' : 'edit_prices',
1357
+			'price_type_selector'   => $default && empty($price) ? $this->_get_base_price_template($tktrow, $prcrow,
1358
+				$price, $default) : $this->_get_price_type_selector($tktrow, $prcrow, $price, $default, $send_disabled),
1359
+			'PRC_ID'                => $default && empty($price) ? 0 : $price->ID(),
1360
+			'PRC_is_default'        => $default && empty($price) ? 0 : $price->get('PRC_is_default'),
1361
+			'PRC_name'              => $default && empty($price) ? '' : $price->get('PRC_name'),
1362
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1363
+			'show_plus_or_minus'    => $default && empty($price) ? '' : ' style="display:none;"',
1364
+			'show_plus'             => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() || $price->is_base_price() ? ' style="display:none;"' : ''),
1365
+			'show_minus'            => $default && empty($price) ? ' style="display:none;"' : ($price->is_discount() ? '' : ' style="display:none;"'),
1366
+			'show_currency_symbol'  => $default && empty($price) ? ' style="display:none"' : ($price->is_percent() ? ' style="display:none"' : ''),
1367
+			'PRC_amount'            => $default && empty($price) ? 0 : $price->get_pretty('PRC_amount',
1368
+				'localized_float'),
1369
+			'show_percentage'       => $default && empty($price) ? ' style="display:none;"' : ($price->is_percent() ? '' : ' style="display:none;"'),
1370
+			'show_trash_icon'       => $show_trash ? '' : ' style="display:none;"',
1371
+			'show_create_button'    => $show_create ? '' : ' style="display:none;"',
1372
+			'PRC_desc'              => $default && empty($price) ? '' : $price->get('PRC_desc'),
1373
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false
1374
+		);
1375
+        
1376
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1377
+			$template_args, $tktrow, $prcrow, $price, $default, $ticket, $show_trash, $show_create,
1378
+			$this->_is_creating_event);
1379
+        
1380
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php';
1381
+        
1382
+		return EEH_Template::display_template($template, $template_args, true);
1383
+	}
1384 1384
     
1385 1385
     
1386
-    protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1387
-    {
1388
-        if ($price->is_base_price()) {
1389
-            return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1390
-        } else {
1391
-            return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1392
-        }
1393
-        
1394
-    }
1386
+	protected function _get_price_type_selector($tktrow, $prcrow, $price, $default, $disabled = false)
1387
+	{
1388
+		if ($price->is_base_price()) {
1389
+			return $this->_get_base_price_template($tktrow, $prcrow, $price, $default);
1390
+		} else {
1391
+			return $this->_get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled);
1392
+		}
1393
+        
1394
+	}
1395 1395
     
1396 1396
     
1397
-    protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1398
-    {
1399
-        $template_args = array(
1400
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1401
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1402
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1403
-            'PRT_name'                  => __('Price', 'event_espresso'),
1404
-            'price_selected_operator'   => '+',
1405
-            'price_selected_is_percent' => 0
1406
-        );
1407
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1408
-        
1409
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1410
-            $template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1411
-        
1412
-        return EEH_Template::display_template($template, $template_args, true);
1413
-    }
1397
+	protected function _get_base_price_template($tktrow, $prcrow, $price, $default)
1398
+	{
1399
+		$template_args = array(
1400
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1401
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1402
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1403
+			'PRT_name'                  => __('Price', 'event_espresso'),
1404
+			'price_selected_operator'   => '+',
1405
+			'price_selected_is_percent' => 0
1406
+		);
1407
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php';
1408
+        
1409
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1410
+			$template_args, $tktrow, $prcrow, $price, $default, $this->_is_creating_event);
1411
+        
1412
+		return EEH_Template::display_template($template, $template_args, true);
1413
+	}
1414 1414
     
1415 1415
     
1416
-    protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1417
-    {
1418
-        $select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1419
-        $price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1420
-            array(
1421
-                'OR' => array(
1422
-                    'PBT_ID'  => '2',
1423
-                    'PBT_ID*' => '3'
1424
-                )
1425
-            )
1426
-        ));
1427
-        $price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1428
-        $all_price_types            = $default && empty($price) ? array(
1429
-            array(
1430
-                'id'   => 0,
1431
-                'text' => __('Select Modifier', 'event_espresso')
1432
-            )
1433
-        ) : array();
1434
-        $selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1435
-        $price_option_spans         = '';
1436
-        //setup pricetypes for selector
1437
-        foreach ($price_types as $price_type) {
1438
-            $all_price_types[] = array(
1439
-                'id'   => $price_type->ID(),
1440
-                'text' => $price_type->get('PRT_name'),
1441
-            );
1416
+	protected function _get_price_modifier_template($tktrow, $prcrow, $price, $default, $disabled = false)
1417
+	{
1418
+		$select_name                = $default && empty($price) ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' : 'edit_prices[' . $tktrow . '][' . $prcrow . '][PRT_ID]';
1419
+		$price_types                = EE_Registry::instance()->load_model('Price_Type')->get_all(array(
1420
+			array(
1421
+				'OR' => array(
1422
+					'PBT_ID'  => '2',
1423
+					'PBT_ID*' => '3'
1424
+				)
1425
+			)
1426
+		));
1427
+		$price_option_span_template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php';
1428
+		$all_price_types            = $default && empty($price) ? array(
1429
+			array(
1430
+				'id'   => 0,
1431
+				'text' => __('Select Modifier', 'event_espresso')
1432
+			)
1433
+		) : array();
1434
+		$selected_price_type_id     = $default && empty($price) ? 0 : $price->type();
1435
+		$price_option_spans         = '';
1436
+		//setup pricetypes for selector
1437
+		foreach ($price_types as $price_type) {
1438
+			$all_price_types[] = array(
1439
+				'id'   => $price_type->ID(),
1440
+				'text' => $price_type->get('PRT_name'),
1441
+			);
1442 1442
             
1443
-            //while we're in the loop let's setup the option spans used by js
1444
-            $spanargs = array(
1445
-                'PRT_ID'         => $price_type->ID(),
1446
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1447
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1448
-            );
1449
-            $price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1450
-        }
1451
-        
1452
-        $select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1453
-        $main_name     = $select_name;
1454
-        $select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1455
-        
1456
-        $template_args = array(
1457
-            'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1458
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1459
-            'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1460
-                $selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1461
-            'main_name'                 => $main_name,
1462
-            'selected_price_type_id'    => $selected_price_type_id,
1463
-            'price_option_spans'        => $price_option_spans,
1464
-            'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1465
-            'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1466
-            'disabled'                  => $disabled
1467
-        );
1468
-        
1469
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1470
-            $template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1471
-        
1472
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1473
-        
1474
-        return EEH_Template::display_template($template, $template_args, true);
1475
-    }
1443
+			//while we're in the loop let's setup the option spans used by js
1444
+			$spanargs = array(
1445
+				'PRT_ID'         => $price_type->ID(),
1446
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1447
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0
1448
+			);
1449
+			$price_option_spans .= EEH_Template::display_template($price_option_span_template, $spanargs, true);
1450
+		}
1451
+        
1452
+		$select_params = $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"';
1453
+		$main_name     = $select_name;
1454
+		$select_name   = $disabled ? 'archive_price[' . $tktrow . '][' . $prcrow . '][PRT_ID]' : $main_name;
1455
+        
1456
+		$template_args = array(
1457
+			'tkt_row'                   => $default ? 'TICKETNUM' : $tktrow,
1458
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $prcrow,
1459
+			'price_modifier_selector'   => EEH_Form_Fields::select_input($select_name, $all_price_types,
1460
+				$selected_price_type_id, $select_params, 'edit-price-PRT_ID'),
1461
+			'main_name'                 => $main_name,
1462
+			'selected_price_type_id'    => $selected_price_type_id,
1463
+			'price_option_spans'        => $price_option_spans,
1464
+			'price_selected_operator'   => $default && empty($price) ? '' : ($price->is_discount() ? '-' : '+'),
1465
+			'price_selected_is_percent' => $default && empty($price) ? '' : ($price->is_percent() ? 1 : 0),
1466
+			'disabled'                  => $disabled
1467
+		);
1468
+        
1469
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1470
+			$template_args, $tktrow, $prcrow, $price, $default, $disabled, $this->_is_creating_event);
1471
+        
1472
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php';
1473
+        
1474
+		return EEH_Template::display_template($template, $template_args, true);
1475
+	}
1476 1476
     
1477 1477
     
1478
-    protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1479
-    {
1480
-        $tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1481
-        $template_args = array(
1482
-            'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1483
-            'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1484
-            'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1485
-            'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1486
-            'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1487
-            'tkt_status_class'         => '',
1488
-        );
1489
-        
1490
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1491
-            $template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1492
-        $template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1493
-        
1494
-        return EEH_Template::display_template($template, $template_args, true);
1495
-    }
1478
+	protected function _get_ticket_datetime_list_item($dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default)
1479
+	{
1480
+		$tkt_dtts      = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) ? $ticket_datetimes[$ticket->ID()] : array();
1481
+		$template_args = array(
1482
+			'dtt_row'                  => $default && ! $dtt instanceof EE_Datetime ? 'DTTNUM' : $dttrow,
1483
+			'tkt_row'                  => $default ? 'TICKETNUM' : $tktrow,
1484
+			'ticket_datetime_selected' => in_array($dttrow, $tkt_dtts) ? ' ticket-selected' : '',
1485
+			'ticket_datetime_checked'  => in_array($dttrow, $tkt_dtts) ? ' checked="checked"' : '',
1486
+			'DTT_name'                 => $default && empty($dtt) ? 'DTTNAME' : $dtt->get_dtt_display_name(true),
1487
+			'tkt_status_class'         => '',
1488
+		);
1489
+        
1490
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
1491
+			$template_args, $dttrow, $tktrow, $dtt, $ticket, $ticket_datetimes, $default, $this->_is_creating_event);
1492
+		$template      = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php';
1493
+        
1494
+		return EEH_Template::display_template($template, $template_args, true);
1495
+	}
1496 1496
     
1497 1497
     
1498
-    protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1499
-    {
1500
-        $template_args = array(
1501
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1502
-            'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1503
-                true),
1504
-            'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1505
-                true, null),
1506
-            'default_price_rows'                       => '',
1507
-            'default_base_price_amount'                => 0,
1508
-            'default_base_price_name'                  => '',
1509
-            'default_base_price_description'           => '',
1510
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1511
-                null, true),
1512
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1513
-                array(), true),
1514
-            'existing_available_datetime_tickets_list' => '',
1515
-            'existing_available_ticket_datetimes_list' => '',
1516
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1517
-                null, null, array(), true),
1518
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1519
-                null, null, array(), true)
1520
-        );
1521
-        
1522
-        $tktrow = 1;
1523
-        foreach ($all_tickets as $ticket) {
1524
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1525
-                $tktrow, null, $ticket, array(), true);
1526
-            $tktrow++;
1527
-        }
1528
-        
1529
-        
1530
-        $dttrow = 1;
1531
-        foreach ($all_dtts as $dtt) {
1532
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1533
-                'TICKETNUM', $dtt, null, array(), true);
1534
-            $dttrow++;
1535
-        }
1536
-        
1537
-        $default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1538
-        $prcrow         = 1;
1539
-        foreach ($default_prices as $price) {
1540
-            if ($price->is_base_price()) {
1541
-                $template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1542
-                $template_args['default_base_price_name']        = $price->get('PRC_name');
1543
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
1544
-                $prcrow++;
1545
-                continue;
1546
-            }
1547
-            $show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1548
-            $show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1549
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1550
-                null, $show_trash, $show_create);
1551
-            $prcrow++;
1552
-        }
1553
-        
1554
-        $template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1555
-            $template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1556
-        
1557
-        $template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1558
-        
1559
-        return EEH_Template::display_template($template, $template_args, true);
1560
-    }
1498
+	protected function _get_ticket_js_structure($all_dtts, $all_tickets)
1499
+	{
1500
+		$template_args = array(
1501
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row('DTTNUM', null, true, $all_dtts),
1502
+			'default_ticket_row'                       => $this->_get_ticket_row('TICKETNUM', null, array(), array(),
1503
+				true),
1504
+			'default_price_row'                        => $this->_get_ticket_price_row('TICKETNUM', 'PRICENUM', null,
1505
+				true, null),
1506
+			'default_price_rows'                       => '',
1507
+			'default_base_price_amount'                => 0,
1508
+			'default_base_price_name'                  => '',
1509
+			'default_base_price_description'           => '',
1510
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template('TICKETNUM', 'PRICENUM',
1511
+				null, true),
1512
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row('DTTNUM', null, array(),
1513
+				array(), true),
1514
+			'existing_available_datetime_tickets_list' => '',
1515
+			'existing_available_ticket_datetimes_list' => '',
1516
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item('DTTNUM', 'TICKETNUM',
1517
+				null, null, array(), true),
1518
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item('DTTNUM', 'TICKETNUM',
1519
+				null, null, array(), true)
1520
+		);
1521
+        
1522
+		$tktrow = 1;
1523
+		foreach ($all_tickets as $ticket) {
1524
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item('DTTNUM',
1525
+				$tktrow, null, $ticket, array(), true);
1526
+			$tktrow++;
1527
+		}
1528
+        
1529
+        
1530
+		$dttrow = 1;
1531
+		foreach ($all_dtts as $dtt) {
1532
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item($dttrow,
1533
+				'TICKETNUM', $dtt, null, array(), true);
1534
+			$dttrow++;
1535
+		}
1536
+        
1537
+		$default_prices = EE_Registry::instance()->load_model('Price')->get_all_default_prices();
1538
+		$prcrow         = 1;
1539
+		foreach ($default_prices as $price) {
1540
+			if ($price->is_base_price()) {
1541
+				$template_args['default_base_price_amount']      = $price->get_pretty('PRC_amount', 'localized_float');
1542
+				$template_args['default_base_price_name']        = $price->get('PRC_name');
1543
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
1544
+				$prcrow++;
1545
+				continue;
1546
+			}
1547
+			$show_trash  = (count($default_prices) > 1 && $prcrow === 1) || count($default_prices) === 1 ? false : true;
1548
+			$show_create = count($default_prices) > 1 && count($default_prices) !== $prcrow ? false : true;
1549
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row('TICKETNUM', $prcrow, $price, true,
1550
+				null, $show_trash, $show_create);
1551
+			$prcrow++;
1552
+		}
1553
+        
1554
+		$template_args = apply_filters('FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
1555
+			$template_args, $all_dtts, $all_tickets, $this->_is_creating_event);
1556
+        
1557
+		$template = PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php';
1558
+        
1559
+		return EEH_Template::display_template($template, $template_args, true);
1560
+	}
1561 1561
     
1562 1562
     
1563 1563
 } //end class espresso_events_Pricing_Hooks
Please login to merge, or discard this patch.
core/EE_Registry.core.php 1 patch
Indentation   +1336 added lines, -1336 removed lines patch added patch discarded remove patch
@@ -16,1372 +16,1372 @@
 block discarded – undo
16 16
 class EE_Registry
17 17
 {
18 18
 
19
-    /**
20
-     *    EE_Registry Object
21
-     *
22
-     * @var EE_Registry $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance = null;
26
-
27
-    /**
28
-     * @var EE_Dependency_Map $_dependency_map
29
-     * @access    protected
30
-     */
31
-    protected $_dependency_map = null;
32
-
33
-    /**
34
-     * @var array $_class_abbreviations
35
-     * @access    protected
36
-     */
37
-    protected $_class_abbreviations = array();
38
-
39
-    /**
40
-     * @access public
41
-     * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
-     */
43
-    public $BUS;
44
-
45
-    /**
46
-     *    EE_Cart Object
47
-     *
48
-     * @access    public
49
-     * @var    EE_Cart $CART
50
-     */
51
-    public $CART = null;
52
-
53
-    /**
54
-     *    EE_Config Object
55
-     *
56
-     * @access    public
57
-     * @var    EE_Config $CFG
58
-     */
59
-    public $CFG = null;
60
-
61
-    /**
62
-     * EE_Network_Config Object
63
-     *
64
-     * @access public
65
-     * @var EE_Network_Config $NET_CFG
66
-     */
67
-    public $NET_CFG = null;
68
-
69
-    /**
70
-     *    StdClass object for storing library classes in
71
-     *
72
-     * @public LIB
73
-     * @var StdClass $LIB
74
-     */
75
-    public $LIB = null;
76
-
77
-    /**
78
-     *    EE_Request_Handler Object
79
-     *
80
-     * @access    public
81
-     * @var    EE_Request_Handler $REQ
82
-     */
83
-    public $REQ = null;
84
-
85
-    /**
86
-     *    EE_Session Object
87
-     *
88
-     * @access    public
89
-     * @var    EE_Session $SSN
90
-     */
91
-    public $SSN = null;
92
-
93
-    /**
94
-     * holds the ee capabilities object.
95
-     *
96
-     * @since 4.5.0
97
-     * @var EE_Capabilities
98
-     */
99
-    public $CAP = null;
100
-
101
-    /**
102
-     * holds the EE_Message_Resource_Manager object.
103
-     *
104
-     * @since 4.9.0
105
-     * @var EE_Message_Resource_Manager
106
-     */
107
-    public $MRM = null;
108
-
109
-
110
-    /**
111
-     * Holds the Assets Registry instance
112
-     * @var Registry
113
-     */
114
-    public $AssetsRegistry = null;
115
-
116
-    /**
117
-     *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
-     *
119
-     * @access    public
120
-     * @var    EE_Addon[]
121
-     */
122
-    public $addons = null;
123
-
124
-    /**
125
-     *    $models
126
-     * @access    public
127
-     * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
-     */
129
-    public $models = array();
130
-
131
-    /**
132
-     *    $modules
133
-     * @access    public
134
-     * @var    EED_Module[] $modules
135
-     */
136
-    public $modules = null;
137
-
138
-    /**
139
-     *    $shortcodes
140
-     * @access    public
141
-     * @var    EES_Shortcode[] $shortcodes
142
-     */
143
-    public $shortcodes = null;
144
-
145
-    /**
146
-     *    $widgets
147
-     * @access    public
148
-     * @var    WP_Widget[] $widgets
149
-     */
150
-    public $widgets = null;
151
-
152
-    /**
153
-     * $non_abstract_db_models
154
-     * @access public
155
-     * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
-     * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
-     * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
-     * classnames (eg "EEM_Event")
159
-     */
160
-    public $non_abstract_db_models = array();
161
-
162
-
163
-    /**
164
-     *    $i18n_js_strings - internationalization for JS strings
165
-     *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
-     *    in js file:  var translatedString = eei18n.string_key;
167
-     *
168
-     * @access    public
169
-     * @var    array
170
-     */
171
-    public static $i18n_js_strings = array();
172
-
173
-
174
-    /**
175
-     *    $main_file - path to espresso.php
176
-     *
177
-     * @access    public
178
-     * @var    array
179
-     */
180
-    public $main_file;
181
-
182
-    /**
183
-     * array of ReflectionClass objects where the key is the class name
184
-     *
185
-     * @access    public
186
-     * @var ReflectionClass[]
187
-     */
188
-    public $_reflectors;
189
-
190
-    /**
191
-     * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
-     *
193
-     * @access    protected
194
-     * @var boolean $_cache_on
195
-     */
196
-    protected $_cache_on = true;
197
-
198
-
199
-
200
-    /**
201
-     * @singleton method used to instantiate class object
202
-     * @access    public
203
-     * @param  \EE_Dependency_Map $dependency_map
204
-     * @return \EE_Registry instance
205
-     */
206
-    public static function instance(\EE_Dependency_Map $dependency_map = null)
207
-    {
208
-        // check if class object is instantiated
209
-        if ( ! self::$_instance instanceof EE_Registry) {
210
-            self::$_instance = new EE_Registry($dependency_map);
211
-        }
212
-        return self::$_instance;
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     *protected constructor to prevent direct creation
219
-     *
220
-     * @Constructor
221
-     * @access protected
222
-     * @param  \EE_Dependency_Map $dependency_map
223
-     * @return \EE_Registry
224
-     */
225
-    protected function __construct(\EE_Dependency_Map $dependency_map)
226
-    {
227
-        $this->_dependency_map = $dependency_map;
228
-        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * initialize
235
-     */
236
-    public function initialize()
237
-    {
238
-        $this->_class_abbreviations = apply_filters(
239
-            'FHEE__EE_Registry____construct___class_abbreviations',
240
-            array(
241
-                'EE_Config'                                       => 'CFG',
242
-                'EE_Session'                                      => 'SSN',
243
-                'EE_Capabilities'                                 => 'CAP',
244
-                'EE_Cart'                                         => 'CART',
245
-                'EE_Network_Config'                               => 'NET_CFG',
246
-                'EE_Request_Handler'                              => 'REQ',
247
-                'EE_Message_Resource_Manager'                     => 'MRM',
248
-                'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
-            )
250
-        );
251
-        // class library
252
-        $this->LIB = new stdClass();
253
-        $this->addons = new stdClass();
254
-        $this->modules = new stdClass();
255
-        $this->shortcodes = new stdClass();
256
-        $this->widgets = new stdClass();
257
-        $this->load_core('Base', array(), true);
258
-        // add our request and response objects to the cache
259
-        $request_loader = $this->_dependency_map->class_loader('EE_Request');
260
-        $this->_set_cached_class(
261
-            $request_loader(),
262
-            'EE_Request'
263
-        );
264
-        $response_loader = $this->_dependency_map->class_loader('EE_Response');
265
-        $this->_set_cached_class(
266
-            $response_loader(),
267
-            'EE_Response'
268
-        );
269
-        add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     *    init
276
-     *
277
-     * @access    public
278
-     * @return    void
279
-     */
280
-    public function init()
281
-    {
282
-        $this->AssetsRegistry = new Registry();
283
-        // Get current page protocol
284
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
-        // Output admin-ajax.php URL with same protocol as current page
286
-        self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
-        self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
-    }
289
-
290
-
291
-
292
-    /**
293
-     * localize_i18n_js_strings
294
-     *
295
-     * @return string
296
-     */
297
-    public static function localize_i18n_js_strings()
298
-    {
299
-        $i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
-        foreach ($i18n_js_strings as $key => $value) {
301
-            if (is_scalar($value)) {
302
-                $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
-            }
304
-        }
305
-        return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
-    }
307
-
308
-
309
-
310
-    /**
311
-     * @param mixed string | EED_Module $module
312
-     */
313
-    public function add_module($module)
314
-    {
315
-        if ($module instanceof EED_Module) {
316
-            $module_class = get_class($module);
317
-            $this->modules->{$module_class} = $module;
318
-        } else {
319
-            if ( ! class_exists('EE_Module_Request_Router')) {
320
-                $this->load_core('Module_Request_Router');
321
-            }
322
-            $this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
-        }
324
-    }
325
-
326
-
327
-
328
-    /**
329
-     * @param string $module_name
330
-     * @return mixed EED_Module | NULL
331
-     */
332
-    public function get_module($module_name = '')
333
-    {
334
-        return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     *    loads core classes - must be singletons
341
-     *
342
-     * @access    public
343
-     * @param string $class_name - simple class name ie: session
344
-     * @param mixed  $arguments
345
-     * @param bool   $load_only
346
-     * @return mixed
347
-     */
348
-    public function load_core($class_name, $arguments = array(), $load_only = false)
349
-    {
350
-        $core_paths = apply_filters(
351
-            'FHEE__EE_Registry__load_core__core_paths',
352
-            array(
353
-                EE_CORE,
354
-                EE_ADMIN,
355
-                EE_CPTS,
356
-                EE_CORE . 'data_migration_scripts' . DS,
357
-                EE_CORE . 'request_stack' . DS,
358
-                EE_CORE . 'middleware' . DS,
359
-            )
360
-        );
361
-        // retrieve instantiated class
362
-        return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
-    }
364
-
365
-
366
-
367
-    /**
368
-     *    loads service classes
369
-     *
370
-     * @access    public
371
-     * @param string $class_name - simple class name ie: session
372
-     * @param mixed  $arguments
373
-     * @param bool   $load_only
374
-     * @return mixed
375
-     */
376
-    public function load_service($class_name, $arguments = array(), $load_only = false)
377
-    {
378
-        $service_paths = apply_filters(
379
-            'FHEE__EE_Registry__load_service__service_paths',
380
-            array(
381
-                EE_CORE . 'services' . DS,
382
-            )
383
-        );
384
-        // retrieve instantiated class
385
-        return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
-    }
387
-
388
-
389
-
390
-    /**
391
-     *    loads data_migration_scripts
392
-     *
393
-     * @access    public
394
-     * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
-     * @param mixed  $arguments
396
-     * @return EE_Data_Migration_Script_Base|mixed
397
-     */
398
-    public function load_dms($class_name, $arguments = array())
399
-    {
400
-        // retrieve instantiated class
401
-        return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     *    loads object creating classes - must be singletons
408
-     *
409
-     * @param string $class_name - simple class name ie: attendee
410
-     * @param mixed  $arguments  - an array of arguments to pass to the class
411
-     * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
-     * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
413
-     * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
-     * @return EE_Base_Class | bool
415
-     */
416
-    public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
-    {
418
-        $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
-            EE_CORE,
420
-            EE_CLASSES,
421
-            EE_BUSINESS,
422
-        ));
423
-        // retrieve instantiated class
424
-        return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     *    loads helper classes - must be singletons
431
-     *
432
-     * @param string $class_name - simple class name ie: price
433
-     * @param mixed  $arguments
434
-     * @param bool   $load_only
435
-     * @return EEH_Base | bool
436
-     */
437
-    public function load_helper($class_name, $arguments = array(), $load_only = true)
438
-    {
439
-        // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
-        $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
-        // retrieve instantiated class
442
-        return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     *    loads core classes - must be singletons
449
-     *
450
-     * @access    public
451
-     * @param string $class_name - simple class name ie: session
452
-     * @param mixed  $arguments
453
-     * @param bool   $load_only
454
-     * @param bool   $cache      whether to cache the object or not.
455
-     * @return mixed
456
-     */
457
-    public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
-    {
459
-        $paths = array(
460
-            EE_LIBRARIES,
461
-            EE_LIBRARIES . 'messages' . DS,
462
-            EE_LIBRARIES . 'shortcodes' . DS,
463
-            EE_LIBRARIES . 'qtips' . DS,
464
-            EE_LIBRARIES . 'payment_methods' . DS,
465
-        );
466
-        // retrieve instantiated class
467
-        return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
-    }
469
-
470
-
471
-
472
-    /**
473
-     *    loads model classes - must be singletons
474
-     *
475
-     * @param string $class_name - simple class name ie: price
476
-     * @param mixed  $arguments
477
-     * @param bool   $load_only
478
-     * @return EEM_Base | bool
479
-     */
480
-    public function load_model($class_name, $arguments = array(), $load_only = false)
481
-    {
482
-        $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
-            EE_MODELS,
484
-            EE_CORE,
485
-        ));
486
-        // retrieve instantiated class
487
-        return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
-    }
489
-
490
-
491
-
492
-    /**
493
-     *    loads model classes - must be singletons
494
-     *
495
-     * @param string $class_name - simple class name ie: price
496
-     * @param mixed  $arguments
497
-     * @param bool   $load_only
498
-     * @return mixed | bool
499
-     */
500
-    public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
-    {
502
-        $paths = array(
503
-            EE_MODELS . 'fields' . DS,
504
-            EE_MODELS . 'helpers' . DS,
505
-            EE_MODELS . 'relations' . DS,
506
-            EE_MODELS . 'strategies' . DS,
507
-        );
508
-        // retrieve instantiated class
509
-        return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Determines if $model_name is the name of an actual EE model.
516
-     *
517
-     * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
-     * @return boolean
519
-     */
520
-    public function is_model_name($model_name)
521
-    {
522
-        return isset($this->models[$model_name]) ? true : false;
523
-    }
524
-
525
-
526
-
527
-    /**
528
-     *    generic class loader
529
-     *
530
-     * @param string $path_to_file - directory path to file location, not including filename
531
-     * @param string $file_name    - file name  ie:  my_file.php, including extension
532
-     * @param string $type         - file type - core? class? helper? model?
533
-     * @param mixed  $arguments
534
-     * @param bool   $load_only
535
-     * @return mixed
536
-     */
537
-    public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
-    {
539
-        // retrieve instantiated class
540
-        return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     *    load_addon
547
-     *
548
-     * @param string $path_to_file - directory path to file location, not including filename
549
-     * @param string $class_name   - full class name  ie:  My_Class
550
-     * @param string $type         - file type - core? class? helper? model?
551
-     * @param mixed  $arguments
552
-     * @param bool   $load_only
553
-     * @return EE_Addon
554
-     */
555
-    public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
-    {
557
-        // retrieve instantiated class
558
-        return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
-    }
560
-
561
-
562
-
563
-    /**
564
-     * instantiates, caches, and automatically resolves dependencies
565
-     * for classes that use a Fully Qualified Class Name.
566
-     * if the class is not capable of being loaded using PSR-4 autoloading,
567
-     * then you need to use one of the existing load_*() methods
568
-     * which can resolve the classname and filepath from the passed arguments
569
-     *
570
-     * @param bool|string $class_name   Fully Qualified Class Name
571
-     * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
-     * @param bool        $cache        whether to cache the instantiated object for reuse
573
-     * @param bool        $from_db      some classes are instantiated from the db
574
-     *                                  and thus call a different method to instantiate
575
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
-     * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
-     * @return mixed                    null = failure to load or instantiate class object.
578
-     *                                  object = class loaded and instantiated successfully.
579
-     *                                  bool = fail or success when $load_only is true
580
-     */
581
-    public function create(
582
-        $class_name = false,
583
-        $arguments = array(),
584
-        $cache = false,
585
-        $from_db = false,
586
-        $load_only = false,
587
-        $addon = false
588
-    ) {
589
-        $class_name = $this->_dependency_map->get_alias($class_name);
590
-        if ( ! class_exists($class_name)) {
591
-            // maybe the class is registered with a preceding \
592
-            $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
593
-            // still doesn't exist ?
594
-            if ( ! class_exists($class_name)) {
595
-                return null;
596
-            }
597
-        }
598
-        // if we're only loading the class and it already exists, then let's just return true immediately
599
-        if ($load_only) {
600
-            return true;
601
-        }
602
-        $addon = $addon ? 'addon' : '';
603
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
604
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
605
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
606
-        if ($this->_cache_on && $cache && ! $load_only) {
607
-            // return object if it's already cached
608
-            $cached_class = $this->_get_cached_class($class_name, $addon);
609
-            if ($cached_class !== null) {
610
-                return $cached_class;
611
-            }
612
-        }
613
-        // instantiate the requested object
614
-        $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
615
-        if ($this->_cache_on && $cache) {
616
-            // save it for later... kinda like gum  { : $
617
-            $this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
618
-        }
619
-        $this->_cache_on = true;
620
-        return $class_obj;
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * instantiates, caches, and injects dependencies for classes
627
-     *
628
-     * @param array       $file_paths   an array of paths to folders to look in
629
-     * @param string      $class_prefix EE  or EEM or... ???
630
-     * @param bool|string $class_name   $class name
631
-     * @param string      $type         file type - core? class? helper? model?
632
-     * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
633
-     * @param bool        $from_db      some classes are instantiated from the db
634
-     *                                  and thus call a different method to instantiate
635
-     * @param bool        $cache        whether to cache the instantiated object for reuse
636
-     * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
637
-     * @return null|object|bool         null = failure to load or instantiate class object.
638
-     *                                  object = class loaded and instantiated successfully.
639
-     *                                  bool = fail or success when $load_only is true
640
-     */
641
-    protected function _load(
642
-        $file_paths = array(),
643
-        $class_prefix = 'EE_',
644
-        $class_name = false,
645
-        $type = 'class',
646
-        $arguments = array(),
647
-        $from_db = false,
648
-        $cache = true,
649
-        $load_only = false
650
-    ) {
651
-        // strip php file extension
652
-        $class_name = str_replace('.php', '', trim($class_name));
653
-        // does the class have a prefix ?
654
-        if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
-            // make sure $class_prefix is uppercase
656
-            $class_prefix = strtoupper(trim($class_prefix));
657
-            // add class prefix ONCE!!!
658
-            $class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
-        }
660
-        $class_name = $this->_dependency_map->get_alias($class_name);
661
-        $class_exists = class_exists($class_name);
662
-        // if we're only loading the class and it already exists, then let's just return true immediately
663
-        if ($load_only && $class_exists) {
664
-            return true;
665
-        }
666
-        // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
-        // $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
-        // $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
-        if ($this->_cache_on && $cache && ! $load_only) {
670
-            // return object if it's already cached
671
-            $cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
-            if ($cached_class !== null) {
673
-                return $cached_class;
674
-            }
675
-        }
676
-        // if the class doesn't already exist.. then we need to try and find the file and load it
677
-        if ( ! $class_exists) {
678
-            // get full path to file
679
-            $path = $this->_resolve_path($class_name, $type, $file_paths);
680
-            // load the file
681
-            $loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
-            // if loading failed, or we are only loading a file but NOT instantiating an object
683
-            if ( ! $loaded || $load_only) {
684
-                // return boolean if only loading, or null if an object was expected
685
-                return $load_only ? $loaded : null;
686
-            }
687
-        }
688
-        // instantiate the requested object
689
-        $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
-        if ($this->_cache_on && $cache) {
691
-            // save it for later... kinda like gum  { : $
692
-            $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
-        }
694
-        $this->_cache_on = true;
695
-        return $class_obj;
696
-    }
697
-
698
-
699
-
700
-    /**
701
-     * _get_cached_class
702
-     * attempts to find a cached version of the requested class
703
-     * by looking in the following places:
704
-     *        $this->{$class_abbreviation}            ie:    $this->CART
705
-     *        $this->{$class_name}                        ie:    $this->Some_Class
706
-     *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
707
-     *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
708
-     *
709
-     * @access protected
710
-     * @param string $class_name
711
-     * @param string $class_prefix
712
-     * @return mixed
713
-     */
714
-    protected function _get_cached_class($class_name, $class_prefix = '')
715
-    {
716
-        if (isset($this->_class_abbreviations[$class_name])) {
717
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
718
-        } else {
719
-            // have to specify something, but not anything that will conflict
720
-            $class_abbreviation = 'FANCY_BATMAN_PANTS';
721
-        }
722
-        // check if class has already been loaded, and return it if it has been
723
-        if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
-            return $this->{$class_abbreviation};
725
-        } else if (isset ($this->{$class_name})) {
726
-            return $this->{$class_name};
727
-        } else if (isset ($this->LIB->{$class_name})) {
728
-            return $this->LIB->{$class_name};
729
-        } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
730
-            return $this->addons->{$class_name};
731
-        }
732
-        return null;
733
-    }
734
-
735
-
736
-
737
-    /**
738
-     * _resolve_path
739
-     * attempts to find a full valid filepath for the requested class.
740
-     * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
741
-     * then returns that path if the target file has been found and is readable
742
-     *
743
-     * @access protected
744
-     * @param string $class_name
745
-     * @param string $type
746
-     * @param array  $file_paths
747
-     * @return string | bool
748
-     */
749
-    protected function _resolve_path($class_name, $type = '', $file_paths = array())
750
-    {
751
-        // make sure $file_paths is an array
752
-        $file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
753
-        // cycle thru paths
754
-        foreach ($file_paths as $key => $file_path) {
755
-            // convert all separators to proper DS, if no filepath, then use EE_CLASSES
756
-            $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
757
-            // prep file type
758
-            $type = ! empty($type) ? trim($type, '.') . '.' : '';
759
-            // build full file path
760
-            $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
761
-            //does the file exist and can be read ?
762
-            if (is_readable($file_paths[$key])) {
763
-                return $file_paths[$key];
764
-            }
765
-        }
766
-        return false;
767
-    }
768
-
769
-
770
-
771
-    /**
772
-     * _require_file
773
-     * basically just performs a require_once()
774
-     * but with some error handling
775
-     *
776
-     * @access protected
777
-     * @param  string $path
778
-     * @param  string $class_name
779
-     * @param  string $type
780
-     * @param  array  $file_paths
781
-     * @return boolean
782
-     * @throws \EE_Error
783
-     */
784
-    protected function _require_file($path, $class_name, $type = '', $file_paths = array())
785
-    {
786
-        // don't give up! you gotta...
787
-        try {
788
-            //does the file exist and can it be read ?
789
-            if ( ! $path) {
790
-                // so sorry, can't find the file
791
-                throw new EE_Error (
792
-                    sprintf(
793
-                        __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
794
-                        trim($type, '.'),
795
-                        $class_name,
796
-                        '<br />' . implode(',<br />', $file_paths)
797
-                    )
798
-                );
799
-            }
800
-            // get the file
801
-            require_once($path);
802
-            // if the class isn't already declared somewhere
803
-            if (class_exists($class_name, false) === false) {
804
-                // so sorry, not a class
805
-                throw new EE_Error(
806
-                    sprintf(
807
-                        __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
808
-                        $type,
809
-                        $path,
810
-                        $class_name
811
-                    )
812
-                );
813
-            }
814
-        } catch (EE_Error $e) {
815
-            $e->get_error();
816
-            return false;
817
-        }
818
-        return true;
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * _create_object
825
-     * Attempts to instantiate the requested class via any of the
826
-     * commonly used instantiation methods employed throughout EE.
827
-     * The priority for instantiation is as follows:
828
-     *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
829
-     *        - model objects via their 'new_instance_from_db' method
830
-     *        - model objects via their 'new_instance' method
831
-     *        - "singleton" classes" via their 'instance' method
832
-     *    - standard instantiable classes via their __constructor
833
-     * Prior to instantiation, if the classname exists in the dependency_map,
834
-     * then the constructor for the requested class will be examined to determine
835
-     * if any dependencies exist, and if they can be injected.
836
-     * If so, then those classes will be added to the array of arguments passed to the constructor
837
-     *
838
-     * @access protected
839
-     * @param string $class_name
840
-     * @param array  $arguments
841
-     * @param string $type
842
-     * @param bool   $from_db
843
-     * @return null | object
844
-     * @throws \EE_Error
845
-     */
846
-    protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
847
-    {
848
-        $class_obj = null;
849
-        $instantiation_mode = '0) none';
850
-        // don't give up! you gotta...
851
-        try {
852
-            // create reflection
853
-            $reflector = $this->get_ReflectionClass($class_name);
854
-            // make sure arguments are an array
855
-            $arguments = is_array($arguments) ? $arguments : array($arguments);
856
-            // and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
857
-            // else wrap it in an additional array so that it doesn't get split into multiple parameters
858
-            $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
859
-                ? $arguments
860
-                : array($arguments);
861
-            // attempt to inject dependencies ?
862
-            if ($this->_dependency_map->has($class_name)) {
863
-                $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
864
-            }
865
-            // instantiate the class if possible
866
-            if ($reflector->isAbstract()) {
867
-                // nothing to instantiate, loading file was enough
868
-                // does not throw an exception so $instantiation_mode is unused
869
-                // $instantiation_mode = "1) no constructor abstract class";
870
-                $class_obj = true;
871
-            } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
872
-                // no constructor = static methods only... nothing to instantiate, loading file was enough
873
-                $instantiation_mode = "2) no constructor but instantiable";
874
-                $class_obj = $reflector->newInstance();
875
-            } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
876
-                $instantiation_mode = "3) new_instance_from_db()";
877
-                $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
878
-            } else if (method_exists($class_name, 'new_instance')) {
879
-                $instantiation_mode = "4) new_instance()";
880
-                $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
881
-            } else if (method_exists($class_name, 'instance')) {
882
-                $instantiation_mode = "5) instance()";
883
-                $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
884
-            } else if ($reflector->isInstantiable()) {
885
-                $instantiation_mode = "6) constructor";
886
-                $class_obj = $reflector->newInstanceArgs($arguments);
887
-            } else {
888
-                // heh ? something's not right !
889
-                throw new EE_Error(
890
-                    sprintf(
891
-                        __('The %s file %s could not be instantiated.', 'event_espresso'),
892
-                        $type,
893
-                        $class_name
894
-                    )
895
-                );
896
-            }
897
-        } catch (Exception $e) {
898
-            if ( ! $e instanceof EE_Error) {
899
-                $e = new EE_Error(
900
-                    sprintf(
901
-                        __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
902
-                        $class_name,
903
-                        '<br />',
904
-                        $e->getMessage(),
905
-                        $instantiation_mode
906
-                    )
907
-                );
908
-            }
909
-            $e->get_error();
910
-        }
911
-        return $class_obj;
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
918
-     * @param array $array
919
-     * @return bool
920
-     */
921
-    protected function _array_is_numerically_and_sequentially_indexed(array $array)
922
-    {
923
-        return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * getReflectionClass
930
-     * checks if a ReflectionClass object has already been generated for a class
931
-     * and returns that instead of creating a new one
932
-     *
933
-     * @access public
934
-     * @param string $class_name
935
-     * @return ReflectionClass
936
-     */
937
-    public function get_ReflectionClass($class_name)
938
-    {
939
-        if (
940
-            ! isset($this->_reflectors[$class_name])
941
-            || ! $this->_reflectors[$class_name] instanceof ReflectionClass
942
-        ) {
943
-            $this->_reflectors[$class_name] = new ReflectionClass($class_name);
944
-        }
945
-        return $this->_reflectors[$class_name];
946
-    }
947
-
948
-
949
-
950
-    /**
951
-     * _resolve_dependencies
952
-     * examines the constructor for the requested class to determine
953
-     * if any dependencies exist, and if they can be injected.
954
-     * If so, then those classes will be added to the array of arguments passed to the constructor
955
-     * PLZ NOTE: this is achieved by type hinting the constructor params
956
-     * For example:
957
-     *        if attempting to load a class "Foo" with the following constructor:
958
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
959
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
960
-     *        but only IF they are NOT already present in the incoming arguments array,
961
-     *        and the correct classes can be loaded
962
-     *
963
-     * @access protected
964
-     * @param ReflectionClass $reflector
965
-     * @param string          $class_name
966
-     * @param array           $arguments
967
-     * @return array
968
-     * @throws \ReflectionException
969
-     */
970
-    protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
971
-    {
972
-        // let's examine the constructor
973
-        $constructor = $reflector->getConstructor();
974
-        // whu? huh? nothing?
975
-        if ( ! $constructor) {
976
-            return $arguments;
977
-        }
978
-        // get constructor parameters
979
-        $params = $constructor->getParameters();
980
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
981
-        $argument_keys = array_keys($arguments);
982
-        // now loop thru all of the constructors expected parameters
983
-        foreach ($params as $index => $param) {
984
-            // is this a dependency for a specific class ?
985
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
986
-            if (
987
-                // param is not even a class
988
-                empty($param_class)
989
-                // and something already exists in the incoming arguments for this param
990
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
991
-            ) {
992
-                // so let's skip this argument and move on to the next
993
-                continue;
994
-            } else if (
995
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
996
-                ! empty($param_class)
997
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
998
-                && $arguments[$argument_keys[$index]] instanceof $param_class
999
-            ) {
1000
-                // skip this argument and move on to the next
1001
-                continue;
1002
-            } else if (
1003
-                // parameter is type hinted as a class, and should be injected
1004
-                ! empty($param_class)
1005
-                && $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1006
-            ) {
1007
-                $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1008
-            } else {
1009
-                try {
1010
-                    $arguments[$index] = $param->getDefaultValue();
1011
-                } catch (ReflectionException $e) {
1012
-                    throw new ReflectionException(
1013
-                        sprintf(
1014
-                            __('%1$s for parameter "$%2$s"', 'event_espresso'),
1015
-                            $e->getMessage(),
1016
-                            $param->getName()
1017
-                        )
1018
-                    );
1019
-                }
1020
-            }
1021
-        }
1022
-        return $arguments;
1023
-    }
1024
-
1025
-
1026
-
1027
-    /**
1028
-     * @access protected
1029
-     * @param string $class_name
1030
-     * @param string $param_class
1031
-     * @param array  $arguments
1032
-     * @param mixed  $index
1033
-     * @return array
1034
-     */
1035
-    protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1036
-    {
1037
-        $dependency = null;
1038
-        // should dependency be loaded from cache ?
1039
-        $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1040
-                    !== EE_Dependency_Map::load_new_object
1041
-            ? true
1042
-            : false;
1043
-        // we might have a dependency...
1044
-        // let's MAYBE try and find it in our cache if that's what's been requested
1045
-        $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1046
-        // and grab it if it exists
1047
-        if ($cached_class instanceof $param_class) {
1048
-            $dependency = $cached_class;
1049
-        } else if ($param_class != $class_name) {
1050
-            // obtain the loader method from the dependency map
1051
-            $loader = $this->_dependency_map->class_loader($param_class);
1052
-            // is loader a custom closure ?
1053
-            if ($loader instanceof Closure) {
1054
-                $dependency = $loader();
1055
-            } else {
1056
-                // set the cache on property for the recursive loading call
1057
-                $this->_cache_on = $cache_on;
1058
-                // if not, then let's try and load it via the registry
1059
-                if (method_exists($this, $loader)) {
1060
-                    $dependency = $this->{$loader}($param_class);
1061
-                } else {
1062
-                    $dependency = $this->create($param_class, array(), $cache_on);
1063
-                }
1064
-            }
1065
-        }
1066
-        // did we successfully find the correct dependency ?
1067
-        if ($dependency instanceof $param_class) {
1068
-            // then let's inject it into the incoming array of arguments at the correct location
1069
-            if (isset($argument_keys[$index])) {
1070
-                $arguments[$argument_keys[$index]] = $dependency;
1071
-            } else {
1072
-                $arguments[$index] = $dependency;
1073
-            }
1074
-        }
1075
-        return $arguments;
1076
-    }
1077
-
1078
-
1079
-
1080
-    /**
1081
-     * _set_cached_class
1082
-     * attempts to cache the instantiated class locally
1083
-     * in one of the following places, in the following order:
1084
-     *        $this->{class_abbreviation}   ie:    $this->CART
1085
-     *        $this->{$class_name}          ie:    $this->Some_Class
1086
-     *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1087
-     *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1088
-     *
1089
-     * @access protected
1090
-     * @param object $class_obj
1091
-     * @param string $class_name
1092
-     * @param string $class_prefix
1093
-     * @param bool   $from_db
1094
-     * @return void
1095
-     */
1096
-    protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1097
-    {
1098
-        if (empty($class_obj)) {
1099
-            return;
1100
-        }
1101
-        // return newly instantiated class
1102
-        if (isset($this->_class_abbreviations[$class_name])) {
1103
-            $class_abbreviation = $this->_class_abbreviations[$class_name];
1104
-            $this->{$class_abbreviation} = $class_obj;
1105
-        } else if (property_exists($this, $class_name)) {
1106
-            $this->{$class_name} = $class_obj;
1107
-        } else if ($class_prefix == 'addon') {
1108
-            $this->addons->{$class_name} = $class_obj;
1109
-        } else if ( ! $from_db) {
1110
-            $this->LIB->{$class_name} = $class_obj;
1111
-        }
1112
-    }
1113
-
1114
-
1115
-
1116
-    /**
1117
-     * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1118
-     *
1119
-     * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1120
-     *                          in the EE_Dependency_Map::$_class_loaders array,
1121
-     *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1122
-     * @param array  $arguments
1123
-     * @return object
1124
-     */
1125
-    public static function factory($classname, $arguments = array())
1126
-    {
1127
-        $loader = self::instance()->_dependency_map->class_loader($classname);
1128
-        if ($loader instanceof Closure) {
1129
-            return $loader($arguments);
1130
-        } else if (method_exists(EE_Registry::instance(), $loader)) {
1131
-            return EE_Registry::instance()->{$loader}($classname, $arguments);
1132
-        }
1133
-        return null;
1134
-    }
1135
-
1136
-
1137
-
1138
-    /**
1139
-     * Gets the addon by its name/slug (not classname. For that, just
1140
-     * use the classname as the property name on EE_Config::instance()->addons)
1141
-     *
1142
-     * @param string $name
1143
-     * @return EE_Addon
1144
-     */
1145
-    public function get_addon_by_name($name)
1146
-    {
1147
-        foreach ($this->addons as $addon) {
1148
-            if ($addon->name() == $name) {
1149
-                return $addon;
1150
-            }
1151
-        }
1152
-        return null;
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1159
-     * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1160
-     *
1161
-     * @return EE_Addon[] where the KEYS are the addon's name()
1162
-     */
1163
-    public function get_addons_by_name()
1164
-    {
1165
-        $addons = array();
1166
-        foreach ($this->addons as $addon) {
1167
-            $addons[$addon->name()] = $addon;
1168
-        }
1169
-        return $addons;
1170
-    }
1171
-
1172
-
1173
-
1174
-    /**
1175
-     * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1176
-     * a stale copy of it around
1177
-     *
1178
-     * @param string $model_name
1179
-     * @return \EEM_Base
1180
-     * @throws \EE_Error
1181
-     */
1182
-    public function reset_model($model_name)
1183
-    {
1184
-        $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1185
-        if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1186
-            return null;
1187
-        }
1188
-        //get that model reset it and make sure we nuke the old reference to it
1189
-        if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1190
-            $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1191
-        } else {
1192
-            throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1193
-        }
1194
-        return $this->LIB->{$model_class_name};
1195
-    }
1196
-
1197
-
1198
-
1199
-    /**
1200
-     * Resets the registry.
1201
-     * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1202
-     * is used in a multisite install.  Here is a list of things that are NOT reset.
1203
-     * - $_dependency_map
1204
-     * - $_class_abbreviations
1205
-     * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1206
-     * - $REQ:  Still on the same request so no need to change.
1207
-     * - $CAP: There is no site specific state in the EE_Capability class.
1208
-     * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1209
-     *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1210
-     * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1211
-     *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1212
-     *             switch or on the restore.
1213
-     * - $modules
1214
-     * - $shortcodes
1215
-     * - $widgets
1216
-     *
1217
-     * @param boolean $hard             whether to reset data in the database too, or just refresh
1218
-     *                                  the Registry to its state at the beginning of the request
1219
-     * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1220
-     *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1221
-     *                                  currently reinstantiate the singletons at the moment)
1222
-     * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1223
-     *                                  code instead can just change the model context to a different blog id if necessary
1224
-     * @return EE_Registry
1225
-     */
1226
-    public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1227
-    {
1228
-        $instance = self::instance();
1229
-        EEH_Activation::reset();
1230
-        //properties that get reset
1231
-        $instance->_cache_on = true;
1232
-        $instance->CFG = EE_Config::reset($hard, $reinstantiate);
1233
-        $instance->CART = null;
1234
-        $instance->MRM = null;
1235
-        $instance->AssetsRegistry = new Registry();
1236
-        //messages reset
1237
-        EED_Messages::reset();
1238
-        if ($reset_models) {
1239
-            foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1240
-                $instance->reset_model($model_name);
1241
-            }
1242
-        }
1243
-        $instance->LIB = new stdClass();
1244
-        return $instance;
1245
-    }
1246
-
1247
-
1248
-
1249
-    /**
1250
-     * @override magic methods
1251
-     * @return void
1252
-     */
1253
-    final function __destruct()
1254
-    {
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * @param $a
1261
-     * @param $b
1262
-     */
1263
-    final function __call($a, $b)
1264
-    {
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     * @param $a
1271
-     */
1272
-    final function __get($a)
1273
-    {
1274
-    }
1275
-
1276
-
1277
-
1278
-    /**
1279
-     * @param $a
1280
-     * @param $b
1281
-     */
1282
-    final function __set($a, $b)
1283
-    {
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * @param $a
1290
-     */
1291
-    final function __isset($a)
1292
-    {
1293
-    }
19
+	/**
20
+	 *    EE_Registry Object
21
+	 *
22
+	 * @var EE_Registry $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance = null;
26
+
27
+	/**
28
+	 * @var EE_Dependency_Map $_dependency_map
29
+	 * @access    protected
30
+	 */
31
+	protected $_dependency_map = null;
32
+
33
+	/**
34
+	 * @var array $_class_abbreviations
35
+	 * @access    protected
36
+	 */
37
+	protected $_class_abbreviations = array();
38
+
39
+	/**
40
+	 * @access public
41
+	 * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS
42
+	 */
43
+	public $BUS;
44
+
45
+	/**
46
+	 *    EE_Cart Object
47
+	 *
48
+	 * @access    public
49
+	 * @var    EE_Cart $CART
50
+	 */
51
+	public $CART = null;
52
+
53
+	/**
54
+	 *    EE_Config Object
55
+	 *
56
+	 * @access    public
57
+	 * @var    EE_Config $CFG
58
+	 */
59
+	public $CFG = null;
60
+
61
+	/**
62
+	 * EE_Network_Config Object
63
+	 *
64
+	 * @access public
65
+	 * @var EE_Network_Config $NET_CFG
66
+	 */
67
+	public $NET_CFG = null;
68
+
69
+	/**
70
+	 *    StdClass object for storing library classes in
71
+	 *
72
+	 * @public LIB
73
+	 * @var StdClass $LIB
74
+	 */
75
+	public $LIB = null;
76
+
77
+	/**
78
+	 *    EE_Request_Handler Object
79
+	 *
80
+	 * @access    public
81
+	 * @var    EE_Request_Handler $REQ
82
+	 */
83
+	public $REQ = null;
84
+
85
+	/**
86
+	 *    EE_Session Object
87
+	 *
88
+	 * @access    public
89
+	 * @var    EE_Session $SSN
90
+	 */
91
+	public $SSN = null;
92
+
93
+	/**
94
+	 * holds the ee capabilities object.
95
+	 *
96
+	 * @since 4.5.0
97
+	 * @var EE_Capabilities
98
+	 */
99
+	public $CAP = null;
100
+
101
+	/**
102
+	 * holds the EE_Message_Resource_Manager object.
103
+	 *
104
+	 * @since 4.9.0
105
+	 * @var EE_Message_Resource_Manager
106
+	 */
107
+	public $MRM = null;
108
+
109
+
110
+	/**
111
+	 * Holds the Assets Registry instance
112
+	 * @var Registry
113
+	 */
114
+	public $AssetsRegistry = null;
115
+
116
+	/**
117
+	 *    $addons - StdClass object for holding addons which have registered themselves to work with EE core
118
+	 *
119
+	 * @access    public
120
+	 * @var    EE_Addon[]
121
+	 */
122
+	public $addons = null;
123
+
124
+	/**
125
+	 *    $models
126
+	 * @access    public
127
+	 * @var    EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event')
128
+	 */
129
+	public $models = array();
130
+
131
+	/**
132
+	 *    $modules
133
+	 * @access    public
134
+	 * @var    EED_Module[] $modules
135
+	 */
136
+	public $modules = null;
137
+
138
+	/**
139
+	 *    $shortcodes
140
+	 * @access    public
141
+	 * @var    EES_Shortcode[] $shortcodes
142
+	 */
143
+	public $shortcodes = null;
144
+
145
+	/**
146
+	 *    $widgets
147
+	 * @access    public
148
+	 * @var    WP_Widget[] $widgets
149
+	 */
150
+	public $widgets = null;
151
+
152
+	/**
153
+	 * $non_abstract_db_models
154
+	 * @access public
155
+	 * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models
156
+	 * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)).
157
+	 * Keys are model "short names" (eg "Event") as used in model relations, and values are
158
+	 * classnames (eg "EEM_Event")
159
+	 */
160
+	public $non_abstract_db_models = array();
161
+
162
+
163
+	/**
164
+	 *    $i18n_js_strings - internationalization for JS strings
165
+	 *    usage:   EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' );
166
+	 *    in js file:  var translatedString = eei18n.string_key;
167
+	 *
168
+	 * @access    public
169
+	 * @var    array
170
+	 */
171
+	public static $i18n_js_strings = array();
172
+
173
+
174
+	/**
175
+	 *    $main_file - path to espresso.php
176
+	 *
177
+	 * @access    public
178
+	 * @var    array
179
+	 */
180
+	public $main_file;
181
+
182
+	/**
183
+	 * array of ReflectionClass objects where the key is the class name
184
+	 *
185
+	 * @access    public
186
+	 * @var ReflectionClass[]
187
+	 */
188
+	public $_reflectors;
189
+
190
+	/**
191
+	 * boolean flag to indicate whether or not to load/save dependencies from/to the cache
192
+	 *
193
+	 * @access    protected
194
+	 * @var boolean $_cache_on
195
+	 */
196
+	protected $_cache_on = true;
197
+
198
+
199
+
200
+	/**
201
+	 * @singleton method used to instantiate class object
202
+	 * @access    public
203
+	 * @param  \EE_Dependency_Map $dependency_map
204
+	 * @return \EE_Registry instance
205
+	 */
206
+	public static function instance(\EE_Dependency_Map $dependency_map = null)
207
+	{
208
+		// check if class object is instantiated
209
+		if ( ! self::$_instance instanceof EE_Registry) {
210
+			self::$_instance = new EE_Registry($dependency_map);
211
+		}
212
+		return self::$_instance;
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 *protected constructor to prevent direct creation
219
+	 *
220
+	 * @Constructor
221
+	 * @access protected
222
+	 * @param  \EE_Dependency_Map $dependency_map
223
+	 * @return \EE_Registry
224
+	 */
225
+	protected function __construct(\EE_Dependency_Map $dependency_map)
226
+	{
227
+		$this->_dependency_map = $dependency_map;
228
+		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize'));
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * initialize
235
+	 */
236
+	public function initialize()
237
+	{
238
+		$this->_class_abbreviations = apply_filters(
239
+			'FHEE__EE_Registry____construct___class_abbreviations',
240
+			array(
241
+				'EE_Config'                                       => 'CFG',
242
+				'EE_Session'                                      => 'SSN',
243
+				'EE_Capabilities'                                 => 'CAP',
244
+				'EE_Cart'                                         => 'CART',
245
+				'EE_Network_Config'                               => 'NET_CFG',
246
+				'EE_Request_Handler'                              => 'REQ',
247
+				'EE_Message_Resource_Manager'                     => 'MRM',
248
+				'EventEspresso\core\services\commands\CommandBus' => 'BUS',
249
+			)
250
+		);
251
+		// class library
252
+		$this->LIB = new stdClass();
253
+		$this->addons = new stdClass();
254
+		$this->modules = new stdClass();
255
+		$this->shortcodes = new stdClass();
256
+		$this->widgets = new stdClass();
257
+		$this->load_core('Base', array(), true);
258
+		// add our request and response objects to the cache
259
+		$request_loader = $this->_dependency_map->class_loader('EE_Request');
260
+		$this->_set_cached_class(
261
+			$request_loader(),
262
+			'EE_Request'
263
+		);
264
+		$response_loader = $this->_dependency_map->class_loader('EE_Response');
265
+		$this->_set_cached_class(
266
+			$response_loader(),
267
+			'EE_Response'
268
+		);
269
+		add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init'));
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 *    init
276
+	 *
277
+	 * @access    public
278
+	 * @return    void
279
+	 */
280
+	public function init()
281
+	{
282
+		$this->AssetsRegistry = new Registry();
283
+		// Get current page protocol
284
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
285
+		// Output admin-ajax.php URL with same protocol as current page
286
+		self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol);
287
+		self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false;
288
+	}
289
+
290
+
291
+
292
+	/**
293
+	 * localize_i18n_js_strings
294
+	 *
295
+	 * @return string
296
+	 */
297
+	public static function localize_i18n_js_strings()
298
+	{
299
+		$i18n_js_strings = (array)EE_Registry::$i18n_js_strings;
300
+		foreach ($i18n_js_strings as $key => $value) {
301
+			if (is_scalar($value)) {
302
+				$i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8');
303
+			}
304
+		}
305
+		return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */';
306
+	}
307
+
308
+
309
+
310
+	/**
311
+	 * @param mixed string | EED_Module $module
312
+	 */
313
+	public function add_module($module)
314
+	{
315
+		if ($module instanceof EED_Module) {
316
+			$module_class = get_class($module);
317
+			$this->modules->{$module_class} = $module;
318
+		} else {
319
+			if ( ! class_exists('EE_Module_Request_Router')) {
320
+				$this->load_core('Module_Request_Router');
321
+			}
322
+			$this->modules->{$module} = EE_Module_Request_Router::module_factory($module);
323
+		}
324
+	}
325
+
326
+
327
+
328
+	/**
329
+	 * @param string $module_name
330
+	 * @return mixed EED_Module | NULL
331
+	 */
332
+	public function get_module($module_name = '')
333
+	{
334
+		return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 *    loads core classes - must be singletons
341
+	 *
342
+	 * @access    public
343
+	 * @param string $class_name - simple class name ie: session
344
+	 * @param mixed  $arguments
345
+	 * @param bool   $load_only
346
+	 * @return mixed
347
+	 */
348
+	public function load_core($class_name, $arguments = array(), $load_only = false)
349
+	{
350
+		$core_paths = apply_filters(
351
+			'FHEE__EE_Registry__load_core__core_paths',
352
+			array(
353
+				EE_CORE,
354
+				EE_ADMIN,
355
+				EE_CPTS,
356
+				EE_CORE . 'data_migration_scripts' . DS,
357
+				EE_CORE . 'request_stack' . DS,
358
+				EE_CORE . 'middleware' . DS,
359
+			)
360
+		);
361
+		// retrieve instantiated class
362
+		return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only);
363
+	}
364
+
365
+
366
+
367
+	/**
368
+	 *    loads service classes
369
+	 *
370
+	 * @access    public
371
+	 * @param string $class_name - simple class name ie: session
372
+	 * @param mixed  $arguments
373
+	 * @param bool   $load_only
374
+	 * @return mixed
375
+	 */
376
+	public function load_service($class_name, $arguments = array(), $load_only = false)
377
+	{
378
+		$service_paths = apply_filters(
379
+			'FHEE__EE_Registry__load_service__service_paths',
380
+			array(
381
+				EE_CORE . 'services' . DS,
382
+			)
383
+		);
384
+		// retrieve instantiated class
385
+		return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only);
386
+	}
387
+
388
+
389
+
390
+	/**
391
+	 *    loads data_migration_scripts
392
+	 *
393
+	 * @access    public
394
+	 * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0
395
+	 * @param mixed  $arguments
396
+	 * @return EE_Data_Migration_Script_Base|mixed
397
+	 */
398
+	public function load_dms($class_name, $arguments = array())
399
+	{
400
+		// retrieve instantiated class
401
+		return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 *    loads object creating classes - must be singletons
408
+	 *
409
+	 * @param string $class_name - simple class name ie: attendee
410
+	 * @param mixed  $arguments  - an array of arguments to pass to the class
411
+	 * @param bool   $from_db    - some classes are instantiated from the db and thus call a different method to instantiate
412
+	 * @param bool   $cache      if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop)
413
+	 * @param bool   $load_only  whether or not to just load the file and NOT instantiate, or load AND instantiate (default)
414
+	 * @return EE_Base_Class | bool
415
+	 */
416
+	public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false)
417
+	{
418
+		$paths = apply_filters('FHEE__EE_Registry__load_class__paths', array(
419
+			EE_CORE,
420
+			EE_CLASSES,
421
+			EE_BUSINESS,
422
+		));
423
+		// retrieve instantiated class
424
+		return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only);
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 *    loads helper classes - must be singletons
431
+	 *
432
+	 * @param string $class_name - simple class name ie: price
433
+	 * @param mixed  $arguments
434
+	 * @param bool   $load_only
435
+	 * @return EEH_Base | bool
436
+	 */
437
+	public function load_helper($class_name, $arguments = array(), $load_only = true)
438
+	{
439
+		// todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed
440
+		$helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS));
441
+		// retrieve instantiated class
442
+		return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only);
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 *    loads core classes - must be singletons
449
+	 *
450
+	 * @access    public
451
+	 * @param string $class_name - simple class name ie: session
452
+	 * @param mixed  $arguments
453
+	 * @param bool   $load_only
454
+	 * @param bool   $cache      whether to cache the object or not.
455
+	 * @return mixed
456
+	 */
457
+	public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true)
458
+	{
459
+		$paths = array(
460
+			EE_LIBRARIES,
461
+			EE_LIBRARIES . 'messages' . DS,
462
+			EE_LIBRARIES . 'shortcodes' . DS,
463
+			EE_LIBRARIES . 'qtips' . DS,
464
+			EE_LIBRARIES . 'payment_methods' . DS,
465
+		);
466
+		// retrieve instantiated class
467
+		return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only);
468
+	}
469
+
470
+
471
+
472
+	/**
473
+	 *    loads model classes - must be singletons
474
+	 *
475
+	 * @param string $class_name - simple class name ie: price
476
+	 * @param mixed  $arguments
477
+	 * @param bool   $load_only
478
+	 * @return EEM_Base | bool
479
+	 */
480
+	public function load_model($class_name, $arguments = array(), $load_only = false)
481
+	{
482
+		$paths = apply_filters('FHEE__EE_Registry__load_model__paths', array(
483
+			EE_MODELS,
484
+			EE_CORE,
485
+		));
486
+		// retrieve instantiated class
487
+		return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only);
488
+	}
489
+
490
+
491
+
492
+	/**
493
+	 *    loads model classes - must be singletons
494
+	 *
495
+	 * @param string $class_name - simple class name ie: price
496
+	 * @param mixed  $arguments
497
+	 * @param bool   $load_only
498
+	 * @return mixed | bool
499
+	 */
500
+	public function load_model_class($class_name, $arguments = array(), $load_only = true)
501
+	{
502
+		$paths = array(
503
+			EE_MODELS . 'fields' . DS,
504
+			EE_MODELS . 'helpers' . DS,
505
+			EE_MODELS . 'relations' . DS,
506
+			EE_MODELS . 'strategies' . DS,
507
+		);
508
+		// retrieve instantiated class
509
+		return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Determines if $model_name is the name of an actual EE model.
516
+	 *
517
+	 * @param string $model_name like Event, Attendee, Question_Group_Question, etc.
518
+	 * @return boolean
519
+	 */
520
+	public function is_model_name($model_name)
521
+	{
522
+		return isset($this->models[$model_name]) ? true : false;
523
+	}
524
+
525
+
526
+
527
+	/**
528
+	 *    generic class loader
529
+	 *
530
+	 * @param string $path_to_file - directory path to file location, not including filename
531
+	 * @param string $file_name    - file name  ie:  my_file.php, including extension
532
+	 * @param string $type         - file type - core? class? helper? model?
533
+	 * @param mixed  $arguments
534
+	 * @param bool   $load_only
535
+	 * @return mixed
536
+	 */
537
+	public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true)
538
+	{
539
+		// retrieve instantiated class
540
+		return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only);
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 *    load_addon
547
+	 *
548
+	 * @param string $path_to_file - directory path to file location, not including filename
549
+	 * @param string $class_name   - full class name  ie:  My_Class
550
+	 * @param string $type         - file type - core? class? helper? model?
551
+	 * @param mixed  $arguments
552
+	 * @param bool   $load_only
553
+	 * @return EE_Addon
554
+	 */
555
+	public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false)
556
+	{
557
+		// retrieve instantiated class
558
+		return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only);
559
+	}
560
+
561
+
562
+
563
+	/**
564
+	 * instantiates, caches, and automatically resolves dependencies
565
+	 * for classes that use a Fully Qualified Class Name.
566
+	 * if the class is not capable of being loaded using PSR-4 autoloading,
567
+	 * then you need to use one of the existing load_*() methods
568
+	 * which can resolve the classname and filepath from the passed arguments
569
+	 *
570
+	 * @param bool|string $class_name   Fully Qualified Class Name
571
+	 * @param array       $arguments    an argument, or array of arguments to pass to the class upon instantiation
572
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
573
+	 * @param bool        $from_db      some classes are instantiated from the db
574
+	 *                                  and thus call a different method to instantiate
575
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
576
+	 * @param bool|string $addon        if true, will cache the object in the EE_Registry->$addons array
577
+	 * @return mixed                    null = failure to load or instantiate class object.
578
+	 *                                  object = class loaded and instantiated successfully.
579
+	 *                                  bool = fail or success when $load_only is true
580
+	 */
581
+	public function create(
582
+		$class_name = false,
583
+		$arguments = array(),
584
+		$cache = false,
585
+		$from_db = false,
586
+		$load_only = false,
587
+		$addon = false
588
+	) {
589
+		$class_name = $this->_dependency_map->get_alias($class_name);
590
+		if ( ! class_exists($class_name)) {
591
+			// maybe the class is registered with a preceding \
592
+			$class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name;
593
+			// still doesn't exist ?
594
+			if ( ! class_exists($class_name)) {
595
+				return null;
596
+			}
597
+		}
598
+		// if we're only loading the class and it already exists, then let's just return true immediately
599
+		if ($load_only) {
600
+			return true;
601
+		}
602
+		$addon = $addon ? 'addon' : '';
603
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
604
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
605
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
606
+		if ($this->_cache_on && $cache && ! $load_only) {
607
+			// return object if it's already cached
608
+			$cached_class = $this->_get_cached_class($class_name, $addon);
609
+			if ($cached_class !== null) {
610
+				return $cached_class;
611
+			}
612
+		}
613
+		// instantiate the requested object
614
+		$class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db);
615
+		if ($this->_cache_on && $cache) {
616
+			// save it for later... kinda like gum  { : $
617
+			$this->_set_cached_class($class_obj, $class_name, $addon, $from_db);
618
+		}
619
+		$this->_cache_on = true;
620
+		return $class_obj;
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * instantiates, caches, and injects dependencies for classes
627
+	 *
628
+	 * @param array       $file_paths   an array of paths to folders to look in
629
+	 * @param string      $class_prefix EE  or EEM or... ???
630
+	 * @param bool|string $class_name   $class name
631
+	 * @param string      $type         file type - core? class? helper? model?
632
+	 * @param mixed       $arguments    an argument or array of arguments to pass to the class upon instantiation
633
+	 * @param bool        $from_db      some classes are instantiated from the db
634
+	 *                                  and thus call a different method to instantiate
635
+	 * @param bool        $cache        whether to cache the instantiated object for reuse
636
+	 * @param bool        $load_only    if true, will only load the file, but will NOT instantiate an object
637
+	 * @return null|object|bool         null = failure to load or instantiate class object.
638
+	 *                                  object = class loaded and instantiated successfully.
639
+	 *                                  bool = fail or success when $load_only is true
640
+	 */
641
+	protected function _load(
642
+		$file_paths = array(),
643
+		$class_prefix = 'EE_',
644
+		$class_name = false,
645
+		$type = 'class',
646
+		$arguments = array(),
647
+		$from_db = false,
648
+		$cache = true,
649
+		$load_only = false
650
+	) {
651
+		// strip php file extension
652
+		$class_name = str_replace('.php', '', trim($class_name));
653
+		// does the class have a prefix ?
654
+		if ( ! empty($class_prefix) && $class_prefix != 'addon') {
655
+			// make sure $class_prefix is uppercase
656
+			$class_prefix = strtoupper(trim($class_prefix));
657
+			// add class prefix ONCE!!!
658
+			$class_name = $class_prefix . str_replace($class_prefix, '', $class_name);
659
+		}
660
+		$class_name = $this->_dependency_map->get_alias($class_name);
661
+		$class_exists = class_exists($class_name);
662
+		// if we're only loading the class and it already exists, then let's just return true immediately
663
+		if ($load_only && $class_exists) {
664
+			return true;
665
+		}
666
+		// $this->_cache_on is toggled during the recursive loading that can occur with dependency injection
667
+		// $cache is controlled by individual calls to separate Registry loader methods like load_class()
668
+		// $load_only is also controlled by individual calls to separate Registry loader methods like load_file()
669
+		if ($this->_cache_on && $cache && ! $load_only) {
670
+			// return object if it's already cached
671
+			$cached_class = $this->_get_cached_class($class_name, $class_prefix);
672
+			if ($cached_class !== null) {
673
+				return $cached_class;
674
+			}
675
+		}
676
+		// if the class doesn't already exist.. then we need to try and find the file and load it
677
+		if ( ! $class_exists) {
678
+			// get full path to file
679
+			$path = $this->_resolve_path($class_name, $type, $file_paths);
680
+			// load the file
681
+			$loaded = $this->_require_file($path, $class_name, $type, $file_paths);
682
+			// if loading failed, or we are only loading a file but NOT instantiating an object
683
+			if ( ! $loaded || $load_only) {
684
+				// return boolean if only loading, or null if an object was expected
685
+				return $load_only ? $loaded : null;
686
+			}
687
+		}
688
+		// instantiate the requested object
689
+		$class_obj = $this->_create_object($class_name, $arguments, $type, $from_db);
690
+		if ($this->_cache_on && $cache) {
691
+			// save it for later... kinda like gum  { : $
692
+			$this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db);
693
+		}
694
+		$this->_cache_on = true;
695
+		return $class_obj;
696
+	}
697
+
698
+
699
+
700
+	/**
701
+	 * _get_cached_class
702
+	 * attempts to find a cached version of the requested class
703
+	 * by looking in the following places:
704
+	 *        $this->{$class_abbreviation}            ie:    $this->CART
705
+	 *        $this->{$class_name}                        ie:    $this->Some_Class
706
+	 *        $this->LIB->{$class_name}                ie:    $this->LIB->Some_Class
707
+	 *        $this->addon->{$class_name}    ie:    $this->addon->Some_Addon_Class
708
+	 *
709
+	 * @access protected
710
+	 * @param string $class_name
711
+	 * @param string $class_prefix
712
+	 * @return mixed
713
+	 */
714
+	protected function _get_cached_class($class_name, $class_prefix = '')
715
+	{
716
+		if (isset($this->_class_abbreviations[$class_name])) {
717
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
718
+		} else {
719
+			// have to specify something, but not anything that will conflict
720
+			$class_abbreviation = 'FANCY_BATMAN_PANTS';
721
+		}
722
+		// check if class has already been loaded, and return it if it has been
723
+		if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) {
724
+			return $this->{$class_abbreviation};
725
+		} else if (isset ($this->{$class_name})) {
726
+			return $this->{$class_name};
727
+		} else if (isset ($this->LIB->{$class_name})) {
728
+			return $this->LIB->{$class_name};
729
+		} else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) {
730
+			return $this->addons->{$class_name};
731
+		}
732
+		return null;
733
+	}
734
+
735
+
736
+
737
+	/**
738
+	 * _resolve_path
739
+	 * attempts to find a full valid filepath for the requested class.
740
+	 * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php"
741
+	 * then returns that path if the target file has been found and is readable
742
+	 *
743
+	 * @access protected
744
+	 * @param string $class_name
745
+	 * @param string $type
746
+	 * @param array  $file_paths
747
+	 * @return string | bool
748
+	 */
749
+	protected function _resolve_path($class_name, $type = '', $file_paths = array())
750
+	{
751
+		// make sure $file_paths is an array
752
+		$file_paths = is_array($file_paths) ? $file_paths : array($file_paths);
753
+		// cycle thru paths
754
+		foreach ($file_paths as $key => $file_path) {
755
+			// convert all separators to proper DS, if no filepath, then use EE_CLASSES
756
+			$file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES;
757
+			// prep file type
758
+			$type = ! empty($type) ? trim($type, '.') . '.' : '';
759
+			// build full file path
760
+			$file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php';
761
+			//does the file exist and can be read ?
762
+			if (is_readable($file_paths[$key])) {
763
+				return $file_paths[$key];
764
+			}
765
+		}
766
+		return false;
767
+	}
768
+
769
+
770
+
771
+	/**
772
+	 * _require_file
773
+	 * basically just performs a require_once()
774
+	 * but with some error handling
775
+	 *
776
+	 * @access protected
777
+	 * @param  string $path
778
+	 * @param  string $class_name
779
+	 * @param  string $type
780
+	 * @param  array  $file_paths
781
+	 * @return boolean
782
+	 * @throws \EE_Error
783
+	 */
784
+	protected function _require_file($path, $class_name, $type = '', $file_paths = array())
785
+	{
786
+		// don't give up! you gotta...
787
+		try {
788
+			//does the file exist and can it be read ?
789
+			if ( ! $path) {
790
+				// so sorry, can't find the file
791
+				throw new EE_Error (
792
+					sprintf(
793
+						__('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'),
794
+						trim($type, '.'),
795
+						$class_name,
796
+						'<br />' . implode(',<br />', $file_paths)
797
+					)
798
+				);
799
+			}
800
+			// get the file
801
+			require_once($path);
802
+			// if the class isn't already declared somewhere
803
+			if (class_exists($class_name, false) === false) {
804
+				// so sorry, not a class
805
+				throw new EE_Error(
806
+					sprintf(
807
+						__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'),
808
+						$type,
809
+						$path,
810
+						$class_name
811
+					)
812
+				);
813
+			}
814
+		} catch (EE_Error $e) {
815
+			$e->get_error();
816
+			return false;
817
+		}
818
+		return true;
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * _create_object
825
+	 * Attempts to instantiate the requested class via any of the
826
+	 * commonly used instantiation methods employed throughout EE.
827
+	 * The priority for instantiation is as follows:
828
+	 *        - abstract classes or any class flagged as "load only" (no instantiation occurs)
829
+	 *        - model objects via their 'new_instance_from_db' method
830
+	 *        - model objects via their 'new_instance' method
831
+	 *        - "singleton" classes" via their 'instance' method
832
+	 *    - standard instantiable classes via their __constructor
833
+	 * Prior to instantiation, if the classname exists in the dependency_map,
834
+	 * then the constructor for the requested class will be examined to determine
835
+	 * if any dependencies exist, and if they can be injected.
836
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
837
+	 *
838
+	 * @access protected
839
+	 * @param string $class_name
840
+	 * @param array  $arguments
841
+	 * @param string $type
842
+	 * @param bool   $from_db
843
+	 * @return null | object
844
+	 * @throws \EE_Error
845
+	 */
846
+	protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false)
847
+	{
848
+		$class_obj = null;
849
+		$instantiation_mode = '0) none';
850
+		// don't give up! you gotta...
851
+		try {
852
+			// create reflection
853
+			$reflector = $this->get_ReflectionClass($class_name);
854
+			// make sure arguments are an array
855
+			$arguments = is_array($arguments) ? $arguments : array($arguments);
856
+			// and if arguments array is numerically and sequentially indexed, then we want it to remain as is,
857
+			// else wrap it in an additional array so that it doesn't get split into multiple parameters
858
+			$arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments)
859
+				? $arguments
860
+				: array($arguments);
861
+			// attempt to inject dependencies ?
862
+			if ($this->_dependency_map->has($class_name)) {
863
+				$arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments);
864
+			}
865
+			// instantiate the class if possible
866
+			if ($reflector->isAbstract()) {
867
+				// nothing to instantiate, loading file was enough
868
+				// does not throw an exception so $instantiation_mode is unused
869
+				// $instantiation_mode = "1) no constructor abstract class";
870
+				$class_obj = true;
871
+			} else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) {
872
+				// no constructor = static methods only... nothing to instantiate, loading file was enough
873
+				$instantiation_mode = "2) no constructor but instantiable";
874
+				$class_obj = $reflector->newInstance();
875
+			} else if ($from_db && method_exists($class_name, 'new_instance_from_db')) {
876
+				$instantiation_mode = "3) new_instance_from_db()";
877
+				$class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments);
878
+			} else if (method_exists($class_name, 'new_instance')) {
879
+				$instantiation_mode = "4) new_instance()";
880
+				$class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments);
881
+			} else if (method_exists($class_name, 'instance')) {
882
+				$instantiation_mode = "5) instance()";
883
+				$class_obj = call_user_func_array(array($class_name, 'instance'), $arguments);
884
+			} else if ($reflector->isInstantiable()) {
885
+				$instantiation_mode = "6) constructor";
886
+				$class_obj = $reflector->newInstanceArgs($arguments);
887
+			} else {
888
+				// heh ? something's not right !
889
+				throw new EE_Error(
890
+					sprintf(
891
+						__('The %s file %s could not be instantiated.', 'event_espresso'),
892
+						$type,
893
+						$class_name
894
+					)
895
+				);
896
+			}
897
+		} catch (Exception $e) {
898
+			if ( ! $e instanceof EE_Error) {
899
+				$e = new EE_Error(
900
+					sprintf(
901
+						__('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'),
902
+						$class_name,
903
+						'<br />',
904
+						$e->getMessage(),
905
+						$instantiation_mode
906
+					)
907
+				);
908
+			}
909
+			$e->get_error();
910
+		}
911
+		return $class_obj;
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
918
+	 * @param array $array
919
+	 * @return bool
920
+	 */
921
+	protected function _array_is_numerically_and_sequentially_indexed(array $array)
922
+	{
923
+		return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true;
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * getReflectionClass
930
+	 * checks if a ReflectionClass object has already been generated for a class
931
+	 * and returns that instead of creating a new one
932
+	 *
933
+	 * @access public
934
+	 * @param string $class_name
935
+	 * @return ReflectionClass
936
+	 */
937
+	public function get_ReflectionClass($class_name)
938
+	{
939
+		if (
940
+			! isset($this->_reflectors[$class_name])
941
+			|| ! $this->_reflectors[$class_name] instanceof ReflectionClass
942
+		) {
943
+			$this->_reflectors[$class_name] = new ReflectionClass($class_name);
944
+		}
945
+		return $this->_reflectors[$class_name];
946
+	}
947
+
948
+
949
+
950
+	/**
951
+	 * _resolve_dependencies
952
+	 * examines the constructor for the requested class to determine
953
+	 * if any dependencies exist, and if they can be injected.
954
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
955
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
956
+	 * For example:
957
+	 *        if attempting to load a class "Foo" with the following constructor:
958
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
959
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
960
+	 *        but only IF they are NOT already present in the incoming arguments array,
961
+	 *        and the correct classes can be loaded
962
+	 *
963
+	 * @access protected
964
+	 * @param ReflectionClass $reflector
965
+	 * @param string          $class_name
966
+	 * @param array           $arguments
967
+	 * @return array
968
+	 * @throws \ReflectionException
969
+	 */
970
+	protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array())
971
+	{
972
+		// let's examine the constructor
973
+		$constructor = $reflector->getConstructor();
974
+		// whu? huh? nothing?
975
+		if ( ! $constructor) {
976
+			return $arguments;
977
+		}
978
+		// get constructor parameters
979
+		$params = $constructor->getParameters();
980
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
981
+		$argument_keys = array_keys($arguments);
982
+		// now loop thru all of the constructors expected parameters
983
+		foreach ($params as $index => $param) {
984
+			// is this a dependency for a specific class ?
985
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
986
+			if (
987
+				// param is not even a class
988
+				empty($param_class)
989
+				// and something already exists in the incoming arguments for this param
990
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
991
+			) {
992
+				// so let's skip this argument and move on to the next
993
+				continue;
994
+			} else if (
995
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
996
+				! empty($param_class)
997
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
998
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
999
+			) {
1000
+				// skip this argument and move on to the next
1001
+				continue;
1002
+			} else if (
1003
+				// parameter is type hinted as a class, and should be injected
1004
+				! empty($param_class)
1005
+				&& $this->_dependency_map->has_dependency_for_class($class_name, $param_class)
1006
+			) {
1007
+				$arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index);
1008
+			} else {
1009
+				try {
1010
+					$arguments[$index] = $param->getDefaultValue();
1011
+				} catch (ReflectionException $e) {
1012
+					throw new ReflectionException(
1013
+						sprintf(
1014
+							__('%1$s for parameter "$%2$s"', 'event_espresso'),
1015
+							$e->getMessage(),
1016
+							$param->getName()
1017
+						)
1018
+					);
1019
+				}
1020
+			}
1021
+		}
1022
+		return $arguments;
1023
+	}
1024
+
1025
+
1026
+
1027
+	/**
1028
+	 * @access protected
1029
+	 * @param string $class_name
1030
+	 * @param string $param_class
1031
+	 * @param array  $arguments
1032
+	 * @param mixed  $index
1033
+	 * @return array
1034
+	 */
1035
+	protected function _resolve_dependency($class_name, $param_class, $arguments, $index)
1036
+	{
1037
+		$dependency = null;
1038
+		// should dependency be loaded from cache ?
1039
+		$cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class)
1040
+					!== EE_Dependency_Map::load_new_object
1041
+			? true
1042
+			: false;
1043
+		// we might have a dependency...
1044
+		// let's MAYBE try and find it in our cache if that's what's been requested
1045
+		$cached_class = $cache_on ? $this->_get_cached_class($param_class) : null;
1046
+		// and grab it if it exists
1047
+		if ($cached_class instanceof $param_class) {
1048
+			$dependency = $cached_class;
1049
+		} else if ($param_class != $class_name) {
1050
+			// obtain the loader method from the dependency map
1051
+			$loader = $this->_dependency_map->class_loader($param_class);
1052
+			// is loader a custom closure ?
1053
+			if ($loader instanceof Closure) {
1054
+				$dependency = $loader();
1055
+			} else {
1056
+				// set the cache on property for the recursive loading call
1057
+				$this->_cache_on = $cache_on;
1058
+				// if not, then let's try and load it via the registry
1059
+				if (method_exists($this, $loader)) {
1060
+					$dependency = $this->{$loader}($param_class);
1061
+				} else {
1062
+					$dependency = $this->create($param_class, array(), $cache_on);
1063
+				}
1064
+			}
1065
+		}
1066
+		// did we successfully find the correct dependency ?
1067
+		if ($dependency instanceof $param_class) {
1068
+			// then let's inject it into the incoming array of arguments at the correct location
1069
+			if (isset($argument_keys[$index])) {
1070
+				$arguments[$argument_keys[$index]] = $dependency;
1071
+			} else {
1072
+				$arguments[$index] = $dependency;
1073
+			}
1074
+		}
1075
+		return $arguments;
1076
+	}
1077
+
1078
+
1079
+
1080
+	/**
1081
+	 * _set_cached_class
1082
+	 * attempts to cache the instantiated class locally
1083
+	 * in one of the following places, in the following order:
1084
+	 *        $this->{class_abbreviation}   ie:    $this->CART
1085
+	 *        $this->{$class_name}          ie:    $this->Some_Class
1086
+	 *        $this->addon->{$$class_name}    ie:    $this->addon->Some_Addon_Class
1087
+	 *        $this->LIB->{$class_name}     ie:    $this->LIB->Some_Class
1088
+	 *
1089
+	 * @access protected
1090
+	 * @param object $class_obj
1091
+	 * @param string $class_name
1092
+	 * @param string $class_prefix
1093
+	 * @param bool   $from_db
1094
+	 * @return void
1095
+	 */
1096
+	protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false)
1097
+	{
1098
+		if (empty($class_obj)) {
1099
+			return;
1100
+		}
1101
+		// return newly instantiated class
1102
+		if (isset($this->_class_abbreviations[$class_name])) {
1103
+			$class_abbreviation = $this->_class_abbreviations[$class_name];
1104
+			$this->{$class_abbreviation} = $class_obj;
1105
+		} else if (property_exists($this, $class_name)) {
1106
+			$this->{$class_name} = $class_obj;
1107
+		} else if ($class_prefix == 'addon') {
1108
+			$this->addons->{$class_name} = $class_obj;
1109
+		} else if ( ! $from_db) {
1110
+			$this->LIB->{$class_name} = $class_obj;
1111
+		}
1112
+	}
1113
+
1114
+
1115
+
1116
+	/**
1117
+	 * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array
1118
+	 *
1119
+	 * @param string $classname PLEASE NOTE: the class name needs to match what's registered
1120
+	 *                          in the EE_Dependency_Map::$_class_loaders array,
1121
+	 *                          including the class prefix, ie: "EE_", "EEM_", "EEH_", etc
1122
+	 * @param array  $arguments
1123
+	 * @return object
1124
+	 */
1125
+	public static function factory($classname, $arguments = array())
1126
+	{
1127
+		$loader = self::instance()->_dependency_map->class_loader($classname);
1128
+		if ($loader instanceof Closure) {
1129
+			return $loader($arguments);
1130
+		} else if (method_exists(EE_Registry::instance(), $loader)) {
1131
+			return EE_Registry::instance()->{$loader}($classname, $arguments);
1132
+		}
1133
+		return null;
1134
+	}
1135
+
1136
+
1137
+
1138
+	/**
1139
+	 * Gets the addon by its name/slug (not classname. For that, just
1140
+	 * use the classname as the property name on EE_Config::instance()->addons)
1141
+	 *
1142
+	 * @param string $name
1143
+	 * @return EE_Addon
1144
+	 */
1145
+	public function get_addon_by_name($name)
1146
+	{
1147
+		foreach ($this->addons as $addon) {
1148
+			if ($addon->name() == $name) {
1149
+				return $addon;
1150
+			}
1151
+		}
1152
+		return null;
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is
1159
+	 * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname}
1160
+	 *
1161
+	 * @return EE_Addon[] where the KEYS are the addon's name()
1162
+	 */
1163
+	public function get_addons_by_name()
1164
+	{
1165
+		$addons = array();
1166
+		foreach ($this->addons as $addon) {
1167
+			$addons[$addon->name()] = $addon;
1168
+		}
1169
+		return $addons;
1170
+	}
1171
+
1172
+
1173
+
1174
+	/**
1175
+	 * Resets the specified model's instance AND makes sure EE_Registry doesn't keep
1176
+	 * a stale copy of it around
1177
+	 *
1178
+	 * @param string $model_name
1179
+	 * @return \EEM_Base
1180
+	 * @throws \EE_Error
1181
+	 */
1182
+	public function reset_model($model_name)
1183
+	{
1184
+		$model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name;
1185
+		if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) {
1186
+			return null;
1187
+		}
1188
+		//get that model reset it and make sure we nuke the old reference to it
1189
+		if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) {
1190
+			$this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset();
1191
+		} else {
1192
+			throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name));
1193
+		}
1194
+		return $this->LIB->{$model_class_name};
1195
+	}
1196
+
1197
+
1198
+
1199
+	/**
1200
+	 * Resets the registry.
1201
+	 * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog
1202
+	 * is used in a multisite install.  Here is a list of things that are NOT reset.
1203
+	 * - $_dependency_map
1204
+	 * - $_class_abbreviations
1205
+	 * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset.
1206
+	 * - $REQ:  Still on the same request so no need to change.
1207
+	 * - $CAP: There is no site specific state in the EE_Capability class.
1208
+	 * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session
1209
+	 *         can be active in a single request.  Resetting could resolve in "headers already sent" errors.
1210
+	 * - $addons:  In multisite, the state of the addons is something controlled via hooks etc in a normal request.  So
1211
+	 *             for now, we won't reset the addons because it could break calls to an add-ons class/methods in the
1212
+	 *             switch or on the restore.
1213
+	 * - $modules
1214
+	 * - $shortcodes
1215
+	 * - $widgets
1216
+	 *
1217
+	 * @param boolean $hard             whether to reset data in the database too, or just refresh
1218
+	 *                                  the Registry to its state at the beginning of the request
1219
+	 * @param boolean $reinstantiate    whether to create new instances of EE_Registry's singletons too,
1220
+	 *                                  or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN
1221
+	 *                                  currently reinstantiate the singletons at the moment)
1222
+	 * @param   bool  $reset_models     Defaults to true.  When false, then the models are not reset.  This is so client
1223
+	 *                                  code instead can just change the model context to a different blog id if necessary
1224
+	 * @return EE_Registry
1225
+	 */
1226
+	public static function reset($hard = false, $reinstantiate = true, $reset_models = true)
1227
+	{
1228
+		$instance = self::instance();
1229
+		EEH_Activation::reset();
1230
+		//properties that get reset
1231
+		$instance->_cache_on = true;
1232
+		$instance->CFG = EE_Config::reset($hard, $reinstantiate);
1233
+		$instance->CART = null;
1234
+		$instance->MRM = null;
1235
+		$instance->AssetsRegistry = new Registry();
1236
+		//messages reset
1237
+		EED_Messages::reset();
1238
+		if ($reset_models) {
1239
+			foreach (array_keys($instance->non_abstract_db_models) as $model_name) {
1240
+				$instance->reset_model($model_name);
1241
+			}
1242
+		}
1243
+		$instance->LIB = new stdClass();
1244
+		return $instance;
1245
+	}
1246
+
1247
+
1248
+
1249
+	/**
1250
+	 * @override magic methods
1251
+	 * @return void
1252
+	 */
1253
+	final function __destruct()
1254
+	{
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * @param $a
1261
+	 * @param $b
1262
+	 */
1263
+	final function __call($a, $b)
1264
+	{
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 * @param $a
1271
+	 */
1272
+	final function __get($a)
1273
+	{
1274
+	}
1275
+
1276
+
1277
+
1278
+	/**
1279
+	 * @param $a
1280
+	 * @param $b
1281
+	 */
1282
+	final function __set($a, $b)
1283
+	{
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * @param $a
1290
+	 */
1291
+	final function __isset($a)
1292
+	{
1293
+	}
1294 1294
 
1295 1295
 
1296 1296
 
1297
-    /**
1298
-     * @param $a
1299
-     */
1300
-    final function __unset($a)
1301
-    {
1302
-    }
1297
+	/**
1298
+	 * @param $a
1299
+	 */
1300
+	final function __unset($a)
1301
+	{
1302
+	}
1303 1303
 
1304 1304
 
1305 1305
 
1306
-    /**
1307
-     * @return array
1308
-     */
1309
-    final function __sleep()
1310
-    {
1311
-        return array();
1312
-    }
1306
+	/**
1307
+	 * @return array
1308
+	 */
1309
+	final function __sleep()
1310
+	{
1311
+		return array();
1312
+	}
1313 1313
 
1314 1314
 
1315 1315
 
1316
-    final function __wakeup()
1317
-    {
1318
-    }
1316
+	final function __wakeup()
1317
+	{
1318
+	}
1319 1319
 
1320 1320
 
1321 1321
 
1322
-    /**
1323
-     * @return string
1324
-     */
1325
-    final function __toString()
1326
-    {
1327
-        return '';
1328
-    }
1322
+	/**
1323
+	 * @return string
1324
+	 */
1325
+	final function __toString()
1326
+	{
1327
+		return '';
1328
+	}
1329 1329
 
1330 1330
 
1331 1331
 
1332
-    final function __invoke()
1333
-    {
1334
-    }
1332
+	final function __invoke()
1333
+	{
1334
+	}
1335 1335
 
1336 1336
 
1337 1337
 
1338
-    final static function __set_state()
1339
-    {
1340
-    }
1338
+	final static function __set_state()
1339
+	{
1340
+	}
1341 1341
 
1342 1342
 
1343 1343
 
1344
-    final function __clone()
1345
-    {
1346
-    }
1344
+	final function __clone()
1345
+	{
1346
+	}
1347 1347
 
1348 1348
 
1349 1349
 
1350
-    /**
1351
-     * @param $a
1352
-     * @param $b
1353
-     */
1354
-    final static function __callStatic($a, $b)
1355
-    {
1356
-    }
1350
+	/**
1351
+	 * @param $a
1352
+	 * @param $b
1353
+	 */
1354
+	final static function __callStatic($a, $b)
1355
+	{
1356
+	}
1357 1357
 
1358 1358
 
1359 1359
 
1360
-    /**
1361
-     * Gets all the custom post type models defined
1362
-     *
1363
-     * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1364
-     */
1365
-    public function cpt_models()
1366
-    {
1367
-        $cpt_models = array();
1368
-        foreach ($this->non_abstract_db_models as $short_name => $classname) {
1369
-            if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1370
-                $cpt_models[$short_name] = $classname;
1371
-            }
1372
-        }
1373
-        return $cpt_models;
1374
-    }
1360
+	/**
1361
+	 * Gets all the custom post type models defined
1362
+	 *
1363
+	 * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event")
1364
+	 */
1365
+	public function cpt_models()
1366
+	{
1367
+		$cpt_models = array();
1368
+		foreach ($this->non_abstract_db_models as $short_name => $classname) {
1369
+			if (is_subclass_of($classname, 'EEM_CPT_Base')) {
1370
+				$cpt_models[$short_name] = $classname;
1371
+			}
1372
+		}
1373
+		return $cpt_models;
1374
+	}
1375 1375
 
1376 1376
 
1377 1377
 
1378
-    /**
1379
-     * @return \EE_Config
1380
-     */
1381
-    public static function CFG()
1382
-    {
1383
-        return self::instance()->CFG;
1384
-    }
1378
+	/**
1379
+	 * @return \EE_Config
1380
+	 */
1381
+	public static function CFG()
1382
+	{
1383
+		return self::instance()->CFG;
1384
+	}
1385 1385
 
1386 1386
 
1387 1387
 }
Please login to merge, or discard this patch.
core/EE_Data_Mapper.core.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 
29 29
 
30 30
    /**
31
-     * instance of the EE_Data_Mapper Object
32
-     * @private _instance
33
-     */
31
+    * instance of the EE_Data_Mapper Object
32
+    * @private _instance
33
+    */
34 34
 	private static $_instance = NULL;
35 35
 
36 36
 
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	}
83 83
 	final function __wakeup() {}
84 84
 	final function __toString() {
85
-	    return '';
86
-    }
85
+		return '';
86
+	}
87 87
 	final function __invoke() {}
88 88
 	final static function __set_state() {}
89 89
 	final function __clone() {}
Please login to merge, or discard this patch.
registration_form/templates/questions_main_meta_box.template.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -98,14 +98,14 @@
 block discarded – undo
98 98
 				</th>
99 99
 				<td>
100 100
 					<?php
101
-                        $disabled = ! empty( $QST_system ) && $QST_system !== EEM_Attendee::system_question_phone;
102
-                        if( $disabled ){
103
-                            $disabled_attr =  'disabled="disabled"';
104
-						    $id =  '_disabled';
105
-                        } else {
106
-                            $disabled_attr = '';
107
-                            $id = '';
108
-                        }
101
+						$disabled = ! empty( $QST_system ) && $QST_system !== EEM_Attendee::system_question_phone;
102
+						if( $disabled ){
103
+							$disabled_attr =  'disabled="disabled"';
104
+							$id =  '_disabled';
105
+						} else {
106
+							$disabled_attr = '';
107
+							$id = '';
108
+						}
109 109
 
110 110
 						echo EEH_Form_Fields::select_input( 'QST_type' . $id, $question_types, $question->type(), 'id="QST_type' . $id . '"' . $disabled_attr );
111 111
 						if( $disabled ) { ?>
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
 //does question have any answers? cause if it does then we have to disable type
16 16
 $has_answers = $question->has_answers();
17 17
 
18
-if ( $QST_system === 'country' ) {
18
+if ($QST_system === 'country') {
19 19
 	echo EEH_HTML::div(
20
-		EEH_HTML::h4( '<span class="dashicons dashicons-info"></span>' . esc_html__( 'Did you know...', 'event_espresso' ) ) .
20
+		EEH_HTML::h4('<span class="dashicons dashicons-info"></span>'.esc_html__('Did you know...', 'event_espresso')).
21 21
 		EEH_HTML::p(
22 22
 			esc_html__(
23 23
 				'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.',
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		<tbody>
35 35
 			<tr>
36 36
 				<th>
37
-					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info');?>
37
+					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info'); ?>
38 38
 				</th>
39 39
 				<td>
40 40
 					<input type="text" class="regular-text" id="QST_display_text" name="QST_display_text" value="<?php $question->f('QST_display_text')?>"/>
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
 
45 45
 			<tr>
46 46
 				<th>
47
-					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info');?>
47
+					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info'); ?>
48 48
 				</th>
49 49
 				<td>
50 50
 					<?php
51
-						$disabled_attr = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
52
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
51
+						$disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : '';
52
+						$id = ! empty($QST_system) ? '_disabled' : '';
53 53
 					?>
54 54
 					<input type="text" class="regular-text" id="QST_admin_label<?php echo $id?>" name="QST_admin_label<?php echo $id?>" value="<?php $question->f('QST_admin_label')?>"<?php echo $disabled_attr?>/>
55 55
 					<input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" name = "QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>" />
56
-					<?php if ( ! empty( $QST_system )) { ?>
56
+					<?php if ( ! empty($QST_system)) { ?>
57 57
 						<input type="hidden"  id="QST_admin_label" name="QST_admin_label" value="<?php echo $question->admin_label()?>"/>
58 58
 					<?php } ?>
59 59
 					<br/>
60 60
 					<p class="description">
61
-					<?php if ( ! empty( $QST_system )) { ?>
61
+					<?php if ( ! empty($QST_system)) { ?>
62 62
 					<span class="description" style="color:#D54E21;">
63
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
63
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
64 64
 					</span>
65 65
 					<?php } ?>
66 66
 
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 
71 71
 			<tr>
72 72
 				<th>
73
-					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info');?>
73
+					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info'); ?>
74 74
 				</th>
75 75
 				<td>
76 76
 					<?php
77
-						$disabled_attr = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
78
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
77
+						$disabled_attr = ! empty($QST_system) ? ' disabled="disabled"' : '';
78
+						$id = ! empty($QST_system) ? '_disabled' : '';
79 79
 						$admin_only = $question->get('QST_admin_only');
80
-						$checked = !empty( $admin_only ) ? ' checked="checked"' : '';
80
+						$checked = ! empty($admin_only) ? ' checked="checked"' : '';
81 81
 					?>
82 82
 					<input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" name = "QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled_attr; echo $checked; ?>/>
83 83
 					<br/>
84 84
 					<p class="description">
85
-					<?php if ( ! empty( $QST_system )) { ?>
85
+					<?php if ( ! empty($QST_system)) { ?>
86 86
 					<span class="description" style="color:#D54E21;">
87
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
87
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
88 88
 					</span>
89 89
 					<?php } ?>
90 90
 
@@ -94,28 +94,28 @@  discard block
 block discarded – undo
94 94
 
95 95
 			<tr>
96 96
 				<th>
97
-					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info');?>
97
+					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info'); ?>
98 98
 				</th>
99 99
 				<td>
100 100
 					<?php
101
-                        $disabled = ! empty( $QST_system ) && $QST_system !== EEM_Attendee::system_question_phone;
102
-                        if( $disabled ){
103
-                            $disabled_attr =  'disabled="disabled"';
104
-						    $id =  '_disabled';
101
+                        $disabled = ! empty($QST_system) && $QST_system !== EEM_Attendee::system_question_phone;
102
+                        if ($disabled) {
103
+                            $disabled_attr = 'disabled="disabled"';
104
+						    $id = '_disabled';
105 105
                         } else {
106 106
                             $disabled_attr = '';
107 107
                             $id = '';
108 108
                         }
109 109
 
110
-						echo EEH_Form_Fields::select_input( 'QST_type' . $id, $question_types, $question->type(), 'id="QST_type' . $id . '"' . $disabled_attr );
111
-						if( $disabled ) { ?>
110
+						echo EEH_Form_Fields::select_input('QST_type'.$id, $question_types, $question->type(), 'id="QST_type'.$id.'"'.$disabled_attr);
111
+						if ($disabled) { ?>
112 112
 							<input type="hidden"  id="QST_type" name="QST_type" value="<?php echo $question->type()?>"/>
113 113
 						<?php
114
-							$explanatory_text = esc_html__('System question! This field cannot be changed.','event_espresso');
115
-						}else{
116
-							$explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.','event_espresso');
114
+							$explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso');
115
+						} else {
116
+							$explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', 'event_espresso');
117 117
 						}
118
-						if ( $disabled || $has_answers ) { ?>
118
+						if ($disabled || $has_answers) { ?>
119 119
 							<p><span class="description" style="color:#D54E21;">
120 120
 								<?php echo $explanatory_text; ?>
121 121
 							</span></p>
@@ -128,22 +128,22 @@  discard block
 block discarded – undo
128 128
 			<tr id="text_input_question_options">
129 129
 				<th>
130 130
 					<label>
131
-						<?php esc_html_e( 'Maximum Allowed Response Size', 'event_espresso' );?>
131
+						<?php esc_html_e('Maximum Allowed Response Size', 'event_espresso'); ?>
132 132
 					</label>
133 133
 				</th>
134 134
 				<td>
135
-					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'";?> value="<?php $question->f( 'QST_max' );?>" min="1">
135
+					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1">
136 136
 					<p>
137 137
 						<span class="description">
138
-							<?php esc_html_e( 'Maximum number of characters allowed when answering this question', 'event_espresso' );?>
138
+							<?php esc_html_e('Maximum number of characters allowed when answering this question', 'event_espresso'); ?>
139 139
 						</span>
140 140
 					</p>
141
-					<?php if ( $QST_system ) { ?>
141
+					<?php if ($QST_system) { ?>
142 142
 					<p>
143 143
 						<span class="description" style="color:#D54E21;">
144 144
 							<?php printf(
145
-									esc_html__( 'System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso' ),
146
-									$max_max );?>
145
+									esc_html__('System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso'),
146
+									$max_max ); ?>
147 147
 						</span>
148 148
 					</p>
149 149
 					<?php } ?>
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 			<tr id="question_options">
153 153
 				<th>
154 154
 					<label>
155
-						<?php esc_html_e('Answer Options','event_espresso')?>
155
+						<?php esc_html_e('Answer Options', 'event_espresso')?>
156 156
 					</label>
157 157
 				</th>
158 158
 				<td>
@@ -161,10 +161,10 @@  discard block
 block discarded – undo
161 161
 						<thead>
162 162
 							<tr>
163 163
 								<th class="option-value-header">
164
-									<?php esc_html_e('Value','event_espresso')?>
164
+									<?php esc_html_e('Value', 'event_espresso')?>
165 165
 								</th>
166 166
 								<th class="option-desc-header">
167
-									<?php esc_html_e('Description (optional, only shown on registration form)','event_espresso')?>
167
+									<?php esc_html_e('Description (optional, only shown on registration form)', 'event_espresso')?>
168 168
 								</th>
169 169
 								<th>
170 170
 								</th>
@@ -187,17 +187,17 @@  discard block
 block discarded – undo
187 187
 							</tr>
188 188
 
189 189
 							<?php
190
-							$count=0;
190
+							$count = 0;
191 191
 							$question_options = $question->options();
192
-							if ( ! empty( $question_options )) {
193
-								foreach( $question_options as $option_id => $option ) {
194
-									$disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"'  : '';
192
+							if ( ! empty($question_options)) {
193
+								foreach ($question_options as $option_id => $option) {
194
+									$disabled_attr = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : '';
195 195
 							?>
196 196
 								<tr class="question-option ee-options-sortable">
197 197
 									<td class="option-value-cell">
198 198
 										<input type="hidden" class="QSO_order" name="question_options[<?php echo $count; ?>][QSO_order]" value="<?php echo $count; ?>">
199 199
 										<input type="text" class="option-value regular-text" name="question_options[<?php echo $count?>][QSO_value]" value="<?php  $option->f('QSO_value')?>"<?php echo $disabled_attr; ?>>
200
-										<?php if ( $has_answers ) : ?>
200
+										<?php if ($has_answers) : ?>
201 201
 											<input type="hidden" name="question_options[<?php echo $count; ?>][QSO_value]" value="<?php echo $option->f('QSO_value'); ?>" >
202 202
 										<?php endif; ?>
203 203
 									</td>
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 										<input type="text" class="option-desc regular-text" name="question_options[<?php echo $count?>][QSO_desc]" value="<?php $option->f('QSO_desc')?>">
206 206
 									</td>
207 207
 									<td>
208
-										<?php if ( ! $option->system() ) { ?>
208
+										<?php if ( ! $option->system()) { ?>
209 209
 											<span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span>
210 210
 										<?php } ?>
211 211
                                         <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span>
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 					</table>
245 245
 
246 246
 					<a id="new-question-option" class="button" style="margin:0 0 1em 3px;">
247
-						<?php esc_html_e('Add Another Answer Option','event_espresso')?>
247
+						<?php esc_html_e('Add Another Answer Option', 'event_espresso')?>
248 248
 					</a><br/>
249 249
 
250 250
 					<p class="description">
251
-						<?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.','event_espresso')?>
251
+						<?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', 'event_espresso')?>
252 252
 					</p>
253
-					<?php if ( $has_answers ) : ?>
253
+					<?php if ($has_answers) : ?>
254 254
 					<p class="description" style="color:#D54E21;">
255 255
 							<?php esc_html_e('Answer values that are uneditable are this way because there are registrations in the database that have answers for this question.  If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes.  This will ensure that the existing registrations that chose the original answer will preserve that answer.', 'event_espresso'); ?>
256 256
 					</p>
@@ -261,32 +261,32 @@  discard block
 block discarded – undo
261 261
 
262 262
 			<tr>
263 263
 				<th>
264
-					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info');?>
264
+					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info'); ?>
265 265
 				</th>
266 266
 				<td>
267 267
 					<?php
268
-					$system_required = array( 'fname', 'email' );
269
-					$disabled_attr = in_array( $QST_system, $system_required ) ? ' disabled="disabled"' : '';
268
+					$system_required = array('fname', 'email');
269
+					$disabled_attr = in_array($QST_system, $system_required) ? ' disabled="disabled"' : '';
270 270
 					$required_on = $question->get('QST_admin_only');
271 271
 					$show_required_msg = $required_on ? '' : ' display:none;';
272
-					$disabled_attr = $required_on || ! empty( $disabled_attr ) ? ' disabled="disabled"' : '';
273
-					$id = ! empty( $disabled_attr ) && in_array( $QST_system, $system_required) ? '_disabled' : '';
274
-					$requiredOptions=array(
275
-						array( 'text'=> esc_html__( 'Optional', 'event_espresso' ), 'id'=>0 ),
276
-						array( 'text'=> esc_html__( 'Required', 'event_espresso' ), 'id'=>1 )
272
+					$disabled_attr = $required_on || ! empty($disabled_attr) ? ' disabled="disabled"' : '';
273
+					$id = ! empty($disabled_attr) && in_array($QST_system, $system_required) ? '_disabled' : '';
274
+					$requiredOptions = array(
275
+						array('text'=> esc_html__('Optional', 'event_espresso'), 'id'=>0),
276
+						array('text'=> esc_html__('Required', 'event_espresso'), 'id'=>1)
277 277
 					);
278
-					echo EEH_Form_Fields::select_input('QST_required' . $id, $requiredOptions, $question->required(), 'id="QST_required' . $id . '"' . $disabled_attr );
278
+					echo EEH_Form_Fields::select_input('QST_required'.$id, $requiredOptions, $question->required(), 'id="QST_required'.$id.'"'.$disabled_attr);
279 279
 					?>
280 280
 						<p><span id="required_toggled_on" class="description" style="color:#D54E21;<?php echo $show_required_msg; ?>">
281
-						<?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.','event_espresso')?>
281
+						<?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.', 'event_espresso')?>
282 282
 						</span></p>
283 283
 						<p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;">
284
-							<?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only','event_espresso')?>
284
+							<?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only', 'event_espresso')?>
285 285
 						</span></p>
286
-					<?php if (! empty( $disabled_attr ) && in_array( $QST_system, $system_required ) ) { ?>
286
+					<?php if ( ! empty($disabled_attr) && in_array($QST_system, $system_required)) { ?>
287 287
 						<input type="hidden"  id="QST_required" name="QST_required" value="1"/>
288 288
 						<p><span class="description" style="color:#D54E21;">
289
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
289
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
290 290
 					</span></p>
291 291
 					<?php } ?>
292 292
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 
296 296
 			<tr>
297 297
 				<th>
298
-					<label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info');?>
298
+					<label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?>
299 299
 				</th>
300 300
 				<td>
301 301
 					<input type="text" maxlength="100" class="regular-text" id="QST_required_text" name="QST_required_text" value="<?php  $question->f('QST_required_text')?>"/>
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@
 block discarded – undo
112 112
 							<input type="hidden"  id="QST_type" name="QST_type" value="<?php echo $question->type()?>"/>
113 113
 						<?php
114 114
 							$explanatory_text = esc_html__('System question! This field cannot be changed.','event_espresso');
115
-						}else{
115
+						} else{
116 116
 							$explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.','event_espresso');
117 117
 						}
118 118
 						if ( $disabled || $has_answers ) { ?>
Please login to merge, or discard this patch.
admin_pages/registration_form/Registration_Form_Admin_Page.core.php 2 patches
Indentation   +643 added lines, -643 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -28,599 +28,599 @@  discard block
 block discarded – undo
28 28
 class Registration_Form_Admin_Page extends EE_Admin_Page
29 29
 {
30 30
 
31
-    /**
32
-     * _question
33
-     * holds the specific question object for the question details screen
34
-     *
35
-     * @var EE_Question $_question
36
-     */
37
-    protected $_question;
38
-
39
-    /**
40
-     * _question_group
41
-     * holds the specific question group object for the question group details screen
42
-     *
43
-     * @var EE_Question_Group $_question_group
44
-     */
45
-    protected $_question_group;
46
-
47
-    /**
48
-     *_question_model EEM_Question model instance (for queries)
49
-     *
50
-     * @var EEM_Question $_question_model ;
51
-     */
52
-    protected $_question_model;
53
-
54
-    /**
55
-     * _question_group_model EEM_Question_group instance (for queries)
56
-     *
57
-     * @var EEM_Question_Group $_question_group_model
58
-     */
59
-    protected $_question_group_model;
60
-
61
-
62
-    /**
63
-     * @Constructor
64
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
-     * @access public
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
-        $this->_question_model       = EEM_Question::instance();
72
-        $this->_question_group_model = EEM_Question_Group::instance();
73
-        parent::__construct($routing);
74
-    }
75
-
76
-
77
-    protected function _init_page_props()
78
-    {
79
-        $this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
-        $this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
-        $this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
-        $this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
-    }
84
-
85
-
86
-    protected function _ajax_hooks()
87
-    {
88
-    }
89
-
90
-
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
-        $this->_labels           = array(
95
-            'buttons' => array(
96
-                'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
-            ),
98
-        );
99
-    }
100
-
101
-
102
-    /**
103
-     *_set_page_routes
104
-     */
105
-    protected function _set_page_routes()
106
-    {
107
-        $qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
-        $this->_page_routes = array(
109
-            'default' => array(
110
-                'func'       => '_questions_overview_list_table',
111
-                'capability' => 'ee_read_questions',
112
-            ),
113
-
114
-            'edit_question' => array(
115
-                'func'       => '_edit_question',
116
-                'capability' => 'ee_edit_question',
117
-                'obj_id'     => $qst_id,
118
-                'args'       => array('edit'),
119
-            ),
120
-
121
-            'question_groups' => array(
122
-                'func'       => '_questions_groups_preview',
123
-                'capability' => 'ee_read_question_groups',
124
-            ),
125
-
126
-            'update_question' => array(
127
-                'func'       => '_insert_or_update_question',
128
-                'args'       => array('new_question' => false),
129
-                'capability' => 'ee_edit_question',
130
-                'obj_id'     => $qst_id,
131
-                'noheader'   => true,
132
-            ),
133
-        );
134
-    }
135
-
136
-
137
-    protected function _set_page_config()
138
-    {
139
-        $this->_page_config = array(
140
-            'default' => array(
141
-                'nav'           => array(
142
-                    'label' => esc_html__('Questions', 'event_espresso'),
143
-                    'order' => 10,
144
-                ),
145
-                'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
-                'metaboxes'     => $this->_default_espresso_metaboxes,
147
-                'help_tabs'     => array(
148
-                    'registration_form_questions_overview_help_tab'                           => array(
149
-                        'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
-                        'filename' => 'registration_form_questions_overview',
151
-                    ),
152
-                    'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
-                        'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
-                        'filename' => 'registration_form_questions_overview_table_column_headings',
155
-                    ),
156
-                    'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
-                        'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
-                        'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
-                    ),
160
-                ),
161
-                'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
-                'require_nonce' => false,
163
-                'qtips'         => array(
164
-                    'EE_Registration_Form_Tips',
165
-                )/**/
166
-            ),
167
-
168
-            'question_groups' => array(
169
-                'nav'           => array(
170
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
171
-                    'order' => 20,
172
-                ),
173
-                'metaboxes'     => $this->_default_espresso_metaboxes,
174
-                'help_tabs'     => array(
175
-                    'registration_form_question_groups_help_tab' => array(
176
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
177
-                        'filename' => 'registration_form_question_groups',
178
-                    ),
179
-                ),
180
-                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
-                'require_nonce' => false,
182
-            ),
183
-
184
-            'edit_question' => array(
185
-                'nav'           => array(
186
-                    'label'      => esc_html__('Edit Question', 'event_espresso'),
187
-                    'order'      => 15,
188
-                    'persistent' => false,
189
-                    'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
-                        $this->_current_page_view_url) : $this->_admin_base_url,
191
-                ),
192
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
-                'help_tabs'     => array(
194
-                    'registration_form_edit_question_group_help_tab' => array(
195
-                        'title'    => esc_html__('Edit Question', 'event_espresso'),
196
-                        'filename' => 'registration_form_edit_question',
197
-                    ),
198
-                ),
199
-                'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
-                'require_nonce' => false,
201
-            ),
202
-        );
203
-    }
204
-
205
-
206
-    protected function _add_screen_options()
207
-    {
208
-        //todo
209
-    }
210
-
211
-    protected function _add_screen_options_default()
212
-    {
213
-        $page_title              = $this->_admin_page_title;
214
-        $this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
-        $this->_per_page_screen_option();
216
-        $this->_admin_page_title = $page_title;
217
-    }
218
-
219
-    protected function _add_screen_options_question_groups()
220
-    {
221
-        $page_title              = $this->_admin_page_title;
222
-        $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
-        $this->_per_page_screen_option();
224
-        $this->_admin_page_title = $page_title;
225
-    }
226
-
227
-    //none of the below group are currently used for Event Categories
228
-    protected function _add_feature_pointers()
229
-    {
230
-    }
231
-
232
-    public function load_scripts_styles()
233
-    {
234
-        wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
-        wp_enqueue_style('espresso_registration');
237
-    }
238
-
239
-    public function admin_init()
240
-    {
241
-    }
242
-
243
-    public function admin_notices()
244
-    {
245
-    }
246
-
247
-    public function admin_footer_scripts()
248
-    {
249
-    }
250
-
251
-
252
-    public function load_scripts_styles_default()
253
-    {
254
-    }
255
-
256
-
257
-    public function load_scripts_styles_add_question()
258
-    {
259
-        $this->load_scripts_styles_forms();
260
-        wp_register_script('espresso_registration_form_single',
261
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262
-            EVENT_ESPRESSO_VERSION, true);
263
-        wp_enqueue_script('espresso_registration_form_single');
264
-    }
265
-
266
-    public function load_scripts_styles_edit_question()
267
-    {
268
-        $this->load_scripts_styles_forms();
269
-        wp_register_script('espresso_registration_form_single',
270
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271
-            EVENT_ESPRESSO_VERSION, true);
272
-        wp_enqueue_script('espresso_registration_form_single');
273
-    }
274
-
275
-
276
-    public function recaptcha_info_help_tab()
277
-    {
278
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
279
-        EEH_Template::display_template($template, array());
280
-    }
281
-
282
-
283
-    public function load_scripts_styles_forms()
284
-    {
285
-        //styles
286
-        wp_enqueue_style('espresso-ui-theme');
287
-        //scripts
288
-        wp_enqueue_script('ee_admin_js');
289
-    }
290
-
291
-
292
-    protected function _set_list_table_views_default()
293
-    {
294
-        $this->_views = array(
295
-            'all' => array(
296
-                'slug'  => 'all',
297
-                'label' => esc_html__('View All Questions', 'event_espresso'),
298
-                'count' => 0,
31
+	/**
32
+	 * _question
33
+	 * holds the specific question object for the question details screen
34
+	 *
35
+	 * @var EE_Question $_question
36
+	 */
37
+	protected $_question;
38
+
39
+	/**
40
+	 * _question_group
41
+	 * holds the specific question group object for the question group details screen
42
+	 *
43
+	 * @var EE_Question_Group $_question_group
44
+	 */
45
+	protected $_question_group;
46
+
47
+	/**
48
+	 *_question_model EEM_Question model instance (for queries)
49
+	 *
50
+	 * @var EEM_Question $_question_model ;
51
+	 */
52
+	protected $_question_model;
53
+
54
+	/**
55
+	 * _question_group_model EEM_Question_group instance (for queries)
56
+	 *
57
+	 * @var EEM_Question_Group $_question_group_model
58
+	 */
59
+	protected $_question_group_model;
60
+
61
+
62
+	/**
63
+	 * @Constructor
64
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
+	 * @access public
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		require_once(EE_MODELS . 'EEM_Question.model.php');
70
+		require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
+		$this->_question_model       = EEM_Question::instance();
72
+		$this->_question_group_model = EEM_Question_Group::instance();
73
+		parent::__construct($routing);
74
+	}
75
+
76
+
77
+	protected function _init_page_props()
78
+	{
79
+		$this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
+		$this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
+		$this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
+		$this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
+	}
84
+
85
+
86
+	protected function _ajax_hooks()
87
+	{
88
+	}
89
+
90
+
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
+		$this->_labels           = array(
95
+			'buttons' => array(
96
+				'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
+			),
98
+		);
99
+	}
100
+
101
+
102
+	/**
103
+	 *_set_page_routes
104
+	 */
105
+	protected function _set_page_routes()
106
+	{
107
+		$qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
+		$this->_page_routes = array(
109
+			'default' => array(
110
+				'func'       => '_questions_overview_list_table',
111
+				'capability' => 'ee_read_questions',
112
+			),
113
+
114
+			'edit_question' => array(
115
+				'func'       => '_edit_question',
116
+				'capability' => 'ee_edit_question',
117
+				'obj_id'     => $qst_id,
118
+				'args'       => array('edit'),
119
+			),
120
+
121
+			'question_groups' => array(
122
+				'func'       => '_questions_groups_preview',
123
+				'capability' => 'ee_read_question_groups',
124
+			),
125
+
126
+			'update_question' => array(
127
+				'func'       => '_insert_or_update_question',
128
+				'args'       => array('new_question' => false),
129
+				'capability' => 'ee_edit_question',
130
+				'obj_id'     => $qst_id,
131
+				'noheader'   => true,
132
+			),
133
+		);
134
+	}
135
+
136
+
137
+	protected function _set_page_config()
138
+	{
139
+		$this->_page_config = array(
140
+			'default' => array(
141
+				'nav'           => array(
142
+					'label' => esc_html__('Questions', 'event_espresso'),
143
+					'order' => 10,
144
+				),
145
+				'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
+				'metaboxes'     => $this->_default_espresso_metaboxes,
147
+				'help_tabs'     => array(
148
+					'registration_form_questions_overview_help_tab'                           => array(
149
+						'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
+						'filename' => 'registration_form_questions_overview',
151
+					),
152
+					'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
+						'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
+						'filename' => 'registration_form_questions_overview_table_column_headings',
155
+					),
156
+					'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
+						'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
+						'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
+					),
160
+				),
161
+				'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
+				'require_nonce' => false,
163
+				'qtips'         => array(
164
+					'EE_Registration_Form_Tips',
165
+				)/**/
166
+			),
167
+
168
+			'question_groups' => array(
169
+				'nav'           => array(
170
+					'label' => esc_html__('Question Groups', 'event_espresso'),
171
+					'order' => 20,
172
+				),
173
+				'metaboxes'     => $this->_default_espresso_metaboxes,
174
+				'help_tabs'     => array(
175
+					'registration_form_question_groups_help_tab' => array(
176
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
177
+						'filename' => 'registration_form_question_groups',
178
+					),
179
+				),
180
+				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
+				'require_nonce' => false,
182
+			),
183
+
184
+			'edit_question' => array(
185
+				'nav'           => array(
186
+					'label'      => esc_html__('Edit Question', 'event_espresso'),
187
+					'order'      => 15,
188
+					'persistent' => false,
189
+					'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
+						$this->_current_page_view_url) : $this->_admin_base_url,
191
+				),
192
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
+				'help_tabs'     => array(
194
+					'registration_form_edit_question_group_help_tab' => array(
195
+						'title'    => esc_html__('Edit Question', 'event_espresso'),
196
+						'filename' => 'registration_form_edit_question',
197
+					),
198
+				),
199
+				'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
+				'require_nonce' => false,
201
+			),
202
+		);
203
+	}
204
+
205
+
206
+	protected function _add_screen_options()
207
+	{
208
+		//todo
209
+	}
210
+
211
+	protected function _add_screen_options_default()
212
+	{
213
+		$page_title              = $this->_admin_page_title;
214
+		$this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
+		$this->_per_page_screen_option();
216
+		$this->_admin_page_title = $page_title;
217
+	}
218
+
219
+	protected function _add_screen_options_question_groups()
220
+	{
221
+		$page_title              = $this->_admin_page_title;
222
+		$this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
+		$this->_per_page_screen_option();
224
+		$this->_admin_page_title = $page_title;
225
+	}
226
+
227
+	//none of the below group are currently used for Event Categories
228
+	protected function _add_feature_pointers()
229
+	{
230
+	}
231
+
232
+	public function load_scripts_styles()
233
+	{
234
+		wp_register_style('espresso_registration',
235
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
+		wp_enqueue_style('espresso_registration');
237
+	}
238
+
239
+	public function admin_init()
240
+	{
241
+	}
242
+
243
+	public function admin_notices()
244
+	{
245
+	}
246
+
247
+	public function admin_footer_scripts()
248
+	{
249
+	}
250
+
251
+
252
+	public function load_scripts_styles_default()
253
+	{
254
+	}
255
+
256
+
257
+	public function load_scripts_styles_add_question()
258
+	{
259
+		$this->load_scripts_styles_forms();
260
+		wp_register_script('espresso_registration_form_single',
261
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262
+			EVENT_ESPRESSO_VERSION, true);
263
+		wp_enqueue_script('espresso_registration_form_single');
264
+	}
265
+
266
+	public function load_scripts_styles_edit_question()
267
+	{
268
+		$this->load_scripts_styles_forms();
269
+		wp_register_script('espresso_registration_form_single',
270
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271
+			EVENT_ESPRESSO_VERSION, true);
272
+		wp_enqueue_script('espresso_registration_form_single');
273
+	}
274
+
275
+
276
+	public function recaptcha_info_help_tab()
277
+	{
278
+		$template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
279
+		EEH_Template::display_template($template, array());
280
+	}
281
+
282
+
283
+	public function load_scripts_styles_forms()
284
+	{
285
+		//styles
286
+		wp_enqueue_style('espresso-ui-theme');
287
+		//scripts
288
+		wp_enqueue_script('ee_admin_js');
289
+	}
290
+
291
+
292
+	protected function _set_list_table_views_default()
293
+	{
294
+		$this->_views = array(
295
+			'all' => array(
296
+				'slug'  => 'all',
297
+				'label' => esc_html__('View All Questions', 'event_espresso'),
298
+				'count' => 0,
299 299
 //				'bulk_action' => array(
300 300
 //					'trash_questions' => esc_html__('Trash', 'event_espresso'),
301 301
 //					)
302
-            ),
303
-        );
304
-
305
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
306
-            'espresso_registration_form_trash_questions')
307
-        ) {
308
-            $this->_views['trash'] = array(
309
-                'slug'  => 'trash',
310
-                'label' => esc_html__('Trash', 'event_espresso'),
311
-                'count' => 0,
302
+			),
303
+		);
304
+
305
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
306
+			'espresso_registration_form_trash_questions')
307
+		) {
308
+			$this->_views['trash'] = array(
309
+				'slug'  => 'trash',
310
+				'label' => esc_html__('Trash', 'event_espresso'),
311
+				'count' => 0,
312 312
 //				'bulk_action' => array(
313 313
 //					'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'),
314 314
 //					'restore_questions' => esc_html__('Restore', 'event_espresso'),
315
-            );
316
-        }
317
-    }
318
-
319
-    /**
320
-     * This just previews the question groups tab that comes in caffeinated.
321
-     *
322
-     * @return string html
323
-     */
324
-    protected function _questions_groups_preview()
325
-    {
326
-        $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
-                'event_espresso') . '" />';
329
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
-                'event_espresso') . '</strong>';
331
-        $this->display_admin_caf_preview_page('question_groups_tab');
332
-    }
333
-
334
-
335
-    /**
336
-     * Extracts the question field's values from the POST request to update or insert them
337
-     *
338
-     * @param \EEM_Base $model
339
-     * @return array where each key is the name of a model's field/db column, and each value is its value.
340
-     */
341
-    protected function _set_column_values_for(EEM_Base $model)
342
-    {
343
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
344
-        $set_column_values = array();
345
-
346
-        //some initial checks for proper values.
347
-        //if QST_admin_only, then no matter what QST_required is we disable.
348
-        if (! empty($this->_req_data['QST_admin_only'])) {
349
-            $this->_req_data['QST_required'] = 0;
350
-        }
351
-        foreach ($model->field_settings() as $fieldName => $settings) {
352
-            // basically if QSG_identifier is empty or not set
353
-            if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354
-                $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
315
+			);
316
+		}
317
+	}
318
+
319
+	/**
320
+	 * This just previews the question groups tab that comes in caffeinated.
321
+	 *
322
+	 * @return string html
323
+	 */
324
+	protected function _questions_groups_preview()
325
+	{
326
+		$this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
+		$this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
+				'event_espresso') . '" />';
329
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
+				'event_espresso') . '</strong>';
331
+		$this->display_admin_caf_preview_page('question_groups_tab');
332
+	}
333
+
334
+
335
+	/**
336
+	 * Extracts the question field's values from the POST request to update or insert them
337
+	 *
338
+	 * @param \EEM_Base $model
339
+	 * @return array where each key is the name of a model's field/db column, and each value is its value.
340
+	 */
341
+	protected function _set_column_values_for(EEM_Base $model)
342
+	{
343
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
344
+		$set_column_values = array();
345
+
346
+		//some initial checks for proper values.
347
+		//if QST_admin_only, then no matter what QST_required is we disable.
348
+		if (! empty($this->_req_data['QST_admin_only'])) {
349
+			$this->_req_data['QST_required'] = 0;
350
+		}
351
+		foreach ($model->field_settings() as $fieldName => $settings) {
352
+			// basically if QSG_identifier is empty or not set
353
+			if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354
+				$QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
+				$set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
356 356
 //				dd($set_column_values);
357
-            } //if the admin label is blank, use a slug version of the question text
358
-            else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359
-                $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360
-                $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
362
-                $set_column_values[$fieldName] = 0;
363
-            } else if ($fieldName === 'QST_max') {
364
-                $qst_system = EEM_Question::instance()->get_var(
365
-                    array(
366
-                        array(
367
-                            'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
368
-                        ),
369
-                    ),
370
-                    'QST_system');
371
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372
-                if (empty($this->_req_data['QST_max']) ||
373
-                    $this->_req_data['QST_max'] > $max_max
374
-                ) {
375
-                    $set_column_values[$fieldName] = $max_max;
376
-                }
377
-            }
378
-
379
-
380
-            //only add a property to the array if it's not null (otherwise the model should just use the default value)
381
-            if (
382
-                ! isset($set_column_values[$fieldName]) &&
383
-                isset($this->_req_data[$fieldName])
384
-            ) {
385
-                $set_column_values[$fieldName] = $this->_req_data[$fieldName];
386
-            }
387
-
388
-        }
389
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
390
-    }
391
-
392
-
393
-    /**
394
-     *_questions_overview_list_table
395
-     */
396
-    protected function _questions_overview_list_table()
397
-    {
398
-        $this->_search_btn_label = esc_html__('Questions', 'event_espresso');
399
-        $this->display_admin_list_table_page_with_sidebar();
400
-    }
401
-
402
-
403
-    /**
404
-     * _edit_question
405
-     */
406
-    protected function _edit_question()
407
-    {
408
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
409
-        $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
410
-
411
-        switch ($this->_req_action) {
412
-            case 'add_question' :
413
-                $this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
414
-                break;
415
-            case 'edit_question' :
416
-                $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
417
-                break;
418
-            default :
419
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
420
-        }
421
-
422
-        // add PRC_ID to title if editing
423
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
424
-        if ($ID) {
425
-            $question                 = $this->_question_model->get_one_by_ID($ID);
426
-            $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
427
-            $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
428
-        } else {
429
-            $question = EE_Question::new_instance();
430
-            $question->set_order_to_latest();
431
-            $this->_set_add_edit_form_tags('insert_question');
432
-        }
433
-        if( $question->system_ID() === EEM_Attendee::system_question_phone ){
434
-            $question_types = array_intersect_key(
435
-                EEM_Question::instance()->allowed_question_types(),
436
-                array_flip(
437
-                    array(
438
-                        EEM_Question::QST_type_text,
439
-                        EEM_Question::QST_type_us_phone
440
-                    )
441
-                )
442
-            );
443
-        } else {
444
-            $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types();
445
-        }
446
-        $this->_template_args['QST_ID']                     = $ID;
447
-        $this->_template_args['question']                   = $question;
448
-        $this->_template_args['question_types']             = $question_types;
449
-        $this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
450
-            $question->system_ID()
451
-        );
452
-        $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
453
-        $this->_set_publish_post_box_vars('id', $ID);
454
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
455
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
456
-            $this->_template_args, true
457
-        );
458
-
459
-        // the details template wrapper
460
-        $this->display_admin_page_with_sidebar();
461
-    }
462
-
463
-
464
-    /**
465
-     * @return string
466
-     */
467
-    protected function _get_question_type_descriptions()
468
-    {
469
-        EE_Registry::instance()->load_helper('HTML');
470
-        $descriptions               = '';
471
-        $question_type_descriptions = EEM_Question::instance()->question_descriptions();
472
-        foreach ($question_type_descriptions as $type => $question_type_description) {
473
-            if ($type == 'HTML_TEXTAREA') {
474
-                $html = new EE_Simple_HTML_Validation_Strategy();
475
-                $question_type_description .= sprintf(
476
-                    esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
477
-                    '<br/>',
478
-                    $html->get_list_of_allowed_tags()
479
-                );
480
-            }
481
-            $descriptions .= EEH_HTML::p(
482
-                $question_type_description,
483
-                'question_type_description-' . $type,
484
-                'question_type_description description',
485
-                'display:none;'
486
-            );
487
-        }
488
-        return $descriptions;
489
-    }
490
-
491
-
492
-    /**
493
-     * @param bool|true $new_question
494
-     * @throws \EE_Error
495
-     */
496
-    protected function _insert_or_update_question($new_question = true)
497
-    {
498
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
499
-        $set_column_values = $this->_set_column_values_for($this->_question_model);
500
-        if ($new_question) {
501
-            $ID          = $this->_question_model->insert($set_column_values);
502
-            $success     = $ID ? true : false;
503
-            $action_desc = 'added';
504
-        } else {
505
-            $ID     = absint($this->_req_data['QST_ID']);
506
-            $pk     = $this->_question_model->primary_key_name();
507
-            $wheres = array($pk => $ID);
508
-            unset($set_column_values[$pk]);
509
-            $success     = $this->_question_model->update($set_column_values, array($wheres));
510
-            $action_desc = 'updated';
511
-        }
512
-
513
-        if ($ID) {
514
-            //save the related options
515
-            //trash removed options, save old ones
516
-            //get list of all options
517
-            /** @type EE_Question $question */
518
-            $question = $this->_question_model->get_one_by_ID($ID);
519
-            $options  = $question->options();
520
-            if (! empty($options)) {
521
-                foreach ($options as $option_ID => $option) {
522
-                    $option_req_index = $this->_get_option_req_data_index($option_ID);
523
-                    if ($option_req_index !== false) {
524
-                        $option->save($this->_req_data['question_options'][$option_req_index]);
525
-                    } else {
526
-                        //not found, remove it
527
-                        $option->delete();
528
-                    }
529
-                }
530
-            }
531
-            //save new related options
532
-            foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
533
-                //skip $index that is from our sample
534
-                if ( $index === 'xxcountxx' ) {
535
-                    continue;
536
-                }
537
-                //note we allow saving blank options.
538
-                if (empty($option_req_data['QSO_ID'])
539
-                ) {//no ID! save it!
540
-                    $new_option = EE_Question_Option::new_instance(array(
541
-                        'QSO_value' => $option_req_data['QSO_value'],
542
-                        'QSO_desc'  => $option_req_data['QSO_desc'],
543
-                        'QSO_order' => $option_req_data['QSO_order'],
544
-                        'QST_ID'    => $question->ID(),
545
-                    ));
546
-                    $new_option->save();
547
-                }
548
-            }
549
-        }
550
-        $query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
551
-        if ($success !== false) {
552
-            $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
553
-                $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
554
-                $this->_question_model->item_name());
555
-            EE_Error::add_success($msg);
556
-        }
557
-
558
-        $this->_redirect_after_action(false, '', $action_desc, $query_args, true);
559
-    }
560
-
561
-
562
-    /**
563
-     * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
564
-     * by ID
565
-     * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
566
-     * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
567
-     *
568
-     * @param int $ID of the question option to find
569
-     * @return int index in question_options array if successful, FALSE if unsuccessful
570
-     */
571
-    protected function _get_option_req_data_index($ID)
572
-    {
573
-        $req_data_for_question_options = $this->_req_data['question_options'];
574
-        foreach ($req_data_for_question_options as $num => $option_data) {
575
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
576
-                return $num;
577
-            }
578
-        }
579
-        return false;
580
-    }
581
-
582
-
583
-
584
-
585
-    /***********/
586
-    /* QUERIES */
587
-    /**
588
-     * For internal use in getting all the query parameters
589
-     * (because it's pretty well the same between question, question groups,
590
-     * and for both when searching for trashed and untrashed ones)
591
-     *
592
-     * @param EEM_Base $model either EEM_Question or EEM_Question_Group
593
-     * @param int      $per_page
594
-     * @param int      $current_page
595
-     * @return array lik EEM_Base::get_all's $query_params parameter
596
-     */
597
-    protected function get_query_params($model, $per_page = 10, $current_page = 10)
598
-    {
599
-        $query_params             = array();
600
-        $offset                   = ($current_page - 1) * $per_page;
601
-        $query_params['limit']    = array($offset, $per_page);
602
-        $order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
603
-        $orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
604
-        $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
605
-        $query_params['order_by'] = array($field_to_order_by => $order);
606
-        $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
607
-        if (! empty($search_string)) {
608
-            if ($model instanceof EEM_Question_Group) {
609
-                $query_params[0] = array(
610
-                    'OR' => array(
611
-                        'QSG_name' => array('LIKE', "%$search_string%"),
612
-                        'QSG_desc' => array('LIKE', "%$search_string%"),
613
-                    ),
614
-                );
615
-            } else {
616
-                $query_params[0] = array(
617
-                    'QST_display_text' => array('LIKE', "%$search_string%"),
618
-                );
619
-            }
620
-        }
621
-
622
-        //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
623
-        /*if ( $model instanceof EEM_Question_Group ) {
357
+			} //if the admin label is blank, use a slug version of the question text
358
+			else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359
+				$QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360
+				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
+			} else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
362
+				$set_column_values[$fieldName] = 0;
363
+			} else if ($fieldName === 'QST_max') {
364
+				$qst_system = EEM_Question::instance()->get_var(
365
+					array(
366
+						array(
367
+							'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
368
+						),
369
+					),
370
+					'QST_system');
371
+				$max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372
+				if (empty($this->_req_data['QST_max']) ||
373
+					$this->_req_data['QST_max'] > $max_max
374
+				) {
375
+					$set_column_values[$fieldName] = $max_max;
376
+				}
377
+			}
378
+
379
+
380
+			//only add a property to the array if it's not null (otherwise the model should just use the default value)
381
+			if (
382
+				! isset($set_column_values[$fieldName]) &&
383
+				isset($this->_req_data[$fieldName])
384
+			) {
385
+				$set_column_values[$fieldName] = $this->_req_data[$fieldName];
386
+			}
387
+
388
+		}
389
+		return $set_column_values;//validation fo this data to be performed by the model before insertion.
390
+	}
391
+
392
+
393
+	/**
394
+	 *_questions_overview_list_table
395
+	 */
396
+	protected function _questions_overview_list_table()
397
+	{
398
+		$this->_search_btn_label = esc_html__('Questions', 'event_espresso');
399
+		$this->display_admin_list_table_page_with_sidebar();
400
+	}
401
+
402
+
403
+	/**
404
+	 * _edit_question
405
+	 */
406
+	protected function _edit_question()
407
+	{
408
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
409
+		$ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
410
+
411
+		switch ($this->_req_action) {
412
+			case 'add_question' :
413
+				$this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
414
+				break;
415
+			case 'edit_question' :
416
+				$this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
417
+				break;
418
+			default :
419
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
420
+		}
421
+
422
+		// add PRC_ID to title if editing
423
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
424
+		if ($ID) {
425
+			$question                 = $this->_question_model->get_one_by_ID($ID);
426
+			$additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
427
+			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
428
+		} else {
429
+			$question = EE_Question::new_instance();
430
+			$question->set_order_to_latest();
431
+			$this->_set_add_edit_form_tags('insert_question');
432
+		}
433
+		if( $question->system_ID() === EEM_Attendee::system_question_phone ){
434
+			$question_types = array_intersect_key(
435
+				EEM_Question::instance()->allowed_question_types(),
436
+				array_flip(
437
+					array(
438
+						EEM_Question::QST_type_text,
439
+						EEM_Question::QST_type_us_phone
440
+					)
441
+				)
442
+			);
443
+		} else {
444
+			$question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types();
445
+		}
446
+		$this->_template_args['QST_ID']                     = $ID;
447
+		$this->_template_args['question']                   = $question;
448
+		$this->_template_args['question_types']             = $question_types;
449
+		$this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
450
+			$question->system_ID()
451
+		);
452
+		$this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
453
+		$this->_set_publish_post_box_vars('id', $ID);
454
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
455
+			REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
456
+			$this->_template_args, true
457
+		);
458
+
459
+		// the details template wrapper
460
+		$this->display_admin_page_with_sidebar();
461
+	}
462
+
463
+
464
+	/**
465
+	 * @return string
466
+	 */
467
+	protected function _get_question_type_descriptions()
468
+	{
469
+		EE_Registry::instance()->load_helper('HTML');
470
+		$descriptions               = '';
471
+		$question_type_descriptions = EEM_Question::instance()->question_descriptions();
472
+		foreach ($question_type_descriptions as $type => $question_type_description) {
473
+			if ($type == 'HTML_TEXTAREA') {
474
+				$html = new EE_Simple_HTML_Validation_Strategy();
475
+				$question_type_description .= sprintf(
476
+					esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
477
+					'<br/>',
478
+					$html->get_list_of_allowed_tags()
479
+				);
480
+			}
481
+			$descriptions .= EEH_HTML::p(
482
+				$question_type_description,
483
+				'question_type_description-' . $type,
484
+				'question_type_description description',
485
+				'display:none;'
486
+			);
487
+		}
488
+		return $descriptions;
489
+	}
490
+
491
+
492
+	/**
493
+	 * @param bool|true $new_question
494
+	 * @throws \EE_Error
495
+	 */
496
+	protected function _insert_or_update_question($new_question = true)
497
+	{
498
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
499
+		$set_column_values = $this->_set_column_values_for($this->_question_model);
500
+		if ($new_question) {
501
+			$ID          = $this->_question_model->insert($set_column_values);
502
+			$success     = $ID ? true : false;
503
+			$action_desc = 'added';
504
+		} else {
505
+			$ID     = absint($this->_req_data['QST_ID']);
506
+			$pk     = $this->_question_model->primary_key_name();
507
+			$wheres = array($pk => $ID);
508
+			unset($set_column_values[$pk]);
509
+			$success     = $this->_question_model->update($set_column_values, array($wheres));
510
+			$action_desc = 'updated';
511
+		}
512
+
513
+		if ($ID) {
514
+			//save the related options
515
+			//trash removed options, save old ones
516
+			//get list of all options
517
+			/** @type EE_Question $question */
518
+			$question = $this->_question_model->get_one_by_ID($ID);
519
+			$options  = $question->options();
520
+			if (! empty($options)) {
521
+				foreach ($options as $option_ID => $option) {
522
+					$option_req_index = $this->_get_option_req_data_index($option_ID);
523
+					if ($option_req_index !== false) {
524
+						$option->save($this->_req_data['question_options'][$option_req_index]);
525
+					} else {
526
+						//not found, remove it
527
+						$option->delete();
528
+					}
529
+				}
530
+			}
531
+			//save new related options
532
+			foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
533
+				//skip $index that is from our sample
534
+				if ( $index === 'xxcountxx' ) {
535
+					continue;
536
+				}
537
+				//note we allow saving blank options.
538
+				if (empty($option_req_data['QSO_ID'])
539
+				) {//no ID! save it!
540
+					$new_option = EE_Question_Option::new_instance(array(
541
+						'QSO_value' => $option_req_data['QSO_value'],
542
+						'QSO_desc'  => $option_req_data['QSO_desc'],
543
+						'QSO_order' => $option_req_data['QSO_order'],
544
+						'QST_ID'    => $question->ID(),
545
+					));
546
+					$new_option->save();
547
+				}
548
+			}
549
+		}
550
+		$query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
551
+		if ($success !== false) {
552
+			$msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
553
+				$this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
554
+				$this->_question_model->item_name());
555
+			EE_Error::add_success($msg);
556
+		}
557
+
558
+		$this->_redirect_after_action(false, '', $action_desc, $query_args, true);
559
+	}
560
+
561
+
562
+	/**
563
+	 * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
564
+	 * by ID
565
+	 * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
566
+	 * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
567
+	 *
568
+	 * @param int $ID of the question option to find
569
+	 * @return int index in question_options array if successful, FALSE if unsuccessful
570
+	 */
571
+	protected function _get_option_req_data_index($ID)
572
+	{
573
+		$req_data_for_question_options = $this->_req_data['question_options'];
574
+		foreach ($req_data_for_question_options as $num => $option_data) {
575
+			if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
576
+				return $num;
577
+			}
578
+		}
579
+		return false;
580
+	}
581
+
582
+
583
+
584
+
585
+	/***********/
586
+	/* QUERIES */
587
+	/**
588
+	 * For internal use in getting all the query parameters
589
+	 * (because it's pretty well the same between question, question groups,
590
+	 * and for both when searching for trashed and untrashed ones)
591
+	 *
592
+	 * @param EEM_Base $model either EEM_Question or EEM_Question_Group
593
+	 * @param int      $per_page
594
+	 * @param int      $current_page
595
+	 * @return array lik EEM_Base::get_all's $query_params parameter
596
+	 */
597
+	protected function get_query_params($model, $per_page = 10, $current_page = 10)
598
+	{
599
+		$query_params             = array();
600
+		$offset                   = ($current_page - 1) * $per_page;
601
+		$query_params['limit']    = array($offset, $per_page);
602
+		$order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
603
+		$orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
604
+		$field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
605
+		$query_params['order_by'] = array($field_to_order_by => $order);
606
+		$search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
607
+		if (! empty($search_string)) {
608
+			if ($model instanceof EEM_Question_Group) {
609
+				$query_params[0] = array(
610
+					'OR' => array(
611
+						'QSG_name' => array('LIKE', "%$search_string%"),
612
+						'QSG_desc' => array('LIKE', "%$search_string%"),
613
+					),
614
+				);
615
+			} else {
616
+				$query_params[0] = array(
617
+					'QST_display_text' => array('LIKE', "%$search_string%"),
618
+				);
619
+			}
620
+		}
621
+
622
+		//capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
623
+		/*if ( $model instanceof EEM_Question_Group ) {
624 624
             if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) {
625 625
                 $query_params[0] = array(
626 626
                     'AND' => array(
@@ -650,62 +650,62 @@  discard block
 block discarded – undo
650 650
             }
651 651
         }/**/
652 652
 
653
-        return $query_params;
654
-
655
-    }
656
-
657
-
658
-    /**
659
-     * @param int        $per_page
660
-     * @param int        $current_page
661
-     * @param bool|false $count
662
-     * @return \EE_Soft_Delete_Base_Class[]|int
663
-     */
664
-    public function get_questions($per_page = 10, $current_page = 1, $count = false)
665
-    {
666
-        $QST          = EEM_Question::instance();
667
-        $query_params = $this->get_query_params($QST, $per_page, $current_page);
668
-        if ($count) {
669
-            $where   = isset($query_params[0]) ? array($query_params[0]) : array();
670
-            $results = $QST->count($where);
671
-        } else {
672
-            $results = $QST->get_all($query_params);
673
-        }
674
-        return $results;
675
-
676
-    }
677
-
678
-
679
-    /**
680
-     * @param            $per_page
681
-     * @param int        $current_page
682
-     * @param bool|false $count
683
-     * @return \EE_Soft_Delete_Base_Class[]|int
684
-     */
685
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
686
-    {
687
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
688
-        $where        = isset($query_params[0]) ? array($query_params[0]) : array();
689
-        $questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
690
-        return $questions;
691
-    }
692
-
693
-
694
-    /**
695
-     * @param            $per_page
696
-     * @param int        $current_page
697
-     * @param bool|false $count
698
-     * @return \EE_Soft_Delete_Base_Class[]
699
-     */
700
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
701
-    {
702
-        /** @type EEM_Question_Group $questionGroupModel */
703
-        $questionGroupModel = EEM_Question_Group::instance();
704
-        //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
705
-        return $questionGroupModel->get_all(
706
-            $this->get_query_params($questionGroupModel, $per_page, $current_page)
707
-        );
708
-    }
653
+		return $query_params;
654
+
655
+	}
656
+
657
+
658
+	/**
659
+	 * @param int        $per_page
660
+	 * @param int        $current_page
661
+	 * @param bool|false $count
662
+	 * @return \EE_Soft_Delete_Base_Class[]|int
663
+	 */
664
+	public function get_questions($per_page = 10, $current_page = 1, $count = false)
665
+	{
666
+		$QST          = EEM_Question::instance();
667
+		$query_params = $this->get_query_params($QST, $per_page, $current_page);
668
+		if ($count) {
669
+			$where   = isset($query_params[0]) ? array($query_params[0]) : array();
670
+			$results = $QST->count($where);
671
+		} else {
672
+			$results = $QST->get_all($query_params);
673
+		}
674
+		return $results;
675
+
676
+	}
677
+
678
+
679
+	/**
680
+	 * @param            $per_page
681
+	 * @param int        $current_page
682
+	 * @param bool|false $count
683
+	 * @return \EE_Soft_Delete_Base_Class[]|int
684
+	 */
685
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
686
+	{
687
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
688
+		$where        = isset($query_params[0]) ? array($query_params[0]) : array();
689
+		$questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
690
+		return $questions;
691
+	}
692
+
693
+
694
+	/**
695
+	 * @param            $per_page
696
+	 * @param int        $current_page
697
+	 * @param bool|false $count
698
+	 * @return \EE_Soft_Delete_Base_Class[]
699
+	 */
700
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
701
+	{
702
+		/** @type EEM_Question_Group $questionGroupModel */
703
+		$questionGroupModel = EEM_Question_Group::instance();
704
+		//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
705
+		return $questionGroupModel->get_all(
706
+			$this->get_query_params($questionGroupModel, $per_page, $current_page)
707
+		);
708
+	}
709 709
 
710 710
 
711 711
 } //ends Registration_Form_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function __construct($routing = true)
68 68
     {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
69
+        require_once(EE_MODELS.'EEM_Question.model.php');
70
+        require_once(EE_MODELS.'EEM_Question_Group.model.php');
71 71
         $this->_question_model       = EEM_Question::instance();
72 72
         $this->_question_group_model = EEM_Question_Group::instance();
73 73
         parent::__construct($routing);
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     public function load_scripts_styles()
233 233
     {
234 234
         wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
235
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236 236
         wp_enqueue_style('espresso_registration');
237 237
     }
238 238
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     {
259 259
         $this->load_scripts_styles_forms();
260 260
         wp_register_script('espresso_registration_form_single',
261
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
261
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262 262
             EVENT_ESPRESSO_VERSION, true);
263 263
         wp_enqueue_script('espresso_registration_form_single');
264 264
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     {
268 268
         $this->load_scripts_styles_forms();
269 269
         wp_register_script('espresso_registration_form_single',
270
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
270
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271 271
             EVENT_ESPRESSO_VERSION, true);
272 272
         wp_enqueue_script('espresso_registration_form_single');
273 273
     }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
     public function recaptcha_info_help_tab()
277 277
     {
278
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
278
+        $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php';
279 279
         EEH_Template::display_template($template, array());
280 280
     }
281 281
 
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
     protected function _questions_groups_preview()
325 325
     {
326 326
         $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
-                'event_espresso') . '" />';
329
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
-                'event_espresso') . '</strong>';
327
+        $this->_template_args['preview_img']  = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot',
328
+                'event_espresso').'" />';
329
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
+                'event_espresso').'</strong>';
331 331
         $this->display_admin_caf_preview_page('question_groups_tab');
332 332
     }
333 333
 
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
 
346 346
         //some initial checks for proper values.
347 347
         //if QST_admin_only, then no matter what QST_required is we disable.
348
-        if (! empty($this->_req_data['QST_admin_only'])) {
348
+        if ( ! empty($this->_req_data['QST_admin_only'])) {
349 349
             $this->_req_data['QST_required'] = 0;
350 350
         }
351 351
         foreach ($model->field_settings() as $fieldName => $settings) {
352 352
             // basically if QSG_identifier is empty or not set
353 353
             if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354 354
                 $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
355
+                $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true);
356 356
 //				dd($set_column_values);
357 357
             } //if the admin label is blank, use a slug version of the question text
358 358
             else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359 359
                 $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360 360
                 $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
361
+            } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) {
362 362
                 $set_column_values[$fieldName] = 0;
363 363
             } else if ($fieldName === 'QST_max') {
364 364
                 $qst_system = EEM_Question::instance()->get_var(
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                         ),
369 369
                     ),
370 370
                     'QST_system');
371
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
371
+                $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372 372
                 if (empty($this->_req_data['QST_max']) ||
373 373
                     $this->_req_data['QST_max'] > $max_max
374 374
                 ) {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             }
387 387
 
388 388
         }
389
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
389
+        return $set_column_values; //validation fo this data to be performed by the model before insertion.
390 390
     }
391 391
 
392 392
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
         }
421 421
 
422 422
         // add PRC_ID to title if editing
423
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
423
+        $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
424 424
         if ($ID) {
425 425
             $question                 = $this->_question_model->get_one_by_ID($ID);
426 426
             $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
             $question->set_order_to_latest();
431 431
             $this->_set_add_edit_form_tags('insert_question');
432 432
         }
433
-        if( $question->system_ID() === EEM_Attendee::system_question_phone ){
433
+        if ($question->system_ID() === EEM_Attendee::system_question_phone) {
434 434
             $question_types = array_intersect_key(
435 435
                 EEM_Question::instance()->allowed_question_types(),
436 436
                 array_flip(
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
         $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
453 453
         $this->_set_publish_post_box_vars('id', $ID);
454 454
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
455
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
455
+            REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php',
456 456
             $this->_template_args, true
457 457
         );
458 458
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
             }
481 481
             $descriptions .= EEH_HTML::p(
482 482
                 $question_type_description,
483
-                'question_type_description-' . $type,
483
+                'question_type_description-'.$type,
484 484
                 'question_type_description description',
485 485
                 'display:none;'
486 486
             );
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
             /** @type EE_Question $question */
518 518
             $question = $this->_question_model->get_one_by_ID($ID);
519 519
             $options  = $question->options();
520
-            if (! empty($options)) {
520
+            if ( ! empty($options)) {
521 521
                 foreach ($options as $option_ID => $option) {
522 522
                     $option_req_index = $this->_get_option_req_data_index($option_ID);
523 523
                     if ($option_req_index !== false) {
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
             //save new related options
532 532
             foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
533 533
                 //skip $index that is from our sample
534
-                if ( $index === 'xxcountxx' ) {
534
+                if ($index === 'xxcountxx') {
535 535
                     continue;
536 536
                 }
537 537
                 //note we allow saving blank options.
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
     {
573 573
         $req_data_for_question_options = $this->_req_data['question_options'];
574 574
         foreach ($req_data_for_question_options as $num => $option_data) {
575
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
575
+            if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) {
576 576
                 return $num;
577 577
             }
578 578
         }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
         $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
605 605
         $query_params['order_by'] = array($field_to_order_by => $order);
606 606
         $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
607
-        if (! empty($search_string)) {
607
+        if ( ! empty($search_string)) {
608 608
             if ($model instanceof EEM_Question_Group) {
609 609
                 $query_params[0] = array(
610 610
                     'OR' => array(
Please login to merge, or discard this patch.
core/data_migration_scripts/EE_DMS_Core_4_9_0.dms.php 2 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
 $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15
-    $matches = array();
16
-    preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
-    $class_to_filepath[$matches[1]] = $filepath;
15
+	$matches = array();
16
+	preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches);
17
+	$class_to_filepath[$matches[1]] = $filepath;
18 18
 }
19 19
 //give addons a chance to autoload their stages too
20 20
 $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath);
@@ -33,68 +33,68 @@  discard block
 block discarded – undo
33 33
 class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base
34 34
 {
35 35
 
36
-    /**
37
-     * return EE_DMS_Core_4_9_0
38
-     *
39
-     * @param TableManager  $table_manager
40
-     * @param TableAnalysis $table_analysis
41
-     */
42
-    public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
-    {
44
-        $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
-        $this->_priority = 10;
46
-        $this->_migration_stages = array(
47
-            new EE_DMS_4_9_0_Email_System_Question(),
48
-            new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
-        );
50
-        parent::__construct($table_manager, $table_analysis);
51
-    }
36
+	/**
37
+	 * return EE_DMS_Core_4_9_0
38
+	 *
39
+	 * @param TableManager  $table_manager
40
+	 * @param TableAnalysis $table_analysis
41
+	 */
42
+	public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null)
43
+	{
44
+		$this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso");
45
+		$this->_priority = 10;
46
+		$this->_migration_stages = array(
47
+			new EE_DMS_4_9_0_Email_System_Question(),
48
+			new EE_DMS_4_9_0_Answers_With_No_Registration(),
49
+		);
50
+		parent::__construct($table_manager, $table_analysis);
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     * Whether to migrate or not.
57
-     *
58
-     * @param array $version_array
59
-     * @return bool
60
-     */
61
-    public function can_migrate_from_version($version_array)
62
-    {
63
-        $version_string = $version_array['Core'];
64
-        if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
-            //			echo "$version_string can be migrated from";
66
-            return true;
67
-        } elseif ( ! $version_string) {
68
-            //			echo "no version string provided: $version_string";
69
-            //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
-        } else {
72
-            //			echo "$version_string doesnt apply";
73
-            return false;
74
-        }
75
-    }
55
+	/**
56
+	 * Whether to migrate or not.
57
+	 *
58
+	 * @param array $version_array
59
+	 * @return bool
60
+	 */
61
+	public function can_migrate_from_version($version_array)
62
+	{
63
+		$version_string = $version_array['Core'];
64
+		if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) {
65
+			//			echo "$version_string can be migrated from";
66
+			return true;
67
+		} elseif ( ! $version_string) {
68
+			//			echo "no version string provided: $version_string";
69
+			//no version string provided... this must be pre 4.3
70
+			return false;//changed mind. dont want people thinking they should migrate yet because they cant
71
+		} else {
72
+			//			echo "$version_string doesnt apply";
73
+			return false;
74
+		}
75
+	}
76 76
 
77 77
 
78 78
 
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function schema_changes_before_migration()
83
-    {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
-        $now_in_mysql = current_time('mysql', true);
86
-        $table_name = 'esp_answer';
87
-        $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function schema_changes_before_migration()
83
+	{
84
+		require_once(EE_HELPERS . 'EEH_Activation.helper.php');
85
+		$now_in_mysql = current_time('mysql', true);
86
+		$table_name = 'esp_answer';
87
+		$sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
88 88
 					REG_ID int(10) unsigned NOT NULL,
89 89
 					QST_ID int(10) unsigned NOT NULL,
90 90
 					ANS_value text NOT NULL,
91 91
 					PRIMARY KEY  (ANS_ID),
92 92
 					KEY REG_ID (REG_ID),
93 93
 					KEY QST_ID (QST_ID)";
94
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
-        $table_name = 'esp_attendee_meta';
96
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
-        $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
94
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
95
+		$table_name = 'esp_attendee_meta';
96
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email');
97
+		$sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
98 98
 				ATT_ID bigint(20) unsigned NOT NULL,
99 99
 				ATT_fname varchar(45) NOT NULL,
100 100
 				ATT_lname varchar(45) NOT NULL,
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 				KEY ATT_email (ATT_email(191)),
112 112
 				KEY ATT_lname (ATT_lname),
113 113
 				KEY ATT_fname (ATT_fname)";
114
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
-        $table_name = 'esp_checkin';
116
-        $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
114
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB ');
115
+		$table_name = 'esp_checkin';
116
+		$sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
117 117
 				REG_ID int(10) unsigned NOT NULL,
118 118
 				DTT_ID int(10) unsigned NOT NULL,
119 119
 				CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 				PRIMARY KEY  (CHK_ID),
122 122
 				KEY REG_ID (REG_ID),
123 123
 				KEY DTT_ID (DTT_ID)";
124
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
-        $table_name = 'esp_country';
126
-        $sql = "CNT_ISO varchar(2) NOT NULL,
124
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
125
+		$table_name = 'esp_country';
126
+		$sql = "CNT_ISO varchar(2) NOT NULL,
127 127
 				CNT_ISO3 varchar(3) NOT NULL,
128 128
 				RGN_ID tinyint(3) unsigned DEFAULT NULL,
129 129
 				CNT_name varchar(45) NOT NULL,
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
 				CNT_is_EU tinyint(1) DEFAULT '0',
140 140
 				CNT_active tinyint(1) DEFAULT '0',
141 141
 				PRIMARY KEY  (CNT_ISO)";
142
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
-        $table_name = 'esp_currency';
144
-        $sql = "CUR_code varchar(6) NOT NULL,
142
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
143
+		$table_name = 'esp_currency';
144
+		$sql = "CUR_code varchar(6) NOT NULL,
145 145
 				CUR_single varchar(45) DEFAULT 'dollar',
146 146
 				CUR_plural varchar(45) DEFAULT 'dollars',
147 147
 				CUR_sign varchar(45) DEFAULT '$',
148 148
 				CUR_dec_plc varchar(1) NOT NULL DEFAULT '2',
149 149
 				CUR_active tinyint(1) DEFAULT '0',
150 150
 				PRIMARY KEY  (CUR_code)";
151
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
-        $table_name = 'esp_currency_payment_method';
153
-        $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
151
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
152
+		$table_name = 'esp_currency_payment_method';
153
+		$sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT,
154 154
 				CUR_code varchar(6) NOT NULL,
155 155
 				PMD_ID int(11) NOT NULL,
156 156
 				PRIMARY KEY  (CPM_ID),
157 157
 				KEY PMD_ID (PMD_ID)";
158
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
-        $table_name = 'esp_datetime';
160
-        $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
158
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
159
+		$table_name = 'esp_datetime';
160
+		$sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
161 161
 				EVT_ID bigint(20) unsigned NOT NULL,
162 162
 				DTT_name varchar(255) NOT NULL DEFAULT '',
163 163
 				DTT_description text NOT NULL,
@@ -174,25 +174,25 @@  discard block
 block discarded – undo
174 174
 				KEY DTT_EVT_start (DTT_EVT_start),
175 175
 				KEY EVT_ID (EVT_ID),
176 176
 				KEY DTT_is_primary (DTT_is_primary)";
177
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
-        $table_name = "esp_datetime_ticket";
179
-        $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
177
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
178
+		$table_name = "esp_datetime_ticket";
179
+		$sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
180 180
 				DTT_ID int(10) unsigned NOT NULL,
181 181
 				TKT_ID int(10) unsigned NOT NULL,
182 182
 				PRIMARY KEY  (DTK_ID),
183 183
 				KEY DTT_ID (DTT_ID),
184 184
 				KEY TKT_ID (TKT_ID)";
185
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
-        $table_name = 'esp_event_message_template';
187
-        $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
185
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
186
+		$table_name = 'esp_event_message_template';
187
+		$sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
188 188
 				EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0,
189 189
 				GRP_ID int(10) unsigned NOT NULL DEFAULT 0,
190 190
 				PRIMARY KEY  (EMT_ID),
191 191
 				KEY EVT_ID (EVT_ID),
192 192
 				KEY GRP_ID (GRP_ID)";
193
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
-        $table_name = 'esp_event_meta';
195
-        $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
193
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
194
+		$table_name = 'esp_event_meta';
195
+		$sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT,
196 196
 				EVT_ID bigint(20) unsigned NOT NULL,
197 197
 				EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1,
198 198
 				EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1,
@@ -207,34 +207,34 @@  discard block
 block discarded – undo
207 207
 				EVT_donations tinyint(1) NULL,
208 208
 				PRIMARY KEY  (EVTM_ID),
209 209
 				KEY EVT_ID (EVT_ID)";
210
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
-        $table_name = 'esp_event_question_group';
212
-        $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
210
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
211
+		$table_name = 'esp_event_question_group';
212
+		$sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
213 213
 				EVT_ID bigint(20) unsigned NOT NULL,
214 214
 				QSG_ID int(10) unsigned NOT NULL,
215 215
 				EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
216 216
 				PRIMARY KEY  (EQG_ID),
217 217
 				KEY EVT_ID (EVT_ID),
218 218
 				KEY QSG_ID (QSG_ID)";
219
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
-        $table_name = 'esp_event_venue';
221
-        $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
219
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
220
+		$table_name = 'esp_event_venue';
221
+		$sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT,
222 222
 				EVT_ID bigint(20) unsigned NOT NULL,
223 223
 				VNU_ID bigint(20) unsigned NOT NULL,
224 224
 				EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0,
225 225
 				PRIMARY KEY  (EVV_ID)";
226
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
-        $table_name = 'esp_extra_meta';
228
-        $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
226
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
227
+		$table_name = 'esp_extra_meta';
228
+		$sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT,
229 229
 				OBJ_ID int(11) DEFAULT NULL,
230 230
 				EXM_type varchar(45) DEFAULT NULL,
231 231
 				EXM_key varchar(45) DEFAULT NULL,
232 232
 				EXM_value text,
233 233
 				PRIMARY KEY  (EXM_ID),
234 234
 				KEY EXM_type (EXM_type,OBJ_ID,EXM_key)";
235
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
-        $table_name = 'esp_extra_join';
237
-        $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
235
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
236
+		$table_name = 'esp_extra_join';
237
+		$sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT,
238 238
 				EXJ_first_model_id varchar(6) NOT NULL,
239 239
 				EXJ_first_model_name varchar(20) NOT NULL,
240 240
 				EXJ_second_model_id varchar(6) NOT NULL,
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
 				PRIMARY KEY  (EXJ_ID),
243 243
 				KEY first_model (EXJ_first_model_name,EXJ_first_model_id),
244 244
 				KEY second_model (EXJ_second_model_name,EXJ_second_model_id)";
245
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
-        $table_name = 'esp_line_item';
247
-        $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
245
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
246
+		$table_name = 'esp_line_item';
247
+		$sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT,
248 248
 				LIN_code varchar(245) NOT NULL DEFAULT '',
249 249
 				TXN_ID int(11) DEFAULT NULL,
250 250
 				LIN_name varchar(245) NOT NULL DEFAULT '',
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
263 263
 				PRIMARY KEY  (LIN_ID),
264 264
 				KEY LIN_code (LIN_code(191)),
265 265
 				KEY TXN_ID (TXN_ID)";
266
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
267
-        $table_name = 'esp_log';
268
-        $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
266
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
267
+		$table_name = 'esp_log';
268
+		$sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT,
269 269
 				LOG_time datetime DEFAULT NULL,
270 270
 				OBJ_ID varchar(45) DEFAULT NULL,
271 271
 				OBJ_type varchar(45) DEFAULT NULL,
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
 				KEY LOG_time (LOG_time),
277 277
 				KEY OBJ (OBJ_type,OBJ_ID),
278 278
 				KEY LOG_type (LOG_type)";
279
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
-        $table_name = 'esp_message';
281
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
-        $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
-        $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
279
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
280
+		$table_name = 'esp_message';
281
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to');
282
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from');
283
+		$this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject');
284
+		$sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT,
285 285
 				GRP_ID int(10) unsigned NULL,
286 286
 				MSG_token varchar(255) NULL,
287 287
 				TXN_ID int(10) unsigned NULL,
@@ -313,18 +313,18 @@  discard block
 block discarded – undo
313 313
 				KEY STS_ID (STS_ID),
314 314
 				KEY MSG_created (MSG_created),
315 315
 				KEY MSG_modified (MSG_modified)";
316
-        $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
-        $table_name = 'esp_message_template';
318
-        $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
316
+		$this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
317
+		$table_name = 'esp_message_template';
318
+		$sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
319 319
 				GRP_ID int(10) unsigned NOT NULL,
320 320
 				MTP_context varchar(50) NOT NULL,
321 321
 				MTP_template_field varchar(30) NOT NULL,
322 322
 				MTP_content text NOT NULL,
323 323
 				PRIMARY KEY  (MTP_ID),
324 324
 				KEY GRP_ID (GRP_ID)";
325
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
-        $table_name = 'esp_message_template_group';
327
-        $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
325
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
326
+		$table_name = 'esp_message_template_group';
327
+		$sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
328 328
 				MTP_user_id int(10) NOT NULL DEFAULT '1',
329 329
 				MTP_name varchar(245) NOT NULL DEFAULT '',
330 330
 				MTP_description varchar(245) NOT NULL DEFAULT '',
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 				MTP_is_active tinyint(1) NOT NULL DEFAULT '1',
337 337
 				PRIMARY KEY  (GRP_ID),
338 338
 				KEY MTP_user_id (MTP_user_id)";
339
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
-        $table_name = 'esp_payment';
341
-        $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
339
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
340
+		$table_name = 'esp_payment';
341
+		$sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
342 342
 				TXN_ID int(10) unsigned DEFAULT NULL,
343 343
 				STS_ID varchar(3) DEFAULT NULL,
344 344
 				PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
 				PRIMARY KEY  (PAY_ID),
356 356
 				KEY PAY_timestamp (PAY_timestamp),
357 357
 				KEY TXN_ID (TXN_ID)";
358
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
359
-        $table_name = 'esp_payment_method';
360
-        $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
358
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
359
+		$table_name = 'esp_payment_method';
360
+		$sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT,
361 361
 				PMD_type varchar(124) DEFAULT NULL,
362 362
 				PMD_name varchar(255) DEFAULT NULL,
363 363
 				PMD_desc text,
@@ -373,24 +373,24 @@  discard block
 block discarded – undo
373 373
 				PRIMARY KEY  (PMD_ID),
374 374
 				UNIQUE KEY PMD_slug_UNIQUE (PMD_slug),
375 375
 				KEY PMD_type (PMD_type)";
376
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
-        $table_name = "esp_ticket_price";
378
-        $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
376
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
377
+		$table_name = "esp_ticket_price";
378
+		$sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
379 379
 				TKT_ID int(10) unsigned NOT NULL,
380 380
 				PRC_ID int(10) unsigned NOT NULL,
381 381
 				PRIMARY KEY  (TKP_ID),
382 382
 				KEY TKT_ID (TKT_ID),
383 383
 				KEY PRC_ID (PRC_ID)";
384
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
-        $table_name = "esp_ticket_template";
386
-        $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
384
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
385
+		$table_name = "esp_ticket_template";
386
+		$sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
387 387
 				TTM_name varchar(45) NOT NULL,
388 388
 				TTM_description text,
389 389
 				TTM_file varchar(45),
390 390
 				PRIMARY KEY  (TTM_ID)";
391
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
-        $table_name = 'esp_question';
393
-        $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
391
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
392
+		$table_name = 'esp_question';
393
+		$sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
394 394
 				QST_display_text text NOT NULL,
395 395
 				QST_admin_label varchar(255) NOT NULL,
396 396
 				QST_system varchar(25) DEFAULT NULL,
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
 				QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0,
405 405
 				PRIMARY KEY  (QST_ID),
406 406
 				KEY QST_order (QST_order)';
407
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
-        $table_name = 'esp_question_group_question';
409
-        $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
407
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
408
+		$table_name = 'esp_question_group_question';
409
+		$sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
410 410
 				QSG_ID int(10) unsigned NOT NULL,
411 411
 				QST_ID int(10) unsigned NOT NULL,
412 412
 				QGQ_order int(10) unsigned NOT NULL DEFAULT 0,
413 413
 				PRIMARY KEY  (QGQ_ID),
414 414
 				KEY QST_ID (QST_ID),
415 415
 				KEY QSG_ID_order (QSG_ID,QGQ_order)";
416
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
-        $table_name = 'esp_question_option';
418
-        $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
416
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
417
+		$table_name = 'esp_question_option';
418
+		$sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
419 419
 				QSO_value varchar(255) NOT NULL,
420 420
 				QSO_desc text NOT NULL,
421 421
 				QST_ID int(10) unsigned NOT NULL,
@@ -425,9 +425,9 @@  discard block
 block discarded – undo
425 425
 				PRIMARY KEY  (QSO_ID),
426 426
 				KEY QST_ID (QST_ID),
427 427
 				KEY QSO_order (QSO_order)";
428
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
-        $table_name = 'esp_registration';
430
-        $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
428
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
429
+		$table_name = 'esp_registration';
430
+		$sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
431 431
 				EVT_ID bigint(20) unsigned NOT NULL,
432 432
 				ATT_ID bigint(20) unsigned NOT NULL,
433 433
 				TXN_ID int(10) unsigned NOT NULL,
@@ -451,18 +451,18 @@  discard block
 block discarded – undo
451 451
 				KEY TKT_ID (TKT_ID),
452 452
 				KEY EVT_ID (EVT_ID),
453 453
 				KEY STS_ID (STS_ID)";
454
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
455
-        $table_name = 'esp_registration_payment';
456
-        $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
454
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
455
+		$table_name = 'esp_registration_payment';
456
+		$sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
457 457
 					  REG_ID int(10) unsigned NOT NULL,
458 458
 					  PAY_ID int(10) unsigned NULL,
459 459
 					  RPY_amount decimal(10,3) NOT NULL DEFAULT '0.00',
460 460
 					  PRIMARY KEY  (RPY_ID),
461 461
 					  KEY REG_ID (REG_ID),
462 462
 					  KEY PAY_ID (PAY_ID)";
463
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
464
-        $table_name = 'esp_state';
465
-        $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
463
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
464
+		$table_name = 'esp_state';
465
+		$sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT,
466 466
 				CNT_ISO varchar(2) NOT NULL,
467 467
 				STA_abbrev varchar(24) NOT NULL,
468 468
 				STA_name varchar(100) NOT NULL,
@@ -470,9 +470,9 @@  discard block
 block discarded – undo
470 470
 				PRIMARY KEY  (STA_ID),
471 471
 				KEY STA_abbrev (STA_abbrev),
472 472
 				KEY CNT_ISO (CNT_ISO)";
473
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
-        $table_name = 'esp_status';
475
-        $sql = "STS_ID varchar(3) NOT NULL,
473
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
474
+		$table_name = 'esp_status';
475
+		$sql = "STS_ID varchar(3) NOT NULL,
476 476
 				STS_code varchar(45) NOT NULL,
477 477
 				STS_type varchar(45) NOT NULL,
478 478
 				STS_can_edit tinyint(1) NOT NULL DEFAULT 0,
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 				STS_open tinyint(1) NOT NULL DEFAULT 1,
481 481
 				UNIQUE KEY STS_ID_UNIQUE (STS_ID),
482 482
 				KEY STS_type (STS_type)";
483
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
-        $table_name = 'esp_transaction';
485
-        $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
483
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
484
+		$table_name = 'esp_transaction';
485
+		$sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
486 486
 				TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
487 487
 				TXN_total decimal(10,3) DEFAULT '0.00',
488 488
 				TXN_paid decimal(10,3) NOT NULL DEFAULT '0.00',
@@ -494,9 +494,9 @@  discard block
 block discarded – undo
494 494
 				PRIMARY KEY  (TXN_ID),
495 495
 				KEY TXN_timestamp (TXN_timestamp),
496 496
 				KEY STS_ID (STS_ID)";
497
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
498
-        $table_name = 'esp_venue_meta';
499
-        $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
497
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
498
+		$table_name = 'esp_venue_meta';
499
+		$sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT,
500 500
 			VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0,
501 501
 			VNU_address varchar(255) DEFAULT NULL,
502 502
 			VNU_address2 varchar(255) DEFAULT NULL,
@@ -515,10 +515,10 @@  discard block
 block discarded – undo
515 515
 			KEY VNU_ID (VNU_ID),
516 516
 			KEY STA_ID (STA_ID),
517 517
 			KEY CNT_ISO (CNT_ISO)";
518
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
-        //modified tables
520
-        $table_name = "esp_price";
521
-        $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
518
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
519
+		//modified tables
520
+		$table_name = "esp_price";
521
+		$sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
522 522
 				PRT_ID tinyint(3) unsigned NOT NULL,
523 523
 				PRC_amount decimal(10,3) NOT NULL DEFAULT '0.00',
524 524
 				PRC_name varchar(245) NOT NULL,
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
 				PRC_parent int(10) unsigned DEFAULT 0,
532 532
 				PRIMARY KEY  (PRC_ID),
533 533
 				KEY PRT_ID (PRT_ID)";
534
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
535
-        $table_name = "esp_price_type";
536
-        $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
534
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
535
+		$table_name = "esp_price_type";
536
+		$sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
537 537
 				PRT_name varchar(45) NOT NULL,
538 538
 				PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1',
539 539
 				PRT_is_percent tinyint(1) NOT NULL DEFAULT '0',
@@ -542,9 +542,9 @@  discard block
 block discarded – undo
542 542
 				PRT_deleted tinyint(1) NOT NULL DEFAULT '0',
543 543
 				UNIQUE KEY PRT_name_UNIQUE (PRT_name),
544 544
 				PRIMARY KEY  (PRT_ID)";
545
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
-        $table_name = "esp_ticket";
547
-        $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
545
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB ');
546
+		$table_name = "esp_ticket";
547
+		$sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
548 548
 				TTM_ID int(10) unsigned NOT NULL,
549 549
 				TKT_name varchar(245) NOT NULL DEFAULT '',
550 550
 				TKT_description text NOT NULL,
@@ -567,9 +567,9 @@  discard block
 block discarded – undo
567 567
 				TKT_deleted tinyint(1) NOT NULL DEFAULT '0',
568 568
 				PRIMARY KEY  (TKT_ID),
569 569
 				KEY TKT_start_date (TKT_start_date)";
570
-        $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
-        $table_name = 'esp_question_group';
572
-        $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
570
+		$this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB');
571
+		$table_name = 'esp_question_group';
572
+		$sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
573 573
 				QSG_name varchar(255) NOT NULL,
574 574
 				QSG_identifier varchar(100) NOT NULL,
575 575
 				QSG_desc text NULL,
@@ -582,138 +582,138 @@  discard block
 block discarded – undo
582 582
 				PRIMARY KEY  (QSG_ID),
583 583
 				UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier),
584 584
 				KEY QSG_order (QSG_order)';
585
-        $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
-        /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
-        $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
-        //(because many need to convert old string states to foreign keys into the states table)
589
-        $script_4_1_defaults->insert_default_states();
590
-        $script_4_1_defaults->insert_default_countries();
591
-        /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
-        $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
-        $script_4_5_defaults->insert_default_price_types();
594
-        $script_4_5_defaults->insert_default_prices();
595
-        $script_4_5_defaults->insert_default_tickets();
596
-        /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
-        $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
-        $script_4_6_defaults->add_default_admin_only_payments();
599
-        $script_4_6_defaults->insert_default_currencies();
600
-        /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
-        $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
-        $script_4_8_defaults->verify_new_countries();
603
-        $script_4_8_defaults->verify_new_currencies();
604
-        $this->verify_db_collations();
605
-        $this->verify_db_collations_again();
606
-        return true;
607
-    }
585
+		$this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB');
586
+		/** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */
587
+		$script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0');
588
+		//(because many need to convert old string states to foreign keys into the states table)
589
+		$script_4_1_defaults->insert_default_states();
590
+		$script_4_1_defaults->insert_default_countries();
591
+		/** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */
592
+		$script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0');
593
+		$script_4_5_defaults->insert_default_price_types();
594
+		$script_4_5_defaults->insert_default_prices();
595
+		$script_4_5_defaults->insert_default_tickets();
596
+		/** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */
597
+		$script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0');
598
+		$script_4_6_defaults->add_default_admin_only_payments();
599
+		$script_4_6_defaults->insert_default_currencies();
600
+		/** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */
601
+		$script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0');
602
+		$script_4_8_defaults->verify_new_countries();
603
+		$script_4_8_defaults->verify_new_currencies();
604
+		$this->verify_db_collations();
605
+		$this->verify_db_collations_again();
606
+		return true;
607
+	}
608 608
 
609 609
 
610 610
 
611
-    /**
612
-     * @return boolean
613
-     */
614
-    public function schema_changes_after_migration()
615
-    {
616
-        return true;
617
-    }
611
+	/**
612
+	 * @return boolean
613
+	 */
614
+	public function schema_changes_after_migration()
615
+	{
616
+		return true;
617
+	}
618 618
 
619 619
 
620 620
 
621
-    public function migration_page_hooks()
622
-    {
623
-    }
621
+	public function migration_page_hooks()
622
+	{
623
+	}
624 624
 
625 625
 
626 626
 
627
-    /**
628
-     * Verify all EE4 models' tables use utf8mb4 collation
629
-     *
630
-     * @return void
631
-     */
632
-    public function verify_db_collations()
633
-    {
634
-        if (get_option('ee_verified_db_collations', false)) {
635
-            return;
636
-        }
637
-        // grab tables from each model
638
-        $tables_to_check = array();
639
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
-            if (method_exists($model_name, 'instance')) {
641
-                $model_obj = call_user_func(array($model_name, 'instance'));
642
-                if ($model_obj instanceof EEM_Base) {
643
-                    foreach ($model_obj->get_tables() as $table) {
644
-                        if (
645
-                            strpos($table->get_table_name(), 'esp_')
646
-                            && (is_main_site()//for main tables, verify global tables
647
-                                || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
-                            )
649
-                            && function_exists('maybe_convert_table_to_utf8mb4')
650
-                        ) {
651
-                            $tables_to_check[] = $table->get_table_name();
652
-                        }
653
-                    }
654
-                }
655
-            }
656
-        }
657
-        //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
-        //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
-        //of hard-coding this
660
-        $addon_tables = array(
661
-            //mailchimp
662
-            'esp_event_mailchimp_list_group',
663
-            'esp_event_question_mailchimp_field',
664
-            //multisite
665
-            'esp_blog_meta',
666
-            //people
667
-            'esp_people_to_post',
668
-            //promotions
669
-            'esp_promotion',
670
-            'esp_promotion_object',
671
-        );
672
-        foreach ($addon_tables as $table_name) {
673
-                $tables_to_check[] = $table_name;
674
-        }
675
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
-        //ok and now let's remember this was done (without needing to check the db schemas all over again)
677
-        add_option('ee_verified_db_collations', true, null, 'no');
678
-        //seeing how this ran with the fix from 10435, no need to check again
679
-        add_option('ee_verified_db_collations_again',true,null,'no');
680
-    }
627
+	/**
628
+	 * Verify all EE4 models' tables use utf8mb4 collation
629
+	 *
630
+	 * @return void
631
+	 */
632
+	public function verify_db_collations()
633
+	{
634
+		if (get_option('ee_verified_db_collations', false)) {
635
+			return;
636
+		}
637
+		// grab tables from each model
638
+		$tables_to_check = array();
639
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
640
+			if (method_exists($model_name, 'instance')) {
641
+				$model_obj = call_user_func(array($model_name, 'instance'));
642
+				if ($model_obj instanceof EEM_Base) {
643
+					foreach ($model_obj->get_tables() as $table) {
644
+						if (
645
+							strpos($table->get_table_name(), 'esp_')
646
+							&& (is_main_site()//for main tables, verify global tables
647
+								|| ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up)
648
+							)
649
+							&& function_exists('maybe_convert_table_to_utf8mb4')
650
+						) {
651
+							$tables_to_check[] = $table->get_table_name();
652
+						}
653
+					}
654
+				}
655
+			}
656
+		}
657
+		//and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active
658
+		//when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead
659
+		//of hard-coding this
660
+		$addon_tables = array(
661
+			//mailchimp
662
+			'esp_event_mailchimp_list_group',
663
+			'esp_event_question_mailchimp_field',
664
+			//multisite
665
+			'esp_blog_meta',
666
+			//people
667
+			'esp_people_to_post',
668
+			//promotions
669
+			'esp_promotion',
670
+			'esp_promotion_object',
671
+		);
672
+		foreach ($addon_tables as $table_name) {
673
+				$tables_to_check[] = $table_name;
674
+		}
675
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
676
+		//ok and now let's remember this was done (without needing to check the db schemas all over again)
677
+		add_option('ee_verified_db_collations', true, null, 'no');
678
+		//seeing how this ran with the fix from 10435, no need to check again
679
+		add_option('ee_verified_db_collations_again',true,null,'no');
680
+	}
681 681
 
682 682
 
683 683
 
684
-    /**
685
-     * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
-     * which meant some DB collations might not have been updated
687
-     * @return void
688
-     */
689
-    public function verify_db_collations_again(){
690
-        if (get_option('ee_verified_db_collations_again', false)) {
691
-            return;
692
-        }
693
-        $tables_to_check = array(
694
-            'esp_attendee_meta',
695
-            'esp_message'
696
-        );
697
-        $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
-        add_option('ee_verified_db_collations_again',true,null,'no');
699
-    }
684
+	/**
685
+	 * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435
686
+	 * which meant some DB collations might not have been updated
687
+	 * @return void
688
+	 */
689
+	public function verify_db_collations_again(){
690
+		if (get_option('ee_verified_db_collations_again', false)) {
691
+			return;
692
+		}
693
+		$tables_to_check = array(
694
+			'esp_attendee_meta',
695
+			'esp_message'
696
+		);
697
+		$this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
+		add_option('ee_verified_db_collations_again',true,null,'no');
699
+	}
700 700
 
701 701
 
702 702
 
703
-    /**
704
-     * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
-     * @param $tables_to_check
706
-     * @return boolean true if logic ran, false if it didn't
707
-     */
708
-    protected function _verify_db_collations_for_tables($tables_to_check)
709
-    {
710
-        foreach ($tables_to_check as $table_name) {
711
-            $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
-                && $this->_get_table_analysis()->tableExists($table_name)
714
-            ) {
715
-                maybe_convert_table_to_utf8mb4($table_name);
716
-            }
717
-        }
718
-    }
703
+	/**
704
+	 * Runs maybe_convert_table_to_utf8mb4 on the specified tables
705
+	 * @param $tables_to_check
706
+	 * @return boolean true if logic ran, false if it didn't
707
+	 */
708
+	protected function _verify_db_collations_for_tables($tables_to_check)
709
+	{
710
+		foreach ($tables_to_check as $table_name) {
711
+			$table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
+			if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
713
+				&& $this->_get_table_analysis()->tableExists($table_name)
714
+			) {
715
+				maybe_convert_table_to_utf8mb4($table_name);
716
+			}
717
+		}
718
+	}
719 719
 }
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 //unfortunately, this needs to be done upon INCLUSION of this file,
10 10
 //instead of construction, because it only gets constructed on first page load
11 11
 //(all other times it gets resurrected from a wordpress option)
12
-$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*');
12
+$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*');
13 13
 $class_to_filepath = array();
14 14
 foreach ($stages as $filepath) {
15 15
     $matches = array();
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         } elseif ( ! $version_string) {
68 68
             //			echo "no version string provided: $version_string";
69 69
             //no version string provided... this must be pre 4.3
70
-            return false;//changed mind. dont want people thinking they should migrate yet because they cant
70
+            return false; //changed mind. dont want people thinking they should migrate yet because they cant
71 71
         } else {
72 72
             //			echo "$version_string doesnt apply";
73 73
             return false;
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function schema_changes_before_migration()
83 83
     {
84
-        require_once(EE_HELPERS . 'EEH_Activation.helper.php');
84
+        require_once(EE_HELPERS.'EEH_Activation.helper.php');
85 85
         $now_in_mysql = current_time('mysql', true);
86 86
         $table_name = 'esp_answer';
87 87
         $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT,
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         //ok and now let's remember this was done (without needing to check the db schemas all over again)
677 677
         add_option('ee_verified_db_collations', true, null, 'no');
678 678
         //seeing how this ran with the fix from 10435, no need to check again
679
-        add_option('ee_verified_db_collations_again',true,null,'no');
679
+        add_option('ee_verified_db_collations_again', true, null, 'no');
680 680
     }
681 681
 
682 682
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
      * which meant some DB collations might not have been updated
687 687
      * @return void
688 688
      */
689
-    public function verify_db_collations_again(){
689
+    public function verify_db_collations_again() {
690 690
         if (get_option('ee_verified_db_collations_again', false)) {
691 691
             return;
692 692
         }
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
             'esp_message'
696 696
         );
697 697
         $this->_verify_db_collations_for_tables(array_unique($tables_to_check));
698
-        add_option('ee_verified_db_collations_again',true,null,'no');
698
+        add_option('ee_verified_db_collations_again', true, null, 'no');
699 699
     }
700 700
 
701 701
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
     {
710 710
         foreach ($tables_to_check as $table_name) {
711 711
             $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name);
712
-            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name )
712
+            if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name)
713 713
                 && $this->_get_table_analysis()->tableExists($table_name)
714 714
             ) {
715 715
                 maybe_convert_table_to_utf8mb4($table_name);
Please login to merge, or discard this patch.
core/services/database/TableManager.php 2 patches
Indentation   +243 added lines, -245 removed lines patch added patch discarded remove patch
@@ -17,253 +17,251 @@
 block discarded – undo
17 17
 class TableManager extends \EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var TableAnalysis $table_analysis
22
-     */
23
-    private $table_analysis;
24
-
25
-
26
-
27
-    /**
28
-     * TableManager constructor.
29
-     *
30
-     * @param TableAnalysis $TableAnalysis
31
-     */
32
-    public function __construct(TableAnalysis $TableAnalysis)
33
-    {
34
-        $this->table_analysis = $TableAnalysis;
35
-    }
36
-
37
-
38
-
39
-    /**
40
-     * Gets the injected table analyzer, or throws an exception
41
-     *
42
-     * @return TableAnalysis
43
-     * @throws \EE_Error
44
-     */
45
-    protected function getTableAnalysis()
46
-    {
47
-        if ($this->table_analysis instanceof TableAnalysis) {
48
-            return $this->table_analysis;
49
-        } else {
50
-            throw new \EE_Error(
51
-                sprintf(
52
-                    __('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
-                    get_class($this)
54
-                )
55
-            );
56
-        }
57
-    }
58
-
59
-
60
-
61
-    /**
62
-     * @param string $table_name which can optionally start with $wpdb->prefix or not
63
-     * @param string $column_name
64
-     * @param string $column_info
65
-     * @return bool|false|int
66
-     */
67
-    public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
-    {
69
-        if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
-            return false;
71
-        }
72
-        global $wpdb;
73
-        $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
-        $columns = $this->getTableColumns($table_name);
75
-        if ( ! in_array($column_name, $columns)) {
76
-            $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
-            return $wpdb->query($alter_query);
78
-        }
79
-        return true;
80
-    }
81
-
82
-
83
-
84
-    /**
85
-     * Gets the name of all columns on the  table. $table_name can
86
-     * optionally start with $wpdb->prefix or not
87
-     *
88
-     * @global \wpdb $wpdb
89
-     * @param string $table_name
90
-     * @return array
91
-     */
92
-    public function getTableColumns($table_name)
93
-    {
94
-        global $wpdb;
95
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
-        $field_array = array();
97
-        if ( ! empty($table_name)) {
98
-            $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
-            if ($columns !== false) {
100
-                foreach ($columns as $column) {
101
-                    $field_array[] = $column->Field;
102
-                }
103
-            }
104
-        }
105
-        return $field_array;
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Drops the specified table from the database. $table_name can
112
-     * optionally start with $wpdb->prefix or not
113
-     *
114
-     * @global \wpdb $wpdb
115
-     * @param string $table_name
116
-     * @return int
117
-     */
118
-    public function dropTable($table_name)
119
-    {
120
-        global $wpdb;
121
-        if ($this->getTableAnalysis()->tableExists($table_name)) {
122
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
-            return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
-        }
125
-        return 0;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
-     * each table name provided has a wpdb prefix attached, and that it exists.
133
-     * Returns the list actually deleted
134
-     *
135
-     * @global WPDB $wpdb
136
-     * @param array $table_names
137
-     * @return array of table names which we deleted
138
-     */
139
-    public function dropTables($table_names)
140
-    {
141
-        $tables_to_delete = array();
142
-        foreach ($table_names as $table_name) {
143
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
-            if ($this->getTableAnalysis()->tableExists($table_name)) {
145
-                $tables_to_delete[] = $table_name;
146
-            }
147
-        }
148
-        if( ! empty( $tables_to_delete ) ) {
149
-            global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
-        }
152
-        return $tables_to_delete;
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Drops the specified index from the specified table. $table_name can
159
-     * optionally start with $wpdb->prefix or not
160
-
161
-     *
20
+	/**
21
+	 * @var TableAnalysis $table_analysis
22
+	 */
23
+	private $table_analysis;
24
+
25
+
26
+
27
+	/**
28
+	 * TableManager constructor.
29
+	 *
30
+	 * @param TableAnalysis $TableAnalysis
31
+	 */
32
+	public function __construct(TableAnalysis $TableAnalysis)
33
+	{
34
+		$this->table_analysis = $TableAnalysis;
35
+	}
36
+
37
+
38
+
39
+	/**
40
+	 * Gets the injected table analyzer, or throws an exception
41
+	 *
42
+	 * @return TableAnalysis
43
+	 * @throws \EE_Error
44
+	 */
45
+	protected function getTableAnalysis()
46
+	{
47
+		if ($this->table_analysis instanceof TableAnalysis) {
48
+			return $this->table_analysis;
49
+		} else {
50
+			throw new \EE_Error(
51
+				sprintf(
52
+					__('Table analysis class on class %1$s is not set properly.', 'event_espresso'),
53
+					get_class($this)
54
+				)
55
+			);
56
+		}
57
+	}
58
+
59
+
60
+
61
+	/**
62
+	 * @param string $table_name which can optionally start with $wpdb->prefix or not
63
+	 * @param string $column_name
64
+	 * @param string $column_info
65
+	 * @return bool|false|int
66
+	 */
67
+	public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL')
68
+	{
69
+		if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) {
70
+			return false;
71
+		}
72
+		global $wpdb;
73
+		$full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
74
+		$columns = $this->getTableColumns($table_name);
75
+		if ( ! in_array($column_name, $columns)) {
76
+			$alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}";
77
+			return $wpdb->query($alter_query);
78
+		}
79
+		return true;
80
+	}
81
+
82
+
83
+
84
+	/**
85
+	 * Gets the name of all columns on the  table. $table_name can
86
+	 * optionally start with $wpdb->prefix or not
87
+	 *
88
+	 * @global \wpdb $wpdb
89
+	 * @param string $table_name
90
+	 * @return array
91
+	 */
92
+	public function getTableColumns($table_name)
93
+	{
94
+		global $wpdb;
95
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
96
+		$field_array = array();
97
+		if ( ! empty($table_name)) {
98
+			$columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} ");
99
+			if ($columns !== false) {
100
+				foreach ($columns as $column) {
101
+					$field_array[] = $column->Field;
102
+				}
103
+			}
104
+		}
105
+		return $field_array;
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Drops the specified table from the database. $table_name can
112
+	 * optionally start with $wpdb->prefix or not
113
+	 *
114
+	 * @global \wpdb $wpdb
115
+	 * @param string $table_name
116
+	 * @return int
117
+	 */
118
+	public function dropTable($table_name)
119
+	{
120
+		global $wpdb;
121
+		if ($this->getTableAnalysis()->tableExists($table_name)) {
122
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
123
+			return $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
124
+		}
125
+		return 0;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
132
+	 * each table name provided has a wpdb prefix attached, and that it exists.
133
+	 * Returns the list actually deleted
134
+	 *
135
+	 * @global WPDB $wpdb
136
+	 * @param array $table_names
137
+	 * @return array of table names which we deleted
138
+	 */
139
+	public function dropTables($table_names)
140
+	{
141
+		$tables_to_delete = array();
142
+		foreach ($table_names as $table_name) {
143
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
144
+			if ($this->getTableAnalysis()->tableExists($table_name)) {
145
+				$tables_to_delete[] = $table_name;
146
+			}
147
+		}
148
+		if( ! empty( $tables_to_delete ) ) {
149
+			global $wpdb;
150
+			$wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
151
+		}
152
+		return $tables_to_delete;
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Drops the specified index from the specified table. $table_name can
159
+	 * optionally start with $wpdb->prefix or not
160
+	 *
162 161
 *@global \wpdb       $wpdb
163
-     * @param string $table_name
164
-     * @param string $index_name
165
-     * @return int the number of indexes dropped. False if there was a datbase error
166
-     */
167
-    public function dropIndex($table_name, $index_name)
168
-    {
169
-        if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
170
-            return 0;
171
-        }
172
-        global $wpdb;
173
-        $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
174
-        $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
175
-        if (
176
-            $this->getTableAnalysis()->tableExists($table_name)
177
-            && $wpdb->get_var($index_exists_query)
178
-               === $table_name //using get_var with the $index_exists_query returns the table's name
179
-        ) {
180
-            return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
181
-        }
182
-        return 0;
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Just creates the requested table. $table_name can
189
-     * optionally start with $wpdb->prefix or not
190
-
191
-     *
162
+	 * @param string $table_name
163
+	 * @param string $index_name
164
+	 * @return int the number of indexes dropped. False if there was a datbase error
165
+	 */
166
+	public function dropIndex($table_name, $index_name)
167
+	{
168
+		if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) {
169
+			return 0;
170
+		}
171
+		global $wpdb;
172
+		$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
173
+		$index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'";
174
+		if (
175
+			$this->getTableAnalysis()->tableExists($table_name)
176
+			&& $wpdb->get_var($index_exists_query)
177
+			   === $table_name //using get_var with the $index_exists_query returns the table's name
178
+		) {
179
+			return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}");
180
+		}
181
+		return 0;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Just creates the requested table. $table_name can
188
+	 * optionally start with $wpdb->prefix or not
189
+	 *
192 190
 *@param string       $table_name
193
-     * @param string $create_sql defining the table's columns and indexes
194
-     * @param string $engine     (no need to specify "ENGINE=", that's implied)
195
-     * @return void
196
-     * @throws \EE_Error
197
-     */
198
-    public function createTable($table_name, $create_sql, $engine = 'MyISAM')
199
-    {
200
-        // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
201
-        if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
202
-            $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203
-            /** @var \wpdb $wpdb */
204
-            global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
206
-
207
-            //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208
-            //happened. And then we can choose to tell the end user
209
-            $old_show_errors_policy = $wpdb->show_errors(true);
210
-            $old_error_suppression_policy = $wpdb->suppress_errors(false);
211
-            ob_start();
212
-            dbDelta($SQL);
213
-            $output = ob_get_contents();
214
-            ob_end_clean();
215
-            $wpdb->show_errors($old_show_errors_policy);
216
-            $wpdb->suppress_errors($old_error_suppression_policy);
217
-            if ( ! empty($output)) {
218
-                throw new \EE_Error($output);
219
-            }
220
-        } else {
221
-            throw new \EE_Error(
222
-                sprintf(
223
-                    __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
224
-                        'event_espresso'),
225
-                    '<br />',
226
-                    $create_sql
227
-                )
228
-            );
229
-        }
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * Drops the specified index if it's size differs from $desired_index_size.
236
-     * WordPress' dbdelta method doesn't automatically change index sizes, so this
237
-     * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
238
-     * If the table doesn't exist, or it exists but the index does not, or returns false
239
-     *
191
+	 * @param string $create_sql defining the table's columns and indexes
192
+	 * @param string $engine     (no need to specify "ENGINE=", that's implied)
193
+	 * @return void
194
+	 * @throws \EE_Error
195
+	 */
196
+	public function createTable($table_name, $create_sql, $engine = 'MyISAM')
197
+	{
198
+		// does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns )
199
+		if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) {
200
+			$table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
201
+			/** @var \wpdb $wpdb */
202
+			global $wpdb;
203
+			$SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
204
+
205
+			//get $wpdb to echo errors, but buffer them. This way at least WE know an error
206
+			//happened. And then we can choose to tell the end user
207
+			$old_show_errors_policy = $wpdb->show_errors(true);
208
+			$old_error_suppression_policy = $wpdb->suppress_errors(false);
209
+			ob_start();
210
+			dbDelta($SQL);
211
+			$output = ob_get_contents();
212
+			ob_end_clean();
213
+			$wpdb->show_errors($old_show_errors_policy);
214
+			$wpdb->suppress_errors($old_error_suppression_policy);
215
+			if ( ! empty($output)) {
216
+				throw new \EE_Error($output);
217
+			}
218
+		} else {
219
+			throw new \EE_Error(
220
+				sprintf(
221
+					__('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s',
222
+						'event_espresso'),
223
+					'<br />',
224
+					$create_sql
225
+				)
226
+			);
227
+		}
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * Drops the specified index if it's size differs from $desired_index_size.
234
+	 * WordPress' dbdelta method doesn't automatically change index sizes, so this
235
+	 * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal.
236
+	 * If the table doesn't exist, or it exists but the index does not, or returns false
237
+	 *
240 238
 *@param string $table_name
241
-     * @param string $index_name
242
-     * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
243
-     * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
244
-     *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
245
-     * @return bool whether an index was dropped or not
246
-     * @throws /EE_Error if table analysis object isn't defined
247
-     */
248
-    public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
249
-    {
250
-        if($column_name === null){
251
-            $column_name = $index_name;
252
-        }
253
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
254
-            return false;
255
-        }
256
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
257
-        if(empty($index_entries)){
258
-            return false;
259
-        }
260
-        foreach($index_entries as $index_entry){
261
-            if( $column_name === $index_entry->Column_name
262
-                && (string)$desired_index_size !== $index_entry->Sub_part){
263
-                return $this->dropIndex($table_name,$index_name);
264
-            }
265
-        }
266
-        return false;
267
-    }
239
+	 * @param string $index_name
240
+	 * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE)
241
+	 * @param string|int $desired_index_size defaults to 191, the max for utf8mb4.
242
+	 *                   See https://events.codebasehq.com/redirect?https://make.wordpress.org/core/2015/04/02/the-utf8mb4-upgrade/
243
+	 * @return bool whether an index was dropped or not
244
+	 * @throws /EE_Error if table analysis object isn't defined
245
+	 */
246
+	public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
247
+	{
248
+		if($column_name === null){
249
+			$column_name = $index_name;
250
+		}
251
+		if(!$this->getTableAnalysis()->tableExists($table_name)){
252
+			return false;
253
+		}
254
+		$index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
255
+		if(empty($index_entries)){
256
+			return false;
257
+		}
258
+		foreach($index_entries as $index_entry){
259
+			if( $column_name === $index_entry->Column_name
260
+				&& (string)$desired_index_size !== $index_entry->Sub_part){
261
+				return $this->dropIndex($table_name,$index_name);
262
+			}
263
+		}
264
+		return false;
265
+	}
268 266
 
269 267
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -145,9 +145,9 @@  discard block
 block discarded – undo
145 145
                 $tables_to_delete[] = $table_name;
146 146
             }
147 147
         }
148
-        if( ! empty( $tables_to_delete ) ) {
148
+        if ( ! empty($tables_to_delete)) {
149 149
             global $wpdb;
150
-            $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete));
150
+            $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete));
151 151
         }
152 152
         return $tables_to_delete;
153 153
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name);
203 203
             /** @var \wpdb $wpdb */
204 204
             global $wpdb;
205
-            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate();
205
+            $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate();
206 206
 
207 207
             //get $wpdb to echo errors, but buffer them. This way at least WE know an error
208 208
             //happened. And then we can choose to tell the end user
@@ -247,20 +247,20 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = 191)
249 249
     {
250
-        if($column_name === null){
250
+        if ($column_name === null) {
251 251
             $column_name = $index_name;
252 252
         }
253
-        if(!$this->getTableAnalysis()->tableExists($table_name)){
253
+        if ( ! $this->getTableAnalysis()->tableExists($table_name)) {
254 254
             return false;
255 255
         }
256
-        $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name);
257
-        if(empty($index_entries)){
256
+        $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name);
257
+        if (empty($index_entries)) {
258 258
             return false;
259 259
         }
260
-        foreach($index_entries as $index_entry){
261
-            if( $column_name === $index_entry->Column_name
262
-                && (string)$desired_index_size !== $index_entry->Sub_part){
263
-                return $this->dropIndex($table_name,$index_name);
260
+        foreach ($index_entries as $index_entry) {
261
+            if ($column_name === $index_entry->Column_name
262
+                && (string) $desired_index_size !== $index_entry->Sub_part) {
263
+                return $this->dropIndex($table_name, $index_name);
264 264
             }
265 265
         }
266 266
         return false;
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 1 patch
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
  * @since		 	   4.8.30.rc.007
18 18
  *
19 19
  */
20
-if( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
21
-	exit( 'No direct script access allowed' );
20
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
21
+	exit('No direct script access allowed');
22 22
 }
23 23
 
24
-define( 'BATCH_URL', plugin_dir_url( __FILE__ ) );
24
+define('BATCH_URL', plugin_dir_url(__FILE__));
25 25
 
26
-class EED_Batch extends EED_Module{
26
+class EED_Batch extends EED_Module {
27 27
 	
28 28
 	/**
29 29
 	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
 	public static function set_hooks() {
71 71
 		//because this is a possibel attack vector, let's have this disabled until 
72 72
 		//we at least have a real use for it on the frontend
73
-		if( apply_filters( 'FHEE__EED_Batch__set_hooks__enable_frontend_batch', false ) ) {
74
-			add_action( 'wp_enqueue_scripts', array( self::instance(), 'enqueue_scripts' ) );
75
-			add_filter( 'template_include', array( self::instance(), 'override_template' ), 99 );
73
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
74
+			add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
75
+			add_filter('template_include', array(self::instance(), 'override_template'), 99);
76 76
 		}
77 77
 	}
78 78
 	
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
 	 * Initializes some hooks for the admin in order to run batch jobs
81 81
 	 */
82 82
 	public static function set_hooks_admin() {
83
-		add_action( 'admin_menu', array( self::instance(), 'register_admin_pages' ) );
84
-		add_action( 'admin_enqueue_scripts', array( self::instance(), 'enqueue_scripts' ) );
83
+		add_action('admin_menu', array(self::instance(), 'register_admin_pages'));
84
+		add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts'));
85 85
 		
86 86
 		//ajax
87
-		add_action('wp_ajax_espresso_batch_continue',array(self::instance(),'batch_continue'));
88
-		add_action('wp_ajax_espresso_batch_cleanup',array(self::instance(),'batch_cleanup'));
89
-		add_action('wp_ajax_nopriv_espresso_batch_continue',array(self::instance(),'batch_continue'));
90
-		add_action('wp_ajax_nopriv_espresso_batch_cleanup',array(self::instance(),'batch_cleanup'));
87
+		add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue'));
88
+		add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
89
+		add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue'));
90
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup'));
91 91
 	}
92 92
 	
93 93
 	/**
94 94
 	 * Enqueues batch scripts on the frontend or admin, and creates a job
95 95
 	 */
96 96
 	public function enqueue_scripts() { 
97
-		if( isset( $_REQUEST[ 'espresso_batch' ] ) 
97
+		if (isset($_REQUEST['espresso_batch']) 
98 98
 			|| 
99 99
 			( 
100
-				isset( $_REQUEST[ 'page' ] )
101
-				&& $_REQUEST[ 'page' ] == 'espresso_batch'
100
+				isset($_REQUEST['page'])
101
+				&& $_REQUEST['page'] == 'espresso_batch'
102 102
 			) 
103 103
 		) { 
104
-			switch( $this->batch_request_type() ) {
104
+			switch ($this->batch_request_type()) {
105 105
 				case self::batch_job:
106 106
 					$this->enqueue_scripts_styles_batch_create();
107 107
 					break;
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function enqueue_scripts_styles_batch_create() {	
119 119
 		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
120
-		wp_enqueue_script( 'batch_runner_init', BATCH_URL . 'assets/batch_runner_init.js', array( 'batch_runner' ), EVENT_ESPRESSO_VERSION, true );
121
-		wp_localize_script( 'batch_runner_init', 'ee_job_response', $job_response->to_array() );
122
-		wp_localize_script( 'batch_runner_init', 'ee_job_i18n', 
120
+		wp_enqueue_script('batch_runner_init', BATCH_URL.'assets/batch_runner_init.js', array('batch_runner'), EVENT_ESPRESSO_VERSION, true);
121
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
122
+		wp_localize_script('batch_runner_init', 'ee_job_i18n', 
123 123
 			array(
124
-				'return_url' => $_REQUEST['return_url' ],
124
+				'return_url' => $_REQUEST['return_url'],
125 125
 			));
126 126
 	}
127 127
 	
@@ -131,15 +131,15 @@  discard block
 block discarded – undo
131 131
 	public function enqueue_scripts_styles_batch_file_create() {
132 132
 		//creates a job based on the request variable
133 133
 		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
134
-		wp_enqueue_script( 'batch_file_runner_init', BATCH_URL . 'assets/batch_file_runner_init.js', array( 'batch_runner' ), EVENT_ESPRESSO_VERSION, true );
135
-		wp_localize_script( 'batch_file_runner_init', 'ee_job_response', $job_response->to_array() );
136
-		wp_localize_script( 'batch_file_runner_init', 'ee_job_i18n', 
134
+		wp_enqueue_script('batch_file_runner_init', BATCH_URL.'assets/batch_file_runner_init.js', array('batch_runner'), EVENT_ESPRESSO_VERSION, true);
135
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
136
+		wp_localize_script('batch_file_runner_init', 'ee_job_i18n', 
137 137
 				array(
138 138
 					'download_and_redirecting' => sprintf( 
139 139
 							__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'),
140
-							'<a href="' . $_REQUEST['return_url' ] .'">',
140
+							'<a href="'.$_REQUEST['return_url'].'">',
141 141
 							'</a>' ),
142
-					'return_url' => $_REQUEST['return_url' ],
142
+					'return_url' => $_REQUEST['return_url'],
143 143
 				));
144 144
 	}
145 145
 	
@@ -150,26 +150,26 @@  discard block
 block discarded – undo
150 150
 	 * @return \EventEspressoBatchRequest\Helpers\JobStepResponse
151 151
 	 */
152 152
 	protected function _enqueue_batch_job_scripts_and_styles_and_start_job() {
153
-		wp_register_script( 'progress_bar', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', array( 'jquery' ) );
154
-		wp_enqueue_style( 'progress_bar', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', array(), EVENT_ESPRESSO_VERSION );
155
-		wp_enqueue_script( 'batch_runner', EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', array( 'progress_bar' ));
153
+		wp_register_script('progress_bar', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', array('jquery'));
154
+		wp_enqueue_style('progress_bar', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', array(), EVENT_ESPRESSO_VERSION);
155
+		wp_enqueue_script('batch_runner', EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', array('progress_bar'));
156 156
 		//just copy the bits of EE admin's eei18n that we need in the JS
157 157
 		wp_localize_script(
158 158
 		    'batch_runner',
159 159
             'eei18n',
160 160
             array(
161 161
                 'ajax_url' => WP_AJAX_URL,
162
-                'is_admin' => (bool)is_admin(),
162
+                'is_admin' => (bool) is_admin(),
163 163
                 'error_message' => esc_html__('An error occurred and the job has been stopped.', 'event_espresso')
164 164
             )
165 165
         );
166
-		$job_handler_classname = stripslashes( $_GET[ 'job_handler' ] );
166
+		$job_handler_classname = stripslashes($_GET['job_handler']);
167 167
 		$request_data = array_diff_key( 
168 168
 				$_REQUEST, 
169
-				array_flip( array( 'action',  'page', 'ee', 'batch' ) ) );
169
+				array_flip(array('action', 'page', 'ee', 'batch')) );
170 170
 		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
171 171
 		//eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
172
-		$job_response = $batch_runner->create_job( $job_handler_classname, $request_data );
172
+		$job_response = $batch_runner->create_job($job_handler_classname, $request_data);
173 173
 		//remember the response for later. We need it to display the page body
174 174
 		$this->_job_step_response = $job_response;
175 175
 		return $job_response;
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 	 * @param string $template
181 181
 	 * @return string
182 182
 	 */
183
-	public function override_template( $template ) {
184
-		if( isset( $_REQUEST[ 'espresso_batch' ] ) && isset( $_REQUEST[ 'batch' ] ) ) {
185
-			return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html';
183
+	public function override_template($template) {
184
+		if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) {
185
+			return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html';
186 186
 		}
187 187
 		return $template;
188 188
 	}
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 	public function register_admin_pages() {
194 194
 		add_submenu_page( 
195 195
 			'', //parent slug. we don't want this to actually appear in the menu
196
-			__( 'Batch Job', 'event_espresso' ), //page title
196
+			__('Batch Job', 'event_espresso'), //page title
197 197
 			'n/a', //menu title
198 198
 			'read', //we want this page to actually be accessible to anyone,  
199 199
 			'espresso_batch', //menu slug
200
-			array( self::instance(), 'show_admin_page' )
200
+			array(self::instance(), 'show_admin_page')
201 201
 		);
202 202
 	}
203 203
 	
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public function show_admin_page() { 
209 209
 		echo EEH_Template::locate_template( 
210
-			EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', 
211
-			array( 'batch_request_type' => $this->batch_request_type() )
210
+			EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', 
211
+			array('batch_request_type' => $this->batch_request_type())
212 212
 		);
213 213
 	}
214 214
 	
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
 	 * Receives ajax calls for continuing a job
217 217
 	 */
218 218
 	public function batch_continue() {
219
-		$job_id = sanitize_text_field( $_REQUEST[ 'job_id' ] );
219
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
220 220
 		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
221
-		$response_obj = $batch_runner->continue_job( $job_id);
222
-		$this->_return_json( $response_obj->to_array() );
221
+		$response_obj = $batch_runner->continue_job($job_id);
222
+		$this->_return_json($response_obj->to_array());
223 223
 	}
224 224
 	
225 225
 	/**
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
 	 * @return type
228 228
 	 */
229 229
 	public function batch_cleanup() {
230
-		$job_id = sanitize_text_field( $_REQUEST[ 'job_id' ] );
230
+		$job_id = sanitize_text_field($_REQUEST['job_id']);
231 231
 		$batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
232
-		$response_obj = $batch_runner->cleanup_job( $job_id );
233
-		$this->_return_json( $response_obj->to_array() );
232
+		$response_obj = $batch_runner->cleanup_job($job_id);
233
+		$this->_return_json($response_obj->to_array());
234 234
 	}
235 235
 	
236 236
 	
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 	 *	'isEEajax' => true,//indicates this is a response from EE
247 247
 	 * )
248 248
 	 */
249
-	protected function _return_json( $data ) {
249
+	protected function _return_json($data) {
250 250
 		$json = array(
251 251
 			'notices' => EE_Error::get_notices(),
252 252
 			'data' => $data,
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
 
256 256
 
257 257
 		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
258
-		if ( NULL === error_get_last() || ! headers_sent() ) {
258
+		if (NULL === error_get_last() || ! headers_sent()) {
259 259
 			header('Content-Type: application/json; charset=UTF-8');
260 260
 		}
261
-        echo wp_json_encode( $json );
261
+        echo wp_json_encode($json);
262 262
 		exit();
263 263
 	}
264 264
 	
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
275 275
 	 */
276 276
 	public function batch_request_type() {
277
-		if( $this->_batch_request_type === null ) {
278
-			if( isset( $_GET[ 'batch' ] ) ) {
279
-				if( $_GET[ 'batch' ] == self::batch_job ) {
277
+		if ($this->_batch_request_type === null) {
278
+			if (isset($_GET['batch'])) {
279
+				if ($_GET['batch'] == self::batch_job) {
280 280
 					$this->_batch_request_type = self::batch_job;
281
-				} elseif( $_GET[ 'batch' ] == self::batch_file_job ) {
281
+				} elseif ($_GET['batch'] == self::batch_file_job) {
282 282
 					$this->_batch_request_type = self::batch_file_job;
283 283
 				}
284 284
 			}
285 285
 			//if we didn't find that it was a batch request, indicate it wasn't
286
-			if( $this->_batch_request_type === null ) {
286
+			if ($this->_batch_request_type === null) {
287 287
 				$this->_batch_request_type = self::batch_not_job;
288 288
 			}
289 289
 		}
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 * Unnecessary
295 295
 	 * @param type $WP
296 296
 	 */
297
-	public function run( $WP ) {
297
+	public function run($WP) {
298 298
 		
299 299
 	}
300 300
 
Please login to merge, or discard this patch.