@@ -20,1143 +20,1143 @@ |
||
| 20 | 20 | class EE_Dependency_Map |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * This means that the requested class dependency is not present in the dependency map |
|
| 25 | - */ |
|
| 26 | - const not_registered = 0; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | - */ |
|
| 31 | - const load_new_object = 1; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | - */ |
|
| 37 | - const load_from_cache = 2; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * When registering a dependency, |
|
| 41 | - * this indicates to keep any existing dependencies that already exist, |
|
| 42 | - * and simply discard any new dependencies declared in the incoming data |
|
| 43 | - */ |
|
| 44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * When registering a dependency, |
|
| 48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | - */ |
|
| 50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @type EE_Dependency_Map $_instance |
|
| 55 | - */ |
|
| 56 | - protected static $_instance; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var ClassInterfaceCache $class_cache |
|
| 60 | - */ |
|
| 61 | - private $class_cache; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @type RequestInterface $request |
|
| 65 | - */ |
|
| 66 | - protected $request; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @type LegacyRequestInterface $legacy_request |
|
| 70 | - */ |
|
| 71 | - protected $legacy_request; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @type ResponseInterface $response |
|
| 75 | - */ |
|
| 76 | - protected $response; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @type LoaderInterface $loader |
|
| 80 | - */ |
|
| 81 | - protected $loader; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @type array $_dependency_map |
|
| 85 | - */ |
|
| 86 | - protected $_dependency_map = array(); |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @type array $_class_loaders |
|
| 90 | - */ |
|
| 91 | - protected $_class_loaders = array(); |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * EE_Dependency_Map constructor. |
|
| 96 | - * |
|
| 97 | - * @param ClassInterfaceCache $class_cache |
|
| 98 | - */ |
|
| 99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | - { |
|
| 101 | - $this->class_cache = $class_cache; |
|
| 102 | - do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return void |
|
| 108 | - */ |
|
| 109 | - public function initialize() |
|
| 110 | - { |
|
| 111 | - $this->_register_core_dependencies(); |
|
| 112 | - $this->_register_core_class_loaders(); |
|
| 113 | - $this->_register_core_aliases(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @singleton method used to instantiate class object |
|
| 119 | - * @param ClassInterfaceCache|null $class_cache |
|
| 120 | - * @return EE_Dependency_Map |
|
| 121 | - */ |
|
| 122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 123 | - { |
|
| 124 | - // check if class object is instantiated, and instantiated properly |
|
| 125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
| 126 | - && $class_cache instanceof ClassInterfaceCache |
|
| 127 | - ) { |
|
| 128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
| 129 | - } |
|
| 130 | - return self::$_instance; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param RequestInterface $request |
|
| 136 | - */ |
|
| 137 | - public function setRequest(RequestInterface $request) |
|
| 138 | - { |
|
| 139 | - $this->request = $request; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param LegacyRequestInterface $legacy_request |
|
| 145 | - */ |
|
| 146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 147 | - { |
|
| 148 | - $this->legacy_request = $legacy_request; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param ResponseInterface $response |
|
| 154 | - */ |
|
| 155 | - public function setResponse(ResponseInterface $response) |
|
| 156 | - { |
|
| 157 | - $this->response = $response; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @param LoaderInterface $loader |
|
| 163 | - */ |
|
| 164 | - public function setLoader(LoaderInterface $loader) |
|
| 165 | - { |
|
| 166 | - $this->loader = $loader; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $class |
|
| 172 | - * @param array $dependencies |
|
| 173 | - * @param int $overwrite |
|
| 174 | - * @return bool |
|
| 175 | - */ |
|
| 176 | - public static function register_dependencies( |
|
| 177 | - $class, |
|
| 178 | - array $dependencies, |
|
| 179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 180 | - ) { |
|
| 181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 187 | - * to the class specified by the first parameter. |
|
| 188 | - * IMPORTANT !!! |
|
| 189 | - * The order of elements in the incoming $dependencies array MUST match |
|
| 190 | - * the order of the constructor parameters for the class in question. |
|
| 191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
| 192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 193 | - * |
|
| 194 | - * @param string $class |
|
| 195 | - * @param array $dependencies |
|
| 196 | - * @param int $overwrite |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function registerDependencies( |
|
| 200 | - $class, |
|
| 201 | - array $dependencies, |
|
| 202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 203 | - ) { |
|
| 204 | - $class = trim($class, '\\'); |
|
| 205 | - $registered = false; |
|
| 206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
| 208 | - } |
|
| 209 | - // we need to make sure that any aliases used when registering a dependency |
|
| 210 | - // get resolved to the correct class name |
|
| 211 | - foreach ($dependencies as $dependency => $load_source) { |
|
| 212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
| 213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 215 | - ) { |
|
| 216 | - unset($dependencies[ $dependency ]); |
|
| 217 | - $dependencies[ $alias ] = $load_source; |
|
| 218 | - $registered = true; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - // now add our two lists of dependencies together. |
|
| 222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
| 223 | - // so $dependencies is NOT overwritten because it is listed first |
|
| 224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 225 | - // Union is way faster than array_merge() but should be used with caution... |
|
| 226 | - // especially with numerically indexed arrays |
|
| 227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 228 | - // now we need to ensure that the resulting dependencies |
|
| 229 | - // array only has the entries that are required for the class |
|
| 230 | - // so first count how many dependencies were originally registered for the class |
|
| 231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
| 233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 234 | - // then truncate the final array to match that count |
|
| 235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
| 236 | - // otherwise just take the incoming array because nothing previously existed |
|
| 237 | - : $dependencies; |
|
| 238 | - return $registered; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string $class_name |
|
| 244 | - * @param string $loader |
|
| 245 | - * @return bool |
|
| 246 | - * @throws DomainException |
|
| 247 | - */ |
|
| 248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 249 | - { |
|
| 250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 251 | - throw new DomainException( |
|
| 252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 253 | - ); |
|
| 254 | - } |
|
| 255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 256 | - if (! is_callable($loader) |
|
| 257 | - && ( |
|
| 258 | - strpos($loader, 'load_') !== 0 |
|
| 259 | - || ! method_exists('EE_Registry', $loader) |
|
| 260 | - ) |
|
| 261 | - ) { |
|
| 262 | - throw new DomainException( |
|
| 263 | - sprintf( |
|
| 264 | - esc_html__( |
|
| 265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 266 | - 'event_espresso' |
|
| 267 | - ), |
|
| 268 | - $loader |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
| 273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
| 274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 275 | - return true; |
|
| 276 | - } |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return array |
|
| 283 | - */ |
|
| 284 | - public function dependency_map() |
|
| 285 | - { |
|
| 286 | - return $this->_dependency_map; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
| 292 | - * |
|
| 293 | - * @param string $class_name |
|
| 294 | - * @return boolean |
|
| 295 | - */ |
|
| 296 | - public function has($class_name = '') |
|
| 297 | - { |
|
| 298 | - // all legacy models have the same dependencies |
|
| 299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 300 | - $class_name = 'LEGACY_MODELS'; |
|
| 301 | - } |
|
| 302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 308 | - * |
|
| 309 | - * @param string $class_name |
|
| 310 | - * @param string $dependency |
|
| 311 | - * @return bool |
|
| 312 | - */ |
|
| 313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 314 | - { |
|
| 315 | - // all legacy models have the same dependencies |
|
| 316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | - $class_name = 'LEGACY_MODELS'; |
|
| 318 | - } |
|
| 319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
| 321 | - ? true |
|
| 322 | - : false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 328 | - * |
|
| 329 | - * @param string $class_name |
|
| 330 | - * @param string $dependency |
|
| 331 | - * @return int |
|
| 332 | - */ |
|
| 333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 334 | - { |
|
| 335 | - // all legacy models have the same dependencies |
|
| 336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | - $class_name = 'LEGACY_MODELS'; |
|
| 338 | - } |
|
| 339 | - $dependency = $this->getFqnForAlias($dependency); |
|
| 340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
| 341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 342 | - : EE_Dependency_Map::not_registered; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param string $class_name |
|
| 348 | - * @return string | Closure |
|
| 349 | - */ |
|
| 350 | - public function class_loader($class_name) |
|
| 351 | - { |
|
| 352 | - // all legacy models use load_model() |
|
| 353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
| 354 | - return 'load_model'; |
|
| 355 | - } |
|
| 356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
| 358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
| 359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 360 | - ) { |
|
| 361 | - return 'load_core'; |
|
| 362 | - } |
|
| 363 | - $class_name = $this->getFqnForAlias($class_name); |
|
| 364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @return array |
|
| 370 | - */ |
|
| 371 | - public function class_loaders() |
|
| 372 | - { |
|
| 373 | - return $this->_class_loaders; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * adds an alias for a classname |
|
| 379 | - * |
|
| 380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 383 | - */ |
|
| 384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
| 385 | - { |
|
| 386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
| 392 | - * WHY? |
|
| 393 | - * Because if a class is type hinting for a concretion, |
|
| 394 | - * then why would we need to find another class to supply it? |
|
| 395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 397 | - * Don't go looking for some substitute. |
|
| 398 | - * Whereas if a class is type hinting for an interface... |
|
| 399 | - * then we need to find an actual class to use. |
|
| 400 | - * So the interface IS the alias for some other FQN, |
|
| 401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 402 | - * represents some other class. |
|
| 403 | - * |
|
| 404 | - * @param string $fqn |
|
| 405 | - * @param string $for_class |
|
| 406 | - * @return bool |
|
| 407 | - */ |
|
| 408 | - public function isAlias($fqn = '', $for_class = '') |
|
| 409 | - { |
|
| 410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 417 | - * for example: |
|
| 418 | - * if the following two entries were added to the _aliases array: |
|
| 419 | - * array( |
|
| 420 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 422 | - * ) |
|
| 423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 424 | - * to load an instance of 'some\namespace\classname' |
|
| 425 | - * |
|
| 426 | - * @param string $alias |
|
| 427 | - * @param string $for_class |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
| 431 | - { |
|
| 432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 439 | - * This is done by using the following class constants: |
|
| 440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 442 | - */ |
|
| 443 | - protected function _register_core_dependencies() |
|
| 444 | - { |
|
| 445 | - $this->_dependency_map = array( |
|
| 446 | - 'EE_Request_Handler' => array( |
|
| 447 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 448 | - ), |
|
| 449 | - 'EE_System' => array( |
|
| 450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 454 | - ), |
|
| 455 | - 'EE_Session' => array( |
|
| 456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
| 460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 461 | - ), |
|
| 462 | - 'EE_Cart' => array( |
|
| 463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 464 | - ), |
|
| 465 | - 'EE_Front_Controller' => array( |
|
| 466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 467 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 469 | - ), |
|
| 470 | - 'EE_Messenger_Collection_Loader' => array( |
|
| 471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 472 | - ), |
|
| 473 | - 'EE_Message_Type_Collection_Loader' => array( |
|
| 474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 475 | - ), |
|
| 476 | - 'EE_Message_Resource_Manager' => array( |
|
| 477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 480 | - ), |
|
| 481 | - 'EE_Message_Factory' => array( |
|
| 482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 483 | - ), |
|
| 484 | - 'EE_messages' => array( |
|
| 485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | - ), |
|
| 487 | - 'EE_Messages_Generator' => array( |
|
| 488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 492 | - ), |
|
| 493 | - 'EE_Messages_Processor' => array( |
|
| 494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 495 | - ), |
|
| 496 | - 'EE_Messages_Queue' => array( |
|
| 497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 498 | - ), |
|
| 499 | - 'EE_Messages_Template_Defaults' => array( |
|
| 500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 502 | - ), |
|
| 503 | - 'EE_Message_To_Generate_From_Request' => array( |
|
| 504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 505 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 506 | - ), |
|
| 507 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | - ), |
|
| 510 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 513 | - ), |
|
| 514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 516 | - ), |
|
| 517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 520 | - ), |
|
| 521 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 523 | - ), |
|
| 524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 526 | - ), |
|
| 527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 529 | - ), |
|
| 530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 532 | - ), |
|
| 533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | - ), |
|
| 536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | - ), |
|
| 539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | - ), |
|
| 542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | - ), |
|
| 545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | - ), |
|
| 548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 550 | - ), |
|
| 551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | - ), |
|
| 554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | - ), |
|
| 557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 559 | - ), |
|
| 560 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
| 561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 562 | - ), |
|
| 563 | - 'EE_Data_Migration_Class_Base' => array( |
|
| 564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 566 | - ), |
|
| 567 | - 'EE_DMS_Core_4_1_0' => array( |
|
| 568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 570 | - ), |
|
| 571 | - 'EE_DMS_Core_4_2_0' => array( |
|
| 572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 574 | - ), |
|
| 575 | - 'EE_DMS_Core_4_3_0' => array( |
|
| 576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 578 | - ), |
|
| 579 | - 'EE_DMS_Core_4_4_0' => array( |
|
| 580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | - ), |
|
| 583 | - 'EE_DMS_Core_4_5_0' => array( |
|
| 584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 586 | - ), |
|
| 587 | - 'EE_DMS_Core_4_6_0' => array( |
|
| 588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 590 | - ), |
|
| 591 | - 'EE_DMS_Core_4_7_0' => array( |
|
| 592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | - ), |
|
| 595 | - 'EE_DMS_Core_4_8_0' => array( |
|
| 596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 598 | - ), |
|
| 599 | - 'EE_DMS_Core_4_9_0' => array( |
|
| 600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 602 | - ), |
|
| 603 | - 'EE_DMS_Core_4_10_0' => array( |
|
| 604 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 605 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 607 | - ), |
|
| 608 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
| 609 | - null, |
|
| 610 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 611 | - ), |
|
| 612 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
| 613 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 614 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
| 615 | - ), |
|
| 616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | - ), |
|
| 619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 621 | - ), |
|
| 622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 624 | - ), |
|
| 625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | - ), |
|
| 628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 630 | - ), |
|
| 631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 633 | - ), |
|
| 634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 636 | - ), |
|
| 637 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 639 | - ), |
|
| 640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 641 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 642 | - ), |
|
| 643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 644 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 645 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 646 | - ), |
|
| 647 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 648 | - null, |
|
| 649 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 650 | - ), |
|
| 651 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 652 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 653 | - ), |
|
| 654 | - 'LEGACY_MODELS' => array( |
|
| 655 | - null, |
|
| 656 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 657 | - ), |
|
| 658 | - 'EE_Module_Request_Router' => array( |
|
| 659 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 660 | - ), |
|
| 661 | - 'EE_Registration_Processor' => array( |
|
| 662 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 663 | - ), |
|
| 664 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 665 | - null, |
|
| 666 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 667 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 668 | - ), |
|
| 669 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 670 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 671 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 672 | - ), |
|
| 673 | - 'EE_Admin_Transactions_List_Table' => array( |
|
| 674 | - null, |
|
| 675 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 676 | - ), |
|
| 677 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 678 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 679 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
| 681 | - ), |
|
| 682 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 683 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 684 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 685 | - ), |
|
| 686 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 687 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 688 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 689 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 690 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 691 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 692 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 693 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | - ), |
|
| 695 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 696 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 697 | - ), |
|
| 698 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 699 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 700 | - ), |
|
| 701 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 702 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 703 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 704 | - ), |
|
| 705 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 706 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 707 | - ), |
|
| 708 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 709 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 710 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 711 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 712 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 713 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 714 | - ), |
|
| 715 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 716 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 717 | - ), |
|
| 718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
| 719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 721 | - ), |
|
| 722 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
| 723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 724 | - ), |
|
| 725 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
| 726 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 727 | - ), |
|
| 728 | - 'EE_CPT_Strategy' => array( |
|
| 729 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 731 | - ), |
|
| 732 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
| 733 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 734 | - ), |
|
| 735 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
| 736 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 737 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 738 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 739 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 740 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 741 | - ), |
|
| 742 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
| 743 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 744 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
| 745 | - ), |
|
| 746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
| 747 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 748 | - ), |
|
| 749 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
| 750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 751 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
| 752 | - ), |
|
| 753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
| 754 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
| 755 | - ), |
|
| 756 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
| 757 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 758 | - ), |
|
| 759 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
| 760 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 761 | - ), |
|
| 762 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
| 763 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 764 | - ), |
|
| 765 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
| 766 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
| 767 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
| 768 | - ), |
|
| 769 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
| 770 | - null, |
|
| 771 | - null, |
|
| 772 | - null, |
|
| 773 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 775 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 776 | - ), |
|
| 777 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
| 778 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 779 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 780 | - ), |
|
| 781 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
| 782 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
| 783 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
| 784 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
| 785 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 786 | - ), |
|
| 787 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
| 788 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 789 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 790 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 791 | - ), |
|
| 792 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
| 793 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 794 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 795 | - ), |
|
| 796 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
| 797 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
| 798 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 799 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
| 800 | - ), |
|
| 801 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
| 802 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 803 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 804 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 805 | - ), |
|
| 806 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
| 807 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 808 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 809 | - ), |
|
| 810 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
| 811 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 812 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 813 | - ), |
|
| 814 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
| 815 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
| 816 | - ), |
|
| 817 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
| 818 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 819 | - ), |
|
| 820 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
| 821 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
| 822 | - ), |
|
| 823 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
| 824 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 825 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 826 | - ), |
|
| 827 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
| 828 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 829 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 830 | - ), |
|
| 831 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
| 832 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 833 | - ), |
|
| 834 | - 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
| 835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 836 | - ), |
|
| 837 | - 'EE_URL_Validation_Strategy' => array( |
|
| 838 | - null, |
|
| 839 | - null, |
|
| 840 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
| 841 | - ), |
|
| 842 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
| 843 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 844 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
| 845 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 846 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 847 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
| 848 | - ), |
|
| 849 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
| 850 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
| 851 | - 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
| 852 | - ), |
|
| 853 | - 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
| 854 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 855 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 856 | - ), |
|
| 857 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
| 858 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 859 | - 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
| 860 | - ), |
|
| 861 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
| 862 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 863 | - ), |
|
| 864 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 865 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 866 | - ], |
|
| 867 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
| 868 | - null, |
|
| 869 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 870 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 871 | - ], |
|
| 872 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
| 873 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 874 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 875 | - ], |
|
| 876 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
| 877 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 878 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 879 | - ], |
|
| 880 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
| 881 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 882 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 883 | - ], |
|
| 884 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
| 885 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 886 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 887 | - ], |
|
| 888 | - 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 889 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 890 | - ], |
|
| 891 | - 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 892 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 893 | - ], |
|
| 894 | - 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 895 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 896 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 897 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 898 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 899 | - ], |
|
| 900 | - 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 901 | - 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 902 | - ] |
|
| 903 | - ); |
|
| 904 | - } |
|
| 905 | - |
|
| 906 | - |
|
| 907 | - /** |
|
| 908 | - * Registers how core classes are loaded. |
|
| 909 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 910 | - * 'EE_Request_Handler' => 'load_core' |
|
| 911 | - * 'EE_Messages_Queue' => 'load_lib' |
|
| 912 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
| 913 | - * or, if greater control is required, by providing a custom closure. For example: |
|
| 914 | - * 'Some_Class' => function () { |
|
| 915 | - * return new Some_Class(); |
|
| 916 | - * }, |
|
| 917 | - * This is required for instantiating dependencies |
|
| 918 | - * where an interface has been type hinted in a class constructor. For example: |
|
| 919 | - * 'Required_Interface' => function () { |
|
| 920 | - * return new A_Class_That_Implements_Required_Interface(); |
|
| 921 | - * }, |
|
| 922 | - */ |
|
| 923 | - protected function _register_core_class_loaders() |
|
| 924 | - { |
|
| 925 | - $this->_class_loaders = array( |
|
| 926 | - // load_core |
|
| 927 | - 'EE_Dependency_Map' => function () { |
|
| 928 | - return $this; |
|
| 929 | - }, |
|
| 930 | - 'EE_Capabilities' => 'load_core', |
|
| 931 | - 'EE_Encryption' => 'load_core', |
|
| 932 | - 'EE_Front_Controller' => 'load_core', |
|
| 933 | - 'EE_Module_Request_Router' => 'load_core', |
|
| 934 | - 'EE_Registry' => 'load_core', |
|
| 935 | - 'EE_Request' => function () { |
|
| 936 | - return $this->legacy_request; |
|
| 937 | - }, |
|
| 938 | - 'EventEspresso\core\services\request\Request' => function () { |
|
| 939 | - return $this->request; |
|
| 940 | - }, |
|
| 941 | - 'EventEspresso\core\services\request\Response' => function () { |
|
| 942 | - return $this->response; |
|
| 943 | - }, |
|
| 944 | - 'EE_Base' => 'load_core', |
|
| 945 | - 'EE_Request_Handler' => 'load_core', |
|
| 946 | - 'EE_Session' => 'load_core', |
|
| 947 | - 'EE_Cron_Tasks' => 'load_core', |
|
| 948 | - 'EE_System' => 'load_core', |
|
| 949 | - 'EE_Maintenance_Mode' => 'load_core', |
|
| 950 | - 'EE_Register_CPTs' => 'load_core', |
|
| 951 | - 'EE_Admin' => 'load_core', |
|
| 952 | - 'EE_CPT_Strategy' => 'load_core', |
|
| 953 | - // load_class |
|
| 954 | - 'EE_Registration_Processor' => 'load_class', |
|
| 955 | - // load_lib |
|
| 956 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 957 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
| 958 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 959 | - 'EE_Messenger_Collection' => 'load_lib', |
|
| 960 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 961 | - 'EE_Messages_Processor' => 'load_lib', |
|
| 962 | - 'EE_Message_Repository' => 'load_lib', |
|
| 963 | - 'EE_Messages_Queue' => 'load_lib', |
|
| 964 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 965 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 966 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 967 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 968 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 969 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 970 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 971 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 972 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 973 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 974 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 975 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 976 | - 'EE_Messages_Generator' => function () { |
|
| 977 | - return EE_Registry::instance()->load_lib( |
|
| 978 | - 'Messages_Generator', |
|
| 979 | - array(), |
|
| 980 | - false, |
|
| 981 | - false |
|
| 982 | - ); |
|
| 983 | - }, |
|
| 984 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 985 | - return EE_Registry::instance()->load_lib( |
|
| 986 | - 'Messages_Template_Defaults', |
|
| 987 | - $arguments, |
|
| 988 | - false, |
|
| 989 | - false |
|
| 990 | - ); |
|
| 991 | - }, |
|
| 992 | - // load_helper |
|
| 993 | - 'EEH_Parse_Shortcodes' => function () { |
|
| 994 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 995 | - return new EEH_Parse_Shortcodes(); |
|
| 996 | - } |
|
| 997 | - return null; |
|
| 998 | - }, |
|
| 999 | - 'EE_Template_Config' => function () { |
|
| 1000 | - return EE_Config::instance()->template_settings; |
|
| 1001 | - }, |
|
| 1002 | - 'EE_Currency_Config' => function () { |
|
| 1003 | - return EE_Config::instance()->currency; |
|
| 1004 | - }, |
|
| 1005 | - 'EE_Registration_Config' => function () { |
|
| 1006 | - return EE_Config::instance()->registration; |
|
| 1007 | - }, |
|
| 1008 | - 'EE_Core_Config' => function () { |
|
| 1009 | - return EE_Config::instance()->core; |
|
| 1010 | - }, |
|
| 1011 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 1012 | - return LoaderFactory::getLoader(); |
|
| 1013 | - }, |
|
| 1014 | - 'EE_Network_Config' => function () { |
|
| 1015 | - return EE_Network_Config::instance(); |
|
| 1016 | - }, |
|
| 1017 | - 'EE_Config' => function () { |
|
| 1018 | - return EE_Config::instance(); |
|
| 1019 | - }, |
|
| 1020 | - 'EventEspresso\core\domain\Domain' => function () { |
|
| 1021 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
| 1022 | - }, |
|
| 1023 | - 'EE_Admin_Config' => function () { |
|
| 1024 | - return EE_Config::instance()->admin; |
|
| 1025 | - }, |
|
| 1026 | - 'EE_Organization_Config' => function () { |
|
| 1027 | - return EE_Config::instance()->organization; |
|
| 1028 | - }, |
|
| 1029 | - 'EE_Network_Core_Config' => function () { |
|
| 1030 | - return EE_Network_Config::instance()->core; |
|
| 1031 | - }, |
|
| 1032 | - 'EE_Environment_Config' => function () { |
|
| 1033 | - return EE_Config::instance()->environment; |
|
| 1034 | - }, |
|
| 1035 | - ); |
|
| 1036 | - } |
|
| 1037 | - |
|
| 1038 | - |
|
| 1039 | - /** |
|
| 1040 | - * can be used for supplying alternate names for classes, |
|
| 1041 | - * or for connecting interface names to instantiable classes |
|
| 1042 | - */ |
|
| 1043 | - protected function _register_core_aliases() |
|
| 1044 | - { |
|
| 1045 | - $aliases = array( |
|
| 1046 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 1047 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 1048 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 1049 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 1050 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 1051 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 1052 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1053 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 1054 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1055 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 1056 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1057 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 1058 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 1059 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 1060 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 1061 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 1062 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 1063 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 1064 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 1065 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 1066 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1067 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 1068 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1069 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 1070 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 1071 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1072 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1073 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1074 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1075 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1076 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1077 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1078 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1079 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1080 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1081 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1082 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1083 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1084 | - ); |
|
| 1085 | - foreach ($aliases as $alias => $fqn) { |
|
| 1086 | - if (is_array($fqn)) { |
|
| 1087 | - foreach ($fqn as $class => $for_class) { |
|
| 1088 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1089 | - } |
|
| 1090 | - continue; |
|
| 1091 | - } |
|
| 1092 | - $this->class_cache->addAlias($fqn, $alias); |
|
| 1093 | - } |
|
| 1094 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1095 | - $this->class_cache->addAlias( |
|
| 1096 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1097 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1098 | - ); |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1105 | - * request Primarily used by unit tests. |
|
| 1106 | - */ |
|
| 1107 | - public function reset() |
|
| 1108 | - { |
|
| 1109 | - $this->_register_core_class_loaders(); |
|
| 1110 | - $this->_register_core_dependencies(); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1116 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1117 | - * WHY? |
|
| 1118 | - * Because if a class is type hinting for a concretion, |
|
| 1119 | - * then why would we need to find another class to supply it? |
|
| 1120 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1121 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1122 | - * Don't go looking for some substitute. |
|
| 1123 | - * Whereas if a class is type hinting for an interface... |
|
| 1124 | - * then we need to find an actual class to use. |
|
| 1125 | - * So the interface IS the alias for some other FQN, |
|
| 1126 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1127 | - * represents some other class. |
|
| 1128 | - * |
|
| 1129 | - * @deprecated 4.9.62.p |
|
| 1130 | - * @param string $fqn |
|
| 1131 | - * @param string $for_class |
|
| 1132 | - * @return bool |
|
| 1133 | - */ |
|
| 1134 | - public function has_alias($fqn = '', $for_class = '') |
|
| 1135 | - { |
|
| 1136 | - return $this->isAlias($fqn, $for_class); |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - |
|
| 1140 | - /** |
|
| 1141 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1142 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1143 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1144 | - * for example: |
|
| 1145 | - * if the following two entries were added to the _aliases array: |
|
| 1146 | - * array( |
|
| 1147 | - * 'interface_alias' => 'some\namespace\interface' |
|
| 1148 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1149 | - * ) |
|
| 1150 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1151 | - * to load an instance of 'some\namespace\classname' |
|
| 1152 | - * |
|
| 1153 | - * @deprecated 4.9.62.p |
|
| 1154 | - * @param string $alias |
|
| 1155 | - * @param string $for_class |
|
| 1156 | - * @return string |
|
| 1157 | - */ |
|
| 1158 | - public function get_alias($alias = '', $for_class = '') |
|
| 1159 | - { |
|
| 1160 | - return $this->getFqnForAlias($alias, $for_class); |
|
| 1161 | - } |
|
| 23 | + /** |
|
| 24 | + * This means that the requested class dependency is not present in the dependency map |
|
| 25 | + */ |
|
| 26 | + const not_registered = 0; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
| 30 | + */ |
|
| 31 | + const load_new_object = 1; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
| 35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
| 36 | + */ |
|
| 37 | + const load_from_cache = 2; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * When registering a dependency, |
|
| 41 | + * this indicates to keep any existing dependencies that already exist, |
|
| 42 | + * and simply discard any new dependencies declared in the incoming data |
|
| 43 | + */ |
|
| 44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * When registering a dependency, |
|
| 48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
| 49 | + */ |
|
| 50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @type EE_Dependency_Map $_instance |
|
| 55 | + */ |
|
| 56 | + protected static $_instance; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var ClassInterfaceCache $class_cache |
|
| 60 | + */ |
|
| 61 | + private $class_cache; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @type RequestInterface $request |
|
| 65 | + */ |
|
| 66 | + protected $request; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @type LegacyRequestInterface $legacy_request |
|
| 70 | + */ |
|
| 71 | + protected $legacy_request; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @type ResponseInterface $response |
|
| 75 | + */ |
|
| 76 | + protected $response; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @type LoaderInterface $loader |
|
| 80 | + */ |
|
| 81 | + protected $loader; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @type array $_dependency_map |
|
| 85 | + */ |
|
| 86 | + protected $_dependency_map = array(); |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @type array $_class_loaders |
|
| 90 | + */ |
|
| 91 | + protected $_class_loaders = array(); |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * EE_Dependency_Map constructor. |
|
| 96 | + * |
|
| 97 | + * @param ClassInterfaceCache $class_cache |
|
| 98 | + */ |
|
| 99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
| 100 | + { |
|
| 101 | + $this->class_cache = $class_cache; |
|
| 102 | + do_action('EE_Dependency_Map____construct', $this); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return void |
|
| 108 | + */ |
|
| 109 | + public function initialize() |
|
| 110 | + { |
|
| 111 | + $this->_register_core_dependencies(); |
|
| 112 | + $this->_register_core_class_loaders(); |
|
| 113 | + $this->_register_core_aliases(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @singleton method used to instantiate class object |
|
| 119 | + * @param ClassInterfaceCache|null $class_cache |
|
| 120 | + * @return EE_Dependency_Map |
|
| 121 | + */ |
|
| 122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
| 123 | + { |
|
| 124 | + // check if class object is instantiated, and instantiated properly |
|
| 125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
| 126 | + && $class_cache instanceof ClassInterfaceCache |
|
| 127 | + ) { |
|
| 128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
| 129 | + } |
|
| 130 | + return self::$_instance; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param RequestInterface $request |
|
| 136 | + */ |
|
| 137 | + public function setRequest(RequestInterface $request) |
|
| 138 | + { |
|
| 139 | + $this->request = $request; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param LegacyRequestInterface $legacy_request |
|
| 145 | + */ |
|
| 146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
| 147 | + { |
|
| 148 | + $this->legacy_request = $legacy_request; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param ResponseInterface $response |
|
| 154 | + */ |
|
| 155 | + public function setResponse(ResponseInterface $response) |
|
| 156 | + { |
|
| 157 | + $this->response = $response; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @param LoaderInterface $loader |
|
| 163 | + */ |
|
| 164 | + public function setLoader(LoaderInterface $loader) |
|
| 165 | + { |
|
| 166 | + $this->loader = $loader; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $class |
|
| 172 | + * @param array $dependencies |
|
| 173 | + * @param int $overwrite |
|
| 174 | + * @return bool |
|
| 175 | + */ |
|
| 176 | + public static function register_dependencies( |
|
| 177 | + $class, |
|
| 178 | + array $dependencies, |
|
| 179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 180 | + ) { |
|
| 181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
| 187 | + * to the class specified by the first parameter. |
|
| 188 | + * IMPORTANT !!! |
|
| 189 | + * The order of elements in the incoming $dependencies array MUST match |
|
| 190 | + * the order of the constructor parameters for the class in question. |
|
| 191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
| 192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
| 193 | + * |
|
| 194 | + * @param string $class |
|
| 195 | + * @param array $dependencies |
|
| 196 | + * @param int $overwrite |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function registerDependencies( |
|
| 200 | + $class, |
|
| 201 | + array $dependencies, |
|
| 202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
| 203 | + ) { |
|
| 204 | + $class = trim($class, '\\'); |
|
| 205 | + $registered = false; |
|
| 206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
| 207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
| 208 | + } |
|
| 209 | + // we need to make sure that any aliases used when registering a dependency |
|
| 210 | + // get resolved to the correct class name |
|
| 211 | + foreach ($dependencies as $dependency => $load_source) { |
|
| 212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
| 213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
| 214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
| 215 | + ) { |
|
| 216 | + unset($dependencies[ $dependency ]); |
|
| 217 | + $dependencies[ $alias ] = $load_source; |
|
| 218 | + $registered = true; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + // now add our two lists of dependencies together. |
|
| 222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
| 223 | + // so $dependencies is NOT overwritten because it is listed first |
|
| 224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
| 225 | + // Union is way faster than array_merge() but should be used with caution... |
|
| 226 | + // especially with numerically indexed arrays |
|
| 227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
| 228 | + // now we need to ensure that the resulting dependencies |
|
| 229 | + // array only has the entries that are required for the class |
|
| 230 | + // so first count how many dependencies were originally registered for the class |
|
| 231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
| 232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
| 233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
| 234 | + // then truncate the final array to match that count |
|
| 235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
| 236 | + // otherwise just take the incoming array because nothing previously existed |
|
| 237 | + : $dependencies; |
|
| 238 | + return $registered; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string $class_name |
|
| 244 | + * @param string $loader |
|
| 245 | + * @return bool |
|
| 246 | + * @throws DomainException |
|
| 247 | + */ |
|
| 248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
| 249 | + { |
|
| 250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
| 251 | + throw new DomainException( |
|
| 252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
| 253 | + ); |
|
| 254 | + } |
|
| 255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
| 256 | + if (! is_callable($loader) |
|
| 257 | + && ( |
|
| 258 | + strpos($loader, 'load_') !== 0 |
|
| 259 | + || ! method_exists('EE_Registry', $loader) |
|
| 260 | + ) |
|
| 261 | + ) { |
|
| 262 | + throw new DomainException( |
|
| 263 | + sprintf( |
|
| 264 | + esc_html__( |
|
| 265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
| 266 | + 'event_espresso' |
|
| 267 | + ), |
|
| 268 | + $loader |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
| 273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
| 274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
| 275 | + return true; |
|
| 276 | + } |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return array |
|
| 283 | + */ |
|
| 284 | + public function dependency_map() |
|
| 285 | + { |
|
| 286 | + return $this->_dependency_map; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
| 292 | + * |
|
| 293 | + * @param string $class_name |
|
| 294 | + * @return boolean |
|
| 295 | + */ |
|
| 296 | + public function has($class_name = '') |
|
| 297 | + { |
|
| 298 | + // all legacy models have the same dependencies |
|
| 299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 300 | + $class_name = 'LEGACY_MODELS'; |
|
| 301 | + } |
|
| 302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
| 308 | + * |
|
| 309 | + * @param string $class_name |
|
| 310 | + * @param string $dependency |
|
| 311 | + * @return bool |
|
| 312 | + */ |
|
| 313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
| 314 | + { |
|
| 315 | + // all legacy models have the same dependencies |
|
| 316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 317 | + $class_name = 'LEGACY_MODELS'; |
|
| 318 | + } |
|
| 319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
| 320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
| 321 | + ? true |
|
| 322 | + : false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
| 328 | + * |
|
| 329 | + * @param string $class_name |
|
| 330 | + * @param string $dependency |
|
| 331 | + * @return int |
|
| 332 | + */ |
|
| 333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
| 334 | + { |
|
| 335 | + // all legacy models have the same dependencies |
|
| 336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 337 | + $class_name = 'LEGACY_MODELS'; |
|
| 338 | + } |
|
| 339 | + $dependency = $this->getFqnForAlias($dependency); |
|
| 340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
| 341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
| 342 | + : EE_Dependency_Map::not_registered; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param string $class_name |
|
| 348 | + * @return string | Closure |
|
| 349 | + */ |
|
| 350 | + public function class_loader($class_name) |
|
| 351 | + { |
|
| 352 | + // all legacy models use load_model() |
|
| 353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
| 354 | + return 'load_model'; |
|
| 355 | + } |
|
| 356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
| 357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
| 358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
| 359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
| 360 | + ) { |
|
| 361 | + return 'load_core'; |
|
| 362 | + } |
|
| 363 | + $class_name = $this->getFqnForAlias($class_name); |
|
| 364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @return array |
|
| 370 | + */ |
|
| 371 | + public function class_loaders() |
|
| 372 | + { |
|
| 373 | + return $this->_class_loaders; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * adds an alias for a classname |
|
| 379 | + * |
|
| 380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
| 381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
| 382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
| 383 | + */ |
|
| 384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
| 385 | + { |
|
| 386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
| 392 | + * WHY? |
|
| 393 | + * Because if a class is type hinting for a concretion, |
|
| 394 | + * then why would we need to find another class to supply it? |
|
| 395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 397 | + * Don't go looking for some substitute. |
|
| 398 | + * Whereas if a class is type hinting for an interface... |
|
| 399 | + * then we need to find an actual class to use. |
|
| 400 | + * So the interface IS the alias for some other FQN, |
|
| 401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 402 | + * represents some other class. |
|
| 403 | + * |
|
| 404 | + * @param string $fqn |
|
| 405 | + * @param string $for_class |
|
| 406 | + * @return bool |
|
| 407 | + */ |
|
| 408 | + public function isAlias($fqn = '', $for_class = '') |
|
| 409 | + { |
|
| 410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 417 | + * for example: |
|
| 418 | + * if the following two entries were added to the _aliases array: |
|
| 419 | + * array( |
|
| 420 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 422 | + * ) |
|
| 423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 424 | + * to load an instance of 'some\namespace\classname' |
|
| 425 | + * |
|
| 426 | + * @param string $alias |
|
| 427 | + * @param string $for_class |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
| 431 | + { |
|
| 432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
| 438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
| 439 | + * This is done by using the following class constants: |
|
| 440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
| 441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
| 442 | + */ |
|
| 443 | + protected function _register_core_dependencies() |
|
| 444 | + { |
|
| 445 | + $this->_dependency_map = array( |
|
| 446 | + 'EE_Request_Handler' => array( |
|
| 447 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 448 | + ), |
|
| 449 | + 'EE_System' => array( |
|
| 450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 454 | + ), |
|
| 455 | + 'EE_Session' => array( |
|
| 456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
| 460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
| 461 | + ), |
|
| 462 | + 'EE_Cart' => array( |
|
| 463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 464 | + ), |
|
| 465 | + 'EE_Front_Controller' => array( |
|
| 466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 467 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 469 | + ), |
|
| 470 | + 'EE_Messenger_Collection_Loader' => array( |
|
| 471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
| 472 | + ), |
|
| 473 | + 'EE_Message_Type_Collection_Loader' => array( |
|
| 474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
| 475 | + ), |
|
| 476 | + 'EE_Message_Resource_Manager' => array( |
|
| 477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
| 479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 480 | + ), |
|
| 481 | + 'EE_Message_Factory' => array( |
|
| 482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 483 | + ), |
|
| 484 | + 'EE_messages' => array( |
|
| 485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 486 | + ), |
|
| 487 | + 'EE_Messages_Generator' => array( |
|
| 488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
| 489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
| 490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
| 491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
| 492 | + ), |
|
| 493 | + 'EE_Messages_Processor' => array( |
|
| 494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 495 | + ), |
|
| 496 | + 'EE_Messages_Queue' => array( |
|
| 497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
| 498 | + ), |
|
| 499 | + 'EE_Messages_Template_Defaults' => array( |
|
| 500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
| 501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
| 502 | + ), |
|
| 503 | + 'EE_Message_To_Generate_From_Request' => array( |
|
| 504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
| 505 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 506 | + ), |
|
| 507 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
| 508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
| 509 | + ), |
|
| 510 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
| 511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
| 513 | + ), |
|
| 514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
| 515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 516 | + ), |
|
| 517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
| 518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
| 519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
| 520 | + ), |
|
| 521 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
| 522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 523 | + ), |
|
| 524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
| 525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 526 | + ), |
|
| 527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
| 528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 529 | + ), |
|
| 530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
| 531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
| 532 | + ), |
|
| 533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
| 534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 535 | + ), |
|
| 536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
| 537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 538 | + ), |
|
| 539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
| 540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 541 | + ), |
|
| 542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
| 543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 544 | + ), |
|
| 545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
| 546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
| 547 | + ), |
|
| 548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
| 549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 550 | + ), |
|
| 551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
| 552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 553 | + ), |
|
| 554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
| 555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
| 556 | + ), |
|
| 557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
| 558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 559 | + ), |
|
| 560 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
| 561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 562 | + ), |
|
| 563 | + 'EE_Data_Migration_Class_Base' => array( |
|
| 564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 566 | + ), |
|
| 567 | + 'EE_DMS_Core_4_1_0' => array( |
|
| 568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 570 | + ), |
|
| 571 | + 'EE_DMS_Core_4_2_0' => array( |
|
| 572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 574 | + ), |
|
| 575 | + 'EE_DMS_Core_4_3_0' => array( |
|
| 576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 578 | + ), |
|
| 579 | + 'EE_DMS_Core_4_4_0' => array( |
|
| 580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 582 | + ), |
|
| 583 | + 'EE_DMS_Core_4_5_0' => array( |
|
| 584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 586 | + ), |
|
| 587 | + 'EE_DMS_Core_4_6_0' => array( |
|
| 588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 590 | + ), |
|
| 591 | + 'EE_DMS_Core_4_7_0' => array( |
|
| 592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 594 | + ), |
|
| 595 | + 'EE_DMS_Core_4_8_0' => array( |
|
| 596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 598 | + ), |
|
| 599 | + 'EE_DMS_Core_4_9_0' => array( |
|
| 600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 602 | + ), |
|
| 603 | + 'EE_DMS_Core_4_10_0' => array( |
|
| 604 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
| 605 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
| 606 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
| 607 | + ), |
|
| 608 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
| 609 | + null, |
|
| 610 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 611 | + ), |
|
| 612 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
| 613 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 614 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
| 615 | + ), |
|
| 616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
| 617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 618 | + ), |
|
| 619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
| 620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 621 | + ), |
|
| 622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
| 623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 624 | + ), |
|
| 625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
| 626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 627 | + ), |
|
| 628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
| 629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 630 | + ), |
|
| 631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
| 632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 633 | + ), |
|
| 634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
| 635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
| 636 | + ), |
|
| 637 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
| 638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 639 | + ), |
|
| 640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
| 641 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
| 642 | + ), |
|
| 643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
| 644 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 645 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 646 | + ), |
|
| 647 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
| 648 | + null, |
|
| 649 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
| 650 | + ), |
|
| 651 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
| 652 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 653 | + ), |
|
| 654 | + 'LEGACY_MODELS' => array( |
|
| 655 | + null, |
|
| 656 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
| 657 | + ), |
|
| 658 | + 'EE_Module_Request_Router' => array( |
|
| 659 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 660 | + ), |
|
| 661 | + 'EE_Registration_Processor' => array( |
|
| 662 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
| 663 | + ), |
|
| 664 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
| 665 | + null, |
|
| 666 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
| 667 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 668 | + ), |
|
| 669 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
| 670 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
| 671 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 672 | + ), |
|
| 673 | + 'EE_Admin_Transactions_List_Table' => array( |
|
| 674 | + null, |
|
| 675 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
| 676 | + ), |
|
| 677 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
| 678 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
| 679 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
| 680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
| 681 | + ), |
|
| 682 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
| 683 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
| 684 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 685 | + ), |
|
| 686 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
| 687 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 688 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 689 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 690 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 691 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 692 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 693 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
| 694 | + ), |
|
| 695 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
| 696 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 697 | + ), |
|
| 698 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
| 699 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 700 | + ), |
|
| 701 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
| 702 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 703 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 704 | + ), |
|
| 705 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
| 706 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
| 707 | + ), |
|
| 708 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
| 709 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 710 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 711 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
| 712 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 713 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
| 714 | + ), |
|
| 715 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
| 716 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 717 | + ), |
|
| 718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
| 719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 721 | + ), |
|
| 722 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
| 723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 724 | + ), |
|
| 725 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
| 726 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 727 | + ), |
|
| 728 | + 'EE_CPT_Strategy' => array( |
|
| 729 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
| 731 | + ), |
|
| 732 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
| 733 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 734 | + ), |
|
| 735 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
| 736 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 737 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
| 738 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
| 739 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 740 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 741 | + ), |
|
| 742 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
| 743 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
| 744 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
| 745 | + ), |
|
| 746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
| 747 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 748 | + ), |
|
| 749 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
| 750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 751 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
| 752 | + ), |
|
| 753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
| 754 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
| 755 | + ), |
|
| 756 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
| 757 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 758 | + ), |
|
| 759 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
| 760 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
| 761 | + ), |
|
| 762 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
| 763 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 764 | + ), |
|
| 765 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
| 766 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
| 767 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
| 768 | + ), |
|
| 769 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
| 770 | + null, |
|
| 771 | + null, |
|
| 772 | + null, |
|
| 773 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
| 774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 775 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 776 | + ), |
|
| 777 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
| 778 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 779 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
| 780 | + ), |
|
| 781 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
| 782 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
| 783 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
| 784 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
| 785 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 786 | + ), |
|
| 787 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
| 788 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 789 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
| 790 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
| 791 | + ), |
|
| 792 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
| 793 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 794 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 795 | + ), |
|
| 796 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
| 797 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
| 798 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 799 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
| 800 | + ), |
|
| 801 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
| 802 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
| 803 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
| 804 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
| 805 | + ), |
|
| 806 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
| 807 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
| 808 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 809 | + ), |
|
| 810 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
| 811 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
| 812 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
| 813 | + ), |
|
| 814 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
| 815 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
| 816 | + ), |
|
| 817 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
| 818 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 819 | + ), |
|
| 820 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
| 821 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
| 822 | + ), |
|
| 823 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
| 824 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 825 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 826 | + ), |
|
| 827 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
| 828 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 829 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 830 | + ), |
|
| 831 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
| 832 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 833 | + ), |
|
| 834 | + 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
| 835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 836 | + ), |
|
| 837 | + 'EE_URL_Validation_Strategy' => array( |
|
| 838 | + null, |
|
| 839 | + null, |
|
| 840 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
| 841 | + ), |
|
| 842 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
| 843 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 844 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
| 845 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 846 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
| 847 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
| 848 | + ), |
|
| 849 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
| 850 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
| 851 | + 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
| 852 | + ), |
|
| 853 | + 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
| 854 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 855 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 856 | + ), |
|
| 857 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
| 858 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
| 859 | + 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
| 860 | + ), |
|
| 861 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
| 862 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 863 | + ), |
|
| 864 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
| 865 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
| 866 | + ], |
|
| 867 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
| 868 | + null, |
|
| 869 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 870 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
| 871 | + ], |
|
| 872 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
| 873 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 874 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
| 875 | + ], |
|
| 876 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
| 877 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 878 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 879 | + ], |
|
| 880 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
| 881 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 882 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 883 | + ], |
|
| 884 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
| 885 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
| 886 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
| 887 | + ], |
|
| 888 | + 'EventEspressoBatchRequest\JobHandlers\ExecuteBatchDeletion' => [ |
|
| 889 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 890 | + ], |
|
| 891 | + 'EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion' => [ |
|
| 892 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache |
|
| 893 | + ], |
|
| 894 | + 'EventEspresso\core\domain\services\admin\events\data\PreviewDeletion' => [ |
|
| 895 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 896 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
| 897 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
| 898 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
| 899 | + ], |
|
| 900 | + 'EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion' => [ |
|
| 901 | + 'EventEspresso\core\services\orm\tree_traversal\NodeGroupDao' => EE_Dependency_Map::load_from_cache, |
|
| 902 | + ] |
|
| 903 | + ); |
|
| 904 | + } |
|
| 905 | + |
|
| 906 | + |
|
| 907 | + /** |
|
| 908 | + * Registers how core classes are loaded. |
|
| 909 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
| 910 | + * 'EE_Request_Handler' => 'load_core' |
|
| 911 | + * 'EE_Messages_Queue' => 'load_lib' |
|
| 912 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
| 913 | + * or, if greater control is required, by providing a custom closure. For example: |
|
| 914 | + * 'Some_Class' => function () { |
|
| 915 | + * return new Some_Class(); |
|
| 916 | + * }, |
|
| 917 | + * This is required for instantiating dependencies |
|
| 918 | + * where an interface has been type hinted in a class constructor. For example: |
|
| 919 | + * 'Required_Interface' => function () { |
|
| 920 | + * return new A_Class_That_Implements_Required_Interface(); |
|
| 921 | + * }, |
|
| 922 | + */ |
|
| 923 | + protected function _register_core_class_loaders() |
|
| 924 | + { |
|
| 925 | + $this->_class_loaders = array( |
|
| 926 | + // load_core |
|
| 927 | + 'EE_Dependency_Map' => function () { |
|
| 928 | + return $this; |
|
| 929 | + }, |
|
| 930 | + 'EE_Capabilities' => 'load_core', |
|
| 931 | + 'EE_Encryption' => 'load_core', |
|
| 932 | + 'EE_Front_Controller' => 'load_core', |
|
| 933 | + 'EE_Module_Request_Router' => 'load_core', |
|
| 934 | + 'EE_Registry' => 'load_core', |
|
| 935 | + 'EE_Request' => function () { |
|
| 936 | + return $this->legacy_request; |
|
| 937 | + }, |
|
| 938 | + 'EventEspresso\core\services\request\Request' => function () { |
|
| 939 | + return $this->request; |
|
| 940 | + }, |
|
| 941 | + 'EventEspresso\core\services\request\Response' => function () { |
|
| 942 | + return $this->response; |
|
| 943 | + }, |
|
| 944 | + 'EE_Base' => 'load_core', |
|
| 945 | + 'EE_Request_Handler' => 'load_core', |
|
| 946 | + 'EE_Session' => 'load_core', |
|
| 947 | + 'EE_Cron_Tasks' => 'load_core', |
|
| 948 | + 'EE_System' => 'load_core', |
|
| 949 | + 'EE_Maintenance_Mode' => 'load_core', |
|
| 950 | + 'EE_Register_CPTs' => 'load_core', |
|
| 951 | + 'EE_Admin' => 'load_core', |
|
| 952 | + 'EE_CPT_Strategy' => 'load_core', |
|
| 953 | + // load_class |
|
| 954 | + 'EE_Registration_Processor' => 'load_class', |
|
| 955 | + // load_lib |
|
| 956 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
| 957 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
| 958 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
| 959 | + 'EE_Messenger_Collection' => 'load_lib', |
|
| 960 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
| 961 | + 'EE_Messages_Processor' => 'load_lib', |
|
| 962 | + 'EE_Message_Repository' => 'load_lib', |
|
| 963 | + 'EE_Messages_Queue' => 'load_lib', |
|
| 964 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
| 965 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
| 966 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
| 967 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
| 968 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
| 969 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
| 970 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
| 971 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
| 972 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
| 973 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
| 974 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
| 975 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
| 976 | + 'EE_Messages_Generator' => function () { |
|
| 977 | + return EE_Registry::instance()->load_lib( |
|
| 978 | + 'Messages_Generator', |
|
| 979 | + array(), |
|
| 980 | + false, |
|
| 981 | + false |
|
| 982 | + ); |
|
| 983 | + }, |
|
| 984 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
| 985 | + return EE_Registry::instance()->load_lib( |
|
| 986 | + 'Messages_Template_Defaults', |
|
| 987 | + $arguments, |
|
| 988 | + false, |
|
| 989 | + false |
|
| 990 | + ); |
|
| 991 | + }, |
|
| 992 | + // load_helper |
|
| 993 | + 'EEH_Parse_Shortcodes' => function () { |
|
| 994 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
| 995 | + return new EEH_Parse_Shortcodes(); |
|
| 996 | + } |
|
| 997 | + return null; |
|
| 998 | + }, |
|
| 999 | + 'EE_Template_Config' => function () { |
|
| 1000 | + return EE_Config::instance()->template_settings; |
|
| 1001 | + }, |
|
| 1002 | + 'EE_Currency_Config' => function () { |
|
| 1003 | + return EE_Config::instance()->currency; |
|
| 1004 | + }, |
|
| 1005 | + 'EE_Registration_Config' => function () { |
|
| 1006 | + return EE_Config::instance()->registration; |
|
| 1007 | + }, |
|
| 1008 | + 'EE_Core_Config' => function () { |
|
| 1009 | + return EE_Config::instance()->core; |
|
| 1010 | + }, |
|
| 1011 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
| 1012 | + return LoaderFactory::getLoader(); |
|
| 1013 | + }, |
|
| 1014 | + 'EE_Network_Config' => function () { |
|
| 1015 | + return EE_Network_Config::instance(); |
|
| 1016 | + }, |
|
| 1017 | + 'EE_Config' => function () { |
|
| 1018 | + return EE_Config::instance(); |
|
| 1019 | + }, |
|
| 1020 | + 'EventEspresso\core\domain\Domain' => function () { |
|
| 1021 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
| 1022 | + }, |
|
| 1023 | + 'EE_Admin_Config' => function () { |
|
| 1024 | + return EE_Config::instance()->admin; |
|
| 1025 | + }, |
|
| 1026 | + 'EE_Organization_Config' => function () { |
|
| 1027 | + return EE_Config::instance()->organization; |
|
| 1028 | + }, |
|
| 1029 | + 'EE_Network_Core_Config' => function () { |
|
| 1030 | + return EE_Network_Config::instance()->core; |
|
| 1031 | + }, |
|
| 1032 | + 'EE_Environment_Config' => function () { |
|
| 1033 | + return EE_Config::instance()->environment; |
|
| 1034 | + }, |
|
| 1035 | + ); |
|
| 1036 | + } |
|
| 1037 | + |
|
| 1038 | + |
|
| 1039 | + /** |
|
| 1040 | + * can be used for supplying alternate names for classes, |
|
| 1041 | + * or for connecting interface names to instantiable classes |
|
| 1042 | + */ |
|
| 1043 | + protected function _register_core_aliases() |
|
| 1044 | + { |
|
| 1045 | + $aliases = array( |
|
| 1046 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
| 1047 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
| 1048 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
| 1049 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
| 1050 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
| 1051 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
| 1052 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1053 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
| 1054 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 1055 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
| 1056 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
| 1057 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
| 1058 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
| 1059 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
| 1060 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
| 1061 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
| 1062 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
| 1063 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
| 1064 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
| 1065 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
| 1066 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1067 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
| 1068 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
| 1069 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
| 1070 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
| 1071 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
| 1072 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
| 1073 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
| 1074 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
| 1075 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
| 1076 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
| 1077 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
| 1078 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
| 1079 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
| 1080 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
| 1081 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
| 1082 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
| 1083 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
| 1084 | + ); |
|
| 1085 | + foreach ($aliases as $alias => $fqn) { |
|
| 1086 | + if (is_array($fqn)) { |
|
| 1087 | + foreach ($fqn as $class => $for_class) { |
|
| 1088 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
| 1089 | + } |
|
| 1090 | + continue; |
|
| 1091 | + } |
|
| 1092 | + $this->class_cache->addAlias($fqn, $alias); |
|
| 1093 | + } |
|
| 1094 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1095 | + $this->class_cache->addAlias( |
|
| 1096 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
| 1097 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
| 1098 | + ); |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
| 1105 | + * request Primarily used by unit tests. |
|
| 1106 | + */ |
|
| 1107 | + public function reset() |
|
| 1108 | + { |
|
| 1109 | + $this->_register_core_class_loaders(); |
|
| 1110 | + $this->_register_core_dependencies(); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
| 1116 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
| 1117 | + * WHY? |
|
| 1118 | + * Because if a class is type hinting for a concretion, |
|
| 1119 | + * then why would we need to find another class to supply it? |
|
| 1120 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
| 1121 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
| 1122 | + * Don't go looking for some substitute. |
|
| 1123 | + * Whereas if a class is type hinting for an interface... |
|
| 1124 | + * then we need to find an actual class to use. |
|
| 1125 | + * So the interface IS the alias for some other FQN, |
|
| 1126 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
| 1127 | + * represents some other class. |
|
| 1128 | + * |
|
| 1129 | + * @deprecated 4.9.62.p |
|
| 1130 | + * @param string $fqn |
|
| 1131 | + * @param string $for_class |
|
| 1132 | + * @return bool |
|
| 1133 | + */ |
|
| 1134 | + public function has_alias($fqn = '', $for_class = '') |
|
| 1135 | + { |
|
| 1136 | + return $this->isAlias($fqn, $for_class); |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + |
|
| 1140 | + /** |
|
| 1141 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
| 1142 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
| 1143 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
| 1144 | + * for example: |
|
| 1145 | + * if the following two entries were added to the _aliases array: |
|
| 1146 | + * array( |
|
| 1147 | + * 'interface_alias' => 'some\namespace\interface' |
|
| 1148 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
| 1149 | + * ) |
|
| 1150 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
| 1151 | + * to load an instance of 'some\namespace\classname' |
|
| 1152 | + * |
|
| 1153 | + * @deprecated 4.9.62.p |
|
| 1154 | + * @param string $alias |
|
| 1155 | + * @param string $for_class |
|
| 1156 | + * @return string |
|
| 1157 | + */ |
|
| 1158 | + public function get_alias($alias = '', $for_class = '') |
|
| 1159 | + { |
|
| 1160 | + return $this->getFqnForAlias($alias, $for_class); |
|
| 1161 | + } |
|
| 1162 | 1162 | } |
@@ -29,638 +29,638 @@ |
||
| 29 | 29 | abstract class FormHandler implements FormHandlerInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | - */ |
|
| 35 | - const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | - */ |
|
| 40 | - const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | - */ |
|
| 45 | - const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | - */ |
|
| 50 | - const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * if set to false, then this form has no displayable content, |
|
| 54 | - * and will only be used for processing data sent passed via GET or POST |
|
| 55 | - * defaults to true ( ie: form has displayable content ) |
|
| 56 | - * |
|
| 57 | - * @var boolean $displayable |
|
| 58 | - */ |
|
| 59 | - private $displayable = true; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string $form_name |
|
| 63 | - */ |
|
| 64 | - private $form_name; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var string $admin_name |
|
| 68 | - */ |
|
| 69 | - private $admin_name; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string $slug |
|
| 73 | - */ |
|
| 74 | - private $slug; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var string $submit_btn_text |
|
| 78 | - */ |
|
| 79 | - private $submit_btn_text; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var string $form_action |
|
| 83 | - */ |
|
| 84 | - private $form_action; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * form params in key value pairs |
|
| 88 | - * can be added to form action URL or as hidden inputs |
|
| 89 | - * |
|
| 90 | - * @var array $form_args |
|
| 91 | - */ |
|
| 92 | - private $form_args = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * value of one of the string constant above |
|
| 96 | - * |
|
| 97 | - * @var string $form_config |
|
| 98 | - */ |
|
| 99 | - private $form_config; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * whether or not the form was determined to be invalid |
|
| 103 | - * |
|
| 104 | - * @var boolean $form_has_errors |
|
| 105 | - */ |
|
| 106 | - private $form_has_errors; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * the absolute top level form section being used on the page |
|
| 110 | - * |
|
| 111 | - * @var EE_Form_Section_Proper $form |
|
| 112 | - */ |
|
| 113 | - private $form; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var EE_Registry $registry |
|
| 117 | - */ |
|
| 118 | - protected $registry; |
|
| 119 | - |
|
| 120 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Form constructor. |
|
| 125 | - * |
|
| 126 | - * @param string $form_name |
|
| 127 | - * @param string $admin_name |
|
| 128 | - * @param string $slug |
|
| 129 | - * @param string $form_action |
|
| 130 | - * @param string $form_config |
|
| 131 | - * @param EE_Registry|null $registry |
|
| 132 | - */ |
|
| 133 | - public function __construct( |
|
| 134 | - $form_name, |
|
| 135 | - $admin_name, |
|
| 136 | - $slug, |
|
| 137 | - $form_action = '', |
|
| 138 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 139 | - EE_Registry $registry = null |
|
| 140 | - ) { |
|
| 141 | - $this->setFormName($form_name); |
|
| 142 | - $this->setAdminName($admin_name); |
|
| 143 | - $this->setSlug($slug); |
|
| 144 | - $this->setFormAction($form_action); |
|
| 145 | - $this->setFormConfig($form_config); |
|
| 146 | - $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 147 | - $this->registry = $registry; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - public static function getFormConfigConstants() |
|
| 155 | - { |
|
| 156 | - return array( |
|
| 157 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 158 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 159 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 160 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param bool $for_display |
|
| 167 | - * @return EE_Form_Section_Proper |
|
| 168 | - * @throws EE_Error |
|
| 169 | - * @throws LogicException |
|
| 170 | - */ |
|
| 171 | - public function form($for_display = false) |
|
| 172 | - { |
|
| 173 | - if (! $this->formIsValid()) { |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - if ($for_display) { |
|
| 177 | - $form_config = $this->formConfig(); |
|
| 178 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 179 | - || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 180 | - ) { |
|
| 181 | - $this->appendSubmitButton(); |
|
| 182 | - $this->clearFormButtonFloats(); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - return $this->form; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return boolean |
|
| 191 | - * @throws LogicException |
|
| 192 | - */ |
|
| 193 | - public function formIsValid() |
|
| 194 | - { |
|
| 195 | - if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 196 | - return true; |
|
| 197 | - } |
|
| 198 | - $form = apply_filters( |
|
| 199 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 200 | - $this->generate(), |
|
| 201 | - $this |
|
| 202 | - ); |
|
| 203 | - if ($this->verifyForm($form)) { |
|
| 204 | - $this->setForm($form); |
|
| 205 | - } |
|
| 206 | - return true; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param EE_Form_Section_Proper|null $form |
|
| 212 | - * @return bool |
|
| 213 | - * @throws LogicException |
|
| 214 | - */ |
|
| 215 | - public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 216 | - { |
|
| 217 | - $form = $form !== null ? $form : $this->form; |
|
| 218 | - if ($form instanceof EE_Form_Section_Proper) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - throw new LogicException( |
|
| 222 | - sprintf( |
|
| 223 | - esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 224 | - $this->form_name, |
|
| 225 | - var_export($form, true) |
|
| 226 | - ) |
|
| 227 | - ); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param EE_Form_Section_Proper $form |
|
| 233 | - */ |
|
| 234 | - public function setForm(EE_Form_Section_Proper $form) |
|
| 235 | - { |
|
| 236 | - $this->form = $form; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @return boolean |
|
| 242 | - */ |
|
| 243 | - public function displayable() |
|
| 244 | - { |
|
| 245 | - return $this->displayable; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param boolean $displayable |
|
| 251 | - */ |
|
| 252 | - public function setDisplayable($displayable = false) |
|
| 253 | - { |
|
| 254 | - $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * a public name for the form that can be displayed on the frontend of a site |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function formName() |
|
| 264 | - { |
|
| 265 | - return $this->form_name; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param string $form_name |
|
| 271 | - * @throws InvalidDataTypeException |
|
| 272 | - */ |
|
| 273 | - public function setFormName($form_name) |
|
| 274 | - { |
|
| 275 | - if (! is_string($form_name)) { |
|
| 276 | - throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 277 | - } |
|
| 278 | - $this->form_name = $form_name; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * a public name for the form that can be displayed, but only in the admin |
|
| 284 | - * |
|
| 285 | - * @return string |
|
| 286 | - */ |
|
| 287 | - public function adminName() |
|
| 288 | - { |
|
| 289 | - return $this->admin_name; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param string $admin_name |
|
| 295 | - * @throws InvalidDataTypeException |
|
| 296 | - */ |
|
| 297 | - public function setAdminName($admin_name) |
|
| 298 | - { |
|
| 299 | - if (! is_string($admin_name)) { |
|
| 300 | - throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 301 | - } |
|
| 302 | - $this->admin_name = $admin_name; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * a URL friendly string that can be used for identifying the form |
|
| 308 | - * |
|
| 309 | - * @return string |
|
| 310 | - */ |
|
| 311 | - public function slug() |
|
| 312 | - { |
|
| 313 | - return $this->slug; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param string $slug |
|
| 319 | - * @throws InvalidDataTypeException |
|
| 320 | - */ |
|
| 321 | - public function setSlug($slug) |
|
| 322 | - { |
|
| 323 | - if (! is_string($slug)) { |
|
| 324 | - throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 325 | - } |
|
| 326 | - $this->slug = $slug; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function submitBtnText() |
|
| 334 | - { |
|
| 335 | - return $this->submit_btn_text; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * @param string $submit_btn_text |
|
| 341 | - * @throws InvalidDataTypeException |
|
| 342 | - * @throws InvalidArgumentException |
|
| 343 | - */ |
|
| 344 | - public function setSubmitBtnText($submit_btn_text) |
|
| 345 | - { |
|
| 346 | - if (! is_string($submit_btn_text)) { |
|
| 347 | - throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 348 | - } |
|
| 349 | - if (empty($submit_btn_text)) { |
|
| 350 | - throw new InvalidArgumentException( |
|
| 351 | - esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - $this->submit_btn_text = $submit_btn_text; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @return string |
|
| 360 | - */ |
|
| 361 | - public function formAction() |
|
| 362 | - { |
|
| 363 | - return ! empty($this->form_args) |
|
| 364 | - ? add_query_arg($this->form_args, $this->form_action) |
|
| 365 | - : $this->form_action; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param string $form_action |
|
| 371 | - * @throws InvalidDataTypeException |
|
| 372 | - */ |
|
| 373 | - public function setFormAction($form_action) |
|
| 374 | - { |
|
| 375 | - if (! is_string($form_action)) { |
|
| 376 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 377 | - } |
|
| 378 | - $this->form_action = $form_action; |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @param array $form_args |
|
| 384 | - * @throws InvalidDataTypeException |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - */ |
|
| 387 | - public function addFormActionArgs($form_args = array()) |
|
| 388 | - { |
|
| 389 | - if (is_object($form_args)) { |
|
| 390 | - throw new InvalidDataTypeException( |
|
| 391 | - '$form_args', |
|
| 392 | - $form_args, |
|
| 393 | - 'anything other than an object was expected.' |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - if (empty($form_args)) { |
|
| 397 | - throw new InvalidArgumentException( |
|
| 398 | - esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - $this->form_args = array_merge($this->form_args, $form_args); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * @return string |
|
| 407 | - */ |
|
| 408 | - public function formConfig() |
|
| 409 | - { |
|
| 410 | - return $this->form_config; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $form_config |
|
| 416 | - * @throws DomainException |
|
| 417 | - */ |
|
| 418 | - public function setFormConfig($form_config) |
|
| 419 | - { |
|
| 420 | - if (! in_array( |
|
| 421 | - $form_config, |
|
| 422 | - array( |
|
| 423 | - FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 424 | - FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 425 | - FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 426 | - FormHandler::DO_NOT_SETUP_FORM, |
|
| 427 | - ), |
|
| 428 | - true |
|
| 429 | - ) |
|
| 430 | - ) { |
|
| 431 | - throw new DomainException( |
|
| 432 | - sprintf( |
|
| 433 | - esc_html__( |
|
| 434 | - '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 435 | - 'event_espresso' |
|
| 436 | - ), |
|
| 437 | - $form_config |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - } |
|
| 441 | - $this->form_config = $form_config; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * called after the form is instantiated |
|
| 447 | - * and used for performing any logic that needs to occur early |
|
| 448 | - * before any of the other methods are called. |
|
| 449 | - * returns true if everything is ok to proceed, |
|
| 450 | - * and false if no further form logic should be implemented |
|
| 451 | - * |
|
| 452 | - * @return boolean |
|
| 453 | - */ |
|
| 454 | - public function initialize() |
|
| 455 | - { |
|
| 456 | - $this->form_has_errors = EE_Error::has_error(true); |
|
| 457 | - return true; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * used for setting up css and js |
|
| 463 | - * |
|
| 464 | - * @return void |
|
| 465 | - * @throws LogicException |
|
| 466 | - * @throws EE_Error |
|
| 467 | - */ |
|
| 468 | - public function enqueueStylesAndScripts() |
|
| 469 | - { |
|
| 470 | - $this->form()->enqueue_js(); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * creates and returns the actual form |
|
| 476 | - * |
|
| 477 | - * @return EE_Form_Section_Proper |
|
| 478 | - */ |
|
| 479 | - abstract public function generate(); |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 484 | - * |
|
| 485 | - * @param string $text |
|
| 486 | - * @return EE_Submit_Input |
|
| 487 | - */ |
|
| 488 | - public function generateSubmitButton($text = '') |
|
| 489 | - { |
|
| 490 | - $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 491 | - return new EE_Submit_Input( |
|
| 492 | - array( |
|
| 493 | - 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 494 | - 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | - 'html_class' => 'ee-form-submit', |
|
| 496 | - 'html_label' => ' ', |
|
| 497 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 498 | - 'default' => $text, |
|
| 499 | - ) |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 506 | - * |
|
| 507 | - * @param string $text |
|
| 508 | - * @return void |
|
| 509 | - * @throws EE_Error |
|
| 510 | - */ |
|
| 511 | - public function appendSubmitButton($text = '') |
|
| 512 | - { |
|
| 513 | - if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - $this->form->add_subsections( |
|
| 517 | - array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 518 | - null, |
|
| 519 | - false |
|
| 520 | - ); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 526 | - * |
|
| 527 | - * @param string $text |
|
| 528 | - * @return EE_Submit_Input |
|
| 529 | - */ |
|
| 530 | - public function generateCancelButton($text = '') |
|
| 531 | - { |
|
| 532 | - $cancel_button = new EE_Submit_Input( |
|
| 533 | - array( |
|
| 534 | - 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 535 | - 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 536 | - 'html_class' => 'ee-cancel-form', |
|
| 537 | - 'html_label' => ' ', |
|
| 538 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 539 | - 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - $cancel_button->set_button_css_attributes(false); |
|
| 543 | - return $cancel_button; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * appends a float clearing div onto end of form |
|
| 549 | - * |
|
| 550 | - * @return void |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function clearFormButtonFloats() |
|
| 554 | - { |
|
| 555 | - $this->form->add_subsections( |
|
| 556 | - array( |
|
| 557 | - 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 558 | - EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 559 | - ), |
|
| 560 | - ), |
|
| 561 | - null, |
|
| 562 | - false |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 569 | - * returns a string of HTML that can be directly echoed in a template |
|
| 570 | - * |
|
| 571 | - * @return string |
|
| 572 | - * @throws \InvalidArgumentException |
|
| 573 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 574 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 575 | - * @throws LogicException |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function display() |
|
| 579 | - { |
|
| 580 | - $form_html = apply_filters( |
|
| 581 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 582 | - '' |
|
| 583 | - ); |
|
| 584 | - $form_config = $this->formConfig(); |
|
| 585 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 586 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 587 | - ) { |
|
| 588 | - $additional_props = $this->requiresMultipartEnctype() |
|
| 589 | - ? 'enctype="multipart/form-data"' |
|
| 590 | - : ''; |
|
| 591 | - $form_html .= $this->form()->form_open( |
|
| 592 | - $this->formAction(), |
|
| 593 | - 'POST', |
|
| 594 | - $additional_props |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - $form_html .= $this->form(true)->get_html(); |
|
| 598 | - if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 599 | - || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 600 | - ) { |
|
| 601 | - $form_html .= $this->form()->form_close(); |
|
| 602 | - } |
|
| 603 | - $form_html .= apply_filters( |
|
| 604 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 605 | - '' |
|
| 606 | - ); |
|
| 607 | - return $form_html; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 612 | - * @since 4.9.80.p |
|
| 613 | - * @return bool |
|
| 614 | - * @throws EE_Error |
|
| 615 | - */ |
|
| 616 | - public function requiresMultipartEnctype() |
|
| 617 | - { |
|
| 618 | - foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 619 | - if ($input instanceof EE_File_Input) { |
|
| 620 | - return true; |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - return false; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * handles processing the form submission |
|
| 629 | - * returns true or false depending on whether the form was processed successfully or not |
|
| 630 | - * |
|
| 631 | - * @param array $submitted_form_data |
|
| 632 | - * @return array |
|
| 633 | - * @throws \InvalidArgumentException |
|
| 634 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 635 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 636 | - * @throws EE_Error |
|
| 637 | - * @throws LogicException |
|
| 638 | - * @throws InvalidFormSubmissionException |
|
| 639 | - */ |
|
| 640 | - public function process($submitted_form_data = array()) |
|
| 641 | - { |
|
| 642 | - if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 643 | - throw new InvalidFormSubmissionException($this->form_name); |
|
| 644 | - } |
|
| 645 | - $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 646 | - if (! $this->form()->is_valid()) { |
|
| 647 | - throw new InvalidFormSubmissionException( |
|
| 648 | - $this->form_name, |
|
| 649 | - sprintf( |
|
| 650 | - esc_html__( |
|
| 651 | - 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 652 | - 'event_espresso' |
|
| 653 | - ), |
|
| 654 | - $this->form_name, |
|
| 655 | - '<br />', |
|
| 656 | - implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 657 | - ) |
|
| 658 | - ); |
|
| 659 | - } |
|
| 660 | - return apply_filters( |
|
| 661 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 662 | - $this->form()->valid_data(), |
|
| 663 | - $this |
|
| 664 | - ); |
|
| 665 | - } |
|
| 32 | + /** |
|
| 33 | + * will add opening and closing HTML form tags as well as a submit button |
|
| 34 | + */ |
|
| 35 | + const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * will add opening and closing HTML form tags but NOT a submit button |
|
| 39 | + */ |
|
| 40 | + const ADD_FORM_TAGS_ONLY = 'add_form_tags_only'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * will NOT add opening and closing HTML form tags but will add a submit button |
|
| 44 | + */ |
|
| 45 | + const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * will NOT add opening and closing HTML form tags NOR a submit button |
|
| 49 | + */ |
|
| 50 | + const DO_NOT_SETUP_FORM = 'do_not_setup_form'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * if set to false, then this form has no displayable content, |
|
| 54 | + * and will only be used for processing data sent passed via GET or POST |
|
| 55 | + * defaults to true ( ie: form has displayable content ) |
|
| 56 | + * |
|
| 57 | + * @var boolean $displayable |
|
| 58 | + */ |
|
| 59 | + private $displayable = true; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string $form_name |
|
| 63 | + */ |
|
| 64 | + private $form_name; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var string $admin_name |
|
| 68 | + */ |
|
| 69 | + private $admin_name; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string $slug |
|
| 73 | + */ |
|
| 74 | + private $slug; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var string $submit_btn_text |
|
| 78 | + */ |
|
| 79 | + private $submit_btn_text; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var string $form_action |
|
| 83 | + */ |
|
| 84 | + private $form_action; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * form params in key value pairs |
|
| 88 | + * can be added to form action URL or as hidden inputs |
|
| 89 | + * |
|
| 90 | + * @var array $form_args |
|
| 91 | + */ |
|
| 92 | + private $form_args = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * value of one of the string constant above |
|
| 96 | + * |
|
| 97 | + * @var string $form_config |
|
| 98 | + */ |
|
| 99 | + private $form_config; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * whether or not the form was determined to be invalid |
|
| 103 | + * |
|
| 104 | + * @var boolean $form_has_errors |
|
| 105 | + */ |
|
| 106 | + private $form_has_errors; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * the absolute top level form section being used on the page |
|
| 110 | + * |
|
| 111 | + * @var EE_Form_Section_Proper $form |
|
| 112 | + */ |
|
| 113 | + private $form; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var EE_Registry $registry |
|
| 117 | + */ |
|
| 118 | + protected $registry; |
|
| 119 | + |
|
| 120 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Form constructor. |
|
| 125 | + * |
|
| 126 | + * @param string $form_name |
|
| 127 | + * @param string $admin_name |
|
| 128 | + * @param string $slug |
|
| 129 | + * @param string $form_action |
|
| 130 | + * @param string $form_config |
|
| 131 | + * @param EE_Registry|null $registry |
|
| 132 | + */ |
|
| 133 | + public function __construct( |
|
| 134 | + $form_name, |
|
| 135 | + $admin_name, |
|
| 136 | + $slug, |
|
| 137 | + $form_action = '', |
|
| 138 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 139 | + EE_Registry $registry = null |
|
| 140 | + ) { |
|
| 141 | + $this->setFormName($form_name); |
|
| 142 | + $this->setAdminName($admin_name); |
|
| 143 | + $this->setSlug($slug); |
|
| 144 | + $this->setFormAction($form_action); |
|
| 145 | + $this->setFormConfig($form_config); |
|
| 146 | + $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso')); |
|
| 147 | + $this->registry = $registry; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + public static function getFormConfigConstants() |
|
| 155 | + { |
|
| 156 | + return array( |
|
| 157 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 158 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 159 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 160 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param bool $for_display |
|
| 167 | + * @return EE_Form_Section_Proper |
|
| 168 | + * @throws EE_Error |
|
| 169 | + * @throws LogicException |
|
| 170 | + */ |
|
| 171 | + public function form($for_display = false) |
|
| 172 | + { |
|
| 173 | + if (! $this->formIsValid()) { |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + if ($for_display) { |
|
| 177 | + $form_config = $this->formConfig(); |
|
| 178 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 179 | + || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY |
|
| 180 | + ) { |
|
| 181 | + $this->appendSubmitButton(); |
|
| 182 | + $this->clearFormButtonFloats(); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + return $this->form; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return boolean |
|
| 191 | + * @throws LogicException |
|
| 192 | + */ |
|
| 193 | + public function formIsValid() |
|
| 194 | + { |
|
| 195 | + if ($this->form instanceof EE_Form_Section_Proper) { |
|
| 196 | + return true; |
|
| 197 | + } |
|
| 198 | + $form = apply_filters( |
|
| 199 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object', |
|
| 200 | + $this->generate(), |
|
| 201 | + $this |
|
| 202 | + ); |
|
| 203 | + if ($this->verifyForm($form)) { |
|
| 204 | + $this->setForm($form); |
|
| 205 | + } |
|
| 206 | + return true; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param EE_Form_Section_Proper|null $form |
|
| 212 | + * @return bool |
|
| 213 | + * @throws LogicException |
|
| 214 | + */ |
|
| 215 | + public function verifyForm(EE_Form_Section_Proper $form = null) |
|
| 216 | + { |
|
| 217 | + $form = $form !== null ? $form : $this->form; |
|
| 218 | + if ($form instanceof EE_Form_Section_Proper) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + throw new LogicException( |
|
| 222 | + sprintf( |
|
| 223 | + esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'), |
|
| 224 | + $this->form_name, |
|
| 225 | + var_export($form, true) |
|
| 226 | + ) |
|
| 227 | + ); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param EE_Form_Section_Proper $form |
|
| 233 | + */ |
|
| 234 | + public function setForm(EE_Form_Section_Proper $form) |
|
| 235 | + { |
|
| 236 | + $this->form = $form; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @return boolean |
|
| 242 | + */ |
|
| 243 | + public function displayable() |
|
| 244 | + { |
|
| 245 | + return $this->displayable; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param boolean $displayable |
|
| 251 | + */ |
|
| 252 | + public function setDisplayable($displayable = false) |
|
| 253 | + { |
|
| 254 | + $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * a public name for the form that can be displayed on the frontend of a site |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function formName() |
|
| 264 | + { |
|
| 265 | + return $this->form_name; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param string $form_name |
|
| 271 | + * @throws InvalidDataTypeException |
|
| 272 | + */ |
|
| 273 | + public function setFormName($form_name) |
|
| 274 | + { |
|
| 275 | + if (! is_string($form_name)) { |
|
| 276 | + throw new InvalidDataTypeException('$form_name', $form_name, 'string'); |
|
| 277 | + } |
|
| 278 | + $this->form_name = $form_name; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * a public name for the form that can be displayed, but only in the admin |
|
| 284 | + * |
|
| 285 | + * @return string |
|
| 286 | + */ |
|
| 287 | + public function adminName() |
|
| 288 | + { |
|
| 289 | + return $this->admin_name; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param string $admin_name |
|
| 295 | + * @throws InvalidDataTypeException |
|
| 296 | + */ |
|
| 297 | + public function setAdminName($admin_name) |
|
| 298 | + { |
|
| 299 | + if (! is_string($admin_name)) { |
|
| 300 | + throw new InvalidDataTypeException('$admin_name', $admin_name, 'string'); |
|
| 301 | + } |
|
| 302 | + $this->admin_name = $admin_name; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * a URL friendly string that can be used for identifying the form |
|
| 308 | + * |
|
| 309 | + * @return string |
|
| 310 | + */ |
|
| 311 | + public function slug() |
|
| 312 | + { |
|
| 313 | + return $this->slug; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param string $slug |
|
| 319 | + * @throws InvalidDataTypeException |
|
| 320 | + */ |
|
| 321 | + public function setSlug($slug) |
|
| 322 | + { |
|
| 323 | + if (! is_string($slug)) { |
|
| 324 | + throw new InvalidDataTypeException('$slug', $slug, 'string'); |
|
| 325 | + } |
|
| 326 | + $this->slug = $slug; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function submitBtnText() |
|
| 334 | + { |
|
| 335 | + return $this->submit_btn_text; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * @param string $submit_btn_text |
|
| 341 | + * @throws InvalidDataTypeException |
|
| 342 | + * @throws InvalidArgumentException |
|
| 343 | + */ |
|
| 344 | + public function setSubmitBtnText($submit_btn_text) |
|
| 345 | + { |
|
| 346 | + if (! is_string($submit_btn_text)) { |
|
| 347 | + throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string'); |
|
| 348 | + } |
|
| 349 | + if (empty($submit_btn_text)) { |
|
| 350 | + throw new InvalidArgumentException( |
|
| 351 | + esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso') |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + $this->submit_btn_text = $submit_btn_text; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @return string |
|
| 360 | + */ |
|
| 361 | + public function formAction() |
|
| 362 | + { |
|
| 363 | + return ! empty($this->form_args) |
|
| 364 | + ? add_query_arg($this->form_args, $this->form_action) |
|
| 365 | + : $this->form_action; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param string $form_action |
|
| 371 | + * @throws InvalidDataTypeException |
|
| 372 | + */ |
|
| 373 | + public function setFormAction($form_action) |
|
| 374 | + { |
|
| 375 | + if (! is_string($form_action)) { |
|
| 376 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
| 377 | + } |
|
| 378 | + $this->form_action = $form_action; |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @param array $form_args |
|
| 384 | + * @throws InvalidDataTypeException |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + */ |
|
| 387 | + public function addFormActionArgs($form_args = array()) |
|
| 388 | + { |
|
| 389 | + if (is_object($form_args)) { |
|
| 390 | + throw new InvalidDataTypeException( |
|
| 391 | + '$form_args', |
|
| 392 | + $form_args, |
|
| 393 | + 'anything other than an object was expected.' |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + if (empty($form_args)) { |
|
| 397 | + throw new InvalidArgumentException( |
|
| 398 | + esc_html__('The redirect arguments can not be an empty array.', 'event_espresso') |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + $this->form_args = array_merge($this->form_args, $form_args); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * @return string |
|
| 407 | + */ |
|
| 408 | + public function formConfig() |
|
| 409 | + { |
|
| 410 | + return $this->form_config; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $form_config |
|
| 416 | + * @throws DomainException |
|
| 417 | + */ |
|
| 418 | + public function setFormConfig($form_config) |
|
| 419 | + { |
|
| 420 | + if (! in_array( |
|
| 421 | + $form_config, |
|
| 422 | + array( |
|
| 423 | + FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
| 424 | + FormHandler::ADD_FORM_TAGS_ONLY, |
|
| 425 | + FormHandler::ADD_FORM_SUBMIT_ONLY, |
|
| 426 | + FormHandler::DO_NOT_SETUP_FORM, |
|
| 427 | + ), |
|
| 428 | + true |
|
| 429 | + ) |
|
| 430 | + ) { |
|
| 431 | + throw new DomainException( |
|
| 432 | + sprintf( |
|
| 433 | + esc_html__( |
|
| 434 | + '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form', |
|
| 435 | + 'event_espresso' |
|
| 436 | + ), |
|
| 437 | + $form_config |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + } |
|
| 441 | + $this->form_config = $form_config; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * called after the form is instantiated |
|
| 447 | + * and used for performing any logic that needs to occur early |
|
| 448 | + * before any of the other methods are called. |
|
| 449 | + * returns true if everything is ok to proceed, |
|
| 450 | + * and false if no further form logic should be implemented |
|
| 451 | + * |
|
| 452 | + * @return boolean |
|
| 453 | + */ |
|
| 454 | + public function initialize() |
|
| 455 | + { |
|
| 456 | + $this->form_has_errors = EE_Error::has_error(true); |
|
| 457 | + return true; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * used for setting up css and js |
|
| 463 | + * |
|
| 464 | + * @return void |
|
| 465 | + * @throws LogicException |
|
| 466 | + * @throws EE_Error |
|
| 467 | + */ |
|
| 468 | + public function enqueueStylesAndScripts() |
|
| 469 | + { |
|
| 470 | + $this->form()->enqueue_js(); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * creates and returns the actual form |
|
| 476 | + * |
|
| 477 | + * @return EE_Form_Section_Proper |
|
| 478 | + */ |
|
| 479 | + abstract public function generate(); |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * creates and returns an EE_Submit_Input labeled "Submit" |
|
| 484 | + * |
|
| 485 | + * @param string $text |
|
| 486 | + * @return EE_Submit_Input |
|
| 487 | + */ |
|
| 488 | + public function generateSubmitButton($text = '') |
|
| 489 | + { |
|
| 490 | + $text = ! empty($text) ? $text : $this->submitBtnText(); |
|
| 491 | + return new EE_Submit_Input( |
|
| 492 | + array( |
|
| 493 | + 'html_name' => 'ee-form-submit-' . $this->slug(), |
|
| 494 | + 'html_id' => 'ee-form-submit-' . $this->slug(), |
|
| 495 | + 'html_class' => 'ee-form-submit', |
|
| 496 | + 'html_label' => ' ', |
|
| 497 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 498 | + 'default' => $text, |
|
| 499 | + ) |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * calls generateSubmitButton() and appends it onto the form along with a float clearing div |
|
| 506 | + * |
|
| 507 | + * @param string $text |
|
| 508 | + * @return void |
|
| 509 | + * @throws EE_Error |
|
| 510 | + */ |
|
| 511 | + public function appendSubmitButton($text = '') |
|
| 512 | + { |
|
| 513 | + if ($this->form->subsection_exists($this->slug() . '-submit-btn')) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + $this->form->add_subsections( |
|
| 517 | + array($this->slug() . '-submit-btn' => $this->generateSubmitButton($text)), |
|
| 518 | + null, |
|
| 519 | + false |
|
| 520 | + ); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * creates and returns an EE_Submit_Input labeled "Cancel" |
|
| 526 | + * |
|
| 527 | + * @param string $text |
|
| 528 | + * @return EE_Submit_Input |
|
| 529 | + */ |
|
| 530 | + public function generateCancelButton($text = '') |
|
| 531 | + { |
|
| 532 | + $cancel_button = new EE_Submit_Input( |
|
| 533 | + array( |
|
| 534 | + 'html_name' => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!! |
|
| 535 | + 'html_id' => 'ee-cancel-form-' . $this->slug(), |
|
| 536 | + 'html_class' => 'ee-cancel-form', |
|
| 537 | + 'html_label' => ' ', |
|
| 538 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
| 539 | + 'default' => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'), |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + $cancel_button->set_button_css_attributes(false); |
|
| 543 | + return $cancel_button; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * appends a float clearing div onto end of form |
|
| 549 | + * |
|
| 550 | + * @return void |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function clearFormButtonFloats() |
|
| 554 | + { |
|
| 555 | + $this->form->add_subsections( |
|
| 556 | + array( |
|
| 557 | + 'clear-submit-btn-float' => new EE_Form_Section_HTML( |
|
| 558 | + EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx() |
|
| 559 | + ), |
|
| 560 | + ), |
|
| 561 | + null, |
|
| 562 | + false |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * takes the generated form and displays it along with ony other non-form HTML that may be required |
|
| 569 | + * returns a string of HTML that can be directly echoed in a template |
|
| 570 | + * |
|
| 571 | + * @return string |
|
| 572 | + * @throws \InvalidArgumentException |
|
| 573 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 574 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 575 | + * @throws LogicException |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function display() |
|
| 579 | + { |
|
| 580 | + $form_html = apply_filters( |
|
| 581 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
|
| 582 | + '' |
|
| 583 | + ); |
|
| 584 | + $form_config = $this->formConfig(); |
|
| 585 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 586 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 587 | + ) { |
|
| 588 | + $additional_props = $this->requiresMultipartEnctype() |
|
| 589 | + ? 'enctype="multipart/form-data"' |
|
| 590 | + : ''; |
|
| 591 | + $form_html .= $this->form()->form_open( |
|
| 592 | + $this->formAction(), |
|
| 593 | + 'POST', |
|
| 594 | + $additional_props |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + $form_html .= $this->form(true)->get_html(); |
|
| 598 | + if ($form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT |
|
| 599 | + || $form_config === FormHandler::ADD_FORM_TAGS_ONLY |
|
| 600 | + ) { |
|
| 601 | + $form_html .= $this->form()->form_close(); |
|
| 602 | + } |
|
| 603 | + $form_html .= apply_filters( |
|
| 604 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form', |
|
| 605 | + '' |
|
| 606 | + ); |
|
| 607 | + return $form_html; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Determines if this form needs "enctype='multipart/form-data'" or not. |
|
| 612 | + * @since 4.9.80.p |
|
| 613 | + * @return bool |
|
| 614 | + * @throws EE_Error |
|
| 615 | + */ |
|
| 616 | + public function requiresMultipartEnctype() |
|
| 617 | + { |
|
| 618 | + foreach ($this->form()->inputs_in_subsections() as $input) { |
|
| 619 | + if ($input instanceof EE_File_Input) { |
|
| 620 | + return true; |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + return false; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * handles processing the form submission |
|
| 629 | + * returns true or false depending on whether the form was processed successfully or not |
|
| 630 | + * |
|
| 631 | + * @param array $submitted_form_data |
|
| 632 | + * @return array |
|
| 633 | + * @throws \InvalidArgumentException |
|
| 634 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 635 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 636 | + * @throws EE_Error |
|
| 637 | + * @throws LogicException |
|
| 638 | + * @throws InvalidFormSubmissionException |
|
| 639 | + */ |
|
| 640 | + public function process($submitted_form_data = array()) |
|
| 641 | + { |
|
| 642 | + if (! $this->form()->was_submitted($submitted_form_data)) { |
|
| 643 | + throw new InvalidFormSubmissionException($this->form_name); |
|
| 644 | + } |
|
| 645 | + $this->form(true)->receive_form_submission($submitted_form_data); |
|
| 646 | + if (! $this->form()->is_valid()) { |
|
| 647 | + throw new InvalidFormSubmissionException( |
|
| 648 | + $this->form_name, |
|
| 649 | + sprintf( |
|
| 650 | + esc_html__( |
|
| 651 | + 'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s', |
|
| 652 | + 'event_espresso' |
|
| 653 | + ), |
|
| 654 | + $this->form_name, |
|
| 655 | + '<br />', |
|
| 656 | + implode('<br />', $this->form()->get_validation_errors_accumulated()) |
|
| 657 | + ) |
|
| 658 | + ); |
|
| 659 | + } |
|
| 660 | + return apply_filters( |
|
| 661 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data', |
|
| 662 | + $this->form()->valid_data(), |
|
| 663 | + $this |
|
| 664 | + ); |
|
| 665 | + } |
|
| 666 | 666 | } |
@@ -13,133 +13,133 @@ |
||
| 13 | 13 | class EEM_WP_User extends EEM_Base |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * private instance of the EEM_WP_User object |
|
| 18 | - * |
|
| 19 | - * @type EEM_WP_User |
|
| 20 | - */ |
|
| 21 | - protected static $_instance; |
|
| 16 | + /** |
|
| 17 | + * private instance of the EEM_WP_User object |
|
| 18 | + * |
|
| 19 | + * @type EEM_WP_User |
|
| 20 | + */ |
|
| 21 | + protected static $_instance; |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * constructor |
|
| 26 | - * |
|
| 27 | - * @param null $timezone |
|
| 28 | - * @param ModelFieldFactory $model_field_factory |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws InvalidArgumentException |
|
| 31 | - */ |
|
| 32 | - protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 33 | - { |
|
| 34 | - $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
| 35 | - $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
| 36 | - global $wpdb; |
|
| 37 | - $this->_tables = array( |
|
| 38 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
| 39 | - ); |
|
| 40 | - $this->_fields = array( |
|
| 41 | - 'WP_User' => array( |
|
| 42 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 43 | - 'ID', |
|
| 44 | - esc_html__('WP_User ID', 'event_espresso') |
|
| 45 | - ), |
|
| 46 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
| 47 | - 'user_login', |
|
| 48 | - esc_html__('User Login', 'event_espresso'), |
|
| 49 | - false |
|
| 50 | - ), |
|
| 51 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
| 52 | - 'user_pass', |
|
| 53 | - esc_html__('User Password', 'event_espresso'), |
|
| 54 | - false |
|
| 55 | - ), |
|
| 56 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
| 57 | - 'user_nicename', |
|
| 58 | - esc_html__(' User Nice Name', 'event_espresso'), |
|
| 59 | - false |
|
| 60 | - ), |
|
| 61 | - 'user_email' => $model_field_factory->createEmailField( |
|
| 62 | - 'user_email', |
|
| 63 | - esc_html__('User Email', 'event_espresso'), |
|
| 64 | - false, |
|
| 65 | - null |
|
| 66 | - ), |
|
| 67 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
| 68 | - 'user_registered', |
|
| 69 | - esc_html__('Date User Registered', 'event_espresso'), |
|
| 70 | - $timezone |
|
| 71 | - ), |
|
| 72 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
| 73 | - 'user_activation_key', |
|
| 74 | - esc_html__('User Activation Key', 'event_espresso'), |
|
| 75 | - false |
|
| 76 | - ), |
|
| 77 | - 'user_status' => $model_field_factory->createIntegerField( |
|
| 78 | - 'user_status', |
|
| 79 | - esc_html__('User Status', 'event_espresso') |
|
| 80 | - ), |
|
| 81 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
| 82 | - 'display_name', |
|
| 83 | - esc_html__('Display Name', 'event_espresso'), |
|
| 84 | - false |
|
| 85 | - ), |
|
| 86 | - ), |
|
| 87 | - ); |
|
| 88 | - $this->_model_relations = array( |
|
| 89 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
| 90 | - // all models are related to the change log |
|
| 91 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
| 92 | - 'Event' => new EE_Has_Many_Relation(), |
|
| 93 | - 'Message' => new EE_Has_Many_Relation(), |
|
| 94 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
| 95 | - 'Price' => new EE_Has_Many_Relation(), |
|
| 96 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
| 97 | - 'Question' => new EE_Has_Many_Relation(), |
|
| 98 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
| 99 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
| 100 | - 'Venue' => new EE_Has_Many_Relation(), |
|
| 101 | - ); |
|
| 102 | - $this->foreign_key_aliases = [ |
|
| 103 | - 'Event.EVT_wp_user' => 'WP_User.ID', |
|
| 104 | - 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
| 105 | - 'Price.PRC_wp_user' => 'WP_User.ID', |
|
| 106 | - 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
| 107 | - 'Question.QST_wp_user' => 'WP_User.ID', |
|
| 108 | - 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
| 109 | - 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
| 110 | - 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
| 111 | - ]; |
|
| 112 | - $this->_wp_core_model = true; |
|
| 113 | - $this->_caps_slug = 'users'; |
|
| 114 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
| 115 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
| 116 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 117 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
| 118 | - } |
|
| 119 | - // @todo: account for create_users controls whether they can create users at all |
|
| 120 | - parent::__construct($timezone); |
|
| 121 | - } |
|
| 24 | + /** |
|
| 25 | + * constructor |
|
| 26 | + * |
|
| 27 | + * @param null $timezone |
|
| 28 | + * @param ModelFieldFactory $model_field_factory |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws InvalidArgumentException |
|
| 31 | + */ |
|
| 32 | + protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 33 | + { |
|
| 34 | + $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
| 35 | + $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
| 36 | + global $wpdb; |
|
| 37 | + $this->_tables = array( |
|
| 38 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
| 39 | + ); |
|
| 40 | + $this->_fields = array( |
|
| 41 | + 'WP_User' => array( |
|
| 42 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 43 | + 'ID', |
|
| 44 | + esc_html__('WP_User ID', 'event_espresso') |
|
| 45 | + ), |
|
| 46 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
| 47 | + 'user_login', |
|
| 48 | + esc_html__('User Login', 'event_espresso'), |
|
| 49 | + false |
|
| 50 | + ), |
|
| 51 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
| 52 | + 'user_pass', |
|
| 53 | + esc_html__('User Password', 'event_espresso'), |
|
| 54 | + false |
|
| 55 | + ), |
|
| 56 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
| 57 | + 'user_nicename', |
|
| 58 | + esc_html__(' User Nice Name', 'event_espresso'), |
|
| 59 | + false |
|
| 60 | + ), |
|
| 61 | + 'user_email' => $model_field_factory->createEmailField( |
|
| 62 | + 'user_email', |
|
| 63 | + esc_html__('User Email', 'event_espresso'), |
|
| 64 | + false, |
|
| 65 | + null |
|
| 66 | + ), |
|
| 67 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
| 68 | + 'user_registered', |
|
| 69 | + esc_html__('Date User Registered', 'event_espresso'), |
|
| 70 | + $timezone |
|
| 71 | + ), |
|
| 72 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
| 73 | + 'user_activation_key', |
|
| 74 | + esc_html__('User Activation Key', 'event_espresso'), |
|
| 75 | + false |
|
| 76 | + ), |
|
| 77 | + 'user_status' => $model_field_factory->createIntegerField( |
|
| 78 | + 'user_status', |
|
| 79 | + esc_html__('User Status', 'event_espresso') |
|
| 80 | + ), |
|
| 81 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
| 82 | + 'display_name', |
|
| 83 | + esc_html__('Display Name', 'event_espresso'), |
|
| 84 | + false |
|
| 85 | + ), |
|
| 86 | + ), |
|
| 87 | + ); |
|
| 88 | + $this->_model_relations = array( |
|
| 89 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
| 90 | + // all models are related to the change log |
|
| 91 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
| 92 | + 'Event' => new EE_Has_Many_Relation(), |
|
| 93 | + 'Message' => new EE_Has_Many_Relation(), |
|
| 94 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
| 95 | + 'Price' => new EE_Has_Many_Relation(), |
|
| 96 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
| 97 | + 'Question' => new EE_Has_Many_Relation(), |
|
| 98 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
| 99 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
| 100 | + 'Venue' => new EE_Has_Many_Relation(), |
|
| 101 | + ); |
|
| 102 | + $this->foreign_key_aliases = [ |
|
| 103 | + 'Event.EVT_wp_user' => 'WP_User.ID', |
|
| 104 | + 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
| 105 | + 'Price.PRC_wp_user' => 'WP_User.ID', |
|
| 106 | + 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
| 107 | + 'Question.QST_wp_user' => 'WP_User.ID', |
|
| 108 | + 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
| 109 | + 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
| 110 | + 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
| 111 | + ]; |
|
| 112 | + $this->_wp_core_model = true; |
|
| 113 | + $this->_caps_slug = 'users'; |
|
| 114 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
| 115 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
| 116 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 117 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
| 118 | + } |
|
| 119 | + // @todo: account for create_users controls whether they can create users at all |
|
| 120 | + parent::__construct($timezone); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - * @throws EE_Error |
|
| 129 | - */ |
|
| 130 | - public function wp_user_field_name() |
|
| 131 | - { |
|
| 132 | - return $this->primary_key_name(); |
|
| 133 | - } |
|
| 124 | + /** |
|
| 125 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + * @throws EE_Error |
|
| 129 | + */ |
|
| 130 | + public function wp_user_field_name() |
|
| 131 | + { |
|
| 132 | + return $this->primary_key_name(); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
| 138 | - * |
|
| 139 | - * @return boolean |
|
| 140 | - */ |
|
| 141 | - public function is_owned() |
|
| 142 | - { |
|
| 143 | - return true; |
|
| 144 | - } |
|
| 136 | + /** |
|
| 137 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
| 138 | + * |
|
| 139 | + * @return boolean |
|
| 140 | + */ |
|
| 141 | + public function is_owned() |
|
| 142 | + { |
|
| 143 | + return true; |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -12,432 +12,432 @@ |
||
| 12 | 12 | class EEM_Attendee extends EEM_CPT_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - // private instance of the Attendee object |
|
| 16 | - protected static $_instance = null; |
|
| 15 | + // private instance of the Attendee object |
|
| 16 | + protected static $_instance = null; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * QST_system for questions are strings not integers now, |
|
| 20 | - * so these constants are deprecated. |
|
| 21 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
| 22 | - * |
|
| 23 | - * @deprecated |
|
| 24 | - */ |
|
| 25 | - const fname_question_id = 1; |
|
| 18 | + /** |
|
| 19 | + * QST_system for questions are strings not integers now, |
|
| 20 | + * so these constants are deprecated. |
|
| 21 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
| 22 | + * |
|
| 23 | + * @deprecated |
|
| 24 | + */ |
|
| 25 | + const fname_question_id = 1; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @deprecated |
|
| 29 | - */ |
|
| 30 | - const lname_question_id = 2; |
|
| 27 | + /** |
|
| 28 | + * @deprecated |
|
| 29 | + */ |
|
| 30 | + const lname_question_id = 2; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @deprecated |
|
| 35 | - */ |
|
| 36 | - const email_question_id = 3; |
|
| 33 | + /** |
|
| 34 | + * @deprecated |
|
| 35 | + */ |
|
| 36 | + const email_question_id = 3; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @deprecated |
|
| 41 | - */ |
|
| 42 | - const address_question_id = 4; |
|
| 39 | + /** |
|
| 40 | + * @deprecated |
|
| 41 | + */ |
|
| 42 | + const address_question_id = 4; |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @deprecated |
|
| 47 | - */ |
|
| 48 | - const address2_question_id = 5; |
|
| 45 | + /** |
|
| 46 | + * @deprecated |
|
| 47 | + */ |
|
| 48 | + const address2_question_id = 5; |
|
| 49 | 49 | |
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @deprecated |
|
| 53 | - */ |
|
| 54 | - const city_question_id = 6; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @deprecated |
|
| 59 | - */ |
|
| 60 | - const state_question_id = 7; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @deprecated |
|
| 65 | - */ |
|
| 66 | - const country_question_id = 8; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @deprecated |
|
| 71 | - */ |
|
| 72 | - const zip_question_id = 9; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @deprecated |
|
| 77 | - */ |
|
| 78 | - const phone_question_id = 10; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * When looking for questions that correspond to attendee fields, |
|
| 82 | - * look for the question with this QST_system value. |
|
| 83 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
| 84 | - */ |
|
| 85 | - const system_question_fname = 'fname'; |
|
| 86 | - |
|
| 87 | - const system_question_lname = 'lname'; |
|
| 88 | - |
|
| 89 | - const system_question_email = 'email'; |
|
| 90 | - |
|
| 91 | - const system_question_email_confirm = 'email_confirm'; |
|
| 92 | - |
|
| 93 | - const system_question_address = 'address'; |
|
| 94 | - |
|
| 95 | - const system_question_address2 = 'address2'; |
|
| 96 | - |
|
| 97 | - const system_question_city = 'city'; |
|
| 98 | - |
|
| 99 | - const system_question_state = 'state'; |
|
| 100 | - |
|
| 101 | - const system_question_country = 'country'; |
|
| 102 | - |
|
| 103 | - const system_question_zip = 'zip'; |
|
| 104 | - |
|
| 105 | - const system_question_phone = 'phone'; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 109 | - * also all the values of QST_system in the questions table, and values |
|
| 110 | - * are their corresponding Attendee field names |
|
| 111 | - * |
|
| 112 | - * @var array |
|
| 113 | - */ |
|
| 114 | - protected $_system_question_to_attendee_field_name = array( |
|
| 115 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 116 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 117 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
| 118 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
| 119 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 120 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
| 121 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
| 122 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 123 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 124 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * EEM_Attendee constructor. |
|
| 131 | - * |
|
| 132 | - * @param null $timezone |
|
| 133 | - * @param ModelFieldFactory $model_field_factory |
|
| 134 | - * @throws EE_Error |
|
| 135 | - * @throws InvalidArgumentException |
|
| 136 | - */ |
|
| 137 | - protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 138 | - { |
|
| 139 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 140 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 141 | - $this->_tables = array( |
|
| 142 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 143 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 144 | - 'esp_attendee_meta', |
|
| 145 | - 'ATTM_ID', |
|
| 146 | - 'ATT_ID' |
|
| 147 | - ), |
|
| 148 | - ); |
|
| 149 | - $this->_fields = array( |
|
| 150 | - 'Attendee_CPT' => array( |
|
| 151 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 152 | - 'ID', |
|
| 153 | - esc_html__('Attendee ID', 'event_espresso') |
|
| 154 | - ), |
|
| 155 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 156 | - 'post_title', |
|
| 157 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 158 | - false, |
|
| 159 | - esc_html__('Unknown', 'event_espresso') |
|
| 160 | - ), |
|
| 161 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 162 | - 'post_content', |
|
| 163 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
| 164 | - false, |
|
| 165 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 166 | - ), |
|
| 167 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 168 | - 'post_name', |
|
| 169 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 170 | - ), |
|
| 171 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 172 | - 'post_date', |
|
| 173 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
| 174 | - ), |
|
| 175 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 176 | - 'post_excerpt', |
|
| 177 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 178 | - true, |
|
| 179 | - esc_html__('No Biography Provided', 'event_espresso') |
|
| 180 | - ), |
|
| 181 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 182 | - 'post_modified', |
|
| 183 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 184 | - ), |
|
| 185 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 186 | - 'post_author', |
|
| 187 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 188 | - false |
|
| 189 | - ), |
|
| 190 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 191 | - 'post_parent', |
|
| 192 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 193 | - false, |
|
| 194 | - 0 |
|
| 195 | - ), |
|
| 196 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 197 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
| 198 | - 'post_status', |
|
| 199 | - esc_html__('Attendee Status', 'event_espresso'), |
|
| 200 | - false, |
|
| 201 | - 'publish' |
|
| 202 | - ), |
|
| 203 | - 'password' => new EE_Password_Field( |
|
| 204 | - 'post_password', |
|
| 205 | - __('Password', 'event_espresso'), |
|
| 206 | - false, |
|
| 207 | - '', |
|
| 208 | - array( |
|
| 209 | - 'ATT_bio', |
|
| 210 | - 'ATT_short_bio', |
|
| 211 | - 'ATT_address', |
|
| 212 | - 'ATT_address2', |
|
| 213 | - 'ATT_city', |
|
| 214 | - 'STA_ID', |
|
| 215 | - 'CNT_ISO', |
|
| 216 | - 'ATT_zip', |
|
| 217 | - 'ATT_email', |
|
| 218 | - 'ATT_phone' |
|
| 219 | - ) |
|
| 220 | - ) |
|
| 221 | - ), |
|
| 222 | - 'Attendee_Meta' => array( |
|
| 223 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 224 | - 'ATTM_ID', |
|
| 225 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 226 | - false |
|
| 227 | - ), |
|
| 228 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 229 | - 'ATT_ID', |
|
| 230 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 231 | - false |
|
| 232 | - ), |
|
| 233 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 234 | - 'ATT_fname', |
|
| 235 | - esc_html__('First Name', 'event_espresso') |
|
| 236 | - ), |
|
| 237 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 238 | - 'ATT_lname', |
|
| 239 | - esc_html__('Last Name', 'event_espresso') |
|
| 240 | - ), |
|
| 241 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 242 | - 'ATT_address', |
|
| 243 | - esc_html__('Address Part 1', 'event_espresso') |
|
| 244 | - ), |
|
| 245 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 246 | - 'ATT_address2', |
|
| 247 | - esc_html__('Address Part 2', 'event_espresso') |
|
| 248 | - ), |
|
| 249 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 250 | - 'ATT_city', |
|
| 251 | - esc_html__('City', 'event_espresso') |
|
| 252 | - ), |
|
| 253 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 254 | - 'STA_ID', |
|
| 255 | - esc_html__('State', 'event_espresso'), |
|
| 256 | - true, |
|
| 257 | - 0, |
|
| 258 | - 'State' |
|
| 259 | - ), |
|
| 260 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 261 | - 'CNT_ISO', |
|
| 262 | - esc_html__('Country', 'event_espresso'), |
|
| 263 | - true, |
|
| 264 | - '', |
|
| 265 | - 'Country' |
|
| 266 | - ), |
|
| 267 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 268 | - 'ATT_zip', |
|
| 269 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 270 | - ), |
|
| 271 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
| 272 | - 'ATT_email', |
|
| 273 | - esc_html__('Email Address', 'event_espresso') |
|
| 274 | - ), |
|
| 275 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 276 | - 'ATT_phone', |
|
| 277 | - esc_html__('Phone', 'event_espresso') |
|
| 278 | - ), |
|
| 279 | - ), |
|
| 280 | - ); |
|
| 281 | - $this->_model_relations = array( |
|
| 282 | - 'Registration' => new EE_Has_Many_Relation(), |
|
| 283 | - 'State' => new EE_Belongs_To_Relation(), |
|
| 284 | - 'Country' => new EE_Belongs_To_Relation(), |
|
| 285 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 286 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 287 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 288 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
| 289 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 290 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 291 | - ); |
|
| 292 | - $this->_caps_slug = 'contacts'; |
|
| 293 | - $this->model_chain_to_password = ''; |
|
| 294 | - parent::__construct($timezone); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 301 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 302 | - * |
|
| 303 | - * @param string $system_question_string |
|
| 304 | - * @return string|null if not found |
|
| 305 | - */ |
|
| 306 | - public function get_attendee_field_for_system_question($system_question_string) |
|
| 307 | - { |
|
| 308 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
| 309 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
| 310 | - : null; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 317 | - * |
|
| 318 | - * @return array |
|
| 319 | - */ |
|
| 320 | - public function system_question_to_attendee_field_mapping() |
|
| 321 | - { |
|
| 322 | - return $this->_system_question_to_attendee_field_name; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 329 | - * |
|
| 330 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 331 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 332 | - * @throws EE_Error |
|
| 333 | - */ |
|
| 334 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 335 | - { |
|
| 336 | - return $this->get_all( |
|
| 337 | - array( |
|
| 338 | - array( |
|
| 339 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 340 | - ? $transaction_id_or_obj->ID() |
|
| 341 | - : $transaction_id_or_obj, |
|
| 342 | - ), |
|
| 343 | - ) |
|
| 344 | - ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * retrieve a single attendee from db via their ID |
|
| 351 | - * |
|
| 352 | - * @param $ATT_ID |
|
| 353 | - * @return mixed array on success, FALSE on fail |
|
| 354 | - * @deprecated |
|
| 355 | - */ |
|
| 356 | - public function get_attendee_by_ID($ATT_ID = false) |
|
| 357 | - { |
|
| 358 | - // retrieve a particular EE_Attendee |
|
| 359 | - return $this->get_one_by_ID($ATT_ID); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * retrieve a single attendee from db via their ID |
|
| 366 | - * |
|
| 367 | - * @param array $where_cols_n_values |
|
| 368 | - * @return mixed array on success, FALSE on fail |
|
| 369 | - * @throws EE_Error |
|
| 370 | - */ |
|
| 371 | - public function get_attendee($where_cols_n_values = array()) |
|
| 372 | - { |
|
| 373 | - if (empty($where_cols_n_values)) { |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 377 | - if (! empty($attendee)) { |
|
| 378 | - return array_shift($attendee); |
|
| 379 | - } |
|
| 380 | - return false; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Search for an existing Attendee record in the DB |
|
| 387 | - * |
|
| 388 | - * @param array $where_cols_n_values |
|
| 389 | - * @return bool|mixed |
|
| 390 | - * @throws EE_Error |
|
| 391 | - */ |
|
| 392 | - public function find_existing_attendee($where_cols_n_values = null) |
|
| 393 | - { |
|
| 394 | - // search by combo of first and last names plus the email address |
|
| 395 | - $attendee_data_keys = array( |
|
| 396 | - 'ATT_fname' => $this->_ATT_fname, |
|
| 397 | - 'ATT_lname' => $this->_ATT_lname, |
|
| 398 | - 'ATT_email' => $this->_ATT_email, |
|
| 399 | - ); |
|
| 400 | - // no search params means attendee object already exists. |
|
| 401 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 402 | - ? $where_cols_n_values |
|
| 403 | - : $attendee_data_keys; |
|
| 404 | - $valid_data = true; |
|
| 405 | - // check for required values |
|
| 406 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 407 | - ? $valid_data |
|
| 408 | - : false; |
|
| 409 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 410 | - ? $valid_data |
|
| 411 | - : false; |
|
| 412 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 413 | - ? $valid_data |
|
| 414 | - : false; |
|
| 415 | - if ($valid_data) { |
|
| 416 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
| 417 | - if ($attendee instanceof EE_Attendee) { |
|
| 418 | - return $attendee; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Takes an incoming array of EE_Registration ids |
|
| 428 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 429 | - * |
|
| 430 | - * @since 4.3.0 |
|
| 431 | - * @param array $ids array of EE_Registration ids |
|
| 432 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
| 433 | - * @throws EE_Error |
|
| 434 | - */ |
|
| 435 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
| 436 | - { |
|
| 437 | - $ids = (array) $ids; |
|
| 438 | - $_where = array( |
|
| 439 | - 'Registration.REG_ID' => array('in', $ids), |
|
| 440 | - ); |
|
| 441 | - return $this->get_all(array($_where)); |
|
| 442 | - } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @deprecated |
|
| 53 | + */ |
|
| 54 | + const city_question_id = 6; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @deprecated |
|
| 59 | + */ |
|
| 60 | + const state_question_id = 7; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @deprecated |
|
| 65 | + */ |
|
| 66 | + const country_question_id = 8; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @deprecated |
|
| 71 | + */ |
|
| 72 | + const zip_question_id = 9; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @deprecated |
|
| 77 | + */ |
|
| 78 | + const phone_question_id = 10; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * When looking for questions that correspond to attendee fields, |
|
| 82 | + * look for the question with this QST_system value. |
|
| 83 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
| 84 | + */ |
|
| 85 | + const system_question_fname = 'fname'; |
|
| 86 | + |
|
| 87 | + const system_question_lname = 'lname'; |
|
| 88 | + |
|
| 89 | + const system_question_email = 'email'; |
|
| 90 | + |
|
| 91 | + const system_question_email_confirm = 'email_confirm'; |
|
| 92 | + |
|
| 93 | + const system_question_address = 'address'; |
|
| 94 | + |
|
| 95 | + const system_question_address2 = 'address2'; |
|
| 96 | + |
|
| 97 | + const system_question_city = 'city'; |
|
| 98 | + |
|
| 99 | + const system_question_state = 'state'; |
|
| 100 | + |
|
| 101 | + const system_question_country = 'country'; |
|
| 102 | + |
|
| 103 | + const system_question_zip = 'zip'; |
|
| 104 | + |
|
| 105 | + const system_question_phone = 'phone'; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
| 109 | + * also all the values of QST_system in the questions table, and values |
|
| 110 | + * are their corresponding Attendee field names |
|
| 111 | + * |
|
| 112 | + * @var array |
|
| 113 | + */ |
|
| 114 | + protected $_system_question_to_attendee_field_name = array( |
|
| 115 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
| 116 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
| 117 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
| 118 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
| 119 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
| 120 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
| 121 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
| 122 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
| 123 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
| 124 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * EEM_Attendee constructor. |
|
| 131 | + * |
|
| 132 | + * @param null $timezone |
|
| 133 | + * @param ModelFieldFactory $model_field_factory |
|
| 134 | + * @throws EE_Error |
|
| 135 | + * @throws InvalidArgumentException |
|
| 136 | + */ |
|
| 137 | + protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
| 138 | + { |
|
| 139 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
| 140 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
| 141 | + $this->_tables = array( |
|
| 142 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
| 143 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
| 144 | + 'esp_attendee_meta', |
|
| 145 | + 'ATTM_ID', |
|
| 146 | + 'ATT_ID' |
|
| 147 | + ), |
|
| 148 | + ); |
|
| 149 | + $this->_fields = array( |
|
| 150 | + 'Attendee_CPT' => array( |
|
| 151 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
| 152 | + 'ID', |
|
| 153 | + esc_html__('Attendee ID', 'event_espresso') |
|
| 154 | + ), |
|
| 155 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
| 156 | + 'post_title', |
|
| 157 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
| 158 | + false, |
|
| 159 | + esc_html__('Unknown', 'event_espresso') |
|
| 160 | + ), |
|
| 161 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
| 162 | + 'post_content', |
|
| 163 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
| 164 | + false, |
|
| 165 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 166 | + ), |
|
| 167 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
| 168 | + 'post_name', |
|
| 169 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
| 170 | + ), |
|
| 171 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
| 172 | + 'post_date', |
|
| 173 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
| 174 | + ), |
|
| 175 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
| 176 | + 'post_excerpt', |
|
| 177 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
| 178 | + true, |
|
| 179 | + esc_html__('No Biography Provided', 'event_espresso') |
|
| 180 | + ), |
|
| 181 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
| 182 | + 'post_modified', |
|
| 183 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
| 184 | + ), |
|
| 185 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
| 186 | + 'post_author', |
|
| 187 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
| 188 | + false |
|
| 189 | + ), |
|
| 190 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
| 191 | + 'post_parent', |
|
| 192 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
| 193 | + false, |
|
| 194 | + 0 |
|
| 195 | + ), |
|
| 196 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
| 197 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
| 198 | + 'post_status', |
|
| 199 | + esc_html__('Attendee Status', 'event_espresso'), |
|
| 200 | + false, |
|
| 201 | + 'publish' |
|
| 202 | + ), |
|
| 203 | + 'password' => new EE_Password_Field( |
|
| 204 | + 'post_password', |
|
| 205 | + __('Password', 'event_espresso'), |
|
| 206 | + false, |
|
| 207 | + '', |
|
| 208 | + array( |
|
| 209 | + 'ATT_bio', |
|
| 210 | + 'ATT_short_bio', |
|
| 211 | + 'ATT_address', |
|
| 212 | + 'ATT_address2', |
|
| 213 | + 'ATT_city', |
|
| 214 | + 'STA_ID', |
|
| 215 | + 'CNT_ISO', |
|
| 216 | + 'ATT_zip', |
|
| 217 | + 'ATT_email', |
|
| 218 | + 'ATT_phone' |
|
| 219 | + ) |
|
| 220 | + ) |
|
| 221 | + ), |
|
| 222 | + 'Attendee_Meta' => array( |
|
| 223 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
| 224 | + 'ATTM_ID', |
|
| 225 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
| 226 | + false |
|
| 227 | + ), |
|
| 228 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
| 229 | + 'ATT_ID', |
|
| 230 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
| 231 | + false |
|
| 232 | + ), |
|
| 233 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
| 234 | + 'ATT_fname', |
|
| 235 | + esc_html__('First Name', 'event_espresso') |
|
| 236 | + ), |
|
| 237 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
| 238 | + 'ATT_lname', |
|
| 239 | + esc_html__('Last Name', 'event_espresso') |
|
| 240 | + ), |
|
| 241 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
| 242 | + 'ATT_address', |
|
| 243 | + esc_html__('Address Part 1', 'event_espresso') |
|
| 244 | + ), |
|
| 245 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
| 246 | + 'ATT_address2', |
|
| 247 | + esc_html__('Address Part 2', 'event_espresso') |
|
| 248 | + ), |
|
| 249 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
| 250 | + 'ATT_city', |
|
| 251 | + esc_html__('City', 'event_espresso') |
|
| 252 | + ), |
|
| 253 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
| 254 | + 'STA_ID', |
|
| 255 | + esc_html__('State', 'event_espresso'), |
|
| 256 | + true, |
|
| 257 | + 0, |
|
| 258 | + 'State' |
|
| 259 | + ), |
|
| 260 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
| 261 | + 'CNT_ISO', |
|
| 262 | + esc_html__('Country', 'event_espresso'), |
|
| 263 | + true, |
|
| 264 | + '', |
|
| 265 | + 'Country' |
|
| 266 | + ), |
|
| 267 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
| 268 | + 'ATT_zip', |
|
| 269 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
| 270 | + ), |
|
| 271 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
| 272 | + 'ATT_email', |
|
| 273 | + esc_html__('Email Address', 'event_espresso') |
|
| 274 | + ), |
|
| 275 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
| 276 | + 'ATT_phone', |
|
| 277 | + esc_html__('Phone', 'event_espresso') |
|
| 278 | + ), |
|
| 279 | + ), |
|
| 280 | + ); |
|
| 281 | + $this->_model_relations = array( |
|
| 282 | + 'Registration' => new EE_Has_Many_Relation(), |
|
| 283 | + 'State' => new EE_Belongs_To_Relation(), |
|
| 284 | + 'Country' => new EE_Belongs_To_Relation(), |
|
| 285 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
| 286 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 287 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
| 288 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
| 289 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
| 290 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
| 291 | + ); |
|
| 292 | + $this->_caps_slug = 'contacts'; |
|
| 293 | + $this->model_chain_to_password = ''; |
|
| 294 | + parent::__construct($timezone); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
| 301 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
| 302 | + * |
|
| 303 | + * @param string $system_question_string |
|
| 304 | + * @return string|null if not found |
|
| 305 | + */ |
|
| 306 | + public function get_attendee_field_for_system_question($system_question_string) |
|
| 307 | + { |
|
| 308 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
| 309 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
| 310 | + : null; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
| 317 | + * |
|
| 318 | + * @return array |
|
| 319 | + */ |
|
| 320 | + public function system_question_to_attendee_field_mapping() |
|
| 321 | + { |
|
| 322 | + return $this->_system_question_to_attendee_field_name; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
| 329 | + * |
|
| 330 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
| 331 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 332 | + * @throws EE_Error |
|
| 333 | + */ |
|
| 334 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
| 335 | + { |
|
| 336 | + return $this->get_all( |
|
| 337 | + array( |
|
| 338 | + array( |
|
| 339 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
| 340 | + ? $transaction_id_or_obj->ID() |
|
| 341 | + : $transaction_id_or_obj, |
|
| 342 | + ), |
|
| 343 | + ) |
|
| 344 | + ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * retrieve a single attendee from db via their ID |
|
| 351 | + * |
|
| 352 | + * @param $ATT_ID |
|
| 353 | + * @return mixed array on success, FALSE on fail |
|
| 354 | + * @deprecated |
|
| 355 | + */ |
|
| 356 | + public function get_attendee_by_ID($ATT_ID = false) |
|
| 357 | + { |
|
| 358 | + // retrieve a particular EE_Attendee |
|
| 359 | + return $this->get_one_by_ID($ATT_ID); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * retrieve a single attendee from db via their ID |
|
| 366 | + * |
|
| 367 | + * @param array $where_cols_n_values |
|
| 368 | + * @return mixed array on success, FALSE on fail |
|
| 369 | + * @throws EE_Error |
|
| 370 | + */ |
|
| 371 | + public function get_attendee($where_cols_n_values = array()) |
|
| 372 | + { |
|
| 373 | + if (empty($where_cols_n_values)) { |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
| 377 | + if (! empty($attendee)) { |
|
| 378 | + return array_shift($attendee); |
|
| 379 | + } |
|
| 380 | + return false; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Search for an existing Attendee record in the DB |
|
| 387 | + * |
|
| 388 | + * @param array $where_cols_n_values |
|
| 389 | + * @return bool|mixed |
|
| 390 | + * @throws EE_Error |
|
| 391 | + */ |
|
| 392 | + public function find_existing_attendee($where_cols_n_values = null) |
|
| 393 | + { |
|
| 394 | + // search by combo of first and last names plus the email address |
|
| 395 | + $attendee_data_keys = array( |
|
| 396 | + 'ATT_fname' => $this->_ATT_fname, |
|
| 397 | + 'ATT_lname' => $this->_ATT_lname, |
|
| 398 | + 'ATT_email' => $this->_ATT_email, |
|
| 399 | + ); |
|
| 400 | + // no search params means attendee object already exists. |
|
| 401 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
| 402 | + ? $where_cols_n_values |
|
| 403 | + : $attendee_data_keys; |
|
| 404 | + $valid_data = true; |
|
| 405 | + // check for required values |
|
| 406 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
| 407 | + ? $valid_data |
|
| 408 | + : false; |
|
| 409 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
| 410 | + ? $valid_data |
|
| 411 | + : false; |
|
| 412 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
| 413 | + ? $valid_data |
|
| 414 | + : false; |
|
| 415 | + if ($valid_data) { |
|
| 416 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
| 417 | + if ($attendee instanceof EE_Attendee) { |
|
| 418 | + return $attendee; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Takes an incoming array of EE_Registration ids |
|
| 428 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
| 429 | + * |
|
| 430 | + * @since 4.3.0 |
|
| 431 | + * @param array $ids array of EE_Registration ids |
|
| 432 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
| 433 | + * @throws EE_Error |
|
| 434 | + */ |
|
| 435 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
| 436 | + { |
|
| 437 | + $ids = (array) $ids; |
|
| 438 | + $_where = array( |
|
| 439 | + 'Registration.REG_ID' => array('in', $ids), |
|
| 440 | + ); |
|
| 441 | + return $this->get_all(array($_where)); |
|
| 442 | + } |
|
| 443 | 443 | } |
@@ -20,1056 +20,1056 @@ |
||
| 20 | 20 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - const debug = false; |
|
| 24 | - |
|
| 25 | - private static $nl = ''; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
| 29 | - * |
|
| 30 | - * @var array $ticket_selections |
|
| 31 | - */ |
|
| 32 | - protected $ticket_selections = array(); |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 36 | - * according to how they are displayed in the actual Ticket_Selector |
|
| 37 | - * this tracks the current row being processed |
|
| 38 | - * |
|
| 39 | - * @var int $current_row |
|
| 40 | - */ |
|
| 41 | - protected $current_row = 0; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * an array for tracking names of tickets that have sold out |
|
| 45 | - * |
|
| 46 | - * @var array $sold_out_tickets |
|
| 47 | - */ |
|
| 48 | - protected $sold_out_tickets = array(); |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
| 52 | - * |
|
| 53 | - * @var array $decremented_tickets |
|
| 54 | - */ |
|
| 55 | - protected $decremented_tickets = array(); |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - public static function set_hooks() |
|
| 64 | - { |
|
| 65 | - self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 66 | - // release tickets for expired carts |
|
| 67 | - add_action( |
|
| 68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 70 | - 1 |
|
| 71 | - ); |
|
| 72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 73 | - add_filter( |
|
| 74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 76 | - 20, |
|
| 77 | - 3 |
|
| 78 | - ); |
|
| 79 | - // add notices for sold out tickets |
|
| 80 | - add_action( |
|
| 81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 83 | - 10 |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - // handle tickets deleted from cart |
|
| 87 | - add_action( |
|
| 88 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 89 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 90 | - 10, |
|
| 91 | - 2 |
|
| 92 | - ); |
|
| 93 | - // handle emptied carts |
|
| 94 | - add_action( |
|
| 95 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 96 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 97 | - 10, |
|
| 98 | - 1 |
|
| 99 | - ); |
|
| 100 | - add_action( |
|
| 101 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | - 10, |
|
| 104 | - 1 |
|
| 105 | - ); |
|
| 106 | - // handle cancelled registrations |
|
| 107 | - add_action( |
|
| 108 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 109 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 110 | - 10, |
|
| 111 | - 1 |
|
| 112 | - ); |
|
| 113 | - // cron tasks |
|
| 114 | - add_action( |
|
| 115 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 116 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 117 | - 10, |
|
| 118 | - 1 |
|
| 119 | - ); |
|
| 120 | - add_action( |
|
| 121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | - 10, |
|
| 124 | - 1 |
|
| 125 | - ); |
|
| 126 | - add_action( |
|
| 127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 128 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 129 | - 10, |
|
| 130 | - 1 |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 137 | - * |
|
| 138 | - * @return void |
|
| 139 | - */ |
|
| 140 | - public static function set_hooks_admin() |
|
| 141 | - { |
|
| 142 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 148 | - */ |
|
| 149 | - public static function instance() |
|
| 150 | - { |
|
| 151 | - return parent::get_instance(__CLASS__); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param WP_Query $WP_Query |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - public function run($WP_Query) |
|
| 160 | - { |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Retrieves grand totals from the line items that have no TXN ID |
|
| 170 | - * and timestamps less than the current time minus the session lifespan. |
|
| 171 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 172 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 173 | - * |
|
| 174 | - * @return void |
|
| 175 | - * @throws DomainException |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - * @throws UnexpectedEntityException |
|
| 181 | - */ |
|
| 182 | - public static function release_tickets_for_expired_carts() |
|
| 183 | - { |
|
| 184 | - if (self::debug) { |
|
| 185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 186 | - } |
|
| 187 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 188 | - $expired_ticket_IDs = array(); |
|
| 189 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 190 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 191 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 192 | - ); |
|
| 193 | - $timestamp = $session_lifespan->expiration(); |
|
| 194 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 195 | - if (self::debug) { |
|
| 196 | - echo self::$nl . ' . time(): ' . time(); |
|
| 197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 202 | - } |
|
| 203 | - if (! empty($expired_ticket_line_items)) { |
|
| 204 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 206 | - continue; |
|
| 207 | - } |
|
| 208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 209 | - if (self::debug) { |
|
| 210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
| 212 | - . date( |
|
| 213 | - 'Y-m-d h:i a', |
|
| 214 | - $expired_ticket_line_item->timestamp(true) |
|
| 215 | - ); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - if (! empty($expired_ticket_IDs)) { |
|
| 219 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 220 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 221 | - array(), |
|
| 222 | - __FUNCTION__ |
|
| 223 | - ); |
|
| 224 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 225 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - do_action( |
|
| 229 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 230 | - $expired_ticket_IDs, |
|
| 231 | - $expired_ticket_line_items |
|
| 232 | - ); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 242 | - * |
|
| 243 | - * @param int $qty |
|
| 244 | - * @param EE_Ticket $ticket |
|
| 245 | - * @return bool |
|
| 246 | - * @throws UnexpectedEntityException |
|
| 247 | - * @throws EE_Error |
|
| 248 | - */ |
|
| 249 | - public static function validate_ticket_sale($qty, EE_Ticket $ticket) |
|
| 250 | - { |
|
| 251 | - $qty = absint($qty); |
|
| 252 | - if ($qty > 0) { |
|
| 253 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 254 | - } |
|
| 255 | - if (self::debug) { |
|
| 256 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 257 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 258 | - } |
|
| 259 | - return $qty; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 265 | - * |
|
| 266 | - * @param EE_Ticket $ticket |
|
| 267 | - * @param int $qty |
|
| 268 | - * @return int |
|
| 269 | - * @throws UnexpectedEntityException |
|
| 270 | - * @throws EE_Error |
|
| 271 | - */ |
|
| 272 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 273 | - { |
|
| 274 | - if (self::debug) { |
|
| 275 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 276 | - } |
|
| 277 | - if (! $ticket instanceof EE_Ticket) { |
|
| 278 | - return 0; |
|
| 279 | - } |
|
| 280 | - if (self::debug) { |
|
| 281 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 282 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 283 | - } |
|
| 284 | - $ticket->refresh_from_db(); |
|
| 285 | - // first let's determine the ticket availability based on sales |
|
| 286 | - $available = $ticket->qty('saleable'); |
|
| 287 | - if (self::debug) { |
|
| 288 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 289 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 290 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 291 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 292 | - echo self::$nl . ' . . . available: ' . $available; |
|
| 293 | - } |
|
| 294 | - if ($available < 1) { |
|
| 295 | - $this->_ticket_sold_out($ticket); |
|
| 296 | - return 0; |
|
| 297 | - } |
|
| 298 | - if (self::debug) { |
|
| 299 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
| 300 | - } |
|
| 301 | - if ($available < $qty) { |
|
| 302 | - $qty = $available; |
|
| 303 | - if (self::debug) { |
|
| 304 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 305 | - } |
|
| 306 | - $this->_ticket_quantity_decremented($ticket); |
|
| 307 | - } |
|
| 308 | - if ($this->_reserve_ticket($ticket, $qty)) { |
|
| 309 | - return $qty; |
|
| 310 | - } else { |
|
| 311 | - return 0; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * increments ticket reserved based on quantity passed |
|
| 318 | - * |
|
| 319 | - * @param EE_Ticket $ticket |
|
| 320 | - * @param int $quantity |
|
| 321 | - * @return bool indicating success or failure |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 325 | - { |
|
| 326 | - if (self::debug) { |
|
| 327 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 328 | - } |
|
| 329 | - return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param EE_Ticket $ticket |
|
| 335 | - * @param int $quantity |
|
| 336 | - * @return bool |
|
| 337 | - * @throws EE_Error |
|
| 338 | - */ |
|
| 339 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 340 | - { |
|
| 341 | - if (self::debug) { |
|
| 342 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 343 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
| 344 | - } |
|
| 345 | - $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
| 346 | - if (self::debug) { |
|
| 347 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
| 348 | - } |
|
| 349 | - return $ticket->save() ? 1 : 0; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * removes quantities within the ticket selector based on zero ticket availability |
|
| 355 | - * |
|
| 356 | - * @param EE_Ticket $ticket |
|
| 357 | - * @return void |
|
| 358 | - * @throws UnexpectedEntityException |
|
| 359 | - * @throws EE_Error |
|
| 360 | - */ |
|
| 361 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 362 | - { |
|
| 363 | - if (self::debug) { |
|
| 364 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 365 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 366 | - } |
|
| 367 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 373 | - * |
|
| 374 | - * @param EE_Ticket $ticket |
|
| 375 | - * @return void |
|
| 376 | - * @throws UnexpectedEntityException |
|
| 377 | - * @throws EE_Error |
|
| 378 | - */ |
|
| 379 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 380 | - { |
|
| 381 | - if (self::debug) { |
|
| 382 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 383 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 384 | - } |
|
| 385 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * builds string out of ticket and event name |
|
| 391 | - * |
|
| 392 | - * @param EE_Ticket $ticket |
|
| 393 | - * @return string |
|
| 394 | - * @throws UnexpectedEntityException |
|
| 395 | - * @throws EE_Error |
|
| 396 | - */ |
|
| 397 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 398 | - { |
|
| 399 | - $event = $ticket->get_related_event(); |
|
| 400 | - if ($event instanceof EE_Event) { |
|
| 401 | - $ticket_name = sprintf( |
|
| 402 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 403 | - $ticket->name(), |
|
| 404 | - $event->name() |
|
| 405 | - ); |
|
| 406 | - } else { |
|
| 407 | - $ticket_name = $ticket->name(); |
|
| 408 | - } |
|
| 409 | - return $ticket_name; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /********************************** EVENT CART **********************************/ |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * releases or reserves ticket(s) based on quantity passed |
|
| 419 | - * |
|
| 420 | - * @param EE_Line_Item $line_item |
|
| 421 | - * @param int $quantity |
|
| 422 | - * @return void |
|
| 423 | - * @throws EE_Error |
|
| 424 | - * @throws InvalidArgumentException |
|
| 425 | - * @throws InvalidDataTypeException |
|
| 426 | - * @throws InvalidInterfaceException |
|
| 427 | - */ |
|
| 428 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 429 | - { |
|
| 430 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 431 | - if ($ticket instanceof EE_Ticket) { |
|
| 432 | - $ticket->add_extra_meta( |
|
| 433 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 434 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 435 | - ); |
|
| 436 | - if ($quantity > 0) { |
|
| 437 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 438 | - } else { |
|
| 439 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * releases reserved ticket(s) based on quantity passed |
|
| 447 | - * |
|
| 448 | - * @param EE_Ticket $ticket |
|
| 449 | - * @param int $quantity |
|
| 450 | - * @return void |
|
| 451 | - * @throws EE_Error |
|
| 452 | - */ |
|
| 453 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 454 | - { |
|
| 455 | - $ticket->add_extra_meta( |
|
| 456 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 457 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 458 | - ); |
|
| 459 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - |
|
| 464 | - /********************************** POST_NOTICES **********************************/ |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - * @throws InvalidArgumentException |
|
| 471 | - * @throws ReflectionException |
|
| 472 | - * @throws InvalidDataTypeException |
|
| 473 | - * @throws InvalidInterfaceException |
|
| 474 | - */ |
|
| 475 | - public static function post_notices() |
|
| 476 | - { |
|
| 477 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * @return void |
|
| 483 | - * @throws EE_Error |
|
| 484 | - * @throws InvalidArgumentException |
|
| 485 | - * @throws ReflectionException |
|
| 486 | - * @throws InvalidDataTypeException |
|
| 487 | - * @throws InvalidInterfaceException |
|
| 488 | - */ |
|
| 489 | - protected function _post_notices() |
|
| 490 | - { |
|
| 491 | - if (self::debug) { |
|
| 492 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 493 | - } |
|
| 494 | - $refresh_msg = ''; |
|
| 495 | - $none_added_msg = ''; |
|
| 496 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 497 | - $refresh_msg = __( |
|
| 498 | - 'Please refresh the page to view updated ticket quantities.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ); |
|
| 501 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 502 | - } |
|
| 503 | - if (! empty($this->sold_out_tickets)) { |
|
| 504 | - EE_Error::add_attention( |
|
| 505 | - sprintf( |
|
| 506 | - apply_filters( |
|
| 507 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 508 | - __( |
|
| 509 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 510 | - 'event_espresso' |
|
| 511 | - ) |
|
| 512 | - ), |
|
| 513 | - '<br />', |
|
| 514 | - implode('<br />', $this->sold_out_tickets), |
|
| 515 | - $none_added_msg, |
|
| 516 | - $refresh_msg |
|
| 517 | - ) |
|
| 518 | - ); |
|
| 519 | - // alter code flow in the Ticket Selector for better UX |
|
| 520 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 521 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 522 | - $this->sold_out_tickets = array(); |
|
| 523 | - // and reset the cart |
|
| 524 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 525 | - } |
|
| 526 | - if (! empty($this->decremented_tickets)) { |
|
| 527 | - EE_Error::add_attention( |
|
| 528 | - sprintf( |
|
| 529 | - apply_filters( |
|
| 530 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 531 | - __( |
|
| 532 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 533 | - 'event_espresso' |
|
| 534 | - ) |
|
| 535 | - ), |
|
| 536 | - '<br />', |
|
| 537 | - implode('<br />', $this->decremented_tickets), |
|
| 538 | - $none_added_msg, |
|
| 539 | - $refresh_msg |
|
| 540 | - ) |
|
| 541 | - ); |
|
| 542 | - $this->decremented_tickets = array(); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
| 553 | - * by default, will NOT release tickets for finalized transactions |
|
| 554 | - * |
|
| 555 | - * @param EE_Transaction $transaction |
|
| 556 | - * @return int |
|
| 557 | - * @throws EE_Error |
|
| 558 | - * @throws InvalidSessionDataException |
|
| 559 | - */ |
|
| 560 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 561 | - { |
|
| 562 | - if (self::debug) { |
|
| 563 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 564 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 565 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 566 | - } |
|
| 567 | - // check if 'finalize_registration' step has been completed... |
|
| 568 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 569 | - if (self::debug) { |
|
| 570 | - // DEBUG LOG |
|
| 571 | - EEH_Debug_Tools::log( |
|
| 572 | - __CLASS__, |
|
| 573 | - __FUNCTION__, |
|
| 574 | - __LINE__, |
|
| 575 | - array('finalized' => $finalized), |
|
| 576 | - false, |
|
| 577 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 578 | - ); |
|
| 579 | - } |
|
| 580 | - // how many tickets were released |
|
| 581 | - $count = 0; |
|
| 582 | - if (self::debug) { |
|
| 583 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 584 | - } |
|
| 585 | - $release_tickets_with_TXN_status = array( |
|
| 586 | - EEM_Transaction::failed_status_code, |
|
| 587 | - EEM_Transaction::abandoned_status_code, |
|
| 588 | - EEM_Transaction::incomplete_status_code, |
|
| 589 | - ); |
|
| 590 | - $events = array(); |
|
| 591 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 592 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 593 | - // cancel any reserved tickets for registrations that were not approved |
|
| 594 | - $registrations = $transaction->registrations(); |
|
| 595 | - if (self::debug) { |
|
| 596 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 597 | - $reg = reset($registrations); |
|
| 598 | - $ticket = $reg->ticket(); |
|
| 599 | - if ($ticket instanceof EE_Ticket) { |
|
| 600 | - $ticket->add_extra_meta( |
|
| 601 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 602 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 603 | - ); |
|
| 604 | - } |
|
| 605 | - } |
|
| 606 | - if (! empty($registrations)) { |
|
| 607 | - foreach ($registrations as $registration) { |
|
| 608 | - if ($registration instanceof EE_Registration |
|
| 609 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 610 | - ) { |
|
| 611 | - $count++; |
|
| 612 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 613 | - } |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - if ($events !== array()) { |
|
| 618 | - foreach ($events as $event) { |
|
| 619 | - /** @var EE_Event $event */ |
|
| 620 | - $event->perform_sold_out_status_check(); |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - return $count; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * releases reserved tickets for an EE_Registration |
|
| 629 | - * by default, will NOT release tickets for APPROVED registrations |
|
| 630 | - * |
|
| 631 | - * @param EE_Registration $registration |
|
| 632 | - * @param EE_Transaction $transaction |
|
| 633 | - * @return int |
|
| 634 | - * @throws EE_Error |
|
| 635 | - */ |
|
| 636 | - protected function _release_reserved_ticket_for_registration( |
|
| 637 | - EE_Registration $registration, |
|
| 638 | - EE_Transaction $transaction |
|
| 639 | - ) { |
|
| 640 | - $STS_ID = $transaction->status_ID(); |
|
| 641 | - if (self::debug) { |
|
| 642 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 643 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 644 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 645 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 646 | - } |
|
| 647 | - if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
| 648 | - $STS_ID === EEM_Transaction::failed_status_code |
|
| 649 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 650 | - || ( |
|
| 651 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 652 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 653 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 654 | - ) |
|
| 655 | - ) { |
|
| 656 | - if (self::debug) { |
|
| 657 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 658 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 659 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 660 | - var_dump($rsrvd); |
|
| 661 | - } |
|
| 662 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
| 663 | - return 1; |
|
| 664 | - } |
|
| 665 | - return 0; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - |
|
| 670 | - /********************************** SESSION_CART_RESET **********************************/ |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 675 | - * |
|
| 676 | - * @param EE_Session $session |
|
| 677 | - * @return void |
|
| 678 | - * @throws EE_Error |
|
| 679 | - * @throws InvalidArgumentException |
|
| 680 | - * @throws ReflectionException |
|
| 681 | - * @throws InvalidDataTypeException |
|
| 682 | - * @throws InvalidInterfaceException |
|
| 683 | - */ |
|
| 684 | - public static function session_cart_reset(EE_Session $session) |
|
| 685 | - { |
|
| 686 | - // don't release tickets if checkout was already reset |
|
| 687 | - if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
| 688 | - return; |
|
| 689 | - } |
|
| 690 | - if (self::debug) { |
|
| 691 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 692 | - } |
|
| 693 | - // first check of the session has a valid Checkout object |
|
| 694 | - $checkout = $session->checkout(); |
|
| 695 | - if ($checkout instanceof EE_Checkout) { |
|
| 696 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 697 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 698 | - return; |
|
| 699 | - } |
|
| 700 | - $cart = $session->cart(); |
|
| 701 | - if ($cart instanceof EE_Cart) { |
|
| 702 | - if (self::debug) { |
|
| 703 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 704 | - } |
|
| 705 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 706 | - } else { |
|
| 707 | - if (self::debug) { |
|
| 708 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 709 | - var_export($cart, true); |
|
| 710 | - } |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * releases reserved tickets in the EE_Cart |
|
| 717 | - * |
|
| 718 | - * @param EE_Cart $cart |
|
| 719 | - * @return void |
|
| 720 | - * @throws EE_Error |
|
| 721 | - * @throws InvalidArgumentException |
|
| 722 | - * @throws ReflectionException |
|
| 723 | - * @throws InvalidDataTypeException |
|
| 724 | - * @throws InvalidInterfaceException |
|
| 725 | - */ |
|
| 726 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 727 | - { |
|
| 728 | - if (self::debug) { |
|
| 729 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 730 | - } |
|
| 731 | - $ticket_line_items = $cart->get_tickets(); |
|
| 732 | - if (empty($ticket_line_items)) { |
|
| 733 | - return; |
|
| 734 | - } |
|
| 735 | - if (self::debug) { |
|
| 736 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
| 737 | - } |
|
| 738 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 739 | - if (self::debug) { |
|
| 740 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 741 | - } |
|
| 742 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 743 | - if (self::debug) { |
|
| 744 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 745 | - } |
|
| 746 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 747 | - if ($ticket instanceof EE_Ticket) { |
|
| 748 | - if (self::debug) { |
|
| 749 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 750 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 751 | - } |
|
| 752 | - $ticket->add_extra_meta( |
|
| 753 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 754 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 755 | - ); |
|
| 756 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - if (self::debug) { |
|
| 761 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 772 | - * |
|
| 773 | - * @param EE_Session $session |
|
| 774 | - * @return void |
|
| 775 | - * @throws EE_Error |
|
| 776 | - * @throws InvalidSessionDataException |
|
| 777 | - */ |
|
| 778 | - public static function session_checkout_reset(EE_Session $session) |
|
| 779 | - { |
|
| 780 | - // don't release tickets if cart was already reset |
|
| 781 | - if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 782 | - return; |
|
| 783 | - } |
|
| 784 | - $checkout = $session->checkout(); |
|
| 785 | - if ($checkout instanceof EE_Checkout) { |
|
| 786 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * releases reserved tickets for the EE_Checkout->transaction |
|
| 793 | - * |
|
| 794 | - * @param EE_Checkout $checkout |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - * @throws InvalidSessionDataException |
|
| 798 | - */ |
|
| 799 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 800 | - { |
|
| 801 | - if (self::debug) { |
|
| 802 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 803 | - } |
|
| 804 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 805 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 806 | - return; |
|
| 807 | - } |
|
| 808 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - |
|
| 812 | - |
|
| 813 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * @param EE_Session $session |
|
| 818 | - * @return void |
|
| 819 | - */ |
|
| 820 | - public static function session_expired_reset(EE_Session $session) |
|
| 821 | - { |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - |
|
| 825 | - |
|
| 826 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 827 | - |
|
| 828 | - |
|
| 829 | - /** |
|
| 830 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 831 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 832 | - * |
|
| 833 | - * @param EE_Transaction $transaction |
|
| 834 | - * @return void |
|
| 835 | - * @throws EE_Error |
|
| 836 | - * @throws InvalidSessionDataException |
|
| 837 | - */ |
|
| 838 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 839 | - { |
|
| 840 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 841 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 842 | - if (self::debug) { |
|
| 843 | - // DEBUG LOG |
|
| 844 | - EEH_Debug_Tools::log( |
|
| 845 | - __CLASS__, |
|
| 846 | - __FUNCTION__, |
|
| 847 | - __LINE__, |
|
| 848 | - array($transaction), |
|
| 849 | - false, |
|
| 850 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 851 | - ); |
|
| 852 | - } |
|
| 853 | - return; |
|
| 854 | - } |
|
| 855 | - // have their been any successful payments made ? |
|
| 856 | - $payments = $transaction->payments(); |
|
| 857 | - foreach ($payments as $payment) { |
|
| 858 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 859 | - if (self::debug) { |
|
| 860 | - // DEBUG LOG |
|
| 861 | - EEH_Debug_Tools::log( |
|
| 862 | - __CLASS__, |
|
| 863 | - __FUNCTION__, |
|
| 864 | - __LINE__, |
|
| 865 | - array($payment), |
|
| 866 | - false, |
|
| 867 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 868 | - ); |
|
| 869 | - } |
|
| 870 | - return; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - // since you haven't even attempted to pay for your ticket... |
|
| 874 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - |
|
| 878 | - |
|
| 879 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 880 | - |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 884 | - * |
|
| 885 | - * @param EE_Transaction $transaction |
|
| 886 | - * @return void |
|
| 887 | - * @throws EE_Error |
|
| 888 | - * @throws InvalidSessionDataException |
|
| 889 | - */ |
|
| 890 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 891 | - { |
|
| 892 | - // since you haven't even attempted to pay for your ticket... |
|
| 893 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 899 | - |
|
| 900 | - |
|
| 901 | - /** |
|
| 902 | - * Resets the ticket and datetime reserved counts. |
|
| 903 | - * |
|
| 904 | - * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
| 905 | - * on the valid transactions. |
|
| 906 | - * |
|
| 907 | - * @return int number of tickets whose reservations were released. |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws DomainException |
|
| 910 | - * @throws InvalidDataTypeException |
|
| 911 | - * @throws InvalidInterfaceException |
|
| 912 | - * @throws InvalidArgumentException |
|
| 913 | - * @throws UnexpectedEntityException |
|
| 914 | - * @throws ReflectionException |
|
| 915 | - */ |
|
| 916 | - public static function reset_reservation_counts() |
|
| 917 | - { |
|
| 918 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 919 | - $valid_reserved_tickets = array(); |
|
| 920 | - /** @var EE_Transaction[] $transactions_in_progress */ |
|
| 921 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
| 922 | - foreach ($transactions_in_progress as $transaction) { |
|
| 923 | - // if this TXN has been fully completed, then skip it |
|
| 924 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 925 | - continue; |
|
| 926 | - } |
|
| 927 | - $total_line_item = $transaction->total_line_item(); |
|
| 928 | - // $transaction_in_progress->line |
|
| 929 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 930 | - throw new DomainException( |
|
| 931 | - esc_html__( |
|
| 932 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 933 | - 'event_espresso' |
|
| 934 | - ) |
|
| 935 | - ); |
|
| 936 | - } |
|
| 937 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 938 | - $total_line_item |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 942 | - foreach ($total_line_items as $total_line_item) { |
|
| 943 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 944 | - $total_line_item |
|
| 945 | - ); |
|
| 946 | - } |
|
| 947 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 948 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 949 | - $tickets_with_reservations, |
|
| 950 | - $valid_reserved_tickets, |
|
| 951 | - __FUNCTION__ |
|
| 952 | - ); |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - |
|
| 956 | - /** |
|
| 957 | - * @param EE_Line_Item $total_line_item |
|
| 958 | - * @return EE_Line_Item[] |
|
| 959 | - */ |
|
| 960 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 961 | - { |
|
| 962 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 963 | - $valid_reserved_tickets = array(); |
|
| 964 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 965 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 966 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 967 | - $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
| 968 | - } |
|
| 969 | - } |
|
| 970 | - return $valid_reserved_tickets; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
| 976 | - * |
|
| 977 | - * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
| 978 | - * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
| 979 | - * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
| 980 | - * |
|
| 981 | - * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
| 982 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
| 983 | - * whose session has NOT expired. We will use these to determine the number of ticket |
|
| 984 | - * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
| 985 | - * we don't know which of those have already been taken into account when reducing ticket |
|
| 986 | - * reservation counts, and which haven't. |
|
| 987 | - * @return int |
|
| 988 | - * @throws UnexpectedEntityException |
|
| 989 | - * @throws DomainException |
|
| 990 | - * @throws EE_Error |
|
| 991 | - */ |
|
| 992 | - protected static function release_reservations_for_tickets( |
|
| 993 | - array $tickets_with_reservations, |
|
| 994 | - array $valid_reserved_ticket_line_items = array(), |
|
| 995 | - $source = '' |
|
| 996 | - ) { |
|
| 997 | - $total_tickets_released = 0; |
|
| 998 | - $sold_out_events = array(); |
|
| 999 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1000 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1001 | - continue; |
|
| 1002 | - } |
|
| 1003 | - // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
| 1004 | - // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
| 1005 | - // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
| 1006 | - // the number to RELEASE. It's the same end result, just different path. |
|
| 1007 | - // Begin by assuming we're going to release all the reservations on this ticket. |
|
| 1008 | - $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
| 1009 | - // Now reduce that number using the list of current valid reservations. |
|
| 1010 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1011 | - if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1012 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1013 | - ) { |
|
| 1014 | - $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
| 1018 | - if ($expired_reservations_count > 0) { |
|
| 1019 | - $ticket_with_reservations->add_extra_meta( |
|
| 1020 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1021 | - __LINE__ . ') ' . $source . '()' |
|
| 1022 | - ); |
|
| 1023 | - $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
| 1024 | - $total_tickets_released += $expired_reservations_count; |
|
| 1025 | - $event = $ticket_with_reservations->get_related_event(); |
|
| 1026 | - // track sold out events |
|
| 1027 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1028 | - $sold_out_events[] = $event; |
|
| 1029 | - } |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - // Double check whether sold out events should remain sold out after releasing tickets |
|
| 1033 | - if ($sold_out_events !== array()) { |
|
| 1034 | - foreach ($sold_out_events as $sold_out_event) { |
|
| 1035 | - /** @var EE_Event $sold_out_event */ |
|
| 1036 | - $sold_out_event->perform_sold_out_status_check(); |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - return $total_tickets_released; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - /********************************** SHUTDOWN **********************************/ |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * @param int $timestamp |
|
| 1049 | - * @return false|int |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - * @throws InvalidArgumentException |
|
| 1052 | - * @throws InvalidDataTypeException |
|
| 1053 | - * @throws InvalidInterfaceException |
|
| 1054 | - */ |
|
| 1055 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1056 | - { |
|
| 1057 | - /** @type WPDB $wpdb */ |
|
| 1058 | - global $wpdb; |
|
| 1059 | - if (! absint($timestamp)) { |
|
| 1060 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1061 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1062 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1063 | - ); |
|
| 1064 | - $timestamp = $session_lifespan->expiration(); |
|
| 1065 | - } |
|
| 1066 | - return $wpdb->query( |
|
| 1067 | - $wpdb->prepare( |
|
| 1068 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 23 | + const debug = false; |
|
| 24 | + |
|
| 25 | + private static $nl = ''; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
| 29 | + * |
|
| 30 | + * @var array $ticket_selections |
|
| 31 | + */ |
|
| 32 | + protected $ticket_selections = array(); |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 36 | + * according to how they are displayed in the actual Ticket_Selector |
|
| 37 | + * this tracks the current row being processed |
|
| 38 | + * |
|
| 39 | + * @var int $current_row |
|
| 40 | + */ |
|
| 41 | + protected $current_row = 0; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * an array for tracking names of tickets that have sold out |
|
| 45 | + * |
|
| 46 | + * @var array $sold_out_tickets |
|
| 47 | + */ |
|
| 48 | + protected $sold_out_tickets = array(); |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
| 52 | + * |
|
| 53 | + * @var array $decremented_tickets |
|
| 54 | + */ |
|
| 55 | + protected $decremented_tickets = array(); |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + public static function set_hooks() |
|
| 64 | + { |
|
| 65 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 66 | + // release tickets for expired carts |
|
| 67 | + add_action( |
|
| 68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 70 | + 1 |
|
| 71 | + ); |
|
| 72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 73 | + add_filter( |
|
| 74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 76 | + 20, |
|
| 77 | + 3 |
|
| 78 | + ); |
|
| 79 | + // add notices for sold out tickets |
|
| 80 | + add_action( |
|
| 81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 83 | + 10 |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + // handle tickets deleted from cart |
|
| 87 | + add_action( |
|
| 88 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 89 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 90 | + 10, |
|
| 91 | + 2 |
|
| 92 | + ); |
|
| 93 | + // handle emptied carts |
|
| 94 | + add_action( |
|
| 95 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 96 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 97 | + 10, |
|
| 98 | + 1 |
|
| 99 | + ); |
|
| 100 | + add_action( |
|
| 101 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | + 10, |
|
| 104 | + 1 |
|
| 105 | + ); |
|
| 106 | + // handle cancelled registrations |
|
| 107 | + add_action( |
|
| 108 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 109 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 110 | + 10, |
|
| 111 | + 1 |
|
| 112 | + ); |
|
| 113 | + // cron tasks |
|
| 114 | + add_action( |
|
| 115 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 116 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 117 | + 10, |
|
| 118 | + 1 |
|
| 119 | + ); |
|
| 120 | + add_action( |
|
| 121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | + 10, |
|
| 124 | + 1 |
|
| 125 | + ); |
|
| 126 | + add_action( |
|
| 127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 128 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 129 | + 10, |
|
| 130 | + 1 |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 137 | + * |
|
| 138 | + * @return void |
|
| 139 | + */ |
|
| 140 | + public static function set_hooks_admin() |
|
| 141 | + { |
|
| 142 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 148 | + */ |
|
| 149 | + public static function instance() |
|
| 150 | + { |
|
| 151 | + return parent::get_instance(__CLASS__); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param WP_Query $WP_Query |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + public function run($WP_Query) |
|
| 160 | + { |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Retrieves grand totals from the line items that have no TXN ID |
|
| 170 | + * and timestamps less than the current time minus the session lifespan. |
|
| 171 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 172 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 173 | + * |
|
| 174 | + * @return void |
|
| 175 | + * @throws DomainException |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + * @throws UnexpectedEntityException |
|
| 181 | + */ |
|
| 182 | + public static function release_tickets_for_expired_carts() |
|
| 183 | + { |
|
| 184 | + if (self::debug) { |
|
| 185 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 186 | + } |
|
| 187 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 188 | + $expired_ticket_IDs = array(); |
|
| 189 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 190 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 191 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 192 | + ); |
|
| 193 | + $timestamp = $session_lifespan->expiration(); |
|
| 194 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
| 195 | + if (self::debug) { |
|
| 196 | + echo self::$nl . ' . time(): ' . time(); |
|
| 197 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
| 198 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
| 199 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
| 200 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
| 201 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
| 202 | + } |
|
| 203 | + if (! empty($expired_ticket_line_items)) { |
|
| 204 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
| 205 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
| 206 | + continue; |
|
| 207 | + } |
|
| 208 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
| 209 | + if (self::debug) { |
|
| 210 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
| 211 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
| 212 | + . date( |
|
| 213 | + 'Y-m-d h:i a', |
|
| 214 | + $expired_ticket_line_item->timestamp(true) |
|
| 215 | + ); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + if (! empty($expired_ticket_IDs)) { |
|
| 219 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 220 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 221 | + array(), |
|
| 222 | + __FUNCTION__ |
|
| 223 | + ); |
|
| 224 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
| 225 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + do_action( |
|
| 229 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 230 | + $expired_ticket_IDs, |
|
| 231 | + $expired_ticket_line_items |
|
| 232 | + ); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 242 | + * |
|
| 243 | + * @param int $qty |
|
| 244 | + * @param EE_Ticket $ticket |
|
| 245 | + * @return bool |
|
| 246 | + * @throws UnexpectedEntityException |
|
| 247 | + * @throws EE_Error |
|
| 248 | + */ |
|
| 249 | + public static function validate_ticket_sale($qty, EE_Ticket $ticket) |
|
| 250 | + { |
|
| 251 | + $qty = absint($qty); |
|
| 252 | + if ($qty > 0) { |
|
| 253 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 254 | + } |
|
| 255 | + if (self::debug) { |
|
| 256 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 257 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 258 | + } |
|
| 259 | + return $qty; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 265 | + * |
|
| 266 | + * @param EE_Ticket $ticket |
|
| 267 | + * @param int $qty |
|
| 268 | + * @return int |
|
| 269 | + * @throws UnexpectedEntityException |
|
| 270 | + * @throws EE_Error |
|
| 271 | + */ |
|
| 272 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 273 | + { |
|
| 274 | + if (self::debug) { |
|
| 275 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 276 | + } |
|
| 277 | + if (! $ticket instanceof EE_Ticket) { |
|
| 278 | + return 0; |
|
| 279 | + } |
|
| 280 | + if (self::debug) { |
|
| 281 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 282 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
| 283 | + } |
|
| 284 | + $ticket->refresh_from_db(); |
|
| 285 | + // first let's determine the ticket availability based on sales |
|
| 286 | + $available = $ticket->qty('saleable'); |
|
| 287 | + if (self::debug) { |
|
| 288 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
| 289 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
| 290 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 291 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 292 | + echo self::$nl . ' . . . available: ' . $available; |
|
| 293 | + } |
|
| 294 | + if ($available < 1) { |
|
| 295 | + $this->_ticket_sold_out($ticket); |
|
| 296 | + return 0; |
|
| 297 | + } |
|
| 298 | + if (self::debug) { |
|
| 299 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
| 300 | + } |
|
| 301 | + if ($available < $qty) { |
|
| 302 | + $qty = $available; |
|
| 303 | + if (self::debug) { |
|
| 304 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
| 305 | + } |
|
| 306 | + $this->_ticket_quantity_decremented($ticket); |
|
| 307 | + } |
|
| 308 | + if ($this->_reserve_ticket($ticket, $qty)) { |
|
| 309 | + return $qty; |
|
| 310 | + } else { |
|
| 311 | + return 0; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * increments ticket reserved based on quantity passed |
|
| 318 | + * |
|
| 319 | + * @param EE_Ticket $ticket |
|
| 320 | + * @param int $quantity |
|
| 321 | + * @return bool indicating success or failure |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 325 | + { |
|
| 326 | + if (self::debug) { |
|
| 327 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
| 328 | + } |
|
| 329 | + return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param EE_Ticket $ticket |
|
| 335 | + * @param int $quantity |
|
| 336 | + * @return bool |
|
| 337 | + * @throws EE_Error |
|
| 338 | + */ |
|
| 339 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 340 | + { |
|
| 341 | + if (self::debug) { |
|
| 342 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
| 343 | + echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
| 344 | + } |
|
| 345 | + $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
| 346 | + if (self::debug) { |
|
| 347 | + echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
| 348 | + } |
|
| 349 | + return $ticket->save() ? 1 : 0; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * removes quantities within the ticket selector based on zero ticket availability |
|
| 355 | + * |
|
| 356 | + * @param EE_Ticket $ticket |
|
| 357 | + * @return void |
|
| 358 | + * @throws UnexpectedEntityException |
|
| 359 | + * @throws EE_Error |
|
| 360 | + */ |
|
| 361 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 362 | + { |
|
| 363 | + if (self::debug) { |
|
| 364 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 365 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 366 | + } |
|
| 367 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 373 | + * |
|
| 374 | + * @param EE_Ticket $ticket |
|
| 375 | + * @return void |
|
| 376 | + * @throws UnexpectedEntityException |
|
| 377 | + * @throws EE_Error |
|
| 378 | + */ |
|
| 379 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 380 | + { |
|
| 381 | + if (self::debug) { |
|
| 382 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 383 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 384 | + } |
|
| 385 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * builds string out of ticket and event name |
|
| 391 | + * |
|
| 392 | + * @param EE_Ticket $ticket |
|
| 393 | + * @return string |
|
| 394 | + * @throws UnexpectedEntityException |
|
| 395 | + * @throws EE_Error |
|
| 396 | + */ |
|
| 397 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 398 | + { |
|
| 399 | + $event = $ticket->get_related_event(); |
|
| 400 | + if ($event instanceof EE_Event) { |
|
| 401 | + $ticket_name = sprintf( |
|
| 402 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 403 | + $ticket->name(), |
|
| 404 | + $event->name() |
|
| 405 | + ); |
|
| 406 | + } else { |
|
| 407 | + $ticket_name = $ticket->name(); |
|
| 408 | + } |
|
| 409 | + return $ticket_name; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /********************************** EVENT CART **********************************/ |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * releases or reserves ticket(s) based on quantity passed |
|
| 419 | + * |
|
| 420 | + * @param EE_Line_Item $line_item |
|
| 421 | + * @param int $quantity |
|
| 422 | + * @return void |
|
| 423 | + * @throws EE_Error |
|
| 424 | + * @throws InvalidArgumentException |
|
| 425 | + * @throws InvalidDataTypeException |
|
| 426 | + * @throws InvalidInterfaceException |
|
| 427 | + */ |
|
| 428 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 429 | + { |
|
| 430 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 431 | + if ($ticket instanceof EE_Ticket) { |
|
| 432 | + $ticket->add_extra_meta( |
|
| 433 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 434 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 435 | + ); |
|
| 436 | + if ($quantity > 0) { |
|
| 437 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 438 | + } else { |
|
| 439 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * releases reserved ticket(s) based on quantity passed |
|
| 447 | + * |
|
| 448 | + * @param EE_Ticket $ticket |
|
| 449 | + * @param int $quantity |
|
| 450 | + * @return void |
|
| 451 | + * @throws EE_Error |
|
| 452 | + */ |
|
| 453 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 454 | + { |
|
| 455 | + $ticket->add_extra_meta( |
|
| 456 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 457 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 458 | + ); |
|
| 459 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + |
|
| 464 | + /********************************** POST_NOTICES **********************************/ |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + * @throws InvalidArgumentException |
|
| 471 | + * @throws ReflectionException |
|
| 472 | + * @throws InvalidDataTypeException |
|
| 473 | + * @throws InvalidInterfaceException |
|
| 474 | + */ |
|
| 475 | + public static function post_notices() |
|
| 476 | + { |
|
| 477 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * @return void |
|
| 483 | + * @throws EE_Error |
|
| 484 | + * @throws InvalidArgumentException |
|
| 485 | + * @throws ReflectionException |
|
| 486 | + * @throws InvalidDataTypeException |
|
| 487 | + * @throws InvalidInterfaceException |
|
| 488 | + */ |
|
| 489 | + protected function _post_notices() |
|
| 490 | + { |
|
| 491 | + if (self::debug) { |
|
| 492 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 493 | + } |
|
| 494 | + $refresh_msg = ''; |
|
| 495 | + $none_added_msg = ''; |
|
| 496 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 497 | + $refresh_msg = __( |
|
| 498 | + 'Please refresh the page to view updated ticket quantities.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ); |
|
| 501 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 502 | + } |
|
| 503 | + if (! empty($this->sold_out_tickets)) { |
|
| 504 | + EE_Error::add_attention( |
|
| 505 | + sprintf( |
|
| 506 | + apply_filters( |
|
| 507 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 508 | + __( |
|
| 509 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 510 | + 'event_espresso' |
|
| 511 | + ) |
|
| 512 | + ), |
|
| 513 | + '<br />', |
|
| 514 | + implode('<br />', $this->sold_out_tickets), |
|
| 515 | + $none_added_msg, |
|
| 516 | + $refresh_msg |
|
| 517 | + ) |
|
| 518 | + ); |
|
| 519 | + // alter code flow in the Ticket Selector for better UX |
|
| 520 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 521 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 522 | + $this->sold_out_tickets = array(); |
|
| 523 | + // and reset the cart |
|
| 524 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 525 | + } |
|
| 526 | + if (! empty($this->decremented_tickets)) { |
|
| 527 | + EE_Error::add_attention( |
|
| 528 | + sprintf( |
|
| 529 | + apply_filters( |
|
| 530 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 531 | + __( |
|
| 532 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 533 | + 'event_espresso' |
|
| 534 | + ) |
|
| 535 | + ), |
|
| 536 | + '<br />', |
|
| 537 | + implode('<br />', $this->decremented_tickets), |
|
| 538 | + $none_added_msg, |
|
| 539 | + $refresh_msg |
|
| 540 | + ) |
|
| 541 | + ); |
|
| 542 | + $this->decremented_tickets = array(); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
| 553 | + * by default, will NOT release tickets for finalized transactions |
|
| 554 | + * |
|
| 555 | + * @param EE_Transaction $transaction |
|
| 556 | + * @return int |
|
| 557 | + * @throws EE_Error |
|
| 558 | + * @throws InvalidSessionDataException |
|
| 559 | + */ |
|
| 560 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 561 | + { |
|
| 562 | + if (self::debug) { |
|
| 563 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 564 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
| 565 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
| 566 | + } |
|
| 567 | + // check if 'finalize_registration' step has been completed... |
|
| 568 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 569 | + if (self::debug) { |
|
| 570 | + // DEBUG LOG |
|
| 571 | + EEH_Debug_Tools::log( |
|
| 572 | + __CLASS__, |
|
| 573 | + __FUNCTION__, |
|
| 574 | + __LINE__, |
|
| 575 | + array('finalized' => $finalized), |
|
| 576 | + false, |
|
| 577 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 578 | + ); |
|
| 579 | + } |
|
| 580 | + // how many tickets were released |
|
| 581 | + $count = 0; |
|
| 582 | + if (self::debug) { |
|
| 583 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
| 584 | + } |
|
| 585 | + $release_tickets_with_TXN_status = array( |
|
| 586 | + EEM_Transaction::failed_status_code, |
|
| 587 | + EEM_Transaction::abandoned_status_code, |
|
| 588 | + EEM_Transaction::incomplete_status_code, |
|
| 589 | + ); |
|
| 590 | + $events = array(); |
|
| 591 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 592 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 593 | + // cancel any reserved tickets for registrations that were not approved |
|
| 594 | + $registrations = $transaction->registrations(); |
|
| 595 | + if (self::debug) { |
|
| 596 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
| 597 | + $reg = reset($registrations); |
|
| 598 | + $ticket = $reg->ticket(); |
|
| 599 | + if ($ticket instanceof EE_Ticket) { |
|
| 600 | + $ticket->add_extra_meta( |
|
| 601 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 602 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 603 | + ); |
|
| 604 | + } |
|
| 605 | + } |
|
| 606 | + if (! empty($registrations)) { |
|
| 607 | + foreach ($registrations as $registration) { |
|
| 608 | + if ($registration instanceof EE_Registration |
|
| 609 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 610 | + ) { |
|
| 611 | + $count++; |
|
| 612 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + if ($events !== array()) { |
|
| 618 | + foreach ($events as $event) { |
|
| 619 | + /** @var EE_Event $event */ |
|
| 620 | + $event->perform_sold_out_status_check(); |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + return $count; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * releases reserved tickets for an EE_Registration |
|
| 629 | + * by default, will NOT release tickets for APPROVED registrations |
|
| 630 | + * |
|
| 631 | + * @param EE_Registration $registration |
|
| 632 | + * @param EE_Transaction $transaction |
|
| 633 | + * @return int |
|
| 634 | + * @throws EE_Error |
|
| 635 | + */ |
|
| 636 | + protected function _release_reserved_ticket_for_registration( |
|
| 637 | + EE_Registration $registration, |
|
| 638 | + EE_Transaction $transaction |
|
| 639 | + ) { |
|
| 640 | + $STS_ID = $transaction->status_ID(); |
|
| 641 | + if (self::debug) { |
|
| 642 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 643 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
| 644 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
| 645 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
| 646 | + } |
|
| 647 | + if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
| 648 | + $STS_ID === EEM_Transaction::failed_status_code |
|
| 649 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 650 | + || ( |
|
| 651 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 652 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 653 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 654 | + ) |
|
| 655 | + ) { |
|
| 656 | + if (self::debug) { |
|
| 657 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
| 658 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 659 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 660 | + var_dump($rsrvd); |
|
| 661 | + } |
|
| 662 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
| 663 | + return 1; |
|
| 664 | + } |
|
| 665 | + return 0; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + |
|
| 670 | + /********************************** SESSION_CART_RESET **********************************/ |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 675 | + * |
|
| 676 | + * @param EE_Session $session |
|
| 677 | + * @return void |
|
| 678 | + * @throws EE_Error |
|
| 679 | + * @throws InvalidArgumentException |
|
| 680 | + * @throws ReflectionException |
|
| 681 | + * @throws InvalidDataTypeException |
|
| 682 | + * @throws InvalidInterfaceException |
|
| 683 | + */ |
|
| 684 | + public static function session_cart_reset(EE_Session $session) |
|
| 685 | + { |
|
| 686 | + // don't release tickets if checkout was already reset |
|
| 687 | + if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
| 688 | + return; |
|
| 689 | + } |
|
| 690 | + if (self::debug) { |
|
| 691 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 692 | + } |
|
| 693 | + // first check of the session has a valid Checkout object |
|
| 694 | + $checkout = $session->checkout(); |
|
| 695 | + if ($checkout instanceof EE_Checkout) { |
|
| 696 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 697 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 698 | + return; |
|
| 699 | + } |
|
| 700 | + $cart = $session->cart(); |
|
| 701 | + if ($cart instanceof EE_Cart) { |
|
| 702 | + if (self::debug) { |
|
| 703 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
| 704 | + } |
|
| 705 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 706 | + } else { |
|
| 707 | + if (self::debug) { |
|
| 708 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
| 709 | + var_export($cart, true); |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * releases reserved tickets in the EE_Cart |
|
| 717 | + * |
|
| 718 | + * @param EE_Cart $cart |
|
| 719 | + * @return void |
|
| 720 | + * @throws EE_Error |
|
| 721 | + * @throws InvalidArgumentException |
|
| 722 | + * @throws ReflectionException |
|
| 723 | + * @throws InvalidDataTypeException |
|
| 724 | + * @throws InvalidInterfaceException |
|
| 725 | + */ |
|
| 726 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 727 | + { |
|
| 728 | + if (self::debug) { |
|
| 729 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 730 | + } |
|
| 731 | + $ticket_line_items = $cart->get_tickets(); |
|
| 732 | + if (empty($ticket_line_items)) { |
|
| 733 | + return; |
|
| 734 | + } |
|
| 735 | + if (self::debug) { |
|
| 736 | + echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
| 737 | + } |
|
| 738 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 739 | + if (self::debug) { |
|
| 740 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 741 | + } |
|
| 742 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 743 | + if (self::debug) { |
|
| 744 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 745 | + } |
|
| 746 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 747 | + if ($ticket instanceof EE_Ticket) { |
|
| 748 | + if (self::debug) { |
|
| 749 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
| 750 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 751 | + } |
|
| 752 | + $ticket->add_extra_meta( |
|
| 753 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 754 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 755 | + ); |
|
| 756 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 757 | + } |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + if (self::debug) { |
|
| 761 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 772 | + * |
|
| 773 | + * @param EE_Session $session |
|
| 774 | + * @return void |
|
| 775 | + * @throws EE_Error |
|
| 776 | + * @throws InvalidSessionDataException |
|
| 777 | + */ |
|
| 778 | + public static function session_checkout_reset(EE_Session $session) |
|
| 779 | + { |
|
| 780 | + // don't release tickets if cart was already reset |
|
| 781 | + if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 782 | + return; |
|
| 783 | + } |
|
| 784 | + $checkout = $session->checkout(); |
|
| 785 | + if ($checkout instanceof EE_Checkout) { |
|
| 786 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * releases reserved tickets for the EE_Checkout->transaction |
|
| 793 | + * |
|
| 794 | + * @param EE_Checkout $checkout |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + * @throws InvalidSessionDataException |
|
| 798 | + */ |
|
| 799 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 800 | + { |
|
| 801 | + if (self::debug) { |
|
| 802 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 803 | + } |
|
| 804 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 805 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 806 | + return; |
|
| 807 | + } |
|
| 808 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + |
|
| 812 | + |
|
| 813 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * @param EE_Session $session |
|
| 818 | + * @return void |
|
| 819 | + */ |
|
| 820 | + public static function session_expired_reset(EE_Session $session) |
|
| 821 | + { |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + |
|
| 825 | + |
|
| 826 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 827 | + |
|
| 828 | + |
|
| 829 | + /** |
|
| 830 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 831 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 832 | + * |
|
| 833 | + * @param EE_Transaction $transaction |
|
| 834 | + * @return void |
|
| 835 | + * @throws EE_Error |
|
| 836 | + * @throws InvalidSessionDataException |
|
| 837 | + */ |
|
| 838 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 839 | + { |
|
| 840 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 841 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 842 | + if (self::debug) { |
|
| 843 | + // DEBUG LOG |
|
| 844 | + EEH_Debug_Tools::log( |
|
| 845 | + __CLASS__, |
|
| 846 | + __FUNCTION__, |
|
| 847 | + __LINE__, |
|
| 848 | + array($transaction), |
|
| 849 | + false, |
|
| 850 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | + return; |
|
| 854 | + } |
|
| 855 | + // have their been any successful payments made ? |
|
| 856 | + $payments = $transaction->payments(); |
|
| 857 | + foreach ($payments as $payment) { |
|
| 858 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 859 | + if (self::debug) { |
|
| 860 | + // DEBUG LOG |
|
| 861 | + EEH_Debug_Tools::log( |
|
| 862 | + __CLASS__, |
|
| 863 | + __FUNCTION__, |
|
| 864 | + __LINE__, |
|
| 865 | + array($payment), |
|
| 866 | + false, |
|
| 867 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 868 | + ); |
|
| 869 | + } |
|
| 870 | + return; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + // since you haven't even attempted to pay for your ticket... |
|
| 874 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + |
|
| 878 | + |
|
| 879 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 880 | + |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 884 | + * |
|
| 885 | + * @param EE_Transaction $transaction |
|
| 886 | + * @return void |
|
| 887 | + * @throws EE_Error |
|
| 888 | + * @throws InvalidSessionDataException |
|
| 889 | + */ |
|
| 890 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 891 | + { |
|
| 892 | + // since you haven't even attempted to pay for your ticket... |
|
| 893 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 899 | + |
|
| 900 | + |
|
| 901 | + /** |
|
| 902 | + * Resets the ticket and datetime reserved counts. |
|
| 903 | + * |
|
| 904 | + * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
| 905 | + * on the valid transactions. |
|
| 906 | + * |
|
| 907 | + * @return int number of tickets whose reservations were released. |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws DomainException |
|
| 910 | + * @throws InvalidDataTypeException |
|
| 911 | + * @throws InvalidInterfaceException |
|
| 912 | + * @throws InvalidArgumentException |
|
| 913 | + * @throws UnexpectedEntityException |
|
| 914 | + * @throws ReflectionException |
|
| 915 | + */ |
|
| 916 | + public static function reset_reservation_counts() |
|
| 917 | + { |
|
| 918 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 919 | + $valid_reserved_tickets = array(); |
|
| 920 | + /** @var EE_Transaction[] $transactions_in_progress */ |
|
| 921 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
| 922 | + foreach ($transactions_in_progress as $transaction) { |
|
| 923 | + // if this TXN has been fully completed, then skip it |
|
| 924 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 925 | + continue; |
|
| 926 | + } |
|
| 927 | + $total_line_item = $transaction->total_line_item(); |
|
| 928 | + // $transaction_in_progress->line |
|
| 929 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
| 930 | + throw new DomainException( |
|
| 931 | + esc_html__( |
|
| 932 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 933 | + 'event_espresso' |
|
| 934 | + ) |
|
| 935 | + ); |
|
| 936 | + } |
|
| 937 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 938 | + $total_line_item |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 942 | + foreach ($total_line_items as $total_line_item) { |
|
| 943 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 944 | + $total_line_item |
|
| 945 | + ); |
|
| 946 | + } |
|
| 947 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 948 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 949 | + $tickets_with_reservations, |
|
| 950 | + $valid_reserved_tickets, |
|
| 951 | + __FUNCTION__ |
|
| 952 | + ); |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + |
|
| 956 | + /** |
|
| 957 | + * @param EE_Line_Item $total_line_item |
|
| 958 | + * @return EE_Line_Item[] |
|
| 959 | + */ |
|
| 960 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 961 | + { |
|
| 962 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 963 | + $valid_reserved_tickets = array(); |
|
| 964 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 965 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 966 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 967 | + $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
| 968 | + } |
|
| 969 | + } |
|
| 970 | + return $valid_reserved_tickets; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
| 976 | + * |
|
| 977 | + * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
| 978 | + * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
| 979 | + * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
| 980 | + * |
|
| 981 | + * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
| 982 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
| 983 | + * whose session has NOT expired. We will use these to determine the number of ticket |
|
| 984 | + * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
| 985 | + * we don't know which of those have already been taken into account when reducing ticket |
|
| 986 | + * reservation counts, and which haven't. |
|
| 987 | + * @return int |
|
| 988 | + * @throws UnexpectedEntityException |
|
| 989 | + * @throws DomainException |
|
| 990 | + * @throws EE_Error |
|
| 991 | + */ |
|
| 992 | + protected static function release_reservations_for_tickets( |
|
| 993 | + array $tickets_with_reservations, |
|
| 994 | + array $valid_reserved_ticket_line_items = array(), |
|
| 995 | + $source = '' |
|
| 996 | + ) { |
|
| 997 | + $total_tickets_released = 0; |
|
| 998 | + $sold_out_events = array(); |
|
| 999 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1000 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1001 | + continue; |
|
| 1002 | + } |
|
| 1003 | + // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
| 1004 | + // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
| 1005 | + // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
| 1006 | + // the number to RELEASE. It's the same end result, just different path. |
|
| 1007 | + // Begin by assuming we're going to release all the reservations on this ticket. |
|
| 1008 | + $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
| 1009 | + // Now reduce that number using the list of current valid reservations. |
|
| 1010 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1011 | + if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1012 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1013 | + ) { |
|
| 1014 | + $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
| 1018 | + if ($expired_reservations_count > 0) { |
|
| 1019 | + $ticket_with_reservations->add_extra_meta( |
|
| 1020 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1021 | + __LINE__ . ') ' . $source . '()' |
|
| 1022 | + ); |
|
| 1023 | + $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
| 1024 | + $total_tickets_released += $expired_reservations_count; |
|
| 1025 | + $event = $ticket_with_reservations->get_related_event(); |
|
| 1026 | + // track sold out events |
|
| 1027 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1028 | + $sold_out_events[] = $event; |
|
| 1029 | + } |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + // Double check whether sold out events should remain sold out after releasing tickets |
|
| 1033 | + if ($sold_out_events !== array()) { |
|
| 1034 | + foreach ($sold_out_events as $sold_out_event) { |
|
| 1035 | + /** @var EE_Event $sold_out_event */ |
|
| 1036 | + $sold_out_event->perform_sold_out_status_check(); |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + return $total_tickets_released; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + /********************************** SHUTDOWN **********************************/ |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * @param int $timestamp |
|
| 1049 | + * @return false|int |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + * @throws InvalidArgumentException |
|
| 1052 | + * @throws InvalidDataTypeException |
|
| 1053 | + * @throws InvalidInterfaceException |
|
| 1054 | + */ |
|
| 1055 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
| 1056 | + { |
|
| 1057 | + /** @type WPDB $wpdb */ |
|
| 1058 | + global $wpdb; |
|
| 1059 | + if (! absint($timestamp)) { |
|
| 1060 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
| 1061 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
| 1062 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
| 1063 | + ); |
|
| 1064 | + $timestamp = $session_lifespan->expiration(); |
|
| 1065 | + } |
|
| 1066 | + return $wpdb->query( |
|
| 1067 | + $wpdb->prepare( |
|
| 1068 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1069 | 1069 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1070 | - // use GMT time because that's what LIN_timestamps are in |
|
| 1071 | - date('Y-m-d H:i:s', $timestamp) |
|
| 1072 | - ) |
|
| 1073 | - ); |
|
| 1074 | - } |
|
| 1070 | + // use GMT time because that's what LIN_timestamps are in |
|
| 1071 | + date('Y-m-d H:i:s', $timestamp) |
|
| 1072 | + ) |
|
| 1073 | + ); |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
@@ -17,813 +17,813 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return EED_Module|EED_Add_New_State |
|
| 22 | - */ |
|
| 23 | - public static function instance() |
|
| 24 | - { |
|
| 25 | - return parent::get_instance(__CLASS__); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | - add_filter( |
|
| 40 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 41 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 42 | - 1, |
|
| 43 | - 1 |
|
| 44 | - ); |
|
| 45 | - add_filter( |
|
| 46 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 47 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 48 | - 1, |
|
| 49 | - 1 |
|
| 50 | - ); |
|
| 51 | - add_filter( |
|
| 52 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 53 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 54 | - 10, |
|
| 55 | - 1 |
|
| 56 | - ); |
|
| 57 | - add_filter( |
|
| 58 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 59 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 60 | - 10, |
|
| 61 | - 5 |
|
| 62 | - ); |
|
| 63 | - add_filter( |
|
| 64 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 65 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 66 | - 10, |
|
| 67 | - 5 |
|
| 68 | - ); |
|
| 69 | - add_filter( |
|
| 70 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 71 | - array('EED_Add_New_State', 'state_options'), |
|
| 72 | - 10, |
|
| 73 | - 1 |
|
| 74 | - ); |
|
| 75 | - add_filter( |
|
| 76 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 77 | - array('EED_Add_New_State', 'country_options'), |
|
| 78 | - 10, |
|
| 79 | - 1 |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 86 | - * |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 89 | - public static function set_hooks_admin() |
|
| 90 | - { |
|
| 91 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 92 | - add_filter( |
|
| 93 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 94 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 95 | - 1, |
|
| 96 | - 1 |
|
| 97 | - ); |
|
| 98 | - add_filter( |
|
| 99 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 100 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 101 | - 1, |
|
| 102 | - 1 |
|
| 103 | - ); |
|
| 104 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 105 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 106 | - add_filter( |
|
| 107 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 108 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 109 | - 10, |
|
| 110 | - 1 |
|
| 111 | - ); |
|
| 112 | - add_action( |
|
| 113 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 114 | - array('EED_Add_New_State', 'update_country_settings'), |
|
| 115 | - 10, |
|
| 116 | - 3 |
|
| 117 | - ); |
|
| 118 | - add_action( |
|
| 119 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 120 | - array('EED_Add_New_State', 'update_country_settings'), |
|
| 121 | - 10, |
|
| 122 | - 3 |
|
| 123 | - ); |
|
| 124 | - add_filter( |
|
| 125 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 126 | - array('EED_Add_New_State', 'state_options'), |
|
| 127 | - 10, |
|
| 128 | - 1 |
|
| 129 | - ); |
|
| 130 | - add_filter( |
|
| 131 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 132 | - array('EED_Add_New_State', 'country_options'), |
|
| 133 | - 10, |
|
| 134 | - 1 |
|
| 135 | - ); |
|
| 136 | - add_filter( |
|
| 137 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 138 | - array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
| 139 | - 10, |
|
| 140 | - 1 |
|
| 141 | - ); |
|
| 142 | - add_filter( |
|
| 143 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 144 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 145 | - 10, |
|
| 146 | - 5 |
|
| 147 | - ); |
|
| 148 | - add_filter( |
|
| 149 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 150 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 151 | - 10, |
|
| 152 | - 5 |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - public static function set_definitions() |
|
| 161 | - { |
|
| 162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 163 | - define( |
|
| 164 | - 'ANS_TEMPLATES_PATH', |
|
| 165 | - str_replace( |
|
| 166 | - '\\', |
|
| 167 | - '/', |
|
| 168 | - plugin_dir_path(__FILE__) |
|
| 169 | - ) . 'templates/' |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param WP $WP |
|
| 176 | - * @return void |
|
| 177 | - */ |
|
| 178 | - public function run($WP) |
|
| 179 | - { |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public static function translate_js_strings() |
|
| 187 | - { |
|
| 188 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 189 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 190 | - 'event_espresso' |
|
| 191 | - ); |
|
| 192 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 193 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ); |
|
| 196 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 197 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 198 | - 'event_espresso' |
|
| 199 | - ); |
|
| 200 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 201 | - 'The new state was successfully saved to the database.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ); |
|
| 204 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 205 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return void |
|
| 213 | - */ |
|
| 214 | - public static function wp_enqueue_scripts() |
|
| 215 | - { |
|
| 216 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 217 | - wp_register_script( |
|
| 218 | - 'add_new_state', |
|
| 219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 220 | - array('espresso_core', 'single_page_checkout'), |
|
| 221 | - EVENT_ESPRESSO_VERSION, |
|
| 222 | - true |
|
| 223 | - ); |
|
| 224 | - wp_enqueue_script('add_new_state'); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * display_add_new_state_micro_form |
|
| 232 | - * |
|
| 233 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 234 | - * @return string |
|
| 235 | - * @throws EE_Error |
|
| 236 | - * @throws InvalidArgumentException |
|
| 237 | - * @throws InvalidDataTypeException |
|
| 238 | - * @throws InvalidInterfaceException |
|
| 239 | - */ |
|
| 240 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 241 | - { |
|
| 242 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 245 | - // is the "state" question in this form section? |
|
| 246 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | - // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | - // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | - if ($input instanceof EE_State_Select_Input) { |
|
| 251 | - $input->html_name(); |
|
| 252 | - } |
|
| 253 | - return $question_group_reg_form; |
|
| 254 | - } |
|
| 255 | - // we're only doing this for state select inputs |
|
| 256 | - if ($input instanceof EE_State_Select_Input |
|
| 257 | - && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 258 | - ) { |
|
| 259 | - // grab any set values from the request |
|
| 260 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 261 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 262 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 263 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 264 | - $country_options = array(); |
|
| 265 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 266 | - if (! empty($countries)) { |
|
| 267 | - foreach ($countries as $country) { |
|
| 268 | - if ($country instanceof EE_Country) { |
|
| 269 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 274 | - array( |
|
| 275 | - 'name' => 'new_state_micro_form', |
|
| 276 | - 'html_id' => 'new_state_micro_form', |
|
| 277 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 278 | - 'subsections' => array( |
|
| 279 | - // add hidden input to indicate that a new state is being added |
|
| 280 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 281 | - array( |
|
| 282 | - 'html_name' => str_replace( |
|
| 283 | - 'state', |
|
| 284 | - 'nsmf_add_new_state', |
|
| 285 | - $input->html_name() |
|
| 286 | - ), |
|
| 287 | - 'html_id' => str_replace( |
|
| 288 | - 'state', |
|
| 289 | - 'nsmf_add_new_state', |
|
| 290 | - $input->html_id() |
|
| 291 | - ), |
|
| 292 | - 'default' => 0, |
|
| 293 | - ) |
|
| 294 | - ), |
|
| 295 | - // add link for displaying hidden container |
|
| 296 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 297 | - apply_filters( |
|
| 298 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 299 | - EEH_HTML::link( |
|
| 300 | - '', |
|
| 301 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 302 | - '', |
|
| 303 | - 'display-' . $input->html_id(), |
|
| 304 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 305 | - '', |
|
| 306 | - 'data-target="' . $input->html_id() . '"' |
|
| 307 | - ) |
|
| 308 | - ) |
|
| 309 | - ), |
|
| 310 | - // add initial html for hidden container |
|
| 311 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 312 | - apply_filters( |
|
| 313 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 314 | - EEH_HTML::div( |
|
| 315 | - '', |
|
| 316 | - $input->html_id() . '-dv', |
|
| 317 | - 'ee-form-add-new-state-dv', |
|
| 318 | - 'display: none;' |
|
| 319 | - ) . |
|
| 320 | - EEH_HTML::h6( |
|
| 321 | - esc_html__( |
|
| 322 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 323 | - 'event_espresso' |
|
| 324 | - ) |
|
| 325 | - ) . |
|
| 326 | - EEH_HTML::ul() . |
|
| 327 | - EEH_HTML::li( |
|
| 328 | - esc_html__( |
|
| 329 | - 'first select the Country that your State/Province belongs to', |
|
| 330 | - 'event_espresso' |
|
| 331 | - ) |
|
| 332 | - ) . |
|
| 333 | - EEH_HTML::li( |
|
| 334 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 335 | - ) . |
|
| 336 | - EEH_HTML::li( |
|
| 337 | - esc_html__( |
|
| 338 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 339 | - 'event_espresso' |
|
| 340 | - ) |
|
| 341 | - ) . |
|
| 342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 343 | - EEH_HTML::ulx() |
|
| 344 | - ) |
|
| 345 | - ), |
|
| 346 | - // NEW STATE COUNTRY |
|
| 347 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 348 | - $country_options, |
|
| 349 | - array( |
|
| 350 | - 'html_name' => $country_name, |
|
| 351 | - 'html_id' => str_replace( |
|
| 352 | - 'state', |
|
| 353 | - 'nsmf_new_state_country', |
|
| 354 | - $input->html_id() |
|
| 355 | - ), |
|
| 356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 357 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 358 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 359 | - 'required' => false, |
|
| 360 | - ) |
|
| 361 | - ), |
|
| 362 | - // NEW STATE NAME |
|
| 363 | - 'new_state_name' => new EE_Text_Input( |
|
| 364 | - array( |
|
| 365 | - 'html_name' => $state_name, |
|
| 366 | - 'html_id' => str_replace( |
|
| 367 | - 'state', |
|
| 368 | - 'nsmf_new_state_name', |
|
| 369 | - $input->html_id() |
|
| 370 | - ), |
|
| 371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 372 | - 'html_label_text' => esc_html__( |
|
| 373 | - 'New State/Province Name', |
|
| 374 | - 'event_espresso' |
|
| 375 | - ), |
|
| 376 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 377 | - 'required' => false, |
|
| 378 | - ) |
|
| 379 | - ), |
|
| 380 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 381 | - // NEW STATE NAME |
|
| 382 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | - array( |
|
| 384 | - 'html_name' => $abbrv_name, |
|
| 385 | - 'html_id' => str_replace( |
|
| 386 | - 'state', |
|
| 387 | - 'nsmf_new_state_abbrv', |
|
| 388 | - $input->html_id() |
|
| 389 | - ), |
|
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | - 'html_label_text' => esc_html__( |
|
| 392 | - 'New State/Province Abbreviation', |
|
| 393 | - 'event_espresso' |
|
| 394 | - ) . ' *', |
|
| 395 | - 'other_html_attributes' => 'size="24"', |
|
| 396 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 397 | - 'required' => false, |
|
| 398 | - ) |
|
| 399 | - ), |
|
| 400 | - // "submit" button |
|
| 401 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | - apply_filters( |
|
| 403 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | - EEH_HTML::nbsp(3) . |
|
| 405 | - EEH_HTML::link( |
|
| 406 | - '', |
|
| 407 | - esc_html__('ADD', 'event_espresso'), |
|
| 408 | - '', |
|
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 410 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 411 | - '', |
|
| 412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 413 | - ) |
|
| 414 | - ) |
|
| 415 | - ), |
|
| 416 | - // extra info |
|
| 417 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 418 | - apply_filters( |
|
| 419 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 420 | - EEH_HTML::br(2) |
|
| 421 | - . |
|
| 422 | - EEH_HTML::div('', '', 'small-text') |
|
| 423 | - . |
|
| 424 | - EEH_HTML::strong( |
|
| 425 | - '* ' . |
|
| 426 | - esc_html__( |
|
| 427 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 428 | - 'event_espresso' |
|
| 429 | - ) |
|
| 430 | - ) |
|
| 431 | - . |
|
| 432 | - EEH_HTML::br() |
|
| 433 | - . |
|
| 434 | - sprintf( |
|
| 435 | - esc_html__( |
|
| 436 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 437 | - 'event_espresso' |
|
| 438 | - ), |
|
| 439 | - EEH_HTML::link( |
|
| 440 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 441 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 442 | - '', |
|
| 443 | - '', |
|
| 444 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 445 | - '', |
|
| 446 | - 'target="_blank"' |
|
| 447 | - ) |
|
| 448 | - ) |
|
| 449 | - . |
|
| 450 | - EEH_HTML::divx() |
|
| 451 | - . |
|
| 452 | - EEH_HTML::br() |
|
| 453 | - . |
|
| 454 | - EEH_HTML::link( |
|
| 455 | - '', |
|
| 456 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 457 | - '', |
|
| 458 | - 'hide-' . $input->html_id(), |
|
| 459 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 460 | - '', |
|
| 461 | - 'data-target="' . $input->html_id() . '"' |
|
| 462 | - ) |
|
| 463 | - . |
|
| 464 | - EEH_HTML::divx() |
|
| 465 | - . |
|
| 466 | - EEH_HTML::br() |
|
| 467 | - ) |
|
| 468 | - ), |
|
| 469 | - ), |
|
| 470 | - ) |
|
| 471 | - ); |
|
| 472 | - $question_group_reg_form->add_subsections( |
|
| 473 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 474 | - 'state', |
|
| 475 | - false |
|
| 476 | - ); |
|
| 477 | - } |
|
| 478 | - return $question_group_reg_form; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * set_new_state_input_width |
|
| 484 | - * |
|
| 485 | - * @return int|string |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws InvalidArgumentException |
|
| 488 | - * @throws InvalidDataTypeException |
|
| 489 | - * @throws InvalidInterfaceException |
|
| 490 | - * @throws ReflectionException |
|
| 491 | - */ |
|
| 492 | - public static function add_new_state() |
|
| 493 | - { |
|
| 494 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 495 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 496 | - EE_Registry::instance()->load_model('State'); |
|
| 497 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 498 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 499 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 500 | - : false; |
|
| 501 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 502 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 503 | - : false; |
|
| 504 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 505 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 506 | - : false; |
|
| 507 | - if ($state_country && $state_name && $state_abbr) { |
|
| 508 | - $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 509 | - array( |
|
| 510 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 511 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 512 | - 'STA_name' => ucwords($state_name), |
|
| 513 | - 'STA_active' => false, |
|
| 514 | - ) |
|
| 515 | - ); |
|
| 516 | - if ($new_state instanceof EE_State) { |
|
| 517 | - // clean house |
|
| 518 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 519 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 520 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 521 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 522 | - // get any existing new states |
|
| 523 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 524 | - 'nsmf_new_states' |
|
| 525 | - ); |
|
| 526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 527 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 528 | - array('nsmf_new_states' => $new_states) |
|
| 529 | - ); |
|
| 530 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 531 | - echo wp_json_encode( |
|
| 532 | - array( |
|
| 533 | - 'success' => true, |
|
| 534 | - 'id' => $new_state->ID(), |
|
| 535 | - 'name' => $new_state->name(), |
|
| 536 | - 'abbrev' => $new_state->abbrev(), |
|
| 537 | - 'country_iso' => $new_state->country_iso(), |
|
| 538 | - 'country_name' => $new_state->country()->name(), |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - exit(); |
|
| 542 | - } |
|
| 543 | - return $new_state->ID(); |
|
| 544 | - } |
|
| 545 | - } else { |
|
| 546 | - $error = esc_html__( |
|
| 547 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ); |
|
| 550 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 551 | - echo wp_json_encode(array('error' => $error)); |
|
| 552 | - exit(); |
|
| 553 | - } |
|
| 554 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - return false; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * recursively drills down through request params to remove any that were added by this module |
|
| 563 | - * |
|
| 564 | - * @param array $request_params |
|
| 565 | - * @return array |
|
| 566 | - */ |
|
| 567 | - public static function filter_checkout_request_params($request_params) |
|
| 568 | - { |
|
| 569 | - foreach ($request_params as $form_section) { |
|
| 570 | - if (is_array($form_section)) { |
|
| 571 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 572 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - return $request_params; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * @param array $request_params |
|
| 581 | - * @return array |
|
| 582 | - */ |
|
| 583 | - public static function unset_new_state_request_params($request_params) |
|
| 584 | - { |
|
| 585 | - unset( |
|
| 586 | - $request_params['new_state_micro_form'], |
|
| 587 | - $request_params['new_state_micro_add_new_state'], |
|
| 588 | - $request_params['new_state_micro_new_state_country'], |
|
| 589 | - $request_params['new_state_micro_new_state_name'], |
|
| 590 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 591 | - ); |
|
| 592 | - return $request_params; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @param array $props_n_values |
|
| 598 | - * @return bool |
|
| 599 | - * @throws EE_Error |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidDataTypeException |
|
| 602 | - * @throws InvalidInterfaceException |
|
| 603 | - */ |
|
| 604 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 605 | - { |
|
| 606 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 607 | - if (! empty($existing_state)) { |
|
| 608 | - return array_pop($existing_state); |
|
| 609 | - } |
|
| 610 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 611 | - if ($new_state instanceof EE_State) { |
|
| 612 | - $country_settings_url = add_query_arg( |
|
| 613 | - array( |
|
| 614 | - 'page' => 'espresso_general_settings', |
|
| 615 | - 'action' => 'country_settings', |
|
| 616 | - 'country' => $new_state->country_iso(), |
|
| 617 | - ), |
|
| 618 | - admin_url('admin.php') |
|
| 619 | - ); |
|
| 620 | - // if not non-ajax admin |
|
| 621 | - new PersistentAdminNotice( |
|
| 622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 623 | - sprintf( |
|
| 624 | - esc_html__( |
|
| 625 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 626 | - 'event_espresso' |
|
| 627 | - ), |
|
| 628 | - '<b>' . $new_state->name() . '</b>', |
|
| 629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 631 | - '<a href="' |
|
| 632 | - . $country_settings_url |
|
| 633 | - . '">' |
|
| 634 | - . esc_html__( |
|
| 635 | - 'Event Espresso - General Settings > Countries Tab', |
|
| 636 | - 'event_espresso' |
|
| 637 | - ) |
|
| 638 | - . '</a>', |
|
| 639 | - '<br />' |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 642 | - $new_state->save(); |
|
| 643 | - EEM_State::instance()->reset_cached_states(); |
|
| 644 | - return $new_state; |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * @param string $CNT_ISO |
|
| 652 | - * @param string $STA_ID |
|
| 653 | - * @param array $cols_n_values |
|
| 654 | - * @return void |
|
| 655 | - * @throws DomainException |
|
| 656 | - * @throws EE_Error |
|
| 657 | - * @throws InvalidArgumentException |
|
| 658 | - * @throws InvalidDataTypeException |
|
| 659 | - * @throws InvalidInterfaceException |
|
| 660 | - */ |
|
| 661 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 662 | - { |
|
| 663 | - if (! $CNT_ISO) { |
|
| 664 | - EE_Error::add_error( |
|
| 665 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 666 | - __FILE__, |
|
| 667 | - __FUNCTION__, |
|
| 668 | - __LINE__ |
|
| 669 | - ); |
|
| 670 | - } |
|
| 671 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 672 | - : false; |
|
| 673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 675 | - if ($state instanceof EE_State) { |
|
| 676 | - $STA_abbrev = $state->abbrev(); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - if (! $STA_abbrev) { |
|
| 680 | - EE_Error::add_error( |
|
| 681 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 682 | - __FILE__, |
|
| 683 | - __FUNCTION__, |
|
| 684 | - __LINE__ |
|
| 685 | - ); |
|
| 686 | - } |
|
| 687 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 688 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 689 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 690 | - ); |
|
| 691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * @param EE_State[] $state_options |
|
| 697 | - * @param EE_SPCO_Reg_Step_Attendee_Information|null $reg_step |
|
| 698 | - * @param EE_Registration|null $registration |
|
| 699 | - * @param EE_Question|null $question |
|
| 700 | - * @param null $answer |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws ReflectionException |
|
| 704 | - */ |
|
| 705 | - public static function inject_new_reg_state_into_options( |
|
| 706 | - array $state_options, |
|
| 707 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step = null, |
|
| 708 | - EE_Registration $registration = null, |
|
| 709 | - EE_Question $question = null, |
|
| 710 | - $answer = null |
|
| 711 | - ) { |
|
| 712 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 713 | - && $question->type() === EEM_Question::QST_type_state |
|
| 714 | - ) { |
|
| 715 | - $STA_ID = $answer->value(); |
|
| 716 | - if (! empty($STA_ID)) { |
|
| 717 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 718 | - if ($state instanceof EE_State) { |
|
| 719 | - $country = $state->country(); |
|
| 720 | - if ($country instanceof EE_Country) { |
|
| 721 | - if (! isset($state_options[ $country->name() ])) { |
|
| 722 | - $state_options[ $country->name() ] = array(); |
|
| 723 | - } |
|
| 724 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 725 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - return $state_options; |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * @param EE_Country[] $country_options |
|
| 737 | - * @param EE_SPCO_Reg_Step_Attendee_Information|null $reg_step |
|
| 738 | - * @param EE_Registration|null $registration |
|
| 739 | - * @param EE_Question|null $question |
|
| 740 | - * @param null $answer |
|
| 741 | - * @return array |
|
| 742 | - * @throws EE_Error |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public static function inject_new_reg_country_into_options( |
|
| 746 | - array $country_options, |
|
| 747 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step = null, |
|
| 748 | - EE_Registration $registration = null, |
|
| 749 | - EE_Question $question = null, |
|
| 750 | - $answer = null |
|
| 751 | - ) { |
|
| 752 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 753 | - && $question->type() === EEM_Question::QST_type_country |
|
| 754 | - ) { |
|
| 755 | - $CNT_ISO = $answer->value(); |
|
| 756 | - if (! empty($CNT_ISO)) { |
|
| 757 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 758 | - if ($country instanceof EE_Country) { |
|
| 759 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 760 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - return $country_options; |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - /** |
|
| 770 | - * @param EE_State[] $state_options |
|
| 771 | - * @return array |
|
| 772 | - * @throws EE_Error |
|
| 773 | - * @throws InvalidArgumentException |
|
| 774 | - * @throws InvalidDataTypeException |
|
| 775 | - * @throws InvalidInterfaceException |
|
| 776 | - */ |
|
| 777 | - public static function state_options($state_options = array()) |
|
| 778 | - { |
|
| 779 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 780 | - foreach ($new_states as $new_state) { |
|
| 781 | - if ($new_state instanceof EE_State |
|
| 782 | - && $new_state->country() instanceof EE_Country |
|
| 783 | - ) { |
|
| 784 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - return $state_options; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * @return array |
|
| 793 | - * @throws InvalidArgumentException |
|
| 794 | - * @throws InvalidDataTypeException |
|
| 795 | - * @throws InvalidInterfaceException |
|
| 796 | - */ |
|
| 797 | - protected static function _get_new_states() |
|
| 798 | - { |
|
| 799 | - $new_states = array(); |
|
| 800 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 801 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 802 | - 'nsmf_new_states' |
|
| 803 | - ); |
|
| 804 | - } |
|
| 805 | - return is_array($new_states) ? $new_states : array(); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * @param EE_Country[] $country_options |
|
| 811 | - * @return array |
|
| 812 | - * @throws EE_Error |
|
| 813 | - * @throws InvalidArgumentException |
|
| 814 | - * @throws InvalidDataTypeException |
|
| 815 | - * @throws InvalidInterfaceException |
|
| 816 | - */ |
|
| 817 | - public static function country_options($country_options = array()) |
|
| 818 | - { |
|
| 819 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 820 | - foreach ($new_states as $new_state) { |
|
| 821 | - if ($new_state instanceof EE_State |
|
| 822 | - && $new_state->country() instanceof EE_Country |
|
| 823 | - ) { |
|
| 824 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - return $country_options; |
|
| 828 | - } |
|
| 20 | + /** |
|
| 21 | + * @return EED_Module|EED_Add_New_State |
|
| 22 | + */ |
|
| 23 | + public static function instance() |
|
| 24 | + { |
|
| 25 | + return parent::get_instance(__CLASS__); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | + add_filter( |
|
| 40 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 41 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 42 | + 1, |
|
| 43 | + 1 |
|
| 44 | + ); |
|
| 45 | + add_filter( |
|
| 46 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 47 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 48 | + 1, |
|
| 49 | + 1 |
|
| 50 | + ); |
|
| 51 | + add_filter( |
|
| 52 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 53 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 54 | + 10, |
|
| 55 | + 1 |
|
| 56 | + ); |
|
| 57 | + add_filter( |
|
| 58 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 59 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 60 | + 10, |
|
| 61 | + 5 |
|
| 62 | + ); |
|
| 63 | + add_filter( |
|
| 64 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 65 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 66 | + 10, |
|
| 67 | + 5 |
|
| 68 | + ); |
|
| 69 | + add_filter( |
|
| 70 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 71 | + array('EED_Add_New_State', 'state_options'), |
|
| 72 | + 10, |
|
| 73 | + 1 |
|
| 74 | + ); |
|
| 75 | + add_filter( |
|
| 76 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 77 | + array('EED_Add_New_State', 'country_options'), |
|
| 78 | + 10, |
|
| 79 | + 1 |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 86 | + * |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | + public static function set_hooks_admin() |
|
| 90 | + { |
|
| 91 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 92 | + add_filter( |
|
| 93 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 94 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 95 | + 1, |
|
| 96 | + 1 |
|
| 97 | + ); |
|
| 98 | + add_filter( |
|
| 99 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 100 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 101 | + 1, |
|
| 102 | + 1 |
|
| 103 | + ); |
|
| 104 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 105 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 106 | + add_filter( |
|
| 107 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 108 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 109 | + 10, |
|
| 110 | + 1 |
|
| 111 | + ); |
|
| 112 | + add_action( |
|
| 113 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 114 | + array('EED_Add_New_State', 'update_country_settings'), |
|
| 115 | + 10, |
|
| 116 | + 3 |
|
| 117 | + ); |
|
| 118 | + add_action( |
|
| 119 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 120 | + array('EED_Add_New_State', 'update_country_settings'), |
|
| 121 | + 10, |
|
| 122 | + 3 |
|
| 123 | + ); |
|
| 124 | + add_filter( |
|
| 125 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 126 | + array('EED_Add_New_State', 'state_options'), |
|
| 127 | + 10, |
|
| 128 | + 1 |
|
| 129 | + ); |
|
| 130 | + add_filter( |
|
| 131 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 132 | + array('EED_Add_New_State', 'country_options'), |
|
| 133 | + 10, |
|
| 134 | + 1 |
|
| 135 | + ); |
|
| 136 | + add_filter( |
|
| 137 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 138 | + array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
| 139 | + 10, |
|
| 140 | + 1 |
|
| 141 | + ); |
|
| 142 | + add_filter( |
|
| 143 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 144 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 145 | + 10, |
|
| 146 | + 5 |
|
| 147 | + ); |
|
| 148 | + add_filter( |
|
| 149 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 150 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 151 | + 10, |
|
| 152 | + 5 |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + public static function set_definitions() |
|
| 161 | + { |
|
| 162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 163 | + define( |
|
| 164 | + 'ANS_TEMPLATES_PATH', |
|
| 165 | + str_replace( |
|
| 166 | + '\\', |
|
| 167 | + '/', |
|
| 168 | + plugin_dir_path(__FILE__) |
|
| 169 | + ) . 'templates/' |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param WP $WP |
|
| 176 | + * @return void |
|
| 177 | + */ |
|
| 178 | + public function run($WP) |
|
| 179 | + { |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public static function translate_js_strings() |
|
| 187 | + { |
|
| 188 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 189 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 190 | + 'event_espresso' |
|
| 191 | + ); |
|
| 192 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 193 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ); |
|
| 196 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 197 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 198 | + 'event_espresso' |
|
| 199 | + ); |
|
| 200 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 201 | + 'The new state was successfully saved to the database.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ); |
|
| 204 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 205 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return void |
|
| 213 | + */ |
|
| 214 | + public static function wp_enqueue_scripts() |
|
| 215 | + { |
|
| 216 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 217 | + wp_register_script( |
|
| 218 | + 'add_new_state', |
|
| 219 | + ANS_ASSETS_URL . 'add_new_state.js', |
|
| 220 | + array('espresso_core', 'single_page_checkout'), |
|
| 221 | + EVENT_ESPRESSO_VERSION, |
|
| 222 | + true |
|
| 223 | + ); |
|
| 224 | + wp_enqueue_script('add_new_state'); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * display_add_new_state_micro_form |
|
| 232 | + * |
|
| 233 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 234 | + * @return string |
|
| 235 | + * @throws EE_Error |
|
| 236 | + * @throws InvalidArgumentException |
|
| 237 | + * @throws InvalidDataTypeException |
|
| 238 | + * @throws InvalidInterfaceException |
|
| 239 | + */ |
|
| 240 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 241 | + { |
|
| 242 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 245 | + // is the "state" question in this form section? |
|
| 246 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | + // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | + // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | + if ($input instanceof EE_State_Select_Input) { |
|
| 251 | + $input->html_name(); |
|
| 252 | + } |
|
| 253 | + return $question_group_reg_form; |
|
| 254 | + } |
|
| 255 | + // we're only doing this for state select inputs |
|
| 256 | + if ($input instanceof EE_State_Select_Input |
|
| 257 | + && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 258 | + ) { |
|
| 259 | + // grab any set values from the request |
|
| 260 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 261 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 262 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 263 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 264 | + $country_options = array(); |
|
| 265 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 266 | + if (! empty($countries)) { |
|
| 267 | + foreach ($countries as $country) { |
|
| 268 | + if ($country instanceof EE_Country) { |
|
| 269 | + $country_options[ $country->ID() ] = $country->name(); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 274 | + array( |
|
| 275 | + 'name' => 'new_state_micro_form', |
|
| 276 | + 'html_id' => 'new_state_micro_form', |
|
| 277 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 278 | + 'subsections' => array( |
|
| 279 | + // add hidden input to indicate that a new state is being added |
|
| 280 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 281 | + array( |
|
| 282 | + 'html_name' => str_replace( |
|
| 283 | + 'state', |
|
| 284 | + 'nsmf_add_new_state', |
|
| 285 | + $input->html_name() |
|
| 286 | + ), |
|
| 287 | + 'html_id' => str_replace( |
|
| 288 | + 'state', |
|
| 289 | + 'nsmf_add_new_state', |
|
| 290 | + $input->html_id() |
|
| 291 | + ), |
|
| 292 | + 'default' => 0, |
|
| 293 | + ) |
|
| 294 | + ), |
|
| 295 | + // add link for displaying hidden container |
|
| 296 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 297 | + apply_filters( |
|
| 298 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 299 | + EEH_HTML::link( |
|
| 300 | + '', |
|
| 301 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 302 | + '', |
|
| 303 | + 'display-' . $input->html_id(), |
|
| 304 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 305 | + '', |
|
| 306 | + 'data-target="' . $input->html_id() . '"' |
|
| 307 | + ) |
|
| 308 | + ) |
|
| 309 | + ), |
|
| 310 | + // add initial html for hidden container |
|
| 311 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 312 | + apply_filters( |
|
| 313 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 314 | + EEH_HTML::div( |
|
| 315 | + '', |
|
| 316 | + $input->html_id() . '-dv', |
|
| 317 | + 'ee-form-add-new-state-dv', |
|
| 318 | + 'display: none;' |
|
| 319 | + ) . |
|
| 320 | + EEH_HTML::h6( |
|
| 321 | + esc_html__( |
|
| 322 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 323 | + 'event_espresso' |
|
| 324 | + ) |
|
| 325 | + ) . |
|
| 326 | + EEH_HTML::ul() . |
|
| 327 | + EEH_HTML::li( |
|
| 328 | + esc_html__( |
|
| 329 | + 'first select the Country that your State/Province belongs to', |
|
| 330 | + 'event_espresso' |
|
| 331 | + ) |
|
| 332 | + ) . |
|
| 333 | + EEH_HTML::li( |
|
| 334 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 335 | + ) . |
|
| 336 | + EEH_HTML::li( |
|
| 337 | + esc_html__( |
|
| 338 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 339 | + 'event_espresso' |
|
| 340 | + ) |
|
| 341 | + ) . |
|
| 342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 343 | + EEH_HTML::ulx() |
|
| 344 | + ) |
|
| 345 | + ), |
|
| 346 | + // NEW STATE COUNTRY |
|
| 347 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 348 | + $country_options, |
|
| 349 | + array( |
|
| 350 | + 'html_name' => $country_name, |
|
| 351 | + 'html_id' => str_replace( |
|
| 352 | + 'state', |
|
| 353 | + 'nsmf_new_state_country', |
|
| 354 | + $input->html_id() |
|
| 355 | + ), |
|
| 356 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 357 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 358 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 359 | + 'required' => false, |
|
| 360 | + ) |
|
| 361 | + ), |
|
| 362 | + // NEW STATE NAME |
|
| 363 | + 'new_state_name' => new EE_Text_Input( |
|
| 364 | + array( |
|
| 365 | + 'html_name' => $state_name, |
|
| 366 | + 'html_id' => str_replace( |
|
| 367 | + 'state', |
|
| 368 | + 'nsmf_new_state_name', |
|
| 369 | + $input->html_id() |
|
| 370 | + ), |
|
| 371 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 372 | + 'html_label_text' => esc_html__( |
|
| 373 | + 'New State/Province Name', |
|
| 374 | + 'event_espresso' |
|
| 375 | + ), |
|
| 376 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 377 | + 'required' => false, |
|
| 378 | + ) |
|
| 379 | + ), |
|
| 380 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 381 | + // NEW STATE NAME |
|
| 382 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | + array( |
|
| 384 | + 'html_name' => $abbrv_name, |
|
| 385 | + 'html_id' => str_replace( |
|
| 386 | + 'state', |
|
| 387 | + 'nsmf_new_state_abbrv', |
|
| 388 | + $input->html_id() |
|
| 389 | + ), |
|
| 390 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | + 'html_label_text' => esc_html__( |
|
| 392 | + 'New State/Province Abbreviation', |
|
| 393 | + 'event_espresso' |
|
| 394 | + ) . ' *', |
|
| 395 | + 'other_html_attributes' => 'size="24"', |
|
| 396 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 397 | + 'required' => false, |
|
| 398 | + ) |
|
| 399 | + ), |
|
| 400 | + // "submit" button |
|
| 401 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | + apply_filters( |
|
| 403 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | + EEH_HTML::nbsp(3) . |
|
| 405 | + EEH_HTML::link( |
|
| 406 | + '', |
|
| 407 | + esc_html__('ADD', 'event_espresso'), |
|
| 408 | + '', |
|
| 409 | + 'submit-' . $new_state_submit_id, |
|
| 410 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 411 | + '', |
|
| 412 | + 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 413 | + ) |
|
| 414 | + ) |
|
| 415 | + ), |
|
| 416 | + // extra info |
|
| 417 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 418 | + apply_filters( |
|
| 419 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 420 | + EEH_HTML::br(2) |
|
| 421 | + . |
|
| 422 | + EEH_HTML::div('', '', 'small-text') |
|
| 423 | + . |
|
| 424 | + EEH_HTML::strong( |
|
| 425 | + '* ' . |
|
| 426 | + esc_html__( |
|
| 427 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 428 | + 'event_espresso' |
|
| 429 | + ) |
|
| 430 | + ) |
|
| 431 | + . |
|
| 432 | + EEH_HTML::br() |
|
| 433 | + . |
|
| 434 | + sprintf( |
|
| 435 | + esc_html__( |
|
| 436 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 437 | + 'event_espresso' |
|
| 438 | + ), |
|
| 439 | + EEH_HTML::link( |
|
| 440 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 441 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 442 | + '', |
|
| 443 | + '', |
|
| 444 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 445 | + '', |
|
| 446 | + 'target="_blank"' |
|
| 447 | + ) |
|
| 448 | + ) |
|
| 449 | + . |
|
| 450 | + EEH_HTML::divx() |
|
| 451 | + . |
|
| 452 | + EEH_HTML::br() |
|
| 453 | + . |
|
| 454 | + EEH_HTML::link( |
|
| 455 | + '', |
|
| 456 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 457 | + '', |
|
| 458 | + 'hide-' . $input->html_id(), |
|
| 459 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 460 | + '', |
|
| 461 | + 'data-target="' . $input->html_id() . '"' |
|
| 462 | + ) |
|
| 463 | + . |
|
| 464 | + EEH_HTML::divx() |
|
| 465 | + . |
|
| 466 | + EEH_HTML::br() |
|
| 467 | + ) |
|
| 468 | + ), |
|
| 469 | + ), |
|
| 470 | + ) |
|
| 471 | + ); |
|
| 472 | + $question_group_reg_form->add_subsections( |
|
| 473 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 474 | + 'state', |
|
| 475 | + false |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | + return $question_group_reg_form; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * set_new_state_input_width |
|
| 484 | + * |
|
| 485 | + * @return int|string |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws InvalidArgumentException |
|
| 488 | + * @throws InvalidDataTypeException |
|
| 489 | + * @throws InvalidInterfaceException |
|
| 490 | + * @throws ReflectionException |
|
| 491 | + */ |
|
| 492 | + public static function add_new_state() |
|
| 493 | + { |
|
| 494 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 495 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 496 | + EE_Registry::instance()->load_model('State'); |
|
| 497 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 498 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 499 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 500 | + : false; |
|
| 501 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 502 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 503 | + : false; |
|
| 504 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 505 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 506 | + : false; |
|
| 507 | + if ($state_country && $state_name && $state_abbr) { |
|
| 508 | + $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 509 | + array( |
|
| 510 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 511 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 512 | + 'STA_name' => ucwords($state_name), |
|
| 513 | + 'STA_active' => false, |
|
| 514 | + ) |
|
| 515 | + ); |
|
| 516 | + if ($new_state instanceof EE_State) { |
|
| 517 | + // clean house |
|
| 518 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 519 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 520 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 521 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 522 | + // get any existing new states |
|
| 523 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 524 | + 'nsmf_new_states' |
|
| 525 | + ); |
|
| 526 | + $new_states[ $new_state->ID() ] = $new_state; |
|
| 527 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 528 | + array('nsmf_new_states' => $new_states) |
|
| 529 | + ); |
|
| 530 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 531 | + echo wp_json_encode( |
|
| 532 | + array( |
|
| 533 | + 'success' => true, |
|
| 534 | + 'id' => $new_state->ID(), |
|
| 535 | + 'name' => $new_state->name(), |
|
| 536 | + 'abbrev' => $new_state->abbrev(), |
|
| 537 | + 'country_iso' => $new_state->country_iso(), |
|
| 538 | + 'country_name' => $new_state->country()->name(), |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + exit(); |
|
| 542 | + } |
|
| 543 | + return $new_state->ID(); |
|
| 544 | + } |
|
| 545 | + } else { |
|
| 546 | + $error = esc_html__( |
|
| 547 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ); |
|
| 550 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 551 | + echo wp_json_encode(array('error' => $error)); |
|
| 552 | + exit(); |
|
| 553 | + } |
|
| 554 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + return false; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * recursively drills down through request params to remove any that were added by this module |
|
| 563 | + * |
|
| 564 | + * @param array $request_params |
|
| 565 | + * @return array |
|
| 566 | + */ |
|
| 567 | + public static function filter_checkout_request_params($request_params) |
|
| 568 | + { |
|
| 569 | + foreach ($request_params as $form_section) { |
|
| 570 | + if (is_array($form_section)) { |
|
| 571 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 572 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + return $request_params; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * @param array $request_params |
|
| 581 | + * @return array |
|
| 582 | + */ |
|
| 583 | + public static function unset_new_state_request_params($request_params) |
|
| 584 | + { |
|
| 585 | + unset( |
|
| 586 | + $request_params['new_state_micro_form'], |
|
| 587 | + $request_params['new_state_micro_add_new_state'], |
|
| 588 | + $request_params['new_state_micro_new_state_country'], |
|
| 589 | + $request_params['new_state_micro_new_state_name'], |
|
| 590 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 591 | + ); |
|
| 592 | + return $request_params; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @param array $props_n_values |
|
| 598 | + * @return bool |
|
| 599 | + * @throws EE_Error |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidDataTypeException |
|
| 602 | + * @throws InvalidInterfaceException |
|
| 603 | + */ |
|
| 604 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 605 | + { |
|
| 606 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 607 | + if (! empty($existing_state)) { |
|
| 608 | + return array_pop($existing_state); |
|
| 609 | + } |
|
| 610 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 611 | + if ($new_state instanceof EE_State) { |
|
| 612 | + $country_settings_url = add_query_arg( |
|
| 613 | + array( |
|
| 614 | + 'page' => 'espresso_general_settings', |
|
| 615 | + 'action' => 'country_settings', |
|
| 616 | + 'country' => $new_state->country_iso(), |
|
| 617 | + ), |
|
| 618 | + admin_url('admin.php') |
|
| 619 | + ); |
|
| 620 | + // if not non-ajax admin |
|
| 621 | + new PersistentAdminNotice( |
|
| 622 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 623 | + sprintf( |
|
| 624 | + esc_html__( |
|
| 625 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 626 | + 'event_espresso' |
|
| 627 | + ), |
|
| 628 | + '<b>' . $new_state->name() . '</b>', |
|
| 629 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 631 | + '<a href="' |
|
| 632 | + . $country_settings_url |
|
| 633 | + . '">' |
|
| 634 | + . esc_html__( |
|
| 635 | + 'Event Espresso - General Settings > Countries Tab', |
|
| 636 | + 'event_espresso' |
|
| 637 | + ) |
|
| 638 | + . '</a>', |
|
| 639 | + '<br />' |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | + $new_state->save(); |
|
| 643 | + EEM_State::instance()->reset_cached_states(); |
|
| 644 | + return $new_state; |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * @param string $CNT_ISO |
|
| 652 | + * @param string $STA_ID |
|
| 653 | + * @param array $cols_n_values |
|
| 654 | + * @return void |
|
| 655 | + * @throws DomainException |
|
| 656 | + * @throws EE_Error |
|
| 657 | + * @throws InvalidArgumentException |
|
| 658 | + * @throws InvalidDataTypeException |
|
| 659 | + * @throws InvalidInterfaceException |
|
| 660 | + */ |
|
| 661 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 662 | + { |
|
| 663 | + if (! $CNT_ISO) { |
|
| 664 | + EE_Error::add_error( |
|
| 665 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 666 | + __FILE__, |
|
| 667 | + __FUNCTION__, |
|
| 668 | + __LINE__ |
|
| 669 | + ); |
|
| 670 | + } |
|
| 671 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 672 | + : false; |
|
| 673 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 675 | + if ($state instanceof EE_State) { |
|
| 676 | + $STA_abbrev = $state->abbrev(); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + if (! $STA_abbrev) { |
|
| 680 | + EE_Error::add_error( |
|
| 681 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 682 | + __FILE__, |
|
| 683 | + __FUNCTION__, |
|
| 684 | + __LINE__ |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 688 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 689 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 690 | + ); |
|
| 691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * @param EE_State[] $state_options |
|
| 697 | + * @param EE_SPCO_Reg_Step_Attendee_Information|null $reg_step |
|
| 698 | + * @param EE_Registration|null $registration |
|
| 699 | + * @param EE_Question|null $question |
|
| 700 | + * @param null $answer |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws ReflectionException |
|
| 704 | + */ |
|
| 705 | + public static function inject_new_reg_state_into_options( |
|
| 706 | + array $state_options, |
|
| 707 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step = null, |
|
| 708 | + EE_Registration $registration = null, |
|
| 709 | + EE_Question $question = null, |
|
| 710 | + $answer = null |
|
| 711 | + ) { |
|
| 712 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 713 | + && $question->type() === EEM_Question::QST_type_state |
|
| 714 | + ) { |
|
| 715 | + $STA_ID = $answer->value(); |
|
| 716 | + if (! empty($STA_ID)) { |
|
| 717 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 718 | + if ($state instanceof EE_State) { |
|
| 719 | + $country = $state->country(); |
|
| 720 | + if ($country instanceof EE_Country) { |
|
| 721 | + if (! isset($state_options[ $country->name() ])) { |
|
| 722 | + $state_options[ $country->name() ] = array(); |
|
| 723 | + } |
|
| 724 | + if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 725 | + $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + return $state_options; |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * @param EE_Country[] $country_options |
|
| 737 | + * @param EE_SPCO_Reg_Step_Attendee_Information|null $reg_step |
|
| 738 | + * @param EE_Registration|null $registration |
|
| 739 | + * @param EE_Question|null $question |
|
| 740 | + * @param null $answer |
|
| 741 | + * @return array |
|
| 742 | + * @throws EE_Error |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public static function inject_new_reg_country_into_options( |
|
| 746 | + array $country_options, |
|
| 747 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step = null, |
|
| 748 | + EE_Registration $registration = null, |
|
| 749 | + EE_Question $question = null, |
|
| 750 | + $answer = null |
|
| 751 | + ) { |
|
| 752 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 753 | + && $question->type() === EEM_Question::QST_type_country |
|
| 754 | + ) { |
|
| 755 | + $CNT_ISO = $answer->value(); |
|
| 756 | + if (! empty($CNT_ISO)) { |
|
| 757 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 758 | + if ($country instanceof EE_Country) { |
|
| 759 | + if (! isset($country_options[ $CNT_ISO ])) { |
|
| 760 | + $country_options[ $CNT_ISO ] = $country->name(); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + return $country_options; |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + /** |
|
| 770 | + * @param EE_State[] $state_options |
|
| 771 | + * @return array |
|
| 772 | + * @throws EE_Error |
|
| 773 | + * @throws InvalidArgumentException |
|
| 774 | + * @throws InvalidDataTypeException |
|
| 775 | + * @throws InvalidInterfaceException |
|
| 776 | + */ |
|
| 777 | + public static function state_options($state_options = array()) |
|
| 778 | + { |
|
| 779 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 780 | + foreach ($new_states as $new_state) { |
|
| 781 | + if ($new_state instanceof EE_State |
|
| 782 | + && $new_state->country() instanceof EE_Country |
|
| 783 | + ) { |
|
| 784 | + $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + return $state_options; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * @return array |
|
| 793 | + * @throws InvalidArgumentException |
|
| 794 | + * @throws InvalidDataTypeException |
|
| 795 | + * @throws InvalidInterfaceException |
|
| 796 | + */ |
|
| 797 | + protected static function _get_new_states() |
|
| 798 | + { |
|
| 799 | + $new_states = array(); |
|
| 800 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 801 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 802 | + 'nsmf_new_states' |
|
| 803 | + ); |
|
| 804 | + } |
|
| 805 | + return is_array($new_states) ? $new_states : array(); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * @param EE_Country[] $country_options |
|
| 811 | + * @return array |
|
| 812 | + * @throws EE_Error |
|
| 813 | + * @throws InvalidArgumentException |
|
| 814 | + * @throws InvalidDataTypeException |
|
| 815 | + * @throws InvalidInterfaceException |
|
| 816 | + */ |
|
| 817 | + public static function country_options($country_options = array()) |
|
| 818 | + { |
|
| 819 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 820 | + foreach ($new_states as $new_state) { |
|
| 821 | + if ($new_state instanceof EE_State |
|
| 822 | + && $new_state->country() instanceof EE_Country |
|
| 823 | + ) { |
|
| 824 | + $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + return $country_options; |
|
| 828 | + } |
|
| 829 | 829 | } |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public static function set_definitions() |
| 161 | 161 | { |
| 162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
| 162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
| 163 | 163 | define( |
| 164 | 164 | 'ANS_TEMPLATES_PATH', |
| 165 | 165 | str_replace( |
| 166 | 166 | '\\', |
| 167 | 167 | '/', |
| 168 | 168 | plugin_dir_path(__FILE__) |
| 169 | - ) . 'templates/' |
|
| 169 | + ).'templates/' |
|
| 170 | 170 | ); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 217 | 217 | wp_register_script( |
| 218 | 218 | 'add_new_state', |
| 219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 219 | + ANS_ASSETS_URL.'add_new_state.js', |
|
| 220 | 220 | array('espresso_core', 'single_page_checkout'), |
| 221 | 221 | EVENT_ESPRESSO_VERSION, |
| 222 | 222 | true |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 264 | 264 | $country_options = array(); |
| 265 | 265 | $countries = EEM_Country::instance()->get_all_countries(); |
| 266 | - if (! empty($countries)) { |
|
| 266 | + if ( ! empty($countries)) { |
|
| 267 | 267 | foreach ($countries as $country) { |
| 268 | 268 | if ($country instanceof EE_Country) { |
| 269 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 269 | + $country_options[$country->ID()] = $country->name(); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | } |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | '', |
| 301 | 301 | esc_html__('click here to add a new state/province', 'event_espresso'), |
| 302 | 302 | '', |
| 303 | - 'display-' . $input->html_id(), |
|
| 303 | + 'display-'.$input->html_id(), |
|
| 304 | 304 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 305 | 305 | '', |
| 306 | - 'data-target="' . $input->html_id() . '"' |
|
| 306 | + 'data-target="'.$input->html_id().'"' |
|
| 307 | 307 | ) |
| 308 | 308 | ) |
| 309 | 309 | ), |
@@ -313,33 +313,33 @@ discard block |
||
| 313 | 313 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 314 | 314 | EEH_HTML::div( |
| 315 | 315 | '', |
| 316 | - $input->html_id() . '-dv', |
|
| 316 | + $input->html_id().'-dv', |
|
| 317 | 317 | 'ee-form-add-new-state-dv', |
| 318 | 318 | 'display: none;' |
| 319 | - ) . |
|
| 319 | + ). |
|
| 320 | 320 | EEH_HTML::h6( |
| 321 | 321 | esc_html__( |
| 322 | 322 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
| 323 | 323 | 'event_espresso' |
| 324 | 324 | ) |
| 325 | - ) . |
|
| 326 | - EEH_HTML::ul() . |
|
| 325 | + ). |
|
| 326 | + EEH_HTML::ul(). |
|
| 327 | 327 | EEH_HTML::li( |
| 328 | 328 | esc_html__( |
| 329 | 329 | 'first select the Country that your State/Province belongs to', |
| 330 | 330 | 'event_espresso' |
| 331 | 331 | ) |
| 332 | - ) . |
|
| 332 | + ). |
|
| 333 | 333 | EEH_HTML::li( |
| 334 | 334 | esc_html__('enter the name of your State/Province', 'event_espresso') |
| 335 | - ) . |
|
| 335 | + ). |
|
| 336 | 336 | EEH_HTML::li( |
| 337 | 337 | esc_html__( |
| 338 | 338 | 'enter a two to six letter abbreviation for the name of your State/Province', |
| 339 | 339 | 'event_espresso' |
| 340 | 340 | ) |
| 341 | - ) . |
|
| 342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 341 | + ). |
|
| 342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
| 343 | 343 | EEH_HTML::ulx() |
| 344 | 344 | ) |
| 345 | 345 | ), |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | 'nsmf_new_state_country', |
| 354 | 354 | $input->html_id() |
| 355 | 355 | ), |
| 356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 356 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 357 | 357 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
| 358 | 358 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
| 359 | 359 | 'required' => false, |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | 'nsmf_new_state_name', |
| 369 | 369 | $input->html_id() |
| 370 | 370 | ), |
| 371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 371 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 372 | 372 | 'html_label_text' => esc_html__( |
| 373 | 373 | 'New State/Province Name', |
| 374 | 374 | 'event_espresso' |
@@ -387,11 +387,11 @@ discard block |
||
| 387 | 387 | 'nsmf_new_state_abbrv', |
| 388 | 388 | $input->html_id() |
| 389 | 389 | ), |
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 390 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 391 | 391 | 'html_label_text' => esc_html__( |
| 392 | 392 | 'New State/Province Abbreviation', |
| 393 | 393 | 'event_espresso' |
| 394 | - ) . ' *', |
|
| 394 | + ).' *', |
|
| 395 | 395 | 'other_html_attributes' => 'size="24"', |
| 396 | 396 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
| 397 | 397 | 'required' => false, |
@@ -401,15 +401,15 @@ discard block |
||
| 401 | 401 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
| 402 | 402 | apply_filters( |
| 403 | 403 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
| 404 | - EEH_HTML::nbsp(3) . |
|
| 404 | + EEH_HTML::nbsp(3). |
|
| 405 | 405 | EEH_HTML::link( |
| 406 | 406 | '', |
| 407 | 407 | esc_html__('ADD', 'event_espresso'), |
| 408 | 408 | '', |
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 409 | + 'submit-'.$new_state_submit_id, |
|
| 410 | 410 | 'ee-form-add-new-state-submit button button-secondary', |
| 411 | 411 | '', |
| 412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 412 | + 'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"' |
|
| 413 | 413 | ) |
| 414 | 414 | ) |
| 415 | 415 | ), |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | EEH_HTML::div('', '', 'small-text') |
| 423 | 423 | . |
| 424 | 424 | EEH_HTML::strong( |
| 425 | - '* ' . |
|
| 425 | + '* '. |
|
| 426 | 426 | esc_html__( |
| 427 | 427 | 'Don\'t know your State/Province Abbreviation?', |
| 428 | 428 | 'event_espresso' |
@@ -455,10 +455,10 @@ discard block |
||
| 455 | 455 | '', |
| 456 | 456 | esc_html__('cancel new State/Province', 'event_espresso'), |
| 457 | 457 | '', |
| 458 | - 'hide-' . $input->html_id(), |
|
| 458 | + 'hide-'.$input->html_id(), |
|
| 459 | 459 | 'ee-form-cancel-new-state-lnk smaller-text', |
| 460 | 460 | '', |
| 461 | - 'data-target="' . $input->html_id() . '"' |
|
| 461 | + 'data-target="'.$input->html_id().'"' |
|
| 462 | 462 | ) |
| 463 | 463 | . |
| 464 | 464 | EEH_HTML::divx() |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
| 524 | 524 | 'nsmf_new_states' |
| 525 | 525 | ); |
| 526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 526 | + $new_states[$new_state->ID()] = $new_state; |
|
| 527 | 527 | EE_Registry::instance()->SSN->set_session_data( |
| 528 | 528 | array('nsmf_new_states' => $new_states) |
| 529 | 529 | ); |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | public static function save_new_state_to_db($props_n_values = array()) |
| 605 | 605 | { |
| 606 | 606 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
| 607 | - if (! empty($existing_state)) { |
|
| 607 | + if ( ! empty($existing_state)) { |
|
| 608 | 608 | return array_pop($existing_state); |
| 609 | 609 | } |
| 610 | 610 | $new_state = EE_State::new_instance($props_n_values); |
@@ -619,15 +619,15 @@ discard block |
||
| 619 | 619 | ); |
| 620 | 620 | // if not non-ajax admin |
| 621 | 621 | new PersistentAdminNotice( |
| 622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 622 | + 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(), |
|
| 623 | 623 | sprintf( |
| 624 | 624 | esc_html__( |
| 625 | 625 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 626 | 626 | 'event_espresso' |
| 627 | 627 | ), |
| 628 | - '<b>' . $new_state->name() . '</b>', |
|
| 629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 628 | + '<b>'.$new_state->name().'</b>', |
|
| 629 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 630 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 631 | 631 | '<a href="' |
| 632 | 632 | . $country_settings_url |
| 633 | 633 | . '">' |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | */ |
| 661 | 661 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
| 662 | 662 | { |
| 663 | - if (! $CNT_ISO) { |
|
| 663 | + if ( ! $CNT_ISO) { |
|
| 664 | 664 | EE_Error::add_error( |
| 665 | 665 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
| 666 | 666 | __FILE__, |
@@ -670,13 +670,13 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 672 | 672 | : false; |
| 673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 673 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | 674 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 675 | 675 | if ($state instanceof EE_State) { |
| 676 | 676 | $STA_abbrev = $state->abbrev(); |
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | - if (! $STA_abbrev) { |
|
| 679 | + if ( ! $STA_abbrev) { |
|
| 680 | 680 | EE_Error::add_error( |
| 681 | 681 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 682 | 682 | __FILE__, |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
| 689 | 689 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
| 690 | 690 | ); |
| 691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -713,16 +713,16 @@ discard block |
||
| 713 | 713 | && $question->type() === EEM_Question::QST_type_state |
| 714 | 714 | ) { |
| 715 | 715 | $STA_ID = $answer->value(); |
| 716 | - if (! empty($STA_ID)) { |
|
| 716 | + if ( ! empty($STA_ID)) { |
|
| 717 | 717 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 718 | 718 | if ($state instanceof EE_State) { |
| 719 | 719 | $country = $state->country(); |
| 720 | 720 | if ($country instanceof EE_Country) { |
| 721 | - if (! isset($state_options[ $country->name() ])) { |
|
| 722 | - $state_options[ $country->name() ] = array(); |
|
| 721 | + if ( ! isset($state_options[$country->name()])) { |
|
| 722 | + $state_options[$country->name()] = array(); |
|
| 723 | 723 | } |
| 724 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 725 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 724 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 725 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 726 | 726 | } |
| 727 | 727 | } |
| 728 | 728 | } |
@@ -753,11 +753,11 @@ discard block |
||
| 753 | 753 | && $question->type() === EEM_Question::QST_type_country |
| 754 | 754 | ) { |
| 755 | 755 | $CNT_ISO = $answer->value(); |
| 756 | - if (! empty($CNT_ISO)) { |
|
| 756 | + if ( ! empty($CNT_ISO)) { |
|
| 757 | 757 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 758 | 758 | if ($country instanceof EE_Country) { |
| 759 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 760 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 759 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 760 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 761 | 761 | } |
| 762 | 762 | } |
| 763 | 763 | } |
@@ -781,7 +781,7 @@ discard block |
||
| 781 | 781 | if ($new_state instanceof EE_State |
| 782 | 782 | && $new_state->country() instanceof EE_Country |
| 783 | 783 | ) { |
| 784 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 784 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | return $state_options; |
@@ -821,7 +821,7 @@ discard block |
||
| 821 | 821 | if ($new_state instanceof EE_State |
| 822 | 822 | && $new_state->country() instanceof EE_Country |
| 823 | 823 | ) { |
| 824 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 824 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 825 | 825 | } |
| 826 | 826 | } |
| 827 | 827 | return $country_options; |
@@ -17,1336 +17,1336 @@ |
||
| 17 | 17 | class EED_Messages extends EED_Module |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * This holds the EE_messages controller |
|
| 22 | - * |
|
| 23 | - * @deprecated 4.9.0 |
|
| 24 | - * @var EE_messages $_EEMSG |
|
| 25 | - */ |
|
| 26 | - protected static $_EEMSG; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 30 | - */ |
|
| 31 | - protected static $_message_resource_manager; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * This holds the EE_Messages_Processor business class. |
|
| 35 | - * |
|
| 36 | - * @type EE_Messages_Processor |
|
| 37 | - */ |
|
| 38 | - protected static $_MSG_PROCESSOR; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * holds all the paths for various messages components. |
|
| 42 | - * Utilized by autoloader registry |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected static $_MSG_PATHS; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 51 | - * Format is: |
|
| 52 | - * array( |
|
| 53 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 54 | - * ) |
|
| 55 | - * |
|
| 56 | - * @var EE_Messages_Template_Pack[] |
|
| 57 | - */ |
|
| 58 | - protected static $_TMP_PACKS = array(); |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return EED_Messages |
|
| 63 | - */ |
|
| 64 | - public static function instance() |
|
| 65 | - { |
|
| 66 | - return parent::get_instance(__CLASS__); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 72 | - * |
|
| 73 | - * @since 4.5.0 |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public static function set_hooks() |
|
| 77 | - { |
|
| 78 | - // actions |
|
| 79 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 80 | - add_action( |
|
| 81 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | - array('EED_Messages', 'maybe_registration'), |
|
| 83 | - 10, |
|
| 84 | - 2 |
|
| 85 | - ); |
|
| 86 | - // filters |
|
| 87 | - add_filter( |
|
| 88 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 89 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 90 | - 10, |
|
| 91 | - 4 |
|
| 92 | - ); |
|
| 93 | - add_filter( |
|
| 94 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 95 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 96 | - 10, |
|
| 97 | - 4 |
|
| 98 | - ); |
|
| 99 | - // register routes |
|
| 100 | - self::_register_routes(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return void |
|
| 108 | - */ |
|
| 109 | - public static function set_hooks_admin() |
|
| 110 | - { |
|
| 111 | - // actions |
|
| 112 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 113 | - add_action( |
|
| 114 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 115 | - array('EED_Messages', 'payment_reminder'), |
|
| 116 | - 10 |
|
| 117 | - ); |
|
| 118 | - add_action( |
|
| 119 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 120 | - array('EED_Messages', 'maybe_registration'), |
|
| 121 | - 10, |
|
| 122 | - 3 |
|
| 123 | - ); |
|
| 124 | - add_action( |
|
| 125 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 126 | - array('EED_Messages', 'send_newsletter_message'), |
|
| 127 | - 10, |
|
| 128 | - 2 |
|
| 129 | - ); |
|
| 130 | - add_action( |
|
| 131 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 132 | - array('EED_Messages', 'cancelled_registration'), |
|
| 133 | - 10 |
|
| 134 | - ); |
|
| 135 | - add_action( |
|
| 136 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 137 | - array('EED_Messages', 'process_admin_payment'), |
|
| 138 | - 10, |
|
| 139 | - 1 |
|
| 140 | - ); |
|
| 141 | - // filters |
|
| 142 | - add_filter( |
|
| 143 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 144 | - array('EED_Messages', 'process_resend'), |
|
| 145 | - 10, |
|
| 146 | - 2 |
|
| 147 | - ); |
|
| 148 | - add_filter( |
|
| 149 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 150 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 151 | - 10, |
|
| 152 | - 4 |
|
| 153 | - ); |
|
| 154 | - add_filter( |
|
| 155 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 156 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 157 | - 10, |
|
| 158 | - 4 |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * All the message triggers done by route go in here. |
|
| 165 | - * |
|
| 166 | - * @since 4.5.0 |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - protected static function _register_routes() |
|
| 170 | - { |
|
| 171 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 172 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 173 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 174 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 175 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * This is called when a browser display trigger is executed. |
|
| 181 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 182 | - * browser. |
|
| 183 | - * |
|
| 184 | - * @since 4.9.0 |
|
| 185 | - * @param WP $WP |
|
| 186 | - * @throws EE_Error |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws ReflectionException |
|
| 189 | - * @throws InvalidDataTypeException |
|
| 190 | - * @throws InvalidInterfaceException |
|
| 191 | - */ |
|
| 192 | - public function browser_trigger($WP) |
|
| 193 | - { |
|
| 194 | - // ensure controller is loaded |
|
| 195 | - self::_load_controller(); |
|
| 196 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 197 | - try { |
|
| 198 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 199 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 200 | - } catch (EE_Error $e) { |
|
| 201 | - $error_msg = __( |
|
| 202 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ); |
|
| 205 | - // add specific message for developers if WP_DEBUG in on |
|
| 206 | - $error_msg .= '||' . $e->getMessage(); |
|
| 207 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * This is called when a browser error trigger is executed. |
|
| 214 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 215 | - * message and display it. |
|
| 216 | - * |
|
| 217 | - * @since 4.9.0 |
|
| 218 | - * @param $WP |
|
| 219 | - * @throws EE_Error |
|
| 220 | - * @throws InvalidArgumentException |
|
| 221 | - * @throws InvalidDataTypeException |
|
| 222 | - * @throws InvalidInterfaceException |
|
| 223 | - */ |
|
| 224 | - public function browser_error_trigger($WP) |
|
| 225 | - { |
|
| 226 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 227 | - if ($token) { |
|
| 228 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 229 | - if ($message instanceof EE_Message) { |
|
| 230 | - header('HTTP/1.1 200 OK'); |
|
| 231 | - $error_msg = nl2br($message->error_message()); |
|
| 232 | - ?> |
|
| 20 | + /** |
|
| 21 | + * This holds the EE_messages controller |
|
| 22 | + * |
|
| 23 | + * @deprecated 4.9.0 |
|
| 24 | + * @var EE_messages $_EEMSG |
|
| 25 | + */ |
|
| 26 | + protected static $_EEMSG; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 30 | + */ |
|
| 31 | + protected static $_message_resource_manager; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * This holds the EE_Messages_Processor business class. |
|
| 35 | + * |
|
| 36 | + * @type EE_Messages_Processor |
|
| 37 | + */ |
|
| 38 | + protected static $_MSG_PROCESSOR; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * holds all the paths for various messages components. |
|
| 42 | + * Utilized by autoloader registry |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected static $_MSG_PATHS; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 51 | + * Format is: |
|
| 52 | + * array( |
|
| 53 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 54 | + * ) |
|
| 55 | + * |
|
| 56 | + * @var EE_Messages_Template_Pack[] |
|
| 57 | + */ |
|
| 58 | + protected static $_TMP_PACKS = array(); |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return EED_Messages |
|
| 63 | + */ |
|
| 64 | + public static function instance() |
|
| 65 | + { |
|
| 66 | + return parent::get_instance(__CLASS__); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 72 | + * |
|
| 73 | + * @since 4.5.0 |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public static function set_hooks() |
|
| 77 | + { |
|
| 78 | + // actions |
|
| 79 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 80 | + add_action( |
|
| 81 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 82 | + array('EED_Messages', 'maybe_registration'), |
|
| 83 | + 10, |
|
| 84 | + 2 |
|
| 85 | + ); |
|
| 86 | + // filters |
|
| 87 | + add_filter( |
|
| 88 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 89 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 90 | + 10, |
|
| 91 | + 4 |
|
| 92 | + ); |
|
| 93 | + add_filter( |
|
| 94 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 95 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 96 | + 10, |
|
| 97 | + 4 |
|
| 98 | + ); |
|
| 99 | + // register routes |
|
| 100 | + self::_register_routes(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return void |
|
| 108 | + */ |
|
| 109 | + public static function set_hooks_admin() |
|
| 110 | + { |
|
| 111 | + // actions |
|
| 112 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 113 | + add_action( |
|
| 114 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 115 | + array('EED_Messages', 'payment_reminder'), |
|
| 116 | + 10 |
|
| 117 | + ); |
|
| 118 | + add_action( |
|
| 119 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 120 | + array('EED_Messages', 'maybe_registration'), |
|
| 121 | + 10, |
|
| 122 | + 3 |
|
| 123 | + ); |
|
| 124 | + add_action( |
|
| 125 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 126 | + array('EED_Messages', 'send_newsletter_message'), |
|
| 127 | + 10, |
|
| 128 | + 2 |
|
| 129 | + ); |
|
| 130 | + add_action( |
|
| 131 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 132 | + array('EED_Messages', 'cancelled_registration'), |
|
| 133 | + 10 |
|
| 134 | + ); |
|
| 135 | + add_action( |
|
| 136 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 137 | + array('EED_Messages', 'process_admin_payment'), |
|
| 138 | + 10, |
|
| 139 | + 1 |
|
| 140 | + ); |
|
| 141 | + // filters |
|
| 142 | + add_filter( |
|
| 143 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 144 | + array('EED_Messages', 'process_resend'), |
|
| 145 | + 10, |
|
| 146 | + 2 |
|
| 147 | + ); |
|
| 148 | + add_filter( |
|
| 149 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 150 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 151 | + 10, |
|
| 152 | + 4 |
|
| 153 | + ); |
|
| 154 | + add_filter( |
|
| 155 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 156 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 157 | + 10, |
|
| 158 | + 4 |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * All the message triggers done by route go in here. |
|
| 165 | + * |
|
| 166 | + * @since 4.5.0 |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + protected static function _register_routes() |
|
| 170 | + { |
|
| 171 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 172 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 173 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 174 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 175 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * This is called when a browser display trigger is executed. |
|
| 181 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 182 | + * browser. |
|
| 183 | + * |
|
| 184 | + * @since 4.9.0 |
|
| 185 | + * @param WP $WP |
|
| 186 | + * @throws EE_Error |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws ReflectionException |
|
| 189 | + * @throws InvalidDataTypeException |
|
| 190 | + * @throws InvalidInterfaceException |
|
| 191 | + */ |
|
| 192 | + public function browser_trigger($WP) |
|
| 193 | + { |
|
| 194 | + // ensure controller is loaded |
|
| 195 | + self::_load_controller(); |
|
| 196 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 197 | + try { |
|
| 198 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 199 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 200 | + } catch (EE_Error $e) { |
|
| 201 | + $error_msg = __( |
|
| 202 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ); |
|
| 205 | + // add specific message for developers if WP_DEBUG in on |
|
| 206 | + $error_msg .= '||' . $e->getMessage(); |
|
| 207 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * This is called when a browser error trigger is executed. |
|
| 214 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 215 | + * message and display it. |
|
| 216 | + * |
|
| 217 | + * @since 4.9.0 |
|
| 218 | + * @param $WP |
|
| 219 | + * @throws EE_Error |
|
| 220 | + * @throws InvalidArgumentException |
|
| 221 | + * @throws InvalidDataTypeException |
|
| 222 | + * @throws InvalidInterfaceException |
|
| 223 | + */ |
|
| 224 | + public function browser_error_trigger($WP) |
|
| 225 | + { |
|
| 226 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 227 | + if ($token) { |
|
| 228 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 229 | + if ($message instanceof EE_Message) { |
|
| 230 | + header('HTTP/1.1 200 OK'); |
|
| 231 | + $error_msg = nl2br($message->error_message()); |
|
| 232 | + ?> |
|
| 233 | 233 | <!DOCTYPE html> |
| 234 | 234 | <html> |
| 235 | 235 | <head></head> |
| 236 | 236 | <body> |
| 237 | 237 | <?php echo empty($error_msg) |
| 238 | - ? esc_html__( |
|
| 239 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 240 | - 'event_espresso' |
|
| 241 | - ) |
|
| 242 | - : wp_kses( |
|
| 243 | - $error_msg, |
|
| 244 | - array( |
|
| 245 | - 'a' => array( |
|
| 246 | - 'href' => array(), |
|
| 247 | - 'title' => array(), |
|
| 248 | - ), |
|
| 249 | - 'span' => array(), |
|
| 250 | - 'div' => array(), |
|
| 251 | - 'p' => array(), |
|
| 252 | - 'strong' => array(), |
|
| 253 | - 'em' => array(), |
|
| 254 | - 'br' => array(), |
|
| 255 | - ) |
|
| 256 | - ); ?> |
|
| 238 | + ? esc_html__( |
|
| 239 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 240 | + 'event_espresso' |
|
| 241 | + ) |
|
| 242 | + : wp_kses( |
|
| 243 | + $error_msg, |
|
| 244 | + array( |
|
| 245 | + 'a' => array( |
|
| 246 | + 'href' => array(), |
|
| 247 | + 'title' => array(), |
|
| 248 | + ), |
|
| 249 | + 'span' => array(), |
|
| 250 | + 'div' => array(), |
|
| 251 | + 'p' => array(), |
|
| 252 | + 'strong' => array(), |
|
| 253 | + 'em' => array(), |
|
| 254 | + 'br' => array(), |
|
| 255 | + ) |
|
| 256 | + ); ?> |
|
| 257 | 257 | </body> |
| 258 | 258 | </html> |
| 259 | 259 | <?php |
| 260 | - exit; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * This runs when the msg_url_trigger route has initiated. |
|
| 269 | - * |
|
| 270 | - * @since 4.5.0 |
|
| 271 | - * @param WP $WP |
|
| 272 | - * @throws EE_Error |
|
| 273 | - * @throws InvalidArgumentException |
|
| 274 | - * @throws ReflectionException |
|
| 275 | - * @throws InvalidDataTypeException |
|
| 276 | - * @throws InvalidInterfaceException |
|
| 277 | - */ |
|
| 278 | - public function run($WP) |
|
| 279 | - { |
|
| 280 | - // ensure controller is loaded |
|
| 281 | - self::_load_controller(); |
|
| 282 | - // attempt to process message |
|
| 283 | - try { |
|
| 284 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 285 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 286 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 287 | - } catch (EE_Error $e) { |
|
| 288 | - $error_msg = __( |
|
| 289 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 290 | - 'event_espresso' |
|
| 291 | - ); |
|
| 292 | - // add specific message for developers if WP_DEBUG in on |
|
| 293 | - $error_msg .= '||' . $e->getMessage(); |
|
| 294 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 301 | - * |
|
| 302 | - * @param WP $WP |
|
| 303 | - */ |
|
| 304 | - public function execute_batch_request($WP) |
|
| 305 | - { |
|
| 306 | - $this->run_cron(); |
|
| 307 | - header('HTTP/1.1 200 OK'); |
|
| 308 | - exit(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 314 | - * request. |
|
| 315 | - */ |
|
| 316 | - public function run_cron() |
|
| 317 | - { |
|
| 318 | - self::_load_controller(); |
|
| 319 | - // get required vars |
|
| 320 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 321 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 322 | - |
|
| 323 | - // now let's verify transient, if not valid exit immediately |
|
| 324 | - if (! get_transient($transient_key)) { |
|
| 325 | - /** |
|
| 326 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 327 | - * request. |
|
| 328 | - */ |
|
| 329 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // if made it here, lets' delete the transient to keep the db clean |
|
| 333 | - delete_transient($transient_key); |
|
| 334 | - |
|
| 335 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 336 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 337 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 338 | - self::$_MSG_PROCESSOR->$method(); |
|
| 339 | - } else { |
|
| 340 | - // no matching task |
|
| 341 | - /** |
|
| 342 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 343 | - * request. |
|
| 344 | - */ |
|
| 345 | - trigger_error( |
|
| 346 | - esc_attr( |
|
| 347 | - sprintf( |
|
| 348 | - __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 349 | - $cron_type |
|
| 350 | - ) |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * This is used to retrieve the template pack for the given name. |
|
| 362 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 363 | - * the default template pack is returned. |
|
| 364 | - * |
|
| 365 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 366 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 367 | - * in generating the Pack class name). |
|
| 368 | - * @return EE_Messages_Template_Pack |
|
| 369 | - * @throws EE_Error |
|
| 370 | - * @throws InvalidArgumentException |
|
| 371 | - * @throws ReflectionException |
|
| 372 | - * @throws InvalidDataTypeException |
|
| 373 | - * @throws InvalidInterfaceException |
|
| 374 | - */ |
|
| 375 | - public static function get_template_pack($template_pack_name) |
|
| 376 | - { |
|
| 377 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 378 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Retrieves an array of all template packs. |
|
| 384 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 385 | - * |
|
| 386 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 387 | - * @return EE_Messages_Template_Pack[] |
|
| 388 | - * @throws EE_Error |
|
| 389 | - * @throws InvalidArgumentException |
|
| 390 | - * @throws ReflectionException |
|
| 391 | - * @throws InvalidDataTypeException |
|
| 392 | - * @throws InvalidInterfaceException |
|
| 393 | - */ |
|
| 394 | - public static function get_template_packs() |
|
| 395 | - { |
|
| 396 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 397 | - |
|
| 398 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
| 399 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 400 | - $template_pack_collection->rewind(); |
|
| 401 | - $template_packs = array(); |
|
| 402 | - while ($template_pack_collection->valid()) { |
|
| 403 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 404 | - $template_pack_collection->next(); |
|
| 405 | - } |
|
| 406 | - return $template_packs; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 412 | - * |
|
| 413 | - * @since 4.5.0 |
|
| 414 | - * @return void |
|
| 415 | - * @throws EE_Error |
|
| 416 | - */ |
|
| 417 | - public static function set_autoloaders() |
|
| 418 | - { |
|
| 419 | - if (empty(self::$_MSG_PATHS)) { |
|
| 420 | - self::_set_messages_paths(); |
|
| 421 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 422 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 423 | - } |
|
| 424 | - // add aliases |
|
| 425 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 426 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 433 | - * for use by the Messages Autoloaders |
|
| 434 | - * |
|
| 435 | - * @since 4.5.0 |
|
| 436 | - * @return void. |
|
| 437 | - */ |
|
| 438 | - protected static function _set_messages_paths() |
|
| 439 | - { |
|
| 440 | - $dir_ref = array( |
|
| 441 | - 'messages/message_type', |
|
| 442 | - 'messages/messenger', |
|
| 443 | - 'messages/defaults', |
|
| 444 | - 'messages/defaults/email', |
|
| 445 | - 'messages/data_class', |
|
| 446 | - 'messages/validators', |
|
| 447 | - 'messages/validators/email', |
|
| 448 | - 'messages/validators/html', |
|
| 449 | - 'shortcodes', |
|
| 450 | - ); |
|
| 451 | - $paths = array(); |
|
| 452 | - foreach ($dir_ref as $index => $dir) { |
|
| 453 | - $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 454 | - } |
|
| 455 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Takes care of loading dependencies |
|
| 461 | - * |
|
| 462 | - * @since 4.5.0 |
|
| 463 | - * @return void |
|
| 464 | - * @throws EE_Error |
|
| 465 | - * @throws InvalidArgumentException |
|
| 466 | - * @throws ReflectionException |
|
| 467 | - * @throws InvalidDataTypeException |
|
| 468 | - * @throws InvalidInterfaceException |
|
| 469 | - */ |
|
| 470 | - protected static function _load_controller() |
|
| 471 | - { |
|
| 472 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 473 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 474 | - self::set_autoloaders(); |
|
| 475 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 476 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 477 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @param EE_Transaction $transaction |
|
| 484 | - * @throws EE_Error |
|
| 485 | - * @throws InvalidArgumentException |
|
| 486 | - * @throws InvalidDataTypeException |
|
| 487 | - * @throws InvalidInterfaceException |
|
| 488 | - * @throws ReflectionException |
|
| 489 | - */ |
|
| 490 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 491 | - { |
|
| 492 | - self::_load_controller(); |
|
| 493 | - $data = array($transaction, null); |
|
| 494 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 500 | - * |
|
| 501 | - * @param EE_Transaction $transaction object |
|
| 502 | - * @param EE_Payment|null $payment object |
|
| 503 | - * @return void |
|
| 504 | - * @throws EE_Error |
|
| 505 | - * @throws InvalidArgumentException |
|
| 506 | - * @throws ReflectionException |
|
| 507 | - * @throws InvalidDataTypeException |
|
| 508 | - * @throws InvalidInterfaceException |
|
| 509 | - */ |
|
| 510 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 511 | - { |
|
| 512 | - // if there's no payment object, then we cannot do a payment type message! |
|
| 513 | - if (! $payment instanceof EE_Payment) { |
|
| 514 | - return; |
|
| 515 | - } |
|
| 516 | - self::_load_controller(); |
|
| 517 | - $data = array($transaction, $payment); |
|
| 518 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 519 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 520 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 521 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 522 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * @param EE_Transaction $transaction |
|
| 528 | - * @throws EE_Error |
|
| 529 | - * @throws InvalidArgumentException |
|
| 530 | - * @throws InvalidDataTypeException |
|
| 531 | - * @throws InvalidInterfaceException |
|
| 532 | - * @throws ReflectionException |
|
| 533 | - */ |
|
| 534 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 535 | - { |
|
| 536 | - self::_load_controller(); |
|
| 537 | - $data = array($transaction, null); |
|
| 538 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Trigger for Registration messages |
|
| 544 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 545 | - * incoming transaction. |
|
| 546 | - * |
|
| 547 | - * @param EE_Registration $registration |
|
| 548 | - * @param array $extra_details |
|
| 549 | - * @return void |
|
| 550 | - * @throws EE_Error |
|
| 551 | - * @throws InvalidArgumentException |
|
| 552 | - * @throws InvalidDataTypeException |
|
| 553 | - * @throws InvalidInterfaceException |
|
| 554 | - * @throws ReflectionException |
|
| 555 | - * @throws EntityNotFoundException |
|
| 556 | - */ |
|
| 557 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 558 | - { |
|
| 559 | - |
|
| 560 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 561 | - // no messages please |
|
| 562 | - return; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 566 | - $all_registrations = $registration->transaction()->registrations( |
|
| 567 | - array( |
|
| 568 | - array('REG_deleted' => false), |
|
| 569 | - 'order_by' => array( |
|
| 570 | - 'Event.EVT_name' => 'ASC', |
|
| 571 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 572 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 573 | - ), |
|
| 574 | - ) |
|
| 575 | - ); |
|
| 576 | - // cached array of statuses so we only trigger messages once per status. |
|
| 577 | - $statuses_sent = array(); |
|
| 578 | - self::_load_controller(); |
|
| 579 | - $mtgs = array(); |
|
| 580 | - |
|
| 581 | - // loop through registrations and trigger messages once per status. |
|
| 582 | - foreach ($all_registrations as $reg) { |
|
| 583 | - // already triggered? |
|
| 584 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 585 | - continue; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 589 | - $mtgs = array_merge( |
|
| 590 | - $mtgs, |
|
| 591 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 592 | - $message_type, |
|
| 593 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 594 | - ) |
|
| 595 | - ); |
|
| 596 | - $statuses_sent[] = $reg->status_ID(); |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if (count($statuses_sent) > 1) { |
|
| 600 | - $mtgs = array_merge( |
|
| 601 | - $mtgs, |
|
| 602 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 603 | - 'registration_summary', |
|
| 604 | - array($registration->transaction(), null) |
|
| 605 | - ) |
|
| 606 | - ); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - // batch queue and initiate request |
|
| 610 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 611 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 617 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 618 | - * |
|
| 619 | - * @param EE_Registration $registration [description] |
|
| 620 | - * @param array $extra_details [description] |
|
| 621 | - * @return bool true = send away, false = nope halt the presses. |
|
| 622 | - */ |
|
| 623 | - protected static function _verify_registration_notification_send( |
|
| 624 | - EE_Registration $registration, |
|
| 625 | - $extra_details = array() |
|
| 626 | - ) { |
|
| 627 | - if (! $registration->is_primary_registrant()) { |
|
| 628 | - return false; |
|
| 629 | - } |
|
| 630 | - // first we check if we're in admin and not doing front ajax |
|
| 631 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 632 | - // make sure appropriate admin params are set for sending messages |
|
| 633 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | - || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 635 | - ) { |
|
| 636 | - // no messages sent please. |
|
| 637 | - return false; |
|
| 638 | - } |
|
| 639 | - } else { |
|
| 640 | - // frontend request (either regular or via AJAX) |
|
| 641 | - // TXN is NOT finalized ? |
|
| 642 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - // return visit but nothing changed ??? |
|
| 646 | - if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 647 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 648 | - ) { |
|
| 649 | - return false; |
|
| 650 | - } |
|
| 651 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 652 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 653 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 654 | - ) { |
|
| 655 | - return false; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - // release the kraken |
|
| 659 | - return true; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 665 | - * status id. |
|
| 666 | - * |
|
| 667 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 668 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 669 | - * @param string $reg_status |
|
| 670 | - * @return array |
|
| 671 | - * @throws EE_Error |
|
| 672 | - * @throws InvalidArgumentException |
|
| 673 | - * @throws ReflectionException |
|
| 674 | - * @throws InvalidDataTypeException |
|
| 675 | - * @throws InvalidInterfaceException |
|
| 676 | - */ |
|
| 677 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 678 | - { |
|
| 679 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 680 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 682 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - |
|
| 686 | - /** |
|
| 687 | - * Simply returns the payment message type for the given payment status. |
|
| 688 | - * |
|
| 689 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 690 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 691 | - * @param string $payment_status The payment status being matched. |
|
| 692 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 693 | - * @throws EE_Error |
|
| 694 | - * @throws InvalidArgumentException |
|
| 695 | - * @throws ReflectionException |
|
| 696 | - * @throws InvalidDataTypeException |
|
| 697 | - * @throws InvalidInterfaceException |
|
| 698 | - */ |
|
| 699 | - protected static function _get_payment_message_type($payment_status) |
|
| 700 | - { |
|
| 701 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 702 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 704 | - : false; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 710 | - * |
|
| 711 | - * @access public |
|
| 712 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 713 | - * @return bool success/fail |
|
| 714 | - * @throws EE_Error |
|
| 715 | - * @throws InvalidArgumentException |
|
| 716 | - * @throws InvalidDataTypeException |
|
| 717 | - * @throws InvalidInterfaceException |
|
| 718 | - * @throws ReflectionException |
|
| 719 | - */ |
|
| 720 | - public static function process_resend($req_data) |
|
| 721 | - { |
|
| 722 | - self::_load_controller(); |
|
| 723 | - |
|
| 724 | - // if $msgID in this request then skip to the new resend_message |
|
| 725 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 726 | - return self::resend_message(); |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 730 | - $req_data = (array) $req_data; |
|
| 731 | - foreach ($req_data as $request_key => $request_value) { |
|
| 732 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 736 | - )) { |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - try { |
|
| 741 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 742 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 743 | - } catch (EE_Error $e) { |
|
| 744 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 745 | - return false; |
|
| 746 | - } |
|
| 747 | - EE_Error::add_success( |
|
| 748 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 749 | - ); |
|
| 750 | - return true; // everything got queued. |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - /** |
|
| 755 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 756 | - * |
|
| 757 | - * @return bool |
|
| 758 | - * @throws EE_Error |
|
| 759 | - * @throws InvalidArgumentException |
|
| 760 | - * @throws InvalidDataTypeException |
|
| 761 | - * @throws InvalidInterfaceException |
|
| 762 | - * @throws ReflectionException |
|
| 763 | - */ |
|
| 764 | - public static function resend_message() |
|
| 765 | - { |
|
| 766 | - self::_load_controller(); |
|
| 767 | - |
|
| 768 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 769 | - if (! $msgID) { |
|
| 770 | - EE_Error::add_error( |
|
| 771 | - __( |
|
| 772 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 773 | - 'event_espresso' |
|
| 774 | - ), |
|
| 775 | - __FILE__, |
|
| 776 | - __FUNCTION__, |
|
| 777 | - __LINE__ |
|
| 778 | - ); |
|
| 779 | - return false; |
|
| 780 | - } |
|
| 781 | - |
|
| 782 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 783 | - |
|
| 784 | - // setup success message. |
|
| 785 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 786 | - EE_Error::add_success( |
|
| 787 | - sprintf( |
|
| 788 | - _n( |
|
| 789 | - 'There was %d message queued for resending.', |
|
| 790 | - 'There were %d messages queued for resending.', |
|
| 791 | - $count_ready_for_resend, |
|
| 792 | - 'event_espresso' |
|
| 793 | - ), |
|
| 794 | - $count_ready_for_resend |
|
| 795 | - ) |
|
| 796 | - ); |
|
| 797 | - return true; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - |
|
| 801 | - /** |
|
| 802 | - * Message triggers for manual payment applied by admin |
|
| 803 | - * |
|
| 804 | - * @param EE_Payment $payment EE_payment object |
|
| 805 | - * @return bool success/fail |
|
| 806 | - * @throws EE_Error |
|
| 807 | - * @throws InvalidArgumentException |
|
| 808 | - * @throws ReflectionException |
|
| 809 | - * @throws InvalidDataTypeException |
|
| 810 | - * @throws InvalidInterfaceException |
|
| 811 | - */ |
|
| 812 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 813 | - { |
|
| 814 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 815 | - // we need to get the transaction object |
|
| 816 | - $transaction = $payment->transaction(); |
|
| 817 | - if ($transaction instanceof EE_Transaction) { |
|
| 818 | - $data = array($transaction, $payment); |
|
| 819 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 820 | - |
|
| 821 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 822 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 823 | - |
|
| 824 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 825 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 826 | - ? false : $message_type; |
|
| 827 | - |
|
| 828 | - self::_load_controller(); |
|
| 829 | - |
|
| 830 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 831 | - |
|
| 832 | - // get count of queued for generation |
|
| 833 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 834 | - array( |
|
| 835 | - EEM_Message::status_incomplete, |
|
| 836 | - EEM_Message::status_idle, |
|
| 837 | - ) |
|
| 838 | - ); |
|
| 839 | - |
|
| 840 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 841 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 842 | - return true; |
|
| 843 | - } else { |
|
| 844 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 845 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 846 | - ); |
|
| 847 | - /** |
|
| 848 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 849 | - * IMMEDIATE generation. |
|
| 850 | - */ |
|
| 851 | - if ($count_failed > 0) { |
|
| 852 | - EE_Error::add_error( |
|
| 853 | - sprintf( |
|
| 854 | - _n( |
|
| 855 | - 'The payment notification generation failed.', |
|
| 856 | - '%d payment notifications failed being sent.', |
|
| 857 | - $count_failed, |
|
| 858 | - 'event_espresso' |
|
| 859 | - ), |
|
| 860 | - $count_failed |
|
| 861 | - ), |
|
| 862 | - __FILE__, |
|
| 863 | - __FUNCTION__, |
|
| 864 | - __LINE__ |
|
| 865 | - ); |
|
| 866 | - |
|
| 867 | - return false; |
|
| 868 | - } else { |
|
| 869 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 870 | - return true; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - } else { |
|
| 874 | - EE_Error::add_error( |
|
| 875 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 876 | - 'event_espresso' |
|
| 877 | - ); |
|
| 878 | - return false; |
|
| 879 | - } |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 885 | - * |
|
| 886 | - * @since 4.3.0 |
|
| 887 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 888 | - * @param int $grp_id a specific message template group id. |
|
| 889 | - * @return void |
|
| 890 | - * @throws EE_Error |
|
| 891 | - * @throws InvalidArgumentException |
|
| 892 | - * @throws InvalidDataTypeException |
|
| 893 | - * @throws InvalidInterfaceException |
|
| 894 | - * @throws ReflectionException |
|
| 895 | - */ |
|
| 896 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 897 | - { |
|
| 898 | - // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 899 | - EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 900 | - self::_load_controller(); |
|
| 901 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 907 | - * |
|
| 908 | - * @since 4.3.0 |
|
| 909 | - * @param string $registration_message_trigger_url |
|
| 910 | - * @param EE_Registration $registration |
|
| 911 | - * @param string $messenger |
|
| 912 | - * @param string $message_type |
|
| 913 | - * @return string |
|
| 914 | - * @throws EE_Error |
|
| 915 | - * @throws InvalidArgumentException |
|
| 916 | - * @throws InvalidDataTypeException |
|
| 917 | - * @throws InvalidInterfaceException |
|
| 918 | - */ |
|
| 919 | - public static function registration_message_trigger_url( |
|
| 920 | - $registration_message_trigger_url, |
|
| 921 | - EE_Registration $registration, |
|
| 922 | - $messenger = 'html', |
|
| 923 | - $message_type = 'invoice' |
|
| 924 | - ) { |
|
| 925 | - // whitelist $messenger |
|
| 926 | - switch ($messenger) { |
|
| 927 | - case 'pdf': |
|
| 928 | - $sending_messenger = 'pdf'; |
|
| 929 | - $generating_messenger = 'html'; |
|
| 930 | - break; |
|
| 931 | - case 'html': |
|
| 932 | - default: |
|
| 933 | - $sending_messenger = 'html'; |
|
| 934 | - $generating_messenger = 'html'; |
|
| 935 | - break; |
|
| 936 | - } |
|
| 937 | - // whitelist $message_type |
|
| 938 | - switch ($message_type) { |
|
| 939 | - case 'receipt': |
|
| 940 | - $message_type = 'receipt'; |
|
| 941 | - break; |
|
| 942 | - case 'invoice': |
|
| 943 | - default: |
|
| 944 | - $message_type = 'invoice'; |
|
| 945 | - break; |
|
| 946 | - } |
|
| 947 | - // verify that both the messenger AND the message type are active |
|
| 948 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 949 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
| 950 | - ) { |
|
| 951 | - // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 952 | - $template_query_params = array( |
|
| 953 | - 'MTP_is_active' => true, |
|
| 954 | - 'MTP_messenger' => $generating_messenger, |
|
| 955 | - 'MTP_message_type' => $message_type, |
|
| 956 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 957 | - ); |
|
| 958 | - // get the message template group. |
|
| 959 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 960 | - // if we don't have an EE_Message_Template_Group then return |
|
| 961 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 962 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 963 | - unset($template_query_params['Event.EVT_ID']); |
|
| 964 | - // get global template as the fallback |
|
| 965 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 966 | - } |
|
| 967 | - // if we don't have an EE_Message_Template_Group then return |
|
| 968 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 969 | - return ''; |
|
| 970 | - } |
|
| 971 | - // generate the URL |
|
| 972 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 973 | - $sending_messenger, |
|
| 974 | - $generating_messenger, |
|
| 975 | - 'purchaser', |
|
| 976 | - $message_type, |
|
| 977 | - $registration, |
|
| 978 | - $msg_template_group->ID(), |
|
| 979 | - $registration->transaction_ID() |
|
| 980 | - ); |
|
| 981 | - } |
|
| 982 | - return $registration_message_trigger_url; |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - |
|
| 986 | - /** |
|
| 987 | - * Use to generate and return a message preview! |
|
| 988 | - * |
|
| 989 | - * @param string $type This should correspond with a valid message type |
|
| 990 | - * @param string $context This should correspond with a valid context for the message type |
|
| 991 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 992 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 993 | - * preview |
|
| 994 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 995 | - * @throws EE_Error |
|
| 996 | - * @throws InvalidArgumentException |
|
| 997 | - * @throws InvalidDataTypeException |
|
| 998 | - * @throws InvalidInterfaceException |
|
| 999 | - * @throws ReflectionException |
|
| 1000 | - */ |
|
| 1001 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1002 | - { |
|
| 1003 | - self::_load_controller(); |
|
| 1004 | - $mtg = new EE_Message_To_Generate( |
|
| 1005 | - $messenger, |
|
| 1006 | - $type, |
|
| 1007 | - array(), |
|
| 1008 | - $context, |
|
| 1009 | - true |
|
| 1010 | - ); |
|
| 1011 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1012 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1013 | - // loop through all content for the preview and remove any persisted records. |
|
| 1014 | - $content = ''; |
|
| 1015 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1016 | - $content = $message->content(); |
|
| 1017 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1018 | - $message->delete(); |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - return $content; |
|
| 1022 | - } else { |
|
| 1023 | - return $generated_preview_queue; |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1030 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1031 | - * content found in the EE_Message objects in the queue. |
|
| 1032 | - * |
|
| 1033 | - * @since 4.9.0 |
|
| 1034 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 1035 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1036 | - * type name is still required to send along the message type to the |
|
| 1037 | - * messenger because this is used for determining what specific |
|
| 1038 | - * variations might be loaded for the generated message. |
|
| 1039 | - * @param EE_Messages_Queue $queue |
|
| 1040 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1041 | - * aggregate EE_Message object. |
|
| 1042 | - * @return bool success or fail. |
|
| 1043 | - * @throws EE_Error |
|
| 1044 | - * @throws InvalidArgumentException |
|
| 1045 | - * @throws ReflectionException |
|
| 1046 | - * @throws InvalidDataTypeException |
|
| 1047 | - * @throws InvalidInterfaceException |
|
| 1048 | - */ |
|
| 1049 | - public static function send_message_with_messenger_only( |
|
| 1050 | - $messenger, |
|
| 1051 | - $message_type, |
|
| 1052 | - EE_Messages_Queue $queue, |
|
| 1053 | - $custom_subject = '' |
|
| 1054 | - ) { |
|
| 1055 | - self::_load_controller(); |
|
| 1056 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1057 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1058 | - 'Message_To_Generate_From_Queue', |
|
| 1059 | - array( |
|
| 1060 | - $messenger, |
|
| 1061 | - $message_type, |
|
| 1062 | - $queue, |
|
| 1063 | - $custom_subject, |
|
| 1064 | - ) |
|
| 1065 | - ); |
|
| 1066 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1072 | - * |
|
| 1073 | - * @since 4.9.0 |
|
| 1074 | - * @param array $message_ids An array of message ids |
|
| 1075 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1076 | - * messages. |
|
| 1077 | - * @throws EE_Error |
|
| 1078 | - * @throws InvalidArgumentException |
|
| 1079 | - * @throws InvalidDataTypeException |
|
| 1080 | - * @throws InvalidInterfaceException |
|
| 1081 | - * @throws ReflectionException |
|
| 1082 | - */ |
|
| 1083 | - public static function generate_now($message_ids) |
|
| 1084 | - { |
|
| 1085 | - self::_load_controller(); |
|
| 1086 | - $messages = EEM_Message::instance()->get_all( |
|
| 1087 | - array( |
|
| 1088 | - 0 => array( |
|
| 1089 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1090 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1091 | - ), |
|
| 1092 | - ) |
|
| 1093 | - ); |
|
| 1094 | - $generated_queue = false; |
|
| 1095 | - if ($messages) { |
|
| 1096 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1100 | - EE_Error::add_error( |
|
| 1101 | - __( |
|
| 1102 | - 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1103 | - 'event_espresso' |
|
| 1104 | - ), |
|
| 1105 | - __FILE__, |
|
| 1106 | - __FUNCTION__, |
|
| 1107 | - __LINE__ |
|
| 1108 | - ); |
|
| 1109 | - } |
|
| 1110 | - return $generated_queue; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1116 | - * EEM_Message::status_idle |
|
| 1117 | - * |
|
| 1118 | - * @since 4.9.0 |
|
| 1119 | - * @param $message_ids |
|
| 1120 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1121 | - * @throws EE_Error |
|
| 1122 | - * @throws InvalidArgumentException |
|
| 1123 | - * @throws InvalidDataTypeException |
|
| 1124 | - * @throws InvalidInterfaceException |
|
| 1125 | - * @throws ReflectionException |
|
| 1126 | - */ |
|
| 1127 | - public static function send_now($message_ids) |
|
| 1128 | - { |
|
| 1129 | - self::_load_controller(); |
|
| 1130 | - $messages = EEM_Message::instance()->get_all( |
|
| 1131 | - array( |
|
| 1132 | - 0 => array( |
|
| 1133 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1134 | - 'STS_ID' => array( |
|
| 1135 | - 'IN', |
|
| 1136 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1137 | - ), |
|
| 1138 | - ), |
|
| 1139 | - ) |
|
| 1140 | - ); |
|
| 1141 | - $sent_queue = false; |
|
| 1142 | - if ($messages) { |
|
| 1143 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1147 | - EE_Error::add_error( |
|
| 1148 | - __( |
|
| 1149 | - 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1150 | - 'event_espresso' |
|
| 1151 | - ), |
|
| 1152 | - __FILE__, |
|
| 1153 | - __FUNCTION__, |
|
| 1154 | - __LINE__ |
|
| 1155 | - ); |
|
| 1156 | - } else { |
|
| 1157 | - // can count how many sent by using the messages in the queue |
|
| 1158 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1159 | - if ($sent_count > 0) { |
|
| 1160 | - EE_Error::add_success( |
|
| 1161 | - sprintf( |
|
| 1162 | - _n( |
|
| 1163 | - 'There was %d message successfully sent.', |
|
| 1164 | - 'There were %d messages successfully sent.', |
|
| 1165 | - $sent_count, |
|
| 1166 | - 'event_espresso' |
|
| 1167 | - ), |
|
| 1168 | - $sent_count |
|
| 1169 | - ) |
|
| 1170 | - ); |
|
| 1171 | - } else { |
|
| 1172 | - EE_Error::overwrite_errors(); |
|
| 1173 | - EE_Error::add_error( |
|
| 1174 | - __( |
|
| 1175 | - 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 260 | + exit; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * This runs when the msg_url_trigger route has initiated. |
|
| 269 | + * |
|
| 270 | + * @since 4.5.0 |
|
| 271 | + * @param WP $WP |
|
| 272 | + * @throws EE_Error |
|
| 273 | + * @throws InvalidArgumentException |
|
| 274 | + * @throws ReflectionException |
|
| 275 | + * @throws InvalidDataTypeException |
|
| 276 | + * @throws InvalidInterfaceException |
|
| 277 | + */ |
|
| 278 | + public function run($WP) |
|
| 279 | + { |
|
| 280 | + // ensure controller is loaded |
|
| 281 | + self::_load_controller(); |
|
| 282 | + // attempt to process message |
|
| 283 | + try { |
|
| 284 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 285 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 286 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 287 | + } catch (EE_Error $e) { |
|
| 288 | + $error_msg = __( |
|
| 289 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 290 | + 'event_espresso' |
|
| 291 | + ); |
|
| 292 | + // add specific message for developers if WP_DEBUG in on |
|
| 293 | + $error_msg .= '||' . $e->getMessage(); |
|
| 294 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 301 | + * |
|
| 302 | + * @param WP $WP |
|
| 303 | + */ |
|
| 304 | + public function execute_batch_request($WP) |
|
| 305 | + { |
|
| 306 | + $this->run_cron(); |
|
| 307 | + header('HTTP/1.1 200 OK'); |
|
| 308 | + exit(); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 314 | + * request. |
|
| 315 | + */ |
|
| 316 | + public function run_cron() |
|
| 317 | + { |
|
| 318 | + self::_load_controller(); |
|
| 319 | + // get required vars |
|
| 320 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 321 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 322 | + |
|
| 323 | + // now let's verify transient, if not valid exit immediately |
|
| 324 | + if (! get_transient($transient_key)) { |
|
| 325 | + /** |
|
| 326 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 327 | + * request. |
|
| 328 | + */ |
|
| 329 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // if made it here, lets' delete the transient to keep the db clean |
|
| 333 | + delete_transient($transient_key); |
|
| 334 | + |
|
| 335 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 336 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 337 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 338 | + self::$_MSG_PROCESSOR->$method(); |
|
| 339 | + } else { |
|
| 340 | + // no matching task |
|
| 341 | + /** |
|
| 342 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 343 | + * request. |
|
| 344 | + */ |
|
| 345 | + trigger_error( |
|
| 346 | + esc_attr( |
|
| 347 | + sprintf( |
|
| 348 | + __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 349 | + $cron_type |
|
| 350 | + ) |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * This is used to retrieve the template pack for the given name. |
|
| 362 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 363 | + * the default template pack is returned. |
|
| 364 | + * |
|
| 365 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 366 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 367 | + * in generating the Pack class name). |
|
| 368 | + * @return EE_Messages_Template_Pack |
|
| 369 | + * @throws EE_Error |
|
| 370 | + * @throws InvalidArgumentException |
|
| 371 | + * @throws ReflectionException |
|
| 372 | + * @throws InvalidDataTypeException |
|
| 373 | + * @throws InvalidInterfaceException |
|
| 374 | + */ |
|
| 375 | + public static function get_template_pack($template_pack_name) |
|
| 376 | + { |
|
| 377 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 378 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Retrieves an array of all template packs. |
|
| 384 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 385 | + * |
|
| 386 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 387 | + * @return EE_Messages_Template_Pack[] |
|
| 388 | + * @throws EE_Error |
|
| 389 | + * @throws InvalidArgumentException |
|
| 390 | + * @throws ReflectionException |
|
| 391 | + * @throws InvalidDataTypeException |
|
| 392 | + * @throws InvalidInterfaceException |
|
| 393 | + */ |
|
| 394 | + public static function get_template_packs() |
|
| 395 | + { |
|
| 396 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 397 | + |
|
| 398 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
| 399 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 400 | + $template_pack_collection->rewind(); |
|
| 401 | + $template_packs = array(); |
|
| 402 | + while ($template_pack_collection->valid()) { |
|
| 403 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 404 | + $template_pack_collection->next(); |
|
| 405 | + } |
|
| 406 | + return $template_packs; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 412 | + * |
|
| 413 | + * @since 4.5.0 |
|
| 414 | + * @return void |
|
| 415 | + * @throws EE_Error |
|
| 416 | + */ |
|
| 417 | + public static function set_autoloaders() |
|
| 418 | + { |
|
| 419 | + if (empty(self::$_MSG_PATHS)) { |
|
| 420 | + self::_set_messages_paths(); |
|
| 421 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 422 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 423 | + } |
|
| 424 | + // add aliases |
|
| 425 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 426 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 433 | + * for use by the Messages Autoloaders |
|
| 434 | + * |
|
| 435 | + * @since 4.5.0 |
|
| 436 | + * @return void. |
|
| 437 | + */ |
|
| 438 | + protected static function _set_messages_paths() |
|
| 439 | + { |
|
| 440 | + $dir_ref = array( |
|
| 441 | + 'messages/message_type', |
|
| 442 | + 'messages/messenger', |
|
| 443 | + 'messages/defaults', |
|
| 444 | + 'messages/defaults/email', |
|
| 445 | + 'messages/data_class', |
|
| 446 | + 'messages/validators', |
|
| 447 | + 'messages/validators/email', |
|
| 448 | + 'messages/validators/html', |
|
| 449 | + 'shortcodes', |
|
| 450 | + ); |
|
| 451 | + $paths = array(); |
|
| 452 | + foreach ($dir_ref as $index => $dir) { |
|
| 453 | + $paths[ $index ] = EE_LIBRARIES . $dir; |
|
| 454 | + } |
|
| 455 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Takes care of loading dependencies |
|
| 461 | + * |
|
| 462 | + * @since 4.5.0 |
|
| 463 | + * @return void |
|
| 464 | + * @throws EE_Error |
|
| 465 | + * @throws InvalidArgumentException |
|
| 466 | + * @throws ReflectionException |
|
| 467 | + * @throws InvalidDataTypeException |
|
| 468 | + * @throws InvalidInterfaceException |
|
| 469 | + */ |
|
| 470 | + protected static function _load_controller() |
|
| 471 | + { |
|
| 472 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 473 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 474 | + self::set_autoloaders(); |
|
| 475 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 476 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 477 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @param EE_Transaction $transaction |
|
| 484 | + * @throws EE_Error |
|
| 485 | + * @throws InvalidArgumentException |
|
| 486 | + * @throws InvalidDataTypeException |
|
| 487 | + * @throws InvalidInterfaceException |
|
| 488 | + * @throws ReflectionException |
|
| 489 | + */ |
|
| 490 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 491 | + { |
|
| 492 | + self::_load_controller(); |
|
| 493 | + $data = array($transaction, null); |
|
| 494 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 500 | + * |
|
| 501 | + * @param EE_Transaction $transaction object |
|
| 502 | + * @param EE_Payment|null $payment object |
|
| 503 | + * @return void |
|
| 504 | + * @throws EE_Error |
|
| 505 | + * @throws InvalidArgumentException |
|
| 506 | + * @throws ReflectionException |
|
| 507 | + * @throws InvalidDataTypeException |
|
| 508 | + * @throws InvalidInterfaceException |
|
| 509 | + */ |
|
| 510 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 511 | + { |
|
| 512 | + // if there's no payment object, then we cannot do a payment type message! |
|
| 513 | + if (! $payment instanceof EE_Payment) { |
|
| 514 | + return; |
|
| 515 | + } |
|
| 516 | + self::_load_controller(); |
|
| 517 | + $data = array($transaction, $payment); |
|
| 518 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 519 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 520 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 521 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 522 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * @param EE_Transaction $transaction |
|
| 528 | + * @throws EE_Error |
|
| 529 | + * @throws InvalidArgumentException |
|
| 530 | + * @throws InvalidDataTypeException |
|
| 531 | + * @throws InvalidInterfaceException |
|
| 532 | + * @throws ReflectionException |
|
| 533 | + */ |
|
| 534 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 535 | + { |
|
| 536 | + self::_load_controller(); |
|
| 537 | + $data = array($transaction, null); |
|
| 538 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Trigger for Registration messages |
|
| 544 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 545 | + * incoming transaction. |
|
| 546 | + * |
|
| 547 | + * @param EE_Registration $registration |
|
| 548 | + * @param array $extra_details |
|
| 549 | + * @return void |
|
| 550 | + * @throws EE_Error |
|
| 551 | + * @throws InvalidArgumentException |
|
| 552 | + * @throws InvalidDataTypeException |
|
| 553 | + * @throws InvalidInterfaceException |
|
| 554 | + * @throws ReflectionException |
|
| 555 | + * @throws EntityNotFoundException |
|
| 556 | + */ |
|
| 557 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 558 | + { |
|
| 559 | + |
|
| 560 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 561 | + // no messages please |
|
| 562 | + return; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 566 | + $all_registrations = $registration->transaction()->registrations( |
|
| 567 | + array( |
|
| 568 | + array('REG_deleted' => false), |
|
| 569 | + 'order_by' => array( |
|
| 570 | + 'Event.EVT_name' => 'ASC', |
|
| 571 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 572 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 573 | + ), |
|
| 574 | + ) |
|
| 575 | + ); |
|
| 576 | + // cached array of statuses so we only trigger messages once per status. |
|
| 577 | + $statuses_sent = array(); |
|
| 578 | + self::_load_controller(); |
|
| 579 | + $mtgs = array(); |
|
| 580 | + |
|
| 581 | + // loop through registrations and trigger messages once per status. |
|
| 582 | + foreach ($all_registrations as $reg) { |
|
| 583 | + // already triggered? |
|
| 584 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 585 | + continue; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 589 | + $mtgs = array_merge( |
|
| 590 | + $mtgs, |
|
| 591 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 592 | + $message_type, |
|
| 593 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 594 | + ) |
|
| 595 | + ); |
|
| 596 | + $statuses_sent[] = $reg->status_ID(); |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + if (count($statuses_sent) > 1) { |
|
| 600 | + $mtgs = array_merge( |
|
| 601 | + $mtgs, |
|
| 602 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 603 | + 'registration_summary', |
|
| 604 | + array($registration->transaction(), null) |
|
| 605 | + ) |
|
| 606 | + ); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + // batch queue and initiate request |
|
| 610 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 611 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 617 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 618 | + * |
|
| 619 | + * @param EE_Registration $registration [description] |
|
| 620 | + * @param array $extra_details [description] |
|
| 621 | + * @return bool true = send away, false = nope halt the presses. |
|
| 622 | + */ |
|
| 623 | + protected static function _verify_registration_notification_send( |
|
| 624 | + EE_Registration $registration, |
|
| 625 | + $extra_details = array() |
|
| 626 | + ) { |
|
| 627 | + if (! $registration->is_primary_registrant()) { |
|
| 628 | + return false; |
|
| 629 | + } |
|
| 630 | + // first we check if we're in admin and not doing front ajax |
|
| 631 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 632 | + // make sure appropriate admin params are set for sending messages |
|
| 633 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 634 | + || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 635 | + ) { |
|
| 636 | + // no messages sent please. |
|
| 637 | + return false; |
|
| 638 | + } |
|
| 639 | + } else { |
|
| 640 | + // frontend request (either regular or via AJAX) |
|
| 641 | + // TXN is NOT finalized ? |
|
| 642 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + // return visit but nothing changed ??? |
|
| 646 | + if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 647 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 648 | + ) { |
|
| 649 | + return false; |
|
| 650 | + } |
|
| 651 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 652 | + if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 653 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 654 | + ) { |
|
| 655 | + return false; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + // release the kraken |
|
| 659 | + return true; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 665 | + * status id. |
|
| 666 | + * |
|
| 667 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 668 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 669 | + * @param string $reg_status |
|
| 670 | + * @return array |
|
| 671 | + * @throws EE_Error |
|
| 672 | + * @throws InvalidArgumentException |
|
| 673 | + * @throws ReflectionException |
|
| 674 | + * @throws InvalidDataTypeException |
|
| 675 | + * @throws InvalidInterfaceException |
|
| 676 | + */ |
|
| 677 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 678 | + { |
|
| 679 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 680 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 681 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 682 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + |
|
| 686 | + /** |
|
| 687 | + * Simply returns the payment message type for the given payment status. |
|
| 688 | + * |
|
| 689 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 690 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 691 | + * @param string $payment_status The payment status being matched. |
|
| 692 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 693 | + * @throws EE_Error |
|
| 694 | + * @throws InvalidArgumentException |
|
| 695 | + * @throws ReflectionException |
|
| 696 | + * @throws InvalidDataTypeException |
|
| 697 | + * @throws InvalidInterfaceException |
|
| 698 | + */ |
|
| 699 | + protected static function _get_payment_message_type($payment_status) |
|
| 700 | + { |
|
| 701 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 702 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 703 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 704 | + : false; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 710 | + * |
|
| 711 | + * @access public |
|
| 712 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 713 | + * @return bool success/fail |
|
| 714 | + * @throws EE_Error |
|
| 715 | + * @throws InvalidArgumentException |
|
| 716 | + * @throws InvalidDataTypeException |
|
| 717 | + * @throws InvalidInterfaceException |
|
| 718 | + * @throws ReflectionException |
|
| 719 | + */ |
|
| 720 | + public static function process_resend($req_data) |
|
| 721 | + { |
|
| 722 | + self::_load_controller(); |
|
| 723 | + |
|
| 724 | + // if $msgID in this request then skip to the new resend_message |
|
| 725 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 726 | + return self::resend_message(); |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 730 | + $req_data = (array) $req_data; |
|
| 731 | + foreach ($req_data as $request_key => $request_value) { |
|
| 732 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 736 | + )) { |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + try { |
|
| 741 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 742 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 743 | + } catch (EE_Error $e) { |
|
| 744 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 745 | + return false; |
|
| 746 | + } |
|
| 747 | + EE_Error::add_success( |
|
| 748 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 749 | + ); |
|
| 750 | + return true; // everything got queued. |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + /** |
|
| 755 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 756 | + * |
|
| 757 | + * @return bool |
|
| 758 | + * @throws EE_Error |
|
| 759 | + * @throws InvalidArgumentException |
|
| 760 | + * @throws InvalidDataTypeException |
|
| 761 | + * @throws InvalidInterfaceException |
|
| 762 | + * @throws ReflectionException |
|
| 763 | + */ |
|
| 764 | + public static function resend_message() |
|
| 765 | + { |
|
| 766 | + self::_load_controller(); |
|
| 767 | + |
|
| 768 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 769 | + if (! $msgID) { |
|
| 770 | + EE_Error::add_error( |
|
| 771 | + __( |
|
| 772 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 773 | + 'event_espresso' |
|
| 774 | + ), |
|
| 775 | + __FILE__, |
|
| 776 | + __FUNCTION__, |
|
| 777 | + __LINE__ |
|
| 778 | + ); |
|
| 779 | + return false; |
|
| 780 | + } |
|
| 781 | + |
|
| 782 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 783 | + |
|
| 784 | + // setup success message. |
|
| 785 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 786 | + EE_Error::add_success( |
|
| 787 | + sprintf( |
|
| 788 | + _n( |
|
| 789 | + 'There was %d message queued for resending.', |
|
| 790 | + 'There were %d messages queued for resending.', |
|
| 791 | + $count_ready_for_resend, |
|
| 792 | + 'event_espresso' |
|
| 793 | + ), |
|
| 794 | + $count_ready_for_resend |
|
| 795 | + ) |
|
| 796 | + ); |
|
| 797 | + return true; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + |
|
| 801 | + /** |
|
| 802 | + * Message triggers for manual payment applied by admin |
|
| 803 | + * |
|
| 804 | + * @param EE_Payment $payment EE_payment object |
|
| 805 | + * @return bool success/fail |
|
| 806 | + * @throws EE_Error |
|
| 807 | + * @throws InvalidArgumentException |
|
| 808 | + * @throws ReflectionException |
|
| 809 | + * @throws InvalidDataTypeException |
|
| 810 | + * @throws InvalidInterfaceException |
|
| 811 | + */ |
|
| 812 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 813 | + { |
|
| 814 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 815 | + // we need to get the transaction object |
|
| 816 | + $transaction = $payment->transaction(); |
|
| 817 | + if ($transaction instanceof EE_Transaction) { |
|
| 818 | + $data = array($transaction, $payment); |
|
| 819 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 820 | + |
|
| 821 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 822 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 823 | + |
|
| 824 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 825 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 826 | + ? false : $message_type; |
|
| 827 | + |
|
| 828 | + self::_load_controller(); |
|
| 829 | + |
|
| 830 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 831 | + |
|
| 832 | + // get count of queued for generation |
|
| 833 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 834 | + array( |
|
| 835 | + EEM_Message::status_incomplete, |
|
| 836 | + EEM_Message::status_idle, |
|
| 837 | + ) |
|
| 838 | + ); |
|
| 839 | + |
|
| 840 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 841 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 842 | + return true; |
|
| 843 | + } else { |
|
| 844 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 845 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 846 | + ); |
|
| 847 | + /** |
|
| 848 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 849 | + * IMMEDIATE generation. |
|
| 850 | + */ |
|
| 851 | + if ($count_failed > 0) { |
|
| 852 | + EE_Error::add_error( |
|
| 853 | + sprintf( |
|
| 854 | + _n( |
|
| 855 | + 'The payment notification generation failed.', |
|
| 856 | + '%d payment notifications failed being sent.', |
|
| 857 | + $count_failed, |
|
| 858 | + 'event_espresso' |
|
| 859 | + ), |
|
| 860 | + $count_failed |
|
| 861 | + ), |
|
| 862 | + __FILE__, |
|
| 863 | + __FUNCTION__, |
|
| 864 | + __LINE__ |
|
| 865 | + ); |
|
| 866 | + |
|
| 867 | + return false; |
|
| 868 | + } else { |
|
| 869 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 870 | + return true; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + } else { |
|
| 874 | + EE_Error::add_error( |
|
| 875 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 876 | + 'event_espresso' |
|
| 877 | + ); |
|
| 878 | + return false; |
|
| 879 | + } |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 885 | + * |
|
| 886 | + * @since 4.3.0 |
|
| 887 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 888 | + * @param int $grp_id a specific message template group id. |
|
| 889 | + * @return void |
|
| 890 | + * @throws EE_Error |
|
| 891 | + * @throws InvalidArgumentException |
|
| 892 | + * @throws InvalidDataTypeException |
|
| 893 | + * @throws InvalidInterfaceException |
|
| 894 | + * @throws ReflectionException |
|
| 895 | + */ |
|
| 896 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 897 | + { |
|
| 898 | + // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 899 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 900 | + self::_load_controller(); |
|
| 901 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 907 | + * |
|
| 908 | + * @since 4.3.0 |
|
| 909 | + * @param string $registration_message_trigger_url |
|
| 910 | + * @param EE_Registration $registration |
|
| 911 | + * @param string $messenger |
|
| 912 | + * @param string $message_type |
|
| 913 | + * @return string |
|
| 914 | + * @throws EE_Error |
|
| 915 | + * @throws InvalidArgumentException |
|
| 916 | + * @throws InvalidDataTypeException |
|
| 917 | + * @throws InvalidInterfaceException |
|
| 918 | + */ |
|
| 919 | + public static function registration_message_trigger_url( |
|
| 920 | + $registration_message_trigger_url, |
|
| 921 | + EE_Registration $registration, |
|
| 922 | + $messenger = 'html', |
|
| 923 | + $message_type = 'invoice' |
|
| 924 | + ) { |
|
| 925 | + // whitelist $messenger |
|
| 926 | + switch ($messenger) { |
|
| 927 | + case 'pdf': |
|
| 928 | + $sending_messenger = 'pdf'; |
|
| 929 | + $generating_messenger = 'html'; |
|
| 930 | + break; |
|
| 931 | + case 'html': |
|
| 932 | + default: |
|
| 933 | + $sending_messenger = 'html'; |
|
| 934 | + $generating_messenger = 'html'; |
|
| 935 | + break; |
|
| 936 | + } |
|
| 937 | + // whitelist $message_type |
|
| 938 | + switch ($message_type) { |
|
| 939 | + case 'receipt': |
|
| 940 | + $message_type = 'receipt'; |
|
| 941 | + break; |
|
| 942 | + case 'invoice': |
|
| 943 | + default: |
|
| 944 | + $message_type = 'invoice'; |
|
| 945 | + break; |
|
| 946 | + } |
|
| 947 | + // verify that both the messenger AND the message type are active |
|
| 948 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 949 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
| 950 | + ) { |
|
| 951 | + // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 952 | + $template_query_params = array( |
|
| 953 | + 'MTP_is_active' => true, |
|
| 954 | + 'MTP_messenger' => $generating_messenger, |
|
| 955 | + 'MTP_message_type' => $message_type, |
|
| 956 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 957 | + ); |
|
| 958 | + // get the message template group. |
|
| 959 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 960 | + // if we don't have an EE_Message_Template_Group then return |
|
| 961 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 962 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 963 | + unset($template_query_params['Event.EVT_ID']); |
|
| 964 | + // get global template as the fallback |
|
| 965 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 966 | + } |
|
| 967 | + // if we don't have an EE_Message_Template_Group then return |
|
| 968 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 969 | + return ''; |
|
| 970 | + } |
|
| 971 | + // generate the URL |
|
| 972 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 973 | + $sending_messenger, |
|
| 974 | + $generating_messenger, |
|
| 975 | + 'purchaser', |
|
| 976 | + $message_type, |
|
| 977 | + $registration, |
|
| 978 | + $msg_template_group->ID(), |
|
| 979 | + $registration->transaction_ID() |
|
| 980 | + ); |
|
| 981 | + } |
|
| 982 | + return $registration_message_trigger_url; |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + |
|
| 986 | + /** |
|
| 987 | + * Use to generate and return a message preview! |
|
| 988 | + * |
|
| 989 | + * @param string $type This should correspond with a valid message type |
|
| 990 | + * @param string $context This should correspond with a valid context for the message type |
|
| 991 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 992 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 993 | + * preview |
|
| 994 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 995 | + * @throws EE_Error |
|
| 996 | + * @throws InvalidArgumentException |
|
| 997 | + * @throws InvalidDataTypeException |
|
| 998 | + * @throws InvalidInterfaceException |
|
| 999 | + * @throws ReflectionException |
|
| 1000 | + */ |
|
| 1001 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 1002 | + { |
|
| 1003 | + self::_load_controller(); |
|
| 1004 | + $mtg = new EE_Message_To_Generate( |
|
| 1005 | + $messenger, |
|
| 1006 | + $type, |
|
| 1007 | + array(), |
|
| 1008 | + $context, |
|
| 1009 | + true |
|
| 1010 | + ); |
|
| 1011 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1012 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1013 | + // loop through all content for the preview and remove any persisted records. |
|
| 1014 | + $content = ''; |
|
| 1015 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1016 | + $content = $message->content(); |
|
| 1017 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1018 | + $message->delete(); |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + return $content; |
|
| 1022 | + } else { |
|
| 1023 | + return $generated_preview_queue; |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1030 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1031 | + * content found in the EE_Message objects in the queue. |
|
| 1032 | + * |
|
| 1033 | + * @since 4.9.0 |
|
| 1034 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 1035 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1036 | + * type name is still required to send along the message type to the |
|
| 1037 | + * messenger because this is used for determining what specific |
|
| 1038 | + * variations might be loaded for the generated message. |
|
| 1039 | + * @param EE_Messages_Queue $queue |
|
| 1040 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1041 | + * aggregate EE_Message object. |
|
| 1042 | + * @return bool success or fail. |
|
| 1043 | + * @throws EE_Error |
|
| 1044 | + * @throws InvalidArgumentException |
|
| 1045 | + * @throws ReflectionException |
|
| 1046 | + * @throws InvalidDataTypeException |
|
| 1047 | + * @throws InvalidInterfaceException |
|
| 1048 | + */ |
|
| 1049 | + public static function send_message_with_messenger_only( |
|
| 1050 | + $messenger, |
|
| 1051 | + $message_type, |
|
| 1052 | + EE_Messages_Queue $queue, |
|
| 1053 | + $custom_subject = '' |
|
| 1054 | + ) { |
|
| 1055 | + self::_load_controller(); |
|
| 1056 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1057 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1058 | + 'Message_To_Generate_From_Queue', |
|
| 1059 | + array( |
|
| 1060 | + $messenger, |
|
| 1061 | + $message_type, |
|
| 1062 | + $queue, |
|
| 1063 | + $custom_subject, |
|
| 1064 | + ) |
|
| 1065 | + ); |
|
| 1066 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1072 | + * |
|
| 1073 | + * @since 4.9.0 |
|
| 1074 | + * @param array $message_ids An array of message ids |
|
| 1075 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1076 | + * messages. |
|
| 1077 | + * @throws EE_Error |
|
| 1078 | + * @throws InvalidArgumentException |
|
| 1079 | + * @throws InvalidDataTypeException |
|
| 1080 | + * @throws InvalidInterfaceException |
|
| 1081 | + * @throws ReflectionException |
|
| 1082 | + */ |
|
| 1083 | + public static function generate_now($message_ids) |
|
| 1084 | + { |
|
| 1085 | + self::_load_controller(); |
|
| 1086 | + $messages = EEM_Message::instance()->get_all( |
|
| 1087 | + array( |
|
| 1088 | + 0 => array( |
|
| 1089 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1090 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1091 | + ), |
|
| 1092 | + ) |
|
| 1093 | + ); |
|
| 1094 | + $generated_queue = false; |
|
| 1095 | + if ($messages) { |
|
| 1096 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1100 | + EE_Error::add_error( |
|
| 1101 | + __( |
|
| 1102 | + 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1103 | + 'event_espresso' |
|
| 1104 | + ), |
|
| 1105 | + __FILE__, |
|
| 1106 | + __FUNCTION__, |
|
| 1107 | + __LINE__ |
|
| 1108 | + ); |
|
| 1109 | + } |
|
| 1110 | + return $generated_queue; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1116 | + * EEM_Message::status_idle |
|
| 1117 | + * |
|
| 1118 | + * @since 4.9.0 |
|
| 1119 | + * @param $message_ids |
|
| 1120 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1121 | + * @throws EE_Error |
|
| 1122 | + * @throws InvalidArgumentException |
|
| 1123 | + * @throws InvalidDataTypeException |
|
| 1124 | + * @throws InvalidInterfaceException |
|
| 1125 | + * @throws ReflectionException |
|
| 1126 | + */ |
|
| 1127 | + public static function send_now($message_ids) |
|
| 1128 | + { |
|
| 1129 | + self::_load_controller(); |
|
| 1130 | + $messages = EEM_Message::instance()->get_all( |
|
| 1131 | + array( |
|
| 1132 | + 0 => array( |
|
| 1133 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1134 | + 'STS_ID' => array( |
|
| 1135 | + 'IN', |
|
| 1136 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1137 | + ), |
|
| 1138 | + ), |
|
| 1139 | + ) |
|
| 1140 | + ); |
|
| 1141 | + $sent_queue = false; |
|
| 1142 | + if ($messages) { |
|
| 1143 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1147 | + EE_Error::add_error( |
|
| 1148 | + __( |
|
| 1149 | + 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1150 | + 'event_espresso' |
|
| 1151 | + ), |
|
| 1152 | + __FILE__, |
|
| 1153 | + __FUNCTION__, |
|
| 1154 | + __LINE__ |
|
| 1155 | + ); |
|
| 1156 | + } else { |
|
| 1157 | + // can count how many sent by using the messages in the queue |
|
| 1158 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1159 | + if ($sent_count > 0) { |
|
| 1160 | + EE_Error::add_success( |
|
| 1161 | + sprintf( |
|
| 1162 | + _n( |
|
| 1163 | + 'There was %d message successfully sent.', |
|
| 1164 | + 'There were %d messages successfully sent.', |
|
| 1165 | + $sent_count, |
|
| 1166 | + 'event_espresso' |
|
| 1167 | + ), |
|
| 1168 | + $sent_count |
|
| 1169 | + ) |
|
| 1170 | + ); |
|
| 1171 | + } else { |
|
| 1172 | + EE_Error::overwrite_errors(); |
|
| 1173 | + EE_Error::add_error( |
|
| 1174 | + __( |
|
| 1175 | + 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 1176 | 1176 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1177 | - 'event_espresso' |
|
| 1178 | - ), |
|
| 1179 | - __FILE__, |
|
| 1180 | - __FUNCTION__, |
|
| 1181 | - __LINE__ |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - return $sent_queue; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - |
|
| 1189 | - /** |
|
| 1190 | - * Generate and send immediately from the given $message_ids |
|
| 1191 | - * |
|
| 1192 | - * @param array $message_ids EE_Message entity ids. |
|
| 1193 | - * @throws EE_Error |
|
| 1194 | - * @throws InvalidArgumentException |
|
| 1195 | - * @throws InvalidDataTypeException |
|
| 1196 | - * @throws InvalidInterfaceException |
|
| 1197 | - * @throws ReflectionException |
|
| 1198 | - */ |
|
| 1199 | - public static function generate_and_send_now(array $message_ids) |
|
| 1200 | - { |
|
| 1201 | - $generated_queue = self::generate_now($message_ids); |
|
| 1202 | - // now let's just trigger sending immediately from this queue. |
|
| 1203 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1204 | - ? $generated_queue->execute() |
|
| 1205 | - : 0; |
|
| 1206 | - if ($messages_sent) { |
|
| 1207 | - EE_Error::add_success( |
|
| 1208 | - esc_html( |
|
| 1209 | - sprintf( |
|
| 1210 | - _n( |
|
| 1211 | - 'There was %d message successfully generated and sent.', |
|
| 1212 | - 'There were %d messages successfully generated and sent.', |
|
| 1213 | - $messages_sent, |
|
| 1214 | - 'event_espresso' |
|
| 1215 | - ), |
|
| 1216 | - $messages_sent |
|
| 1217 | - ) |
|
| 1218 | - ) |
|
| 1219 | - ); |
|
| 1220 | - // errors would be added via the generate_now method. |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * This will queue the incoming message ids for resending. |
|
| 1227 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1228 | - * |
|
| 1229 | - * @since 4.9.0 |
|
| 1230 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1231 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1232 | - * resending. |
|
| 1233 | - * @throws EE_Error |
|
| 1234 | - * @throws InvalidArgumentException |
|
| 1235 | - * @throws InvalidDataTypeException |
|
| 1236 | - * @throws InvalidInterfaceException |
|
| 1237 | - * @throws ReflectionException |
|
| 1238 | - */ |
|
| 1239 | - public static function queue_for_resending($message_ids) |
|
| 1240 | - { |
|
| 1241 | - self::_load_controller(); |
|
| 1242 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1243 | - |
|
| 1244 | - // get queue and count |
|
| 1245 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1246 | - |
|
| 1247 | - if ($queue_count > 0 |
|
| 1248 | - ) { |
|
| 1249 | - EE_Error::add_success( |
|
| 1250 | - sprintf( |
|
| 1251 | - _n( |
|
| 1252 | - '%d message successfully queued for resending.', |
|
| 1253 | - '%d messages successfully queued for resending.', |
|
| 1254 | - $queue_count, |
|
| 1255 | - 'event_espresso' |
|
| 1256 | - ), |
|
| 1257 | - $queue_count |
|
| 1258 | - ) |
|
| 1259 | - ); |
|
| 1260 | - /** |
|
| 1261 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1262 | - */ |
|
| 1263 | - } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1264 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1265 | - ) { |
|
| 1266 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1267 | - if ($queue_count > 0) { |
|
| 1268 | - EE_Error::add_success( |
|
| 1269 | - sprintf( |
|
| 1270 | - _n( |
|
| 1271 | - '%d message successfully sent.', |
|
| 1272 | - '%d messages successfully sent.', |
|
| 1273 | - $queue_count, |
|
| 1274 | - 'event_espresso' |
|
| 1275 | - ), |
|
| 1276 | - $queue_count |
|
| 1277 | - ) |
|
| 1278 | - ); |
|
| 1279 | - } else { |
|
| 1280 | - EE_Error::add_error( |
|
| 1281 | - __( |
|
| 1282 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1283 | - 'event_espresso' |
|
| 1284 | - ), |
|
| 1285 | - __FILE__, |
|
| 1286 | - __FUNCTION__, |
|
| 1287 | - __LINE__ |
|
| 1288 | - ); |
|
| 1289 | - } |
|
| 1290 | - } else { |
|
| 1291 | - EE_Error::add_error( |
|
| 1292 | - __( |
|
| 1293 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1294 | - 'event_espresso' |
|
| 1295 | - ), |
|
| 1296 | - __FILE__, |
|
| 1297 | - __FUNCTION__, |
|
| 1298 | - __LINE__ |
|
| 1299 | - ); |
|
| 1300 | - } |
|
| 1301 | - return (bool) $queue_count; |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - |
|
| 1305 | - /** |
|
| 1306 | - * debug |
|
| 1307 | - * |
|
| 1308 | - * @param string $class |
|
| 1309 | - * @param string $func |
|
| 1310 | - * @param string $line |
|
| 1311 | - * @param EE_Transaction|null $transaction |
|
| 1312 | - * @param array $info |
|
| 1313 | - * @param bool $display_request |
|
| 1314 | - * @throws EE_Error |
|
| 1315 | - * @throws ReflectionException |
|
| 1316 | - * @throws InvalidSessionDataException |
|
| 1317 | - */ |
|
| 1318 | - protected static function log( |
|
| 1319 | - $class = '', |
|
| 1320 | - $func = '', |
|
| 1321 | - $line = '', |
|
| 1322 | - EE_Transaction $transaction = null, |
|
| 1323 | - $info = array(), |
|
| 1324 | - $display_request = false |
|
| 1325 | - ) { |
|
| 1326 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1327 | - if ($transaction instanceof EE_Transaction) { |
|
| 1328 | - // don't serialize objects |
|
| 1329 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1330 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1331 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1332 | - if ($transaction->ID()) { |
|
| 1333 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1334 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - |
|
| 1341 | - /** |
|
| 1342 | - * Resets all the static properties in this class when called. |
|
| 1343 | - */ |
|
| 1344 | - public static function reset() |
|
| 1345 | - { |
|
| 1346 | - self::$_EEMSG = null; |
|
| 1347 | - self::$_message_resource_manager = null; |
|
| 1348 | - self::$_MSG_PROCESSOR = null; |
|
| 1349 | - self::$_MSG_PATHS = null; |
|
| 1350 | - self::$_TMP_PACKS = array(); |
|
| 1351 | - } |
|
| 1177 | + 'event_espresso' |
|
| 1178 | + ), |
|
| 1179 | + __FILE__, |
|
| 1180 | + __FUNCTION__, |
|
| 1181 | + __LINE__ |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + return $sent_queue; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + |
|
| 1189 | + /** |
|
| 1190 | + * Generate and send immediately from the given $message_ids |
|
| 1191 | + * |
|
| 1192 | + * @param array $message_ids EE_Message entity ids. |
|
| 1193 | + * @throws EE_Error |
|
| 1194 | + * @throws InvalidArgumentException |
|
| 1195 | + * @throws InvalidDataTypeException |
|
| 1196 | + * @throws InvalidInterfaceException |
|
| 1197 | + * @throws ReflectionException |
|
| 1198 | + */ |
|
| 1199 | + public static function generate_and_send_now(array $message_ids) |
|
| 1200 | + { |
|
| 1201 | + $generated_queue = self::generate_now($message_ids); |
|
| 1202 | + // now let's just trigger sending immediately from this queue. |
|
| 1203 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1204 | + ? $generated_queue->execute() |
|
| 1205 | + : 0; |
|
| 1206 | + if ($messages_sent) { |
|
| 1207 | + EE_Error::add_success( |
|
| 1208 | + esc_html( |
|
| 1209 | + sprintf( |
|
| 1210 | + _n( |
|
| 1211 | + 'There was %d message successfully generated and sent.', |
|
| 1212 | + 'There were %d messages successfully generated and sent.', |
|
| 1213 | + $messages_sent, |
|
| 1214 | + 'event_espresso' |
|
| 1215 | + ), |
|
| 1216 | + $messages_sent |
|
| 1217 | + ) |
|
| 1218 | + ) |
|
| 1219 | + ); |
|
| 1220 | + // errors would be added via the generate_now method. |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * This will queue the incoming message ids for resending. |
|
| 1227 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1228 | + * |
|
| 1229 | + * @since 4.9.0 |
|
| 1230 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1231 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1232 | + * resending. |
|
| 1233 | + * @throws EE_Error |
|
| 1234 | + * @throws InvalidArgumentException |
|
| 1235 | + * @throws InvalidDataTypeException |
|
| 1236 | + * @throws InvalidInterfaceException |
|
| 1237 | + * @throws ReflectionException |
|
| 1238 | + */ |
|
| 1239 | + public static function queue_for_resending($message_ids) |
|
| 1240 | + { |
|
| 1241 | + self::_load_controller(); |
|
| 1242 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1243 | + |
|
| 1244 | + // get queue and count |
|
| 1245 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1246 | + |
|
| 1247 | + if ($queue_count > 0 |
|
| 1248 | + ) { |
|
| 1249 | + EE_Error::add_success( |
|
| 1250 | + sprintf( |
|
| 1251 | + _n( |
|
| 1252 | + '%d message successfully queued for resending.', |
|
| 1253 | + '%d messages successfully queued for resending.', |
|
| 1254 | + $queue_count, |
|
| 1255 | + 'event_espresso' |
|
| 1256 | + ), |
|
| 1257 | + $queue_count |
|
| 1258 | + ) |
|
| 1259 | + ); |
|
| 1260 | + /** |
|
| 1261 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1262 | + */ |
|
| 1263 | + } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1264 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1265 | + ) { |
|
| 1266 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1267 | + if ($queue_count > 0) { |
|
| 1268 | + EE_Error::add_success( |
|
| 1269 | + sprintf( |
|
| 1270 | + _n( |
|
| 1271 | + '%d message successfully sent.', |
|
| 1272 | + '%d messages successfully sent.', |
|
| 1273 | + $queue_count, |
|
| 1274 | + 'event_espresso' |
|
| 1275 | + ), |
|
| 1276 | + $queue_count |
|
| 1277 | + ) |
|
| 1278 | + ); |
|
| 1279 | + } else { |
|
| 1280 | + EE_Error::add_error( |
|
| 1281 | + __( |
|
| 1282 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1283 | + 'event_espresso' |
|
| 1284 | + ), |
|
| 1285 | + __FILE__, |
|
| 1286 | + __FUNCTION__, |
|
| 1287 | + __LINE__ |
|
| 1288 | + ); |
|
| 1289 | + } |
|
| 1290 | + } else { |
|
| 1291 | + EE_Error::add_error( |
|
| 1292 | + __( |
|
| 1293 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1294 | + 'event_espresso' |
|
| 1295 | + ), |
|
| 1296 | + __FILE__, |
|
| 1297 | + __FUNCTION__, |
|
| 1298 | + __LINE__ |
|
| 1299 | + ); |
|
| 1300 | + } |
|
| 1301 | + return (bool) $queue_count; |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + |
|
| 1305 | + /** |
|
| 1306 | + * debug |
|
| 1307 | + * |
|
| 1308 | + * @param string $class |
|
| 1309 | + * @param string $func |
|
| 1310 | + * @param string $line |
|
| 1311 | + * @param EE_Transaction|null $transaction |
|
| 1312 | + * @param array $info |
|
| 1313 | + * @param bool $display_request |
|
| 1314 | + * @throws EE_Error |
|
| 1315 | + * @throws ReflectionException |
|
| 1316 | + * @throws InvalidSessionDataException |
|
| 1317 | + */ |
|
| 1318 | + protected static function log( |
|
| 1319 | + $class = '', |
|
| 1320 | + $func = '', |
|
| 1321 | + $line = '', |
|
| 1322 | + EE_Transaction $transaction = null, |
|
| 1323 | + $info = array(), |
|
| 1324 | + $display_request = false |
|
| 1325 | + ) { |
|
| 1326 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1327 | + if ($transaction instanceof EE_Transaction) { |
|
| 1328 | + // don't serialize objects |
|
| 1329 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1330 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1331 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1332 | + if ($transaction->ID()) { |
|
| 1333 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1334 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + |
|
| 1341 | + /** |
|
| 1342 | + * Resets all the static properties in this class when called. |
|
| 1343 | + */ |
|
| 1344 | + public static function reset() |
|
| 1345 | + { |
|
| 1346 | + self::$_EEMSG = null; |
|
| 1347 | + self::$_message_resource_manager = null; |
|
| 1348 | + self::$_MSG_PROCESSOR = null; |
|
| 1349 | + self::$_MSG_PATHS = null; |
|
| 1350 | + self::$_TMP_PACKS = array(); |
|
| 1351 | + } |
|
| 1352 | 1352 | } |
@@ -15,2201 +15,2201 @@ |
||
| 15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * This property is just used to hold the status of whether an event is currently being |
|
| 20 | - * created (true) or edited (false) |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $_is_creating_event; |
|
| 18 | + /** |
|
| 19 | + * This property is just used to hold the status of whether an event is currently being |
|
| 20 | + * created (true) or edited (false) |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $_is_creating_event; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | - * time. |
|
| 30 | - * Is set in the _set_hooks_properties() method. |
|
| 31 | - * |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $_date_format_strings; |
|
| 27 | + /** |
|
| 28 | + * Used to contain the format strings for date and time that will be used for php date and |
|
| 29 | + * time. |
|
| 30 | + * Is set in the _set_hooks_properties() method. |
|
| 31 | + * |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $_date_format_strings; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string $_date_time_format |
|
| 38 | - */ |
|
| 39 | - protected $_date_time_format; |
|
| 36 | + /** |
|
| 37 | + * @var string $_date_time_format |
|
| 38 | + */ |
|
| 39 | + protected $_date_time_format; |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @throws InvalidArgumentException |
|
| 44 | - * @throws InvalidInterfaceException |
|
| 45 | - * @throws InvalidDataTypeException |
|
| 46 | - */ |
|
| 47 | - protected function _set_hooks_properties() |
|
| 48 | - { |
|
| 49 | - $this->_name = 'pricing'; |
|
| 50 | - // capability check |
|
| 51 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 52 | - 'ee_read_default_prices', |
|
| 53 | - 'advanced_ticket_datetime_metabox' |
|
| 54 | - )) { |
|
| 55 | - return; |
|
| 56 | - } |
|
| 57 | - $this->_setup_metaboxes(); |
|
| 58 | - $this->_set_date_time_formats(); |
|
| 59 | - $this->_validate_format_strings(); |
|
| 60 | - $this->_set_scripts_styles(); |
|
| 61 | - // commented out temporarily until logic is implemented in callback |
|
| 62 | - // add_action( |
|
| 63 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 64 | - // array($this, 'autosave_handling') |
|
| 65 | - // ); |
|
| 66 | - add_filter( |
|
| 67 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 68 | - array($this, 'caf_updates') |
|
| 69 | - ); |
|
| 70 | - } |
|
| 42 | + /** |
|
| 43 | + * @throws InvalidArgumentException |
|
| 44 | + * @throws InvalidInterfaceException |
|
| 45 | + * @throws InvalidDataTypeException |
|
| 46 | + */ |
|
| 47 | + protected function _set_hooks_properties() |
|
| 48 | + { |
|
| 49 | + $this->_name = 'pricing'; |
|
| 50 | + // capability check |
|
| 51 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 52 | + 'ee_read_default_prices', |
|
| 53 | + 'advanced_ticket_datetime_metabox' |
|
| 54 | + )) { |
|
| 55 | + return; |
|
| 56 | + } |
|
| 57 | + $this->_setup_metaboxes(); |
|
| 58 | + $this->_set_date_time_formats(); |
|
| 59 | + $this->_validate_format_strings(); |
|
| 60 | + $this->_set_scripts_styles(); |
|
| 61 | + // commented out temporarily until logic is implemented in callback |
|
| 62 | + // add_action( |
|
| 63 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
| 64 | + // array($this, 'autosave_handling') |
|
| 65 | + // ); |
|
| 66 | + add_filter( |
|
| 67 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
| 68 | + array($this, 'caf_updates') |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - protected function _setup_metaboxes() |
|
| 77 | - { |
|
| 78 | - // if we were going to add our own metaboxes we'd use the below. |
|
| 79 | - $this->_metaboxes = array( |
|
| 80 | - 0 => array( |
|
| 81 | - 'page_route' => array('edit', 'create_new'), |
|
| 82 | - 'func' => 'pricing_metabox', |
|
| 83 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 84 | - 'priority' => 'high', |
|
| 85 | - 'context' => 'normal', |
|
| 86 | - ), |
|
| 87 | - ); |
|
| 88 | - $this->_remove_metaboxes = array( |
|
| 89 | - 0 => array( |
|
| 90 | - 'page_route' => array('edit', 'create_new'), |
|
| 91 | - 'id' => 'espresso_event_editor_tickets', |
|
| 92 | - 'context' => 'normal', |
|
| 93 | - ), |
|
| 94 | - ); |
|
| 95 | - } |
|
| 73 | + /** |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + protected function _setup_metaboxes() |
|
| 77 | + { |
|
| 78 | + // if we were going to add our own metaboxes we'd use the below. |
|
| 79 | + $this->_metaboxes = array( |
|
| 80 | + 0 => array( |
|
| 81 | + 'page_route' => array('edit', 'create_new'), |
|
| 82 | + 'func' => 'pricing_metabox', |
|
| 83 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
| 84 | + 'priority' => 'high', |
|
| 85 | + 'context' => 'normal', |
|
| 86 | + ), |
|
| 87 | + ); |
|
| 88 | + $this->_remove_metaboxes = array( |
|
| 89 | + 0 => array( |
|
| 90 | + 'page_route' => array('edit', 'create_new'), |
|
| 91 | + 'id' => 'espresso_event_editor_tickets', |
|
| 92 | + 'context' => 'normal', |
|
| 93 | + ), |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - protected function _set_date_time_formats() |
|
| 102 | - { |
|
| 103 | - /** |
|
| 104 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 105 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 106 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 107 | - * |
|
| 108 | - * @since 4.6.7 |
|
| 109 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 110 | - */ |
|
| 111 | - $this->_date_format_strings = apply_filters( |
|
| 112 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 113 | - array( |
|
| 114 | - 'date' => 'Y-m-d', |
|
| 115 | - 'time' => 'h:i a', |
|
| 116 | - ) |
|
| 117 | - ); |
|
| 118 | - // validate |
|
| 119 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 120 | - ? $this->_date_format_strings['date'] |
|
| 121 | - : null; |
|
| 122 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 123 | - ? $this->_date_format_strings['time'] |
|
| 124 | - : null; |
|
| 125 | - $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 126 | - . ' ' |
|
| 127 | - . $this->_date_format_strings['time']; |
|
| 128 | - } |
|
| 98 | + /** |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + protected function _set_date_time_formats() |
|
| 102 | + { |
|
| 103 | + /** |
|
| 104 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
| 105 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
| 106 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
| 107 | + * |
|
| 108 | + * @since 4.6.7 |
|
| 109 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
| 110 | + */ |
|
| 111 | + $this->_date_format_strings = apply_filters( |
|
| 112 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
| 113 | + array( |
|
| 114 | + 'date' => 'Y-m-d', |
|
| 115 | + 'time' => 'h:i a', |
|
| 116 | + ) |
|
| 117 | + ); |
|
| 118 | + // validate |
|
| 119 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
| 120 | + ? $this->_date_format_strings['date'] |
|
| 121 | + : null; |
|
| 122 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
| 123 | + ? $this->_date_format_strings['time'] |
|
| 124 | + : null; |
|
| 125 | + $this->_date_time_format = $this->_date_format_strings['date'] |
|
| 126 | + . ' ' |
|
| 127 | + . $this->_date_format_strings['time']; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @return void |
|
| 133 | - */ |
|
| 134 | - protected function _validate_format_strings() |
|
| 135 | - { |
|
| 136 | - // validate format strings |
|
| 137 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 138 | - $this->_date_time_format |
|
| 139 | - ); |
|
| 140 | - if (is_array($format_validation)) { |
|
| 141 | - $msg = '<p>'; |
|
| 142 | - $msg .= sprintf( |
|
| 143 | - esc_html__( |
|
| 144 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ), |
|
| 147 | - $this->_date_time_format |
|
| 148 | - ); |
|
| 149 | - $msg .= '</p><ul>'; |
|
| 150 | - foreach ($format_validation as $error) { |
|
| 151 | - $msg .= '<li>' . $error . '</li>'; |
|
| 152 | - } |
|
| 153 | - $msg .= '</ul><p>'; |
|
| 154 | - $msg .= sprintf( |
|
| 155 | - esc_html__( |
|
| 156 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 157 | - 'event_espresso' |
|
| 158 | - ), |
|
| 159 | - '<span style="color:#D54E21;">', |
|
| 160 | - '</span>' |
|
| 161 | - ); |
|
| 162 | - $msg .= '</p>'; |
|
| 163 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 164 | - $this->_date_format_strings = array( |
|
| 165 | - 'date' => 'Y-m-d', |
|
| 166 | - 'time' => 'h:i a', |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - } |
|
| 131 | + /** |
|
| 132 | + * @return void |
|
| 133 | + */ |
|
| 134 | + protected function _validate_format_strings() |
|
| 135 | + { |
|
| 136 | + // validate format strings |
|
| 137 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
| 138 | + $this->_date_time_format |
|
| 139 | + ); |
|
| 140 | + if (is_array($format_validation)) { |
|
| 141 | + $msg = '<p>'; |
|
| 142 | + $msg .= sprintf( |
|
| 143 | + esc_html__( |
|
| 144 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ), |
|
| 147 | + $this->_date_time_format |
|
| 148 | + ); |
|
| 149 | + $msg .= '</p><ul>'; |
|
| 150 | + foreach ($format_validation as $error) { |
|
| 151 | + $msg .= '<li>' . $error . '</li>'; |
|
| 152 | + } |
|
| 153 | + $msg .= '</ul><p>'; |
|
| 154 | + $msg .= sprintf( |
|
| 155 | + esc_html__( |
|
| 156 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
| 157 | + 'event_espresso' |
|
| 158 | + ), |
|
| 159 | + '<span style="color:#D54E21;">', |
|
| 160 | + '</span>' |
|
| 161 | + ); |
|
| 162 | + $msg .= '</p>'; |
|
| 163 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 164 | + $this->_date_format_strings = array( |
|
| 165 | + 'date' => 'Y-m-d', |
|
| 166 | + 'time' => 'h:i a', |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * @return void |
|
| 174 | - */ |
|
| 175 | - protected function _set_scripts_styles() |
|
| 176 | - { |
|
| 177 | - $this->_scripts_styles = array( |
|
| 178 | - 'registers' => array( |
|
| 179 | - 'ee-tickets-datetimes-css' => array( |
|
| 180 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 181 | - 'type' => 'css', |
|
| 182 | - ), |
|
| 183 | - 'ee-dtt-ticket-metabox' => array( |
|
| 184 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 185 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 186 | - ), |
|
| 187 | - ), |
|
| 188 | - 'deregisters' => array( |
|
| 189 | - 'event-editor-css' => array('type' => 'css'), |
|
| 190 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
| 191 | - ), |
|
| 192 | - 'enqueues' => array( |
|
| 193 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 194 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 195 | - ), |
|
| 196 | - 'localize' => array( |
|
| 197 | - 'ee-dtt-ticket-metabox' => array( |
|
| 198 | - 'DTT_TRASH_BLOCK' => array( |
|
| 199 | - 'main_warning' => esc_html__( |
|
| 200 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 201 | - 'event_espresso' |
|
| 202 | - ), |
|
| 203 | - 'after_warning' => esc_html__( |
|
| 204 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 205 | - 'event_espresso' |
|
| 206 | - ), |
|
| 207 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 208 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 209 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 211 | - 'single_warning_from_tkt' => esc_html__( |
|
| 212 | - '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.', |
|
| 213 | - 'event_espresso' |
|
| 214 | - ), |
|
| 215 | - 'single_warning_from_dtt' => esc_html__( |
|
| 216 | - '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.', |
|
| 217 | - 'event_espresso' |
|
| 218 | - ), |
|
| 219 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 220 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 221 | - ), |
|
| 222 | - 'DTT_ERROR_MSG' => array( |
|
| 223 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 224 | - 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 225 | - . '<button class="button-secondary ee-modal-cancel">' |
|
| 226 | - . esc_html__('Dismiss', 'event_espresso') |
|
| 227 | - . '</button></div>', |
|
| 228 | - ), |
|
| 229 | - 'DTT_OVERSELL_WARNING' => array( |
|
| 230 | - 'datetime_ticket' => esc_html__( |
|
| 231 | - '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.', |
|
| 232 | - 'event_espresso' |
|
| 233 | - ), |
|
| 234 | - 'ticket_datetime' => esc_html__( |
|
| 235 | - '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.', |
|
| 236 | - 'event_espresso' |
|
| 237 | - ), |
|
| 238 | - ), |
|
| 239 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 240 | - $this->_date_format_strings['date'], |
|
| 241 | - $this->_date_format_strings['time'] |
|
| 242 | - ), |
|
| 243 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 244 | - ), |
|
| 245 | - ), |
|
| 246 | - ); |
|
| 247 | - } |
|
| 172 | + /** |
|
| 173 | + * @return void |
|
| 174 | + */ |
|
| 175 | + protected function _set_scripts_styles() |
|
| 176 | + { |
|
| 177 | + $this->_scripts_styles = array( |
|
| 178 | + 'registers' => array( |
|
| 179 | + 'ee-tickets-datetimes-css' => array( |
|
| 180 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 181 | + 'type' => 'css', |
|
| 182 | + ), |
|
| 183 | + 'ee-dtt-ticket-metabox' => array( |
|
| 184 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 185 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
| 186 | + ), |
|
| 187 | + ), |
|
| 188 | + 'deregisters' => array( |
|
| 189 | + 'event-editor-css' => array('type' => 'css'), |
|
| 190 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
| 191 | + ), |
|
| 192 | + 'enqueues' => array( |
|
| 193 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
| 194 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
| 195 | + ), |
|
| 196 | + 'localize' => array( |
|
| 197 | + 'ee-dtt-ticket-metabox' => array( |
|
| 198 | + 'DTT_TRASH_BLOCK' => array( |
|
| 199 | + 'main_warning' => esc_html__( |
|
| 200 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
| 201 | + 'event_espresso' |
|
| 202 | + ), |
|
| 203 | + 'after_warning' => esc_html__( |
|
| 204 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
| 205 | + 'event_espresso' |
|
| 206 | + ), |
|
| 207 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 208 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 209 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 210 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 211 | + 'single_warning_from_tkt' => esc_html__( |
|
| 212 | + '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.', |
|
| 213 | + 'event_espresso' |
|
| 214 | + ), |
|
| 215 | + 'single_warning_from_dtt' => esc_html__( |
|
| 216 | + '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.', |
|
| 217 | + 'event_espresso' |
|
| 218 | + ), |
|
| 219 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
| 220 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 221 | + ), |
|
| 222 | + 'DTT_ERROR_MSG' => array( |
|
| 223 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
| 224 | + 'dismiss_button' => '<div class="save-cancel-button-container">' |
|
| 225 | + . '<button class="button-secondary ee-modal-cancel">' |
|
| 226 | + . esc_html__('Dismiss', 'event_espresso') |
|
| 227 | + . '</button></div>', |
|
| 228 | + ), |
|
| 229 | + 'DTT_OVERSELL_WARNING' => array( |
|
| 230 | + 'datetime_ticket' => esc_html__( |
|
| 231 | + '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.', |
|
| 232 | + 'event_espresso' |
|
| 233 | + ), |
|
| 234 | + 'ticket_datetime' => esc_html__( |
|
| 235 | + '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.', |
|
| 236 | + 'event_espresso' |
|
| 237 | + ), |
|
| 238 | + ), |
|
| 239 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
| 240 | + $this->_date_format_strings['date'], |
|
| 241 | + $this->_date_format_strings['time'] |
|
| 242 | + ), |
|
| 243 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
| 244 | + ), |
|
| 245 | + ), |
|
| 246 | + ); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * @param array $update_callbacks |
|
| 252 | - * @return array |
|
| 253 | - */ |
|
| 254 | - public function caf_updates(array $update_callbacks) |
|
| 255 | - { |
|
| 256 | - foreach ($update_callbacks as $key => $callback) { |
|
| 257 | - if ($callback[1] === '_default_tickets_update') { |
|
| 258 | - unset($update_callbacks[ $key ]); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 262 | - return $update_callbacks; |
|
| 263 | - } |
|
| 250 | + /** |
|
| 251 | + * @param array $update_callbacks |
|
| 252 | + * @return array |
|
| 253 | + */ |
|
| 254 | + public function caf_updates(array $update_callbacks) |
|
| 255 | + { |
|
| 256 | + foreach ($update_callbacks as $key => $callback) { |
|
| 257 | + if ($callback[1] === '_default_tickets_update') { |
|
| 258 | + unset($update_callbacks[ $key ]); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
| 262 | + return $update_callbacks; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 268 | - * |
|
| 269 | - * @param EE_Event $event The Event object we're attaching data to |
|
| 270 | - * @param array $data The request data from the form |
|
| 271 | - * @throws ReflectionException |
|
| 272 | - * @throws Exception |
|
| 273 | - * @throws InvalidInterfaceException |
|
| 274 | - * @throws InvalidDataTypeException |
|
| 275 | - * @throws EE_Error |
|
| 276 | - * @throws InvalidArgumentException |
|
| 277 | - */ |
|
| 278 | - public function datetime_and_tickets_caf_update($event, $data) |
|
| 279 | - { |
|
| 280 | - // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 281 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 282 | - // next tackle the tickets (and prices?) |
|
| 283 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 284 | - } |
|
| 266 | + /** |
|
| 267 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
| 268 | + * |
|
| 269 | + * @param EE_Event $event The Event object we're attaching data to |
|
| 270 | + * @param array $data The request data from the form |
|
| 271 | + * @throws ReflectionException |
|
| 272 | + * @throws Exception |
|
| 273 | + * @throws InvalidInterfaceException |
|
| 274 | + * @throws InvalidDataTypeException |
|
| 275 | + * @throws EE_Error |
|
| 276 | + * @throws InvalidArgumentException |
|
| 277 | + */ |
|
| 278 | + public function datetime_and_tickets_caf_update($event, $data) |
|
| 279 | + { |
|
| 280 | + // first we need to start with datetimes cause they are the "root" items attached to events. |
|
| 281 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
| 282 | + // next tackle the tickets (and prices?) |
|
| 283 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | 286 | |
| 287 | - /** |
|
| 288 | - * update event_datetimes |
|
| 289 | - * |
|
| 290 | - * @param EE_Event $event Event being updated |
|
| 291 | - * @param array $data the request data from the form |
|
| 292 | - * @return EE_Datetime[] |
|
| 293 | - * @throws Exception |
|
| 294 | - * @throws ReflectionException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - * @throws InvalidDataTypeException |
|
| 297 | - * @throws InvalidArgumentException |
|
| 298 | - * @throws EE_Error |
|
| 299 | - */ |
|
| 300 | - protected function _update_datetimes($event, $data) |
|
| 301 | - { |
|
| 302 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 303 | - $saved_dtt_ids = array(); |
|
| 304 | - $saved_dtt_objs = array(); |
|
| 305 | - if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 306 | - throw new InvalidArgumentException( |
|
| 307 | - esc_html__( |
|
| 308 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 309 | - 'event_espresso' |
|
| 310 | - ) |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 314 | - // trim all values to ensure any excess whitespace is removed. |
|
| 315 | - $datetime_data = array_map( |
|
| 316 | - function ($datetime_data) { |
|
| 317 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 318 | - }, |
|
| 319 | - $datetime_data |
|
| 320 | - ); |
|
| 321 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 322 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
| 323 | - ? $datetime_data['DTT_EVT_end'] |
|
| 324 | - : $datetime_data['DTT_EVT_start']; |
|
| 325 | - $datetime_values = array( |
|
| 326 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 327 | - ? $datetime_data['DTT_ID'] |
|
| 328 | - : null, |
|
| 329 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 330 | - ? $datetime_data['DTT_name'] |
|
| 331 | - : '', |
|
| 332 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 333 | - ? $datetime_data['DTT_description'] |
|
| 334 | - : '', |
|
| 335 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 336 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 337 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 338 | - ? EE_INF |
|
| 339 | - : $datetime_data['DTT_reg_limit'], |
|
| 340 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 341 | - ? $row |
|
| 342 | - : $datetime_data['DTT_order'], |
|
| 343 | - ); |
|
| 344 | - // if we have an id then let's get existing object first and then set the new values. |
|
| 345 | - // Otherwise we instantiate a new object for save. |
|
| 346 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 347 | - $datetime = EE_Registry::instance() |
|
| 348 | - ->load_model('Datetime', array($timezone)) |
|
| 349 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 350 | - // set date and time format according to what is set in this class. |
|
| 351 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 352 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 353 | - foreach ($datetime_values as $field => $value) { |
|
| 354 | - $datetime->set($field, $value); |
|
| 355 | - } |
|
| 356 | - // make sure the $dtt_id here is saved just in case |
|
| 357 | - // after the add_relation_to() the autosave replaces it. |
|
| 358 | - // We need to do this so we dont' TRASH the parent DTT. |
|
| 359 | - // (save the ID for both key and value to avoid duplications) |
|
| 360 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 361 | - } else { |
|
| 362 | - $datetime = EE_Registry::instance()->load_class( |
|
| 363 | - 'Datetime', |
|
| 364 | - array( |
|
| 365 | - $datetime_values, |
|
| 366 | - $timezone, |
|
| 367 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 368 | - ), |
|
| 369 | - false, |
|
| 370 | - false |
|
| 371 | - ); |
|
| 372 | - foreach ($datetime_values as $field => $value) { |
|
| 373 | - $datetime->set($field, $value); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - $datetime->save(); |
|
| 377 | - do_action( |
|
| 378 | - 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 379 | - $datetime, |
|
| 380 | - $row, |
|
| 381 | - $datetime_data, |
|
| 382 | - $data |
|
| 383 | - ); |
|
| 384 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 385 | - // before going any further make sure our dates are setup correctly |
|
| 386 | - // so that the end date is always equal or greater than the start date. |
|
| 387 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 388 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 389 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 390 | - $datetime->save(); |
|
| 391 | - } |
|
| 392 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 393 | - // because it is possible there was a new one created for the autosave. |
|
| 394 | - // (save the ID for both key and value to avoid duplications) |
|
| 395 | - $DTT_ID = $datetime->ID(); |
|
| 396 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 397 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 398 | - // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 399 | - } |
|
| 400 | - $event->save(); |
|
| 401 | - // now we need to REMOVE any datetimes that got deleted. |
|
| 402 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 403 | - // So its safe to permanently delete at this point. |
|
| 404 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 405 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 406 | - if (is_array($old_datetimes)) { |
|
| 407 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 408 | - foreach ($datetimes_to_delete as $id) { |
|
| 409 | - $id = absint($id); |
|
| 410 | - if (empty($id)) { |
|
| 411 | - continue; |
|
| 412 | - } |
|
| 413 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 414 | - // remove tkt relationships. |
|
| 415 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 416 | - foreach ($related_tickets as $tkt) { |
|
| 417 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 418 | - } |
|
| 419 | - $event->_remove_relation_to($id, 'Datetime'); |
|
| 420 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - return $saved_dtt_objs; |
|
| 424 | - } |
|
| 287 | + /** |
|
| 288 | + * update event_datetimes |
|
| 289 | + * |
|
| 290 | + * @param EE_Event $event Event being updated |
|
| 291 | + * @param array $data the request data from the form |
|
| 292 | + * @return EE_Datetime[] |
|
| 293 | + * @throws Exception |
|
| 294 | + * @throws ReflectionException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + * @throws InvalidDataTypeException |
|
| 297 | + * @throws InvalidArgumentException |
|
| 298 | + * @throws EE_Error |
|
| 299 | + */ |
|
| 300 | + protected function _update_datetimes($event, $data) |
|
| 301 | + { |
|
| 302 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 303 | + $saved_dtt_ids = array(); |
|
| 304 | + $saved_dtt_objs = array(); |
|
| 305 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
| 306 | + throw new InvalidArgumentException( |
|
| 307 | + esc_html__( |
|
| 308 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
| 309 | + 'event_espresso' |
|
| 310 | + ) |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
| 314 | + // trim all values to ensure any excess whitespace is removed. |
|
| 315 | + $datetime_data = array_map( |
|
| 316 | + function ($datetime_data) { |
|
| 317 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
| 318 | + }, |
|
| 319 | + $datetime_data |
|
| 320 | + ); |
|
| 321 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
| 322 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
| 323 | + ? $datetime_data['DTT_EVT_end'] |
|
| 324 | + : $datetime_data['DTT_EVT_start']; |
|
| 325 | + $datetime_values = array( |
|
| 326 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
| 327 | + ? $datetime_data['DTT_ID'] |
|
| 328 | + : null, |
|
| 329 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
| 330 | + ? $datetime_data['DTT_name'] |
|
| 331 | + : '', |
|
| 332 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
| 333 | + ? $datetime_data['DTT_description'] |
|
| 334 | + : '', |
|
| 335 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
| 336 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
| 337 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
| 338 | + ? EE_INF |
|
| 339 | + : $datetime_data['DTT_reg_limit'], |
|
| 340 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
| 341 | + ? $row |
|
| 342 | + : $datetime_data['DTT_order'], |
|
| 343 | + ); |
|
| 344 | + // if we have an id then let's get existing object first and then set the new values. |
|
| 345 | + // Otherwise we instantiate a new object for save. |
|
| 346 | + if (! empty($datetime_data['DTT_ID'])) { |
|
| 347 | + $datetime = EE_Registry::instance() |
|
| 348 | + ->load_model('Datetime', array($timezone)) |
|
| 349 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
| 350 | + // set date and time format according to what is set in this class. |
|
| 351 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
| 352 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
| 353 | + foreach ($datetime_values as $field => $value) { |
|
| 354 | + $datetime->set($field, $value); |
|
| 355 | + } |
|
| 356 | + // make sure the $dtt_id here is saved just in case |
|
| 357 | + // after the add_relation_to() the autosave replaces it. |
|
| 358 | + // We need to do this so we dont' TRASH the parent DTT. |
|
| 359 | + // (save the ID for both key and value to avoid duplications) |
|
| 360 | + $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 361 | + } else { |
|
| 362 | + $datetime = EE_Registry::instance()->load_class( |
|
| 363 | + 'Datetime', |
|
| 364 | + array( |
|
| 365 | + $datetime_values, |
|
| 366 | + $timezone, |
|
| 367 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
| 368 | + ), |
|
| 369 | + false, |
|
| 370 | + false |
|
| 371 | + ); |
|
| 372 | + foreach ($datetime_values as $field => $value) { |
|
| 373 | + $datetime->set($field, $value); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + $datetime->save(); |
|
| 377 | + do_action( |
|
| 378 | + 'AHEE__espresso_events_Pricing_Hooks___update_datetimes_after_save', |
|
| 379 | + $datetime, |
|
| 380 | + $row, |
|
| 381 | + $datetime_data, |
|
| 382 | + $data |
|
| 383 | + ); |
|
| 384 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
| 385 | + // before going any further make sure our dates are setup correctly |
|
| 386 | + // so that the end date is always equal or greater than the start date. |
|
| 387 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
| 388 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
| 389 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
| 390 | + $datetime->save(); |
|
| 391 | + } |
|
| 392 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
| 393 | + // because it is possible there was a new one created for the autosave. |
|
| 394 | + // (save the ID for both key and value to avoid duplications) |
|
| 395 | + $DTT_ID = $datetime->ID(); |
|
| 396 | + $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 397 | + $saved_dtt_objs[ $row ] = $datetime; |
|
| 398 | + // @todo if ANY of these updates fail then we want the appropriate global error message. |
|
| 399 | + } |
|
| 400 | + $event->save(); |
|
| 401 | + // now we need to REMOVE any datetimes that got deleted. |
|
| 402 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
| 403 | + // So its safe to permanently delete at this point. |
|
| 404 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
| 405 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
| 406 | + if (is_array($old_datetimes)) { |
|
| 407 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
| 408 | + foreach ($datetimes_to_delete as $id) { |
|
| 409 | + $id = absint($id); |
|
| 410 | + if (empty($id)) { |
|
| 411 | + continue; |
|
| 412 | + } |
|
| 413 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
| 414 | + // remove tkt relationships. |
|
| 415 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
| 416 | + foreach ($related_tickets as $tkt) { |
|
| 417 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
| 418 | + } |
|
| 419 | + $event->_remove_relation_to($id, 'Datetime'); |
|
| 420 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + return $saved_dtt_objs; |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | 426 | |
| 427 | - /** |
|
| 428 | - * update tickets |
|
| 429 | - * |
|
| 430 | - * @param EE_Event $event Event object being updated |
|
| 431 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 432 | - * @param array $data incoming request data |
|
| 433 | - * @return EE_Ticket[] |
|
| 434 | - * @throws Exception |
|
| 435 | - * @throws ReflectionException |
|
| 436 | - * @throws InvalidInterfaceException |
|
| 437 | - * @throws InvalidDataTypeException |
|
| 438 | - * @throws InvalidArgumentException |
|
| 439 | - * @throws EE_Error |
|
| 440 | - */ |
|
| 441 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 442 | - { |
|
| 443 | - $new_tkt = null; |
|
| 444 | - $new_default = null; |
|
| 445 | - // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 446 | - $data = stripslashes_deep($data); |
|
| 447 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 448 | - $saved_tickets = $datetimes_on_existing = array(); |
|
| 449 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 450 | - if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 451 | - throw new InvalidArgumentException( |
|
| 452 | - esc_html__( |
|
| 453 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 454 | - 'event_espresso' |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - } |
|
| 458 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 459 | - $update_prices = $create_new_TKT = false; |
|
| 460 | - // figure out what datetimes were added to the ticket |
|
| 461 | - // and what datetimes were removed from the ticket in the session. |
|
| 462 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 463 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 464 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 465 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 466 | - // trim inputs to ensure any excess whitespace is removed. |
|
| 467 | - $tkt = array_map( |
|
| 468 | - function ($ticket_data) { |
|
| 469 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 470 | - }, |
|
| 471 | - $tkt |
|
| 472 | - ); |
|
| 473 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 474 | - // because we're doing calculations prior to using the models. |
|
| 475 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 476 | - $ticket_price = isset($tkt['TKT_price']) |
|
| 477 | - ? round((float) $tkt['TKT_price'], 3) |
|
| 478 | - : 0; |
|
| 479 | - // note incoming base price needs converted from localized value. |
|
| 480 | - $base_price = isset($tkt['TKT_base_price']) |
|
| 481 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 482 | - : 0; |
|
| 483 | - // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 484 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 485 | - ? $base_price |
|
| 486 | - : $ticket_price; |
|
| 487 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 488 | - ? $tkt['TKT_base_price_ID'] |
|
| 489 | - : 0; |
|
| 490 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 491 | - ? $data['edit_prices'][ $row ] |
|
| 492 | - : array(); |
|
| 493 | - $now = null; |
|
| 494 | - if (empty($tkt['TKT_start_date'])) { |
|
| 495 | - // lets' use now in the set timezone. |
|
| 496 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 497 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 498 | - } |
|
| 499 | - if (empty($tkt['TKT_end_date'])) { |
|
| 500 | - /** |
|
| 501 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 502 | - */ |
|
| 503 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 504 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 505 | - } |
|
| 506 | - $TKT_values = array( |
|
| 507 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 508 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 509 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 510 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 511 | - && $tkt['TKT_description'] !== esc_html__( |
|
| 512 | - 'You can modify this description', |
|
| 513 | - 'event_espresso' |
|
| 514 | - ) |
|
| 515 | - ? $tkt['TKT_description'] |
|
| 516 | - : '', |
|
| 517 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 518 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 519 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 520 | - ? EE_INF |
|
| 521 | - : $tkt['TKT_qty'], |
|
| 522 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 523 | - ? EE_INF |
|
| 524 | - : $tkt['TKT_uses'], |
|
| 525 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 526 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 527 | - 'TKT_row' => $row, |
|
| 528 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 529 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 530 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 531 | - 'TKT_price' => $ticket_price, |
|
| 532 | - ); |
|
| 533 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 534 | - // which means in turn that the prices will become new prices as well. |
|
| 535 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 536 | - $TKT_values['TKT_ID'] = 0; |
|
| 537 | - $TKT_values['TKT_is_default'] = 0; |
|
| 538 | - $update_prices = true; |
|
| 539 | - } |
|
| 540 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 541 | - // we actually do our saves ahead of doing any add_relations to |
|
| 542 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 543 | - // but DID have it's items modified. |
|
| 544 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 545 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 546 | - if (absint($TKT_values['TKT_ID'])) { |
|
| 547 | - $ticket = EE_Registry::instance() |
|
| 548 | - ->load_model('Ticket', array($timezone)) |
|
| 549 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
| 550 | - if ($ticket instanceof EE_Ticket) { |
|
| 551 | - $ticket = $this->_update_ticket_datetimes( |
|
| 552 | - $ticket, |
|
| 553 | - $saved_datetimes, |
|
| 554 | - $datetimes_added, |
|
| 555 | - $datetimes_removed |
|
| 556 | - ); |
|
| 557 | - // are there any registrations using this ticket ? |
|
| 558 | - $tickets_sold = $ticket->count_related( |
|
| 559 | - 'Registration', |
|
| 560 | - array( |
|
| 561 | - array( |
|
| 562 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 563 | - ), |
|
| 564 | - ) |
|
| 565 | - ); |
|
| 566 | - // set ticket formats |
|
| 567 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 568 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 569 | - // let's just check the total price for the existing ticket |
|
| 570 | - // and determine if it matches the new total price. |
|
| 571 | - // if they are different then we create a new ticket (if tickets sold) |
|
| 572 | - // if they aren't different then we go ahead and modify existing ticket. |
|
| 573 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 574 | - // set new values |
|
| 575 | - foreach ($TKT_values as $field => $value) { |
|
| 576 | - if ($field === 'TKT_qty') { |
|
| 577 | - $ticket->set_qty($value); |
|
| 578 | - } else { |
|
| 579 | - $ticket->set($field, $value); |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 583 | - // Otherwise we have to create a new ticket. |
|
| 584 | - if ($create_new_TKT) { |
|
| 585 | - $new_tkt = $this->_duplicate_ticket( |
|
| 586 | - $ticket, |
|
| 587 | - $price_rows, |
|
| 588 | - $ticket_price, |
|
| 589 | - $base_price, |
|
| 590 | - $base_price_id |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - } else { |
|
| 595 | - // no TKT_id so a new TKT |
|
| 596 | - $ticket = EE_Ticket::new_instance( |
|
| 597 | - $TKT_values, |
|
| 598 | - $timezone, |
|
| 599 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 600 | - ); |
|
| 601 | - if ($ticket instanceof EE_Ticket) { |
|
| 602 | - // make sure ticket has an ID of setting relations won't work |
|
| 603 | - $ticket->save(); |
|
| 604 | - $ticket = $this->_update_ticket_datetimes( |
|
| 605 | - $ticket, |
|
| 606 | - $saved_datetimes, |
|
| 607 | - $datetimes_added, |
|
| 608 | - $datetimes_removed |
|
| 609 | - ); |
|
| 610 | - $update_prices = true; |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - // make sure any current values have been saved. |
|
| 614 | - // $ticket->save(); |
|
| 615 | - // before going any further make sure our dates are setup correctly |
|
| 616 | - // so that the end date is always equal or greater than the start date. |
|
| 617 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 618 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 619 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 620 | - } |
|
| 621 | - // let's make sure the base price is handled |
|
| 622 | - $ticket = ! $create_new_TKT |
|
| 623 | - ? $this->_add_prices_to_ticket( |
|
| 624 | - array(), |
|
| 625 | - $ticket, |
|
| 626 | - $update_prices, |
|
| 627 | - $base_price, |
|
| 628 | - $base_price_id |
|
| 629 | - ) |
|
| 630 | - : $ticket; |
|
| 631 | - // add/update price_modifiers |
|
| 632 | - $ticket = ! $create_new_TKT |
|
| 633 | - ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 634 | - : $ticket; |
|
| 635 | - // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 636 | - $ticket->ensure_TKT_Price_correct(); |
|
| 637 | - // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 638 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 639 | - $update_prices = true; |
|
| 640 | - $new_default = clone $ticket; |
|
| 641 | - $new_default->set('TKT_ID', 0); |
|
| 642 | - $new_default->set('TKT_is_default', 1); |
|
| 643 | - $new_default->set('TKT_row', 1); |
|
| 644 | - $new_default->set('TKT_price', $ticket_price); |
|
| 645 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 646 | - // (note this is just removing the cached relations in the object) |
|
| 647 | - $new_default->_remove_relations('Datetime'); |
|
| 648 | - // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 649 | - $new_default = $this->_add_prices_to_ticket( |
|
| 650 | - $price_rows, |
|
| 651 | - $new_default, |
|
| 652 | - $update_prices |
|
| 653 | - ); |
|
| 654 | - // don't forget the base price! |
|
| 655 | - $new_default = $this->_add_prices_to_ticket( |
|
| 656 | - array(), |
|
| 657 | - $new_default, |
|
| 658 | - $update_prices, |
|
| 659 | - $base_price, |
|
| 660 | - $base_price_id |
|
| 661 | - ); |
|
| 662 | - $new_default->save(); |
|
| 663 | - do_action( |
|
| 664 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 665 | - $new_default, |
|
| 666 | - $row, |
|
| 667 | - $ticket, |
|
| 668 | - $data |
|
| 669 | - ); |
|
| 670 | - } |
|
| 671 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 672 | - // for the given dtt that are related to the current ticket. |
|
| 673 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 674 | - // what current ticket the archived tickets are related to |
|
| 675 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 676 | - // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 677 | - // save existing TKT |
|
| 678 | - $ticket->save(); |
|
| 679 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 680 | - // save new TKT |
|
| 681 | - $new_tkt->save(); |
|
| 682 | - // add new ticket to array |
|
| 683 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 684 | - do_action( |
|
| 685 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 686 | - $new_tkt, |
|
| 687 | - $row, |
|
| 688 | - $tkt, |
|
| 689 | - $data |
|
| 690 | - ); |
|
| 691 | - } else { |
|
| 692 | - // add tkt to saved tkts |
|
| 693 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 694 | - do_action( |
|
| 695 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 696 | - $ticket, |
|
| 697 | - $row, |
|
| 698 | - $tkt, |
|
| 699 | - $data |
|
| 700 | - ); |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - // now we need to handle tickets actually "deleted permanently". |
|
| 704 | - // There are cases where we'd want this to happen |
|
| 705 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 706 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 707 | - // No sense in keeping all the related data in the db! |
|
| 708 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 709 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 710 | - foreach ($tickets_removed as $id) { |
|
| 711 | - $id = absint($id); |
|
| 712 | - // get the ticket for this id |
|
| 713 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 714 | - // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 715 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 716 | - continue; |
|
| 717 | - } |
|
| 718 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 719 | - // because we don't actually permanently delete these tickets. |
|
| 720 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 721 | - $tkt_to_remove->delete(); |
|
| 722 | - continue; |
|
| 723 | - } |
|
| 724 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 725 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 726 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 727 | - foreach ($datetimes as $datetime) { |
|
| 728 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 729 | - } |
|
| 730 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
| 731 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 732 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
| 733 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 734 | - // finally let's delete this ticket |
|
| 735 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 736 | - $tkt_to_remove->delete_permanently(); |
|
| 737 | - } |
|
| 738 | - return $saved_tickets; |
|
| 739 | - } |
|
| 427 | + /** |
|
| 428 | + * update tickets |
|
| 429 | + * |
|
| 430 | + * @param EE_Event $event Event object being updated |
|
| 431 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
| 432 | + * @param array $data incoming request data |
|
| 433 | + * @return EE_Ticket[] |
|
| 434 | + * @throws Exception |
|
| 435 | + * @throws ReflectionException |
|
| 436 | + * @throws InvalidInterfaceException |
|
| 437 | + * @throws InvalidDataTypeException |
|
| 438 | + * @throws InvalidArgumentException |
|
| 439 | + * @throws EE_Error |
|
| 440 | + */ |
|
| 441 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
| 442 | + { |
|
| 443 | + $new_tkt = null; |
|
| 444 | + $new_default = null; |
|
| 445 | + // stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
| 446 | + $data = stripslashes_deep($data); |
|
| 447 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
| 448 | + $saved_tickets = $datetimes_on_existing = array(); |
|
| 449 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
| 450 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
| 451 | + throw new InvalidArgumentException( |
|
| 452 | + esc_html__( |
|
| 453 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
| 454 | + 'event_espresso' |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
| 459 | + $update_prices = $create_new_TKT = false; |
|
| 460 | + // figure out what datetimes were added to the ticket |
|
| 461 | + // and what datetimes were removed from the ticket in the session. |
|
| 462 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 463 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 464 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
| 465 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
| 466 | + // trim inputs to ensure any excess whitespace is removed. |
|
| 467 | + $tkt = array_map( |
|
| 468 | + function ($ticket_data) { |
|
| 469 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
| 470 | + }, |
|
| 471 | + $tkt |
|
| 472 | + ); |
|
| 473 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
| 474 | + // because we're doing calculations prior to using the models. |
|
| 475 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
| 476 | + $ticket_price = isset($tkt['TKT_price']) |
|
| 477 | + ? round((float) $tkt['TKT_price'], 3) |
|
| 478 | + : 0; |
|
| 479 | + // note incoming base price needs converted from localized value. |
|
| 480 | + $base_price = isset($tkt['TKT_base_price']) |
|
| 481 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
| 482 | + : 0; |
|
| 483 | + // if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
| 484 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
| 485 | + ? $base_price |
|
| 486 | + : $ticket_price; |
|
| 487 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
| 488 | + ? $tkt['TKT_base_price_ID'] |
|
| 489 | + : 0; |
|
| 490 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 491 | + ? $data['edit_prices'][ $row ] |
|
| 492 | + : array(); |
|
| 493 | + $now = null; |
|
| 494 | + if (empty($tkt['TKT_start_date'])) { |
|
| 495 | + // lets' use now in the set timezone. |
|
| 496 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
| 497 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
| 498 | + } |
|
| 499 | + if (empty($tkt['TKT_end_date'])) { |
|
| 500 | + /** |
|
| 501 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
| 502 | + */ |
|
| 503 | + $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 504 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
| 505 | + } |
|
| 506 | + $TKT_values = array( |
|
| 507 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
| 508 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
| 509 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
| 510 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
| 511 | + && $tkt['TKT_description'] !== esc_html__( |
|
| 512 | + 'You can modify this description', |
|
| 513 | + 'event_espresso' |
|
| 514 | + ) |
|
| 515 | + ? $tkt['TKT_description'] |
|
| 516 | + : '', |
|
| 517 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
| 518 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
| 519 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
| 520 | + ? EE_INF |
|
| 521 | + : $tkt['TKT_qty'], |
|
| 522 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
| 523 | + ? EE_INF |
|
| 524 | + : $tkt['TKT_uses'], |
|
| 525 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
| 526 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
| 527 | + 'TKT_row' => $row, |
|
| 528 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
| 529 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
| 530 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
| 531 | + 'TKT_price' => $ticket_price, |
|
| 532 | + ); |
|
| 533 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
| 534 | + // which means in turn that the prices will become new prices as well. |
|
| 535 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
| 536 | + $TKT_values['TKT_ID'] = 0; |
|
| 537 | + $TKT_values['TKT_is_default'] = 0; |
|
| 538 | + $update_prices = true; |
|
| 539 | + } |
|
| 540 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
| 541 | + // we actually do our saves ahead of doing any add_relations to |
|
| 542 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
| 543 | + // but DID have it's items modified. |
|
| 544 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
| 545 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
| 546 | + if (absint($TKT_values['TKT_ID'])) { |
|
| 547 | + $ticket = EE_Registry::instance() |
|
| 548 | + ->load_model('Ticket', array($timezone)) |
|
| 549 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
| 550 | + if ($ticket instanceof EE_Ticket) { |
|
| 551 | + $ticket = $this->_update_ticket_datetimes( |
|
| 552 | + $ticket, |
|
| 553 | + $saved_datetimes, |
|
| 554 | + $datetimes_added, |
|
| 555 | + $datetimes_removed |
|
| 556 | + ); |
|
| 557 | + // are there any registrations using this ticket ? |
|
| 558 | + $tickets_sold = $ticket->count_related( |
|
| 559 | + 'Registration', |
|
| 560 | + array( |
|
| 561 | + array( |
|
| 562 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
| 563 | + ), |
|
| 564 | + ) |
|
| 565 | + ); |
|
| 566 | + // set ticket formats |
|
| 567 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
| 568 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
| 569 | + // let's just check the total price for the existing ticket |
|
| 570 | + // and determine if it matches the new total price. |
|
| 571 | + // if they are different then we create a new ticket (if tickets sold) |
|
| 572 | + // if they aren't different then we go ahead and modify existing ticket. |
|
| 573 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
| 574 | + // set new values |
|
| 575 | + foreach ($TKT_values as $field => $value) { |
|
| 576 | + if ($field === 'TKT_qty') { |
|
| 577 | + $ticket->set_qty($value); |
|
| 578 | + } else { |
|
| 579 | + $ticket->set($field, $value); |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
| 583 | + // Otherwise we have to create a new ticket. |
|
| 584 | + if ($create_new_TKT) { |
|
| 585 | + $new_tkt = $this->_duplicate_ticket( |
|
| 586 | + $ticket, |
|
| 587 | + $price_rows, |
|
| 588 | + $ticket_price, |
|
| 589 | + $base_price, |
|
| 590 | + $base_price_id |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + } else { |
|
| 595 | + // no TKT_id so a new TKT |
|
| 596 | + $ticket = EE_Ticket::new_instance( |
|
| 597 | + $TKT_values, |
|
| 598 | + $timezone, |
|
| 599 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
| 600 | + ); |
|
| 601 | + if ($ticket instanceof EE_Ticket) { |
|
| 602 | + // make sure ticket has an ID of setting relations won't work |
|
| 603 | + $ticket->save(); |
|
| 604 | + $ticket = $this->_update_ticket_datetimes( |
|
| 605 | + $ticket, |
|
| 606 | + $saved_datetimes, |
|
| 607 | + $datetimes_added, |
|
| 608 | + $datetimes_removed |
|
| 609 | + ); |
|
| 610 | + $update_prices = true; |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + // make sure any current values have been saved. |
|
| 614 | + // $ticket->save(); |
|
| 615 | + // before going any further make sure our dates are setup correctly |
|
| 616 | + // so that the end date is always equal or greater than the start date. |
|
| 617 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
| 618 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
| 619 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
| 620 | + } |
|
| 621 | + // let's make sure the base price is handled |
|
| 622 | + $ticket = ! $create_new_TKT |
|
| 623 | + ? $this->_add_prices_to_ticket( |
|
| 624 | + array(), |
|
| 625 | + $ticket, |
|
| 626 | + $update_prices, |
|
| 627 | + $base_price, |
|
| 628 | + $base_price_id |
|
| 629 | + ) |
|
| 630 | + : $ticket; |
|
| 631 | + // add/update price_modifiers |
|
| 632 | + $ticket = ! $create_new_TKT |
|
| 633 | + ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) |
|
| 634 | + : $ticket; |
|
| 635 | + // need to make sue that the TKT_price is accurate after saving the prices. |
|
| 636 | + $ticket->ensure_TKT_Price_correct(); |
|
| 637 | + // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
| 638 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 639 | + $update_prices = true; |
|
| 640 | + $new_default = clone $ticket; |
|
| 641 | + $new_default->set('TKT_ID', 0); |
|
| 642 | + $new_default->set('TKT_is_default', 1); |
|
| 643 | + $new_default->set('TKT_row', 1); |
|
| 644 | + $new_default->set('TKT_price', $ticket_price); |
|
| 645 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
| 646 | + // (note this is just removing the cached relations in the object) |
|
| 647 | + $new_default->_remove_relations('Datetime'); |
|
| 648 | + // @todo we need to add the current attached prices as new prices to the new default ticket. |
|
| 649 | + $new_default = $this->_add_prices_to_ticket( |
|
| 650 | + $price_rows, |
|
| 651 | + $new_default, |
|
| 652 | + $update_prices |
|
| 653 | + ); |
|
| 654 | + // don't forget the base price! |
|
| 655 | + $new_default = $this->_add_prices_to_ticket( |
|
| 656 | + array(), |
|
| 657 | + $new_default, |
|
| 658 | + $update_prices, |
|
| 659 | + $base_price, |
|
| 660 | + $base_price_id |
|
| 661 | + ); |
|
| 662 | + $new_default->save(); |
|
| 663 | + do_action( |
|
| 664 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
| 665 | + $new_default, |
|
| 666 | + $row, |
|
| 667 | + $ticket, |
|
| 668 | + $data |
|
| 669 | + ); |
|
| 670 | + } |
|
| 671 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
| 672 | + // for the given dtt that are related to the current ticket. |
|
| 673 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
| 674 | + // what current ticket the archived tickets are related to |
|
| 675 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
| 676 | + // let's assign any tickets that have been setup to the saved_tickets tracker |
|
| 677 | + // save existing TKT |
|
| 678 | + $ticket->save(); |
|
| 679 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
| 680 | + // save new TKT |
|
| 681 | + $new_tkt->save(); |
|
| 682 | + // add new ticket to array |
|
| 683 | + $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 684 | + do_action( |
|
| 685 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
| 686 | + $new_tkt, |
|
| 687 | + $row, |
|
| 688 | + $tkt, |
|
| 689 | + $data |
|
| 690 | + ); |
|
| 691 | + } else { |
|
| 692 | + // add tkt to saved tkts |
|
| 693 | + $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 694 | + do_action( |
|
| 695 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
| 696 | + $ticket, |
|
| 697 | + $row, |
|
| 698 | + $tkt, |
|
| 699 | + $data |
|
| 700 | + ); |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + // now we need to handle tickets actually "deleted permanently". |
|
| 704 | + // There are cases where we'd want this to happen |
|
| 705 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
| 706 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
| 707 | + // No sense in keeping all the related data in the db! |
|
| 708 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
| 709 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
| 710 | + foreach ($tickets_removed as $id) { |
|
| 711 | + $id = absint($id); |
|
| 712 | + // get the ticket for this id |
|
| 713 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
| 714 | + // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
| 715 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
| 716 | + continue; |
|
| 717 | + } |
|
| 718 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
| 719 | + // because we don't actually permanently delete these tickets. |
|
| 720 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
| 721 | + $tkt_to_remove->delete(); |
|
| 722 | + continue; |
|
| 723 | + } |
|
| 724 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
| 725 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
| 726 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
| 727 | + foreach ($datetimes as $datetime) { |
|
| 728 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
| 729 | + } |
|
| 730 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
| 731 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
| 732 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
| 733 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
| 734 | + // finally let's delete this ticket |
|
| 735 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
| 736 | + $tkt_to_remove->delete_permanently(); |
|
| 737 | + } |
|
| 738 | + return $saved_tickets; |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | 741 | |
| 742 | - /** |
|
| 743 | - * @access protected |
|
| 744 | - * @param EE_Ticket $ticket |
|
| 745 | - * @param \EE_Datetime[] $saved_datetimes |
|
| 746 | - * @param \EE_Datetime[] $added_datetimes |
|
| 747 | - * @param \EE_Datetime[] $removed_datetimes |
|
| 748 | - * @return EE_Ticket |
|
| 749 | - * @throws EE_Error |
|
| 750 | - */ |
|
| 751 | - protected function _update_ticket_datetimes( |
|
| 752 | - EE_Ticket $ticket, |
|
| 753 | - $saved_datetimes = array(), |
|
| 754 | - $added_datetimes = array(), |
|
| 755 | - $removed_datetimes = array() |
|
| 756 | - ) { |
|
| 757 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 758 | - // and removing the ticket from datetimes it got removed from. |
|
| 759 | - // first let's add datetimes |
|
| 760 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 761 | - foreach ($added_datetimes as $row_id) { |
|
| 762 | - $row_id = (int) $row_id; |
|
| 763 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 764 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 765 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 766 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 767 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 768 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - // then remove datetimes |
|
| 774 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 775 | - foreach ($removed_datetimes as $row_id) { |
|
| 776 | - $row_id = (int) $row_id; |
|
| 777 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 778 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 779 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 780 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 781 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 782 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
| 783 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 784 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - // cap ticket qty by datetime reg limits |
|
| 790 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 791 | - return $ticket; |
|
| 792 | - } |
|
| 742 | + /** |
|
| 743 | + * @access protected |
|
| 744 | + * @param EE_Ticket $ticket |
|
| 745 | + * @param \EE_Datetime[] $saved_datetimes |
|
| 746 | + * @param \EE_Datetime[] $added_datetimes |
|
| 747 | + * @param \EE_Datetime[] $removed_datetimes |
|
| 748 | + * @return EE_Ticket |
|
| 749 | + * @throws EE_Error |
|
| 750 | + */ |
|
| 751 | + protected function _update_ticket_datetimes( |
|
| 752 | + EE_Ticket $ticket, |
|
| 753 | + $saved_datetimes = array(), |
|
| 754 | + $added_datetimes = array(), |
|
| 755 | + $removed_datetimes = array() |
|
| 756 | + ) { |
|
| 757 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
| 758 | + // and removing the ticket from datetimes it got removed from. |
|
| 759 | + // first let's add datetimes |
|
| 760 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 761 | + foreach ($added_datetimes as $row_id) { |
|
| 762 | + $row_id = (int) $row_id; |
|
| 763 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 764 | + $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 765 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 766 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
| 767 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 768 | + $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + // then remove datetimes |
|
| 774 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 775 | + foreach ($removed_datetimes as $row_id) { |
|
| 776 | + $row_id = (int) $row_id; |
|
| 777 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
| 778 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
| 779 | + if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 780 | + $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 781 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
| 782 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
| 783 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
| 784 | + $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + // cap ticket qty by datetime reg limits |
|
| 790 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
| 791 | + return $ticket; |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | 794 | |
| 795 | - /** |
|
| 796 | - * @access protected |
|
| 797 | - * @param EE_Ticket $ticket |
|
| 798 | - * @param array $price_rows |
|
| 799 | - * @param int $ticket_price |
|
| 800 | - * @param int $base_price |
|
| 801 | - * @param int $base_price_id |
|
| 802 | - * @return EE_Ticket |
|
| 803 | - * @throws ReflectionException |
|
| 804 | - * @throws InvalidArgumentException |
|
| 805 | - * @throws InvalidInterfaceException |
|
| 806 | - * @throws InvalidDataTypeException |
|
| 807 | - * @throws EE_Error |
|
| 808 | - */ |
|
| 809 | - protected function _duplicate_ticket( |
|
| 810 | - EE_Ticket $ticket, |
|
| 811 | - $price_rows = array(), |
|
| 812 | - $ticket_price = 0, |
|
| 813 | - $base_price = 0, |
|
| 814 | - $base_price_id = 0 |
|
| 815 | - ) { |
|
| 816 | - // create new ticket that's a copy of the existing |
|
| 817 | - // except a new id of course (and not archived) |
|
| 818 | - // AND has the new TKT_price associated with it. |
|
| 819 | - $new_ticket = clone $ticket; |
|
| 820 | - $new_ticket->set('TKT_ID', 0); |
|
| 821 | - $new_ticket->set_deleted(0); |
|
| 822 | - $new_ticket->set_price($ticket_price); |
|
| 823 | - $new_ticket->set_sold(0); |
|
| 824 | - // let's get a new ID for this ticket |
|
| 825 | - $new_ticket->save(); |
|
| 826 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 827 | - $datetimes_on_existing = $ticket->datetimes(); |
|
| 828 | - $new_ticket = $this->_update_ticket_datetimes( |
|
| 829 | - $new_ticket, |
|
| 830 | - $datetimes_on_existing, |
|
| 831 | - array_keys($datetimes_on_existing) |
|
| 832 | - ); |
|
| 833 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 834 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 835 | - // available. |
|
| 836 | - if ($ticket->sold() > 0) { |
|
| 837 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 838 | - $new_ticket->set_qty($new_qty); |
|
| 839 | - } |
|
| 840 | - // now we update the prices just for this ticket |
|
| 841 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 842 | - // and we update the base price |
|
| 843 | - $new_ticket = $this->_add_prices_to_ticket( |
|
| 844 | - array(), |
|
| 845 | - $new_ticket, |
|
| 846 | - true, |
|
| 847 | - $base_price, |
|
| 848 | - $base_price_id |
|
| 849 | - ); |
|
| 850 | - return $new_ticket; |
|
| 851 | - } |
|
| 795 | + /** |
|
| 796 | + * @access protected |
|
| 797 | + * @param EE_Ticket $ticket |
|
| 798 | + * @param array $price_rows |
|
| 799 | + * @param int $ticket_price |
|
| 800 | + * @param int $base_price |
|
| 801 | + * @param int $base_price_id |
|
| 802 | + * @return EE_Ticket |
|
| 803 | + * @throws ReflectionException |
|
| 804 | + * @throws InvalidArgumentException |
|
| 805 | + * @throws InvalidInterfaceException |
|
| 806 | + * @throws InvalidDataTypeException |
|
| 807 | + * @throws EE_Error |
|
| 808 | + */ |
|
| 809 | + protected function _duplicate_ticket( |
|
| 810 | + EE_Ticket $ticket, |
|
| 811 | + $price_rows = array(), |
|
| 812 | + $ticket_price = 0, |
|
| 813 | + $base_price = 0, |
|
| 814 | + $base_price_id = 0 |
|
| 815 | + ) { |
|
| 816 | + // create new ticket that's a copy of the existing |
|
| 817 | + // except a new id of course (and not archived) |
|
| 818 | + // AND has the new TKT_price associated with it. |
|
| 819 | + $new_ticket = clone $ticket; |
|
| 820 | + $new_ticket->set('TKT_ID', 0); |
|
| 821 | + $new_ticket->set_deleted(0); |
|
| 822 | + $new_ticket->set_price($ticket_price); |
|
| 823 | + $new_ticket->set_sold(0); |
|
| 824 | + // let's get a new ID for this ticket |
|
| 825 | + $new_ticket->save(); |
|
| 826 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
| 827 | + $datetimes_on_existing = $ticket->datetimes(); |
|
| 828 | + $new_ticket = $this->_update_ticket_datetimes( |
|
| 829 | + $new_ticket, |
|
| 830 | + $datetimes_on_existing, |
|
| 831 | + array_keys($datetimes_on_existing) |
|
| 832 | + ); |
|
| 833 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
| 834 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
| 835 | + // available. |
|
| 836 | + if ($ticket->sold() > 0) { |
|
| 837 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
| 838 | + $new_ticket->set_qty($new_qty); |
|
| 839 | + } |
|
| 840 | + // now we update the prices just for this ticket |
|
| 841 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
| 842 | + // and we update the base price |
|
| 843 | + $new_ticket = $this->_add_prices_to_ticket( |
|
| 844 | + array(), |
|
| 845 | + $new_ticket, |
|
| 846 | + true, |
|
| 847 | + $base_price, |
|
| 848 | + $base_price_id |
|
| 849 | + ); |
|
| 850 | + return $new_ticket; |
|
| 851 | + } |
|
| 852 | 852 | |
| 853 | 853 | |
| 854 | - /** |
|
| 855 | - * This attaches a list of given prices to a ticket. |
|
| 856 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 857 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 858 | - * price info and prices are automatically "archived" via the ticket. |
|
| 859 | - * |
|
| 860 | - * @access private |
|
| 861 | - * @param array $prices Array of prices from the form. |
|
| 862 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 863 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 864 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 865 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 866 | - * @return EE_Ticket |
|
| 867 | - * @throws ReflectionException |
|
| 868 | - * @throws InvalidArgumentException |
|
| 869 | - * @throws InvalidInterfaceException |
|
| 870 | - * @throws InvalidDataTypeException |
|
| 871 | - * @throws EE_Error |
|
| 872 | - */ |
|
| 873 | - protected function _add_prices_to_ticket( |
|
| 874 | - array $prices, |
|
| 875 | - EE_Ticket $ticket, |
|
| 876 | - $new_prices = false, |
|
| 877 | - $base_price = false, |
|
| 878 | - $base_price_id = false |
|
| 879 | - ) { |
|
| 880 | - // let's just get any current prices that may exist on the given ticket |
|
| 881 | - // so we can remove any prices that got trashed in this session. |
|
| 882 | - $current_prices_on_ticket = $base_price !== false |
|
| 883 | - ? $ticket->base_price(true) |
|
| 884 | - : $ticket->price_modifiers(); |
|
| 885 | - $updated_prices = array(); |
|
| 886 | - // if $base_price ! FALSE then updating a base price. |
|
| 887 | - if ($base_price !== false) { |
|
| 888 | - $prices[1] = array( |
|
| 889 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 890 | - 'PRT_ID' => 1, |
|
| 891 | - 'PRC_amount' => $base_price, |
|
| 892 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
| 893 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 894 | - ); |
|
| 895 | - } |
|
| 896 | - // possibly need to save tkt |
|
| 897 | - if (! $ticket->ID()) { |
|
| 898 | - $ticket->save(); |
|
| 899 | - } |
|
| 900 | - foreach ($prices as $row => $prc) { |
|
| 901 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 902 | - if (empty($prt_id)) { |
|
| 903 | - continue; |
|
| 904 | - } //prices MUST have a price type id. |
|
| 905 | - $PRC_values = array( |
|
| 906 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 907 | - 'PRT_ID' => $prt_id, |
|
| 908 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 909 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 910 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 911 | - 'PRC_is_default' => false, |
|
| 912 | - // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 913 | - 'PRC_order' => $row, |
|
| 914 | - ); |
|
| 915 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 916 | - $PRC_values['PRC_ID'] = 0; |
|
| 917 | - $price = EE_Registry::instance()->load_class( |
|
| 918 | - 'Price', |
|
| 919 | - array($PRC_values), |
|
| 920 | - false, |
|
| 921 | - false |
|
| 922 | - ); |
|
| 923 | - } else { |
|
| 924 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 925 | - // update this price with new values |
|
| 926 | - foreach ($PRC_values as $field => $value) { |
|
| 927 | - $price->set($field, $value); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - $price->save(); |
|
| 931 | - $updated_prices[ $price->ID() ] = $price; |
|
| 932 | - $ticket->_add_relation_to($price, 'Price'); |
|
| 933 | - } |
|
| 934 | - // now let's remove any prices that got removed from the ticket |
|
| 935 | - if (! empty($current_prices_on_ticket)) { |
|
| 936 | - $current = array_keys($current_prices_on_ticket); |
|
| 937 | - $updated = array_keys($updated_prices); |
|
| 938 | - $prices_to_remove = array_diff($current, $updated); |
|
| 939 | - if (! empty($prices_to_remove)) { |
|
| 940 | - foreach ($prices_to_remove as $prc_id) { |
|
| 941 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 942 | - $ticket->_remove_relation_to($p, 'Price'); |
|
| 943 | - // delete permanently the price |
|
| 944 | - $p->delete_permanently(); |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - } |
|
| 948 | - return $ticket; |
|
| 949 | - } |
|
| 854 | + /** |
|
| 855 | + * This attaches a list of given prices to a ticket. |
|
| 856 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
| 857 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
| 858 | + * price info and prices are automatically "archived" via the ticket. |
|
| 859 | + * |
|
| 860 | + * @access private |
|
| 861 | + * @param array $prices Array of prices from the form. |
|
| 862 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
| 863 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
| 864 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
| 865 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
| 866 | + * @return EE_Ticket |
|
| 867 | + * @throws ReflectionException |
|
| 868 | + * @throws InvalidArgumentException |
|
| 869 | + * @throws InvalidInterfaceException |
|
| 870 | + * @throws InvalidDataTypeException |
|
| 871 | + * @throws EE_Error |
|
| 872 | + */ |
|
| 873 | + protected function _add_prices_to_ticket( |
|
| 874 | + array $prices, |
|
| 875 | + EE_Ticket $ticket, |
|
| 876 | + $new_prices = false, |
|
| 877 | + $base_price = false, |
|
| 878 | + $base_price_id = false |
|
| 879 | + ) { |
|
| 880 | + // let's just get any current prices that may exist on the given ticket |
|
| 881 | + // so we can remove any prices that got trashed in this session. |
|
| 882 | + $current_prices_on_ticket = $base_price !== false |
|
| 883 | + ? $ticket->base_price(true) |
|
| 884 | + : $ticket->price_modifiers(); |
|
| 885 | + $updated_prices = array(); |
|
| 886 | + // if $base_price ! FALSE then updating a base price. |
|
| 887 | + if ($base_price !== false) { |
|
| 888 | + $prices[1] = array( |
|
| 889 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
| 890 | + 'PRT_ID' => 1, |
|
| 891 | + 'PRC_amount' => $base_price, |
|
| 892 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
| 893 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
| 894 | + ); |
|
| 895 | + } |
|
| 896 | + // possibly need to save tkt |
|
| 897 | + if (! $ticket->ID()) { |
|
| 898 | + $ticket->save(); |
|
| 899 | + } |
|
| 900 | + foreach ($prices as $row => $prc) { |
|
| 901 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
| 902 | + if (empty($prt_id)) { |
|
| 903 | + continue; |
|
| 904 | + } //prices MUST have a price type id. |
|
| 905 | + $PRC_values = array( |
|
| 906 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
| 907 | + 'PRT_ID' => $prt_id, |
|
| 908 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
| 909 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
| 910 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
| 911 | + 'PRC_is_default' => false, |
|
| 912 | + // make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
| 913 | + 'PRC_order' => $row, |
|
| 914 | + ); |
|
| 915 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
| 916 | + $PRC_values['PRC_ID'] = 0; |
|
| 917 | + $price = EE_Registry::instance()->load_class( |
|
| 918 | + 'Price', |
|
| 919 | + array($PRC_values), |
|
| 920 | + false, |
|
| 921 | + false |
|
| 922 | + ); |
|
| 923 | + } else { |
|
| 924 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
| 925 | + // update this price with new values |
|
| 926 | + foreach ($PRC_values as $field => $value) { |
|
| 927 | + $price->set($field, $value); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + $price->save(); |
|
| 931 | + $updated_prices[ $price->ID() ] = $price; |
|
| 932 | + $ticket->_add_relation_to($price, 'Price'); |
|
| 933 | + } |
|
| 934 | + // now let's remove any prices that got removed from the ticket |
|
| 935 | + if (! empty($current_prices_on_ticket)) { |
|
| 936 | + $current = array_keys($current_prices_on_ticket); |
|
| 937 | + $updated = array_keys($updated_prices); |
|
| 938 | + $prices_to_remove = array_diff($current, $updated); |
|
| 939 | + if (! empty($prices_to_remove)) { |
|
| 940 | + foreach ($prices_to_remove as $prc_id) { |
|
| 941 | + $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 942 | + $ticket->_remove_relation_to($p, 'Price'); |
|
| 943 | + // delete permanently the price |
|
| 944 | + $p->delete_permanently(); |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + } |
|
| 948 | + return $ticket; |
|
| 949 | + } |
|
| 950 | 950 | |
| 951 | 951 | |
| 952 | - /** |
|
| 953 | - * @param Events_Admin_Page $event_admin_obj |
|
| 954 | - * @return Events_Admin_Page |
|
| 955 | - */ |
|
| 956 | - public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 957 | - { |
|
| 958 | - return $event_admin_obj; |
|
| 959 | - // doing nothing for the moment. |
|
| 960 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 961 | - // (use the set_template_args() method) |
|
| 962 | - /** |
|
| 963 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 964 | - * 1. TKT_is_default_selector (visible) |
|
| 965 | - * 2. TKT_is_default (hidden) |
|
| 966 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 967 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 968 | - * this ticket to be saved as a default. |
|
| 969 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 970 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 971 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 972 | - * the TKT HAS been saved as a default.. |
|
| 973 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 974 | - * On Autosave: |
|
| 975 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 976 | - * then set the TKT_is_default to false. |
|
| 977 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 978 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 979 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 980 | - */ |
|
| 981 | - } |
|
| 952 | + /** |
|
| 953 | + * @param Events_Admin_Page $event_admin_obj |
|
| 954 | + * @return Events_Admin_Page |
|
| 955 | + */ |
|
| 956 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
| 957 | + { |
|
| 958 | + return $event_admin_obj; |
|
| 959 | + // doing nothing for the moment. |
|
| 960 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
| 961 | + // (use the set_template_args() method) |
|
| 962 | + /** |
|
| 963 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
| 964 | + * 1. TKT_is_default_selector (visible) |
|
| 965 | + * 2. TKT_is_default (hidden) |
|
| 966 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
| 967 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
| 968 | + * this ticket to be saved as a default. |
|
| 969 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
| 970 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
| 971 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
| 972 | + * the TKT HAS been saved as a default.. |
|
| 973 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
| 974 | + * On Autosave: |
|
| 975 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
| 976 | + * then set the TKT_is_default to false. |
|
| 977 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
| 978 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
| 979 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
| 980 | + */ |
|
| 981 | + } |
|
| 982 | 982 | |
| 983 | 983 | |
| 984 | - /** |
|
| 985 | - * @throws ReflectionException |
|
| 986 | - * @throws InvalidArgumentException |
|
| 987 | - * @throws InvalidInterfaceException |
|
| 988 | - * @throws InvalidDataTypeException |
|
| 989 | - * @throws DomainException |
|
| 990 | - * @throws EE_Error |
|
| 991 | - */ |
|
| 992 | - public function pricing_metabox() |
|
| 993 | - { |
|
| 994 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 995 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 996 | - // set is_creating_event property. |
|
| 997 | - $EVT_ID = $event->ID(); |
|
| 998 | - $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 999 | - // default main template args |
|
| 1000 | - $main_template_args = array( |
|
| 1001 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1002 | - 'event_editor_event_datetimes_help_tab', |
|
| 1003 | - $this->_adminpage_obj->page_slug, |
|
| 1004 | - $this->_adminpage_obj->get_req_action(), |
|
| 1005 | - false, |
|
| 1006 | - false |
|
| 1007 | - ), |
|
| 1008 | - // todo need to add a filter to the template for the help text |
|
| 1009 | - // in the Events_Admin_Page core file so we can add further help |
|
| 1010 | - 'existing_datetime_ids' => '', |
|
| 1011 | - 'total_dtt_rows' => 1, |
|
| 1012 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1013 | - 'add_new_dtt_info', |
|
| 1014 | - $this->_adminpage_obj->page_slug, |
|
| 1015 | - $this->_adminpage_obj->get_req_action(), |
|
| 1016 | - false, |
|
| 1017 | - false |
|
| 1018 | - ), |
|
| 1019 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1020 | - 'datetime_rows' => '', |
|
| 1021 | - 'show_tickets_container' => '', |
|
| 1022 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1023 | - 'ticket_rows' => '', |
|
| 1024 | - 'existing_ticket_ids' => '', |
|
| 1025 | - 'total_ticket_rows' => 1, |
|
| 1026 | - 'ticket_js_structure' => '', |
|
| 1027 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1028 | - // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1029 | - ); |
|
| 1030 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1031 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1032 | - /** |
|
| 1033 | - * 1. Start with retrieving Datetimes |
|
| 1034 | - * 2. For each datetime get related tickets |
|
| 1035 | - * 3. For each ticket get related prices |
|
| 1036 | - */ |
|
| 1037 | - /** @var EEM_Datetime $datetime_model */ |
|
| 1038 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1039 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1040 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1041 | - /** |
|
| 1042 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1043 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1044 | - */ |
|
| 1045 | - $datetime_row = 1; |
|
| 1046 | - foreach ($datetimes as $datetime) { |
|
| 1047 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1048 | - $datetime->set('DTT_order', $datetime_row); |
|
| 1049 | - $existing_datetime_ids[] = $DTT_ID; |
|
| 1050 | - // tickets attached |
|
| 1051 | - $related_tickets = $datetime->ID() > 0 |
|
| 1052 | - ? $datetime->get_many_related( |
|
| 1053 | - 'Ticket', |
|
| 1054 | - array( |
|
| 1055 | - array( |
|
| 1056 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1057 | - ), |
|
| 1058 | - 'default_where_conditions' => 'none', |
|
| 1059 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1060 | - ) |
|
| 1061 | - ) |
|
| 1062 | - : array(); |
|
| 1063 | - // if there are no related tickets this is likely a new event OR autodraft |
|
| 1064 | - // event so we need to generate the default tickets because datetimes |
|
| 1065 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1066 | - // datetime on the event. |
|
| 1067 | - if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1068 | - /** @var EEM_Ticket $ticket_model */ |
|
| 1069 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1070 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1071 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1072 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1073 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1074 | - $main_default_ticket = reset($related_tickets); |
|
| 1075 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1076 | - foreach ($default_prices as $default_price) { |
|
| 1077 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1078 | - continue; |
|
| 1079 | - } |
|
| 1080 | - $main_default_ticket->cache('Price', $default_price); |
|
| 1081 | - } |
|
| 1082 | - } |
|
| 1083 | - } |
|
| 1084 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1085 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1086 | - // So we're going to temporarily cache some of that information. |
|
| 1087 | - // loop through and setup the ticket rows and make sure the order is set. |
|
| 1088 | - foreach ($related_tickets as $ticket) { |
|
| 1089 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1090 | - $ticket_row = $ticket->get('TKT_row'); |
|
| 1091 | - // we only want unique tickets in our final display!! |
|
| 1092 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1093 | - $existing_ticket_ids[] = $TKT_ID; |
|
| 1094 | - $all_tickets[] = $ticket; |
|
| 1095 | - } |
|
| 1096 | - // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1097 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1098 | - // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1099 | - if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1101 | - ) { |
|
| 1102 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - $datetime_row++; |
|
| 1106 | - } |
|
| 1107 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1108 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1109 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1110 | - // sort $all_tickets by order |
|
| 1111 | - usort( |
|
| 1112 | - $all_tickets, |
|
| 1113 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | - $a_order = (int) $a->get('TKT_order'); |
|
| 1115 | - $b_order = (int) $b->get('TKT_order'); |
|
| 1116 | - if ($a_order === $b_order) { |
|
| 1117 | - return 0; |
|
| 1118 | - } |
|
| 1119 | - return ($a_order < $b_order) ? -1 : 1; |
|
| 1120 | - } |
|
| 1121 | - ); |
|
| 1122 | - // k NOW we have all the data we need for setting up the dtt rows |
|
| 1123 | - // and ticket rows so we start our dtt loop again. |
|
| 1124 | - $datetime_row = 1; |
|
| 1125 | - foreach ($datetimes as $datetime) { |
|
| 1126 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1127 | - $datetime_row, |
|
| 1128 | - $datetime, |
|
| 1129 | - $datetime_tickets, |
|
| 1130 | - $all_tickets, |
|
| 1131 | - false, |
|
| 1132 | - $datetimes |
|
| 1133 | - ); |
|
| 1134 | - $datetime_row++; |
|
| 1135 | - } |
|
| 1136 | - // then loop through all tickets for the ticket rows. |
|
| 1137 | - $ticket_row = 1; |
|
| 1138 | - foreach ($all_tickets as $ticket) { |
|
| 1139 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1140 | - $ticket_row, |
|
| 1141 | - $ticket, |
|
| 1142 | - $ticket_datetimes, |
|
| 1143 | - $datetimes, |
|
| 1144 | - false, |
|
| 1145 | - $all_tickets |
|
| 1146 | - ); |
|
| 1147 | - $ticket_row++; |
|
| 1148 | - } |
|
| 1149 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1150 | - EEH_Template::display_template( |
|
| 1151 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1152 | - $main_template_args |
|
| 1153 | - ); |
|
| 1154 | - } |
|
| 984 | + /** |
|
| 985 | + * @throws ReflectionException |
|
| 986 | + * @throws InvalidArgumentException |
|
| 987 | + * @throws InvalidInterfaceException |
|
| 988 | + * @throws InvalidDataTypeException |
|
| 989 | + * @throws DomainException |
|
| 990 | + * @throws EE_Error |
|
| 991 | + */ |
|
| 992 | + public function pricing_metabox() |
|
| 993 | + { |
|
| 994 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
| 995 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
| 996 | + // set is_creating_event property. |
|
| 997 | + $EVT_ID = $event->ID(); |
|
| 998 | + $this->_is_creating_event = empty($this->_req_data['post']); |
|
| 999 | + // default main template args |
|
| 1000 | + $main_template_args = array( |
|
| 1001 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
| 1002 | + 'event_editor_event_datetimes_help_tab', |
|
| 1003 | + $this->_adminpage_obj->page_slug, |
|
| 1004 | + $this->_adminpage_obj->get_req_action(), |
|
| 1005 | + false, |
|
| 1006 | + false |
|
| 1007 | + ), |
|
| 1008 | + // todo need to add a filter to the template for the help text |
|
| 1009 | + // in the Events_Admin_Page core file so we can add further help |
|
| 1010 | + 'existing_datetime_ids' => '', |
|
| 1011 | + 'total_dtt_rows' => 1, |
|
| 1012 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
| 1013 | + 'add_new_dtt_info', |
|
| 1014 | + $this->_adminpage_obj->page_slug, |
|
| 1015 | + $this->_adminpage_obj->get_req_action(), |
|
| 1016 | + false, |
|
| 1017 | + false |
|
| 1018 | + ), |
|
| 1019 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1020 | + 'datetime_rows' => '', |
|
| 1021 | + 'show_tickets_container' => '', |
|
| 1022 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
| 1023 | + 'ticket_rows' => '', |
|
| 1024 | + 'existing_ticket_ids' => '', |
|
| 1025 | + 'total_ticket_rows' => 1, |
|
| 1026 | + 'ticket_js_structure' => '', |
|
| 1027 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
| 1028 | + // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
| 1029 | + ); |
|
| 1030 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
| 1031 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1032 | + /** |
|
| 1033 | + * 1. Start with retrieving Datetimes |
|
| 1034 | + * 2. For each datetime get related tickets |
|
| 1035 | + * 3. For each ticket get related prices |
|
| 1036 | + */ |
|
| 1037 | + /** @var EEM_Datetime $datetime_model */ |
|
| 1038 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
| 1039 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
| 1040 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
| 1041 | + /** |
|
| 1042 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
| 1043 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
| 1044 | + */ |
|
| 1045 | + $datetime_row = 1; |
|
| 1046 | + foreach ($datetimes as $datetime) { |
|
| 1047 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
| 1048 | + $datetime->set('DTT_order', $datetime_row); |
|
| 1049 | + $existing_datetime_ids[] = $DTT_ID; |
|
| 1050 | + // tickets attached |
|
| 1051 | + $related_tickets = $datetime->ID() > 0 |
|
| 1052 | + ? $datetime->get_many_related( |
|
| 1053 | + 'Ticket', |
|
| 1054 | + array( |
|
| 1055 | + array( |
|
| 1056 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
| 1057 | + ), |
|
| 1058 | + 'default_where_conditions' => 'none', |
|
| 1059 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
| 1060 | + ) |
|
| 1061 | + ) |
|
| 1062 | + : array(); |
|
| 1063 | + // if there are no related tickets this is likely a new event OR autodraft |
|
| 1064 | + // event so we need to generate the default tickets because datetimes |
|
| 1065 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
| 1066 | + // datetime on the event. |
|
| 1067 | + if (empty($related_tickets) && count($datetimes) < 2) { |
|
| 1068 | + /** @var EEM_Ticket $ticket_model */ |
|
| 1069 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
| 1070 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
| 1071 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
| 1072 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
| 1073 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
| 1074 | + $main_default_ticket = reset($related_tickets); |
|
| 1075 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
| 1076 | + foreach ($default_prices as $default_price) { |
|
| 1077 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
| 1078 | + continue; |
|
| 1079 | + } |
|
| 1080 | + $main_default_ticket->cache('Price', $default_price); |
|
| 1081 | + } |
|
| 1082 | + } |
|
| 1083 | + } |
|
| 1084 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
| 1085 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
| 1086 | + // So we're going to temporarily cache some of that information. |
|
| 1087 | + // loop through and setup the ticket rows and make sure the order is set. |
|
| 1088 | + foreach ($related_tickets as $ticket) { |
|
| 1089 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
| 1090 | + $ticket_row = $ticket->get('TKT_row'); |
|
| 1091 | + // we only want unique tickets in our final display!! |
|
| 1092 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1093 | + $existing_ticket_ids[] = $TKT_ID; |
|
| 1094 | + $all_tickets[] = $ticket; |
|
| 1095 | + } |
|
| 1096 | + // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
| 1097 | + $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1098 | + // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
| 1099 | + if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | + || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1101 | + ) { |
|
| 1102 | + $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + $datetime_row++; |
|
| 1106 | + } |
|
| 1107 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
| 1108 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
| 1109 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
| 1110 | + // sort $all_tickets by order |
|
| 1111 | + usort( |
|
| 1112 | + $all_tickets, |
|
| 1113 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | + $a_order = (int) $a->get('TKT_order'); |
|
| 1115 | + $b_order = (int) $b->get('TKT_order'); |
|
| 1116 | + if ($a_order === $b_order) { |
|
| 1117 | + return 0; |
|
| 1118 | + } |
|
| 1119 | + return ($a_order < $b_order) ? -1 : 1; |
|
| 1120 | + } |
|
| 1121 | + ); |
|
| 1122 | + // k NOW we have all the data we need for setting up the dtt rows |
|
| 1123 | + // and ticket rows so we start our dtt loop again. |
|
| 1124 | + $datetime_row = 1; |
|
| 1125 | + foreach ($datetimes as $datetime) { |
|
| 1126 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
| 1127 | + $datetime_row, |
|
| 1128 | + $datetime, |
|
| 1129 | + $datetime_tickets, |
|
| 1130 | + $all_tickets, |
|
| 1131 | + false, |
|
| 1132 | + $datetimes |
|
| 1133 | + ); |
|
| 1134 | + $datetime_row++; |
|
| 1135 | + } |
|
| 1136 | + // then loop through all tickets for the ticket rows. |
|
| 1137 | + $ticket_row = 1; |
|
| 1138 | + foreach ($all_tickets as $ticket) { |
|
| 1139 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
| 1140 | + $ticket_row, |
|
| 1141 | + $ticket, |
|
| 1142 | + $ticket_datetimes, |
|
| 1143 | + $datetimes, |
|
| 1144 | + false, |
|
| 1145 | + $all_tickets |
|
| 1146 | + ); |
|
| 1147 | + $ticket_row++; |
|
| 1148 | + } |
|
| 1149 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
| 1150 | + EEH_Template::display_template( |
|
| 1151 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1152 | + $main_template_args |
|
| 1153 | + ); |
|
| 1154 | + } |
|
| 1155 | 1155 | |
| 1156 | 1156 | |
| 1157 | - /** |
|
| 1158 | - * @param int $datetime_row |
|
| 1159 | - * @param EE_Datetime $datetime |
|
| 1160 | - * @param array $datetime_tickets |
|
| 1161 | - * @param array $all_tickets |
|
| 1162 | - * @param bool $default |
|
| 1163 | - * @param array $all_datetimes |
|
| 1164 | - * @return mixed |
|
| 1165 | - * @throws DomainException |
|
| 1166 | - * @throws EE_Error |
|
| 1167 | - */ |
|
| 1168 | - protected function _get_datetime_row( |
|
| 1169 | - $datetime_row, |
|
| 1170 | - EE_Datetime $datetime, |
|
| 1171 | - $datetime_tickets = array(), |
|
| 1172 | - $all_tickets = array(), |
|
| 1173 | - $default = false, |
|
| 1174 | - $all_datetimes = array() |
|
| 1175 | - ) { |
|
| 1176 | - $dtt_display_template_args = array( |
|
| 1177 | - 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1178 | - $datetime_row, |
|
| 1179 | - $datetime, |
|
| 1180 | - $default, |
|
| 1181 | - $all_datetimes |
|
| 1182 | - ), |
|
| 1183 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1184 | - $datetime_row, |
|
| 1185 | - $datetime, |
|
| 1186 | - $datetime_tickets, |
|
| 1187 | - $all_tickets, |
|
| 1188 | - $default |
|
| 1189 | - ), |
|
| 1190 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1191 | - ); |
|
| 1192 | - return EEH_Template::display_template( |
|
| 1193 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | - $dtt_display_template_args, |
|
| 1195 | - true |
|
| 1196 | - ); |
|
| 1197 | - } |
|
| 1157 | + /** |
|
| 1158 | + * @param int $datetime_row |
|
| 1159 | + * @param EE_Datetime $datetime |
|
| 1160 | + * @param array $datetime_tickets |
|
| 1161 | + * @param array $all_tickets |
|
| 1162 | + * @param bool $default |
|
| 1163 | + * @param array $all_datetimes |
|
| 1164 | + * @return mixed |
|
| 1165 | + * @throws DomainException |
|
| 1166 | + * @throws EE_Error |
|
| 1167 | + */ |
|
| 1168 | + protected function _get_datetime_row( |
|
| 1169 | + $datetime_row, |
|
| 1170 | + EE_Datetime $datetime, |
|
| 1171 | + $datetime_tickets = array(), |
|
| 1172 | + $all_tickets = array(), |
|
| 1173 | + $default = false, |
|
| 1174 | + $all_datetimes = array() |
|
| 1175 | + ) { |
|
| 1176 | + $dtt_display_template_args = array( |
|
| 1177 | + 'dtt_edit_row' => $this->_get_dtt_edit_row( |
|
| 1178 | + $datetime_row, |
|
| 1179 | + $datetime, |
|
| 1180 | + $default, |
|
| 1181 | + $all_datetimes |
|
| 1182 | + ), |
|
| 1183 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
| 1184 | + $datetime_row, |
|
| 1185 | + $datetime, |
|
| 1186 | + $datetime_tickets, |
|
| 1187 | + $all_tickets, |
|
| 1188 | + $default |
|
| 1189 | + ), |
|
| 1190 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1191 | + ); |
|
| 1192 | + return EEH_Template::display_template( |
|
| 1193 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | + $dtt_display_template_args, |
|
| 1195 | + true |
|
| 1196 | + ); |
|
| 1197 | + } |
|
| 1198 | 1198 | |
| 1199 | 1199 | |
| 1200 | - /** |
|
| 1201 | - * This method is used to generate a dtt fields edit row. |
|
| 1202 | - * The same row is used to generate a row with valid DTT objects |
|
| 1203 | - * and the default row that is used as the skeleton by the js. |
|
| 1204 | - * |
|
| 1205 | - * @param int $datetime_row The row number for the row being generated. |
|
| 1206 | - * @param EE_Datetime $datetime |
|
| 1207 | - * @param bool $default Whether a default row is being generated or not. |
|
| 1208 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1209 | - * @return string |
|
| 1210 | - * @throws DomainException |
|
| 1211 | - * @throws EE_Error |
|
| 1212 | - */ |
|
| 1213 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1214 | - { |
|
| 1215 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1216 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1217 | - $template_args = array( |
|
| 1218 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1219 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1220 | - 'edit_dtt_expanded' => '', |
|
| 1221 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1222 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1223 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1224 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1225 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1226 | - 'DTT_reg_limit' => $default |
|
| 1227 | - ? '' |
|
| 1228 | - : $datetime->get_pretty( |
|
| 1229 | - 'DTT_reg_limit', |
|
| 1230 | - 'input' |
|
| 1231 | - ), |
|
| 1232 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1233 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1234 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1235 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1236 | - ? '' |
|
| 1237 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1238 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | - ? 'ee-lock-icon' |
|
| 1240 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1241 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1242 | - ? '' |
|
| 1243 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1244 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1245 | - REG_ADMIN_URL |
|
| 1246 | - ), |
|
| 1247 | - ); |
|
| 1248 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1249 | - ? ' style="display:none"' |
|
| 1250 | - : ''; |
|
| 1251 | - // allow filtering of template args at this point. |
|
| 1252 | - $template_args = apply_filters( |
|
| 1253 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1254 | - $template_args, |
|
| 1255 | - $datetime_row, |
|
| 1256 | - $datetime, |
|
| 1257 | - $default, |
|
| 1258 | - $all_datetimes, |
|
| 1259 | - $this->_is_creating_event |
|
| 1260 | - ); |
|
| 1261 | - return EEH_Template::display_template( |
|
| 1262 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | - $template_args, |
|
| 1264 | - true |
|
| 1265 | - ); |
|
| 1266 | - } |
|
| 1200 | + /** |
|
| 1201 | + * This method is used to generate a dtt fields edit row. |
|
| 1202 | + * The same row is used to generate a row with valid DTT objects |
|
| 1203 | + * and the default row that is used as the skeleton by the js. |
|
| 1204 | + * |
|
| 1205 | + * @param int $datetime_row The row number for the row being generated. |
|
| 1206 | + * @param EE_Datetime $datetime |
|
| 1207 | + * @param bool $default Whether a default row is being generated or not. |
|
| 1208 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
| 1209 | + * @return string |
|
| 1210 | + * @throws DomainException |
|
| 1211 | + * @throws EE_Error |
|
| 1212 | + */ |
|
| 1213 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
| 1214 | + { |
|
| 1215 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
| 1216 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
| 1217 | + $template_args = array( |
|
| 1218 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1219 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1220 | + 'edit_dtt_expanded' => '', |
|
| 1221 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1222 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
| 1223 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1224 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
| 1225 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
| 1226 | + 'DTT_reg_limit' => $default |
|
| 1227 | + ? '' |
|
| 1228 | + : $datetime->get_pretty( |
|
| 1229 | + 'DTT_reg_limit', |
|
| 1230 | + 'input' |
|
| 1231 | + ), |
|
| 1232 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1233 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
| 1234 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
| 1235 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1236 | + ? '' |
|
| 1237 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1238 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
| 1239 | + ? 'ee-lock-icon' |
|
| 1240 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1241 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
| 1242 | + ? '' |
|
| 1243 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
| 1244 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
| 1245 | + REG_ADMIN_URL |
|
| 1246 | + ), |
|
| 1247 | + ); |
|
| 1248 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1249 | + ? ' style="display:none"' |
|
| 1250 | + : ''; |
|
| 1251 | + // allow filtering of template args at this point. |
|
| 1252 | + $template_args = apply_filters( |
|
| 1253 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
| 1254 | + $template_args, |
|
| 1255 | + $datetime_row, |
|
| 1256 | + $datetime, |
|
| 1257 | + $default, |
|
| 1258 | + $all_datetimes, |
|
| 1259 | + $this->_is_creating_event |
|
| 1260 | + ); |
|
| 1261 | + return EEH_Template::display_template( |
|
| 1262 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | + $template_args, |
|
| 1264 | + true |
|
| 1265 | + ); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | 1268 | |
| 1269 | - /** |
|
| 1270 | - * @param int $datetime_row |
|
| 1271 | - * @param EE_Datetime $datetime |
|
| 1272 | - * @param array $datetime_tickets |
|
| 1273 | - * @param array $all_tickets |
|
| 1274 | - * @param bool $default |
|
| 1275 | - * @return mixed |
|
| 1276 | - * @throws DomainException |
|
| 1277 | - * @throws EE_Error |
|
| 1278 | - */ |
|
| 1279 | - protected function _get_dtt_attached_tickets_row( |
|
| 1280 | - $datetime_row, |
|
| 1281 | - $datetime, |
|
| 1282 | - $datetime_tickets = array(), |
|
| 1283 | - $all_tickets = array(), |
|
| 1284 | - $default = false |
|
| 1285 | - ) { |
|
| 1286 | - $template_args = array( |
|
| 1287 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1288 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1289 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1290 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1291 | - 'show_tickets_row' => ' style="display:none;"', |
|
| 1292 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1293 | - 'add_new_ticket_via_datetime', |
|
| 1294 | - $this->_adminpage_obj->page_slug, |
|
| 1295 | - $this->_adminpage_obj->get_req_action(), |
|
| 1296 | - false, |
|
| 1297 | - false |
|
| 1298 | - ), |
|
| 1299 | - // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1300 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1301 | - ); |
|
| 1302 | - // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1303 | - if (! $default) { |
|
| 1304 | - $ticket_row = 1; |
|
| 1305 | - foreach ($all_tickets as $ticket) { |
|
| 1306 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1307 | - $datetime_row, |
|
| 1308 | - $ticket_row, |
|
| 1309 | - $datetime, |
|
| 1310 | - $ticket, |
|
| 1311 | - $datetime_tickets, |
|
| 1312 | - $default |
|
| 1313 | - ); |
|
| 1314 | - $ticket_row++; |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - // filter template args at this point |
|
| 1318 | - $template_args = apply_filters( |
|
| 1319 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1320 | - $template_args, |
|
| 1321 | - $datetime_row, |
|
| 1322 | - $datetime, |
|
| 1323 | - $datetime_tickets, |
|
| 1324 | - $all_tickets, |
|
| 1325 | - $default, |
|
| 1326 | - $this->_is_creating_event |
|
| 1327 | - ); |
|
| 1328 | - return EEH_Template::display_template( |
|
| 1329 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | - $template_args, |
|
| 1331 | - true |
|
| 1332 | - ); |
|
| 1333 | - } |
|
| 1269 | + /** |
|
| 1270 | + * @param int $datetime_row |
|
| 1271 | + * @param EE_Datetime $datetime |
|
| 1272 | + * @param array $datetime_tickets |
|
| 1273 | + * @param array $all_tickets |
|
| 1274 | + * @param bool $default |
|
| 1275 | + * @return mixed |
|
| 1276 | + * @throws DomainException |
|
| 1277 | + * @throws EE_Error |
|
| 1278 | + */ |
|
| 1279 | + protected function _get_dtt_attached_tickets_row( |
|
| 1280 | + $datetime_row, |
|
| 1281 | + $datetime, |
|
| 1282 | + $datetime_tickets = array(), |
|
| 1283 | + $all_tickets = array(), |
|
| 1284 | + $default = false |
|
| 1285 | + ) { |
|
| 1286 | + $template_args = array( |
|
| 1287 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
| 1288 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
| 1289 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
| 1290 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1291 | + 'show_tickets_row' => ' style="display:none;"', |
|
| 1292 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
| 1293 | + 'add_new_ticket_via_datetime', |
|
| 1294 | + $this->_adminpage_obj->page_slug, |
|
| 1295 | + $this->_adminpage_obj->get_req_action(), |
|
| 1296 | + false, |
|
| 1297 | + false |
|
| 1298 | + ), |
|
| 1299 | + // todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
| 1300 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
| 1301 | + ); |
|
| 1302 | + // need to setup the list items (but only if this isn't a default skeleton setup) |
|
| 1303 | + if (! $default) { |
|
| 1304 | + $ticket_row = 1; |
|
| 1305 | + foreach ($all_tickets as $ticket) { |
|
| 1306 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 1307 | + $datetime_row, |
|
| 1308 | + $ticket_row, |
|
| 1309 | + $datetime, |
|
| 1310 | + $ticket, |
|
| 1311 | + $datetime_tickets, |
|
| 1312 | + $default |
|
| 1313 | + ); |
|
| 1314 | + $ticket_row++; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + // filter template args at this point |
|
| 1318 | + $template_args = apply_filters( |
|
| 1319 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
| 1320 | + $template_args, |
|
| 1321 | + $datetime_row, |
|
| 1322 | + $datetime, |
|
| 1323 | + $datetime_tickets, |
|
| 1324 | + $all_tickets, |
|
| 1325 | + $default, |
|
| 1326 | + $this->_is_creating_event |
|
| 1327 | + ); |
|
| 1328 | + return EEH_Template::display_template( |
|
| 1329 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | + $template_args, |
|
| 1331 | + true |
|
| 1332 | + ); |
|
| 1333 | + } |
|
| 1334 | 1334 | |
| 1335 | 1335 | |
| 1336 | - /** |
|
| 1337 | - * @param int $datetime_row |
|
| 1338 | - * @param int $ticket_row |
|
| 1339 | - * @param EE_Datetime $datetime |
|
| 1340 | - * @param EE_Ticket $ticket |
|
| 1341 | - * @param array $datetime_tickets |
|
| 1342 | - * @param bool $default |
|
| 1343 | - * @return mixed |
|
| 1344 | - * @throws DomainException |
|
| 1345 | - * @throws EE_Error |
|
| 1346 | - */ |
|
| 1347 | - protected function _get_datetime_tickets_list_item( |
|
| 1348 | - $datetime_row, |
|
| 1349 | - $ticket_row, |
|
| 1350 | - $datetime, |
|
| 1351 | - $ticket, |
|
| 1352 | - $datetime_tickets = array(), |
|
| 1353 | - $default = false |
|
| 1354 | - ) { |
|
| 1355 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1357 | - : array(); |
|
| 1358 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1359 | - $no_ticket = $default && empty($ticket); |
|
| 1360 | - $template_args = array( |
|
| 1361 | - 'dtt_row' => $default |
|
| 1362 | - ? 'DTTNUM' |
|
| 1363 | - : $datetime_row, |
|
| 1364 | - 'tkt_row' => $no_ticket |
|
| 1365 | - ? 'TICKETNUM' |
|
| 1366 | - : $ticket_row, |
|
| 1367 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1368 | - ? ' checked="checked"' |
|
| 1369 | - : '', |
|
| 1370 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | - ? ' ticket-selected' |
|
| 1372 | - : '', |
|
| 1373 | - 'TKT_name' => $no_ticket |
|
| 1374 | - ? 'TKTNAME' |
|
| 1375 | - : $ticket->get('TKT_name'), |
|
| 1376 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1377 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1379 | - ); |
|
| 1380 | - // filter template args |
|
| 1381 | - $template_args = apply_filters( |
|
| 1382 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1383 | - $template_args, |
|
| 1384 | - $datetime_row, |
|
| 1385 | - $ticket_row, |
|
| 1386 | - $datetime, |
|
| 1387 | - $ticket, |
|
| 1388 | - $datetime_tickets, |
|
| 1389 | - $default, |
|
| 1390 | - $this->_is_creating_event |
|
| 1391 | - ); |
|
| 1392 | - return EEH_Template::display_template( |
|
| 1393 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | - $template_args, |
|
| 1395 | - true |
|
| 1396 | - ); |
|
| 1397 | - } |
|
| 1336 | + /** |
|
| 1337 | + * @param int $datetime_row |
|
| 1338 | + * @param int $ticket_row |
|
| 1339 | + * @param EE_Datetime $datetime |
|
| 1340 | + * @param EE_Ticket $ticket |
|
| 1341 | + * @param array $datetime_tickets |
|
| 1342 | + * @param bool $default |
|
| 1343 | + * @return mixed |
|
| 1344 | + * @throws DomainException |
|
| 1345 | + * @throws EE_Error |
|
| 1346 | + */ |
|
| 1347 | + protected function _get_datetime_tickets_list_item( |
|
| 1348 | + $datetime_row, |
|
| 1349 | + $ticket_row, |
|
| 1350 | + $datetime, |
|
| 1351 | + $ticket, |
|
| 1352 | + $datetime_tickets = array(), |
|
| 1353 | + $default = false |
|
| 1354 | + ) { |
|
| 1355 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | + ? $datetime_tickets[ $datetime->ID() ] |
|
| 1357 | + : array(); |
|
| 1358 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
| 1359 | + $no_ticket = $default && empty($ticket); |
|
| 1360 | + $template_args = array( |
|
| 1361 | + 'dtt_row' => $default |
|
| 1362 | + ? 'DTTNUM' |
|
| 1363 | + : $datetime_row, |
|
| 1364 | + 'tkt_row' => $no_ticket |
|
| 1365 | + ? 'TICKETNUM' |
|
| 1366 | + : $ticket_row, |
|
| 1367 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
| 1368 | + ? ' checked="checked"' |
|
| 1369 | + : '', |
|
| 1370 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
| 1371 | + ? ' ticket-selected' |
|
| 1372 | + : '', |
|
| 1373 | + 'TKT_name' => $no_ticket |
|
| 1374 | + ? 'TKTNAME' |
|
| 1375 | + : $ticket->get('TKT_name'), |
|
| 1376 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
| 1377 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1379 | + ); |
|
| 1380 | + // filter template args |
|
| 1381 | + $template_args = apply_filters( |
|
| 1382 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
| 1383 | + $template_args, |
|
| 1384 | + $datetime_row, |
|
| 1385 | + $ticket_row, |
|
| 1386 | + $datetime, |
|
| 1387 | + $ticket, |
|
| 1388 | + $datetime_tickets, |
|
| 1389 | + $default, |
|
| 1390 | + $this->_is_creating_event |
|
| 1391 | + ); |
|
| 1392 | + return EEH_Template::display_template( |
|
| 1393 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | + $template_args, |
|
| 1395 | + true |
|
| 1396 | + ); |
|
| 1397 | + } |
|
| 1398 | 1398 | |
| 1399 | 1399 | |
| 1400 | - /** |
|
| 1401 | - * This generates the ticket row for tickets. |
|
| 1402 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1403 | - * (when default === true) |
|
| 1404 | - * |
|
| 1405 | - * @param int $ticket_row Represents the row number being generated. |
|
| 1406 | - * @param $ticket |
|
| 1407 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1408 | - * or empty for default |
|
| 1409 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1410 | - * @param bool $default Whether default row being generated or not. |
|
| 1411 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1412 | - * (or empty in the case of defaults) |
|
| 1413 | - * @return mixed |
|
| 1414 | - * @throws InvalidArgumentException |
|
| 1415 | - * @throws InvalidInterfaceException |
|
| 1416 | - * @throws InvalidDataTypeException |
|
| 1417 | - * @throws DomainException |
|
| 1418 | - * @throws EE_Error |
|
| 1419 | - * @throws ReflectionException |
|
| 1420 | - */ |
|
| 1421 | - protected function _get_ticket_row( |
|
| 1422 | - $ticket_row, |
|
| 1423 | - $ticket, |
|
| 1424 | - $ticket_datetimes, |
|
| 1425 | - $all_datetimes, |
|
| 1426 | - $default = false, |
|
| 1427 | - $all_tickets = array() |
|
| 1428 | - ) { |
|
| 1429 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1430 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1431 | - $prices = ! empty($ticket) && ! $default |
|
| 1432 | - ? $ticket->get_many_related( |
|
| 1433 | - 'Price', |
|
| 1434 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1435 | - ) |
|
| 1436 | - : array(); |
|
| 1437 | - // if there is only one price (which would be the base price) |
|
| 1438 | - // or NO prices and this ticket is a default ticket, |
|
| 1439 | - // let's just make sure there are no cached default prices on the object. |
|
| 1440 | - // This is done by not including any query_params. |
|
| 1441 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1442 | - $prices = $ticket->prices(); |
|
| 1443 | - } |
|
| 1444 | - // check if we're dealing with a default ticket in which case |
|
| 1445 | - // we don't want any starting_ticket_datetime_row values set |
|
| 1446 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1447 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1448 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1449 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1451 | - : array(); |
|
| 1452 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1453 | - $base_price = $default ? null : $ticket->base_price(); |
|
| 1454 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1455 | - // breaking out complicated condition for ticket_status |
|
| 1456 | - if ($default) { |
|
| 1457 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1458 | - } else { |
|
| 1459 | - $ticket_status_class = $ticket->is_default() |
|
| 1460 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1462 | - } |
|
| 1463 | - // breaking out complicated condition for TKT_taxable |
|
| 1464 | - if ($default) { |
|
| 1465 | - $TKT_taxable = ''; |
|
| 1466 | - } else { |
|
| 1467 | - $TKT_taxable = $ticket->taxable() |
|
| 1468 | - ? ' checked="checked"' |
|
| 1469 | - : ''; |
|
| 1470 | - } |
|
| 1471 | - if ($default) { |
|
| 1472 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1473 | - } elseif ($ticket->is_default()) { |
|
| 1474 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1475 | - } else { |
|
| 1476 | - $TKT_status = $ticket->ticket_status(true); |
|
| 1477 | - } |
|
| 1478 | - if ($default) { |
|
| 1479 | - $TKT_min = ''; |
|
| 1480 | - } else { |
|
| 1481 | - $TKT_min = $ticket->min(); |
|
| 1482 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1483 | - $TKT_min = ''; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - $template_args = array( |
|
| 1487 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1488 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1489 | - // on initial page load this will always be the correct order. |
|
| 1490 | - 'tkt_status_class' => $ticket_status_class, |
|
| 1491 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1492 | - 'edit_tkt_expanded' => '', |
|
| 1493 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1494 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1495 | - 'TKT_start_date' => $default |
|
| 1496 | - ? '' |
|
| 1497 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1498 | - 'TKT_end_date' => $default |
|
| 1499 | - ? '' |
|
| 1500 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1501 | - 'TKT_status' => $TKT_status, |
|
| 1502 | - 'TKT_price' => $default |
|
| 1503 | - ? '' |
|
| 1504 | - : EEH_Template::format_currency( |
|
| 1505 | - $ticket->get_ticket_total_with_taxes(), |
|
| 1506 | - false, |
|
| 1507 | - false |
|
| 1508 | - ), |
|
| 1509 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1510 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1511 | - 'TKT_qty' => $default |
|
| 1512 | - ? '' |
|
| 1513 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1514 | - 'TKT_qty_for_input' => $default |
|
| 1515 | - ? '' |
|
| 1516 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1517 | - 'TKT_uses' => $default |
|
| 1518 | - ? '' |
|
| 1519 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1520 | - 'TKT_min' => $TKT_min, |
|
| 1521 | - 'TKT_max' => $default |
|
| 1522 | - ? '' |
|
| 1523 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1524 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1525 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1526 | - 'TKT_registrations' => $default |
|
| 1527 | - ? 0 |
|
| 1528 | - : $ticket->count_registrations( |
|
| 1529 | - array( |
|
| 1530 | - array( |
|
| 1531 | - 'STS_ID' => array( |
|
| 1532 | - '!=', |
|
| 1533 | - EEM_Registration::status_id_incomplete, |
|
| 1534 | - ), |
|
| 1535 | - ), |
|
| 1536 | - ) |
|
| 1537 | - ), |
|
| 1538 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1539 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1540 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1541 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1542 | - 'TKT_is_default_selector' => '', |
|
| 1543 | - 'ticket_price_rows' => '', |
|
| 1544 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1545 | - ? '' |
|
| 1546 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1547 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1548 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1549 | - ? '' |
|
| 1550 | - : ' style="display:none;"', |
|
| 1551 | - 'show_price_mod_button' => count($prices) > 1 |
|
| 1552 | - || ($default && $count_price_mods > 0) |
|
| 1553 | - || (! $default && $ticket->deleted()) |
|
| 1554 | - ? ' style="display:none;"' |
|
| 1555 | - : '', |
|
| 1556 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1557 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1558 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1559 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1560 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1561 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1562 | - 'TKT_taxable' => $TKT_taxable, |
|
| 1563 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1564 | - ? '' |
|
| 1565 | - : ' style="display:none"', |
|
| 1566 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1567 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1568 | - $ticket_subtotal, |
|
| 1569 | - false, |
|
| 1570 | - false |
|
| 1571 | - ), |
|
| 1572 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1573 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1574 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1575 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1576 | - ? ' ticket-archived' |
|
| 1577 | - : '', |
|
| 1578 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1579 | - && $ticket->deleted() |
|
| 1580 | - && ! $ticket->is_permanently_deleteable() |
|
| 1581 | - ? 'ee-lock-icon ' |
|
| 1582 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1583 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1584 | - ? '' |
|
| 1585 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1586 | - ); |
|
| 1587 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1588 | - ? ' style="display:none"' |
|
| 1589 | - : ''; |
|
| 1590 | - // handle rows that should NOT be empty |
|
| 1591 | - if (empty($template_args['TKT_start_date'])) { |
|
| 1592 | - // if empty then the start date will be now. |
|
| 1593 | - $template_args['TKT_start_date'] = date( |
|
| 1594 | - $this->_date_time_format, |
|
| 1595 | - current_time('timestamp') |
|
| 1596 | - ); |
|
| 1597 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1598 | - } |
|
| 1599 | - if (empty($template_args['TKT_end_date'])) { |
|
| 1600 | - // get the earliest datetime (if present); |
|
| 1601 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1602 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1603 | - 'Datetime', |
|
| 1604 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1605 | - ) |
|
| 1606 | - : null; |
|
| 1607 | - if (! empty($earliest_dtt)) { |
|
| 1608 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1609 | - 'DTT_EVT_start', |
|
| 1610 | - $this->_date_time_format |
|
| 1611 | - ); |
|
| 1612 | - } else { |
|
| 1613 | - // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1614 | - $template_args['TKT_end_date'] = date( |
|
| 1615 | - $this->_date_time_format, |
|
| 1616 | - mktime( |
|
| 1617 | - 24, |
|
| 1618 | - 0, |
|
| 1619 | - 0, |
|
| 1620 | - date('m'), |
|
| 1621 | - date('d') + 29, |
|
| 1622 | - date('Y') |
|
| 1623 | - ) |
|
| 1624 | - ); |
|
| 1625 | - } |
|
| 1626 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1627 | - } |
|
| 1628 | - // generate ticket_datetime items |
|
| 1629 | - if (! $default) { |
|
| 1630 | - $datetime_row = 1; |
|
| 1631 | - foreach ($all_datetimes as $datetime) { |
|
| 1632 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1633 | - $datetime_row, |
|
| 1634 | - $ticket_row, |
|
| 1635 | - $datetime, |
|
| 1636 | - $ticket, |
|
| 1637 | - $ticket_datetimes, |
|
| 1638 | - $default |
|
| 1639 | - ); |
|
| 1640 | - $datetime_row++; |
|
| 1641 | - } |
|
| 1642 | - } |
|
| 1643 | - $price_row = 1; |
|
| 1644 | - foreach ($prices as $price) { |
|
| 1645 | - if (! $price instanceof EE_Price) { |
|
| 1646 | - continue; |
|
| 1647 | - } |
|
| 1648 | - if ($price->is_base_price()) { |
|
| 1649 | - $price_row++; |
|
| 1650 | - continue; |
|
| 1651 | - } |
|
| 1652 | - $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1653 | - $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
| 1654 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1655 | - $ticket_row, |
|
| 1656 | - $price_row, |
|
| 1657 | - $price, |
|
| 1658 | - $default, |
|
| 1659 | - $ticket, |
|
| 1660 | - $show_trash, |
|
| 1661 | - $show_create |
|
| 1662 | - ); |
|
| 1663 | - $price_row++; |
|
| 1664 | - } |
|
| 1665 | - // filter $template_args |
|
| 1666 | - $template_args = apply_filters( |
|
| 1667 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1668 | - $template_args, |
|
| 1669 | - $ticket_row, |
|
| 1670 | - $ticket, |
|
| 1671 | - $ticket_datetimes, |
|
| 1672 | - $all_datetimes, |
|
| 1673 | - $default, |
|
| 1674 | - $all_tickets, |
|
| 1675 | - $this->_is_creating_event |
|
| 1676 | - ); |
|
| 1677 | - return EEH_Template::display_template( |
|
| 1678 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | - $template_args, |
|
| 1680 | - true |
|
| 1681 | - ); |
|
| 1682 | - } |
|
| 1400 | + /** |
|
| 1401 | + * This generates the ticket row for tickets. |
|
| 1402 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
| 1403 | + * (when default === true) |
|
| 1404 | + * |
|
| 1405 | + * @param int $ticket_row Represents the row number being generated. |
|
| 1406 | + * @param $ticket |
|
| 1407 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
| 1408 | + * or empty for default |
|
| 1409 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
| 1410 | + * @param bool $default Whether default row being generated or not. |
|
| 1411 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
| 1412 | + * (or empty in the case of defaults) |
|
| 1413 | + * @return mixed |
|
| 1414 | + * @throws InvalidArgumentException |
|
| 1415 | + * @throws InvalidInterfaceException |
|
| 1416 | + * @throws InvalidDataTypeException |
|
| 1417 | + * @throws DomainException |
|
| 1418 | + * @throws EE_Error |
|
| 1419 | + * @throws ReflectionException |
|
| 1420 | + */ |
|
| 1421 | + protected function _get_ticket_row( |
|
| 1422 | + $ticket_row, |
|
| 1423 | + $ticket, |
|
| 1424 | + $ticket_datetimes, |
|
| 1425 | + $all_datetimes, |
|
| 1426 | + $default = false, |
|
| 1427 | + $all_tickets = array() |
|
| 1428 | + ) { |
|
| 1429 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
| 1430 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
| 1431 | + $prices = ! empty($ticket) && ! $default |
|
| 1432 | + ? $ticket->get_many_related( |
|
| 1433 | + 'Price', |
|
| 1434 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC')) |
|
| 1435 | + ) |
|
| 1436 | + : array(); |
|
| 1437 | + // if there is only one price (which would be the base price) |
|
| 1438 | + // or NO prices and this ticket is a default ticket, |
|
| 1439 | + // let's just make sure there are no cached default prices on the object. |
|
| 1440 | + // This is done by not including any query_params. |
|
| 1441 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
| 1442 | + $prices = $ticket->prices(); |
|
| 1443 | + } |
|
| 1444 | + // check if we're dealing with a default ticket in which case |
|
| 1445 | + // we don't want any starting_ticket_datetime_row values set |
|
| 1446 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
| 1447 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
| 1448 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
| 1449 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1451 | + : array(); |
|
| 1452 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1453 | + $base_price = $default ? null : $ticket->base_price(); |
|
| 1454 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
| 1455 | + // breaking out complicated condition for ticket_status |
|
| 1456 | + if ($default) { |
|
| 1457 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1458 | + } else { |
|
| 1459 | + $ticket_status_class = $ticket->is_default() |
|
| 1460 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1462 | + } |
|
| 1463 | + // breaking out complicated condition for TKT_taxable |
|
| 1464 | + if ($default) { |
|
| 1465 | + $TKT_taxable = ''; |
|
| 1466 | + } else { |
|
| 1467 | + $TKT_taxable = $ticket->taxable() |
|
| 1468 | + ? ' checked="checked"' |
|
| 1469 | + : ''; |
|
| 1470 | + } |
|
| 1471 | + if ($default) { |
|
| 1472 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1473 | + } elseif ($ticket->is_default()) { |
|
| 1474 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
| 1475 | + } else { |
|
| 1476 | + $TKT_status = $ticket->ticket_status(true); |
|
| 1477 | + } |
|
| 1478 | + if ($default) { |
|
| 1479 | + $TKT_min = ''; |
|
| 1480 | + } else { |
|
| 1481 | + $TKT_min = $ticket->min(); |
|
| 1482 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
| 1483 | + $TKT_min = ''; |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + $template_args = array( |
|
| 1487 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1488 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1489 | + // on initial page load this will always be the correct order. |
|
| 1490 | + 'tkt_status_class' => $ticket_status_class, |
|
| 1491 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
| 1492 | + 'edit_tkt_expanded' => '', |
|
| 1493 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
| 1494 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
| 1495 | + 'TKT_start_date' => $default |
|
| 1496 | + ? '' |
|
| 1497 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
| 1498 | + 'TKT_end_date' => $default |
|
| 1499 | + ? '' |
|
| 1500 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
| 1501 | + 'TKT_status' => $TKT_status, |
|
| 1502 | + 'TKT_price' => $default |
|
| 1503 | + ? '' |
|
| 1504 | + : EEH_Template::format_currency( |
|
| 1505 | + $ticket->get_ticket_total_with_taxes(), |
|
| 1506 | + false, |
|
| 1507 | + false |
|
| 1508 | + ), |
|
| 1509 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
| 1510 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
| 1511 | + 'TKT_qty' => $default |
|
| 1512 | + ? '' |
|
| 1513 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
| 1514 | + 'TKT_qty_for_input' => $default |
|
| 1515 | + ? '' |
|
| 1516 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
| 1517 | + 'TKT_uses' => $default |
|
| 1518 | + ? '' |
|
| 1519 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
| 1520 | + 'TKT_min' => $TKT_min, |
|
| 1521 | + 'TKT_max' => $default |
|
| 1522 | + ? '' |
|
| 1523 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
| 1524 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
| 1525 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
| 1526 | + 'TKT_registrations' => $default |
|
| 1527 | + ? 0 |
|
| 1528 | + : $ticket->count_registrations( |
|
| 1529 | + array( |
|
| 1530 | + array( |
|
| 1531 | + 'STS_ID' => array( |
|
| 1532 | + '!=', |
|
| 1533 | + EEM_Registration::status_id_incomplete, |
|
| 1534 | + ), |
|
| 1535 | + ), |
|
| 1536 | + ) |
|
| 1537 | + ), |
|
| 1538 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
| 1539 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
| 1540 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
| 1541 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
| 1542 | + 'TKT_is_default_selector' => '', |
|
| 1543 | + 'ticket_price_rows' => '', |
|
| 1544 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
| 1545 | + ? '' |
|
| 1546 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1547 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
| 1548 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
| 1549 | + ? '' |
|
| 1550 | + : ' style="display:none;"', |
|
| 1551 | + 'show_price_mod_button' => count($prices) > 1 |
|
| 1552 | + || ($default && $count_price_mods > 0) |
|
| 1553 | + || (! $default && $ticket->deleted()) |
|
| 1554 | + ? ' style="display:none;"' |
|
| 1555 | + : '', |
|
| 1556 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
| 1557 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
| 1558 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
| 1559 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
| 1560 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
| 1561 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
| 1562 | + 'TKT_taxable' => $TKT_taxable, |
|
| 1563 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
| 1564 | + ? '' |
|
| 1565 | + : ' style="display:none"', |
|
| 1566 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1567 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
| 1568 | + $ticket_subtotal, |
|
| 1569 | + false, |
|
| 1570 | + false |
|
| 1571 | + ), |
|
| 1572 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
| 1573 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
| 1574 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
| 1575 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1576 | + ? ' ticket-archived' |
|
| 1577 | + : '', |
|
| 1578 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
| 1579 | + && $ticket->deleted() |
|
| 1580 | + && ! $ticket->is_permanently_deleteable() |
|
| 1581 | + ? 'ee-lock-icon ' |
|
| 1582 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
| 1583 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
| 1584 | + ? '' |
|
| 1585 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
| 1586 | + ); |
|
| 1587 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
| 1588 | + ? ' style="display:none"' |
|
| 1589 | + : ''; |
|
| 1590 | + // handle rows that should NOT be empty |
|
| 1591 | + if (empty($template_args['TKT_start_date'])) { |
|
| 1592 | + // if empty then the start date will be now. |
|
| 1593 | + $template_args['TKT_start_date'] = date( |
|
| 1594 | + $this->_date_time_format, |
|
| 1595 | + current_time('timestamp') |
|
| 1596 | + ); |
|
| 1597 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1598 | + } |
|
| 1599 | + if (empty($template_args['TKT_end_date'])) { |
|
| 1600 | + // get the earliest datetime (if present); |
|
| 1601 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
| 1602 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
| 1603 | + 'Datetime', |
|
| 1604 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
| 1605 | + ) |
|
| 1606 | + : null; |
|
| 1607 | + if (! empty($earliest_dtt)) { |
|
| 1608 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
| 1609 | + 'DTT_EVT_start', |
|
| 1610 | + $this->_date_time_format |
|
| 1611 | + ); |
|
| 1612 | + } else { |
|
| 1613 | + // default so let's just use what's been set for the default date-time which is 30 days from now. |
|
| 1614 | + $template_args['TKT_end_date'] = date( |
|
| 1615 | + $this->_date_time_format, |
|
| 1616 | + mktime( |
|
| 1617 | + 24, |
|
| 1618 | + 0, |
|
| 1619 | + 0, |
|
| 1620 | + date('m'), |
|
| 1621 | + date('d') + 29, |
|
| 1622 | + date('Y') |
|
| 1623 | + ) |
|
| 1624 | + ); |
|
| 1625 | + } |
|
| 1626 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1627 | + } |
|
| 1628 | + // generate ticket_datetime items |
|
| 1629 | + if (! $default) { |
|
| 1630 | + $datetime_row = 1; |
|
| 1631 | + foreach ($all_datetimes as $datetime) { |
|
| 1632 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 1633 | + $datetime_row, |
|
| 1634 | + $ticket_row, |
|
| 1635 | + $datetime, |
|
| 1636 | + $ticket, |
|
| 1637 | + $ticket_datetimes, |
|
| 1638 | + $default |
|
| 1639 | + ); |
|
| 1640 | + $datetime_row++; |
|
| 1641 | + } |
|
| 1642 | + } |
|
| 1643 | + $price_row = 1; |
|
| 1644 | + foreach ($prices as $price) { |
|
| 1645 | + if (! $price instanceof EE_Price) { |
|
| 1646 | + continue; |
|
| 1647 | + } |
|
| 1648 | + if ($price->is_base_price()) { |
|
| 1649 | + $price_row++; |
|
| 1650 | + continue; |
|
| 1651 | + } |
|
| 1652 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
| 1653 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
| 1654 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
| 1655 | + $ticket_row, |
|
| 1656 | + $price_row, |
|
| 1657 | + $price, |
|
| 1658 | + $default, |
|
| 1659 | + $ticket, |
|
| 1660 | + $show_trash, |
|
| 1661 | + $show_create |
|
| 1662 | + ); |
|
| 1663 | + $price_row++; |
|
| 1664 | + } |
|
| 1665 | + // filter $template_args |
|
| 1666 | + $template_args = apply_filters( |
|
| 1667 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
| 1668 | + $template_args, |
|
| 1669 | + $ticket_row, |
|
| 1670 | + $ticket, |
|
| 1671 | + $ticket_datetimes, |
|
| 1672 | + $all_datetimes, |
|
| 1673 | + $default, |
|
| 1674 | + $all_tickets, |
|
| 1675 | + $this->_is_creating_event |
|
| 1676 | + ); |
|
| 1677 | + return EEH_Template::display_template( |
|
| 1678 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | + $template_args, |
|
| 1680 | + true |
|
| 1681 | + ); |
|
| 1682 | + } |
|
| 1683 | 1683 | |
| 1684 | 1684 | |
| 1685 | - /** |
|
| 1686 | - * @param int $ticket_row |
|
| 1687 | - * @param EE_Ticket|null $ticket |
|
| 1688 | - * @return string |
|
| 1689 | - * @throws DomainException |
|
| 1690 | - * @throws EE_Error |
|
| 1691 | - */ |
|
| 1692 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1693 | - { |
|
| 1694 | - $tax_rows = ''; |
|
| 1695 | - /** @var EE_Price[] $taxes */ |
|
| 1696 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1697 | - foreach ($taxes as $tax) { |
|
| 1698 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1699 | - $template_args = array( |
|
| 1700 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1701 | - ? '' |
|
| 1702 | - : ' style="display:none;"', |
|
| 1703 | - 'tax_id' => $tax->ID(), |
|
| 1704 | - 'tkt_row' => $ticket_row, |
|
| 1705 | - 'tax_label' => $tax->get('PRC_name'), |
|
| 1706 | - 'tax_added' => $tax_added, |
|
| 1707 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1708 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1709 | - ); |
|
| 1710 | - $template_args = apply_filters( |
|
| 1711 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1712 | - $template_args, |
|
| 1713 | - $ticket_row, |
|
| 1714 | - $ticket, |
|
| 1715 | - $this->_is_creating_event |
|
| 1716 | - ); |
|
| 1717 | - $tax_rows .= EEH_Template::display_template( |
|
| 1718 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | - $template_args, |
|
| 1720 | - true |
|
| 1721 | - ); |
|
| 1722 | - } |
|
| 1723 | - return $tax_rows; |
|
| 1724 | - } |
|
| 1685 | + /** |
|
| 1686 | + * @param int $ticket_row |
|
| 1687 | + * @param EE_Ticket|null $ticket |
|
| 1688 | + * @return string |
|
| 1689 | + * @throws DomainException |
|
| 1690 | + * @throws EE_Error |
|
| 1691 | + */ |
|
| 1692 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
| 1693 | + { |
|
| 1694 | + $tax_rows = ''; |
|
| 1695 | + /** @var EE_Price[] $taxes */ |
|
| 1696 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
| 1697 | + foreach ($taxes as $tax) { |
|
| 1698 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
| 1699 | + $template_args = array( |
|
| 1700 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
| 1701 | + ? '' |
|
| 1702 | + : ' style="display:none;"', |
|
| 1703 | + 'tax_id' => $tax->ID(), |
|
| 1704 | + 'tkt_row' => $ticket_row, |
|
| 1705 | + 'tax_label' => $tax->get('PRC_name'), |
|
| 1706 | + 'tax_added' => $tax_added, |
|
| 1707 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
| 1708 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
| 1709 | + ); |
|
| 1710 | + $template_args = apply_filters( |
|
| 1711 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
| 1712 | + $template_args, |
|
| 1713 | + $ticket_row, |
|
| 1714 | + $ticket, |
|
| 1715 | + $this->_is_creating_event |
|
| 1716 | + ); |
|
| 1717 | + $tax_rows .= EEH_Template::display_template( |
|
| 1718 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | + $template_args, |
|
| 1720 | + true |
|
| 1721 | + ); |
|
| 1722 | + } |
|
| 1723 | + return $tax_rows; |
|
| 1724 | + } |
|
| 1725 | 1725 | |
| 1726 | 1726 | |
| 1727 | - /** |
|
| 1728 | - * @param EE_Price $tax |
|
| 1729 | - * @param EE_Ticket|null $ticket |
|
| 1730 | - * @return float|int |
|
| 1731 | - * @throws EE_Error |
|
| 1732 | - */ |
|
| 1733 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1734 | - { |
|
| 1735 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1736 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1737 | - } |
|
| 1727 | + /** |
|
| 1728 | + * @param EE_Price $tax |
|
| 1729 | + * @param EE_Ticket|null $ticket |
|
| 1730 | + * @return float|int |
|
| 1731 | + * @throws EE_Error |
|
| 1732 | + */ |
|
| 1733 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
| 1734 | + { |
|
| 1735 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
| 1736 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
| 1737 | + } |
|
| 1738 | 1738 | |
| 1739 | 1739 | |
| 1740 | - /** |
|
| 1741 | - * @param int $ticket_row |
|
| 1742 | - * @param int $price_row |
|
| 1743 | - * @param EE_Price|null $price |
|
| 1744 | - * @param bool $default |
|
| 1745 | - * @param EE_Ticket|null $ticket |
|
| 1746 | - * @param bool $show_trash |
|
| 1747 | - * @param bool $show_create |
|
| 1748 | - * @return mixed |
|
| 1749 | - * @throws InvalidArgumentException |
|
| 1750 | - * @throws InvalidInterfaceException |
|
| 1751 | - * @throws InvalidDataTypeException |
|
| 1752 | - * @throws DomainException |
|
| 1753 | - * @throws EE_Error |
|
| 1754 | - * @throws ReflectionException |
|
| 1755 | - */ |
|
| 1756 | - protected function _get_ticket_price_row( |
|
| 1757 | - $ticket_row, |
|
| 1758 | - $price_row, |
|
| 1759 | - $price, |
|
| 1760 | - $default, |
|
| 1761 | - $ticket, |
|
| 1762 | - $show_trash = true, |
|
| 1763 | - $show_create = true |
|
| 1764 | - ) { |
|
| 1765 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1766 | - $template_args = array( |
|
| 1767 | - 'tkt_row' => $default && empty($ticket) |
|
| 1768 | - ? 'TICKETNUM' |
|
| 1769 | - : $ticket_row, |
|
| 1770 | - 'PRC_order' => $default && empty($price) |
|
| 1771 | - ? 'PRICENUM' |
|
| 1772 | - : $price_row, |
|
| 1773 | - 'edit_prices_name' => $default && empty($price) |
|
| 1774 | - ? 'PRICENAMEATTR' |
|
| 1775 | - : 'edit_prices', |
|
| 1776 | - 'price_type_selector' => $default && empty($price) |
|
| 1777 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1778 | - : $this->_get_price_type_selector( |
|
| 1779 | - $ticket_row, |
|
| 1780 | - $price_row, |
|
| 1781 | - $price, |
|
| 1782 | - $default, |
|
| 1783 | - $send_disabled |
|
| 1784 | - ), |
|
| 1785 | - 'PRC_ID' => $default && empty($price) |
|
| 1786 | - ? 0 |
|
| 1787 | - : $price->ID(), |
|
| 1788 | - 'PRC_is_default' => $default && empty($price) |
|
| 1789 | - ? 0 |
|
| 1790 | - : $price->get('PRC_is_default'), |
|
| 1791 | - 'PRC_name' => $default && empty($price) |
|
| 1792 | - ? '' |
|
| 1793 | - : $price->get('PRC_name'), |
|
| 1794 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1795 | - 'show_plus_or_minus' => $default && empty($price) |
|
| 1796 | - ? '' |
|
| 1797 | - : ' style="display:none;"', |
|
| 1798 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1799 | - ? ' style="display:none;"' |
|
| 1800 | - : '', |
|
| 1801 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1802 | - ? ' style="display:none;"' |
|
| 1803 | - : '', |
|
| 1804 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1805 | - ? ' style="display:none"' |
|
| 1806 | - : '', |
|
| 1807 | - 'PRC_amount' => $default && empty($price) |
|
| 1808 | - ? 0 |
|
| 1809 | - : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1810 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1811 | - ? ' style="display:none;"' |
|
| 1812 | - : '', |
|
| 1813 | - 'show_trash_icon' => $show_trash |
|
| 1814 | - ? '' |
|
| 1815 | - : ' style="display:none;"', |
|
| 1816 | - 'show_create_button' => $show_create |
|
| 1817 | - ? '' |
|
| 1818 | - : ' style="display:none;"', |
|
| 1819 | - 'PRC_desc' => $default && empty($price) |
|
| 1820 | - ? '' |
|
| 1821 | - : $price->get('PRC_desc'), |
|
| 1822 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1823 | - ); |
|
| 1824 | - $template_args = apply_filters( |
|
| 1825 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1826 | - $template_args, |
|
| 1827 | - $ticket_row, |
|
| 1828 | - $price_row, |
|
| 1829 | - $price, |
|
| 1830 | - $default, |
|
| 1831 | - $ticket, |
|
| 1832 | - $show_trash, |
|
| 1833 | - $show_create, |
|
| 1834 | - $this->_is_creating_event |
|
| 1835 | - ); |
|
| 1836 | - return EEH_Template::display_template( |
|
| 1837 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | - $template_args, |
|
| 1839 | - true |
|
| 1840 | - ); |
|
| 1841 | - } |
|
| 1740 | + /** |
|
| 1741 | + * @param int $ticket_row |
|
| 1742 | + * @param int $price_row |
|
| 1743 | + * @param EE_Price|null $price |
|
| 1744 | + * @param bool $default |
|
| 1745 | + * @param EE_Ticket|null $ticket |
|
| 1746 | + * @param bool $show_trash |
|
| 1747 | + * @param bool $show_create |
|
| 1748 | + * @return mixed |
|
| 1749 | + * @throws InvalidArgumentException |
|
| 1750 | + * @throws InvalidInterfaceException |
|
| 1751 | + * @throws InvalidDataTypeException |
|
| 1752 | + * @throws DomainException |
|
| 1753 | + * @throws EE_Error |
|
| 1754 | + * @throws ReflectionException |
|
| 1755 | + */ |
|
| 1756 | + protected function _get_ticket_price_row( |
|
| 1757 | + $ticket_row, |
|
| 1758 | + $price_row, |
|
| 1759 | + $price, |
|
| 1760 | + $default, |
|
| 1761 | + $ticket, |
|
| 1762 | + $show_trash = true, |
|
| 1763 | + $show_create = true |
|
| 1764 | + ) { |
|
| 1765 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
| 1766 | + $template_args = array( |
|
| 1767 | + 'tkt_row' => $default && empty($ticket) |
|
| 1768 | + ? 'TICKETNUM' |
|
| 1769 | + : $ticket_row, |
|
| 1770 | + 'PRC_order' => $default && empty($price) |
|
| 1771 | + ? 'PRICENUM' |
|
| 1772 | + : $price_row, |
|
| 1773 | + 'edit_prices_name' => $default && empty($price) |
|
| 1774 | + ? 'PRICENAMEATTR' |
|
| 1775 | + : 'edit_prices', |
|
| 1776 | + 'price_type_selector' => $default && empty($price) |
|
| 1777 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1778 | + : $this->_get_price_type_selector( |
|
| 1779 | + $ticket_row, |
|
| 1780 | + $price_row, |
|
| 1781 | + $price, |
|
| 1782 | + $default, |
|
| 1783 | + $send_disabled |
|
| 1784 | + ), |
|
| 1785 | + 'PRC_ID' => $default && empty($price) |
|
| 1786 | + ? 0 |
|
| 1787 | + : $price->ID(), |
|
| 1788 | + 'PRC_is_default' => $default && empty($price) |
|
| 1789 | + ? 0 |
|
| 1790 | + : $price->get('PRC_is_default'), |
|
| 1791 | + 'PRC_name' => $default && empty($price) |
|
| 1792 | + ? '' |
|
| 1793 | + : $price->get('PRC_name'), |
|
| 1794 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
| 1795 | + 'show_plus_or_minus' => $default && empty($price) |
|
| 1796 | + ? '' |
|
| 1797 | + : ' style="display:none;"', |
|
| 1798 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
| 1799 | + ? ' style="display:none;"' |
|
| 1800 | + : '', |
|
| 1801 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
| 1802 | + ? ' style="display:none;"' |
|
| 1803 | + : '', |
|
| 1804 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
| 1805 | + ? ' style="display:none"' |
|
| 1806 | + : '', |
|
| 1807 | + 'PRC_amount' => $default && empty($price) |
|
| 1808 | + ? 0 |
|
| 1809 | + : $price->get_pretty('PRC_amount', 'localized_float'), |
|
| 1810 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
| 1811 | + ? ' style="display:none;"' |
|
| 1812 | + : '', |
|
| 1813 | + 'show_trash_icon' => $show_trash |
|
| 1814 | + ? '' |
|
| 1815 | + : ' style="display:none;"', |
|
| 1816 | + 'show_create_button' => $show_create |
|
| 1817 | + ? '' |
|
| 1818 | + : ' style="display:none;"', |
|
| 1819 | + 'PRC_desc' => $default && empty($price) |
|
| 1820 | + ? '' |
|
| 1821 | + : $price->get('PRC_desc'), |
|
| 1822 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
| 1823 | + ); |
|
| 1824 | + $template_args = apply_filters( |
|
| 1825 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
| 1826 | + $template_args, |
|
| 1827 | + $ticket_row, |
|
| 1828 | + $price_row, |
|
| 1829 | + $price, |
|
| 1830 | + $default, |
|
| 1831 | + $ticket, |
|
| 1832 | + $show_trash, |
|
| 1833 | + $show_create, |
|
| 1834 | + $this->_is_creating_event |
|
| 1835 | + ); |
|
| 1836 | + return EEH_Template::display_template( |
|
| 1837 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | + $template_args, |
|
| 1839 | + true |
|
| 1840 | + ); |
|
| 1841 | + } |
|
| 1842 | 1842 | |
| 1843 | 1843 | |
| 1844 | - /** |
|
| 1845 | - * @param int $ticket_row |
|
| 1846 | - * @param int $price_row |
|
| 1847 | - * @param EE_Price $price |
|
| 1848 | - * @param bool $default |
|
| 1849 | - * @param bool $disabled |
|
| 1850 | - * @return mixed |
|
| 1851 | - * @throws ReflectionException |
|
| 1852 | - * @throws InvalidArgumentException |
|
| 1853 | - * @throws InvalidInterfaceException |
|
| 1854 | - * @throws InvalidDataTypeException |
|
| 1855 | - * @throws DomainException |
|
| 1856 | - * @throws EE_Error |
|
| 1857 | - */ |
|
| 1858 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1859 | - { |
|
| 1860 | - if ($price->is_base_price()) { |
|
| 1861 | - return $this->_get_base_price_template( |
|
| 1862 | - $ticket_row, |
|
| 1863 | - $price_row, |
|
| 1864 | - $price, |
|
| 1865 | - $default |
|
| 1866 | - ); |
|
| 1867 | - } |
|
| 1868 | - return $this->_get_price_modifier_template( |
|
| 1869 | - $ticket_row, |
|
| 1870 | - $price_row, |
|
| 1871 | - $price, |
|
| 1872 | - $default, |
|
| 1873 | - $disabled |
|
| 1874 | - ); |
|
| 1875 | - } |
|
| 1844 | + /** |
|
| 1845 | + * @param int $ticket_row |
|
| 1846 | + * @param int $price_row |
|
| 1847 | + * @param EE_Price $price |
|
| 1848 | + * @param bool $default |
|
| 1849 | + * @param bool $disabled |
|
| 1850 | + * @return mixed |
|
| 1851 | + * @throws ReflectionException |
|
| 1852 | + * @throws InvalidArgumentException |
|
| 1853 | + * @throws InvalidInterfaceException |
|
| 1854 | + * @throws InvalidDataTypeException |
|
| 1855 | + * @throws DomainException |
|
| 1856 | + * @throws EE_Error |
|
| 1857 | + */ |
|
| 1858 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
| 1859 | + { |
|
| 1860 | + if ($price->is_base_price()) { |
|
| 1861 | + return $this->_get_base_price_template( |
|
| 1862 | + $ticket_row, |
|
| 1863 | + $price_row, |
|
| 1864 | + $price, |
|
| 1865 | + $default |
|
| 1866 | + ); |
|
| 1867 | + } |
|
| 1868 | + return $this->_get_price_modifier_template( |
|
| 1869 | + $ticket_row, |
|
| 1870 | + $price_row, |
|
| 1871 | + $price, |
|
| 1872 | + $default, |
|
| 1873 | + $disabled |
|
| 1874 | + ); |
|
| 1875 | + } |
|
| 1876 | 1876 | |
| 1877 | 1877 | |
| 1878 | - /** |
|
| 1879 | - * @param int $ticket_row |
|
| 1880 | - * @param int $price_row |
|
| 1881 | - * @param EE_Price $price |
|
| 1882 | - * @param bool $default |
|
| 1883 | - * @return mixed |
|
| 1884 | - * @throws DomainException |
|
| 1885 | - * @throws EE_Error |
|
| 1886 | - */ |
|
| 1887 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1888 | - { |
|
| 1889 | - $template_args = array( |
|
| 1890 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1891 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1892 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1893 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1894 | - 'price_selected_operator' => '+', |
|
| 1895 | - 'price_selected_is_percent' => 0, |
|
| 1896 | - ); |
|
| 1897 | - $template_args = apply_filters( |
|
| 1898 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1899 | - $template_args, |
|
| 1900 | - $ticket_row, |
|
| 1901 | - $price_row, |
|
| 1902 | - $price, |
|
| 1903 | - $default, |
|
| 1904 | - $this->_is_creating_event |
|
| 1905 | - ); |
|
| 1906 | - return EEH_Template::display_template( |
|
| 1907 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | - $template_args, |
|
| 1909 | - true |
|
| 1910 | - ); |
|
| 1911 | - } |
|
| 1878 | + /** |
|
| 1879 | + * @param int $ticket_row |
|
| 1880 | + * @param int $price_row |
|
| 1881 | + * @param EE_Price $price |
|
| 1882 | + * @param bool $default |
|
| 1883 | + * @return mixed |
|
| 1884 | + * @throws DomainException |
|
| 1885 | + * @throws EE_Error |
|
| 1886 | + */ |
|
| 1887 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
| 1888 | + { |
|
| 1889 | + $template_args = array( |
|
| 1890 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1891 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
| 1892 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
| 1893 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
| 1894 | + 'price_selected_operator' => '+', |
|
| 1895 | + 'price_selected_is_percent' => 0, |
|
| 1896 | + ); |
|
| 1897 | + $template_args = apply_filters( |
|
| 1898 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
| 1899 | + $template_args, |
|
| 1900 | + $ticket_row, |
|
| 1901 | + $price_row, |
|
| 1902 | + $price, |
|
| 1903 | + $default, |
|
| 1904 | + $this->_is_creating_event |
|
| 1905 | + ); |
|
| 1906 | + return EEH_Template::display_template( |
|
| 1907 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | + $template_args, |
|
| 1909 | + true |
|
| 1910 | + ); |
|
| 1911 | + } |
|
| 1912 | 1912 | |
| 1913 | 1913 | |
| 1914 | - /** |
|
| 1915 | - * @param int $ticket_row |
|
| 1916 | - * @param int $price_row |
|
| 1917 | - * @param EE_Price $price |
|
| 1918 | - * @param bool $default |
|
| 1919 | - * @param bool $disabled |
|
| 1920 | - * @return mixed |
|
| 1921 | - * @throws ReflectionException |
|
| 1922 | - * @throws InvalidArgumentException |
|
| 1923 | - * @throws InvalidInterfaceException |
|
| 1924 | - * @throws InvalidDataTypeException |
|
| 1925 | - * @throws DomainException |
|
| 1926 | - * @throws EE_Error |
|
| 1927 | - */ |
|
| 1928 | - protected function _get_price_modifier_template( |
|
| 1929 | - $ticket_row, |
|
| 1930 | - $price_row, |
|
| 1931 | - $price, |
|
| 1932 | - $default, |
|
| 1933 | - $disabled = false |
|
| 1934 | - ) { |
|
| 1935 | - $select_name = $default && ! $price instanceof EE_Price |
|
| 1936 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1937 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1938 | - /** @var EEM_Price_Type $price_type_model */ |
|
| 1939 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1940 | - $price_types = $price_type_model->get_all(array( |
|
| 1941 | - array( |
|
| 1942 | - 'OR' => array( |
|
| 1943 | - 'PBT_ID' => '2', |
|
| 1944 | - 'PBT_ID*' => '3', |
|
| 1945 | - ), |
|
| 1946 | - ), |
|
| 1947 | - )); |
|
| 1948 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | - : array(); |
|
| 1951 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | - $price_option_spans = ''; |
|
| 1953 | - // setup price types for selector |
|
| 1954 | - foreach ($price_types as $price_type) { |
|
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | - continue; |
|
| 1957 | - } |
|
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1959 | - // while we're in the loop let's setup the option spans used by js |
|
| 1960 | - $span_args = array( |
|
| 1961 | - 'PRT_ID' => $price_type->ID(), |
|
| 1962 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | - ); |
|
| 1965 | - $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | - $span_args, |
|
| 1968 | - true |
|
| 1969 | - ); |
|
| 1970 | - } |
|
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | - : $select_name; |
|
| 1973 | - $select_input = new EE_Select_Input( |
|
| 1974 | - $all_price_types, |
|
| 1975 | - array( |
|
| 1976 | - 'default' => $selected_price_type_id, |
|
| 1977 | - 'html_name' => $select_name, |
|
| 1978 | - 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | - 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1980 | - ) |
|
| 1981 | - ); |
|
| 1982 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1983 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1984 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1985 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1986 | - $template_args = array( |
|
| 1987 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1988 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1989 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1990 | - 'main_name' => $select_name, |
|
| 1991 | - 'selected_price_type_id' => $selected_price_type_id, |
|
| 1992 | - 'price_option_spans' => $price_option_spans, |
|
| 1993 | - 'price_selected_operator' => $price_selected_operator, |
|
| 1994 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1995 | - 'disabled' => $disabled, |
|
| 1996 | - ); |
|
| 1997 | - $template_args = apply_filters( |
|
| 1998 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1999 | - $template_args, |
|
| 2000 | - $ticket_row, |
|
| 2001 | - $price_row, |
|
| 2002 | - $price, |
|
| 2003 | - $default, |
|
| 2004 | - $disabled, |
|
| 2005 | - $this->_is_creating_event |
|
| 2006 | - ); |
|
| 2007 | - return EEH_Template::display_template( |
|
| 2008 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | - $template_args, |
|
| 2010 | - true |
|
| 2011 | - ); |
|
| 2012 | - } |
|
| 1914 | + /** |
|
| 1915 | + * @param int $ticket_row |
|
| 1916 | + * @param int $price_row |
|
| 1917 | + * @param EE_Price $price |
|
| 1918 | + * @param bool $default |
|
| 1919 | + * @param bool $disabled |
|
| 1920 | + * @return mixed |
|
| 1921 | + * @throws ReflectionException |
|
| 1922 | + * @throws InvalidArgumentException |
|
| 1923 | + * @throws InvalidInterfaceException |
|
| 1924 | + * @throws InvalidDataTypeException |
|
| 1925 | + * @throws DomainException |
|
| 1926 | + * @throws EE_Error |
|
| 1927 | + */ |
|
| 1928 | + protected function _get_price_modifier_template( |
|
| 1929 | + $ticket_row, |
|
| 1930 | + $price_row, |
|
| 1931 | + $price, |
|
| 1932 | + $default, |
|
| 1933 | + $disabled = false |
|
| 1934 | + ) { |
|
| 1935 | + $select_name = $default && ! $price instanceof EE_Price |
|
| 1936 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
| 1937 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1938 | + /** @var EEM_Price_Type $price_type_model */ |
|
| 1939 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
| 1940 | + $price_types = $price_type_model->get_all(array( |
|
| 1941 | + array( |
|
| 1942 | + 'OR' => array( |
|
| 1943 | + 'PBT_ID' => '2', |
|
| 1944 | + 'PBT_ID*' => '3', |
|
| 1945 | + ), |
|
| 1946 | + ), |
|
| 1947 | + )); |
|
| 1948 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
| 1949 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
| 1950 | + : array(); |
|
| 1951 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
| 1952 | + $price_option_spans = ''; |
|
| 1953 | + // setup price types for selector |
|
| 1954 | + foreach ($price_types as $price_type) { |
|
| 1955 | + if (! $price_type instanceof EE_Price_Type) { |
|
| 1956 | + continue; |
|
| 1957 | + } |
|
| 1958 | + $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1959 | + // while we're in the loop let's setup the option spans used by js |
|
| 1960 | + $span_args = array( |
|
| 1961 | + 'PRT_ID' => $price_type->ID(), |
|
| 1962 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
| 1963 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
| 1964 | + ); |
|
| 1965 | + $price_option_spans .= EEH_Template::display_template( |
|
| 1966 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | + $span_args, |
|
| 1968 | + true |
|
| 1969 | + ); |
|
| 1970 | + } |
|
| 1971 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1972 | + : $select_name; |
|
| 1973 | + $select_input = new EE_Select_Input( |
|
| 1974 | + $all_price_types, |
|
| 1975 | + array( |
|
| 1976 | + 'default' => $selected_price_type_id, |
|
| 1977 | + 'html_name' => $select_name, |
|
| 1978 | + 'html_class' => 'edit-price-PRT_ID', |
|
| 1979 | + 'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
| 1980 | + ) |
|
| 1981 | + ); |
|
| 1982 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
| 1983 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
| 1984 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
| 1985 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
| 1986 | + $template_args = array( |
|
| 1987 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
| 1988 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
| 1989 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
| 1990 | + 'main_name' => $select_name, |
|
| 1991 | + 'selected_price_type_id' => $selected_price_type_id, |
|
| 1992 | + 'price_option_spans' => $price_option_spans, |
|
| 1993 | + 'price_selected_operator' => $price_selected_operator, |
|
| 1994 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
| 1995 | + 'disabled' => $disabled, |
|
| 1996 | + ); |
|
| 1997 | + $template_args = apply_filters( |
|
| 1998 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
| 1999 | + $template_args, |
|
| 2000 | + $ticket_row, |
|
| 2001 | + $price_row, |
|
| 2002 | + $price, |
|
| 2003 | + $default, |
|
| 2004 | + $disabled, |
|
| 2005 | + $this->_is_creating_event |
|
| 2006 | + ); |
|
| 2007 | + return EEH_Template::display_template( |
|
| 2008 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | + $template_args, |
|
| 2010 | + true |
|
| 2011 | + ); |
|
| 2012 | + } |
|
| 2013 | 2013 | |
| 2014 | 2014 | |
| 2015 | - /** |
|
| 2016 | - * @param int $datetime_row |
|
| 2017 | - * @param int $ticket_row |
|
| 2018 | - * @param EE_Datetime|null $datetime |
|
| 2019 | - * @param EE_Ticket|null $ticket |
|
| 2020 | - * @param array $ticket_datetimes |
|
| 2021 | - * @param bool $default |
|
| 2022 | - * @return mixed |
|
| 2023 | - * @throws DomainException |
|
| 2024 | - * @throws EE_Error |
|
| 2025 | - */ |
|
| 2026 | - protected function _get_ticket_datetime_list_item( |
|
| 2027 | - $datetime_row, |
|
| 2028 | - $ticket_row, |
|
| 2029 | - $datetime, |
|
| 2030 | - $ticket, |
|
| 2031 | - $ticket_datetimes = array(), |
|
| 2032 | - $default = false |
|
| 2033 | - ) { |
|
| 2034 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2036 | - : array(); |
|
| 2037 | - $template_args = array( |
|
| 2038 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2039 | - ? 'DTTNUM' |
|
| 2040 | - : $datetime_row, |
|
| 2041 | - 'tkt_row' => $default |
|
| 2042 | - ? 'TICKETNUM' |
|
| 2043 | - : $ticket_row, |
|
| 2044 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2045 | - ? ' ticket-selected' |
|
| 2046 | - : '', |
|
| 2047 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2048 | - ? ' checked="checked"' |
|
| 2049 | - : '', |
|
| 2050 | - 'DTT_name' => $default && empty($datetime) |
|
| 2051 | - ? 'DTTNAME' |
|
| 2052 | - : $datetime->get_dtt_display_name(true), |
|
| 2053 | - 'tkt_status_class' => '', |
|
| 2054 | - ); |
|
| 2055 | - $template_args = apply_filters( |
|
| 2056 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2057 | - $template_args, |
|
| 2058 | - $datetime_row, |
|
| 2059 | - $ticket_row, |
|
| 2060 | - $datetime, |
|
| 2061 | - $ticket, |
|
| 2062 | - $ticket_datetimes, |
|
| 2063 | - $default, |
|
| 2064 | - $this->_is_creating_event |
|
| 2065 | - ); |
|
| 2066 | - return EEH_Template::display_template( |
|
| 2067 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | - $template_args, |
|
| 2069 | - true |
|
| 2070 | - ); |
|
| 2071 | - } |
|
| 2015 | + /** |
|
| 2016 | + * @param int $datetime_row |
|
| 2017 | + * @param int $ticket_row |
|
| 2018 | + * @param EE_Datetime|null $datetime |
|
| 2019 | + * @param EE_Ticket|null $ticket |
|
| 2020 | + * @param array $ticket_datetimes |
|
| 2021 | + * @param bool $default |
|
| 2022 | + * @return mixed |
|
| 2023 | + * @throws DomainException |
|
| 2024 | + * @throws EE_Error |
|
| 2025 | + */ |
|
| 2026 | + protected function _get_ticket_datetime_list_item( |
|
| 2027 | + $datetime_row, |
|
| 2028 | + $ticket_row, |
|
| 2029 | + $datetime, |
|
| 2030 | + $ticket, |
|
| 2031 | + $ticket_datetimes = array(), |
|
| 2032 | + $default = false |
|
| 2033 | + ) { |
|
| 2034 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | + ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2036 | + : array(); |
|
| 2037 | + $template_args = array( |
|
| 2038 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
| 2039 | + ? 'DTTNUM' |
|
| 2040 | + : $datetime_row, |
|
| 2041 | + 'tkt_row' => $default |
|
| 2042 | + ? 'TICKETNUM' |
|
| 2043 | + : $ticket_row, |
|
| 2044 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2045 | + ? ' ticket-selected' |
|
| 2046 | + : '', |
|
| 2047 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
| 2048 | + ? ' checked="checked"' |
|
| 2049 | + : '', |
|
| 2050 | + 'DTT_name' => $default && empty($datetime) |
|
| 2051 | + ? 'DTTNAME' |
|
| 2052 | + : $datetime->get_dtt_display_name(true), |
|
| 2053 | + 'tkt_status_class' => '', |
|
| 2054 | + ); |
|
| 2055 | + $template_args = apply_filters( |
|
| 2056 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
| 2057 | + $template_args, |
|
| 2058 | + $datetime_row, |
|
| 2059 | + $ticket_row, |
|
| 2060 | + $datetime, |
|
| 2061 | + $ticket, |
|
| 2062 | + $ticket_datetimes, |
|
| 2063 | + $default, |
|
| 2064 | + $this->_is_creating_event |
|
| 2065 | + ); |
|
| 2066 | + return EEH_Template::display_template( |
|
| 2067 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | + $template_args, |
|
| 2069 | + true |
|
| 2070 | + ); |
|
| 2071 | + } |
|
| 2072 | 2072 | |
| 2073 | 2073 | |
| 2074 | - /** |
|
| 2075 | - * @param array $all_datetimes |
|
| 2076 | - * @param array $all_tickets |
|
| 2077 | - * @return mixed |
|
| 2078 | - * @throws ReflectionException |
|
| 2079 | - * @throws InvalidArgumentException |
|
| 2080 | - * @throws InvalidInterfaceException |
|
| 2081 | - * @throws InvalidDataTypeException |
|
| 2082 | - * @throws DomainException |
|
| 2083 | - * @throws EE_Error |
|
| 2084 | - */ |
|
| 2085 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2086 | - { |
|
| 2087 | - $template_args = array( |
|
| 2088 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2089 | - 'DTTNUM', |
|
| 2090 | - null, |
|
| 2091 | - true, |
|
| 2092 | - $all_datetimes |
|
| 2093 | - ), |
|
| 2094 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2095 | - 'TICKETNUM', |
|
| 2096 | - null, |
|
| 2097 | - array(), |
|
| 2098 | - array(), |
|
| 2099 | - true |
|
| 2100 | - ), |
|
| 2101 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2102 | - 'TICKETNUM', |
|
| 2103 | - 'PRICENUM', |
|
| 2104 | - null, |
|
| 2105 | - true, |
|
| 2106 | - null |
|
| 2107 | - ), |
|
| 2108 | - 'default_price_rows' => '', |
|
| 2109 | - 'default_base_price_amount' => 0, |
|
| 2110 | - 'default_base_price_name' => '', |
|
| 2111 | - 'default_base_price_description' => '', |
|
| 2112 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2113 | - 'TICKETNUM', |
|
| 2114 | - 'PRICENUM', |
|
| 2115 | - null, |
|
| 2116 | - true |
|
| 2117 | - ), |
|
| 2118 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2119 | - 'DTTNUM', |
|
| 2120 | - null, |
|
| 2121 | - array(), |
|
| 2122 | - array(), |
|
| 2123 | - true |
|
| 2124 | - ), |
|
| 2125 | - 'existing_available_datetime_tickets_list' => '', |
|
| 2126 | - 'existing_available_ticket_datetimes_list' => '', |
|
| 2127 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2128 | - 'DTTNUM', |
|
| 2129 | - 'TICKETNUM', |
|
| 2130 | - null, |
|
| 2131 | - null, |
|
| 2132 | - array(), |
|
| 2133 | - true |
|
| 2134 | - ), |
|
| 2135 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2136 | - 'DTTNUM', |
|
| 2137 | - 'TICKETNUM', |
|
| 2138 | - null, |
|
| 2139 | - null, |
|
| 2140 | - array(), |
|
| 2141 | - true |
|
| 2142 | - ), |
|
| 2143 | - ); |
|
| 2144 | - $ticket_row = 1; |
|
| 2145 | - foreach ($all_tickets as $ticket) { |
|
| 2146 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2147 | - 'DTTNUM', |
|
| 2148 | - $ticket_row, |
|
| 2149 | - null, |
|
| 2150 | - $ticket, |
|
| 2151 | - array(), |
|
| 2152 | - true |
|
| 2153 | - ); |
|
| 2154 | - $ticket_row++; |
|
| 2155 | - } |
|
| 2156 | - $datetime_row = 1; |
|
| 2157 | - foreach ($all_datetimes as $datetime) { |
|
| 2158 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2159 | - $datetime_row, |
|
| 2160 | - 'TICKETNUM', |
|
| 2161 | - $datetime, |
|
| 2162 | - null, |
|
| 2163 | - array(), |
|
| 2164 | - true |
|
| 2165 | - ); |
|
| 2166 | - $datetime_row++; |
|
| 2167 | - } |
|
| 2168 | - /** @var EEM_Price $price_model */ |
|
| 2169 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2170 | - $default_prices = $price_model->get_all_default_prices(); |
|
| 2171 | - $price_row = 1; |
|
| 2172 | - foreach ($default_prices as $price) { |
|
| 2173 | - if (! $price instanceof EE_Price) { |
|
| 2174 | - continue; |
|
| 2175 | - } |
|
| 2176 | - if ($price->is_base_price()) { |
|
| 2177 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2178 | - 'PRC_amount', |
|
| 2179 | - 'localized_float' |
|
| 2180 | - ); |
|
| 2181 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2182 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2183 | - $price_row++; |
|
| 2184 | - continue; |
|
| 2185 | - } |
|
| 2186 | - $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
| 2187 | - || count($default_prices) === 1); |
|
| 2188 | - $show_create = ! (count($default_prices) > 1 |
|
| 2189 | - && count($default_prices) |
|
| 2190 | - !== $price_row); |
|
| 2191 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2192 | - 'TICKETNUM', |
|
| 2193 | - $price_row, |
|
| 2194 | - $price, |
|
| 2195 | - true, |
|
| 2196 | - null, |
|
| 2197 | - $show_trash, |
|
| 2198 | - $show_create |
|
| 2199 | - ); |
|
| 2200 | - $price_row++; |
|
| 2201 | - } |
|
| 2202 | - $template_args = apply_filters( |
|
| 2203 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2204 | - $template_args, |
|
| 2205 | - $all_datetimes, |
|
| 2206 | - $all_tickets, |
|
| 2207 | - $this->_is_creating_event |
|
| 2208 | - ); |
|
| 2209 | - return EEH_Template::display_template( |
|
| 2210 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | - $template_args, |
|
| 2212 | - true |
|
| 2213 | - ); |
|
| 2214 | - } |
|
| 2074 | + /** |
|
| 2075 | + * @param array $all_datetimes |
|
| 2076 | + * @param array $all_tickets |
|
| 2077 | + * @return mixed |
|
| 2078 | + * @throws ReflectionException |
|
| 2079 | + * @throws InvalidArgumentException |
|
| 2080 | + * @throws InvalidInterfaceException |
|
| 2081 | + * @throws InvalidDataTypeException |
|
| 2082 | + * @throws DomainException |
|
| 2083 | + * @throws EE_Error |
|
| 2084 | + */ |
|
| 2085 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
| 2086 | + { |
|
| 2087 | + $template_args = array( |
|
| 2088 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
| 2089 | + 'DTTNUM', |
|
| 2090 | + null, |
|
| 2091 | + true, |
|
| 2092 | + $all_datetimes |
|
| 2093 | + ), |
|
| 2094 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
| 2095 | + 'TICKETNUM', |
|
| 2096 | + null, |
|
| 2097 | + array(), |
|
| 2098 | + array(), |
|
| 2099 | + true |
|
| 2100 | + ), |
|
| 2101 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
| 2102 | + 'TICKETNUM', |
|
| 2103 | + 'PRICENUM', |
|
| 2104 | + null, |
|
| 2105 | + true, |
|
| 2106 | + null |
|
| 2107 | + ), |
|
| 2108 | + 'default_price_rows' => '', |
|
| 2109 | + 'default_base_price_amount' => 0, |
|
| 2110 | + 'default_base_price_name' => '', |
|
| 2111 | + 'default_base_price_description' => '', |
|
| 2112 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
| 2113 | + 'TICKETNUM', |
|
| 2114 | + 'PRICENUM', |
|
| 2115 | + null, |
|
| 2116 | + true |
|
| 2117 | + ), |
|
| 2118 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
| 2119 | + 'DTTNUM', |
|
| 2120 | + null, |
|
| 2121 | + array(), |
|
| 2122 | + array(), |
|
| 2123 | + true |
|
| 2124 | + ), |
|
| 2125 | + 'existing_available_datetime_tickets_list' => '', |
|
| 2126 | + 'existing_available_ticket_datetimes_list' => '', |
|
| 2127 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
| 2128 | + 'DTTNUM', |
|
| 2129 | + 'TICKETNUM', |
|
| 2130 | + null, |
|
| 2131 | + null, |
|
| 2132 | + array(), |
|
| 2133 | + true |
|
| 2134 | + ), |
|
| 2135 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
| 2136 | + 'DTTNUM', |
|
| 2137 | + 'TICKETNUM', |
|
| 2138 | + null, |
|
| 2139 | + null, |
|
| 2140 | + array(), |
|
| 2141 | + true |
|
| 2142 | + ), |
|
| 2143 | + ); |
|
| 2144 | + $ticket_row = 1; |
|
| 2145 | + foreach ($all_tickets as $ticket) { |
|
| 2146 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
| 2147 | + 'DTTNUM', |
|
| 2148 | + $ticket_row, |
|
| 2149 | + null, |
|
| 2150 | + $ticket, |
|
| 2151 | + array(), |
|
| 2152 | + true |
|
| 2153 | + ); |
|
| 2154 | + $ticket_row++; |
|
| 2155 | + } |
|
| 2156 | + $datetime_row = 1; |
|
| 2157 | + foreach ($all_datetimes as $datetime) { |
|
| 2158 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
| 2159 | + $datetime_row, |
|
| 2160 | + 'TICKETNUM', |
|
| 2161 | + $datetime, |
|
| 2162 | + null, |
|
| 2163 | + array(), |
|
| 2164 | + true |
|
| 2165 | + ); |
|
| 2166 | + $datetime_row++; |
|
| 2167 | + } |
|
| 2168 | + /** @var EEM_Price $price_model */ |
|
| 2169 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
| 2170 | + $default_prices = $price_model->get_all_default_prices(); |
|
| 2171 | + $price_row = 1; |
|
| 2172 | + foreach ($default_prices as $price) { |
|
| 2173 | + if (! $price instanceof EE_Price) { |
|
| 2174 | + continue; |
|
| 2175 | + } |
|
| 2176 | + if ($price->is_base_price()) { |
|
| 2177 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
| 2178 | + 'PRC_amount', |
|
| 2179 | + 'localized_float' |
|
| 2180 | + ); |
|
| 2181 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
| 2182 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
| 2183 | + $price_row++; |
|
| 2184 | + continue; |
|
| 2185 | + } |
|
| 2186 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) |
|
| 2187 | + || count($default_prices) === 1); |
|
| 2188 | + $show_create = ! (count($default_prices) > 1 |
|
| 2189 | + && count($default_prices) |
|
| 2190 | + !== $price_row); |
|
| 2191 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
| 2192 | + 'TICKETNUM', |
|
| 2193 | + $price_row, |
|
| 2194 | + $price, |
|
| 2195 | + true, |
|
| 2196 | + null, |
|
| 2197 | + $show_trash, |
|
| 2198 | + $show_create |
|
| 2199 | + ); |
|
| 2200 | + $price_row++; |
|
| 2201 | + } |
|
| 2202 | + $template_args = apply_filters( |
|
| 2203 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
| 2204 | + $template_args, |
|
| 2205 | + $all_datetimes, |
|
| 2206 | + $all_tickets, |
|
| 2207 | + $this->_is_creating_event |
|
| 2208 | + ); |
|
| 2209 | + return EEH_Template::display_template( |
|
| 2210 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | + $template_args, |
|
| 2212 | + true |
|
| 2213 | + ); |
|
| 2214 | + } |
|
| 2215 | 2215 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | $this->_name = 'pricing'; |
| 50 | 50 | // capability check |
| 51 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 51 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 52 | 52 | 'ee_read_default_prices', |
| 53 | 53 | 'advanced_ticket_datetime_metabox' |
| 54 | 54 | )) { |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | $msg .= '</p><ul>'; |
| 150 | 150 | foreach ($format_validation as $error) { |
| 151 | - $msg .= '<li>' . $error . '</li>'; |
|
| 151 | + $msg .= '<li>'.$error.'</li>'; |
|
| 152 | 152 | } |
| 153 | 153 | $msg .= '</ul><p>'; |
| 154 | 154 | $msg .= sprintf( |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | $this->_scripts_styles = array( |
| 178 | 178 | 'registers' => array( |
| 179 | 179 | 'ee-tickets-datetimes-css' => array( |
| 180 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
| 180 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
| 181 | 181 | 'type' => 'css', |
| 182 | 182 | ), |
| 183 | 183 | 'ee-dtt-ticket-metabox' => array( |
| 184 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
| 184 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
| 185 | 185 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
| 186 | 186 | ), |
| 187 | 187 | ), |
@@ -205,9 +205,9 @@ discard block |
||
| 205 | 205 | 'event_espresso' |
| 206 | 206 | ), |
| 207 | 207 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
| 208 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
| 208 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
| 209 | 209 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
| 210 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
| 210 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
| 211 | 211 | 'single_warning_from_tkt' => esc_html__( |
| 212 | 212 | '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.', |
| 213 | 213 | 'event_espresso' |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | 'event_espresso' |
| 218 | 218 | ), |
| 219 | 219 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
| 220 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
| 220 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
| 221 | 221 | ), |
| 222 | 222 | 'DTT_ERROR_MSG' => array( |
| 223 | 223 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | { |
| 256 | 256 | foreach ($update_callbacks as $key => $callback) { |
| 257 | 257 | if ($callback[1] === '_default_tickets_update') { |
| 258 | - unset($update_callbacks[ $key ]); |
|
| 258 | + unset($update_callbacks[$key]); |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
| 314 | 314 | // trim all values to ensure any excess whitespace is removed. |
| 315 | 315 | $datetime_data = array_map( |
| 316 | - function ($datetime_data) { |
|
| 316 | + function($datetime_data) { |
|
| 317 | 317 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
| 318 | 318 | }, |
| 319 | 319 | $datetime_data |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | ); |
| 344 | 344 | // if we have an id then let's get existing object first and then set the new values. |
| 345 | 345 | // Otherwise we instantiate a new object for save. |
| 346 | - if (! empty($datetime_data['DTT_ID'])) { |
|
| 346 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
| 347 | 347 | $datetime = EE_Registry::instance() |
| 348 | 348 | ->load_model('Datetime', array($timezone)) |
| 349 | 349 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | // after the add_relation_to() the autosave replaces it. |
| 358 | 358 | // We need to do this so we dont' TRASH the parent DTT. |
| 359 | 359 | // (save the ID for both key and value to avoid duplications) |
| 360 | - $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID(); |
|
| 360 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
| 361 | 361 | } else { |
| 362 | 362 | $datetime = EE_Registry::instance()->load_class( |
| 363 | 363 | 'Datetime', |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | // because it is possible there was a new one created for the autosave. |
| 394 | 394 | // (save the ID for both key and value to avoid duplications) |
| 395 | 395 | $DTT_ID = $datetime->ID(); |
| 396 | - $saved_dtt_ids[ $DTT_ID ] = $DTT_ID; |
|
| 397 | - $saved_dtt_objs[ $row ] = $datetime; |
|
| 396 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
| 397 | + $saved_dtt_objs[$row] = $datetime; |
|
| 398 | 398 | // @todo if ANY of these updates fail then we want the appropriate global error message. |
| 399 | 399 | } |
| 400 | 400 | $event->save(); |
@@ -459,13 +459,13 @@ discard block |
||
| 459 | 459 | $update_prices = $create_new_TKT = false; |
| 460 | 460 | // figure out what datetimes were added to the ticket |
| 461 | 461 | // and what datetimes were removed from the ticket in the session. |
| 462 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]); |
|
| 463 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]); |
|
| 462 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
| 463 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
| 464 | 464 | $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
| 465 | 465 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
| 466 | 466 | // trim inputs to ensure any excess whitespace is removed. |
| 467 | 467 | $tkt = array_map( |
| 468 | - function ($ticket_data) { |
|
| 468 | + function($ticket_data) { |
|
| 469 | 469 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
| 470 | 470 | }, |
| 471 | 471 | $tkt |
@@ -487,8 +487,8 @@ discard block |
||
| 487 | 487 | $base_price_id = isset($tkt['TKT_base_price_ID']) |
| 488 | 488 | ? $tkt['TKT_base_price_ID'] |
| 489 | 489 | : 0; |
| 490 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ]) |
|
| 491 | - ? $data['edit_prices'][ $row ] |
|
| 490 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
| 491 | + ? $data['edit_prices'][$row] |
|
| 492 | 492 | : array(); |
| 493 | 493 | $now = null; |
| 494 | 494 | if (empty($tkt['TKT_start_date'])) { |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | /** |
| 501 | 501 | * set the TKT_end_date to the first datetime attached to the ticket. |
| 502 | 502 | */ |
| 503 | - $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ]; |
|
| 503 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
| 504 | 504 | $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
| 505 | 505 | } |
| 506 | 506 | $TKT_values = array( |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | // need to make sue that the TKT_price is accurate after saving the prices. |
| 636 | 636 | $ticket->ensure_TKT_Price_correct(); |
| 637 | 637 | // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
| 638 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 638 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
| 639 | 639 | $update_prices = true; |
| 640 | 640 | $new_default = clone $ticket; |
| 641 | 641 | $new_default->set('TKT_ID', 0); |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | // save new TKT |
| 681 | 681 | $new_tkt->save(); |
| 682 | 682 | // add new ticket to array |
| 683 | - $saved_tickets[ $new_tkt->ID() ] = $new_tkt; |
|
| 683 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
| 684 | 684 | do_action( |
| 685 | 685 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
| 686 | 686 | $new_tkt, |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | ); |
| 691 | 691 | } else { |
| 692 | 692 | // add tkt to saved tkts |
| 693 | - $saved_tickets[ $ticket->ID() ] = $ticket; |
|
| 693 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
| 694 | 694 | do_action( |
| 695 | 695 | 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
| 696 | 696 | $ticket, |
@@ -757,31 +757,31 @@ discard block |
||
| 757 | 757 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
| 758 | 758 | // and removing the ticket from datetimes it got removed from. |
| 759 | 759 | // first let's add datetimes |
| 760 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 760 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
| 761 | 761 | foreach ($added_datetimes as $row_id) { |
| 762 | 762 | $row_id = (int) $row_id; |
| 763 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 764 | - $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 763 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 764 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 765 | 765 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 766 | 766 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
| 767 | 767 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 768 | - $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false); |
|
| 768 | + $saved_datetimes[$row_id]->increaseSold($ticket->sold(), false); |
|
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | 773 | // then remove datetimes |
| 774 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 774 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
| 775 | 775 | foreach ($removed_datetimes as $row_id) { |
| 776 | 776 | $row_id = (int) $row_id; |
| 777 | 777 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
| 778 | 778 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
| 779 | - if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) { |
|
| 780 | - $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime'); |
|
| 779 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
| 780 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
| 781 | 781 | // Is this an existing ticket (has an ID) and does it have any sold? |
| 782 | 782 | // If so, then we need to remove it's sold from the DTT_sold. |
| 783 | 783 | if ($ticket->ID() && $ticket->sold() > 0) { |
| 784 | - $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold()); |
|
| 784 | + $saved_datetimes[$row_id]->decreaseSold($ticket->sold()); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | } |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | ); |
| 895 | 895 | } |
| 896 | 896 | // possibly need to save tkt |
| 897 | - if (! $ticket->ID()) { |
|
| 897 | + if ( ! $ticket->ID()) { |
|
| 898 | 898 | $ticket->save(); |
| 899 | 899 | } |
| 900 | 900 | foreach ($prices as $row => $prc) { |
@@ -928,17 +928,17 @@ discard block |
||
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | $price->save(); |
| 931 | - $updated_prices[ $price->ID() ] = $price; |
|
| 931 | + $updated_prices[$price->ID()] = $price; |
|
| 932 | 932 | $ticket->_add_relation_to($price, 'Price'); |
| 933 | 933 | } |
| 934 | 934 | // now let's remove any prices that got removed from the ticket |
| 935 | - if (! empty($current_prices_on_ticket)) { |
|
| 935 | + if ( ! empty($current_prices_on_ticket)) { |
|
| 936 | 936 | $current = array_keys($current_prices_on_ticket); |
| 937 | 937 | $updated = array_keys($updated_prices); |
| 938 | 938 | $prices_to_remove = array_diff($current, $updated); |
| 939 | - if (! empty($prices_to_remove)) { |
|
| 939 | + if ( ! empty($prices_to_remove)) { |
|
| 940 | 940 | foreach ($prices_to_remove as $prc_id) { |
| 941 | - $p = $current_prices_on_ticket[ $prc_id ]; |
|
| 941 | + $p = $current_prices_on_ticket[$prc_id]; |
|
| 942 | 942 | $ticket->_remove_relation_to($p, 'Price'); |
| 943 | 943 | // delete permanently the price |
| 944 | 944 | $p->delete_permanently(); |
@@ -1089,17 +1089,17 @@ discard block |
||
| 1089 | 1089 | $TKT_ID = $ticket->get('TKT_ID'); |
| 1090 | 1090 | $ticket_row = $ticket->get('TKT_row'); |
| 1091 | 1091 | // we only want unique tickets in our final display!! |
| 1092 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1092 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
| 1093 | 1093 | $existing_ticket_ids[] = $TKT_ID; |
| 1094 | 1094 | $all_tickets[] = $ticket; |
| 1095 | 1095 | } |
| 1096 | 1096 | // temporary cache of this ticket info for this datetime for later processing of datetime rows. |
| 1097 | - $datetime_tickets[ $DTT_ID ][] = $ticket_row; |
|
| 1097 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
| 1098 | 1098 | // temporary cache of this datetime info for this ticket for later processing of ticket rows. |
| 1099 | - if (! isset($ticket_datetimes[ $TKT_ID ]) |
|
| 1100 | - || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true) |
|
| 1099 | + if ( ! isset($ticket_datetimes[$TKT_ID]) |
|
| 1100 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
| 1101 | 1101 | ) { |
| 1102 | - $ticket_datetimes[ $TKT_ID ][] = $datetime_row; |
|
| 1102 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
| 1103 | 1103 | } |
| 1104 | 1104 | } |
| 1105 | 1105 | $datetime_row++; |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | // sort $all_tickets by order |
| 1111 | 1111 | usort( |
| 1112 | 1112 | $all_tickets, |
| 1113 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 1113 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 1114 | 1114 | $a_order = (int) $a->get('TKT_order'); |
| 1115 | 1115 | $b_order = (int) $b->get('TKT_order'); |
| 1116 | 1116 | if ($a_order === $b_order) { |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | } |
| 1149 | 1149 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
| 1150 | 1150 | EEH_Template::display_template( |
| 1151 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
| 1151 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
| 1152 | 1152 | $main_template_args |
| 1153 | 1153 | ); |
| 1154 | 1154 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
| 1191 | 1191 | ); |
| 1192 | 1192 | return EEH_Template::display_template( |
| 1193 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
| 1193 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
| 1194 | 1194 | $dtt_display_template_args, |
| 1195 | 1195 | true |
| 1196 | 1196 | ); |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | $this->_is_creating_event |
| 1260 | 1260 | ); |
| 1261 | 1261 | return EEH_Template::display_template( |
| 1262 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
| 1262 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
| 1263 | 1263 | $template_args, |
| 1264 | 1264 | true |
| 1265 | 1265 | ); |
@@ -1300,7 +1300,7 @@ discard block |
||
| 1300 | 1300 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
| 1301 | 1301 | ); |
| 1302 | 1302 | // need to setup the list items (but only if this isn't a default skeleton setup) |
| 1303 | - if (! $default) { |
|
| 1303 | + if ( ! $default) { |
|
| 1304 | 1304 | $ticket_row = 1; |
| 1305 | 1305 | foreach ($all_tickets as $ticket) { |
| 1306 | 1306 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1326,7 +1326,7 @@ discard block |
||
| 1326 | 1326 | $this->_is_creating_event |
| 1327 | 1327 | ); |
| 1328 | 1328 | return EEH_Template::display_template( |
| 1329 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1329 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
| 1330 | 1330 | $template_args, |
| 1331 | 1331 | true |
| 1332 | 1332 | ); |
@@ -1352,8 +1352,8 @@ discard block |
||
| 1352 | 1352 | $datetime_tickets = array(), |
| 1353 | 1353 | $default = false |
| 1354 | 1354 | ) { |
| 1355 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ]) |
|
| 1356 | - ? $datetime_tickets[ $datetime->ID() ] |
|
| 1355 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
| 1356 | + ? $datetime_tickets[$datetime->ID()] |
|
| 1357 | 1357 | : array(); |
| 1358 | 1358 | $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
| 1359 | 1359 | $no_ticket = $default && empty($ticket); |
@@ -1374,8 +1374,8 @@ discard block |
||
| 1374 | 1374 | ? 'TKTNAME' |
| 1375 | 1375 | : $ticket->get('TKT_name'), |
| 1376 | 1376 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
| 1377 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1378 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
| 1377 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1378 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
| 1379 | 1379 | ); |
| 1380 | 1380 | // filter template args |
| 1381 | 1381 | $template_args = apply_filters( |
@@ -1390,7 +1390,7 @@ discard block |
||
| 1390 | 1390 | $this->_is_creating_event |
| 1391 | 1391 | ); |
| 1392 | 1392 | return EEH_Template::display_template( |
| 1393 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1393 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
| 1394 | 1394 | $template_args, |
| 1395 | 1395 | true |
| 1396 | 1396 | ); |
@@ -1446,19 +1446,19 @@ discard block |
||
| 1446 | 1446 | // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
| 1447 | 1447 | // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
| 1448 | 1448 | $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
| 1449 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 1450 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 1449 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 1450 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 1451 | 1451 | : array(); |
| 1452 | 1452 | $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
| 1453 | 1453 | $base_price = $default ? null : $ticket->base_price(); |
| 1454 | 1454 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
| 1455 | 1455 | // breaking out complicated condition for ticket_status |
| 1456 | 1456 | if ($default) { |
| 1457 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1457 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1458 | 1458 | } else { |
| 1459 | 1459 | $ticket_status_class = $ticket->is_default() |
| 1460 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
| 1461 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
| 1460 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
| 1461 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
| 1462 | 1462 | } |
| 1463 | 1463 | // breaking out complicated condition for TKT_taxable |
| 1464 | 1464 | if ($default) { |
@@ -1550,7 +1550,7 @@ discard block |
||
| 1550 | 1550 | : ' style="display:none;"', |
| 1551 | 1551 | 'show_price_mod_button' => count($prices) > 1 |
| 1552 | 1552 | || ($default && $count_price_mods > 0) |
| 1553 | - || (! $default && $ticket->deleted()) |
|
| 1553 | + || ( ! $default && $ticket->deleted()) |
|
| 1554 | 1554 | ? ' style="display:none;"' |
| 1555 | 1555 | : '', |
| 1556 | 1556 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1594,7 +1594,7 @@ discard block |
||
| 1594 | 1594 | $this->_date_time_format, |
| 1595 | 1595 | current_time('timestamp') |
| 1596 | 1596 | ); |
| 1597 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1597 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1598 | 1598 | } |
| 1599 | 1599 | if (empty($template_args['TKT_end_date'])) { |
| 1600 | 1600 | // get the earliest datetime (if present); |
@@ -1604,7 +1604,7 @@ discard block |
||
| 1604 | 1604 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
| 1605 | 1605 | ) |
| 1606 | 1606 | : null; |
| 1607 | - if (! empty($earliest_dtt)) { |
|
| 1607 | + if ( ! empty($earliest_dtt)) { |
|
| 1608 | 1608 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
| 1609 | 1609 | 'DTT_EVT_start', |
| 1610 | 1610 | $this->_date_time_format |
@@ -1623,10 +1623,10 @@ discard block |
||
| 1623 | 1623 | ) |
| 1624 | 1624 | ); |
| 1625 | 1625 | } |
| 1626 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
| 1626 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
| 1627 | 1627 | } |
| 1628 | 1628 | // generate ticket_datetime items |
| 1629 | - if (! $default) { |
|
| 1629 | + if ( ! $default) { |
|
| 1630 | 1630 | $datetime_row = 1; |
| 1631 | 1631 | foreach ($all_datetimes as $datetime) { |
| 1632 | 1632 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1642,7 +1642,7 @@ discard block |
||
| 1642 | 1642 | } |
| 1643 | 1643 | $price_row = 1; |
| 1644 | 1644 | foreach ($prices as $price) { |
| 1645 | - if (! $price instanceof EE_Price) { |
|
| 1645 | + if ( ! $price instanceof EE_Price) { |
|
| 1646 | 1646 | continue; |
| 1647 | 1647 | } |
| 1648 | 1648 | if ($price->is_base_price()) { |
@@ -1675,7 +1675,7 @@ discard block |
||
| 1675 | 1675 | $this->_is_creating_event |
| 1676 | 1676 | ); |
| 1677 | 1677 | return EEH_Template::display_template( |
| 1678 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
| 1678 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
| 1679 | 1679 | $template_args, |
| 1680 | 1680 | true |
| 1681 | 1681 | ); |
@@ -1715,7 +1715,7 @@ discard block |
||
| 1715 | 1715 | $this->_is_creating_event |
| 1716 | 1716 | ); |
| 1717 | 1717 | $tax_rows .= EEH_Template::display_template( |
| 1718 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1718 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
| 1719 | 1719 | $template_args, |
| 1720 | 1720 | true |
| 1721 | 1721 | ); |
@@ -1834,7 +1834,7 @@ discard block |
||
| 1834 | 1834 | $this->_is_creating_event |
| 1835 | 1835 | ); |
| 1836 | 1836 | return EEH_Template::display_template( |
| 1837 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1837 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
| 1838 | 1838 | $template_args, |
| 1839 | 1839 | true |
| 1840 | 1840 | ); |
@@ -1904,7 +1904,7 @@ discard block |
||
| 1904 | 1904 | $this->_is_creating_event |
| 1905 | 1905 | ); |
| 1906 | 1906 | return EEH_Template::display_template( |
| 1907 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
| 1907 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
| 1908 | 1908 | $template_args, |
| 1909 | 1909 | true |
| 1910 | 1910 | ); |
@@ -1934,7 +1934,7 @@ discard block |
||
| 1934 | 1934 | ) { |
| 1935 | 1935 | $select_name = $default && ! $price instanceof EE_Price |
| 1936 | 1936 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
| 1937 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
| 1937 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
| 1938 | 1938 | /** @var EEM_Price_Type $price_type_model */ |
| 1939 | 1939 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
| 1940 | 1940 | $price_types = $price_type_model->get_all(array( |
@@ -1952,10 +1952,10 @@ discard block |
||
| 1952 | 1952 | $price_option_spans = ''; |
| 1953 | 1953 | // setup price types for selector |
| 1954 | 1954 | foreach ($price_types as $price_type) { |
| 1955 | - if (! $price_type instanceof EE_Price_Type) { |
|
| 1955 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
| 1956 | 1956 | continue; |
| 1957 | 1957 | } |
| 1958 | - $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name'); |
|
| 1958 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
| 1959 | 1959 | // while we're in the loop let's setup the option spans used by js |
| 1960 | 1960 | $span_args = array( |
| 1961 | 1961 | 'PRT_ID' => $price_type->ID(), |
@@ -1963,12 +1963,12 @@ discard block |
||
| 1963 | 1963 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
| 1964 | 1964 | ); |
| 1965 | 1965 | $price_option_spans .= EEH_Template::display_template( |
| 1966 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
| 1966 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
| 1967 | 1967 | $span_args, |
| 1968 | 1968 | true |
| 1969 | 1969 | ); |
| 1970 | 1970 | } |
| 1971 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' |
|
| 1971 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' |
|
| 1972 | 1972 | : $select_name; |
| 1973 | 1973 | $select_input = new EE_Select_Input( |
| 1974 | 1974 | $all_price_types, |
@@ -2005,7 +2005,7 @@ discard block |
||
| 2005 | 2005 | $this->_is_creating_event |
| 2006 | 2006 | ); |
| 2007 | 2007 | return EEH_Template::display_template( |
| 2008 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2008 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
| 2009 | 2009 | $template_args, |
| 2010 | 2010 | true |
| 2011 | 2011 | ); |
@@ -2031,8 +2031,8 @@ discard block |
||
| 2031 | 2031 | $ticket_datetimes = array(), |
| 2032 | 2032 | $default = false |
| 2033 | 2033 | ) { |
| 2034 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ]) |
|
| 2035 | - ? $ticket_datetimes[ $ticket->ID() ] |
|
| 2034 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
| 2035 | + ? $ticket_datetimes[$ticket->ID()] |
|
| 2036 | 2036 | : array(); |
| 2037 | 2037 | $template_args = array( |
| 2038 | 2038 | 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
@@ -2064,7 +2064,7 @@ discard block |
||
| 2064 | 2064 | $this->_is_creating_event |
| 2065 | 2065 | ); |
| 2066 | 2066 | return EEH_Template::display_template( |
| 2067 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2067 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
| 2068 | 2068 | $template_args, |
| 2069 | 2069 | true |
| 2070 | 2070 | ); |
@@ -2170,7 +2170,7 @@ discard block |
||
| 2170 | 2170 | $default_prices = $price_model->get_all_default_prices(); |
| 2171 | 2171 | $price_row = 1; |
| 2172 | 2172 | foreach ($default_prices as $price) { |
| 2173 | - if (! $price instanceof EE_Price) { |
|
| 2173 | + if ( ! $price instanceof EE_Price) { |
|
| 2174 | 2174 | continue; |
| 2175 | 2175 | } |
| 2176 | 2176 | if ($price->is_base_price()) { |
@@ -2207,7 +2207,7 @@ discard block |
||
| 2207 | 2207 | $this->_is_creating_event |
| 2208 | 2208 | ); |
| 2209 | 2209 | return EEH_Template::display_template( |
| 2210 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2210 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
| 2211 | 2211 | $template_args, |
| 2212 | 2212 | true |
| 2213 | 2213 | ); |
@@ -12,1424 +12,1424 @@ |
||
| 12 | 12 | class Pricing_Admin_Page extends EE_Admin_Page |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * constructor |
|
| 17 | - * |
|
| 18 | - * @Constructor |
|
| 19 | - * @access public |
|
| 20 | - * @param bool $routing |
|
| 21 | - * @return Pricing_Admin_Page |
|
| 22 | - */ |
|
| 23 | - public function __construct($routing = true) |
|
| 24 | - { |
|
| 25 | - parent::__construct($routing); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - protected function _init_page_props() |
|
| 30 | - { |
|
| 31 | - $this->page_slug = PRICING_PG_SLUG; |
|
| 32 | - $this->page_label = PRICING_LABEL; |
|
| 33 | - $this->_admin_base_url = PRICING_ADMIN_URL; |
|
| 34 | - $this->_admin_base_path = PRICING_ADMIN; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - protected function _ajax_hooks() |
|
| 39 | - { |
|
| 40 | - add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - protected function _define_page_props() |
|
| 45 | - { |
|
| 46 | - $this->_admin_page_title = PRICING_LABEL; |
|
| 47 | - $this->_labels = array( |
|
| 48 | - 'buttons' => array( |
|
| 49 | - 'add' => __('Add New Default Price', 'event_espresso'), |
|
| 50 | - 'edit' => __('Edit Default Price', 'event_espresso'), |
|
| 51 | - 'delete' => __('Delete Default Price', 'event_espresso'), |
|
| 52 | - 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
| 53 | - 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
| 54 | - 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
| 55 | - ), |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * an array for storing request actions and their corresponding methods |
|
| 62 | - * |
|
| 63 | - * @access private |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - protected function _set_page_routes() |
|
| 67 | - { |
|
| 68 | - $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
| 69 | - ? $this->_req_data['PRC_ID'] : 0; |
|
| 70 | - $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
| 71 | - ? $this->_req_data['PRT_ID'] : 0; |
|
| 72 | - $this->_page_routes = array( |
|
| 73 | - 'default' => array( |
|
| 74 | - 'func' => '_price_overview_list_table', |
|
| 75 | - 'capability' => 'ee_read_default_prices', |
|
| 76 | - ), |
|
| 77 | - 'add_new_price' => array( |
|
| 78 | - 'func' => '_edit_price_details', |
|
| 79 | - 'capability' => 'ee_edit_default_prices', |
|
| 80 | - ), |
|
| 81 | - 'edit_price' => array( |
|
| 82 | - 'func' => '_edit_price_details', |
|
| 83 | - 'capability' => 'ee_edit_default_price', |
|
| 84 | - 'obj_id' => $prc_id, |
|
| 85 | - ), |
|
| 86 | - 'insert_price' => array( |
|
| 87 | - 'func' => '_insert_or_update_price', |
|
| 88 | - 'args' => array('insert' => true), |
|
| 89 | - 'noheader' => true, |
|
| 90 | - 'capability' => 'ee_edit_default_prices', |
|
| 91 | - ), |
|
| 92 | - 'update_price' => array( |
|
| 93 | - 'func' => '_insert_or_update_price', |
|
| 94 | - 'args' => array('insert' => false), |
|
| 95 | - 'noheader' => true, |
|
| 96 | - 'capability' => 'ee_edit_default_price', |
|
| 97 | - 'obj_id' => $prc_id, |
|
| 98 | - ), |
|
| 99 | - 'trash_price' => array( |
|
| 100 | - 'func' => '_trash_or_restore_price', |
|
| 101 | - 'args' => array('trash' => true), |
|
| 102 | - 'noheader' => true, |
|
| 103 | - 'capability' => 'ee_delete_default_price', |
|
| 104 | - 'obj_id' => $prc_id, |
|
| 105 | - ), |
|
| 106 | - 'restore_price' => array( |
|
| 107 | - 'func' => '_trash_or_restore_price', |
|
| 108 | - 'args' => array('trash' => false), |
|
| 109 | - 'noheader' => true, |
|
| 110 | - 'capability' => 'ee_delete_default_price', |
|
| 111 | - 'obj_id' => $prc_id, |
|
| 112 | - ), |
|
| 113 | - 'delete_price' => array( |
|
| 114 | - 'func' => '_delete_price', |
|
| 115 | - 'noheader' => true, |
|
| 116 | - 'capability' => 'ee_delete_default_price', |
|
| 117 | - 'obj_id' => $prc_id, |
|
| 118 | - ), |
|
| 119 | - 'espresso_update_price_order' => array( |
|
| 120 | - 'func' => 'update_price_order', |
|
| 121 | - 'noheader' => true, |
|
| 122 | - 'capability' => 'ee_edit_default_prices', |
|
| 123 | - ), |
|
| 124 | - // price types |
|
| 125 | - 'price_types' => array( |
|
| 126 | - 'func' => '_price_types_overview_list_table', |
|
| 127 | - 'capability' => 'ee_read_default_price_types', |
|
| 128 | - ), |
|
| 129 | - 'add_new_price_type' => array( |
|
| 130 | - 'func' => '_edit_price_type_details', |
|
| 131 | - 'capability' => 'ee_edit_default_price_types', |
|
| 132 | - ), |
|
| 133 | - 'edit_price_type' => array( |
|
| 134 | - 'func' => '_edit_price_type_details', |
|
| 135 | - 'capability' => 'ee_edit_default_price_type', |
|
| 136 | - 'obj_id' => $prt_id, |
|
| 137 | - ), |
|
| 138 | - 'insert_price_type' => array( |
|
| 139 | - 'func' => '_insert_or_update_price_type', |
|
| 140 | - 'args' => array('new_price_type' => true), |
|
| 141 | - 'noheader' => true, |
|
| 142 | - 'capability' => 'ee_edit_default_price_types', |
|
| 143 | - ), |
|
| 144 | - 'update_price_type' => array( |
|
| 145 | - 'func' => '_insert_or_update_price_type', |
|
| 146 | - 'args' => array('new_price_type' => false), |
|
| 147 | - 'noheader' => true, |
|
| 148 | - 'capability' => 'ee_edit_default_price_type', |
|
| 149 | - 'obj_id' => $prt_id, |
|
| 150 | - ), |
|
| 151 | - 'trash_price_type' => array( |
|
| 152 | - 'func' => '_trash_or_restore_price_type', |
|
| 153 | - 'args' => array('trash' => true), |
|
| 154 | - 'noheader' => true, |
|
| 155 | - 'capability' => 'ee_delete_default_price_type', |
|
| 156 | - 'obj_id' => $prt_id, |
|
| 157 | - ), |
|
| 158 | - 'restore_price_type' => array( |
|
| 159 | - 'func' => '_trash_or_restore_price_type', |
|
| 160 | - 'args' => array('trash' => false), |
|
| 161 | - 'noheader' => true, |
|
| 162 | - 'capability' => 'ee_delete_default_price_type', |
|
| 163 | - 'obj_id' => $prt_id, |
|
| 164 | - ), |
|
| 165 | - 'delete_price_type' => array( |
|
| 166 | - 'func' => '_delete_price_type', |
|
| 167 | - 'noheader' => true, |
|
| 168 | - 'capability' => 'ee_delete_default_price_type', |
|
| 169 | - 'obj_id' => $prt_id, |
|
| 170 | - ), |
|
| 171 | - 'tax_settings' => array( |
|
| 172 | - 'func' => '_tax_settings', |
|
| 173 | - 'capability' => 'manage_options', |
|
| 174 | - ), |
|
| 175 | - 'update_tax_settings' => array( |
|
| 176 | - 'func' => '_update_tax_settings', |
|
| 177 | - 'capability' => 'manage_options', |
|
| 178 | - 'noheader' => true, |
|
| 179 | - ), |
|
| 180 | - ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - protected function _set_page_config() |
|
| 185 | - { |
|
| 186 | - |
|
| 187 | - $this->_page_config = array( |
|
| 188 | - 'default' => array( |
|
| 189 | - 'nav' => array( |
|
| 190 | - 'label' => __('Default Pricing', 'event_espresso'), |
|
| 191 | - 'order' => 10, |
|
| 192 | - ), |
|
| 193 | - 'list_table' => 'Prices_List_Table', |
|
| 194 | - 'help_tabs' => array( |
|
| 195 | - 'pricing_default_pricing_help_tab' => array( |
|
| 196 | - 'title' => __('Default Pricing', 'event_espresso'), |
|
| 197 | - 'filename' => 'pricing_default_pricing', |
|
| 198 | - ), |
|
| 199 | - 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
| 200 | - 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
| 201 | - 'filename' => 'pricing_default_pricing_table_column_headings', |
|
| 202 | - ), |
|
| 203 | - 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
| 204 | - 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
| 205 | - 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
| 206 | - ), |
|
| 207 | - ), |
|
| 208 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 209 | - // 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
| 210 | - 'require_nonce' => false, |
|
| 211 | - ), |
|
| 212 | - 'add_new_price' => array( |
|
| 213 | - 'nav' => array( |
|
| 214 | - 'label' => __('Add New Default Price', 'event_espresso'), |
|
| 215 | - 'order' => 20, |
|
| 216 | - 'persistent' => false, |
|
| 217 | - ), |
|
| 218 | - 'help_tabs' => array( |
|
| 219 | - 'add_new_default_price_help_tab' => array( |
|
| 220 | - 'title' => __('Add New Default Price', 'event_espresso'), |
|
| 221 | - 'filename' => 'pricing_add_new_default_price', |
|
| 222 | - ), |
|
| 223 | - ), |
|
| 224 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 225 | - // 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
| 226 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 227 | - 'require_nonce' => false, |
|
| 228 | - ), |
|
| 229 | - 'edit_price' => array( |
|
| 230 | - 'nav' => array( |
|
| 231 | - 'label' => __('Edit Default Price', 'event_espresso'), |
|
| 232 | - 'order' => 20, |
|
| 233 | - 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
| 234 | - array('id' => $this->_req_data['id']), |
|
| 235 | - $this->_current_page_view_url |
|
| 236 | - ) : $this->_admin_base_url, |
|
| 237 | - 'persistent' => false, |
|
| 238 | - ), |
|
| 239 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 240 | - 'help_tabs' => array( |
|
| 241 | - 'edit_default_price_help_tab' => array( |
|
| 242 | - 'title' => __('Edit Default Price', 'event_espresso'), |
|
| 243 | - 'filename' => 'pricing_edit_default_price', |
|
| 244 | - ), |
|
| 245 | - ), |
|
| 246 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 247 | - // 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
| 248 | - 'require_nonce' => false, |
|
| 249 | - ), |
|
| 250 | - 'price_types' => array( |
|
| 251 | - 'nav' => array( |
|
| 252 | - 'label' => __('Price Types', 'event_espresso'), |
|
| 253 | - 'order' => 30, |
|
| 254 | - ), |
|
| 255 | - 'list_table' => 'Price_Types_List_Table', |
|
| 256 | - 'help_tabs' => array( |
|
| 257 | - 'pricing_price_types_help_tab' => array( |
|
| 258 | - 'title' => __('Price Types', 'event_espresso'), |
|
| 259 | - 'filename' => 'pricing_price_types', |
|
| 260 | - ), |
|
| 261 | - 'pricing_price_types_table_column_headings_help_tab' => array( |
|
| 262 | - 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
| 263 | - 'filename' => 'pricing_price_types_table_column_headings', |
|
| 264 | - ), |
|
| 265 | - 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
| 266 | - 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
| 267 | - 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
| 268 | - ), |
|
| 269 | - ), |
|
| 270 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 271 | - // 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
| 272 | - 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 273 | - 'require_nonce' => false, |
|
| 274 | - ), |
|
| 275 | - 'add_new_price_type' => array( |
|
| 276 | - 'nav' => array( |
|
| 277 | - 'label' => __('Add New Price Type', 'event_espresso'), |
|
| 278 | - 'order' => 40, |
|
| 279 | - 'persistent' => false, |
|
| 280 | - ), |
|
| 281 | - 'help_tabs' => array( |
|
| 282 | - 'add_new_price_type_help_tab' => array( |
|
| 283 | - 'title' => __('Add New Price Type', 'event_espresso'), |
|
| 284 | - 'filename' => 'pricing_add_new_price_type', |
|
| 285 | - ), |
|
| 286 | - ), |
|
| 287 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 288 | - // 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
| 289 | - 'metaboxes' => array( |
|
| 290 | - '_publish_post_box', |
|
| 291 | - '_espresso_news_post_box', |
|
| 292 | - '_price_type_details_meta_boxes', |
|
| 293 | - ), |
|
| 294 | - 'require_nonce' => false, |
|
| 295 | - ), |
|
| 296 | - 'edit_price_type' => array( |
|
| 297 | - 'nav' => array( |
|
| 298 | - 'label' => __('Edit Price Type', 'event_espresso'), |
|
| 299 | - 'order' => 40, |
|
| 300 | - 'persistent' => false, |
|
| 301 | - ), |
|
| 302 | - 'help_tabs' => array( |
|
| 303 | - 'edit_price_type_help_tab' => array( |
|
| 304 | - 'title' => __('Edit Price Type', 'event_espresso'), |
|
| 305 | - 'filename' => 'pricing_edit_price_type', |
|
| 306 | - ), |
|
| 307 | - ), |
|
| 308 | - // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 309 | - // 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
| 310 | - 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
| 311 | - |
|
| 312 | - 'require_nonce' => false, |
|
| 313 | - ), |
|
| 314 | - 'tax_settings' => array( |
|
| 315 | - 'nav' => array( |
|
| 316 | - 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
| 317 | - 'order' => 40, |
|
| 318 | - ), |
|
| 319 | - 'labels' => array( |
|
| 320 | - 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
| 321 | - ), |
|
| 322 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 323 | - // 'help_tabs' => array( |
|
| 324 | - // 'registration_form_reg_form_settings_help_tab' => array( |
|
| 325 | - // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 326 | - // 'filename' => 'registration_form_reg_form_settings' |
|
| 327 | - // ), |
|
| 328 | - // ), |
|
| 329 | - // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 330 | - 'require_nonce' => true, |
|
| 331 | - ), |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - protected function _add_screen_options() |
|
| 337 | - { |
|
| 338 | - // todo |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - protected function _add_screen_options_default() |
|
| 343 | - { |
|
| 344 | - $this->_per_page_screen_option(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - protected function _add_screen_options_price_types() |
|
| 349 | - { |
|
| 350 | - $page_title = $this->_admin_page_title; |
|
| 351 | - $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
| 352 | - $this->_per_page_screen_option(); |
|
| 353 | - $this->_admin_page_title = $page_title; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - protected function _add_feature_pointers() |
|
| 358 | - { |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - public function load_scripts_styles() |
|
| 363 | - { |
|
| 364 | - // styles |
|
| 365 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 366 | - wp_register_style( |
|
| 367 | - 'espresso_PRICING', |
|
| 368 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
| 369 | - array(), |
|
| 370 | - EVENT_ESPRESSO_VERSION |
|
| 371 | - ); |
|
| 372 | - wp_enqueue_style('espresso_PRICING'); |
|
| 373 | - |
|
| 374 | - // scripts |
|
| 375 | - wp_enqueue_script('ee_admin_js'); |
|
| 376 | - wp_enqueue_script('jquery-ui-position'); |
|
| 377 | - wp_enqueue_script('jquery-ui-widget'); |
|
| 378 | - // wp_enqueue_script('jquery-ui-dialog'); |
|
| 379 | - // wp_enqueue_script('jquery-ui-draggable'); |
|
| 380 | - // wp_enqueue_script('jquery-ui-datepicker'); |
|
| 381 | - wp_register_script( |
|
| 382 | - 'espresso_PRICING', |
|
| 383 | - PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
| 384 | - array('jquery'), |
|
| 385 | - EVENT_ESPRESSO_VERSION, |
|
| 386 | - true |
|
| 387 | - ); |
|
| 388 | - wp_enqueue_script('espresso_PRICING'); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - public function load_scripts_styles_default() |
|
| 393 | - { |
|
| 394 | - wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - public function admin_footer_scripts() |
|
| 399 | - { |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - public function admin_init() |
|
| 403 | - { |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - public function admin_notices() |
|
| 407 | - { |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - protected function _set_list_table_views_default() |
|
| 412 | - { |
|
| 413 | - $this->_views = array( |
|
| 414 | - 'all' => array( |
|
| 415 | - 'slug' => 'all', |
|
| 416 | - 'label' => __('View All Default Pricing', 'event_espresso'), |
|
| 417 | - 'count' => 0, |
|
| 418 | - 'bulk_action' => array( |
|
| 419 | - 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
| 420 | - ), |
|
| 421 | - ), |
|
| 422 | - ); |
|
| 423 | - |
|
| 424 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 425 | - $this->_views['trashed'] = array( |
|
| 426 | - 'slug' => 'trashed', |
|
| 427 | - 'label' => __('Trash', 'event_espresso'), |
|
| 428 | - 'count' => 0, |
|
| 429 | - 'bulk_action' => array( |
|
| 430 | - 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
| 431 | - 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
| 432 | - ), |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - protected function _set_list_table_views_price_types() |
|
| 439 | - { |
|
| 440 | - $this->_views = array( |
|
| 441 | - 'all' => array( |
|
| 442 | - 'slug' => 'all', |
|
| 443 | - 'label' => __('All', 'event_espresso'), |
|
| 444 | - 'count' => 0, |
|
| 445 | - 'bulk_action' => array( |
|
| 446 | - 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
| 447 | - ), |
|
| 448 | - ), |
|
| 449 | - ); |
|
| 450 | - |
|
| 451 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 452 | - 'ee_delete_default_price_types', |
|
| 453 | - 'pricing_trash_price_type' |
|
| 454 | - )) { |
|
| 455 | - $this->_views['trashed'] = array( |
|
| 456 | - 'slug' => 'trashed', |
|
| 457 | - 'label' => __('Trash', 'event_espresso'), |
|
| 458 | - 'count' => 0, |
|
| 459 | - 'bulk_action' => array( |
|
| 460 | - 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
| 461 | - 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
| 462 | - ), |
|
| 463 | - ); |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * generates HTML for main Prices Admin page |
|
| 470 | - * |
|
| 471 | - * @access protected |
|
| 472 | - * @return void |
|
| 473 | - */ |
|
| 474 | - protected function _price_overview_list_table() |
|
| 475 | - { |
|
| 476 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 477 | - 'add_new_price', |
|
| 478 | - 'add', |
|
| 479 | - array(), |
|
| 480 | - 'add-new-h2' |
|
| 481 | - ); |
|
| 482 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 483 | - $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
| 484 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * retrieve data for Prices List table |
|
| 490 | - * |
|
| 491 | - * @access public |
|
| 492 | - * @param int $per_page how many prices displayed per page |
|
| 493 | - * @param boolean $count return the count or objects |
|
| 494 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 495 | - * @return mixed (int|array) int = count || array of price objects |
|
| 496 | - */ |
|
| 497 | - public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 498 | - { |
|
| 499 | - |
|
| 500 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 501 | - // start with an empty array |
|
| 502 | - $event_pricing = array(); |
|
| 503 | - |
|
| 504 | - require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
| 505 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 506 | - // $PRC = EEM_Price::instance(); |
|
| 507 | - |
|
| 508 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 509 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 510 | - : 'ASC'; |
|
| 511 | - |
|
| 512 | - switch ($this->_req_data['orderby']) { |
|
| 513 | - case 'name': |
|
| 514 | - $orderby = array('PRC_name' => $order); |
|
| 515 | - break; |
|
| 516 | - case 'type': |
|
| 517 | - $orderby = array('Price_Type.PRT_name' => $order); |
|
| 518 | - break; |
|
| 519 | - case 'amount': |
|
| 520 | - $orderby = array('PRC_amount' => $order); |
|
| 521 | - break; |
|
| 522 | - default: |
|
| 523 | - $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 527 | - ? $this->_req_data['paged'] : 1; |
|
| 528 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 529 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 530 | - |
|
| 531 | - $_where = array( |
|
| 532 | - 'PRC_is_default' => 1, |
|
| 533 | - 'PRC_deleted' => $trashed, |
|
| 534 | - ); |
|
| 535 | - |
|
| 536 | - $offset = ($current_page - 1) * $per_page; |
|
| 537 | - $limit = array($offset, $per_page); |
|
| 538 | - |
|
| 539 | - if (isset($this->_req_data['s'])) { |
|
| 540 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 541 | - $_where['OR'] = array( |
|
| 542 | - 'PRC_name' => array('LIKE', $sstr), |
|
| 543 | - 'PRC_desc' => array('LIKE', $sstr), |
|
| 544 | - 'PRC_amount' => array('LIKE', $sstr), |
|
| 545 | - 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
| 546 | - ); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - $query_params = array( |
|
| 550 | - $_where, |
|
| 551 | - 'order_by' => $orderby, |
|
| 552 | - 'limit' => $limit, |
|
| 553 | - 'group_by' => 'PRC_ID', |
|
| 554 | - ); |
|
| 555 | - |
|
| 556 | - if ($count) { |
|
| 557 | - return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
| 558 | - : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 559 | - } else { |
|
| 560 | - return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * _price_details |
|
| 567 | - * |
|
| 568 | - * @access protected |
|
| 569 | - * @return void |
|
| 570 | - */ |
|
| 571 | - protected function _edit_price_details() |
|
| 572 | - { |
|
| 573 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 574 | - // grab price ID |
|
| 575 | - $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 576 | - : false; |
|
| 577 | - // change page title based on request action |
|
| 578 | - switch ($this->_req_action) { |
|
| 579 | - case 'add_new_price': |
|
| 580 | - $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
| 581 | - break; |
|
| 582 | - case 'edit_price': |
|
| 583 | - $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
| 584 | - break; |
|
| 585 | - default: |
|
| 586 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 587 | - } |
|
| 588 | - // add PRC_ID to title if editing |
|
| 589 | - $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
| 590 | - |
|
| 591 | - // get prices |
|
| 592 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 593 | - $PRC = EEM_Price::instance(); |
|
| 594 | - |
|
| 595 | - if ($PRC_ID) { |
|
| 596 | - $price = $PRC->get_one_by_ID($PRC_ID); |
|
| 597 | - $additional_hidden_fields = array( |
|
| 598 | - 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
| 599 | - ); |
|
| 600 | - $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
| 601 | - } else { |
|
| 602 | - $price = $PRC->get_new_price(); |
|
| 603 | - $this->_set_add_edit_form_tags('insert_price'); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $this->_template_args['PRC_ID'] = $PRC_ID; |
|
| 607 | - $this->_template_args['price'] = $price; |
|
| 608 | - |
|
| 609 | - // get price types |
|
| 610 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 611 | - $PRT = EEM_Price_Type::instance(); |
|
| 612 | - $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
| 613 | - $price_type_names = array(); |
|
| 614 | - if (empty($price_types)) { |
|
| 615 | - $msg = __( |
|
| 616 | - 'You have no price types defined. Please add a price type before adding a price.', |
|
| 617 | - 'event_espresso' |
|
| 618 | - ); |
|
| 619 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 620 | - exit(); |
|
| 621 | - } else { |
|
| 622 | - foreach ($price_types as $type) { |
|
| 623 | - // if ($type->is_global()) { |
|
| 624 | - $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
| 625 | - // } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - $this->_template_args['price_types'] = $price_type_names; |
|
| 630 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 631 | - |
|
| 632 | - $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
| 633 | - // the details template wrapper |
|
| 634 | - $this->display_admin_page_with_sidebar(); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * declare price details page metaboxes |
|
| 640 | - * |
|
| 641 | - * @access protected |
|
| 642 | - * @return void |
|
| 643 | - */ |
|
| 644 | - protected function _price_details_meta_boxes() |
|
| 645 | - { |
|
| 646 | - add_meta_box( |
|
| 647 | - 'edit-price-details-mbox', |
|
| 648 | - __('Default Price Details', 'event_espresso'), |
|
| 649 | - array($this, '_edit_price_details_meta_box'), |
|
| 650 | - $this->wp_page_slug, |
|
| 651 | - 'normal', |
|
| 652 | - 'high' |
|
| 653 | - ); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * _edit_price_details_meta_box |
|
| 659 | - * |
|
| 660 | - * @access public |
|
| 661 | - * @return void |
|
| 662 | - */ |
|
| 663 | - public function _edit_price_details_meta_box() |
|
| 664 | - { |
|
| 665 | - echo EEH_Template::display_template( |
|
| 666 | - PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
| 667 | - $this->_template_args, |
|
| 668 | - true |
|
| 669 | - ); |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * set_price_column_values |
|
| 675 | - * |
|
| 676 | - * @access protected |
|
| 677 | - * @return array |
|
| 678 | - */ |
|
| 679 | - protected function set_price_column_values() |
|
| 680 | - { |
|
| 681 | - |
|
| 682 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 683 | - |
|
| 684 | - $set_column_values = array( |
|
| 685 | - 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
| 686 | - 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
| 687 | - 'PRC_name' => $this->_req_data['PRC_name'], |
|
| 688 | - 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
| 689 | - 'PRC_is_default' => 1, |
|
| 690 | - 'PRC_overrides' => null, |
|
| 691 | - 'PRC_order' => 0, |
|
| 692 | - 'PRC_deleted' => 0, |
|
| 693 | - 'PRC_parent' => 0, |
|
| 694 | - ); |
|
| 695 | - return $set_column_values; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * insert_or_update_price |
|
| 701 | - * |
|
| 702 | - * @param boolean $insert - whether to insert or update |
|
| 703 | - * @access protected |
|
| 704 | - * @return void |
|
| 705 | - */ |
|
| 706 | - protected function _insert_or_update_price($insert = false) |
|
| 707 | - { |
|
| 708 | - |
|
| 709 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 710 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | - |
|
| 712 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 713 | - $PRC = EEM_Price::instance(); |
|
| 714 | - |
|
| 715 | - // why be so pessimistic ??? : ( |
|
| 716 | - $success = 0; |
|
| 717 | - |
|
| 718 | - $set_column_values = $this->set_price_column_values(); |
|
| 719 | - // is this a new Price ? |
|
| 720 | - if ($insert) { |
|
| 721 | - // run the insert |
|
| 722 | - if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
| 723 | - // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
| 724 | - $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
| 725 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 726 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 727 | - $ticket->_add_relation_to($PR, 'Price'); |
|
| 728 | - $ticket->save(); |
|
| 729 | - } |
|
| 730 | - $success = 1; |
|
| 731 | - } else { |
|
| 732 | - $PRC_ID = false; |
|
| 733 | - $success = 0; |
|
| 734 | - } |
|
| 735 | - $action_desc = 'created'; |
|
| 736 | - } else { |
|
| 737 | - $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
| 738 | - // run the update |
|
| 739 | - $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
| 740 | - if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
| 741 | - $success = 1; |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 745 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 746 | - // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
| 747 | - if ($PRC_ID === 1) { |
|
| 748 | - $ticket = $PR->get_first_related('Ticket'); |
|
| 749 | - if ($ticket) { |
|
| 750 | - $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
| 751 | - $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
| 752 | - $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
| 753 | - $ticket->save(); |
|
| 754 | - } |
|
| 755 | - } else { |
|
| 756 | - // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
| 757 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 758 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 759 | - $ticket->save(); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - $action_desc = 'updated'; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
| 767 | - |
|
| 768 | - $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - |
|
| 772 | - /** |
|
| 773 | - * _trash_or_restore_price |
|
| 774 | - * |
|
| 775 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 776 | - * @access protected |
|
| 777 | - * @return void |
|
| 778 | - */ |
|
| 779 | - protected function _trash_or_restore_price($trash = true) |
|
| 780 | - { |
|
| 781 | - |
|
| 782 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 783 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 784 | - |
|
| 785 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 786 | - $PRC = EEM_Price::instance(); |
|
| 787 | - |
|
| 788 | - $success = 1; |
|
| 789 | - $PRC_deleted = $trash ? true : false; |
|
| 790 | - |
|
| 791 | - // get base ticket for updating |
|
| 792 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 793 | - // Checkboxes |
|
| 794 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 795 | - // if array has more than one element than success message should be plural |
|
| 796 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 797 | - // cycle thru checkboxes |
|
| 798 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 799 | - if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
| 800 | - $success = 0; |
|
| 801 | - } else { |
|
| 802 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 803 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 804 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 805 | - if ($PRC_deleted) { |
|
| 806 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 807 | - } else { |
|
| 808 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 809 | - } |
|
| 810 | - $ticket->save(); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - // grab single id and delete |
|
| 816 | - $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 817 | - if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
| 818 | - $success = 0; |
|
| 819 | - } else { |
|
| 820 | - $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 821 | - if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 822 | - // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 823 | - if ($PRC_deleted) { |
|
| 824 | - $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 825 | - } else { |
|
| 826 | - $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 827 | - } |
|
| 828 | - $ticket->save(); |
|
| 829 | - } |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - $query_args = array( |
|
| 833 | - 'action' => 'default', |
|
| 834 | - ); |
|
| 835 | - |
|
| 836 | - if ($success) { |
|
| 837 | - if ($trash) { |
|
| 838 | - $msg = $success == 2 |
|
| 839 | - ? __('The Prices have been trashed.', 'event_espresso') |
|
| 840 | - : __( |
|
| 841 | - 'The Price has been trashed.', |
|
| 842 | - 'event_espresso' |
|
| 843 | - ); |
|
| 844 | - } else { |
|
| 845 | - $msg = $success == 2 |
|
| 846 | - ? __('The Prices have been restored.', 'event_espresso') |
|
| 847 | - : __( |
|
| 848 | - 'The Price has been restored.', |
|
| 849 | - 'event_espresso' |
|
| 850 | - ); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - EE_Error::add_success($msg); |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * _delete_price |
|
| 862 | - * |
|
| 863 | - * @access protected |
|
| 864 | - * @return void |
|
| 865 | - */ |
|
| 866 | - protected function _delete_price() |
|
| 867 | - { |
|
| 868 | - |
|
| 869 | - // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 870 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 871 | - |
|
| 872 | - require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 873 | - $PRC = EEM_Price::instance(); |
|
| 874 | - |
|
| 875 | - $success = 1; |
|
| 876 | - // Checkboxes |
|
| 877 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 878 | - // if array has more than one element than success message should be plural |
|
| 879 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 880 | - // cycle thru bulk action checkboxes |
|
| 881 | - while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 882 | - if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
| 883 | - $success = 0; |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - } else { |
|
| 887 | - // grab single id and delete |
|
| 888 | - $PRC_ID = absint($this->_req_data['id']); |
|
| 889 | - if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
| 890 | - $success = 0; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - |
|
| 898 | - public function update_price_order() |
|
| 899 | - { |
|
| 900 | - $success = __('Price order was updated successfully.', 'event_espresso'); |
|
| 901 | - |
|
| 902 | - // grab our row IDs |
|
| 903 | - $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
| 904 | - ',', |
|
| 905 | - rtrim( |
|
| 906 | - $this->_req_data['row_ids'], |
|
| 907 | - ',' |
|
| 908 | - ) |
|
| 909 | - ) : false; |
|
| 910 | - |
|
| 911 | - if (is_array($row_ids)) { |
|
| 912 | - for ($i = 0; $i < count($row_ids); $i++) { |
|
| 913 | - // Update the prices when re-ordering |
|
| 914 | - $id = absint($row_ids[ $i ]); |
|
| 915 | - if (EEM_Price::instance()->update( |
|
| 916 | - array('PRC_order' => $i + 1), |
|
| 917 | - array(array('PRC_ID' => $id)) |
|
| 918 | - ) === false) { |
|
| 919 | - $success = false; |
|
| 920 | - } |
|
| 921 | - } |
|
| 922 | - } else { |
|
| 923 | - $success = false; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
| 927 | - |
|
| 928 | - echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 929 | - die(); |
|
| 930 | - } |
|
| 931 | - |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - |
|
| 935 | - |
|
| 936 | - |
|
| 937 | - /************************************************************************************************************************************************************** |
|
| 15 | + /** |
|
| 16 | + * constructor |
|
| 17 | + * |
|
| 18 | + * @Constructor |
|
| 19 | + * @access public |
|
| 20 | + * @param bool $routing |
|
| 21 | + * @return Pricing_Admin_Page |
|
| 22 | + */ |
|
| 23 | + public function __construct($routing = true) |
|
| 24 | + { |
|
| 25 | + parent::__construct($routing); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + protected function _init_page_props() |
|
| 30 | + { |
|
| 31 | + $this->page_slug = PRICING_PG_SLUG; |
|
| 32 | + $this->page_label = PRICING_LABEL; |
|
| 33 | + $this->_admin_base_url = PRICING_ADMIN_URL; |
|
| 34 | + $this->_admin_base_path = PRICING_ADMIN; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + protected function _ajax_hooks() |
|
| 39 | + { |
|
| 40 | + add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order')); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + protected function _define_page_props() |
|
| 45 | + { |
|
| 46 | + $this->_admin_page_title = PRICING_LABEL; |
|
| 47 | + $this->_labels = array( |
|
| 48 | + 'buttons' => array( |
|
| 49 | + 'add' => __('Add New Default Price', 'event_espresso'), |
|
| 50 | + 'edit' => __('Edit Default Price', 'event_espresso'), |
|
| 51 | + 'delete' => __('Delete Default Price', 'event_espresso'), |
|
| 52 | + 'add_type' => __('Add New Default Price Type', 'event_espresso'), |
|
| 53 | + 'edit_type' => __('Edit Price Type', 'event_espresso'), |
|
| 54 | + 'delete_type' => __('Delete Price Type', 'event_espresso'), |
|
| 55 | + ), |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * an array for storing request actions and their corresponding methods |
|
| 62 | + * |
|
| 63 | + * @access private |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + protected function _set_page_routes() |
|
| 67 | + { |
|
| 68 | + $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID']) |
|
| 69 | + ? $this->_req_data['PRC_ID'] : 0; |
|
| 70 | + $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID']) |
|
| 71 | + ? $this->_req_data['PRT_ID'] : 0; |
|
| 72 | + $this->_page_routes = array( |
|
| 73 | + 'default' => array( |
|
| 74 | + 'func' => '_price_overview_list_table', |
|
| 75 | + 'capability' => 'ee_read_default_prices', |
|
| 76 | + ), |
|
| 77 | + 'add_new_price' => array( |
|
| 78 | + 'func' => '_edit_price_details', |
|
| 79 | + 'capability' => 'ee_edit_default_prices', |
|
| 80 | + ), |
|
| 81 | + 'edit_price' => array( |
|
| 82 | + 'func' => '_edit_price_details', |
|
| 83 | + 'capability' => 'ee_edit_default_price', |
|
| 84 | + 'obj_id' => $prc_id, |
|
| 85 | + ), |
|
| 86 | + 'insert_price' => array( |
|
| 87 | + 'func' => '_insert_or_update_price', |
|
| 88 | + 'args' => array('insert' => true), |
|
| 89 | + 'noheader' => true, |
|
| 90 | + 'capability' => 'ee_edit_default_prices', |
|
| 91 | + ), |
|
| 92 | + 'update_price' => array( |
|
| 93 | + 'func' => '_insert_or_update_price', |
|
| 94 | + 'args' => array('insert' => false), |
|
| 95 | + 'noheader' => true, |
|
| 96 | + 'capability' => 'ee_edit_default_price', |
|
| 97 | + 'obj_id' => $prc_id, |
|
| 98 | + ), |
|
| 99 | + 'trash_price' => array( |
|
| 100 | + 'func' => '_trash_or_restore_price', |
|
| 101 | + 'args' => array('trash' => true), |
|
| 102 | + 'noheader' => true, |
|
| 103 | + 'capability' => 'ee_delete_default_price', |
|
| 104 | + 'obj_id' => $prc_id, |
|
| 105 | + ), |
|
| 106 | + 'restore_price' => array( |
|
| 107 | + 'func' => '_trash_or_restore_price', |
|
| 108 | + 'args' => array('trash' => false), |
|
| 109 | + 'noheader' => true, |
|
| 110 | + 'capability' => 'ee_delete_default_price', |
|
| 111 | + 'obj_id' => $prc_id, |
|
| 112 | + ), |
|
| 113 | + 'delete_price' => array( |
|
| 114 | + 'func' => '_delete_price', |
|
| 115 | + 'noheader' => true, |
|
| 116 | + 'capability' => 'ee_delete_default_price', |
|
| 117 | + 'obj_id' => $prc_id, |
|
| 118 | + ), |
|
| 119 | + 'espresso_update_price_order' => array( |
|
| 120 | + 'func' => 'update_price_order', |
|
| 121 | + 'noheader' => true, |
|
| 122 | + 'capability' => 'ee_edit_default_prices', |
|
| 123 | + ), |
|
| 124 | + // price types |
|
| 125 | + 'price_types' => array( |
|
| 126 | + 'func' => '_price_types_overview_list_table', |
|
| 127 | + 'capability' => 'ee_read_default_price_types', |
|
| 128 | + ), |
|
| 129 | + 'add_new_price_type' => array( |
|
| 130 | + 'func' => '_edit_price_type_details', |
|
| 131 | + 'capability' => 'ee_edit_default_price_types', |
|
| 132 | + ), |
|
| 133 | + 'edit_price_type' => array( |
|
| 134 | + 'func' => '_edit_price_type_details', |
|
| 135 | + 'capability' => 'ee_edit_default_price_type', |
|
| 136 | + 'obj_id' => $prt_id, |
|
| 137 | + ), |
|
| 138 | + 'insert_price_type' => array( |
|
| 139 | + 'func' => '_insert_or_update_price_type', |
|
| 140 | + 'args' => array('new_price_type' => true), |
|
| 141 | + 'noheader' => true, |
|
| 142 | + 'capability' => 'ee_edit_default_price_types', |
|
| 143 | + ), |
|
| 144 | + 'update_price_type' => array( |
|
| 145 | + 'func' => '_insert_or_update_price_type', |
|
| 146 | + 'args' => array('new_price_type' => false), |
|
| 147 | + 'noheader' => true, |
|
| 148 | + 'capability' => 'ee_edit_default_price_type', |
|
| 149 | + 'obj_id' => $prt_id, |
|
| 150 | + ), |
|
| 151 | + 'trash_price_type' => array( |
|
| 152 | + 'func' => '_trash_or_restore_price_type', |
|
| 153 | + 'args' => array('trash' => true), |
|
| 154 | + 'noheader' => true, |
|
| 155 | + 'capability' => 'ee_delete_default_price_type', |
|
| 156 | + 'obj_id' => $prt_id, |
|
| 157 | + ), |
|
| 158 | + 'restore_price_type' => array( |
|
| 159 | + 'func' => '_trash_or_restore_price_type', |
|
| 160 | + 'args' => array('trash' => false), |
|
| 161 | + 'noheader' => true, |
|
| 162 | + 'capability' => 'ee_delete_default_price_type', |
|
| 163 | + 'obj_id' => $prt_id, |
|
| 164 | + ), |
|
| 165 | + 'delete_price_type' => array( |
|
| 166 | + 'func' => '_delete_price_type', |
|
| 167 | + 'noheader' => true, |
|
| 168 | + 'capability' => 'ee_delete_default_price_type', |
|
| 169 | + 'obj_id' => $prt_id, |
|
| 170 | + ), |
|
| 171 | + 'tax_settings' => array( |
|
| 172 | + 'func' => '_tax_settings', |
|
| 173 | + 'capability' => 'manage_options', |
|
| 174 | + ), |
|
| 175 | + 'update_tax_settings' => array( |
|
| 176 | + 'func' => '_update_tax_settings', |
|
| 177 | + 'capability' => 'manage_options', |
|
| 178 | + 'noheader' => true, |
|
| 179 | + ), |
|
| 180 | + ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + protected function _set_page_config() |
|
| 185 | + { |
|
| 186 | + |
|
| 187 | + $this->_page_config = array( |
|
| 188 | + 'default' => array( |
|
| 189 | + 'nav' => array( |
|
| 190 | + 'label' => __('Default Pricing', 'event_espresso'), |
|
| 191 | + 'order' => 10, |
|
| 192 | + ), |
|
| 193 | + 'list_table' => 'Prices_List_Table', |
|
| 194 | + 'help_tabs' => array( |
|
| 195 | + 'pricing_default_pricing_help_tab' => array( |
|
| 196 | + 'title' => __('Default Pricing', 'event_espresso'), |
|
| 197 | + 'filename' => 'pricing_default_pricing', |
|
| 198 | + ), |
|
| 199 | + 'pricing_default_pricing_table_column_headings_help_tab' => array( |
|
| 200 | + 'title' => __('Default Pricing Table Column Headings', 'event_espresso'), |
|
| 201 | + 'filename' => 'pricing_default_pricing_table_column_headings', |
|
| 202 | + ), |
|
| 203 | + 'pricing_default_pricing_views_bulk_actions_search_help_tab' => array( |
|
| 204 | + 'title' => __('Default Pricing Views & Bulk Actions & Search', 'event_espresso'), |
|
| 205 | + 'filename' => 'pricing_default_pricing_views_bulk_actions_search', |
|
| 206 | + ), |
|
| 207 | + ), |
|
| 208 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 209 | + // 'help_tour' => array('Pricing_Default_Prices_Help_Tour'), |
|
| 210 | + 'require_nonce' => false, |
|
| 211 | + ), |
|
| 212 | + 'add_new_price' => array( |
|
| 213 | + 'nav' => array( |
|
| 214 | + 'label' => __('Add New Default Price', 'event_espresso'), |
|
| 215 | + 'order' => 20, |
|
| 216 | + 'persistent' => false, |
|
| 217 | + ), |
|
| 218 | + 'help_tabs' => array( |
|
| 219 | + 'add_new_default_price_help_tab' => array( |
|
| 220 | + 'title' => __('Add New Default Price', 'event_espresso'), |
|
| 221 | + 'filename' => 'pricing_add_new_default_price', |
|
| 222 | + ), |
|
| 223 | + ), |
|
| 224 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 225 | + // 'help_tour' => array('Pricing_Add_New_Default_Price_Help_Tour'), |
|
| 226 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 227 | + 'require_nonce' => false, |
|
| 228 | + ), |
|
| 229 | + 'edit_price' => array( |
|
| 230 | + 'nav' => array( |
|
| 231 | + 'label' => __('Edit Default Price', 'event_espresso'), |
|
| 232 | + 'order' => 20, |
|
| 233 | + 'url' => isset($this->_req_data['id']) ? add_query_arg( |
|
| 234 | + array('id' => $this->_req_data['id']), |
|
| 235 | + $this->_current_page_view_url |
|
| 236 | + ) : $this->_admin_base_url, |
|
| 237 | + 'persistent' => false, |
|
| 238 | + ), |
|
| 239 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'), |
|
| 240 | + 'help_tabs' => array( |
|
| 241 | + 'edit_default_price_help_tab' => array( |
|
| 242 | + 'title' => __('Edit Default Price', 'event_espresso'), |
|
| 243 | + 'filename' => 'pricing_edit_default_price', |
|
| 244 | + ), |
|
| 245 | + ), |
|
| 246 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 247 | + // 'help_tour' => array('Pricing_Edit_Default_Price_Help_Tour'), |
|
| 248 | + 'require_nonce' => false, |
|
| 249 | + ), |
|
| 250 | + 'price_types' => array( |
|
| 251 | + 'nav' => array( |
|
| 252 | + 'label' => __('Price Types', 'event_espresso'), |
|
| 253 | + 'order' => 30, |
|
| 254 | + ), |
|
| 255 | + 'list_table' => 'Price_Types_List_Table', |
|
| 256 | + 'help_tabs' => array( |
|
| 257 | + 'pricing_price_types_help_tab' => array( |
|
| 258 | + 'title' => __('Price Types', 'event_espresso'), |
|
| 259 | + 'filename' => 'pricing_price_types', |
|
| 260 | + ), |
|
| 261 | + 'pricing_price_types_table_column_headings_help_tab' => array( |
|
| 262 | + 'title' => __('Price Types Table Column Headings', 'event_espresso'), |
|
| 263 | + 'filename' => 'pricing_price_types_table_column_headings', |
|
| 264 | + ), |
|
| 265 | + 'pricing_price_types_views_bulk_actions_search_help_tab' => array( |
|
| 266 | + 'title' => __('Price Types Views & Bulk Actions & Search', 'event_espresso'), |
|
| 267 | + 'filename' => 'pricing_price_types_views_bulk_actions_search', |
|
| 268 | + ), |
|
| 269 | + ), |
|
| 270 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 271 | + // 'help_tour' => array('Pricing_Price_Types_Default_Help_Tour'), |
|
| 272 | + 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
|
| 273 | + 'require_nonce' => false, |
|
| 274 | + ), |
|
| 275 | + 'add_new_price_type' => array( |
|
| 276 | + 'nav' => array( |
|
| 277 | + 'label' => __('Add New Price Type', 'event_espresso'), |
|
| 278 | + 'order' => 40, |
|
| 279 | + 'persistent' => false, |
|
| 280 | + ), |
|
| 281 | + 'help_tabs' => array( |
|
| 282 | + 'add_new_price_type_help_tab' => array( |
|
| 283 | + 'title' => __('Add New Price Type', 'event_espresso'), |
|
| 284 | + 'filename' => 'pricing_add_new_price_type', |
|
| 285 | + ), |
|
| 286 | + ), |
|
| 287 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 288 | + // 'help_tour' => array('Pricing_Add_New_Price_Type_Help_Tour'), |
|
| 289 | + 'metaboxes' => array( |
|
| 290 | + '_publish_post_box', |
|
| 291 | + '_espresso_news_post_box', |
|
| 292 | + '_price_type_details_meta_boxes', |
|
| 293 | + ), |
|
| 294 | + 'require_nonce' => false, |
|
| 295 | + ), |
|
| 296 | + 'edit_price_type' => array( |
|
| 297 | + 'nav' => array( |
|
| 298 | + 'label' => __('Edit Price Type', 'event_espresso'), |
|
| 299 | + 'order' => 40, |
|
| 300 | + 'persistent' => false, |
|
| 301 | + ), |
|
| 302 | + 'help_tabs' => array( |
|
| 303 | + 'edit_price_type_help_tab' => array( |
|
| 304 | + 'title' => __('Edit Price Type', 'event_espresso'), |
|
| 305 | + 'filename' => 'pricing_edit_price_type', |
|
| 306 | + ), |
|
| 307 | + ), |
|
| 308 | + // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836 |
|
| 309 | + // 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'), |
|
| 310 | + 'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'), |
|
| 311 | + |
|
| 312 | + 'require_nonce' => false, |
|
| 313 | + ), |
|
| 314 | + 'tax_settings' => array( |
|
| 315 | + 'nav' => array( |
|
| 316 | + 'label' => esc_html__('Tax Settings', 'event_espresso'), |
|
| 317 | + 'order' => 40, |
|
| 318 | + ), |
|
| 319 | + 'labels' => array( |
|
| 320 | + 'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'), |
|
| 321 | + ), |
|
| 322 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
| 323 | + // 'help_tabs' => array( |
|
| 324 | + // 'registration_form_reg_form_settings_help_tab' => array( |
|
| 325 | + // 'title' => esc_html__('Registration Form Settings', 'event_espresso'), |
|
| 326 | + // 'filename' => 'registration_form_reg_form_settings' |
|
| 327 | + // ), |
|
| 328 | + // ), |
|
| 329 | + // 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
| 330 | + 'require_nonce' => true, |
|
| 331 | + ), |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + protected function _add_screen_options() |
|
| 337 | + { |
|
| 338 | + // todo |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + protected function _add_screen_options_default() |
|
| 343 | + { |
|
| 344 | + $this->_per_page_screen_option(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + protected function _add_screen_options_price_types() |
|
| 349 | + { |
|
| 350 | + $page_title = $this->_admin_page_title; |
|
| 351 | + $this->_admin_page_title = __('Price Types', 'event_espresso'); |
|
| 352 | + $this->_per_page_screen_option(); |
|
| 353 | + $this->_admin_page_title = $page_title; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + protected function _add_feature_pointers() |
|
| 358 | + { |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + public function load_scripts_styles() |
|
| 363 | + { |
|
| 364 | + // styles |
|
| 365 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 366 | + wp_register_style( |
|
| 367 | + 'espresso_PRICING', |
|
| 368 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.css', |
|
| 369 | + array(), |
|
| 370 | + EVENT_ESPRESSO_VERSION |
|
| 371 | + ); |
|
| 372 | + wp_enqueue_style('espresso_PRICING'); |
|
| 373 | + |
|
| 374 | + // scripts |
|
| 375 | + wp_enqueue_script('ee_admin_js'); |
|
| 376 | + wp_enqueue_script('jquery-ui-position'); |
|
| 377 | + wp_enqueue_script('jquery-ui-widget'); |
|
| 378 | + // wp_enqueue_script('jquery-ui-dialog'); |
|
| 379 | + // wp_enqueue_script('jquery-ui-draggable'); |
|
| 380 | + // wp_enqueue_script('jquery-ui-datepicker'); |
|
| 381 | + wp_register_script( |
|
| 382 | + 'espresso_PRICING', |
|
| 383 | + PRICING_ASSETS_URL . 'espresso_pricing_admin.js', |
|
| 384 | + array('jquery'), |
|
| 385 | + EVENT_ESPRESSO_VERSION, |
|
| 386 | + true |
|
| 387 | + ); |
|
| 388 | + wp_enqueue_script('espresso_PRICING'); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + public function load_scripts_styles_default() |
|
| 393 | + { |
|
| 394 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + public function admin_footer_scripts() |
|
| 399 | + { |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + public function admin_init() |
|
| 403 | + { |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + public function admin_notices() |
|
| 407 | + { |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + protected function _set_list_table_views_default() |
|
| 412 | + { |
|
| 413 | + $this->_views = array( |
|
| 414 | + 'all' => array( |
|
| 415 | + 'slug' => 'all', |
|
| 416 | + 'label' => __('View All Default Pricing', 'event_espresso'), |
|
| 417 | + 'count' => 0, |
|
| 418 | + 'bulk_action' => array( |
|
| 419 | + 'trash_price' => __('Move to Trash', 'event_espresso'), |
|
| 420 | + ), |
|
| 421 | + ), |
|
| 422 | + ); |
|
| 423 | + |
|
| 424 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
| 425 | + $this->_views['trashed'] = array( |
|
| 426 | + 'slug' => 'trashed', |
|
| 427 | + 'label' => __('Trash', 'event_espresso'), |
|
| 428 | + 'count' => 0, |
|
| 429 | + 'bulk_action' => array( |
|
| 430 | + 'restore_price' => __('Restore from Trash', 'event_espresso'), |
|
| 431 | + 'delete_price' => __('Delete Permanently', 'event_espresso'), |
|
| 432 | + ), |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + protected function _set_list_table_views_price_types() |
|
| 439 | + { |
|
| 440 | + $this->_views = array( |
|
| 441 | + 'all' => array( |
|
| 442 | + 'slug' => 'all', |
|
| 443 | + 'label' => __('All', 'event_espresso'), |
|
| 444 | + 'count' => 0, |
|
| 445 | + 'bulk_action' => array( |
|
| 446 | + 'trash_price_type' => __('Move to Trash', 'event_espresso'), |
|
| 447 | + ), |
|
| 448 | + ), |
|
| 449 | + ); |
|
| 450 | + |
|
| 451 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 452 | + 'ee_delete_default_price_types', |
|
| 453 | + 'pricing_trash_price_type' |
|
| 454 | + )) { |
|
| 455 | + $this->_views['trashed'] = array( |
|
| 456 | + 'slug' => 'trashed', |
|
| 457 | + 'label' => __('Trash', 'event_espresso'), |
|
| 458 | + 'count' => 0, |
|
| 459 | + 'bulk_action' => array( |
|
| 460 | + 'restore_price_type' => __('Restore from Trash', 'event_espresso'), |
|
| 461 | + 'delete_price_type' => __('Delete Permanently', 'event_espresso'), |
|
| 462 | + ), |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * generates HTML for main Prices Admin page |
|
| 470 | + * |
|
| 471 | + * @access protected |
|
| 472 | + * @return void |
|
| 473 | + */ |
|
| 474 | + protected function _price_overview_list_table() |
|
| 475 | + { |
|
| 476 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 477 | + 'add_new_price', |
|
| 478 | + 'add', |
|
| 479 | + array(), |
|
| 480 | + 'add-new-h2' |
|
| 481 | + ); |
|
| 482 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 483 | + $this->_search_btn_label = __('Default Prices', 'event_espresso'); |
|
| 484 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * retrieve data for Prices List table |
|
| 490 | + * |
|
| 491 | + * @access public |
|
| 492 | + * @param int $per_page how many prices displayed per page |
|
| 493 | + * @param boolean $count return the count or objects |
|
| 494 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 495 | + * @return mixed (int|array) int = count || array of price objects |
|
| 496 | + */ |
|
| 497 | + public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 498 | + { |
|
| 499 | + |
|
| 500 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 501 | + // start with an empty array |
|
| 502 | + $event_pricing = array(); |
|
| 503 | + |
|
| 504 | + require_once(PRICING_ADMIN . 'Prices_List_Table.class.php'); |
|
| 505 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 506 | + // $PRC = EEM_Price::instance(); |
|
| 507 | + |
|
| 508 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 509 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 510 | + : 'ASC'; |
|
| 511 | + |
|
| 512 | + switch ($this->_req_data['orderby']) { |
|
| 513 | + case 'name': |
|
| 514 | + $orderby = array('PRC_name' => $order); |
|
| 515 | + break; |
|
| 516 | + case 'type': |
|
| 517 | + $orderby = array('Price_Type.PRT_name' => $order); |
|
| 518 | + break; |
|
| 519 | + case 'amount': |
|
| 520 | + $orderby = array('PRC_amount' => $order); |
|
| 521 | + break; |
|
| 522 | + default: |
|
| 523 | + $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 527 | + ? $this->_req_data['paged'] : 1; |
|
| 528 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 529 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 530 | + |
|
| 531 | + $_where = array( |
|
| 532 | + 'PRC_is_default' => 1, |
|
| 533 | + 'PRC_deleted' => $trashed, |
|
| 534 | + ); |
|
| 535 | + |
|
| 536 | + $offset = ($current_page - 1) * $per_page; |
|
| 537 | + $limit = array($offset, $per_page); |
|
| 538 | + |
|
| 539 | + if (isset($this->_req_data['s'])) { |
|
| 540 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 541 | + $_where['OR'] = array( |
|
| 542 | + 'PRC_name' => array('LIKE', $sstr), |
|
| 543 | + 'PRC_desc' => array('LIKE', $sstr), |
|
| 544 | + 'PRC_amount' => array('LIKE', $sstr), |
|
| 545 | + 'Price_Type.PRT_name' => array('LIKE', $sstr), |
|
| 546 | + ); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + $query_params = array( |
|
| 550 | + $_where, |
|
| 551 | + 'order_by' => $orderby, |
|
| 552 | + 'limit' => $limit, |
|
| 553 | + 'group_by' => 'PRC_ID', |
|
| 554 | + ); |
|
| 555 | + |
|
| 556 | + if ($count) { |
|
| 557 | + return $trashed ? EEM_Price::instance()->count(array($_where)) |
|
| 558 | + : EEM_Price::instance()->count_deleted_and_undeleted(array($_where)); |
|
| 559 | + } else { |
|
| 560 | + return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * _price_details |
|
| 567 | + * |
|
| 568 | + * @access protected |
|
| 569 | + * @return void |
|
| 570 | + */ |
|
| 571 | + protected function _edit_price_details() |
|
| 572 | + { |
|
| 573 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 574 | + // grab price ID |
|
| 575 | + $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 576 | + : false; |
|
| 577 | + // change page title based on request action |
|
| 578 | + switch ($this->_req_action) { |
|
| 579 | + case 'add_new_price': |
|
| 580 | + $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso'); |
|
| 581 | + break; |
|
| 582 | + case 'edit_price': |
|
| 583 | + $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso'); |
|
| 584 | + break; |
|
| 585 | + default: |
|
| 586 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 587 | + } |
|
| 588 | + // add PRC_ID to title if editing |
|
| 589 | + $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title; |
|
| 590 | + |
|
| 591 | + // get prices |
|
| 592 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 593 | + $PRC = EEM_Price::instance(); |
|
| 594 | + |
|
| 595 | + if ($PRC_ID) { |
|
| 596 | + $price = $PRC->get_one_by_ID($PRC_ID); |
|
| 597 | + $additional_hidden_fields = array( |
|
| 598 | + 'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID), |
|
| 599 | + ); |
|
| 600 | + $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields); |
|
| 601 | + } else { |
|
| 602 | + $price = $PRC->get_new_price(); |
|
| 603 | + $this->_set_add_edit_form_tags('insert_price'); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $this->_template_args['PRC_ID'] = $PRC_ID; |
|
| 607 | + $this->_template_args['price'] = $price; |
|
| 608 | + |
|
| 609 | + // get price types |
|
| 610 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 611 | + $PRT = EEM_Price_Type::instance(); |
|
| 612 | + $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1)))); |
|
| 613 | + $price_type_names = array(); |
|
| 614 | + if (empty($price_types)) { |
|
| 615 | + $msg = __( |
|
| 616 | + 'You have no price types defined. Please add a price type before adding a price.', |
|
| 617 | + 'event_espresso' |
|
| 618 | + ); |
|
| 619 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 620 | + exit(); |
|
| 621 | + } else { |
|
| 622 | + foreach ($price_types as $type) { |
|
| 623 | + // if ($type->is_global()) { |
|
| 624 | + $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name()); |
|
| 625 | + // } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + $this->_template_args['price_types'] = $price_type_names; |
|
| 630 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 631 | + |
|
| 632 | + $this->_set_publish_post_box_vars('id', $PRC_ID); |
|
| 633 | + // the details template wrapper |
|
| 634 | + $this->display_admin_page_with_sidebar(); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * declare price details page metaboxes |
|
| 640 | + * |
|
| 641 | + * @access protected |
|
| 642 | + * @return void |
|
| 643 | + */ |
|
| 644 | + protected function _price_details_meta_boxes() |
|
| 645 | + { |
|
| 646 | + add_meta_box( |
|
| 647 | + 'edit-price-details-mbox', |
|
| 648 | + __('Default Price Details', 'event_espresso'), |
|
| 649 | + array($this, '_edit_price_details_meta_box'), |
|
| 650 | + $this->wp_page_slug, |
|
| 651 | + 'normal', |
|
| 652 | + 'high' |
|
| 653 | + ); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * _edit_price_details_meta_box |
|
| 659 | + * |
|
| 660 | + * @access public |
|
| 661 | + * @return void |
|
| 662 | + */ |
|
| 663 | + public function _edit_price_details_meta_box() |
|
| 664 | + { |
|
| 665 | + echo EEH_Template::display_template( |
|
| 666 | + PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php', |
|
| 667 | + $this->_template_args, |
|
| 668 | + true |
|
| 669 | + ); |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * set_price_column_values |
|
| 675 | + * |
|
| 676 | + * @access protected |
|
| 677 | + * @return array |
|
| 678 | + */ |
|
| 679 | + protected function set_price_column_values() |
|
| 680 | + { |
|
| 681 | + |
|
| 682 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 683 | + |
|
| 684 | + $set_column_values = array( |
|
| 685 | + 'PRT_ID' => absint($this->_req_data['PRT_ID']), |
|
| 686 | + 'PRC_amount' => $this->_req_data['PRC_amount'], |
|
| 687 | + 'PRC_name' => $this->_req_data['PRC_name'], |
|
| 688 | + 'PRC_desc' => $this->_req_data['PRC_desc'], |
|
| 689 | + 'PRC_is_default' => 1, |
|
| 690 | + 'PRC_overrides' => null, |
|
| 691 | + 'PRC_order' => 0, |
|
| 692 | + 'PRC_deleted' => 0, |
|
| 693 | + 'PRC_parent' => 0, |
|
| 694 | + ); |
|
| 695 | + return $set_column_values; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * insert_or_update_price |
|
| 701 | + * |
|
| 702 | + * @param boolean $insert - whether to insert or update |
|
| 703 | + * @access protected |
|
| 704 | + * @return void |
|
| 705 | + */ |
|
| 706 | + protected function _insert_or_update_price($insert = false) |
|
| 707 | + { |
|
| 708 | + |
|
| 709 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 710 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 711 | + |
|
| 712 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 713 | + $PRC = EEM_Price::instance(); |
|
| 714 | + |
|
| 715 | + // why be so pessimistic ??? : ( |
|
| 716 | + $success = 0; |
|
| 717 | + |
|
| 718 | + $set_column_values = $this->set_price_column_values(); |
|
| 719 | + // is this a new Price ? |
|
| 720 | + if ($insert) { |
|
| 721 | + // run the insert |
|
| 722 | + if ($PRC_ID = $PRC->insert($set_column_values)) { |
|
| 723 | + // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type |
|
| 724 | + $PR = EEM_price::instance()->get_one_by_ID($PRC_ID); |
|
| 725 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 726 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 727 | + $ticket->_add_relation_to($PR, 'Price'); |
|
| 728 | + $ticket->save(); |
|
| 729 | + } |
|
| 730 | + $success = 1; |
|
| 731 | + } else { |
|
| 732 | + $PRC_ID = false; |
|
| 733 | + $success = 0; |
|
| 734 | + } |
|
| 735 | + $action_desc = 'created'; |
|
| 736 | + } else { |
|
| 737 | + $PRC_ID = absint($this->_req_data['PRC_ID']); |
|
| 738 | + // run the update |
|
| 739 | + $where_cols_n_values = array('PRC_ID' => $PRC_ID); |
|
| 740 | + if ($PRC->update($set_column_values, array($where_cols_n_values))) { |
|
| 741 | + $success = 1; |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 745 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 746 | + // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated. |
|
| 747 | + if ($PRC_ID === 1) { |
|
| 748 | + $ticket = $PR->get_first_related('Ticket'); |
|
| 749 | + if ($ticket) { |
|
| 750 | + $ticket->set('TKT_price', $PR->get('PRC_amount')); |
|
| 751 | + $ticket->set('TKT_name', $PR->get('PRC_name')); |
|
| 752 | + $ticket->set('TKT_description', $PR->get('PRC_desc')); |
|
| 753 | + $ticket->save(); |
|
| 754 | + } |
|
| 755 | + } else { |
|
| 756 | + // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type. |
|
| 757 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 758 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 759 | + $ticket->save(); |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + $action_desc = 'updated'; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + $query_args = array('action' => 'edit_price', 'id' => $PRC_ID); |
|
| 767 | + |
|
| 768 | + $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + |
|
| 772 | + /** |
|
| 773 | + * _trash_or_restore_price |
|
| 774 | + * |
|
| 775 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 776 | + * @access protected |
|
| 777 | + * @return void |
|
| 778 | + */ |
|
| 779 | + protected function _trash_or_restore_price($trash = true) |
|
| 780 | + { |
|
| 781 | + |
|
| 782 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 783 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 784 | + |
|
| 785 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 786 | + $PRC = EEM_Price::instance(); |
|
| 787 | + |
|
| 788 | + $success = 1; |
|
| 789 | + $PRC_deleted = $trash ? true : false; |
|
| 790 | + |
|
| 791 | + // get base ticket for updating |
|
| 792 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(1); |
|
| 793 | + // Checkboxes |
|
| 794 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 795 | + // if array has more than one element than success message should be plural |
|
| 796 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 797 | + // cycle thru checkboxes |
|
| 798 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 799 | + if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) { |
|
| 800 | + $success = 0; |
|
| 801 | + } else { |
|
| 802 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 803 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 804 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 805 | + if ($PRC_deleted) { |
|
| 806 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 807 | + } else { |
|
| 808 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 809 | + } |
|
| 810 | + $ticket->save(); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + // grab single id and delete |
|
| 816 | + $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 817 | + if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) { |
|
| 818 | + $success = 0; |
|
| 819 | + } else { |
|
| 820 | + $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID); |
|
| 821 | + if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) { |
|
| 822 | + // if trashing then remove relations to base default ticket. If restoring then add back to base default ticket |
|
| 823 | + if ($PRC_deleted) { |
|
| 824 | + $ticket->_remove_relation_to($PRC_ID, 'Price'); |
|
| 825 | + } else { |
|
| 826 | + $ticket->_add_relation_to($PRC_ID, 'Price'); |
|
| 827 | + } |
|
| 828 | + $ticket->save(); |
|
| 829 | + } |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + $query_args = array( |
|
| 833 | + 'action' => 'default', |
|
| 834 | + ); |
|
| 835 | + |
|
| 836 | + if ($success) { |
|
| 837 | + if ($trash) { |
|
| 838 | + $msg = $success == 2 |
|
| 839 | + ? __('The Prices have been trashed.', 'event_espresso') |
|
| 840 | + : __( |
|
| 841 | + 'The Price has been trashed.', |
|
| 842 | + 'event_espresso' |
|
| 843 | + ); |
|
| 844 | + } else { |
|
| 845 | + $msg = $success == 2 |
|
| 846 | + ? __('The Prices have been restored.', 'event_espresso') |
|
| 847 | + : __( |
|
| 848 | + 'The Price has been restored.', |
|
| 849 | + 'event_espresso' |
|
| 850 | + ); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + EE_Error::add_success($msg); |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * _delete_price |
|
| 862 | + * |
|
| 863 | + * @access protected |
|
| 864 | + * @return void |
|
| 865 | + */ |
|
| 866 | + protected function _delete_price() |
|
| 867 | + { |
|
| 868 | + |
|
| 869 | + // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>'; |
|
| 870 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 871 | + |
|
| 872 | + require_once(EE_MODELS . 'EEM_Price.model.php'); |
|
| 873 | + $PRC = EEM_Price::instance(); |
|
| 874 | + |
|
| 875 | + $success = 1; |
|
| 876 | + // Checkboxes |
|
| 877 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 878 | + // if array has more than one element than success message should be plural |
|
| 879 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 880 | + // cycle thru bulk action checkboxes |
|
| 881 | + while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 882 | + if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) { |
|
| 883 | + $success = 0; |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + } else { |
|
| 887 | + // grab single id and delete |
|
| 888 | + $PRC_ID = absint($this->_req_data['id']); |
|
| 889 | + if (! $PRC->delete_permanently_by_ID($PRC_ID)) { |
|
| 890 | + $success = 0; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + $this->_redirect_after_action($success, 'Prices', 'deleted', array()); |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + |
|
| 898 | + public function update_price_order() |
|
| 899 | + { |
|
| 900 | + $success = __('Price order was updated successfully.', 'event_espresso'); |
|
| 901 | + |
|
| 902 | + // grab our row IDs |
|
| 903 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode( |
|
| 904 | + ',', |
|
| 905 | + rtrim( |
|
| 906 | + $this->_req_data['row_ids'], |
|
| 907 | + ',' |
|
| 908 | + ) |
|
| 909 | + ) : false; |
|
| 910 | + |
|
| 911 | + if (is_array($row_ids)) { |
|
| 912 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
| 913 | + // Update the prices when re-ordering |
|
| 914 | + $id = absint($row_ids[ $i ]); |
|
| 915 | + if (EEM_Price::instance()->update( |
|
| 916 | + array('PRC_order' => $i + 1), |
|
| 917 | + array(array('PRC_ID' => $id)) |
|
| 918 | + ) === false) { |
|
| 919 | + $success = false; |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | + } else { |
|
| 923 | + $success = false; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + $errors = ! $success ? __('An error occurred. The price order was not updated.', 'event_espresso') : false; |
|
| 927 | + |
|
| 928 | + echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors)); |
|
| 929 | + die(); |
|
| 930 | + } |
|
| 931 | + |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + |
|
| 935 | + |
|
| 936 | + |
|
| 937 | + /************************************************************************************************************************************************************** |
|
| 938 | 938 | ******************************************************************** TICKET PRICE TYPES ****************************************************************** |
| 939 | 939 | **************************************************************************************************************************************************************/ |
| 940 | 940 | |
| 941 | 941 | |
| 942 | - /** |
|
| 943 | - * generates HTML for main Prices Admin page |
|
| 944 | - * |
|
| 945 | - * @access protected |
|
| 946 | - * @return void |
|
| 947 | - */ |
|
| 948 | - protected function _price_types_overview_list_table() |
|
| 949 | - { |
|
| 950 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 951 | - 'add_new_price_type', |
|
| 952 | - 'add_type', |
|
| 953 | - array(), |
|
| 954 | - 'add-new-h2' |
|
| 955 | - ); |
|
| 956 | - $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 957 | - $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
| 958 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * retrieve data for Price Types List table |
|
| 964 | - * |
|
| 965 | - * @access public |
|
| 966 | - * @param int $per_page how many prices displayed per page |
|
| 967 | - * @param boolean $count return the count or objects |
|
| 968 | - * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 969 | - * @return mixed (int|array) int = count || array of price objects |
|
| 970 | - */ |
|
| 971 | - public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 972 | - { |
|
| 973 | - |
|
| 974 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 975 | - // start with an empty array |
|
| 976 | - |
|
| 977 | - require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
| 978 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 979 | - |
|
| 980 | - $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 981 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 982 | - : 'ASC'; |
|
| 983 | - switch ($this->_req_data['orderby']) { |
|
| 984 | - case 'name': |
|
| 985 | - $orderby = array('PRT_name' => $order); |
|
| 986 | - break; |
|
| 987 | - default: |
|
| 988 | - $orderby = array('PRT_order' => $order); |
|
| 989 | - } |
|
| 990 | - |
|
| 991 | - |
|
| 992 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 993 | - ? $this->_req_data['paged'] : 1; |
|
| 994 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 995 | - ? $this->_req_data['perpage'] : $per_page; |
|
| 996 | - |
|
| 997 | - $offset = ($current_page - 1) * $per_page; |
|
| 998 | - $limit = array($offset, $per_page); |
|
| 999 | - |
|
| 1000 | - $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
| 1001 | - |
|
| 1002 | - if (isset($this->_req_data['s'])) { |
|
| 1003 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1004 | - $_where['OR'] = array( |
|
| 1005 | - 'PRT_name' => array('LIKE', $sstr), |
|
| 1006 | - ); |
|
| 1007 | - } |
|
| 1008 | - $query_params = array( |
|
| 1009 | - $_where, |
|
| 1010 | - 'order_by' => $orderby, |
|
| 1011 | - 'limit' => $limit, |
|
| 1012 | - ); |
|
| 1013 | - if ($count) { |
|
| 1014 | - return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
| 1015 | - } else { |
|
| 1016 | - return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - |
|
| 1023 | - /** |
|
| 1024 | - * _edit_price_type_details |
|
| 1025 | - * |
|
| 1026 | - * @access protected |
|
| 1027 | - * @return void |
|
| 1028 | - */ |
|
| 1029 | - protected function _edit_price_type_details() |
|
| 1030 | - { |
|
| 1031 | - |
|
| 1032 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1033 | - |
|
| 1034 | - |
|
| 1035 | - // grab price type ID |
|
| 1036 | - $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 1037 | - : false; |
|
| 1038 | - // change page title based on request action |
|
| 1039 | - switch ($this->_req_action) { |
|
| 1040 | - case 'add_new_price_type': |
|
| 1041 | - $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
| 1042 | - break; |
|
| 1043 | - case 'edit_price_type': |
|
| 1044 | - $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
| 1045 | - break; |
|
| 1046 | - default: |
|
| 1047 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 1048 | - } |
|
| 1049 | - // add PRT_ID to title if editing |
|
| 1050 | - $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
| 1051 | - |
|
| 1052 | - if ($PRT_ID) { |
|
| 1053 | - $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
| 1054 | - $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
| 1055 | - $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
| 1056 | - } else { |
|
| 1057 | - $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
| 1058 | - $this->_set_add_edit_form_tags('insert_price_type'); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - $this->_template_args['PRT_ID'] = $PRT_ID; |
|
| 1062 | - $this->_template_args['price_type'] = $price_type; |
|
| 1063 | - |
|
| 1064 | - |
|
| 1065 | - $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
| 1066 | - $select_values = array(); |
|
| 1067 | - foreach ($base_types as $ref => $text) { |
|
| 1068 | - if ($ref == EEM_Price_Type::base_type_base_price) { |
|
| 1069 | - // do not allow creation of base_type_base_prices because that's a system only base type. |
|
| 1070 | - continue; |
|
| 1071 | - } |
|
| 1072 | - $values[] = array('id' => $ref, 'text' => $text); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - |
|
| 1076 | - $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
| 1077 | - 'base_type', |
|
| 1078 | - $values, |
|
| 1079 | - $price_type->base_type(), |
|
| 1080 | - 'id="price-type-base-type-slct"' |
|
| 1081 | - ); |
|
| 1082 | - $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 1083 | - $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
| 1084 | - $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
| 1085 | - // the details template wrapper |
|
| 1086 | - $this->display_admin_page_with_sidebar(); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * declare price type details page metaboxes |
|
| 1092 | - * |
|
| 1093 | - * @access protected |
|
| 1094 | - * @return void |
|
| 1095 | - */ |
|
| 1096 | - protected function _price_type_details_meta_boxes() |
|
| 1097 | - { |
|
| 1098 | - add_meta_box( |
|
| 1099 | - 'edit-price-details-mbox', |
|
| 1100 | - __('Price Type Details', 'event_espresso'), |
|
| 1101 | - array($this, '_edit_price_type_details_meta_box'), |
|
| 1102 | - $this->wp_page_slug, |
|
| 1103 | - 'normal', |
|
| 1104 | - 'high' |
|
| 1105 | - ); |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - |
|
| 1109 | - /** |
|
| 1110 | - * _edit_price_type_details_meta_box |
|
| 1111 | - * |
|
| 1112 | - * @access public |
|
| 1113 | - * @return void |
|
| 1114 | - */ |
|
| 1115 | - public function _edit_price_type_details_meta_box() |
|
| 1116 | - { |
|
| 1117 | - echo EEH_Template::display_template( |
|
| 1118 | - PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
| 1119 | - $this->_template_args, |
|
| 1120 | - true |
|
| 1121 | - ); |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * set_price_type_column_values |
|
| 1127 | - * |
|
| 1128 | - * @access protected |
|
| 1129 | - * @return void |
|
| 1130 | - */ |
|
| 1131 | - protected function set_price_type_column_values() |
|
| 1132 | - { |
|
| 1133 | - |
|
| 1134 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1135 | - |
|
| 1136 | - $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
| 1137 | - : EEM_Price_Type::base_type_base_price; |
|
| 1138 | - |
|
| 1139 | - switch ($base_type) { |
|
| 1140 | - case EEM_Price_Type::base_type_base_price: |
|
| 1141 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
| 1142 | - $this->_req_data['PRT_is_percent'] = 0; |
|
| 1143 | - $this->_req_data['PRT_order'] = 0; |
|
| 1144 | - break; |
|
| 1145 | - |
|
| 1146 | - case EEM_Price_Type::base_type_discount: |
|
| 1147 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
| 1148 | - break; |
|
| 1149 | - |
|
| 1150 | - case EEM_Price_Type::base_type_surcharge: |
|
| 1151 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
| 1152 | - break; |
|
| 1153 | - |
|
| 1154 | - case EEM_Price_Type::base_type_tax: |
|
| 1155 | - $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
| 1156 | - $this->_req_data['PRT_is_percent'] = 1; |
|
| 1157 | - break; |
|
| 1158 | - }/**/ |
|
| 1159 | - |
|
| 1160 | - $set_column_values = array( |
|
| 1161 | - 'PRT_name' => $this->_req_data['PRT_name'], |
|
| 1162 | - 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
| 1163 | - 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
| 1164 | - 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
| 1165 | - 'PRT_deleted' => 0, |
|
| 1166 | - ); |
|
| 1167 | - |
|
| 1168 | - return $set_column_values; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * _insert_or_update_price_type |
|
| 1174 | - * |
|
| 1175 | - * @param boolean $new_price_type - whether to insert or update |
|
| 1176 | - * @access protected |
|
| 1177 | - * @return void |
|
| 1178 | - */ |
|
| 1179 | - protected function _insert_or_update_price_type($new_price_type = false) |
|
| 1180 | - { |
|
| 1181 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1182 | - |
|
| 1183 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1184 | - $PRT = EEM_Price_Type::instance(); |
|
| 1185 | - |
|
| 1186 | - // why be so pessimistic ??? : ( |
|
| 1187 | - $success = 0; |
|
| 1188 | - |
|
| 1189 | - $set_column_values = $this->set_price_type_column_values(); |
|
| 1190 | - // is this a new Price ? |
|
| 1191 | - if ($new_price_type) { |
|
| 1192 | - // run the insert |
|
| 1193 | - if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
| 1194 | - $success = 1; |
|
| 1195 | - } |
|
| 1196 | - $action_desc = 'created'; |
|
| 1197 | - } else { |
|
| 1198 | - $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
| 1199 | - // run the update |
|
| 1200 | - $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
| 1201 | - if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
| 1202 | - $success = 1; |
|
| 1203 | - } |
|
| 1204 | - $action_desc = 'updated'; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
| 1208 | - $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - |
|
| 1212 | - /** |
|
| 1213 | - * _trash_or_restore_price_type |
|
| 1214 | - * |
|
| 1215 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 1216 | - * @access protected |
|
| 1217 | - * @return void |
|
| 1218 | - */ |
|
| 1219 | - protected function _trash_or_restore_price_type($trash = true) |
|
| 1220 | - { |
|
| 1221 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1222 | - |
|
| 1223 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1224 | - $PRT = EEM_Price_Type::instance(); |
|
| 1225 | - |
|
| 1226 | - $success = 1; |
|
| 1227 | - $PRT_deleted = $trash ? true : false; |
|
| 1228 | - // Checkboxes |
|
| 1229 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1230 | - // if array has more than one element than success message should be plural |
|
| 1231 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1232 | - $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
| 1233 | - // cycle thru checkboxes |
|
| 1234 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1235 | - if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1236 | - $success = 0; |
|
| 1237 | - } |
|
| 1238 | - } |
|
| 1239 | - } else { |
|
| 1240 | - // grab single id and delete |
|
| 1241 | - $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 1242 | - if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1243 | - $success = 0; |
|
| 1244 | - } |
|
| 1245 | - $what = 'Price Type'; |
|
| 1246 | - } |
|
| 1247 | - |
|
| 1248 | - $query_args = array('action' => 'price_types'); |
|
| 1249 | - if ($success) { |
|
| 1250 | - if ($trash) { |
|
| 1251 | - $msg = $success > 1 |
|
| 1252 | - ? __('The Price Types have been trashed.', 'event_espresso') |
|
| 1253 | - : __( |
|
| 1254 | - 'The Price Type has been trashed.', |
|
| 1255 | - 'event_espresso' |
|
| 1256 | - ); |
|
| 1257 | - } else { |
|
| 1258 | - $msg = $success > 1 |
|
| 1259 | - ? __('The Price Types have been restored.', 'event_espresso') |
|
| 1260 | - : __( |
|
| 1261 | - 'The Price Type has been restored.', |
|
| 1262 | - 'event_espresso' |
|
| 1263 | - ); |
|
| 1264 | - } |
|
| 1265 | - EE_Error::add_success($msg); |
|
| 1266 | - } |
|
| 1267 | - |
|
| 1268 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * _delete_price_type |
|
| 1274 | - * |
|
| 1275 | - * @access protected |
|
| 1276 | - * @return void |
|
| 1277 | - */ |
|
| 1278 | - protected function _delete_price_type() |
|
| 1279 | - { |
|
| 1280 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1281 | - |
|
| 1282 | - $PRT = EEM_Price_Type::instance(); |
|
| 1283 | - |
|
| 1284 | - $success = 1; |
|
| 1285 | - // Checkboxes |
|
| 1286 | - if (! empty($this->_req_data['checkbox'])) { |
|
| 1287 | - // if array has more than one element than success message should be plural |
|
| 1288 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1289 | - $what = $PRT->item_name($success); |
|
| 1290 | - // cycle thru bulk action checkboxes |
|
| 1291 | - while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1292 | - if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
| 1293 | - $success = 0; |
|
| 1294 | - } |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - |
|
| 1299 | - $query_args = array('action' => 'price_types'); |
|
| 1300 | - $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
| 1301 | - } |
|
| 1302 | - |
|
| 1303 | - |
|
| 1304 | - /** |
|
| 1305 | - * _learn_more_about_pricing_link |
|
| 1306 | - * |
|
| 1307 | - * @access protected |
|
| 1308 | - * @return string |
|
| 1309 | - */ |
|
| 1310 | - protected function _learn_more_about_pricing_link() |
|
| 1311 | - { |
|
| 1312 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
| 1313 | - 'learn more about how pricing works', |
|
| 1314 | - 'event_espresso' |
|
| 1315 | - ) . '</a>'; |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - protected function _tax_settings() |
|
| 1320 | - { |
|
| 1321 | - $this->_set_add_edit_form_tags('update_tax_settings'); |
|
| 1322 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1323 | - $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
| 1324 | - $this->display_admin_page_with_sidebar(); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * @return \EE_Form_Section_Proper |
|
| 1330 | - * @throws \EE_Error |
|
| 1331 | - */ |
|
| 1332 | - protected function tax_settings_form() |
|
| 1333 | - { |
|
| 1334 | - return new EE_Form_Section_Proper( |
|
| 1335 | - array( |
|
| 1336 | - 'name' => 'tax_settings_form', |
|
| 1337 | - 'html_id' => 'tax_settings_form', |
|
| 1338 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1339 | - 'subsections' => apply_filters( |
|
| 1340 | - 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
| 1341 | - array( |
|
| 1342 | - 'tax_settings' => new EE_Form_Section_Proper( |
|
| 1343 | - array( |
|
| 1344 | - 'name' => 'tax_settings_tbl', |
|
| 1345 | - 'html_id' => 'tax_settings_tbl', |
|
| 1346 | - 'html_class' => 'form-table', |
|
| 1347 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1348 | - 'subsections' => array( |
|
| 1349 | - 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
| 1350 | - array( |
|
| 1351 | - 'html_label_text' => __( |
|
| 1352 | - "Show Prices With Taxes Included?", |
|
| 1353 | - 'event_espresso' |
|
| 1354 | - ), |
|
| 1355 | - 'html_help_text' => __( |
|
| 1356 | - 'Indicates whether or not to display prices with the taxes included', |
|
| 1357 | - 'event_espresso' |
|
| 1358 | - ), |
|
| 1359 | - 'default' => isset( |
|
| 1360 | - EE_Registry::instance() |
|
| 1361 | - ->CFG |
|
| 1362 | - ->tax_settings |
|
| 1363 | - ->prices_displayed_including_taxes |
|
| 1364 | - ) |
|
| 1365 | - ? EE_Registry::instance() |
|
| 1366 | - ->CFG |
|
| 1367 | - ->tax_settings |
|
| 1368 | - ->prices_displayed_including_taxes |
|
| 1369 | - : true, |
|
| 1370 | - 'display_html_label_text' => false, |
|
| 1371 | - ) |
|
| 1372 | - ), |
|
| 1373 | - ), |
|
| 1374 | - ) |
|
| 1375 | - ), |
|
| 1376 | - ) |
|
| 1377 | - ), |
|
| 1378 | - ) |
|
| 1379 | - ); |
|
| 1380 | - } |
|
| 1381 | - |
|
| 1382 | - |
|
| 1383 | - /** |
|
| 1384 | - * _update_tax_settings |
|
| 1385 | - * |
|
| 1386 | - * @since 4.9.13 |
|
| 1387 | - * @return void |
|
| 1388 | - */ |
|
| 1389 | - public function _update_tax_settings() |
|
| 1390 | - { |
|
| 1391 | - if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
| 1392 | - EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
| 1393 | - } |
|
| 1394 | - try { |
|
| 1395 | - $tax_form = $this->tax_settings_form(); |
|
| 1396 | - // check for form submission |
|
| 1397 | - if ($tax_form->was_submitted()) { |
|
| 1398 | - // capture form data |
|
| 1399 | - $tax_form->receive_form_submission(); |
|
| 1400 | - // validate form data |
|
| 1401 | - if ($tax_form->is_valid()) { |
|
| 1402 | - // grab validated data from form |
|
| 1403 | - $valid_data = $tax_form->valid_data(); |
|
| 1404 | - // set data on config |
|
| 1405 | - EE_Registry::instance() |
|
| 1406 | - ->CFG |
|
| 1407 | - ->tax_settings |
|
| 1408 | - ->prices_displayed_including_taxes |
|
| 1409 | - = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
| 1410 | - } else { |
|
| 1411 | - if ($tax_form->submission_error_message() !== '') { |
|
| 1412 | - EE_Error::add_error( |
|
| 1413 | - $tax_form->submission_error_message(), |
|
| 1414 | - __FILE__, |
|
| 1415 | - __FUNCTION__, |
|
| 1416 | - __LINE__ |
|
| 1417 | - ); |
|
| 1418 | - } |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - } catch (EE_Error $e) { |
|
| 1422 | - EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - $what = 'Tax Settings'; |
|
| 1426 | - $success = $this->_update_espresso_configuration( |
|
| 1427 | - $what, |
|
| 1428 | - EE_Registry::instance()->CFG->tax_settings, |
|
| 1429 | - __FILE__, |
|
| 1430 | - __FUNCTION__, |
|
| 1431 | - __LINE__ |
|
| 1432 | - ); |
|
| 1433 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
| 1434 | - } |
|
| 942 | + /** |
|
| 943 | + * generates HTML for main Prices Admin page |
|
| 944 | + * |
|
| 945 | + * @access protected |
|
| 946 | + * @return void |
|
| 947 | + */ |
|
| 948 | + protected function _price_types_overview_list_table() |
|
| 949 | + { |
|
| 950 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 951 | + 'add_new_price_type', |
|
| 952 | + 'add_type', |
|
| 953 | + array(), |
|
| 954 | + 'add-new-h2' |
|
| 955 | + ); |
|
| 956 | + $this->admin_page_title .= $this->_learn_more_about_pricing_link(); |
|
| 957 | + $this->_search_btn_label = __('Price Types', 'event_espresso'); |
|
| 958 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * retrieve data for Price Types List table |
|
| 964 | + * |
|
| 965 | + * @access public |
|
| 966 | + * @param int $per_page how many prices displayed per page |
|
| 967 | + * @param boolean $count return the count or objects |
|
| 968 | + * @param boolean $trashed whether the current view is of the trash can - eww yuck! |
|
| 969 | + * @return mixed (int|array) int = count || array of price objects |
|
| 970 | + */ |
|
| 971 | + public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false) |
|
| 972 | + { |
|
| 973 | + |
|
| 974 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 975 | + // start with an empty array |
|
| 976 | + |
|
| 977 | + require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php'); |
|
| 978 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 979 | + |
|
| 980 | + $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby']; |
|
| 981 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] |
|
| 982 | + : 'ASC'; |
|
| 983 | + switch ($this->_req_data['orderby']) { |
|
| 984 | + case 'name': |
|
| 985 | + $orderby = array('PRT_name' => $order); |
|
| 986 | + break; |
|
| 987 | + default: |
|
| 988 | + $orderby = array('PRT_order' => $order); |
|
| 989 | + } |
|
| 990 | + |
|
| 991 | + |
|
| 992 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 993 | + ? $this->_req_data['paged'] : 1; |
|
| 994 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 995 | + ? $this->_req_data['perpage'] : $per_page; |
|
| 996 | + |
|
| 997 | + $offset = ($current_page - 1) * $per_page; |
|
| 998 | + $limit = array($offset, $per_page); |
|
| 999 | + |
|
| 1000 | + $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1)); |
|
| 1001 | + |
|
| 1002 | + if (isset($this->_req_data['s'])) { |
|
| 1003 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 1004 | + $_where['OR'] = array( |
|
| 1005 | + 'PRT_name' => array('LIKE', $sstr), |
|
| 1006 | + ); |
|
| 1007 | + } |
|
| 1008 | + $query_params = array( |
|
| 1009 | + $_where, |
|
| 1010 | + 'order_by' => $orderby, |
|
| 1011 | + 'limit' => $limit, |
|
| 1012 | + ); |
|
| 1013 | + if ($count) { |
|
| 1014 | + return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params); |
|
| 1015 | + } else { |
|
| 1016 | + return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params); |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + // EEH_Debug_Tools::printr( $price_types, '$price_types <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + |
|
| 1023 | + /** |
|
| 1024 | + * _edit_price_type_details |
|
| 1025 | + * |
|
| 1026 | + * @access protected |
|
| 1027 | + * @return void |
|
| 1028 | + */ |
|
| 1029 | + protected function _edit_price_type_details() |
|
| 1030 | + { |
|
| 1031 | + |
|
| 1032 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1033 | + |
|
| 1034 | + |
|
| 1035 | + // grab price type ID |
|
| 1036 | + $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) |
|
| 1037 | + : false; |
|
| 1038 | + // change page title based on request action |
|
| 1039 | + switch ($this->_req_action) { |
|
| 1040 | + case 'add_new_price_type': |
|
| 1041 | + $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso'); |
|
| 1042 | + break; |
|
| 1043 | + case 'edit_price_type': |
|
| 1044 | + $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso'); |
|
| 1045 | + break; |
|
| 1046 | + default: |
|
| 1047 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
| 1048 | + } |
|
| 1049 | + // add PRT_ID to title if editing |
|
| 1050 | + $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title; |
|
| 1051 | + |
|
| 1052 | + if ($PRT_ID) { |
|
| 1053 | + $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID); |
|
| 1054 | + $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID)); |
|
| 1055 | + $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields); |
|
| 1056 | + } else { |
|
| 1057 | + $price_type = EEM_Price_Type::instance()->get_new_price_type(); |
|
| 1058 | + $this->_set_add_edit_form_tags('insert_price_type'); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + $this->_template_args['PRT_ID'] = $PRT_ID; |
|
| 1062 | + $this->_template_args['price_type'] = $price_type; |
|
| 1063 | + |
|
| 1064 | + |
|
| 1065 | + $base_types = EEM_Price_Type::instance()->get_base_types(); |
|
| 1066 | + $select_values = array(); |
|
| 1067 | + foreach ($base_types as $ref => $text) { |
|
| 1068 | + if ($ref == EEM_Price_Type::base_type_base_price) { |
|
| 1069 | + // do not allow creation of base_type_base_prices because that's a system only base type. |
|
| 1070 | + continue; |
|
| 1071 | + } |
|
| 1072 | + $values[] = array('id' => $ref, 'text' => $text); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + |
|
| 1076 | + $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input( |
|
| 1077 | + 'base_type', |
|
| 1078 | + $values, |
|
| 1079 | + $price_type->base_type(), |
|
| 1080 | + 'id="price-type-base-type-slct"' |
|
| 1081 | + ); |
|
| 1082 | + $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link(); |
|
| 1083 | + $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url); |
|
| 1084 | + $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL); |
|
| 1085 | + // the details template wrapper |
|
| 1086 | + $this->display_admin_page_with_sidebar(); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * declare price type details page metaboxes |
|
| 1092 | + * |
|
| 1093 | + * @access protected |
|
| 1094 | + * @return void |
|
| 1095 | + */ |
|
| 1096 | + protected function _price_type_details_meta_boxes() |
|
| 1097 | + { |
|
| 1098 | + add_meta_box( |
|
| 1099 | + 'edit-price-details-mbox', |
|
| 1100 | + __('Price Type Details', 'event_espresso'), |
|
| 1101 | + array($this, '_edit_price_type_details_meta_box'), |
|
| 1102 | + $this->wp_page_slug, |
|
| 1103 | + 'normal', |
|
| 1104 | + 'high' |
|
| 1105 | + ); |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + |
|
| 1109 | + /** |
|
| 1110 | + * _edit_price_type_details_meta_box |
|
| 1111 | + * |
|
| 1112 | + * @access public |
|
| 1113 | + * @return void |
|
| 1114 | + */ |
|
| 1115 | + public function _edit_price_type_details_meta_box() |
|
| 1116 | + { |
|
| 1117 | + echo EEH_Template::display_template( |
|
| 1118 | + PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php', |
|
| 1119 | + $this->_template_args, |
|
| 1120 | + true |
|
| 1121 | + ); |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * set_price_type_column_values |
|
| 1127 | + * |
|
| 1128 | + * @access protected |
|
| 1129 | + * @return void |
|
| 1130 | + */ |
|
| 1131 | + protected function set_price_type_column_values() |
|
| 1132 | + { |
|
| 1133 | + |
|
| 1134 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1135 | + |
|
| 1136 | + $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type'] |
|
| 1137 | + : EEM_Price_Type::base_type_base_price; |
|
| 1138 | + |
|
| 1139 | + switch ($base_type) { |
|
| 1140 | + case EEM_Price_Type::base_type_base_price: |
|
| 1141 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price; |
|
| 1142 | + $this->_req_data['PRT_is_percent'] = 0; |
|
| 1143 | + $this->_req_data['PRT_order'] = 0; |
|
| 1144 | + break; |
|
| 1145 | + |
|
| 1146 | + case EEM_Price_Type::base_type_discount: |
|
| 1147 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount; |
|
| 1148 | + break; |
|
| 1149 | + |
|
| 1150 | + case EEM_Price_Type::base_type_surcharge: |
|
| 1151 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge; |
|
| 1152 | + break; |
|
| 1153 | + |
|
| 1154 | + case EEM_Price_Type::base_type_tax: |
|
| 1155 | + $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax; |
|
| 1156 | + $this->_req_data['PRT_is_percent'] = 1; |
|
| 1157 | + break; |
|
| 1158 | + }/**/ |
|
| 1159 | + |
|
| 1160 | + $set_column_values = array( |
|
| 1161 | + 'PRT_name' => $this->_req_data['PRT_name'], |
|
| 1162 | + 'PBT_ID' => absint($this->_req_data['PBT_ID']), |
|
| 1163 | + 'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']), |
|
| 1164 | + 'PRT_order' => absint($this->_req_data['PRT_order']), |
|
| 1165 | + 'PRT_deleted' => 0, |
|
| 1166 | + ); |
|
| 1167 | + |
|
| 1168 | + return $set_column_values; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * _insert_or_update_price_type |
|
| 1174 | + * |
|
| 1175 | + * @param boolean $new_price_type - whether to insert or update |
|
| 1176 | + * @access protected |
|
| 1177 | + * @return void |
|
| 1178 | + */ |
|
| 1179 | + protected function _insert_or_update_price_type($new_price_type = false) |
|
| 1180 | + { |
|
| 1181 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1182 | + |
|
| 1183 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1184 | + $PRT = EEM_Price_Type::instance(); |
|
| 1185 | + |
|
| 1186 | + // why be so pessimistic ??? : ( |
|
| 1187 | + $success = 0; |
|
| 1188 | + |
|
| 1189 | + $set_column_values = $this->set_price_type_column_values(); |
|
| 1190 | + // is this a new Price ? |
|
| 1191 | + if ($new_price_type) { |
|
| 1192 | + // run the insert |
|
| 1193 | + if ($PRT_ID = $PRT->insert($set_column_values)) { |
|
| 1194 | + $success = 1; |
|
| 1195 | + } |
|
| 1196 | + $action_desc = 'created'; |
|
| 1197 | + } else { |
|
| 1198 | + $PRT_ID = absint($this->_req_data['PRT_ID']); |
|
| 1199 | + // run the update |
|
| 1200 | + $where_cols_n_values = array('PRT_ID' => $PRT_ID); |
|
| 1201 | + if ($PRT->update($set_column_values, array($where_cols_n_values))) { |
|
| 1202 | + $success = 1; |
|
| 1203 | + } |
|
| 1204 | + $action_desc = 'updated'; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID); |
|
| 1208 | + $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args); |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + |
|
| 1212 | + /** |
|
| 1213 | + * _trash_or_restore_price_type |
|
| 1214 | + * |
|
| 1215 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 1216 | + * @access protected |
|
| 1217 | + * @return void |
|
| 1218 | + */ |
|
| 1219 | + protected function _trash_or_restore_price_type($trash = true) |
|
| 1220 | + { |
|
| 1221 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1222 | + |
|
| 1223 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
| 1224 | + $PRT = EEM_Price_Type::instance(); |
|
| 1225 | + |
|
| 1226 | + $success = 1; |
|
| 1227 | + $PRT_deleted = $trash ? true : false; |
|
| 1228 | + // Checkboxes |
|
| 1229 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1230 | + // if array has more than one element than success message should be plural |
|
| 1231 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1232 | + $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type'; |
|
| 1233 | + // cycle thru checkboxes |
|
| 1234 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1235 | + if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1236 | + $success = 0; |
|
| 1237 | + } |
|
| 1238 | + } |
|
| 1239 | + } else { |
|
| 1240 | + // grab single id and delete |
|
| 1241 | + $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0; |
|
| 1242 | + if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) { |
|
| 1243 | + $success = 0; |
|
| 1244 | + } |
|
| 1245 | + $what = 'Price Type'; |
|
| 1246 | + } |
|
| 1247 | + |
|
| 1248 | + $query_args = array('action' => 'price_types'); |
|
| 1249 | + if ($success) { |
|
| 1250 | + if ($trash) { |
|
| 1251 | + $msg = $success > 1 |
|
| 1252 | + ? __('The Price Types have been trashed.', 'event_espresso') |
|
| 1253 | + : __( |
|
| 1254 | + 'The Price Type has been trashed.', |
|
| 1255 | + 'event_espresso' |
|
| 1256 | + ); |
|
| 1257 | + } else { |
|
| 1258 | + $msg = $success > 1 |
|
| 1259 | + ? __('The Price Types have been restored.', 'event_espresso') |
|
| 1260 | + : __( |
|
| 1261 | + 'The Price Type has been restored.', |
|
| 1262 | + 'event_espresso' |
|
| 1263 | + ); |
|
| 1264 | + } |
|
| 1265 | + EE_Error::add_success($msg); |
|
| 1266 | + } |
|
| 1267 | + |
|
| 1268 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * _delete_price_type |
|
| 1274 | + * |
|
| 1275 | + * @access protected |
|
| 1276 | + * @return void |
|
| 1277 | + */ |
|
| 1278 | + protected function _delete_price_type() |
|
| 1279 | + { |
|
| 1280 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1281 | + |
|
| 1282 | + $PRT = EEM_Price_Type::instance(); |
|
| 1283 | + |
|
| 1284 | + $success = 1; |
|
| 1285 | + // Checkboxes |
|
| 1286 | + if (! empty($this->_req_data['checkbox'])) { |
|
| 1287 | + // if array has more than one element than success message should be plural |
|
| 1288 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 1289 | + $what = $PRT->item_name($success); |
|
| 1290 | + // cycle thru bulk action checkboxes |
|
| 1291 | + while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1292 | + if (! $PRT->delete_permanently_by_ID($PRT_ID)) { |
|
| 1293 | + $success = 0; |
|
| 1294 | + } |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + |
|
| 1299 | + $query_args = array('action' => 'price_types'); |
|
| 1300 | + $this->_redirect_after_action($success, $what, 'deleted', $query_args); |
|
| 1301 | + } |
|
| 1302 | + |
|
| 1303 | + |
|
| 1304 | + /** |
|
| 1305 | + * _learn_more_about_pricing_link |
|
| 1306 | + * |
|
| 1307 | + * @access protected |
|
| 1308 | + * @return string |
|
| 1309 | + */ |
|
| 1310 | + protected function _learn_more_about_pricing_link() |
|
| 1311 | + { |
|
| 1312 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __( |
|
| 1313 | + 'learn more about how pricing works', |
|
| 1314 | + 'event_espresso' |
|
| 1315 | + ) . '</a>'; |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + protected function _tax_settings() |
|
| 1320 | + { |
|
| 1321 | + $this->_set_add_edit_form_tags('update_tax_settings'); |
|
| 1322 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
| 1323 | + $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html(); |
|
| 1324 | + $this->display_admin_page_with_sidebar(); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * @return \EE_Form_Section_Proper |
|
| 1330 | + * @throws \EE_Error |
|
| 1331 | + */ |
|
| 1332 | + protected function tax_settings_form() |
|
| 1333 | + { |
|
| 1334 | + return new EE_Form_Section_Proper( |
|
| 1335 | + array( |
|
| 1336 | + 'name' => 'tax_settings_form', |
|
| 1337 | + 'html_id' => 'tax_settings_form', |
|
| 1338 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1339 | + 'subsections' => apply_filters( |
|
| 1340 | + 'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections', |
|
| 1341 | + array( |
|
| 1342 | + 'tax_settings' => new EE_Form_Section_Proper( |
|
| 1343 | + array( |
|
| 1344 | + 'name' => 'tax_settings_tbl', |
|
| 1345 | + 'html_id' => 'tax_settings_tbl', |
|
| 1346 | + 'html_class' => 'form-table', |
|
| 1347 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1348 | + 'subsections' => array( |
|
| 1349 | + 'prices_displayed_including_taxes' => new EE_Yes_No_Input( |
|
| 1350 | + array( |
|
| 1351 | + 'html_label_text' => __( |
|
| 1352 | + "Show Prices With Taxes Included?", |
|
| 1353 | + 'event_espresso' |
|
| 1354 | + ), |
|
| 1355 | + 'html_help_text' => __( |
|
| 1356 | + 'Indicates whether or not to display prices with the taxes included', |
|
| 1357 | + 'event_espresso' |
|
| 1358 | + ), |
|
| 1359 | + 'default' => isset( |
|
| 1360 | + EE_Registry::instance() |
|
| 1361 | + ->CFG |
|
| 1362 | + ->tax_settings |
|
| 1363 | + ->prices_displayed_including_taxes |
|
| 1364 | + ) |
|
| 1365 | + ? EE_Registry::instance() |
|
| 1366 | + ->CFG |
|
| 1367 | + ->tax_settings |
|
| 1368 | + ->prices_displayed_including_taxes |
|
| 1369 | + : true, |
|
| 1370 | + 'display_html_label_text' => false, |
|
| 1371 | + ) |
|
| 1372 | + ), |
|
| 1373 | + ), |
|
| 1374 | + ) |
|
| 1375 | + ), |
|
| 1376 | + ) |
|
| 1377 | + ), |
|
| 1378 | + ) |
|
| 1379 | + ); |
|
| 1380 | + } |
|
| 1381 | + |
|
| 1382 | + |
|
| 1383 | + /** |
|
| 1384 | + * _update_tax_settings |
|
| 1385 | + * |
|
| 1386 | + * @since 4.9.13 |
|
| 1387 | + * @return void |
|
| 1388 | + */ |
|
| 1389 | + public function _update_tax_settings() |
|
| 1390 | + { |
|
| 1391 | + if (! isset(EE_Registry::instance()->CFG->tax_settings)) { |
|
| 1392 | + EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config(); |
|
| 1393 | + } |
|
| 1394 | + try { |
|
| 1395 | + $tax_form = $this->tax_settings_form(); |
|
| 1396 | + // check for form submission |
|
| 1397 | + if ($tax_form->was_submitted()) { |
|
| 1398 | + // capture form data |
|
| 1399 | + $tax_form->receive_form_submission(); |
|
| 1400 | + // validate form data |
|
| 1401 | + if ($tax_form->is_valid()) { |
|
| 1402 | + // grab validated data from form |
|
| 1403 | + $valid_data = $tax_form->valid_data(); |
|
| 1404 | + // set data on config |
|
| 1405 | + EE_Registry::instance() |
|
| 1406 | + ->CFG |
|
| 1407 | + ->tax_settings |
|
| 1408 | + ->prices_displayed_including_taxes |
|
| 1409 | + = $valid_data['tax_settings']['prices_displayed_including_taxes']; |
|
| 1410 | + } else { |
|
| 1411 | + if ($tax_form->submission_error_message() !== '') { |
|
| 1412 | + EE_Error::add_error( |
|
| 1413 | + $tax_form->submission_error_message(), |
|
| 1414 | + __FILE__, |
|
| 1415 | + __FUNCTION__, |
|
| 1416 | + __LINE__ |
|
| 1417 | + ); |
|
| 1418 | + } |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + } catch (EE_Error $e) { |
|
| 1422 | + EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + $what = 'Tax Settings'; |
|
| 1426 | + $success = $this->_update_espresso_configuration( |
|
| 1427 | + $what, |
|
| 1428 | + EE_Registry::instance()->CFG->tax_settings, |
|
| 1429 | + __FILE__, |
|
| 1430 | + __FUNCTION__, |
|
| 1431 | + __LINE__ |
|
| 1432 | + ); |
|
| 1433 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings')); |
|
| 1434 | + } |
|
| 1435 | 1435 | } |