@@ -164,7 +164,7 @@ |
||
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $ticket |
|
| 167 | + * @param \EE_Base_Class $ticket |
|
| 168 | 168 | * @throws DomainException |
| 169 | 169 | * @throws EE_Error |
| 170 | 170 | * @throws UnexpectedEntityException |
@@ -26,702 +26,702 @@ |
||
| 26 | 26 | class EventSpacesCalculator |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var EE_Event $event |
|
| 31 | - */ |
|
| 32 | - private $event; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array $datetime_query_params |
|
| 36 | - */ |
|
| 37 | - private $datetime_query_params; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var EE_Ticket[] $active_tickets |
|
| 41 | - */ |
|
| 42 | - private $active_tickets = array(); |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EE_Datetime[] $datetimes |
|
| 46 | - */ |
|
| 47 | - private $datetimes = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Array of Ticket IDs grouped by Datetime |
|
| 51 | - * |
|
| 52 | - * @var array $datetimes |
|
| 53 | - */ |
|
| 54 | - private $datetime_tickets = array(); |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Max spaces for each Datetime (reg limit - previous sold) |
|
| 58 | - * |
|
| 59 | - * @var array $datetime_spaces |
|
| 60 | - */ |
|
| 61 | - private $datetime_spaces = array(); |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Array of Datetime IDs grouped by Ticket |
|
| 65 | - * |
|
| 66 | - * @var array[] $ticket_datetimes |
|
| 67 | - */ |
|
| 68 | - private $ticket_datetimes = array(); |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 72 | - * |
|
| 73 | - * @var array $ticket_quantities |
|
| 74 | - */ |
|
| 75 | - private $ticket_quantities = array(); |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * total quantity of sold and reserved for each ticket |
|
| 79 | - * |
|
| 80 | - * @var array $tickets_sold |
|
| 81 | - */ |
|
| 82 | - private $tickets_sold = array(); |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * total spaces available across all datetimes |
|
| 86 | - * |
|
| 87 | - * @var array $total_spaces |
|
| 88 | - */ |
|
| 89 | - private $total_spaces = array(); |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var boolean $debug |
|
| 93 | - */ |
|
| 94 | - private $debug = false; // true false |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @var null|int $spaces_remaining |
|
| 98 | - */ |
|
| 99 | - private $spaces_remaining; |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @var null|int $total_spaces_available |
|
| 103 | - */ |
|
| 104 | - private $total_spaces_available; |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * EventSpacesCalculator constructor. |
|
| 109 | - * |
|
| 110 | - * @param EE_Event $event |
|
| 111 | - * @param array $datetime_query_params |
|
| 112 | - * @throws EE_Error |
|
| 113 | - */ |
|
| 114 | - public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 115 | - { |
|
| 116 | - $this->event = $event; |
|
| 117 | - $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 118 | - $this->setHooks(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - private function setHooks() |
|
| 126 | - { |
|
| 127 | - add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
| 128 | - add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
| 129 | - add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
| 130 | - add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
| 131 | - add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
| 132 | - add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
| 133 | - add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
| 134 | - add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return void |
|
| 140 | - */ |
|
| 141 | - public function clearResults() |
|
| 142 | - { |
|
| 143 | - $this->spaces_remaining = null; |
|
| 144 | - $this->total_spaces_available = null; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @return EE_Ticket[] |
|
| 150 | - * @throws EE_Error |
|
| 151 | - * @throws InvalidDataTypeException |
|
| 152 | - * @throws InvalidInterfaceException |
|
| 153 | - * @throws InvalidArgumentException |
|
| 154 | - */ |
|
| 155 | - public function getActiveTickets() |
|
| 156 | - { |
|
| 157 | - if (empty($this->active_tickets)) { |
|
| 158 | - $this->active_tickets = $this->event->tickets( |
|
| 159 | - array( |
|
| 160 | - array('TKT_deleted' => false), |
|
| 161 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - return $this->active_tickets; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param EE_Ticket[] $active_tickets |
|
| 171 | - * @throws EE_Error |
|
| 172 | - * @throws DomainException |
|
| 173 | - * @throws UnexpectedEntityException |
|
| 174 | - */ |
|
| 175 | - public function setActiveTickets(array $active_tickets = array()) |
|
| 176 | - { |
|
| 177 | - if (! empty($active_tickets)) { |
|
| 178 | - foreach ($active_tickets as $active_ticket) { |
|
| 179 | - $this->validateTicket($active_ticket); |
|
| 180 | - } |
|
| 181 | - // sort incoming array by ticket quantity (asc) |
|
| 182 | - usort( |
|
| 183 | - $active_tickets, |
|
| 184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 185 | - if ($a->qty() === $b->qty()) { |
|
| 186 | - return 0; |
|
| 187 | - } |
|
| 188 | - return ($a->qty() < $b->qty()) |
|
| 189 | - ? -1 |
|
| 190 | - : 1; |
|
| 191 | - } |
|
| 192 | - ); |
|
| 193 | - } |
|
| 194 | - $this->active_tickets = $active_tickets; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @param $ticket |
|
| 200 | - * @throws DomainException |
|
| 201 | - * @throws EE_Error |
|
| 202 | - * @throws UnexpectedEntityException |
|
| 203 | - */ |
|
| 204 | - private function validateTicket($ticket) |
|
| 205 | - { |
|
| 206 | - if (! $ticket instanceof EE_Ticket) { |
|
| 207 | - throw new DomainException( |
|
| 208 | - esc_html__( |
|
| 209 | - 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 210 | - 'event_espresso' |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - } |
|
| 214 | - if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 215 | - throw new DomainException( |
|
| 216 | - sprintf( |
|
| 217 | - esc_html__( |
|
| 218 | - 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 219 | - 'event_espresso' |
|
| 220 | - ), |
|
| 221 | - $ticket->get_event_ID(), |
|
| 222 | - $this->event->ID() |
|
| 223 | - ) |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * @return EE_Datetime[] |
|
| 231 | - */ |
|
| 232 | - public function getDatetimes() |
|
| 233 | - { |
|
| 234 | - return $this->datetimes; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param EE_Datetime $datetime |
|
| 240 | - * @throws EE_Error |
|
| 241 | - * @throws DomainException |
|
| 242 | - */ |
|
| 243 | - public function setDatetime(EE_Datetime $datetime) |
|
| 244 | - { |
|
| 245 | - if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 246 | - throw new DomainException( |
|
| 247 | - sprintf( |
|
| 248 | - esc_html__( |
|
| 249 | - 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 250 | - 'event_espresso' |
|
| 251 | - ), |
|
| 252 | - $datetime->event()->ID(), |
|
| 253 | - $this->event->ID() |
|
| 254 | - ) |
|
| 255 | - ); |
|
| 256 | - } |
|
| 257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * calculate spaces remaining based on "saleable" tickets |
|
| 263 | - * |
|
| 264 | - * @return float|int |
|
| 265 | - * @throws EE_Error |
|
| 266 | - * @throws DomainException |
|
| 267 | - * @throws UnexpectedEntityException |
|
| 268 | - * @throws InvalidDataTypeException |
|
| 269 | - * @throws InvalidInterfaceException |
|
| 270 | - * @throws InvalidArgumentException |
|
| 271 | - */ |
|
| 272 | - public function spacesRemaining() |
|
| 273 | - { |
|
| 274 | - if ($this->spaces_remaining === null) { |
|
| 275 | - $this->initialize(); |
|
| 276 | - $this->spaces_remaining = $this->calculate(); |
|
| 277 | - } |
|
| 278 | - return $this->spaces_remaining; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * calculates total available spaces for an event with no regard for sold tickets |
|
| 284 | - * |
|
| 285 | - * @return int|float |
|
| 286 | - * @throws EE_Error |
|
| 287 | - * @throws DomainException |
|
| 288 | - * @throws UnexpectedEntityException |
|
| 289 | - * @throws InvalidDataTypeException |
|
| 290 | - * @throws InvalidInterfaceException |
|
| 291 | - * @throws InvalidArgumentException |
|
| 292 | - */ |
|
| 293 | - public function totalSpacesAvailable() |
|
| 294 | - { |
|
| 295 | - if ($this->total_spaces_available === null) { |
|
| 296 | - $this->initialize(); |
|
| 297 | - $this->total_spaces_available = $this->calculate(false); |
|
| 298 | - } |
|
| 299 | - return $this->total_spaces_available; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Loops through the active tickets for the event |
|
| 305 | - * and builds a series of data arrays that will be used for calculating |
|
| 306 | - * the total maximum available spaces, as well as the spaces remaining. |
|
| 307 | - * Because ticket quantities affect datetime spaces and vice versa, |
|
| 308 | - * we need to be constantly updating these data arrays as things change, |
|
| 309 | - * which is the entire reason for their existence. |
|
| 310 | - * |
|
| 311 | - * @throws EE_Error |
|
| 312 | - * @throws DomainException |
|
| 313 | - * @throws UnexpectedEntityException |
|
| 314 | - * @throws InvalidDataTypeException |
|
| 315 | - * @throws InvalidInterfaceException |
|
| 316 | - * @throws InvalidArgumentException |
|
| 317 | - */ |
|
| 318 | - private function initialize() |
|
| 319 | - { |
|
| 320 | - if ($this->debug) { |
|
| 321 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 322 | - } |
|
| 323 | - $this->datetime_tickets = array(); |
|
| 324 | - $this->datetime_spaces = array(); |
|
| 325 | - $this->ticket_datetimes = array(); |
|
| 326 | - $this->ticket_quantities = array(); |
|
| 327 | - $this->tickets_sold = array(); |
|
| 328 | - $this->total_spaces = array(); |
|
| 329 | - $active_tickets = $this->getActiveTickets(); |
|
| 330 | - if (! empty($active_tickets)) { |
|
| 331 | - foreach ($active_tickets as $ticket) { |
|
| 332 | - $this->validateTicket($ticket); |
|
| 333 | - // we need to index our data arrays using strings for the purpose of sorting, |
|
| 334 | - // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 335 | - $ticket_identifier = "T{$ticket->ID()}"; |
|
| 336 | - // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
| 337 | - // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
| 338 | - $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
| 339 | - // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 340 | - $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 341 | - foreach ($ticket_datetimes as $datetime) { |
|
| 342 | - // save all datetimes |
|
| 343 | - $this->setDatetime($datetime); |
|
| 344 | - $datetime_identifier = "D{$datetime->ID()}"; |
|
| 345 | - $reg_limit = $datetime->reg_limit(); |
|
| 346 | - // ticket quantity can not exceed datetime reg limit |
|
| 347 | - $max_tickets = min($max_tickets, $reg_limit); |
|
| 348 | - // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 349 | - // we are going to move all of our data into the following arrays: |
|
| 350 | - // datetime spaces initially represents the reg limit for each datetime, |
|
| 351 | - // but this will get adjusted as tickets are accounted for |
|
| 352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 353 | - // just an array of ticket IDs grouped by datetime |
|
| 354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 355 | - // and an array of datetime IDs grouped by ticket |
|
| 356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 357 | - } |
|
| 358 | - // total quantity of sold and reserved for each ticket |
|
| 359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 360 | - // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 365 | - asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 366 | - // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 367 | - // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 368 | - // but overwrite all of the data with that from datetime_tickets |
|
| 369 | - $this->datetime_tickets = array_merge( |
|
| 370 | - $this->datetime_spaces, |
|
| 371 | - $this->datetime_tickets |
|
| 372 | - ); |
|
| 373 | - if ($this->debug) { |
|
| 374 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 375 | - \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 376 | - \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * performs calculations on initialized data |
|
| 383 | - * |
|
| 384 | - * @param bool $consider_sold |
|
| 385 | - * @return int|float |
|
| 386 | - */ |
|
| 387 | - private function calculate($consider_sold = true) |
|
| 388 | - { |
|
| 389 | - if ($this->debug) { |
|
| 390 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | - \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
| 392 | - } |
|
| 393 | - if ($consider_sold) { |
|
| 394 | - // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 395 | - $this->adjustTicketQuantitiesDueToSales(); |
|
| 396 | - } |
|
| 397 | - foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 398 | - $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 399 | - } |
|
| 400 | - // total spaces available is just the sum of the spaces available for each datetime |
|
| 401 | - $spaces_remaining = array_sum($this->total_spaces); |
|
| 402 | - if ($this->debug) { |
|
| 403 | - \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 404 | - \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 405 | - \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 406 | - } |
|
| 407 | - return $spaces_remaining; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 413 | - */ |
|
| 414 | - private function adjustTicketQuantitiesDueToSales() |
|
| 415 | - { |
|
| 416 | - if ($this->debug) { |
|
| 417 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 418 | - } |
|
| 419 | - foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 420 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 421 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 422 | - // don't let values go below zero |
|
| 423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
| 424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
| 425 | - 0 |
|
| 426 | - ); |
|
| 427 | - if ($this->debug) { |
|
| 428 | - \EEH_Debug_Tools::printr( |
|
| 429 | - "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
| 430 | - 'subtracting', |
|
| 431 | - __FILE__, |
|
| 432 | - __LINE__ |
|
| 433 | - ); |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 438 | - ) { |
|
| 439 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 440 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 441 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 442 | - // don't let values go below zero |
|
| 443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
| 444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
| 445 | - 0 |
|
| 446 | - ); |
|
| 447 | - if ($this->debug) { |
|
| 448 | - \EEH_Debug_Tools::printr( |
|
| 449 | - "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 450 | - 'subtracting', |
|
| 451 | - __FILE__, |
|
| 452 | - __LINE__ |
|
| 453 | - ); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * @param string $datetime_identifier |
|
| 464 | - * @param array $tickets |
|
| 465 | - */ |
|
| 466 | - private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 467 | - { |
|
| 468 | - // make sure a reg limit is set for the datetime |
|
| 469 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 470 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 471 | - : 0; |
|
| 472 | - // and bail if it is not |
|
| 473 | - if (! $reg_limit) { |
|
| 474 | - if ($this->debug) { |
|
| 475 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 476 | - } |
|
| 477 | - return; |
|
| 478 | - } |
|
| 479 | - if ($this->debug) { |
|
| 480 | - \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 481 | - \EEH_Debug_Tools::printr( |
|
| 482 | - "{$reg_limit}", |
|
| 483 | - 'REG LIMIT', |
|
| 484 | - __FILE__, |
|
| 485 | - __LINE__ |
|
| 486 | - ); |
|
| 487 | - } |
|
| 488 | - // number of allocated spaces always starts at zero |
|
| 489 | - $spaces_allocated = 0; |
|
| 490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 491 | - foreach ($tickets as $ticket_identifier) { |
|
| 492 | - $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 493 | - $datetime_identifier, |
|
| 494 | - $reg_limit, |
|
| 495 | - $ticket_identifier, |
|
| 496 | - $spaces_allocated |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - // spaces can't be negative |
|
| 500 | - $spaces_allocated = max($spaces_allocated, 0); |
|
| 501 | - if ($spaces_allocated) { |
|
| 502 | - // track any non-zero values |
|
| 503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 504 | - if ($this->debug) { |
|
| 505 | - \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 506 | - } |
|
| 507 | - } else { |
|
| 508 | - if ($this->debug) { |
|
| 509 | - \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - if ($this->debug) { |
|
| 513 | - \EEH_Debug_Tools::printr( |
|
| 514 | - $this->total_spaces[ $datetime_identifier ], |
|
| 515 | - '$total_spaces', |
|
| 516 | - __FILE__, |
|
| 517 | - __LINE__ |
|
| 518 | - ); |
|
| 519 | - \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 520 | - \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @param string $datetime_identifier |
|
| 527 | - * @param int $reg_limit |
|
| 528 | - * @param string $ticket_identifier |
|
| 529 | - * @param int $spaces_allocated |
|
| 530 | - * @return int |
|
| 531 | - */ |
|
| 532 | - private function calculateAvailableSpacesForTicket( |
|
| 533 | - $datetime_identifier, |
|
| 534 | - $reg_limit, |
|
| 535 | - $ticket_identifier, |
|
| 536 | - $spaces_allocated |
|
| 537 | - ) { |
|
| 538 | - // make sure ticket quantity is set |
|
| 539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 541 | - : 0; |
|
| 542 | - if ($this->debug) { |
|
| 543 | - \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 544 | - \EEH_Debug_Tools::printr( |
|
| 545 | - "{$ticket_quantity}", |
|
| 546 | - "ticket $ticket_identifier quantity: ", |
|
| 547 | - __FILE__, |
|
| 548 | - __LINE__, |
|
| 549 | - 2 |
|
| 550 | - ); |
|
| 551 | - } |
|
| 552 | - if ($ticket_quantity) { |
|
| 553 | - if ($this->debug) { |
|
| 554 | - \EEH_Debug_Tools::printr( |
|
| 555 | - ($spaces_allocated <= $reg_limit) |
|
| 556 | - ? 'true' |
|
| 557 | - : 'false', |
|
| 558 | - ' . spaces_allocated <= reg_limit = ', |
|
| 559 | - __FILE__, |
|
| 560 | - __LINE__ |
|
| 561 | - ); |
|
| 562 | - } |
|
| 563 | - // if the datetime is NOT at full capacity yet |
|
| 564 | - if ($spaces_allocated <= $reg_limit) { |
|
| 565 | - // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 566 | - // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 567 | - // or the maximum ticket quantity |
|
| 568 | - $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 569 | - // adjust the available quantity in our tracking array |
|
| 570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 571 | - // and increment spaces allocated for this datetime |
|
| 572 | - $spaces_allocated += $ticket_quantity; |
|
| 573 | - $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 574 | - if ($this->debug) { |
|
| 575 | - \EEH_Debug_Tools::printr( |
|
| 576 | - "{$ticket_quantity} {$ticket_identifier} tickets", |
|
| 577 | - ' > > allocate ', |
|
| 578 | - __FILE__, |
|
| 579 | - __LINE__, |
|
| 580 | - 3 |
|
| 581 | - ); |
|
| 582 | - if ($at_capacity) { |
|
| 583 | - \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - // now adjust all other datetimes that allow access to this ticket |
|
| 587 | - $this->adjustDatetimes( |
|
| 588 | - $datetime_identifier, |
|
| 589 | - $ticket_identifier, |
|
| 590 | - $ticket_quantity, |
|
| 591 | - $at_capacity |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - return $spaces_allocated; |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * subtracts ticket amounts from all datetime reg limits |
|
| 601 | - * that allow access to the ticket specified, |
|
| 602 | - * because that ticket could be used |
|
| 603 | - * to attend any of the datetimes it has access to |
|
| 604 | - * |
|
| 605 | - * @param string $datetime_identifier |
|
| 606 | - * @param string $ticket_identifier |
|
| 607 | - * @param bool $at_capacity |
|
| 608 | - * @param int $ticket_quantity |
|
| 609 | - */ |
|
| 610 | - private function adjustDatetimes( |
|
| 611 | - $datetime_identifier, |
|
| 612 | - $ticket_identifier, |
|
| 613 | - $ticket_quantity, |
|
| 614 | - $at_capacity |
|
| 615 | - ) { |
|
| 616 | - /** @var array $datetime_tickets */ |
|
| 617 | - foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 618 | - if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 619 | - continue; |
|
| 620 | - } |
|
| 621 | - $adjusted = $this->adjustDatetimeSpaces( |
|
| 622 | - $datetime_ID, |
|
| 623 | - $ticket_identifier, |
|
| 624 | - $ticket_quantity |
|
| 625 | - ); |
|
| 626 | - // skip to next ticket if nothing changed |
|
| 627 | - if (! ($adjusted || $at_capacity)) { |
|
| 628 | - continue; |
|
| 629 | - } |
|
| 630 | - // then all of it's tickets are now unavailable |
|
| 631 | - foreach ($datetime_tickets as $datetime_ticket) { |
|
| 632 | - if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 635 | - ) { |
|
| 636 | - if ($this->debug) { |
|
| 637 | - \EEH_Debug_Tools::printr( |
|
| 638 | - $datetime_ticket, |
|
| 639 | - ' . . . adjust ticket quantities for', |
|
| 640 | - __FILE__, |
|
| 641 | - __LINE__ |
|
| 642 | - ); |
|
| 643 | - } |
|
| 644 | - // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 645 | - // otherwise just subtract the ticket quantity |
|
| 646 | - $new_quantity = $at_capacity |
|
| 647 | - ? 0 |
|
| 648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 649 | - // don't let ticket quantity go below zero |
|
| 650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 651 | - if ($this->debug) { |
|
| 652 | - \EEH_Debug_Tools::printr( |
|
| 653 | - $at_capacity |
|
| 654 | - ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 656 | - " . . . . {$datetime_ticket} quantity set to ", |
|
| 657 | - __FILE__, |
|
| 658 | - __LINE__ |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 663 | - if ($datetime_ticket === $ticket_identifier) { |
|
| 664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 666 | - ) { |
|
| 667 | - if ($this->debug) { |
|
| 668 | - \EEH_Debug_Tools::printr( |
|
| 669 | - $datetime_ticket, |
|
| 670 | - ' . . adjust other Datetimes for', |
|
| 671 | - __FILE__, |
|
| 672 | - __LINE__ |
|
| 673 | - ); |
|
| 674 | - } |
|
| 675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 676 | - // don't adjust the current datetime twice |
|
| 677 | - if ($datetime !== $datetime_identifier) { |
|
| 678 | - $this->adjustDatetimeSpaces( |
|
| 679 | - $datetime, |
|
| 680 | - $datetime_ticket, |
|
| 681 | - $ticket_quantity |
|
| 682 | - ); |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 692 | - { |
|
| 693 | - // does datetime have spaces available? |
|
| 694 | - // and does the supplied ticket have access to this datetime ? |
|
| 695 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 696 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 697 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 698 | - ) { |
|
| 699 | - if ($this->debug) { |
|
| 700 | - \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 701 | - \EEH_Debug_Tools::printr( |
|
| 702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
| 703 | - " . . current {$datetime_identifier} spaces available", |
|
| 704 | - __FILE__, |
|
| 705 | - __LINE__ |
|
| 706 | - ); |
|
| 707 | - } |
|
| 708 | - // then decrement the available spaces for the datetime |
|
| 709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 710 | - // but don't let quantities go below zero |
|
| 711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 713 | - 0 |
|
| 714 | - ); |
|
| 715 | - if ($this->debug) { |
|
| 716 | - \EEH_Debug_Tools::printr( |
|
| 717 | - "{$ticket_quantity}", |
|
| 718 | - " . . . {$datetime_identifier} capacity reduced by", |
|
| 719 | - __FILE__, |
|
| 720 | - __LINE__ |
|
| 721 | - ); |
|
| 722 | - } |
|
| 723 | - return true; |
|
| 724 | - } |
|
| 725 | - return false; |
|
| 726 | - } |
|
| 29 | + /** |
|
| 30 | + * @var EE_Event $event |
|
| 31 | + */ |
|
| 32 | + private $event; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array $datetime_query_params |
|
| 36 | + */ |
|
| 37 | + private $datetime_query_params; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var EE_Ticket[] $active_tickets |
|
| 41 | + */ |
|
| 42 | + private $active_tickets = array(); |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EE_Datetime[] $datetimes |
|
| 46 | + */ |
|
| 47 | + private $datetimes = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Array of Ticket IDs grouped by Datetime |
|
| 51 | + * |
|
| 52 | + * @var array $datetimes |
|
| 53 | + */ |
|
| 54 | + private $datetime_tickets = array(); |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Max spaces for each Datetime (reg limit - previous sold) |
|
| 58 | + * |
|
| 59 | + * @var array $datetime_spaces |
|
| 60 | + */ |
|
| 61 | + private $datetime_spaces = array(); |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Array of Datetime IDs grouped by Ticket |
|
| 65 | + * |
|
| 66 | + * @var array[] $ticket_datetimes |
|
| 67 | + */ |
|
| 68 | + private $ticket_datetimes = array(); |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 72 | + * |
|
| 73 | + * @var array $ticket_quantities |
|
| 74 | + */ |
|
| 75 | + private $ticket_quantities = array(); |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * total quantity of sold and reserved for each ticket |
|
| 79 | + * |
|
| 80 | + * @var array $tickets_sold |
|
| 81 | + */ |
|
| 82 | + private $tickets_sold = array(); |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * total spaces available across all datetimes |
|
| 86 | + * |
|
| 87 | + * @var array $total_spaces |
|
| 88 | + */ |
|
| 89 | + private $total_spaces = array(); |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var boolean $debug |
|
| 93 | + */ |
|
| 94 | + private $debug = false; // true false |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @var null|int $spaces_remaining |
|
| 98 | + */ |
|
| 99 | + private $spaces_remaining; |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @var null|int $total_spaces_available |
|
| 103 | + */ |
|
| 104 | + private $total_spaces_available; |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * EventSpacesCalculator constructor. |
|
| 109 | + * |
|
| 110 | + * @param EE_Event $event |
|
| 111 | + * @param array $datetime_query_params |
|
| 112 | + * @throws EE_Error |
|
| 113 | + */ |
|
| 114 | + public function __construct(EE_Event $event, array $datetime_query_params = array()) |
|
| 115 | + { |
|
| 116 | + $this->event = $event; |
|
| 117 | + $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC')); |
|
| 118 | + $this->setHooks(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + private function setHooks() |
|
| 126 | + { |
|
| 127 | + add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults')); |
|
| 128 | + add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults')); |
|
| 129 | + add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults')); |
|
| 130 | + add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults')); |
|
| 131 | + add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults')); |
|
| 132 | + add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults')); |
|
| 133 | + add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults')); |
|
| 134 | + add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults')); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return void |
|
| 140 | + */ |
|
| 141 | + public function clearResults() |
|
| 142 | + { |
|
| 143 | + $this->spaces_remaining = null; |
|
| 144 | + $this->total_spaces_available = null; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @return EE_Ticket[] |
|
| 150 | + * @throws EE_Error |
|
| 151 | + * @throws InvalidDataTypeException |
|
| 152 | + * @throws InvalidInterfaceException |
|
| 153 | + * @throws InvalidArgumentException |
|
| 154 | + */ |
|
| 155 | + public function getActiveTickets() |
|
| 156 | + { |
|
| 157 | + if (empty($this->active_tickets)) { |
|
| 158 | + $this->active_tickets = $this->event->tickets( |
|
| 159 | + array( |
|
| 160 | + array('TKT_deleted' => false), |
|
| 161 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + return $this->active_tickets; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param EE_Ticket[] $active_tickets |
|
| 171 | + * @throws EE_Error |
|
| 172 | + * @throws DomainException |
|
| 173 | + * @throws UnexpectedEntityException |
|
| 174 | + */ |
|
| 175 | + public function setActiveTickets(array $active_tickets = array()) |
|
| 176 | + { |
|
| 177 | + if (! empty($active_tickets)) { |
|
| 178 | + foreach ($active_tickets as $active_ticket) { |
|
| 179 | + $this->validateTicket($active_ticket); |
|
| 180 | + } |
|
| 181 | + // sort incoming array by ticket quantity (asc) |
|
| 182 | + usort( |
|
| 183 | + $active_tickets, |
|
| 184 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
| 185 | + if ($a->qty() === $b->qty()) { |
|
| 186 | + return 0; |
|
| 187 | + } |
|
| 188 | + return ($a->qty() < $b->qty()) |
|
| 189 | + ? -1 |
|
| 190 | + : 1; |
|
| 191 | + } |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | + $this->active_tickets = $active_tickets; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @param $ticket |
|
| 200 | + * @throws DomainException |
|
| 201 | + * @throws EE_Error |
|
| 202 | + * @throws UnexpectedEntityException |
|
| 203 | + */ |
|
| 204 | + private function validateTicket($ticket) |
|
| 205 | + { |
|
| 206 | + if (! $ticket instanceof EE_Ticket) { |
|
| 207 | + throw new DomainException( |
|
| 208 | + esc_html__( |
|
| 209 | + 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
|
| 210 | + 'event_espresso' |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + } |
|
| 214 | + if ($ticket->get_event_ID() !== $this->event->ID()) { |
|
| 215 | + throw new DomainException( |
|
| 216 | + sprintf( |
|
| 217 | + esc_html__( |
|
| 218 | + 'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 219 | + 'event_espresso' |
|
| 220 | + ), |
|
| 221 | + $ticket->get_event_ID(), |
|
| 222 | + $this->event->ID() |
|
| 223 | + ) |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @return EE_Datetime[] |
|
| 231 | + */ |
|
| 232 | + public function getDatetimes() |
|
| 233 | + { |
|
| 234 | + return $this->datetimes; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param EE_Datetime $datetime |
|
| 240 | + * @throws EE_Error |
|
| 241 | + * @throws DomainException |
|
| 242 | + */ |
|
| 243 | + public function setDatetime(EE_Datetime $datetime) |
|
| 244 | + { |
|
| 245 | + if ($datetime->event()->ID() !== $this->event->ID()) { |
|
| 246 | + throw new DomainException( |
|
| 247 | + sprintf( |
|
| 248 | + esc_html__( |
|
| 249 | + 'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.', |
|
| 250 | + 'event_espresso' |
|
| 251 | + ), |
|
| 252 | + $datetime->event()->ID(), |
|
| 253 | + $this->event->ID() |
|
| 254 | + ) |
|
| 255 | + ); |
|
| 256 | + } |
|
| 257 | + $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * calculate spaces remaining based on "saleable" tickets |
|
| 263 | + * |
|
| 264 | + * @return float|int |
|
| 265 | + * @throws EE_Error |
|
| 266 | + * @throws DomainException |
|
| 267 | + * @throws UnexpectedEntityException |
|
| 268 | + * @throws InvalidDataTypeException |
|
| 269 | + * @throws InvalidInterfaceException |
|
| 270 | + * @throws InvalidArgumentException |
|
| 271 | + */ |
|
| 272 | + public function spacesRemaining() |
|
| 273 | + { |
|
| 274 | + if ($this->spaces_remaining === null) { |
|
| 275 | + $this->initialize(); |
|
| 276 | + $this->spaces_remaining = $this->calculate(); |
|
| 277 | + } |
|
| 278 | + return $this->spaces_remaining; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * calculates total available spaces for an event with no regard for sold tickets |
|
| 284 | + * |
|
| 285 | + * @return int|float |
|
| 286 | + * @throws EE_Error |
|
| 287 | + * @throws DomainException |
|
| 288 | + * @throws UnexpectedEntityException |
|
| 289 | + * @throws InvalidDataTypeException |
|
| 290 | + * @throws InvalidInterfaceException |
|
| 291 | + * @throws InvalidArgumentException |
|
| 292 | + */ |
|
| 293 | + public function totalSpacesAvailable() |
|
| 294 | + { |
|
| 295 | + if ($this->total_spaces_available === null) { |
|
| 296 | + $this->initialize(); |
|
| 297 | + $this->total_spaces_available = $this->calculate(false); |
|
| 298 | + } |
|
| 299 | + return $this->total_spaces_available; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Loops through the active tickets for the event |
|
| 305 | + * and builds a series of data arrays that will be used for calculating |
|
| 306 | + * the total maximum available spaces, as well as the spaces remaining. |
|
| 307 | + * Because ticket quantities affect datetime spaces and vice versa, |
|
| 308 | + * we need to be constantly updating these data arrays as things change, |
|
| 309 | + * which is the entire reason for their existence. |
|
| 310 | + * |
|
| 311 | + * @throws EE_Error |
|
| 312 | + * @throws DomainException |
|
| 313 | + * @throws UnexpectedEntityException |
|
| 314 | + * @throws InvalidDataTypeException |
|
| 315 | + * @throws InvalidInterfaceException |
|
| 316 | + * @throws InvalidArgumentException |
|
| 317 | + */ |
|
| 318 | + private function initialize() |
|
| 319 | + { |
|
| 320 | + if ($this->debug) { |
|
| 321 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 322 | + } |
|
| 323 | + $this->datetime_tickets = array(); |
|
| 324 | + $this->datetime_spaces = array(); |
|
| 325 | + $this->ticket_datetimes = array(); |
|
| 326 | + $this->ticket_quantities = array(); |
|
| 327 | + $this->tickets_sold = array(); |
|
| 328 | + $this->total_spaces = array(); |
|
| 329 | + $active_tickets = $this->getActiveTickets(); |
|
| 330 | + if (! empty($active_tickets)) { |
|
| 331 | + foreach ($active_tickets as $ticket) { |
|
| 332 | + $this->validateTicket($ticket); |
|
| 333 | + // we need to index our data arrays using strings for the purpose of sorting, |
|
| 334 | + // but we also need them to be unique, so we'll just prepend a letter T to the ID |
|
| 335 | + $ticket_identifier = "T{$ticket->ID()}"; |
|
| 336 | + // to start, we'll just consider the raw qty to be the maximum availability for this ticket, |
|
| 337 | + // unless the ticket is past its "sell until" date, in which case the qty will be 0 |
|
| 338 | + $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty(); |
|
| 339 | + // but we'll adjust that after looping over each datetime for the ticket and checking reg limits |
|
| 340 | + $ticket_datetimes = $ticket->datetimes($this->datetime_query_params); |
|
| 341 | + foreach ($ticket_datetimes as $datetime) { |
|
| 342 | + // save all datetimes |
|
| 343 | + $this->setDatetime($datetime); |
|
| 344 | + $datetime_identifier = "D{$datetime->ID()}"; |
|
| 345 | + $reg_limit = $datetime->reg_limit(); |
|
| 346 | + // ticket quantity can not exceed datetime reg limit |
|
| 347 | + $max_tickets = min($max_tickets, $reg_limit); |
|
| 348 | + // as described earlier, because we need to be able to constantly adjust numbers for things, |
|
| 349 | + // we are going to move all of our data into the following arrays: |
|
| 350 | + // datetime spaces initially represents the reg limit for each datetime, |
|
| 351 | + // but this will get adjusted as tickets are accounted for |
|
| 352 | + $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 353 | + // just an array of ticket IDs grouped by datetime |
|
| 354 | + $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 355 | + // and an array of datetime IDs grouped by ticket |
|
| 356 | + $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 357 | + } |
|
| 358 | + // total quantity of sold and reserved for each ticket |
|
| 359 | + $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 360 | + // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
|
| 361 | + $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + // sort datetime spaces by reg limit, but maintain our string indexes |
|
| 365 | + asort($this->datetime_spaces, SORT_NUMERIC); |
|
| 366 | + // datetime tickets need to be sorted in the SAME order as the above array... |
|
| 367 | + // so we'll just use array_merge() to take the structure of datetime_spaces |
|
| 368 | + // but overwrite all of the data with that from datetime_tickets |
|
| 369 | + $this->datetime_tickets = array_merge( |
|
| 370 | + $this->datetime_spaces, |
|
| 371 | + $this->datetime_tickets |
|
| 372 | + ); |
|
| 373 | + if ($this->debug) { |
|
| 374 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 375 | + \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__); |
|
| 376 | + \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * performs calculations on initialized data |
|
| 383 | + * |
|
| 384 | + * @param bool $consider_sold |
|
| 385 | + * @return int|float |
|
| 386 | + */ |
|
| 387 | + private function calculate($consider_sold = true) |
|
| 388 | + { |
|
| 389 | + if ($this->debug) { |
|
| 390 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 391 | + \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__); |
|
| 392 | + } |
|
| 393 | + if ($consider_sold) { |
|
| 394 | + // subtract amounts sold from all ticket quantities and datetime spaces |
|
| 395 | + $this->adjustTicketQuantitiesDueToSales(); |
|
| 396 | + } |
|
| 397 | + foreach ($this->datetime_tickets as $datetime_identifier => $tickets) { |
|
| 398 | + $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets); |
|
| 399 | + } |
|
| 400 | + // total spaces available is just the sum of the spaces available for each datetime |
|
| 401 | + $spaces_remaining = array_sum($this->total_spaces); |
|
| 402 | + if ($this->debug) { |
|
| 403 | + \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__); |
|
| 404 | + \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__); |
|
| 405 | + \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__); |
|
| 406 | + } |
|
| 407 | + return $spaces_remaining; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * subtracts amount of tickets sold from ticket quantities and datetime spaces |
|
| 413 | + */ |
|
| 414 | + private function adjustTicketQuantitiesDueToSales() |
|
| 415 | + { |
|
| 416 | + if ($this->debug) { |
|
| 417 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
| 418 | + } |
|
| 419 | + foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
|
| 420 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 421 | + $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 422 | + // don't let values go below zero |
|
| 423 | + $this->ticket_quantities[ $ticket_identifier ] = max( |
|
| 424 | + $this->ticket_quantities[ $ticket_identifier ], |
|
| 425 | + 0 |
|
| 426 | + ); |
|
| 427 | + if ($this->debug) { |
|
| 428 | + \EEH_Debug_Tools::printr( |
|
| 429 | + "{$tickets_sold} sales for ticket {$ticket_identifier} ", |
|
| 430 | + 'subtracting', |
|
| 431 | + __FILE__, |
|
| 432 | + __LINE__ |
|
| 433 | + ); |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 437 | + && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 438 | + ) { |
|
| 439 | + foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 440 | + if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 441 | + $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 442 | + // don't let values go below zero |
|
| 443 | + $this->datetime_spaces[ $ticket_datetime ] = max( |
|
| 444 | + $this->datetime_spaces[ $ticket_datetime ], |
|
| 445 | + 0 |
|
| 446 | + ); |
|
| 447 | + if ($this->debug) { |
|
| 448 | + \EEH_Debug_Tools::printr( |
|
| 449 | + "{$tickets_sold} sales for datetime {$ticket_datetime} ", |
|
| 450 | + 'subtracting', |
|
| 451 | + __FILE__, |
|
| 452 | + __LINE__ |
|
| 453 | + ); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * @param string $datetime_identifier |
|
| 464 | + * @param array $tickets |
|
| 465 | + */ |
|
| 466 | + private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
|
| 467 | + { |
|
| 468 | + // make sure a reg limit is set for the datetime |
|
| 469 | + $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 470 | + ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 471 | + : 0; |
|
| 472 | + // and bail if it is not |
|
| 473 | + if (! $reg_limit) { |
|
| 474 | + if ($this->debug) { |
|
| 475 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
|
| 476 | + } |
|
| 477 | + return; |
|
| 478 | + } |
|
| 479 | + if ($this->debug) { |
|
| 480 | + \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1); |
|
| 481 | + \EEH_Debug_Tools::printr( |
|
| 482 | + "{$reg_limit}", |
|
| 483 | + 'REG LIMIT', |
|
| 484 | + __FILE__, |
|
| 485 | + __LINE__ |
|
| 486 | + ); |
|
| 487 | + } |
|
| 488 | + // number of allocated spaces always starts at zero |
|
| 489 | + $spaces_allocated = 0; |
|
| 490 | + $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 491 | + foreach ($tickets as $ticket_identifier) { |
|
| 492 | + $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
|
| 493 | + $datetime_identifier, |
|
| 494 | + $reg_limit, |
|
| 495 | + $ticket_identifier, |
|
| 496 | + $spaces_allocated |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + // spaces can't be negative |
|
| 500 | + $spaces_allocated = max($spaces_allocated, 0); |
|
| 501 | + if ($spaces_allocated) { |
|
| 502 | + // track any non-zero values |
|
| 503 | + $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 504 | + if ($this->debug) { |
|
| 505 | + \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
|
| 506 | + } |
|
| 507 | + } else { |
|
| 508 | + if ($this->debug) { |
|
| 509 | + \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + if ($this->debug) { |
|
| 513 | + \EEH_Debug_Tools::printr( |
|
| 514 | + $this->total_spaces[ $datetime_identifier ], |
|
| 515 | + '$total_spaces', |
|
| 516 | + __FILE__, |
|
| 517 | + __LINE__ |
|
| 518 | + ); |
|
| 519 | + \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__); |
|
| 520 | + \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @param string $datetime_identifier |
|
| 527 | + * @param int $reg_limit |
|
| 528 | + * @param string $ticket_identifier |
|
| 529 | + * @param int $spaces_allocated |
|
| 530 | + * @return int |
|
| 531 | + */ |
|
| 532 | + private function calculateAvailableSpacesForTicket( |
|
| 533 | + $datetime_identifier, |
|
| 534 | + $reg_limit, |
|
| 535 | + $ticket_identifier, |
|
| 536 | + $spaces_allocated |
|
| 537 | + ) { |
|
| 538 | + // make sure ticket quantity is set |
|
| 539 | + $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 540 | + ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 541 | + : 0; |
|
| 542 | + if ($this->debug) { |
|
| 543 | + \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
|
| 544 | + \EEH_Debug_Tools::printr( |
|
| 545 | + "{$ticket_quantity}", |
|
| 546 | + "ticket $ticket_identifier quantity: ", |
|
| 547 | + __FILE__, |
|
| 548 | + __LINE__, |
|
| 549 | + 2 |
|
| 550 | + ); |
|
| 551 | + } |
|
| 552 | + if ($ticket_quantity) { |
|
| 553 | + if ($this->debug) { |
|
| 554 | + \EEH_Debug_Tools::printr( |
|
| 555 | + ($spaces_allocated <= $reg_limit) |
|
| 556 | + ? 'true' |
|
| 557 | + : 'false', |
|
| 558 | + ' . spaces_allocated <= reg_limit = ', |
|
| 559 | + __FILE__, |
|
| 560 | + __LINE__ |
|
| 561 | + ); |
|
| 562 | + } |
|
| 563 | + // if the datetime is NOT at full capacity yet |
|
| 564 | + if ($spaces_allocated <= $reg_limit) { |
|
| 565 | + // then the maximum ticket quantity we can allocate is the lowest value of either: |
|
| 566 | + // the number of remaining spaces for the datetime, which is the limit - spaces already taken |
|
| 567 | + // or the maximum ticket quantity |
|
| 568 | + $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
|
| 569 | + // adjust the available quantity in our tracking array |
|
| 570 | + $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 571 | + // and increment spaces allocated for this datetime |
|
| 572 | + $spaces_allocated += $ticket_quantity; |
|
| 573 | + $at_capacity = $spaces_allocated >= $reg_limit; |
|
| 574 | + if ($this->debug) { |
|
| 575 | + \EEH_Debug_Tools::printr( |
|
| 576 | + "{$ticket_quantity} {$ticket_identifier} tickets", |
|
| 577 | + ' > > allocate ', |
|
| 578 | + __FILE__, |
|
| 579 | + __LINE__, |
|
| 580 | + 3 |
|
| 581 | + ); |
|
| 582 | + if ($at_capacity) { |
|
| 583 | + \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3); |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + // now adjust all other datetimes that allow access to this ticket |
|
| 587 | + $this->adjustDatetimes( |
|
| 588 | + $datetime_identifier, |
|
| 589 | + $ticket_identifier, |
|
| 590 | + $ticket_quantity, |
|
| 591 | + $at_capacity |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + return $spaces_allocated; |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * subtracts ticket amounts from all datetime reg limits |
|
| 601 | + * that allow access to the ticket specified, |
|
| 602 | + * because that ticket could be used |
|
| 603 | + * to attend any of the datetimes it has access to |
|
| 604 | + * |
|
| 605 | + * @param string $datetime_identifier |
|
| 606 | + * @param string $ticket_identifier |
|
| 607 | + * @param bool $at_capacity |
|
| 608 | + * @param int $ticket_quantity |
|
| 609 | + */ |
|
| 610 | + private function adjustDatetimes( |
|
| 611 | + $datetime_identifier, |
|
| 612 | + $ticket_identifier, |
|
| 613 | + $ticket_quantity, |
|
| 614 | + $at_capacity |
|
| 615 | + ) { |
|
| 616 | + /** @var array $datetime_tickets */ |
|
| 617 | + foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) { |
|
| 618 | + if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) { |
|
| 619 | + continue; |
|
| 620 | + } |
|
| 621 | + $adjusted = $this->adjustDatetimeSpaces( |
|
| 622 | + $datetime_ID, |
|
| 623 | + $ticket_identifier, |
|
| 624 | + $ticket_quantity |
|
| 625 | + ); |
|
| 626 | + // skip to next ticket if nothing changed |
|
| 627 | + if (! ($adjusted || $at_capacity)) { |
|
| 628 | + continue; |
|
| 629 | + } |
|
| 630 | + // then all of it's tickets are now unavailable |
|
| 631 | + foreach ($datetime_tickets as $datetime_ticket) { |
|
| 632 | + if (($ticket_identifier === $datetime_ticket || $at_capacity) |
|
| 633 | + && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 634 | + && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 635 | + ) { |
|
| 636 | + if ($this->debug) { |
|
| 637 | + \EEH_Debug_Tools::printr( |
|
| 638 | + $datetime_ticket, |
|
| 639 | + ' . . . adjust ticket quantities for', |
|
| 640 | + __FILE__, |
|
| 641 | + __LINE__ |
|
| 642 | + ); |
|
| 643 | + } |
|
| 644 | + // if this datetime is at full capacity, set any tracked available quantities to zero |
|
| 645 | + // otherwise just subtract the ticket quantity |
|
| 646 | + $new_quantity = $at_capacity |
|
| 647 | + ? 0 |
|
| 648 | + : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 649 | + // don't let ticket quantity go below zero |
|
| 650 | + $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 651 | + if ($this->debug) { |
|
| 652 | + \EEH_Debug_Tools::printr( |
|
| 653 | + $at_capacity |
|
| 654 | + ? "0 because Datetime {$datetime_identifier} is at capacity" |
|
| 655 | + : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 656 | + " . . . . {$datetime_ticket} quantity set to ", |
|
| 657 | + __FILE__, |
|
| 658 | + __LINE__ |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + // but we also need to adjust spaces for any other datetimes this ticket has access to |
|
| 663 | + if ($datetime_ticket === $ticket_identifier) { |
|
| 664 | + if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 665 | + && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 666 | + ) { |
|
| 667 | + if ($this->debug) { |
|
| 668 | + \EEH_Debug_Tools::printr( |
|
| 669 | + $datetime_ticket, |
|
| 670 | + ' . . adjust other Datetimes for', |
|
| 671 | + __FILE__, |
|
| 672 | + __LINE__ |
|
| 673 | + ); |
|
| 674 | + } |
|
| 675 | + foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 676 | + // don't adjust the current datetime twice |
|
| 677 | + if ($datetime !== $datetime_identifier) { |
|
| 678 | + $this->adjustDatetimeSpaces( |
|
| 679 | + $datetime, |
|
| 680 | + $datetime_ticket, |
|
| 681 | + $ticket_quantity |
|
| 682 | + ); |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0) |
|
| 692 | + { |
|
| 693 | + // does datetime have spaces available? |
|
| 694 | + // and does the supplied ticket have access to this datetime ? |
|
| 695 | + if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 696 | + && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 697 | + && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 698 | + ) { |
|
| 699 | + if ($this->debug) { |
|
| 700 | + \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
|
| 701 | + \EEH_Debug_Tools::printr( |
|
| 702 | + "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
| 703 | + " . . current {$datetime_identifier} spaces available", |
|
| 704 | + __FILE__, |
|
| 705 | + __LINE__ |
|
| 706 | + ); |
|
| 707 | + } |
|
| 708 | + // then decrement the available spaces for the datetime |
|
| 709 | + $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 710 | + // but don't let quantities go below zero |
|
| 711 | + $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 712 | + $this->datetime_spaces[ $datetime_identifier ], |
|
| 713 | + 0 |
|
| 714 | + ); |
|
| 715 | + if ($this->debug) { |
|
| 716 | + \EEH_Debug_Tools::printr( |
|
| 717 | + "{$ticket_quantity}", |
|
| 718 | + " . . . {$datetime_identifier} capacity reduced by", |
|
| 719 | + __FILE__, |
|
| 720 | + __LINE__ |
|
| 721 | + ); |
|
| 722 | + } |
|
| 723 | + return true; |
|
| 724 | + } |
|
| 725 | + return false; |
|
| 726 | + } |
|
| 727 | 727 | } |
@@ -174,14 +174,14 @@ discard block |
||
| 174 | 174 | */ |
| 175 | 175 | public function setActiveTickets(array $active_tickets = array()) |
| 176 | 176 | { |
| 177 | - if (! empty($active_tickets)) { |
|
| 177 | + if ( ! empty($active_tickets)) { |
|
| 178 | 178 | foreach ($active_tickets as $active_ticket) { |
| 179 | 179 | $this->validateTicket($active_ticket); |
| 180 | 180 | } |
| 181 | 181 | // sort incoming array by ticket quantity (asc) |
| 182 | 182 | usort( |
| 183 | 183 | $active_tickets, |
| 184 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
| 184 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
| 185 | 185 | if ($a->qty() === $b->qty()) { |
| 186 | 186 | return 0; |
| 187 | 187 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | private function validateTicket($ticket) |
| 205 | 205 | { |
| 206 | - if (! $ticket instanceof EE_Ticket) { |
|
| 206 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 207 | 207 | throw new DomainException( |
| 208 | 208 | esc_html__( |
| 209 | 209 | 'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.', |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ) |
| 255 | 255 | ); |
| 256 | 256 | } |
| 257 | - $this->datetimes[ $datetime->ID() ] = $datetime; |
|
| 257 | + $this->datetimes[$datetime->ID()] = $datetime; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $this->tickets_sold = array(); |
| 328 | 328 | $this->total_spaces = array(); |
| 329 | 329 | $active_tickets = $this->getActiveTickets(); |
| 330 | - if (! empty($active_tickets)) { |
|
| 330 | + if ( ! empty($active_tickets)) { |
|
| 331 | 331 | foreach ($active_tickets as $ticket) { |
| 332 | 332 | $this->validateTicket($ticket); |
| 333 | 333 | // we need to index our data arrays using strings for the purpose of sorting, |
@@ -349,16 +349,16 @@ discard block |
||
| 349 | 349 | // we are going to move all of our data into the following arrays: |
| 350 | 350 | // datetime spaces initially represents the reg limit for each datetime, |
| 351 | 351 | // but this will get adjusted as tickets are accounted for |
| 352 | - $this->datetime_spaces[ $datetime_identifier ] = $reg_limit; |
|
| 352 | + $this->datetime_spaces[$datetime_identifier] = $reg_limit; |
|
| 353 | 353 | // just an array of ticket IDs grouped by datetime |
| 354 | - $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier; |
|
| 354 | + $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier; |
|
| 355 | 355 | // and an array of datetime IDs grouped by ticket |
| 356 | - $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier; |
|
| 356 | + $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier; |
|
| 357 | 357 | } |
| 358 | 358 | // total quantity of sold and reserved for each ticket |
| 359 | - $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved(); |
|
| 359 | + $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved(); |
|
| 360 | 360 | // and the maximum ticket quantities for each ticket (adjusted for reg limit) |
| 361 | - $this->ticket_quantities[ $ticket_identifier ] = $max_tickets; |
|
| 361 | + $this->ticket_quantities[$ticket_identifier] = $max_tickets; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | // sort datetime spaces by reg limit, but maintain our string indexes |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
| 418 | 418 | } |
| 419 | 419 | foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) { |
| 420 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 421 | - $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold; |
|
| 420 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 421 | + $this->ticket_quantities[$ticket_identifier] -= $tickets_sold; |
|
| 422 | 422 | // don't let values go below zero |
| 423 | - $this->ticket_quantities[ $ticket_identifier ] = max( |
|
| 424 | - $this->ticket_quantities[ $ticket_identifier ], |
|
| 423 | + $this->ticket_quantities[$ticket_identifier] = max( |
|
| 424 | + $this->ticket_quantities[$ticket_identifier], |
|
| 425 | 425 | 0 |
| 426 | 426 | ); |
| 427 | 427 | if ($this->debug) { |
@@ -433,15 +433,15 @@ discard block |
||
| 433 | 433 | ); |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | - if (isset($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 437 | - && is_array($this->ticket_datetimes[ $ticket_identifier ]) |
|
| 436 | + if (isset($this->ticket_datetimes[$ticket_identifier]) |
|
| 437 | + && is_array($this->ticket_datetimes[$ticket_identifier]) |
|
| 438 | 438 | ) { |
| 439 | - foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) { |
|
| 440 | - if (isset($this->ticket_quantities[ $ticket_identifier ])) { |
|
| 441 | - $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold; |
|
| 439 | + foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) { |
|
| 440 | + if (isset($this->ticket_quantities[$ticket_identifier])) { |
|
| 441 | + $this->datetime_spaces[$ticket_datetime] -= $tickets_sold; |
|
| 442 | 442 | // don't let values go below zero |
| 443 | - $this->datetime_spaces[ $ticket_datetime ] = max( |
|
| 444 | - $this->datetime_spaces[ $ticket_datetime ], |
|
| 443 | + $this->datetime_spaces[$ticket_datetime] = max( |
|
| 444 | + $this->datetime_spaces[$ticket_datetime], |
|
| 445 | 445 | 0 |
| 446 | 446 | ); |
| 447 | 447 | if ($this->debug) { |
@@ -466,11 +466,11 @@ discard block |
||
| 466 | 466 | private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets) |
| 467 | 467 | { |
| 468 | 468 | // make sure a reg limit is set for the datetime |
| 469 | - $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ]) |
|
| 470 | - ? $this->datetime_spaces[ $datetime_identifier ] |
|
| 469 | + $reg_limit = isset($this->datetime_spaces[$datetime_identifier]) |
|
| 470 | + ? $this->datetime_spaces[$datetime_identifier] |
|
| 471 | 471 | : 0; |
| 472 | 472 | // and bail if it is not |
| 473 | - if (! $reg_limit) { |
|
| 473 | + if ( ! $reg_limit) { |
|
| 474 | 474 | if ($this->debug) { |
| 475 | 475 | \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__); |
| 476 | 476 | } |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | } |
| 488 | 488 | // number of allocated spaces always starts at zero |
| 489 | 489 | $spaces_allocated = 0; |
| 490 | - $this->total_spaces[ $datetime_identifier ] = 0; |
|
| 490 | + $this->total_spaces[$datetime_identifier] = 0; |
|
| 491 | 491 | foreach ($tickets as $ticket_identifier) { |
| 492 | 492 | $spaces_allocated = $this->calculateAvailableSpacesForTicket( |
| 493 | 493 | $datetime_identifier, |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | $spaces_allocated = max($spaces_allocated, 0); |
| 501 | 501 | if ($spaces_allocated) { |
| 502 | 502 | // track any non-zero values |
| 503 | - $this->total_spaces[ $datetime_identifier ] += $spaces_allocated; |
|
| 503 | + $this->total_spaces[$datetime_identifier] += $spaces_allocated; |
|
| 504 | 504 | if ($this->debug) { |
| 505 | 505 | \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__); |
| 506 | 506 | } |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | if ($this->debug) { |
| 513 | 513 | \EEH_Debug_Tools::printr( |
| 514 | - $this->total_spaces[ $datetime_identifier ], |
|
| 514 | + $this->total_spaces[$datetime_identifier], |
|
| 515 | 515 | '$total_spaces', |
| 516 | 516 | __FILE__, |
| 517 | 517 | __LINE__ |
@@ -536,8 +536,8 @@ discard block |
||
| 536 | 536 | $spaces_allocated |
| 537 | 537 | ) { |
| 538 | 538 | // make sure ticket quantity is set |
| 539 | - $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ]) |
|
| 540 | - ? $this->ticket_quantities[ $ticket_identifier ] |
|
| 539 | + $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier]) |
|
| 540 | + ? $this->ticket_quantities[$ticket_identifier] |
|
| 541 | 541 | : 0; |
| 542 | 542 | if ($this->debug) { |
| 543 | 543 | \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__); |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | // or the maximum ticket quantity |
| 568 | 568 | $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity); |
| 569 | 569 | // adjust the available quantity in our tracking array |
| 570 | - $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity; |
|
| 570 | + $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity; |
|
| 571 | 571 | // and increment spaces allocated for this datetime |
| 572 | 572 | $spaces_allocated += $ticket_quantity; |
| 573 | 573 | $at_capacity = $spaces_allocated >= $reg_limit; |
@@ -624,14 +624,14 @@ discard block |
||
| 624 | 624 | $ticket_quantity |
| 625 | 625 | ); |
| 626 | 626 | // skip to next ticket if nothing changed |
| 627 | - if (! ($adjusted || $at_capacity)) { |
|
| 627 | + if ( ! ($adjusted || $at_capacity)) { |
|
| 628 | 628 | continue; |
| 629 | 629 | } |
| 630 | 630 | // then all of it's tickets are now unavailable |
| 631 | 631 | foreach ($datetime_tickets as $datetime_ticket) { |
| 632 | 632 | if (($ticket_identifier === $datetime_ticket || $at_capacity) |
| 633 | - && isset($this->ticket_quantities[ $datetime_ticket ]) |
|
| 634 | - && $this->ticket_quantities[ $datetime_ticket ] > 0 |
|
| 633 | + && isset($this->ticket_quantities[$datetime_ticket]) |
|
| 634 | + && $this->ticket_quantities[$datetime_ticket] > 0 |
|
| 635 | 635 | ) { |
| 636 | 636 | if ($this->debug) { |
| 637 | 637 | \EEH_Debug_Tools::printr( |
@@ -645,14 +645,14 @@ discard block |
||
| 645 | 645 | // otherwise just subtract the ticket quantity |
| 646 | 646 | $new_quantity = $at_capacity |
| 647 | 647 | ? 0 |
| 648 | - : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity; |
|
| 648 | + : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity; |
|
| 649 | 649 | // don't let ticket quantity go below zero |
| 650 | - $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0); |
|
| 650 | + $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0); |
|
| 651 | 651 | if ($this->debug) { |
| 652 | 652 | \EEH_Debug_Tools::printr( |
| 653 | 653 | $at_capacity |
| 654 | 654 | ? "0 because Datetime {$datetime_identifier} is at capacity" |
| 655 | - : "{$this->ticket_quantities[ $datetime_ticket ]}", |
|
| 655 | + : "{$this->ticket_quantities[$datetime_ticket]}", |
|
| 656 | 656 | " . . . . {$datetime_ticket} quantity set to ", |
| 657 | 657 | __FILE__, |
| 658 | 658 | __LINE__ |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | // but we also need to adjust spaces for any other datetimes this ticket has access to |
| 663 | 663 | if ($datetime_ticket === $ticket_identifier) { |
| 664 | - if (isset($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 665 | - && is_array($this->ticket_datetimes[ $datetime_ticket ]) |
|
| 664 | + if (isset($this->ticket_datetimes[$datetime_ticket]) |
|
| 665 | + && is_array($this->ticket_datetimes[$datetime_ticket]) |
|
| 666 | 666 | ) { |
| 667 | 667 | if ($this->debug) { |
| 668 | 668 | \EEH_Debug_Tools::printr( |
@@ -672,7 +672,7 @@ discard block |
||
| 672 | 672 | __LINE__ |
| 673 | 673 | ); |
| 674 | 674 | } |
| 675 | - foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) { |
|
| 675 | + foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) { |
|
| 676 | 676 | // don't adjust the current datetime twice |
| 677 | 677 | if ($datetime !== $datetime_identifier) { |
| 678 | 678 | $this->adjustDatetimeSpaces( |
@@ -692,24 +692,24 @@ discard block |
||
| 692 | 692 | { |
| 693 | 693 | // does datetime have spaces available? |
| 694 | 694 | // and does the supplied ticket have access to this datetime ? |
| 695 | - if ($this->datetime_spaces[ $datetime_identifier ] > 0 |
|
| 696 | - && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ]) |
|
| 697 | - && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true) |
|
| 695 | + if ($this->datetime_spaces[$datetime_identifier] > 0 |
|
| 696 | + && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier]) |
|
| 697 | + && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true) |
|
| 698 | 698 | ) { |
| 699 | 699 | if ($this->debug) { |
| 700 | 700 | \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__); |
| 701 | 701 | \EEH_Debug_Tools::printr( |
| 702 | - "{$this->datetime_spaces[ $datetime_identifier ]}", |
|
| 702 | + "{$this->datetime_spaces[$datetime_identifier]}", |
|
| 703 | 703 | " . . current {$datetime_identifier} spaces available", |
| 704 | 704 | __FILE__, |
| 705 | 705 | __LINE__ |
| 706 | 706 | ); |
| 707 | 707 | } |
| 708 | 708 | // then decrement the available spaces for the datetime |
| 709 | - $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity; |
|
| 709 | + $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity; |
|
| 710 | 710 | // but don't let quantities go below zero |
| 711 | - $this->datetime_spaces[ $datetime_identifier ] = max( |
|
| 712 | - $this->datetime_spaces[ $datetime_identifier ], |
|
| 711 | + $this->datetime_spaces[$datetime_identifier] = max( |
|
| 712 | + $this->datetime_spaces[$datetime_identifier], |
|
| 713 | 713 | 0 |
| 714 | 714 | ); |
| 715 | 715 | if ($this->debug) { |
@@ -64,6 +64,9 @@ |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
| 67 | + /** |
|
| 68 | + * @param string $argument_label |
|
| 69 | + */ |
|
| 67 | 70 | private function throwValidationException($argument_label, $argument_value) |
| 68 | 71 | { |
| 69 | 72 | throw new InvalidArgumentException( |
@@ -11,109 +11,109 @@ |
||
| 11 | 11 | class EE_Number_Input_Display_Strategy extends EE_Display_Strategy_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * minimum value for number field |
|
| 16 | - * |
|
| 17 | - * @var int|null $min |
|
| 18 | - */ |
|
| 19 | - protected $min; |
|
| 14 | + /** |
|
| 15 | + * minimum value for number field |
|
| 16 | + * |
|
| 17 | + * @var int|null $min |
|
| 18 | + */ |
|
| 19 | + protected $min; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * maximum value for number field |
|
| 23 | - * |
|
| 24 | - * @var int|null $max |
|
| 25 | - */ |
|
| 26 | - protected $max; |
|
| 21 | + /** |
|
| 22 | + * maximum value for number field |
|
| 23 | + * |
|
| 24 | + * @var int|null $max |
|
| 25 | + */ |
|
| 26 | + protected $max; |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * This is used to set the "step" attribute for the html5 number input. |
|
| 31 | - * Controls the increments on the input when incrementing or decrementing the value. |
|
| 32 | - * Note: Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that |
|
| 33 | - * to increment by 1. So although "any" is accepted as a value, it is converted to 1. |
|
| 34 | - * @var float |
|
| 35 | - */ |
|
| 36 | - protected $step; |
|
| 29 | + /** |
|
| 30 | + * This is used to set the "step" attribute for the html5 number input. |
|
| 31 | + * Controls the increments on the input when incrementing or decrementing the value. |
|
| 32 | + * Note: Although the step attribute allows for the string "any" to be used, Firefox and Chrome will interpret that |
|
| 33 | + * to increment by 1. So although "any" is accepted as a value, it is converted to 1. |
|
| 34 | + * @var float |
|
| 35 | + */ |
|
| 36 | + protected $step; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * EE_Number_Input_Display_Strategy constructor. |
|
| 41 | - * Null is the default value for the incoming arguments because 0 is a valid value. So we use null |
|
| 42 | - * to indicate NOT setting this attribute. |
|
| 43 | - * |
|
| 44 | - * @param int|null $min |
|
| 45 | - * @param int|null $max |
|
| 46 | - * @param int|null $step |
|
| 47 | - * @throws InvalidArgumentException |
|
| 48 | - */ |
|
| 49 | - public function __construct($min = null, $max = null, $step = null) |
|
| 50 | - { |
|
| 51 | - $this->min = is_numeric($min) || $min === null |
|
| 52 | - ? $min |
|
| 53 | - : $this->throwValidationException('min', $min); |
|
| 54 | - $this->max = is_numeric($max) || $max === null |
|
| 55 | - ? $max |
|
| 56 | - : $this->throwValidationException('max', $max); |
|
| 57 | - $step = $step === 'any' ? 1 : $step; |
|
| 58 | - $this->step = is_numeric($step) || $step === null |
|
| 59 | - ? $step |
|
| 60 | - : $this->throwValidationException('step', $step); |
|
| 61 | - } |
|
| 39 | + /** |
|
| 40 | + * EE_Number_Input_Display_Strategy constructor. |
|
| 41 | + * Null is the default value for the incoming arguments because 0 is a valid value. So we use null |
|
| 42 | + * to indicate NOT setting this attribute. |
|
| 43 | + * |
|
| 44 | + * @param int|null $min |
|
| 45 | + * @param int|null $max |
|
| 46 | + * @param int|null $step |
|
| 47 | + * @throws InvalidArgumentException |
|
| 48 | + */ |
|
| 49 | + public function __construct($min = null, $max = null, $step = null) |
|
| 50 | + { |
|
| 51 | + $this->min = is_numeric($min) || $min === null |
|
| 52 | + ? $min |
|
| 53 | + : $this->throwValidationException('min', $min); |
|
| 54 | + $this->max = is_numeric($max) || $max === null |
|
| 55 | + ? $max |
|
| 56 | + : $this->throwValidationException('max', $max); |
|
| 57 | + $step = $step === 'any' ? 1 : $step; |
|
| 58 | + $this->step = is_numeric($step) || $step === null |
|
| 59 | + ? $step |
|
| 60 | + : $this->throwValidationException('step', $step); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - private function throwValidationException($argument_label, $argument_value) |
|
| 65 | - { |
|
| 66 | - throw new InvalidArgumentException( |
|
| 67 | - sprintf( |
|
| 68 | - esc_html__( |
|
| 69 | - 'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.', |
|
| 70 | - 'event_espresso' |
|
| 71 | - ), |
|
| 72 | - $argument_label, |
|
| 73 | - __CLASS__, |
|
| 74 | - $argument_value |
|
| 75 | - ) |
|
| 76 | - ); |
|
| 77 | - } |
|
| 64 | + private function throwValidationException($argument_label, $argument_value) |
|
| 65 | + { |
|
| 66 | + throw new InvalidArgumentException( |
|
| 67 | + sprintf( |
|
| 68 | + esc_html__( |
|
| 69 | + 'The %1$s parameter value for %2$s must be numeric or null, %3$s was passed into the constructor.', |
|
| 70 | + 'event_espresso' |
|
| 71 | + ), |
|
| 72 | + $argument_label, |
|
| 73 | + __CLASS__, |
|
| 74 | + $argument_value |
|
| 75 | + ) |
|
| 76 | + ); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return string of html to display the field |
|
| 83 | - */ |
|
| 84 | - public function display() |
|
| 85 | - { |
|
| 86 | - $input = $this->_opening_tag('input'); |
|
| 87 | - $input .= $this->_attributes_string( |
|
| 88 | - array_merge( |
|
| 89 | - $this->_standard_attributes_array(), |
|
| 90 | - $this->getNumberInputAttributes() |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 93 | - $input .= $this->_close_tag(); |
|
| 94 | - return $input; |
|
| 95 | - } |
|
| 81 | + /** |
|
| 82 | + * @return string of html to display the field |
|
| 83 | + */ |
|
| 84 | + public function display() |
|
| 85 | + { |
|
| 86 | + $input = $this->_opening_tag('input'); |
|
| 87 | + $input .= $this->_attributes_string( |
|
| 88 | + array_merge( |
|
| 89 | + $this->_standard_attributes_array(), |
|
| 90 | + $this->getNumberInputAttributes() |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | + $input .= $this->_close_tag(); |
|
| 94 | + return $input; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Return the attributes specific to this display strategy |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - private function getNumberInputAttributes() |
|
| 103 | - { |
|
| 104 | - $attributes = array( |
|
| 105 | - 'type' => 'number', |
|
| 106 | - 'value' => $this->_input->raw_value_in_form() |
|
| 107 | - ); |
|
| 108 | - if ($this->min !== null) { |
|
| 109 | - $attributes['min'] = $this->min; |
|
| 110 | - } |
|
| 111 | - if ($this->max !== null) { |
|
| 112 | - $attributes['max'] = $this->max; |
|
| 113 | - } |
|
| 114 | - if ($this->step !== null) { |
|
| 115 | - $attributes['step'] = $this->step; |
|
| 116 | - } |
|
| 117 | - return $attributes; |
|
| 118 | - } |
|
| 98 | + /** |
|
| 99 | + * Return the attributes specific to this display strategy |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + private function getNumberInputAttributes() |
|
| 103 | + { |
|
| 104 | + $attributes = array( |
|
| 105 | + 'type' => 'number', |
|
| 106 | + 'value' => $this->_input->raw_value_in_form() |
|
| 107 | + ); |
|
| 108 | + if ($this->min !== null) { |
|
| 109 | + $attributes['min'] = $this->min; |
|
| 110 | + } |
|
| 111 | + if ($this->max !== null) { |
|
| 112 | + $attributes['max'] = $this->max; |
|
| 113 | + } |
|
| 114 | + if ($this->step !== null) { |
|
| 115 | + $attributes['step'] = $this->step; |
|
| 116 | + } |
|
| 117 | + return $attributes; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -11,33 +11,33 @@ |
||
| 11 | 11 | class EE_Float_Input extends EE_Form_Input_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param array $input_settings |
|
| 16 | - * @throws InvalidArgumentException |
|
| 17 | - */ |
|
| 18 | - public function __construct($input_settings = array()) |
|
| 19 | - { |
|
| 20 | - $this->_set_display_strategy( |
|
| 21 | - new EE_Number_Input_Display_Strategy( |
|
| 22 | - isset($input_settings['min_value']) |
|
| 23 | - ? $input_settings['min_value'] |
|
| 24 | - : null, |
|
| 25 | - isset($input_settings['max_value']) |
|
| 26 | - ? $input_settings['max_value'] |
|
| 27 | - : null, |
|
| 28 | - isset($input_settings['step_value']) |
|
| 29 | - ? $input_settings['step_value'] |
|
| 30 | - : null |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - $this->_set_normalization_strategy(new EE_Float_Normalization()); |
|
| 34 | - $this->_add_validation_strategy( |
|
| 35 | - new EE_Float_Validation_Strategy( |
|
| 36 | - isset($input_settings['validation_error_message']) |
|
| 37 | - ? $input_settings['validation_error_message'] |
|
| 38 | - : null |
|
| 39 | - ) |
|
| 40 | - ); |
|
| 41 | - parent::__construct($input_settings); |
|
| 42 | - } |
|
| 14 | + /** |
|
| 15 | + * @param array $input_settings |
|
| 16 | + * @throws InvalidArgumentException |
|
| 17 | + */ |
|
| 18 | + public function __construct($input_settings = array()) |
|
| 19 | + { |
|
| 20 | + $this->_set_display_strategy( |
|
| 21 | + new EE_Number_Input_Display_Strategy( |
|
| 22 | + isset($input_settings['min_value']) |
|
| 23 | + ? $input_settings['min_value'] |
|
| 24 | + : null, |
|
| 25 | + isset($input_settings['max_value']) |
|
| 26 | + ? $input_settings['max_value'] |
|
| 27 | + : null, |
|
| 28 | + isset($input_settings['step_value']) |
|
| 29 | + ? $input_settings['step_value'] |
|
| 30 | + : null |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + $this->_set_normalization_strategy(new EE_Float_Normalization()); |
|
| 34 | + $this->_add_validation_strategy( |
|
| 35 | + new EE_Float_Validation_Strategy( |
|
| 36 | + isset($input_settings['validation_error_message']) |
|
| 37 | + ? $input_settings['validation_error_message'] |
|
| 38 | + : null |
|
| 39 | + ) |
|
| 40 | + ); |
|
| 41 | + parent::__construct($input_settings); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -152,7 +152,7 @@ |
||
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * @param EE_Event $item |
| 155 | - * @return mixed|string |
|
| 155 | + * @return string |
|
| 156 | 156 | * @throws EE_Error |
| 157 | 157 | */ |
| 158 | 158 | public function column_id(EE_Event $item) |
@@ -15,504 +15,504 @@ |
||
| 15 | 15 | class Events_Admin_List_Table extends EE_Admin_List_Table |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var EE_Datetime |
|
| 20 | - */ |
|
| 21 | - private $_dtt; |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Initial setup of data properties for the list table. |
|
| 26 | - */ |
|
| 27 | - protected function _setup_data() |
|
| 28 | - { |
|
| 29 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 30 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Set up of additional properties for the list table. |
|
| 36 | - */ |
|
| 37 | - protected function _set_properties() |
|
| 38 | - { |
|
| 39 | - $this->_wp_list_args = array( |
|
| 40 | - 'singular' => esc_html__('event', 'event_espresso'), |
|
| 41 | - 'plural' => esc_html__('events', 'event_espresso'), |
|
| 42 | - 'ajax' => true, // for now |
|
| 43 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 44 | - ); |
|
| 45 | - $this->_columns = array( |
|
| 46 | - 'cb' => '<input type="checkbox" />', |
|
| 47 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
| 48 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
| 49 | - 'author' => esc_html__('Author', 'event_espresso'), |
|
| 50 | - 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 51 | - 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 52 | - 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 53 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 54 | - . '<span class="screen-reader-text">' |
|
| 55 | - . esc_html__('Approved Registrations', 'event_espresso') |
|
| 56 | - . '</span>' |
|
| 57 | - . '</span>', |
|
| 58 | - // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 59 | - 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 60 | - ); |
|
| 61 | - $this->_sortable_columns = array( |
|
| 62 | - 'id' => array('EVT_ID' => true), |
|
| 63 | - 'name' => array('EVT_name' => false), |
|
| 64 | - 'author' => array('EVT_wp_user' => false), |
|
| 65 | - 'venue' => array('Venue.VNU_name' => false), |
|
| 66 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 67 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 68 | - ); |
|
| 69 | - $this->_primary_column = 'id'; |
|
| 70 | - $this->_hidden_columns = array('author'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - protected function _get_table_filters() |
|
| 78 | - { |
|
| 79 | - return array(); // no filters with decaf |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Setup of views properties. |
|
| 85 | - * |
|
| 86 | - * @throws InvalidDataTypeException |
|
| 87 | - * @throws InvalidInterfaceException |
|
| 88 | - * @throws InvalidArgumentException |
|
| 89 | - */ |
|
| 90 | - protected function _add_view_counts() |
|
| 91 | - { |
|
| 92 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 93 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 94 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 95 | - 'ee_delete_events', |
|
| 96 | - 'espresso_events_trash_events' |
|
| 97 | - )) { |
|
| 98 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param EE_Event $item |
|
| 105 | - * @return string |
|
| 106 | - * @throws EE_Error |
|
| 107 | - */ |
|
| 108 | - protected function _get_row_class($item) |
|
| 109 | - { |
|
| 110 | - $class = parent::_get_row_class($item); |
|
| 111 | - // add status class |
|
| 112 | - $class .= $item instanceof EE_Event |
|
| 113 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 114 | - : ''; |
|
| 115 | - if ($this->_has_checkbox_column) { |
|
| 116 | - $class .= ' has-checkbox-column'; |
|
| 117 | - } |
|
| 118 | - return $class; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @param EE_Event $item |
|
| 124 | - * @return string |
|
| 125 | - * @throws EE_Error |
|
| 126 | - */ |
|
| 127 | - public function column_status(EE_Event $item) |
|
| 128 | - { |
|
| 129 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 130 | - . $item->get_active_status() |
|
| 131 | - . '"></span>'; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param EE_Event $item |
|
| 137 | - * @return string |
|
| 138 | - * @throws EE_Error |
|
| 139 | - */ |
|
| 140 | - public function column_cb($item) |
|
| 141 | - { |
|
| 142 | - if (! $item instanceof EE_Event) { |
|
| 143 | - return ''; |
|
| 144 | - } |
|
| 145 | - $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 146 | - // does event have any attached registrations? |
|
| 147 | - $regs = $item->count_related('Registration'); |
|
| 148 | - return $regs > 0 && $this->_view === 'trash' |
|
| 149 | - ? '<span class="ee-lock-icon"></span>' |
|
| 150 | - : sprintf( |
|
| 151 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 152 | - $item->ID() |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param EE_Event $item |
|
| 159 | - * @return mixed|string |
|
| 160 | - * @throws EE_Error |
|
| 161 | - */ |
|
| 162 | - public function column_id(EE_Event $item) |
|
| 163 | - { |
|
| 164 | - $content = $item->ID(); |
|
| 165 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 166 | - return $content; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param EE_Event $item |
|
| 172 | - * @return string |
|
| 173 | - * @throws EE_Error |
|
| 174 | - * @throws InvalidArgumentException |
|
| 175 | - * @throws InvalidDataTypeException |
|
| 176 | - * @throws InvalidInterfaceException |
|
| 177 | - */ |
|
| 178 | - public function column_name(EE_Event $item) |
|
| 179 | - { |
|
| 180 | - $edit_query_args = array( |
|
| 181 | - 'action' => 'edit', |
|
| 182 | - 'post' => $item->ID(), |
|
| 183 | - ); |
|
| 184 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 185 | - $actions = $this->_column_name_action_setup($item); |
|
| 186 | - $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 187 | - $content = '<strong><a class="row-title" href="' |
|
| 188 | - . $edit_link . '">' |
|
| 189 | - . $item->name() |
|
| 190 | - . '</a></strong>' |
|
| 191 | - . $status; |
|
| 192 | - $content .= '<br><span class="ee-status-text-small">' |
|
| 193 | - . EEH_Template::pretty_status( |
|
| 194 | - $item->get_active_status(), |
|
| 195 | - false, |
|
| 196 | - 'sentence' |
|
| 197 | - ) |
|
| 198 | - . '</span>'; |
|
| 199 | - $content .= $this->row_actions($actions); |
|
| 200 | - return $content; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Just a method for setting up the actions for the name column |
|
| 206 | - * |
|
| 207 | - * @param EE_Event $item |
|
| 208 | - * @return array array of actions |
|
| 209 | - * @throws EE_Error |
|
| 210 | - * @throws InvalidArgumentException |
|
| 211 | - * @throws InvalidDataTypeException |
|
| 212 | - * @throws InvalidInterfaceException |
|
| 213 | - */ |
|
| 214 | - protected function _column_name_action_setup(EE_Event $item) |
|
| 215 | - { |
|
| 216 | - // todo: remove when attendees is active |
|
| 217 | - if (! defined('REG_ADMIN_URL')) { |
|
| 218 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 219 | - } |
|
| 220 | - $actions = array(); |
|
| 221 | - $restore_event_link = ''; |
|
| 222 | - $delete_event_link = ''; |
|
| 223 | - $trash_event_link = ''; |
|
| 224 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | - 'ee_edit_event', |
|
| 226 | - 'espresso_events_edit', |
|
| 227 | - $item->ID() |
|
| 228 | - )) { |
|
| 229 | - $edit_query_args = array( |
|
| 230 | - 'action' => 'edit', |
|
| 231 | - 'post' => $item->ID(), |
|
| 232 | - ); |
|
| 233 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 234 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 235 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 236 | - . esc_html__('Edit', 'event_espresso') |
|
| 237 | - . '</a>'; |
|
| 238 | - } |
|
| 239 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 240 | - 'ee_read_registrations', |
|
| 241 | - 'espresso_registrations_view_registration' |
|
| 242 | - ) |
|
| 243 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 244 | - 'ee_read_event', |
|
| 245 | - 'espresso_registrations_view_registration', |
|
| 246 | - $item->ID() |
|
| 247 | - ) |
|
| 248 | - ) { |
|
| 249 | - $attendees_query_args = array( |
|
| 250 | - 'action' => 'default', |
|
| 251 | - 'event_id' => $item->ID(), |
|
| 252 | - ); |
|
| 253 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 254 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 255 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 256 | - . esc_html__('Registrations', 'event_espresso') |
|
| 257 | - . '</a>'; |
|
| 258 | - } |
|
| 259 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 260 | - 'ee_delete_event', |
|
| 261 | - 'espresso_events_trash_event', |
|
| 262 | - $item->ID() |
|
| 263 | - )) { |
|
| 264 | - $trash_event_query_args = array( |
|
| 265 | - 'action' => 'trash_event', |
|
| 266 | - 'EVT_ID' => $item->ID(), |
|
| 267 | - ); |
|
| 268 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 269 | - $trash_event_query_args, |
|
| 270 | - EVENTS_ADMIN_URL |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 274 | - 'ee_delete_event', |
|
| 275 | - 'espresso_events_restore_event', |
|
| 276 | - $item->ID() |
|
| 277 | - )) { |
|
| 278 | - $restore_event_query_args = array( |
|
| 279 | - 'action' => 'restore_event', |
|
| 280 | - 'EVT_ID' => $item->ID(), |
|
| 281 | - ); |
|
| 282 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 283 | - $restore_event_query_args, |
|
| 284 | - EVENTS_ADMIN_URL |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 288 | - 'ee_delete_event', |
|
| 289 | - 'espresso_events_delete_event', |
|
| 290 | - $item->ID() |
|
| 291 | - )) { |
|
| 292 | - $delete_event_query_args = array( |
|
| 293 | - 'action' => 'delete_event', |
|
| 294 | - 'EVT_ID' => $item->ID(), |
|
| 295 | - ); |
|
| 296 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 297 | - $delete_event_query_args, |
|
| 298 | - EVENTS_ADMIN_URL |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - $view_link = get_permalink($item->ID()); |
|
| 302 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 303 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 304 | - . esc_html__('View', 'event_espresso') |
|
| 305 | - . '</a>'; |
|
| 306 | - if ($item->get('status') === 'trash') { |
|
| 307 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 308 | - 'ee_delete_event', |
|
| 309 | - 'espresso_events_restore_event', |
|
| 310 | - $item->ID() |
|
| 311 | - )) { |
|
| 312 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 313 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 314 | - . '">' |
|
| 315 | - . esc_html__('Restore from Trash', 'event_espresso') |
|
| 316 | - . '</a>'; |
|
| 317 | - } |
|
| 318 | - if ($item->count_related('Registration') === 0 |
|
| 319 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 320 | - 'ee_delete_event', |
|
| 321 | - 'espresso_events_delete_event', |
|
| 322 | - $item->ID() |
|
| 323 | - ) |
|
| 324 | - ) { |
|
| 325 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 326 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 327 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
| 328 | - . '</a>'; |
|
| 329 | - } |
|
| 330 | - } else { |
|
| 331 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 332 | - 'ee_delete_event', |
|
| 333 | - 'espresso_events_trash_event', |
|
| 334 | - $item->ID() |
|
| 335 | - )) { |
|
| 336 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 337 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 338 | - . esc_html__('Trash', 'event_espresso') |
|
| 339 | - . '</a>'; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - return $actions; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * @param EE_Event $item |
|
| 348 | - * @return string |
|
| 349 | - * @throws EE_Error |
|
| 350 | - */ |
|
| 351 | - public function column_author(EE_Event $item) |
|
| 352 | - { |
|
| 353 | - // user author info |
|
| 354 | - $event_author = get_userdata($item->wp_user()); |
|
| 355 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 356 | - // filter link |
|
| 357 | - $query_args = array( |
|
| 358 | - 'action' => 'default', |
|
| 359 | - 'EVT_wp_user' => $item->wp_user(), |
|
| 360 | - ); |
|
| 361 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 362 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 363 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 364 | - . $event_author->display_name |
|
| 365 | - . '</a>'; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * @param EE_Event $item |
|
| 371 | - * @return string |
|
| 372 | - * @throws EE_Error |
|
| 373 | - */ |
|
| 374 | - public function column_venue(EE_Event $item) |
|
| 375 | - { |
|
| 376 | - $venue = $item->get_first_related('Venue'); |
|
| 377 | - return ! empty($venue) |
|
| 378 | - ? $venue->name() |
|
| 379 | - : ''; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @param EE_Event $item |
|
| 385 | - * @return string |
|
| 386 | - * @throws EE_Error |
|
| 387 | - */ |
|
| 388 | - public function column_start_date_time(EE_Event $item) |
|
| 389 | - { |
|
| 390 | - return $this->_dtt instanceof EE_Datetime |
|
| 391 | - ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 392 | - : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * @param EE_Event $item |
|
| 398 | - * @return string |
|
| 399 | - * @throws EE_Error |
|
| 400 | - */ |
|
| 401 | - public function column_reg_begins(EE_Event $item) |
|
| 402 | - { |
|
| 403 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 404 | - return $reg_start instanceof EE_Ticket |
|
| 405 | - ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 406 | - : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * @param EE_Event $item |
|
| 412 | - * @return int|string |
|
| 413 | - * @throws EE_Error |
|
| 414 | - * @throws InvalidArgumentException |
|
| 415 | - * @throws InvalidDataTypeException |
|
| 416 | - * @throws InvalidInterfaceException |
|
| 417 | - */ |
|
| 418 | - public function column_attendees(EE_Event $item) |
|
| 419 | - { |
|
| 420 | - $attendees_query_args = array( |
|
| 421 | - 'action' => 'default', |
|
| 422 | - 'event_id' => $item->ID(), |
|
| 423 | - ); |
|
| 424 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 425 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 426 | - return EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | - 'ee_read_event', |
|
| 428 | - 'espresso_registrations_view_registration', |
|
| 429 | - $item->ID() |
|
| 430 | - ) |
|
| 431 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 432 | - 'ee_read_registrations', |
|
| 433 | - 'espresso_registrations_view_registration' |
|
| 434 | - ) |
|
| 435 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 436 | - : $registered_attendees; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @param EE_Event $item |
|
| 442 | - * @return float |
|
| 443 | - * @throws EE_Error |
|
| 444 | - * @throws InvalidArgumentException |
|
| 445 | - * @throws InvalidDataTypeException |
|
| 446 | - * @throws InvalidInterfaceException |
|
| 447 | - */ |
|
| 448 | - public function column_tkts_sold(EE_Event $item) |
|
| 449 | - { |
|
| 450 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @param EE_Event $item |
|
| 456 | - * @return string |
|
| 457 | - * @throws EE_Error |
|
| 458 | - * @throws InvalidArgumentException |
|
| 459 | - * @throws InvalidDataTypeException |
|
| 460 | - * @throws InvalidInterfaceException |
|
| 461 | - */ |
|
| 462 | - public function column_actions(EE_Event $item) |
|
| 463 | - { |
|
| 464 | - // todo: remove when attendees is active |
|
| 465 | - if (! defined('REG_ADMIN_URL')) { |
|
| 466 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 467 | - } |
|
| 468 | - $action_links = array(); |
|
| 469 | - $view_link = get_permalink($item->ID()); |
|
| 470 | - $action_links[] = '<a href="' . $view_link . '"' |
|
| 471 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 472 | - $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 473 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 474 | - 'ee_edit_event', |
|
| 475 | - 'espresso_events_edit', |
|
| 476 | - $item->ID() |
|
| 477 | - )) { |
|
| 478 | - $edit_query_args = array( |
|
| 479 | - 'action' => 'edit', |
|
| 480 | - 'post' => $item->ID(), |
|
| 481 | - ); |
|
| 482 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 483 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
| 484 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 485 | - . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 486 | - . '</a>'; |
|
| 487 | - } |
|
| 488 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 489 | - 'ee_read_registrations', |
|
| 490 | - 'espresso_registrations_view_registration' |
|
| 491 | - ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | - 'ee_read_event', |
|
| 493 | - 'espresso_registrations_view_registration', |
|
| 494 | - $item->ID() |
|
| 495 | - ) |
|
| 496 | - ) { |
|
| 497 | - $attendees_query_args = array( |
|
| 498 | - 'action' => 'default', |
|
| 499 | - 'event_id' => $item->ID(), |
|
| 500 | - ); |
|
| 501 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 502 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 503 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 504 | - . '<div class="dashicons dashicons-groups"></div>' |
|
| 505 | - . '</a>'; |
|
| 506 | - } |
|
| 507 | - $action_links = apply_filters( |
|
| 508 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 509 | - $action_links, |
|
| 510 | - $item |
|
| 511 | - ); |
|
| 512 | - return $this->_action_string( |
|
| 513 | - implode("\n\t", $action_links), |
|
| 514 | - $item, |
|
| 515 | - 'div' |
|
| 516 | - ); |
|
| 517 | - } |
|
| 18 | + /** |
|
| 19 | + * @var EE_Datetime |
|
| 20 | + */ |
|
| 21 | + private $_dtt; |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Initial setup of data properties for the list table. |
|
| 26 | + */ |
|
| 27 | + protected function _setup_data() |
|
| 28 | + { |
|
| 29 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
| 30 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Set up of additional properties for the list table. |
|
| 36 | + */ |
|
| 37 | + protected function _set_properties() |
|
| 38 | + { |
|
| 39 | + $this->_wp_list_args = array( |
|
| 40 | + 'singular' => esc_html__('event', 'event_espresso'), |
|
| 41 | + 'plural' => esc_html__('events', 'event_espresso'), |
|
| 42 | + 'ajax' => true, // for now |
|
| 43 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
| 44 | + ); |
|
| 45 | + $this->_columns = array( |
|
| 46 | + 'cb' => '<input type="checkbox" />', |
|
| 47 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
| 48 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
| 49 | + 'author' => esc_html__('Author', 'event_espresso'), |
|
| 50 | + 'venue' => esc_html__('Venue', 'event_espresso'), |
|
| 51 | + 'start_date_time' => esc_html__('Event Start', 'event_espresso'), |
|
| 52 | + 'reg_begins' => esc_html__('On Sale', 'event_espresso'), |
|
| 53 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">' |
|
| 54 | + . '<span class="screen-reader-text">' |
|
| 55 | + . esc_html__('Approved Registrations', 'event_espresso') |
|
| 56 | + . '</span>' |
|
| 57 | + . '</span>', |
|
| 58 | + // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'), |
|
| 59 | + 'actions' => esc_html__('Actions', 'event_espresso'), |
|
| 60 | + ); |
|
| 61 | + $this->_sortable_columns = array( |
|
| 62 | + 'id' => array('EVT_ID' => true), |
|
| 63 | + 'name' => array('EVT_name' => false), |
|
| 64 | + 'author' => array('EVT_wp_user' => false), |
|
| 65 | + 'venue' => array('Venue.VNU_name' => false), |
|
| 66 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
| 67 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
| 68 | + ); |
|
| 69 | + $this->_primary_column = 'id'; |
|
| 70 | + $this->_hidden_columns = array('author'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + protected function _get_table_filters() |
|
| 78 | + { |
|
| 79 | + return array(); // no filters with decaf |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Setup of views properties. |
|
| 85 | + * |
|
| 86 | + * @throws InvalidDataTypeException |
|
| 87 | + * @throws InvalidInterfaceException |
|
| 88 | + * @throws InvalidArgumentException |
|
| 89 | + */ |
|
| 90 | + protected function _add_view_counts() |
|
| 91 | + { |
|
| 92 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
| 93 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
| 94 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 95 | + 'ee_delete_events', |
|
| 96 | + 'espresso_events_trash_events' |
|
| 97 | + )) { |
|
| 98 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param EE_Event $item |
|
| 105 | + * @return string |
|
| 106 | + * @throws EE_Error |
|
| 107 | + */ |
|
| 108 | + protected function _get_row_class($item) |
|
| 109 | + { |
|
| 110 | + $class = parent::_get_row_class($item); |
|
| 111 | + // add status class |
|
| 112 | + $class .= $item instanceof EE_Event |
|
| 113 | + ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 114 | + : ''; |
|
| 115 | + if ($this->_has_checkbox_column) { |
|
| 116 | + $class .= ' has-checkbox-column'; |
|
| 117 | + } |
|
| 118 | + return $class; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @param EE_Event $item |
|
| 124 | + * @return string |
|
| 125 | + * @throws EE_Error |
|
| 126 | + */ |
|
| 127 | + public function column_status(EE_Event $item) |
|
| 128 | + { |
|
| 129 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' |
|
| 130 | + . $item->get_active_status() |
|
| 131 | + . '"></span>'; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param EE_Event $item |
|
| 137 | + * @return string |
|
| 138 | + * @throws EE_Error |
|
| 139 | + */ |
|
| 140 | + public function column_cb($item) |
|
| 141 | + { |
|
| 142 | + if (! $item instanceof EE_Event) { |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | + $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
|
| 146 | + // does event have any attached registrations? |
|
| 147 | + $regs = $item->count_related('Registration'); |
|
| 148 | + return $regs > 0 && $this->_view === 'trash' |
|
| 149 | + ? '<span class="ee-lock-icon"></span>' |
|
| 150 | + : sprintf( |
|
| 151 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', |
|
| 152 | + $item->ID() |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param EE_Event $item |
|
| 159 | + * @return mixed|string |
|
| 160 | + * @throws EE_Error |
|
| 161 | + */ |
|
| 162 | + public function column_id(EE_Event $item) |
|
| 163 | + { |
|
| 164 | + $content = $item->ID(); |
|
| 165 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 166 | + return $content; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param EE_Event $item |
|
| 172 | + * @return string |
|
| 173 | + * @throws EE_Error |
|
| 174 | + * @throws InvalidArgumentException |
|
| 175 | + * @throws InvalidDataTypeException |
|
| 176 | + * @throws InvalidInterfaceException |
|
| 177 | + */ |
|
| 178 | + public function column_name(EE_Event $item) |
|
| 179 | + { |
|
| 180 | + $edit_query_args = array( |
|
| 181 | + 'action' => 'edit', |
|
| 182 | + 'post' => $item->ID(), |
|
| 183 | + ); |
|
| 184 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 185 | + $actions = $this->_column_name_action_setup($item); |
|
| 186 | + $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
| 187 | + $content = '<strong><a class="row-title" href="' |
|
| 188 | + . $edit_link . '">' |
|
| 189 | + . $item->name() |
|
| 190 | + . '</a></strong>' |
|
| 191 | + . $status; |
|
| 192 | + $content .= '<br><span class="ee-status-text-small">' |
|
| 193 | + . EEH_Template::pretty_status( |
|
| 194 | + $item->get_active_status(), |
|
| 195 | + false, |
|
| 196 | + 'sentence' |
|
| 197 | + ) |
|
| 198 | + . '</span>'; |
|
| 199 | + $content .= $this->row_actions($actions); |
|
| 200 | + return $content; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Just a method for setting up the actions for the name column |
|
| 206 | + * |
|
| 207 | + * @param EE_Event $item |
|
| 208 | + * @return array array of actions |
|
| 209 | + * @throws EE_Error |
|
| 210 | + * @throws InvalidArgumentException |
|
| 211 | + * @throws InvalidDataTypeException |
|
| 212 | + * @throws InvalidInterfaceException |
|
| 213 | + */ |
|
| 214 | + protected function _column_name_action_setup(EE_Event $item) |
|
| 215 | + { |
|
| 216 | + // todo: remove when attendees is active |
|
| 217 | + if (! defined('REG_ADMIN_URL')) { |
|
| 218 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 219 | + } |
|
| 220 | + $actions = array(); |
|
| 221 | + $restore_event_link = ''; |
|
| 222 | + $delete_event_link = ''; |
|
| 223 | + $trash_event_link = ''; |
|
| 224 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 225 | + 'ee_edit_event', |
|
| 226 | + 'espresso_events_edit', |
|
| 227 | + $item->ID() |
|
| 228 | + )) { |
|
| 229 | + $edit_query_args = array( |
|
| 230 | + 'action' => 'edit', |
|
| 231 | + 'post' => $item->ID(), |
|
| 232 | + ); |
|
| 233 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 234 | + $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 235 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 236 | + . esc_html__('Edit', 'event_espresso') |
|
| 237 | + . '</a>'; |
|
| 238 | + } |
|
| 239 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 240 | + 'ee_read_registrations', |
|
| 241 | + 'espresso_registrations_view_registration' |
|
| 242 | + ) |
|
| 243 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 244 | + 'ee_read_event', |
|
| 245 | + 'espresso_registrations_view_registration', |
|
| 246 | + $item->ID() |
|
| 247 | + ) |
|
| 248 | + ) { |
|
| 249 | + $attendees_query_args = array( |
|
| 250 | + 'action' => 'default', |
|
| 251 | + 'event_id' => $item->ID(), |
|
| 252 | + ); |
|
| 253 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 254 | + $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 255 | + . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 256 | + . esc_html__('Registrations', 'event_espresso') |
|
| 257 | + . '</a>'; |
|
| 258 | + } |
|
| 259 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 260 | + 'ee_delete_event', |
|
| 261 | + 'espresso_events_trash_event', |
|
| 262 | + $item->ID() |
|
| 263 | + )) { |
|
| 264 | + $trash_event_query_args = array( |
|
| 265 | + 'action' => 'trash_event', |
|
| 266 | + 'EVT_ID' => $item->ID(), |
|
| 267 | + ); |
|
| 268 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 269 | + $trash_event_query_args, |
|
| 270 | + EVENTS_ADMIN_URL |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 274 | + 'ee_delete_event', |
|
| 275 | + 'espresso_events_restore_event', |
|
| 276 | + $item->ID() |
|
| 277 | + )) { |
|
| 278 | + $restore_event_query_args = array( |
|
| 279 | + 'action' => 'restore_event', |
|
| 280 | + 'EVT_ID' => $item->ID(), |
|
| 281 | + ); |
|
| 282 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 283 | + $restore_event_query_args, |
|
| 284 | + EVENTS_ADMIN_URL |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 288 | + 'ee_delete_event', |
|
| 289 | + 'espresso_events_delete_event', |
|
| 290 | + $item->ID() |
|
| 291 | + )) { |
|
| 292 | + $delete_event_query_args = array( |
|
| 293 | + 'action' => 'delete_event', |
|
| 294 | + 'EVT_ID' => $item->ID(), |
|
| 295 | + ); |
|
| 296 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 297 | + $delete_event_query_args, |
|
| 298 | + EVENTS_ADMIN_URL |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + $view_link = get_permalink($item->ID()); |
|
| 302 | + $actions['view'] = '<a href="' . $view_link . '"' |
|
| 303 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 304 | + . esc_html__('View', 'event_espresso') |
|
| 305 | + . '</a>'; |
|
| 306 | + if ($item->get('status') === 'trash') { |
|
| 307 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 308 | + 'ee_delete_event', |
|
| 309 | + 'espresso_events_restore_event', |
|
| 310 | + $item->ID() |
|
| 311 | + )) { |
|
| 312 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 313 | + . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 314 | + . '">' |
|
| 315 | + . esc_html__('Restore from Trash', 'event_espresso') |
|
| 316 | + . '</a>'; |
|
| 317 | + } |
|
| 318 | + if ($item->count_related('Registration') === 0 |
|
| 319 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 320 | + 'ee_delete_event', |
|
| 321 | + 'espresso_events_delete_event', |
|
| 322 | + $item->ID() |
|
| 323 | + ) |
|
| 324 | + ) { |
|
| 325 | + $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 326 | + . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 327 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
| 328 | + . '</a>'; |
|
| 329 | + } |
|
| 330 | + } else { |
|
| 331 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 332 | + 'ee_delete_event', |
|
| 333 | + 'espresso_events_trash_event', |
|
| 334 | + $item->ID() |
|
| 335 | + )) { |
|
| 336 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 337 | + . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 338 | + . esc_html__('Trash', 'event_espresso') |
|
| 339 | + . '</a>'; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + return $actions; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * @param EE_Event $item |
|
| 348 | + * @return string |
|
| 349 | + * @throws EE_Error |
|
| 350 | + */ |
|
| 351 | + public function column_author(EE_Event $item) |
|
| 352 | + { |
|
| 353 | + // user author info |
|
| 354 | + $event_author = get_userdata($item->wp_user()); |
|
| 355 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
| 356 | + // filter link |
|
| 357 | + $query_args = array( |
|
| 358 | + 'action' => 'default', |
|
| 359 | + 'EVT_wp_user' => $item->wp_user(), |
|
| 360 | + ); |
|
| 361 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
| 362 | + return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 363 | + . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 364 | + . $event_author->display_name |
|
| 365 | + . '</a>'; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * @param EE_Event $item |
|
| 371 | + * @return string |
|
| 372 | + * @throws EE_Error |
|
| 373 | + */ |
|
| 374 | + public function column_venue(EE_Event $item) |
|
| 375 | + { |
|
| 376 | + $venue = $item->get_first_related('Venue'); |
|
| 377 | + return ! empty($venue) |
|
| 378 | + ? $venue->name() |
|
| 379 | + : ''; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @param EE_Event $item |
|
| 385 | + * @return string |
|
| 386 | + * @throws EE_Error |
|
| 387 | + */ |
|
| 388 | + public function column_start_date_time(EE_Event $item) |
|
| 389 | + { |
|
| 390 | + return $this->_dtt instanceof EE_Datetime |
|
| 391 | + ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') |
|
| 392 | + : esc_html__('No Date was saved for this Event', 'event_espresso'); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * @param EE_Event $item |
|
| 398 | + * @return string |
|
| 399 | + * @throws EE_Error |
|
| 400 | + */ |
|
| 401 | + public function column_reg_begins(EE_Event $item) |
|
| 402 | + { |
|
| 403 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
| 404 | + return $reg_start instanceof EE_Ticket |
|
| 405 | + ? $reg_start->get_i18n_datetime('TKT_start_date') |
|
| 406 | + : esc_html__('No Tickets have been setup for this Event', 'event_espresso'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * @param EE_Event $item |
|
| 412 | + * @return int|string |
|
| 413 | + * @throws EE_Error |
|
| 414 | + * @throws InvalidArgumentException |
|
| 415 | + * @throws InvalidDataTypeException |
|
| 416 | + * @throws InvalidInterfaceException |
|
| 417 | + */ |
|
| 418 | + public function column_attendees(EE_Event $item) |
|
| 419 | + { |
|
| 420 | + $attendees_query_args = array( |
|
| 421 | + 'action' => 'default', |
|
| 422 | + 'event_id' => $item->ID(), |
|
| 423 | + ); |
|
| 424 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 425 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
| 426 | + return EE_Registry::instance()->CAP->current_user_can( |
|
| 427 | + 'ee_read_event', |
|
| 428 | + 'espresso_registrations_view_registration', |
|
| 429 | + $item->ID() |
|
| 430 | + ) |
|
| 431 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 432 | + 'ee_read_registrations', |
|
| 433 | + 'espresso_registrations_view_registration' |
|
| 434 | + ) |
|
| 435 | + ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 436 | + : $registered_attendees; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @param EE_Event $item |
|
| 442 | + * @return float |
|
| 443 | + * @throws EE_Error |
|
| 444 | + * @throws InvalidArgumentException |
|
| 445 | + * @throws InvalidDataTypeException |
|
| 446 | + * @throws InvalidInterfaceException |
|
| 447 | + */ |
|
| 448 | + public function column_tkts_sold(EE_Event $item) |
|
| 449 | + { |
|
| 450 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @param EE_Event $item |
|
| 456 | + * @return string |
|
| 457 | + * @throws EE_Error |
|
| 458 | + * @throws InvalidArgumentException |
|
| 459 | + * @throws InvalidDataTypeException |
|
| 460 | + * @throws InvalidInterfaceException |
|
| 461 | + */ |
|
| 462 | + public function column_actions(EE_Event $item) |
|
| 463 | + { |
|
| 464 | + // todo: remove when attendees is active |
|
| 465 | + if (! defined('REG_ADMIN_URL')) { |
|
| 466 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
| 467 | + } |
|
| 468 | + $action_links = array(); |
|
| 469 | + $view_link = get_permalink($item->ID()); |
|
| 470 | + $action_links[] = '<a href="' . $view_link . '"' |
|
| 471 | + . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 472 | + $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
| 473 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 474 | + 'ee_edit_event', |
|
| 475 | + 'espresso_events_edit', |
|
| 476 | + $item->ID() |
|
| 477 | + )) { |
|
| 478 | + $edit_query_args = array( |
|
| 479 | + 'action' => 'edit', |
|
| 480 | + 'post' => $item->ID(), |
|
| 481 | + ); |
|
| 482 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
| 483 | + $action_links[] = '<a href="' . $edit_link . '"' |
|
| 484 | + . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 485 | + . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
|
| 486 | + . '</a>'; |
|
| 487 | + } |
|
| 488 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 489 | + 'ee_read_registrations', |
|
| 490 | + 'espresso_registrations_view_registration' |
|
| 491 | + ) && EE_Registry::instance()->CAP->current_user_can( |
|
| 492 | + 'ee_read_event', |
|
| 493 | + 'espresso_registrations_view_registration', |
|
| 494 | + $item->ID() |
|
| 495 | + ) |
|
| 496 | + ) { |
|
| 497 | + $attendees_query_args = array( |
|
| 498 | + 'action' => 'default', |
|
| 499 | + 'event_id' => $item->ID(), |
|
| 500 | + ); |
|
| 501 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
| 502 | + $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 503 | + . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 504 | + . '<div class="dashicons dashicons-groups"></div>' |
|
| 505 | + . '</a>'; |
|
| 506 | + } |
|
| 507 | + $action_links = apply_filters( |
|
| 508 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
| 509 | + $action_links, |
|
| 510 | + $item |
|
| 511 | + ); |
|
| 512 | + return $this->_action_string( |
|
| 513 | + implode("\n\t", $action_links), |
|
| 514 | + $item, |
|
| 515 | + 'div' |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | 518 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | $class = parent::_get_row_class($item); |
| 111 | 111 | // add status class |
| 112 | 112 | $class .= $item instanceof EE_Event |
| 113 | - ? ' ee-status-strip event-status-' . $item->get_active_status() |
|
| 113 | + ? ' ee-status-strip event-status-'.$item->get_active_status() |
|
| 114 | 114 | : ''; |
| 115 | 115 | if ($this->_has_checkbox_column) { |
| 116 | 116 | $class .= ' has-checkbox-column'; |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | public function column_cb($item) |
| 141 | 141 | { |
| 142 | - if (! $item instanceof EE_Event) { |
|
| 142 | + if ( ! $item instanceof EE_Event) { |
|
| 143 | 143 | return ''; |
| 144 | 144 | } |
| 145 | 145 | $this->_dtt = $item->primary_datetime(); // set this for use in other columns |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | public function column_id(EE_Event $item) |
| 163 | 163 | { |
| 164 | 164 | $content = $item->ID(); |
| 165 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
| 165 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
| 166 | 166 | return $content; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $actions = $this->_column_name_action_setup($item); |
| 186 | 186 | $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
| 187 | 187 | $content = '<strong><a class="row-title" href="' |
| 188 | - . $edit_link . '">' |
|
| 188 | + . $edit_link.'">' |
|
| 189 | 189 | . $item->name() |
| 190 | 190 | . '</a></strong>' |
| 191 | 191 | . $status; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | protected function _column_name_action_setup(EE_Event $item) |
| 215 | 215 | { |
| 216 | 216 | // todo: remove when attendees is active |
| 217 | - if (! defined('REG_ADMIN_URL')) { |
|
| 217 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 218 | 218 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 219 | 219 | } |
| 220 | 220 | $actions = array(); |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | 'post' => $item->ID(), |
| 232 | 232 | ); |
| 233 | 233 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 234 | - $actions['edit'] = '<a href="' . $edit_link . '"' |
|
| 235 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 234 | + $actions['edit'] = '<a href="'.$edit_link.'"' |
|
| 235 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 236 | 236 | . esc_html__('Edit', 'event_espresso') |
| 237 | 237 | . '</a>'; |
| 238 | 238 | } |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | 'event_id' => $item->ID(), |
| 252 | 252 | ); |
| 253 | 253 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 254 | - $actions['attendees'] = '<a href="' . $attendees_link . '"' |
|
| 255 | - . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">' |
|
| 254 | + $actions['attendees'] = '<a href="'.$attendees_link.'"' |
|
| 255 | + . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">' |
|
| 256 | 256 | . esc_html__('Registrations', 'event_espresso') |
| 257 | 257 | . '</a>'; |
| 258 | 258 | } |
@@ -299,8 +299,8 @@ discard block |
||
| 299 | 299 | ); |
| 300 | 300 | } |
| 301 | 301 | $view_link = get_permalink($item->ID()); |
| 302 | - $actions['view'] = '<a href="' . $view_link . '"' |
|
| 303 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '">' |
|
| 302 | + $actions['view'] = '<a href="'.$view_link.'"' |
|
| 303 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'">' |
|
| 304 | 304 | . esc_html__('View', 'event_espresso') |
| 305 | 305 | . '</a>'; |
| 306 | 306 | if ($item->get('status') === 'trash') { |
@@ -309,8 +309,8 @@ discard block |
||
| 309 | 309 | 'espresso_events_restore_event', |
| 310 | 310 | $item->ID() |
| 311 | 311 | )) { |
| 312 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"' |
|
| 313 | - . ' title="' . esc_attr__('Restore from Trash', 'event_espresso') |
|
| 312 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"' |
|
| 313 | + . ' title="'.esc_attr__('Restore from Trash', 'event_espresso') |
|
| 314 | 314 | . '">' |
| 315 | 315 | . esc_html__('Restore from Trash', 'event_espresso') |
| 316 | 316 | . '</a>'; |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | $item->ID() |
| 323 | 323 | ) |
| 324 | 324 | ) { |
| 325 | - $actions['delete'] = '<a href="' . $delete_event_link . '"' |
|
| 326 | - . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">' |
|
| 325 | + $actions['delete'] = '<a href="'.$delete_event_link.'"' |
|
| 326 | + . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">' |
|
| 327 | 327 | . esc_html__('Delete Permanently', 'event_espresso') |
| 328 | 328 | . '</a>'; |
| 329 | 329 | } |
@@ -333,8 +333,8 @@ discard block |
||
| 333 | 333 | 'espresso_events_trash_event', |
| 334 | 334 | $item->ID() |
| 335 | 335 | )) { |
| 336 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '"' |
|
| 337 | - . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">' |
|
| 336 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'"' |
|
| 337 | + . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">' |
|
| 338 | 338 | . esc_html__('Trash', 'event_espresso') |
| 339 | 339 | . '</a>'; |
| 340 | 340 | } |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | 'EVT_wp_user' => $item->wp_user(), |
| 360 | 360 | ); |
| 361 | 361 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
| 362 | - return $gravatar . ' <a href="' . $filter_url . '"' |
|
| 363 | - . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">' |
|
| 362 | + return $gravatar.' <a href="'.$filter_url.'"' |
|
| 363 | + . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">' |
|
| 364 | 364 | . $event_author->display_name |
| 365 | 365 | . '</a>'; |
| 366 | 366 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | 'ee_read_registrations', |
| 433 | 433 | 'espresso_registrations_view_registration' |
| 434 | 434 | ) |
| 435 | - ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' |
|
| 435 | + ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' |
|
| 436 | 436 | : $registered_attendees; |
| 437 | 437 | } |
| 438 | 438 | |
@@ -462,13 +462,13 @@ discard block |
||
| 462 | 462 | public function column_actions(EE_Event $item) |
| 463 | 463 | { |
| 464 | 464 | // todo: remove when attendees is active |
| 465 | - if (! defined('REG_ADMIN_URL')) { |
|
| 465 | + if ( ! defined('REG_ADMIN_URL')) { |
|
| 466 | 466 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
| 467 | 467 | } |
| 468 | 468 | $action_links = array(); |
| 469 | 469 | $view_link = get_permalink($item->ID()); |
| 470 | - $action_links[] = '<a href="' . $view_link . '"' |
|
| 471 | - . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">'; |
|
| 470 | + $action_links[] = '<a href="'.$view_link.'"' |
|
| 471 | + . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">'; |
|
| 472 | 472 | $action_links[] = '<div class="dashicons dashicons-search"></div></a>'; |
| 473 | 473 | if (EE_Registry::instance()->CAP->current_user_can( |
| 474 | 474 | 'ee_edit_event', |
@@ -480,8 +480,8 @@ discard block |
||
| 480 | 480 | 'post' => $item->ID(), |
| 481 | 481 | ); |
| 482 | 482 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
| 483 | - $action_links[] = '<a href="' . $edit_link . '"' |
|
| 484 | - . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">' |
|
| 483 | + $action_links[] = '<a href="'.$edit_link.'"' |
|
| 484 | + . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">' |
|
| 485 | 485 | . '<div class="ee-icon ee-icon-calendar-edit"></div>' |
| 486 | 486 | . '</a>'; |
| 487 | 487 | } |
@@ -499,8 +499,8 @@ discard block |
||
| 499 | 499 | 'event_id' => $item->ID(), |
| 500 | 500 | ); |
| 501 | 501 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
| 502 | - $action_links[] = '<a href="' . $attendees_link . '"' |
|
| 503 | - . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">' |
|
| 502 | + $action_links[] = '<a href="'.$attendees_link.'"' |
|
| 503 | + . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">' |
|
| 504 | 504 | . '<div class="dashicons dashicons-groups"></div>' |
| 505 | 505 | . '</a>'; |
| 506 | 506 | } |
@@ -33,9 +33,6 @@ |
||
| 33 | 33 | use EE_WP_Post_Status_Field; |
| 34 | 34 | use EE_WP_Post_Type_Field; |
| 35 | 35 | use EE_WP_User_Field; |
| 36 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
| 37 | -use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
| 38 | -use EventEspresso\core\services\loaders\LoaderFactory; |
|
| 39 | 36 | use EventEspresso\core\services\loaders\LoaderInterface; |
| 40 | 37 | use InvalidArgumentException; |
| 41 | 38 | |
@@ -125,7 +125,6 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * @param string $table_column |
| 127 | 127 | * @param string $nice_name |
| 128 | - * @param string $timezone_string |
|
| 129 | 128 | * @param bool $nullable |
| 130 | 129 | * @param string $default_value |
| 131 | 130 | * @throws EE_Error |
@@ -170,7 +169,7 @@ discard block |
||
| 170 | 169 | * @param string $table_column |
| 171 | 170 | * @param string $nice_name |
| 172 | 171 | * @param bool $nullable |
| 173 | - * @param null $default_value |
|
| 172 | + * @param integer $default_value |
|
| 174 | 173 | * @return EE_DB_Only_Int_Field |
| 175 | 174 | */ |
| 176 | 175 | public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
@@ -280,7 +279,7 @@ discard block |
||
| 280 | 279 | * @param string $table_column |
| 281 | 280 | * @param string $nice_name |
| 282 | 281 | * @param bool $nullable |
| 283 | - * @param null $default_value |
|
| 282 | + * @param integer $default_value |
|
| 284 | 283 | * @param string $model_name |
| 285 | 284 | * @return EE_Foreign_Key_Int_Field |
| 286 | 285 | */ |
@@ -297,7 +296,7 @@ discard block |
||
| 297 | 296 | * @param string $table_column |
| 298 | 297 | * @param string $nice_name |
| 299 | 298 | * @param bool $nullable |
| 300 | - * @param null $default_value |
|
| 299 | + * @param string $default_value |
|
| 301 | 300 | * @param string $model_name |
| 302 | 301 | * @return EE_Foreign_Key_String_Field |
| 303 | 302 | */ |
@@ -533,7 +532,7 @@ discard block |
||
| 533 | 532 | * @param string $table_column |
| 534 | 533 | * @param string $nice_name |
| 535 | 534 | * @param bool $nullable |
| 536 | - * @param mixed $default_value |
|
| 535 | + * @param string $default_value |
|
| 537 | 536 | * @param array $values If additional stati are to be used other than the default WP |
| 538 | 537 | * statuses, then they can be registered via this property. The |
| 539 | 538 | * format of the array should be as follows: array( |
@@ -51,547 +51,547 @@ |
||
| 51 | 51 | class ModelFieldFactory |
| 52 | 52 | { |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var LoaderInterface $loader |
|
| 56 | - */ |
|
| 57 | - private $loader; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * ModelFieldFactory constructor. |
|
| 62 | - * |
|
| 63 | - * @param LoaderInterface $loader |
|
| 64 | - */ |
|
| 65 | - public function __construct(LoaderInterface $loader) |
|
| 66 | - { |
|
| 67 | - $this->loader = $loader; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param string $table_column |
|
| 73 | - * @param string $nice_name |
|
| 74 | - * @param bool $nullable |
|
| 75 | - * @param null $default_value |
|
| 76 | - * @return EE_All_Caps_Text_Field |
|
| 77 | - */ |
|
| 78 | - public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 79 | - { |
|
| 80 | - return $this->loader->getNew( |
|
| 81 | - 'EE_All_Caps_Text_Field', |
|
| 82 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $table_column |
|
| 89 | - * @param string $nice_name |
|
| 90 | - * @param bool $nullable |
|
| 91 | - * @param null $default_value |
|
| 92 | - * @param string $model_name |
|
| 93 | - * @return EE_Any_Foreign_Model_Name_Field |
|
| 94 | - */ |
|
| 95 | - public function createAnyForeignModelNameField( |
|
| 96 | - $table_column, |
|
| 97 | - $nice_name, |
|
| 98 | - $nullable, |
|
| 99 | - $default_value = null, |
|
| 100 | - $model_name |
|
| 101 | - ) { |
|
| 102 | - return $this->loader->getNew( |
|
| 103 | - 'EE_Any_Foreign_Model_Name_Field', |
|
| 104 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param string $table_column |
|
| 111 | - * @param string $nice_name |
|
| 112 | - * @param bool $nullable |
|
| 113 | - * @param null $default_value |
|
| 114 | - * @return EE_Boolean_Field |
|
| 115 | - */ |
|
| 116 | - public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 117 | - { |
|
| 118 | - return $this->loader->getNew( |
|
| 119 | - 'EE_Boolean_Field', |
|
| 120 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param string $table_column |
|
| 127 | - * @param string $nice_name |
|
| 128 | - * @param string $timezone_string |
|
| 129 | - * @param bool $nullable |
|
| 130 | - * @param string $default_value |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - * @return EE_Datetime_Field |
|
| 134 | - */ |
|
| 135 | - public function createDatetimeField( |
|
| 136 | - $table_column, |
|
| 137 | - $nice_name, |
|
| 138 | - $nullable = false, |
|
| 139 | - $default_value = EE_Datetime_Field::now |
|
| 140 | - ) { |
|
| 141 | - return $this->loader->getNew( |
|
| 142 | - 'EE_Datetime_Field', |
|
| 143 | - array( |
|
| 144 | - $table_column, |
|
| 145 | - $nice_name, |
|
| 146 | - $nullable, |
|
| 147 | - $default_value, |
|
| 148 | - ) |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param string $table_column |
|
| 155 | - * @param string $nice_name |
|
| 156 | - * @param bool $nullable |
|
| 157 | - * @param null $default_value |
|
| 158 | - * @return EE_DB_Only_Float_Field |
|
| 159 | - */ |
|
| 160 | - public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 161 | - { |
|
| 162 | - return $this->loader->getNew( |
|
| 163 | - 'EE_DB_Only_Float_Field', |
|
| 164 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 165 | - ); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @param string $table_column |
|
| 171 | - * @param string $nice_name |
|
| 172 | - * @param bool $nullable |
|
| 173 | - * @param null $default_value |
|
| 174 | - * @return EE_DB_Only_Int_Field |
|
| 175 | - */ |
|
| 176 | - public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 177 | - { |
|
| 178 | - return $this->loader->getNew( |
|
| 179 | - 'EE_DB_Only_Int_Field', |
|
| 180 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @param string $table_column |
|
| 187 | - * @param string $nice_name |
|
| 188 | - * @param bool $nullable |
|
| 189 | - * @param null $default_value |
|
| 190 | - * @return EE_DB_Only_Text_Field |
|
| 191 | - */ |
|
| 192 | - public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 193 | - { |
|
| 194 | - return $this->loader->getNew( |
|
| 195 | - 'EE_DB_Only_Text_Field', |
|
| 196 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 197 | - ); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param string $table_column |
|
| 203 | - * @param string $nice_name |
|
| 204 | - * @param bool $nullable |
|
| 205 | - * @param string $default_value |
|
| 206 | - * @return EE_Email_Field |
|
| 207 | - */ |
|
| 208 | - public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 209 | - { |
|
| 210 | - return $this->loader->getNew( |
|
| 211 | - 'EE_Email_Field', |
|
| 212 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 213 | - ); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * @param string $table_column |
|
| 219 | - * @param string $nice_name |
|
| 220 | - * @param bool $nullable |
|
| 221 | - * @param null $default_value |
|
| 222 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 223 | - * values are how they should be displayed |
|
| 224 | - * @return EE_Enum_Integer_Field |
|
| 225 | - */ |
|
| 226 | - public function createEnumIntegerField( |
|
| 227 | - $table_column, |
|
| 228 | - $nice_name, |
|
| 229 | - $nullable, |
|
| 230 | - $default_value = null, |
|
| 231 | - array $allowed_enum_values |
|
| 232 | - ) { |
|
| 233 | - return $this->loader->getNew( |
|
| 234 | - 'EE_Enum_Integer_Field', |
|
| 235 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 236 | - ); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param string $table_column |
|
| 242 | - * @param string $nice_name |
|
| 243 | - * @param bool $nullable |
|
| 244 | - * @param null $default_value |
|
| 245 | - * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 246 | - * values are how they should be displayed |
|
| 247 | - * @return EE_Enum_Text_Field |
|
| 248 | - */ |
|
| 249 | - public function createEnumTextField( |
|
| 250 | - $table_column, |
|
| 251 | - $nice_name, |
|
| 252 | - $nullable, |
|
| 253 | - $default_value, |
|
| 254 | - array $allowed_enum_values |
|
| 255 | - ) { |
|
| 256 | - return $this->loader->getNew( |
|
| 257 | - 'EE_Enum_Text_Field', |
|
| 258 | - array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @param string $table_column |
|
| 265 | - * @param string $nice_name |
|
| 266 | - * @param bool $nullable |
|
| 267 | - * @param null $default_value |
|
| 268 | - * @return EE_Float_Field |
|
| 269 | - */ |
|
| 270 | - public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 271 | - { |
|
| 272 | - return $this->loader->getNew( |
|
| 273 | - 'EE_Float_Field', |
|
| 274 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param string $table_column |
|
| 281 | - * @param string $nice_name |
|
| 282 | - * @param bool $nullable |
|
| 283 | - * @param null $default_value |
|
| 284 | - * @param string $model_name |
|
| 285 | - * @return EE_Foreign_Key_Int_Field |
|
| 286 | - */ |
|
| 287 | - public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 288 | - { |
|
| 289 | - return $this->loader->getNew( |
|
| 290 | - 'EE_Foreign_Key_Int_Field', |
|
| 291 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @param string $table_column |
|
| 298 | - * @param string $nice_name |
|
| 299 | - * @param bool $nullable |
|
| 300 | - * @param null $default_value |
|
| 301 | - * @param string $model_name |
|
| 302 | - * @return EE_Foreign_Key_String_Field |
|
| 303 | - */ |
|
| 304 | - public function createForeignKeyStringField( |
|
| 305 | - $table_column, |
|
| 306 | - $nice_name, |
|
| 307 | - $nullable, |
|
| 308 | - $default_value, |
|
| 309 | - $model_name |
|
| 310 | - ) { |
|
| 311 | - return $this->loader->getNew( |
|
| 312 | - 'EE_Foreign_Key_String_Field', |
|
| 313 | - array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param string $table_column |
|
| 320 | - * @param string $nice_name |
|
| 321 | - * @param bool $nullable |
|
| 322 | - * @param null $default_value |
|
| 323 | - * @return EE_Full_HTML_Field |
|
| 324 | - */ |
|
| 325 | - public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 326 | - { |
|
| 327 | - return $this->loader->getNew( |
|
| 328 | - 'EE_Full_HTML_Field', |
|
| 329 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * @param string $table_column |
|
| 336 | - * @param string $nice_name |
|
| 337 | - * @param bool $nullable |
|
| 338 | - * @param null $default_value |
|
| 339 | - * @return EE_Infinite_Integer_Field |
|
| 340 | - */ |
|
| 341 | - public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 342 | - { |
|
| 343 | - return $this->loader->getNew( |
|
| 344 | - 'EE_Infinite_Integer_Field', |
|
| 345 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 346 | - ); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @param string $table_column |
|
| 352 | - * @param string $nice_name |
|
| 353 | - * @param bool $nullable |
|
| 354 | - * @param integer $default_value |
|
| 355 | - * @return EE_Integer_Field |
|
| 356 | - */ |
|
| 357 | - public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
| 358 | - { |
|
| 359 | - return $this->loader->getNew( |
|
| 360 | - 'EE_Integer_Field', |
|
| 361 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 362 | - ); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * @param string $table_column |
|
| 368 | - * @param string $nice_name |
|
| 369 | - * @param bool $nullable |
|
| 370 | - * @param null $default_value |
|
| 371 | - * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
| 372 | - */ |
|
| 373 | - public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 374 | - { |
|
| 375 | - return $this->loader->getNew( |
|
| 376 | - 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
| 377 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 378 | - ); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * @param string $table_column |
|
| 384 | - * @param string $nice_name |
|
| 385 | - * @param bool $nullable |
|
| 386 | - * @param null $default_value |
|
| 387 | - * @return EE_Maybe_Serialized_Text_Field |
|
| 388 | - */ |
|
| 389 | - public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 390 | - { |
|
| 391 | - return $this->loader->getNew( |
|
| 392 | - 'EE_Maybe_Serialized_Text_Field', |
|
| 393 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @param string $table_column |
|
| 400 | - * @param string $nice_name |
|
| 401 | - * @param bool $nullable |
|
| 402 | - * @param null $default_value |
|
| 403 | - * @return EE_Money_Field |
|
| 404 | - */ |
|
| 405 | - public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 406 | - { |
|
| 407 | - return $this->loader->getNew( |
|
| 408 | - 'EE_Money_Field', |
|
| 409 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 410 | - ); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @param string $table_column |
|
| 416 | - * @param string $nice_name |
|
| 417 | - * @param bool $nullable |
|
| 418 | - * @param string $default_value |
|
| 419 | - * @return EE_Plain_Text_Field |
|
| 420 | - */ |
|
| 421 | - public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 422 | - { |
|
| 423 | - return $this->loader->getNew( |
|
| 424 | - 'EE_Plain_Text_Field', |
|
| 425 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @param string $table_column |
|
| 432 | - * @param string $nice_name |
|
| 433 | - * @param bool $nullable |
|
| 434 | - * @param null $default_value |
|
| 435 | - * @return EE_Post_Content_Field |
|
| 436 | - */ |
|
| 437 | - public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 438 | - { |
|
| 439 | - return $this->loader->getNew( |
|
| 440 | - 'EE_Post_Content_Field', |
|
| 441 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * @param string $table_column |
|
| 448 | - * @param string $nice_name |
|
| 449 | - * @return EE_Primary_Key_Int_Field |
|
| 450 | - */ |
|
| 451 | - public function createPrimaryKeyIntField($table_column, $nice_name) |
|
| 452 | - { |
|
| 453 | - return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * @param string $table_column |
|
| 459 | - * @param string $nice_name |
|
| 460 | - * @return EE_Primary_Key_String_Field |
|
| 461 | - */ |
|
| 462 | - public function createPrimaryKeyStringField($table_column, $nice_name) |
|
| 463 | - { |
|
| 464 | - return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @param string $table_column |
|
| 470 | - * @param string $nice_name |
|
| 471 | - * @param bool $nullable |
|
| 472 | - * @param null $default_value |
|
| 473 | - * @return EE_Serialized_Text_Field |
|
| 474 | - */ |
|
| 475 | - public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 476 | - { |
|
| 477 | - return $this->loader->getNew( |
|
| 478 | - 'EE_Serialized_Text_Field', |
|
| 479 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 480 | - ); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * @param string $table_column |
|
| 486 | - * @param string $nice_name |
|
| 487 | - * @param bool $nullable |
|
| 488 | - * @param null $default_value |
|
| 489 | - * @return EE_Simple_HTML_Field |
|
| 490 | - */ |
|
| 491 | - public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 492 | - { |
|
| 493 | - return $this->loader->getNew( |
|
| 494 | - 'EE_Simple_HTML_Field', |
|
| 495 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * @param string $table_column |
|
| 502 | - * @param string $nice_name |
|
| 503 | - * @param bool $nullable |
|
| 504 | - * @param null $default_value |
|
| 505 | - * @return EE_Slug_Field |
|
| 506 | - */ |
|
| 507 | - public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
| 508 | - { |
|
| 509 | - return $this->loader->getNew( |
|
| 510 | - 'EE_Slug_Field', |
|
| 511 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 512 | - ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * @param string $table_column |
|
| 518 | - * @param string $nice_name |
|
| 519 | - * @param bool $nullable |
|
| 520 | - * @param null $default_value |
|
| 521 | - * @return EE_Trashed_Flag_Field |
|
| 522 | - */ |
|
| 523 | - public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 524 | - { |
|
| 525 | - return $this->loader->getNew( |
|
| 526 | - 'EE_Trashed_Flag_Field', |
|
| 527 | - array($table_column, $nice_name, $nullable, $default_value) |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * @param string $table_column |
|
| 534 | - * @param string $nice_name |
|
| 535 | - * @param bool $nullable |
|
| 536 | - * @param mixed $default_value |
|
| 537 | - * @param array $values If additional stati are to be used other than the default WP |
|
| 538 | - * statuses, then they can be registered via this property. The |
|
| 539 | - * format of the array should be as follows: array( |
|
| 540 | - * 'status_reference' => array( |
|
| 541 | - * 'label' => __('Status Reference Label', 'event_espresso'), |
|
| 542 | - * 'public' => true, // whether this status should |
|
| 543 | - * be shown on the frontend of the site |
|
| 544 | - * 'exclude_from_search' => false, // whether this status should |
|
| 545 | - * be excluded from wp searches |
|
| 546 | - * 'show_in_admin_all_list' => true, // whether this status is |
|
| 547 | - * included in queries for the admin "all" view in list table |
|
| 548 | - * views. |
|
| 549 | - * 'show_in_admin_status_list' => true, // show in the list of |
|
| 550 | - * statuses with post counts at the top of the admin list tables |
|
| 551 | - * (i.e. Status Reference(2) ) |
|
| 552 | - * 'label_count' => _n_noop( |
|
| 553 | - * 'Status Reference <span class="count">(%s)</span>', |
|
| 554 | - * 'Status References <span class="count">(%s)</span>' |
|
| 555 | - * ), // the text to display on |
|
| 556 | - * the admin screen |
|
| 557 | - * ( or you won't see your status count ). |
|
| 558 | - * ) |
|
| 559 | - * ) |
|
| 560 | - * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 561 | - * @return EE_WP_Post_Status_Field |
|
| 562 | - */ |
|
| 563 | - public function createWpPostStatusField( |
|
| 564 | - $table_column, |
|
| 565 | - $nice_name, |
|
| 566 | - $nullable, |
|
| 567 | - $default_value = null, |
|
| 568 | - array $values = array() |
|
| 569 | - ) { |
|
| 570 | - return $this->loader->getNew( |
|
| 571 | - 'EE_WP_Post_Status_Field', |
|
| 572 | - array($table_column, $nice_name, $nullable, $default_value, $values) |
|
| 573 | - ); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @param string $post_type |
|
| 579 | - * @return EE_WP_Post_Type_Field |
|
| 580 | - */ |
|
| 581 | - public function createWpPostTypeField($post_type) |
|
| 582 | - { |
|
| 583 | - return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @param string $table_column |
|
| 589 | - * @param string $nice_name |
|
| 590 | - * @param bool $nullable |
|
| 591 | - * @return EE_WP_User_Field |
|
| 592 | - */ |
|
| 593 | - public function createWpUserField($table_column, $nice_name, $nullable) |
|
| 594 | - { |
|
| 595 | - return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
| 596 | - } |
|
| 54 | + /** |
|
| 55 | + * @var LoaderInterface $loader |
|
| 56 | + */ |
|
| 57 | + private $loader; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * ModelFieldFactory constructor. |
|
| 62 | + * |
|
| 63 | + * @param LoaderInterface $loader |
|
| 64 | + */ |
|
| 65 | + public function __construct(LoaderInterface $loader) |
|
| 66 | + { |
|
| 67 | + $this->loader = $loader; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param string $table_column |
|
| 73 | + * @param string $nice_name |
|
| 74 | + * @param bool $nullable |
|
| 75 | + * @param null $default_value |
|
| 76 | + * @return EE_All_Caps_Text_Field |
|
| 77 | + */ |
|
| 78 | + public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 79 | + { |
|
| 80 | + return $this->loader->getNew( |
|
| 81 | + 'EE_All_Caps_Text_Field', |
|
| 82 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $table_column |
|
| 89 | + * @param string $nice_name |
|
| 90 | + * @param bool $nullable |
|
| 91 | + * @param null $default_value |
|
| 92 | + * @param string $model_name |
|
| 93 | + * @return EE_Any_Foreign_Model_Name_Field |
|
| 94 | + */ |
|
| 95 | + public function createAnyForeignModelNameField( |
|
| 96 | + $table_column, |
|
| 97 | + $nice_name, |
|
| 98 | + $nullable, |
|
| 99 | + $default_value = null, |
|
| 100 | + $model_name |
|
| 101 | + ) { |
|
| 102 | + return $this->loader->getNew( |
|
| 103 | + 'EE_Any_Foreign_Model_Name_Field', |
|
| 104 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param string $table_column |
|
| 111 | + * @param string $nice_name |
|
| 112 | + * @param bool $nullable |
|
| 113 | + * @param null $default_value |
|
| 114 | + * @return EE_Boolean_Field |
|
| 115 | + */ |
|
| 116 | + public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 117 | + { |
|
| 118 | + return $this->loader->getNew( |
|
| 119 | + 'EE_Boolean_Field', |
|
| 120 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param string $table_column |
|
| 127 | + * @param string $nice_name |
|
| 128 | + * @param string $timezone_string |
|
| 129 | + * @param bool $nullable |
|
| 130 | + * @param string $default_value |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + * @return EE_Datetime_Field |
|
| 134 | + */ |
|
| 135 | + public function createDatetimeField( |
|
| 136 | + $table_column, |
|
| 137 | + $nice_name, |
|
| 138 | + $nullable = false, |
|
| 139 | + $default_value = EE_Datetime_Field::now |
|
| 140 | + ) { |
|
| 141 | + return $this->loader->getNew( |
|
| 142 | + 'EE_Datetime_Field', |
|
| 143 | + array( |
|
| 144 | + $table_column, |
|
| 145 | + $nice_name, |
|
| 146 | + $nullable, |
|
| 147 | + $default_value, |
|
| 148 | + ) |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param string $table_column |
|
| 155 | + * @param string $nice_name |
|
| 156 | + * @param bool $nullable |
|
| 157 | + * @param null $default_value |
|
| 158 | + * @return EE_DB_Only_Float_Field |
|
| 159 | + */ |
|
| 160 | + public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 161 | + { |
|
| 162 | + return $this->loader->getNew( |
|
| 163 | + 'EE_DB_Only_Float_Field', |
|
| 164 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 165 | + ); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @param string $table_column |
|
| 171 | + * @param string $nice_name |
|
| 172 | + * @param bool $nullable |
|
| 173 | + * @param null $default_value |
|
| 174 | + * @return EE_DB_Only_Int_Field |
|
| 175 | + */ |
|
| 176 | + public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 177 | + { |
|
| 178 | + return $this->loader->getNew( |
|
| 179 | + 'EE_DB_Only_Int_Field', |
|
| 180 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @param string $table_column |
|
| 187 | + * @param string $nice_name |
|
| 188 | + * @param bool $nullable |
|
| 189 | + * @param null $default_value |
|
| 190 | + * @return EE_DB_Only_Text_Field |
|
| 191 | + */ |
|
| 192 | + public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 193 | + { |
|
| 194 | + return $this->loader->getNew( |
|
| 195 | + 'EE_DB_Only_Text_Field', |
|
| 196 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param string $table_column |
|
| 203 | + * @param string $nice_name |
|
| 204 | + * @param bool $nullable |
|
| 205 | + * @param string $default_value |
|
| 206 | + * @return EE_Email_Field |
|
| 207 | + */ |
|
| 208 | + public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 209 | + { |
|
| 210 | + return $this->loader->getNew( |
|
| 211 | + 'EE_Email_Field', |
|
| 212 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 213 | + ); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * @param string $table_column |
|
| 219 | + * @param string $nice_name |
|
| 220 | + * @param bool $nullable |
|
| 221 | + * @param null $default_value |
|
| 222 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 223 | + * values are how they should be displayed |
|
| 224 | + * @return EE_Enum_Integer_Field |
|
| 225 | + */ |
|
| 226 | + public function createEnumIntegerField( |
|
| 227 | + $table_column, |
|
| 228 | + $nice_name, |
|
| 229 | + $nullable, |
|
| 230 | + $default_value = null, |
|
| 231 | + array $allowed_enum_values |
|
| 232 | + ) { |
|
| 233 | + return $this->loader->getNew( |
|
| 234 | + 'EE_Enum_Integer_Field', |
|
| 235 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 236 | + ); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param string $table_column |
|
| 242 | + * @param string $nice_name |
|
| 243 | + * @param bool $nullable |
|
| 244 | + * @param null $default_value |
|
| 245 | + * @param array $allowed_enum_values keys are values to be used in the DB, |
|
| 246 | + * values are how they should be displayed |
|
| 247 | + * @return EE_Enum_Text_Field |
|
| 248 | + */ |
|
| 249 | + public function createEnumTextField( |
|
| 250 | + $table_column, |
|
| 251 | + $nice_name, |
|
| 252 | + $nullable, |
|
| 253 | + $default_value, |
|
| 254 | + array $allowed_enum_values |
|
| 255 | + ) { |
|
| 256 | + return $this->loader->getNew( |
|
| 257 | + 'EE_Enum_Text_Field', |
|
| 258 | + array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * @param string $table_column |
|
| 265 | + * @param string $nice_name |
|
| 266 | + * @param bool $nullable |
|
| 267 | + * @param null $default_value |
|
| 268 | + * @return EE_Float_Field |
|
| 269 | + */ |
|
| 270 | + public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 271 | + { |
|
| 272 | + return $this->loader->getNew( |
|
| 273 | + 'EE_Float_Field', |
|
| 274 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param string $table_column |
|
| 281 | + * @param string $nice_name |
|
| 282 | + * @param bool $nullable |
|
| 283 | + * @param null $default_value |
|
| 284 | + * @param string $model_name |
|
| 285 | + * @return EE_Foreign_Key_Int_Field |
|
| 286 | + */ |
|
| 287 | + public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 288 | + { |
|
| 289 | + return $this->loader->getNew( |
|
| 290 | + 'EE_Foreign_Key_Int_Field', |
|
| 291 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @param string $table_column |
|
| 298 | + * @param string $nice_name |
|
| 299 | + * @param bool $nullable |
|
| 300 | + * @param null $default_value |
|
| 301 | + * @param string $model_name |
|
| 302 | + * @return EE_Foreign_Key_String_Field |
|
| 303 | + */ |
|
| 304 | + public function createForeignKeyStringField( |
|
| 305 | + $table_column, |
|
| 306 | + $nice_name, |
|
| 307 | + $nullable, |
|
| 308 | + $default_value, |
|
| 309 | + $model_name |
|
| 310 | + ) { |
|
| 311 | + return $this->loader->getNew( |
|
| 312 | + 'EE_Foreign_Key_String_Field', |
|
| 313 | + array($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param string $table_column |
|
| 320 | + * @param string $nice_name |
|
| 321 | + * @param bool $nullable |
|
| 322 | + * @param null $default_value |
|
| 323 | + * @return EE_Full_HTML_Field |
|
| 324 | + */ |
|
| 325 | + public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 326 | + { |
|
| 327 | + return $this->loader->getNew( |
|
| 328 | + 'EE_Full_HTML_Field', |
|
| 329 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * @param string $table_column |
|
| 336 | + * @param string $nice_name |
|
| 337 | + * @param bool $nullable |
|
| 338 | + * @param null $default_value |
|
| 339 | + * @return EE_Infinite_Integer_Field |
|
| 340 | + */ |
|
| 341 | + public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 342 | + { |
|
| 343 | + return $this->loader->getNew( |
|
| 344 | + 'EE_Infinite_Integer_Field', |
|
| 345 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 346 | + ); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @param string $table_column |
|
| 352 | + * @param string $nice_name |
|
| 353 | + * @param bool $nullable |
|
| 354 | + * @param integer $default_value |
|
| 355 | + * @return EE_Integer_Field |
|
| 356 | + */ |
|
| 357 | + public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
| 358 | + { |
|
| 359 | + return $this->loader->getNew( |
|
| 360 | + 'EE_Integer_Field', |
|
| 361 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 362 | + ); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * @param string $table_column |
|
| 368 | + * @param string $nice_name |
|
| 369 | + * @param bool $nullable |
|
| 370 | + * @param null $default_value |
|
| 371 | + * @return EE_Maybe_Serialized_Simple_HTML_Field |
|
| 372 | + */ |
|
| 373 | + public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 374 | + { |
|
| 375 | + return $this->loader->getNew( |
|
| 376 | + 'EE_Maybe_Serialized_Simple_HTML_Field', |
|
| 377 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 378 | + ); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * @param string $table_column |
|
| 384 | + * @param string $nice_name |
|
| 385 | + * @param bool $nullable |
|
| 386 | + * @param null $default_value |
|
| 387 | + * @return EE_Maybe_Serialized_Text_Field |
|
| 388 | + */ |
|
| 389 | + public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 390 | + { |
|
| 391 | + return $this->loader->getNew( |
|
| 392 | + 'EE_Maybe_Serialized_Text_Field', |
|
| 393 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @param string $table_column |
|
| 400 | + * @param string $nice_name |
|
| 401 | + * @param bool $nullable |
|
| 402 | + * @param null $default_value |
|
| 403 | + * @return EE_Money_Field |
|
| 404 | + */ |
|
| 405 | + public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 406 | + { |
|
| 407 | + return $this->loader->getNew( |
|
| 408 | + 'EE_Money_Field', |
|
| 409 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 410 | + ); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @param string $table_column |
|
| 416 | + * @param string $nice_name |
|
| 417 | + * @param bool $nullable |
|
| 418 | + * @param string $default_value |
|
| 419 | + * @return EE_Plain_Text_Field |
|
| 420 | + */ |
|
| 421 | + public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
| 422 | + { |
|
| 423 | + return $this->loader->getNew( |
|
| 424 | + 'EE_Plain_Text_Field', |
|
| 425 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @param string $table_column |
|
| 432 | + * @param string $nice_name |
|
| 433 | + * @param bool $nullable |
|
| 434 | + * @param null $default_value |
|
| 435 | + * @return EE_Post_Content_Field |
|
| 436 | + */ |
|
| 437 | + public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 438 | + { |
|
| 439 | + return $this->loader->getNew( |
|
| 440 | + 'EE_Post_Content_Field', |
|
| 441 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * @param string $table_column |
|
| 448 | + * @param string $nice_name |
|
| 449 | + * @return EE_Primary_Key_Int_Field |
|
| 450 | + */ |
|
| 451 | + public function createPrimaryKeyIntField($table_column, $nice_name) |
|
| 452 | + { |
|
| 453 | + return $this->loader->getNew('EE_Primary_Key_Int_Field', array($table_column, $nice_name)); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * @param string $table_column |
|
| 459 | + * @param string $nice_name |
|
| 460 | + * @return EE_Primary_Key_String_Field |
|
| 461 | + */ |
|
| 462 | + public function createPrimaryKeyStringField($table_column, $nice_name) |
|
| 463 | + { |
|
| 464 | + return $this->loader->getNew('EE_Primary_Key_String_Field', array($table_column, $nice_name)); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @param string $table_column |
|
| 470 | + * @param string $nice_name |
|
| 471 | + * @param bool $nullable |
|
| 472 | + * @param null $default_value |
|
| 473 | + * @return EE_Serialized_Text_Field |
|
| 474 | + */ |
|
| 475 | + public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 476 | + { |
|
| 477 | + return $this->loader->getNew( |
|
| 478 | + 'EE_Serialized_Text_Field', |
|
| 479 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 480 | + ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * @param string $table_column |
|
| 486 | + * @param string $nice_name |
|
| 487 | + * @param bool $nullable |
|
| 488 | + * @param null $default_value |
|
| 489 | + * @return EE_Simple_HTML_Field |
|
| 490 | + */ |
|
| 491 | + public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 492 | + { |
|
| 493 | + return $this->loader->getNew( |
|
| 494 | + 'EE_Simple_HTML_Field', |
|
| 495 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * @param string $table_column |
|
| 502 | + * @param string $nice_name |
|
| 503 | + * @param bool $nullable |
|
| 504 | + * @param null $default_value |
|
| 505 | + * @return EE_Slug_Field |
|
| 506 | + */ |
|
| 507 | + public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
| 508 | + { |
|
| 509 | + return $this->loader->getNew( |
|
| 510 | + 'EE_Slug_Field', |
|
| 511 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 512 | + ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * @param string $table_column |
|
| 518 | + * @param string $nice_name |
|
| 519 | + * @param bool $nullable |
|
| 520 | + * @param null $default_value |
|
| 521 | + * @return EE_Trashed_Flag_Field |
|
| 522 | + */ |
|
| 523 | + public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
| 524 | + { |
|
| 525 | + return $this->loader->getNew( |
|
| 526 | + 'EE_Trashed_Flag_Field', |
|
| 527 | + array($table_column, $nice_name, $nullable, $default_value) |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * @param string $table_column |
|
| 534 | + * @param string $nice_name |
|
| 535 | + * @param bool $nullable |
|
| 536 | + * @param mixed $default_value |
|
| 537 | + * @param array $values If additional stati are to be used other than the default WP |
|
| 538 | + * statuses, then they can be registered via this property. The |
|
| 539 | + * format of the array should be as follows: array( |
|
| 540 | + * 'status_reference' => array( |
|
| 541 | + * 'label' => __('Status Reference Label', 'event_espresso'), |
|
| 542 | + * 'public' => true, // whether this status should |
|
| 543 | + * be shown on the frontend of the site |
|
| 544 | + * 'exclude_from_search' => false, // whether this status should |
|
| 545 | + * be excluded from wp searches |
|
| 546 | + * 'show_in_admin_all_list' => true, // whether this status is |
|
| 547 | + * included in queries for the admin "all" view in list table |
|
| 548 | + * views. |
|
| 549 | + * 'show_in_admin_status_list' => true, // show in the list of |
|
| 550 | + * statuses with post counts at the top of the admin list tables |
|
| 551 | + * (i.e. Status Reference(2) ) |
|
| 552 | + * 'label_count' => _n_noop( |
|
| 553 | + * 'Status Reference <span class="count">(%s)</span>', |
|
| 554 | + * 'Status References <span class="count">(%s)</span>' |
|
| 555 | + * ), // the text to display on |
|
| 556 | + * the admin screen |
|
| 557 | + * ( or you won't see your status count ). |
|
| 558 | + * ) |
|
| 559 | + * ) |
|
| 560 | + * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
|
| 561 | + * @return EE_WP_Post_Status_Field |
|
| 562 | + */ |
|
| 563 | + public function createWpPostStatusField( |
|
| 564 | + $table_column, |
|
| 565 | + $nice_name, |
|
| 566 | + $nullable, |
|
| 567 | + $default_value = null, |
|
| 568 | + array $values = array() |
|
| 569 | + ) { |
|
| 570 | + return $this->loader->getNew( |
|
| 571 | + 'EE_WP_Post_Status_Field', |
|
| 572 | + array($table_column, $nice_name, $nullable, $default_value, $values) |
|
| 573 | + ); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @param string $post_type |
|
| 579 | + * @return EE_WP_Post_Type_Field |
|
| 580 | + */ |
|
| 581 | + public function createWpPostTypeField($post_type) |
|
| 582 | + { |
|
| 583 | + return $this->loader->getNew('EE_WP_Post_Type_Field', array($post_type)); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @param string $table_column |
|
| 589 | + * @param string $nice_name |
|
| 590 | + * @param bool $nullable |
|
| 591 | + * @return EE_WP_User_Field |
|
| 592 | + */ |
|
| 593 | + public function createWpUserField($table_column, $nice_name, $nullable) |
|
| 594 | + { |
|
| 595 | + return $this->loader->getNew('EE_WP_User_Field', array($table_column, $nice_name, $nullable)); |
|
| 596 | + } |
|
| 597 | 597 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | - * @param $string |
|
| 278 | + * @param string $string |
|
| 279 | 279 | * @return void |
| 280 | 280 | */ |
| 281 | 281 | public function add_output($string) |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | /** |
| 330 | - * @return mixed |
|
| 330 | + * @return boolean |
|
| 331 | 331 | */ |
| 332 | 332 | public function is_espresso_page() |
| 333 | 333 | { |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | /** |
| 390 | 390 | * remove param |
| 391 | 391 | * |
| 392 | - * @param $key |
|
| 392 | + * @param string $key |
|
| 393 | 393 | * @return void |
| 394 | 394 | */ |
| 395 | 395 | public function un_set($key) |
@@ -12,369 +12,369 @@ |
||
| 12 | 12 | final class EE_Request_Handler implements InterminableInterface |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var EE_Request $request |
|
| 17 | - */ |
|
| 18 | - private $request; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var array $_notice |
|
| 22 | - */ |
|
| 23 | - private $_notice = array(); |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * rendered output to be returned to WP |
|
| 27 | - * |
|
| 28 | - * @var string $_output |
|
| 29 | - */ |
|
| 30 | - private $_output = ''; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * whether current request is via AJAX |
|
| 34 | - * |
|
| 35 | - * @var boolean $ajax |
|
| 36 | - */ |
|
| 37 | - public $ajax = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * whether current request is via AJAX from the frontend of the site |
|
| 41 | - * |
|
| 42 | - * @var boolean $front_ajax |
|
| 43 | - */ |
|
| 44 | - public $front_ajax = false; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param EE_Request $request |
|
| 49 | - */ |
|
| 50 | - public function __construct(EE_Request $request) |
|
| 51 | - { |
|
| 52 | - $this->request = $request; |
|
| 53 | - $this->ajax = $this->request->ajax; |
|
| 54 | - $this->front_ajax = $this->request->front_ajax; |
|
| 55 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param WP $wp |
|
| 61 | - * @return void |
|
| 62 | - * @throws EE_Error |
|
| 63 | - * @throws ReflectionException |
|
| 64 | - */ |
|
| 65 | - public function parse_request($wp = null) |
|
| 66 | - { |
|
| 67 | - // if somebody forgot to provide us with WP, that's ok because its global |
|
| 68 | - if (! $wp instanceof WP) { |
|
| 69 | - global $wp; |
|
| 70 | - } |
|
| 71 | - $this->set_request_vars($wp); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param WP $wp |
|
| 77 | - * @return void |
|
| 78 | - * @throws EE_Error |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - */ |
|
| 81 | - public function set_request_vars($wp = null) |
|
| 82 | - { |
|
| 83 | - if (! is_admin()) { |
|
| 84 | - // set request post_id |
|
| 85 | - $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
| 86 | - // set request post name |
|
| 87 | - $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
| 88 | - // set request post_type |
|
| 89 | - $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
| 90 | - // true or false ? is this page being used by EE ? |
|
| 91 | - $this->set_espresso_page(); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param WP $wp |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - public function get_post_id_from_request($wp = null) |
|
| 101 | - { |
|
| 102 | - if (! $wp instanceof WP) { |
|
| 103 | - global $wp; |
|
| 104 | - } |
|
| 105 | - $post_id = null; |
|
| 106 | - if (isset($wp->query_vars['p'])) { |
|
| 107 | - $post_id = $wp->query_vars['p']; |
|
| 108 | - } |
|
| 109 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
| 110 | - $post_id = $wp->query_vars['page_id']; |
|
| 111 | - } |
|
| 112 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
| 113 | - $post_id = basename($wp->request); |
|
| 114 | - } |
|
| 115 | - return $post_id; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param WP $wp |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function get_post_name_from_request($wp = null) |
|
| 124 | - { |
|
| 125 | - if (! $wp instanceof WP) { |
|
| 126 | - global $wp; |
|
| 127 | - } |
|
| 128 | - $post_name = null; |
|
| 129 | - if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
| 130 | - $post_name = $wp->query_vars['name']; |
|
| 131 | - } |
|
| 132 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
| 133 | - $post_name = $wp->query_vars['pagename']; |
|
| 134 | - } |
|
| 135 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
| 136 | - $possible_post_name = basename($wp->request); |
|
| 137 | - if (! is_numeric($possible_post_name)) { |
|
| 138 | - /** @type WPDB $wpdb */ |
|
| 139 | - global $wpdb; |
|
| 140 | - $SQL = |
|
| 141 | - "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
| 142 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
| 143 | - if ($possible_post_name) { |
|
| 144 | - $post_name = $possible_post_name; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - if (! $post_name && $this->get('post_id')) { |
|
| 149 | - /** @type WPDB $wpdb */ |
|
| 150 | - global $wpdb; |
|
| 151 | - $SQL = |
|
| 152 | - "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
| 153 | - $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
| 154 | - if ($possible_post_name) { |
|
| 155 | - $post_name = $possible_post_name; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - return $post_name; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @param WP $wp |
|
| 164 | - * @return mixed |
|
| 165 | - */ |
|
| 166 | - public function get_post_type_from_request($wp = null) |
|
| 167 | - { |
|
| 168 | - if (! $wp instanceof WP) { |
|
| 169 | - global $wp; |
|
| 170 | - } |
|
| 171 | - return isset($wp->query_vars['post_type']) |
|
| 172 | - ? $wp->query_vars['post_type'] |
|
| 173 | - : null; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Just a helper method for getting the url for the displayed page. |
|
| 179 | - * |
|
| 180 | - * @param WP $wp |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function get_current_page_permalink($wp = null) |
|
| 184 | - { |
|
| 185 | - $post_id = $this->get_post_id_from_request($wp); |
|
| 186 | - if ($post_id) { |
|
| 187 | - $current_page_permalink = get_permalink($post_id); |
|
| 188 | - } else { |
|
| 189 | - if (! $wp instanceof WP) { |
|
| 190 | - global $wp; |
|
| 191 | - } |
|
| 192 | - if ($wp->request) { |
|
| 193 | - $current_page_permalink = site_url($wp->request); |
|
| 194 | - } else { |
|
| 195 | - $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - return $current_page_permalink; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return bool |
|
| 204 | - * @throws EE_Error |
|
| 205 | - * @throws ReflectionException |
|
| 206 | - */ |
|
| 207 | - public function test_for_espresso_page() |
|
| 208 | - { |
|
| 209 | - global $wp; |
|
| 210 | - /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
| 211 | - $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 212 | - $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
| 213 | - if (is_array($espresso_CPT_taxonomies)) { |
|
| 214 | - foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
| 215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
| 216 | - return true; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - // load espresso CPT endpoints |
|
| 221 | - $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
| 222 | - $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
| 223 | - $post_types = (array) $this->get('post_type'); |
|
| 224 | - foreach ($post_types as $post_type) { |
|
| 225 | - // was a post name passed ? |
|
| 226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
| 227 | - // kk we know this is an espresso page, but is it a specific post ? |
|
| 228 | - if (! $this->get('post_name')) { |
|
| 229 | - // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
| 230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
| 231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
| 232 | - : ''; |
|
| 233 | - // if the post type matches on of our then set the endpoint |
|
| 234 | - if ($post_name) { |
|
| 235 | - $this->set('post_name', $post_name); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - return true; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - return false; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param $key |
|
| 246 | - * @param $value |
|
| 247 | - * @return void |
|
| 248 | - */ |
|
| 249 | - public function set_notice($key, $value) |
|
| 250 | - { |
|
| 251 | - $this->_notice[ $key ] = $value; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * @param $key |
|
| 257 | - * @return mixed |
|
| 258 | - */ |
|
| 259 | - public function get_notice($key) |
|
| 260 | - { |
|
| 261 | - return isset($this->_notice[ $key ]) |
|
| 262 | - ? $this->_notice[ $key ] |
|
| 263 | - : null; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param $string |
|
| 269 | - * @return void |
|
| 270 | - */ |
|
| 271 | - public function add_output($string) |
|
| 272 | - { |
|
| 273 | - $this->_output .= $string; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @return string |
|
| 279 | - */ |
|
| 280 | - public function get_output() |
|
| 281 | - { |
|
| 282 | - return $this->_output; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $item |
|
| 288 | - * @param $key |
|
| 289 | - */ |
|
| 290 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
| 291 | - { |
|
| 292 | - $item = strpos($item, 'email') !== false |
|
| 293 | - ? sanitize_email($item) |
|
| 294 | - : sanitize_text_field($item); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @param null|bool $value |
|
| 300 | - * @return void |
|
| 301 | - * @throws EE_Error |
|
| 302 | - * @throws ReflectionException |
|
| 303 | - */ |
|
| 304 | - public function set_espresso_page($value = null) |
|
| 305 | - { |
|
| 306 | - $this->request->set( |
|
| 307 | - 'is_espresso_page', |
|
| 308 | - ! empty($value) |
|
| 309 | - ? $value |
|
| 310 | - : $this->test_for_espresso_page() |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * @return mixed |
|
| 317 | - */ |
|
| 318 | - public function is_espresso_page() |
|
| 319 | - { |
|
| 320 | - return $this->request->is_set('is_espresso_page'); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * returns contents of $_REQUEST |
|
| 326 | - * |
|
| 327 | - * @return array |
|
| 328 | - */ |
|
| 329 | - public function params() |
|
| 330 | - { |
|
| 331 | - return $this->request->params(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param $key |
|
| 337 | - * @param $value |
|
| 338 | - * @param bool $override_ee |
|
| 339 | - * @return void |
|
| 340 | - */ |
|
| 341 | - public function set($key, $value, $override_ee = false) |
|
| 342 | - { |
|
| 343 | - $this->request->set($key, $value, $override_ee); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @param $key |
|
| 349 | - * @param null $default |
|
| 350 | - * @return mixed |
|
| 351 | - */ |
|
| 352 | - public function get($key, $default = null) |
|
| 353 | - { |
|
| 354 | - return $this->request->get($key, $default); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * check if param exists |
|
| 360 | - * |
|
| 361 | - * @param $key |
|
| 362 | - * @return boolean |
|
| 363 | - */ |
|
| 364 | - public function is_set($key) |
|
| 365 | - { |
|
| 366 | - return $this->request->is_set($key); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * remove param |
|
| 372 | - * |
|
| 373 | - * @param $key |
|
| 374 | - * @return void |
|
| 375 | - */ |
|
| 376 | - public function un_set($key) |
|
| 377 | - { |
|
| 378 | - $this->request->un_set($key); |
|
| 379 | - } |
|
| 15 | + /** |
|
| 16 | + * @var EE_Request $request |
|
| 17 | + */ |
|
| 18 | + private $request; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var array $_notice |
|
| 22 | + */ |
|
| 23 | + private $_notice = array(); |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * rendered output to be returned to WP |
|
| 27 | + * |
|
| 28 | + * @var string $_output |
|
| 29 | + */ |
|
| 30 | + private $_output = ''; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * whether current request is via AJAX |
|
| 34 | + * |
|
| 35 | + * @var boolean $ajax |
|
| 36 | + */ |
|
| 37 | + public $ajax = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * whether current request is via AJAX from the frontend of the site |
|
| 41 | + * |
|
| 42 | + * @var boolean $front_ajax |
|
| 43 | + */ |
|
| 44 | + public $front_ajax = false; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param EE_Request $request |
|
| 49 | + */ |
|
| 50 | + public function __construct(EE_Request $request) |
|
| 51 | + { |
|
| 52 | + $this->request = $request; |
|
| 53 | + $this->ajax = $this->request->ajax; |
|
| 54 | + $this->front_ajax = $this->request->front_ajax; |
|
| 55 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param WP $wp |
|
| 61 | + * @return void |
|
| 62 | + * @throws EE_Error |
|
| 63 | + * @throws ReflectionException |
|
| 64 | + */ |
|
| 65 | + public function parse_request($wp = null) |
|
| 66 | + { |
|
| 67 | + // if somebody forgot to provide us with WP, that's ok because its global |
|
| 68 | + if (! $wp instanceof WP) { |
|
| 69 | + global $wp; |
|
| 70 | + } |
|
| 71 | + $this->set_request_vars($wp); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param WP $wp |
|
| 77 | + * @return void |
|
| 78 | + * @throws EE_Error |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + */ |
|
| 81 | + public function set_request_vars($wp = null) |
|
| 82 | + { |
|
| 83 | + if (! is_admin()) { |
|
| 84 | + // set request post_id |
|
| 85 | + $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
|
| 86 | + // set request post name |
|
| 87 | + $this->request->set('post_name', $this->get_post_name_from_request($wp)); |
|
| 88 | + // set request post_type |
|
| 89 | + $this->request->set('post_type', $this->get_post_type_from_request($wp)); |
|
| 90 | + // true or false ? is this page being used by EE ? |
|
| 91 | + $this->set_espresso_page(); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param WP $wp |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + public function get_post_id_from_request($wp = null) |
|
| 101 | + { |
|
| 102 | + if (! $wp instanceof WP) { |
|
| 103 | + global $wp; |
|
| 104 | + } |
|
| 105 | + $post_id = null; |
|
| 106 | + if (isset($wp->query_vars['p'])) { |
|
| 107 | + $post_id = $wp->query_vars['p']; |
|
| 108 | + } |
|
| 109 | + if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
| 110 | + $post_id = $wp->query_vars['page_id']; |
|
| 111 | + } |
|
| 112 | + if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
| 113 | + $post_id = basename($wp->request); |
|
| 114 | + } |
|
| 115 | + return $post_id; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param WP $wp |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function get_post_name_from_request($wp = null) |
|
| 124 | + { |
|
| 125 | + if (! $wp instanceof WP) { |
|
| 126 | + global $wp; |
|
| 127 | + } |
|
| 128 | + $post_name = null; |
|
| 129 | + if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
|
| 130 | + $post_name = $wp->query_vars['name']; |
|
| 131 | + } |
|
| 132 | + if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
| 133 | + $post_name = $wp->query_vars['pagename']; |
|
| 134 | + } |
|
| 135 | + if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
| 136 | + $possible_post_name = basename($wp->request); |
|
| 137 | + if (! is_numeric($possible_post_name)) { |
|
| 138 | + /** @type WPDB $wpdb */ |
|
| 139 | + global $wpdb; |
|
| 140 | + $SQL = |
|
| 141 | + "SELECT ID from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s"; |
|
| 142 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name)); |
|
| 143 | + if ($possible_post_name) { |
|
| 144 | + $post_name = $possible_post_name; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + if (! $post_name && $this->get('post_id')) { |
|
| 149 | + /** @type WPDB $wpdb */ |
|
| 150 | + global $wpdb; |
|
| 151 | + $SQL = |
|
| 152 | + "SELECT post_name from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d"; |
|
| 153 | + $possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id'))); |
|
| 154 | + if ($possible_post_name) { |
|
| 155 | + $post_name = $possible_post_name; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + return $post_name; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @param WP $wp |
|
| 164 | + * @return mixed |
|
| 165 | + */ |
|
| 166 | + public function get_post_type_from_request($wp = null) |
|
| 167 | + { |
|
| 168 | + if (! $wp instanceof WP) { |
|
| 169 | + global $wp; |
|
| 170 | + } |
|
| 171 | + return isset($wp->query_vars['post_type']) |
|
| 172 | + ? $wp->query_vars['post_type'] |
|
| 173 | + : null; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Just a helper method for getting the url for the displayed page. |
|
| 179 | + * |
|
| 180 | + * @param WP $wp |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function get_current_page_permalink($wp = null) |
|
| 184 | + { |
|
| 185 | + $post_id = $this->get_post_id_from_request($wp); |
|
| 186 | + if ($post_id) { |
|
| 187 | + $current_page_permalink = get_permalink($post_id); |
|
| 188 | + } else { |
|
| 189 | + if (! $wp instanceof WP) { |
|
| 190 | + global $wp; |
|
| 191 | + } |
|
| 192 | + if ($wp->request) { |
|
| 193 | + $current_page_permalink = site_url($wp->request); |
|
| 194 | + } else { |
|
| 195 | + $current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI'])); |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + return $current_page_permalink; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return bool |
|
| 204 | + * @throws EE_Error |
|
| 205 | + * @throws ReflectionException |
|
| 206 | + */ |
|
| 207 | + public function test_for_espresso_page() |
|
| 208 | + { |
|
| 209 | + global $wp; |
|
| 210 | + /** @type EE_CPT_Strategy $EE_CPT_Strategy */ |
|
| 211 | + $EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy'); |
|
| 212 | + $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
|
| 213 | + if (is_array($espresso_CPT_taxonomies)) { |
|
| 214 | + foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
|
| 215 | + if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + // load espresso CPT endpoints |
|
| 221 | + $espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints(); |
|
| 222 | + $post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints); |
|
| 223 | + $post_types = (array) $this->get('post_type'); |
|
| 224 | + foreach ($post_types as $post_type) { |
|
| 225 | + // was a post name passed ? |
|
| 226 | + if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
| 227 | + // kk we know this is an espresso page, but is it a specific post ? |
|
| 228 | + if (! $this->get('post_name')) { |
|
| 229 | + // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
|
| 230 | + $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
| 231 | + ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
| 232 | + : ''; |
|
| 233 | + // if the post type matches on of our then set the endpoint |
|
| 234 | + if ($post_name) { |
|
| 235 | + $this->set('post_name', $post_name); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + return true; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + return false; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param $key |
|
| 246 | + * @param $value |
|
| 247 | + * @return void |
|
| 248 | + */ |
|
| 249 | + public function set_notice($key, $value) |
|
| 250 | + { |
|
| 251 | + $this->_notice[ $key ] = $value; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * @param $key |
|
| 257 | + * @return mixed |
|
| 258 | + */ |
|
| 259 | + public function get_notice($key) |
|
| 260 | + { |
|
| 261 | + return isset($this->_notice[ $key ]) |
|
| 262 | + ? $this->_notice[ $key ] |
|
| 263 | + : null; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param $string |
|
| 269 | + * @return void |
|
| 270 | + */ |
|
| 271 | + public function add_output($string) |
|
| 272 | + { |
|
| 273 | + $this->_output .= $string; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @return string |
|
| 279 | + */ |
|
| 280 | + public function get_output() |
|
| 281 | + { |
|
| 282 | + return $this->_output; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $item |
|
| 288 | + * @param $key |
|
| 289 | + */ |
|
| 290 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
| 291 | + { |
|
| 292 | + $item = strpos($item, 'email') !== false |
|
| 293 | + ? sanitize_email($item) |
|
| 294 | + : sanitize_text_field($item); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @param null|bool $value |
|
| 300 | + * @return void |
|
| 301 | + * @throws EE_Error |
|
| 302 | + * @throws ReflectionException |
|
| 303 | + */ |
|
| 304 | + public function set_espresso_page($value = null) |
|
| 305 | + { |
|
| 306 | + $this->request->set( |
|
| 307 | + 'is_espresso_page', |
|
| 308 | + ! empty($value) |
|
| 309 | + ? $value |
|
| 310 | + : $this->test_for_espresso_page() |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @return mixed |
|
| 317 | + */ |
|
| 318 | + public function is_espresso_page() |
|
| 319 | + { |
|
| 320 | + return $this->request->is_set('is_espresso_page'); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * returns contents of $_REQUEST |
|
| 326 | + * |
|
| 327 | + * @return array |
|
| 328 | + */ |
|
| 329 | + public function params() |
|
| 330 | + { |
|
| 331 | + return $this->request->params(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param $key |
|
| 337 | + * @param $value |
|
| 338 | + * @param bool $override_ee |
|
| 339 | + * @return void |
|
| 340 | + */ |
|
| 341 | + public function set($key, $value, $override_ee = false) |
|
| 342 | + { |
|
| 343 | + $this->request->set($key, $value, $override_ee); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @param $key |
|
| 349 | + * @param null $default |
|
| 350 | + * @return mixed |
|
| 351 | + */ |
|
| 352 | + public function get($key, $default = null) |
|
| 353 | + { |
|
| 354 | + return $this->request->get($key, $default); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * check if param exists |
|
| 360 | + * |
|
| 361 | + * @param $key |
|
| 362 | + * @return boolean |
|
| 363 | + */ |
|
| 364 | + public function is_set($key) |
|
| 365 | + { |
|
| 366 | + return $this->request->is_set($key); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * remove param |
|
| 372 | + * |
|
| 373 | + * @param $key |
|
| 374 | + * @return void |
|
| 375 | + */ |
|
| 376 | + public function un_set($key) |
|
| 377 | + { |
|
| 378 | + $this->request->un_set($key); |
|
| 379 | + } |
|
| 380 | 380 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | public function parse_request($wp = null) |
| 66 | 66 | { |
| 67 | 67 | // if somebody forgot to provide us with WP, that's ok because its global |
| 68 | - if (! $wp instanceof WP) { |
|
| 68 | + if ( ! $wp instanceof WP) { |
|
| 69 | 69 | global $wp; |
| 70 | 70 | } |
| 71 | 71 | $this->set_request_vars($wp); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | public function set_request_vars($wp = null) |
| 82 | 82 | { |
| 83 | - if (! is_admin()) { |
|
| 83 | + if ( ! is_admin()) { |
|
| 84 | 84 | // set request post_id |
| 85 | 85 | $this->request->set('post_id', $this->get_post_id_from_request($wp)); |
| 86 | 86 | // set request post name |
@@ -99,17 +99,17 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function get_post_id_from_request($wp = null) |
| 101 | 101 | { |
| 102 | - if (! $wp instanceof WP) { |
|
| 102 | + if ( ! $wp instanceof WP) { |
|
| 103 | 103 | global $wp; |
| 104 | 104 | } |
| 105 | 105 | $post_id = null; |
| 106 | 106 | if (isset($wp->query_vars['p'])) { |
| 107 | 107 | $post_id = $wp->query_vars['p']; |
| 108 | 108 | } |
| 109 | - if (! $post_id && isset($wp->query_vars['page_id'])) { |
|
| 109 | + if ( ! $post_id && isset($wp->query_vars['page_id'])) { |
|
| 110 | 110 | $post_id = $wp->query_vars['page_id']; |
| 111 | 111 | } |
| 112 | - if (! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
| 112 | + if ( ! $post_id && $wp->request !== null && is_numeric(basename($wp->request))) { |
|
| 113 | 113 | $post_id = basename($wp->request); |
| 114 | 114 | } |
| 115 | 115 | return $post_id; |
@@ -122,19 +122,19 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function get_post_name_from_request($wp = null) |
| 124 | 124 | { |
| 125 | - if (! $wp instanceof WP) { |
|
| 125 | + if ( ! $wp instanceof WP) { |
|
| 126 | 126 | global $wp; |
| 127 | 127 | } |
| 128 | 128 | $post_name = null; |
| 129 | 129 | if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) { |
| 130 | 130 | $post_name = $wp->query_vars['name']; |
| 131 | 131 | } |
| 132 | - if (! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
| 132 | + if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) { |
|
| 133 | 133 | $post_name = $wp->query_vars['pagename']; |
| 134 | 134 | } |
| 135 | - if (! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
| 135 | + if ( ! $post_name && $wp->request !== null && ! empty($wp->request)) { |
|
| 136 | 136 | $possible_post_name = basename($wp->request); |
| 137 | - if (! is_numeric($possible_post_name)) { |
|
| 137 | + if ( ! is_numeric($possible_post_name)) { |
|
| 138 | 138 | /** @type WPDB $wpdb */ |
| 139 | 139 | global $wpdb; |
| 140 | 140 | $SQL = |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | - if (! $post_name && $this->get('post_id')) { |
|
| 148 | + if ( ! $post_name && $this->get('post_id')) { |
|
| 149 | 149 | /** @type WPDB $wpdb */ |
| 150 | 150 | global $wpdb; |
| 151 | 151 | $SQL = |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function get_post_type_from_request($wp = null) |
| 167 | 167 | { |
| 168 | - if (! $wp instanceof WP) { |
|
| 168 | + if ( ! $wp instanceof WP) { |
|
| 169 | 169 | global $wp; |
| 170 | 170 | } |
| 171 | 171 | return isset($wp->query_vars['post_type']) |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if ($post_id) { |
| 187 | 187 | $current_page_permalink = get_permalink($post_id); |
| 188 | 188 | } else { |
| 189 | - if (! $wp instanceof WP) { |
|
| 189 | + if ( ! $wp instanceof WP) { |
|
| 190 | 190 | global $wp; |
| 191 | 191 | } |
| 192 | 192 | if ($wp->request) { |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies(); |
| 213 | 213 | if (is_array($espresso_CPT_taxonomies)) { |
| 214 | 214 | foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy => $details) { |
| 215 | - if (isset($wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ])) { |
|
| 215 | + if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) { |
|
| 216 | 216 | return true; |
| 217 | 217 | } |
| 218 | 218 | } |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | $post_types = (array) $this->get('post_type'); |
| 224 | 224 | foreach ($post_types as $post_type) { |
| 225 | 225 | // was a post name passed ? |
| 226 | - if (isset($post_type_CPT_endpoints[ $post_type ])) { |
|
| 226 | + if (isset($post_type_CPT_endpoints[$post_type])) { |
|
| 227 | 227 | // kk we know this is an espresso page, but is it a specific post ? |
| 228 | - if (! $this->get('post_name')) { |
|
| 228 | + if ( ! $this->get('post_name')) { |
|
| 229 | 229 | // there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events |
| 230 | - $post_name = isset($post_type_CPT_endpoints[ $this->get('post_type') ]) |
|
| 231 | - ? $post_type_CPT_endpoints[ $this->get('post_type') ] |
|
| 230 | + $post_name = isset($post_type_CPT_endpoints[$this->get('post_type')]) |
|
| 231 | + ? $post_type_CPT_endpoints[$this->get('post_type')] |
|
| 232 | 232 | : ''; |
| 233 | 233 | // if the post type matches on of our then set the endpoint |
| 234 | 234 | if ($post_name) { |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function set_notice($key, $value) |
| 250 | 250 | { |
| 251 | - $this->_notice[ $key ] = $value; |
|
| 251 | + $this->_notice[$key] = $value; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
@@ -258,8 +258,8 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | public function get_notice($key) |
| 260 | 260 | { |
| 261 | - return isset($this->_notice[ $key ]) |
|
| 262 | - ? $this->_notice[ $key ] |
|
| 261 | + return isset($this->_notice[$key]) |
|
| 262 | + ? $this->_notice[$key] |
|
| 263 | 263 | : null; |
| 264 | 264 | } |
| 265 | 265 | |
@@ -1164,7 +1164,7 @@ discard block |
||
| 1164 | 1164 | * Sets deleted |
| 1165 | 1165 | * |
| 1166 | 1166 | * @param boolean $deleted |
| 1167 | - * @return bool |
|
| 1167 | + * @return boolean|null |
|
| 1168 | 1168 | * @throws EE_Error |
| 1169 | 1169 | * @throws RuntimeException |
| 1170 | 1170 | */ |
@@ -1222,6 +1222,7 @@ discard block |
||
| 1222 | 1222 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
| 1223 | 1223 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
| 1224 | 1224 | * consider registration status as well as datetime access. |
| 1225 | + * @param integer $DTT_OR_ID |
|
| 1225 | 1226 | * @return bool |
| 1226 | 1227 | * @throws EE_Error |
| 1227 | 1228 | */ |
@@ -1392,7 +1393,7 @@ discard block |
||
| 1392 | 1393 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
| 1393 | 1394 | * "Latest" is defined by the `DTT_EVT_start` column. |
| 1394 | 1395 | * |
| 1395 | - * @return EE_Datetime|null |
|
| 1396 | + * @return null|EE_Base_Class |
|
| 1396 | 1397 | * @throws EE_Error |
| 1397 | 1398 | */ |
| 1398 | 1399 | public function get_latest_related_datetime() |
@@ -1688,7 +1689,7 @@ discard block |
||
| 1688 | 1689 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
| 1689 | 1690 | * Note: if there are no payments on the registration there will be no payment method returned. |
| 1690 | 1691 | * |
| 1691 | - * @return EE_Payment_Method|null |
|
| 1692 | + * @return null|EE_Base_Class |
|
| 1692 | 1693 | */ |
| 1693 | 1694 | public function payment_method() |
| 1694 | 1695 | { |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | { |
| 120 | 120 | switch ($field_name) { |
| 121 | 121 | case 'REG_code': |
| 122 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 122 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
| 123 | 123 | $this->set_reg_code($field_value, $use_default); |
| 124 | 124 | } |
| 125 | 125 | break; |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | public function event() |
| 397 | 397 | { |
| 398 | 398 | $event = $this->get_first_related('Event'); |
| 399 | - if (! $event instanceof \EE_Event) { |
|
| 399 | + if ( ! $event instanceof \EE_Event) { |
|
| 400 | 400 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
| 401 | 401 | } |
| 402 | 402 | return $event; |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | { |
| 440 | 440 | // reserved ticket and datetime counts will be decremented as sold counts are incremented |
| 441 | 441 | // so stop tracking that this reg has a ticket reserved |
| 442 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 442 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 443 | 443 | $ticket = $this->ticket(); |
| 444 | 444 | $ticket->increase_sold(); |
| 445 | 445 | $ticket->save(); |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | && $update_ticket |
| 496 | 496 | ) { |
| 497 | 497 | $ticket = $this->ticket(); |
| 498 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 498 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 499 | 499 | $ticket->save(); |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | && $update_ticket |
| 527 | 527 | ) { |
| 528 | 528 | $ticket = $this->ticket(); |
| 529 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 529 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')'); |
|
| 530 | 530 | $ticket->save(); |
| 531 | 531 | } |
| 532 | 532 | } |
@@ -1201,7 +1201,7 @@ discard block |
||
| 1201 | 1201 | : ''; |
| 1202 | 1202 | break; |
| 1203 | 1203 | } |
| 1204 | - return $icon . $status[ $this->status_ID() ]; |
|
| 1204 | + return $icon.$status[$this->status_ID()]; |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | |
@@ -1419,7 +1419,7 @@ discard block |
||
| 1419 | 1419 | return false; |
| 1420 | 1420 | } |
| 1421 | 1421 | // is there a datetime ticket that matches this dtt_ID? |
| 1422 | - if (! (EEM_Datetime_Ticket::instance()->exists( |
|
| 1422 | + if ( ! (EEM_Datetime_Ticket::instance()->exists( |
|
| 1423 | 1423 | array( |
| 1424 | 1424 | array( |
| 1425 | 1425 | 'TKT_ID' => $this->get('TKT_ID'), |
@@ -1450,7 +1450,7 @@ discard block |
||
| 1450 | 1450 | { |
| 1451 | 1451 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
| 1452 | 1452 | |
| 1453 | - if (! $DTT_ID) { |
|
| 1453 | + if ( ! $DTT_ID) { |
|
| 1454 | 1454 | return false; |
| 1455 | 1455 | } |
| 1456 | 1456 | |
@@ -1458,7 +1458,7 @@ discard block |
||
| 1458 | 1458 | |
| 1459 | 1459 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
| 1460 | 1460 | // check-in or not. |
| 1461 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1461 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
| 1462 | 1462 | return true; |
| 1463 | 1463 | } |
| 1464 | 1464 | |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | $datetime = $this->get_latest_related_datetime(); |
| 1519 | 1519 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
| 1520 | 1520 | // verify the registration can checkin for the given DTT_ID |
| 1521 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1521 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1522 | 1522 | EE_Error::add_error( |
| 1523 | 1523 | sprintf( |
| 1524 | 1524 | esc_html__( |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | ); |
| 1542 | 1542 | // start by getting the current status so we know what status we'll be changing to. |
| 1543 | 1543 | $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
| 1544 | - $status_to = $status_paths[ $cur_status ]; |
|
| 1544 | + $status_to = $status_paths[$cur_status]; |
|
| 1545 | 1545 | // database only records true for checked IN or false for checked OUT |
| 1546 | 1546 | // no record ( null ) means checked in NEVER, but we obviously don't save that |
| 1547 | 1547 | $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | public function transaction() |
| 1707 | 1707 | { |
| 1708 | 1708 | $transaction = $this->get_first_related('Transaction'); |
| 1709 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1709 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
| 1710 | 1710 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
| 1711 | 1711 | } |
| 1712 | 1712 | return $transaction; |
@@ -1760,11 +1760,11 @@ discard block |
||
| 1760 | 1760 | ); |
| 1761 | 1761 | return; |
| 1762 | 1762 | } |
| 1763 | - if (! $this->reg_code()) { |
|
| 1763 | + if ( ! $this->reg_code()) { |
|
| 1764 | 1764 | parent::set('REG_code', $REG_code, $use_default); |
| 1765 | 1765 | } else { |
| 1766 | 1766 | EE_Error::doing_it_wrong( |
| 1767 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1767 | + __CLASS__.'::'.__FUNCTION__, |
|
| 1768 | 1768 | esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
| 1769 | 1769 | '4.6.0' |
| 1770 | 1770 | ); |
@@ -1915,7 +1915,7 @@ discard block |
||
| 1915 | 1915 | break; |
| 1916 | 1916 | } |
| 1917 | 1917 | } |
| 1918 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1918 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1919 | 1919 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
| 1920 | 1920 | } |
| 1921 | 1921 | return $line_item; |
@@ -17,2071 +17,2071 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Used to reference when a registration has never been checked in. |
|
| 22 | - * |
|
| 23 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 24 | - * @type int |
|
| 25 | - */ |
|
| 26 | - const checkin_status_never = 2; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Used to reference when a registration has been checked in. |
|
| 30 | - * |
|
| 31 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 32 | - * @type int |
|
| 33 | - */ |
|
| 34 | - const checkin_status_in = 1; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Used to reference when a registration has been checked out. |
|
| 39 | - * |
|
| 40 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 41 | - * @type int |
|
| 42 | - */ |
|
| 43 | - const checkin_status_out = 0; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * extra meta key for tracking reg status os trashed registrations |
|
| 48 | - * |
|
| 49 | - * @type string |
|
| 50 | - */ |
|
| 51 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * extra meta key for tracking if registration has reserved ticket |
|
| 56 | - * |
|
| 57 | - * @type string |
|
| 58 | - */ |
|
| 59 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param array $props_n_values incoming values |
|
| 64 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 65 | - * used.) |
|
| 66 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 67 | - * date_format and the second value is the time format |
|
| 68 | - * @return EE_Registration |
|
| 69 | - * @throws EE_Error |
|
| 70 | - */ |
|
| 71 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 72 | - { |
|
| 73 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 74 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param array $props_n_values incoming values from the database |
|
| 80 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 81 | - * the website will be used. |
|
| 82 | - * @return EE_Registration |
|
| 83 | - */ |
|
| 84 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 85 | - { |
|
| 86 | - return new self($props_n_values, true, $timezone); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Set Event ID |
|
| 92 | - * |
|
| 93 | - * @param int $EVT_ID Event ID |
|
| 94 | - * @throws EE_Error |
|
| 95 | - * @throws RuntimeException |
|
| 96 | - */ |
|
| 97 | - public function set_event($EVT_ID = 0) |
|
| 98 | - { |
|
| 99 | - $this->set('EVT_ID', $EVT_ID); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 105 | - * be routed to internal methods |
|
| 106 | - * |
|
| 107 | - * @param string $field_name |
|
| 108 | - * @param mixed $field_value |
|
| 109 | - * @param bool $use_default |
|
| 110 | - * @throws EE_Error |
|
| 111 | - * @throws EntityNotFoundException |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws ReflectionException |
|
| 116 | - * @throws RuntimeException |
|
| 117 | - */ |
|
| 118 | - public function set($field_name, $field_value, $use_default = false) |
|
| 119 | - { |
|
| 120 | - switch ($field_name) { |
|
| 121 | - case 'REG_code': |
|
| 122 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
| 123 | - $this->set_reg_code($field_value, $use_default); |
|
| 124 | - } |
|
| 125 | - break; |
|
| 126 | - case 'STS_ID': |
|
| 127 | - $this->set_status($field_value, $use_default); |
|
| 128 | - break; |
|
| 129 | - default: |
|
| 130 | - parent::set($field_name, $field_value, $use_default); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Set Status ID |
|
| 137 | - * updates the registration status and ALSO... |
|
| 138 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 139 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 140 | - * |
|
| 141 | - * @param string $new_STS_ID |
|
| 142 | - * @param boolean $use_default |
|
| 143 | - * @param ContextInterface|null $context |
|
| 144 | - * @return bool |
|
| 145 | - * @throws EE_Error |
|
| 146 | - * @throws EntityNotFoundException |
|
| 147 | - * @throws InvalidArgumentException |
|
| 148 | - * @throws ReflectionException |
|
| 149 | - * @throws RuntimeException |
|
| 150 | - * @throws InvalidDataTypeException |
|
| 151 | - * @throws InvalidInterfaceException |
|
| 152 | - */ |
|
| 153 | - public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 154 | - { |
|
| 155 | - // get current REG_Status |
|
| 156 | - $old_STS_ID = $this->status_ID(); |
|
| 157 | - // if status has changed |
|
| 158 | - if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 159 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
| 160 | - && ! empty($new_STS_ID) // as well as the new status |
|
| 161 | - && $this->ID() // ensure registration is in the db |
|
| 162 | - ) { |
|
| 163 | - // TO approved |
|
| 164 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 165 | - // reserve a space by incrementing ticket and datetime sold values |
|
| 166 | - $this->_reserve_registration_space(); |
|
| 167 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 168 | - // OR FROM approved |
|
| 169 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 170 | - // release a space by decrementing ticket and datetime sold values |
|
| 171 | - $this->_release_registration_space(); |
|
| 172 | - do_action( |
|
| 173 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
| 174 | - $this, |
|
| 175 | - $old_STS_ID, |
|
| 176 | - $new_STS_ID, |
|
| 177 | - $context |
|
| 178 | - ); |
|
| 179 | - } |
|
| 180 | - // update status |
|
| 181 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 182 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 183 | - if ($this->statusChangeUpdatesTransaction($context)) { |
|
| 184 | - $this->updateTransactionAfterStatusChange(); |
|
| 185 | - } |
|
| 186 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - // even though the old value matches the new value, it's still good to |
|
| 190 | - // allow the parent set method to have a say |
|
| 191 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 192 | - return true; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 198 | - * |
|
| 199 | - * @param string $new_STS_ID |
|
| 200 | - * @param string $old_STS_ID |
|
| 201 | - * @param ContextInterface|null $context |
|
| 202 | - * @throws EE_Error |
|
| 203 | - * @throws InvalidArgumentException |
|
| 204 | - * @throws InvalidDataTypeException |
|
| 205 | - * @throws InvalidInterfaceException |
|
| 206 | - * @throws ReflectionException |
|
| 207 | - */ |
|
| 208 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 209 | - { |
|
| 210 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
| 211 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 212 | - // true if registration has been cancelled or declined |
|
| 213 | - $this->updateIfCanceled( |
|
| 214 | - $closed_reg_statuses, |
|
| 215 | - $new_STS_ID, |
|
| 216 | - $old_STS_ID, |
|
| 217 | - $context |
|
| 218 | - ); |
|
| 219 | - $this->updateIfDeclined( |
|
| 220 | - $closed_reg_statuses, |
|
| 221 | - $new_STS_ID, |
|
| 222 | - $old_STS_ID, |
|
| 223 | - $context |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 230 | - * |
|
| 231 | - * @param array $closed_reg_statuses |
|
| 232 | - * @param string $new_STS_ID |
|
| 233 | - * @param string $old_STS_ID |
|
| 234 | - * @param ContextInterface|null $context |
|
| 235 | - * @throws EE_Error |
|
| 236 | - * @throws InvalidArgumentException |
|
| 237 | - * @throws InvalidDataTypeException |
|
| 238 | - * @throws InvalidInterfaceException |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - */ |
|
| 241 | - private function updateIfCanceled( |
|
| 242 | - array $closed_reg_statuses, |
|
| 243 | - $new_STS_ID, |
|
| 244 | - $old_STS_ID, |
|
| 245 | - ContextInterface $context = null |
|
| 246 | - ) { |
|
| 247 | - // true if registration has been cancelled or declined |
|
| 248 | - if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 249 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 250 | - ) { |
|
| 251 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 252 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 253 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 254 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 255 | - // cancelled or declined registration |
|
| 256 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 257 | - $this, |
|
| 258 | - $closed_reg_statuses |
|
| 259 | - ); |
|
| 260 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 261 | - $this, |
|
| 262 | - $closed_reg_statuses, |
|
| 263 | - false |
|
| 264 | - ); |
|
| 265 | - do_action( |
|
| 266 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 267 | - $this, |
|
| 268 | - $old_STS_ID, |
|
| 269 | - $new_STS_ID, |
|
| 270 | - $context |
|
| 271 | - ); |
|
| 272 | - return; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * update REGs and TXN when cancelled or declined registrations involved |
|
| 279 | - * |
|
| 280 | - * @param array $closed_reg_statuses |
|
| 281 | - * @param string $new_STS_ID |
|
| 282 | - * @param string $old_STS_ID |
|
| 283 | - * @param ContextInterface|null $context |
|
| 284 | - * @throws EE_Error |
|
| 285 | - * @throws InvalidArgumentException |
|
| 286 | - * @throws InvalidDataTypeException |
|
| 287 | - * @throws InvalidInterfaceException |
|
| 288 | - * @throws ReflectionException |
|
| 289 | - */ |
|
| 290 | - private function updateIfDeclined( |
|
| 291 | - array $closed_reg_statuses, |
|
| 292 | - $new_STS_ID, |
|
| 293 | - $old_STS_ID, |
|
| 294 | - ContextInterface $context = null |
|
| 295 | - ) { |
|
| 296 | - // true if reinstating cancelled or declined registration |
|
| 297 | - if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 298 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 299 | - ) { |
|
| 300 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 301 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 302 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 303 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 304 | - // reinstating cancelled or declined registration |
|
| 305 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 306 | - $this, |
|
| 307 | - $closed_reg_statuses |
|
| 308 | - ); |
|
| 309 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 310 | - $this, |
|
| 311 | - $closed_reg_statuses, |
|
| 312 | - false |
|
| 313 | - ); |
|
| 314 | - do_action( |
|
| 315 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 316 | - $this, |
|
| 317 | - $old_STS_ID, |
|
| 318 | - $new_STS_ID, |
|
| 319 | - $context |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @param ContextInterface|null $context |
|
| 327 | - * @return bool |
|
| 328 | - */ |
|
| 329 | - private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 330 | - { |
|
| 331 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 332 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 333 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
| 334 | - $context, |
|
| 335 | - $this |
|
| 336 | - ); |
|
| 337 | - return ! ( |
|
| 338 | - $context instanceof ContextInterface |
|
| 339 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @throws EE_Error |
|
| 346 | - * @throws EntityNotFoundException |
|
| 347 | - * @throws InvalidArgumentException |
|
| 348 | - * @throws InvalidDataTypeException |
|
| 349 | - * @throws InvalidInterfaceException |
|
| 350 | - * @throws ReflectionException |
|
| 351 | - * @throws RuntimeException |
|
| 352 | - */ |
|
| 353 | - private function updateTransactionAfterStatusChange() |
|
| 354 | - { |
|
| 355 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 356 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 357 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 358 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * get Status ID |
|
| 364 | - */ |
|
| 365 | - public function status_ID() |
|
| 366 | - { |
|
| 367 | - return $this->get('STS_ID'); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Gets the ticket this registration is for |
|
| 373 | - * |
|
| 374 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
| 375 | - * |
|
| 376 | - * @return EE_Ticket|EE_Base_Class |
|
| 377 | - * @throws EE_Error |
|
| 378 | - */ |
|
| 379 | - public function ticket($include_archived = true) |
|
| 380 | - { |
|
| 381 | - $query_params = array(); |
|
| 382 | - if ($include_archived) { |
|
| 383 | - $query_params['default_where_conditions'] = 'none'; |
|
| 384 | - } |
|
| 385 | - return $this->get_first_related('Ticket', $query_params); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Gets the event this registration is for |
|
| 391 | - * |
|
| 392 | - * @return EE_Event |
|
| 393 | - * @throws EE_Error |
|
| 394 | - * @throws EntityNotFoundException |
|
| 395 | - */ |
|
| 396 | - public function event() |
|
| 397 | - { |
|
| 398 | - $event = $this->get_first_related('Event'); |
|
| 399 | - if (! $event instanceof \EE_Event) { |
|
| 400 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 401 | - } |
|
| 402 | - return $event; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 408 | - * with the author of the event this registration is for. |
|
| 409 | - * |
|
| 410 | - * @since 4.5.0 |
|
| 411 | - * @return int |
|
| 412 | - * @throws EE_Error |
|
| 413 | - * @throws EntityNotFoundException |
|
| 414 | - */ |
|
| 415 | - public function wp_user() |
|
| 416 | - { |
|
| 417 | - $event = $this->event(); |
|
| 418 | - if ($event instanceof EE_Event) { |
|
| 419 | - return $event->wp_user(); |
|
| 420 | - } |
|
| 421 | - return 0; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 427 | - * |
|
| 428 | - * @return void |
|
| 429 | - * @throws DomainException |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws EntityNotFoundException |
|
| 432 | - * @throws InvalidArgumentException |
|
| 433 | - * @throws InvalidDataTypeException |
|
| 434 | - * @throws InvalidInterfaceException |
|
| 435 | - * @throws ReflectionException |
|
| 436 | - * @throws UnexpectedEntityException |
|
| 437 | - */ |
|
| 438 | - private function _reserve_registration_space() |
|
| 439 | - { |
|
| 440 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 441 | - // so stop tracking that this reg has a ticket reserved |
|
| 442 | - $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 443 | - $ticket = $this->ticket(); |
|
| 444 | - $ticket->increase_sold(); |
|
| 445 | - $ticket->save(); |
|
| 446 | - // possibly set event status to sold out |
|
| 447 | - $this->event()->perform_sold_out_status_check(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 453 | - * |
|
| 454 | - * @return void |
|
| 455 | - * @throws DomainException |
|
| 456 | - * @throws EE_Error |
|
| 457 | - * @throws EntityNotFoundException |
|
| 458 | - * @throws InvalidArgumentException |
|
| 459 | - * @throws InvalidDataTypeException |
|
| 460 | - * @throws InvalidInterfaceException |
|
| 461 | - * @throws ReflectionException |
|
| 462 | - * @throws UnexpectedEntityException |
|
| 463 | - */ |
|
| 464 | - private function _release_registration_space() |
|
| 465 | - { |
|
| 466 | - $ticket = $this->ticket(); |
|
| 467 | - $ticket->decrease_sold(); |
|
| 468 | - $ticket->save(); |
|
| 469 | - // possibly change event status from sold out back to previous status |
|
| 470 | - $this->event()->perform_sold_out_status_check(); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * tracks this registration's ticket reservation in extra meta |
|
| 476 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 477 | - * |
|
| 478 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 479 | - * @return void |
|
| 480 | - * @throws EE_Error |
|
| 481 | - * @throws InvalidArgumentException |
|
| 482 | - * @throws InvalidDataTypeException |
|
| 483 | - * @throws InvalidInterfaceException |
|
| 484 | - * @throws ReflectionException |
|
| 485 | - */ |
|
| 486 | - public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 487 | - { |
|
| 488 | - // only reserve ticket if space is not currently reserved |
|
| 489 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 490 | - $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 491 | - // IMPORTANT !!! |
|
| 492 | - // although checking $update_ticket first would be more efficient, |
|
| 493 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 494 | - if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 495 | - && $update_ticket |
|
| 496 | - ) { |
|
| 497 | - $ticket = $this->ticket(); |
|
| 498 | - $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 499 | - $ticket->save(); |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * stops tracking this registration's ticket reservation in extra meta |
|
| 507 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 508 | - * |
|
| 509 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 510 | - * @return void |
|
| 511 | - * @throws EE_Error |
|
| 512 | - * @throws InvalidArgumentException |
|
| 513 | - * @throws InvalidDataTypeException |
|
| 514 | - * @throws InvalidInterfaceException |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - */ |
|
| 517 | - public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 518 | - { |
|
| 519 | - // only release ticket if space is currently reserved |
|
| 520 | - if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 521 | - $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 522 | - // IMPORTANT !!! |
|
| 523 | - // although checking $update_ticket first would be more efficient, |
|
| 524 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 525 | - if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 526 | - && $update_ticket |
|
| 527 | - ) { |
|
| 528 | - $ticket = $this->ticket(); |
|
| 529 | - $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 530 | - $ticket->save(); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Set Attendee ID |
|
| 538 | - * |
|
| 539 | - * @param int $ATT_ID Attendee ID |
|
| 540 | - * @throws EE_Error |
|
| 541 | - * @throws RuntimeException |
|
| 542 | - */ |
|
| 543 | - public function set_attendee_id($ATT_ID = 0) |
|
| 544 | - { |
|
| 545 | - $this->set('ATT_ID', $ATT_ID); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Set Transaction ID |
|
| 551 | - * |
|
| 552 | - * @param int $TXN_ID Transaction ID |
|
| 553 | - * @throws EE_Error |
|
| 554 | - * @throws RuntimeException |
|
| 555 | - */ |
|
| 556 | - public function set_transaction_id($TXN_ID = 0) |
|
| 557 | - { |
|
| 558 | - $this->set('TXN_ID', $TXN_ID); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * Set Session |
|
| 564 | - * |
|
| 565 | - * @param string $REG_session PHP Session ID |
|
| 566 | - * @throws EE_Error |
|
| 567 | - * @throws RuntimeException |
|
| 568 | - */ |
|
| 569 | - public function set_session($REG_session = '') |
|
| 570 | - { |
|
| 571 | - $this->set('REG_session', $REG_session); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * Set Registration URL Link |
|
| 577 | - * |
|
| 578 | - * @param string $REG_url_link Registration URL Link |
|
| 579 | - * @throws EE_Error |
|
| 580 | - * @throws RuntimeException |
|
| 581 | - */ |
|
| 582 | - public function set_reg_url_link($REG_url_link = '') |
|
| 583 | - { |
|
| 584 | - $this->set('REG_url_link', $REG_url_link); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Set Attendee Counter |
|
| 590 | - * |
|
| 591 | - * @param int $REG_count Primary Attendee |
|
| 592 | - * @throws EE_Error |
|
| 593 | - * @throws RuntimeException |
|
| 594 | - */ |
|
| 595 | - public function set_count($REG_count = 1) |
|
| 596 | - { |
|
| 597 | - $this->set('REG_count', $REG_count); |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * Set Group Size |
|
| 603 | - * |
|
| 604 | - * @param boolean $REG_group_size Group Registration |
|
| 605 | - * @throws EE_Error |
|
| 606 | - * @throws RuntimeException |
|
| 607 | - */ |
|
| 608 | - public function set_group_size($REG_group_size = false) |
|
| 609 | - { |
|
| 610 | - $this->set('REG_group_size', $REG_group_size); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 616 | - * EEM_Registration::status_id_not_approved |
|
| 617 | - * |
|
| 618 | - * @return boolean |
|
| 619 | - */ |
|
| 620 | - public function is_not_approved() |
|
| 621 | - { |
|
| 622 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 628 | - * EEM_Registration::status_id_pending_payment |
|
| 629 | - * |
|
| 630 | - * @return boolean |
|
| 631 | - */ |
|
| 632 | - public function is_pending_payment() |
|
| 633 | - { |
|
| 634 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 640 | - * |
|
| 641 | - * @return boolean |
|
| 642 | - */ |
|
| 643 | - public function is_approved() |
|
| 644 | - { |
|
| 645 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 651 | - * |
|
| 652 | - * @return boolean |
|
| 653 | - */ |
|
| 654 | - public function is_cancelled() |
|
| 655 | - { |
|
| 656 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 662 | - * |
|
| 663 | - * @return boolean |
|
| 664 | - */ |
|
| 665 | - public function is_declined() |
|
| 666 | - { |
|
| 667 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 673 | - * EEM_Registration::status_id_incomplete |
|
| 674 | - * |
|
| 675 | - * @return boolean |
|
| 676 | - */ |
|
| 677 | - public function is_incomplete() |
|
| 678 | - { |
|
| 679 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set Registration Date |
|
| 685 | - * |
|
| 686 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 687 | - * Date |
|
| 688 | - * @throws EE_Error |
|
| 689 | - * @throws RuntimeException |
|
| 690 | - */ |
|
| 691 | - public function set_reg_date($REG_date = false) |
|
| 692 | - { |
|
| 693 | - $this->set('REG_date', $REG_date); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Set final price owing for this registration after all ticket/price modifications |
|
| 699 | - * |
|
| 700 | - * @access public |
|
| 701 | - * @param float $REG_final_price |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws RuntimeException |
|
| 704 | - */ |
|
| 705 | - public function set_final_price($REG_final_price = 0.00) |
|
| 706 | - { |
|
| 707 | - $this->set('REG_final_price', $REG_final_price); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Set amount paid towards this registration's final price |
|
| 713 | - * |
|
| 714 | - * @access public |
|
| 715 | - * @param float $REG_paid |
|
| 716 | - * @throws EE_Error |
|
| 717 | - * @throws RuntimeException |
|
| 718 | - */ |
|
| 719 | - public function set_paid($REG_paid = 0.00) |
|
| 720 | - { |
|
| 721 | - $this->set('REG_paid', $REG_paid); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Attendee Is Going |
|
| 727 | - * |
|
| 728 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
| 729 | - * @throws EE_Error |
|
| 730 | - * @throws RuntimeException |
|
| 731 | - */ |
|
| 732 | - public function set_att_is_going($REG_att_is_going = false) |
|
| 733 | - { |
|
| 734 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Gets the related attendee |
|
| 740 | - * |
|
| 741 | - * @return EE_Attendee |
|
| 742 | - * @throws EE_Error |
|
| 743 | - */ |
|
| 744 | - public function attendee() |
|
| 745 | - { |
|
| 746 | - return $this->get_first_related('Attendee'); |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * get Event ID |
|
| 752 | - */ |
|
| 753 | - public function event_ID() |
|
| 754 | - { |
|
| 755 | - return $this->get('EVT_ID'); |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * get Event ID |
|
| 761 | - */ |
|
| 762 | - public function event_name() |
|
| 763 | - { |
|
| 764 | - $event = $this->event_obj(); |
|
| 765 | - if ($event) { |
|
| 766 | - return $event->name(); |
|
| 767 | - } else { |
|
| 768 | - return null; |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Fetches the event this registration is for |
|
| 775 | - * |
|
| 776 | - * @return EE_Event |
|
| 777 | - * @throws EE_Error |
|
| 778 | - */ |
|
| 779 | - public function event_obj() |
|
| 780 | - { |
|
| 781 | - return $this->get_first_related('Event'); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * get Attendee ID |
|
| 787 | - */ |
|
| 788 | - public function attendee_ID() |
|
| 789 | - { |
|
| 790 | - return $this->get('ATT_ID'); |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * get PHP Session ID |
|
| 796 | - */ |
|
| 797 | - public function session_ID() |
|
| 798 | - { |
|
| 799 | - return $this->get('REG_session'); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - |
|
| 803 | - /** |
|
| 804 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 805 | - * |
|
| 806 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 807 | - * @return string |
|
| 808 | - */ |
|
| 809 | - public function receipt_url($messenger = 'html') |
|
| 810 | - { |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 814 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 815 | - * |
|
| 816 | - * @since 4.5.0 |
|
| 817 | - */ |
|
| 818 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 819 | - $has_custom = EEH_Template::locate_template( |
|
| 820 | - $template_relative_path, |
|
| 821 | - array(), |
|
| 822 | - true, |
|
| 823 | - true, |
|
| 824 | - true |
|
| 825 | - ); |
|
| 826 | - |
|
| 827 | - if ($has_custom) { |
|
| 828 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 829 | - } |
|
| 830 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 836 | - * |
|
| 837 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 838 | - * @return string |
|
| 839 | - * @throws EE_Error |
|
| 840 | - */ |
|
| 841 | - public function invoice_url($messenger = 'html') |
|
| 842 | - { |
|
| 843 | - /** |
|
| 844 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 845 | - * already in use on old system. If there is then we just return the standard url for it. |
|
| 846 | - * |
|
| 847 | - * @since 4.5.0 |
|
| 848 | - */ |
|
| 849 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 850 | - $has_custom = EEH_Template::locate_template( |
|
| 851 | - $template_relative_path, |
|
| 852 | - array(), |
|
| 853 | - true, |
|
| 854 | - true, |
|
| 855 | - true |
|
| 856 | - ); |
|
| 857 | - |
|
| 858 | - if ($has_custom) { |
|
| 859 | - if ($messenger == 'html') { |
|
| 860 | - return $this->invoice_url('launch'); |
|
| 861 | - } |
|
| 862 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 863 | - |
|
| 864 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 865 | - if ($messenger == 'html') { |
|
| 866 | - $query_args['html'] = true; |
|
| 867 | - } |
|
| 868 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 869 | - } |
|
| 870 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - |
|
| 874 | - /** |
|
| 875 | - * get Registration URL Link |
|
| 876 | - * |
|
| 877 | - * @access public |
|
| 878 | - * @return string |
|
| 879 | - * @throws EE_Error |
|
| 880 | - */ |
|
| 881 | - public function reg_url_link() |
|
| 882 | - { |
|
| 883 | - return (string) $this->get('REG_url_link'); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * Echoes out invoice_url() |
|
| 889 | - * |
|
| 890 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 891 | - * @return void |
|
| 892 | - * @throws EE_Error |
|
| 893 | - */ |
|
| 894 | - public function e_invoice_url($type = 'launch') |
|
| 895 | - { |
|
| 896 | - echo $this->invoice_url($type); |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - |
|
| 900 | - /** |
|
| 901 | - * Echoes out payment_overview_url |
|
| 902 | - */ |
|
| 903 | - public function e_payment_overview_url() |
|
| 904 | - { |
|
| 905 | - echo $this->payment_overview_url(); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Gets the URL for the checkout payment options reg step |
|
| 911 | - * with this registration's REG_url_link added as a query parameter |
|
| 912 | - * |
|
| 913 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 914 | - * payment overview url. |
|
| 915 | - * @return string |
|
| 916 | - * @throws InvalidInterfaceException |
|
| 917 | - * @throws InvalidDataTypeException |
|
| 918 | - * @throws EE_Error |
|
| 919 | - * @throws InvalidArgumentException |
|
| 920 | - */ |
|
| 921 | - public function payment_overview_url($clear_session = false) |
|
| 922 | - { |
|
| 923 | - return add_query_arg( |
|
| 924 | - (array) apply_filters( |
|
| 925 | - 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 926 | - array( |
|
| 927 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 928 | - 'step' => 'payment_options', |
|
| 929 | - 'revisit' => true, |
|
| 930 | - 'clear_session' => (bool) $clear_session, |
|
| 931 | - ), |
|
| 932 | - $this |
|
| 933 | - ), |
|
| 934 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 935 | - ); |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - |
|
| 939 | - /** |
|
| 940 | - * Gets the URL for the checkout attendee information reg step |
|
| 941 | - * with this registration's REG_url_link added as a query parameter |
|
| 942 | - * |
|
| 943 | - * @return string |
|
| 944 | - * @throws InvalidInterfaceException |
|
| 945 | - * @throws InvalidDataTypeException |
|
| 946 | - * @throws EE_Error |
|
| 947 | - * @throws InvalidArgumentException |
|
| 948 | - */ |
|
| 949 | - public function edit_attendee_information_url() |
|
| 950 | - { |
|
| 951 | - return add_query_arg( |
|
| 952 | - (array) apply_filters( |
|
| 953 | - 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 954 | - array( |
|
| 955 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
| 956 | - 'step' => 'attendee_information', |
|
| 957 | - 'revisit' => true, |
|
| 958 | - ), |
|
| 959 | - $this |
|
| 960 | - ), |
|
| 961 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 962 | - ); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - /** |
|
| 967 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 968 | - * |
|
| 969 | - * @return string |
|
| 970 | - * @throws EE_Error |
|
| 971 | - */ |
|
| 972 | - public function get_admin_edit_url() |
|
| 973 | - { |
|
| 974 | - return EEH_URL::add_query_args_and_nonce( |
|
| 975 | - array( |
|
| 976 | - 'page' => 'espresso_registrations', |
|
| 977 | - 'action' => 'view_registration', |
|
| 978 | - '_REG_ID' => $this->ID(), |
|
| 979 | - ), |
|
| 980 | - admin_url('admin.php') |
|
| 981 | - ); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - |
|
| 985 | - /** |
|
| 986 | - * is_primary_registrant? |
|
| 987 | - */ |
|
| 988 | - public function is_primary_registrant() |
|
| 989 | - { |
|
| 990 | - return $this->get('REG_count') == 1 ? true : false; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - |
|
| 994 | - /** |
|
| 995 | - * This returns the primary registration object for this registration group (which may be this object). |
|
| 996 | - * |
|
| 997 | - * @return EE_Registration |
|
| 998 | - * @throws EE_Error |
|
| 999 | - */ |
|
| 1000 | - public function get_primary_registration() |
|
| 1001 | - { |
|
| 1002 | - if ($this->is_primary_registrant()) { |
|
| 1003 | - return $this; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 1007 | - /** @var EE_Registration $primary_registrant */ |
|
| 1008 | - $primary_registrant = EEM_Registration::instance()->get_one( |
|
| 1009 | - array( |
|
| 1010 | - array( |
|
| 1011 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 1012 | - 'REG_count' => 1, |
|
| 1013 | - ), |
|
| 1014 | - ) |
|
| 1015 | - ); |
|
| 1016 | - return $primary_registrant; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - |
|
| 1020 | - /** |
|
| 1021 | - * get Attendee Number |
|
| 1022 | - * |
|
| 1023 | - * @access public |
|
| 1024 | - */ |
|
| 1025 | - public function count() |
|
| 1026 | - { |
|
| 1027 | - return $this->get('REG_count'); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * get Group Size |
|
| 1033 | - */ |
|
| 1034 | - public function group_size() |
|
| 1035 | - { |
|
| 1036 | - return $this->get('REG_group_size'); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * get Registration Date |
|
| 1042 | - */ |
|
| 1043 | - public function date() |
|
| 1044 | - { |
|
| 1045 | - return $this->get('REG_date'); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * gets a pretty date |
|
| 1051 | - * |
|
| 1052 | - * @param string $date_format |
|
| 1053 | - * @param string $time_format |
|
| 1054 | - * @return string |
|
| 1055 | - * @throws EE_Error |
|
| 1056 | - */ |
|
| 1057 | - public function pretty_date($date_format = null, $time_format = null) |
|
| 1058 | - { |
|
| 1059 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * final_price |
|
| 1065 | - * the registration's share of the transaction total, so that the |
|
| 1066 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1067 | - * |
|
| 1068 | - * @return float |
|
| 1069 | - * @throws EE_Error |
|
| 1070 | - */ |
|
| 1071 | - public function final_price() |
|
| 1072 | - { |
|
| 1073 | - return $this->get('REG_final_price'); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - |
|
| 1077 | - /** |
|
| 1078 | - * pretty_final_price |
|
| 1079 | - * final price as formatted string, with correct decimal places and currency symbol |
|
| 1080 | - * |
|
| 1081 | - * @return string |
|
| 1082 | - * @throws EE_Error |
|
| 1083 | - */ |
|
| 1084 | - public function pretty_final_price() |
|
| 1085 | - { |
|
| 1086 | - return $this->get_pretty('REG_final_price'); |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - |
|
| 1090 | - /** |
|
| 1091 | - * get paid (yeah) |
|
| 1092 | - * |
|
| 1093 | - * @return float |
|
| 1094 | - * @throws EE_Error |
|
| 1095 | - */ |
|
| 1096 | - public function paid() |
|
| 1097 | - { |
|
| 1098 | - return $this->get('REG_paid'); |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * pretty_paid |
|
| 1104 | - * |
|
| 1105 | - * @return float |
|
| 1106 | - * @throws EE_Error |
|
| 1107 | - */ |
|
| 1108 | - public function pretty_paid() |
|
| 1109 | - { |
|
| 1110 | - return $this->get_pretty('REG_paid'); |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * owes_monies_and_can_pay |
|
| 1116 | - * whether or not this registration has monies owing and it's' status allows payment |
|
| 1117 | - * |
|
| 1118 | - * @param array $requires_payment |
|
| 1119 | - * @return bool |
|
| 1120 | - * @throws EE_Error |
|
| 1121 | - */ |
|
| 1122 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1123 | - { |
|
| 1124 | - // these reg statuses require payment (if event is not free) |
|
| 1125 | - $requires_payment = ! empty($requires_payment) |
|
| 1126 | - ? $requires_payment |
|
| 1127 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1128 | - if (in_array($this->status_ID(), $requires_payment) && |
|
| 1129 | - $this->final_price() != 0 && |
|
| 1130 | - $this->final_price() != $this->paid() |
|
| 1131 | - ) { |
|
| 1132 | - return true; |
|
| 1133 | - } else { |
|
| 1134 | - return false; |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * Prints out the return value of $this->pretty_status() |
|
| 1141 | - * |
|
| 1142 | - * @param bool $show_icons |
|
| 1143 | - * @return void |
|
| 1144 | - * @throws EE_Error |
|
| 1145 | - */ |
|
| 1146 | - public function e_pretty_status($show_icons = false) |
|
| 1147 | - { |
|
| 1148 | - echo $this->pretty_status($show_icons); |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - |
|
| 1152 | - /** |
|
| 1153 | - * Returns a nice version of the status for displaying to customers |
|
| 1154 | - * |
|
| 1155 | - * @param bool $show_icons |
|
| 1156 | - * @return string |
|
| 1157 | - * @throws EE_Error |
|
| 1158 | - */ |
|
| 1159 | - public function pretty_status($show_icons = false) |
|
| 1160 | - { |
|
| 1161 | - $status = EEM_Status::instance()->localized_status( |
|
| 1162 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1163 | - false, |
|
| 1164 | - 'sentence' |
|
| 1165 | - ); |
|
| 1166 | - $icon = ''; |
|
| 1167 | - switch ($this->status_ID()) { |
|
| 1168 | - case EEM_Registration::status_id_approved: |
|
| 1169 | - $icon = $show_icons |
|
| 1170 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1171 | - : ''; |
|
| 1172 | - break; |
|
| 1173 | - case EEM_Registration::status_id_pending_payment: |
|
| 1174 | - $icon = $show_icons |
|
| 1175 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1176 | - : ''; |
|
| 1177 | - break; |
|
| 1178 | - case EEM_Registration::status_id_not_approved: |
|
| 1179 | - $icon = $show_icons |
|
| 1180 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1181 | - : ''; |
|
| 1182 | - break; |
|
| 1183 | - case EEM_Registration::status_id_cancelled: |
|
| 1184 | - $icon = $show_icons |
|
| 1185 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1186 | - : ''; |
|
| 1187 | - break; |
|
| 1188 | - case EEM_Registration::status_id_incomplete: |
|
| 1189 | - $icon = $show_icons |
|
| 1190 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1191 | - : ''; |
|
| 1192 | - break; |
|
| 1193 | - case EEM_Registration::status_id_declined: |
|
| 1194 | - $icon = $show_icons |
|
| 1195 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1196 | - : ''; |
|
| 1197 | - break; |
|
| 1198 | - case EEM_Registration::status_id_wait_list: |
|
| 1199 | - $icon = $show_icons |
|
| 1200 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1201 | - : ''; |
|
| 1202 | - break; |
|
| 1203 | - } |
|
| 1204 | - return $icon . $status[ $this->status_ID() ]; |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * get Attendee Is Going |
|
| 1210 | - */ |
|
| 1211 | - public function att_is_going() |
|
| 1212 | - { |
|
| 1213 | - return $this->get('REG_att_is_going'); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * Gets related answers |
|
| 1219 | - * |
|
| 1220 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1221 | - * @return EE_Answer[] |
|
| 1222 | - * @throws EE_Error |
|
| 1223 | - */ |
|
| 1224 | - public function answers($query_params = null) |
|
| 1225 | - { |
|
| 1226 | - return $this->get_many_related('Answer', $query_params); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * Gets the registration's answer value to the specified question |
|
| 1232 | - * (either the question's ID or a question object) |
|
| 1233 | - * |
|
| 1234 | - * @param EE_Question|int $question |
|
| 1235 | - * @param bool $pretty_value |
|
| 1236 | - * @return array|string if pretty_value= true, the result will always be a string |
|
| 1237 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1238 | - * will convert it into some kind of string) |
|
| 1239 | - * @throws EE_Error |
|
| 1240 | - */ |
|
| 1241 | - public function answer_value_to_question($question, $pretty_value = true) |
|
| 1242 | - { |
|
| 1243 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1244 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - /** |
|
| 1249 | - * question_groups |
|
| 1250 | - * returns an array of EE_Question_Group objects for this registration |
|
| 1251 | - * |
|
| 1252 | - * @return EE_Question_Group[] |
|
| 1253 | - * @throws EE_Error |
|
| 1254 | - * @throws EntityNotFoundException |
|
| 1255 | - */ |
|
| 1256 | - public function question_groups() |
|
| 1257 | - { |
|
| 1258 | - $question_groups = array(); |
|
| 1259 | - if ($this->event() instanceof EE_Event) { |
|
| 1260 | - $question_groups = $this->event()->question_groups( |
|
| 1261 | - array( |
|
| 1262 | - array( |
|
| 1263 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1264 | - ), |
|
| 1265 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1266 | - ) |
|
| 1267 | - ); |
|
| 1268 | - } |
|
| 1269 | - return $question_groups; |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * count_question_groups |
|
| 1275 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1276 | - * |
|
| 1277 | - * @return int |
|
| 1278 | - * @throws EE_Error |
|
| 1279 | - * @throws EntityNotFoundException |
|
| 1280 | - */ |
|
| 1281 | - public function count_question_groups() |
|
| 1282 | - { |
|
| 1283 | - $qg_count = 0; |
|
| 1284 | - if ($this->event() instanceof EE_Event) { |
|
| 1285 | - $qg_count = $this->event()->count_related( |
|
| 1286 | - 'Question_Group', |
|
| 1287 | - array( |
|
| 1288 | - array( |
|
| 1289 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1290 | - ), |
|
| 1291 | - ) |
|
| 1292 | - ); |
|
| 1293 | - } |
|
| 1294 | - return $qg_count; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * Returns the registration date in the 'standard' string format |
|
| 1300 | - * (function may be improved in the future to allow for different formats and timezones) |
|
| 1301 | - * |
|
| 1302 | - * @return string |
|
| 1303 | - * @throws EE_Error |
|
| 1304 | - */ |
|
| 1305 | - public function reg_date() |
|
| 1306 | - { |
|
| 1307 | - return $this->get_datetime('REG_date'); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - |
|
| 1311 | - /** |
|
| 1312 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1313 | - * the ticket this registration purchased, or the datetime they have registered |
|
| 1314 | - * to attend) |
|
| 1315 | - * |
|
| 1316 | - * @return EE_Datetime_Ticket |
|
| 1317 | - * @throws EE_Error |
|
| 1318 | - */ |
|
| 1319 | - public function datetime_ticket() |
|
| 1320 | - { |
|
| 1321 | - return $this->get_first_related('Datetime_Ticket'); |
|
| 1322 | - } |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * Sets the registration's datetime_ticket. |
|
| 1327 | - * |
|
| 1328 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1329 | - * @return EE_Datetime_Ticket |
|
| 1330 | - * @throws EE_Error |
|
| 1331 | - */ |
|
| 1332 | - public function set_datetime_ticket($datetime_ticket) |
|
| 1333 | - { |
|
| 1334 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * Gets deleted |
|
| 1339 | - * |
|
| 1340 | - * @return bool |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - */ |
|
| 1343 | - public function deleted() |
|
| 1344 | - { |
|
| 1345 | - return $this->get('REG_deleted'); |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Sets deleted |
|
| 1350 | - * |
|
| 1351 | - * @param boolean $deleted |
|
| 1352 | - * @return bool |
|
| 1353 | - * @throws EE_Error |
|
| 1354 | - * @throws RuntimeException |
|
| 1355 | - */ |
|
| 1356 | - public function set_deleted($deleted) |
|
| 1357 | - { |
|
| 1358 | - if ($deleted) { |
|
| 1359 | - $this->delete(); |
|
| 1360 | - } else { |
|
| 1361 | - $this->restore(); |
|
| 1362 | - } |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - /** |
|
| 1367 | - * Get the status object of this object |
|
| 1368 | - * |
|
| 1369 | - * @return EE_Status |
|
| 1370 | - * @throws EE_Error |
|
| 1371 | - */ |
|
| 1372 | - public function status_obj() |
|
| 1373 | - { |
|
| 1374 | - return $this->get_first_related('Status'); |
|
| 1375 | - } |
|
| 1376 | - |
|
| 1377 | - |
|
| 1378 | - /** |
|
| 1379 | - * Returns the number of times this registration has checked into any of the datetimes |
|
| 1380 | - * its available for |
|
| 1381 | - * |
|
| 1382 | - * @return int |
|
| 1383 | - * @throws EE_Error |
|
| 1384 | - */ |
|
| 1385 | - public function count_checkins() |
|
| 1386 | - { |
|
| 1387 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1388 | - } |
|
| 1389 | - |
|
| 1390 | - |
|
| 1391 | - /** |
|
| 1392 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1393 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1394 | - * |
|
| 1395 | - * @return int |
|
| 1396 | - * @throws EE_Error |
|
| 1397 | - */ |
|
| 1398 | - public function count_checkins_not_checkedout() |
|
| 1399 | - { |
|
| 1400 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - |
|
| 1404 | - /** |
|
| 1405 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1406 | - * |
|
| 1407 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1408 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1409 | - * consider registration status as well as datetime access. |
|
| 1410 | - * @return bool |
|
| 1411 | - * @throws EE_Error |
|
| 1412 | - */ |
|
| 1413 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1414 | - { |
|
| 1415 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1416 | - |
|
| 1417 | - // first check registration status |
|
| 1418 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1419 | - return false; |
|
| 1420 | - } |
|
| 1421 | - // is there a datetime ticket that matches this dtt_ID? |
|
| 1422 | - if (! (EEM_Datetime_Ticket::instance()->exists( |
|
| 1423 | - array( |
|
| 1424 | - array( |
|
| 1425 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1426 | - 'DTT_ID' => $DTT_ID, |
|
| 1427 | - ), |
|
| 1428 | - ) |
|
| 1429 | - )) |
|
| 1430 | - ) { |
|
| 1431 | - return false; |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - // final check is against TKT_uses |
|
| 1435 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - |
|
| 1439 | - /** |
|
| 1440 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1441 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1442 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1443 | - * then return false. Otherwise return true. |
|
| 1444 | - * |
|
| 1445 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1446 | - * @return bool true means can checkin. false means cannot checkin. |
|
| 1447 | - * @throws EE_Error |
|
| 1448 | - */ |
|
| 1449 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1450 | - { |
|
| 1451 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1452 | - |
|
| 1453 | - if (! $DTT_ID) { |
|
| 1454 | - return false; |
|
| 1455 | - } |
|
| 1456 | - |
|
| 1457 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1458 | - |
|
| 1459 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1460 | - // check-in or not. |
|
| 1461 | - if (! $max_uses || $max_uses === EE_INF) { |
|
| 1462 | - return true; |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1466 | - // go ahead and toggle. |
|
| 1467 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1468 | - return true; |
|
| 1469 | - } |
|
| 1470 | - |
|
| 1471 | - // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1472 | - // disallows further check-ins. |
|
| 1473 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
| 1474 | - array( |
|
| 1475 | - array( |
|
| 1476 | - 'REG_ID' => $this->ID(), |
|
| 1477 | - 'CHK_in' => true, |
|
| 1478 | - ), |
|
| 1479 | - ), |
|
| 1480 | - 'DTT_ID', |
|
| 1481 | - true |
|
| 1482 | - ); |
|
| 1483 | - // checkins have already reached their max number of uses |
|
| 1484 | - // so registrant can NOT checkin |
|
| 1485 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1486 | - EE_Error::add_error( |
|
| 1487 | - esc_html__( |
|
| 1488 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1489 | - 'event_espresso' |
|
| 1490 | - ), |
|
| 1491 | - __FILE__, |
|
| 1492 | - __FUNCTION__, |
|
| 1493 | - __LINE__ |
|
| 1494 | - ); |
|
| 1495 | - return false; |
|
| 1496 | - } |
|
| 1497 | - return true; |
|
| 1498 | - } |
|
| 1499 | - |
|
| 1500 | - |
|
| 1501 | - /** |
|
| 1502 | - * toggle Check-in status for this registration |
|
| 1503 | - * Check-ins are toggled in the following order: |
|
| 1504 | - * never checked in -> checked in |
|
| 1505 | - * checked in -> checked out |
|
| 1506 | - * checked out -> checked in |
|
| 1507 | - * |
|
| 1508 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1509 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1510 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1511 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1512 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1513 | - * @throws EE_Error |
|
| 1514 | - */ |
|
| 1515 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1516 | - { |
|
| 1517 | - if (empty($DTT_ID)) { |
|
| 1518 | - $datetime = $this->get_latest_related_datetime(); |
|
| 1519 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1520 | - // verify the registration can checkin for the given DTT_ID |
|
| 1521 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1522 | - EE_Error::add_error( |
|
| 1523 | - sprintf( |
|
| 1524 | - esc_html__( |
|
| 1525 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1526 | - 'event_espresso' |
|
| 1527 | - ), |
|
| 1528 | - $this->ID(), |
|
| 1529 | - $DTT_ID |
|
| 1530 | - ), |
|
| 1531 | - __FILE__, |
|
| 1532 | - __FUNCTION__, |
|
| 1533 | - __LINE__ |
|
| 1534 | - ); |
|
| 1535 | - return false; |
|
| 1536 | - } |
|
| 1537 | - $status_paths = array( |
|
| 1538 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1539 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1540 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1541 | - ); |
|
| 1542 | - // start by getting the current status so we know what status we'll be changing to. |
|
| 1543 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1544 | - $status_to = $status_paths[ $cur_status ]; |
|
| 1545 | - // database only records true for checked IN or false for checked OUT |
|
| 1546 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1547 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1548 | - // add relation - note Check-ins are always creating new rows |
|
| 1549 | - // because we are keeping track of Check-ins over time. |
|
| 1550 | - // Eventually we'll probably want to show a list table |
|
| 1551 | - // for the individual Check-ins so that they can be managed. |
|
| 1552 | - $checkin = EE_Checkin::new_instance( |
|
| 1553 | - array( |
|
| 1554 | - 'REG_ID' => $this->ID(), |
|
| 1555 | - 'DTT_ID' => $DTT_ID, |
|
| 1556 | - 'CHK_in' => $new_status, |
|
| 1557 | - ) |
|
| 1558 | - ); |
|
| 1559 | - // if the record could not be saved then return false |
|
| 1560 | - if ($checkin->save() === 0) { |
|
| 1561 | - if (WP_DEBUG) { |
|
| 1562 | - global $wpdb; |
|
| 1563 | - $error = sprintf( |
|
| 1564 | - esc_html__( |
|
| 1565 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1566 | - 'event_espresso' |
|
| 1567 | - ), |
|
| 1568 | - '<br />', |
|
| 1569 | - $wpdb->last_error |
|
| 1570 | - ); |
|
| 1571 | - } else { |
|
| 1572 | - $error = esc_html__( |
|
| 1573 | - 'Registration check in update failed because of an unknown database error', |
|
| 1574 | - 'event_espresso' |
|
| 1575 | - ); |
|
| 1576 | - } |
|
| 1577 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1578 | - return false; |
|
| 1579 | - } |
|
| 1580 | - return $status_to; |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - |
|
| 1584 | - /** |
|
| 1585 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1586 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1587 | - * |
|
| 1588 | - * @return EE_Datetime|null |
|
| 1589 | - * @throws EE_Error |
|
| 1590 | - */ |
|
| 1591 | - public function get_latest_related_datetime() |
|
| 1592 | - { |
|
| 1593 | - return EEM_Datetime::instance()->get_one( |
|
| 1594 | - array( |
|
| 1595 | - array( |
|
| 1596 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1597 | - ), |
|
| 1598 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1599 | - ) |
|
| 1600 | - ); |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - |
|
| 1604 | - /** |
|
| 1605 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1606 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1607 | - * |
|
| 1608 | - * @throws EE_Error |
|
| 1609 | - */ |
|
| 1610 | - public function get_earliest_related_datetime() |
|
| 1611 | - { |
|
| 1612 | - return EEM_Datetime::instance()->get_one( |
|
| 1613 | - array( |
|
| 1614 | - array( |
|
| 1615 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1616 | - ), |
|
| 1617 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1618 | - ) |
|
| 1619 | - ); |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - |
|
| 1623 | - /** |
|
| 1624 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1625 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1626 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1627 | - * |
|
| 1628 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1629 | - * (if empty we'll get the primary datetime for |
|
| 1630 | - * this registration (via event) and use it's ID); |
|
| 1631 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1632 | - * |
|
| 1633 | - * @return int Integer representing Check-in status. |
|
| 1634 | - * @throws EE_Error |
|
| 1635 | - */ |
|
| 1636 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1637 | - { |
|
| 1638 | - $checkin_query_params = array( |
|
| 1639 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1640 | - ); |
|
| 1641 | - |
|
| 1642 | - if ($DTT_ID > 0) { |
|
| 1643 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - // get checkin object (if exists) |
|
| 1647 | - $checkin = $checkin instanceof EE_Checkin |
|
| 1648 | - ? $checkin |
|
| 1649 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1650 | - if ($checkin instanceof EE_Checkin) { |
|
| 1651 | - if ($checkin->get('CHK_in')) { |
|
| 1652 | - return EE_Checkin::status_checked_in; // checked in |
|
| 1653 | - } |
|
| 1654 | - return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
| 1655 | - } |
|
| 1656 | - return EE_Checkin::status_checked_never; // never been checked in |
|
| 1657 | - } |
|
| 1658 | - |
|
| 1659 | - |
|
| 1660 | - /** |
|
| 1661 | - * This method returns a localized message for the toggled Check-in message. |
|
| 1662 | - * |
|
| 1663 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1664 | - * then it is assumed Check-in for primary datetime was toggled. |
|
| 1665 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1666 | - * message can be customized with the attendee name. |
|
| 1667 | - * @return string internationalized message |
|
| 1668 | - * @throws EE_Error |
|
| 1669 | - */ |
|
| 1670 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1671 | - { |
|
| 1672 | - // let's get the attendee first so we can include the name of the attendee |
|
| 1673 | - $attendee = $this->get_first_related('Attendee'); |
|
| 1674 | - if ($attendee instanceof EE_Attendee) { |
|
| 1675 | - if ($error) { |
|
| 1676 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1677 | - } |
|
| 1678 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1679 | - // what is the status message going to be? |
|
| 1680 | - switch ($cur_status) { |
|
| 1681 | - case EE_Checkin::status_checked_never: |
|
| 1682 | - return sprintf( |
|
| 1683 | - __("%s has been removed from Check-in records", "event_espresso"), |
|
| 1684 | - $attendee->full_name() |
|
| 1685 | - ); |
|
| 1686 | - break; |
|
| 1687 | - case EE_Checkin::status_checked_in: |
|
| 1688 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1689 | - break; |
|
| 1690 | - case EE_Checkin::status_checked_out: |
|
| 1691 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1692 | - break; |
|
| 1693 | - } |
|
| 1694 | - } |
|
| 1695 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1696 | - } |
|
| 1697 | - |
|
| 1698 | - |
|
| 1699 | - /** |
|
| 1700 | - * Returns the related EE_Transaction to this registration |
|
| 1701 | - * |
|
| 1702 | - * @return EE_Transaction |
|
| 1703 | - * @throws EE_Error |
|
| 1704 | - * @throws EntityNotFoundException |
|
| 1705 | - */ |
|
| 1706 | - public function transaction() |
|
| 1707 | - { |
|
| 1708 | - $transaction = $this->get_first_related('Transaction'); |
|
| 1709 | - if (! $transaction instanceof \EE_Transaction) { |
|
| 1710 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1711 | - } |
|
| 1712 | - return $transaction; |
|
| 1713 | - } |
|
| 1714 | - |
|
| 1715 | - |
|
| 1716 | - /** |
|
| 1717 | - * get Registration Code |
|
| 1718 | - */ |
|
| 1719 | - public function reg_code() |
|
| 1720 | - { |
|
| 1721 | - return $this->get('REG_code'); |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - |
|
| 1725 | - /** |
|
| 1726 | - * get Transaction ID |
|
| 1727 | - */ |
|
| 1728 | - public function transaction_ID() |
|
| 1729 | - { |
|
| 1730 | - return $this->get('TXN_ID'); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * @return int |
|
| 1736 | - * @throws EE_Error |
|
| 1737 | - */ |
|
| 1738 | - public function ticket_ID() |
|
| 1739 | - { |
|
| 1740 | - return $this->get('TKT_ID'); |
|
| 1741 | - } |
|
| 1742 | - |
|
| 1743 | - |
|
| 1744 | - /** |
|
| 1745 | - * Set Registration Code |
|
| 1746 | - * |
|
| 1747 | - * @access public |
|
| 1748 | - * @param string $REG_code Registration Code |
|
| 1749 | - * @param boolean $use_default |
|
| 1750 | - * @throws EE_Error |
|
| 1751 | - */ |
|
| 1752 | - public function set_reg_code($REG_code, $use_default = false) |
|
| 1753 | - { |
|
| 1754 | - if (empty($REG_code)) { |
|
| 1755 | - EE_Error::add_error( |
|
| 1756 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1757 | - __FILE__, |
|
| 1758 | - __FUNCTION__, |
|
| 1759 | - __LINE__ |
|
| 1760 | - ); |
|
| 1761 | - return; |
|
| 1762 | - } |
|
| 1763 | - if (! $this->reg_code()) { |
|
| 1764 | - parent::set('REG_code', $REG_code, $use_default); |
|
| 1765 | - } else { |
|
| 1766 | - EE_Error::doing_it_wrong( |
|
| 1767 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1768 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1769 | - '4.6.0' |
|
| 1770 | - ); |
|
| 1771 | - } |
|
| 1772 | - } |
|
| 1773 | - |
|
| 1774 | - |
|
| 1775 | - /** |
|
| 1776 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1777 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1778 | - * $registration->transaction()->registrations(); |
|
| 1779 | - * |
|
| 1780 | - * @since 4.5.0 |
|
| 1781 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1782 | - * @throws EE_Error |
|
| 1783 | - */ |
|
| 1784 | - public function get_all_other_registrations_in_group() |
|
| 1785 | - { |
|
| 1786 | - if ($this->group_size() < 2) { |
|
| 1787 | - return array(); |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - $query[0] = array( |
|
| 1791 | - 'TXN_ID' => $this->transaction_ID(), |
|
| 1792 | - 'REG_ID' => array('!=', $this->ID()), |
|
| 1793 | - 'TKT_ID' => $this->ticket_ID(), |
|
| 1794 | - ); |
|
| 1795 | - /** @var EE_Registration[] $registrations */ |
|
| 1796 | - $registrations = $this->get_model()->get_all($query); |
|
| 1797 | - return $registrations; |
|
| 1798 | - } |
|
| 1799 | - |
|
| 1800 | - /** |
|
| 1801 | - * Return the link to the admin details for the object. |
|
| 1802 | - * |
|
| 1803 | - * @return string |
|
| 1804 | - * @throws EE_Error |
|
| 1805 | - */ |
|
| 1806 | - public function get_admin_details_link() |
|
| 1807 | - { |
|
| 1808 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1809 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1810 | - array( |
|
| 1811 | - 'page' => 'espresso_registrations', |
|
| 1812 | - 'action' => 'view_registration', |
|
| 1813 | - '_REG_ID' => $this->ID(), |
|
| 1814 | - ), |
|
| 1815 | - admin_url('admin.php') |
|
| 1816 | - ); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - /** |
|
| 1820 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1821 | - * |
|
| 1822 | - * @return string |
|
| 1823 | - * @throws EE_Error |
|
| 1824 | - */ |
|
| 1825 | - public function get_admin_edit_link() |
|
| 1826 | - { |
|
| 1827 | - return $this->get_admin_details_link(); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - /** |
|
| 1831 | - * Returns the link to a settings page for the object. |
|
| 1832 | - * |
|
| 1833 | - * @return string |
|
| 1834 | - * @throws EE_Error |
|
| 1835 | - */ |
|
| 1836 | - public function get_admin_settings_link() |
|
| 1837 | - { |
|
| 1838 | - return $this->get_admin_details_link(); |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - /** |
|
| 1842 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1843 | - * |
|
| 1844 | - * @return string |
|
| 1845 | - */ |
|
| 1846 | - public function get_admin_overview_link() |
|
| 1847 | - { |
|
| 1848 | - EE_Registry::instance()->load_helper('URL'); |
|
| 1849 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1850 | - array( |
|
| 1851 | - 'page' => 'espresso_registrations', |
|
| 1852 | - ), |
|
| 1853 | - admin_url('admin.php') |
|
| 1854 | - ); |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * @param array $query_params |
|
| 1860 | - * |
|
| 1861 | - * @return \EE_Registration[] |
|
| 1862 | - * @throws EE_Error |
|
| 1863 | - */ |
|
| 1864 | - public function payments($query_params = array()) |
|
| 1865 | - { |
|
| 1866 | - return $this->get_many_related('Payment', $query_params); |
|
| 1867 | - } |
|
| 1868 | - |
|
| 1869 | - |
|
| 1870 | - /** |
|
| 1871 | - * @param array $query_params |
|
| 1872 | - * |
|
| 1873 | - * @return \EE_Registration_Payment[] |
|
| 1874 | - * @throws EE_Error |
|
| 1875 | - */ |
|
| 1876 | - public function registration_payments($query_params = array()) |
|
| 1877 | - { |
|
| 1878 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - |
|
| 1882 | - /** |
|
| 1883 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1884 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1885 | - * |
|
| 1886 | - * @return EE_Payment_Method|null |
|
| 1887 | - */ |
|
| 1888 | - public function payment_method() |
|
| 1889 | - { |
|
| 1890 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - |
|
| 1894 | - /** |
|
| 1895 | - * @return \EE_Line_Item |
|
| 1896 | - * @throws EntityNotFoundException |
|
| 1897 | - * @throws EE_Error |
|
| 1898 | - */ |
|
| 1899 | - public function ticket_line_item() |
|
| 1900 | - { |
|
| 1901 | - $ticket = $this->ticket(); |
|
| 1902 | - $transaction = $this->transaction(); |
|
| 1903 | - $line_item = null; |
|
| 1904 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1905 | - $transaction->total_line_item(), |
|
| 1906 | - 'Ticket', |
|
| 1907 | - array($ticket->ID()) |
|
| 1908 | - ); |
|
| 1909 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1910 | - if ($ticket_line_item instanceof \EE_Line_Item |
|
| 1911 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1912 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1913 | - ) { |
|
| 1914 | - $line_item = $ticket_line_item; |
|
| 1915 | - break; |
|
| 1916 | - } |
|
| 1917 | - } |
|
| 1918 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1919 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1920 | - } |
|
| 1921 | - return $line_item; |
|
| 1922 | - } |
|
| 1923 | - |
|
| 1924 | - |
|
| 1925 | - /** |
|
| 1926 | - * Soft Deletes this model object. |
|
| 1927 | - * |
|
| 1928 | - * @return boolean | int |
|
| 1929 | - * @throws RuntimeException |
|
| 1930 | - * @throws EE_Error |
|
| 1931 | - */ |
|
| 1932 | - public function delete() |
|
| 1933 | - { |
|
| 1934 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1935 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1936 | - } |
|
| 1937 | - return parent::delete(); |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - |
|
| 1941 | - /** |
|
| 1942 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1943 | - * |
|
| 1944 | - * @throws EE_Error |
|
| 1945 | - * @throws RuntimeException |
|
| 1946 | - */ |
|
| 1947 | - public function restore() |
|
| 1948 | - { |
|
| 1949 | - $previous_status = $this->get_extra_meta( |
|
| 1950 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1951 | - true, |
|
| 1952 | - EEM_Registration::status_id_cancelled |
|
| 1953 | - ); |
|
| 1954 | - if ($previous_status) { |
|
| 1955 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1956 | - $this->set_status($previous_status); |
|
| 1957 | - } |
|
| 1958 | - return parent::restore(); |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1964 | - * |
|
| 1965 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1966 | - * depending on whether the reg status changes to or from "Approved" |
|
| 1967 | - * @return boolean whether the Registration status was updated |
|
| 1968 | - * @throws EE_Error |
|
| 1969 | - * @throws RuntimeException |
|
| 1970 | - */ |
|
| 1971 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1972 | - { |
|
| 1973 | - $paid = $this->paid(); |
|
| 1974 | - $price = $this->final_price(); |
|
| 1975 | - switch (true) { |
|
| 1976 | - // overpaid or paid |
|
| 1977 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1978 | - case EEH_Money::compare_floats($paid, $price): |
|
| 1979 | - $new_status = EEM_Registration::status_id_approved; |
|
| 1980 | - break; |
|
| 1981 | - // underpaid |
|
| 1982 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1983 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1984 | - break; |
|
| 1985 | - // uhhh Houston... |
|
| 1986 | - default: |
|
| 1987 | - throw new RuntimeException( |
|
| 1988 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1989 | - ); |
|
| 1990 | - } |
|
| 1991 | - if ($new_status !== $this->status_ID()) { |
|
| 1992 | - if ($trigger_set_status_logic) { |
|
| 1993 | - return $this->set_status($new_status); |
|
| 1994 | - } |
|
| 1995 | - parent::set('STS_ID', $new_status); |
|
| 1996 | - return true; |
|
| 1997 | - } |
|
| 1998 | - return false; |
|
| 1999 | - } |
|
| 2000 | - |
|
| 2001 | - |
|
| 2002 | - /*************************** DEPRECATED ***************************/ |
|
| 2003 | - |
|
| 2004 | - |
|
| 2005 | - /** |
|
| 2006 | - * @deprecated |
|
| 2007 | - * @since 4.7.0 |
|
| 2008 | - * @access public |
|
| 2009 | - */ |
|
| 2010 | - public function price_paid() |
|
| 2011 | - { |
|
| 2012 | - EE_Error::doing_it_wrong( |
|
| 2013 | - 'EE_Registration::price_paid()', |
|
| 2014 | - esc_html__( |
|
| 2015 | - 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
| 2016 | - 'event_espresso' |
|
| 2017 | - ), |
|
| 2018 | - '4.7.0' |
|
| 2019 | - ); |
|
| 2020 | - return $this->final_price(); |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - |
|
| 2024 | - /** |
|
| 2025 | - * @deprecated |
|
| 2026 | - * @since 4.7.0 |
|
| 2027 | - * @access public |
|
| 2028 | - * @param float $REG_final_price |
|
| 2029 | - * @throws EE_Error |
|
| 2030 | - * @throws RuntimeException |
|
| 2031 | - */ |
|
| 2032 | - public function set_price_paid($REG_final_price = 0.00) |
|
| 2033 | - { |
|
| 2034 | - EE_Error::doing_it_wrong( |
|
| 2035 | - 'EE_Registration::set_price_paid()', |
|
| 2036 | - esc_html__( |
|
| 2037 | - 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
| 2038 | - 'event_espresso' |
|
| 2039 | - ), |
|
| 2040 | - '4.7.0' |
|
| 2041 | - ); |
|
| 2042 | - $this->set_final_price($REG_final_price); |
|
| 2043 | - } |
|
| 2044 | - |
|
| 2045 | - |
|
| 2046 | - /** |
|
| 2047 | - * @deprecated |
|
| 2048 | - * @since 4.7.0 |
|
| 2049 | - * @return string |
|
| 2050 | - * @throws EE_Error |
|
| 2051 | - */ |
|
| 2052 | - public function pretty_price_paid() |
|
| 2053 | - { |
|
| 2054 | - EE_Error::doing_it_wrong( |
|
| 2055 | - 'EE_Registration::pretty_price_paid()', |
|
| 2056 | - esc_html__( |
|
| 2057 | - 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2058 | - 'event_espresso' |
|
| 2059 | - ), |
|
| 2060 | - '4.7.0' |
|
| 2061 | - ); |
|
| 2062 | - return $this->pretty_final_price(); |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - |
|
| 2066 | - /** |
|
| 2067 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2068 | - * |
|
| 2069 | - * @deprecated 4.9.17 |
|
| 2070 | - * @return EE_Datetime |
|
| 2071 | - * @throws EE_Error |
|
| 2072 | - * @throws EntityNotFoundException |
|
| 2073 | - */ |
|
| 2074 | - public function get_related_primary_datetime() |
|
| 2075 | - { |
|
| 2076 | - EE_Error::doing_it_wrong( |
|
| 2077 | - __METHOD__, |
|
| 2078 | - esc_html__( |
|
| 2079 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2080 | - 'event_espresso' |
|
| 2081 | - ), |
|
| 2082 | - '4.9.17', |
|
| 2083 | - '5.0.0' |
|
| 2084 | - ); |
|
| 2085 | - return $this->event()->primary_datetime(); |
|
| 2086 | - } |
|
| 20 | + /** |
|
| 21 | + * Used to reference when a registration has never been checked in. |
|
| 22 | + * |
|
| 23 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
| 24 | + * @type int |
|
| 25 | + */ |
|
| 26 | + const checkin_status_never = 2; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Used to reference when a registration has been checked in. |
|
| 30 | + * |
|
| 31 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
| 32 | + * @type int |
|
| 33 | + */ |
|
| 34 | + const checkin_status_in = 1; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Used to reference when a registration has been checked out. |
|
| 39 | + * |
|
| 40 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
| 41 | + * @type int |
|
| 42 | + */ |
|
| 43 | + const checkin_status_out = 0; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * extra meta key for tracking reg status os trashed registrations |
|
| 48 | + * |
|
| 49 | + * @type string |
|
| 50 | + */ |
|
| 51 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * extra meta key for tracking if registration has reserved ticket |
|
| 56 | + * |
|
| 57 | + * @type string |
|
| 58 | + */ |
|
| 59 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param array $props_n_values incoming values |
|
| 64 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 65 | + * used.) |
|
| 66 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 67 | + * date_format and the second value is the time format |
|
| 68 | + * @return EE_Registration |
|
| 69 | + * @throws EE_Error |
|
| 70 | + */ |
|
| 71 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 72 | + { |
|
| 73 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 74 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param array $props_n_values incoming values from the database |
|
| 80 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 81 | + * the website will be used. |
|
| 82 | + * @return EE_Registration |
|
| 83 | + */ |
|
| 84 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 85 | + { |
|
| 86 | + return new self($props_n_values, true, $timezone); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Set Event ID |
|
| 92 | + * |
|
| 93 | + * @param int $EVT_ID Event ID |
|
| 94 | + * @throws EE_Error |
|
| 95 | + * @throws RuntimeException |
|
| 96 | + */ |
|
| 97 | + public function set_event($EVT_ID = 0) |
|
| 98 | + { |
|
| 99 | + $this->set('EVT_ID', $EVT_ID); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
| 105 | + * be routed to internal methods |
|
| 106 | + * |
|
| 107 | + * @param string $field_name |
|
| 108 | + * @param mixed $field_value |
|
| 109 | + * @param bool $use_default |
|
| 110 | + * @throws EE_Error |
|
| 111 | + * @throws EntityNotFoundException |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws ReflectionException |
|
| 116 | + * @throws RuntimeException |
|
| 117 | + */ |
|
| 118 | + public function set($field_name, $field_value, $use_default = false) |
|
| 119 | + { |
|
| 120 | + switch ($field_name) { |
|
| 121 | + case 'REG_code': |
|
| 122 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
| 123 | + $this->set_reg_code($field_value, $use_default); |
|
| 124 | + } |
|
| 125 | + break; |
|
| 126 | + case 'STS_ID': |
|
| 127 | + $this->set_status($field_value, $use_default); |
|
| 128 | + break; |
|
| 129 | + default: |
|
| 130 | + parent::set($field_name, $field_value, $use_default); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Set Status ID |
|
| 137 | + * updates the registration status and ALSO... |
|
| 138 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
| 139 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
| 140 | + * |
|
| 141 | + * @param string $new_STS_ID |
|
| 142 | + * @param boolean $use_default |
|
| 143 | + * @param ContextInterface|null $context |
|
| 144 | + * @return bool |
|
| 145 | + * @throws EE_Error |
|
| 146 | + * @throws EntityNotFoundException |
|
| 147 | + * @throws InvalidArgumentException |
|
| 148 | + * @throws ReflectionException |
|
| 149 | + * @throws RuntimeException |
|
| 150 | + * @throws InvalidDataTypeException |
|
| 151 | + * @throws InvalidInterfaceException |
|
| 152 | + */ |
|
| 153 | + public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null) |
|
| 154 | + { |
|
| 155 | + // get current REG_Status |
|
| 156 | + $old_STS_ID = $this->status_ID(); |
|
| 157 | + // if status has changed |
|
| 158 | + if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
| 159 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
| 160 | + && ! empty($new_STS_ID) // as well as the new status |
|
| 161 | + && $this->ID() // ensure registration is in the db |
|
| 162 | + ) { |
|
| 163 | + // TO approved |
|
| 164 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
| 165 | + // reserve a space by incrementing ticket and datetime sold values |
|
| 166 | + $this->_reserve_registration_space(); |
|
| 167 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 168 | + // OR FROM approved |
|
| 169 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
| 170 | + // release a space by decrementing ticket and datetime sold values |
|
| 171 | + $this->_release_registration_space(); |
|
| 172 | + do_action( |
|
| 173 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
| 174 | + $this, |
|
| 175 | + $old_STS_ID, |
|
| 176 | + $new_STS_ID, |
|
| 177 | + $context |
|
| 178 | + ); |
|
| 179 | + } |
|
| 180 | + // update status |
|
| 181 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 182 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
| 183 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
| 184 | + $this->updateTransactionAfterStatusChange(); |
|
| 185 | + } |
|
| 186 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + // even though the old value matches the new value, it's still good to |
|
| 190 | + // allow the parent set method to have a say |
|
| 191 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
| 192 | + return true; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 198 | + * |
|
| 199 | + * @param string $new_STS_ID |
|
| 200 | + * @param string $old_STS_ID |
|
| 201 | + * @param ContextInterface|null $context |
|
| 202 | + * @throws EE_Error |
|
| 203 | + * @throws InvalidArgumentException |
|
| 204 | + * @throws InvalidDataTypeException |
|
| 205 | + * @throws InvalidInterfaceException |
|
| 206 | + * @throws ReflectionException |
|
| 207 | + */ |
|
| 208 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, ContextInterface $context = null) |
|
| 209 | + { |
|
| 210 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
| 211 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
| 212 | + // true if registration has been cancelled or declined |
|
| 213 | + $this->updateIfCanceled( |
|
| 214 | + $closed_reg_statuses, |
|
| 215 | + $new_STS_ID, |
|
| 216 | + $old_STS_ID, |
|
| 217 | + $context |
|
| 218 | + ); |
|
| 219 | + $this->updateIfDeclined( |
|
| 220 | + $closed_reg_statuses, |
|
| 221 | + $new_STS_ID, |
|
| 222 | + $old_STS_ID, |
|
| 223 | + $context |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 230 | + * |
|
| 231 | + * @param array $closed_reg_statuses |
|
| 232 | + * @param string $new_STS_ID |
|
| 233 | + * @param string $old_STS_ID |
|
| 234 | + * @param ContextInterface|null $context |
|
| 235 | + * @throws EE_Error |
|
| 236 | + * @throws InvalidArgumentException |
|
| 237 | + * @throws InvalidDataTypeException |
|
| 238 | + * @throws InvalidInterfaceException |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + */ |
|
| 241 | + private function updateIfCanceled( |
|
| 242 | + array $closed_reg_statuses, |
|
| 243 | + $new_STS_ID, |
|
| 244 | + $old_STS_ID, |
|
| 245 | + ContextInterface $context = null |
|
| 246 | + ) { |
|
| 247 | + // true if registration has been cancelled or declined |
|
| 248 | + if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 249 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 250 | + ) { |
|
| 251 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 252 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 253 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 254 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 255 | + // cancelled or declined registration |
|
| 256 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
| 257 | + $this, |
|
| 258 | + $closed_reg_statuses |
|
| 259 | + ); |
|
| 260 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
| 261 | + $this, |
|
| 262 | + $closed_reg_statuses, |
|
| 263 | + false |
|
| 264 | + ); |
|
| 265 | + do_action( |
|
| 266 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
| 267 | + $this, |
|
| 268 | + $old_STS_ID, |
|
| 269 | + $new_STS_ID, |
|
| 270 | + $context |
|
| 271 | + ); |
|
| 272 | + return; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * update REGs and TXN when cancelled or declined registrations involved |
|
| 279 | + * |
|
| 280 | + * @param array $closed_reg_statuses |
|
| 281 | + * @param string $new_STS_ID |
|
| 282 | + * @param string $old_STS_ID |
|
| 283 | + * @param ContextInterface|null $context |
|
| 284 | + * @throws EE_Error |
|
| 285 | + * @throws InvalidArgumentException |
|
| 286 | + * @throws InvalidDataTypeException |
|
| 287 | + * @throws InvalidInterfaceException |
|
| 288 | + * @throws ReflectionException |
|
| 289 | + */ |
|
| 290 | + private function updateIfDeclined( |
|
| 291 | + array $closed_reg_statuses, |
|
| 292 | + $new_STS_ID, |
|
| 293 | + $old_STS_ID, |
|
| 294 | + ContextInterface $context = null |
|
| 295 | + ) { |
|
| 296 | + // true if reinstating cancelled or declined registration |
|
| 297 | + if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
| 298 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
| 299 | + ) { |
|
| 300 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 301 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 302 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 303 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 304 | + // reinstating cancelled or declined registration |
|
| 305 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
| 306 | + $this, |
|
| 307 | + $closed_reg_statuses |
|
| 308 | + ); |
|
| 309 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
| 310 | + $this, |
|
| 311 | + $closed_reg_statuses, |
|
| 312 | + false |
|
| 313 | + ); |
|
| 314 | + do_action( |
|
| 315 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
| 316 | + $this, |
|
| 317 | + $old_STS_ID, |
|
| 318 | + $new_STS_ID, |
|
| 319 | + $context |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * @param ContextInterface|null $context |
|
| 327 | + * @return bool |
|
| 328 | + */ |
|
| 329 | + private function statusChangeUpdatesTransaction(ContextInterface $context = null) |
|
| 330 | + { |
|
| 331 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
| 332 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
| 333 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
| 334 | + $context, |
|
| 335 | + $this |
|
| 336 | + ); |
|
| 337 | + return ! ( |
|
| 338 | + $context instanceof ContextInterface |
|
| 339 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @throws EE_Error |
|
| 346 | + * @throws EntityNotFoundException |
|
| 347 | + * @throws InvalidArgumentException |
|
| 348 | + * @throws InvalidDataTypeException |
|
| 349 | + * @throws InvalidInterfaceException |
|
| 350 | + * @throws ReflectionException |
|
| 351 | + * @throws RuntimeException |
|
| 352 | + */ |
|
| 353 | + private function updateTransactionAfterStatusChange() |
|
| 354 | + { |
|
| 355 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 356 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 357 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
| 358 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * get Status ID |
|
| 364 | + */ |
|
| 365 | + public function status_ID() |
|
| 366 | + { |
|
| 367 | + return $this->get('STS_ID'); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Gets the ticket this registration is for |
|
| 373 | + * |
|
| 374 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
| 375 | + * |
|
| 376 | + * @return EE_Ticket|EE_Base_Class |
|
| 377 | + * @throws EE_Error |
|
| 378 | + */ |
|
| 379 | + public function ticket($include_archived = true) |
|
| 380 | + { |
|
| 381 | + $query_params = array(); |
|
| 382 | + if ($include_archived) { |
|
| 383 | + $query_params['default_where_conditions'] = 'none'; |
|
| 384 | + } |
|
| 385 | + return $this->get_first_related('Ticket', $query_params); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Gets the event this registration is for |
|
| 391 | + * |
|
| 392 | + * @return EE_Event |
|
| 393 | + * @throws EE_Error |
|
| 394 | + * @throws EntityNotFoundException |
|
| 395 | + */ |
|
| 396 | + public function event() |
|
| 397 | + { |
|
| 398 | + $event = $this->get_first_related('Event'); |
|
| 399 | + if (! $event instanceof \EE_Event) { |
|
| 400 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
| 401 | + } |
|
| 402 | + return $event; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
| 408 | + * with the author of the event this registration is for. |
|
| 409 | + * |
|
| 410 | + * @since 4.5.0 |
|
| 411 | + * @return int |
|
| 412 | + * @throws EE_Error |
|
| 413 | + * @throws EntityNotFoundException |
|
| 414 | + */ |
|
| 415 | + public function wp_user() |
|
| 416 | + { |
|
| 417 | + $event = $this->event(); |
|
| 418 | + if ($event instanceof EE_Event) { |
|
| 419 | + return $event->wp_user(); |
|
| 420 | + } |
|
| 421 | + return 0; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
| 427 | + * |
|
| 428 | + * @return void |
|
| 429 | + * @throws DomainException |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws EntityNotFoundException |
|
| 432 | + * @throws InvalidArgumentException |
|
| 433 | + * @throws InvalidDataTypeException |
|
| 434 | + * @throws InvalidInterfaceException |
|
| 435 | + * @throws ReflectionException |
|
| 436 | + * @throws UnexpectedEntityException |
|
| 437 | + */ |
|
| 438 | + private function _reserve_registration_space() |
|
| 439 | + { |
|
| 440 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
| 441 | + // so stop tracking that this reg has a ticket reserved |
|
| 442 | + $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 443 | + $ticket = $this->ticket(); |
|
| 444 | + $ticket->increase_sold(); |
|
| 445 | + $ticket->save(); |
|
| 446 | + // possibly set event status to sold out |
|
| 447 | + $this->event()->perform_sold_out_status_check(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
| 453 | + * |
|
| 454 | + * @return void |
|
| 455 | + * @throws DomainException |
|
| 456 | + * @throws EE_Error |
|
| 457 | + * @throws EntityNotFoundException |
|
| 458 | + * @throws InvalidArgumentException |
|
| 459 | + * @throws InvalidDataTypeException |
|
| 460 | + * @throws InvalidInterfaceException |
|
| 461 | + * @throws ReflectionException |
|
| 462 | + * @throws UnexpectedEntityException |
|
| 463 | + */ |
|
| 464 | + private function _release_registration_space() |
|
| 465 | + { |
|
| 466 | + $ticket = $this->ticket(); |
|
| 467 | + $ticket->decrease_sold(); |
|
| 468 | + $ticket->save(); |
|
| 469 | + // possibly change event status from sold out back to previous status |
|
| 470 | + $this->event()->perform_sold_out_status_check(); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * tracks this registration's ticket reservation in extra meta |
|
| 476 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
| 477 | + * |
|
| 478 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
| 479 | + * @return void |
|
| 480 | + * @throws EE_Error |
|
| 481 | + * @throws InvalidArgumentException |
|
| 482 | + * @throws InvalidDataTypeException |
|
| 483 | + * @throws InvalidInterfaceException |
|
| 484 | + * @throws ReflectionException |
|
| 485 | + */ |
|
| 486 | + public function reserve_ticket($update_ticket = false, $source = 'unknown') |
|
| 487 | + { |
|
| 488 | + // only reserve ticket if space is not currently reserved |
|
| 489 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) { |
|
| 490 | + $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 491 | + // IMPORTANT !!! |
|
| 492 | + // although checking $update_ticket first would be more efficient, |
|
| 493 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 494 | + if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) |
|
| 495 | + && $update_ticket |
|
| 496 | + ) { |
|
| 497 | + $ticket = $this->ticket(); |
|
| 498 | + $ticket->increase_reserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 499 | + $ticket->save(); |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * stops tracking this registration's ticket reservation in extra meta |
|
| 507 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
| 508 | + * |
|
| 509 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
| 510 | + * @return void |
|
| 511 | + * @throws EE_Error |
|
| 512 | + * @throws InvalidArgumentException |
|
| 513 | + * @throws InvalidDataTypeException |
|
| 514 | + * @throws InvalidInterfaceException |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + */ |
|
| 517 | + public function release_reserved_ticket($update_ticket = false, $source = 'unknown') |
|
| 518 | + { |
|
| 519 | + // only release ticket if space is currently reserved |
|
| 520 | + if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) { |
|
| 521 | + $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}"); |
|
| 522 | + // IMPORTANT !!! |
|
| 523 | + // although checking $update_ticket first would be more efficient, |
|
| 524 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
| 525 | + if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false) |
|
| 526 | + && $update_ticket |
|
| 527 | + ) { |
|
| 528 | + $ticket = $this->ticket(); |
|
| 529 | + $ticket->decrease_reserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 530 | + $ticket->save(); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Set Attendee ID |
|
| 538 | + * |
|
| 539 | + * @param int $ATT_ID Attendee ID |
|
| 540 | + * @throws EE_Error |
|
| 541 | + * @throws RuntimeException |
|
| 542 | + */ |
|
| 543 | + public function set_attendee_id($ATT_ID = 0) |
|
| 544 | + { |
|
| 545 | + $this->set('ATT_ID', $ATT_ID); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Set Transaction ID |
|
| 551 | + * |
|
| 552 | + * @param int $TXN_ID Transaction ID |
|
| 553 | + * @throws EE_Error |
|
| 554 | + * @throws RuntimeException |
|
| 555 | + */ |
|
| 556 | + public function set_transaction_id($TXN_ID = 0) |
|
| 557 | + { |
|
| 558 | + $this->set('TXN_ID', $TXN_ID); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Set Session |
|
| 564 | + * |
|
| 565 | + * @param string $REG_session PHP Session ID |
|
| 566 | + * @throws EE_Error |
|
| 567 | + * @throws RuntimeException |
|
| 568 | + */ |
|
| 569 | + public function set_session($REG_session = '') |
|
| 570 | + { |
|
| 571 | + $this->set('REG_session', $REG_session); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * Set Registration URL Link |
|
| 577 | + * |
|
| 578 | + * @param string $REG_url_link Registration URL Link |
|
| 579 | + * @throws EE_Error |
|
| 580 | + * @throws RuntimeException |
|
| 581 | + */ |
|
| 582 | + public function set_reg_url_link($REG_url_link = '') |
|
| 583 | + { |
|
| 584 | + $this->set('REG_url_link', $REG_url_link); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Set Attendee Counter |
|
| 590 | + * |
|
| 591 | + * @param int $REG_count Primary Attendee |
|
| 592 | + * @throws EE_Error |
|
| 593 | + * @throws RuntimeException |
|
| 594 | + */ |
|
| 595 | + public function set_count($REG_count = 1) |
|
| 596 | + { |
|
| 597 | + $this->set('REG_count', $REG_count); |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * Set Group Size |
|
| 603 | + * |
|
| 604 | + * @param boolean $REG_group_size Group Registration |
|
| 605 | + * @throws EE_Error |
|
| 606 | + * @throws RuntimeException |
|
| 607 | + */ |
|
| 608 | + public function set_group_size($REG_group_size = false) |
|
| 609 | + { |
|
| 610 | + $this->set('REG_group_size', $REG_group_size); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
| 616 | + * EEM_Registration::status_id_not_approved |
|
| 617 | + * |
|
| 618 | + * @return boolean |
|
| 619 | + */ |
|
| 620 | + public function is_not_approved() |
|
| 621 | + { |
|
| 622 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
| 628 | + * EEM_Registration::status_id_pending_payment |
|
| 629 | + * |
|
| 630 | + * @return boolean |
|
| 631 | + */ |
|
| 632 | + public function is_pending_payment() |
|
| 633 | + { |
|
| 634 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
| 640 | + * |
|
| 641 | + * @return boolean |
|
| 642 | + */ |
|
| 643 | + public function is_approved() |
|
| 644 | + { |
|
| 645 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
| 651 | + * |
|
| 652 | + * @return boolean |
|
| 653 | + */ |
|
| 654 | + public function is_cancelled() |
|
| 655 | + { |
|
| 656 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
| 662 | + * |
|
| 663 | + * @return boolean |
|
| 664 | + */ |
|
| 665 | + public function is_declined() |
|
| 666 | + { |
|
| 667 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
| 673 | + * EEM_Registration::status_id_incomplete |
|
| 674 | + * |
|
| 675 | + * @return boolean |
|
| 676 | + */ |
|
| 677 | + public function is_incomplete() |
|
| 678 | + { |
|
| 679 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Set Registration Date |
|
| 685 | + * |
|
| 686 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
| 687 | + * Date |
|
| 688 | + * @throws EE_Error |
|
| 689 | + * @throws RuntimeException |
|
| 690 | + */ |
|
| 691 | + public function set_reg_date($REG_date = false) |
|
| 692 | + { |
|
| 693 | + $this->set('REG_date', $REG_date); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Set final price owing for this registration after all ticket/price modifications |
|
| 699 | + * |
|
| 700 | + * @access public |
|
| 701 | + * @param float $REG_final_price |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws RuntimeException |
|
| 704 | + */ |
|
| 705 | + public function set_final_price($REG_final_price = 0.00) |
|
| 706 | + { |
|
| 707 | + $this->set('REG_final_price', $REG_final_price); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Set amount paid towards this registration's final price |
|
| 713 | + * |
|
| 714 | + * @access public |
|
| 715 | + * @param float $REG_paid |
|
| 716 | + * @throws EE_Error |
|
| 717 | + * @throws RuntimeException |
|
| 718 | + */ |
|
| 719 | + public function set_paid($REG_paid = 0.00) |
|
| 720 | + { |
|
| 721 | + $this->set('REG_paid', $REG_paid); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Attendee Is Going |
|
| 727 | + * |
|
| 728 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
| 729 | + * @throws EE_Error |
|
| 730 | + * @throws RuntimeException |
|
| 731 | + */ |
|
| 732 | + public function set_att_is_going($REG_att_is_going = false) |
|
| 733 | + { |
|
| 734 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Gets the related attendee |
|
| 740 | + * |
|
| 741 | + * @return EE_Attendee |
|
| 742 | + * @throws EE_Error |
|
| 743 | + */ |
|
| 744 | + public function attendee() |
|
| 745 | + { |
|
| 746 | + return $this->get_first_related('Attendee'); |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * get Event ID |
|
| 752 | + */ |
|
| 753 | + public function event_ID() |
|
| 754 | + { |
|
| 755 | + return $this->get('EVT_ID'); |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * get Event ID |
|
| 761 | + */ |
|
| 762 | + public function event_name() |
|
| 763 | + { |
|
| 764 | + $event = $this->event_obj(); |
|
| 765 | + if ($event) { |
|
| 766 | + return $event->name(); |
|
| 767 | + } else { |
|
| 768 | + return null; |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Fetches the event this registration is for |
|
| 775 | + * |
|
| 776 | + * @return EE_Event |
|
| 777 | + * @throws EE_Error |
|
| 778 | + */ |
|
| 779 | + public function event_obj() |
|
| 780 | + { |
|
| 781 | + return $this->get_first_related('Event'); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * get Attendee ID |
|
| 787 | + */ |
|
| 788 | + public function attendee_ID() |
|
| 789 | + { |
|
| 790 | + return $this->get('ATT_ID'); |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * get PHP Session ID |
|
| 796 | + */ |
|
| 797 | + public function session_ID() |
|
| 798 | + { |
|
| 799 | + return $this->get('REG_session'); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + |
|
| 803 | + /** |
|
| 804 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
| 805 | + * |
|
| 806 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 807 | + * @return string |
|
| 808 | + */ |
|
| 809 | + public function receipt_url($messenger = 'html') |
|
| 810 | + { |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
| 814 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 815 | + * |
|
| 816 | + * @since 4.5.0 |
|
| 817 | + */ |
|
| 818 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
| 819 | + $has_custom = EEH_Template::locate_template( |
|
| 820 | + $template_relative_path, |
|
| 821 | + array(), |
|
| 822 | + true, |
|
| 823 | + true, |
|
| 824 | + true |
|
| 825 | + ); |
|
| 826 | + |
|
| 827 | + if ($has_custom) { |
|
| 828 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
| 829 | + } |
|
| 830 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
| 836 | + * |
|
| 837 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
| 838 | + * @return string |
|
| 839 | + * @throws EE_Error |
|
| 840 | + */ |
|
| 841 | + public function invoice_url($messenger = 'html') |
|
| 842 | + { |
|
| 843 | + /** |
|
| 844 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
| 845 | + * already in use on old system. If there is then we just return the standard url for it. |
|
| 846 | + * |
|
| 847 | + * @since 4.5.0 |
|
| 848 | + */ |
|
| 849 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
| 850 | + $has_custom = EEH_Template::locate_template( |
|
| 851 | + $template_relative_path, |
|
| 852 | + array(), |
|
| 853 | + true, |
|
| 854 | + true, |
|
| 855 | + true |
|
| 856 | + ); |
|
| 857 | + |
|
| 858 | + if ($has_custom) { |
|
| 859 | + if ($messenger == 'html') { |
|
| 860 | + return $this->invoice_url('launch'); |
|
| 861 | + } |
|
| 862 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
| 863 | + |
|
| 864 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
| 865 | + if ($messenger == 'html') { |
|
| 866 | + $query_args['html'] = true; |
|
| 867 | + } |
|
| 868 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
| 869 | + } |
|
| 870 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + |
|
| 874 | + /** |
|
| 875 | + * get Registration URL Link |
|
| 876 | + * |
|
| 877 | + * @access public |
|
| 878 | + * @return string |
|
| 879 | + * @throws EE_Error |
|
| 880 | + */ |
|
| 881 | + public function reg_url_link() |
|
| 882 | + { |
|
| 883 | + return (string) $this->get('REG_url_link'); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * Echoes out invoice_url() |
|
| 889 | + * |
|
| 890 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
| 891 | + * @return void |
|
| 892 | + * @throws EE_Error |
|
| 893 | + */ |
|
| 894 | + public function e_invoice_url($type = 'launch') |
|
| 895 | + { |
|
| 896 | + echo $this->invoice_url($type); |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + |
|
| 900 | + /** |
|
| 901 | + * Echoes out payment_overview_url |
|
| 902 | + */ |
|
| 903 | + public function e_payment_overview_url() |
|
| 904 | + { |
|
| 905 | + echo $this->payment_overview_url(); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Gets the URL for the checkout payment options reg step |
|
| 911 | + * with this registration's REG_url_link added as a query parameter |
|
| 912 | + * |
|
| 913 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
| 914 | + * payment overview url. |
|
| 915 | + * @return string |
|
| 916 | + * @throws InvalidInterfaceException |
|
| 917 | + * @throws InvalidDataTypeException |
|
| 918 | + * @throws EE_Error |
|
| 919 | + * @throws InvalidArgumentException |
|
| 920 | + */ |
|
| 921 | + public function payment_overview_url($clear_session = false) |
|
| 922 | + { |
|
| 923 | + return add_query_arg( |
|
| 924 | + (array) apply_filters( |
|
| 925 | + 'FHEE__EE_Registration__payment_overview_url__query_args', |
|
| 926 | + array( |
|
| 927 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 928 | + 'step' => 'payment_options', |
|
| 929 | + 'revisit' => true, |
|
| 930 | + 'clear_session' => (bool) $clear_session, |
|
| 931 | + ), |
|
| 932 | + $this |
|
| 933 | + ), |
|
| 934 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 935 | + ); |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + |
|
| 939 | + /** |
|
| 940 | + * Gets the URL for the checkout attendee information reg step |
|
| 941 | + * with this registration's REG_url_link added as a query parameter |
|
| 942 | + * |
|
| 943 | + * @return string |
|
| 944 | + * @throws InvalidInterfaceException |
|
| 945 | + * @throws InvalidDataTypeException |
|
| 946 | + * @throws EE_Error |
|
| 947 | + * @throws InvalidArgumentException |
|
| 948 | + */ |
|
| 949 | + public function edit_attendee_information_url() |
|
| 950 | + { |
|
| 951 | + return add_query_arg( |
|
| 952 | + (array) apply_filters( |
|
| 953 | + 'FHEE__EE_Registration__edit_attendee_information_url__query_args', |
|
| 954 | + array( |
|
| 955 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
| 956 | + 'step' => 'attendee_information', |
|
| 957 | + 'revisit' => true, |
|
| 958 | + ), |
|
| 959 | + $this |
|
| 960 | + ), |
|
| 961 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 962 | + ); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + /** |
|
| 967 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
| 968 | + * |
|
| 969 | + * @return string |
|
| 970 | + * @throws EE_Error |
|
| 971 | + */ |
|
| 972 | + public function get_admin_edit_url() |
|
| 973 | + { |
|
| 974 | + return EEH_URL::add_query_args_and_nonce( |
|
| 975 | + array( |
|
| 976 | + 'page' => 'espresso_registrations', |
|
| 977 | + 'action' => 'view_registration', |
|
| 978 | + '_REG_ID' => $this->ID(), |
|
| 979 | + ), |
|
| 980 | + admin_url('admin.php') |
|
| 981 | + ); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + |
|
| 985 | + /** |
|
| 986 | + * is_primary_registrant? |
|
| 987 | + */ |
|
| 988 | + public function is_primary_registrant() |
|
| 989 | + { |
|
| 990 | + return $this->get('REG_count') == 1 ? true : false; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + |
|
| 994 | + /** |
|
| 995 | + * This returns the primary registration object for this registration group (which may be this object). |
|
| 996 | + * |
|
| 997 | + * @return EE_Registration |
|
| 998 | + * @throws EE_Error |
|
| 999 | + */ |
|
| 1000 | + public function get_primary_registration() |
|
| 1001 | + { |
|
| 1002 | + if ($this->is_primary_registrant()) { |
|
| 1003 | + return $this; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
| 1007 | + /** @var EE_Registration $primary_registrant */ |
|
| 1008 | + $primary_registrant = EEM_Registration::instance()->get_one( |
|
| 1009 | + array( |
|
| 1010 | + array( |
|
| 1011 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 1012 | + 'REG_count' => 1, |
|
| 1013 | + ), |
|
| 1014 | + ) |
|
| 1015 | + ); |
|
| 1016 | + return $primary_registrant; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + |
|
| 1020 | + /** |
|
| 1021 | + * get Attendee Number |
|
| 1022 | + * |
|
| 1023 | + * @access public |
|
| 1024 | + */ |
|
| 1025 | + public function count() |
|
| 1026 | + { |
|
| 1027 | + return $this->get('REG_count'); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + |
|
| 1031 | + /** |
|
| 1032 | + * get Group Size |
|
| 1033 | + */ |
|
| 1034 | + public function group_size() |
|
| 1035 | + { |
|
| 1036 | + return $this->get('REG_group_size'); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * get Registration Date |
|
| 1042 | + */ |
|
| 1043 | + public function date() |
|
| 1044 | + { |
|
| 1045 | + return $this->get('REG_date'); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * gets a pretty date |
|
| 1051 | + * |
|
| 1052 | + * @param string $date_format |
|
| 1053 | + * @param string $time_format |
|
| 1054 | + * @return string |
|
| 1055 | + * @throws EE_Error |
|
| 1056 | + */ |
|
| 1057 | + public function pretty_date($date_format = null, $time_format = null) |
|
| 1058 | + { |
|
| 1059 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * final_price |
|
| 1065 | + * the registration's share of the transaction total, so that the |
|
| 1066 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
| 1067 | + * |
|
| 1068 | + * @return float |
|
| 1069 | + * @throws EE_Error |
|
| 1070 | + */ |
|
| 1071 | + public function final_price() |
|
| 1072 | + { |
|
| 1073 | + return $this->get('REG_final_price'); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + |
|
| 1077 | + /** |
|
| 1078 | + * pretty_final_price |
|
| 1079 | + * final price as formatted string, with correct decimal places and currency symbol |
|
| 1080 | + * |
|
| 1081 | + * @return string |
|
| 1082 | + * @throws EE_Error |
|
| 1083 | + */ |
|
| 1084 | + public function pretty_final_price() |
|
| 1085 | + { |
|
| 1086 | + return $this->get_pretty('REG_final_price'); |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + |
|
| 1090 | + /** |
|
| 1091 | + * get paid (yeah) |
|
| 1092 | + * |
|
| 1093 | + * @return float |
|
| 1094 | + * @throws EE_Error |
|
| 1095 | + */ |
|
| 1096 | + public function paid() |
|
| 1097 | + { |
|
| 1098 | + return $this->get('REG_paid'); |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * pretty_paid |
|
| 1104 | + * |
|
| 1105 | + * @return float |
|
| 1106 | + * @throws EE_Error |
|
| 1107 | + */ |
|
| 1108 | + public function pretty_paid() |
|
| 1109 | + { |
|
| 1110 | + return $this->get_pretty('REG_paid'); |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * owes_monies_and_can_pay |
|
| 1116 | + * whether or not this registration has monies owing and it's' status allows payment |
|
| 1117 | + * |
|
| 1118 | + * @param array $requires_payment |
|
| 1119 | + * @return bool |
|
| 1120 | + * @throws EE_Error |
|
| 1121 | + */ |
|
| 1122 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
| 1123 | + { |
|
| 1124 | + // these reg statuses require payment (if event is not free) |
|
| 1125 | + $requires_payment = ! empty($requires_payment) |
|
| 1126 | + ? $requires_payment |
|
| 1127 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
| 1128 | + if (in_array($this->status_ID(), $requires_payment) && |
|
| 1129 | + $this->final_price() != 0 && |
|
| 1130 | + $this->final_price() != $this->paid() |
|
| 1131 | + ) { |
|
| 1132 | + return true; |
|
| 1133 | + } else { |
|
| 1134 | + return false; |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * Prints out the return value of $this->pretty_status() |
|
| 1141 | + * |
|
| 1142 | + * @param bool $show_icons |
|
| 1143 | + * @return void |
|
| 1144 | + * @throws EE_Error |
|
| 1145 | + */ |
|
| 1146 | + public function e_pretty_status($show_icons = false) |
|
| 1147 | + { |
|
| 1148 | + echo $this->pretty_status($show_icons); |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + |
|
| 1152 | + /** |
|
| 1153 | + * Returns a nice version of the status for displaying to customers |
|
| 1154 | + * |
|
| 1155 | + * @param bool $show_icons |
|
| 1156 | + * @return string |
|
| 1157 | + * @throws EE_Error |
|
| 1158 | + */ |
|
| 1159 | + public function pretty_status($show_icons = false) |
|
| 1160 | + { |
|
| 1161 | + $status = EEM_Status::instance()->localized_status( |
|
| 1162 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
| 1163 | + false, |
|
| 1164 | + 'sentence' |
|
| 1165 | + ); |
|
| 1166 | + $icon = ''; |
|
| 1167 | + switch ($this->status_ID()) { |
|
| 1168 | + case EEM_Registration::status_id_approved: |
|
| 1169 | + $icon = $show_icons |
|
| 1170 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
| 1171 | + : ''; |
|
| 1172 | + break; |
|
| 1173 | + case EEM_Registration::status_id_pending_payment: |
|
| 1174 | + $icon = $show_icons |
|
| 1175 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
| 1176 | + : ''; |
|
| 1177 | + break; |
|
| 1178 | + case EEM_Registration::status_id_not_approved: |
|
| 1179 | + $icon = $show_icons |
|
| 1180 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
| 1181 | + : ''; |
|
| 1182 | + break; |
|
| 1183 | + case EEM_Registration::status_id_cancelled: |
|
| 1184 | + $icon = $show_icons |
|
| 1185 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
| 1186 | + : ''; |
|
| 1187 | + break; |
|
| 1188 | + case EEM_Registration::status_id_incomplete: |
|
| 1189 | + $icon = $show_icons |
|
| 1190 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
| 1191 | + : ''; |
|
| 1192 | + break; |
|
| 1193 | + case EEM_Registration::status_id_declined: |
|
| 1194 | + $icon = $show_icons |
|
| 1195 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
| 1196 | + : ''; |
|
| 1197 | + break; |
|
| 1198 | + case EEM_Registration::status_id_wait_list: |
|
| 1199 | + $icon = $show_icons |
|
| 1200 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
| 1201 | + : ''; |
|
| 1202 | + break; |
|
| 1203 | + } |
|
| 1204 | + return $icon . $status[ $this->status_ID() ]; |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * get Attendee Is Going |
|
| 1210 | + */ |
|
| 1211 | + public function att_is_going() |
|
| 1212 | + { |
|
| 1213 | + return $this->get('REG_att_is_going'); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * Gets related answers |
|
| 1219 | + * |
|
| 1220 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1221 | + * @return EE_Answer[] |
|
| 1222 | + * @throws EE_Error |
|
| 1223 | + */ |
|
| 1224 | + public function answers($query_params = null) |
|
| 1225 | + { |
|
| 1226 | + return $this->get_many_related('Answer', $query_params); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * Gets the registration's answer value to the specified question |
|
| 1232 | + * (either the question's ID or a question object) |
|
| 1233 | + * |
|
| 1234 | + * @param EE_Question|int $question |
|
| 1235 | + * @param bool $pretty_value |
|
| 1236 | + * @return array|string if pretty_value= true, the result will always be a string |
|
| 1237 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
| 1238 | + * will convert it into some kind of string) |
|
| 1239 | + * @throws EE_Error |
|
| 1240 | + */ |
|
| 1241 | + public function answer_value_to_question($question, $pretty_value = true) |
|
| 1242 | + { |
|
| 1243 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
| 1244 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + /** |
|
| 1249 | + * question_groups |
|
| 1250 | + * returns an array of EE_Question_Group objects for this registration |
|
| 1251 | + * |
|
| 1252 | + * @return EE_Question_Group[] |
|
| 1253 | + * @throws EE_Error |
|
| 1254 | + * @throws EntityNotFoundException |
|
| 1255 | + */ |
|
| 1256 | + public function question_groups() |
|
| 1257 | + { |
|
| 1258 | + $question_groups = array(); |
|
| 1259 | + if ($this->event() instanceof EE_Event) { |
|
| 1260 | + $question_groups = $this->event()->question_groups( |
|
| 1261 | + array( |
|
| 1262 | + array( |
|
| 1263 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1264 | + ), |
|
| 1265 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 1266 | + ) |
|
| 1267 | + ); |
|
| 1268 | + } |
|
| 1269 | + return $question_groups; |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * count_question_groups |
|
| 1275 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
| 1276 | + * |
|
| 1277 | + * @return int |
|
| 1278 | + * @throws EE_Error |
|
| 1279 | + * @throws EntityNotFoundException |
|
| 1280 | + */ |
|
| 1281 | + public function count_question_groups() |
|
| 1282 | + { |
|
| 1283 | + $qg_count = 0; |
|
| 1284 | + if ($this->event() instanceof EE_Event) { |
|
| 1285 | + $qg_count = $this->event()->count_related( |
|
| 1286 | + 'Question_Group', |
|
| 1287 | + array( |
|
| 1288 | + array( |
|
| 1289 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
| 1290 | + ), |
|
| 1291 | + ) |
|
| 1292 | + ); |
|
| 1293 | + } |
|
| 1294 | + return $qg_count; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * Returns the registration date in the 'standard' string format |
|
| 1300 | + * (function may be improved in the future to allow for different formats and timezones) |
|
| 1301 | + * |
|
| 1302 | + * @return string |
|
| 1303 | + * @throws EE_Error |
|
| 1304 | + */ |
|
| 1305 | + public function reg_date() |
|
| 1306 | + { |
|
| 1307 | + return $this->get_datetime('REG_date'); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + |
|
| 1311 | + /** |
|
| 1312 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
| 1313 | + * the ticket this registration purchased, or the datetime they have registered |
|
| 1314 | + * to attend) |
|
| 1315 | + * |
|
| 1316 | + * @return EE_Datetime_Ticket |
|
| 1317 | + * @throws EE_Error |
|
| 1318 | + */ |
|
| 1319 | + public function datetime_ticket() |
|
| 1320 | + { |
|
| 1321 | + return $this->get_first_related('Datetime_Ticket'); |
|
| 1322 | + } |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * Sets the registration's datetime_ticket. |
|
| 1327 | + * |
|
| 1328 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
| 1329 | + * @return EE_Datetime_Ticket |
|
| 1330 | + * @throws EE_Error |
|
| 1331 | + */ |
|
| 1332 | + public function set_datetime_ticket($datetime_ticket) |
|
| 1333 | + { |
|
| 1334 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + /** |
|
| 1338 | + * Gets deleted |
|
| 1339 | + * |
|
| 1340 | + * @return bool |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + */ |
|
| 1343 | + public function deleted() |
|
| 1344 | + { |
|
| 1345 | + return $this->get('REG_deleted'); |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Sets deleted |
|
| 1350 | + * |
|
| 1351 | + * @param boolean $deleted |
|
| 1352 | + * @return bool |
|
| 1353 | + * @throws EE_Error |
|
| 1354 | + * @throws RuntimeException |
|
| 1355 | + */ |
|
| 1356 | + public function set_deleted($deleted) |
|
| 1357 | + { |
|
| 1358 | + if ($deleted) { |
|
| 1359 | + $this->delete(); |
|
| 1360 | + } else { |
|
| 1361 | + $this->restore(); |
|
| 1362 | + } |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + /** |
|
| 1367 | + * Get the status object of this object |
|
| 1368 | + * |
|
| 1369 | + * @return EE_Status |
|
| 1370 | + * @throws EE_Error |
|
| 1371 | + */ |
|
| 1372 | + public function status_obj() |
|
| 1373 | + { |
|
| 1374 | + return $this->get_first_related('Status'); |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + |
|
| 1378 | + /** |
|
| 1379 | + * Returns the number of times this registration has checked into any of the datetimes |
|
| 1380 | + * its available for |
|
| 1381 | + * |
|
| 1382 | + * @return int |
|
| 1383 | + * @throws EE_Error |
|
| 1384 | + */ |
|
| 1385 | + public function count_checkins() |
|
| 1386 | + { |
|
| 1387 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
| 1388 | + } |
|
| 1389 | + |
|
| 1390 | + |
|
| 1391 | + /** |
|
| 1392 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
| 1393 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
| 1394 | + * |
|
| 1395 | + * @return int |
|
| 1396 | + * @throws EE_Error |
|
| 1397 | + */ |
|
| 1398 | + public function count_checkins_not_checkedout() |
|
| 1399 | + { |
|
| 1400 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + |
|
| 1404 | + /** |
|
| 1405 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
| 1406 | + * |
|
| 1407 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1408 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
| 1409 | + * consider registration status as well as datetime access. |
|
| 1410 | + * @return bool |
|
| 1411 | + * @throws EE_Error |
|
| 1412 | + */ |
|
| 1413 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
| 1414 | + { |
|
| 1415 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1416 | + |
|
| 1417 | + // first check registration status |
|
| 1418 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
| 1419 | + return false; |
|
| 1420 | + } |
|
| 1421 | + // is there a datetime ticket that matches this dtt_ID? |
|
| 1422 | + if (! (EEM_Datetime_Ticket::instance()->exists( |
|
| 1423 | + array( |
|
| 1424 | + array( |
|
| 1425 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
| 1426 | + 'DTT_ID' => $DTT_ID, |
|
| 1427 | + ), |
|
| 1428 | + ) |
|
| 1429 | + )) |
|
| 1430 | + ) { |
|
| 1431 | + return false; |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + // final check is against TKT_uses |
|
| 1435 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + |
|
| 1439 | + /** |
|
| 1440 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
| 1441 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
| 1442 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
| 1443 | + * then return false. Otherwise return true. |
|
| 1444 | + * |
|
| 1445 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
| 1446 | + * @return bool true means can checkin. false means cannot checkin. |
|
| 1447 | + * @throws EE_Error |
|
| 1448 | + */ |
|
| 1449 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
| 1450 | + { |
|
| 1451 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
| 1452 | + |
|
| 1453 | + if (! $DTT_ID) { |
|
| 1454 | + return false; |
|
| 1455 | + } |
|
| 1456 | + |
|
| 1457 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
| 1458 | + |
|
| 1459 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
| 1460 | + // check-in or not. |
|
| 1461 | + if (! $max_uses || $max_uses === EE_INF) { |
|
| 1462 | + return true; |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + // does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
| 1466 | + // go ahead and toggle. |
|
| 1467 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
| 1468 | + return true; |
|
| 1469 | + } |
|
| 1470 | + |
|
| 1471 | + // made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
| 1472 | + // disallows further check-ins. |
|
| 1473 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count( |
|
| 1474 | + array( |
|
| 1475 | + array( |
|
| 1476 | + 'REG_ID' => $this->ID(), |
|
| 1477 | + 'CHK_in' => true, |
|
| 1478 | + ), |
|
| 1479 | + ), |
|
| 1480 | + 'DTT_ID', |
|
| 1481 | + true |
|
| 1482 | + ); |
|
| 1483 | + // checkins have already reached their max number of uses |
|
| 1484 | + // so registrant can NOT checkin |
|
| 1485 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
| 1486 | + EE_Error::add_error( |
|
| 1487 | + esc_html__( |
|
| 1488 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
| 1489 | + 'event_espresso' |
|
| 1490 | + ), |
|
| 1491 | + __FILE__, |
|
| 1492 | + __FUNCTION__, |
|
| 1493 | + __LINE__ |
|
| 1494 | + ); |
|
| 1495 | + return false; |
|
| 1496 | + } |
|
| 1497 | + return true; |
|
| 1498 | + } |
|
| 1499 | + |
|
| 1500 | + |
|
| 1501 | + /** |
|
| 1502 | + * toggle Check-in status for this registration |
|
| 1503 | + * Check-ins are toggled in the following order: |
|
| 1504 | + * never checked in -> checked in |
|
| 1505 | + * checked in -> checked out |
|
| 1506 | + * checked out -> checked in |
|
| 1507 | + * |
|
| 1508 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
| 1509 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
| 1510 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
| 1511 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
| 1512 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
| 1513 | + * @throws EE_Error |
|
| 1514 | + */ |
|
| 1515 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
| 1516 | + { |
|
| 1517 | + if (empty($DTT_ID)) { |
|
| 1518 | + $datetime = $this->get_latest_related_datetime(); |
|
| 1519 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
| 1520 | + // verify the registration can checkin for the given DTT_ID |
|
| 1521 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
| 1522 | + EE_Error::add_error( |
|
| 1523 | + sprintf( |
|
| 1524 | + esc_html__( |
|
| 1525 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
| 1526 | + 'event_espresso' |
|
| 1527 | + ), |
|
| 1528 | + $this->ID(), |
|
| 1529 | + $DTT_ID |
|
| 1530 | + ), |
|
| 1531 | + __FILE__, |
|
| 1532 | + __FUNCTION__, |
|
| 1533 | + __LINE__ |
|
| 1534 | + ); |
|
| 1535 | + return false; |
|
| 1536 | + } |
|
| 1537 | + $status_paths = array( |
|
| 1538 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
| 1539 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
| 1540 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
| 1541 | + ); |
|
| 1542 | + // start by getting the current status so we know what status we'll be changing to. |
|
| 1543 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
| 1544 | + $status_to = $status_paths[ $cur_status ]; |
|
| 1545 | + // database only records true for checked IN or false for checked OUT |
|
| 1546 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
| 1547 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
| 1548 | + // add relation - note Check-ins are always creating new rows |
|
| 1549 | + // because we are keeping track of Check-ins over time. |
|
| 1550 | + // Eventually we'll probably want to show a list table |
|
| 1551 | + // for the individual Check-ins so that they can be managed. |
|
| 1552 | + $checkin = EE_Checkin::new_instance( |
|
| 1553 | + array( |
|
| 1554 | + 'REG_ID' => $this->ID(), |
|
| 1555 | + 'DTT_ID' => $DTT_ID, |
|
| 1556 | + 'CHK_in' => $new_status, |
|
| 1557 | + ) |
|
| 1558 | + ); |
|
| 1559 | + // if the record could not be saved then return false |
|
| 1560 | + if ($checkin->save() === 0) { |
|
| 1561 | + if (WP_DEBUG) { |
|
| 1562 | + global $wpdb; |
|
| 1563 | + $error = sprintf( |
|
| 1564 | + esc_html__( |
|
| 1565 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
| 1566 | + 'event_espresso' |
|
| 1567 | + ), |
|
| 1568 | + '<br />', |
|
| 1569 | + $wpdb->last_error |
|
| 1570 | + ); |
|
| 1571 | + } else { |
|
| 1572 | + $error = esc_html__( |
|
| 1573 | + 'Registration check in update failed because of an unknown database error', |
|
| 1574 | + 'event_espresso' |
|
| 1575 | + ); |
|
| 1576 | + } |
|
| 1577 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 1578 | + return false; |
|
| 1579 | + } |
|
| 1580 | + return $status_to; |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + |
|
| 1584 | + /** |
|
| 1585 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
| 1586 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
| 1587 | + * |
|
| 1588 | + * @return EE_Datetime|null |
|
| 1589 | + * @throws EE_Error |
|
| 1590 | + */ |
|
| 1591 | + public function get_latest_related_datetime() |
|
| 1592 | + { |
|
| 1593 | + return EEM_Datetime::instance()->get_one( |
|
| 1594 | + array( |
|
| 1595 | + array( |
|
| 1596 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1597 | + ), |
|
| 1598 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
| 1599 | + ) |
|
| 1600 | + ); |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + |
|
| 1604 | + /** |
|
| 1605 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
| 1606 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
| 1607 | + * |
|
| 1608 | + * @throws EE_Error |
|
| 1609 | + */ |
|
| 1610 | + public function get_earliest_related_datetime() |
|
| 1611 | + { |
|
| 1612 | + return EEM_Datetime::instance()->get_one( |
|
| 1613 | + array( |
|
| 1614 | + array( |
|
| 1615 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
| 1616 | + ), |
|
| 1617 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 1618 | + ) |
|
| 1619 | + ); |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + |
|
| 1623 | + /** |
|
| 1624 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
| 1625 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
| 1626 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
| 1627 | + * |
|
| 1628 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
| 1629 | + * (if empty we'll get the primary datetime for |
|
| 1630 | + * this registration (via event) and use it's ID); |
|
| 1631 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
| 1632 | + * |
|
| 1633 | + * @return int Integer representing Check-in status. |
|
| 1634 | + * @throws EE_Error |
|
| 1635 | + */ |
|
| 1636 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
| 1637 | + { |
|
| 1638 | + $checkin_query_params = array( |
|
| 1639 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
| 1640 | + ); |
|
| 1641 | + |
|
| 1642 | + if ($DTT_ID > 0) { |
|
| 1643 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
| 1644 | + } |
|
| 1645 | + |
|
| 1646 | + // get checkin object (if exists) |
|
| 1647 | + $checkin = $checkin instanceof EE_Checkin |
|
| 1648 | + ? $checkin |
|
| 1649 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
| 1650 | + if ($checkin instanceof EE_Checkin) { |
|
| 1651 | + if ($checkin->get('CHK_in')) { |
|
| 1652 | + return EE_Checkin::status_checked_in; // checked in |
|
| 1653 | + } |
|
| 1654 | + return EE_Checkin::status_checked_out; // had checked in but is now checked out. |
|
| 1655 | + } |
|
| 1656 | + return EE_Checkin::status_checked_never; // never been checked in |
|
| 1657 | + } |
|
| 1658 | + |
|
| 1659 | + |
|
| 1660 | + /** |
|
| 1661 | + * This method returns a localized message for the toggled Check-in message. |
|
| 1662 | + * |
|
| 1663 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
| 1664 | + * then it is assumed Check-in for primary datetime was toggled. |
|
| 1665 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
| 1666 | + * message can be customized with the attendee name. |
|
| 1667 | + * @return string internationalized message |
|
| 1668 | + * @throws EE_Error |
|
| 1669 | + */ |
|
| 1670 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
| 1671 | + { |
|
| 1672 | + // let's get the attendee first so we can include the name of the attendee |
|
| 1673 | + $attendee = $this->get_first_related('Attendee'); |
|
| 1674 | + if ($attendee instanceof EE_Attendee) { |
|
| 1675 | + if ($error) { |
|
| 1676 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
| 1677 | + } |
|
| 1678 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
| 1679 | + // what is the status message going to be? |
|
| 1680 | + switch ($cur_status) { |
|
| 1681 | + case EE_Checkin::status_checked_never: |
|
| 1682 | + return sprintf( |
|
| 1683 | + __("%s has been removed from Check-in records", "event_espresso"), |
|
| 1684 | + $attendee->full_name() |
|
| 1685 | + ); |
|
| 1686 | + break; |
|
| 1687 | + case EE_Checkin::status_checked_in: |
|
| 1688 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
| 1689 | + break; |
|
| 1690 | + case EE_Checkin::status_checked_out: |
|
| 1691 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
| 1692 | + break; |
|
| 1693 | + } |
|
| 1694 | + } |
|
| 1695 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
| 1696 | + } |
|
| 1697 | + |
|
| 1698 | + |
|
| 1699 | + /** |
|
| 1700 | + * Returns the related EE_Transaction to this registration |
|
| 1701 | + * |
|
| 1702 | + * @return EE_Transaction |
|
| 1703 | + * @throws EE_Error |
|
| 1704 | + * @throws EntityNotFoundException |
|
| 1705 | + */ |
|
| 1706 | + public function transaction() |
|
| 1707 | + { |
|
| 1708 | + $transaction = $this->get_first_related('Transaction'); |
|
| 1709 | + if (! $transaction instanceof \EE_Transaction) { |
|
| 1710 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
| 1711 | + } |
|
| 1712 | + return $transaction; |
|
| 1713 | + } |
|
| 1714 | + |
|
| 1715 | + |
|
| 1716 | + /** |
|
| 1717 | + * get Registration Code |
|
| 1718 | + */ |
|
| 1719 | + public function reg_code() |
|
| 1720 | + { |
|
| 1721 | + return $this->get('REG_code'); |
|
| 1722 | + } |
|
| 1723 | + |
|
| 1724 | + |
|
| 1725 | + /** |
|
| 1726 | + * get Transaction ID |
|
| 1727 | + */ |
|
| 1728 | + public function transaction_ID() |
|
| 1729 | + { |
|
| 1730 | + return $this->get('TXN_ID'); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * @return int |
|
| 1736 | + * @throws EE_Error |
|
| 1737 | + */ |
|
| 1738 | + public function ticket_ID() |
|
| 1739 | + { |
|
| 1740 | + return $this->get('TKT_ID'); |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + |
|
| 1744 | + /** |
|
| 1745 | + * Set Registration Code |
|
| 1746 | + * |
|
| 1747 | + * @access public |
|
| 1748 | + * @param string $REG_code Registration Code |
|
| 1749 | + * @param boolean $use_default |
|
| 1750 | + * @throws EE_Error |
|
| 1751 | + */ |
|
| 1752 | + public function set_reg_code($REG_code, $use_default = false) |
|
| 1753 | + { |
|
| 1754 | + if (empty($REG_code)) { |
|
| 1755 | + EE_Error::add_error( |
|
| 1756 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
| 1757 | + __FILE__, |
|
| 1758 | + __FUNCTION__, |
|
| 1759 | + __LINE__ |
|
| 1760 | + ); |
|
| 1761 | + return; |
|
| 1762 | + } |
|
| 1763 | + if (! $this->reg_code()) { |
|
| 1764 | + parent::set('REG_code', $REG_code, $use_default); |
|
| 1765 | + } else { |
|
| 1766 | + EE_Error::doing_it_wrong( |
|
| 1767 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 1768 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
| 1769 | + '4.6.0' |
|
| 1770 | + ); |
|
| 1771 | + } |
|
| 1772 | + } |
|
| 1773 | + |
|
| 1774 | + |
|
| 1775 | + /** |
|
| 1776 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
| 1777 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
| 1778 | + * $registration->transaction()->registrations(); |
|
| 1779 | + * |
|
| 1780 | + * @since 4.5.0 |
|
| 1781 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
| 1782 | + * @throws EE_Error |
|
| 1783 | + */ |
|
| 1784 | + public function get_all_other_registrations_in_group() |
|
| 1785 | + { |
|
| 1786 | + if ($this->group_size() < 2) { |
|
| 1787 | + return array(); |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + $query[0] = array( |
|
| 1791 | + 'TXN_ID' => $this->transaction_ID(), |
|
| 1792 | + 'REG_ID' => array('!=', $this->ID()), |
|
| 1793 | + 'TKT_ID' => $this->ticket_ID(), |
|
| 1794 | + ); |
|
| 1795 | + /** @var EE_Registration[] $registrations */ |
|
| 1796 | + $registrations = $this->get_model()->get_all($query); |
|
| 1797 | + return $registrations; |
|
| 1798 | + } |
|
| 1799 | + |
|
| 1800 | + /** |
|
| 1801 | + * Return the link to the admin details for the object. |
|
| 1802 | + * |
|
| 1803 | + * @return string |
|
| 1804 | + * @throws EE_Error |
|
| 1805 | + */ |
|
| 1806 | + public function get_admin_details_link() |
|
| 1807 | + { |
|
| 1808 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1809 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1810 | + array( |
|
| 1811 | + 'page' => 'espresso_registrations', |
|
| 1812 | + 'action' => 'view_registration', |
|
| 1813 | + '_REG_ID' => $this->ID(), |
|
| 1814 | + ), |
|
| 1815 | + admin_url('admin.php') |
|
| 1816 | + ); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + /** |
|
| 1820 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 1821 | + * |
|
| 1822 | + * @return string |
|
| 1823 | + * @throws EE_Error |
|
| 1824 | + */ |
|
| 1825 | + public function get_admin_edit_link() |
|
| 1826 | + { |
|
| 1827 | + return $this->get_admin_details_link(); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + /** |
|
| 1831 | + * Returns the link to a settings page for the object. |
|
| 1832 | + * |
|
| 1833 | + * @return string |
|
| 1834 | + * @throws EE_Error |
|
| 1835 | + */ |
|
| 1836 | + public function get_admin_settings_link() |
|
| 1837 | + { |
|
| 1838 | + return $this->get_admin_details_link(); |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + /** |
|
| 1842 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 1843 | + * |
|
| 1844 | + * @return string |
|
| 1845 | + */ |
|
| 1846 | + public function get_admin_overview_link() |
|
| 1847 | + { |
|
| 1848 | + EE_Registry::instance()->load_helper('URL'); |
|
| 1849 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1850 | + array( |
|
| 1851 | + 'page' => 'espresso_registrations', |
|
| 1852 | + ), |
|
| 1853 | + admin_url('admin.php') |
|
| 1854 | + ); |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * @param array $query_params |
|
| 1860 | + * |
|
| 1861 | + * @return \EE_Registration[] |
|
| 1862 | + * @throws EE_Error |
|
| 1863 | + */ |
|
| 1864 | + public function payments($query_params = array()) |
|
| 1865 | + { |
|
| 1866 | + return $this->get_many_related('Payment', $query_params); |
|
| 1867 | + } |
|
| 1868 | + |
|
| 1869 | + |
|
| 1870 | + /** |
|
| 1871 | + * @param array $query_params |
|
| 1872 | + * |
|
| 1873 | + * @return \EE_Registration_Payment[] |
|
| 1874 | + * @throws EE_Error |
|
| 1875 | + */ |
|
| 1876 | + public function registration_payments($query_params = array()) |
|
| 1877 | + { |
|
| 1878 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + |
|
| 1882 | + /** |
|
| 1883 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
| 1884 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
| 1885 | + * |
|
| 1886 | + * @return EE_Payment_Method|null |
|
| 1887 | + */ |
|
| 1888 | + public function payment_method() |
|
| 1889 | + { |
|
| 1890 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
| 1891 | + } |
|
| 1892 | + |
|
| 1893 | + |
|
| 1894 | + /** |
|
| 1895 | + * @return \EE_Line_Item |
|
| 1896 | + * @throws EntityNotFoundException |
|
| 1897 | + * @throws EE_Error |
|
| 1898 | + */ |
|
| 1899 | + public function ticket_line_item() |
|
| 1900 | + { |
|
| 1901 | + $ticket = $this->ticket(); |
|
| 1902 | + $transaction = $this->transaction(); |
|
| 1903 | + $line_item = null; |
|
| 1904 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 1905 | + $transaction->total_line_item(), |
|
| 1906 | + 'Ticket', |
|
| 1907 | + array($ticket->ID()) |
|
| 1908 | + ); |
|
| 1909 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 1910 | + if ($ticket_line_item instanceof \EE_Line_Item |
|
| 1911 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
| 1912 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
| 1913 | + ) { |
|
| 1914 | + $line_item = $ticket_line_item; |
|
| 1915 | + break; |
|
| 1916 | + } |
|
| 1917 | + } |
|
| 1918 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
| 1919 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
| 1920 | + } |
|
| 1921 | + return $line_item; |
|
| 1922 | + } |
|
| 1923 | + |
|
| 1924 | + |
|
| 1925 | + /** |
|
| 1926 | + * Soft Deletes this model object. |
|
| 1927 | + * |
|
| 1928 | + * @return boolean | int |
|
| 1929 | + * @throws RuntimeException |
|
| 1930 | + * @throws EE_Error |
|
| 1931 | + */ |
|
| 1932 | + public function delete() |
|
| 1933 | + { |
|
| 1934 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
| 1935 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
| 1936 | + } |
|
| 1937 | + return parent::delete(); |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + |
|
| 1941 | + /** |
|
| 1942 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
| 1943 | + * |
|
| 1944 | + * @throws EE_Error |
|
| 1945 | + * @throws RuntimeException |
|
| 1946 | + */ |
|
| 1947 | + public function restore() |
|
| 1948 | + { |
|
| 1949 | + $previous_status = $this->get_extra_meta( |
|
| 1950 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
| 1951 | + true, |
|
| 1952 | + EEM_Registration::status_id_cancelled |
|
| 1953 | + ); |
|
| 1954 | + if ($previous_status) { |
|
| 1955 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
| 1956 | + $this->set_status($previous_status); |
|
| 1957 | + } |
|
| 1958 | + return parent::restore(); |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
| 1964 | + * |
|
| 1965 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
| 1966 | + * depending on whether the reg status changes to or from "Approved" |
|
| 1967 | + * @return boolean whether the Registration status was updated |
|
| 1968 | + * @throws EE_Error |
|
| 1969 | + * @throws RuntimeException |
|
| 1970 | + */ |
|
| 1971 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
| 1972 | + { |
|
| 1973 | + $paid = $this->paid(); |
|
| 1974 | + $price = $this->final_price(); |
|
| 1975 | + switch (true) { |
|
| 1976 | + // overpaid or paid |
|
| 1977 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
| 1978 | + case EEH_Money::compare_floats($paid, $price): |
|
| 1979 | + $new_status = EEM_Registration::status_id_approved; |
|
| 1980 | + break; |
|
| 1981 | + // underpaid |
|
| 1982 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
| 1983 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
| 1984 | + break; |
|
| 1985 | + // uhhh Houston... |
|
| 1986 | + default: |
|
| 1987 | + throw new RuntimeException( |
|
| 1988 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
| 1989 | + ); |
|
| 1990 | + } |
|
| 1991 | + if ($new_status !== $this->status_ID()) { |
|
| 1992 | + if ($trigger_set_status_logic) { |
|
| 1993 | + return $this->set_status($new_status); |
|
| 1994 | + } |
|
| 1995 | + parent::set('STS_ID', $new_status); |
|
| 1996 | + return true; |
|
| 1997 | + } |
|
| 1998 | + return false; |
|
| 1999 | + } |
|
| 2000 | + |
|
| 2001 | + |
|
| 2002 | + /*************************** DEPRECATED ***************************/ |
|
| 2003 | + |
|
| 2004 | + |
|
| 2005 | + /** |
|
| 2006 | + * @deprecated |
|
| 2007 | + * @since 4.7.0 |
|
| 2008 | + * @access public |
|
| 2009 | + */ |
|
| 2010 | + public function price_paid() |
|
| 2011 | + { |
|
| 2012 | + EE_Error::doing_it_wrong( |
|
| 2013 | + 'EE_Registration::price_paid()', |
|
| 2014 | + esc_html__( |
|
| 2015 | + 'This method is deprecated, please use EE_Registration::final_price() instead.', |
|
| 2016 | + 'event_espresso' |
|
| 2017 | + ), |
|
| 2018 | + '4.7.0' |
|
| 2019 | + ); |
|
| 2020 | + return $this->final_price(); |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + |
|
| 2024 | + /** |
|
| 2025 | + * @deprecated |
|
| 2026 | + * @since 4.7.0 |
|
| 2027 | + * @access public |
|
| 2028 | + * @param float $REG_final_price |
|
| 2029 | + * @throws EE_Error |
|
| 2030 | + * @throws RuntimeException |
|
| 2031 | + */ |
|
| 2032 | + public function set_price_paid($REG_final_price = 0.00) |
|
| 2033 | + { |
|
| 2034 | + EE_Error::doing_it_wrong( |
|
| 2035 | + 'EE_Registration::set_price_paid()', |
|
| 2036 | + esc_html__( |
|
| 2037 | + 'This method is deprecated, please use EE_Registration::set_final_price() instead.', |
|
| 2038 | + 'event_espresso' |
|
| 2039 | + ), |
|
| 2040 | + '4.7.0' |
|
| 2041 | + ); |
|
| 2042 | + $this->set_final_price($REG_final_price); |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + |
|
| 2046 | + /** |
|
| 2047 | + * @deprecated |
|
| 2048 | + * @since 4.7.0 |
|
| 2049 | + * @return string |
|
| 2050 | + * @throws EE_Error |
|
| 2051 | + */ |
|
| 2052 | + public function pretty_price_paid() |
|
| 2053 | + { |
|
| 2054 | + EE_Error::doing_it_wrong( |
|
| 2055 | + 'EE_Registration::pretty_price_paid()', |
|
| 2056 | + esc_html__( |
|
| 2057 | + 'This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
| 2058 | + 'event_espresso' |
|
| 2059 | + ), |
|
| 2060 | + '4.7.0' |
|
| 2061 | + ); |
|
| 2062 | + return $this->pretty_final_price(); |
|
| 2063 | + } |
|
| 2064 | + |
|
| 2065 | + |
|
| 2066 | + /** |
|
| 2067 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
| 2068 | + * |
|
| 2069 | + * @deprecated 4.9.17 |
|
| 2070 | + * @return EE_Datetime |
|
| 2071 | + * @throws EE_Error |
|
| 2072 | + * @throws EntityNotFoundException |
|
| 2073 | + */ |
|
| 2074 | + public function get_related_primary_datetime() |
|
| 2075 | + { |
|
| 2076 | + EE_Error::doing_it_wrong( |
|
| 2077 | + __METHOD__, |
|
| 2078 | + esc_html__( |
|
| 2079 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
| 2080 | + 'event_espresso' |
|
| 2081 | + ), |
|
| 2082 | + '4.9.17', |
|
| 2083 | + '5.0.0' |
|
| 2084 | + ); |
|
| 2085 | + return $this->event()->primary_datetime(); |
|
| 2086 | + } |
|
| 2087 | 2087 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | |
| 147 | 147 | /** |
| 148 | - * @return null |
|
| 148 | + * @return EE_Line_Item_Display |
|
| 149 | 149 | */ |
| 150 | 150 | public function line_item_display() |
| 151 | 151 | { |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | /** |
| 157 | - * @param null $line_item_display |
|
| 157 | + * @param EE_Line_Item_Display $line_item_display |
|
| 158 | 158 | */ |
| 159 | 159 | public function set_line_item_display($line_item_display) |
| 160 | 160 | { |
@@ -882,7 +882,7 @@ discard block |
||
| 882 | 882 | * _apply_registration_payments_to_amount_owing |
| 883 | 883 | * |
| 884 | 884 | * @access protected |
| 885 | - * @param array $registrations |
|
| 885 | + * @param EE_Base_Class[] $registrations |
|
| 886 | 886 | * @throws EE_Error |
| 887 | 887 | */ |
| 888 | 888 | protected function _apply_registration_payments_to_amount_owing(array $registrations) |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | * get_billing_form_html_for_payment_method |
| 1189 | 1189 | * |
| 1190 | 1190 | * @access public |
| 1191 | - * @return string |
|
| 1191 | + * @return boolean |
|
| 1192 | 1192 | * @throws EE_Error |
| 1193 | 1193 | * @throws InvalidArgumentException |
| 1194 | 1194 | * @throws ReflectionException |
@@ -1255,7 +1255,7 @@ discard block |
||
| 1255 | 1255 | * |
| 1256 | 1256 | * @access private |
| 1257 | 1257 | * @param EE_Payment_Method $payment_method |
| 1258 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1258 | + * @return EE_Billing_Info_Form |
|
| 1259 | 1259 | * @throws EE_Error |
| 1260 | 1260 | * @throws InvalidArgumentException |
| 1261 | 1261 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -1364,7 +1364,7 @@ discard block |
||
| 1364 | 1364 | * switch_payment_method |
| 1365 | 1365 | * |
| 1366 | 1366 | * @access public |
| 1367 | - * @return string |
|
| 1367 | + * @return boolean |
|
| 1368 | 1368 | * @throws EE_Error |
| 1369 | 1369 | * @throws InvalidArgumentException |
| 1370 | 1370 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -1643,7 +1643,7 @@ discard block |
||
| 1643 | 1643 | /** |
| 1644 | 1644 | * process_reg_step |
| 1645 | 1645 | * |
| 1646 | - * @return bool |
|
| 1646 | + * @return null|boolean |
|
| 1647 | 1647 | * @throws EE_Error |
| 1648 | 1648 | * @throws InvalidArgumentException |
| 1649 | 1649 | * @throws ReflectionException |
@@ -1774,7 +1774,7 @@ discard block |
||
| 1774 | 1774 | * update_reg_step |
| 1775 | 1775 | * this is the final step after a user revisits the site to retry a payment |
| 1776 | 1776 | * |
| 1777 | - * @return bool |
|
| 1777 | + * @return null|boolean |
|
| 1778 | 1778 | * @throws EE_Error |
| 1779 | 1779 | * @throws InvalidArgumentException |
| 1780 | 1780 | * @throws ReflectionException |
@@ -2221,7 +2221,7 @@ discard block |
||
| 2221 | 2221 | * |
| 2222 | 2222 | * @access private |
| 2223 | 2223 | * @type EE_Payment_Method $payment_method |
| 2224 | - * @return mixed EE_Payment | boolean |
|
| 2224 | + * @return EE_Payment|null EE_Payment | boolean |
|
| 2225 | 2225 | * @throws EE_Error |
| 2226 | 2226 | * @throws InvalidArgumentException |
| 2227 | 2227 | * @throws ReflectionException |
@@ -2546,7 +2546,7 @@ discard block |
||
| 2546 | 2546 | * or present the payment options again |
| 2547 | 2547 | * |
| 2548 | 2548 | * @access private |
| 2549 | - * @return EE_Payment|FALSE |
|
| 2549 | + * @return boolean |
|
| 2550 | 2550 | * @throws EE_Error |
| 2551 | 2551 | * @throws InvalidArgumentException |
| 2552 | 2552 | * @throws ReflectionException |
@@ -2686,8 +2686,8 @@ discard block |
||
| 2686 | 2686 | * _redirect_wayward_request |
| 2687 | 2687 | * |
| 2688 | 2688 | * @access private |
| 2689 | - * @param \EE_Registration|null $primary_registrant |
|
| 2690 | - * @return bool |
|
| 2689 | + * @param EE_Registration $primary_registrant |
|
| 2690 | + * @return false|null |
|
| 2691 | 2691 | * @throws EE_Error |
| 2692 | 2692 | * @throws InvalidArgumentException |
| 2693 | 2693 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | { |
| 130 | 130 | $this->_slug = 'payment_options'; |
| 131 | 131 | $this->_name = esc_html__('Payment Options', 'event_espresso'); |
| 132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
| 132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php'; |
|
| 133 | 133 | $this->checkout = $checkout; |
| 134 | 134 | $this->_reset_success_message(); |
| 135 | 135 | $this->set_instructions( |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | $transaction = $this->checkout->transaction; |
| 214 | 214 | // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
| 215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 215 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | 216 | return; |
| 217 | 217 | } |
| 218 | 218 | foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
@@ -304,18 +304,18 @@ discard block |
||
| 304 | 304 | foreach ($registrations as $REG_ID => $registration) { |
| 305 | 305 | /** @var $registration EE_Registration */ |
| 306 | 306 | // has this registration lost it's space ? |
| 307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 307 | + if (isset($ejected_registrations[$REG_ID])) { |
|
| 308 | 308 | if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
| 309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 309 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
| 310 | 310 | } else { |
| 311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 311 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
| 312 | 312 | } |
| 313 | 313 | continue; |
| 314 | 314 | } |
| 315 | 315 | // event requires admin approval |
| 316 | 316 | if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
| 317 | 317 | // add event to list of events with pre-approval reg status |
| 318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 318 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
| 319 | 319 | do_action( |
| 320 | 320 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
| 321 | 321 | $registration->event(), |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | ) |
| 332 | 332 | ) { |
| 333 | 333 | // add event to list of events that are sold out |
| 334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 334 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
| 335 | 335 | do_action( |
| 336 | 336 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
| 337 | 337 | $registration->event(), |
@@ -341,38 +341,38 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | // are they allowed to pay now and is there monies owing? |
| 343 | 343 | if ($registration->owes_monies_and_can_pay()) { |
| 344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 344 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
| 345 | 345 | do_action( |
| 346 | 346 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
| 347 | 347 | $registration->event(), |
| 348 | 348 | $this |
| 349 | 349 | ); |
| 350 | - } elseif (! $this->checkout->revisit |
|
| 350 | + } elseif ( ! $this->checkout->revisit |
|
| 351 | 351 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
| 352 | 352 | && $registration->ticket()->is_free() |
| 353 | 353 | ) { |
| 354 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
| 354 | + $registrations_for_free_events[$registration->event()->ID()] = $registration; |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | $subsections = array(); |
| 358 | 358 | // now decide which template to load |
| 359 | - if (! empty($sold_out_events)) { |
|
| 359 | + if ( ! empty($sold_out_events)) { |
|
| 360 | 360 | $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
| 361 | 361 | } |
| 362 | - if (! empty($insufficient_spaces_available)) { |
|
| 362 | + if ( ! empty($insufficient_spaces_available)) { |
|
| 363 | 363 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
| 364 | 364 | $insufficient_spaces_available |
| 365 | 365 | ); |
| 366 | 366 | } |
| 367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
| 367 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
| 368 | 368 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
| 369 | 369 | $registrations_requiring_pre_approval |
| 370 | 370 | ); |
| 371 | 371 | } |
| 372 | - if (! empty($registrations_for_free_events)) { |
|
| 372 | + if ( ! empty($registrations_for_free_events)) { |
|
| 373 | 373 | $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
| 374 | 374 | } |
| 375 | - if (! empty($registrations_requiring_payment)) { |
|
| 375 | + if ( ! empty($registrations_requiring_payment)) { |
|
| 376 | 376 | if ($this->checkout->amount_owing > 0) { |
| 377 | 377 | // autoload Line_Item_Display classes |
| 378 | 378 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
@@ -437,13 +437,13 @@ discard block |
||
| 437 | 437 | */ |
| 438 | 438 | public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
| 439 | 439 | { |
| 440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 440 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | 441 | return $line_item_filter_collection; |
| 442 | 442 | } |
| 443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 443 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | 444 | return $line_item_filter_collection; |
| 445 | 445 | } |
| 446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 446 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | 447 | return $line_item_filter_collection; |
| 448 | 448 | } |
| 449 | 449 | $line_item_filter_collection->add( |
@@ -483,8 +483,8 @@ discard block |
||
| 483 | 483 | ); |
| 484 | 484 | foreach ($registrations as $REG_ID => $registration) { |
| 485 | 485 | // has this registration lost it's space ? |
| 486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | - unset($registrations[ $REG_ID ]); |
|
| 486 | + if (isset($ejected_registrations[$REG_ID])) { |
|
| 487 | + unset($registrations[$REG_ID]); |
|
| 488 | 488 | continue; |
| 489 | 489 | } |
| 490 | 490 | } |
@@ -534,24 +534,24 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | $EVT_ID = $registration->event_ID(); |
| 536 | 536 | $ticket = $registration->ticket(); |
| 537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 537 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
| 538 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
| 539 | 539 | } |
| 540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
| 540 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
| 541 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
| 542 | + $event_reg_count[$EVT_ID] = 0; |
|
| 543 | 543 | } |
| 544 | - $event_reg_count[ $EVT_ID ]++; |
|
| 545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 544 | + $event_reg_count[$EVT_ID]++; |
|
| 545 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
| 546 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | 547 | } |
| 548 | 548 | } |
| 549 | 549 | if ($revisit |
| 550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 550 | + && ($tickets_remaining[$ticket->ID()] === 0 |
|
| 551 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
| 552 | 552 | ) |
| 553 | 553 | ) { |
| 554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 554 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
| 555 | 555 | if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
| 556 | 556 | /** @type EE_Registration_Processor $registration_processor */ |
| 557 | 557 | $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | foreach ($sold_out_events_array as $sold_out_event) { |
| 612 | 612 | $sold_out_events .= EEH_HTML::li( |
| 613 | 613 | EEH_HTML::span( |
| 614 | - ' ' . $sold_out_event->name(), |
|
| 614 | + ' '.$sold_out_event->name(), |
|
| 615 | 615 | '', |
| 616 | 616 | 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
| 617 | 617 | ) |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | foreach ($insufficient_spaces_events_array as $event) { |
| 668 | 668 | if ($event instanceof EE_Event) { |
| 669 | 669 | $insufficient_space_events .= EEH_HTML::li( |
| 670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 670 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 671 | 671 | ); |
| 672 | 672 | } |
| 673 | 673 | } |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | $events_requiring_pre_approval = ''; |
| 717 | 717 | foreach ($registrations_requiring_pre_approval as $registration) { |
| 718 | 718 | if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
| 719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 719 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
| 720 | 720 | EEH_HTML::span( |
| 721 | 721 | '', |
| 722 | 722 | '', |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | { |
| 858 | 858 | return new EE_Form_Section_Proper( |
| 859 | 859 | array( |
| 860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 860 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
| 861 | 861 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
| 862 | 862 | 'subsections' => array( |
| 863 | 863 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | $payments += $registration->registration_payments(); |
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | - if (! empty($payments)) { |
|
| 900 | + if ( ! empty($payments)) { |
|
| 901 | 901 | foreach ($payments as $payment) { |
| 902 | 902 | if ($payment instanceof EE_Registration_Payment) { |
| 903 | 903 | $this->checkout->amount_owing -= $payment->amount(); |
@@ -1017,23 +1017,23 @@ discard block |
||
| 1017 | 1017 | $payment_method_button = EEH_HTML::img( |
| 1018 | 1018 | $payment_method->button_url(), |
| 1019 | 1019 | $payment_method->name(), |
| 1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1020 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
| 1021 | 1021 | 'spco-payment-method-btn-img' |
| 1022 | 1022 | ); |
| 1023 | 1023 | // check if any payment methods are set as default |
| 1024 | 1024 | // if payment method is already selected OR nothing is selected and this payment method should be |
| 1025 | 1025 | // open_by_default |
| 1026 | 1026 | if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
| 1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1027 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | 1028 | ) { |
| 1029 | 1029 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
| 1030 | 1030 | $this->_save_selected_method_of_payment(); |
| 1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1031 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
| 1032 | 1032 | } else { |
| 1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1033 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
| 1034 | 1034 | } |
| 1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1035 | + $payment_methods_billing_info[$payment_method->slug( |
|
| 1036 | + ).'-info'] = $this->_payment_method_billing_info( |
|
| 1037 | 1037 | $payment_method |
| 1038 | 1038 | ); |
| 1039 | 1039 | } |
@@ -1069,7 +1069,7 @@ discard block |
||
| 1069 | 1069 | */ |
| 1070 | 1070 | protected function _get_available_payment_methods() |
| 1071 | 1071 | { |
| 1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
| 1072 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | 1073 | return $this->checkout->available_payment_methods; |
| 1074 | 1074 | } |
| 1075 | 1075 | $available_payment_methods = array(); |
@@ -1084,7 +1084,7 @@ discard block |
||
| 1084 | 1084 | ); |
| 1085 | 1085 | foreach ($payment_methods as $payment_method) { |
| 1086 | 1086 | if ($payment_method instanceof EE_Payment_Method) { |
| 1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1087 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
| 1088 | 1088 | } |
| 1089 | 1089 | } |
| 1090 | 1090 | return $available_payment_methods; |
@@ -1179,7 +1179,7 @@ discard block |
||
| 1179 | 1179 | ); |
| 1180 | 1180 | return new EE_Form_Section_Proper( |
| 1181 | 1181 | array( |
| 1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1182 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
| 1183 | 1183 | 'html_class' => 'spco-payment-method-info-dv', |
| 1184 | 1184 | // only display the selected or default PM |
| 1185 | 1185 | 'html_style' => $currently_selected ? '' : 'display:none;', |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | // how have they chosen to pay? |
| 1210 | 1210 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
| 1211 | 1211 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
| 1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1212 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | 1213 | return false; |
| 1214 | 1214 | } |
| 1215 | 1215 | if (apply_filters( |
@@ -1381,7 +1381,7 @@ discard block |
||
| 1381 | 1381 | */ |
| 1382 | 1382 | public function switch_payment_method() |
| 1383 | 1383 | { |
| 1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1384 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
| 1385 | 1385 | return false; |
| 1386 | 1386 | } |
| 1387 | 1387 | if (apply_filters( |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | } |
| 1517 | 1517 | } |
| 1518 | 1518 | // verify payment method |
| 1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1519 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | 1520 | // get payment method for selected method of payment |
| 1521 | 1521 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
| 1522 | 1522 | } |
@@ -1541,7 +1541,7 @@ discard block |
||
| 1541 | 1541 | */ |
| 1542 | 1542 | public function save_payer_details_via_ajax() |
| 1543 | 1543 | { |
| 1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1544 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
| 1545 | 1545 | return; |
| 1546 | 1546 | } |
| 1547 | 1547 | // generate billing form for selected method of payment if it hasn't been done already |
@@ -1551,7 +1551,7 @@ discard block |
||
| 1551 | 1551 | ); |
| 1552 | 1552 | } |
| 1553 | 1553 | // generate primary attendee from payer info if applicable |
| 1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1554 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | 1555 | $attendee = $this->_create_attendee_from_request_data(); |
| 1556 | 1556 | if ($attendee instanceof EE_Attendee) { |
| 1557 | 1557 | foreach ($this->checkout->transaction->registrations() as $registration) { |
@@ -1582,7 +1582,7 @@ discard block |
||
| 1582 | 1582 | { |
| 1583 | 1583 | // get State ID |
| 1584 | 1584 | $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
| 1585 | - if (! empty($STA_ID)) { |
|
| 1585 | + if ( ! empty($STA_ID)) { |
|
| 1586 | 1586 | // can we get state object from name ? |
| 1587 | 1587 | EE_Registry::instance()->load_model('State'); |
| 1588 | 1588 | $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | } |
| 1591 | 1591 | // get Country ISO |
| 1592 | 1592 | $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
| 1593 | - if (! empty($CNT_ISO)) { |
|
| 1593 | + if ( ! empty($CNT_ISO)) { |
|
| 1594 | 1594 | // can we get country object from name ? |
| 1595 | 1595 | EE_Registry::instance()->load_model('Country'); |
| 1596 | 1596 | $country = EEM_Country::instance()->get_col( |
@@ -1623,7 +1623,7 @@ discard block |
||
| 1623 | 1623 | } |
| 1624 | 1624 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
| 1625 | 1625 | // AND email address |
| 1626 | - if (! empty($attendee_data['ATT_fname']) |
|
| 1626 | + if ( ! empty($attendee_data['ATT_fname']) |
|
| 1627 | 1627 | && ! empty($attendee_data['ATT_lname']) |
| 1628 | 1628 | && ! empty($attendee_data['ATT_email']) |
| 1629 | 1629 | ) { |
@@ -1838,7 +1838,7 @@ discard block |
||
| 1838 | 1838 | private function _process_payment() |
| 1839 | 1839 | { |
| 1840 | 1840 | // basically confirm that the event hasn't sold out since they hit the page |
| 1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
| 1841 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
| 1842 | 1842 | return false; |
| 1843 | 1843 | } |
| 1844 | 1844 | // ya gotta make a choice man |
@@ -1849,7 +1849,7 @@ discard block |
||
| 1849 | 1849 | return false; |
| 1850 | 1850 | } |
| 1851 | 1851 | // get EE_Payment_Method object |
| 1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1852 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | 1853 | return false; |
| 1854 | 1854 | } |
| 1855 | 1855 | // setup billing form |
@@ -1858,12 +1858,12 @@ discard block |
||
| 1858 | 1858 | $this->checkout->payment_method |
| 1859 | 1859 | ); |
| 1860 | 1860 | // bad billing form ? |
| 1861 | - if (! $this->_billing_form_is_valid()) { |
|
| 1861 | + if ( ! $this->_billing_form_is_valid()) { |
|
| 1862 | 1862 | return false; |
| 1863 | 1863 | } |
| 1864 | 1864 | } |
| 1865 | 1865 | // ensure primary registrant has been fully processed |
| 1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1866 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | 1867 | return false; |
| 1868 | 1868 | } |
| 1869 | 1869 | // if session is close to expiring (under 10 minutes by default) |
@@ -1918,7 +1918,7 @@ discard block |
||
| 1918 | 1918 | protected function _last_second_ticket_verifications() |
| 1919 | 1919 | { |
| 1920 | 1920 | // don't bother re-validating if not a return visit |
| 1921 | - if (! $this->checkout->revisit) { |
|
| 1921 | + if ( ! $this->checkout->revisit) { |
|
| 1922 | 1922 | return true; |
| 1923 | 1923 | } |
| 1924 | 1924 | $registrations = $this->checkout->transaction->registrations(); |
@@ -1984,7 +1984,7 @@ discard block |
||
| 1984 | 1984 | */ |
| 1985 | 1985 | private function _billing_form_is_valid() |
| 1986 | 1986 | { |
| 1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1987 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | 1988 | return true; |
| 1989 | 1989 | } |
| 1990 | 1990 | if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
@@ -2103,7 +2103,7 @@ discard block |
||
| 2103 | 2103 | { |
| 2104 | 2104 | // convert billing form data into an attendee |
| 2105 | 2105 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
| 2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2106 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | 2107 | EE_Error::add_error( |
| 2108 | 2108 | sprintf( |
| 2109 | 2109 | esc_html__( |
@@ -2120,7 +2120,7 @@ discard block |
||
| 2120 | 2120 | return false; |
| 2121 | 2121 | } |
| 2122 | 2122 | $primary_registration = $this->checkout->transaction->primary_registration(); |
| 2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
| 2123 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
| 2124 | 2124 | EE_Error::add_error( |
| 2125 | 2125 | sprintf( |
| 2126 | 2126 | esc_html__( |
@@ -2136,7 +2136,7 @@ discard block |
||
| 2136 | 2136 | ); |
| 2137 | 2137 | return false; |
| 2138 | 2138 | } |
| 2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2139 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | 2140 | instanceof |
| 2141 | 2141 | EE_Attendee |
| 2142 | 2142 | ) { |
@@ -2182,8 +2182,8 @@ discard block |
||
| 2182 | 2182 | return null; |
| 2183 | 2183 | } |
| 2184 | 2184 | // get EE_Payment_Method object |
| 2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2185 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
| 2186 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
| 2187 | 2187 | } else { |
| 2188 | 2188 | // load EEM_Payment_Method |
| 2189 | 2189 | EE_Registry::instance()->load_model('Payment_Method'); |
@@ -2192,7 +2192,7 @@ discard block |
||
| 2192 | 2192 | $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
| 2193 | 2193 | } |
| 2194 | 2194 | // verify $payment_method |
| 2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2195 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | 2196 | // not a payment |
| 2197 | 2197 | EE_Error::add_error( |
| 2198 | 2198 | sprintf( |
@@ -2210,7 +2210,7 @@ discard block |
||
| 2210 | 2210 | return null; |
| 2211 | 2211 | } |
| 2212 | 2212 | // and verify it has a valid Payment_Method Type object |
| 2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2213 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | 2214 | // not a payment |
| 2215 | 2215 | EE_Error::add_error( |
| 2216 | 2216 | sprintf( |
@@ -2248,7 +2248,7 @@ discard block |
||
| 2248 | 2248 | $payment = null; |
| 2249 | 2249 | $this->checkout->transaction->save(); |
| 2250 | 2250 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2251 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | 2252 | return false; |
| 2253 | 2253 | } |
| 2254 | 2254 | try { |
@@ -2352,7 +2352,7 @@ discard block |
||
| 2352 | 2352 | return true; |
| 2353 | 2353 | } |
| 2354 | 2354 | // verify payment object |
| 2355 | - if (! $payment instanceof EE_Payment) { |
|
| 2355 | + if ( ! $payment instanceof EE_Payment) { |
|
| 2356 | 2356 | // not a payment |
| 2357 | 2357 | EE_Error::add_error( |
| 2358 | 2358 | sprintf( |
@@ -2392,7 +2392,7 @@ discard block |
||
| 2392 | 2392 | return true; |
| 2393 | 2393 | // On-Site payment? |
| 2394 | 2394 | } elseif ($this->checkout->payment_method->is_on_site()) { |
| 2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2395 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | 2396 | // $this->_setup_redirect_for_next_step(); |
| 2397 | 2397 | $this->checkout->continue_reg = false; |
| 2398 | 2398 | } |
@@ -2508,7 +2508,7 @@ discard block |
||
| 2508 | 2508 | break; |
| 2509 | 2509 | // bad payment |
| 2510 | 2510 | case EEM_Payment::status_id_failed: |
| 2511 | - if (! empty($msg)) { |
|
| 2511 | + if ( ! empty($msg)) { |
|
| 2512 | 2512 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
| 2513 | 2513 | return false; |
| 2514 | 2514 | } |
@@ -2569,11 +2569,11 @@ discard block |
||
| 2569 | 2569 | // how have they chosen to pay? |
| 2570 | 2570 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
| 2571 | 2571 | // get EE_Payment_Method object |
| 2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2572 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | 2573 | $this->checkout->continue_reg = false; |
| 2574 | 2574 | return false; |
| 2575 | 2575 | } |
| 2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2576 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | 2577 | return false; |
| 2578 | 2578 | } |
| 2579 | 2579 | $this->_validate_offsite_return(); |
@@ -2591,7 +2591,7 @@ discard block |
||
| 2591 | 2591 | // verify TXN |
| 2592 | 2592 | if ($this->checkout->transaction instanceof EE_Transaction) { |
| 2593 | 2593 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
| 2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2594 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | 2595 | $this->checkout->continue_reg = false; |
| 2596 | 2596 | return false; |
| 2597 | 2597 | } |
@@ -2708,13 +2708,13 @@ discard block |
||
| 2708 | 2708 | */ |
| 2709 | 2709 | private function _redirect_wayward_request(EE_Registration $primary_registrant) |
| 2710 | 2710 | { |
| 2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2711 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | 2712 | // try redirecting based on the current TXN |
| 2713 | 2713 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
| 2714 | 2714 | ? $this->checkout->transaction->primary_registration() |
| 2715 | 2715 | : null; |
| 2716 | 2716 | } |
| 2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2717 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | 2718 | EE_Error::add_error( |
| 2719 | 2719 | sprintf( |
| 2720 | 2720 | esc_html__( |
@@ -2784,7 +2784,7 @@ discard block |
||
| 2784 | 2784 | $payment = $this->checkout->transaction->last_payment(); |
| 2785 | 2785 | // $payment_source = 'last_payment after Exception'; |
| 2786 | 2786 | // but if we STILL don't have a payment object |
| 2787 | - if (! $payment instanceof EE_Payment) { |
|
| 2787 | + if ( ! $payment instanceof EE_Payment) { |
|
| 2788 | 2788 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
| 2789 | 2789 | $this->_handle_payment_processor_exception($e); |
| 2790 | 2790 | } |
@@ -12,2889 +12,2889 @@ |
||
| 12 | 12 | class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @access protected |
|
| 17 | - * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | - */ |
|
| 19 | - protected $line_item_display; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @access protected |
|
| 23 | - * @var boolean $handle_IPN_in_this_request |
|
| 24 | - */ |
|
| 25 | - protected $handle_IPN_in_this_request = false; |
|
| 26 | - |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | - * |
|
| 31 | - * @access public |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_filter( |
|
| 37 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | - array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | - ); |
|
| 40 | - add_action( |
|
| 41 | - 'wp_ajax_switch_spco_billing_form', |
|
| 42 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | - ); |
|
| 44 | - add_action( |
|
| 45 | - 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | - array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | - ); |
|
| 48 | - add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | - add_action( |
|
| 50 | - 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | - array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | - ); |
|
| 53 | - add_action( |
|
| 54 | - 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | - ); |
|
| 57 | - add_action( |
|
| 58 | - 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | - array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | - ); |
|
| 61 | - add_filter( |
|
| 62 | - 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | - array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | - 10, |
|
| 65 | - 1 |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * ajax switch_spco_billing_form |
|
| 72 | - * |
|
| 73 | - * @throws \EE_Error |
|
| 74 | - */ |
|
| 75 | - public static function switch_spco_billing_form() |
|
| 76 | - { |
|
| 77 | - EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * ajax save_payer_details |
|
| 83 | - * |
|
| 84 | - * @throws \EE_Error |
|
| 85 | - */ |
|
| 86 | - public static function save_payer_details() |
|
| 87 | - { |
|
| 88 | - EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * ajax get_transaction_details |
|
| 94 | - * |
|
| 95 | - * @throws \EE_Error |
|
| 96 | - */ |
|
| 97 | - public static function get_transaction_details() |
|
| 98 | - { |
|
| 99 | - EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * bypass_recaptcha_for_load_payment_method |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @return array |
|
| 108 | - * @throws InvalidArgumentException |
|
| 109 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | - */ |
|
| 112 | - public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | - { |
|
| 114 | - return array( |
|
| 115 | - 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | - 'step' => 'payment_options', |
|
| 117 | - 'action' => 'spco_billing_form', |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * class constructor |
|
| 124 | - * |
|
| 125 | - * @access public |
|
| 126 | - * @param EE_Checkout $checkout |
|
| 127 | - */ |
|
| 128 | - public function __construct(EE_Checkout $checkout) |
|
| 129 | - { |
|
| 130 | - $this->_slug = 'payment_options'; |
|
| 131 | - $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
| 133 | - $this->checkout = $checkout; |
|
| 134 | - $this->_reset_success_message(); |
|
| 135 | - $this->set_instructions( |
|
| 136 | - esc_html__( |
|
| 137 | - 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | - 'event_espresso' |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @return null |
|
| 146 | - */ |
|
| 147 | - public function line_item_display() |
|
| 148 | - { |
|
| 149 | - return $this->line_item_display; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param null $line_item_display |
|
| 155 | - */ |
|
| 156 | - public function set_line_item_display($line_item_display) |
|
| 157 | - { |
|
| 158 | - $this->line_item_display = $line_item_display; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return boolean |
|
| 164 | - */ |
|
| 165 | - public function handle_IPN_in_this_request() |
|
| 166 | - { |
|
| 167 | - return $this->handle_IPN_in_this_request; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param boolean $handle_IPN_in_this_request |
|
| 173 | - */ |
|
| 174 | - public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | - { |
|
| 176 | - $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * translate_js_strings |
|
| 182 | - * |
|
| 183 | - * @return void |
|
| 184 | - */ |
|
| 185 | - public function translate_js_strings() |
|
| 186 | - { |
|
| 187 | - EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | - 'Please select a method of payment in order to continue.', |
|
| 189 | - 'event_espresso' |
|
| 190 | - ); |
|
| 191 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | - 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | - 'event_espresso' |
|
| 194 | - ); |
|
| 195 | - EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | - 'Forwarding to Secure Payment Provider.', |
|
| 197 | - 'event_espresso' |
|
| 198 | - ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * enqueue_styles_and_scripts |
|
| 204 | - * |
|
| 205 | - * @return void |
|
| 206 | - * @throws EE_Error |
|
| 207 | - * @throws InvalidArgumentException |
|
| 208 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | - */ |
|
| 211 | - public function enqueue_styles_and_scripts() |
|
| 212 | - { |
|
| 213 | - $transaction = $this->checkout->transaction; |
|
| 214 | - // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | - if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | - return; |
|
| 217 | - } |
|
| 218 | - foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | - $transaction, |
|
| 220 | - EEM_Payment_Method::scope_cart |
|
| 221 | - ) as $payment_method) { |
|
| 222 | - $type_obj = $payment_method->type_obj(); |
|
| 223 | - if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | - $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | - $billing_form->enqueue_js(); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * initialize_reg_step |
|
| 235 | - * |
|
| 236 | - * @return bool |
|
| 237 | - * @throws EE_Error |
|
| 238 | - * @throws InvalidArgumentException |
|
| 239 | - * @throws ReflectionException |
|
| 240 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | - */ |
|
| 243 | - public function initialize_reg_step() |
|
| 244 | - { |
|
| 245 | - // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | - if (// don't need payment options for: |
|
| 247 | - // registrations made via the admin |
|
| 248 | - // completed transactions |
|
| 249 | - // overpaid transactions |
|
| 250 | - // $ 0.00 transactions(no payment required) |
|
| 251 | - ! $this->checkout->payment_required() |
|
| 252 | - // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | - && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | - && ! $this->completed() |
|
| 255 | - ) { |
|
| 256 | - // and if so, then we no longer need the Payment Options step |
|
| 257 | - if ($this->is_current_step()) { |
|
| 258 | - $this->checkout->generate_reg_form = false; |
|
| 259 | - } |
|
| 260 | - $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | - // DEBUG LOG |
|
| 262 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - // load EEM_Payment_Method |
|
| 266 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | - // get all active payment methods |
|
| 268 | - $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | - $this->checkout->transaction, |
|
| 270 | - EEM_Payment_Method::scope_cart |
|
| 271 | - ); |
|
| 272 | - return true; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @return EE_Form_Section_Proper |
|
| 278 | - * @throws EE_Error |
|
| 279 | - * @throws InvalidArgumentException |
|
| 280 | - * @throws ReflectionException |
|
| 281 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | - */ |
|
| 286 | - public function generate_reg_form() |
|
| 287 | - { |
|
| 288 | - // reset in case someone changes their mind |
|
| 289 | - $this->_reset_selected_method_of_payment(); |
|
| 290 | - // set some defaults |
|
| 291 | - $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | - $registrations_requiring_payment = array(); |
|
| 293 | - $registrations_for_free_events = array(); |
|
| 294 | - $registrations_requiring_pre_approval = array(); |
|
| 295 | - $sold_out_events = array(); |
|
| 296 | - $insufficient_spaces_available = array(); |
|
| 297 | - $no_payment_required = true; |
|
| 298 | - // loop thru registrations to gather info |
|
| 299 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | - $registrations, |
|
| 302 | - $this->checkout->revisit |
|
| 303 | - ); |
|
| 304 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | - /** @var $registration EE_Registration */ |
|
| 306 | - // has this registration lost it's space ? |
|
| 307 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | - if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | - } else { |
|
| 311 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | - } |
|
| 313 | - continue; |
|
| 314 | - } |
|
| 315 | - // event requires admin approval |
|
| 316 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | - // add event to list of events with pre-approval reg status |
|
| 318 | - $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | - do_action( |
|
| 320 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | - $registration->event(), |
|
| 322 | - $this |
|
| 323 | - ); |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - if ($this->checkout->revisit |
|
| 327 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | - && ( |
|
| 329 | - $registration->event()->is_sold_out() |
|
| 330 | - || $registration->event()->is_sold_out(true) |
|
| 331 | - ) |
|
| 332 | - ) { |
|
| 333 | - // add event to list of events that are sold out |
|
| 334 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | - do_action( |
|
| 336 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | - $registration->event(), |
|
| 338 | - $this |
|
| 339 | - ); |
|
| 340 | - continue; |
|
| 341 | - } |
|
| 342 | - // are they allowed to pay now and is there monies owing? |
|
| 343 | - if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | - do_action( |
|
| 346 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | - $registration->event(), |
|
| 348 | - $this |
|
| 349 | - ); |
|
| 350 | - } elseif (! $this->checkout->revisit |
|
| 351 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | - && $registration->ticket()->is_free() |
|
| 353 | - ) { |
|
| 354 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $subsections = array(); |
|
| 358 | - // now decide which template to load |
|
| 359 | - if (! empty($sold_out_events)) { |
|
| 360 | - $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | - } |
|
| 362 | - if (! empty($insufficient_spaces_available)) { |
|
| 363 | - $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | - $insufficient_spaces_available |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | - $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | - $registrations_requiring_pre_approval |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - if (! empty($registrations_for_free_events)) { |
|
| 373 | - $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | - } |
|
| 375 | - if (! empty($registrations_requiring_payment)) { |
|
| 376 | - if ($this->checkout->amount_owing > 0) { |
|
| 377 | - // autoload Line_Item_Display classes |
|
| 378 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | - apply_filters( |
|
| 381 | - 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | - new EE_Line_Item_Filter_Collection() |
|
| 383 | - ), |
|
| 384 | - $this->checkout->cart->get_grand_total() |
|
| 385 | - ); |
|
| 386 | - /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | - $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | - $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | - $this->line_item_display->display_line_item( |
|
| 392 | - $filtered_line_item_tree, |
|
| 393 | - array('registrations' => $registrations) |
|
| 394 | - ) |
|
| 395 | - ); |
|
| 396 | - $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | - $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | - } |
|
| 399 | - $no_payment_required = false; |
|
| 400 | - } else { |
|
| 401 | - $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | - } |
|
| 403 | - $this->_save_selected_method_of_payment(); |
|
| 404 | - |
|
| 405 | - $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | - $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | - |
|
| 408 | - return new EE_Form_Section_Proper( |
|
| 409 | - array( |
|
| 410 | - 'name' => $this->reg_form_name(), |
|
| 411 | - 'html_id' => $this->reg_form_name(), |
|
| 412 | - 'subsections' => $subsections, |
|
| 413 | - 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | - ) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * add line item filters required for this reg step |
|
| 421 | - * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | - * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | - * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | - * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | - * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | - * filter collection by passing that instead of instantiating a new collection |
|
| 427 | - * |
|
| 428 | - * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | - * @return EE_Line_Item_Filter_Collection |
|
| 430 | - * @throws EE_Error |
|
| 431 | - * @throws InvalidArgumentException |
|
| 432 | - * @throws ReflectionException |
|
| 433 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | - */ |
|
| 438 | - public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | - { |
|
| 440 | - if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | - return $line_item_filter_collection; |
|
| 442 | - } |
|
| 443 | - if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | - return $line_item_filter_collection; |
|
| 445 | - } |
|
| 446 | - if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | - return $line_item_filter_collection; |
|
| 448 | - } |
|
| 449 | - $line_item_filter_collection->add( |
|
| 450 | - new EE_Billable_Line_Item_Filter( |
|
| 451 | - EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | - EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | - ) |
|
| 455 | - ) |
|
| 456 | - ) |
|
| 457 | - ); |
|
| 458 | - $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | - return $line_item_filter_collection; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * remove_ejected_registrations |
|
| 465 | - * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | - * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | - * |
|
| 468 | - * @param \EE_Registration[] $registrations |
|
| 469 | - * @return EE_Registration[] |
|
| 470 | - * @throws EE_Error |
|
| 471 | - * @throws InvalidArgumentException |
|
| 472 | - * @throws ReflectionException |
|
| 473 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | - */ |
|
| 478 | - public static function remove_ejected_registrations(array $registrations) |
|
| 479 | - { |
|
| 480 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | - $registrations, |
|
| 482 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | - ); |
|
| 484 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | - // has this registration lost it's space ? |
|
| 486 | - if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | - unset($registrations[ $REG_ID ]); |
|
| 488 | - continue; |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - return $registrations; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * find_registrations_that_lost_their_space |
|
| 497 | - * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | - * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | - * (unless the event's default reg status is set to APPROVED) |
|
| 500 | - * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | - * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | - * |
|
| 503 | - * @param \EE_Registration[] $registrations |
|
| 504 | - * @param bool $revisit |
|
| 505 | - * @return array |
|
| 506 | - * @throws EE_Error |
|
| 507 | - * @throws InvalidArgumentException |
|
| 508 | - * @throws ReflectionException |
|
| 509 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | - */ |
|
| 514 | - public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | - { |
|
| 516 | - // registrations per event |
|
| 517 | - $event_reg_count = array(); |
|
| 518 | - // spaces left per event |
|
| 519 | - $event_spaces_remaining = array(); |
|
| 520 | - // tickets left sorted by ID |
|
| 521 | - $tickets_remaining = array(); |
|
| 522 | - // registrations that have lost their space |
|
| 523 | - $ejected_registrations = array(); |
|
| 524 | - foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | - if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | - || apply_filters( |
|
| 527 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | - false, |
|
| 529 | - $registration, |
|
| 530 | - $revisit |
|
| 531 | - ) |
|
| 532 | - ) { |
|
| 533 | - continue; |
|
| 534 | - } |
|
| 535 | - $EVT_ID = $registration->event_ID(); |
|
| 536 | - $ticket = $registration->ticket(); |
|
| 537 | - if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | - $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | - } |
|
| 540 | - if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | - if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | - $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | - } |
|
| 544 | - $event_reg_count[ $EVT_ID ]++; |
|
| 545 | - if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | - $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - if ($revisit |
|
| 550 | - && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | - ) |
|
| 553 | - ) { |
|
| 554 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | - if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | - // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | - // NOT incomplete |
|
| 560 | - $registration_processor->manually_update_registration_status( |
|
| 561 | - $registration, |
|
| 562 | - EEM_Registration::status_id_wait_list |
|
| 563 | - ); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - return $ejected_registrations; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * _hide_reg_step_submit_button |
|
| 573 | - * removes the html for the reg step submit button |
|
| 574 | - * by replacing it with an empty string via filter callback |
|
| 575 | - * |
|
| 576 | - * @return void |
|
| 577 | - */ |
|
| 578 | - protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | - { |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * _hide_reg_step_submit_button |
|
| 585 | - * removes the html for the reg step submit button |
|
| 586 | - * by replacing it with an empty string via filter callback |
|
| 587 | - * |
|
| 588 | - * @return void |
|
| 589 | - */ |
|
| 590 | - protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | - { |
|
| 592 | - if ($this->checkout->revisit) { |
|
| 593 | - add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * sold_out_events |
|
| 600 | - * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | - * |
|
| 602 | - * @param \EE_Event[] $sold_out_events_array |
|
| 603 | - * @return \EE_Form_Section_Proper |
|
| 604 | - * @throws \EE_Error |
|
| 605 | - */ |
|
| 606 | - private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | - { |
|
| 608 | - // set some defaults |
|
| 609 | - $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | - $sold_out_events = ''; |
|
| 611 | - foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | - $sold_out_events .= EEH_HTML::li( |
|
| 613 | - EEH_HTML::span( |
|
| 614 | - ' ' . $sold_out_event->name(), |
|
| 615 | - '', |
|
| 616 | - 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | - ) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - return new EE_Form_Section_Proper( |
|
| 621 | - array( |
|
| 622 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | - array( |
|
| 624 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | - . $this->_slug |
|
| 626 | - . DS |
|
| 627 | - . 'sold_out_events.template.php', |
|
| 628 | - 'template_args' => apply_filters( |
|
| 629 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 630 | - array( |
|
| 631 | - 'sold_out_events' => $sold_out_events, |
|
| 632 | - 'sold_out_events_msg' => apply_filters( |
|
| 633 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 634 | - sprintf( |
|
| 635 | - esc_html__( |
|
| 636 | - 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$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.%2$s', |
|
| 637 | - 'event_espresso' |
|
| 638 | - ), |
|
| 639 | - '<strong>', |
|
| 640 | - '</strong>', |
|
| 641 | - '<br />' |
|
| 642 | - ) |
|
| 643 | - ), |
|
| 644 | - ) |
|
| 645 | - ), |
|
| 646 | - ) |
|
| 647 | - ), |
|
| 648 | - ) |
|
| 649 | - ); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * _insufficient_spaces_available |
|
| 655 | - * displays notices regarding events that do not have enough remaining spaces |
|
| 656 | - * to satisfy the current number of registrations looking to pay |
|
| 657 | - * |
|
| 658 | - * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 659 | - * @return \EE_Form_Section_Proper |
|
| 660 | - * @throws \EE_Error |
|
| 661 | - */ |
|
| 662 | - private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 663 | - { |
|
| 664 | - // set some defaults |
|
| 665 | - $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 666 | - $insufficient_space_events = ''; |
|
| 667 | - foreach ($insufficient_spaces_events_array as $event) { |
|
| 668 | - if ($event instanceof EE_Event) { |
|
| 669 | - $insufficient_space_events .= EEH_HTML::li( |
|
| 670 | - EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 671 | - ); |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - return new EE_Form_Section_Proper( |
|
| 675 | - array( |
|
| 676 | - 'subsections' => array( |
|
| 677 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 678 | - 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 679 | - ), |
|
| 680 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 681 | - array( |
|
| 682 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 683 | - . $this->_slug |
|
| 684 | - . DS |
|
| 685 | - . 'sold_out_events.template.php', |
|
| 686 | - 'template_args' => apply_filters( |
|
| 687 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 688 | - array( |
|
| 689 | - 'sold_out_events' => $insufficient_space_events, |
|
| 690 | - 'sold_out_events_msg' => apply_filters( |
|
| 691 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 692 | - esc_html__( |
|
| 693 | - 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 694 | - 'event_espresso' |
|
| 695 | - ) |
|
| 696 | - ), |
|
| 697 | - ) |
|
| 698 | - ), |
|
| 699 | - ) |
|
| 700 | - ), |
|
| 701 | - ) |
|
| 702 | - ); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - /** |
|
| 707 | - * registrations_requiring_pre_approval |
|
| 708 | - * |
|
| 709 | - * @param array $registrations_requiring_pre_approval |
|
| 710 | - * @return EE_Form_Section_Proper |
|
| 711 | - * @throws EE_Error |
|
| 712 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 713 | - */ |
|
| 714 | - private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 715 | - { |
|
| 716 | - $events_requiring_pre_approval = ''; |
|
| 717 | - foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 718 | - if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 719 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 720 | - EEH_HTML::span( |
|
| 721 | - '', |
|
| 722 | - '', |
|
| 723 | - 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 724 | - ) |
|
| 725 | - . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 726 | - ); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - return new EE_Form_Section_Proper( |
|
| 730 | - array( |
|
| 731 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 732 | - array( |
|
| 733 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 734 | - . $this->_slug |
|
| 735 | - . DS |
|
| 736 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
| 737 | - 'template_args' => apply_filters( |
|
| 738 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 739 | - array( |
|
| 740 | - 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 741 | - 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 742 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 743 | - esc_html__( |
|
| 744 | - 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 745 | - 'event_espresso' |
|
| 746 | - ) |
|
| 747 | - ), |
|
| 748 | - ) |
|
| 749 | - ), |
|
| 750 | - ) |
|
| 751 | - ), |
|
| 752 | - ) |
|
| 753 | - ); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - /** |
|
| 758 | - * _no_payment_required |
|
| 759 | - * |
|
| 760 | - * @param \EE_Event[] $registrations_for_free_events |
|
| 761 | - * @return \EE_Form_Section_Proper |
|
| 762 | - * @throws \EE_Error |
|
| 763 | - */ |
|
| 764 | - private function _no_payment_required($registrations_for_free_events = array()) |
|
| 765 | - { |
|
| 766 | - // set some defaults |
|
| 767 | - $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 768 | - // generate no_payment_required form |
|
| 769 | - return new EE_Form_Section_Proper( |
|
| 770 | - array( |
|
| 771 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 772 | - array( |
|
| 773 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 774 | - . $this->_slug |
|
| 775 | - . DS |
|
| 776 | - . 'no_payment_required.template.php', // layout_template |
|
| 777 | - 'template_args' => apply_filters( |
|
| 778 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 779 | - array( |
|
| 780 | - 'revisit' => $this->checkout->revisit, |
|
| 781 | - 'registrations' => array(), |
|
| 782 | - 'ticket_count' => array(), |
|
| 783 | - 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 784 | - 'no_payment_required_msg' => EEH_HTML::p( |
|
| 785 | - esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 786 | - ), |
|
| 787 | - ) |
|
| 788 | - ), |
|
| 789 | - ) |
|
| 790 | - ), |
|
| 791 | - ) |
|
| 792 | - ); |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * _display_payment_options |
|
| 798 | - * |
|
| 799 | - * @param string $transaction_details |
|
| 800 | - * @return EE_Form_Section_Proper |
|
| 801 | - * @throws EE_Error |
|
| 802 | - * @throws InvalidArgumentException |
|
| 803 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 804 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 805 | - */ |
|
| 806 | - private function _display_payment_options($transaction_details = '') |
|
| 807 | - { |
|
| 808 | - // has method_of_payment been set by no-js user? |
|
| 809 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 810 | - // build payment options form |
|
| 811 | - return apply_filters( |
|
| 812 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 813 | - new EE_Form_Section_Proper( |
|
| 814 | - array( |
|
| 815 | - 'subsections' => array( |
|
| 816 | - 'before_payment_options' => apply_filters( |
|
| 817 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 818 | - new EE_Form_Section_Proper( |
|
| 819 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 820 | - ) |
|
| 821 | - ), |
|
| 822 | - 'payment_options' => $this->_setup_payment_options(), |
|
| 823 | - 'after_payment_options' => apply_filters( |
|
| 824 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 825 | - new EE_Form_Section_Proper( |
|
| 826 | - array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 827 | - ) |
|
| 828 | - ), |
|
| 829 | - ), |
|
| 830 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 831 | - array( |
|
| 832 | - 'layout_template_file' => $this->_template, |
|
| 833 | - 'template_args' => apply_filters( |
|
| 834 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 835 | - array( |
|
| 836 | - 'reg_count' => $this->line_item_display->total_items(), |
|
| 837 | - 'transaction_details' => $transaction_details, |
|
| 838 | - 'available_payment_methods' => array(), |
|
| 839 | - ) |
|
| 840 | - ), |
|
| 841 | - ) |
|
| 842 | - ), |
|
| 843 | - ) |
|
| 844 | - ) |
|
| 845 | - ); |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * _extra_hidden_inputs |
|
| 851 | - * |
|
| 852 | - * @param bool $no_payment_required |
|
| 853 | - * @return \EE_Form_Section_Proper |
|
| 854 | - * @throws \EE_Error |
|
| 855 | - */ |
|
| 856 | - private function _extra_hidden_inputs($no_payment_required = true) |
|
| 857 | - { |
|
| 858 | - return new EE_Form_Section_Proper( |
|
| 859 | - array( |
|
| 860 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 861 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 862 | - 'subsections' => array( |
|
| 863 | - 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 864 | - array( |
|
| 865 | - 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 866 | - 'html_name' => 'spco_no_payment_required', |
|
| 867 | - 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 868 | - 'default' => $no_payment_required, |
|
| 869 | - ) |
|
| 870 | - ), |
|
| 871 | - 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 872 | - array( |
|
| 873 | - 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 874 | - 'html_name' => 'spco_transaction_id', |
|
| 875 | - 'html_id' => 'spco-transaction-id', |
|
| 876 | - 'default' => $this->checkout->transaction->ID(), |
|
| 877 | - ) |
|
| 878 | - ), |
|
| 879 | - ), |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * _apply_registration_payments_to_amount_owing |
|
| 887 | - * |
|
| 888 | - * @access protected |
|
| 889 | - * @param array $registrations |
|
| 890 | - * @throws EE_Error |
|
| 891 | - */ |
|
| 892 | - protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 893 | - { |
|
| 894 | - $payments = array(); |
|
| 895 | - foreach ($registrations as $registration) { |
|
| 896 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 897 | - $payments += $registration->registration_payments(); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - if (! empty($payments)) { |
|
| 901 | - foreach ($payments as $payment) { |
|
| 902 | - if ($payment instanceof EE_Registration_Payment) { |
|
| 903 | - $this->checkout->amount_owing -= $payment->amount(); |
|
| 904 | - } |
|
| 905 | - } |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * _reset_selected_method_of_payment |
|
| 912 | - * |
|
| 913 | - * @access private |
|
| 914 | - * @param bool $force_reset |
|
| 915 | - * @return void |
|
| 916 | - * @throws InvalidArgumentException |
|
| 917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | - */ |
|
| 920 | - private function _reset_selected_method_of_payment($force_reset = false) |
|
| 921 | - { |
|
| 922 | - $reset_payment_method = $force_reset |
|
| 923 | - ? true |
|
| 924 | - : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 925 | - if ($reset_payment_method) { |
|
| 926 | - $this->checkout->selected_method_of_payment = null; |
|
| 927 | - $this->checkout->payment_method = null; |
|
| 928 | - $this->checkout->billing_form = null; |
|
| 929 | - $this->_save_selected_method_of_payment(); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - |
|
| 934 | - /** |
|
| 935 | - * _save_selected_method_of_payment |
|
| 936 | - * stores the selected_method_of_payment in the session |
|
| 937 | - * so that it's available for all subsequent requests including AJAX |
|
| 938 | - * |
|
| 939 | - * @access private |
|
| 940 | - * @param string $selected_method_of_payment |
|
| 941 | - * @return void |
|
| 942 | - * @throws InvalidArgumentException |
|
| 943 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 944 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 945 | - */ |
|
| 946 | - private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 947 | - { |
|
| 948 | - $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 949 | - ? $selected_method_of_payment |
|
| 950 | - : $this->checkout->selected_method_of_payment; |
|
| 951 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 952 | - array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 953 | - ); |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - |
|
| 957 | - /** |
|
| 958 | - * _setup_payment_options |
|
| 959 | - * |
|
| 960 | - * @return EE_Form_Section_Proper |
|
| 961 | - * @throws EE_Error |
|
| 962 | - * @throws InvalidArgumentException |
|
| 963 | - * @throws ReflectionException |
|
| 964 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 965 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 966 | - */ |
|
| 967 | - public function _setup_payment_options() |
|
| 968 | - { |
|
| 969 | - // load payment method classes |
|
| 970 | - $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 971 | - if (empty($this->checkout->available_payment_methods)) { |
|
| 972 | - EE_Error::add_error( |
|
| 973 | - apply_filters( |
|
| 974 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 975 | - sprintf( |
|
| 976 | - esc_html__( |
|
| 977 | - 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 978 | - 'event_espresso' |
|
| 979 | - ), |
|
| 980 | - '<br>', |
|
| 981 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 982 | - ) |
|
| 983 | - ), |
|
| 984 | - __FILE__, |
|
| 985 | - __FUNCTION__, |
|
| 986 | - __LINE__ |
|
| 987 | - ); |
|
| 988 | - } |
|
| 989 | - // switch up header depending on number of available payment methods |
|
| 990 | - $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 991 | - ? apply_filters( |
|
| 992 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | - esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 994 | - ) |
|
| 995 | - : apply_filters( |
|
| 996 | - 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 997 | - esc_html__('Method of Payment', 'event_espresso') |
|
| 998 | - ); |
|
| 999 | - $available_payment_methods = array( |
|
| 1000 | - // display the "Payment Method" header |
|
| 1001 | - 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 1002 | - EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
| 1003 | - ), |
|
| 1004 | - ); |
|
| 1005 | - // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1006 | - $available_payment_method_options = array(); |
|
| 1007 | - $default_payment_method_option = array(); |
|
| 1008 | - // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1009 | - $payment_methods_billing_info = array( |
|
| 1010 | - new EE_Form_Section_HTML( |
|
| 1011 | - EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1012 | - ), |
|
| 1013 | - ); |
|
| 1014 | - // loop through payment methods |
|
| 1015 | - foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1016 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1017 | - $payment_method_button = EEH_HTML::img( |
|
| 1018 | - $payment_method->button_url(), |
|
| 1019 | - $payment_method->name(), |
|
| 1020 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1021 | - 'spco-payment-method-btn-img' |
|
| 1022 | - ); |
|
| 1023 | - // check if any payment methods are set as default |
|
| 1024 | - // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1025 | - // open_by_default |
|
| 1026 | - if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1027 | - || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | - ) { |
|
| 1029 | - $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1030 | - $this->_save_selected_method_of_payment(); |
|
| 1031 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1032 | - } else { |
|
| 1033 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1034 | - } |
|
| 1035 | - $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | - ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1037 | - $payment_method |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } |
|
| 1041 | - // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1042 | - // of PMs |
|
| 1043 | - $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1044 | - // now generate the actual form inputs |
|
| 1045 | - $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1046 | - $available_payment_method_options |
|
| 1047 | - ); |
|
| 1048 | - $available_payment_methods += $payment_methods_billing_info; |
|
| 1049 | - // build the available payment methods form |
|
| 1050 | - return new EE_Form_Section_Proper( |
|
| 1051 | - array( |
|
| 1052 | - 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1053 | - 'subsections' => $available_payment_methods, |
|
| 1054 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1055 | - ) |
|
| 1056 | - ); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * _get_available_payment_methods |
|
| 1062 | - * |
|
| 1063 | - * @return EE_Payment_Method[] |
|
| 1064 | - * @throws EE_Error |
|
| 1065 | - * @throws InvalidArgumentException |
|
| 1066 | - * @throws ReflectionException |
|
| 1067 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1068 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1069 | - */ |
|
| 1070 | - protected function _get_available_payment_methods() |
|
| 1071 | - { |
|
| 1072 | - if (! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | - return $this->checkout->available_payment_methods; |
|
| 1074 | - } |
|
| 1075 | - $available_payment_methods = array(); |
|
| 1076 | - // load EEM_Payment_Method |
|
| 1077 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1078 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1079 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1080 | - // get all active payment methods |
|
| 1081 | - $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1082 | - $this->checkout->transaction, |
|
| 1083 | - EEM_Payment_Method::scope_cart |
|
| 1084 | - ); |
|
| 1085 | - foreach ($payment_methods as $payment_method) { |
|
| 1086 | - if ($payment_method instanceof EE_Payment_Method) { |
|
| 1087 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1088 | - } |
|
| 1089 | - } |
|
| 1090 | - return $available_payment_methods; |
|
| 1091 | - } |
|
| 1092 | - |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * _available_payment_method_inputs |
|
| 1096 | - * |
|
| 1097 | - * @access private |
|
| 1098 | - * @param array $available_payment_method_options |
|
| 1099 | - * @return \EE_Form_Section_Proper |
|
| 1100 | - */ |
|
| 1101 | - private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1102 | - { |
|
| 1103 | - // generate inputs |
|
| 1104 | - return new EE_Form_Section_Proper( |
|
| 1105 | - array( |
|
| 1106 | - 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1107 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1108 | - 'subsections' => array( |
|
| 1109 | - '' => new EE_Radio_Button_Input( |
|
| 1110 | - $available_payment_method_options, |
|
| 1111 | - array( |
|
| 1112 | - 'html_name' => 'selected_method_of_payment', |
|
| 1113 | - 'html_class' => 'spco-payment-method', |
|
| 1114 | - 'default' => $this->checkout->selected_method_of_payment, |
|
| 1115 | - 'label_size' => 11, |
|
| 1116 | - 'enforce_label_size' => true, |
|
| 1117 | - ) |
|
| 1118 | - ), |
|
| 1119 | - ), |
|
| 1120 | - ) |
|
| 1121 | - ); |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * _payment_method_billing_info |
|
| 1127 | - * |
|
| 1128 | - * @access private |
|
| 1129 | - * @param EE_Payment_Method $payment_method |
|
| 1130 | - * @return EE_Form_Section_Proper |
|
| 1131 | - * @throws EE_Error |
|
| 1132 | - * @throws InvalidArgumentException |
|
| 1133 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1134 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1135 | - */ |
|
| 1136 | - private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1137 | - { |
|
| 1138 | - $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1139 | - ? true |
|
| 1140 | - : false; |
|
| 1141 | - // generate the billing form for payment method |
|
| 1142 | - $billing_form = $currently_selected |
|
| 1143 | - ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1144 | - : new EE_Form_Section_HTML(); |
|
| 1145 | - $this->checkout->billing_form = $currently_selected |
|
| 1146 | - ? $billing_form |
|
| 1147 | - : $this->checkout->billing_form; |
|
| 1148 | - // it's all in the details |
|
| 1149 | - $info_html = EEH_HTML::h3( |
|
| 1150 | - esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1151 | - '', |
|
| 1152 | - 'spco-payment-method-hdr' |
|
| 1153 | - ); |
|
| 1154 | - // add some info regarding the step, either from what's saved in the admin, |
|
| 1155 | - // or a default string depending on whether the PM has a billing form or not |
|
| 1156 | - if ($payment_method->description()) { |
|
| 1157 | - $payment_method_info = $payment_method->description(); |
|
| 1158 | - } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1159 | - $payment_method_info = sprintf( |
|
| 1160 | - esc_html__( |
|
| 1161 | - 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1162 | - 'event_espresso' |
|
| 1163 | - ), |
|
| 1164 | - $this->submit_button_text() |
|
| 1165 | - ); |
|
| 1166 | - } else { |
|
| 1167 | - $payment_method_info = sprintf( |
|
| 1168 | - esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1169 | - $this->submit_button_text() |
|
| 1170 | - ); |
|
| 1171 | - } |
|
| 1172 | - $info_html .= EEH_HTML::div( |
|
| 1173 | - apply_filters( |
|
| 1174 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1175 | - $payment_method_info |
|
| 1176 | - ), |
|
| 1177 | - '', |
|
| 1178 | - 'spco-payment-method-desc ee-attention' |
|
| 1179 | - ); |
|
| 1180 | - return new EE_Form_Section_Proper( |
|
| 1181 | - array( |
|
| 1182 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1183 | - 'html_class' => 'spco-payment-method-info-dv', |
|
| 1184 | - // only display the selected or default PM |
|
| 1185 | - 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1186 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1187 | - 'subsections' => array( |
|
| 1188 | - 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1189 | - 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1190 | - ), |
|
| 1191 | - ) |
|
| 1192 | - ); |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - |
|
| 1196 | - /** |
|
| 1197 | - * get_billing_form_html_for_payment_method |
|
| 1198 | - * |
|
| 1199 | - * @access public |
|
| 1200 | - * @return string |
|
| 1201 | - * @throws EE_Error |
|
| 1202 | - * @throws InvalidArgumentException |
|
| 1203 | - * @throws ReflectionException |
|
| 1204 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1205 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1206 | - */ |
|
| 1207 | - public function get_billing_form_html_for_payment_method() |
|
| 1208 | - { |
|
| 1209 | - // how have they chosen to pay? |
|
| 1210 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1211 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1212 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | - return false; |
|
| 1214 | - } |
|
| 1215 | - if (apply_filters( |
|
| 1216 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1217 | - false |
|
| 1218 | - )) { |
|
| 1219 | - EE_Error::add_success( |
|
| 1220 | - apply_filters( |
|
| 1221 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1222 | - sprintf( |
|
| 1223 | - esc_html__( |
|
| 1224 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1225 | - 'event_espresso' |
|
| 1226 | - ), |
|
| 1227 | - $this->checkout->payment_method->name() |
|
| 1228 | - ) |
|
| 1229 | - ) |
|
| 1230 | - ); |
|
| 1231 | - } |
|
| 1232 | - // now generate billing form for selected method of payment |
|
| 1233 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1234 | - // fill form with attendee info if applicable |
|
| 1235 | - if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1236 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1237 | - ) { |
|
| 1238 | - $payment_method_billing_form->populate_from_attendee( |
|
| 1239 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1240 | - ); |
|
| 1241 | - } |
|
| 1242 | - // and debug content |
|
| 1243 | - if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1244 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1245 | - ) { |
|
| 1246 | - $payment_method_billing_form = |
|
| 1247 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1248 | - $payment_method_billing_form |
|
| 1249 | - ); |
|
| 1250 | - } |
|
| 1251 | - $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1252 | - ? $payment_method_billing_form->get_html() |
|
| 1253 | - : ''; |
|
| 1254 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1255 | - // localize validation rules for main form |
|
| 1256 | - $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1257 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1258 | - return true; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - |
|
| 1262 | - /** |
|
| 1263 | - * _get_billing_form_for_payment_method |
|
| 1264 | - * |
|
| 1265 | - * @access private |
|
| 1266 | - * @param EE_Payment_Method $payment_method |
|
| 1267 | - * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1268 | - * @throws EE_Error |
|
| 1269 | - * @throws InvalidArgumentException |
|
| 1270 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1271 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1272 | - */ |
|
| 1273 | - private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1274 | - { |
|
| 1275 | - $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1276 | - $this->checkout->transaction, |
|
| 1277 | - array('amount_owing' => $this->checkout->amount_owing) |
|
| 1278 | - ); |
|
| 1279 | - if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1280 | - if (apply_filters( |
|
| 1281 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1282 | - false |
|
| 1283 | - ) |
|
| 1284 | - && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1285 | - ) { |
|
| 1286 | - EE_Error::add_success( |
|
| 1287 | - apply_filters( |
|
| 1288 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1289 | - sprintf( |
|
| 1290 | - esc_html__( |
|
| 1291 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1292 | - 'event_espresso' |
|
| 1293 | - ), |
|
| 1294 | - $payment_method->name() |
|
| 1295 | - ) |
|
| 1296 | - ) |
|
| 1297 | - ); |
|
| 1298 | - } |
|
| 1299 | - return apply_filters( |
|
| 1300 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1301 | - $billing_form, |
|
| 1302 | - $payment_method |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 1305 | - // no actual billing form, so return empty HTML form section |
|
| 1306 | - return new EE_Form_Section_HTML(); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * _get_selected_method_of_payment |
|
| 1312 | - * |
|
| 1313 | - * @access private |
|
| 1314 | - * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1315 | - * is not found in the incoming request |
|
| 1316 | - * @param string $request_param |
|
| 1317 | - * @return NULL|string |
|
| 1318 | - * @throws EE_Error |
|
| 1319 | - * @throws InvalidArgumentException |
|
| 1320 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1321 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1322 | - */ |
|
| 1323 | - private function _get_selected_method_of_payment( |
|
| 1324 | - $required = false, |
|
| 1325 | - $request_param = 'selected_method_of_payment' |
|
| 1326 | - ) { |
|
| 1327 | - // is selected_method_of_payment set in the request ? |
|
| 1328 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1329 | - if ($selected_method_of_payment) { |
|
| 1330 | - // sanitize it |
|
| 1331 | - $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1332 | - ? array_shift($selected_method_of_payment) |
|
| 1333 | - : $selected_method_of_payment; |
|
| 1334 | - $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1335 | - // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1336 | - $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1337 | - } else { |
|
| 1338 | - // or is is set in the session ? |
|
| 1339 | - $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1340 | - 'selected_method_of_payment' |
|
| 1341 | - ); |
|
| 1342 | - } |
|
| 1343 | - // do ya really really gotta have it? |
|
| 1344 | - if (empty($selected_method_of_payment) && $required) { |
|
| 1345 | - EE_Error::add_error( |
|
| 1346 | - sprintf( |
|
| 1347 | - esc_html__( |
|
| 1348 | - 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1349 | - 'event_espresso' |
|
| 1350 | - ), |
|
| 1351 | - '<br/>', |
|
| 1352 | - '<br/>', |
|
| 1353 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1354 | - ), |
|
| 1355 | - __FILE__, |
|
| 1356 | - __FUNCTION__, |
|
| 1357 | - __LINE__ |
|
| 1358 | - ); |
|
| 1359 | - return null; |
|
| 1360 | - } |
|
| 1361 | - return $selected_method_of_payment; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - |
|
| 1369 | - /********************************************************************************************************/ |
|
| 1370 | - /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1371 | - /********************************************************************************************************/ |
|
| 1372 | - /** |
|
| 1373 | - * switch_payment_method |
|
| 1374 | - * |
|
| 1375 | - * @access public |
|
| 1376 | - * @return string |
|
| 1377 | - * @throws EE_Error |
|
| 1378 | - * @throws InvalidArgumentException |
|
| 1379 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1380 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1381 | - */ |
|
| 1382 | - public function switch_payment_method() |
|
| 1383 | - { |
|
| 1384 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1385 | - return false; |
|
| 1386 | - } |
|
| 1387 | - if (apply_filters( |
|
| 1388 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1389 | - false |
|
| 1390 | - )) { |
|
| 1391 | - EE_Error::add_success( |
|
| 1392 | - apply_filters( |
|
| 1393 | - 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1394 | - sprintf( |
|
| 1395 | - esc_html__( |
|
| 1396 | - 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1397 | - 'event_espresso' |
|
| 1398 | - ), |
|
| 1399 | - $this->checkout->payment_method->name() |
|
| 1400 | - ) |
|
| 1401 | - ) |
|
| 1402 | - ); |
|
| 1403 | - } |
|
| 1404 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1405 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1406 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1407 | - $this->checkout->payment_method |
|
| 1408 | - ); |
|
| 1409 | - } |
|
| 1410 | - // fill form with attendee info if applicable |
|
| 1411 | - if (apply_filters( |
|
| 1412 | - 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1413 | - ( |
|
| 1414 | - $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1415 | - && $this->checkout->transaction_has_primary_registrant() |
|
| 1416 | - ), |
|
| 1417 | - $this->checkout->billing_form, |
|
| 1418 | - $this->checkout->transaction |
|
| 1419 | - ) |
|
| 1420 | - ) { |
|
| 1421 | - $this->checkout->billing_form->populate_from_attendee( |
|
| 1422 | - $this->checkout->transaction->primary_registration()->attendee() |
|
| 1423 | - ); |
|
| 1424 | - } |
|
| 1425 | - // and debug content |
|
| 1426 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1427 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1428 | - ) { |
|
| 1429 | - $this->checkout->billing_form = |
|
| 1430 | - $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1431 | - $this->checkout->billing_form |
|
| 1432 | - ); |
|
| 1433 | - } |
|
| 1434 | - // get html and validation rules for form |
|
| 1435 | - if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1436 | - $this->checkout->json_response->set_return_data( |
|
| 1437 | - array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1438 | - ); |
|
| 1439 | - // localize validation rules for main form |
|
| 1440 | - $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1441 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1442 | - } else { |
|
| 1443 | - $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1444 | - } |
|
| 1445 | - // prevents advancement to next step |
|
| 1446 | - $this->checkout->continue_reg = false; |
|
| 1447 | - return true; |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - |
|
| 1451 | - /** |
|
| 1452 | - * _verify_payment_method_is_set |
|
| 1453 | - * |
|
| 1454 | - * @return bool |
|
| 1455 | - * @throws EE_Error |
|
| 1456 | - * @throws InvalidArgumentException |
|
| 1457 | - * @throws ReflectionException |
|
| 1458 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1459 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1460 | - */ |
|
| 1461 | - protected function _verify_payment_method_is_set() |
|
| 1462 | - { |
|
| 1463 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1464 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1465 | - // how have they chosen to pay? |
|
| 1466 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1467 | - } else { |
|
| 1468 | - // choose your own adventure based on method_of_payment |
|
| 1469 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1470 | - case 'events_sold_out': |
|
| 1471 | - EE_Error::add_attention( |
|
| 1472 | - apply_filters( |
|
| 1473 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1474 | - esc_html__( |
|
| 1475 | - 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1476 | - 'event_espresso' |
|
| 1477 | - ) |
|
| 1478 | - ), |
|
| 1479 | - __FILE__, |
|
| 1480 | - __FUNCTION__, |
|
| 1481 | - __LINE__ |
|
| 1482 | - ); |
|
| 1483 | - return false; |
|
| 1484 | - break; |
|
| 1485 | - case 'payments_closed': |
|
| 1486 | - EE_Error::add_attention( |
|
| 1487 | - apply_filters( |
|
| 1488 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1489 | - esc_html__( |
|
| 1490 | - 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1491 | - 'event_espresso' |
|
| 1492 | - ) |
|
| 1493 | - ), |
|
| 1494 | - __FILE__, |
|
| 1495 | - __FUNCTION__, |
|
| 1496 | - __LINE__ |
|
| 1497 | - ); |
|
| 1498 | - return false; |
|
| 1499 | - break; |
|
| 1500 | - case 'no_payment_required': |
|
| 1501 | - EE_Error::add_attention( |
|
| 1502 | - apply_filters( |
|
| 1503 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1504 | - esc_html__( |
|
| 1505 | - 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1506 | - 'event_espresso' |
|
| 1507 | - ) |
|
| 1508 | - ), |
|
| 1509 | - __FILE__, |
|
| 1510 | - __FUNCTION__, |
|
| 1511 | - __LINE__ |
|
| 1512 | - ); |
|
| 1513 | - return false; |
|
| 1514 | - break; |
|
| 1515 | - default: |
|
| 1516 | - } |
|
| 1517 | - } |
|
| 1518 | - // verify payment method |
|
| 1519 | - if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | - // get payment method for selected method of payment |
|
| 1521 | - $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1522 | - } |
|
| 1523 | - return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - |
|
| 1528 | - /********************************************************************************************************/ |
|
| 1529 | - /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1530 | - /********************************************************************************************************/ |
|
| 1531 | - /** |
|
| 1532 | - * save_payer_details_via_ajax |
|
| 1533 | - * |
|
| 1534 | - * @return void |
|
| 1535 | - * @throws EE_Error |
|
| 1536 | - * @throws InvalidArgumentException |
|
| 1537 | - * @throws ReflectionException |
|
| 1538 | - * @throws RuntimeException |
|
| 1539 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1540 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1541 | - */ |
|
| 1542 | - public function save_payer_details_via_ajax() |
|
| 1543 | - { |
|
| 1544 | - if (! $this->_verify_payment_method_is_set()) { |
|
| 1545 | - return; |
|
| 1546 | - } |
|
| 1547 | - // generate billing form for selected method of payment if it hasn't been done already |
|
| 1548 | - if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1549 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1550 | - $this->checkout->payment_method |
|
| 1551 | - ); |
|
| 1552 | - } |
|
| 1553 | - // generate primary attendee from payer info if applicable |
|
| 1554 | - if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | - $attendee = $this->_create_attendee_from_request_data(); |
|
| 1556 | - if ($attendee instanceof EE_Attendee) { |
|
| 1557 | - foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1558 | - if ($registration->is_primary_registrant()) { |
|
| 1559 | - $this->checkout->primary_attendee_obj = $attendee; |
|
| 1560 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1561 | - $registration->set_attendee_id($attendee->ID()); |
|
| 1562 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1563 | - } |
|
| 1564 | - } |
|
| 1565 | - } |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * create_attendee_from_request_data |
|
| 1572 | - * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1573 | - * |
|
| 1574 | - * @return EE_Attendee |
|
| 1575 | - * @throws EE_Error |
|
| 1576 | - * @throws InvalidArgumentException |
|
| 1577 | - * @throws ReflectionException |
|
| 1578 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1579 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1580 | - */ |
|
| 1581 | - protected function _create_attendee_from_request_data() |
|
| 1582 | - { |
|
| 1583 | - // get State ID |
|
| 1584 | - $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1585 | - if (! empty($STA_ID)) { |
|
| 1586 | - // can we get state object from name ? |
|
| 1587 | - EE_Registry::instance()->load_model('State'); |
|
| 1588 | - $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1589 | - $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1590 | - } |
|
| 1591 | - // get Country ISO |
|
| 1592 | - $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1593 | - if (! empty($CNT_ISO)) { |
|
| 1594 | - // can we get country object from name ? |
|
| 1595 | - EE_Registry::instance()->load_model('Country'); |
|
| 1596 | - $country = EEM_Country::instance()->get_col( |
|
| 1597 | - array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1598 | - 'CNT_ISO' |
|
| 1599 | - ); |
|
| 1600 | - $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1601 | - } |
|
| 1602 | - // grab attendee data |
|
| 1603 | - $attendee_data = array( |
|
| 1604 | - 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1605 | - 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1606 | - 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1607 | - 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1608 | - 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1609 | - 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1610 | - 'STA_ID' => $STA_ID, |
|
| 1611 | - 'CNT_ISO' => $CNT_ISO, |
|
| 1612 | - 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1613 | - 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1614 | - ); |
|
| 1615 | - // validate the email address since it is the most important piece of info |
|
| 1616 | - if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1617 | - EE_Error::add_error( |
|
| 1618 | - esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1619 | - __FILE__, |
|
| 1620 | - __FUNCTION__, |
|
| 1621 | - __LINE__ |
|
| 1622 | - ); |
|
| 1623 | - } |
|
| 1624 | - // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1625 | - // AND email address |
|
| 1626 | - if (! empty($attendee_data['ATT_fname']) |
|
| 1627 | - && ! empty($attendee_data['ATT_lname']) |
|
| 1628 | - && ! empty($attendee_data['ATT_email']) |
|
| 1629 | - ) { |
|
| 1630 | - $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1631 | - array( |
|
| 1632 | - 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1633 | - 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1634 | - 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1635 | - ) |
|
| 1636 | - ); |
|
| 1637 | - if ($existing_attendee instanceof EE_Attendee) { |
|
| 1638 | - return $existing_attendee; |
|
| 1639 | - } |
|
| 1640 | - } |
|
| 1641 | - // no existing attendee? kk let's create a new one |
|
| 1642 | - // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1643 | - // don't exist |
|
| 1644 | - $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1645 | - ? $attendee_data['ATT_fname'] |
|
| 1646 | - : $attendee_data['ATT_email']; |
|
| 1647 | - $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1648 | - ? $attendee_data['ATT_lname'] |
|
| 1649 | - : $attendee_data['ATT_email']; |
|
| 1650 | - return EE_Attendee::new_instance($attendee_data); |
|
| 1651 | - } |
|
| 1652 | - |
|
| 1653 | - |
|
| 1654 | - |
|
| 1655 | - /********************************************************************************************************/ |
|
| 1656 | - /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1657 | - /********************************************************************************************************/ |
|
| 1658 | - /** |
|
| 1659 | - * process_reg_step |
|
| 1660 | - * |
|
| 1661 | - * @return bool |
|
| 1662 | - * @throws EE_Error |
|
| 1663 | - * @throws InvalidArgumentException |
|
| 1664 | - * @throws ReflectionException |
|
| 1665 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1666 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1667 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1668 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1669 | - */ |
|
| 1670 | - public function process_reg_step() |
|
| 1671 | - { |
|
| 1672 | - // how have they chosen to pay? |
|
| 1673 | - $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1674 | - ? 'no_payment_required' |
|
| 1675 | - : $this->_get_selected_method_of_payment(true); |
|
| 1676 | - // choose your own adventure based on method_of_payment |
|
| 1677 | - switch ($this->checkout->selected_method_of_payment) { |
|
| 1678 | - case 'events_sold_out': |
|
| 1679 | - $this->checkout->redirect = true; |
|
| 1680 | - $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1681 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1682 | - // mark this reg step as completed |
|
| 1683 | - $this->set_completed(); |
|
| 1684 | - return false; |
|
| 1685 | - break; |
|
| 1686 | - |
|
| 1687 | - case 'payments_closed': |
|
| 1688 | - if (apply_filters( |
|
| 1689 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1690 | - false |
|
| 1691 | - )) { |
|
| 1692 | - EE_Error::add_success( |
|
| 1693 | - esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1694 | - __FILE__, |
|
| 1695 | - __FUNCTION__, |
|
| 1696 | - __LINE__ |
|
| 1697 | - ); |
|
| 1698 | - } |
|
| 1699 | - // mark this reg step as completed |
|
| 1700 | - $this->set_completed(); |
|
| 1701 | - return true; |
|
| 1702 | - break; |
|
| 1703 | - |
|
| 1704 | - case 'no_payment_required': |
|
| 1705 | - if (apply_filters( |
|
| 1706 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1707 | - false |
|
| 1708 | - )) { |
|
| 1709 | - EE_Error::add_success( |
|
| 1710 | - esc_html__('no payment required.', 'event_espresso'), |
|
| 1711 | - __FILE__, |
|
| 1712 | - __FUNCTION__, |
|
| 1713 | - __LINE__ |
|
| 1714 | - ); |
|
| 1715 | - } |
|
| 1716 | - // mark this reg step as completed |
|
| 1717 | - $this->set_completed(); |
|
| 1718 | - return true; |
|
| 1719 | - break; |
|
| 1720 | - |
|
| 1721 | - default: |
|
| 1722 | - $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1723 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1724 | - ); |
|
| 1725 | - $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1726 | - $registrations, |
|
| 1727 | - EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1728 | - ); |
|
| 1729 | - // calculate difference between the two arrays |
|
| 1730 | - $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1731 | - if (empty($registrations)) { |
|
| 1732 | - $this->_redirect_because_event_sold_out(); |
|
| 1733 | - return false; |
|
| 1734 | - } |
|
| 1735 | - $payment_successful = $this->_process_payment(); |
|
| 1736 | - if ($payment_successful) { |
|
| 1737 | - $this->checkout->continue_reg = true; |
|
| 1738 | - $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1739 | - } else { |
|
| 1740 | - $this->checkout->continue_reg = false; |
|
| 1741 | - } |
|
| 1742 | - return $payment_successful; |
|
| 1743 | - } |
|
| 1744 | - } |
|
| 1745 | - |
|
| 1746 | - |
|
| 1747 | - /** |
|
| 1748 | - * _redirect_because_event_sold_out |
|
| 1749 | - * |
|
| 1750 | - * @access protected |
|
| 1751 | - * @return void |
|
| 1752 | - */ |
|
| 1753 | - protected function _redirect_because_event_sold_out() |
|
| 1754 | - { |
|
| 1755 | - $this->checkout->continue_reg = false; |
|
| 1756 | - // set redirect URL |
|
| 1757 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1758 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1759 | - $this->checkout->current_step->reg_step_url() |
|
| 1760 | - ); |
|
| 1761 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - |
|
| 1765 | - /** |
|
| 1766 | - * _maybe_set_completed |
|
| 1767 | - * |
|
| 1768 | - * @access protected |
|
| 1769 | - * @param \EE_Payment_Method $payment_method |
|
| 1770 | - * @return void |
|
| 1771 | - * @throws \EE_Error |
|
| 1772 | - */ |
|
| 1773 | - protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1774 | - { |
|
| 1775 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1776 | - case EE_PMT_Base::offsite: |
|
| 1777 | - break; |
|
| 1778 | - case EE_PMT_Base::onsite: |
|
| 1779 | - case EE_PMT_Base::offline: |
|
| 1780 | - // mark this reg step as completed |
|
| 1781 | - $this->set_completed(); |
|
| 1782 | - break; |
|
| 1783 | - } |
|
| 1784 | - } |
|
| 1785 | - |
|
| 1786 | - |
|
| 1787 | - /** |
|
| 1788 | - * update_reg_step |
|
| 1789 | - * this is the final step after a user revisits the site to retry a payment |
|
| 1790 | - * |
|
| 1791 | - * @return bool |
|
| 1792 | - * @throws EE_Error |
|
| 1793 | - * @throws InvalidArgumentException |
|
| 1794 | - * @throws ReflectionException |
|
| 1795 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1796 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1797 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1798 | - * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1799 | - */ |
|
| 1800 | - public function update_reg_step() |
|
| 1801 | - { |
|
| 1802 | - $success = true; |
|
| 1803 | - // if payment required |
|
| 1804 | - if ($this->checkout->transaction->total() > 0) { |
|
| 1805 | - do_action( |
|
| 1806 | - 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1807 | - $this->checkout->transaction |
|
| 1808 | - ); |
|
| 1809 | - // attempt payment via payment method |
|
| 1810 | - $success = $this->process_reg_step(); |
|
| 1811 | - } |
|
| 1812 | - if ($success && ! $this->checkout->redirect) { |
|
| 1813 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1814 | - $this->checkout->transaction->ID() |
|
| 1815 | - ); |
|
| 1816 | - // set return URL |
|
| 1817 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1818 | - array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1819 | - $this->checkout->thank_you_page_url |
|
| 1820 | - ); |
|
| 1821 | - } |
|
| 1822 | - return $success; |
|
| 1823 | - } |
|
| 1824 | - |
|
| 1825 | - |
|
| 1826 | - /** |
|
| 1827 | - * _process_payment |
|
| 1828 | - * |
|
| 1829 | - * @access private |
|
| 1830 | - * @return bool |
|
| 1831 | - * @throws EE_Error |
|
| 1832 | - * @throws InvalidArgumentException |
|
| 1833 | - * @throws ReflectionException |
|
| 1834 | - * @throws RuntimeException |
|
| 1835 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1836 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1837 | - */ |
|
| 1838 | - private function _process_payment() |
|
| 1839 | - { |
|
| 1840 | - // basically confirm that the event hasn't sold out since they hit the page |
|
| 1841 | - if (! $this->_last_second_ticket_verifications()) { |
|
| 1842 | - return false; |
|
| 1843 | - } |
|
| 1844 | - // ya gotta make a choice man |
|
| 1845 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1846 | - $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1847 | - esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1848 | - ); |
|
| 1849 | - return false; |
|
| 1850 | - } |
|
| 1851 | - // get EE_Payment_Method object |
|
| 1852 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | - return false; |
|
| 1854 | - } |
|
| 1855 | - // setup billing form |
|
| 1856 | - if ($this->checkout->payment_method->is_on_site()) { |
|
| 1857 | - $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1858 | - $this->checkout->payment_method |
|
| 1859 | - ); |
|
| 1860 | - // bad billing form ? |
|
| 1861 | - if (! $this->_billing_form_is_valid()) { |
|
| 1862 | - return false; |
|
| 1863 | - } |
|
| 1864 | - } |
|
| 1865 | - // ensure primary registrant has been fully processed |
|
| 1866 | - if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | - return false; |
|
| 1868 | - } |
|
| 1869 | - // if session is close to expiring (under 10 minutes by default) |
|
| 1870 | - if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1871 | - // add some time to session expiration so that payment can be completed |
|
| 1872 | - EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1873 | - } |
|
| 1874 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1875 | - // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1876 | - // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1877 | - // for events with a default reg status of Approved |
|
| 1878 | - // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1879 | - // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1880 | - // ); |
|
| 1881 | - // attempt payment |
|
| 1882 | - $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1883 | - // process results |
|
| 1884 | - $payment = $this->_validate_payment($payment); |
|
| 1885 | - $payment = $this->_post_payment_processing($payment); |
|
| 1886 | - // verify payment |
|
| 1887 | - if ($payment instanceof EE_Payment) { |
|
| 1888 | - // store that for later |
|
| 1889 | - $this->checkout->payment = $payment; |
|
| 1890 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1891 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1892 | - $payment_status = $payment->status(); |
|
| 1893 | - if ($payment_status === EEM_Payment::status_id_approved |
|
| 1894 | - || $payment_status === EEM_Payment::status_id_pending |
|
| 1895 | - ) { |
|
| 1896 | - return true; |
|
| 1897 | - } else { |
|
| 1898 | - return false; |
|
| 1899 | - } |
|
| 1900 | - } elseif ($payment === true) { |
|
| 1901 | - // please note that offline payment methods will NOT make a payment, |
|
| 1902 | - // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1903 | - $this->checkout->payment = $payment; |
|
| 1904 | - return true; |
|
| 1905 | - } |
|
| 1906 | - // where's my money? |
|
| 1907 | - return false; |
|
| 1908 | - } |
|
| 1909 | - |
|
| 1910 | - |
|
| 1911 | - /** |
|
| 1912 | - * _last_second_ticket_verifications |
|
| 1913 | - * |
|
| 1914 | - * @access public |
|
| 1915 | - * @return bool |
|
| 1916 | - * @throws EE_Error |
|
| 1917 | - */ |
|
| 1918 | - protected function _last_second_ticket_verifications() |
|
| 1919 | - { |
|
| 1920 | - // don't bother re-validating if not a return visit |
|
| 1921 | - if (! $this->checkout->revisit) { |
|
| 1922 | - return true; |
|
| 1923 | - } |
|
| 1924 | - $registrations = $this->checkout->transaction->registrations(); |
|
| 1925 | - if (empty($registrations)) { |
|
| 1926 | - return false; |
|
| 1927 | - } |
|
| 1928 | - foreach ($registrations as $registration) { |
|
| 1929 | - if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1930 | - $event = $registration->event_obj(); |
|
| 1931 | - if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1932 | - EE_Error::add_error( |
|
| 1933 | - apply_filters( |
|
| 1934 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1935 | - sprintf( |
|
| 1936 | - esc_html__( |
|
| 1937 | - 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1938 | - 'event_espresso' |
|
| 1939 | - ), |
|
| 1940 | - $event->name() |
|
| 1941 | - ) |
|
| 1942 | - ), |
|
| 1943 | - __FILE__, |
|
| 1944 | - __FUNCTION__, |
|
| 1945 | - __LINE__ |
|
| 1946 | - ); |
|
| 1947 | - return false; |
|
| 1948 | - } |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - return true; |
|
| 1952 | - } |
|
| 1953 | - |
|
| 1954 | - |
|
| 1955 | - /** |
|
| 1956 | - * redirect_form |
|
| 1957 | - * |
|
| 1958 | - * @access public |
|
| 1959 | - * @return bool |
|
| 1960 | - * @throws EE_Error |
|
| 1961 | - * @throws InvalidArgumentException |
|
| 1962 | - * @throws ReflectionException |
|
| 1963 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1964 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1965 | - */ |
|
| 1966 | - public function redirect_form() |
|
| 1967 | - { |
|
| 1968 | - $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1969 | - $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1970 | - ); |
|
| 1971 | - $html = $payment_method_billing_info->get_html(); |
|
| 1972 | - $html .= $this->checkout->redirect_form; |
|
| 1973 | - EE_Registry::instance()->REQ->add_output($html); |
|
| 1974 | - return true; |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - |
|
| 1978 | - /** |
|
| 1979 | - * _billing_form_is_valid |
|
| 1980 | - * |
|
| 1981 | - * @access private |
|
| 1982 | - * @return bool |
|
| 1983 | - * @throws \EE_Error |
|
| 1984 | - */ |
|
| 1985 | - private function _billing_form_is_valid() |
|
| 1986 | - { |
|
| 1987 | - if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | - return true; |
|
| 1989 | - } |
|
| 1990 | - if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1991 | - if ($this->checkout->billing_form->was_submitted()) { |
|
| 1992 | - $this->checkout->billing_form->receive_form_submission(); |
|
| 1993 | - if ($this->checkout->billing_form->is_valid()) { |
|
| 1994 | - return true; |
|
| 1995 | - } |
|
| 1996 | - $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 1997 | - $error_strings = array(); |
|
| 1998 | - foreach ($validation_errors as $validation_error) { |
|
| 1999 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 2000 | - $form_section = $validation_error->get_form_section(); |
|
| 2001 | - if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2002 | - $label = $form_section->html_label_text(); |
|
| 2003 | - } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2004 | - $label = $form_section->name(); |
|
| 2005 | - } else { |
|
| 2006 | - $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2007 | - } |
|
| 2008 | - $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2009 | - } |
|
| 2010 | - } |
|
| 2011 | - EE_Error::add_error( |
|
| 2012 | - sprintf( |
|
| 2013 | - esc_html__( |
|
| 2014 | - 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2015 | - 'event_espresso' |
|
| 2016 | - ), |
|
| 2017 | - '<br/>', |
|
| 2018 | - implode('<br/>', $error_strings) |
|
| 2019 | - ), |
|
| 2020 | - __FILE__, |
|
| 2021 | - __FUNCTION__, |
|
| 2022 | - __LINE__ |
|
| 2023 | - ); |
|
| 2024 | - } else { |
|
| 2025 | - EE_Error::add_error( |
|
| 2026 | - esc_html__( |
|
| 2027 | - 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2028 | - 'event_espresso' |
|
| 2029 | - ), |
|
| 2030 | - __FILE__, |
|
| 2031 | - __FUNCTION__, |
|
| 2032 | - __LINE__ |
|
| 2033 | - ); |
|
| 2034 | - } |
|
| 2035 | - } else { |
|
| 2036 | - EE_Error::add_error( |
|
| 2037 | - esc_html__( |
|
| 2038 | - 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2039 | - 'event_espresso' |
|
| 2040 | - ), |
|
| 2041 | - __FILE__, |
|
| 2042 | - __FUNCTION__, |
|
| 2043 | - __LINE__ |
|
| 2044 | - ); |
|
| 2045 | - } |
|
| 2046 | - return false; |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * _setup_primary_registrant_prior_to_payment |
|
| 2052 | - * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2053 | - * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2054 | - * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2055 | - * yet) |
|
| 2056 | - * |
|
| 2057 | - * @access private |
|
| 2058 | - * @return bool |
|
| 2059 | - * @throws EE_Error |
|
| 2060 | - * @throws InvalidArgumentException |
|
| 2061 | - * @throws ReflectionException |
|
| 2062 | - * @throws RuntimeException |
|
| 2063 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2064 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2065 | - */ |
|
| 2066 | - private function _setup_primary_registrant_prior_to_payment() |
|
| 2067 | - { |
|
| 2068 | - // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2069 | - // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2070 | - if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2071 | - && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2072 | - && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2073 | - ) { |
|
| 2074 | - return false; |
|
| 2075 | - } |
|
| 2076 | - // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2077 | - // grab the primary_registration object |
|
| 2078 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2079 | - // at this point we'll consider a TXN to not have been failed |
|
| 2080 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2081 | - // save the TXN ( which clears cached copy of primary_registration) |
|
| 2082 | - $this->checkout->transaction->save(); |
|
| 2083 | - // grab TXN ID and save it to the primary_registration |
|
| 2084 | - $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2085 | - // save what we have so far |
|
| 2086 | - $primary_registration->save(); |
|
| 2087 | - return true; |
|
| 2088 | - } |
|
| 2089 | - |
|
| 2090 | - |
|
| 2091 | - /** |
|
| 2092 | - * _capture_primary_registration_data_from_billing_form |
|
| 2093 | - * |
|
| 2094 | - * @access private |
|
| 2095 | - * @return bool |
|
| 2096 | - * @throws EE_Error |
|
| 2097 | - * @throws InvalidArgumentException |
|
| 2098 | - * @throws ReflectionException |
|
| 2099 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2100 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2101 | - */ |
|
| 2102 | - private function _capture_primary_registration_data_from_billing_form() |
|
| 2103 | - { |
|
| 2104 | - // convert billing form data into an attendee |
|
| 2105 | - $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2106 | - if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | - EE_Error::add_error( |
|
| 2108 | - sprintf( |
|
| 2109 | - esc_html__( |
|
| 2110 | - 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2111 | - 'event_espresso' |
|
| 2112 | - ), |
|
| 2113 | - '<br/>', |
|
| 2114 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2115 | - ), |
|
| 2116 | - __FILE__, |
|
| 2117 | - __FUNCTION__, |
|
| 2118 | - __LINE__ |
|
| 2119 | - ); |
|
| 2120 | - return false; |
|
| 2121 | - } |
|
| 2122 | - $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2123 | - if (! $primary_registration instanceof EE_Registration) { |
|
| 2124 | - EE_Error::add_error( |
|
| 2125 | - sprintf( |
|
| 2126 | - esc_html__( |
|
| 2127 | - 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2128 | - 'event_espresso' |
|
| 2129 | - ), |
|
| 2130 | - '<br/>', |
|
| 2131 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2132 | - ), |
|
| 2133 | - __FILE__, |
|
| 2134 | - __FUNCTION__, |
|
| 2135 | - __LINE__ |
|
| 2136 | - ); |
|
| 2137 | - return false; |
|
| 2138 | - } |
|
| 2139 | - if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | - instanceof |
|
| 2141 | - EE_Attendee |
|
| 2142 | - ) { |
|
| 2143 | - EE_Error::add_error( |
|
| 2144 | - sprintf( |
|
| 2145 | - esc_html__( |
|
| 2146 | - 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2147 | - 'event_espresso' |
|
| 2148 | - ), |
|
| 2149 | - '<br/>', |
|
| 2150 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2151 | - ), |
|
| 2152 | - __FILE__, |
|
| 2153 | - __FUNCTION__, |
|
| 2154 | - __LINE__ |
|
| 2155 | - ); |
|
| 2156 | - return false; |
|
| 2157 | - } |
|
| 2158 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 2159 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2160 | - // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2161 | - $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2162 | - return true; |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - |
|
| 2166 | - /** |
|
| 2167 | - * _get_payment_method_for_selected_method_of_payment |
|
| 2168 | - * retrieves a valid payment method |
|
| 2169 | - * |
|
| 2170 | - * @access public |
|
| 2171 | - * @return EE_Payment_Method |
|
| 2172 | - * @throws EE_Error |
|
| 2173 | - * @throws InvalidArgumentException |
|
| 2174 | - * @throws ReflectionException |
|
| 2175 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2176 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | - */ |
|
| 2178 | - private function _get_payment_method_for_selected_method_of_payment() |
|
| 2179 | - { |
|
| 2180 | - if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2181 | - $this->_redirect_because_event_sold_out(); |
|
| 2182 | - return null; |
|
| 2183 | - } |
|
| 2184 | - // get EE_Payment_Method object |
|
| 2185 | - if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2187 | - } else { |
|
| 2188 | - // load EEM_Payment_Method |
|
| 2189 | - EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2190 | - /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2191 | - $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2192 | - $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2193 | - } |
|
| 2194 | - // verify $payment_method |
|
| 2195 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | - // not a payment |
|
| 2197 | - EE_Error::add_error( |
|
| 2198 | - sprintf( |
|
| 2199 | - esc_html__( |
|
| 2200 | - 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2201 | - 'event_espresso' |
|
| 2202 | - ), |
|
| 2203 | - '<br/>', |
|
| 2204 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2205 | - ), |
|
| 2206 | - __FILE__, |
|
| 2207 | - __FUNCTION__, |
|
| 2208 | - __LINE__ |
|
| 2209 | - ); |
|
| 2210 | - return null; |
|
| 2211 | - } |
|
| 2212 | - // and verify it has a valid Payment_Method Type object |
|
| 2213 | - if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | - // not a payment |
|
| 2215 | - EE_Error::add_error( |
|
| 2216 | - sprintf( |
|
| 2217 | - esc_html__( |
|
| 2218 | - 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2219 | - 'event_espresso' |
|
| 2220 | - ), |
|
| 2221 | - '<br/>', |
|
| 2222 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2223 | - ), |
|
| 2224 | - __FILE__, |
|
| 2225 | - __FUNCTION__, |
|
| 2226 | - __LINE__ |
|
| 2227 | - ); |
|
| 2228 | - return null; |
|
| 2229 | - } |
|
| 2230 | - return $payment_method; |
|
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * _attempt_payment |
|
| 2236 | - * |
|
| 2237 | - * @access private |
|
| 2238 | - * @type EE_Payment_Method $payment_method |
|
| 2239 | - * @return mixed EE_Payment | boolean |
|
| 2240 | - * @throws EE_Error |
|
| 2241 | - * @throws InvalidArgumentException |
|
| 2242 | - * @throws ReflectionException |
|
| 2243 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2244 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2245 | - */ |
|
| 2246 | - private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2247 | - { |
|
| 2248 | - $payment = null; |
|
| 2249 | - $this->checkout->transaction->save(); |
|
| 2250 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2251 | - if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | - return false; |
|
| 2253 | - } |
|
| 2254 | - try { |
|
| 2255 | - $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2256 | - // generate payment object |
|
| 2257 | - $payment = $payment_processor->process_payment( |
|
| 2258 | - $payment_method, |
|
| 2259 | - $this->checkout->transaction, |
|
| 2260 | - $this->checkout->amount_owing, |
|
| 2261 | - $this->checkout->billing_form, |
|
| 2262 | - $this->_get_return_url($payment_method), |
|
| 2263 | - 'CART', |
|
| 2264 | - $this->checkout->admin_request, |
|
| 2265 | - true, |
|
| 2266 | - $this->reg_step_url() |
|
| 2267 | - ); |
|
| 2268 | - } catch (Exception $e) { |
|
| 2269 | - $this->_handle_payment_processor_exception($e); |
|
| 2270 | - } |
|
| 2271 | - return $payment; |
|
| 2272 | - } |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - /** |
|
| 2276 | - * _handle_payment_processor_exception |
|
| 2277 | - * |
|
| 2278 | - * @access protected |
|
| 2279 | - * @param \Exception $e |
|
| 2280 | - * @return void |
|
| 2281 | - * @throws EE_Error |
|
| 2282 | - * @throws InvalidArgumentException |
|
| 2283 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2284 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2285 | - */ |
|
| 2286 | - protected function _handle_payment_processor_exception(Exception $e) |
|
| 2287 | - { |
|
| 2288 | - EE_Error::add_error( |
|
| 2289 | - sprintf( |
|
| 2290 | - esc_html__( |
|
| 2291 | - 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2292 | - 'event_espresso' |
|
| 2293 | - ), |
|
| 2294 | - '<br/>', |
|
| 2295 | - EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2296 | - $e->getMessage(), |
|
| 2297 | - $e->getFile(), |
|
| 2298 | - $e->getLine() |
|
| 2299 | - ), |
|
| 2300 | - __FILE__, |
|
| 2301 | - __FUNCTION__, |
|
| 2302 | - __LINE__ |
|
| 2303 | - ); |
|
| 2304 | - } |
|
| 2305 | - |
|
| 2306 | - |
|
| 2307 | - /** |
|
| 2308 | - * _get_return_url |
|
| 2309 | - * |
|
| 2310 | - * @access protected |
|
| 2311 | - * @param \EE_Payment_Method $payment_method |
|
| 2312 | - * @return string |
|
| 2313 | - * @throws \EE_Error |
|
| 2314 | - */ |
|
| 2315 | - protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2316 | - { |
|
| 2317 | - $return_url = ''; |
|
| 2318 | - switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2319 | - case EE_PMT_Base::offsite: |
|
| 2320 | - $return_url = add_query_arg( |
|
| 2321 | - array( |
|
| 2322 | - 'action' => 'process_gateway_response', |
|
| 2323 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2324 | - 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2325 | - ), |
|
| 2326 | - $this->reg_step_url() |
|
| 2327 | - ); |
|
| 2328 | - break; |
|
| 2329 | - case EE_PMT_Base::onsite: |
|
| 2330 | - case EE_PMT_Base::offline: |
|
| 2331 | - $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2332 | - break; |
|
| 2333 | - } |
|
| 2334 | - return $return_url; |
|
| 2335 | - } |
|
| 2336 | - |
|
| 2337 | - |
|
| 2338 | - /** |
|
| 2339 | - * _validate_payment |
|
| 2340 | - * |
|
| 2341 | - * @access private |
|
| 2342 | - * @param EE_Payment $payment |
|
| 2343 | - * @return EE_Payment|FALSE |
|
| 2344 | - * @throws EE_Error |
|
| 2345 | - * @throws InvalidArgumentException |
|
| 2346 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2347 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2348 | - */ |
|
| 2349 | - private function _validate_payment($payment = null) |
|
| 2350 | - { |
|
| 2351 | - if ($this->checkout->payment_method->is_off_line()) { |
|
| 2352 | - return true; |
|
| 2353 | - } |
|
| 2354 | - // verify payment object |
|
| 2355 | - if (! $payment instanceof EE_Payment) { |
|
| 2356 | - // not a payment |
|
| 2357 | - EE_Error::add_error( |
|
| 2358 | - sprintf( |
|
| 2359 | - esc_html__( |
|
| 2360 | - 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2361 | - 'event_espresso' |
|
| 2362 | - ), |
|
| 2363 | - '<br/>', |
|
| 2364 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2365 | - ), |
|
| 2366 | - __FILE__, |
|
| 2367 | - __FUNCTION__, |
|
| 2368 | - __LINE__ |
|
| 2369 | - ); |
|
| 2370 | - return false; |
|
| 2371 | - } |
|
| 2372 | - return $payment; |
|
| 2373 | - } |
|
| 2374 | - |
|
| 2375 | - |
|
| 2376 | - /** |
|
| 2377 | - * _post_payment_processing |
|
| 2378 | - * |
|
| 2379 | - * @access private |
|
| 2380 | - * @param EE_Payment|bool $payment |
|
| 2381 | - * @return bool |
|
| 2382 | - * @throws EE_Error |
|
| 2383 | - * @throws InvalidArgumentException |
|
| 2384 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2385 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2386 | - */ |
|
| 2387 | - private function _post_payment_processing($payment = null) |
|
| 2388 | - { |
|
| 2389 | - // Off-Line payment? |
|
| 2390 | - if ($payment === true) { |
|
| 2391 | - // $this->_setup_redirect_for_next_step(); |
|
| 2392 | - return true; |
|
| 2393 | - // On-Site payment? |
|
| 2394 | - } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2395 | - if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | - // $this->_setup_redirect_for_next_step(); |
|
| 2397 | - $this->checkout->continue_reg = false; |
|
| 2398 | - } |
|
| 2399 | - // Off-Site payment? |
|
| 2400 | - } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2401 | - // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2402 | - if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2403 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2404 | - $this->checkout->redirect = true; |
|
| 2405 | - $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2406 | - $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2407 | - // set JSON response |
|
| 2408 | - $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2409 | - // and lastly, let's bump the payment status to pending |
|
| 2410 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2411 | - $payment->save(); |
|
| 2412 | - } else { |
|
| 2413 | - // not a payment |
|
| 2414 | - $this->checkout->continue_reg = false; |
|
| 2415 | - EE_Error::add_error( |
|
| 2416 | - sprintf( |
|
| 2417 | - esc_html__( |
|
| 2418 | - 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2419 | - 'event_espresso' |
|
| 2420 | - ), |
|
| 2421 | - '<br/>', |
|
| 2422 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2423 | - ), |
|
| 2424 | - __FILE__, |
|
| 2425 | - __FUNCTION__, |
|
| 2426 | - __LINE__ |
|
| 2427 | - ); |
|
| 2428 | - } |
|
| 2429 | - } else { |
|
| 2430 | - // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2431 | - $this->checkout->continue_reg = false; |
|
| 2432 | - return false; |
|
| 2433 | - } |
|
| 2434 | - return $payment; |
|
| 2435 | - } |
|
| 2436 | - |
|
| 2437 | - |
|
| 2438 | - /** |
|
| 2439 | - * _process_payment_status |
|
| 2440 | - * |
|
| 2441 | - * @access private |
|
| 2442 | - * @type EE_Payment $payment |
|
| 2443 | - * @param string $payment_occurs |
|
| 2444 | - * @return bool |
|
| 2445 | - * @throws EE_Error |
|
| 2446 | - * @throws InvalidArgumentException |
|
| 2447 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2448 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2449 | - */ |
|
| 2450 | - private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2451 | - { |
|
| 2452 | - // off-line payment? carry on |
|
| 2453 | - if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2454 | - return true; |
|
| 2455 | - } |
|
| 2456 | - // verify payment validity |
|
| 2457 | - if ($payment instanceof EE_Payment) { |
|
| 2458 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2459 | - $msg = $payment->gateway_response(); |
|
| 2460 | - // check results |
|
| 2461 | - switch ($payment->status()) { |
|
| 2462 | - // good payment |
|
| 2463 | - case EEM_Payment::status_id_approved: |
|
| 2464 | - EE_Error::add_success( |
|
| 2465 | - esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2466 | - __FILE__, |
|
| 2467 | - __FUNCTION__, |
|
| 2468 | - __LINE__ |
|
| 2469 | - ); |
|
| 2470 | - return true; |
|
| 2471 | - break; |
|
| 2472 | - // slow payment |
|
| 2473 | - case EEM_Payment::status_id_pending: |
|
| 2474 | - if (empty($msg)) { |
|
| 2475 | - $msg = esc_html__( |
|
| 2476 | - 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2477 | - 'event_espresso' |
|
| 2478 | - ); |
|
| 2479 | - } |
|
| 2480 | - EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2481 | - return true; |
|
| 2482 | - break; |
|
| 2483 | - // don't wanna payment |
|
| 2484 | - case EEM_Payment::status_id_cancelled: |
|
| 2485 | - if (empty($msg)) { |
|
| 2486 | - $msg = _n( |
|
| 2487 | - 'Payment cancelled. Please try again.', |
|
| 2488 | - 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2489 | - count($this->checkout->available_payment_methods), |
|
| 2490 | - 'event_espresso' |
|
| 2491 | - ); |
|
| 2492 | - } |
|
| 2493 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2494 | - return false; |
|
| 2495 | - break; |
|
| 2496 | - // not enough payment |
|
| 2497 | - case EEM_Payment::status_id_declined: |
|
| 2498 | - if (empty($msg)) { |
|
| 2499 | - $msg = _n( |
|
| 2500 | - 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2501 | - 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2502 | - count($this->checkout->available_payment_methods), |
|
| 2503 | - 'event_espresso' |
|
| 2504 | - ); |
|
| 2505 | - } |
|
| 2506 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2507 | - return false; |
|
| 2508 | - break; |
|
| 2509 | - // bad payment |
|
| 2510 | - case EEM_Payment::status_id_failed: |
|
| 2511 | - if (! empty($msg)) { |
|
| 2512 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2513 | - return false; |
|
| 2514 | - } |
|
| 2515 | - // default to error below |
|
| 2516 | - break; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2520 | - // the payment processing is just running slower than the registrant's request |
|
| 2521 | - if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2522 | - return true; |
|
| 2523 | - } |
|
| 2524 | - EE_Error::add_error( |
|
| 2525 | - sprintf( |
|
| 2526 | - esc_html__( |
|
| 2527 | - 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2528 | - 'event_espresso' |
|
| 2529 | - ), |
|
| 2530 | - '<br/>', |
|
| 2531 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2532 | - ), |
|
| 2533 | - __FILE__, |
|
| 2534 | - __FUNCTION__, |
|
| 2535 | - __LINE__ |
|
| 2536 | - ); |
|
| 2537 | - return false; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - |
|
| 2542 | - |
|
| 2543 | - |
|
| 2544 | - |
|
| 2545 | - /********************************************************************************************************/ |
|
| 2546 | - /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2547 | - /********************************************************************************************************/ |
|
| 2548 | - /** |
|
| 2549 | - * process_gateway_response |
|
| 2550 | - * this is the return point for Off-Site Payment Methods |
|
| 2551 | - * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2552 | - * otherwise, it will load up the last payment made for the TXN. |
|
| 2553 | - * If the payment retrieved looks good, it will then either: |
|
| 2554 | - * complete the current step and allow advancement to the next reg step |
|
| 2555 | - * or present the payment options again |
|
| 2556 | - * |
|
| 2557 | - * @access private |
|
| 2558 | - * @return EE_Payment|FALSE |
|
| 2559 | - * @throws EE_Error |
|
| 2560 | - * @throws InvalidArgumentException |
|
| 2561 | - * @throws ReflectionException |
|
| 2562 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2563 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2564 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2565 | - */ |
|
| 2566 | - public function process_gateway_response() |
|
| 2567 | - { |
|
| 2568 | - $payment = null; |
|
| 2569 | - // how have they chosen to pay? |
|
| 2570 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2571 | - // get EE_Payment_Method object |
|
| 2572 | - if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | - $this->checkout->continue_reg = false; |
|
| 2574 | - return false; |
|
| 2575 | - } |
|
| 2576 | - if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | - return false; |
|
| 2578 | - } |
|
| 2579 | - $this->_validate_offsite_return(); |
|
| 2580 | - // DEBUG LOG |
|
| 2581 | - // $this->checkout->log( |
|
| 2582 | - // __CLASS__, |
|
| 2583 | - // __FUNCTION__, |
|
| 2584 | - // __LINE__, |
|
| 2585 | - // array( |
|
| 2586 | - // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2587 | - // 'payment_method' => $this->checkout->payment_method, |
|
| 2588 | - // ), |
|
| 2589 | - // true |
|
| 2590 | - // ); |
|
| 2591 | - // verify TXN |
|
| 2592 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2593 | - $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2594 | - if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | - $this->checkout->continue_reg = false; |
|
| 2596 | - return false; |
|
| 2597 | - } |
|
| 2598 | - $payment = $this->_process_off_site_payment($gateway); |
|
| 2599 | - $payment = $this->_process_cancelled_payments($payment); |
|
| 2600 | - $payment = $this->_validate_payment($payment); |
|
| 2601 | - // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2602 | - if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2603 | - // $this->_setup_redirect_for_next_step(); |
|
| 2604 | - // store that for later |
|
| 2605 | - $this->checkout->payment = $payment; |
|
| 2606 | - // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2607 | - // because we will complete this step during the IPN processing then |
|
| 2608 | - if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2609 | - $this->set_completed(); |
|
| 2610 | - } |
|
| 2611 | - return true; |
|
| 2612 | - } |
|
| 2613 | - } |
|
| 2614 | - // DEBUG LOG |
|
| 2615 | - // $this->checkout->log( |
|
| 2616 | - // __CLASS__, |
|
| 2617 | - // __FUNCTION__, |
|
| 2618 | - // __LINE__, |
|
| 2619 | - // array('payment' => $payment) |
|
| 2620 | - // ); |
|
| 2621 | - $this->checkout->continue_reg = false; |
|
| 2622 | - return false; |
|
| 2623 | - } |
|
| 2624 | - |
|
| 2625 | - |
|
| 2626 | - /** |
|
| 2627 | - * _validate_return |
|
| 2628 | - * |
|
| 2629 | - * @access private |
|
| 2630 | - * @return void |
|
| 2631 | - * @throws EE_Error |
|
| 2632 | - * @throws InvalidArgumentException |
|
| 2633 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2634 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2635 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2636 | - */ |
|
| 2637 | - private function _validate_offsite_return() |
|
| 2638 | - { |
|
| 2639 | - $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2640 | - if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2641 | - // Houston... we might have a problem |
|
| 2642 | - $invalid_TXN = false; |
|
| 2643 | - // first gather some info |
|
| 2644 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2645 | - $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2646 | - ? $valid_TXN->primary_registration() |
|
| 2647 | - : null; |
|
| 2648 | - // let's start by retrieving the cart for this TXN |
|
| 2649 | - $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2650 | - if ($cart instanceof EE_Cart) { |
|
| 2651 | - // verify that the current cart has tickets |
|
| 2652 | - $tickets = $cart->get_tickets(); |
|
| 2653 | - if (empty($tickets)) { |
|
| 2654 | - $invalid_TXN = true; |
|
| 2655 | - } |
|
| 2656 | - } else { |
|
| 2657 | - $invalid_TXN = true; |
|
| 2658 | - } |
|
| 2659 | - $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2660 | - ? $primary_registrant->session_ID() |
|
| 2661 | - : null; |
|
| 2662 | - // validate current Session ID and compare against valid TXN session ID |
|
| 2663 | - if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2664 | - || EE_Session::instance()->id() === null |
|
| 2665 | - || ( |
|
| 2666 | - // WARNING !!! |
|
| 2667 | - // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2668 | - // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2669 | - // so now we need to determine if this current TXN looks valid or not |
|
| 2670 | - // and whether this reg step has even been started ? |
|
| 2671 | - EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2672 | - // really? you're half way through this reg step, but you never started it ? |
|
| 2673 | - && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2674 | - ) |
|
| 2675 | - ) { |
|
| 2676 | - $invalid_TXN = true; |
|
| 2677 | - } |
|
| 2678 | - if ($invalid_TXN) { |
|
| 2679 | - // is the valid TXN completed ? |
|
| 2680 | - if ($valid_TXN instanceof EE_Transaction) { |
|
| 2681 | - // has this step even been started ? |
|
| 2682 | - $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2683 | - if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2684 | - // so it **looks** like this is a double request from PayPal |
|
| 2685 | - // so let's try to pick up where we left off |
|
| 2686 | - $this->checkout->transaction = $valid_TXN; |
|
| 2687 | - $this->checkout->refresh_all_entities(true); |
|
| 2688 | - return; |
|
| 2689 | - } |
|
| 2690 | - } |
|
| 2691 | - // you appear to be lost? |
|
| 2692 | - $this->_redirect_wayward_request($primary_registrant); |
|
| 2693 | - } |
|
| 2694 | - } |
|
| 2695 | - } |
|
| 2696 | - |
|
| 2697 | - |
|
| 2698 | - /** |
|
| 2699 | - * _redirect_wayward_request |
|
| 2700 | - * |
|
| 2701 | - * @access private |
|
| 2702 | - * @param \EE_Registration|null $primary_registrant |
|
| 2703 | - * @return bool |
|
| 2704 | - * @throws EE_Error |
|
| 2705 | - * @throws InvalidArgumentException |
|
| 2706 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2707 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2708 | - */ |
|
| 2709 | - private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2710 | - { |
|
| 2711 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | - // try redirecting based on the current TXN |
|
| 2713 | - $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2714 | - ? $this->checkout->transaction->primary_registration() |
|
| 2715 | - : null; |
|
| 2716 | - } |
|
| 2717 | - if (! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | - EE_Error::add_error( |
|
| 2719 | - sprintf( |
|
| 2720 | - esc_html__( |
|
| 2721 | - 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2722 | - 'event_espresso' |
|
| 2723 | - ), |
|
| 2724 | - '<br/>', |
|
| 2725 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2726 | - ), |
|
| 2727 | - __FILE__, |
|
| 2728 | - __FUNCTION__, |
|
| 2729 | - __LINE__ |
|
| 2730 | - ); |
|
| 2731 | - return false; |
|
| 2732 | - } |
|
| 2733 | - // make sure transaction is not locked |
|
| 2734 | - $this->checkout->transaction->unlock(); |
|
| 2735 | - wp_safe_redirect( |
|
| 2736 | - add_query_arg( |
|
| 2737 | - array( |
|
| 2738 | - 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2739 | - ), |
|
| 2740 | - $this->checkout->thank_you_page_url |
|
| 2741 | - ) |
|
| 2742 | - ); |
|
| 2743 | - exit(); |
|
| 2744 | - } |
|
| 2745 | - |
|
| 2746 | - |
|
| 2747 | - /** |
|
| 2748 | - * _process_off_site_payment |
|
| 2749 | - * |
|
| 2750 | - * @access private |
|
| 2751 | - * @param \EE_Offsite_Gateway $gateway |
|
| 2752 | - * @return EE_Payment |
|
| 2753 | - * @throws EE_Error |
|
| 2754 | - * @throws InvalidArgumentException |
|
| 2755 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2756 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2757 | - */ |
|
| 2758 | - private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2759 | - { |
|
| 2760 | - try { |
|
| 2761 | - $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2762 | - // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2763 | - $this->set_handle_IPN_in_this_request( |
|
| 2764 | - $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2765 | - ); |
|
| 2766 | - if ($this->handle_IPN_in_this_request()) { |
|
| 2767 | - // get payment details and process results |
|
| 2768 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2769 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2770 | - $payment = $payment_processor->process_ipn( |
|
| 2771 | - $request_data, |
|
| 2772 | - $this->checkout->transaction, |
|
| 2773 | - $this->checkout->payment_method, |
|
| 2774 | - true, |
|
| 2775 | - false |
|
| 2776 | - ); |
|
| 2777 | - // $payment_source = 'process_ipn'; |
|
| 2778 | - } else { |
|
| 2779 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2780 | - // $payment_source = 'last_payment'; |
|
| 2781 | - } |
|
| 2782 | - } catch (Exception $e) { |
|
| 2783 | - // let's just eat the exception and try to move on using any previously set payment info |
|
| 2784 | - $payment = $this->checkout->transaction->last_payment(); |
|
| 2785 | - // $payment_source = 'last_payment after Exception'; |
|
| 2786 | - // but if we STILL don't have a payment object |
|
| 2787 | - if (! $payment instanceof EE_Payment) { |
|
| 2788 | - // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2789 | - $this->_handle_payment_processor_exception($e); |
|
| 2790 | - } |
|
| 2791 | - } |
|
| 2792 | - // DEBUG LOG |
|
| 2793 | - // $this->checkout->log( |
|
| 2794 | - // __CLASS__, |
|
| 2795 | - // __FUNCTION__, |
|
| 2796 | - // __LINE__, |
|
| 2797 | - // array( |
|
| 2798 | - // 'process_ipn_payment' => $payment, |
|
| 2799 | - // 'payment_source' => $payment_source, |
|
| 2800 | - // ) |
|
| 2801 | - // ); |
|
| 2802 | - return $payment; |
|
| 2803 | - } |
|
| 2804 | - |
|
| 2805 | - |
|
| 2806 | - /** |
|
| 2807 | - * _process_cancelled_payments |
|
| 2808 | - * just makes sure that the payment status gets updated correctly |
|
| 2809 | - * so tha tan error isn't generated during payment validation |
|
| 2810 | - * |
|
| 2811 | - * @access private |
|
| 2812 | - * @param EE_Payment $payment |
|
| 2813 | - * @return EE_Payment | FALSE |
|
| 2814 | - * @throws \EE_Error |
|
| 2815 | - */ |
|
| 2816 | - private function _process_cancelled_payments($payment = null) |
|
| 2817 | - { |
|
| 2818 | - if ($payment instanceof EE_Payment |
|
| 2819 | - && isset($_REQUEST['ee_cancel_payment']) |
|
| 2820 | - && $payment->status() === EEM_Payment::status_id_failed |
|
| 2821 | - ) { |
|
| 2822 | - $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2823 | - } |
|
| 2824 | - return $payment; |
|
| 2825 | - } |
|
| 2826 | - |
|
| 2827 | - |
|
| 2828 | - /** |
|
| 2829 | - * get_transaction_details_for_gateways |
|
| 2830 | - * |
|
| 2831 | - * @access public |
|
| 2832 | - * @return int |
|
| 2833 | - * @throws EE_Error |
|
| 2834 | - * @throws InvalidArgumentException |
|
| 2835 | - * @throws ReflectionException |
|
| 2836 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2837 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2838 | - */ |
|
| 2839 | - public function get_transaction_details_for_gateways() |
|
| 2840 | - { |
|
| 2841 | - $txn_details = array(); |
|
| 2842 | - // ya gotta make a choice man |
|
| 2843 | - if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2844 | - $txn_details = array( |
|
| 2845 | - 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2846 | - ); |
|
| 2847 | - } |
|
| 2848 | - // get EE_Payment_Method object |
|
| 2849 | - if (empty($txn_details) |
|
| 2850 | - && |
|
| 2851 | - ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2852 | - ) { |
|
| 2853 | - $txn_details = array( |
|
| 2854 | - 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2855 | - 'error' => esc_html__( |
|
| 2856 | - 'A valid Payment Method could not be determined.', |
|
| 2857 | - 'event_espresso' |
|
| 2858 | - ), |
|
| 2859 | - ); |
|
| 2860 | - } |
|
| 2861 | - if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2862 | - $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2863 | - $txn_details = array( |
|
| 2864 | - 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2865 | - 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2866 | - 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2867 | - 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2868 | - 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2869 | - 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2870 | - 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2871 | - 'payment_amount' => $this->checkout->amount_owing, |
|
| 2872 | - 'return_url' => $return_url, |
|
| 2873 | - 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2874 | - 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2875 | - array( |
|
| 2876 | - 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2877 | - 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2878 | - ) |
|
| 2879 | - ), |
|
| 2880 | - ); |
|
| 2881 | - } |
|
| 2882 | - echo wp_json_encode($txn_details); |
|
| 2883 | - exit(); |
|
| 2884 | - } |
|
| 2885 | - |
|
| 2886 | - |
|
| 2887 | - /** |
|
| 2888 | - * __sleep |
|
| 2889 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2890 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2891 | - * reg form, because if needed, it will be regenerated anyways |
|
| 2892 | - * |
|
| 2893 | - * @return array |
|
| 2894 | - */ |
|
| 2895 | - public function __sleep() |
|
| 2896 | - { |
|
| 2897 | - // remove the reg form and the checkout |
|
| 2898 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2899 | - } |
|
| 15 | + /** |
|
| 16 | + * @access protected |
|
| 17 | + * @var EE_Line_Item_Display $Line_Item_Display |
|
| 18 | + */ |
|
| 19 | + protected $line_item_display; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @access protected |
|
| 23 | + * @var boolean $handle_IPN_in_this_request |
|
| 24 | + */ |
|
| 25 | + protected $handle_IPN_in_this_request = false; |
|
| 26 | + |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 30 | + * |
|
| 31 | + * @access public |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_filter( |
|
| 37 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 38 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
| 39 | + ); |
|
| 40 | + add_action( |
|
| 41 | + 'wp_ajax_switch_spco_billing_form', |
|
| 42 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 43 | + ); |
|
| 44 | + add_action( |
|
| 45 | + 'wp_ajax_nopriv_switch_spco_billing_form', |
|
| 46 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
| 47 | + ); |
|
| 48 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
| 49 | + add_action( |
|
| 50 | + 'wp_ajax_nopriv_save_payer_details', |
|
| 51 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
| 52 | + ); |
|
| 53 | + add_action( |
|
| 54 | + 'wp_ajax_get_transaction_details_for_gateways', |
|
| 55 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 56 | + ); |
|
| 57 | + add_action( |
|
| 58 | + 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
|
| 59 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
| 60 | + ); |
|
| 61 | + add_filter( |
|
| 62 | + 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
|
| 63 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
| 64 | + 10, |
|
| 65 | + 1 |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * ajax switch_spco_billing_form |
|
| 72 | + * |
|
| 73 | + * @throws \EE_Error |
|
| 74 | + */ |
|
| 75 | + public static function switch_spco_billing_form() |
|
| 76 | + { |
|
| 77 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * ajax save_payer_details |
|
| 83 | + * |
|
| 84 | + * @throws \EE_Error |
|
| 85 | + */ |
|
| 86 | + public static function save_payer_details() |
|
| 87 | + { |
|
| 88 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * ajax get_transaction_details |
|
| 94 | + * |
|
| 95 | + * @throws \EE_Error |
|
| 96 | + */ |
|
| 97 | + public static function get_transaction_details() |
|
| 98 | + { |
|
| 99 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * bypass_recaptcha_for_load_payment_method |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @return array |
|
| 108 | + * @throws InvalidArgumentException |
|
| 109 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 110 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 111 | + */ |
|
| 112 | + public static function bypass_recaptcha_for_load_payment_method() |
|
| 113 | + { |
|
| 114 | + return array( |
|
| 115 | + 'EESID' => EE_Registry::instance()->SSN->id(), |
|
| 116 | + 'step' => 'payment_options', |
|
| 117 | + 'action' => 'spco_billing_form', |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * class constructor |
|
| 124 | + * |
|
| 125 | + * @access public |
|
| 126 | + * @param EE_Checkout $checkout |
|
| 127 | + */ |
|
| 128 | + public function __construct(EE_Checkout $checkout) |
|
| 129 | + { |
|
| 130 | + $this->_slug = 'payment_options'; |
|
| 131 | + $this->_name = esc_html__('Payment Options', 'event_espresso'); |
|
| 132 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
| 133 | + $this->checkout = $checkout; |
|
| 134 | + $this->_reset_success_message(); |
|
| 135 | + $this->set_instructions( |
|
| 136 | + esc_html__( |
|
| 137 | + 'Please select a method of payment and provide any necessary billing information before proceeding.', |
|
| 138 | + 'event_espresso' |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @return null |
|
| 146 | + */ |
|
| 147 | + public function line_item_display() |
|
| 148 | + { |
|
| 149 | + return $this->line_item_display; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param null $line_item_display |
|
| 155 | + */ |
|
| 156 | + public function set_line_item_display($line_item_display) |
|
| 157 | + { |
|
| 158 | + $this->line_item_display = $line_item_display; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return boolean |
|
| 164 | + */ |
|
| 165 | + public function handle_IPN_in_this_request() |
|
| 166 | + { |
|
| 167 | + return $this->handle_IPN_in_this_request; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param boolean $handle_IPN_in_this_request |
|
| 173 | + */ |
|
| 174 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) |
|
| 175 | + { |
|
| 176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * translate_js_strings |
|
| 182 | + * |
|
| 183 | + * @return void |
|
| 184 | + */ |
|
| 185 | + public function translate_js_strings() |
|
| 186 | + { |
|
| 187 | + EE_Registry::$i18n_js_strings['no_payment_method'] = esc_html__( |
|
| 188 | + 'Please select a method of payment in order to continue.', |
|
| 189 | + 'event_espresso' |
|
| 190 | + ); |
|
| 191 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__( |
|
| 192 | + 'A valid method of payment could not be determined. Please refresh the page and try again.', |
|
| 193 | + 'event_espresso' |
|
| 194 | + ); |
|
| 195 | + EE_Registry::$i18n_js_strings['forwarding_to_offsite'] = esc_html__( |
|
| 196 | + 'Forwarding to Secure Payment Provider.', |
|
| 197 | + 'event_espresso' |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * enqueue_styles_and_scripts |
|
| 204 | + * |
|
| 205 | + * @return void |
|
| 206 | + * @throws EE_Error |
|
| 207 | + * @throws InvalidArgumentException |
|
| 208 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 209 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 210 | + */ |
|
| 211 | + public function enqueue_styles_and_scripts() |
|
| 212 | + { |
|
| 213 | + $transaction = $this->checkout->transaction; |
|
| 214 | + // if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
|
| 215 | + if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
| 216 | + return; |
|
| 217 | + } |
|
| 218 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 219 | + $transaction, |
|
| 220 | + EEM_Payment_Method::scope_cart |
|
| 221 | + ) as $payment_method) { |
|
| 222 | + $type_obj = $payment_method->type_obj(); |
|
| 223 | + if ($type_obj instanceof EE_PMT_Base) { |
|
| 224 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
| 225 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 226 | + $billing_form->enqueue_js(); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * initialize_reg_step |
|
| 235 | + * |
|
| 236 | + * @return bool |
|
| 237 | + * @throws EE_Error |
|
| 238 | + * @throws InvalidArgumentException |
|
| 239 | + * @throws ReflectionException |
|
| 240 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 241 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 242 | + */ |
|
| 243 | + public function initialize_reg_step() |
|
| 244 | + { |
|
| 245 | + // TODO: if /when we implement donations, then this will need overriding |
|
| 246 | + if (// don't need payment options for: |
|
| 247 | + // registrations made via the admin |
|
| 248 | + // completed transactions |
|
| 249 | + // overpaid transactions |
|
| 250 | + // $ 0.00 transactions(no payment required) |
|
| 251 | + ! $this->checkout->payment_required() |
|
| 252 | + // but do NOT remove if current action being called belongs to this reg step |
|
| 253 | + && ! is_callable(array($this, $this->checkout->action)) |
|
| 254 | + && ! $this->completed() |
|
| 255 | + ) { |
|
| 256 | + // and if so, then we no longer need the Payment Options step |
|
| 257 | + if ($this->is_current_step()) { |
|
| 258 | + $this->checkout->generate_reg_form = false; |
|
| 259 | + } |
|
| 260 | + $this->checkout->remove_reg_step($this->_slug); |
|
| 261 | + // DEBUG LOG |
|
| 262 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + // load EEM_Payment_Method |
|
| 266 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 267 | + // get all active payment methods |
|
| 268 | + $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
|
| 269 | + $this->checkout->transaction, |
|
| 270 | + EEM_Payment_Method::scope_cart |
|
| 271 | + ); |
|
| 272 | + return true; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @return EE_Form_Section_Proper |
|
| 278 | + * @throws EE_Error |
|
| 279 | + * @throws InvalidArgumentException |
|
| 280 | + * @throws ReflectionException |
|
| 281 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 282 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 283 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 284 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 285 | + */ |
|
| 286 | + public function generate_reg_form() |
|
| 287 | + { |
|
| 288 | + // reset in case someone changes their mind |
|
| 289 | + $this->_reset_selected_method_of_payment(); |
|
| 290 | + // set some defaults |
|
| 291 | + $this->checkout->selected_method_of_payment = 'payments_closed'; |
|
| 292 | + $registrations_requiring_payment = array(); |
|
| 293 | + $registrations_for_free_events = array(); |
|
| 294 | + $registrations_requiring_pre_approval = array(); |
|
| 295 | + $sold_out_events = array(); |
|
| 296 | + $insufficient_spaces_available = array(); |
|
| 297 | + $no_payment_required = true; |
|
| 298 | + // loop thru registrations to gather info |
|
| 299 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 300 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 301 | + $registrations, |
|
| 302 | + $this->checkout->revisit |
|
| 303 | + ); |
|
| 304 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 305 | + /** @var $registration EE_Registration */ |
|
| 306 | + // has this registration lost it's space ? |
|
| 307 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 308 | + if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) { |
|
| 309 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 310 | + } else { |
|
| 311 | + $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
| 312 | + } |
|
| 313 | + continue; |
|
| 314 | + } |
|
| 315 | + // event requires admin approval |
|
| 316 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
| 317 | + // add event to list of events with pre-approval reg status |
|
| 318 | + $registrations_requiring_pre_approval[ $REG_ID ] = $registration; |
|
| 319 | + do_action( |
|
| 320 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
| 321 | + $registration->event(), |
|
| 322 | + $this |
|
| 323 | + ); |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + if ($this->checkout->revisit |
|
| 327 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 328 | + && ( |
|
| 329 | + $registration->event()->is_sold_out() |
|
| 330 | + || $registration->event()->is_sold_out(true) |
|
| 331 | + ) |
|
| 332 | + ) { |
|
| 333 | + // add event to list of events that are sold out |
|
| 334 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
| 335 | + do_action( |
|
| 336 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
| 337 | + $registration->event(), |
|
| 338 | + $this |
|
| 339 | + ); |
|
| 340 | + continue; |
|
| 341 | + } |
|
| 342 | + // are they allowed to pay now and is there monies owing? |
|
| 343 | + if ($registration->owes_monies_and_can_pay()) { |
|
| 344 | + $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
| 345 | + do_action( |
|
| 346 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
|
| 347 | + $registration->event(), |
|
| 348 | + $this |
|
| 349 | + ); |
|
| 350 | + } elseif (! $this->checkout->revisit |
|
| 351 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 352 | + && $registration->ticket()->is_free() |
|
| 353 | + ) { |
|
| 354 | + $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $subsections = array(); |
|
| 358 | + // now decide which template to load |
|
| 359 | + if (! empty($sold_out_events)) { |
|
| 360 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
| 361 | + } |
|
| 362 | + if (! empty($insufficient_spaces_available)) { |
|
| 363 | + $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
|
| 364 | + $insufficient_spaces_available |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + if (! empty($registrations_requiring_pre_approval)) { |
|
| 368 | + $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
|
| 369 | + $registrations_requiring_pre_approval |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + if (! empty($registrations_for_free_events)) { |
|
| 373 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
| 374 | + } |
|
| 375 | + if (! empty($registrations_requiring_payment)) { |
|
| 376 | + if ($this->checkout->amount_owing > 0) { |
|
| 377 | + // autoload Line_Item_Display classes |
|
| 378 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 379 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 380 | + apply_filters( |
|
| 381 | + 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
|
| 382 | + new EE_Line_Item_Filter_Collection() |
|
| 383 | + ), |
|
| 384 | + $this->checkout->cart->get_grand_total() |
|
| 385 | + ); |
|
| 386 | + /** @var EE_Line_Item $filtered_line_item_tree */ |
|
| 387 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 388 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 389 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
| 390 | + $subsections['payment_options'] = $this->_display_payment_options( |
|
| 391 | + $this->line_item_display->display_line_item( |
|
| 392 | + $filtered_line_item_tree, |
|
| 393 | + array('registrations' => $registrations) |
|
| 394 | + ) |
|
| 395 | + ); |
|
| 396 | + $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
|
| 397 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
| 398 | + } |
|
| 399 | + $no_payment_required = false; |
|
| 400 | + } else { |
|
| 401 | + $this->_hide_reg_step_submit_button_if_revisit(); |
|
| 402 | + } |
|
| 403 | + $this->_save_selected_method_of_payment(); |
|
| 404 | + |
|
| 405 | + $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
|
| 406 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
| 407 | + |
|
| 408 | + return new EE_Form_Section_Proper( |
|
| 409 | + array( |
|
| 410 | + 'name' => $this->reg_form_name(), |
|
| 411 | + 'html_id' => $this->reg_form_name(), |
|
| 412 | + 'subsections' => $subsections, |
|
| 413 | + 'layout_strategy' => new EE_No_Layout(), |
|
| 414 | + ) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * add line item filters required for this reg step |
|
| 421 | + * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks(): |
|
| 422 | + * add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options', |
|
| 423 | + * 'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the |
|
| 424 | + * payment options reg step, can apply these filters via the following: apply_filters( |
|
| 425 | + * 'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing |
|
| 426 | + * filter collection by passing that instead of instantiating a new collection |
|
| 427 | + * |
|
| 428 | + * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection |
|
| 429 | + * @return EE_Line_Item_Filter_Collection |
|
| 430 | + * @throws EE_Error |
|
| 431 | + * @throws InvalidArgumentException |
|
| 432 | + * @throws ReflectionException |
|
| 433 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 434 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 435 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 436 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 437 | + */ |
|
| 438 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) |
|
| 439 | + { |
|
| 440 | + if (! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 441 | + return $line_item_filter_collection; |
|
| 442 | + } |
|
| 443 | + if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
| 444 | + return $line_item_filter_collection; |
|
| 445 | + } |
|
| 446 | + if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
| 447 | + return $line_item_filter_collection; |
|
| 448 | + } |
|
| 449 | + $line_item_filter_collection->add( |
|
| 450 | + new EE_Billable_Line_Item_Filter( |
|
| 451 | + EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
|
| 452 | + EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 453 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 454 | + ) |
|
| 455 | + ) |
|
| 456 | + ) |
|
| 457 | + ); |
|
| 458 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 459 | + return $line_item_filter_collection; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * remove_ejected_registrations |
|
| 465 | + * if a registrant has lost their potential space at an event due to lack of payment, |
|
| 466 | + * then this method removes them from the list of registrations being paid for during this request |
|
| 467 | + * |
|
| 468 | + * @param \EE_Registration[] $registrations |
|
| 469 | + * @return EE_Registration[] |
|
| 470 | + * @throws EE_Error |
|
| 471 | + * @throws InvalidArgumentException |
|
| 472 | + * @throws ReflectionException |
|
| 473 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 474 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 475 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 476 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 477 | + */ |
|
| 478 | + public static function remove_ejected_registrations(array $registrations) |
|
| 479 | + { |
|
| 480 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 481 | + $registrations, |
|
| 482 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 483 | + ); |
|
| 484 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 485 | + // has this registration lost it's space ? |
|
| 486 | + if (isset($ejected_registrations[ $REG_ID ])) { |
|
| 487 | + unset($registrations[ $REG_ID ]); |
|
| 488 | + continue; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + return $registrations; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * find_registrations_that_lost_their_space |
|
| 497 | + * If a registrant chooses an offline payment method like Invoice, |
|
| 498 | + * then no space is reserved for them at the event until they fully pay fo that site |
|
| 499 | + * (unless the event's default reg status is set to APPROVED) |
|
| 500 | + * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales, |
|
| 501 | + * then this method will determine which registrations have lost the ability to complete the reg process. |
|
| 502 | + * |
|
| 503 | + * @param \EE_Registration[] $registrations |
|
| 504 | + * @param bool $revisit |
|
| 505 | + * @return array |
|
| 506 | + * @throws EE_Error |
|
| 507 | + * @throws InvalidArgumentException |
|
| 508 | + * @throws ReflectionException |
|
| 509 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 510 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 511 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 512 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 513 | + */ |
|
| 514 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) |
|
| 515 | + { |
|
| 516 | + // registrations per event |
|
| 517 | + $event_reg_count = array(); |
|
| 518 | + // spaces left per event |
|
| 519 | + $event_spaces_remaining = array(); |
|
| 520 | + // tickets left sorted by ID |
|
| 521 | + $tickets_remaining = array(); |
|
| 522 | + // registrations that have lost their space |
|
| 523 | + $ejected_registrations = array(); |
|
| 524 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 525 | + if ($registration->status_ID() === EEM_Registration::status_id_approved |
|
| 526 | + || apply_filters( |
|
| 527 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
| 528 | + false, |
|
| 529 | + $registration, |
|
| 530 | + $revisit |
|
| 531 | + ) |
|
| 532 | + ) { |
|
| 533 | + continue; |
|
| 534 | + } |
|
| 535 | + $EVT_ID = $registration->event_ID(); |
|
| 536 | + $ticket = $registration->ticket(); |
|
| 537 | + if (! isset($tickets_remaining[ $ticket->ID() ])) { |
|
| 538 | + $tickets_remaining[ $ticket->ID() ] = $ticket->remaining(); |
|
| 539 | + } |
|
| 540 | + if ($tickets_remaining[ $ticket->ID() ] > 0) { |
|
| 541 | + if (! isset($event_reg_count[ $EVT_ID ])) { |
|
| 542 | + $event_reg_count[ $EVT_ID ] = 0; |
|
| 543 | + } |
|
| 544 | + $event_reg_count[ $EVT_ID ]++; |
|
| 545 | + if (! isset($event_spaces_remaining[ $EVT_ID ])) { |
|
| 546 | + $event_spaces_remaining[ $EVT_ID ] = $registration->event()->spaces_remaining_for_sale(); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + if ($revisit |
|
| 550 | + && ($tickets_remaining[ $ticket->ID() ] === 0 |
|
| 551 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
| 552 | + ) |
|
| 553 | + ) { |
|
| 554 | + $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
| 555 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
| 556 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 557 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 558 | + // at this point, we should have enough details about the registrant to consider the registration |
|
| 559 | + // NOT incomplete |
|
| 560 | + $registration_processor->manually_update_registration_status( |
|
| 561 | + $registration, |
|
| 562 | + EEM_Registration::status_id_wait_list |
|
| 563 | + ); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + return $ejected_registrations; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * _hide_reg_step_submit_button |
|
| 573 | + * removes the html for the reg step submit button |
|
| 574 | + * by replacing it with an empty string via filter callback |
|
| 575 | + * |
|
| 576 | + * @return void |
|
| 577 | + */ |
|
| 578 | + protected function _adjust_registration_status_if_event_old_sold() |
|
| 579 | + { |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * _hide_reg_step_submit_button |
|
| 585 | + * removes the html for the reg step submit button |
|
| 586 | + * by replacing it with an empty string via filter callback |
|
| 587 | + * |
|
| 588 | + * @return void |
|
| 589 | + */ |
|
| 590 | + protected function _hide_reg_step_submit_button_if_revisit() |
|
| 591 | + { |
|
| 592 | + if ($this->checkout->revisit) { |
|
| 593 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * sold_out_events |
|
| 600 | + * displays notices regarding events that have sold out since hte registrant first signed up |
|
| 601 | + * |
|
| 602 | + * @param \EE_Event[] $sold_out_events_array |
|
| 603 | + * @return \EE_Form_Section_Proper |
|
| 604 | + * @throws \EE_Error |
|
| 605 | + */ |
|
| 606 | + private function _sold_out_events($sold_out_events_array = array()) |
|
| 607 | + { |
|
| 608 | + // set some defaults |
|
| 609 | + $this->checkout->selected_method_of_payment = 'events_sold_out'; |
|
| 610 | + $sold_out_events = ''; |
|
| 611 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
| 612 | + $sold_out_events .= EEH_HTML::li( |
|
| 613 | + EEH_HTML::span( |
|
| 614 | + ' ' . $sold_out_event->name(), |
|
| 615 | + '', |
|
| 616 | + 'dashicons dashicons-marker ee-icon-size-16 pink-text' |
|
| 617 | + ) |
|
| 618 | + ); |
|
| 619 | + } |
|
| 620 | + return new EE_Form_Section_Proper( |
|
| 621 | + array( |
|
| 622 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 623 | + array( |
|
| 624 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 625 | + . $this->_slug |
|
| 626 | + . DS |
|
| 627 | + . 'sold_out_events.template.php', |
|
| 628 | + 'template_args' => apply_filters( |
|
| 629 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 630 | + array( |
|
| 631 | + 'sold_out_events' => $sold_out_events, |
|
| 632 | + 'sold_out_events_msg' => apply_filters( |
|
| 633 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
|
| 634 | + sprintf( |
|
| 635 | + esc_html__( |
|
| 636 | + 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$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.%2$s', |
|
| 637 | + 'event_espresso' |
|
| 638 | + ), |
|
| 639 | + '<strong>', |
|
| 640 | + '</strong>', |
|
| 641 | + '<br />' |
|
| 642 | + ) |
|
| 643 | + ), |
|
| 644 | + ) |
|
| 645 | + ), |
|
| 646 | + ) |
|
| 647 | + ), |
|
| 648 | + ) |
|
| 649 | + ); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * _insufficient_spaces_available |
|
| 655 | + * displays notices regarding events that do not have enough remaining spaces |
|
| 656 | + * to satisfy the current number of registrations looking to pay |
|
| 657 | + * |
|
| 658 | + * @param \EE_Event[] $insufficient_spaces_events_array |
|
| 659 | + * @return \EE_Form_Section_Proper |
|
| 660 | + * @throws \EE_Error |
|
| 661 | + */ |
|
| 662 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) |
|
| 663 | + { |
|
| 664 | + // set some defaults |
|
| 665 | + $this->checkout->selected_method_of_payment = 'invoice'; |
|
| 666 | + $insufficient_space_events = ''; |
|
| 667 | + foreach ($insufficient_spaces_events_array as $event) { |
|
| 668 | + if ($event instanceof EE_Event) { |
|
| 669 | + $insufficient_space_events .= EEH_HTML::li( |
|
| 670 | + EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
| 671 | + ); |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + return new EE_Form_Section_Proper( |
|
| 675 | + array( |
|
| 676 | + 'subsections' => array( |
|
| 677 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 678 | + 'extra_hidden_inputs' => $this->_extra_hidden_inputs(), |
|
| 679 | + ), |
|
| 680 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 681 | + array( |
|
| 682 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 683 | + . $this->_slug |
|
| 684 | + . DS |
|
| 685 | + . 'sold_out_events.template.php', |
|
| 686 | + 'template_args' => apply_filters( |
|
| 687 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
|
| 688 | + array( |
|
| 689 | + 'sold_out_events' => $insufficient_space_events, |
|
| 690 | + 'sold_out_events_msg' => apply_filters( |
|
| 691 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg', |
|
| 692 | + esc_html__( |
|
| 693 | + 'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 694 | + 'event_espresso' |
|
| 695 | + ) |
|
| 696 | + ), |
|
| 697 | + ) |
|
| 698 | + ), |
|
| 699 | + ) |
|
| 700 | + ), |
|
| 701 | + ) |
|
| 702 | + ); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + /** |
|
| 707 | + * registrations_requiring_pre_approval |
|
| 708 | + * |
|
| 709 | + * @param array $registrations_requiring_pre_approval |
|
| 710 | + * @return EE_Form_Section_Proper |
|
| 711 | + * @throws EE_Error |
|
| 712 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 713 | + */ |
|
| 714 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) |
|
| 715 | + { |
|
| 716 | + $events_requiring_pre_approval = ''; |
|
| 717 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
| 718 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
| 719 | + $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
| 720 | + EEH_HTML::span( |
|
| 721 | + '', |
|
| 722 | + '', |
|
| 723 | + 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
|
| 724 | + ) |
|
| 725 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
| 726 | + ); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + return new EE_Form_Section_Proper( |
|
| 730 | + array( |
|
| 731 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 732 | + array( |
|
| 733 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 734 | + . $this->_slug |
|
| 735 | + . DS |
|
| 736 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
| 737 | + 'template_args' => apply_filters( |
|
| 738 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
|
| 739 | + array( |
|
| 740 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
| 741 | + 'events_requiring_pre_approval_msg' => apply_filters( |
|
| 742 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
|
| 743 | + esc_html__( |
|
| 744 | + 'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
| 745 | + 'event_espresso' |
|
| 746 | + ) |
|
| 747 | + ), |
|
| 748 | + ) |
|
| 749 | + ), |
|
| 750 | + ) |
|
| 751 | + ), |
|
| 752 | + ) |
|
| 753 | + ); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + /** |
|
| 758 | + * _no_payment_required |
|
| 759 | + * |
|
| 760 | + * @param \EE_Event[] $registrations_for_free_events |
|
| 761 | + * @return \EE_Form_Section_Proper |
|
| 762 | + * @throws \EE_Error |
|
| 763 | + */ |
|
| 764 | + private function _no_payment_required($registrations_for_free_events = array()) |
|
| 765 | + { |
|
| 766 | + // set some defaults |
|
| 767 | + $this->checkout->selected_method_of_payment = 'no_payment_required'; |
|
| 768 | + // generate no_payment_required form |
|
| 769 | + return new EE_Form_Section_Proper( |
|
| 770 | + array( |
|
| 771 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 772 | + array( |
|
| 773 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 774 | + . $this->_slug |
|
| 775 | + . DS |
|
| 776 | + . 'no_payment_required.template.php', // layout_template |
|
| 777 | + 'template_args' => apply_filters( |
|
| 778 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
|
| 779 | + array( |
|
| 780 | + 'revisit' => $this->checkout->revisit, |
|
| 781 | + 'registrations' => array(), |
|
| 782 | + 'ticket_count' => array(), |
|
| 783 | + 'registrations_for_free_events' => $registrations_for_free_events, |
|
| 784 | + 'no_payment_required_msg' => EEH_HTML::p( |
|
| 785 | + esc_html__('This is a free event, so no billing will occur.', 'event_espresso') |
|
| 786 | + ), |
|
| 787 | + ) |
|
| 788 | + ), |
|
| 789 | + ) |
|
| 790 | + ), |
|
| 791 | + ) |
|
| 792 | + ); |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * _display_payment_options |
|
| 798 | + * |
|
| 799 | + * @param string $transaction_details |
|
| 800 | + * @return EE_Form_Section_Proper |
|
| 801 | + * @throws EE_Error |
|
| 802 | + * @throws InvalidArgumentException |
|
| 803 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 804 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 805 | + */ |
|
| 806 | + private function _display_payment_options($transaction_details = '') |
|
| 807 | + { |
|
| 808 | + // has method_of_payment been set by no-js user? |
|
| 809 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
|
| 810 | + // build payment options form |
|
| 811 | + return apply_filters( |
|
| 812 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form', |
|
| 813 | + new EE_Form_Section_Proper( |
|
| 814 | + array( |
|
| 815 | + 'subsections' => array( |
|
| 816 | + 'before_payment_options' => apply_filters( |
|
| 817 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
|
| 818 | + new EE_Form_Section_Proper( |
|
| 819 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 820 | + ) |
|
| 821 | + ), |
|
| 822 | + 'payment_options' => $this->_setup_payment_options(), |
|
| 823 | + 'after_payment_options' => apply_filters( |
|
| 824 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
|
| 825 | + new EE_Form_Section_Proper( |
|
| 826 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
| 827 | + ) |
|
| 828 | + ), |
|
| 829 | + ), |
|
| 830 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 831 | + array( |
|
| 832 | + 'layout_template_file' => $this->_template, |
|
| 833 | + 'template_args' => apply_filters( |
|
| 834 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args', |
|
| 835 | + array( |
|
| 836 | + 'reg_count' => $this->line_item_display->total_items(), |
|
| 837 | + 'transaction_details' => $transaction_details, |
|
| 838 | + 'available_payment_methods' => array(), |
|
| 839 | + ) |
|
| 840 | + ), |
|
| 841 | + ) |
|
| 842 | + ), |
|
| 843 | + ) |
|
| 844 | + ) |
|
| 845 | + ); |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * _extra_hidden_inputs |
|
| 851 | + * |
|
| 852 | + * @param bool $no_payment_required |
|
| 853 | + * @return \EE_Form_Section_Proper |
|
| 854 | + * @throws \EE_Error |
|
| 855 | + */ |
|
| 856 | + private function _extra_hidden_inputs($no_payment_required = true) |
|
| 857 | + { |
|
| 858 | + return new EE_Form_Section_Proper( |
|
| 859 | + array( |
|
| 860 | + 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
| 861 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 862 | + 'subsections' => array( |
|
| 863 | + 'spco_no_payment_required' => new EE_Hidden_Input( |
|
| 864 | + array( |
|
| 865 | + 'normalization_strategy' => new EE_Boolean_Normalization(), |
|
| 866 | + 'html_name' => 'spco_no_payment_required', |
|
| 867 | + 'html_id' => 'spco-no-payment-required-payment_options', |
|
| 868 | + 'default' => $no_payment_required, |
|
| 869 | + ) |
|
| 870 | + ), |
|
| 871 | + 'spco_transaction_id' => new EE_Fixed_Hidden_Input( |
|
| 872 | + array( |
|
| 873 | + 'normalization_strategy' => new EE_Int_Normalization(), |
|
| 874 | + 'html_name' => 'spco_transaction_id', |
|
| 875 | + 'html_id' => 'spco-transaction-id', |
|
| 876 | + 'default' => $this->checkout->transaction->ID(), |
|
| 877 | + ) |
|
| 878 | + ), |
|
| 879 | + ), |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * _apply_registration_payments_to_amount_owing |
|
| 887 | + * |
|
| 888 | + * @access protected |
|
| 889 | + * @param array $registrations |
|
| 890 | + * @throws EE_Error |
|
| 891 | + */ |
|
| 892 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) |
|
| 893 | + { |
|
| 894 | + $payments = array(); |
|
| 895 | + foreach ($registrations as $registration) { |
|
| 896 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
| 897 | + $payments += $registration->registration_payments(); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + if (! empty($payments)) { |
|
| 901 | + foreach ($payments as $payment) { |
|
| 902 | + if ($payment instanceof EE_Registration_Payment) { |
|
| 903 | + $this->checkout->amount_owing -= $payment->amount(); |
|
| 904 | + } |
|
| 905 | + } |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * _reset_selected_method_of_payment |
|
| 912 | + * |
|
| 913 | + * @access private |
|
| 914 | + * @param bool $force_reset |
|
| 915 | + * @return void |
|
| 916 | + * @throws InvalidArgumentException |
|
| 917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | + */ |
|
| 920 | + private function _reset_selected_method_of_payment($force_reset = false) |
|
| 921 | + { |
|
| 922 | + $reset_payment_method = $force_reset |
|
| 923 | + ? true |
|
| 924 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
| 925 | + if ($reset_payment_method) { |
|
| 926 | + $this->checkout->selected_method_of_payment = null; |
|
| 927 | + $this->checkout->payment_method = null; |
|
| 928 | + $this->checkout->billing_form = null; |
|
| 929 | + $this->_save_selected_method_of_payment(); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + |
|
| 934 | + /** |
|
| 935 | + * _save_selected_method_of_payment |
|
| 936 | + * stores the selected_method_of_payment in the session |
|
| 937 | + * so that it's available for all subsequent requests including AJAX |
|
| 938 | + * |
|
| 939 | + * @access private |
|
| 940 | + * @param string $selected_method_of_payment |
|
| 941 | + * @return void |
|
| 942 | + * @throws InvalidArgumentException |
|
| 943 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 944 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 945 | + */ |
|
| 946 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') |
|
| 947 | + { |
|
| 948 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
| 949 | + ? $selected_method_of_payment |
|
| 950 | + : $this->checkout->selected_method_of_payment; |
|
| 951 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 952 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
| 953 | + ); |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + |
|
| 957 | + /** |
|
| 958 | + * _setup_payment_options |
|
| 959 | + * |
|
| 960 | + * @return EE_Form_Section_Proper |
|
| 961 | + * @throws EE_Error |
|
| 962 | + * @throws InvalidArgumentException |
|
| 963 | + * @throws ReflectionException |
|
| 964 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 965 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 966 | + */ |
|
| 967 | + public function _setup_payment_options() |
|
| 968 | + { |
|
| 969 | + // load payment method classes |
|
| 970 | + $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
|
| 971 | + if (empty($this->checkout->available_payment_methods)) { |
|
| 972 | + EE_Error::add_error( |
|
| 973 | + apply_filters( |
|
| 974 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods', |
|
| 975 | + sprintf( |
|
| 976 | + esc_html__( |
|
| 977 | + 'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.', |
|
| 978 | + 'event_espresso' |
|
| 979 | + ), |
|
| 980 | + '<br>', |
|
| 981 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 982 | + ) |
|
| 983 | + ), |
|
| 984 | + __FILE__, |
|
| 985 | + __FUNCTION__, |
|
| 986 | + __LINE__ |
|
| 987 | + ); |
|
| 988 | + } |
|
| 989 | + // switch up header depending on number of available payment methods |
|
| 990 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
| 991 | + ? apply_filters( |
|
| 992 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 993 | + esc_html__('Please Select Your Method of Payment', 'event_espresso') |
|
| 994 | + ) |
|
| 995 | + : apply_filters( |
|
| 996 | + 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
|
| 997 | + esc_html__('Method of Payment', 'event_espresso') |
|
| 998 | + ); |
|
| 999 | + $available_payment_methods = array( |
|
| 1000 | + // display the "Payment Method" header |
|
| 1001 | + 'payment_method_header' => new EE_Form_Section_HTML( |
|
| 1002 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
| 1003 | + ), |
|
| 1004 | + ); |
|
| 1005 | + // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
|
| 1006 | + $available_payment_method_options = array(); |
|
| 1007 | + $default_payment_method_option = array(); |
|
| 1008 | + // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
|
| 1009 | + $payment_methods_billing_info = array( |
|
| 1010 | + new EE_Form_Section_HTML( |
|
| 1011 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
| 1012 | + ), |
|
| 1013 | + ); |
|
| 1014 | + // loop through payment methods |
|
| 1015 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
| 1016 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1017 | + $payment_method_button = EEH_HTML::img( |
|
| 1018 | + $payment_method->button_url(), |
|
| 1019 | + $payment_method->name(), |
|
| 1020 | + 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
| 1021 | + 'spco-payment-method-btn-img' |
|
| 1022 | + ); |
|
| 1023 | + // check if any payment methods are set as default |
|
| 1024 | + // if payment method is already selected OR nothing is selected and this payment method should be |
|
| 1025 | + // open_by_default |
|
| 1026 | + if (($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
| 1027 | + || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
| 1028 | + ) { |
|
| 1029 | + $this->checkout->selected_method_of_payment = $payment_method->slug(); |
|
| 1030 | + $this->_save_selected_method_of_payment(); |
|
| 1031 | + $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
| 1032 | + } else { |
|
| 1033 | + $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
| 1034 | + } |
|
| 1035 | + $payment_methods_billing_info[ $payment_method->slug( |
|
| 1036 | + ) . '-info' ] = $this->_payment_method_billing_info( |
|
| 1037 | + $payment_method |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + // prepend available_payment_method_options with default_payment_method_option so that it appears first in list |
|
| 1042 | + // of PMs |
|
| 1043 | + $available_payment_method_options = $default_payment_method_option + $available_payment_method_options; |
|
| 1044 | + // now generate the actual form inputs |
|
| 1045 | + $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs( |
|
| 1046 | + $available_payment_method_options |
|
| 1047 | + ); |
|
| 1048 | + $available_payment_methods += $payment_methods_billing_info; |
|
| 1049 | + // build the available payment methods form |
|
| 1050 | + return new EE_Form_Section_Proper( |
|
| 1051 | + array( |
|
| 1052 | + 'html_id' => 'spco-available-methods-of-payment-dv', |
|
| 1053 | + 'subsections' => $available_payment_methods, |
|
| 1054 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1055 | + ) |
|
| 1056 | + ); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * _get_available_payment_methods |
|
| 1062 | + * |
|
| 1063 | + * @return EE_Payment_Method[] |
|
| 1064 | + * @throws EE_Error |
|
| 1065 | + * @throws InvalidArgumentException |
|
| 1066 | + * @throws ReflectionException |
|
| 1067 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1068 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1069 | + */ |
|
| 1070 | + protected function _get_available_payment_methods() |
|
| 1071 | + { |
|
| 1072 | + if (! empty($this->checkout->available_payment_methods)) { |
|
| 1073 | + return $this->checkout->available_payment_methods; |
|
| 1074 | + } |
|
| 1075 | + $available_payment_methods = array(); |
|
| 1076 | + // load EEM_Payment_Method |
|
| 1077 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 1078 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 1079 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 1080 | + // get all active payment methods |
|
| 1081 | + $payment_methods = $EEM_Payment_Method->get_all_for_transaction( |
|
| 1082 | + $this->checkout->transaction, |
|
| 1083 | + EEM_Payment_Method::scope_cart |
|
| 1084 | + ); |
|
| 1085 | + foreach ($payment_methods as $payment_method) { |
|
| 1086 | + if ($payment_method instanceof EE_Payment_Method) { |
|
| 1087 | + $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | + return $available_payment_methods; |
|
| 1091 | + } |
|
| 1092 | + |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * _available_payment_method_inputs |
|
| 1096 | + * |
|
| 1097 | + * @access private |
|
| 1098 | + * @param array $available_payment_method_options |
|
| 1099 | + * @return \EE_Form_Section_Proper |
|
| 1100 | + */ |
|
| 1101 | + private function _available_payment_method_inputs($available_payment_method_options = array()) |
|
| 1102 | + { |
|
| 1103 | + // generate inputs |
|
| 1104 | + return new EE_Form_Section_Proper( |
|
| 1105 | + array( |
|
| 1106 | + 'html_id' => 'ee-available-payment-method-inputs', |
|
| 1107 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1108 | + 'subsections' => array( |
|
| 1109 | + '' => new EE_Radio_Button_Input( |
|
| 1110 | + $available_payment_method_options, |
|
| 1111 | + array( |
|
| 1112 | + 'html_name' => 'selected_method_of_payment', |
|
| 1113 | + 'html_class' => 'spco-payment-method', |
|
| 1114 | + 'default' => $this->checkout->selected_method_of_payment, |
|
| 1115 | + 'label_size' => 11, |
|
| 1116 | + 'enforce_label_size' => true, |
|
| 1117 | + ) |
|
| 1118 | + ), |
|
| 1119 | + ), |
|
| 1120 | + ) |
|
| 1121 | + ); |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * _payment_method_billing_info |
|
| 1127 | + * |
|
| 1128 | + * @access private |
|
| 1129 | + * @param EE_Payment_Method $payment_method |
|
| 1130 | + * @return EE_Form_Section_Proper |
|
| 1131 | + * @throws EE_Error |
|
| 1132 | + * @throws InvalidArgumentException |
|
| 1133 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1134 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1135 | + */ |
|
| 1136 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) |
|
| 1137 | + { |
|
| 1138 | + $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
|
| 1139 | + ? true |
|
| 1140 | + : false; |
|
| 1141 | + // generate the billing form for payment method |
|
| 1142 | + $billing_form = $currently_selected |
|
| 1143 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
| 1144 | + : new EE_Form_Section_HTML(); |
|
| 1145 | + $this->checkout->billing_form = $currently_selected |
|
| 1146 | + ? $billing_form |
|
| 1147 | + : $this->checkout->billing_form; |
|
| 1148 | + // it's all in the details |
|
| 1149 | + $info_html = EEH_HTML::h3( |
|
| 1150 | + esc_html__('Important information regarding your payment', 'event_espresso'), |
|
| 1151 | + '', |
|
| 1152 | + 'spco-payment-method-hdr' |
|
| 1153 | + ); |
|
| 1154 | + // add some info regarding the step, either from what's saved in the admin, |
|
| 1155 | + // or a default string depending on whether the PM has a billing form or not |
|
| 1156 | + if ($payment_method->description()) { |
|
| 1157 | + $payment_method_info = $payment_method->description(); |
|
| 1158 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1159 | + $payment_method_info = sprintf( |
|
| 1160 | + esc_html__( |
|
| 1161 | + 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
|
| 1162 | + 'event_espresso' |
|
| 1163 | + ), |
|
| 1164 | + $this->submit_button_text() |
|
| 1165 | + ); |
|
| 1166 | + } else { |
|
| 1167 | + $payment_method_info = sprintf( |
|
| 1168 | + esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
| 1169 | + $this->submit_button_text() |
|
| 1170 | + ); |
|
| 1171 | + } |
|
| 1172 | + $info_html .= EEH_HTML::div( |
|
| 1173 | + apply_filters( |
|
| 1174 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info', |
|
| 1175 | + $payment_method_info |
|
| 1176 | + ), |
|
| 1177 | + '', |
|
| 1178 | + 'spco-payment-method-desc ee-attention' |
|
| 1179 | + ); |
|
| 1180 | + return new EE_Form_Section_Proper( |
|
| 1181 | + array( |
|
| 1182 | + 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
| 1183 | + 'html_class' => 'spco-payment-method-info-dv', |
|
| 1184 | + // only display the selected or default PM |
|
| 1185 | + 'html_style' => $currently_selected ? '' : 'display:none;', |
|
| 1186 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 1187 | + 'subsections' => array( |
|
| 1188 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
| 1189 | + 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(), |
|
| 1190 | + ), |
|
| 1191 | + ) |
|
| 1192 | + ); |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + |
|
| 1196 | + /** |
|
| 1197 | + * get_billing_form_html_for_payment_method |
|
| 1198 | + * |
|
| 1199 | + * @access public |
|
| 1200 | + * @return string |
|
| 1201 | + * @throws EE_Error |
|
| 1202 | + * @throws InvalidArgumentException |
|
| 1203 | + * @throws ReflectionException |
|
| 1204 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1205 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1206 | + */ |
|
| 1207 | + public function get_billing_form_html_for_payment_method() |
|
| 1208 | + { |
|
| 1209 | + // how have they chosen to pay? |
|
| 1210 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1211 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1212 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1213 | + return false; |
|
| 1214 | + } |
|
| 1215 | + if (apply_filters( |
|
| 1216 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1217 | + false |
|
| 1218 | + )) { |
|
| 1219 | + EE_Error::add_success( |
|
| 1220 | + apply_filters( |
|
| 1221 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1222 | + sprintf( |
|
| 1223 | + esc_html__( |
|
| 1224 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1225 | + 'event_espresso' |
|
| 1226 | + ), |
|
| 1227 | + $this->checkout->payment_method->name() |
|
| 1228 | + ) |
|
| 1229 | + ) |
|
| 1230 | + ); |
|
| 1231 | + } |
|
| 1232 | + // now generate billing form for selected method of payment |
|
| 1233 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
| 1234 | + // fill form with attendee info if applicable |
|
| 1235 | + if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1236 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1237 | + ) { |
|
| 1238 | + $payment_method_billing_form->populate_from_attendee( |
|
| 1239 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1240 | + ); |
|
| 1241 | + } |
|
| 1242 | + // and debug content |
|
| 1243 | + if ($payment_method_billing_form instanceof EE_Billing_Info_Form |
|
| 1244 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1245 | + ) { |
|
| 1246 | + $payment_method_billing_form = |
|
| 1247 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1248 | + $payment_method_billing_form |
|
| 1249 | + ); |
|
| 1250 | + } |
|
| 1251 | + $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
|
| 1252 | + ? $payment_method_billing_form->get_html() |
|
| 1253 | + : ''; |
|
| 1254 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
| 1255 | + // localize validation rules for main form |
|
| 1256 | + $this->checkout->current_step->reg_form->localize_validation_rules(); |
|
| 1257 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1258 | + return true; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + |
|
| 1262 | + /** |
|
| 1263 | + * _get_billing_form_for_payment_method |
|
| 1264 | + * |
|
| 1265 | + * @access private |
|
| 1266 | + * @param EE_Payment_Method $payment_method |
|
| 1267 | + * @return EE_Billing_Info_Form|EE_Form_Section_HTML |
|
| 1268 | + * @throws EE_Error |
|
| 1269 | + * @throws InvalidArgumentException |
|
| 1270 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1271 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1272 | + */ |
|
| 1273 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) |
|
| 1274 | + { |
|
| 1275 | + $billing_form = $payment_method->type_obj()->billing_form( |
|
| 1276 | + $this->checkout->transaction, |
|
| 1277 | + array('amount_owing' => $this->checkout->amount_owing) |
|
| 1278 | + ); |
|
| 1279 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
| 1280 | + if (apply_filters( |
|
| 1281 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1282 | + false |
|
| 1283 | + ) |
|
| 1284 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
| 1285 | + ) { |
|
| 1286 | + EE_Error::add_success( |
|
| 1287 | + apply_filters( |
|
| 1288 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1289 | + sprintf( |
|
| 1290 | + esc_html__( |
|
| 1291 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1292 | + 'event_espresso' |
|
| 1293 | + ), |
|
| 1294 | + $payment_method->name() |
|
| 1295 | + ) |
|
| 1296 | + ) |
|
| 1297 | + ); |
|
| 1298 | + } |
|
| 1299 | + return apply_filters( |
|
| 1300 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 1301 | + $billing_form, |
|
| 1302 | + $payment_method |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | + // no actual billing form, so return empty HTML form section |
|
| 1306 | + return new EE_Form_Section_HTML(); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * _get_selected_method_of_payment |
|
| 1312 | + * |
|
| 1313 | + * @access private |
|
| 1314 | + * @param boolean $required whether to throw an error if the "selected_method_of_payment" |
|
| 1315 | + * is not found in the incoming request |
|
| 1316 | + * @param string $request_param |
|
| 1317 | + * @return NULL|string |
|
| 1318 | + * @throws EE_Error |
|
| 1319 | + * @throws InvalidArgumentException |
|
| 1320 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1321 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1322 | + */ |
|
| 1323 | + private function _get_selected_method_of_payment( |
|
| 1324 | + $required = false, |
|
| 1325 | + $request_param = 'selected_method_of_payment' |
|
| 1326 | + ) { |
|
| 1327 | + // is selected_method_of_payment set in the request ? |
|
| 1328 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
| 1329 | + if ($selected_method_of_payment) { |
|
| 1330 | + // sanitize it |
|
| 1331 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
| 1332 | + ? array_shift($selected_method_of_payment) |
|
| 1333 | + : $selected_method_of_payment; |
|
| 1334 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
| 1335 | + // store it in the session so that it's available for all subsequent requests including AJAX |
|
| 1336 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
| 1337 | + } else { |
|
| 1338 | + // or is is set in the session ? |
|
| 1339 | + $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
|
| 1340 | + 'selected_method_of_payment' |
|
| 1341 | + ); |
|
| 1342 | + } |
|
| 1343 | + // do ya really really gotta have it? |
|
| 1344 | + if (empty($selected_method_of_payment) && $required) { |
|
| 1345 | + EE_Error::add_error( |
|
| 1346 | + sprintf( |
|
| 1347 | + esc_html__( |
|
| 1348 | + 'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.', |
|
| 1349 | + 'event_espresso' |
|
| 1350 | + ), |
|
| 1351 | + '<br/>', |
|
| 1352 | + '<br/>', |
|
| 1353 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 1354 | + ), |
|
| 1355 | + __FILE__, |
|
| 1356 | + __FUNCTION__, |
|
| 1357 | + __LINE__ |
|
| 1358 | + ); |
|
| 1359 | + return null; |
|
| 1360 | + } |
|
| 1361 | + return $selected_method_of_payment; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + |
|
| 1369 | + /********************************************************************************************************/ |
|
| 1370 | + /*********************************** SWITCH PAYMENT METHOD ************************************/ |
|
| 1371 | + /********************************************************************************************************/ |
|
| 1372 | + /** |
|
| 1373 | + * switch_payment_method |
|
| 1374 | + * |
|
| 1375 | + * @access public |
|
| 1376 | + * @return string |
|
| 1377 | + * @throws EE_Error |
|
| 1378 | + * @throws InvalidArgumentException |
|
| 1379 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1380 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1381 | + */ |
|
| 1382 | + public function switch_payment_method() |
|
| 1383 | + { |
|
| 1384 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1385 | + return false; |
|
| 1386 | + } |
|
| 1387 | + if (apply_filters( |
|
| 1388 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
|
| 1389 | + false |
|
| 1390 | + )) { |
|
| 1391 | + EE_Error::add_success( |
|
| 1392 | + apply_filters( |
|
| 1393 | + 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
|
| 1394 | + sprintf( |
|
| 1395 | + esc_html__( |
|
| 1396 | + 'You have selected "%s" as your method of payment. Please note the important payment information below.', |
|
| 1397 | + 'event_espresso' |
|
| 1398 | + ), |
|
| 1399 | + $this->checkout->payment_method->name() |
|
| 1400 | + ) |
|
| 1401 | + ) |
|
| 1402 | + ); |
|
| 1403 | + } |
|
| 1404 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1405 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1406 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1407 | + $this->checkout->payment_method |
|
| 1408 | + ); |
|
| 1409 | + } |
|
| 1410 | + // fill form with attendee info if applicable |
|
| 1411 | + if (apply_filters( |
|
| 1412 | + 'FHEE__populate_billing_form_fields_from_attendee', |
|
| 1413 | + ( |
|
| 1414 | + $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 1415 | + && $this->checkout->transaction_has_primary_registrant() |
|
| 1416 | + ), |
|
| 1417 | + $this->checkout->billing_form, |
|
| 1418 | + $this->checkout->transaction |
|
| 1419 | + ) |
|
| 1420 | + ) { |
|
| 1421 | + $this->checkout->billing_form->populate_from_attendee( |
|
| 1422 | + $this->checkout->transaction->primary_registration()->attendee() |
|
| 1423 | + ); |
|
| 1424 | + } |
|
| 1425 | + // and debug content |
|
| 1426 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
| 1427 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
| 1428 | + ) { |
|
| 1429 | + $this->checkout->billing_form = |
|
| 1430 | + $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
|
| 1431 | + $this->checkout->billing_form |
|
| 1432 | + ); |
|
| 1433 | + } |
|
| 1434 | + // get html and validation rules for form |
|
| 1435 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
| 1436 | + $this->checkout->json_response->set_return_data( |
|
| 1437 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
| 1438 | + ); |
|
| 1439 | + // localize validation rules for main form |
|
| 1440 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
| 1441 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
| 1442 | + } else { |
|
| 1443 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
| 1444 | + } |
|
| 1445 | + // prevents advancement to next step |
|
| 1446 | + $this->checkout->continue_reg = false; |
|
| 1447 | + return true; |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + |
|
| 1451 | + /** |
|
| 1452 | + * _verify_payment_method_is_set |
|
| 1453 | + * |
|
| 1454 | + * @return bool |
|
| 1455 | + * @throws EE_Error |
|
| 1456 | + * @throws InvalidArgumentException |
|
| 1457 | + * @throws ReflectionException |
|
| 1458 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1459 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1460 | + */ |
|
| 1461 | + protected function _verify_payment_method_is_set() |
|
| 1462 | + { |
|
| 1463 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1464 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1465 | + // how have they chosen to pay? |
|
| 1466 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 1467 | + } else { |
|
| 1468 | + // choose your own adventure based on method_of_payment |
|
| 1469 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1470 | + case 'events_sold_out': |
|
| 1471 | + EE_Error::add_attention( |
|
| 1472 | + apply_filters( |
|
| 1473 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
|
| 1474 | + esc_html__( |
|
| 1475 | + 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
| 1476 | + 'event_espresso' |
|
| 1477 | + ) |
|
| 1478 | + ), |
|
| 1479 | + __FILE__, |
|
| 1480 | + __FUNCTION__, |
|
| 1481 | + __LINE__ |
|
| 1482 | + ); |
|
| 1483 | + return false; |
|
| 1484 | + break; |
|
| 1485 | + case 'payments_closed': |
|
| 1486 | + EE_Error::add_attention( |
|
| 1487 | + apply_filters( |
|
| 1488 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
|
| 1489 | + esc_html__( |
|
| 1490 | + 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', |
|
| 1491 | + 'event_espresso' |
|
| 1492 | + ) |
|
| 1493 | + ), |
|
| 1494 | + __FILE__, |
|
| 1495 | + __FUNCTION__, |
|
| 1496 | + __LINE__ |
|
| 1497 | + ); |
|
| 1498 | + return false; |
|
| 1499 | + break; |
|
| 1500 | + case 'no_payment_required': |
|
| 1501 | + EE_Error::add_attention( |
|
| 1502 | + apply_filters( |
|
| 1503 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
|
| 1504 | + esc_html__( |
|
| 1505 | + 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', |
|
| 1506 | + 'event_espresso' |
|
| 1507 | + ) |
|
| 1508 | + ), |
|
| 1509 | + __FILE__, |
|
| 1510 | + __FUNCTION__, |
|
| 1511 | + __LINE__ |
|
| 1512 | + ); |
|
| 1513 | + return false; |
|
| 1514 | + break; |
|
| 1515 | + default: |
|
| 1516 | + } |
|
| 1517 | + } |
|
| 1518 | + // verify payment method |
|
| 1519 | + if (! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
| 1520 | + // get payment method for selected method of payment |
|
| 1521 | + $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
|
| 1522 | + } |
|
| 1523 | + return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false; |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + |
|
| 1528 | + /********************************************************************************************************/ |
|
| 1529 | + /*************************************** SAVE PAYER DETAILS ****************************************/ |
|
| 1530 | + /********************************************************************************************************/ |
|
| 1531 | + /** |
|
| 1532 | + * save_payer_details_via_ajax |
|
| 1533 | + * |
|
| 1534 | + * @return void |
|
| 1535 | + * @throws EE_Error |
|
| 1536 | + * @throws InvalidArgumentException |
|
| 1537 | + * @throws ReflectionException |
|
| 1538 | + * @throws RuntimeException |
|
| 1539 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1540 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1541 | + */ |
|
| 1542 | + public function save_payer_details_via_ajax() |
|
| 1543 | + { |
|
| 1544 | + if (! $this->_verify_payment_method_is_set()) { |
|
| 1545 | + return; |
|
| 1546 | + } |
|
| 1547 | + // generate billing form for selected method of payment if it hasn't been done already |
|
| 1548 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1549 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1550 | + $this->checkout->payment_method |
|
| 1551 | + ); |
|
| 1552 | + } |
|
| 1553 | + // generate primary attendee from payer info if applicable |
|
| 1554 | + if (! $this->checkout->transaction_has_primary_registrant()) { |
|
| 1555 | + $attendee = $this->_create_attendee_from_request_data(); |
|
| 1556 | + if ($attendee instanceof EE_Attendee) { |
|
| 1557 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
| 1558 | + if ($registration->is_primary_registrant()) { |
|
| 1559 | + $this->checkout->primary_attendee_obj = $attendee; |
|
| 1560 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1561 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1562 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1563 | + } |
|
| 1564 | + } |
|
| 1565 | + } |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * create_attendee_from_request_data |
|
| 1572 | + * uses info from alternate GET or POST data (such as AJAX) to create a new attendee |
|
| 1573 | + * |
|
| 1574 | + * @return EE_Attendee |
|
| 1575 | + * @throws EE_Error |
|
| 1576 | + * @throws InvalidArgumentException |
|
| 1577 | + * @throws ReflectionException |
|
| 1578 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1579 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1580 | + */ |
|
| 1581 | + protected function _create_attendee_from_request_data() |
|
| 1582 | + { |
|
| 1583 | + // get State ID |
|
| 1584 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
| 1585 | + if (! empty($STA_ID)) { |
|
| 1586 | + // can we get state object from name ? |
|
| 1587 | + EE_Registry::instance()->load_model('State'); |
|
| 1588 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
| 1589 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
| 1590 | + } |
|
| 1591 | + // get Country ISO |
|
| 1592 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
| 1593 | + if (! empty($CNT_ISO)) { |
|
| 1594 | + // can we get country object from name ? |
|
| 1595 | + EE_Registry::instance()->load_model('Country'); |
|
| 1596 | + $country = EEM_Country::instance()->get_col( |
|
| 1597 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
| 1598 | + 'CNT_ISO' |
|
| 1599 | + ); |
|
| 1600 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
| 1601 | + } |
|
| 1602 | + // grab attendee data |
|
| 1603 | + $attendee_data = array( |
|
| 1604 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
| 1605 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
| 1606 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
| 1607 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
| 1608 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
| 1609 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
| 1610 | + 'STA_ID' => $STA_ID, |
|
| 1611 | + 'CNT_ISO' => $CNT_ISO, |
|
| 1612 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
| 1613 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
| 1614 | + ); |
|
| 1615 | + // validate the email address since it is the most important piece of info |
|
| 1616 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
| 1617 | + EE_Error::add_error( |
|
| 1618 | + esc_html__('An invalid email address was submitted.', 'event_espresso'), |
|
| 1619 | + __FILE__, |
|
| 1620 | + __FUNCTION__, |
|
| 1621 | + __LINE__ |
|
| 1622 | + ); |
|
| 1623 | + } |
|
| 1624 | + // does this attendee already exist in the db ? we're searching using a combination of first name, last name, |
|
| 1625 | + // AND email address |
|
| 1626 | + if (! empty($attendee_data['ATT_fname']) |
|
| 1627 | + && ! empty($attendee_data['ATT_lname']) |
|
| 1628 | + && ! empty($attendee_data['ATT_email']) |
|
| 1629 | + ) { |
|
| 1630 | + $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
|
| 1631 | + array( |
|
| 1632 | + 'ATT_fname' => $attendee_data['ATT_fname'], |
|
| 1633 | + 'ATT_lname' => $attendee_data['ATT_lname'], |
|
| 1634 | + 'ATT_email' => $attendee_data['ATT_email'], |
|
| 1635 | + ) |
|
| 1636 | + ); |
|
| 1637 | + if ($existing_attendee instanceof EE_Attendee) { |
|
| 1638 | + return $existing_attendee; |
|
| 1639 | + } |
|
| 1640 | + } |
|
| 1641 | + // no existing attendee? kk let's create a new one |
|
| 1642 | + // kinda lame, but we need a first and last name to create an attendee, so use the email address if those |
|
| 1643 | + // don't exist |
|
| 1644 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
| 1645 | + ? $attendee_data['ATT_fname'] |
|
| 1646 | + : $attendee_data['ATT_email']; |
|
| 1647 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
| 1648 | + ? $attendee_data['ATT_lname'] |
|
| 1649 | + : $attendee_data['ATT_email']; |
|
| 1650 | + return EE_Attendee::new_instance($attendee_data); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + |
|
| 1654 | + |
|
| 1655 | + /********************************************************************************************************/ |
|
| 1656 | + /**************************************** PROCESS REG STEP *****************************************/ |
|
| 1657 | + /********************************************************************************************************/ |
|
| 1658 | + /** |
|
| 1659 | + * process_reg_step |
|
| 1660 | + * |
|
| 1661 | + * @return bool |
|
| 1662 | + * @throws EE_Error |
|
| 1663 | + * @throws InvalidArgumentException |
|
| 1664 | + * @throws ReflectionException |
|
| 1665 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1666 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1667 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1668 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1669 | + */ |
|
| 1670 | + public function process_reg_step() |
|
| 1671 | + { |
|
| 1672 | + // how have they chosen to pay? |
|
| 1673 | + $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
|
| 1674 | + ? 'no_payment_required' |
|
| 1675 | + : $this->_get_selected_method_of_payment(true); |
|
| 1676 | + // choose your own adventure based on method_of_payment |
|
| 1677 | + switch ($this->checkout->selected_method_of_payment) { |
|
| 1678 | + case 'events_sold_out': |
|
| 1679 | + $this->checkout->redirect = true; |
|
| 1680 | + $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
|
| 1681 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1682 | + // mark this reg step as completed |
|
| 1683 | + $this->set_completed(); |
|
| 1684 | + return false; |
|
| 1685 | + break; |
|
| 1686 | + |
|
| 1687 | + case 'payments_closed': |
|
| 1688 | + if (apply_filters( |
|
| 1689 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
|
| 1690 | + false |
|
| 1691 | + )) { |
|
| 1692 | + EE_Error::add_success( |
|
| 1693 | + esc_html__('no payment required at this time.', 'event_espresso'), |
|
| 1694 | + __FILE__, |
|
| 1695 | + __FUNCTION__, |
|
| 1696 | + __LINE__ |
|
| 1697 | + ); |
|
| 1698 | + } |
|
| 1699 | + // mark this reg step as completed |
|
| 1700 | + $this->set_completed(); |
|
| 1701 | + return true; |
|
| 1702 | + break; |
|
| 1703 | + |
|
| 1704 | + case 'no_payment_required': |
|
| 1705 | + if (apply_filters( |
|
| 1706 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
|
| 1707 | + false |
|
| 1708 | + )) { |
|
| 1709 | + EE_Error::add_success( |
|
| 1710 | + esc_html__('no payment required.', 'event_espresso'), |
|
| 1711 | + __FILE__, |
|
| 1712 | + __FUNCTION__, |
|
| 1713 | + __LINE__ |
|
| 1714 | + ); |
|
| 1715 | + } |
|
| 1716 | + // mark this reg step as completed |
|
| 1717 | + $this->set_completed(); |
|
| 1718 | + return true; |
|
| 1719 | + break; |
|
| 1720 | + |
|
| 1721 | + default: |
|
| 1722 | + $registrations = EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
|
| 1723 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
| 1724 | + ); |
|
| 1725 | + $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
|
| 1726 | + $registrations, |
|
| 1727 | + EE_Registry::instance()->SSN->checkout()->revisit |
|
| 1728 | + ); |
|
| 1729 | + // calculate difference between the two arrays |
|
| 1730 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
| 1731 | + if (empty($registrations)) { |
|
| 1732 | + $this->_redirect_because_event_sold_out(); |
|
| 1733 | + return false; |
|
| 1734 | + } |
|
| 1735 | + $payment_successful = $this->_process_payment(); |
|
| 1736 | + if ($payment_successful) { |
|
| 1737 | + $this->checkout->continue_reg = true; |
|
| 1738 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
| 1739 | + } else { |
|
| 1740 | + $this->checkout->continue_reg = false; |
|
| 1741 | + } |
|
| 1742 | + return $payment_successful; |
|
| 1743 | + } |
|
| 1744 | + } |
|
| 1745 | + |
|
| 1746 | + |
|
| 1747 | + /** |
|
| 1748 | + * _redirect_because_event_sold_out |
|
| 1749 | + * |
|
| 1750 | + * @access protected |
|
| 1751 | + * @return void |
|
| 1752 | + */ |
|
| 1753 | + protected function _redirect_because_event_sold_out() |
|
| 1754 | + { |
|
| 1755 | + $this->checkout->continue_reg = false; |
|
| 1756 | + // set redirect URL |
|
| 1757 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1758 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1759 | + $this->checkout->current_step->reg_step_url() |
|
| 1760 | + ); |
|
| 1761 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + |
|
| 1765 | + /** |
|
| 1766 | + * _maybe_set_completed |
|
| 1767 | + * |
|
| 1768 | + * @access protected |
|
| 1769 | + * @param \EE_Payment_Method $payment_method |
|
| 1770 | + * @return void |
|
| 1771 | + * @throws \EE_Error |
|
| 1772 | + */ |
|
| 1773 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) |
|
| 1774 | + { |
|
| 1775 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 1776 | + case EE_PMT_Base::offsite: |
|
| 1777 | + break; |
|
| 1778 | + case EE_PMT_Base::onsite: |
|
| 1779 | + case EE_PMT_Base::offline: |
|
| 1780 | + // mark this reg step as completed |
|
| 1781 | + $this->set_completed(); |
|
| 1782 | + break; |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + |
|
| 1786 | + |
|
| 1787 | + /** |
|
| 1788 | + * update_reg_step |
|
| 1789 | + * this is the final step after a user revisits the site to retry a payment |
|
| 1790 | + * |
|
| 1791 | + * @return bool |
|
| 1792 | + * @throws EE_Error |
|
| 1793 | + * @throws InvalidArgumentException |
|
| 1794 | + * @throws ReflectionException |
|
| 1795 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1796 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1797 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1798 | + * @throws \EventEspresso\core\exceptions\InvalidStatusException |
|
| 1799 | + */ |
|
| 1800 | + public function update_reg_step() |
|
| 1801 | + { |
|
| 1802 | + $success = true; |
|
| 1803 | + // if payment required |
|
| 1804 | + if ($this->checkout->transaction->total() > 0) { |
|
| 1805 | + do_action( |
|
| 1806 | + 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
|
| 1807 | + $this->checkout->transaction |
|
| 1808 | + ); |
|
| 1809 | + // attempt payment via payment method |
|
| 1810 | + $success = $this->process_reg_step(); |
|
| 1811 | + } |
|
| 1812 | + if ($success && ! $this->checkout->redirect) { |
|
| 1813 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
|
| 1814 | + $this->checkout->transaction->ID() |
|
| 1815 | + ); |
|
| 1816 | + // set return URL |
|
| 1817 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1818 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
| 1819 | + $this->checkout->thank_you_page_url |
|
| 1820 | + ); |
|
| 1821 | + } |
|
| 1822 | + return $success; |
|
| 1823 | + } |
|
| 1824 | + |
|
| 1825 | + |
|
| 1826 | + /** |
|
| 1827 | + * _process_payment |
|
| 1828 | + * |
|
| 1829 | + * @access private |
|
| 1830 | + * @return bool |
|
| 1831 | + * @throws EE_Error |
|
| 1832 | + * @throws InvalidArgumentException |
|
| 1833 | + * @throws ReflectionException |
|
| 1834 | + * @throws RuntimeException |
|
| 1835 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1836 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1837 | + */ |
|
| 1838 | + private function _process_payment() |
|
| 1839 | + { |
|
| 1840 | + // basically confirm that the event hasn't sold out since they hit the page |
|
| 1841 | + if (! $this->_last_second_ticket_verifications()) { |
|
| 1842 | + return false; |
|
| 1843 | + } |
|
| 1844 | + // ya gotta make a choice man |
|
| 1845 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 1846 | + $this->checkout->json_response->set_plz_select_method_of_payment( |
|
| 1847 | + esc_html__('Please select a method of payment before proceeding.', 'event_espresso') |
|
| 1848 | + ); |
|
| 1849 | + return false; |
|
| 1850 | + } |
|
| 1851 | + // get EE_Payment_Method object |
|
| 1852 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 1853 | + return false; |
|
| 1854 | + } |
|
| 1855 | + // setup billing form |
|
| 1856 | + if ($this->checkout->payment_method->is_on_site()) { |
|
| 1857 | + $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
|
| 1858 | + $this->checkout->payment_method |
|
| 1859 | + ); |
|
| 1860 | + // bad billing form ? |
|
| 1861 | + if (! $this->_billing_form_is_valid()) { |
|
| 1862 | + return false; |
|
| 1863 | + } |
|
| 1864 | + } |
|
| 1865 | + // ensure primary registrant has been fully processed |
|
| 1866 | + if (! $this->_setup_primary_registrant_prior_to_payment()) { |
|
| 1867 | + return false; |
|
| 1868 | + } |
|
| 1869 | + // if session is close to expiring (under 10 minutes by default) |
|
| 1870 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
| 1871 | + // add some time to session expiration so that payment can be completed |
|
| 1872 | + EE_Registry::instance()->SSN->extend_expiration(); |
|
| 1873 | + } |
|
| 1874 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1875 | + // $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
| 1876 | + // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations |
|
| 1877 | + // for events with a default reg status of Approved |
|
| 1878 | + // $transaction_processor->toggle_registration_statuses_for_default_approved_events( |
|
| 1879 | + // $this->checkout->transaction, $this->checkout->reg_cache_where_params |
|
| 1880 | + // ); |
|
| 1881 | + // attempt payment |
|
| 1882 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
| 1883 | + // process results |
|
| 1884 | + $payment = $this->_validate_payment($payment); |
|
| 1885 | + $payment = $this->_post_payment_processing($payment); |
|
| 1886 | + // verify payment |
|
| 1887 | + if ($payment instanceof EE_Payment) { |
|
| 1888 | + // store that for later |
|
| 1889 | + $this->checkout->payment = $payment; |
|
| 1890 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
|
| 1891 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1892 | + $payment_status = $payment->status(); |
|
| 1893 | + if ($payment_status === EEM_Payment::status_id_approved |
|
| 1894 | + || $payment_status === EEM_Payment::status_id_pending |
|
| 1895 | + ) { |
|
| 1896 | + return true; |
|
| 1897 | + } else { |
|
| 1898 | + return false; |
|
| 1899 | + } |
|
| 1900 | + } elseif ($payment === true) { |
|
| 1901 | + // please note that offline payment methods will NOT make a payment, |
|
| 1902 | + // but instead just mark themselves as the PMD_ID on the transaction, and return true |
|
| 1903 | + $this->checkout->payment = $payment; |
|
| 1904 | + return true; |
|
| 1905 | + } |
|
| 1906 | + // where's my money? |
|
| 1907 | + return false; |
|
| 1908 | + } |
|
| 1909 | + |
|
| 1910 | + |
|
| 1911 | + /** |
|
| 1912 | + * _last_second_ticket_verifications |
|
| 1913 | + * |
|
| 1914 | + * @access public |
|
| 1915 | + * @return bool |
|
| 1916 | + * @throws EE_Error |
|
| 1917 | + */ |
|
| 1918 | + protected function _last_second_ticket_verifications() |
|
| 1919 | + { |
|
| 1920 | + // don't bother re-validating if not a return visit |
|
| 1921 | + if (! $this->checkout->revisit) { |
|
| 1922 | + return true; |
|
| 1923 | + } |
|
| 1924 | + $registrations = $this->checkout->transaction->registrations(); |
|
| 1925 | + if (empty($registrations)) { |
|
| 1926 | + return false; |
|
| 1927 | + } |
|
| 1928 | + foreach ($registrations as $registration) { |
|
| 1929 | + if ($registration instanceof EE_Registration && ! $registration->is_approved()) { |
|
| 1930 | + $event = $registration->event_obj(); |
|
| 1931 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
| 1932 | + EE_Error::add_error( |
|
| 1933 | + apply_filters( |
|
| 1934 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
|
| 1935 | + sprintf( |
|
| 1936 | + esc_html__( |
|
| 1937 | + 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', |
|
| 1938 | + 'event_espresso' |
|
| 1939 | + ), |
|
| 1940 | + $event->name() |
|
| 1941 | + ) |
|
| 1942 | + ), |
|
| 1943 | + __FILE__, |
|
| 1944 | + __FUNCTION__, |
|
| 1945 | + __LINE__ |
|
| 1946 | + ); |
|
| 1947 | + return false; |
|
| 1948 | + } |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + return true; |
|
| 1952 | + } |
|
| 1953 | + |
|
| 1954 | + |
|
| 1955 | + /** |
|
| 1956 | + * redirect_form |
|
| 1957 | + * |
|
| 1958 | + * @access public |
|
| 1959 | + * @return bool |
|
| 1960 | + * @throws EE_Error |
|
| 1961 | + * @throws InvalidArgumentException |
|
| 1962 | + * @throws ReflectionException |
|
| 1963 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1964 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1965 | + */ |
|
| 1966 | + public function redirect_form() |
|
| 1967 | + { |
|
| 1968 | + $payment_method_billing_info = $this->_payment_method_billing_info( |
|
| 1969 | + $this->_get_payment_method_for_selected_method_of_payment() |
|
| 1970 | + ); |
|
| 1971 | + $html = $payment_method_billing_info->get_html(); |
|
| 1972 | + $html .= $this->checkout->redirect_form; |
|
| 1973 | + EE_Registry::instance()->REQ->add_output($html); |
|
| 1974 | + return true; |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + |
|
| 1978 | + /** |
|
| 1979 | + * _billing_form_is_valid |
|
| 1980 | + * |
|
| 1981 | + * @access private |
|
| 1982 | + * @return bool |
|
| 1983 | + * @throws \EE_Error |
|
| 1984 | + */ |
|
| 1985 | + private function _billing_form_is_valid() |
|
| 1986 | + { |
|
| 1987 | + if (! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
| 1988 | + return true; |
|
| 1989 | + } |
|
| 1990 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
| 1991 | + if ($this->checkout->billing_form->was_submitted()) { |
|
| 1992 | + $this->checkout->billing_form->receive_form_submission(); |
|
| 1993 | + if ($this->checkout->billing_form->is_valid()) { |
|
| 1994 | + return true; |
|
| 1995 | + } |
|
| 1996 | + $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
|
| 1997 | + $error_strings = array(); |
|
| 1998 | + foreach ($validation_errors as $validation_error) { |
|
| 1999 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 2000 | + $form_section = $validation_error->get_form_section(); |
|
| 2001 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
| 2002 | + $label = $form_section->html_label_text(); |
|
| 2003 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
| 2004 | + $label = $form_section->name(); |
|
| 2005 | + } else { |
|
| 2006 | + $label = esc_html__('Validation Error', 'event_espresso'); |
|
| 2007 | + } |
|
| 2008 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
| 2009 | + } |
|
| 2010 | + } |
|
| 2011 | + EE_Error::add_error( |
|
| 2012 | + sprintf( |
|
| 2013 | + esc_html__( |
|
| 2014 | + 'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s', |
|
| 2015 | + 'event_espresso' |
|
| 2016 | + ), |
|
| 2017 | + '<br/>', |
|
| 2018 | + implode('<br/>', $error_strings) |
|
| 2019 | + ), |
|
| 2020 | + __FILE__, |
|
| 2021 | + __FUNCTION__, |
|
| 2022 | + __LINE__ |
|
| 2023 | + ); |
|
| 2024 | + } else { |
|
| 2025 | + EE_Error::add_error( |
|
| 2026 | + esc_html__( |
|
| 2027 | + 'The billing form was not submitted or something prevented it\'s submission.', |
|
| 2028 | + 'event_espresso' |
|
| 2029 | + ), |
|
| 2030 | + __FILE__, |
|
| 2031 | + __FUNCTION__, |
|
| 2032 | + __LINE__ |
|
| 2033 | + ); |
|
| 2034 | + } |
|
| 2035 | + } else { |
|
| 2036 | + EE_Error::add_error( |
|
| 2037 | + esc_html__( |
|
| 2038 | + 'The submitted billing form is invalid possibly due to a technical reason.', |
|
| 2039 | + 'event_espresso' |
|
| 2040 | + ), |
|
| 2041 | + __FILE__, |
|
| 2042 | + __FUNCTION__, |
|
| 2043 | + __LINE__ |
|
| 2044 | + ); |
|
| 2045 | + } |
|
| 2046 | + return false; |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * _setup_primary_registrant_prior_to_payment |
|
| 2052 | + * ensures that the primary registrant has a valid attendee object created with the critical details populated |
|
| 2053 | + * (first & last name & email) and that both the transaction object and primary registration object have been saved |
|
| 2054 | + * plz note that any other registrations will NOT be saved at this point (because they may not have any details |
|
| 2055 | + * yet) |
|
| 2056 | + * |
|
| 2057 | + * @access private |
|
| 2058 | + * @return bool |
|
| 2059 | + * @throws EE_Error |
|
| 2060 | + * @throws InvalidArgumentException |
|
| 2061 | + * @throws ReflectionException |
|
| 2062 | + * @throws RuntimeException |
|
| 2063 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2064 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2065 | + */ |
|
| 2066 | + private function _setup_primary_registrant_prior_to_payment() |
|
| 2067 | + { |
|
| 2068 | + // check if transaction has a primary registrant and that it has a related Attendee object |
|
| 2069 | + // if not, then we need to at least gather some primary registrant data before attempting payment |
|
| 2070 | + if ($this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form |
|
| 2071 | + && ! $this->checkout->transaction_has_primary_registrant() |
|
| 2072 | + && ! $this->_capture_primary_registration_data_from_billing_form() |
|
| 2073 | + ) { |
|
| 2074 | + return false; |
|
| 2075 | + } |
|
| 2076 | + // because saving an object clears it's cache, we need to do the chevy shuffle |
|
| 2077 | + // grab the primary_registration object |
|
| 2078 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2079 | + // at this point we'll consider a TXN to not have been failed |
|
| 2080 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 2081 | + // save the TXN ( which clears cached copy of primary_registration) |
|
| 2082 | + $this->checkout->transaction->save(); |
|
| 2083 | + // grab TXN ID and save it to the primary_registration |
|
| 2084 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
| 2085 | + // save what we have so far |
|
| 2086 | + $primary_registration->save(); |
|
| 2087 | + return true; |
|
| 2088 | + } |
|
| 2089 | + |
|
| 2090 | + |
|
| 2091 | + /** |
|
| 2092 | + * _capture_primary_registration_data_from_billing_form |
|
| 2093 | + * |
|
| 2094 | + * @access private |
|
| 2095 | + * @return bool |
|
| 2096 | + * @throws EE_Error |
|
| 2097 | + * @throws InvalidArgumentException |
|
| 2098 | + * @throws ReflectionException |
|
| 2099 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2100 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2101 | + */ |
|
| 2102 | + private function _capture_primary_registration_data_from_billing_form() |
|
| 2103 | + { |
|
| 2104 | + // convert billing form data into an attendee |
|
| 2105 | + $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
|
| 2106 | + if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
| 2107 | + EE_Error::add_error( |
|
| 2108 | + sprintf( |
|
| 2109 | + esc_html__( |
|
| 2110 | + 'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2111 | + 'event_espresso' |
|
| 2112 | + ), |
|
| 2113 | + '<br/>', |
|
| 2114 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2115 | + ), |
|
| 2116 | + __FILE__, |
|
| 2117 | + __FUNCTION__, |
|
| 2118 | + __LINE__ |
|
| 2119 | + ); |
|
| 2120 | + return false; |
|
| 2121 | + } |
|
| 2122 | + $primary_registration = $this->checkout->transaction->primary_registration(); |
|
| 2123 | + if (! $primary_registration instanceof EE_Registration) { |
|
| 2124 | + EE_Error::add_error( |
|
| 2125 | + sprintf( |
|
| 2126 | + esc_html__( |
|
| 2127 | + 'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2128 | + 'event_espresso' |
|
| 2129 | + ), |
|
| 2130 | + '<br/>', |
|
| 2131 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2132 | + ), |
|
| 2133 | + __FILE__, |
|
| 2134 | + __FUNCTION__, |
|
| 2135 | + __LINE__ |
|
| 2136 | + ); |
|
| 2137 | + return false; |
|
| 2138 | + } |
|
| 2139 | + if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
| 2140 | + instanceof |
|
| 2141 | + EE_Attendee |
|
| 2142 | + ) { |
|
| 2143 | + EE_Error::add_error( |
|
| 2144 | + sprintf( |
|
| 2145 | + esc_html__( |
|
| 2146 | + 'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2147 | + 'event_espresso' |
|
| 2148 | + ), |
|
| 2149 | + '<br/>', |
|
| 2150 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2151 | + ), |
|
| 2152 | + __FILE__, |
|
| 2153 | + __FUNCTION__, |
|
| 2154 | + __LINE__ |
|
| 2155 | + ); |
|
| 2156 | + return false; |
|
| 2157 | + } |
|
| 2158 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 2159 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 2160 | + // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
|
| 2161 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
| 2162 | + return true; |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + |
|
| 2166 | + /** |
|
| 2167 | + * _get_payment_method_for_selected_method_of_payment |
|
| 2168 | + * retrieves a valid payment method |
|
| 2169 | + * |
|
| 2170 | + * @access public |
|
| 2171 | + * @return EE_Payment_Method |
|
| 2172 | + * @throws EE_Error |
|
| 2173 | + * @throws InvalidArgumentException |
|
| 2174 | + * @throws ReflectionException |
|
| 2175 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2176 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2177 | + */ |
|
| 2178 | + private function _get_payment_method_for_selected_method_of_payment() |
|
| 2179 | + { |
|
| 2180 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
| 2181 | + $this->_redirect_because_event_sold_out(); |
|
| 2182 | + return null; |
|
| 2183 | + } |
|
| 2184 | + // get EE_Payment_Method object |
|
| 2185 | + if (isset($this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ])) { |
|
| 2186 | + $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
| 2187 | + } else { |
|
| 2188 | + // load EEM_Payment_Method |
|
| 2189 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
| 2190 | + /** @type EEM_Payment_Method $EEM_Payment_Method */ |
|
| 2191 | + $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
|
| 2192 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
| 2193 | + } |
|
| 2194 | + // verify $payment_method |
|
| 2195 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
| 2196 | + // not a payment |
|
| 2197 | + EE_Error::add_error( |
|
| 2198 | + sprintf( |
|
| 2199 | + esc_html__( |
|
| 2200 | + 'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2201 | + 'event_espresso' |
|
| 2202 | + ), |
|
| 2203 | + '<br/>', |
|
| 2204 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2205 | + ), |
|
| 2206 | + __FILE__, |
|
| 2207 | + __FUNCTION__, |
|
| 2208 | + __LINE__ |
|
| 2209 | + ); |
|
| 2210 | + return null; |
|
| 2211 | + } |
|
| 2212 | + // and verify it has a valid Payment_Method Type object |
|
| 2213 | + if (! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 2214 | + // not a payment |
|
| 2215 | + EE_Error::add_error( |
|
| 2216 | + sprintf( |
|
| 2217 | + esc_html__( |
|
| 2218 | + 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2219 | + 'event_espresso' |
|
| 2220 | + ), |
|
| 2221 | + '<br/>', |
|
| 2222 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2223 | + ), |
|
| 2224 | + __FILE__, |
|
| 2225 | + __FUNCTION__, |
|
| 2226 | + __LINE__ |
|
| 2227 | + ); |
|
| 2228 | + return null; |
|
| 2229 | + } |
|
| 2230 | + return $payment_method; |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * _attempt_payment |
|
| 2236 | + * |
|
| 2237 | + * @access private |
|
| 2238 | + * @type EE_Payment_Method $payment_method |
|
| 2239 | + * @return mixed EE_Payment | boolean |
|
| 2240 | + * @throws EE_Error |
|
| 2241 | + * @throws InvalidArgumentException |
|
| 2242 | + * @throws ReflectionException |
|
| 2243 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2244 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2245 | + */ |
|
| 2246 | + private function _attempt_payment(EE_Payment_Method $payment_method) |
|
| 2247 | + { |
|
| 2248 | + $payment = null; |
|
| 2249 | + $this->checkout->transaction->save(); |
|
| 2250 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2251 | + if (! $payment_processor instanceof EE_Payment_Processor) { |
|
| 2252 | + return false; |
|
| 2253 | + } |
|
| 2254 | + try { |
|
| 2255 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
| 2256 | + // generate payment object |
|
| 2257 | + $payment = $payment_processor->process_payment( |
|
| 2258 | + $payment_method, |
|
| 2259 | + $this->checkout->transaction, |
|
| 2260 | + $this->checkout->amount_owing, |
|
| 2261 | + $this->checkout->billing_form, |
|
| 2262 | + $this->_get_return_url($payment_method), |
|
| 2263 | + 'CART', |
|
| 2264 | + $this->checkout->admin_request, |
|
| 2265 | + true, |
|
| 2266 | + $this->reg_step_url() |
|
| 2267 | + ); |
|
| 2268 | + } catch (Exception $e) { |
|
| 2269 | + $this->_handle_payment_processor_exception($e); |
|
| 2270 | + } |
|
| 2271 | + return $payment; |
|
| 2272 | + } |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + /** |
|
| 2276 | + * _handle_payment_processor_exception |
|
| 2277 | + * |
|
| 2278 | + * @access protected |
|
| 2279 | + * @param \Exception $e |
|
| 2280 | + * @return void |
|
| 2281 | + * @throws EE_Error |
|
| 2282 | + * @throws InvalidArgumentException |
|
| 2283 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2284 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2285 | + */ |
|
| 2286 | + protected function _handle_payment_processor_exception(Exception $e) |
|
| 2287 | + { |
|
| 2288 | + EE_Error::add_error( |
|
| 2289 | + sprintf( |
|
| 2290 | + esc_html__( |
|
| 2291 | + 'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s', |
|
| 2292 | + 'event_espresso' |
|
| 2293 | + ), |
|
| 2294 | + '<br/>', |
|
| 2295 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
| 2296 | + $e->getMessage(), |
|
| 2297 | + $e->getFile(), |
|
| 2298 | + $e->getLine() |
|
| 2299 | + ), |
|
| 2300 | + __FILE__, |
|
| 2301 | + __FUNCTION__, |
|
| 2302 | + __LINE__ |
|
| 2303 | + ); |
|
| 2304 | + } |
|
| 2305 | + |
|
| 2306 | + |
|
| 2307 | + /** |
|
| 2308 | + * _get_return_url |
|
| 2309 | + * |
|
| 2310 | + * @access protected |
|
| 2311 | + * @param \EE_Payment_Method $payment_method |
|
| 2312 | + * @return string |
|
| 2313 | + * @throws \EE_Error |
|
| 2314 | + */ |
|
| 2315 | + protected function _get_return_url(EE_Payment_Method $payment_method) |
|
| 2316 | + { |
|
| 2317 | + $return_url = ''; |
|
| 2318 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
| 2319 | + case EE_PMT_Base::offsite: |
|
| 2320 | + $return_url = add_query_arg( |
|
| 2321 | + array( |
|
| 2322 | + 'action' => 'process_gateway_response', |
|
| 2323 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2324 | + 'spco_txn' => $this->checkout->transaction->ID(), |
|
| 2325 | + ), |
|
| 2326 | + $this->reg_step_url() |
|
| 2327 | + ); |
|
| 2328 | + break; |
|
| 2329 | + case EE_PMT_Base::onsite: |
|
| 2330 | + case EE_PMT_Base::offline: |
|
| 2331 | + $return_url = $this->checkout->next_step->reg_step_url(); |
|
| 2332 | + break; |
|
| 2333 | + } |
|
| 2334 | + return $return_url; |
|
| 2335 | + } |
|
| 2336 | + |
|
| 2337 | + |
|
| 2338 | + /** |
|
| 2339 | + * _validate_payment |
|
| 2340 | + * |
|
| 2341 | + * @access private |
|
| 2342 | + * @param EE_Payment $payment |
|
| 2343 | + * @return EE_Payment|FALSE |
|
| 2344 | + * @throws EE_Error |
|
| 2345 | + * @throws InvalidArgumentException |
|
| 2346 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2347 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2348 | + */ |
|
| 2349 | + private function _validate_payment($payment = null) |
|
| 2350 | + { |
|
| 2351 | + if ($this->checkout->payment_method->is_off_line()) { |
|
| 2352 | + return true; |
|
| 2353 | + } |
|
| 2354 | + // verify payment object |
|
| 2355 | + if (! $payment instanceof EE_Payment) { |
|
| 2356 | + // not a payment |
|
| 2357 | + EE_Error::add_error( |
|
| 2358 | + sprintf( |
|
| 2359 | + esc_html__( |
|
| 2360 | + 'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2361 | + 'event_espresso' |
|
| 2362 | + ), |
|
| 2363 | + '<br/>', |
|
| 2364 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2365 | + ), |
|
| 2366 | + __FILE__, |
|
| 2367 | + __FUNCTION__, |
|
| 2368 | + __LINE__ |
|
| 2369 | + ); |
|
| 2370 | + return false; |
|
| 2371 | + } |
|
| 2372 | + return $payment; |
|
| 2373 | + } |
|
| 2374 | + |
|
| 2375 | + |
|
| 2376 | + /** |
|
| 2377 | + * _post_payment_processing |
|
| 2378 | + * |
|
| 2379 | + * @access private |
|
| 2380 | + * @param EE_Payment|bool $payment |
|
| 2381 | + * @return bool |
|
| 2382 | + * @throws EE_Error |
|
| 2383 | + * @throws InvalidArgumentException |
|
| 2384 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2385 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2386 | + */ |
|
| 2387 | + private function _post_payment_processing($payment = null) |
|
| 2388 | + { |
|
| 2389 | + // Off-Line payment? |
|
| 2390 | + if ($payment === true) { |
|
| 2391 | + // $this->_setup_redirect_for_next_step(); |
|
| 2392 | + return true; |
|
| 2393 | + // On-Site payment? |
|
| 2394 | + } elseif ($this->checkout->payment_method->is_on_site()) { |
|
| 2395 | + if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
| 2396 | + // $this->_setup_redirect_for_next_step(); |
|
| 2397 | + $this->checkout->continue_reg = false; |
|
| 2398 | + } |
|
| 2399 | + // Off-Site payment? |
|
| 2400 | + } elseif ($this->checkout->payment_method->is_off_site()) { |
|
| 2401 | + // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
|
| 2402 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
| 2403 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
| 2404 | + $this->checkout->redirect = true; |
|
| 2405 | + $this->checkout->redirect_form = $payment->redirect_form(); |
|
| 2406 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
| 2407 | + // set JSON response |
|
| 2408 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
| 2409 | + // and lastly, let's bump the payment status to pending |
|
| 2410 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
| 2411 | + $payment->save(); |
|
| 2412 | + } else { |
|
| 2413 | + // not a payment |
|
| 2414 | + $this->checkout->continue_reg = false; |
|
| 2415 | + EE_Error::add_error( |
|
| 2416 | + sprintf( |
|
| 2417 | + esc_html__( |
|
| 2418 | + 'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.', |
|
| 2419 | + 'event_espresso' |
|
| 2420 | + ), |
|
| 2421 | + '<br/>', |
|
| 2422 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2423 | + ), |
|
| 2424 | + __FILE__, |
|
| 2425 | + __FUNCTION__, |
|
| 2426 | + __LINE__ |
|
| 2427 | + ); |
|
| 2428 | + } |
|
| 2429 | + } else { |
|
| 2430 | + // ummm ya... not Off-Line, not On-Site, not off-Site ???? |
|
| 2431 | + $this->checkout->continue_reg = false; |
|
| 2432 | + return false; |
|
| 2433 | + } |
|
| 2434 | + return $payment; |
|
| 2435 | + } |
|
| 2436 | + |
|
| 2437 | + |
|
| 2438 | + /** |
|
| 2439 | + * _process_payment_status |
|
| 2440 | + * |
|
| 2441 | + * @access private |
|
| 2442 | + * @type EE_Payment $payment |
|
| 2443 | + * @param string $payment_occurs |
|
| 2444 | + * @return bool |
|
| 2445 | + * @throws EE_Error |
|
| 2446 | + * @throws InvalidArgumentException |
|
| 2447 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2448 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2449 | + */ |
|
| 2450 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) |
|
| 2451 | + { |
|
| 2452 | + // off-line payment? carry on |
|
| 2453 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
| 2454 | + return true; |
|
| 2455 | + } |
|
| 2456 | + // verify payment validity |
|
| 2457 | + if ($payment instanceof EE_Payment) { |
|
| 2458 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
| 2459 | + $msg = $payment->gateway_response(); |
|
| 2460 | + // check results |
|
| 2461 | + switch ($payment->status()) { |
|
| 2462 | + // good payment |
|
| 2463 | + case EEM_Payment::status_id_approved: |
|
| 2464 | + EE_Error::add_success( |
|
| 2465 | + esc_html__('Your payment was processed successfully.', 'event_espresso'), |
|
| 2466 | + __FILE__, |
|
| 2467 | + __FUNCTION__, |
|
| 2468 | + __LINE__ |
|
| 2469 | + ); |
|
| 2470 | + return true; |
|
| 2471 | + break; |
|
| 2472 | + // slow payment |
|
| 2473 | + case EEM_Payment::status_id_pending: |
|
| 2474 | + if (empty($msg)) { |
|
| 2475 | + $msg = esc_html__( |
|
| 2476 | + 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
|
| 2477 | + 'event_espresso' |
|
| 2478 | + ); |
|
| 2479 | + } |
|
| 2480 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2481 | + return true; |
|
| 2482 | + break; |
|
| 2483 | + // don't wanna payment |
|
| 2484 | + case EEM_Payment::status_id_cancelled: |
|
| 2485 | + if (empty($msg)) { |
|
| 2486 | + $msg = _n( |
|
| 2487 | + 'Payment cancelled. Please try again.', |
|
| 2488 | + 'Payment cancelled. Please try again or select another method of payment.', |
|
| 2489 | + count($this->checkout->available_payment_methods), |
|
| 2490 | + 'event_espresso' |
|
| 2491 | + ); |
|
| 2492 | + } |
|
| 2493 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2494 | + return false; |
|
| 2495 | + break; |
|
| 2496 | + // not enough payment |
|
| 2497 | + case EEM_Payment::status_id_declined: |
|
| 2498 | + if (empty($msg)) { |
|
| 2499 | + $msg = _n( |
|
| 2500 | + 'We\'re sorry but your payment was declined. Please try again.', |
|
| 2501 | + 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
|
| 2502 | + count($this->checkout->available_payment_methods), |
|
| 2503 | + 'event_espresso' |
|
| 2504 | + ); |
|
| 2505 | + } |
|
| 2506 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2507 | + return false; |
|
| 2508 | + break; |
|
| 2509 | + // bad payment |
|
| 2510 | + case EEM_Payment::status_id_failed: |
|
| 2511 | + if (! empty($msg)) { |
|
| 2512 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 2513 | + return false; |
|
| 2514 | + } |
|
| 2515 | + // default to error below |
|
| 2516 | + break; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + // off-site payment gateway responses are too unreliable, so let's just assume that |
|
| 2520 | + // the payment processing is just running slower than the registrant's request |
|
| 2521 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
| 2522 | + return true; |
|
| 2523 | + } |
|
| 2524 | + EE_Error::add_error( |
|
| 2525 | + sprintf( |
|
| 2526 | + esc_html__( |
|
| 2527 | + 'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.', |
|
| 2528 | + 'event_espresso' |
|
| 2529 | + ), |
|
| 2530 | + '<br/>', |
|
| 2531 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2532 | + ), |
|
| 2533 | + __FILE__, |
|
| 2534 | + __FUNCTION__, |
|
| 2535 | + __LINE__ |
|
| 2536 | + ); |
|
| 2537 | + return false; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + |
|
| 2542 | + |
|
| 2543 | + |
|
| 2544 | + |
|
| 2545 | + /********************************************************************************************************/ |
|
| 2546 | + /********************************** PROCESS GATEWAY RESPONSE **********************************/ |
|
| 2547 | + /********************************************************************************************************/ |
|
| 2548 | + /** |
|
| 2549 | + * process_gateway_response |
|
| 2550 | + * this is the return point for Off-Site Payment Methods |
|
| 2551 | + * It will attempt to "handle the IPN" if it appears that this has not already occurred, |
|
| 2552 | + * otherwise, it will load up the last payment made for the TXN. |
|
| 2553 | + * If the payment retrieved looks good, it will then either: |
|
| 2554 | + * complete the current step and allow advancement to the next reg step |
|
| 2555 | + * or present the payment options again |
|
| 2556 | + * |
|
| 2557 | + * @access private |
|
| 2558 | + * @return EE_Payment|FALSE |
|
| 2559 | + * @throws EE_Error |
|
| 2560 | + * @throws InvalidArgumentException |
|
| 2561 | + * @throws ReflectionException |
|
| 2562 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2563 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2564 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2565 | + */ |
|
| 2566 | + public function process_gateway_response() |
|
| 2567 | + { |
|
| 2568 | + $payment = null; |
|
| 2569 | + // how have they chosen to pay? |
|
| 2570 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
| 2571 | + // get EE_Payment_Method object |
|
| 2572 | + if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
| 2573 | + $this->checkout->continue_reg = false; |
|
| 2574 | + return false; |
|
| 2575 | + } |
|
| 2576 | + if (! $this->checkout->payment_method->is_off_site()) { |
|
| 2577 | + return false; |
|
| 2578 | + } |
|
| 2579 | + $this->_validate_offsite_return(); |
|
| 2580 | + // DEBUG LOG |
|
| 2581 | + // $this->checkout->log( |
|
| 2582 | + // __CLASS__, |
|
| 2583 | + // __FUNCTION__, |
|
| 2584 | + // __LINE__, |
|
| 2585 | + // array( |
|
| 2586 | + // 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2587 | + // 'payment_method' => $this->checkout->payment_method, |
|
| 2588 | + // ), |
|
| 2589 | + // true |
|
| 2590 | + // ); |
|
| 2591 | + // verify TXN |
|
| 2592 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
| 2593 | + $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
|
| 2594 | + if (! $gateway instanceof EE_Offsite_Gateway) { |
|
| 2595 | + $this->checkout->continue_reg = false; |
|
| 2596 | + return false; |
|
| 2597 | + } |
|
| 2598 | + $payment = $this->_process_off_site_payment($gateway); |
|
| 2599 | + $payment = $this->_process_cancelled_payments($payment); |
|
| 2600 | + $payment = $this->_validate_payment($payment); |
|
| 2601 | + // if payment was not declined by the payment gateway or cancelled by the registrant |
|
| 2602 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
| 2603 | + // $this->_setup_redirect_for_next_step(); |
|
| 2604 | + // store that for later |
|
| 2605 | + $this->checkout->payment = $payment; |
|
| 2606 | + // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
|
| 2607 | + // because we will complete this step during the IPN processing then |
|
| 2608 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
| 2609 | + $this->set_completed(); |
|
| 2610 | + } |
|
| 2611 | + return true; |
|
| 2612 | + } |
|
| 2613 | + } |
|
| 2614 | + // DEBUG LOG |
|
| 2615 | + // $this->checkout->log( |
|
| 2616 | + // __CLASS__, |
|
| 2617 | + // __FUNCTION__, |
|
| 2618 | + // __LINE__, |
|
| 2619 | + // array('payment' => $payment) |
|
| 2620 | + // ); |
|
| 2621 | + $this->checkout->continue_reg = false; |
|
| 2622 | + return false; |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + |
|
| 2626 | + /** |
|
| 2627 | + * _validate_return |
|
| 2628 | + * |
|
| 2629 | + * @access private |
|
| 2630 | + * @return void |
|
| 2631 | + * @throws EE_Error |
|
| 2632 | + * @throws InvalidArgumentException |
|
| 2633 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2634 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2635 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 2636 | + */ |
|
| 2637 | + private function _validate_offsite_return() |
|
| 2638 | + { |
|
| 2639 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
| 2640 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
| 2641 | + // Houston... we might have a problem |
|
| 2642 | + $invalid_TXN = false; |
|
| 2643 | + // first gather some info |
|
| 2644 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2645 | + $primary_registrant = $valid_TXN instanceof EE_Transaction |
|
| 2646 | + ? $valid_TXN->primary_registration() |
|
| 2647 | + : null; |
|
| 2648 | + // let's start by retrieving the cart for this TXN |
|
| 2649 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
| 2650 | + if ($cart instanceof EE_Cart) { |
|
| 2651 | + // verify that the current cart has tickets |
|
| 2652 | + $tickets = $cart->get_tickets(); |
|
| 2653 | + if (empty($tickets)) { |
|
| 2654 | + $invalid_TXN = true; |
|
| 2655 | + } |
|
| 2656 | + } else { |
|
| 2657 | + $invalid_TXN = true; |
|
| 2658 | + } |
|
| 2659 | + $valid_TXN_SID = $primary_registrant instanceof EE_Registration |
|
| 2660 | + ? $primary_registrant->session_ID() |
|
| 2661 | + : null; |
|
| 2662 | + // validate current Session ID and compare against valid TXN session ID |
|
| 2663 | + if ($invalid_TXN // if this is already true, then skip other checks |
|
| 2664 | + || EE_Session::instance()->id() === null |
|
| 2665 | + || ( |
|
| 2666 | + // WARNING !!! |
|
| 2667 | + // this could be PayPal sending back duplicate requests (ya they do that) |
|
| 2668 | + // or it **could** mean someone is simply registering AGAIN after having just done so |
|
| 2669 | + // so now we need to determine if this current TXN looks valid or not |
|
| 2670 | + // and whether this reg step has even been started ? |
|
| 2671 | + EE_Session::instance()->id() === $valid_TXN_SID |
|
| 2672 | + // really? you're half way through this reg step, but you never started it ? |
|
| 2673 | + && $this->checkout->transaction->reg_step_completed($this->slug()) === false |
|
| 2674 | + ) |
|
| 2675 | + ) { |
|
| 2676 | + $invalid_TXN = true; |
|
| 2677 | + } |
|
| 2678 | + if ($invalid_TXN) { |
|
| 2679 | + // is the valid TXN completed ? |
|
| 2680 | + if ($valid_TXN instanceof EE_Transaction) { |
|
| 2681 | + // has this step even been started ? |
|
| 2682 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
| 2683 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
| 2684 | + // so it **looks** like this is a double request from PayPal |
|
| 2685 | + // so let's try to pick up where we left off |
|
| 2686 | + $this->checkout->transaction = $valid_TXN; |
|
| 2687 | + $this->checkout->refresh_all_entities(true); |
|
| 2688 | + return; |
|
| 2689 | + } |
|
| 2690 | + } |
|
| 2691 | + // you appear to be lost? |
|
| 2692 | + $this->_redirect_wayward_request($primary_registrant); |
|
| 2693 | + } |
|
| 2694 | + } |
|
| 2695 | + } |
|
| 2696 | + |
|
| 2697 | + |
|
| 2698 | + /** |
|
| 2699 | + * _redirect_wayward_request |
|
| 2700 | + * |
|
| 2701 | + * @access private |
|
| 2702 | + * @param \EE_Registration|null $primary_registrant |
|
| 2703 | + * @return bool |
|
| 2704 | + * @throws EE_Error |
|
| 2705 | + * @throws InvalidArgumentException |
|
| 2706 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2707 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2708 | + */ |
|
| 2709 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) |
|
| 2710 | + { |
|
| 2711 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2712 | + // try redirecting based on the current TXN |
|
| 2713 | + $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
|
| 2714 | + ? $this->checkout->transaction->primary_registration() |
|
| 2715 | + : null; |
|
| 2716 | + } |
|
| 2717 | + if (! $primary_registrant instanceof EE_Registration) { |
|
| 2718 | + EE_Error::add_error( |
|
| 2719 | + sprintf( |
|
| 2720 | + esc_html__( |
|
| 2721 | + 'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.', |
|
| 2722 | + 'event_espresso' |
|
| 2723 | + ), |
|
| 2724 | + '<br/>', |
|
| 2725 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
| 2726 | + ), |
|
| 2727 | + __FILE__, |
|
| 2728 | + __FUNCTION__, |
|
| 2729 | + __LINE__ |
|
| 2730 | + ); |
|
| 2731 | + return false; |
|
| 2732 | + } |
|
| 2733 | + // make sure transaction is not locked |
|
| 2734 | + $this->checkout->transaction->unlock(); |
|
| 2735 | + wp_safe_redirect( |
|
| 2736 | + add_query_arg( |
|
| 2737 | + array( |
|
| 2738 | + 'e_reg_url_link' => $primary_registrant->reg_url_link(), |
|
| 2739 | + ), |
|
| 2740 | + $this->checkout->thank_you_page_url |
|
| 2741 | + ) |
|
| 2742 | + ); |
|
| 2743 | + exit(); |
|
| 2744 | + } |
|
| 2745 | + |
|
| 2746 | + |
|
| 2747 | + /** |
|
| 2748 | + * _process_off_site_payment |
|
| 2749 | + * |
|
| 2750 | + * @access private |
|
| 2751 | + * @param \EE_Offsite_Gateway $gateway |
|
| 2752 | + * @return EE_Payment |
|
| 2753 | + * @throws EE_Error |
|
| 2754 | + * @throws InvalidArgumentException |
|
| 2755 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2756 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2757 | + */ |
|
| 2758 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) |
|
| 2759 | + { |
|
| 2760 | + try { |
|
| 2761 | + $request_data = \EE_Registry::instance()->REQ->params(); |
|
| 2762 | + // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
|
| 2763 | + $this->set_handle_IPN_in_this_request( |
|
| 2764 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
| 2765 | + ); |
|
| 2766 | + if ($this->handle_IPN_in_this_request()) { |
|
| 2767 | + // get payment details and process results |
|
| 2768 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2769 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2770 | + $payment = $payment_processor->process_ipn( |
|
| 2771 | + $request_data, |
|
| 2772 | + $this->checkout->transaction, |
|
| 2773 | + $this->checkout->payment_method, |
|
| 2774 | + true, |
|
| 2775 | + false |
|
| 2776 | + ); |
|
| 2777 | + // $payment_source = 'process_ipn'; |
|
| 2778 | + } else { |
|
| 2779 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2780 | + // $payment_source = 'last_payment'; |
|
| 2781 | + } |
|
| 2782 | + } catch (Exception $e) { |
|
| 2783 | + // let's just eat the exception and try to move on using any previously set payment info |
|
| 2784 | + $payment = $this->checkout->transaction->last_payment(); |
|
| 2785 | + // $payment_source = 'last_payment after Exception'; |
|
| 2786 | + // but if we STILL don't have a payment object |
|
| 2787 | + if (! $payment instanceof EE_Payment) { |
|
| 2788 | + // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
|
| 2789 | + $this->_handle_payment_processor_exception($e); |
|
| 2790 | + } |
|
| 2791 | + } |
|
| 2792 | + // DEBUG LOG |
|
| 2793 | + // $this->checkout->log( |
|
| 2794 | + // __CLASS__, |
|
| 2795 | + // __FUNCTION__, |
|
| 2796 | + // __LINE__, |
|
| 2797 | + // array( |
|
| 2798 | + // 'process_ipn_payment' => $payment, |
|
| 2799 | + // 'payment_source' => $payment_source, |
|
| 2800 | + // ) |
|
| 2801 | + // ); |
|
| 2802 | + return $payment; |
|
| 2803 | + } |
|
| 2804 | + |
|
| 2805 | + |
|
| 2806 | + /** |
|
| 2807 | + * _process_cancelled_payments |
|
| 2808 | + * just makes sure that the payment status gets updated correctly |
|
| 2809 | + * so tha tan error isn't generated during payment validation |
|
| 2810 | + * |
|
| 2811 | + * @access private |
|
| 2812 | + * @param EE_Payment $payment |
|
| 2813 | + * @return EE_Payment | FALSE |
|
| 2814 | + * @throws \EE_Error |
|
| 2815 | + */ |
|
| 2816 | + private function _process_cancelled_payments($payment = null) |
|
| 2817 | + { |
|
| 2818 | + if ($payment instanceof EE_Payment |
|
| 2819 | + && isset($_REQUEST['ee_cancel_payment']) |
|
| 2820 | + && $payment->status() === EEM_Payment::status_id_failed |
|
| 2821 | + ) { |
|
| 2822 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
| 2823 | + } |
|
| 2824 | + return $payment; |
|
| 2825 | + } |
|
| 2826 | + |
|
| 2827 | + |
|
| 2828 | + /** |
|
| 2829 | + * get_transaction_details_for_gateways |
|
| 2830 | + * |
|
| 2831 | + * @access public |
|
| 2832 | + * @return int |
|
| 2833 | + * @throws EE_Error |
|
| 2834 | + * @throws InvalidArgumentException |
|
| 2835 | + * @throws ReflectionException |
|
| 2836 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 2837 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 2838 | + */ |
|
| 2839 | + public function get_transaction_details_for_gateways() |
|
| 2840 | + { |
|
| 2841 | + $txn_details = array(); |
|
| 2842 | + // ya gotta make a choice man |
|
| 2843 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
| 2844 | + $txn_details = array( |
|
| 2845 | + 'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'), |
|
| 2846 | + ); |
|
| 2847 | + } |
|
| 2848 | + // get EE_Payment_Method object |
|
| 2849 | + if (empty($txn_details) |
|
| 2850 | + && |
|
| 2851 | + ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
|
| 2852 | + ) { |
|
| 2853 | + $txn_details = array( |
|
| 2854 | + 'selected_method_of_payment' => $this->checkout->selected_method_of_payment, |
|
| 2855 | + 'error' => esc_html__( |
|
| 2856 | + 'A valid Payment Method could not be determined.', |
|
| 2857 | + 'event_espresso' |
|
| 2858 | + ), |
|
| 2859 | + ); |
|
| 2860 | + } |
|
| 2861 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
| 2862 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
| 2863 | + $txn_details = array( |
|
| 2864 | + 'TXN_ID' => $this->checkout->transaction->ID(), |
|
| 2865 | + 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
|
| 2866 | + 'TXN_total' => $this->checkout->transaction->total(), |
|
| 2867 | + 'TXN_paid' => $this->checkout->transaction->paid(), |
|
| 2868 | + 'TXN_reg_steps' => $this->checkout->transaction->reg_steps(), |
|
| 2869 | + 'STS_ID' => $this->checkout->transaction->status_ID(), |
|
| 2870 | + 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
|
| 2871 | + 'payment_amount' => $this->checkout->amount_owing, |
|
| 2872 | + 'return_url' => $return_url, |
|
| 2873 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
| 2874 | + 'notify_url' => EE_Config::instance()->core->txn_page_url( |
|
| 2875 | + array( |
|
| 2876 | + 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
|
| 2877 | + 'ee_payment_method' => $this->checkout->payment_method->slug(), |
|
| 2878 | + ) |
|
| 2879 | + ), |
|
| 2880 | + ); |
|
| 2881 | + } |
|
| 2882 | + echo wp_json_encode($txn_details); |
|
| 2883 | + exit(); |
|
| 2884 | + } |
|
| 2885 | + |
|
| 2886 | + |
|
| 2887 | + /** |
|
| 2888 | + * __sleep |
|
| 2889 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
| 2890 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
| 2891 | + * reg form, because if needed, it will be regenerated anyways |
|
| 2892 | + * |
|
| 2893 | + * @return array |
|
| 2894 | + */ |
|
| 2895 | + public function __sleep() |
|
| 2896 | + { |
|
| 2897 | + // remove the reg form and the checkout |
|
| 2898 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
| 2899 | + } |
|
| 2900 | 2900 | } |
@@ -211,7 +211,7 @@ |
||
| 211 | 211 | * appropriately. |
| 212 | 212 | * |
| 213 | 213 | * @throws EE_Error |
| 214 | - * @return EE_message_type|false if exception thrown. |
|
| 214 | + * @return null|EE_message_type if exception thrown. |
|
| 215 | 215 | */ |
| 216 | 216 | public function message_type_obj() |
| 217 | 217 | { |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function set_message_type($message_type = false) |
| 50 | 50 | { |
| 51 | - if (! $message_type) { |
|
| 51 | + if ( ! $message_type) { |
|
| 52 | 52 | throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
| 53 | 53 | } |
| 54 | 54 | $this->set('MTP_message_type', $message_type); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function set_messenger($messenger = false) |
| 63 | 63 | { |
| 64 | - if (! $messenger) { |
|
| 64 | + if ( ! $messenger) { |
|
| 65 | 65 | throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
| 66 | 66 | } |
| 67 | 67 | $this->set('MTP_messenger', $messenger); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function set_group_template_id($GRP_ID = false) |
| 76 | 76 | { |
| 77 | - if (! $GRP_ID) { |
|
| 77 | + if ( ! $GRP_ID) { |
|
| 78 | 78 | throw new EE_Error( |
| 79 | 79 | esc_html__( |
| 80 | 80 | 'Missing required value for the message template group id', |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
| 292 | 292 | foreach ($mtps as $mtp) { |
| 293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
| 293 | + $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp; |
|
| 294 | 294 | } |
| 295 | 295 | return $mtps_arr; |
| 296 | 296 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | public function deactivate_context($context) |
| 431 | 431 | { |
| 432 | 432 | $this->validate_context($context); |
| 433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
| 433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false); |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | public function activate_context($context) |
| 446 | 446 | { |
| 447 | 447 | $this->validate_context($context); |
| 448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
| 448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true); |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | { |
| 466 | 466 | $this->validate_context($context); |
| 467 | 467 | return filter_var( |
| 468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
| 468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true), |
|
| 469 | 469 | FILTER_VALIDATE_BOOLEAN |
| 470 | 470 | ); |
| 471 | 471 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | public function validate_context($context) |
| 482 | 482 | { |
| 483 | 483 | $contexts = $this->contexts_config(); |
| 484 | - if (! isset($contexts[ $context ])) { |
|
| 484 | + if ( ! isset($contexts[$context])) { |
|
| 485 | 485 | throw new InvalidIdentifierException( |
| 486 | 486 | '', |
| 487 | 487 | '', |
@@ -13,487 +13,487 @@ |
||
| 13 | 13 | class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
| 18 | - */ |
|
| 19 | - const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param array $props_n_values |
|
| 23 | - * @param string $timezone |
|
| 24 | - * @return EE_Message_Template_Group|mixed |
|
| 25 | - * @throws EE_Error |
|
| 26 | - */ |
|
| 27 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 28 | - { |
|
| 29 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 30 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @param array $props_n_values |
|
| 36 | - * @param string $timezone |
|
| 37 | - * @return EE_Message_Template_Group |
|
| 38 | - */ |
|
| 39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 40 | - { |
|
| 41 | - return new self($props_n_values, true, $timezone); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param bool $message_type |
|
| 47 | - * @throws EE_Error |
|
| 48 | - */ |
|
| 49 | - public function set_message_type($message_type = false) |
|
| 50 | - { |
|
| 51 | - if (! $message_type) { |
|
| 52 | - throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
| 53 | - } |
|
| 54 | - $this->set('MTP_message_type', $message_type); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param bool $messenger |
|
| 60 | - * @throws EE_Error |
|
| 61 | - */ |
|
| 62 | - public function set_messenger($messenger = false) |
|
| 63 | - { |
|
| 64 | - if (! $messenger) { |
|
| 65 | - throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
| 66 | - } |
|
| 67 | - $this->set('MTP_messenger', $messenger); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @param bool $GRP_ID |
|
| 73 | - * @throws EE_Error |
|
| 74 | - */ |
|
| 75 | - public function set_group_template_id($GRP_ID = false) |
|
| 76 | - { |
|
| 77 | - if (! $GRP_ID) { |
|
| 78 | - throw new EE_Error( |
|
| 79 | - esc_html__( |
|
| 80 | - 'Missing required value for the message template group id', |
|
| 81 | - 'event_espresso' |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - $this->set('GRP_ID', $GRP_ID); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * get Group ID |
|
| 91 | - * |
|
| 92 | - * @access public |
|
| 93 | - * @return int |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - public function GRP_ID() |
|
| 97 | - { |
|
| 98 | - return $this->get('GRP_ID'); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * get User ID |
|
| 104 | - * |
|
| 105 | - * @access public |
|
| 106 | - * @return int |
|
| 107 | - * @throws EE_Error |
|
| 108 | - */ |
|
| 109 | - public function user() |
|
| 110 | - { |
|
| 111 | - $user_id = $this->get('MTP_user_id'); |
|
| 112 | - return empty($user_id) ? get_current_user_id() : $user_id; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Wrapper for the user function() (preserve backward compat) |
|
| 118 | - * |
|
| 119 | - * @since 4.5.0 |
|
| 120 | - * @return int |
|
| 121 | - * @throws EE_Error |
|
| 122 | - */ |
|
| 123 | - public function wp_user() |
|
| 124 | - { |
|
| 125 | - return $this->user(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * This simply returns a count of all related events to this message template group |
|
| 131 | - * |
|
| 132 | - * @return int |
|
| 133 | - */ |
|
| 134 | - public function count_events() |
|
| 135 | - { |
|
| 136 | - return $this->count_related('Event'); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * returns the name saved in the db for this template |
|
| 142 | - * |
|
| 143 | - * @return string |
|
| 144 | - * @throws EE_Error |
|
| 145 | - */ |
|
| 146 | - public function name() |
|
| 147 | - { |
|
| 148 | - return $this->get('MTP_name'); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns the description saved in the db for this template group |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - * @throws EE_Error |
|
| 157 | - */ |
|
| 158 | - public function description() |
|
| 159 | - { |
|
| 160 | - return $this->get('MTP_description'); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * returns all related EE_Message_Template objects |
|
| 166 | - * |
|
| 167 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 168 | - * @return EE_Message_Template[] |
|
| 169 | - * @throws EE_Error |
|
| 170 | - */ |
|
| 171 | - public function message_templates($query_params = array()) |
|
| 172 | - { |
|
| 173 | - return $this->get_many_related('Message_Template', $query_params); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * get Message Messenger |
|
| 179 | - * |
|
| 180 | - * @access public |
|
| 181 | - * @return string |
|
| 182 | - * @throws EE_Error |
|
| 183 | - */ |
|
| 184 | - public function messenger() |
|
| 185 | - { |
|
| 186 | - return $this->get('MTP_messenger'); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * get Message Messenger OBJECT |
|
| 192 | - * If an attempt to get the corresponding messenger object fails, then we set this message |
|
| 193 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
| 194 | - * appropriately. |
|
| 195 | - * |
|
| 196 | - * @return EE_messenger |
|
| 197 | - * @throws EE_Error |
|
| 198 | - */ |
|
| 199 | - public function messenger_obj() |
|
| 200 | - { |
|
| 201 | - $messenger = $this->messenger(); |
|
| 202 | - try { |
|
| 203 | - $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
| 204 | - } catch (EE_Error $e) { |
|
| 205 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
| 206 | - // class for this messenger in this group. |
|
| 207 | - $this->set('MTP_is_active', false); |
|
| 208 | - $this->save(); |
|
| 209 | - return null; |
|
| 210 | - } |
|
| 211 | - return $messenger; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * get Message Type |
|
| 217 | - * |
|
| 218 | - * @access public |
|
| 219 | - * @return string |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function message_type() |
|
| 223 | - { |
|
| 224 | - return $this->get('MTP_message_type'); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * get Message type OBJECT |
|
| 230 | - * If an attempt to get the corresponding message type object fails, then we set this message |
|
| 231 | - * template group to inactive, and save to db. Then return null so client code can handle |
|
| 232 | - * appropriately. |
|
| 233 | - * |
|
| 234 | - * @throws EE_Error |
|
| 235 | - * @return EE_message_type|false if exception thrown. |
|
| 236 | - */ |
|
| 237 | - public function message_type_obj() |
|
| 238 | - { |
|
| 239 | - $message_type = $this->message_type(); |
|
| 240 | - try { |
|
| 241 | - $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
| 242 | - } catch (EE_Error $e) { |
|
| 243 | - // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
| 244 | - // class for the message type in this group. |
|
| 245 | - $this->set('MTP_is_active', false); |
|
| 246 | - $this->save(); |
|
| 247 | - return null; |
|
| 248 | - } |
|
| 249 | - return $message_type; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @return array |
|
| 255 | - * @throws EE_Error |
|
| 256 | - */ |
|
| 257 | - public function contexts_config() |
|
| 258 | - { |
|
| 259 | - return $this->message_type_obj()->get_contexts(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * This returns the context_label for contexts as set in the message type object |
|
| 265 | - * Note this is an array with singular and plural keys |
|
| 266 | - * |
|
| 267 | - * @access public |
|
| 268 | - * @return array labels for "context" |
|
| 269 | - * @throws EE_Error |
|
| 270 | - */ |
|
| 271 | - public function context_label() |
|
| 272 | - { |
|
| 273 | - $obj = $this->message_type_obj(); |
|
| 274 | - return $obj->get_context_label(); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * This returns an array of EE_Message_Template objects indexed by context and field. |
|
| 280 | - * |
|
| 281 | - * @return array () |
|
| 282 | - * @throws EE_Error |
|
| 283 | - */ |
|
| 284 | - public function context_templates() |
|
| 285 | - { |
|
| 286 | - $mtps_arr = array(); |
|
| 287 | - $mtps = $this->get_many_related('Message_Template'); |
|
| 288 | - if (empty($mtps)) { |
|
| 289 | - return array(); |
|
| 290 | - } |
|
| 291 | - // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
| 292 | - foreach ($mtps as $mtp) { |
|
| 293 | - $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
| 294 | - } |
|
| 295 | - return $mtps_arr; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * this returns if the template group this template belongs to is global |
|
| 301 | - * |
|
| 302 | - * @return bool true if it is, false if it isn't |
|
| 303 | - * @throws EE_Error |
|
| 304 | - */ |
|
| 305 | - public function is_global() |
|
| 306 | - { |
|
| 307 | - return $this->get('MTP_is_global'); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
| 313 | - * |
|
| 314 | - * @return bool true if it is, false if it isn't |
|
| 315 | - * @throws EE_Error |
|
| 316 | - */ |
|
| 317 | - public function is_active() |
|
| 318 | - { |
|
| 319 | - return $this->get('MTP_is_active'); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
| 325 | - * this template. |
|
| 326 | - * |
|
| 327 | - * @since 4.3.0 |
|
| 328 | - * @uses EEH_MSG_Template::get_shortcodes() |
|
| 329 | - * @param string $context what context we're going to return shortcodes for |
|
| 330 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
| 331 | - * to be returned. |
|
| 332 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
| 333 | - * unique shortcodes for all the given (or all) fields. |
|
| 334 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
| 335 | - * shortcodes found. |
|
| 336 | - * @throws EE_Error |
|
| 337 | - */ |
|
| 338 | - public function get_shortcodes($context, $fields = array(), $merged = false) |
|
| 339 | - { |
|
| 340 | - $messenger = $this->messenger(); |
|
| 341 | - $message_type = $this->message_type(); |
|
| 342 | - return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
| 348 | - * use the default template pack. |
|
| 349 | - * |
|
| 350 | - * @since 4.5.0 |
|
| 351 | - * @return string |
|
| 352 | - * @throws EE_Error |
|
| 353 | - */ |
|
| 354 | - public function get_template_pack_name() |
|
| 355 | - { |
|
| 356 | - return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * This returns the specific template pack object referenced by the template pack name attached to this message |
|
| 362 | - * template group. If no template pack is assigned then the default template pack is retrieved. |
|
| 363 | - * |
|
| 364 | - * @since 4.5.0 |
|
| 365 | - * @return EE_Messages_Template_Pack |
|
| 366 | - * @throws EE_Error |
|
| 367 | - * @throws InvalidArgumentException |
|
| 368 | - * @throws ReflectionException |
|
| 369 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 370 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 371 | - */ |
|
| 372 | - public function get_template_pack() |
|
| 373 | - { |
|
| 374 | - $pack_name = $this->get_template_pack_name(); |
|
| 375 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 376 | - return EEH_MSG_Template::get_template_pack($pack_name); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
| 382 | - * use the default template variation. |
|
| 383 | - * |
|
| 384 | - * @since 4.5.0 |
|
| 385 | - * @return string |
|
| 386 | - * @throws EE_Error |
|
| 387 | - */ |
|
| 388 | - public function get_template_pack_variation() |
|
| 389 | - { |
|
| 390 | - return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * This just sets the template pack name attached to this message template group. |
|
| 396 | - * |
|
| 397 | - * @since 4.5.0 |
|
| 398 | - * @param string $template_pack_name What message template pack is assigned. |
|
| 399 | - * @return int |
|
| 400 | - * @throws EE_Error |
|
| 401 | - */ |
|
| 402 | - public function set_template_pack_name($template_pack_name) |
|
| 403 | - { |
|
| 404 | - return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * This just sets the template pack variation attached to this message template group. |
|
| 410 | - * |
|
| 411 | - * @since 4.5.0 |
|
| 412 | - * @param string $variation What variation is being set on the message template group. |
|
| 413 | - * @return int |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function set_template_pack_variation($variation) |
|
| 417 | - { |
|
| 418 | - return $this->update_extra_meta('MTP_variation', $variation); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Deactivates the given context. |
|
| 424 | - * |
|
| 425 | - * @param $context |
|
| 426 | - * @return bool|int |
|
| 427 | - * @throws EE_Error |
|
| 428 | - * @throws InvalidIdentifierException |
|
| 429 | - */ |
|
| 430 | - public function deactivate_context($context) |
|
| 431 | - { |
|
| 432 | - $this->validate_context($context); |
|
| 433 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Activates the given context. |
|
| 439 | - * |
|
| 440 | - * @param $context |
|
| 441 | - * @return bool|int |
|
| 442 | - * @throws EE_Error |
|
| 443 | - * @throws InvalidIdentifierException |
|
| 444 | - */ |
|
| 445 | - public function activate_context($context) |
|
| 446 | - { |
|
| 447 | - $this->validate_context($context); |
|
| 448 | - return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Returns whether the context is active or not. |
|
| 454 | - * Note, this will default to true if the extra meta record doesn't exist. |
|
| 455 | - * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
| 456 | - * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
| 457 | - * whether a context is "active" or not. |
|
| 458 | - * |
|
| 459 | - * @param $context |
|
| 460 | - * @return bool |
|
| 461 | - * @throws EE_Error |
|
| 462 | - * @throws InvalidIdentifierException |
|
| 463 | - */ |
|
| 464 | - public function is_context_active($context) |
|
| 465 | - { |
|
| 466 | - $this->validate_context($context); |
|
| 467 | - return filter_var( |
|
| 468 | - $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
| 469 | - FILTER_VALIDATE_BOOLEAN |
|
| 470 | - ); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Validates the incoming context to verify it matches a registered context for the related message type. |
|
| 476 | - * |
|
| 477 | - * @param string $context |
|
| 478 | - * @throws EE_Error |
|
| 479 | - * @throws InvalidIdentifierException |
|
| 480 | - */ |
|
| 481 | - public function validate_context($context) |
|
| 482 | - { |
|
| 483 | - $contexts = $this->contexts_config(); |
|
| 484 | - if (! isset($contexts[ $context ])) { |
|
| 485 | - throw new InvalidIdentifierException( |
|
| 486 | - '', |
|
| 487 | - '', |
|
| 488 | - sprintf( |
|
| 489 | - esc_html__( |
|
| 490 | - 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
| 491 | - 'event_espresso' |
|
| 492 | - ), |
|
| 493 | - $context, |
|
| 494 | - implode(',', array_keys($contexts)) |
|
| 495 | - ) |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - } |
|
| 16 | + /** |
|
| 17 | + * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not. |
|
| 18 | + */ |
|
| 19 | + const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param array $props_n_values |
|
| 23 | + * @param string $timezone |
|
| 24 | + * @return EE_Message_Template_Group|mixed |
|
| 25 | + * @throws EE_Error |
|
| 26 | + */ |
|
| 27 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
| 28 | + { |
|
| 29 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
| 30 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @param array $props_n_values |
|
| 36 | + * @param string $timezone |
|
| 37 | + * @return EE_Message_Template_Group |
|
| 38 | + */ |
|
| 39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
| 40 | + { |
|
| 41 | + return new self($props_n_values, true, $timezone); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param bool $message_type |
|
| 47 | + * @throws EE_Error |
|
| 48 | + */ |
|
| 49 | + public function set_message_type($message_type = false) |
|
| 50 | + { |
|
| 51 | + if (! $message_type) { |
|
| 52 | + throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso')); |
|
| 53 | + } |
|
| 54 | + $this->set('MTP_message_type', $message_type); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param bool $messenger |
|
| 60 | + * @throws EE_Error |
|
| 61 | + */ |
|
| 62 | + public function set_messenger($messenger = false) |
|
| 63 | + { |
|
| 64 | + if (! $messenger) { |
|
| 65 | + throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso')); |
|
| 66 | + } |
|
| 67 | + $this->set('MTP_messenger', $messenger); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @param bool $GRP_ID |
|
| 73 | + * @throws EE_Error |
|
| 74 | + */ |
|
| 75 | + public function set_group_template_id($GRP_ID = false) |
|
| 76 | + { |
|
| 77 | + if (! $GRP_ID) { |
|
| 78 | + throw new EE_Error( |
|
| 79 | + esc_html__( |
|
| 80 | + 'Missing required value for the message template group id', |
|
| 81 | + 'event_espresso' |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + $this->set('GRP_ID', $GRP_ID); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * get Group ID |
|
| 91 | + * |
|
| 92 | + * @access public |
|
| 93 | + * @return int |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + public function GRP_ID() |
|
| 97 | + { |
|
| 98 | + return $this->get('GRP_ID'); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * get User ID |
|
| 104 | + * |
|
| 105 | + * @access public |
|
| 106 | + * @return int |
|
| 107 | + * @throws EE_Error |
|
| 108 | + */ |
|
| 109 | + public function user() |
|
| 110 | + { |
|
| 111 | + $user_id = $this->get('MTP_user_id'); |
|
| 112 | + return empty($user_id) ? get_current_user_id() : $user_id; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Wrapper for the user function() (preserve backward compat) |
|
| 118 | + * |
|
| 119 | + * @since 4.5.0 |
|
| 120 | + * @return int |
|
| 121 | + * @throws EE_Error |
|
| 122 | + */ |
|
| 123 | + public function wp_user() |
|
| 124 | + { |
|
| 125 | + return $this->user(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * This simply returns a count of all related events to this message template group |
|
| 131 | + * |
|
| 132 | + * @return int |
|
| 133 | + */ |
|
| 134 | + public function count_events() |
|
| 135 | + { |
|
| 136 | + return $this->count_related('Event'); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * returns the name saved in the db for this template |
|
| 142 | + * |
|
| 143 | + * @return string |
|
| 144 | + * @throws EE_Error |
|
| 145 | + */ |
|
| 146 | + public function name() |
|
| 147 | + { |
|
| 148 | + return $this->get('MTP_name'); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns the description saved in the db for this template group |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + * @throws EE_Error |
|
| 157 | + */ |
|
| 158 | + public function description() |
|
| 159 | + { |
|
| 160 | + return $this->get('MTP_description'); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * returns all related EE_Message_Template objects |
|
| 166 | + * |
|
| 167 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 168 | + * @return EE_Message_Template[] |
|
| 169 | + * @throws EE_Error |
|
| 170 | + */ |
|
| 171 | + public function message_templates($query_params = array()) |
|
| 172 | + { |
|
| 173 | + return $this->get_many_related('Message_Template', $query_params); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * get Message Messenger |
|
| 179 | + * |
|
| 180 | + * @access public |
|
| 181 | + * @return string |
|
| 182 | + * @throws EE_Error |
|
| 183 | + */ |
|
| 184 | + public function messenger() |
|
| 185 | + { |
|
| 186 | + return $this->get('MTP_messenger'); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * get Message Messenger OBJECT |
|
| 192 | + * If an attempt to get the corresponding messenger object fails, then we set this message |
|
| 193 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
| 194 | + * appropriately. |
|
| 195 | + * |
|
| 196 | + * @return EE_messenger |
|
| 197 | + * @throws EE_Error |
|
| 198 | + */ |
|
| 199 | + public function messenger_obj() |
|
| 200 | + { |
|
| 201 | + $messenger = $this->messenger(); |
|
| 202 | + try { |
|
| 203 | + $messenger = EEH_MSG_Template::messenger_obj($messenger); |
|
| 204 | + } catch (EE_Error $e) { |
|
| 205 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
| 206 | + // class for this messenger in this group. |
|
| 207 | + $this->set('MTP_is_active', false); |
|
| 208 | + $this->save(); |
|
| 209 | + return null; |
|
| 210 | + } |
|
| 211 | + return $messenger; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * get Message Type |
|
| 217 | + * |
|
| 218 | + * @access public |
|
| 219 | + * @return string |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function message_type() |
|
| 223 | + { |
|
| 224 | + return $this->get('MTP_message_type'); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * get Message type OBJECT |
|
| 230 | + * If an attempt to get the corresponding message type object fails, then we set this message |
|
| 231 | + * template group to inactive, and save to db. Then return null so client code can handle |
|
| 232 | + * appropriately. |
|
| 233 | + * |
|
| 234 | + * @throws EE_Error |
|
| 235 | + * @return EE_message_type|false if exception thrown. |
|
| 236 | + */ |
|
| 237 | + public function message_type_obj() |
|
| 238 | + { |
|
| 239 | + $message_type = $this->message_type(); |
|
| 240 | + try { |
|
| 241 | + $message_type = EEH_MSG_Template::message_type_obj($message_type); |
|
| 242 | + } catch (EE_Error $e) { |
|
| 243 | + // if an exception was thrown then let's deactivate this message template group because it means there is no |
|
| 244 | + // class for the message type in this group. |
|
| 245 | + $this->set('MTP_is_active', false); |
|
| 246 | + $this->save(); |
|
| 247 | + return null; |
|
| 248 | + } |
|
| 249 | + return $message_type; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @return array |
|
| 255 | + * @throws EE_Error |
|
| 256 | + */ |
|
| 257 | + public function contexts_config() |
|
| 258 | + { |
|
| 259 | + return $this->message_type_obj()->get_contexts(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * This returns the context_label for contexts as set in the message type object |
|
| 265 | + * Note this is an array with singular and plural keys |
|
| 266 | + * |
|
| 267 | + * @access public |
|
| 268 | + * @return array labels for "context" |
|
| 269 | + * @throws EE_Error |
|
| 270 | + */ |
|
| 271 | + public function context_label() |
|
| 272 | + { |
|
| 273 | + $obj = $this->message_type_obj(); |
|
| 274 | + return $obj->get_context_label(); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * This returns an array of EE_Message_Template objects indexed by context and field. |
|
| 280 | + * |
|
| 281 | + * @return array () |
|
| 282 | + * @throws EE_Error |
|
| 283 | + */ |
|
| 284 | + public function context_templates() |
|
| 285 | + { |
|
| 286 | + $mtps_arr = array(); |
|
| 287 | + $mtps = $this->get_many_related('Message_Template'); |
|
| 288 | + if (empty($mtps)) { |
|
| 289 | + return array(); |
|
| 290 | + } |
|
| 291 | + // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field. |
|
| 292 | + foreach ($mtps as $mtp) { |
|
| 293 | + $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp; |
|
| 294 | + } |
|
| 295 | + return $mtps_arr; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * this returns if the template group this template belongs to is global |
|
| 301 | + * |
|
| 302 | + * @return bool true if it is, false if it isn't |
|
| 303 | + * @throws EE_Error |
|
| 304 | + */ |
|
| 305 | + public function is_global() |
|
| 306 | + { |
|
| 307 | + return $this->get('MTP_is_global'); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
| 313 | + * |
|
| 314 | + * @return bool true if it is, false if it isn't |
|
| 315 | + * @throws EE_Error |
|
| 316 | + */ |
|
| 317 | + public function is_active() |
|
| 318 | + { |
|
| 319 | + return $this->get('MTP_is_active'); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
| 325 | + * this template. |
|
| 326 | + * |
|
| 327 | + * @since 4.3.0 |
|
| 328 | + * @uses EEH_MSG_Template::get_shortcodes() |
|
| 329 | + * @param string $context what context we're going to return shortcodes for |
|
| 330 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
| 331 | + * to be returned. |
|
| 332 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field but instead an array of the |
|
| 333 | + * unique shortcodes for all the given (or all) fields. |
|
| 334 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
| 335 | + * shortcodes found. |
|
| 336 | + * @throws EE_Error |
|
| 337 | + */ |
|
| 338 | + public function get_shortcodes($context, $fields = array(), $merged = false) |
|
| 339 | + { |
|
| 340 | + $messenger = $this->messenger(); |
|
| 341 | + $message_type = $this->message_type(); |
|
| 342 | + return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * This just gets the template pack name assigned to this message template group. If it's not set, then we just |
|
| 348 | + * use the default template pack. |
|
| 349 | + * |
|
| 350 | + * @since 4.5.0 |
|
| 351 | + * @return string |
|
| 352 | + * @throws EE_Error |
|
| 353 | + */ |
|
| 354 | + public function get_template_pack_name() |
|
| 355 | + { |
|
| 356 | + return $this->get_extra_meta('MTP_template_pack', true, 'default'); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * This returns the specific template pack object referenced by the template pack name attached to this message |
|
| 362 | + * template group. If no template pack is assigned then the default template pack is retrieved. |
|
| 363 | + * |
|
| 364 | + * @since 4.5.0 |
|
| 365 | + * @return EE_Messages_Template_Pack |
|
| 366 | + * @throws EE_Error |
|
| 367 | + * @throws InvalidArgumentException |
|
| 368 | + * @throws ReflectionException |
|
| 369 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 370 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 371 | + */ |
|
| 372 | + public function get_template_pack() |
|
| 373 | + { |
|
| 374 | + $pack_name = $this->get_template_pack_name(); |
|
| 375 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 376 | + return EEH_MSG_Template::get_template_pack($pack_name); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * This retrieves the template variation assigned to this message template group. If it's not set, then we just |
|
| 382 | + * use the default template variation. |
|
| 383 | + * |
|
| 384 | + * @since 4.5.0 |
|
| 385 | + * @return string |
|
| 386 | + * @throws EE_Error |
|
| 387 | + */ |
|
| 388 | + public function get_template_pack_variation() |
|
| 389 | + { |
|
| 390 | + return $this->get_extra_meta('MTP_variation', true, 'default'); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * This just sets the template pack name attached to this message template group. |
|
| 396 | + * |
|
| 397 | + * @since 4.5.0 |
|
| 398 | + * @param string $template_pack_name What message template pack is assigned. |
|
| 399 | + * @return int |
|
| 400 | + * @throws EE_Error |
|
| 401 | + */ |
|
| 402 | + public function set_template_pack_name($template_pack_name) |
|
| 403 | + { |
|
| 404 | + return $this->update_extra_meta('MTP_template_pack', $template_pack_name); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * This just sets the template pack variation attached to this message template group. |
|
| 410 | + * |
|
| 411 | + * @since 4.5.0 |
|
| 412 | + * @param string $variation What variation is being set on the message template group. |
|
| 413 | + * @return int |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function set_template_pack_variation($variation) |
|
| 417 | + { |
|
| 418 | + return $this->update_extra_meta('MTP_variation', $variation); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Deactivates the given context. |
|
| 424 | + * |
|
| 425 | + * @param $context |
|
| 426 | + * @return bool|int |
|
| 427 | + * @throws EE_Error |
|
| 428 | + * @throws InvalidIdentifierException |
|
| 429 | + */ |
|
| 430 | + public function deactivate_context($context) |
|
| 431 | + { |
|
| 432 | + $this->validate_context($context); |
|
| 433 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Activates the given context. |
|
| 439 | + * |
|
| 440 | + * @param $context |
|
| 441 | + * @return bool|int |
|
| 442 | + * @throws EE_Error |
|
| 443 | + * @throws InvalidIdentifierException |
|
| 444 | + */ |
|
| 445 | + public function activate_context($context) |
|
| 446 | + { |
|
| 447 | + $this->validate_context($context); |
|
| 448 | + return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Returns whether the context is active or not. |
|
| 454 | + * Note, this will default to true if the extra meta record doesn't exist. |
|
| 455 | + * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field |
|
| 456 | + * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of |
|
| 457 | + * whether a context is "active" or not. |
|
| 458 | + * |
|
| 459 | + * @param $context |
|
| 460 | + * @return bool |
|
| 461 | + * @throws EE_Error |
|
| 462 | + * @throws InvalidIdentifierException |
|
| 463 | + */ |
|
| 464 | + public function is_context_active($context) |
|
| 465 | + { |
|
| 466 | + $this->validate_context($context); |
|
| 467 | + return filter_var( |
|
| 468 | + $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true), |
|
| 469 | + FILTER_VALIDATE_BOOLEAN |
|
| 470 | + ); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Validates the incoming context to verify it matches a registered context for the related message type. |
|
| 476 | + * |
|
| 477 | + * @param string $context |
|
| 478 | + * @throws EE_Error |
|
| 479 | + * @throws InvalidIdentifierException |
|
| 480 | + */ |
|
| 481 | + public function validate_context($context) |
|
| 482 | + { |
|
| 483 | + $contexts = $this->contexts_config(); |
|
| 484 | + if (! isset($contexts[ $context ])) { |
|
| 485 | + throw new InvalidIdentifierException( |
|
| 486 | + '', |
|
| 487 | + '', |
|
| 488 | + sprintf( |
|
| 489 | + esc_html__( |
|
| 490 | + 'An invalid string identifying a context was provided. "%1$s" was received, and one of "%2$s" was expected.', |
|
| 491 | + 'event_espresso' |
|
| 492 | + ), |
|
| 493 | + $context, |
|
| 494 | + implode(',', array_keys($contexts)) |
|
| 495 | + ) |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | 499 | } |